/** * gets count of hydrogens. Explicit hydrogen count overrides value of HydrogenCount * attribute if it is greater. * @return hydrogenCount(); */ public int getHydrogenCount() { int hcAttributeValue = 0; if (super.getHydrogenCountAttribute() != null) { hcAttributeValue = super.getHydrogenCount(); } int hcExplicit = getLigandHydrogenAtoms().size(); return Math.max(hcAttributeValue, hcExplicit); }
/** * 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 atom has one or more hydrogen atoms deletes one. * mainly for managing count for aromatics. * @return atom deleted or null */ public CMLAtom deleteAnyLigandHydrogenAtom() { CMLAtom ligand = null; List<CMLAtom> hydrogens = getLigandHydrogenAtoms(); if (hydrogens.size() > 0) { CMLMolecule molecule = this.getMolecule(); ligand = hydrogens.get(0); CMLBond bond = molecule.getBond(this, ligand); molecule.deleteBond(bond); molecule.deleteAtom(ligand); } return ligand; }