def run(prefix): fn = 'test_remove_hg_from_zn_cys.pdb' f = open(fn, 'w') f.write(pdb_lines) f.close() cmd = 'qr.finalise %s action="capping"' % (fn) if 0: print(cmd) rc = easy_run.go(cmd) os.remove(fn) fnc = '%s_capping.pdb' % fn.replace('.pdb', '') f = open(fnc, 'r') lines = f.read() f.close() for line in [ ' HG CYS A 3', ' HG CYS A 8', ' HG CYS A 21', ' HG CYS A 25', ' HG CYS A 33', ' HG CYS A 48', ]: assert line not in lines, 'found %s' % line assert ' HE ARG A 10' in lines, 'not found HE ARG A 10' cmd = 'qr.charges %s verbose=1' % (fnc) if 0: print(cmd) rc = easy_run.go(cmd) assert 'Charge: -1' in rc.stdout_lines os.remove(fnc) return rc
def run(prefix): fn = 'test_remove_hg_from_zn_cys.pdb' f = file(fn, 'wb') f.write(pdb_lines) f.close() cmd = 'qr.finalise %s action="capping"' % (fn) if 0: print cmd rc = easy_run.go(cmd) os.remove(fn) fnc = '%s_capping.pdb' % fn.replace('.pdb', '') f = file(fnc, 'rb') lines = f.read() f.close() assert ' HG CYS A 3' not in lines assert ' HG CYS A 8' not in lines assert ' HG CYS A 21' not in lines assert ' HG CYS A 25' not in lines assert ' HG CYS A 33' not in lines assert ' HG CYS A 48' not in lines assert ' HE ARG A 10' in lines cmd = 'qr.charges %s verbose=1' % (fnc) if 0: print cmd rc = easy_run.go(cmd) assert 'Charge: -1' in rc.stdout_lines os.remove(fnc) return rc
def main(): tf = 'test_cis_127.pdb' f = file(tf, 'wb') f.write(pdb_lines) del f cmd = 'phenix.pdb_interpretation write_geo=True %s' % tf print(cmd) easy_run.go(cmd) f = file('%s.geo' % tf, 'rb') lines = f.read() del f find = '''angle pdb=" C GLY A 73 " pdb=" N PRO A 74 " pdb=" CA PRO A 74 " ideal model delta sigma weight residual 122.60 124.91 -2.31 5.00e+00 4.00e-02 2.14e-01''' assert lines.find(find) > -1 cmd = 'phenix.pdb_interpretation write_geo=True cis_pro_eh99=True %s' % tf print(cmd) easy_run.go(cmd) f = file('%s.geo' % tf, 'rb') lines = f.read() del f find = '''angle pdb=" C GLY A 73 " pdb=" N PRO A 74 " pdb=" CA PRO A 74 " ideal model delta sigma weight residual 127.00 124.91 2.09 2.40e+00 1.74e-01 7.57e-01''' assert lines.find(find) > -1
def tst_adding_disulfur_hydrogen_atoms(switch): element = 'H' if switch.endswith('_D'): element = 'D' fn = 'tst_ready_hydrogens_%s.pdb' % (switch) f = file(fn, 'wb') f.write(pdb_strings[switch]) del f pdb_inp = pdb_input(fn) hierarchy = pdb_inp.construct_hierarchy() from mmtbx.conformation_dependent_library.testing_utils import get_geometry_restraints_manager grm = get_geometry_restraints_manager(pdb_filename=fn) add_disulfur_hydrogen_atoms(grm, hierarchy, element=element) hierarchy.write_pdb_file(fn.replace('.pdb', '_updated.pdb')) if switch == 'CYS_1': f = file(fn.replace('.pdb', '_updated.pdb'), 'rb') lines = f.read() del f assert lines.find('HG') == -1 else: cmd = 'phenix.pdb_interpretation %s write_geo=True' % fn.replace( '.pdb', '_updated.pdb') print(cmd) easy_run.go(cmd) assert_lines_in_file(file_name='%s.geo' % fn.replace('.pdb', '_updated.pdb'), lines=geo_strings[switch])
def run(args, log=sys.stdout): if (len(args) == 0): parsed = defaults(log=log) parsed.show(prefix=" ", out=log) return parsed = defaults(log=log) processed_args = mmtbx.utils.process_command_line_args( args=args, log=sys.stdout, master_params=parsed) processed_args.params.show() params = processed_args.params.extract() if (len(processed_args.pdb_file_names) == 0): raise Sorry("No PDB file found.") if (len(processed_args.pdb_file_names) > 1): raise Sorry("More than one PDB file found.") pdb_file_name = processed_args.pdb_file_names[0] if (params.f_obs.f_calc.atomic_model.add_hydrogens): pdb_file_name_r = os.path.basename(pdb_file_name) + "_reduce" easy_run.go("phenix.reduce %s > %s" % (pdb_file_name, pdb_file_name_r)) pdb_file_name = pdb_file_name_r pdb_inp = iotbx.pdb.input(file_name=pdb_file_name) pdbi_params = mmtbx.monomer_library.pdb_interpretation.master_params.extract( ) if (params.f_obs.f_calc.atomic_model.use_ramachandran_plot_restraints): pdbi_params.peptide_link.ramachandran_restraints = True processed_pdb_file = monomer_library.pdb_interpretation.process( pdb_inp=pdb_inp, mon_lib_srv=monomer_library.server.server(), ener_lib=monomer_library.server.ener_lib(), params=pdbi_params) pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy pdb_hierarchy.atoms().reset_i_seq() xray_structure = processed_pdb_file.xray_structure() mmtbx.utils.assert_xray_structures_equal( x1=xray_structure, x2=pdb_inp.xray_structure_simple()) sctr_keys = xray_structure.scattering_type_registry().type_count_dict( ).keys() has_hd = "H" in sctr_keys or "D" in sctr_keys geometry = processed_pdb_file.geometry_restraints_manager( show_energies=False, plain_pairs_radius=5, assume_hydrogens_all_missing=not has_hd) restraints_manager = mmtbx.restraints.manager(geometry=geometry, normalization=True) root = iotbx.pdb.hierarchy.root() loop_1(params=params, root=root, xray_structure=xray_structure, pdb_hierarchy=pdb_hierarchy, restraints_manager=restraints_manager) root.write_pdb_file( file_name=params.f_obs.f_calc.atomic_model.output_file_name, crystal_symmetry=xray_structure.crystal_symmetry()) simulate_f_obs(root=root, crystal_symmetry=xray_structure.crystal_symmetry(), params=params)
def run(args, log = sys.stdout): if(len(args)==0): parsed = defaults(log=log) parsed.show(prefix=" ", out=log) return parsed = defaults(log=log) processed_args = mmtbx.utils.process_command_line_args(args = args, log = sys.stdout, master_params = parsed) processed_args.params.show() params = processed_args.params.extract() if(len(processed_args.pdb_file_names)==0): raise Sorry("No PDB file found.") if(len(processed_args.pdb_file_names)>1): raise Sorry("More than one PDB file found.") pdb_file_name = processed_args.pdb_file_names[0] if(params.f_obs.f_calc.atomic_model.add_hydrogens): pdb_file_name_r = os.path.basename(pdb_file_name)+"_reduce" easy_run.go("phenix.reduce %s > %s"% (pdb_file_name, pdb_file_name_r)) pdb_file_name = pdb_file_name_r pdb_inp = iotbx.pdb.input(file_name = pdb_file_name) pdbi_params = mmtbx.monomer_library.pdb_interpretation.master_params.extract() if(params.f_obs.f_calc.atomic_model.use_ramachandran_plot_restraints): pdbi_params.peptide_link.ramachandran_restraints=True processed_pdb_file = monomer_library.pdb_interpretation.process( pdb_inp = pdb_inp, mon_lib_srv = monomer_library.server.server(), ener_lib = monomer_library.server.ener_lib(), params = pdbi_params) pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy pdb_hierarchy.atoms().reset_i_seq() xray_structure = processed_pdb_file.xray_structure() mmtbx.utils.assert_xray_structures_equal(x1 = xray_structure, x2 = pdb_inp.xray_structure_simple()) sctr_keys=xray_structure.scattering_type_registry().type_count_dict().keys() has_hd = "H" in sctr_keys or "D" in sctr_keys geometry = processed_pdb_file.geometry_restraints_manager( show_energies = False, plain_pairs_radius = 5, assume_hydrogens_all_missing = not has_hd) restraints_manager = mmtbx.restraints.manager( geometry = geometry, normalization = True) root = iotbx.pdb.hierarchy.root() loop_1( params = params, root = root, xray_structure = xray_structure, pdb_hierarchy = pdb_hierarchy, restraints_manager = restraints_manager) root.write_pdb_file( file_name = params.f_obs.f_calc.atomic_model.output_file_name, crystal_symmetry = xray_structure.crystal_symmetry()) simulate_f_obs(root=root, crystal_symmetry=xray_structure.crystal_symmetry(), params = params)
def main(): for code, item in pdbs.items(): print(code) pf = 'tst_fe_s_%s.pdb' % code with open(pf, 'w') as f: f.write(item[0]) cmd = 'phenix.pdb_interpretation %(pf)s > %(pf)s.log' % locals() print(cmd) easy_run.go(cmd) print(item[1]) for line in item[1].split('\n'): print(line) assert_lines_in_file(file_name='%s.log' % pf, lines=line)
def get_miller_arrays(pdb,cif,mtz_folder): """ convert cif to mtz and write it in the mtz_folder convert cif of the format 'r_name_sf.ent.gz' to mtz file creates mtz file with crystal symmetry in current folder Returns: """ if not (os.path.isfile(pdb) and os.path.isfile(cif)): return None pdb_id = get_4_letters_pdb_id(cif) mtz_fn = os.path.join(mtz_folder, pdb_id + '.mtz') cmd_list = [] cmd_list.append('phenix.cif_as_mtz') cmd_list.append(cif) cmd_list.append('--output-file-name={}'.format(mtz_fn)) cmd_list.append("--merge") cmd_list.append("--remove-systematic-absences") cmd_list.append("--map-to-asu") cmd_list.append("--ignore-bad-sigmas") cmd_list.append("--extend-flags") cmd = ' '.join(cmd_list) r = easy_run.go(cmd) # NOTE !!! in windows r does not returns the errors as expected tmp = [x for x in r.stdout_lines if '--' in x] tmp2 = ''.join(tmp) run_cmd_again = False if '--incompatible_flags_to_work_set' in tmp2: cmd_list.append('--incompatible_flags_to_work_set') run_cmd_again = True if '--symmetry' in tmp2: cmd_list.append('--symmetry={}'.format(pdb)) run_cmd_again = True if run_cmd_again: cmd = ' '.join(cmd_list) easy_run.go(cmd) try: # Get miller arrays from mtz file mtz_object = iotbx.mtz.object(file_name=mtz_fn) miller_arrays = mtz_object.as_miller_arrays() except: miller_arrays = None # cleanup os.remove(cif) if not miller_arrays: return None return miller_arrays
def main(): i=0 filename = 'cdl_nucleotide.pdb' f=open(filename, 'w') f.write(pdb) del f for param1 in range(2): if param1 and not restraintlib_installed: break for param2 in ['phenix', 'csd']: cmd = 'phenix.pdb_interpretation %s write_geo=True cdl_nucleotides=%s cdl_nucleotides_esd=%s' % ( filename, param1, param2, ) print(i, param1, param2, cmd) rc = easy_run.go(cmd) lines=[] for line in rc.stdout_lines: lines.append(line.strip()) for line in std_asserts[i]: assert line in lines, 'missing %s' % line f=open('%s.geo' % filename, 'r') lines=f.read() del f for line in geo_asserts[i]: assert lines.find(line)>-1, 'missing %s' % line i+=1 print('OK') print('OK')
def main(): with open('tst_mcl_02.pdb', 'w') as f: f.write(pdb_string) cmd = 'phenix.pdb_interpretation tst_mcl_02.pdb write_geo=1' print(cmd) rc = easy_run.go(cmd) assert os.path.exists('tst_mcl_02.pdb.geo') return rc.return_code
def run_cmd(prefix, args, pdb_name="m00_poor.pdb", mtz_name="m00_good.mtz"): test_folder_name = prefix cmd = ["qr.refine", mtz_name, os.path.join(qr_unit_tests_data, pdb_name)] for arg in args: cmd.append(arg) cmd.append("output_folder_name=%s" % test_folder_name) cmd.append("> %s.log" % prefix) if (0): print " ".join(cmd) return easy_run.go(" ".join(cmd))
def main(): input_model_filename = 'carbo_linking_output.pdb' with open(input_model_filename, 'w') as f: f.write(input_model) cmd = 'phenix.pdb_interpretation %s' % input_model_filename rc = easy_run.go(cmd) lines = '\n'.join(rc.stdout_lines) assert lines.find(result) > -1 print('OK')
def run(prefix): """ Make sure 'qr.charges tst_22.pdb' runs without errors (finishes successfully). """ pdb_name = os.path.join(qr_unit_tests_data, "tst_22.pdb") cmd = "qr.charges %s verbose=False" % pdb_name if (0): print cmd r = easy_run.go(cmd) # Make sure no assert len(r.stderr_lines) == 0, r.stderr_lines assert len(r.stdout_lines) == 0, r.stdout_lines
def run(prefix): fn = 'test_zn_his_charge.pdb' f = open(fn, 'w') f.write(pdb_lines) f.close() cmd = 'qr.charges %s verbose=1' % (fn) if 0: print(cmd) rc = easy_run.go(cmd) assert 'Charge: 0' in rc.stdout_lines os.remove(fn) return rc
def main(): for i, pdb_str in enumerate([pdb_str_1, pdb_str_2]): print(i) fn = 'tst_mcl_%d.pdb' % i with open(fn, 'w') as f: f.write(pdb_str) cmd = 'phenix.pdb_interpretation %s write_geo=true' % fn print(cmd) rc = easy_run.go(cmd) assert os.path.exists('%s.geo' % fn) assert not rc.return_code
def run(prefix): fn = 'test_cu_cys.pdb' f = open(fn, 'w') f.write(pdb_lines) f.close() cmd = 'qr.finalise %s action="capping"' % (fn) if 0: print(cmd) rc = easy_run.go(cmd) os.remove(fn) fnc = '%s_capping.pdb' % fn.replace('.pdb', '') f = open(fnc, 'r') lines = f.read() f.close() assert ' HG CYS A 78' not in lines cmd = 'qr.charges %s verbose=1' % (fnc) if 0: print(cmd) rc = easy_run.go(cmd) assert 'Charge: 0' in rc.stdout_lines os.remove(fnc) return rc
def tst_adding_side_chain_acid_hydrogen_atoms(switch): element = 'H' if switch.endswith('_D'): element = 'D' for i in range(4): fn = 'tst_ready_hydrogens_%s_%d.pdb' % (switch, i) with open(fn, 'w') as f: f.write(pdb_strings[switch]) pdb_inp = pdb_input(fn) hierarchy = pdb_inp.construct_hierarchy() add_side_chain_acid_hydrogens(hierarchy, configuration_index=i, element=element) hierarchy.write_pdb_file(fn.replace('.pdb', '_updated.pdb')) cmd = 'phenix.pdb_interpretation %s flip_sym=0 write_geo=True' % fn.replace( '.pdb', '_updated.pdb') print(cmd) easy_run.go(cmd) assert_lines_in_file(file_name='%s.geo' % fn.replace('.pdb', '_updated.pdb'), lines=geo_strings[switch][i])
def find_majority_blame(full_path): cmd = 'git blame %s' % full_path rc = easy_run.go(cmd) blames = {} for line in rc.stdout_lines: key = line[line.find('(') + 1:line.find('(') + 11] blames.setdefault(key, 0) blames[key] += 1 m = max(blames.values()) for key, item in blames.items(): if item == m: return key
def run(prefix): fn = 'test_one_alt_loc.pdb' f = file(fn, 'wb') f.write(pdb_lines) f.close() cmd = 'qr.charges %s verbose=1' % (fn) if 0: print cmd rc = easy_run.go(cmd) assert 'Charge: -2' in rc.stdout_lines os.remove(fn) return rc
def test_running_from_command_line(): ''' Make sure mmtbx.nonbonded_overlaps can run without errors ''' file_name = 'test_pdb_file.pdb' if not os.path.isfile(file_name): open(file_name,'w').write(raw_records_1) #self.file_to_delete.append(self.file_name) cmd = 'mmtbx.nonbonded_overlaps {}' cmd = cmd.format(file_name) r = easy_run.go(cmd, join_stdout_stderr=False) assert(not bool(r.stderr_lines))
def run(prefix): fn = 'expansion.pdb' f = open(fn, 'w') f.write(expansion) f.close() fn = 'test_alt_loc_original.pdb' f = open(fn, 'w') f.write(pdb_lines) f.close() cmd = 'phenix.python %s/completion.py %s model_completion=False original_pdb_filename=expansion.pdb' % ( qrefine_path, fn) if 0: print(cmd) easy_run.go(cmd) fnc = '%s_capping.pdb' % fn.replace('.pdb', '') cmd = 'phenix.pdb_interpretation %s' % fnc if 0: print(cmd) rc = easy_run.go(cmd) assert ' H 47 1.00' in rc.stdout_lines os.remove(fn) os.remove(fnc) return rc
def main(): tf = 'test_cis_127.pdb' with open(tf, 'w') as f: f.write(pdb_lines[0]) cmd = 'phenix.pdb_interpretation write_geo=True cis_pro_eh99=False %s' % tf print(cmd) easy_run.go(cmd) with open('%s.geo' % tf, 'r') as f: lines = f.read() find = '''angle pdb=" C GLY A 73 " pdb=" N PRO A 74 " pdb=" CA PRO A 74 " ideal model delta sigma weight residual 122.60 124.91 -2.31 5.00e+00 4.00e-02 2.14e-01''' assert lines.find(find)>-1 cmd = 'phenix.pdb_interpretation write_geo=True cis_pro_eh99=True %s' % tf print(cmd) easy_run.go(cmd) with open('%s.geo' % tf, 'r') as f: lines = f.read() find = '''angle pdb=" C GLY A 73 " pdb=" N PRO A 74 " pdb=" CA PRO A 74 " ideal model delta sigma weight residual 127.00 124.91 2.09 2.40e+00 1.74e-01 7.57e-01''' assert lines.find(find)>-1 tf = 'test_cis_127_1.pdb' with open(tf, 'w') as f: f.write(pdb_lines[1]) cmd = 'phenix.pdb_interpretation write_geo=True cis_pro_eh99=True %s' % tf print(cmd) easy_run.go(cmd) assert os.path.exists('%s.geo' % tf), 'command failed due to missing CD'
def run(): print 'test' f = file('tst_mol_args.pdb', 'wb') f.write(pdb_str) f.close() results = {} for keep_hydrogen in range(3): for nuclear in range(2): cmd = 'phenix.clashscore tst_mol_args.pdb' if keep_hydrogen != 2: cmd += ' keep_hydrogen=%(keep_hydrogen)s' % locals() cmd += ' nuclear=%(nuclear)s' % locals() print 'CMD', cmd rc = easy_run.go(cmd) clashscore1 = get_clashscore(rc.stdout_lines) print clashscore1 results[cmd] = clashscore1 cmd = 'phenix.molprobity tst_mol_args.pdb' if keep_hydrogen != 2: cmd += ' keep_hydrogen=%(keep_hydrogen)s' % locals() cmd += ' pdb_interpretation.use_neutron_distances=%(nuclear)s' % locals( ) print 'CMD', cmd rc = easy_run.go(cmd) clashscore2 = get_clashscore(rc.stdout_lines) print clashscore2 results[cmd] = clashscore2 print '-' * 80 for cmd, c in results.items(): print cmd, c assert clashscore1 == clashscore2, 'molprobity does not match clashscore %s %s: %.f != %.f' % ( keep_hydrogen, nuclear, clashscore1, clashscore2, )
def run(self): model = self.data_manager.get_model() if not model.has_hd(): raise Sorry('Model has no hydrogen atoms! Please add H/D and try again.') cpptraj_exe = os.path.join(amber_dir, 'bin', 'cpptraj' ) preamble = self.data_manager.get_model_names()[0].split('.')[0] print(''' Running cpptraj executable %s on input """ %s """ ''' % ( cpptraj_exe, input_str % locals())) rc = easy_run.go(command=cpptraj_exe, stdin_lines=input_str % locals(), ) rc.show_stdout() print(' Writing H-bonds to %(preamble)s.hbond.dat' % locals()) f=file('%(preamble)s.hbond.dat' % locals(), 'rb') lines = f.read() f.close() if self.params.output.list_h_bonds: print() print(lines) nr = get_number_of_residues(model.get_hierarchy()) if self.params.output.show_number_of_h_bonds_per_1000: h_bonds = len(lines.splitlines())-1 atoms = len(model.get_hierarchy().atoms()) print('_'*80) print(''' Number of H-bonds found : %7d Number of atoms : %7d H-bonds per 1000 atoms : %10.2f H-bonds per residues : %10.2f ''' % (h_bonds, atoms, h_bonds/atoms*1000, h_bonds/nr, ))
def get_updated_file_name(file_name,out_folder='',use_reduce=True): """ When using ready_set or reduce, a new file will be created, one that includes hydrogens. This function finds the new name and returns it Args: file_name: pdb file name including path that should be processed using ready_set or reduce use_reduce (bool): When True use phenix.reduce, otherwise phenix.ready_set out_folder (str): the folder where the updated file will be writen (when different than the source file location) Return: file_name: the file name of the modified pdb file, the one that includes hydrogens """ (path,file_name) = os.path.split(file_name) pdb_id = get_pdb_id(file_name) if out_folder: path = out_folder tmp = file_name.split('.') # check that the file is not already an updated file if not (len(tmp)==3 and tmp[1] == 'updated'): file_name = get_file_from_rcsb(pdb_id) # stop processing if file_name was not found if not os.path.isfile(file_name): return '' reduce = 'phenix.reduce {0} > {1}.updated.pdb' ready_set = '{0}.updated.{1}' if use_reduce: #file_name = file_name[-8:] cmd = reduce.format(file_name,pdb_id) else: cmd = 'phenix.ready_set {0}'.format(file_name) # probe_out = easy_run.go(cmd) # getting to modified file name if use_reduce: file_name = ready_set.format(tmp[0],tmp[-1]) else: line = [x for x in probe_out.stdout_lines if 'Writing model to' in x] if line != []: file_name = line[0].split('Writing model to ')[-1] else: collect_sorry = [x for x in probe_out.stdout_lines if 'Sorry:' in x] for x in collect_sorry: print x return file_name
def run(): f = open('tst_pH_gnp.pdb', 'w') f.write(gnp) f.close() cmd = 'phenix.geometry_minimization tst_pH_gnp.pdb' rc = easy_run.go(cmd) find = [ 'Changed 28 bond restraint(s), added 1 bond restraint(s)', 'Changed 43 angle restraint(s), added 1 angle restraint(s)', ] for f in find: for line in rc.stdout_lines: if line.find(f) > -1: print(line) break else: assert 0, 'line not found: %s' % f return rc
def run_qm_cmd( cmd, log_filename, error_lines=None, redirect_output=True, log=None, verbose=False, ): def loop_over_list(l): for line in l: yield l import time t0 = time.time() if verbose: print('run_qm_cmd', cmd, log_filename) if redirect_output: cmd += ' >& %s' % log_filename print(' Starting : %s' % cmd, file=log) rc = easy_run.go(cmd) if not os.path.exists(log_filename): raise Sorry('QM program did not appear to write log file : %s' % log_filename) generator = loop_over_file(log_filename) # if redirect_output: # generator = loop_over_file(log_filename) # else: # generator = loop_over_list(rc.stdout_lines) status = process_qm_log_file(generator=generator, error_lines=error_lines, log=log) if rc.stderr_lines: print('stderr') for line in rc.stderr_lines: print(line) print('stdout') for line in rc.stdout_lines: print(line) assert 0 return rc
def process_file(file_name): """ Get pdb id and pdb file """ _,fn = os.path.split(file_name) pdb_id = get_pdb_id(fn) # Get files in pdb format even when at LBL, to avoid issues with phenix.reduce if ('_mirror' in file_name) or (file_name == pdb_id): file_name = pdb_id + '.pdb' file_to_clean = [] if not os.path.isfile(file_name): # leave file in folder if it was already there # cmd = 'phenix.fetch_pdb {} --all'.format(pdb_id) cmd = 'phenix.fetch_pdb {}'.format(pdb_id) r = easy_run.go(cmd,join_stdout_stderr=False) for fn in r.stdout_lines: fn = os.path.split(fn)[-1] if '.pdb' in fn: file_name = fn file_to_clean.append(fn) fn = fn.replace('.pdd','_with_h.pdb') file_to_clean.append(fn) return file_name,pdb_id,file_to_clean
def run(): work_dir = '/net/cci-filer2/raid1/home/youval/Work/work/junk' os.chdir(work_dir) # #file_name = '3zzv' #file_name = '4iw4' #file_name = '2btv' files = set(['3m8l', '2btv', '1vcr', '1llc', '3dpr', '3dar', '2w4y', '2zah', '1tnv', '1dwn', '2w0c', '1w39', '1x33', '2izw', '1x35', '3nop', '2bny', '1ei7', '3not', '3nou', '1dzl', '3lob', '3nap', '1vsz']) for fn in files: sf_fn = fetch.get_pdb (fn,'xray',mirror='rcsb',log=sys.stdout,format='cif') cmd = 'phenix.cif_as_mtz {0} --output-file-name=tmp_file.mtz --merge --remove-systematic-absences --map-to-asu --extend-flags'.format(sf_fn) r = easy_run.go(cmd) print 'Results for file: {}'.format(fn) print '-'*60 for x in r.stdout_lines: print x print '='*60
def get_new_file_name(file_name): '''(str) -> str When using ready_set or reduce, a new file will be created, one that includes hydrogens. This function finds the new name and returns it Argument: file_name: a file name of a pdb file, including the path, that was processed using ready_set or reduce Return: file_name: the file name of the modified pdb file, the one that includes hydrogens ''' tmp = file_name.split('.') if not (len(tmp)==3 and tmp[1] == 'updated'): file_name = get_pdb_file(file_name,fetch_file=True,print_out=False) # when using phenix.reduce #file_name = file_name[-8:] cmd = 'phenix.reduce {0} > {1}.updated.{2}'.format(file_name,tmp[0],tmp[-1]) # when using ready_set #cmd = 'phenix.ready_set {0}'.format(file_name) # probe_out = easy_run.go(cmd) # getting to modified file name # when using phenix.reduce file_name = '{0}.updated.{1}'.format(tmp[0],tmp[-1]) # when using ready_set #line = [x for x in probe_out.stdout_lines if 'Writing model to' in x] #if line != []: #file_name = line[0].split('Writing model to ')[-1] #else: #collect_sorry = [x for x in probe_out.stdout_lines if 'Sorry:' in x] #for x in collect_sorry: #print x return file_name
write_tardy_geo_files = False .type = bool include scope mmtbx.monomer_library.pdb_interpretation.grand_master_phil_str """, process_includes=True) if __name__=='__main__': print '*'*80 # set work folder set_working_path('Clashes\junk') print 'Current working path {}'.format(os.getcwd()) #file_name = get_pdb_file('3e8k.pdb') file_name = get_pdb_file('101m_H.pdb') #cmd = 'phenix.ready_set {}'.format(file_name) #print 'Running: {}'.format(cmd) #print '*'*80 #probe_out = easy_run.go(cmd) ## getting to modified file name #line = [x for x in probe_out.stdout_lines if 'Writing model to' in x] #file_name = line[0].split('Writing model to ')[-1] print 'Using the file {}, the file returned from phenix.ready_set'.format(file_name) #print '*'*80 out = easy_run.go('phenix.clashscore {} keep_hydrogens=True'.format(file_name)) #print 'phenix.{}'.format(out.stdout_lines[-1]) for l in out.stdout_lines: print l print '*'*80 # Call the new clashscore run([file_name])
def run(): fn = '4udx_sf4.pdb' f = file(fn, 'wb') f.write(pdbs[fn]) f.close() for i, superpose in enumerate(['None', 'all']): cmd = 'phenix.geometry_minimization %s superpose_ideal=%s' % ( fn, superpose, ) print cmd rc = easy_run.go(cmd) for line in rc.stdout_lines: #print line if line.find('bond_residual_sum') > -1: bond_value = round(float(line.split()[-1])) if line.find('angle_residual_sum') > -1: angle_value = round(float(line.split()[-1])) # in the second iteration bond_value and angle_value are expected to be 0! # assert bond_value, "%f %f" % (bond_value, results[fn][i][0]) # assert angle_value, angle_value assert bond_value == results[fn][i][0], 'not matching %s to %s' % ( bond_value, results[fn][i][0], ) assert angle_value == results[fn][i][1], 'not matching %s to %s' % ( angle_value, results[fn][i][1], ) for i, superpose in enumerate(['None', 'all']): cmd = 'phenix.pdb_interpretation %s superpose_ideal=%s' % ( fn, superpose, ) print cmd rc = easy_run.go(cmd) for line in rc.stdout_lines: #print line if line.find('bond_residual_sum') > -1: value = round(float(line.split()[-1])) print 'value', value assert value == results[fn][i][2], 'not matching %s to %s' % ( value, results[fn][i][2], ) if line.find('angle_residual_sum') > -1: value = round(float(line.split()[-1])) print 'value', value assert value == results[fn][i][3], 'not matching %s to %s' % ( value, results[fn][i][3], ) fn = '4udx_sf4_cys.pdb' f = file(fn, 'wb') f.write(pdbs[fn]) f.close() # lines = ''' # SF4/F3S coordination # SF4 X1001 # pdb="FE1 SF4 X1001 " - pdb=" SG CYS X 51 " # pdb="FE2 SF4 X1001 " - pdb=" SG CYS X 48 " # pdb="FE3 SF4 X1001 " - pdb=" SG CYS X 56 " # pdb="FE4 SF4 X1001 " - pdb=" SG CYS X 70 "''' from libtbx.test_utils import assert_lines_in_file lines = [ 'SF4/F3S coordination', 'SF4 X1001', 'pdb="FE1 SF4 X1001 " - pdb=" SG CYS X 51 "', 'pdb="FE4 SF4 X1001 " - pdb=" SG CYS X 70 "', 'pdb="FE3 SF4 X1001 " - pdb=" SG CYS X 56 "', 'pdb="FE2 SF4 X1001 " - pdb=" SG CYS X 48 "', ] cmd = 'phenix.pdb_interpretation %s link_all=True > %s.log' % (fn, fn) print cmd assert not easy_run.call(cmd) for line in lines: print line assert_lines_in_file(file_name='%s.log' % fn, lines=line) return 0
def run(): msg = [ '', 'Welcome to the Q|R interface checker', '', ] draw_box_around_text(msg, width=78) cmd = 'java -version' rc = easy_run.go(cmd) for line in rc.stdout_lines: if line.find('java version') > -1: version = line.split('"')[1][:3] if float(version) < 1.8: print ''' Need at least Java 1.8. Please update your system Java using a JDK bundle and try again. ''' sys.exit() java_env_vars = { 'JAVA_HOME': 'absolute_path_of_java_home', 'JAVA_LIB_PATH': 'absolute_path_of_java_lib', 'LD_LIBRARY_PATH': '$LD_LIBRARY_PATH:$JAVA_LIB_PATH/server', } count = 0 for env_var in java_env_vars: print ' Set? "%s" "%s"' % (env_var, os.environ.get(env_var, False)) if not os.environ.get(env_var, False): print ''' The following environment variables need setting. ''' for env_var, help in java_env_vars.items(): print '%s %s : %s' % (' ' * 10, env_var, help) if env_var.startswith('JAVA'): print ''' On OSX use /usr/libexec/java_home -v 1.8 to find the install directory ''' elif env_var == 'LD_LIBRARY_PATH': print ''' The Phenix environment ignores the user set LD_LIBRARY_PATH unless the environmental variable PHENIX_TRUST_OTHER_ENV is set. ''' count += 1 break else: print '\n Java appears to be installed\n' if count: print ' STOPPING' sys.exit() qm_engine_env_vars = { 'MOPAC_COMMAND': 'Mopac executable', 'TERACHEM_COMMAND': 'TeraChem directory', } count = [] for env_var in qm_engine_env_vars: if os.environ.get(env_var, False): print '\n Environmental variable %s set for "%s" to "%s"\n' % ( env_var, qm_engine_env_vars[env_var], os.environ[env_var], ) if not os.path.exists(os.environ[env_var]): print ''' Environmental variable "%s" : "%s" does not point to anything! STOPPING ''' % (env_var, os.environ[env_var]) sys.exit() count.append(env_var) else: print ' Environmental variable %s for "%s" not found\n' % ( env_var, qm_engine_env_vars[env_var], ) if count: print ''' QM engines set ''' for env_var in count: print '%s %s : %s' % (' ' * 10, env_var, os.environ[env_var]) print else: print ''' No QM engines found! Install and set an environmental variable from the list. ''' for env_var, help in qm_engine_env_vars.items(): print '%s %s : %s' % (' ' * 10, env_var, help) print draw_box_around_text( ['', 'Done!', '', 'Run a Q|R job using qr.refine', ''])
def run(args): """ Run one of the following refinements: -no_ncs -cartesian_ncs_restraints -torsion_ncs_restraints -ncs_constraints_no_operators -ncs_constraints_all Args: args should contain: pdb_id (str) one of the refinements types -again : when this option present, erase previous refinement results Examples: >>>pyhton run_refinement_test.py 1vcr -no_ncs >>>pyhton run_refinement_test.py 1vcr -torsion_ncs_restraints -again """ osType = sys.platform assert not ('win' in osType),'Please run on LBL machine' delete_existing_results = '-again' in args if delete_existing_results: args.pop(args.index('-again')) assert len(args) == 2, 'Not enough parameters provided' # collect files and set working directories pdb_id = args[0] refine_method = args[1] c = collect_ncs_files.ncs_paper_data_collection() pdb = os.path.join(c.asu_dir,pdb_id + '.pdb') mtz = os.path.join(c.mtz_dir,pdb_id + '.mtz') cif = os.path.join(c.cif_dir,pdb_id + '.ligands.cif') if not os.path.isfile(cif): cif = '' files = '{} {} {} '.format(pdb,mtz,cif) refinement_dir_list = collect_ncs_files.get_refinement_folders() # refinement string s = 'optimize_xyz=true ' s += 'optimize_adp=true strategy=individual_sites+individual_adp' option_list = [ '-no_ncs', '-cartesian_ncs_restraints', '-torsion_ncs_restraints', '-ncs_constraints_sites_no_operators', '-ncs_constraints_sites_operators', '-ncs_constraints_adp_operators', '-ncs_constraints_all'] # remove limits on ncs distance dist_limit = ' refinement.ncs.excessive_distance_limit=None ' cmd_option_list = [ s, 'main.ncs=True ncs.type=cartesian ' + s, 'main.ncs=True ' + s, 'ncs_search=true refine_operators=false strategy=individual_sites', 'ncs_search=true refine_operators=true strategy=individual_sites', 'ncs_search=true refine_operators=true strategy=individual_adp', 'ncs_search=true refine_operators=true strategy=individual_adp+individual_sites'] i = option_list.index(refine_method) cmd_option = cmd_option_list[i] out_folder = refinement_dir_list[i] # cmd = 'phenix.refine {} {} '.format(files,cmd_option) + dist_limit # Run refinement current_dir = os.getcwd() make_new_folder = True os.chdir(out_folder) if os.path.isdir(pdb_id): try: # remove if empty os.rmdir(pdb_id) except OSError: if delete_existing_results: shutil.rmtree(pdb_id) else: print 'refinement results already exist for:',pdb_id make_new_folder = False if make_new_folder: os.mkdir(pdb_id) os.chdir(pdb_id) # r = easy_run.fully_buffered(cmd) r = easy_run.go(cmd) os.chdir(current_dir) print 'Done'
def run(): msg = [ '', 'Welcome to the Q|R interface checker', '', 'For more information: https://github.com/qrefine/qrefine/wiki/Installation', ] draw_box_around_text(msg, width=78) cmd = 'java -version' rc = easy_run.go(cmd) for line in rc.stdout_lines: if line.find('java version') > -1: version = line.split('"')[1][:3] if float(version) < 1.8: print(''' Need at least Java 1.8. Please update your system Java using a JDK bundle and try again. ''') sys.exit() java_env_vars = { 'JAVA_HOME': 'absolute_path_of_java_home', 'JAVA_LIB_PATH': 'absolute_path_of_java_lib', 'LD_LIBRARY_PATH': '$LD_LIBRARY_PATH:$JAVA_LIB_PATH/server', } count = 0 for env_var in java_env_vars: print(' Set? "%s" "%s"' % (env_var, os.environ.get(env_var, False))) if not os.environ.get(env_var, False): print(''' The following environment variables need setting. ''') for env_var, help in java_env_vars.items(): print('%s %s : %s' % (' ' * 10, env_var, help)) if env_var.startswith('JAVA'): print(''' On OSX use /usr/libexec/java_home -v 1.8 to find the install directory ''') elif env_var == 'LD_LIBRARY_PATH': print(''' The Phenix environment ignores the user set LD_LIBRARY_PATH unless the environmental variable PHENIX_TRUST_OTHER_ENV is set. ''') count += 1 break else: print('\n Java appears to be installed\n') if count: print(' STOPPING') #sys.exit() qm_engine_env_vars = { 'MOPAC_COMMAND': 'Mopac executable', 'TERACHEM_COMMAND': 'TeraChem directory', 'Orca_COMMAND': 'Orca directory', 'XTBHOME': 'XTB directory', 'g16root': 'Gaussian 16 directory', 'TURBODIR ': 'Turbomole directory', } count = [] for env_var in qm_engine_env_vars: if os.environ.get(env_var, False): print('\n Environmental variable %s set for "%s" to "%s"\n' % ( env_var, qm_engine_env_vars[env_var], os.environ[env_var], )) if not os.path.exists(os.environ[env_var]): print(''' Environmental variable "%s" : "%s" does not point to anything! STOPPING ''' % (env_var, os.environ[env_var])) sys.exit() count.append(env_var) else: print(' Environmental variable %s for "%s" not found\n' % ( env_var, qm_engine_env_vars[env_var], )) qm_engines_python = { 'PyScf': ' A collection of electronic structure programs powered by Python', 'ANI': 'ANI-1 neural net potential with python interface (ASE)', 'TorchANI': 'Accurate Neural Network Potential on PyTorch' } qm_engines_python_installed = {} for name, description in qm_engines_python.items(): if name == 'PyScf': try: import pyscf print(" PyScf successfully imported") qm_engines_python_installed[name] = description except: print(" PyScf could not be imported") if name == 'TorchANI': try: import torch import torchani print(" TorchANI successfully imported") qm_engines_python_installed[name] = description except: print(" TorchANI could not be imported") if name == 'ANI': try: import ani from ani.ase_interface import aniensloader from ani.ase_interface import ANIENS print(" ANI successfully imported") qm_engines_python_installed[name] = description except: print(" ANI could not be imported") if count: print(''' QM engines set ''') for env_var in count: print('%s %s : %s' % (' ' * 10, env_var, os.environ[env_var])) for name, description in qm_engines_python_installed.items(): print('%s %s : %s' % (' ' * 10, name, description)) else: print(''' No QM engines found! Install and set an environmental variable from the list. ''') for env_var, help in qm_engine_env_vars.items(): print('%s %s : %s' % (' ' * 10, env_var, help)) print draw_box_around_text([ '', 'Done!', '', 'Run a Q|R job using qr.refine', '', 'https://github.com/qrefine/qrefine/wiki/Installation' ])
def get_file(fn): os.chdir('/net/cci-filer2/raid1/home/youval/Work/work/junk') cmd = "phenix.fetch_pdb {}".format(fn) r = easy_run.go(cmd) os.chdir('/net/cci-filer2/raid1/home/youval/Work/work')