HBondDonorCountDescriptor extends AbstractMolecularDescriptor implements IMolecularDescriptor { @Override public DescriptorValue calculate(IAtomContainer atomContainer) { int hBondDonors = 0; IAtomContainer ac; try { ac = (IAtomContainer) atomContainer.clone(); } catch (CloneNotSupportedException e) { return getDummyDescriptorValue(e); } atomloop: for (int atomIndex = 0; atomIndex < ac.getAtomCount(); atomIndex++) { IAtom atom = (IAtom) ac.getAtom(atomIndex); if ((atom.getAtomicNumber() == IElement.O || atom.getAtomicNumber() == IElement.N) && atom.getFormalCharge() >= 0) { Integer implicitH = atom.getImplicitHydrogenCount(); if (implicitH == CDKConstants.UNSET) implicitH = 0; if (implicitH > 0) { hBondDonors++; continue atomloop; } java.util.List neighbours = ac.getConnectedAtomsList(atom); for (Object neighbour : neighbours) { if (((IAtom) neighbour).getAtomicNumber() == IElement.H) { hBondDonors++; continue atomloop; } } } } return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new IntegerResult( hBondDonors), getDescriptorNames()); } HBondDonorCountDescriptor(); @Override DescriptorSpecification getSpecification(); @Override void setParameters(Object[] params); @Override Object[] getParameters(); @Override String[] getDescriptorNames(); @Override DescriptorValue calculate(IAtomContainer atomContainer); @Override IDescriptorResult getDescriptorResultType(); @Override String[] getParameterNames(); @Override Object getParameterType(String name);  }
@Test public void testCID9257() { IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance(); IAtomContainer mol = builder.newInstance(IAtomContainer.class); IAtom a1 = builder.newInstance(IAtom.class, "N"); a1.setFormalCharge(0); a1.setPoint3d(new Point3d(0.5509, 0.9639, 0.0)); mol.addAtom(a1); IAtom a2 = builder.newInstance(IAtom.class, "N"); a2.setFormalCharge(0); a2.setPoint3d(new Point3d(1.1852, -0.2183, 1.0E-4)); mol.addAtom(a2); IAtom a3 = builder.newInstance(IAtom.class, "N"); a3.setFormalCharge(0); a3.setPoint3d(new Point3d(-1.087, -0.4827, 2.0E-4)); mol.addAtom(a3); IAtom a4 = builder.newInstance(IAtom.class, "C"); a4.setFormalCharge(0); a4.setPoint3d(new Point3d(-0.7991, 0.7981, -1.0E-4)); mol.addAtom(a4); IAtom a5 = builder.newInstance(IAtom.class, "C"); a5.setFormalCharge(0); a5.setPoint3d(new Point3d(0.15, -1.0609, -2.0E-4)); mol.addAtom(a5); IAtom a6 = builder.newInstance(IAtom.class, "H"); a6.setFormalCharge(0); a6.setPoint3d(new Point3d(1.094, 1.8191, 1.0E-4)); mol.addAtom(a6); IAtom a7 = builder.newInstance(IAtom.class, "H"); a7.setFormalCharge(0); a7.setPoint3d(new Point3d(-1.4981, 1.6215, -2.0E-4)); mol.addAtom(a7); IAtom a8 = builder.newInstance(IAtom.class, "H"); a8.setFormalCharge(0); a8.setPoint3d(new Point3d(0.3019, -2.13, -2.0E-4)); mol.addAtom(a8); IBond b1 = builder.newInstance(IBond.class, a1, a2, IBond.Order.SINGLE); mol.addBond(b1); IBond b2 = builder.newInstance(IBond.class, a1, a4, IBond.Order.SINGLE); mol.addBond(b2); IBond b3 = builder.newInstance(IBond.class, a1, a6, IBond.Order.SINGLE); mol.addBond(b3); IBond b4 = builder.newInstance(IBond.class, a2, a5, IBond.Order.DOUBLE); mol.addBond(b4); IBond b5 = builder.newInstance(IBond.class, a3, a4, IBond.Order.DOUBLE); mol.addBond(b5); IBond b6 = builder.newInstance(IBond.class, a3, a5, IBond.Order.SINGLE); mol.addBond(b6); IBond b7 = builder.newInstance(IBond.class, a4, a7, IBond.Order.SINGLE); mol.addBond(b7); IBond b8 = builder.newInstance(IBond.class, a5, a8, IBond.Order.SINGLE); mol.addBond(b8); Assert.assertEquals(1, ((IntegerResult) descriptor.calculate(mol).getValue()).intValue()); }