FragmentComplexityDescriptor extends AbstractMolecularDescriptor implements IMolecularDescriptor { @Override public DescriptorValue calculate(IAtomContainer container) { int a = 0; double h = 0; for (int i = 0; i < container.getAtomCount(); i++) { if (container.getAtom(i).getAtomicNumber() != IElement.H) { a++; } if (container.getAtom(i).getAtomicNumber() != IElement.H && container.getAtom(i).getAtomicNumber() != IElement.C) { h++; } } int b = container.getBondCount() + AtomContainerManipulator.getImplicitHydrogenCount(container); double c = Math.abs(b * b - a * a + a) + (h / 100); return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new DoubleResult(c), getDescriptorNames()); } FragmentComplexityDescriptor(); @Override DescriptorSpecification getSpecification(); @Override void setParameters(Object[] params); @Override Object[] getParameters(); @Override String[] getDescriptorNames(); @Override DescriptorValue calculate(IAtomContainer container); @Override IDescriptorResult getDescriptorResultType(); @Override String[] getParameterNames(); @Override Object getParameterType(String name);  }
@Test public void test1FragmentComplexityDescriptor() throws Exception { IMolecularDescriptor descriptor = new FragmentComplexityDescriptor(); String filename = "data/mdl/murckoTest1.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MurckoFragmenter gf = new MurckoFragmenter(); double Complexity = 0; MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT); IAtomContainer mol = reader.read(new AtomContainer()); gf.generateFragments(mol); IAtomContainer[] setOfFragments = gf.getFrameworksAsContainers(); for (int i = 0; i < setOfFragments.length; i++) { addExplicitHydrogens(setOfFragments[i]); Complexity = ((DoubleResult) descriptor.calculate(setOfFragments[i]).getValue()).doubleValue(); } Assert.assertEquals(659.00, Complexity, 0.01); }
@Test public void test2FragmentComplexityDescriptor() throws Exception { IMolecularDescriptor descriptor = new FragmentComplexityDescriptor(); String filename = "data/mdl/murckoTest10.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MurckoFragmenter gf = new MurckoFragmenter(); double Complexity = 0; MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT); IAtomContainer mol = reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class)); gf.generateFragments(mol); IAtomContainer[] setOfFragments = gf.getFrameworksAsContainers(); for (IAtomContainer setOfFragment : setOfFragments) { addExplicitHydrogens(setOfFragment); Complexity = ((DoubleResult) descriptor.calculate(setOfFragment).getValue()).doubleValue(); } Assert.assertEquals(544.01, Complexity, 0.01); }