Exemplo n.º 1
0
def get_atom_pair_similarity(correct_ligand,
                             mol_to_fix,
                             type_fp='normal',
                             use_features=False):
    type_fp = type_fp

    correct_ligand_fingerprint = SimilarityMaps.GetAPFingerprint(
        correct_ligand,
        nBits=4096,
        fpType=type_fp,
    )
    mol_to_fix_fingerprint = SimilarityMaps.GetAPFingerprint(
        mol_to_fix,
        nBits=4096,
        fpType=type_fp,
    )

    test = 1

    sim_func = DataStructs.FingerprintSimilarity

    temp_autoinducer_TanimotoSimilarty = sim_func(
        correct_ligand_fingerprint,
        mol_to_fix_fingerprint,
        metric=DataStructs.TanimotoSimilarity)

    test = 1

    curr_metric = DataStructs.TanimotoSimilarity
    fig, maxweight = SimilarityMaps.GetSimilarityMapForFingerprint(
        correct_ligand,
        mol_to_fix,
        lambda m, idx: SimilarityMaps.GetAPFingerprint(
            m, atomId=idx, fpType='normal'),
        metric=curr_metric)
    # print(maxweight)
    # fig.suptitle('test title', fontsize=20)
    ax = fig.gca()
    # ax.title
    plt.title('test', fontsize=30)
    fig.set_size_inches(7, 7)
    fig.set_dpi(600)
    fig.savefig('test_ap.png', bbox_inches='tight')

    test = 1
Exemplo n.º 2
0
  def testSimilarityMap(self):
    # Morgan2 BV
    refWeights = [0.5, 0.5, 0.5, -0.5, 0.5, 0.5]
    weights = sm.GetAtomicWeightsForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetMorganFingerprint(m, i, radius=2, fpType='bv'))
    for w,r in zip(weights, refWeights): self.assertEqual(w, r)

    fig, maxWeight = sm.GetSimilarityMapForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetMorganFingerprint(m, i, radius=2, fpType='bv'))
    self.assertEqual(maxWeight, 0.5)
    
    weights, maxWeight = sm.GetStandardizedWeights(weights)
    self.assertEqual(maxWeight, 0.5)
    refWeights = [1.0, 1.0, 1.0, -1.0, 1.0, 1.0]
    for w,r in zip(weights, refWeights): self.assertEqual(w, r)

    weights = sm.GetAtomicWeightsForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetMorganFingerprint(m, i, fpType='count'))
    self.assertTrue(weights[3] < 0)
    weights = sm.GetAtomicWeightsForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetMorganFingerprint(m, i, fpType='bv', useFeatures=True))
    self.assertTrue(weights[3] < 0)

    # hashed AP BV
    refWeights = [0.09523, 0.17366, 0.17366, -0.23809, 0.17366, 0.17366]
    weights = sm.GetAtomicWeightsForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetAPFingerprint(m, i, fpType='bv', nBits=1024))
    for w,r in zip(weights, refWeights): self.assertAlmostEqual(w, r, 4)

    weights = sm.GetAtomicWeightsForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetAPFingerprint(m, i, fpType='normal'))
    self.assertTrue(weights[3] < 0)
    weights = sm.GetAtomicWeightsForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetAPFingerprint(m, i, fpType='hashed'))
    self.assertTrue(weights[3] < 0)
    
    # hashed TT BV
    refWeights = [0.5, 0.5, -0.16666, -0.5, -0.16666, 0.5]
    weights = sm.GetAtomicWeightsForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetTTFingerprint(m, i, fpType='bv', nBits=1024, nBitsPerEntry=1))
    for w,r in zip(weights, refWeights): self.assertAlmostEqual(w, r, 4)

    weights = sm.GetAtomicWeightsForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetTTFingerprint(m, i, fpType='normal'))
    self.assertTrue(weights[3] < 0)
    weights = sm.GetAtomicWeightsForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetTTFingerprint(m, i, fpType='hashed'))
    self.assertTrue(weights[3] < 0)

    # RDK fingerprint BV
    refWeights = [0.42105, 0.42105, 0.42105, -0.32895, 0.42105, 0.42105]
    weights = sm.GetAtomicWeightsForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetRDKFingerprint(m, i, nBits=1024, nBitsPerHash=1))
    for w,r in zip(weights, refWeights): self.assertAlmostEqual(w, r, 4)
Exemplo n.º 3
0
    def testSimilarityMapKWArgs(self):
        # Morgan2 BV
        m1 = Chem.MolFromSmiles('CC[C@](F)(Cl)c1ccccc1')
        m2 = Chem.MolFromSmiles('CC[C@@](F)(Cl)c1ccccc1')
        weights = sm.GetAtomicWeightsForFingerprint(
            m1, m2, lambda m, i: sm.GetAPFingerprint(
                m, atomId=i, includeChirality=False))
        for w in weights:
            self.assertAlmostEqual(w, 0.100, 4)
        weights = sm.GetAtomicWeightsForFingerprint(
            m1, m2, lambda m, i: sm.GetAPFingerprint(
                m, atomId=i, includeChirality=True))
        for i, w in enumerate(weights):
            if i != 2:
                self.assertAlmostEqual(w, 0.098, 3)
            else:
                self.assertAlmostEqual(w, -0.082, 3)

        weights = sm.GetAtomicWeightsForFingerprint(
            m1, m2, lambda m, i: sm.GetTTFingerprint(
                m, atomId=i, includeChirality=False))
        for w in weights:
            self.assertTrue(w > 0.0)
        weights = sm.GetAtomicWeightsForFingerprint(
            m1, m2, lambda m, i: sm.GetTTFingerprint(
                m, atomId=i, includeChirality=True))
        for i, w in enumerate(weights):
            if i > 4:
                self.assertTrue(w > 0.0)
            else:
                self.assertTrue(w < 0.0)

        weights = sm.GetAtomicWeightsForFingerprint(
            m1, m2, lambda m, i: sm.GetMorganFingerprint(
                m, radius=1, atomId=i, useChirality=False))
        weights2 = sm.GetAtomicWeightsForFingerprint(
            m1, m2, lambda m, i: sm.GetMorganFingerprint(
                m, radius=1, atomId=i, useChirality=True))
        # testing explicit values here seems silly, just check that the contribution of the
        # chiral center drops:
        self.assertTrue(weights[2] > weights2[2])
def draw_finger_print(smile_file):
    with open(smile_file, 'r') as f:
        for mol in f:
            refmol = Chem.MolFromSmiles(
                'CCCN(CCCCN1CCN(c2ccccc2OC)CC1)Cc1ccc2ccccc2c1'
            )  # this is the template here

            ms = Chem.MolFromSmiles(mol)
            fp = SimilarityMaps.GetAPFingerprint(ms, fpType='normal')
            fp = SimilarityMaps.GetTTFingerprint(ms, fpType='normal')
            fp = SimilarityMaps.GetMorganFingerprint(ms, fpType='bv')

            fig, maxweight = SimilarityMaps.GetSimilarityMapForFingerprint(
                refmol, ms, SimilarityMaps.GetMorganFingerprint)
            fig.save('/home/nad/Desktop/navid22.png')
Exemplo n.º 5
0
def fp_maps(results, query, fingerprint, fpradius, nbits, features, metric,
            out_file, multfile):
    if fingerprint == "ecfp" or fingerprint == "fcfp":
        fp_func = lambda m, idx: SimilarityMaps.GetMorganFingerprint(
            m,
            atomId=idx,
            radius=fpradius,
            fpType='bv',
            nBits=nbits,
            useFeatures=features)
    elif fingerprint == "rdkit":
        fp_func = lambda m, idx: SimilarityMaps.GetRDKFingerprint(
            m, atomId=idx, fpType="bv", nBits=nbits)
    elif fingerprint == "ap":
        fp_func = lambda m, idx: SimilarityMaps.GetAPFingerprint(
            m, atomId=idx, fpType="bv", nBits=nbits)
    else:
        fp_func = lambda m, idx: SimilarityMaps.GetTTFingerprint(
            m, atomId=idx, fpType="bv", nBits=nbits)
    if multfile:
        sim_map_mf(results, query, fp_func, metric, out_file)
    else:
        sim_map(results, query, fp_func, metric, out_file)
Exemplo n.º 6
0
def getAtomPair(mol, nBits=1024):
    return SimilarityMaps.GetAPFingerprint(mol, fpType='bv', nBits=nBits)