FractionalPSADescriptor implements IMolecularDescriptor { @Override public DescriptorValue calculate(IAtomContainer mol) { try { mol = mol.clone(); } catch (CloneNotSupportedException ex) { } double polar = 0, weight = 0; try { IChemObjectBuilder builder = mol.getBuilder(); CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(builder); for (IAtom atom : mol.atoms()) { IAtomType type = matcher.findMatchingAtomType(mol, atom); AtomTypeManipulator.configure(atom, type); } CDKHydrogenAdder adder = CDKHydrogenAdder.getInstance(builder); adder.addImplicitHydrogens(mol); TPSADescriptor tpsa = new TPSADescriptor(); DescriptorValue value = tpsa.calculate(mol); polar = ((DoubleResult) value.getValue()).doubleValue(); for (IAtom atom : mol.atoms()) { weight += Isotopes.getInstance().getMajorIsotope(atom.getSymbol()).getExactMass(); Integer hcount = atom.getImplicitHydrogenCount(); if (hcount != CDKConstants.UNSET) weight += hcount * 1.00782504; } } catch (CDKException | IOException exception) { return getDummyDescriptorValue(exception); } return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new DoubleResult( weight == 0 ? 0 : polar / weight), getDescriptorNames()); } FractionalPSADescriptor(); @Override void initialise(IChemObjectBuilder builder); @Override DescriptorSpecification getSpecification(); @Override void setParameters(Object[] params); @Override Object[] getParameters(); @Override String[] getDescriptorNames(); @Override DescriptorValue calculate(IAtomContainer mol); @Override IDescriptorResult getDescriptorResultType(); @Override String[] getParameterNames(); @Override Object getParameterType(String name);  }
@Test public void testDescriptors() throws Exception { String fnmol = "data/cdd/pyridineacid.mol"; MDLV2000Reader mdl = new MDLV2000Reader(this.getClass().getClassLoader().getResourceAsStream(fnmol)); AtomContainer mol = new AtomContainer(); mdl.read(mol); mdl.close(); FractionalPSADescriptor fpsa = new FractionalPSADescriptor(); DescriptorValue results = fpsa.calculate(mol); String[] names = results.getNames(); if (names.length != 1 || !names[0].equals("tpsaEfficiency")) throw new CDKException("Only expecting 'tpsaEfficiency'"); DoubleResult value = (DoubleResult) results.getValue(); double tpsaEfficiency = value.doubleValue(); final double ANSWER = 0.4036, ANSWER_LO = ANSWER * 0.999, ANSWER_HI = ANSWER * 1.001; if (tpsaEfficiency < ANSWER_LO || tpsaEfficiency > ANSWER_HI) { throw new CDKException("Got " + tpsaEfficiency + ", expected " + ANSWER); } }