AutocorrelationDescriptorMass extends AbstractMolecularDescriptor implements IMolecularDescriptor { @Override public DescriptorValue calculate(IAtomContainer atomContainer) { IAtomContainer container; try { container = (IAtomContainer) atomContainer.clone(); container = AtomContainerManipulator.removeHydrogens(container); } catch (CloneNotSupportedException e) { DoubleArrayResult result = new DoubleArrayResult(5); for (int i = 0; i < 5; i++) result.add(Double.NaN); return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), result, getDescriptorNames(), new CDKException("Error during cloner: " + e.getMessage(), e)); } try { double[] w = listConvertion(container); int natom = container.getAtomCount(); int[][] distancematrix = TopologicalMatrix.getMatrix(container); double[] masSum = new double[5]; for (int k = 0; k < 5; k++) { for (int i = 0; i < natom; i++) { for (int j = 0; j < natom; j++) { if (distancematrix[i][j] == k) { masSum[k] += w[i] * w[j]; } else masSum[k] += 0.0; } } if (k > 0) masSum[k] = masSum[k] / 2; } DoubleArrayResult result = new DoubleArrayResult(5); for (double aMasSum : masSum) { result.add(aMasSum); } return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), result, getDescriptorNames()); } catch (IOException | ClassNotFoundException ex) { DoubleArrayResult result = new DoubleArrayResult(5); for (int i = 0; i < 5; i++) result.add(Double.NaN); return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), result, getDescriptorNames(), new CDKException("Error while calculating the ATS_mass descriptor: " + ex.getMessage(), ex)); } }  @Override DescriptorValue calculate(IAtomContainer atomContainer); @Override String[] getParameterNames(); @Override Object getParameterType(String name); @Override Object[] getParameters(); @Override String[] getDescriptorNames(); @Override DescriptorSpecification getSpecification(); @Override IDescriptorResult getDescriptorResultType(); @Override void setParameters(Object[] params);  }
@Test public void test1() throws Exception { String filename = "data/mdl/clorobenzene.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); IAtomContainer container = reader.read(new AtomContainer()); DescriptorValue count = new AutocorrelationDescriptorMass().calculate(container); Assert.assertEquals(5, count.getValue().length()); Assert.assertTrue(count.getValue() instanceof DoubleArrayResult); DoubleArrayResult result = (DoubleArrayResult) count.getValue(); for (int i = 0; i < 5; i++) { Assert.assertFalse(Double.isNaN(result.get(i))); Assert.assertTrue(0.0 != result.get(i)); } }