/** * Calculates the hydrogen count of a molecule. Includes hydrogenCount * attribute and does not double count bridging hydrogens. */ public int calculateHydrogenCount() { /* beware bridging hydrogens - simply returning the sum of the atom * hydrogen counts may not work! */ int totalImplicitHydrogenCount = 0; Set <CMLAtom> uniqueHydrogens = new HashSet<CMLAtom>(); for (CMLAtom atom : getAtoms()) { int hydrogenCount = atom.getHydrogenCount(); List <CMLAtom> explicitHydrogens = atom.getLigandHydrogenAtoms(); int implicitHydrogenCount = hydrogenCount - explicitHydrogens.size(); if (implicitHydrogenCount > 0) { totalImplicitHydrogenCount += implicitHydrogenCount; } uniqueHydrogens.addAll(explicitHydrogens); } return totalImplicitHydrogenCount + uniqueHydrogens.size(); }
if (CMLMolecule.HydrogenControl.USE_HYDROGEN_COUNT .equals(control)) { hCount += atom.getHydrogenCount() * occupancy;
int hydrogenCount = atom.getHydrogenCount(); if (hydrogenCount > 0) { this.add(AS.H.value, hydrogenCount);
/** * @cdk.bug 1748257 */ @Test public void testBug1748257() { MDMolecule mol = new MDMolecule(); mol.addAtom(new Atom("C")); // 0 mol.addAtom(new Atom("C")); // 1 mol.addAtom(new Atom("H")); // 2 mol.addAtom(new Atom("H")); // 3 mol.addAtom(new Atom("H")); // 4 mol.addAtom(new Atom("H")); // 5 mol.addBond(0, 1, IBond.Order.DOUBLE); // 1 mol.addBond(2, 0, IBond.Order.SINGLE); // 3 mol.addBond(3, 0, IBond.Order.SINGLE); // 4 mol.addBond(4, 1, IBond.Order.SINGLE); // 5 mol.addBond(5, 1, IBond.Order.SINGLE); // 6 Convertor convertor = new Convertor(false, ""); CMLAtom cmlatom = convertor.cdkAtomToCMLAtom(mol, mol.getAtom(2)); Assert.assertEquals(cmlatom.getHydrogenCount(), 0); }