def detect_from_pdb(self, pdb, hetid, chainid=None): """ Add features to pharmacophore model from a ligand in the PDB :param str pdb: pdb code :param str hetid: chemical component code :param str chainid: chain identifier :return: None """ PDBResult(pdb).download(out_dir=self.tmp) prot = Protein.from_file(os.path.join(self.tmp, f"{pdb}.pdb")) prot.add_hydrogens() if chainid: lig = [ l for l in prot.ligands if l.identifier.split(":")[1][:3] == hetid and l.identifier.split(":")[0] == chainid ][0] else: lig = [ l for l in prot.ligands if l.identifier.split(":")[1][:3] == hetid ][0] self.detect_from_ligand(ligand=lig)
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}'))
from ccdc.protein import Protein from hotspots.wrapper_pdb import PDBResult from hotspots.hs_pharmacophore import PharmacophoreModel from hotspots.calculation import Results from hotspots.hs_io import HotspotWriter, HotspotReader dirname = "./result" pdb = "1vr1" reps = "representatives.dat" if not os.path.exists(dirname): os.mkdir(dirname) 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",
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})
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 __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))