Esempio n. 1
0
    def testdetect_from_ligand_ensemble(self):
        wrk_dir = "testdata/pharmacophore_extension/LigandPharmacophoreModel/from_ligand_ensemble"
        with PushDir(wrk_dir):
            test_overlay = io.MoleculeReader("test_overlay.mol2")
            ligand_pharmacophore = LigandPharmacophoreModel()
            ligand_pharmacophore.feature_definitions = [
                "ring_planar_projected"
            ]

            ligand_pharmacophore.detect_from_ligand_ensemble(
                ligands=test_overlay, cutoff=2)
            # ligand_pharmacophore.pymol_visulisation(outdir="")

            self.assertEqual(2, len(ligand_pharmacophore.detected_features))
Esempio n. 2
0
    def testdetect_from_ligand(self):
        wrkdir = "testdata/pharmacophore_extension/LigandPharmacophoreModel/from_ligand"
        with PushDir(wrkdir):
            self.ligand_pharmacophore.feature_definitions = ["acceptor"]
            print(self.ligand_pharmacophore.feature_definitions["acceptor"].
                  point_generator_names)
            self.ligand_pharmacophore.detect_from_ligand(ligand=self.crystal)
            self.assertEqual(5,
                             len(self.ligand_pharmacophore.detected_features))
            # test score setter
            self.assertEqual(
                0, self.ligand_pharmacophore.detected_features[0].score)
            self.ligand_pharmacophore.detected_features[0].score = 5
            self.assertEqual(
                5, self.ligand_pharmacophore.detected_features[0].score)

            # test write
            for f in self.ligand_pharmacophore.detected_features:
                self.ligand_pharmacophore.add_feature(f)

            self.ligand_pharmacophore.write(
                pharmacophore_path="pharmacophore.cm")

            read_me = LigandPharmacophoreModel.from_file("pharmacophore.cm")

            self.assertEqual(len(self.ligand_pharmacophore.features),
                             len(read_me.features))

            print(read_me.features[0].spheres[0].centre)
Esempio n. 3
0
    def create_multiple_pharmacophore_files():

        # setting output directory
        out_dir = "testdata/pharmacophore_extension/PharmacophoreModel"
        if not os.path.exists(out_dir):
            os.mkdir(out_dir)

        # create files
        mols = io.CrystalReader(
            "testdata/pharmacophore_extension/provided_data/test_overlay.mol2")
        for mol in mols:
            lp = LigandPharmacophoreModel()
            lp.feature_definitions = ["ring_planar_projected"]
            lp.detect_from_ligand(mol)
            for feature in lp.detected_features:
                lp.add_feature(feature)

            lp.write(os.path.join(out_dir, f"{mol.identifier}.cm"))
Esempio n. 4
0
    def testdetect_from_ligand_ensemble_cdk2(self):
        wrk_dir = "testdata/pharmacophore_extension/LigandPharmacophoreModel/from_ligand_ensemble_big_all"
        with PushDir(wrk_dir):
            test_overlay = io.MoleculeReader("cdk2_ligands.mol2")
            ligand_pharmacophore = LigandPharmacophoreModel()
            ligand_pharmacophore.feature_definitions = [
                "ring_planar_projected", "donor_projected",
                "acceptor_projected"
            ]

            ligand_pharmacophore.detect_from_ligand_ensemble(
                ligands=test_overlay, cutoff=2)

            feature_count = 4
            selected = ligand_pharmacophore.top_features(num=feature_count)
            ligand_pharmacophore.detected_features = selected

            self.assertEqual(feature_count, len(ligand_pharmacophore))
Esempio n. 5
0
    def generate_pharmacophore(ligands, ref_pdb, out_dir):
        lig_pharms = []
        for ligand in ligands:
            ligand_pharmacophore = LigandPharmacophoreModel()
            ligand_pharmacophore.feature_definitions = [
                "ring", "acceptor_projected", "donor_projected"
            ]

            ligand_pharmacophore.detect_from_ligand(ligand)

            for feat in ligand_pharmacophore.detected_features:
                ligand_pharmacophore.add_feature(feat)

            lig_pharms.append(ligand_pharmacophore)

        # 20 %
        cutoff = len(ligands) * 0.2
        feats, feat_point_grds = create_consensus(lig_pharms, cutoff=cutoff)
        print(feats)
        for feat in feats:
            if feat.identifier == "ring":
                p = feat.spheres[0].centre
                feat.spheres = (GeometricDescriptors.Sphere((p[0], p[1], p[2]),
                                                            2.0), )
                feat.point = feat.spheres[0]

        ensemble_pharm = LigandPharmacophoreModel()
        ensemble_pharm.detected_features = feats
        ensemble_pharm.feature_point_grids = feat_point_grds
        ensemble_pharm.ligands = ligands
        ensemble_pharm.detected_features = ensemble_pharm.top_features(num=6)
        pymol_o = os.path.join(out_dir, "pymol")
        if not os.path.exists(pymol_o):
            os.mkdir(pymol_o)
        ensemble_pharm.pymol_visulisation(pymol_o)

        #  enable rescoring
        tmp = tempfile.mkdtemp()
        ftp_download([ref_pdb, tmp])
        hr = Results(super_grids={
            "apolar": feat_point_grds["ring"],
            "donor": feat_point_grds["donor_projected"],
            "acceptor": feat_point_grds["acceptor_projected"]
        },
                     protein=Protein.from_file(
                         os.path.join(tmp, f"{ref_pdb}.pdb")))

        hr_out = os.path.join(out_dir, "hr")
        if not os.path.exists(hr_out):
            os.mkdir(hr_out)
        with HotspotWriter(hr_out) as w:
            w.write(hr)

        p_out = os.path.join(out_dir, "ligand_pharmacophores")
        if not os.path.exists(p_out):
            os.mkdir(p_out)

        for n in [6, 5, 4, 3]:
            lp = LigandPharmacophoreModel()
            lp.detected_features = feats
            lp.detected_features = lp.top_features(num=n)
            for feat in lp.detected_features:
                lp.add_feature(feat)

            lp.intra_only = True

            lp.write(os.path.join(p_out, f"{n}.cm"))
Esempio n. 6
0
from hotspots.pharmacophore_extension import LigandPharmacophoreModel
from ccdc import io

csd = io.EntryReader('CSD')
crystal = csd.crystal('IBPRAC')
crystal.molecule.add_hydrogens()
ligand_pharmacophore = LigandPharmacophoreModel()

ligand_pharmacophore.feature_definitions = [
    "acceptor_projected", "donor_projected", "ring_planar_projected"
]

ligand_pharmacophore.detect_from_ligand(crystal)
ligand_pharmacophore.pymol_visulisation()
Esempio n. 7
0
 def setUp(self):
     self.csd = csd()
     self.crystal = csd().crystal('AABHTZ')
     self.crystal.molecule.add_hydrogens()
     self.ligand_pharmacophore = LigandPharmacophoreModel()
Esempio n. 8
0
class TestLigandPharmacophoreModel(unittest.TestCase):
    def setUp(self):
        self.csd = csd()
        self.crystal = csd().crystal('AABHTZ')
        self.crystal.molecule.add_hydrogens()
        self.ligand_pharmacophore = LigandPharmacophoreModel()

    def testSetters(self):
        self.assertEqual(0, len(self.ligand_pharmacophore.features))
        self.ligand_pharmacophore.feature_definitions = ["acceptor"]
        self.assertEqual(1, len(self.ligand_pharmacophore.feature_definitions))

    def testdetect_from_ligand(self):
        wrkdir = "testdata/pharmacophore_extension/LigandPharmacophoreModel/from_ligand"
        with PushDir(wrkdir):
            self.ligand_pharmacophore.feature_definitions = ["acceptor"]
            print(self.ligand_pharmacophore.feature_definitions["acceptor"].
                  point_generator_names)
            self.ligand_pharmacophore.detect_from_ligand(ligand=self.crystal)
            self.assertEqual(5,
                             len(self.ligand_pharmacophore.detected_features))
            # test score setter
            self.assertEqual(
                0, self.ligand_pharmacophore.detected_features[0].score)
            self.ligand_pharmacophore.detected_features[0].score = 5
            self.assertEqual(
                5, self.ligand_pharmacophore.detected_features[0].score)

            # test write
            for f in self.ligand_pharmacophore.detected_features:
                self.ligand_pharmacophore.add_feature(f)

            self.ligand_pharmacophore.write(
                pharmacophore_path="pharmacophore.cm")

            read_me = LigandPharmacophoreModel.from_file("pharmacophore.cm")

            self.assertEqual(len(self.ligand_pharmacophore.features),
                             len(read_me.features))

            print(read_me.features[0].spheres[0].centre)

        # self.ligand_pharmacophore.pymol_visulisation()

    def testto_pymol_str(self):
        self.ligand_pharmacophore.feature_definitions = ["acceptor_projected"]
        self.ligand_pharmacophore.detect_from_ligand(ligand=self.crystal)

        f = PyMOLFile()
        f.commands += self.ligand_pharmacophore.detected_features[
            0].to_pymol_str()
        f.write(
            "testdata/pharmacophore_extension/LigandPharmacophoreModel/from_ligand/feature_write.py"
        )

    def testdetect_from_pdb(self):
        testpdb = "2vta"
        testhetid = "LZ1"
        testchainid = "A"
        self.ligand_pharmacophore.feature_definitions = [
            "donor_projected", "acceptor_projected"
        ]
        self.ligand_pharmacophore.detect_from_pdb(pdb=testpdb,
                                                  hetid=testhetid,
                                                  chainid=testchainid)

        self.assertEqual(2, len(self.ligand_pharmacophore.detected_features))
        # self.ligand_pharmacophore.pymol_visulisation("testdata/pharmacophore_extension/LigandPharmacophoreModel/from_pdb")

    def testdetect_from_ligand_ensemble(self):
        wrk_dir = "testdata/pharmacophore_extension/LigandPharmacophoreModel/from_ligand_ensemble"
        with PushDir(wrk_dir):
            test_overlay = io.MoleculeReader("test_overlay.mol2")
            ligand_pharmacophore = LigandPharmacophoreModel()
            ligand_pharmacophore.feature_definitions = [
                "ring_planar_projected"
            ]

            ligand_pharmacophore.detect_from_ligand_ensemble(
                ligands=test_overlay, cutoff=2)
            # ligand_pharmacophore.pymol_visulisation(outdir="")

            self.assertEqual(2, len(ligand_pharmacophore.detected_features))

    def testdetect_from_ligand_ensemble_cdk2(self):
        wrk_dir = "testdata/pharmacophore_extension/LigandPharmacophoreModel/from_ligand_ensemble_big_all"
        with PushDir(wrk_dir):
            test_overlay = io.MoleculeReader("cdk2_ligands.mol2")
            ligand_pharmacophore = LigandPharmacophoreModel()
            ligand_pharmacophore.feature_definitions = [
                "ring_planar_projected", "donor_projected",
                "acceptor_projected"
            ]

            ligand_pharmacophore.detect_from_ligand_ensemble(
                ligands=test_overlay, cutoff=2)

            feature_count = 4
            selected = ligand_pharmacophore.top_features(num=feature_count)
            ligand_pharmacophore.detected_features = selected

            self.assertEqual(feature_count, len(ligand_pharmacophore))