def calc(args): prot_file, hotspot_file = args prot = Protein.from_file(prot_file) # pre prepared runner = Runner() settings = Runner.Settings() settings.apolar_translation_threshold = 8 settings.polar_translation_threshold = 10 # pdb = os.path.basename(prot_file)[0][:4] # # mol_path = os.path.join(os.path.dirname(prot_file)) hr = runner.from_protein(prot, nprocesses=3, settings=settings, probe_size=3) for p, g in hr.super_grids.items(): hr.super_grids[p] = g.dilate_by_atom() try: e = Extractor(hr) bv = e.extract_volume(volume=250) except: bv = Results( protein=hr.protein.copy(), super_grids={p: g.copy() for p, g in hr.super_grids.items()}) hr.identifier = "hotspot" bv.identifier = "bcv" with HotspotWriter(hotspot_file) as w: w.write([hr, bv])
def run(self, cavity=True): """from fragment hotspot calc from protein""" h = Runner() settings = Runner.Settings(sphere_maps=False) if self.args.prepare: self.prepare_protein() else: self.prot = Protein.from_file(self.args.prot_fname) if cavity: cavs = Cavity.from_pdb_file(self.args.prot_fname) print(cavs) else: cavs = None result = h.from_protein(protein=self.prot, charged_probes=False, buriedness_method=self.args.buriedness_method, cavities=cavs, nprocesses=5, settings=settings) with HotspotWriter(path=self.in_dir, zip_results=self.args.zipped) as writer: writer.write(result)
def _get_hotspot(self, cav_id): """ calculate hotspot map from pre-calculated superstar and buriedness grids :param cav_id: :return: """ # inputs prot = Protein.from_file(self.apo_prep) sr = HotspotReader(path=os.path.join(self.superstar[cav_id], "out.zip")).read() superstar = [_AtomicHotspotResult(identifier=ident, grid=grid, buriedness=None) for ident, grid in sr.super_grids.items()] buriedness = Grid.from_file(self.buriedness) # tasks start = time.time() h = Runner() s = h.Settings() s.apolar_translation_threshold = 14 s.polar_translation_threshold = 14 s.polar_contributions = False s.sphere_maps = False s.nrotations = 3000 hr = h.from_superstar(prot, superstar, buriedness, settings=s, clear_tmp=True) finish = time.time() # output if not os.path.exists(self.hotspot[cav_id]): os.mkdir(self.hotspot[cav_id]) with open(self.hotspot_time[cav_id], 'w') as t: t.write(str(finish - start)) with HotspotWriter(self.hotspot[cav_id], zip_results=True) as writer: writer.write(hr)
def run(self): prot = Protein.from_file(self.input().path) cavs = Cavity.from_pdb_file(self.input().path) h = Runner() s = h.Settings() s.apolar_translation_threshold = 15 s.polar_translation_threshold = 15 s.polar_contributions = False s.nrotations = 1000 hr = h.from_protein(prot, buriedness_method='ghecom', nprocesses=1, settings=s, cavities=cavs) out_settings = HotspotWriter.Settings() out_settings.charged = False w = HotspotWriter(os.path.dirname(self.output().path), grid_extension=".grd", zip_results=True, settings=out_settings) w.write(hr)
def _get_protein(pdb_code, tmpdir, protein_path=None): """ Fetch the protein of interest NB: 13-May-2020: There seems to be some funny behaviour from the CCDC pdbwriter Therefore, AVOID writing using MoleculeWriter. (for now) :param str pdb_code: 4 character PDB code :param str tmpdir: path to temporary directory :param str protein_path: path to protein file :return: `ccdc.protein.Protein` """ ext = "pdb" if protein_path: # copy protein to the results 'tmp' directory ext = protein_path.split(".")[1] copyfile(protein_path, os.path.join(tmpdir, f"{pdb_code}.{ext}")) else: # otherwise download from the PDB PDBResult(identifier=pdb_code).download(out_dir=tmpdir) # clean(os.path.join(tmpdir, f"{pdb_code}.pdb"), dry) # clean suffix added return Protein.from_file(os.path.join(tmpdir, f'{pdb_code}.{ext}'))
PDBResult(identifier=pdb).download(out_dir=dirname) if os.path.exists(reps): representatives = reps else: representatives = None try: result = HotspotReader(path=os.path.join(dirname, "out.zip")).read() pharmacophore = result.get_pharmacophore_model() pharmacophore.rank_features(max_features=5) except: pharmacophore = PharmacophoreModel.from_pdb( pdb_code=pdb, chain="H", out_dir=dirname, representatives=representatives) pharmacophore.rank_features(max_features=5) result = Results(super_grids=pharmacophore.dic, protein=Protein.from_file( os.path.join(dirname, pdb + ".pdb"))) pharmacophore.write(os.path.join(dirname, "crossminer.cm")) pharmacophore.write(os.path.join(dirname, "pharmit.json")) # write out Results object settings = HotspotWriter.Settings() settings.isosurface_threshold = [2, 5, 10] with HotspotWriter(dirname, settings=settings) as w: w.write(result)
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(self): if not os.path.exists(self.args.output_directory): os.mkdir(self.args.output_directory) rms_cutoff = 1 tmp = tempfile.mkdtemp() print("Searching the PDB") pdbs, entities = pdb_search(self.args.uniprot, self.args.max_resolution) download(pdbs, out_dir=tmp, processes=self.args.processes) if self.args.ref_pdb not in pdbs: print("Downloading reference data") download([self.args.ref_pdb], out_dir=tmp, processes=1) # chain to entity ref_prot = Protein.from_file( os.path.join(tmp, f"{self.args.ref_pdb}.pdb")) entity = [c.identifier for c in ref_prot.chains].index(self.args.ref_chain) prepare_protein(pdb=self.args.ref_pdb, entity=entity, out_dir=tmp) print("Prepare protein") for pdb, entity in tqdm(zip(pdbs, entities), total=len(pdbs)): # other chains removed, max number chains = 1 try: # list(filter(None.__ne__, L)) prepare_protein(pdb=pdb, entity=entity, out_dir=tmp) except: print("ERROR", pdb, entity) pdbs.remove(pdb) entities.remove(entity) print("Aligning PDBs") # align args = zip([self.args.ref_pdb] * len(pdbs), [self.args.binding_site_ligand] * len(pdbs), pdbs, [tmp] * len(pdbs)) with Pool(processes=self.args.processes) as pool: rms_list = list(tqdm(pool.imap(align, args), total=len(pdbs))) print("Extracting Ligands...") all_ligands = [] # add the reference structure back to PDB list for pdb, rms in zip(pdbs + [self.args.ref_pdb], rms_list + [0]): if rms < rms_cutoff: all_ligands.extend(ligands_from_pdb(pdb, tmp)) print(f" {len(all_ligands)} detected") if self.args.binding_site_ligand: ref_prot = Protein.from_file( os.path.join(tmp, f"{self.args.ref_pdb}.pdb")) ref_mol = [ lig for lig in ref_prot.ligands if lig.identifier == f"{self.args.ref_chain}:{self.args.binding_site_ligand}" ][0] all_ligands = bs_filter(all_ligands, ref_mol) print( f" Binding site filter, {len(all_ligands)} ligands remaining" ) if self.args.no_solvents: all_ligands = remove_solvents(all_ligands) print( f" Removed solvents and metals, {len(all_ligands)} ligands remaining" ) if self.args.cluster: all_ligands = cluster_ligands(all_ligands) print( f" Clustered ligands, {len(all_ligands)} ligands remaining") pdbs, chains, hetids, resnum = zip(*[[ lig.identifier.split(":")[0], lig.identifier.split(":")[1], lig.identifier.split(":")[2][:3], lig.identifier.split(":")[2][3:] ] for lig in all_ligands]) df = pd.DataFrame({ "pdbs": pdbs, "chains": chains, "hetids": hetids, "resnum": resnum }) df.to_csv( os.path.join(self.args.output_directory, "ligand_overlay.csv")) with io.MoleculeWriter( os.path.join(self.args.output_directory, "ligand_overlay.mol2")) as w: for lig in all_ligands: # lig.add_hydrogens() w.write(lig)
def __init__(self): super(self.__class__, self).__init__(description=__doc__) # handle command line arguments self.add_argument( 'protein', help='pdb_code of protein which was used in docking' ) self.add_argument( 'reference', help='pdb_code of reference' ) self.add_argument( 'chemical_id', help='PDB identifier for the docked ligand' ) self.add_argument( 'results', help='path to results files' ) self.add_argument( '-r', '--chain_ref', default='A', help='Chain to used for alignment' ) self.add_argument( '-p', '--chain_protein', default='A', help='Chain to used for alignment' ) self.args = self.parse_args() self.tmp = tempfile.mkdtemp() # download protein PDBResult(self.args.protein).download(self.tmp) self.protein = Protein.from_file(os.path.join(self.tmp, self.args.protein + ".pdb")) self.protein.add_hydrogens() # download reference PDBResult(self.args.reference).download(self.tmp) ref = Protein.from_file(os.path.join(self.tmp, self.args.reference + ".pdb")) ref.add_hydrogens() self.ref = self._align(self.protein, ref) self.reference_ligand = self._extract_ligands(protein=self.ref, ligand=self.args.chemical_id, chain=self.args.chain_ref)[0] with MoleculeWriter(os.path.join(os.path.dirname(os.path.realpath(__file__)), "reference.mol2")) as w: w.write(self.reference_ligand) self.results = MoleculeReader(os.path.join(os.path.dirname(os.path.realpath(__file__)), self.args.results)) self.rmsd_values = [] for l in self.results: self.rmsd_values.append(self.rmsd(l, self.reference_ligand))
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"))
for i in range(nx): for j in range(ny): for k in range(nz): if g.value(i, j, k) == 0: solv_coords.append((i, j, k)) for probe in probe_sizes: print probe remaining = solv_coords for c in remaining: i, j, k = c coord = g2.indices_to_point(i, j, k) if len(points_tree.query_ball_point(coord, probe)) == 0: g2.set_value(i, j, k, 10 - probe) #solv_coords.remove((i,j,k)) return g2.min_value_of_neighbours() prot = Protein.from_file('pdb_files/aa/2aa2/protonated_no_wat.pdb') prot_coords = [a.coordinates for a in prot.heavy_atoms] prot_grid = multi_probes(prot) points_tree = spatial.cKDTree(prot_coords) #out_g = split_array(prot_grid, points_tree) prot_grid.write(('prot_g.grd')) #out_g.write('newdepth.grd')
def _get_superstar(self, cav_id=None): """ calculate SuperStar for each cavity if the buriedness method is ligsite, write out the grid for later :param cav_id: :return: """ # input prot = Protein.from_file(self.apo_prep) if cav_id is 'global': cavity_origin = None else: with open(self.cavities[cav_id], 'rb') as handle: cavity_origin = [pickle.load(handle)] # tasks start = time.time() a = _AtomicHotspot() a.settings.atomic_probes = {"apolar": "AROMATIC CH CARBON", "donor": "UNCHARGED NH NITROGEN", "acceptor": "CARBONYL OXYGEN"} self.superstar_grids = a.calculate(prot, nthreads=None, cavity_origins=cavity_origin) sr = Results(protein=prot, super_grids={result.identifier: result.grid for result in self.superstar_grids}) finish = time.time() # outputs if not os.path.exists(self.superstar[cav_id]): os.mkdir(self.superstar[cav_id]) if cav_id is not 'global': out = os.path.join(a.settings.temp_dir, str(0)) else: out = a.settings.temp_dir for interaction in ["apolar", "acceptor", "donor"]: shutil.copyfile(os.path.join(out, "{}.cavity.mol2".format(interaction)), os.path.join(self.superstar[cav_id], "{}.cavity.mol2".format(interaction))) shutil.make_archive(os.path.join(self.superstar[cav_id], "superstar"), 'zip', out) with HotspotWriter(path=self.superstar[cav_id], zip_results=True) as w: w.write(sr) with open(self.superstar_time[cav_id], 'w') as t: t.write(str(finish - start)) shutil.rmtree(a.settings.temp_dir) if self.buriedness_method == 'ligsite': # only write if it doesn't exist i.e. the first cavity run if not os.path.exists(self.buriedness): for ss in self.superstar_grids: if ss.identifier == "apolar": ss.buriedness.write(self.buriedness)
kr = KLIFSReader(ensemble_directory=join(main_dir, e), ens_name=e) #kr.no_allosteric() kr.get_subset() #kr.save_pdbs() #kr.find_largest_ligand() hot_paths = kr.get_ensemble(nrotations=nrot, charged=False) ref_kr = KLIFSReader(ensemble_directory=join(main_dir, 'CK2a1'), ens_name='CK2a1') # # CK2_kr.save_pdbs() # # largest_ligand = ref_kr.find_largest_ligand() prot = Protein.from_file(join(dirname(largest_ligand), 'protein.mol2')) bs = Protein.BindingSiteFromMolecule( protein=prot, molecule=MoleculeReader(largest_ligand)[0], distance=7.0) s_paths_file = join(main_dir, "shrunk_hot_paths_{}.json".format(nrot)) if exists(s_paths_file): with open(s_paths_file, "r") as f: s_paths_dict = json.load(f) else: s_paths_dict = {} ensemble = Ensemble(root_dir=join(main_dir, e)) ensemble.reference_binding_site = bs #hot_paths = glob(join(ensemble.root_dir, '*', "fullsize_hotspots_{}".format(nrot), "out.zip"))
def from_pdb(self, pdb_code, charged_probes=False, probe_size=7, buriedness_method='ghecom', nprocesses=3, cavities=False, settings=None, clear_tmp=False): """ generates a result from a pdb code :param str pdb_code: PDB code :param bool charged_probes: If True include positive and negative probes :param int probe_size: Size of probe in number of heavy atoms (3-8 atoms) :param str buriedness_method: Either 'ghecom' or 'ligsite' :param int nprocesses: number of CPU's used :param `hotspots.calculation.Runner.Settings` settings: holds the calculation settings :return: a :class:`hotspots.result.Result` instance >>> from hotspots.calculation import Runner >>> runner = Runner() >>> runner.from_pdb("1hcl") Result() """ protoss = False tmp = tempfile.mkdtemp() # if protoss is True: # protoss = Protoss(out_dir=tmp) # self.protein = protoss.add_hydrogens(pdb_code).protein # # else: PDBResult(identifier=pdb_code).download(out_dir=tmp) fname = join(tmp, "{}.pdb".format(pdb_code)) self.protein = Protein.from_file(fname) self._prepare_protein(protoss) self.charged_probes = charged_probes self.probe_size = probe_size self.buriedness_method = buriedness_method self.clear_tmp = clear_tmp self.cavities = None if cavities is True: self.cavities = Cavity.from_pdb_file(fname) self.nprocesses = nprocesses if settings is None: self.sampler_settings = self.Settings() else: self.sampler_settings = settings if self.sampler_settings.return_probes is True: print('here') self._calc_hotspots(return_probes=True) else: self._calc_hotspots() self.super_grids = {p: g[0] for p, g in self.out_grids.items()} if clear_tmp == True: shutil.rmtree(tmp) return Results(super_grids=self.super_grids, protein=self.protein, buriedness=self.buriedness, superstar={x.identifier: x.grid for x in self.superstar_grids}, weighted_superstar={x.identifier: x.grid for x in self.weighted_grids})
if charged_probes: probe_dict = dict(apolar='AROMATIC CH CARBON', donor='UNCHARGED NH NITROGEN', acceptor='CARBONYL OXYGEN', positive='CHARGED NH NITROGEN', negative='CHLORIDE ANION') else: probe_dict = dict(apolar='AROMATIC CH CARBON', donor='UNCHARGED NH NITROGEN', acceptor='CARBONYL OXYGEN') for n, probe in probe_dict.items(): if n == "positive": s = RunSuperstar() s.settings.jobname = "{}.ins".format(n) s.settings.probename = probe s.settings.moleculefile = "protein.pdb" s.settings.cavity_origin = centroid result = s.run_superstar(prot, out_dir) sites.append(result) return sites if __name__ == "__main__": prot = Protein.from_file("protein.pdb") out_dir = "C:/Users/pcurran/Desktop/experiments/ss" sites = _run_ss(prot, out_dir) print sites[0].grid, sites[0].ligsite
def dock(self): """ Setup and execution of docking run with GOLD. NB: Docking Settings class is imported from the Hotspots API rather than Docking API. This is essential for running hotspot guided docking. :return: a :class:`ccdc.io.MoleculeReader` """ docker = Docker() docker.settings = hs_docking.DockerSettings() # download protein PDBResult(self.args.pdb).download(self.temp) protein = Protein.from_file( os.path.join(self.temp, self.args.pdb + ".pdb")) protein.remove_all_waters() protein.remove_all_metals() protein.add_hydrogens() for l in protein.ligands: protein.remove_ligand(l.identifier) f = os.path.join(self.temp, self.args.pdb + ".mol2") with MoleculeWriter(f) as w: w.write(protein) # setup docker.settings.add_protein_file(f) # create binding site from list of residues cavs = Cavity.from_pdb_file( os.path.join(self.temp, self.args.pdb + ".pdb")) cavs[0].to_pymol_file("test.py") c = {} for i, cav in enumerate(cavs): cav.feats = [] for f in cav.features: try: cav.feats.append(f.residue) except: continue # cav.feats = [f.residue for f in cav.features] cav.len = len(cav.feats) c.update({cav.len: cav.feats}) cav.to_pymol_file("{}.py".format(i)) selected_cavity = max(c.keys()) docker.settings.binding_site = docker.settings.BindingSiteFromListOfResidues( protein=docker.settings.proteins[0], residues=c[selected_cavity]) docker.settings.fitness_function = 'plp' docker.settings.autoscale = 100. docker.settings.output_directory = self.temp docker.settings.output_file = "docked_ligands.mol2" docker.settings.add_ligand_file(self.search_ligands, ndocks=25) # constraints if self.args.hotspot_guided is True: e_settings = result.Extractor.Settings() e_settings.mvon = True extractor = result.Extractor(self.hr, settings=e_settings) bv = extractor.extract_best_volume(volume=300)[0] f = hs_utilities.Helper.get_out_dir( os.path.join(self.args.path, "best_volume")) with hs_io.HotspotWriter(path=f) as hw: hw.write(bv) constraints = docker.settings.HotspotHBondConstraint.create( protein=docker.settings.proteins[0], hr=bv, weight=5, min_hbond_score=0.2, max_constraints=5) for constraint in constraints: docker.settings.add_constraint(constraint) docker.settings.generate_fitting_points(hr=bv) mol = Molecule(identifier="constraints") for constraint in constraints: for a in constraint.atoms: mol.add_atom( Atom(atomic_symbol="C", atomic_number=14, label="Du", coordinates=a.coordinates)) with MoleculeWriter(os.path.join(self.args.path, "constaints.mol2")) as w: w.write(mol) docker.dock() results = docker.Results(docker.settings) return results.ligands
def setUp(self): self.protein = Protein.from_file("testdata/1hcl/protein.pdb") self.protein.remove_all_waters() self.protein.add_hydrogens() self.template = Grid.initalise_grid( [atm.coordinates for atm in self.protein.atoms])
print(entry) fetch_pdb(entry) ## create protein objects and dictionary of binding objects from list of entries directory = r'C:\Users\amukhopadhyay\Documents\test_scripts' list_of_protein_objs = [] binding_site_dict = {} for filename in os.listdir(directory): if filename.endswith(".pdb"): print(filename) pdb_id = filename.split(".")[0] print(pdb_id) protein_from_entry = Protein.from_file(filename) print(len(protein_from_entry.chains)) list_of_protein_objs.append(protein_from_entry) list_of_ligands = protein_from_entry.ligands list_of_ligands_identifiers = [ ligands.identifier for ligands in list_of_ligands ] print(list_of_ligands_identifiers) sti_list = (list( filter(lambda x: 'STI' in x, list_of_ligands_identifiers))) sti_indices = [ i for i, s in enumerate(list_of_ligands_identifiers) if 'STI' in s ] print(sti_indices)
from ccdc.protein import Protein from ccdc import io p0 = Protein.from_file(("1xkk.pdb")) p1 = p0.copy() p1.remove_all_waters() with io.MoleculeWriter("1xkk_dry.pdb") as w: w.write(p1) with io.MoleculeWriter("1xkk_dry.mol2") as w: w.write(p1) p2 = Protein.from_file("1xkk_dry.pdb") p3 = Protein.from_file("1xkk_dry.mol2") for p, l in zip([p0, p2, p3], ["original", "mol2writer", "pdbwriter"]): print(l) print(f"# atoms: {len(p.atoms)}") print(f"# residues: {len(p.residues)}, # waters: {len(p.waters)}") print(p.residues[30:50]) print(" ")
def dock(self, number_poses=100): """ :return: """ # Set up protein and ligand, in case they need to be if self.prepare_protein: self.prepare_protein_for_dock() if self.prepare_ligand: self.prepare_ligand_for_dock() reference_ligand = MoleculeReader(self.reference_ligand_path)[0] prepared_protein = Protein.from_file(self.prepared_protein_path) prepared_ligand = MoleculeReader(self.prepared_ligand_path)[0] if self.substructure: substr_string = make_substructure_molecule( template_mol_path=self.reference_ligand_path, query_mol_path=self.prepared_ligand_path) substructure = Molecule.from_string(substr_string, format='sdf') with MoleculeWriter( str( Path(self.gold_results_directory, f"{self.lig_name}_substructure.sdf"))) as sdfwr: sdfwr.write(substructure) # Set up the docking run docker = Docker() docker._conf_file_name = self.conf_file_location docker_settings = docker.settings # Prevent it from generating a ton of output ligand files - the ranked docks are in 'concat_ranked_docked_ligands.mol2' docker_settings._settings.set_delete_rank_files(True) docker_settings._settings.set_delete_empty_directories(True) docker_settings._settings.set_delete_all_initialised_ligands(True) docker_settings._settings.set_delete_all_solutions(True) docker_settings._settings.set_delete_redundant_log_files(True) docker_settings._settings.set_save_lone_pairs(False) # Set up the binding site. Since the sites are based on ragment hits, generate a binding site around the starting hit. docker_settings.reference_ligand_file = self.reference_ligand_path docker_settings.binding_site = docker_settings.BindingSiteFromLigand( prepared_protein, reference_ligand, 6.0) # Default distance around ligand is 6 A. Should be ok for small fragments. docker_settings.add_protein_file(self.prepared_protein_path) docker_settings.diverse_solutions = self.diverse_solutions # Try a template similarity restraint: # if self.substructure: try: docker_settings.add_constraint( docker_settings.ScaffoldMatchConstraint(substructure)) except Exception as e: docker_settings.add_constraint( docker_settings.TemplateSimilarityConstraint( 'all', reference_ligand, weight=75.0)) txtstr = 'Substructure search failed. Using template similarity' log_file = Path(self.results_directory, 'pipeline_error.log') log_file.write_text(txtstr) else: docker_settings.add_constraint( docker_settings.TemplateSimilarityConstraint('all', reference_ligand, weight=150.0)) # Choose the fitness function: options: ['goldscore', 'chemscore', 'asp', 'plp']. plp is the default. docker_settings.fitness_function = 'plp' docker_settings.autoscale = self.autoscale docker_settings.early_termination = False docker_settings.output_directory = self.gold_results_directory docker_settings.output_file = str( Path(self.results_directory, 'concat_ranked_docked_ligands.mol2')) # Add the ligand docker_settings.add_ligand_file( self.prepared_ligand_path, number_poses ) # Second argument determines how many poses are saved # Perform the docking: gold_result = docker.dock(file_name=self.conf_file_location) # pickle.dump(obj=gold_result,file=Path(self.results_directory, 'gold_result').open()) self.docking_result = gold_result return gold_result