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  __doc__=cDataStructs.__doc__
    15  from rdkit.DataStructs.cDataStructs import *
    16
    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 -def FingerprintSimilarity(fp1,fp2,metric=TanimotoSimilarity):
    33    """ returns the calculated similarity between two fingerprints,
    34      handles any folding that may need to be done to ensure that they
    35      are compatible
    36
    37    """
    38    sz1 = fp1.GetNumBits()
    39    sz2 = fp2.GetNumBits()
    40    if sz1<sz2:
    41      fp2 = FoldFingerprint(fp2,sz2//sz1)
    42    elif sz2<sz1:
    43      fp1 = FoldFingerprint(fp1,sz1//sz2)
    44    return metric(fp1,fp2)
    45
    46 -def FoldToTargetDensity(fp,density=0.3,minLength=64):
    47    while fp.GetNumOnBits()/len(fp)>density and len(fp)//2>minLength:
    48      fp = FoldFingerprint(fp,2)
    49    return fp
    50
    51  ExplicitBitVect.ToBitString = BitVectToText
    52  SparseBitVect.ToBitString = BitVectToText
    53