Ok, I'll give in my modified version of the original CDK method I obtained
(forgot how). Be warned though - there're a lot of hacks in this because
basically - AMBIT SMARTS had issues regarding implicit hydrogens, and when
you are dealing with SMARTS atom types I did the minimum necessary to get
it work.
public static synchronized void calculateImplicitHydrogens( IAtomContainer
mol ) {
final String[] HYVALENCE_EL={"C","N","O","S","P", "F"};
final int[] HYVALENCE_VAL={ 4, 3, 2, 2, 3, 1 };
for (int n=0; n < mol.getAtomCount() ;n++)
{
IAtom atom=mol.getAtom(n);
String el=atom.getSymbol();
int hy=0;
// FIXME I don't care at the moment what this is - I just want
the SMILES generators to stop complaining!
atom.setImplicitHydrogenCount( 0 );
if( el != null ) {
for (int i=0;i<HYVALENCE_EL.length;i++) if
(el.equals(HYVALENCE_EL[i])) {hy=HYVALENCE_VAL[i]; break;}
} else {
atom.setImplicitHydrogenCount( 0 );
}
if (hy==0) continue;
int ch = atom.getFormalCharge() == null ? 0 :
atom.getFormalCharge();
if (el.equals("C")) ch=-Math.abs(ch);
final int unpaired=0; // (not current available, maybe
introduce later)
hy+=ch-unpaired;
// (needs to include actual H's) for (int
i=0;i<bondAdj[n].length;i++) hy-=bondOrder[bondAdj[n][i]];
for (IBond bond : mol.getConnectedBondsList(atom))
{
if (bond.getOrder()==IBond.Order.SINGLE) hy-=1;
else if (bond.getOrder()==IBond.Order.DOUBLE) hy-=2;
else if (bond.getOrder()==IBond.Order.TRIPLE) hy-=3;
else if (bond.getOrder()==IBond.Order.QUADRUPLE) hy-=4;
// (look for zero-bonds later on)
}
// treat aromatics as an extra bond (one less hydrogen)
if( isAromatic(atom) )
hy--;
atom.setImplicitHydrogenCount( Math.max(0,hy) );
}
}
On 6 August 2015 at 19:29, John M <[email protected]> wrote:
>
> On 6 August 2015 at 17:36, Edmund Duesbury <[email protected]>
> wrote:
>
>> it's an iterator having an addition/removal somewhere
>
>
> Not a thread collision. Do you have your calculateImplicitHydrogens
> method. Also note implicit H on a query atom is currently superfluous
> unless you use it your self.
>
> Regards,
> John W May
> [email protected]
>
------------------------------------------------------------------------------
_______________________________________________
Cdk-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cdk-user