DataStructs

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

# Source Code for Package DataStructs

     1  # $Id: __init__.py 746 2008-07-07 13:21:24Z glandrum $
     2  #
     3  #  Copyright (C) 2004-2006  Rational Discovery LLC
     4  #
     5  #   @@ All Rights Reserved  @@
     6  #
     7  import rdBase
     8  import cDataStructs
     9  __doc__=cDataStructs.__doc__
    10  from cDataStructs import *
    11
    12
    13  similarityFunctions=[
    14    ('Tanimoto',TanimotoSimilarity,''),
    15    ("Dice",DiceSimilarity,''),
    16    ("Cosine",CosineSimilarity,''),
    17    ("Sokal",SokalSimilarity,''),
    18    ("Russel",RusselSimilarity,''),
    19    ("Kulczynski",KulczynskiSimilarity,''),
    20    ("McConnaughey",McConnaugheySimilarity,''),
    21    ("Asymmetric",AsymmetricSimilarity,''),
    22    ("BraunBlanquet",BraunBlanquetSimilarity,''),
    23    ]
    24
    25 -def FingerprintSimilarity(fp1,fp2,metric=TanimotoSimilarity):
    26    """ returns the calculated similarity between two fingerprints,
    27      handles any folding that may need to be done to ensure that they
    28      are compatible
    29
    30    """
    31    sz1 = fp1.GetNumBits()
    32    sz2 = fp2.GetNumBits()
    33    if sz1<sz2:
    34      fp2 = FoldFingerprint(fp2,sz2/sz1)
    35    elif sz2<sz1:
    36      fp1 = FoldFingerprint(fp1,sz1/sz2)
    37    return metric(fp1,fp2)
    38
    39 -def FoldToTargetDensity(fp,density=0.3,minLength=64):
    40    while float(fp.GetNumOnBits())/len(fp)>density and len(fp)/2>minLength:
    41      fp = FoldFingerprint(fp,2)
    42    return fp
    43
    44  ExplicitBitVect.ToBitString = BitVectToText
    45  SparseBitVect.ToBitString = BitVectToText
    46