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__('tleap', fromlist=[template_name]), template_name) params['pdb'].to_filename('input.pdb') params['water_pdb'].to_filename('water.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: template_module.check(params) except AttributeError: pass
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}".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: parmck_command = ( amberhome + "/bin/parmchk2 " + "-i {name}.prepc -f prepc -o {name}.frcmod".format(name=name)) utils.run_in_shell(parmck_command, 'parmchk2.out') # TODO: check for ATTN warnings 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'])) 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 __init__(self, pdb, working_directory="pdb4amber_reduce"): amberhome = get_amberhome() utils.set_working_directory(working_directory) pdb.to_filename('input.pdb') pdb4amber_command = (amberhome + "/bin/pdb4amber " "-i input.pdb -o pdb4amber.pdb --nohyd --dry") utils.run_in_shell(pdb4amber_command, 'pdb4amber.out') reduce_command = (amberhome + "/bin/reduce " "-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']) ] # store crystalline waters with open('pdb4amber_water.pdb') as f: self.waterPdb = pdb_utils.Pdb(f) os.chdir('..')
# # TEMP (TIRA): For fast debugging and testing # docs_train = docs_train[:100] # docs_test = docs_test[:100] # y_train = y_train[:100] # author_ids_test = author_ids_test[:100] X_train, X_test, clf, feature_names = extract_features( docs_train, docs_test, preset_key) cross_validate_model(clf, X_train, y_train) train_model_and_predict(clf, X_train, y_train, X_test, author_ids_test, preset_key, True, prediction_xmls_destination_main_directory) # Log run time print("@ %.2f seconds: Run finished\n", time.process_time()) ''' The following lines will be executed only if this .py file is run as a script, and not if it is imported as a module. • __name__ is one of the import-related module attributes, which holds the name of the module. • A module's __name__ is set to "__main__" when it is running in the main scope (the scope in which top-level code executes). ''' if __name__ == "__main__": logger = utils.configure_root_logger() utils.set_working_directory() main_development() print('executed successfully LR') # main_tira_evaluation()
} } if args.params is not None: params = utils.merge_dicts_of_dicts(params, json.load(args.params)) args.params.close() print("Starting PREP protocol in {}/".format(pdb_name)) if os.path.exists(pdb_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( pdb_name)) sys.exit() utils.set_working_directory(pdb_name) pdb = pdb_utils.Pdb(args.pdb) ligands = pdb.get_residues_by_name(ligand_name) if len(ligands) == 0: raise ValueError("No ligands found") ligand_index = params['antechamber']['ligand_index'] if ligand_index > len(ligands): raise ValueError("ligand_index is larger than the number of ligands") ligand_atoms = ligands[ligand_index - 1] if len(ligands) > 1: print("More than one ligand detected. Using coordinates from the ligand" " with chainID={} and resSeq={}".format(ligand_atoms[0]['chainID'],