@@ -1018,6 +1018,26 @@ private void calcGroup025_026_028_029_031_032_034_035_043_044(int i) {
10181018 }
10191019 }
10201020
1021+ private boolean isPyrroleLikeHetero (IAtom atom ) {
1022+ if (!atom .isAromatic ())
1023+ return false ;
1024+ switch (atom .getAtomicNumber ()) {
1025+ case 7 :
1026+ case 15 :
1027+ if (atom .getBondCount () == 3 && atom .getFormalCharge () == 0 )
1028+ return true ;
1029+ if (atom .getBondCount () == 2 && atom .getImplicitHydrogenCount () == 1 )
1030+ return true ;
1031+ if (atom .getBondCount () == 2 && atom .getFormalCharge () == -1 )
1032+ return true ;
1033+ return false ;
1034+ case 8 :
1035+ case 16 :
1036+ return true ;
1037+ }
1038+ return false ;
1039+ }
1040+
10211041 private int getHAtomType (IAtom ai , List connectedAtoms ) {
10221042 //ai is the atom connected to a H atoms.
10231043 //ai environment determines what is the H atom type
@@ -1053,76 +1073,95 @@ private int getHAtomType(IAtom ai, List connectedAtoms) {
10531073 return 51 ;
10541074 } // end if(ai.getSymbol().equals("C") && !ai.getFlag(CDKConstants.ISAROMATIC))
10551075
1056- List bonds = atomContainer .getConnectedBondsList (ai );
1057- int doublebondcount = 0 ;
1058- int triplebondcount = 0 ;
1059- String hybrid = "" ;
1060-
1061- for (int j = 0 ; j <= bonds .size () - 1 ; j ++) {
1062- if (((IBond ) bonds .get (j )).getOrder () == IBond .Order .DOUBLE )
1063- doublebondcount ++;
1064- else if (((IBond ) bonds .get (j )).getOrder () == IBond .Order .TRIPLE ) triplebondcount ++;
1065- }
1076+ IAtomType .Hybridization hyb ;
10661077
1067- if (doublebondcount == 0 && triplebondcount == 0 )
1068- hybrid = "sp3" ;
1069- else if (doublebondcount == 1 && triplebondcount == 0 )
1070- hybrid = "sp2" ;
1071- else if (doublebondcount == 2 || triplebondcount == 1 ) hybrid = "sp" ;
1078+ int ndoub = 0 ;
1079+ int ntrip = 0 ;
10721080 int oxNum = 0 ;
10731081 int xCount = 0 ;
1074-
1075- for (int j = 0 ; j <= ca .size () - 1 ; j ++) {
1076- //String s = ((IAtom)ca.get(j)).getSymbol();
1077- // if (s.equals("F") || s.equals("O") || s.equals("Cl")
1078- // || s.equals("Br") || s.equals("N") || s.equals("S"))
1079- if (ap .getNormalizedElectronegativity (((IAtom ) ca .get (j )).getSymbol ()) > 1 ) {
1080- java .util .List bonds2 = atomContainer .getConnectedBondsList (((IAtom ) ca .get (j )));
1081- boolean haveDouble = false ;
1082- for (int k = 0 ; k <= bonds2 .size () - 1 ; k ++) {
1083- if (((IBond ) bonds2 .get (k )).getOrder () == IBond .Order .DOUBLE ) {
1084- haveDouble = true ;
1085- break ;
1082+ boolean hasConjHetereo = false ;
1083+
1084+ for (IBond bond : ai .bonds ()) {
1085+ if (bond .getOrder () == IBond .Order .DOUBLE )
1086+ ndoub ++;
1087+ else if (bond .getOrder () == IBond .Order .TRIPLE )
1088+ ntrip ++;
1089+ final IAtom nbor = bond .getOther (ai );
1090+ if (isHetero (nbor )) {
1091+ if (bond .isAromatic ()) {
1092+ if (bond .getOrder () == IBond .Order .SINGLE ) {
1093+ if (!isPyrroleLikeHetero (nbor ) && !hasConjHetereo ) {
1094+ oxNum += 2 ;
1095+ hasConjHetereo = true ;
1096+ } else
1097+ oxNum ++;
1098+ } else if (!hasConjHetereo ) {
1099+ hasConjHetereo = true ;
1100+ oxNum += 2 ;
1101+ } else {
1102+ oxNum ++;
10861103 }
1104+ } else
1105+ oxNum += bond .getOrder ().numeric ();
1106+ }
1107+ else if (nbor .getAtomicNumber () == 6 ) {
1108+ for (IBond bond2 : nbor .bonds ()) {
1109+ IAtom nbor2 = bond2 .getOther (nbor );
1110+ if (isHetero (nbor2 ))
1111+ xCount ++;
10871112 }
1088- if (haveDouble && ((IAtom ) ca .get (j )).getSymbol ().equals ("N" ))
1089- oxNum += 2 ; // C-N bond order for pyridine type N's is considered to be 2
1090- else
1091- oxNum += BondManipulator
1092- .destroyBondOrder (atomContainer .getBond (ai , ((IAtom ) ca .get (j ))).getOrder ());
10931113 }
1094- java . util . List ca2 = atomContainer . getConnectedAtomsList ((( IAtom ) ca . get ( j )));
1114+ }
10951115
1096- for (int k = 0 ; k <= ca2 .size () - 1 ; k ++) {
1097- String s2 = ((IAtom ) ca2 .get (k )).getSymbol ();
1098- if (!s2 .equals ("C" )) xCount ++;
1099- }
1100- }// end j loop
1101-
1102- if (oxNum == 0 ) {
1103- if (hybrid .equals ("sp3" )) {
1104- if (xCount == 0 )
1105- return 46 ;
1106- else if (xCount == 1 )
1107- return 52 ;
1108- else if (xCount == 2 )
1109- return 53 ;
1110- else if (xCount == 3 )
1111- return 54 ;
1112- else if (xCount >= 4 ) return 55 ;
1113- } else if (hybrid .equals ("sp2" )) {
1114- return 47 ;
1115- } else if (hybrid .equals ("sp" )) {
1116- return 48 ;
1117- }
1118- } else if (oxNum == 1 && hybrid .equals ("sp3" ))
1119- return 47 ;
1120- else if (oxNum == 2 && hybrid .equals ("sp3" ) || oxNum == 1 && hybrid .equals ("sp2" ))
1121- return 48 ;
1122- else if ((oxNum == 3 && hybrid .equals ("sp3" )) || (oxNum >= 2 && hybrid .equals ("sp2" ))
1123- || (oxNum >= 1 && hybrid .equals ("sp" ))) return 49 ;
1124-
1125- return (0 );
1116+ if (ndoub == 0 && ntrip == 0 )
1117+ hyb = IAtomType .Hybridization .SP3 ;
1118+ else if (ndoub == 1 && ntrip == 0 )
1119+ hyb = IAtomType .Hybridization .SP2 ;
1120+ else if (ndoub == 2 || ntrip == 1 )
1121+ hyb = IAtomType .Hybridization .SP1 ;
1122+ else
1123+ return 0 ; // unknown
1124+
1125+ switch (hyb ) {
1126+ case SP1 :
1127+ if (oxNum == 0 )
1128+ return 48 ;
1129+ if (oxNum == 1 )
1130+ return 49 ;
1131+ break ;
1132+ case SP2 :
1133+ if (oxNum == 0 )
1134+ return 47 ;
1135+ if (oxNum == 1 )
1136+ return 48 ;
1137+ if (oxNum == 2 || oxNum == 3 )
1138+ return 49 ;
1139+ break ;
1140+ case SP3 :
1141+ if (oxNum == 0 ) {
1142+ if (xCount == 0 )
1143+ return 46 ;
1144+ else if (xCount == 1 )
1145+ return 52 ;
1146+ else if (xCount == 2 )
1147+ return 53 ;
1148+ else if (xCount == 3 )
1149+ return 54 ;
1150+ else if (xCount == 4 )
1151+ return 55 ;
1152+ }
1153+ if (oxNum == 1 )
1154+ return 47 ;
1155+ if (oxNum == 2 )
1156+ return 48 ;
1157+ if (oxNum == 3 )
1158+ return 49 ;
1159+ break ;
1160+ }
1161+
1162+ System .out .println ("Fall through" );
1163+
1164+ return 0 ;
11261165 }
11271166
11281167 private void calcGroup056_57 (int i ) {
0 commit comments