示例#1
0
 def testTanimotoSim(self):
     """ test Tanimoto Similarity measure
 """
     v1 = klass(10)
     v1[0] = 1
     v1[2] = 1
     v1[6] = 1
     v2 = klass(10)
     v2[0] = 1
     v2[3] = 1
     v2[6] = 1
     v3 = klass(10)
     v3[1] = 1
     v3[4] = 1
     v3[8] = 1
     assert feq(cDataStructs.TanimotoSimilarity(v1, v1),
                1.0), 'bad v1,v1 TanimotoSimilarity'
     assert feq(cDataStructs.TanimotoSimilarity(v2, v2),
                1.0), 'bad v2,v2 TanimotoSimilarity'
     assert feq(cDataStructs.TanimotoSimilarity(v1, v2),
                0.5), 'bad v1,v2 TanimotoSimilarity'
     assert feq(cDataStructs.TanimotoSimilarity(v2, v1),
                0.5), 'bad v2,v1 TanimotoSimilarity'
     assert feq(cDataStructs.TanimotoSimilarity(v1, v3),
                0.0), 'bad v1,v3 TanimotoSimilarity'
     assert feq(cDataStructs.TanimotoSimilarity(v2, v3),
                0.0), 'bad v2,v3 TanimotoSimilarity'
示例#2
0
    def testFingerprints(self):
        " test the parsing of daylight fingerprints "
        #actual daylight output:
        rawD = """
0,Cc1n[nH]c(=O)nc1N,.b+HHa.EgU6+ibEIr89.CpX0g8FZiXH+R0+Ps.mr6tg.2
1,Cc1n[nH]c(=O)[nH]c1=O,.b7HEa..ccc+gWEIr89.8lV8gOF3aXFFR.+Ps.mZ6lg.2
2,Cc1nnc(NN)nc1O,.H+nHq2EcY09y5EIr9e.8p50h0NgiWGNx4+Hm+Gbslw.2
3,Cc1nnc(N)nc1C,.1.HHa..cUI6i5E2rO8.Op10d0NoiWGVx.+Hm.Gb6lo.2
"""
        dists = """0,0,1.000000
0,1,0.788991
0,2,0.677165
0,3,0.686957
1,1,1.000000
1,2,0.578125
1,3,0.591304
2,2,1.000000
2,3,0.732759
3,3,1.000000
"""

        fps = []
        for line in rawD.split('\n'):
            if line:
                sbv = klass(256)
                id, smi, fp = line.split(',')
                cDataStructs.InitFromDaylightString(sbv, fp)
                fps.append(sbv)

        ds = dists.split('\n')
        whichd = 0
        for i in range(len(fps)):
            for j in range(i, len(fps)):
                idx1, idx2, tgt = ds[whichd].split(',')
                whichd += 1
                tgt = float(tgt)
                dist = cDataStructs.TanimotoSimilarity(fps[i], fps[j])
                assert feq(
                    tgt, dist
                ), 'tanimoto between fps %d and %d failed, %f != %f' % (
                    int(idx1), int(idx2), tgt, dist)
示例#3
0
 def similarity_topo(m):  # Topological Fingerprints
     fp1 = FingerprintMols.FingerprintMol(m[0])
     fp2 = FingerprintMols.FingerprintMol(m[1])
     return cDataStructs.TanimotoSimilarity(fp1, fp2)
示例#4
0
 def similarity_fcfp4(m):  # FCFP4 fingerprint
     fp1 = AllChem.GetMorganFingerprint(m[0], 2, useFeatures=True)
     fp2 = AllChem.GetMorganFingerprint(m[1], 2, useFeatures=True)
     return cDataStructs.TanimotoSimilarity(fp1, fp2)
示例#5
0
 def similarity_ecfp4(m):  # ECFP4 fingerprint
     fp1 = AllChem.GetMorganFingerprint(
         m[0], 2)  # 2 is the radius of the atom environments considered
     fp2 = AllChem.GetMorganFingerprint(m[1], 2)
     return cDataStructs.TanimotoSimilarity(fp1, fp2)
示例#6
0
 def similarity_maccs(m):  # compute similarity using MACCS fingerprint
     fp1 = MACCSkeys.GenMACCSKeys(m[0])
     fp2 = MACCSkeys.GenMACCSKeys(m[1])
     return cDataStructs.TanimotoSimilarity(fp1, fp2)