ZagrebIndexDescriptor extends AbstractMolecularDescriptor implements IMolecularDescriptor { @Override public DescriptorValue calculate(IAtomContainer atomContainer) { double zagreb = 0; for (IAtom atom : atomContainer.atoms()) { if (atom.getAtomicNumber() == IElement.H) continue; int atomDegree = 0; List<IAtom> neighbours = atomContainer.getConnectedAtomsList(atom); for (IAtom neighbour : neighbours) { if (neighbour.getAtomicNumber() != IElement.H) { atomDegree += 1; } } zagreb += (atomDegree * atomDegree); } return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new DoubleResult(zagreb), getDescriptorNames()); } ZagrebIndexDescriptor(); @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 test2Dvs3D() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol = sp.parseSmiles("O1C2C34C(C(C1O)CCCc1cc(cc(c1)C(F)(F)F)C(F)(F)F)CCC(C3CCC(O2)(OO4)C)C"); addExplicitHydrogens(mol); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); double value2D = ((DoubleResult) descriptor.calculate(mol).getValue()).doubleValue(); String filename = "data/mdl/cpsa-uncharged.sdf"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); ISimpleChemObjectReader reader = new MDLV2000Reader(ins); ChemFile content = (ChemFile) reader.read((ChemObject) new ChemFile()); List cList = ChemFileManipulator.getAllAtomContainers(content); mol = (IAtomContainer) cList.get(0); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); double value3D = ((DoubleResult) descriptor.calculate(mol).getValue()).doubleValue(); Assert.assertEquals(value2D, value3D, 0.001); }