AromaticBondsCountDescriptor extends AbstractMolecularDescriptor implements IMolecularDescriptor { @Override public DescriptorValue calculate(IAtomContainer atomContainer) { IAtomContainer ac; try { ac = (IAtomContainer) atomContainer.clone(); } catch (CloneNotSupportedException e) { return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new IntegerResult( (int) Double.NaN), getDescriptorNames(), new CDKException("Error during clone")); } int aromaticBondsCount = 0; if (checkAromaticity) { try { AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(ac); } catch (CDKException e) { return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new IntegerResult( (int) Double.NaN), getDescriptorNames(), new CDKException("Error during atom type perception")); } try { Aromaticity.cdkLegacy().apply(ac); } catch (CDKException e) { return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new IntegerResult( (int) Double.NaN), getDescriptorNames(), new CDKException( "Error during aromaticity detection: " + e.getMessage())); } } Iterator bonds = ac.bonds().iterator(); while (bonds.hasNext()) { IBond bond = (IBond) bonds.next(); if (bond.getFlag(CDKConstants.ISAROMATIC)) { aromaticBondsCount += 1; } } return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new IntegerResult( aromaticBondsCount), getDescriptorNames()); } AromaticBondsCountDescriptor(); @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 testViaFlags() throws Exception { IAtomContainer molecule = TestMoleculeFactory.makeBenzene(); for (Iterator bonds = molecule.bonds().iterator(); bonds.hasNext();) { ((IBond) bonds.next()).setFlag(CDKConstants.ISAROMATIC, true); } Assert.assertEquals(6, ((IntegerResult) descriptor.calculate(molecule).getValue()).intValue()); }