def _get_cmd(self, protein, cavity_origin, out=None): """ private method constructs the commandline str required to run atomic hotspot calculation :param str jobname: general format (<probe_type>.ins) :param str probename: probe identifier :param str out: output directory (outputting ins maybe useful for debugging) :return: """ cmds = [] if not out: out = self.settings.temp_dir with PushDir(out): with MoleculeWriter(join(out, 'protein.mol2')) as writer: writer.write(protein) for jobname, probename in self.settings.atomic_probes.items(): instruction = self.InstructionFile(jobname=jobname, probename=probename, settings=self.settings, cavity=cavity_origin) cmds.append('{}'.format(self.settings.superstar_executable) + ' ' + '{}.ins'.format(jobname)) with PushDir(out): instruction.write("{}.ins".format(jobname)) return cmds
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)
def test_docking_constraint_atoms(self): with PushDir("testdata/result/data"): # read hotspot maps with HotspotReader(path="out.zip") as r: self.result = r.read() print(self.result._docking_constraint_atoms())
def _generate_result(self, path): with PushDir(path): files = set(listdir(path)) # fetch protein - this should always be protein.pdb prot_name = [f for f in files if f.split(".")[1] == self.supported_protein_extensions][0] prot = Protein.from_file(prot_name) files.remove(prot_name) # there should only be one grid extension in the directory, if there are more # then you can manually read in your results grid_extension = {f.split(".")[1] for f in files}.intersection(self.supported_grid_extensions) if len(grid_extension) > 1: raise IndexError("Too many grid types, create `hotspots.result.Results` manually") elif len(grid_extension) < 1: raise IndexError("No supported grid types found") elif list(grid_extension)[0] == "dat": raise NotImplementedError("Will put this in if requested") else: grid_extension = list(grid_extension)[0] # read hotspot grids stripped_files = {f.split(".")[0] for f in files} hotspot_grids = stripped_files.intersection(self.supported_interactions) super_grids = {p: Grid.from_file(f"{p}.{grid_extension}") for p in hotspot_grids} # read superstar grids if len([f.startswith("superstar") for f in files]) > 0 and self.read_superstar: superstar_grids = {p: Grid.from_file(f"superstar_{p}.{grid_extension}") for p in hotspot_grids} else: superstar_grids = None # read weighted_superstar grids if len([f.startswith("weighted") for f in files]) > 0 and self.read_weighted: weighted_grids = {p: Grid.from_file(f"weighted_{p}.{grid_extension}") for p in hotspot_grids} else: weighted_grids = None # fetch buriedness grid try: buriedness_name = [f for f in files if f.startswith("buriedness")][0] except IndexError: buriedness_name = None if buriedness_name and self.read_buriedness: buriedness = Grid.from_file(buriedness_name) else: buriedness = None return Results(super_grids=super_grids, protein=prot, buriedness=buriedness, superstar=superstar_grids, weighted_superstar=weighted_grids, identifier=basename(path))
def run(): # must be abspath parent = sys.argv[1] score = sys.argv[2] autoscale = sys.argv[3] run_id = sys.argv[4] crossminer_file = os.path.join(parent, sys.argv[5]) # data conf_name = "hs_gold.conf" out_path = check_dir(os.path.join(parent, "gold_results")) out_path = check_dir(os.path.join(out_path, run_id)) junk = check_dir(os.path.join(out_path, "all")) hotspot = os.path.join(parent, "hotspot_pharmacophore", "out.zip") crystal_ligand = os.path.join(parent, "crystal_ligand.mol2") actives = os.path.join(parent, "actives_final.mol2") decoys = os.path.join(parent, "decoys_final.mol2") prot_file = os.path.join(out_path, "protein.mol2") # output protein with hs_io.HotspotReader(hotspot) as reader: hr = [h for h in reader.read() if h.identifier == "bestvol"][0] with MoleculeWriter(prot_file) as w: w.write(hr.protein) hspm = HotspotPharmacophoreModel.from_file(crossminer_file) constraint_str = hspm.to_gold_conf(score=score) # create template gold_conf_str = template(autoscale, crystal_ligand, actives, decoys, junk, prot_file, constraint_str) print(gold_conf_str) with open(os.path.join(out_path, conf_name), "w") as w: w.write(gold_conf_str) # linux only gold_exe = os.path.join(os.environ["GOLD_DIR"], "bin/gold_auto") # run docking with PushDir(out_path): cmd = f"{gold_exe} {conf_name}" os.system(cmd) # process results docked = MoleculeReader(os.path.join(junk, "docked_ligands.mol2")) # make it consistent with other names with MoleculeWriter(os.path.join(out_path, "docked_ligand.mol2")) as w: for d in docked: for atm in d.atoms: if atm.atomic_symbol == "Unknown": d.remove_atom(atm) w.write(d) shutil.copyfile(os.path.join(junk, "bestranking.lst"), os.path.join(out_path, "bestranking.lst"))
def test_docking_fitting_pts(self): with PushDir("testdata/2vta"): # read hotspot maps with HotspotReader(path="out.zip") as r: self.result = r.read() mol = [ m for m in MoleculeReader("crystal_ligand.sdf") if "LZ1" in m.identifier.split("_") ][0] print(mol.identifier) m = self.result._docking_fitting_pts(mol)
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 create_pharmacophore(path, hetid, chain, out_dir): with PushDir(out_dir): ipm = InteractionPharmacophoreModel() ipm.feature_definitions = [ "donor_projected", "donor_ch_projected", "acceptor_projected", "ring_planar_projected" ] ipm.detect_from_arpeggio(path, hetid, chain) for feat in ipm.detected_features: ipm.add_feature(feat) ipm.write(f"{path.split('_')[0]}_{hetid}.cm")
def _run_job(args): """ private method Runs an Atomic Hotspot calculation using the SuperStar algorithm. :param tup or list args: Command, Jobname, SuperStar Environment Variable and Temporary directory :return: tup, temporary directory and jobname """ cmd, jobname, superstar_env, temp_dir = args print(temp_dir) env = environ.copy() env.update(superstar_env) with PushDir(temp_dir): subprocess.call(cmd, shell=sys.platform != 'win32', env=env) return temp_dir, jobname
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))
def run(self, protein, grid_spacing=0.5): """ executes the command line call NB: different versions of ghecom have different commandline args :param protein: protein :param grid_spacing: grid spacing, must be the same used in hotspot calculation :type protein: `ccdc.protein.Protein` :type grid_spacing: float """ with PushDir(self.temp): with io.MoleculeWriter('protein.pdb') as writer: writer.write(protein) cmd = f"{os.environ['GHECOM_EXE']} -ipdb {self.input} -M M -gw {grid_spacing} -rli 2.5 -rlx 9.5 -opocpdb {self.output}" os.system(cmd) return os.path.join(self.temp, self.output)
def calculate(self): """ runs the buriedness calculation :return: `hotspots.calculation._BuriednessResult`: a class with a :class:`ccdc.utilities.Grid` attribute """ with PushDir(self.settings.working_directory): if self.settings.protein is not None: with MoleculeWriter('protein.pdb') as writer: writer.write(self.settings.protein) cmd = "{} {} -M {} -gw {} -rli {} -rlx {} -opoc {}".format( environ['GHECOM_EXE'], self.settings.in_name, self.settings.mode, self.settings.grid_spacing, self.settings.radius_min_large_sphere, self.settings.radius_max_large_sphere, self.settings.out_name) system(cmd) return _BuriednessResult(self.settings)
def testscore_atoms_as_spheres(self): with PushDir("testdata/result/data"): mols = [m for m in MoleculeReader("gold_docking_poses.sdf")] # create a grid which can contain all docking poses small_blank = Grid.initalise_grid(coords={ atm.coordinates for mol in mols for atm in mol.heavy_atoms }, padding=2) # read hotspot maps with HotspotReader(path="out.zip") as r: self.result = r.read() # dilate the grids for p, g in self.result.super_grids.items(): self.result.super_grids[p] = g.dilate_by_atom() # shrink hotspot maps to save time sub_grids = { p: Grid.shrink(small=small_blank, big=g) for p, g in self.result.super_grids.items() } # create single grid mask_dic, sg = Grid.get_single_grid(sub_grids) self.result.super_grids = mask_dic # set background to 1 self.result.set_background() self.result.normalize_to_max() print([g.extrema for p, g in self.result.super_grids.items()]) for m in mols[:1]: s = self.result.score_atoms_as_spheres(m, small_blank) print(s)
def testdetect_from_pl_ensemble(self): wrkdir = "/home/pcurran/github_packages/pharmacophores/testdata/alignment" with PushDir(wrkdir): paths = [ "1AQ1_aligned.pdb", "1B38_aligned.pdb", "1B39_aligned.pdb", "1CKP_aligned.pdb" ] hetids = ["STU", "ATP", "ATP", "PVB"] chains = ["A", "A", "A", "A"] for i in range(len(paths)): ipm = InteractionPharmacophoreModel() ipm.feature_definitions = [ "donor_projected", "donor_ch_projected", "acceptor_projected", "ring_planar_projected" ] ipm.detect_from_arpeggio(paths[i], hetids[i], chains[i]) for feat in ipm.detected_features: ipm.add_feature(feat) ipm.write(f"{paths[i].split('_')[0]}_{hetids[i]}.cm")