public BitSet getFingerprint(net.bioclipse.core.domain.IMolecule.Property urgency)
      throws BioclipseException {
    if (urgency == net.bioclipse.core.domain.IMolecule.Property.USE_CACHED) return fingerPrint;

    if (urgency == net.bioclipse.core.domain.IMolecule.Property.USE_CALCULATED) {
      Fingerprinter fp = new Fingerprinter();
      try {
        fingerPrint = fp.getFingerprint(getAtomContainer());
      } catch (Exception e) {
        throw new BioclipseException("Could not create fingerprint: " + e.getMessage());
      }
    }
    return fingerPrint;
  }
  public DBMolecule(String name, AtomContainer molecule) {
    super();
    this.setAtomContainer(molecule);
    this.name = name;

    Fingerprinter fingerprinter = new Fingerprinter();
    try {
      fingerPrint = fingerprinter.getFingerprint(molecule);
      persistedFingerPrint = makePersistedFingerPrint(fingerPrint);
    } catch (Exception e) {
      // If this happens often maybe something else is needed
      throw new IllegalArgumentException("could not create fingerPrint for Atomcontainer:" + name);
    }
    smiles = "";
    annotations = new ArrayList<Annotation>();
  }
Ejemplo n.º 3
0
  /**
   * Returns a similarity matrix based on the tanimoto distance of the fingerprints. (Upper
   * triangular matrix)
   *
   * @param molList the mol list
   * @param similarityThreshold the similarity threshold
   * @return the float[][]
   * @throws CDKException the CDK exception
   */
  private float[][] calculateSimilarity(boolean completeMatrix) throws CDKException {
    Map<String, BitSet> candidateToFingerprint = new HashMap<String, BitSet>();

    if (hasAtomContainer) {
      for (String strCandidate : candidateToStructure.keySet()) {
        Fingerprinter f = new Fingerprinter();
        BitSet fp = f.getFingerprint(candidateToStructure.get(strCandidate));
        candidateToFingerprint.put(strCandidate, fp);
      }
    } else {
      SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
      for (String string : candidatesToSmiles.keySet()) {
        try {
          IMolecule mol = sp.parseSmiles(candidatesToSmiles.get(string));
          Fingerprinter f = new Fingerprinter();
          BitSet fp = f.getFingerprint(mol);
          candidateToFingerprint.put(string, fp);
        } catch (Exception e) {
          System.err.println("Error in smiles!" + e.getMessage());
        }
      }
    }

    int countJ = 0;
    int countI = 0;

    if (!hasAtomContainer) {
      for (String candidate1 : candidatesToSmiles.keySet()) {
        //			System.out.print(candidate1 + " ");
        for (String candidate2 : candidatesToSmiles.keySet()) {
          if ((countJ < countI || candidate1.equals(candidate2)) && !completeMatrix) {
            //					System.out.print("x ");
            countJ++;
            continue;
          }
          float similarity =
              compareFingerprints(
                  candidateToFingerprint.get(candidate1), candidateToFingerprint.get(candidate2));
          matrix[countI][countJ] = similarity;
          // allSimilarityValues.append(similarity + "\n");

          countJ++;
          //				System.out.print(compareFingerprints(candidateToFingerprint.get(candidate1),
          // candidateToFingerprint.get(candidate2)) + " ");
        }
        countJ = 0;
        countI++;
        //			System.out.println("");
      }
    } else {
      for (String candidate1 : candidateToStructure.keySet()) {
        //			System.out.print(candidate1 + " ");
        for (String candidate2 : candidateToStructure.keySet()) {
          if ((countJ < countI || candidate1.equals(candidate2)) && !completeMatrix) {
            //					System.out.print("x ");
            countJ++;
            continue;
          }
          float similarity =
              compareFingerprints(
                  candidateToFingerprint.get(candidate1), candidateToFingerprint.get(candidate2));
          matrix[countI][countJ] = similarity;
          // allSimilarityValues.append(similarity + "\n");

          countJ++;
          //				System.out.print(compareFingerprints(candidateToFingerprint.get(candidate1),
          // candidateToFingerprint.get(candidate2)) + " ");
        }
        countJ = 0;
        countI++;
        //			System.out.println("");
      }
    }

    return matrix;
  }