PetitjeanShapeIndexDescriptor extends AbstractMolecularDescriptor implements IMolecularDescriptor { @Override public DescriptorValue calculate(IAtomContainer container) { IAtomContainer local = AtomContainerManipulator.removeHydrogens(container); int tradius = PathTools.getMolecularGraphRadius(local); int tdiameter = PathTools.getMolecularGraphDiameter(local); DoubleArrayResult retval = new DoubleArrayResult(); retval.add((double) (tdiameter - tradius) / (double) tradius); if (GeometryUtil.has3DCoordinates(container)) { int natom = container.getAtomCount(); double[][] distanceMatrix = new double[natom][natom]; for (int i = 0; i < natom; i++) { for (int j = 0; j < natom; j++) { if (i == j) { distanceMatrix[i][j] = 0.0; continue; } Point3d a = container.getAtom(i).getPoint3d(); Point3d b = container.getAtom(j).getPoint3d(); distanceMatrix[i][j] = Math.sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z)); } } double gradius = 999999; double gdiameter = -999999; double[] geta = new double[natom]; for (int i = 0; i < natom; i++) { double max = -99999; for (int j = 0; j < natom; j++) { if (distanceMatrix[i][j] > max) max = distanceMatrix[i][j]; } geta[i] = max; } for (int i = 0; i < natom; i++) { if (geta[i] < gradius) gradius = geta[i]; if (geta[i] > gdiameter) gdiameter = geta[i]; } retval.add((gdiameter - gradius) / gradius); } else { retval.add(Double.NaN); } return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), retval, getDescriptorNames()); } PetitjeanShapeIndexDescriptor(); @Override DescriptorSpecification getSpecification(); @Override void setParameters(Object[] params); @Override Object[] getParameters(); @Override String[] getDescriptorNames(); @Override String[] getParameterNames(); @Override Object getParameterType(String name); @Override DescriptorValue calculate(IAtomContainer container); @Override IDescriptorResult getDescriptorResultType();  }
@Test public void testPetiteJeanShapeNo3D() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer atomContainer = sp.parseSmiles("CCCOCCC(O)=O"); DescriptorValue result = descriptor.calculate(atomContainer); DoubleArrayResult dar = (DoubleArrayResult) result.getValue(); Assert.assertTrue(Double.isNaN(dar.get(1))); }