AromaticAtomsCountDescriptor 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 aromaticAtomsCount = 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())); } } for (int i = 0; i < ac.getAtomCount(); i++) { if (ac.getAtom(i).getFlag(CDKConstants.ISAROMATIC)) { aromaticAtomsCount += 1; } } return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new IntegerResult( aromaticAtomsCount), getDescriptorNames()); } AromaticAtomsCountDescriptor(); @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 atoms = molecule.atoms().iterator(); atoms.hasNext();) { ((IAtom) atoms.next()).setFlag(CDKConstants.ISAROMATIC, true); } Assert.assertEquals(6, ((IntegerResult) descriptor.calculate(molecule).getValue()).intValue()); }