Exemple #1
0
  /**
   * If no isomorphism is found the result is empty vector
   *
   * @param container
   * @return
   */
  public List<List<IAtom>> getAllIsomorphismMappings(IAtomContainer container) {
    if (query == null) return null;
    target = container;
    FlagStoreIsomorphismNode = true;
    isomorphismNodes.clear();
    List<List<IAtom>> result = new ArrayList<List<IAtom>>();

    if (query.getAtomCount() == 1) {
      SMARTSAtom qa = (SMARTSAtom) query.getAtom(0);
      for (int i = 0; i < target.getAtomCount(); i++) {
        if (qa.matches(target.getAtom(i))) {
          List<IAtom> v = new ArrayList<IAtom>();
          v.add(target.getAtom(i));
          result.add(v);
        }
      }
      return result;
    }

    TopLayer.setAtomTopLayers(target, TopLayer.TLProp);
    executeSequence(false);

    if (isomorphismFound) {
      // Getting the data from the all stored Nodes
      for (int k = 0; k < isomorphismNodes.size(); k++) {
        Node node = isomorphismNodes.get(k);
        List<IAtom> v = new ArrayList<IAtom>();
        for (int i = 0; i < node.atoms.length; i++) v.add(node.atoms[i]);
        result.add(v);
      }
    }
    return result;
  }
Exemple #2
0
  /**
   * This function returns null if no isomorphism is found
   *
   * @param container
   * @return
   */
  public List<IAtom> getIsomorphismMapping(IAtomContainer container) {
    if (query == null) return null;
    target = container;
    FlagStoreIsomorphismNode = true;
    isomorphismNodes.clear();

    if (query.getAtomCount() == 1) {
      SMARTSAtom qa = (SMARTSAtom) query.getAtom(0);
      for (int i = 0; i < target.getAtomCount(); i++) {
        if (qa.matches(target.getAtom(i))) {
          List<IAtom> v = new ArrayList<IAtom>();
          v.add(target.getAtom(i));
          return (v);
        }
      }
      return null;
    }

    TopLayer.setAtomTopLayers(target, TopLayer.TLProp);
    executeSequence(true);

    if (isomorphismFound) {
      // Getting the data from the Node
      Node node = isomorphismNodes.get(0);
      List<IAtom> v = new ArrayList<IAtom>();
      for (int i = 0; i < node.atoms.length; i++) v.add(node.atoms[i]);

      return (v);
    } else return (null);
  }
Exemple #3
0
  public void printDebugInfo() {
    System.out.println("Query Atoms Topological Layers");
    for (int i = 0; i < query.getAtomCount(); i++)
      System.out.println("" + i + "  " + query.getAtom(i).getProperty(TopLayer.TLProp).toString());

    System.out.println();
    System.out.println("Query Sequence");
    for (int i = 0; i < sequence.size(); i++) System.out.println(sequence.get(i).toString(query));
  }
Exemple #4
0
  public List<IBond> generateBondMapping(IAtomContainer container, List<IAtom> atomMapping) {
    if (query == null) return null;

    List<IBond> v = new ArrayList<IBond>();
    for (int i = 0; i < query.getBondCount(); i++) {
      IAtom qa0 = query.getBond(i).getAtom(0);
      IAtom qa1 = query.getBond(i).getAtom(1);
      IAtom a0 = atomMapping.get(query.getAtomNumber(qa0));
      IAtom a1 = atomMapping.get(query.getAtomNumber(qa1));

      v.add(container.getBond(a0, a1));
    }

    return (v);
  }
Exemple #5
0
  void expandNode(Node node) {
    // System.out.println(node.toString(target));
    QuerySequenceElement el = sequence.get(node.sequenceElNum);

    if (el.center == null) // This node describers a bond that closes a ring
    {
      // Checking whether this bond is present in the target
      IAtom tAt0 = node.atoms[query.getAtomNumber(el.atoms[0])];
      IAtom tAt1 = node.atoms[query.getAtomNumber(el.atoms[1])];
      IBond tBo = target.getBond(tAt0, tAt1);
      if (tBo != null)
        if (el.bonds[0].matches(tBo)) {
          node.sequenceElNum++;
          // stack.push(node);
          if (node.sequenceElNum == sequence.size()) {
            // The node is not added in the stack if the end of the sequence is reached
            isomorphismFound = true;
            if (FlagStoreIsomorphismNode) isomorphismNodes.add(node);
          } else stack.push(node);
        }
    } else {
      targetAt.clear();
      IAtom tAt = node.atoms[el.centerNum];
      List<IAtom> conAt = target.getConnectedAtomsList(tAt);
      for (int i = 0; i < conAt.size(); i++) {
        if (!containsAtom(node.atoms, conAt.get(i))) targetAt.add(conAt.get(i));
      }

      if (el.atoms.length <= targetAt.size()) generateNodes(node);
    }
  }
Exemple #6
0
  void executeSequence(boolean stopAtFirstMapping) {
    isomorphismFound = false;
    stack.clear();

    // Initial nodes
    QuerySequenceElement el = sequence.get(0);
    for (int k = 0; k < target.getAtomCount(); k++) {
      IAtom at = target.getAtom(k);
      if (el.center.matches(at)) {
        Node node = new Node();
        node.sequenceElNum = 0;
        node.nullifyAtoms(query.getAtomCount());
        node.atoms[el.centerNum] = at;
        stack.push(node);
      }
    }

    // Expanding the tree of all possible mappings
    if (stopAtFirstMapping) {
      while (!stack.isEmpty()) {
        expandNode(stack.pop());
        if (isomorphismFound) break;
      }
    } else {
      while (!stack.isEmpty()) expandNode(stack.pop());
    }
  }
  private boolean checkQuery(IQueryAtomContainer query) {
    if (!(query instanceof PharmacophoreQuery)) return false;
    HashMap<String, String> map = new HashMap<String, String>();
    for (int i = 0; i < query.getAtomCount(); i++) {
      IQueryAtom atom = (IQueryAtom) query.getAtom(i);
      if (!(atom instanceof PharmacophoreQueryAtom)) return false;

      PharmacophoreQueryAtom pqatom = (PharmacophoreQueryAtom) atom;
      String label = pqatom.getSymbol();
      String smarts = pqatom.getSmarts();

      if (!map.containsKey(label)) map.put(label, smarts);
      else {
        if (!map.get(label).equals(smarts)) return false;
      }
    }
    return true;
  }
Exemple #8
0
  public boolean checkIsomorphismAtPosition(IAtomContainer container, int atomNum) {
    if ((atomNum < 0) || (atomNum >= container.getAtomCount())) return false;

    target = container;
    FlagStoreIsomorphismNode = false;
    isomorphismNodes.clear();

    if (query.getAtomCount() == 1) {
      SMARTSAtom qa = (SMARTSAtom) query.getAtom(0);
      return qa.matches(target.getAtom(atomNum));
    }

    TopLayer.setAtomTopLayers(target, TopLayer.TLProp);

    executeSequenceAtPos(atomNum);
    if (isomorphismFound) return true;

    return false;
  }
Exemple #9
0
 boolean singleAtomIsomorphism() {
   SMARTSAtom qa = (SMARTSAtom) query.getAtom(0);
   isomorphismFound = false;
   for (int i = 0; i < target.getAtomCount(); i++) {
     if (qa.matches(target.getAtom(i))) {
       isomorphismFound = true;
       break;
     }
   }
   return (isomorphismFound);
 }
Exemple #10
0
  public boolean hasIsomorphism(IAtomContainer container) {
    target = container;
    FlagStoreIsomorphismNode = false;
    isomorphismNodes.clear();

    if (query.getAtomCount() == 1) return (singleAtomIsomorphism());

    TopLayer.setAtomTopLayers(target, TopLayer.TLProp);
    executeSequence(true);
    return (isomorphismFound);
  }
Exemple #11
0
  public List<Integer> getIsomorphismPositions(IAtomContainer container) {
    target = container;
    FlagStoreIsomorphismNode = false;
    isomorphismNodes.clear();

    List<Integer> v = new ArrayList<Integer>();
    if (query.getAtomCount() == 1) {
      SMARTSAtom qa = (SMARTSAtom) query.getAtom(0);
      for (int i = 0; i < target.getAtomCount(); i++) {
        if (qa.matches(target.getAtom(i))) v.add(new Integer(i));
      }
      return (v);
    }

    TopLayer.setAtomTopLayers(target, TopLayer.TLProp);
    for (int i = 0; i < target.getAtomCount(); i++) {
      executeSequenceAtPos(i);
      if (isomorphismFound) v.add(new Integer(i));
    }
    return (v);
  }
Exemple #12
0
  void executeSequenceAtPos(int pos) {
    isomorphismFound = false;
    stack.clear();

    // Initial node
    QuerySequenceElement el = sequence.get(0);
    IAtom at = target.getAtom(pos);
    if (el.center.matches(at)) {
      Node node = new Node();
      node.sequenceElNum = 0;
      node.nullifyAtoms(query.getAtomCount());
      node.atoms[el.centerNum] = at;
      stack.push(node);
    }

    // Expanding the tree of all possible mappings
    while (!stack.isEmpty()) {
      expandNode(stack.pop());
      if (isomorphismFound) break;
    }
  }
 private boolean hasAngleConstraints(IQueryAtomContainer query) {
   for (IBond bond : query.bonds()) {
     if (bond instanceof PharmacophoreQueryAngleBond) return true;
   }
   return false;
 }
Exemple #14
0
  void setQueryAtomSequence(IQueryAtom firstAt) {
    IQueryAtom firstAtom;
    QuerySequenceElement seqEl;
    TopLayer topLayer;
    // List<IQueryAtom> curAddedAtoms = new List<IQueryAtom>();
    int n;

    if (firstAt == null) firstAtom = (IQueryAtom) query.getFirstAtom();
    else firstAtom = firstAt;
    sequence.clear();
    sequencedAtoms.clear();
    sequencedBondAt1.clear();
    sequencedBondAt2.clear();

    // Set first sequence atom
    sequencedAtoms.add(firstAtom);
    seqEl = new QuerySequenceElement();
    seqEl.center = firstAtom;
    topLayer = (TopLayer) firstAtom.getProperty(TopLayer.TLProp);
    n = topLayer.atoms.size();
    seqEl.atoms = new IQueryAtom[n];
    seqEl.bonds = new IQueryBond[n];
    for (int i = 0; i < n; i++) {
      sequencedAtoms.add((IQueryAtom) topLayer.atoms.get(i));
      seqEl.atoms[i] = (IQueryAtom) topLayer.atoms.get(i);
      seqEl.bonds[i] = (IQueryBond) topLayer.bonds.get(i);
      addSeqBond(seqEl.center, seqEl.atoms[i]);
    }
    sequence.add(seqEl);

    // Sequencing the entire query structure
    Stack<QuerySequenceElement> stack = new Stack<QuerySequenceElement>();
    stack.push(seqEl);
    while (!stack.empty()) {
      // curAddedAtoms.clear();
      QuerySequenceElement curSeqAt = stack.pop();
      for (int i = 0; i < curSeqAt.atoms.length; i++) {
        topLayer = (TopLayer) curSeqAt.atoms[i].getProperty(TopLayer.TLProp);
        if (topLayer.atoms.size() == 1)
          continue; // it is terminal atom and no further sequencing should be done
        int a[] = getSeqAtomsInLayer(topLayer);

        n = 0;
        for (int k = 0; k < a.length; k++) if (a[k] == 0) n++;

        if (n > 0) {
          seqEl = new QuerySequenceElement();
          seqEl.center = curSeqAt.atoms[i];
          seqEl.atoms = new IQueryAtom[n];
          seqEl.bonds = new IQueryBond[n];
          sequence.add(seqEl);
          stack.add(seqEl);
        }

        int j = 0;
        for (int k = 0; k < a.length; k++) {
          if (a[k] == 0) {
            seqEl.atoms[j] = (IQueryAtom) topLayer.atoms.get(k);
            seqEl.bonds[j] = (IQueryBond) topLayer.bonds.get(k);
            addSeqBond(seqEl.center, seqEl.atoms[j]);
            sequencedAtoms.add(seqEl.atoms[j]);
            // curAddedAtoms.add(seqEl.atoms[j]);
            j++;
          } else {
            if (curSeqAt.center == topLayer.atoms.get(k)) continue;
            // Check whether  bond(curSeqAt.atoms[i]-topLayer.atoms.get(k))
            // is already sequenced
            if (getSeqBond(curSeqAt.atoms[i], topLayer.atoms.get(k)) != -1) continue;
            // topLayer.atoms.get(k) atom is already sequenced.
            // Therefore sequnce element of 'bond' type is registered.
            // newSeqEl is not added in the stack (this is not needed for this bond)
            QuerySequenceElement newSeqEl = new QuerySequenceElement();
            newSeqEl.center = null;
            newSeqEl.atoms = new IQueryAtom[2];
            newSeqEl.bonds = new IQueryBond[1];
            newSeqEl.atoms[0] = curSeqAt.atoms[i];
            newSeqEl.atoms[1] = (IQueryAtom) topLayer.atoms.get(k);
            addSeqBond(newSeqEl.atoms[0], newSeqEl.atoms[1]);
            newSeqEl.bonds[0] = (IQueryBond) topLayer.bonds.get(k);
            sequence.add(newSeqEl);
          }
        }
      }
    }

    for (int i = 0; i < sequence.size(); i++) sequence.get(i).setAtomNums(query);
  }