def __init__(self, pdb, name, charge=0, working_directory="antechamber", create_frcmod=True): amberhome = get_amberhome() utils.set_working_directory(working_directory) pdb.to_filename('ligand.pdb') antechamber_command = (amberhome + "/bin/antechamber " + "-i ligand.pdb -fi pdb -o {name}.prepc " "-fo prepc -rn {name} -c bcc -nc {charge} " "-at gaff2".format(name=name, charge=charge)) utils.run_in_shell(antechamber_command, 'antechamber.out') utils.check_file( name + '.prepc', "Antechamber failed to generate {name}.prepc file".format( name=name)) self.working_directory = os.getcwd() if create_frcmod: parmchk_command = ( amberhome + "/bin/parmchk2 " + "-i {name}.prepc -f prepc -o {name}.frcmod".format(name=name)) utils.run_in_shell(parmchk_command, 'parmchk2.out') # TODO: check for ATTN warnings os.chdir('..')
def __init__(self, pychemsh, working_directory='chemshell'): # get path information as needed utils.set_working_directory(working_directory) # get input files chemsh_input = ('../' + pychemsh + '.py') # run Py-ChemShell command chemshell_command = ('chemsh ' + chemsh_input) utils.run_in_shell(chemshell_command, "chemshell.out")
def __init__(self, pdb, working_directory="pdb4amber_reduce", pdb4amber_extra_args="", reduce_extra_args=""): amberhome = get_amberhome() utils.set_working_directory(working_directory) pdb.to_filename('input.pdb') pdb4amber_command = (amberhome + "/bin/pdb4amber " + pdb4amber_extra_args + " -i input.pdb -o pdb4amber.pdb --nohyd") utils.run_in_shell(pdb4amber_command, 'pdb4amber.out') reduce_command = (amberhome + "/bin/reduce " + reduce_extra_args + " -build -nuclear pdb4amber.pdb") utils.run_in_shell(reduce_command, 'reduce.pdb') with open('reduce.pdb') as f: self.pdb = pdb_utils.Pdb(f) renamed_histidines = get_renamed_histidines(self.pdb) residues = self.pdb.residues() for res_hash, res_name in renamed_histidines.items(): pdb_utils.modify_atoms(residues.get(res_hash, []), 'resName', res_name) # Remove hydrogens on HETATMs self.pdb.atoms = [ atom for atom in self.pdb.atoms if (atom['record'] != 'HETATM' or 'new' not in atom['extras']) ] # Remove hydrogens added by reduce to non-protein residues with open('pdb4amber_nonprot.pdb') as f: self.nonprotPdb = pdb_utils.Pdb(f) self.nonprot_residues = set(atom['resName'] for atom in self.nonprotPdb.atoms) self.pdb.atoms = [ atom for atom in self.pdb.atoms if (atom['resName'] not in self.nonprot_residues or 'new' not in atom['extras']) ] os.chdir('..')
def __init__(self, template_name, include=[], nonprot_residues=[], params={}, working_directory='tleap'): utils.set_working_directory(working_directory) enlighten_path = os.path.dirname(__import__(__name__).__file__) tleap_module_path = os.path.join(enlighten_path, 'tleap') template_path = os.path.join(tleap_module_path, template_name + '.in') template_contents = None if os.path.isfile(template_path): with open(template_path) as f: template_contents = f.read() params['include'] = get_tleap_includes(include, nonprot_residues) template_module = getattr( __import__('enlighten2.tleap', fromlist=[template_name]), template_name) params['pdb'].to_filename('input.pdb') with open('tleap.in', 'w') as f: f.write(template_module.run(params, template_contents)) utils.run_in_shell('tleap -f tleap.in', 'tleap.log') try: check_result = template_module.check(params, self) if check_result: sys.exit(check_result) except AttributeError: pass if 'export' in params: with open('params', 'w') as f: json.dump(params['export'], f) os.chdir('..')
def __init__(self, pdb, ph=7.0, ph_offset=0.7, working_directory="propka"): utils.set_working_directory(working_directory) pdb.to_filename('input.pdb') utils.run_in_shell("propka31 input.pdb", "propka31.out") with open('input.pka') as f: propka_results = parse_propka_output(f) self.pdb = pdb.copy() residues = self.pdb.residues() self.prot_pka = ph + ph_offset self.deprot_pka = ph - ph_offset self.prot_list = [] self.deprot_list = [] for hash, pka_entry in propka_results.items(): if hash not in residues: continue if prot_residue(pka_entry, self.prot_pka): pdb_utils.modify_atoms(residues[hash], 'resName', PROT_DICT[pka_entry['resName']]) self.prot_list.append(pka_entry) if deprot_residue(pka_entry, self.deprot_pka): pdb_utils.modify_atoms(residues[hash], 'resName', DEPROT_DICT[pka_entry['resName']]) self.deprot_list.append(pka_entry) # Need to remove hydrogens added by reduce on deprotonated # residues - else top-file creation will fail. self.pdb.remove_atom( pdb_utils.find_atom(residues[hash], lambda atom: 'new' in atom['extras'])) # Also remove HZ1 atoms from deprotonated LYS and CYS if pka_entry['resName'] == 'LYS': self.pdb.remove_atom( pdb_utils.find_atom( residues[hash], lambda atom: atom['name'] == 'HZ1')) if pka_entry['resName'] == 'CYS': self.pdb.remove_atom( pdb_utils.find_atom(residues[hash], lambda atom: atom['name'] == 'HG')) PRINT_PKA_FORMAT = "{resName:>6}{resSeq:>4}{chainID:>2}{pKa:>9.2f}" if len(self.prot_list) > 0: print("The following ASP/GLU residues have predicted pKa's above " "{:4.2f} and will be protonated (on OD2/OE2):".format( self.prot_pka)) print(" pKa") for pka_entry in self.prot_list: print(PRINT_PKA_FORMAT.format(**pka_entry)) if len(self.deprot_list) > 0: print("The following CYS/LYS residues have predicted pKa's below " "{:4.2f} and will be deprotonated:".format(self.deprot_pka)) print(" pKa") for pka_entry in self.deprot_list: print(PRINT_PKA_FORMAT.format(**pka_entry)) os.chdir('..')
def main(): parser = argparse.ArgumentParser( description="" "Prepares the simulation system by performing the following actions:\n" " - ligand parameterisation (with antechamber/prmchk2)\n" " - pdb protonation (apart from ligands, they need to " " be protonated already!)\n" " - tleap to solvate and write starting parm7/rst7 (top/rst)\n\n", formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument("name", help="name of the job") parser.add_argument("pdb", help="protonated PDB file", type=argparse.FileType()) parser.add_argument("ligand", help="name of the residue to be used as the ligand") parser.add_argument("charge", help="charge of the ligand", type=int) parser.add_argument("params", help="JSON file with advanced parameters", type=argparse.FileType(), nargs='?') args = parser.parse_args() job_name = args.name ligand_name = args.ligand ligand_charge = args.charge params = { 'antechamber': { 'ligand': args.ligand, 'charge': args.charge, 'ligand_chainID': "L", 'ligand_index': 1, }, 'propka': { 'with_propka': True, 'ph': 7.0, 'ph_offset': 0.7, }, 'tleap': { 'template': 'sphere', 'solvent_radius': 20.0, 'solvent_closeness': 0.75, 'include': [] } } if args.params is not None: params = utils.merge_dicts_of_dicts(params, json.load(args.params)) args.params.close() params['tleap']['include'] = [ os.path.abspath(path) for path in params['tleap']['include'] ] if os.path.exists(job_name): print("It appears you've already (attempted to) run prep.py with {0}. " "Delete folder {0} or rename pdb if you want to run it again.". format(job_name), file=sys.stderr) sys.exit(1) print("Starting PREP protocol in {}/".format(job_name)) sys.stdout.flush() utils.set_working_directory(job_name) pdb = pdb_utils.Pdb(args.pdb) ligand_index = params['antechamber']['ligand_index'] ligand_atoms = get_ligand_atoms(pdb, ligand_name, ligand_index) # Only generate ligand frcmod if it is not found in include paths ligand_frcmod = utils.file_in_paths(ligand_name + '.frcmod', params['tleap']['include']) antechamber = wrappers.AntechamberWrapper( pdb_utils.Pdb(atoms=ligand_atoms), ligand_name, ligand_charge, create_frcmod=ligand_frcmod is None) sys.stdout.flush() if ligand_frcmod is None: params['tleap']['include'].append(antechamber.working_directory) # Change ligand chain ID to ligand_chainID ligand_chainID = params['antechamber']['ligand_chainID'] pdb_utils.modify_atoms(ligand_atoms, 'chainID', ligand_chainID) # Run pdb4amber and reduce reduceResults = wrappers.Pdb4AmberReduceWrapper(pdb) sys.stdout.flush() pdb = reduceResults.pdb # Run propka31 if requested and found if params['propka']['with_propka']: pdb = run_propka(pdb=pdb, ph=params['propka']['ph'], ph_offset=params['propka']['ph_offset']) sys.stdout.flush() ligand = pdb.get_residues_by_name(ligand_name)[ligand_index - 1] params['tleap']['name'] = os.path.basename(job_name) params['tleap']['pdb'] = pdb params['tleap']['ligand'] = ligand tleap = wrappers.TleapWrapper(params['tleap']['template'], params['tleap']['include'], reduceResults.nonprot_residues, params['tleap']) sys.stdout.flush() os.system("cp {} .".format(tleap.top)) os.system("cp {} .".format(tleap.rst)) print("Finished PREP protocol.")
def main(): parser = argparse.ArgumentParser( description="" "Performs a fast equilibration of a simulation system " "prepared using prep.py. Does the following:" " - initial brief minimization of hydrogens (100 steps)" " - simulated annealing (10000 steps)" " - final brief minimization (100 steps)", formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument("system", help="name of the simulation system (as in prep.py)") parser.add_argument('-relax', action='store_true') parser.add_argument("params", help="additional parameters", type=argparse.FileType(), nargs='?') args = parser.parse_args() if not os.path.isdir(args.system): print("Directory {} is not found. Please run prep first.".format( args.system), file=sys.stderr) print( "If you HAVE run prep.sh, please run dynam.py " "from the same directory as prep.sh.", file=sys.stderr) exit(1) params = {"steps": 25000, "central_atom": None} if args.params is not None: params = {**params, **json.load(args.params)} args.params.close() prep_params_path = os.path.join(args.system, 'tleap', 'params') if os.path.isfile(prep_params_path): with open(prep_params_path, 'r') as f: params = {**params, **json.load(f)} mode = 'relax' if args.relax else 'dynam' if mode == 'relax': belly_radius = params["solvent_radius"] - 8 else: belly_radius = params["solvent_radius"] - 4 bellymask = ":{} <@{}".format(params["central_atom"], belly_radius) sander_params = {**params, "bellymask": bellymask} relax_params = [{ "name": "minimize_h_all", "template": "minh" }, { "name": "minimize_h_in_sphere", "template": "minh_ibelly", "params": sander_params }, { "name": "annealing_with_restraints", "template": "sa_ca", "params": sander_params }, { "name": "annealing_without_restraints", "template": "sa", "params": sander_params }, { "name": "minimize_all_in_sphere", "template": "min_ibelly", "params": sander_params }] dynam_params = [ { "name": "heat", "template": "heat", "params": sander_params }, { "name": "md", "template": "md", "params": sander_params, "monitor": True }, { "name": "minimize", "template": "min", "params": sander_params }, ] tleap_dir = os.path.abspath(os.path.join(args.system, 'tleap')) prmtop = "{}/{}.top".format(tleap_dir, args.system) if mode == 'relax': crd = "{}/{}.rst".format(tleap_dir, args.system) sanderflow_params = relax_params working_dir = '{}/{}'.format(args.system, 'relax') else: relax_dir = os.path.abspath(os.path.join(args.system, 'relax')) crd = "{}/{}_relax.rst".format(relax_dir, args.system) sanderflow_params = dynam_params working_dir = '{}/{}'.format(args.system, get_dynam_dir(args.system)) utils.set_working_directory(working_dir) status, result = sanderflow.run(prmtop, crd, sanderflow_params) if not status: sys.exit(1) final_crd = "{system}_{mode}.rst".format(system=args.system, mode=mode) os.system("cp {crd} {final_crd}".format(crd=result.crd, final_crd=final_crd))