/**
   * Calculates the eccentric connectivity
   *
   * @param container Parameter is the atom container.
   * @return An IntegerResult value representing the eccentric connectivity index
   */
  @TestMethod("testCalculate_IAtomContainer")
  public DescriptorValue calculate(IAtomContainer container) {
    IAtomContainer local = AtomContainerManipulator.removeHydrogens(container);

    int natom = local.getAtomCount();
    int[][] admat = AdjacencyMatrix.getMatrix(local);
    int[][] distmat = PathTools.computeFloydAPSP(admat);

    int eccenindex = 0;
    for (int i = 0; i < natom; i++) {
      int max = -1;
      for (int j = 0; j < natom; j++) {
        if (distmat[i][j] > max) max = distmat[i][j];
      }
      int degree = local.getConnectedBondsCount(i);
      eccenindex += max * degree;
    }
    IntegerResult retval = new IntegerResult(eccenindex);
    return new DescriptorValue(
        getSpecification(),
        getParameterNames(),
        getParameters(),
        retval,
        getDescriptorNames(),
        null);
  }
Esempio n. 2
0
 /**
  * Performs a breadthFirstSearch in an AtomContainer starting with a particular sphere, which
  * usually consists of one start atom, and searches for a pi system.
  *
  * @param container The AtomContainer to be searched
  * @param sphere A sphere of atoms to start the search with
  * @param path A ArrayList which stores the atoms belonging to the pi system
  * @throws org.openscience.cdk.exception.CDKException Description of the Exception
  */
 private void breadthFirstSearch(IAtomContainer container, List<IAtom> sphere, List<IAtom> path)
     throws CDKException {
   IAtom atom;
   IAtom nextAtom;
   List<IAtom> newSphere = new ArrayList<IAtom>();
   // logger.debug("Start of breadthFirstSearch");
   for (int i = 0; i < sphere.size(); i++) {
     atom = sphere.get(i);
     // logger.debug("BreadthFirstSearch around atom " + (atomNr + 1));
     List<IBond> bonds = container.getConnectedBondsList(atom);
     for (IBond bond : bonds) {
       nextAtom = bond.getConnectedAtom(atom);
       if ((!nextAtom.getFlag(CDKConstants.ISAROMATIC) && !nextAtom.getFlag(CDKConstants.ISINRING))
           & !nextAtom.getFlag(CDKConstants.VISITED)) {
         // logger.debug("BDS> AtomNr:"+container.getAtomNumber(nextAtom)+"
         // maxBondOrder:"+container.getMaximumBondOrder(nextAtom)+"
         // Aromatic:"+nextAtom.getFlag(CDKConstants.ISAROMATIC)+"
         // FormalCharge:"+nextAtom.getFormalCharge()+" Charge:"+nextAtom.getCharge()+"
         // Flag:"+nextAtom.getFlag(CDKConstants.VISITED));
         path.add(nextAtom);
         // logger.debug("BreadthFirstSearch is meeting new atom " + (nextAtomNr + 1));
         nextAtom.setFlag(CDKConstants.VISITED, true);
         if (container.getConnectedBondsCount(nextAtom) > 1) {
           newSphere.add(nextAtom);
         }
       } else {
         nextAtom.setFlag(CDKConstants.VISITED, true);
       }
     }
   }
   if (newSphere.size() > 0) {
     breadthFirstSearch(container, newSphere, path);
   }
 }
Esempio n. 3
0
 private boolean isChemicallyValid(IAtomContainer union) throws CDKException {
   for (IAtom atom : union.atoms()) {
     if ((union.getConnectedBondsCount(atom) + atom.getFormalCharge())
         > atom.getFormalNeighbourCount()) {
       return false;
     }
   }
   return true;
 }
Esempio n. 4
0
  /**
   * Finds the Smallest Set of Smallest Rings.
   *
   * @param mol the molecule to be searched for rings
   * @return a RingSet containing the rings in molecule
   */
  public IRingSet findSSSR(IAtomContainer mol) {
    IBond brokenBond = null;
    IChemObjectBuilder builder = mol.getBuilder();
    IRingSet sssr = builder.newInstance(IRingSet.class);
    IAtomContainer molecule = builder.newInstance(IAtomContainer.class);
    molecule.add(mol);
    IAtom smallest;
    int smallestDegree, nodesToBreakCounter, degree;
    IAtom[] rememberNodes;
    IRing ring;

    // Two Vectors - as defined in the article. One to hold the
    // full set of atoms in the structure and on to store the numbers
    // of the nodes that have been trimmed away.
    // Furhter there is a Vector nodesN2 to store the number of N2 nodes
    List<IAtom> fullSet = new ArrayList<IAtom>();
    List<IAtom> trimSet = new ArrayList<IAtom>();
    List<IAtom> nodesN2 = new ArrayList<IAtom>();

    initPath(molecule);
    logger.debug("molecule.getAtomCount(): " + molecule.getAtomCount());
    // load fullSet with the numbers of our atoms
    for (int f = 0; f < molecule.getAtomCount(); f++) {
      fullSet.add(molecule.getAtom(f));
    }
    logger.debug("fullSet.size(): " + fullSet.size());

    do {
      // Add nodes of degree zero to trimset.
      // Also add nodes of degree 2 to nodesN2.
      // In the same run, check, which node has the lowest degree
      // greater than zero.
      smallestDegree = 7;
      smallest = null;
      nodesN2.clear();
      for (int f = 0; f < molecule.getAtomCount(); f++) {
        IAtom atom = molecule.getAtom(f);
        degree = molecule.getConnectedBondsCount(atom);
        if (degree == 0) {
          if (!trimSet.contains(atom)) {
            logger.debug("Atom of degree 0");
            trimSet.add(atom);
          }
        }
        if (degree == 2) {
          nodesN2.add(atom);
        }
        if (degree < smallestDegree && degree > 0) {
          smallest = atom;
          smallestDegree = degree;
        }
      }
      if (smallest == null) break;

      // If there are nodes of degree 1, trim them away
      if (smallestDegree == 1) {
        trimCounter++;
        trim(smallest, molecule);
        trimSet.add(smallest);
      }

      // if there are nodes of degree 2, find out of which rings
      // they are part of.
      else if (smallestDegree == 2) {
        rememberNodes = new IAtom[nodesN2.size()];
        nodesToBreakCounter = 0;
        for (int f = 0; f < nodesN2.size(); f++) {
          ring = getRing((IAtom) nodesN2.get(f), molecule);
          if (ring != null) {
            // check, if this ring already is in SSSR
            if (!RingSetManipulator.ringAlreadyInSet(ring, sssr)) {
              sssr.addAtomContainer(ring);
              rememberNodes[nodesToBreakCounter] = (IAtom) nodesN2.get(f);
              nodesToBreakCounter++;
            }
          }
        }
        if (nodesToBreakCounter == 0) {
          nodesToBreakCounter = 1;
          rememberNodes[0] = (IAtom) nodesN2.get(0);
        }
        for (int f = 0; f < nodesToBreakCounter; f++) {
          breakBond(rememberNodes[f], molecule);
        }
        if (brokenBond != null) {
          molecule.addBond(brokenBond);
          brokenBond = null;
        }
      }
      // if there are nodes of degree 3
      else if (smallestDegree == 3) {
        ring = getRing(smallest, molecule);
        if (ring != null) {

          // check, if this ring already is in SSSR
          if (!RingSetManipulator.ringAlreadyInSet(ring, sssr)) {
            sssr.addAtomContainer(ring);
          }
          brokenBond = checkEdges(ring, molecule);
          molecule.removeElectronContainer(brokenBond);
        }
      }
    } while (trimSet.size() < fullSet.size());
    logger.debug("fullSet.size(): " + fullSet.size());
    logger.debug("trimSet.size(): " + trimSet.size());
    logger.debug("trimCounter: " + trimCounter);
    //		molecule.setProperty(CDKConstants.SMALLEST_RINGS, sssr);
    return sssr;
  }