HBondAcceptorCountDescriptor extends AbstractMolecularDescriptor implements IMolecularDescriptor { @Override public DescriptorValue calculate(IAtomContainer atomContainer) { int hBondAcceptors = 0; IAtomContainer ac; try { ac = (IAtomContainer) atomContainer.clone(); } catch (CloneNotSupportedException e) { return getDummyDescriptorValue(e); } if (checkAromaticity) { try { AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(ac); Aromaticity.cdkLegacy().apply(ac); } catch (CDKException e) { return getDummyDescriptorValue(e); } } atomloop: for (IAtom atom : ac.atoms()) { if (atom.getAtomicNumber() == IElement.N && atom.getFormalCharge() <= 0) { List<IBond> bonds = ac.getConnectedBondsList(atom); int nPiBonds = 0; for (IBond bond : bonds) { if (bond.getOther(atom).getAtomicNumber() == IElement.O) continue atomloop; if (IBond.Order.DOUBLE.equals(bond.getOrder())) nPiBonds++; } if (atom.getFlag(CDKConstants.ISAROMATIC) && nPiBonds == 0) continue; hBondAcceptors++; } else if (atom.getAtomicNumber() == IElement.O && atom.getFormalCharge() <= 0) { List<IBond> neighbours = ac.getConnectedBondsList(atom); for (IBond bond : neighbours) { IAtom neighbor = bond.getOther(atom); if (neighbor.getAtomicNumber() == IElement.N || (neighbor.getAtomicNumber() == IElement.C && neighbor.isAromatic() && bond.getOrder() != IBond.Order.DOUBLE)) continue atomloop;; } hBondAcceptors++; } } return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new IntegerResult( hBondAcceptors), getDescriptorNames()); } HBondAcceptorCountDescriptor(); @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 exocyclicOxygenInAromaticRing() throws InvalidSmilesException { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer m = sp.parseSmiles("Cn1c2nc([nH]c2c(=O)n(c1=O)C)C1CCCC1"); HBondAcceptorCountDescriptor hbond_acceptor_desc = new HBondAcceptorCountDescriptor(); int actual = ((IntegerResult)hbond_acceptor_desc.calculate(m).getValue()).intValue(); org.hamcrest.MatcherAssert.assertThat(actual, CoreMatchers.is(3)); }