Ejemplo n.º 1
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());
    }
  }
Ejemplo n.º 2
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;
  }
Ejemplo n.º 3
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);
  }
Ejemplo n.º 4
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));
  }
Ejemplo n.º 5
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);
  }
Ejemplo n.º 6
0
  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;
  }
Ejemplo n.º 7
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;
  }
Ejemplo n.º 8
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;
    }
  }
Ejemplo n.º 9
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);
  }