Exemple #1
0
    def test5errorHandling(self):
        refPts = (
            Geometry.Point3D(0.0, 0.0, 0.0),
            Geometry.Point3D(1.0, 0.0, 0.0),
            Geometry.Point3D(0.0, 1.0, 0.0),
            Geometry.Point3D(0.0, 0.0, 1.0),
        )
        prbPts = (
            1,
            2,
            3,
            4,
        )
        self.assertRaises(ValueError,
                          lambda: rdAlg.GetAlignmentTransform(refPts, prbPts))
        prbPts = ()
        self.assertRaises(ValueError,
                          lambda: rdAlg.GetAlignmentTransform(refPts, prbPts))

        prbPts = 1
        self.assertRaises(ValueError,
                          lambda: rdAlg.GetAlignmentTransform(refPts, prbPts))

        prbPts = (
            Geometry.Point3D(2.0, 2.0, 3.0),
            Geometry.Point3D(3.0, 2.0, 3.0),
            Geometry.Point3D(2.0, 3.0, 3.0),
            (2.0, 2.0, 5.0),
        )
        self.assertRaises(ValueError,
                          lambda: rdAlg.GetAlignmentTransform(refPts, prbPts))
Exemple #2
0
    def test2Weights(self):
        refPts = np.array(
            [[-math.cos(math.pi / 6), -math.sin(math.pi / 6), 0.0],
             [math.cos(math.pi / 6), -math.sin(math.pi / 6), 0.0],
             [0.0, 1.0, 0.0]], np.float)
        prbPts = np.array([[
            -2 * math.sin(math.pi / 6) + 3.0, 2 * math.cos(math.pi / 6), 4.0
        ], [-2 * math.sin(math.pi / 6) + 3.0, -2 * math.cos(math.pi / 6), 4.0],
                           [5.0, 0.0, 4.0]], np.float)
        res = rdAlg.GetAlignmentTransform(refPts, prbPts)
        self.assertTrue(feq(res[0], 3.0))
        target = [[-1.732, -1., 0.], [1.732, -1., 0.], [0., 2., 0.]]
        cnt = 0
        for item in list(prbPts):
            self.assertTrue(lstFeq(transformPoint(res[1], item), target[cnt]))
            cnt += 1

        weights = np.array([1.0, 1.0, 2.0], np.float)
        res = rdAlg.GetAlignmentTransform(refPts, prbPts, weights)
        self.assertTrue(feq(res[0], 3.75))
        cnt = 0
        target = [[-1.732, -1.25, 0.], [1.732, -1.25, 0.], [0., 1.75, 0.]]
        for item in list(prbPts):
            self.assertTrue(lstFeq(transformPoint(res[1], item), target[cnt]))
            cnt += 1
        weights = [1.0, 1.0, 2.0]
        res = rdAlg.GetAlignmentTransform(refPts, prbPts, weights)
        self.assertTrue(feq(res[0], 3.75))

        weights = [1.0, 2.0, 2.0]
        res = rdAlg.GetAlignmentTransform(refPts, prbPts, weights)
        self.assertTrue(feq(res[0], 4.8))
Exemple #3
0
    def test3tetra(self):
        refPts = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0],
                           [0.0, 0.0, 1.0]], np.float)
        prbPts = np.array([[2.0, 2.0, 3.0], [3.0, 2.0, 3.0], [2.0, 3.0, 3.0]],
                          np.float)
        self.assertRaises(ValueError,
                          lambda: rdAlg.GetAlignmentTransform(refPts, prbPts))

        prbPts = np.array([[2.0, 2.0, 3.0], [3.0, 2.0, 3.0], [2.0, 3.0, 3.0],
                           [2.0, 2.0, 4.0]], np.float)
        res = rdAlg.GetAlignmentTransform(refPts, prbPts)
        self.assertTrue(feq(res[0], 0.0))

        wts = [1.0, 1.0, 1.0]
        self.assertRaises(
            ValueError,
            lambda: rdAlg.GetAlignmentTransform(refPts, prbPts, wts))

        wts = [1.0, 1.0, 1.0, 1.0]
        res = rdAlg.GetAlignmentTransform(refPts, prbPts, wts)
        self.assertTrue(feq(res[0], 0.0))

        # test reflection
        prbPts = np.array([[2.0, 2.0, 3.0], [3.0, 2.0, 3.0], [2.0, 2.0, 4.0],
                           [2.0, 3.0, 3.0]], np.float)
        res = rdAlg.GetAlignmentTransform(refPts, prbPts, wts)
        self.assertTrue(feq(res[0], 1.0))

        res = rdAlg.GetAlignmentTransform(refPts, prbPts, wts, 1)
        self.assertTrue(feq(res[0], 0.0))
        cnt = 0
        refLst = list(refPts)
        for item in list(prbPts):
            self.assertTrue(lstFeq(transformPoint(res[1], item), refLst[cnt]))
            cnt += 1
Exemple #4
0
    def test1Basic(self):
        # passing two numeric arrays
        refPts = np.zeros((2, 3), np.float)
        prbPts = np.zeros((2, 3), np.float)

        refPts[1, 0] = 1.0

        prbPts[0, 0] = 2.0
        prbPts[0, 1] = 2.0
        prbPts[1, 0] = 2.0
        prbPts[1, 1] = 3.0

        res = rdAlg.GetAlignmentTransform(refPts, prbPts)
        self.assertTrue(feq(res[0], 0.0))
        refLst = list(refPts)
        cnt = 0
        for item in list(prbPts):
            self.assertTrue(lstFeq(transformPoint(res[1], item), refLst[cnt]))
            cnt += 1

        # repeat with with lists or tuples
        refPts = ((0.0, 0.0, 0.0), (1.0, 0.0, 0.0))
        prbPts = ((2.0, 2.0, 0.0), (2.0, 3.0, 0.0))
        res = rdAlg.GetAlignmentTransform(refPts, prbPts)
        self.assertTrue(feq(res[0], 0.0))

        refPts = [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0]]
        prbPts = [[2.0, 2.0, 0.0], [2.0, 3.0, 0.0]]
        res = rdAlg.GetAlignmentTransform(refPts, prbPts)
        self.assertTrue(feq(res[0], 0.0))

        # mix it up
        refPts = np.zeros((2, 3), np.float)
        refPts[1, 0] = 1.0
        res = rdAlg.GetAlignmentTransform(refPts, prbPts)
        self.assertTrue(feq(res[0], 0.0))
Exemple #5
0
    def test4points(self):
        refPts = (
            Geometry.Point3D(0.0, 0.0, 0.0),
            Geometry.Point3D(1.0, 0.0, 0.0),
            Geometry.Point3D(0.0, 1.0, 0.0),
            Geometry.Point3D(0.0, 0.0, 1.0),
        )
        prbPts = (
            Geometry.Point3D(2.0, 2.0, 3.0),
            Geometry.Point3D(3.0, 2.0, 3.0),
            Geometry.Point3D(2.0, 3.0, 3.0),
            Geometry.Point3D(2.0, 2.0, 4.0),
        )

        res = rdAlg.GetAlignmentTransform(refPts, prbPts)
        self.assertTrue(feq(res[0], 0.0))
def check_mol(mol):
    res = []
    mol.RemoveAllConformers()
    match, mList = EmbedLib.MatchPharmacophoreToMol(mol, feat_fact, pcophore)
    #mList = [ m for m in Set( mList ) ]
    if match:
        num_match = len(mList)
        for i in range(num_match):
            num_feature = len(mList[i])
            for j in range(num_feature):
                print mList[i][j].GetAtomIds(), mList[i][j].GetFamily()
        bounds = rdDistGeom.GetMoleculeBoundsMatrix(mol)
        pList = EmbedLib.GetAllPharmacophoreMatches(mList, bounds, pcophore)
        num_match = len(pList)
        phMatches = []
        for i in range(num_match):
            num_feature = len(pList[i])
            phMatch = []
            for j in range(num_feature):
                phMatch.append(pList[i][j].GetAtomIds())

            phMatches.append(phMatch)
        for phMatch in phMatches:
            bm, embeds, nFail = EmbedLib.EmbedPharmacophore(mol,
                                                            phMatch,
                                                            pcophore,
                                                            count=5,
                                                            silent=1)
            print "-----> embeds num:", len(embeds)
            for embed in embeds:
                AllChem.UFFOptimizeMolecule(embed)
                feats = feat_fact.GetFeaturesForMol(embed)
                feats_dict = GetFeatsPerAtoms(feats)
                match_feats = [feats_dict[atomid] for atomid in phMatch]
                pro_mat = [list(feat.GetPos()) for feat in match_feats]
                align_data = rdAlignment.GetAlignmentTransform(
                    ref_mat, pro_mat, maxIterations=200)
                AllChem.TransformMol(embed, align_data[1])
                print align_data[0]
                print align_data[1]
                res.append(embed)
    else:
        print "no hits"
    return res
Exemple #7
0
def get_transform_matrix(align_ref, conf_embed, atom_match):
    """Get the transformation matrix for a conformer.

        Parameters
        ----------
        align_ref: list of rdkit.Geometry.Point3D
            list of pharmacophore reference points for the alignment.

        conf_embed: rdkit.Chem.Conformer
            The conformer embedding.

        atom_match: list of list
            List of list of atoms ids that match the pharmacophore.

        Returns
        -------
        a 2-tuple

        ssd: float
            SSD value for the alignment.

        transform_matrix: numpy.ndarray; shape(4, 4)
            The transform matrix.

        """

    align_probe = []  # probe points to align to reference points
    for match_ids in atom_match:
        dummy_point = Geometry.Point3D(0.0, 0.0, 0.0)
        for id in match_ids:
            dummy_point += conf_embed.GetAtomPosition(id)
        dummy_point /= len(match_ids)
        align_probe.append(dummy_point)

    ssd, transform_matrix = rdAlignment.GetAlignmentTransform(
        align_ref, align_probe)
    return ssd, transform_matrix