test_class.file: descriptor/qsarmolecular/src/test/java/org/openscience/cdk/qsar/descriptors/molecular/GravitationalIndexDescriptorTest.java
test_class.identifier: GravitationalIndexDescriptorTest
test_class.superclass: extends MolecularDescriptorTest
test_case.body: @Test
      public void testGravitationalIndex() throws ClassNotFoundException, CDKException, java.lang.Exception {
          String filename = "data/hin/gravindex.hin";
          InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
          ISimpleChemObjectReader reader = new HINReader(ins);
          ChemFile content = (ChemFile) reader.read((ChemObject) new ChemFile());
          List cList = ChemFileManipulator.getAllAtomContainers(content);
          IAtomContainer ac = (IAtomContainer) cList.get(0);
  
          DoubleArrayResult retval = (DoubleArrayResult) descriptor.calculate(ac).getValue();
  
          Assert.assertEquals(1756.5060703860984, retval.get(0), 0.00000001);
          Assert.assertEquals(41.91069159994975, retval.get(1), 0.00000001);
          Assert.assertEquals(12.06562671430088, retval.get(2), 0.00000001);
          Assert.assertEquals(1976.6432599699767, retval.get(3), 0.00000001);
          Assert.assertEquals(44.45945636161082, retval.get(4), 0.00000001);
          Assert.assertEquals(12.549972243701887, retval.get(5), 0.00000001);
          Assert.assertEquals(4333.097373073368, retval.get(6), 0.00000001);
          Assert.assertEquals(65.82626658920714, retval.get(7), 0.00000001);
          Assert.assertEquals(16.302948232909483, retval.get(8), 0.00000001);
      }
test_case.class_method_signature: GravitationalIndexDescriptorTest.testGravitationalIndex()
test_case.full_signature: @Test public void testGravitationalIndex()
test_case.identifier: testGravitationalIndex
test_case.invocations: getResourceAsStream getClassLoader getClass read getAllAtomContainers get getValue calculate assertEquals get assertEquals get assertEquals get assertEquals get assertEquals get assertEquals get assertEquals get assertEquals get assertEquals get
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testGravitationalIndex()
focal_class.declarator: logger = LoggingToolFactory.createLoggingTool(GravitationalIndexDescriptor.class)
focal_class.modifier: private static
focal_class.original_string: private static ILoggingTool logger = LoggingToolFactory.createLoggingTool(GravitationalIndexDescriptor.class);
focal_class.type: ILoggingTool
focal_class.var_name: logger
focal_class.declarator: NAMES = {"GRAV-1", "GRAV-2", "GRAV-3", "GRAVH-1", "GRAVH-2", "GRAVH-3", "GRAV-4",
              "GRAV-5", "GRAV-6"          }
focal_class.modifier: private static final
focal_class.original_string: private static final String[] NAMES = {"GRAV-1", "GRAV-2", "GRAV-3", "GRAVH-1", "GRAVH-2", "GRAVH-3", "GRAV-4",
              "GRAV-5", "GRAV-6"          };
focal_class.type: String[]
focal_class.var_name: NAMES
focal_class.file: descriptor/qsarmolecular/src/main/java/org/openscience/cdk/qsar/descriptors/molecular/GravitationalIndexDescriptor.java
focal_class.identifier: GravitationalIndexDescriptor
focal_class.interfaces: implements IMolecularDescriptor
focal_class.class_method_signature: GravitationalIndexDescriptor.GravitationalIndexDescriptor()
focal_class.full_signature: public  GravitationalIndexDescriptor()
focal_class.identifier: GravitationalIndexDescriptor
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.signature:  GravitationalIndexDescriptor()
focal_class.class_method_signature: GravitationalIndexDescriptor.getSpecification()
focal_class.full_signature: @Override public DescriptorSpecification getSpecification()
focal_class.identifier: getSpecification
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: DescriptorSpecification
focal_class.signature: DescriptorSpecification getSpecification()
focal_class.class_method_signature: GravitationalIndexDescriptor.setParameters(Object[] params)
focal_class.full_signature: @Override public void setParameters(Object[] params)
focal_class.identifier: setParameters
focal_class.modifiers: @Override public
focal_class.parameters: (Object[] params)
focal_class.return: void
focal_class.signature: void setParameters(Object[] params)
focal_class.class_method_signature: GravitationalIndexDescriptor.getParameters()
focal_class.full_signature: @Override public Object[] getParameters()
focal_class.identifier: getParameters
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: Object[]
focal_class.signature: Object[] getParameters()
focal_class.class_method_signature: GravitationalIndexDescriptor.getDescriptorNames()
focal_class.full_signature: @Override public String[] getDescriptorNames()
focal_class.identifier: getDescriptorNames
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: String[]
focal_class.signature: String[] getDescriptorNames()
focal_class.class_method_signature: GravitationalIndexDescriptor.getParameterNames()
focal_class.full_signature: @Override public String[] getParameterNames()
focal_class.identifier: getParameterNames
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: String[]
focal_class.signature: String[] getParameterNames()
focal_class.class_method_signature: GravitationalIndexDescriptor.getParameterType(String name)
focal_class.full_signature: @Override public Object getParameterType(String name)
focal_class.identifier: getParameterType
focal_class.modifiers: @Override public
focal_class.parameters: (String name)
focal_class.return: Object
focal_class.signature: Object getParameterType(String name)
focal_class.class_method_signature: GravitationalIndexDescriptor.getDummyDescriptorValue(Exception e)
focal_class.full_signature: private DescriptorValue getDummyDescriptorValue(Exception e)
focal_class.identifier: getDummyDescriptorValue
focal_class.modifiers: private
focal_class.parameters: (Exception e)
focal_class.return: DescriptorValue
focal_class.signature: DescriptorValue getDummyDescriptorValue(Exception e)
focal_class.class_method_signature: GravitationalIndexDescriptor.calculate(IAtomContainer container)
focal_class.full_signature: @Override public DescriptorValue calculate(IAtomContainer container)
focal_class.identifier: calculate
focal_class.modifiers: @Override public
focal_class.parameters: (IAtomContainer container)
focal_class.return: DescriptorValue
focal_class.signature: DescriptorValue calculate(IAtomContainer container)
focal_class.class_method_signature: GravitationalIndexDescriptor.getDescriptorResultType()
focal_class.full_signature: @Override public IDescriptorResult getDescriptorResultType()
focal_class.identifier: getDescriptorResultType
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: IDescriptorResult
focal_class.signature: IDescriptorResult getDescriptorResultType()
focal_class.superclass: extends AbstractMolecularDescriptor
focal_method.body: @Override
      public DescriptorValue calculate(IAtomContainer container) {
          if (!GeometryUtil.has3DCoordinates(container))
              return getDummyDescriptorValue(new CDKException("Molecule must have 3D coordinates"));
  
          IsotopeFactory factory = null;
          double mass1;
          double mass2;
          try {
              factory = Isotopes.getInstance();
          } catch (Exception e) {
              logger.debug(e);
          }
  
          double sum = 0;
          for (int i = 0; i < container.getBondCount(); i++) {
              IBond bond = container.getBond(i);
  
              if (bond.getAtomCount() != 2) {
                  return getDummyDescriptorValue(new CDKException("GravitationalIndex: Only handles 2 center bonds"));
              }
  
              mass1 = factory.getMajorIsotope(bond.getBegin().getSymbol()).getMassNumber();
              mass2 = factory.getMajorIsotope(bond.getEnd().getSymbol()).getMassNumber();
  
              Point3d p1 = bond.getBegin().getPoint3d();
              Point3d p2 = bond.getEnd().getPoint3d();
  
              double x1 = p1.x;
              double y1 = p1.y;
              double z1 = p1.z;
              double x2 = p2.x;
              double y2 = p2.y;
              double z2 = p2.z;
  
              double dist = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2);
              sum += (mass1 * mass2) / dist;
          }
  
          // heavy atoms only
          double heavysum = 0;
          for (int i = 0; i < container.getBondCount(); i++) {
              IBond b = container.getBond(i);
  
              if (b.getAtomCount() != 2) {
                  return getDummyDescriptorValue(new CDKException("GravitationalIndex: Only handles 2 center bonds"));
              }
  
              if (b.getBegin().getAtomicNumber() == IElement.H || b.getEnd().getAtomicNumber() == IElement.H) continue;
  
              mass1 = factory.getMajorIsotope(b.getBegin().getSymbol()).getMassNumber();
              mass2 = factory.getMajorIsotope(b.getEnd().getSymbol()).getMassNumber();
  
              Point3d point0 = b.getBegin().getPoint3d();
              Point3d point1 = b.getEnd().getPoint3d();
  
              double x1 = point0.x;
              double y1 = point0.y;
              double z1 = point0.z;
              double x2 = point1.x;
              double y2 = point1.y;
              double z2 = point1.z;
  
              double dist = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2);
              heavysum += (mass1 * mass2) / dist;
          }
  
          // all pairs
          ArrayList<Integer> x = new ArrayList<Integer>();
          for (int i = 0; i < container.getAtomCount(); i++) {
              if (container.getAtom(i).getAtomicNumber() != IElement.H) x.add(i);
          }
          int npair = x.size() * (x.size() - 1) / 2;
          pair[] p = new pair[npair];
          for (int i = 0; i < npair; i++)
              p[i] = new pair();
          int pcount = 0;
          for (int i = 0; i < x.size() - 1; i++) {
              for (int j = i + 1; j < x.size(); j++) {
                  int present = 0;
                  int a = x.get(i);
                  int b = x.get(j);
                  for (int k = 0; k < pcount; k++) {
                      if ((p[k].x == a && p[k].y == b) || (p[k].y == a && p[k].x == b)) present = 1;
                  }
                  if (present == 1) continue;
                  p[pcount].x = a;
                  p[pcount].y = b;
                  pcount += 1;
              }
          }
          double allheavysum = 0;
          for (pair aP : p) {
              int atomNumber1 = aP.x;
              int atomNumber2 = aP.y;
  
              mass1 = factory.getMajorIsotope(container.getAtom(atomNumber1).getSymbol()).getMassNumber();
              mass2 = factory.getMajorIsotope(container.getAtom(atomNumber2).getSymbol()).getMassNumber();
  
              double x1 = container.getAtom(atomNumber1).getPoint3d().x;
              double y1 = container.getAtom(atomNumber1).getPoint3d().y;
              double z1 = container.getAtom(atomNumber1).getPoint3d().z;
              double x2 = container.getAtom(atomNumber2).getPoint3d().x;
              double y2 = container.getAtom(atomNumber2).getPoint3d().y;
              double z2 = container.getAtom(atomNumber2).getPoint3d().z;
  
              double dist = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2);
              allheavysum += (mass1 * mass2) / dist;
          }
  
          DoubleArrayResult retval = new DoubleArrayResult(9);
          retval.add(heavysum);
          retval.add(Math.sqrt(heavysum));
          retval.add(Math.pow(heavysum, 1.0 / 3.0));
  
          retval.add(sum);
          retval.add(Math.sqrt(sum));
          retval.add(Math.pow(sum, 1.0 / 3.0));
  
          retval.add(allheavysum);
          retval.add(Math.sqrt(allheavysum));
          retval.add(Math.pow(allheavysum, 1.0 / 3.0));
  
          return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), retval,
                  getDescriptorNames());
      }
focal_method.class_method_signature: GravitationalIndexDescriptor.calculate(IAtomContainer container)
focal_method.full_signature: @Override public DescriptorValue calculate(IAtomContainer container)
focal_method.identifier: calculate
focal_method.invocations: has3DCoordinates getDummyDescriptorValue getInstance debug getBondCount getBond getAtomCount getDummyDescriptorValue getMassNumber getMajorIsotope getSymbol getBegin getMassNumber getMajorIsotope getSymbol getEnd getPoint3d getBegin getPoint3d getEnd getBondCount getBond getAtomCount getDummyDescriptorValue getAtomicNumber getBegin getAtomicNumber getEnd getMassNumber getMajorIsotope getSymbol getBegin getMassNumber getMajorIsotope getSymbol getEnd getPoint3d getBegin getPoint3d getEnd getAtomCount getAtomicNumber getAtom add size size size size get get getMassNumber getMajorIsotope getSymbol getAtom getMassNumber getMajorIsotope getSymbol getAtom getPoint3d getAtom getPoint3d getAtom getPoint3d getAtom getPoint3d getAtom getPoint3d getAtom getPoint3d getAtom add add sqrt add pow add add sqrt add pow add add sqrt add pow getSpecification getParameterNames getParameters getDescriptorNames
focal_method.modifiers: @Override public
focal_method.parameters: (IAtomContainer container)
focal_method.return: DescriptorValue
focal_method.signature: DescriptorValue calculate(IAtomContainer container)