@@ -112,7 +112,7 @@ public boolean locateDelocalizedDoubleBonds(boolean[] isDelocalizedBond, boolean
112112
113113 promoteObviousBonds ();
114114
115- while (promoteOuterShellDelocalizedRingSystems (ringSet ))
115+ while (promoteOuterShellDelocalizedRingSystems (ringSet , mayChangeAtomCharges ))
116116 promoteObviousBonds ();
117117
118118 // try to find and promote entirely aromatic 6-rings
@@ -136,16 +136,22 @@ public boolean locateDelocalizedDoubleBonds(boolean[] isDelocalizedBond, boolean
136136 if (mDelocalizedAtoms - mPiElectronsAdded >= 2 )
137137 connectSeparatedSingletons ();
138138
139- if (mayChangeAtomCharges ) {
140- for (int atom =0 ; atom <mMol .getAtoms (); atom ++) {
141- if (mIsDelocalizedAtom [atom ] && mMol .getImplicitHydrogens (atom ) != 0 ) {
142- if ((mMol .getAtomCharge (atom ) == 1 && mMol .isElectronegative (atom ))
143- || (mMol .getAtomCharge (atom ) == -1 && mMol .getAtomicNo (atom ) == 5 ))
144- mMol .setAtomCharge (atom , 0 );
145- else
146- mMol .setAtomRadical (atom , Molecule .cAtomRadicalStateD );
147- mPiElectronsAdded ++;
148- }
139+ // If finally one or more single delocalized atoms remain, and if these carry an implicit hydrogen,
140+ // and if it is allowed and possible, then add/remove a charge to make the atom's lone pair contribute
141+ // to the neighbour atom's delocalization. If modifying charges is not allowed, then remove an implicit
142+ // hydrogen including one of its binding electrons. An unpaired electron is closer to the intended aromatic
143+ // state than a wrong hybridisation and one implicit hydrogen too much.
144+ // In addition, during id-coordinate parsing of implicit hydrogen atoms, the number of implicit hydrogens
145+ // per non-H atom must exactly match the one given when the idcode with coordinates was encoded.
146+ for (int atom =0 ; atom <mMol .getAtoms (); atom ++) {
147+ if (mIsDelocalizedAtom [atom ] && mMol .getImplicitHydrogens (atom ) != 0 ) {
148+ if (mayChangeAtomCharges
149+ && ((mMol .getAtomCharge (atom ) == 1 && mMol .isElectronegative (atom ))
150+ || (mMol .getAtomCharge (atom ) == -1 && mMol .getAtomicNo (atom ) == 5 )))
151+ mMol .setAtomCharge (atom , 0 );
152+ else
153+ mMol .setAtomRadical (atom , Molecule .cAtomRadicalStateD );
154+ mPiElectronsAdded ++;
149155 }
150156 }
151157
@@ -229,7 +235,7 @@ private boolean promoteSixMemberedAromaticRings(RingCollection ringSet, boolean
229235
230236 if (isQualifyingRing ) {
231237 if (mayChangeAtomCharges )
232- for (int i =0 ; i <6 ; i += 2 )
238+ for (int i =0 ; i <6 ; i ++ )
233239 checkAtomTypePi1 (ringAtom [i ], true );
234240
235241 for (int i =0 ; i <6 ; i +=2 )
@@ -286,7 +292,7 @@ private boolean promoteOneDelocalizationLeak(RingCollection ringSet, boolean may
286292 return false ;
287293 }
288294
289- private boolean promoteOuterShellDelocalizedRingSystems (RingCollection ringSet ) {
295+ private boolean promoteOuterShellDelocalizedRingSystems (RingCollection ringSet , boolean mayChangeAtomCharges ) {
290296 int [] sharedDelocalizedRingCount = new int [mMol .getBonds ()];
291297 for (int r =0 ; r <ringSet .getSize (); r ++) {
292298 int [] ringBond = ringSet .getRingBonds (r );
@@ -325,6 +331,10 @@ private boolean promoteOuterShellDelocalizedRingSystems(RingCollection ringSet)
325331 if (bridgeBonds > 2 && (bridgeBonds & 1 ) == 1 ) {
326332 for (int j =1 ; j <bridgeBonds ; j +=2 ) {
327333 int index = (first +j < ringBond .length ) ? first +j : first +j -ringBond .length ;
334+ if (mayChangeAtomCharges ) {
335+ checkAtomTypePi1 (ringAtom [index ], true );
336+ checkAtomTypePi1 (ringAtom [index == ringAtom .length -1 ? 0 : index +1 ], true );
337+ }
328338 promoteBond (ringBond [index ]);
329339 }
330340 found = true ;
0 commit comments