rdkit.DataStructs

Package rdkit :: Package DataStructs |
[hide private]
[frames] | no frames]

# Source Code for Package rdkit.DataStructs

     1  # $Id$
     2  #
     3  #  Copyright (C) 2004-2006  Rational Discovery LLC
     4  #
     5  #   @@ All Rights Reserved @@
     6  #  This file is part of the RDKit.
     7  #  The contents are covered by the terms of the BSD license
     8  #  which is included in the file license.txt, found at the root
     9  #  of the RDKit source tree.
    10  #
    11  from __future__ import division
    12  from rdkit import rdBase
    13  from rdkit.DataStructs import cDataStructs
    14  from rdkit.DataStructs.cDataStructs import *
    15
    16  __doc__ = cDataStructs.__doc__
    17
    18  similarityFunctions = [
    19    ('Tanimoto', TanimotoSimilarity, ''),
    20    ("Dice", DiceSimilarity, ''),
    21    ("Cosine", CosineSimilarity, ''),
    22    ("Sokal", SokalSimilarity, ''),
    23    ("Russel", RusselSimilarity, ''),
    24    ("RogotGoldberg", RogotGoldbergSimilarity, ''),
    25    ("AllBit", AllBitSimilarity, ''),
    26    ("Kulczynski", KulczynskiSimilarity, ''),
    27    ("McConnaughey", McConnaugheySimilarity, ''),
    28    ("Asymmetric", AsymmetricSimilarity, ''),
    29    ("BraunBlanquet", BraunBlanquetSimilarity, ''),
    30  ]
    31
    32
    33 -def FingerprintSimilarity(fp1, fp2, metric=TanimotoSimilarity):
    34    """ returns the calculated similarity between two fingerprints,
    35      handles any folding that may need to be done to ensure that they
    36      are compatible
    37
    38    """
    39    sz1 = fp1.GetNumBits()
    40    sz2 = fp2.GetNumBits()
    41    if sz1 < sz2:
    42      fp2 = FoldFingerprint(fp2, sz2 // sz1)
    43    elif sz2 < sz1:
    44      fp1 = FoldFingerprint(fp1, sz1 // sz2)
    45    return metric(fp1, fp2)
    46
    47
    48 -def FoldToTargetDensity(fp, density=0.3, minLength=64):
    49    while fp.GetNumOnBits() / len(fp) > density and len(fp) // 2 > minLength:
    50      fp = FoldFingerprint(fp, 2)
    51    return fp
    52
    53
    54  ExplicitBitVect.ToBitString = BitVectToText
    55  SparseBitVect.ToBitString = BitVectToText
    56