Пример #1
0
 private boolean isRingSizeMatch(IAtom atom) {
   List<Integer> ringsizesQ = qAtom.getProperty(CDKConstants.RING_SIZES);
   List<Integer> ringsizesT = atom.getProperty(CDKConstants.RING_SIZES);
   if (ringsizesQ != null && ringsizesT != null) {
     for (int i : ringsizesQ) {
       if (ringsizesT.contains(i)) {
         return true;
       }
     }
   }
   return false;
 }
Пример #2
0
  private IRenderingElement generate(IAtomContainer molecule, RendererModel model, int atomNum)
      throws CDKException {

    // tag the atom and bond ids
    String molId = molecule.getProperty(MarkedElement.ID_KEY);
    if (molId != null) {
      int atomId = 0, bondid = 0;
      for (IAtom atom : molecule.atoms())
        setIfMissing(atom, MarkedElement.ID_KEY, molId + "atm" + ++atomId);
      for (IBond bond : molecule.bonds())
        setIfMissing(bond, MarkedElement.ID_KEY, molId + "bnd" + ++bondid);
    }

    if (annotateAtomNum) {
      for (IAtom atom : molecule.atoms()) {
        if (atom.getProperty(StandardGenerator.ANNOTATION_LABEL) != null)
          throw new UnsupportedOperationException("Multiple annotation labels are not supported.");
        atom.setProperty(StandardGenerator.ANNOTATION_LABEL, Integer.toString(atomNum++));
      }
    } else if (annotateAtomVal) {
      for (IAtom atom : molecule.atoms()) {
        if (atom.getProperty(StandardGenerator.ANNOTATION_LABEL) != null)
          throw new UnsupportedOperationException("Multiple annotation labels are not supported.");
        atom.setProperty(
            StandardGenerator.ANNOTATION_LABEL, atom.getProperty(CDKConstants.COMMENT));
      }
    } else if (annotateAtomMap) {
      for (IAtom atom : molecule.atoms()) {
        if (atom.getProperty(StandardGenerator.ANNOTATION_LABEL) != null)
          throw new UnsupportedOperationException("Multiple annotation labels are not supported.");
        int mapidx = accessAtomMap(atom);
        if (mapidx > 0) {
          atom.setProperty(StandardGenerator.ANNOTATION_LABEL, Integer.toString(mapidx));
        }
      }
    }

    ElementGroup grp = new ElementGroup();
    for (IGenerator<IAtomContainer> gen : gens) grp.add(gen.generate(molecule, model));

    // cleanup
    if (annotateAtomNum || annotateAtomMap) {
      for (IAtom atom : molecule.atoms()) {
        atom.removeProperty(StandardGenerator.ANNOTATION_LABEL);
      }
    }

    return grp;
  }
  /**
   * The method returns partial charges assigned to an heavy atom through MMFF94 method. It is
   * needed to call the addExplicitHydrogensToSatisfyValency method from the class
   * tools.HydrogenAdder.
   *
   * @param atom The IAtom for which the DescriptorValue is requested
   * @param org AtomContainer
   * @return partial charge of parameter atom
   */
  @Override
  public DescriptorValue calculate(IAtom atom, IAtomContainer org) {

    if (atom.getProperty(CHARGE_CACHE) == null) {

      IAtomContainer copy;
      try {
        copy = org.clone();
      } catch (CloneNotSupportedException e) {
        return new DescriptorValue(
            getSpecification(),
            getParameterNames(),
            getParameters(),
            new DoubleResult(Double.NaN),
            NAMES);
      }

      for (IAtom a : org.atoms()) {
        if (a.getImplicitHydrogenCount() == null || a.getImplicitHydrogenCount() != 0) {
          logger.error("Hydrogens must be explict for MMFF charge calculation");
          return new DescriptorValue(
              getSpecification(),
              getParameterNames(),
              getParameters(),
              new DoubleResult(Double.NaN),
              NAMES);
        }
      }

      if (!mmff.assignAtomTypes(copy))
        logger.warn("One or more atoms could not be assigned an MMFF atom type");
      mmff.partialCharges(copy);
      mmff.clearProps(copy);

      // cache charges
      for (int i = 0; i < org.getAtomCount(); i++) {
        org.getAtom(i).setProperty(CHARGE_CACHE, copy.getAtom(i).getCharge());
      }
    }

    return new DescriptorValue(
        getSpecification(),
        getParameterNames(),
        getParameters(),
        new DoubleResult(atom.getProperty(CHARGE_CACHE, Double.class)),
        NAMES);
  }
Пример #4
0
 private static int getLonePairCount(IAtom atom) {
   Integer count = (Integer) atom.getProperty(CDKConstants.LONE_PAIR_COUNT);
   if (count == null) {
     return 0;
   } else {
     return count;
   }
 }
Пример #5
0
 @Test
 public void matches() throws Exception {
   ExplicitConnectionAtom matcher = new ExplicitConnectionAtom(2, mock(IChemObjectBuilder.class));
   IAtom atom = mock(IAtom.class);
   when(atom.getProperty(SMARTSAtomInvariants.KEY))
       .thenReturn(
           new SMARTSAtomInvariants(
               mock(IAtomContainer.class),
               0,
               0,
               Collections.<Integer>emptySet(),
               0,
               0, // <- degree not used due to old CDK bug
               2,
               0));
   assertTrue(matcher.matches(atom));
 }
Пример #6
0
 /**
  * This routine is called 'getRing() in Figueras original article finds the smallest ring of which
  * rootNode is part of.
  *
  * @param rootNode The Atom to be searched for the smallest ring it is part of
  * @param molecule The molecule that contains the rootNode
  * @return The smallest Ring rootnode is part of
  */
 private IRing getRing(IAtom rootNode, IAtomContainer molecule) {
   IAtom node, neighbor, mAtom;
   List neighbors, mAtoms;
   /** OKatoms is Figueras nomenclature, giving the number of atoms in the structure */
   int OKatoms = molecule.getAtomCount();
   /** queue for Breadth First Search of this graph */
   Queue queue = new Queue();
   /* Initialize a path Vector for each node */
   // Vector pfad1,pfad2;
   List<List<IAtom>> path = new ArrayList<List<IAtom>>(OKatoms);
   List<IAtom> intersection = new ArrayList<IAtom>();
   List<IAtom> ring = new ArrayList<IAtom>();
   for (int f = 0; f < OKatoms; f++) {
     path.set(f, new ArrayList<IAtom>());
     ((List<IAtom>) molecule.getAtom(f).getProperty(PATH)).clear();
   }
   // Initialize the queue with nodes attached to rootNode
   neighbors = molecule.getConnectedAtomsList(rootNode);
   for (int f = 0; f < neighbors.size(); f++) {
     // if the degree of the f-st neighbor of rootNode is greater
     // than zero (i.e., it has not yet been deleted from the list)
     neighbor = (IAtom) neighbors.get(f);
     // push the f-st node onto our FIFO queue
     // after assigning rootNode as its source
     queue.push(neighbor);
     ((List<IAtom>) neighbor.getProperty(PATH)).add(rootNode);
     ((List<IAtom>) neighbor.getProperty(PATH)).add(neighbor);
   }
   while (queue.size() > 0) {
     node = (IAtom) queue.pop();
     mAtoms = molecule.getConnectedAtomsList(node);
     for (int f = 0; f < mAtoms.size(); f++) {
       mAtom = (IAtom) mAtoms.get(f);
       if (mAtom
           != ((List) node.getProperty(PATH))
               .get(((List<IAtom>) node.getProperty(PATH)).size() - 2)) {
         if (((List) mAtom.getProperty(PATH)).size() > 0) {
           intersection =
               getIntersection((List) node.getProperty(PATH), (List) mAtom.getProperty(PATH));
           if (intersection.size() == 1) {
             // we have found a valid ring closure
             // now let's prepare the path to
             // return in tempAtomSet
             logger.debug("path1  ", ((List) node.getProperty(PATH)));
             logger.debug("path2  ", ((List) mAtom.getProperty(PATH)));
             logger.debug("rootNode  ", rootNode);
             logger.debug("ring   ", ring);
             ring = getUnion((List) node.getProperty(PATH), (List) mAtom.getProperty(PATH));
             return prepareRing(ring, molecule);
           }
         } else {
           // if path[mNumber] is null
           // update the path[mNumber]
           // pfad2 = (Vector)node.getProperty(PATH);
           mAtom.setProperty(PATH, new ArrayList<IAtom>((List<IAtom>) node.getProperty(PATH)));
           ((List<IAtom>) mAtom.getProperty(PATH)).add(mAtom);
           // pfad1 = (Vector)mAtom.getProperty(PATH);
           // now push the node m onto the queue
           queue.push(mAtom);
         }
       }
     }
   }
   return null;
 }
Пример #7
0
 private Integer accessAtomMap(IAtom atom) {
   Integer mapidx = atom.getProperty(CDKConstants.ATOM_ATOM_MAPPING, Integer.class);
   if (mapidx == null) return 0;
   return mapidx;
 }