Esempio n. 1
0
  /**
   * This function calculates all the possible combinations of MCS
   *
   * @param molecule1
   * @param molecule2
   * @param shouldMatchBonds
   * @param shouldMatchRings
   * @param matchAtomType
   * @return
   * @throws CDKException
   */
  public synchronized List<Map<Integer, Integer>> calculateOverlapsAndReduce(
      IAtomContainer molecule1,
      IAtomContainer molecule2,
      boolean shouldMatchBonds,
      boolean shouldMatchRings,
      boolean matchAtomType)
      throws CDKException {
    setSource(molecule1);
    setTarget(molecule2);
    List<Map<Integer, Integer>> solution = new ArrayList<>();
    setMappings(solution);

    if ((getSource().getAtomCount() == 1) || (getTarget().getAtomCount() == 1)) {
      List<CDKRMap> overlaps = CDKMCS.checkSingleAtomCases(getSource(), getTarget());
      this.setTimeout(CDKMCS.isTimeout());
      int nAtomsMatched = overlaps.size();
      nAtomsMatched = (nAtomsMatched > 0) ? 1 : 0;
      if (nAtomsMatched > 0) {
        /*UnComment this to get one Unique Mapping*/
        // List reducedList = removeRedundantMappingsForSingleAtomCase(overlaps);
        // int counter = 0;
        identifySingleAtomsMatchedParts(overlaps, getSource(), getTarget());
      }

    } else {
      List<List<CDKRMap>> overlaps =
          CDKMCS.search(
              getSource(),
              getTarget(),
              new BitSet(),
              new BitSet(),
              true,
              true,
              shouldMatchBonds,
              shouldMatchRings,
              matchAtomType);
      this.setTimeout(CDKMCS.isTimeout());
      List<List<CDKRMap>> reducedList = removeSubGraph(overlaps);
      Stack<List<CDKRMap>> allMaxOverlaps = getAllMaximum(reducedList);
      while (!allMaxOverlaps.empty()) {
        //                System.out.println("source: " + source.getAtomCount() + ", target: " +
        // target.getAtomCount() + ", overl: " + allMaxOverlaps.peek().size());
        List<List<CDKRMap>> maxOverlapsAtoms =
            makeAtomsMapOfBondsMap(allMaxOverlaps.peek(), getSource(), getTarget());
        //                System.out.println("size of maxOverlaps: " + maxOverlapsAtoms.size());
        identifyMatchedParts(maxOverlapsAtoms, getSource(), getTarget());
        //                identifyMatchedParts(allMaxOverlaps.peek(), source, target);
        allMaxOverlaps.pop();
      }
    }
    return solution;
  }
Esempio n. 2
0
  /**
   * This function calculates only one solution (exact) because we are looking at the molecules
   * which are exactly same in terms of the bonds and atoms determined by the Fingerprint
   *
   * @param Molecule1
   * @param Molecule2
   * @param shouldMatchBonds
   * @param shouldMatchRings
   * @param matchAtomType
   * @throws CDKException
   */
  public synchronized void calculateOverlapsAndReduceExactMatch(
      IAtomContainer Molecule1,
      IAtomContainer Molecule2,
      boolean shouldMatchBonds,
      boolean shouldMatchRings,
      boolean matchAtomType)
      throws CDKException {

    setSource(Molecule1);
    setTarget(Molecule2);

    setMappings(new ArrayList<Map<Integer, Integer>>());

    // System.out.println("Searching: ");
    // List overlaps = UniversalIsomorphismTesterBondTypeInSensitive.getSubgraphAtomsMap(source,
    // target);
    if ((getSource().getAtomCount() == 1) || (getTarget().getAtomCount() == 1)) {

      List<CDKRMap> overlaps = CDKMCS.checkSingleAtomCases(getSource(), getTarget());
      this.setTimeout(CDKMCS.isTimeout());
      int nAtomsMatched = overlaps.size();
      nAtomsMatched = (nAtomsMatched > 0) ? 1 : 0;
      if (nAtomsMatched > 0) {
        identifySingleAtomsMatchedParts(overlaps, getSource(), getTarget());
      }

    } else {

      List<List<CDKRMap>> overlaps =
          CDKMCS.search(
              getSource(),
              getTarget(),
              new BitSet(),
              new BitSet(),
              true,
              true,
              shouldMatchBonds,
              shouldMatchRings,
              matchAtomType);
      this.setTimeout(CDKMCS.isTimeout());
      List<List<CDKRMap>> reducedList = removeSubGraph(overlaps);
      Stack<List<CDKRMap>> allMaxOverlaps = getAllMaximum(reducedList);

      while (!allMaxOverlaps.empty()) {
        List<List<CDKRMap>> maxOverlapsAtoms =
            makeAtomsMapOfBondsMap(allMaxOverlaps.peek(), getSource(), getTarget());
        identifyMatchedParts(maxOverlapsAtoms, getSource(), getTarget());
        allMaxOverlaps.pop();
      }
    }
  }