WienerNumbersDescriptor extends AbstractMolecularDescriptor implements IMolecularDescriptor { @Override public DescriptorValue calculate(IAtomContainer atomContainer) { wienerNumbers = new DoubleArrayResult(2); double wienerPathNumber = 0; double wienerPolarityNumber = 0; matr = ConnectionMatrix.getMatrix(AtomContainerManipulator.removeHydrogens(atomContainer)); int[][] distances = PathTools.computeFloydAPSP(matr); int partial; for (int i = 0; i < distances.length; i++) { for (int j = 0; j < distances.length; j++) { partial = distances[i][j]; wienerPathNumber += partial; if (partial == 3) { wienerPolarityNumber += 1; } } } wienerPathNumber = wienerPathNumber / 2; wienerPolarityNumber = wienerPolarityNumber / 2; wienerNumbers.add(wienerPathNumber); wienerNumbers.add(wienerPolarityNumber); return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), wienerNumbers, getDescriptorNames()); } WienerNumbersDescriptor(); @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 testWithExplicitHydrogens() throws Exception { double[] testResult = {18, 2}; SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol = sp.parseSmiles("[H]C([H])([H])C([H])([H])C(=O)O"); DoubleArrayResult retval = (DoubleArrayResult) descriptor.calculate(mol).getValue(); Assert.assertEquals(testResult[0], retval.get(0), 0.0001); Assert.assertEquals(testResult[1], retval.get(1), 0.0001); }
@Test public void testOriginalWienerPaperCompounds() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); double[] testResult = {10, 20, 35, 56, 84, 120, 165, 220, 286}; String smiles = "CCC"; for (int i = 0; i < testResult.length; i++) { smiles += "C"; IAtomContainer mol = sp.parseSmiles(smiles); DoubleArrayResult retval = (DoubleArrayResult) descriptor.calculate(mol).getValue(); Assert.assertEquals(testResult[i], retval.get(0), 0.0001); } }