def exercise_02(prefix="tst_mi_test_02"): # Same as 01, but with SS annotations in PDB file h_records = """\ HELIX 1 1 PRO A 3 ALA A 21 1 19 HELIX 2 2 ARG A 23 GLN A 44 1 22 """ pdb_file = open("%s_start.pdb" % prefix, "w") pdb_file.write(h_records) pdb_file.write(tst_01_start_lines) pdb_file.close() cmd = " ".join([ "phenix.model_idealization", "%s_start.pdb" % prefix, errpipe, "%s.log" % prefix, errpipe2]) print cmd easy_run.call(cmd) res_log = open("%s.log" % prefix, "r") log_lines = res_log.readlines() for l in ["Replacing ss-elements with ideal ones:\n"]: assert l in log_lines, "'%s' not in log file." % l res_log.close() assert os.path.isfile("%s_start.pdb_idealized.pdb" % prefix) res_pdb = open("%s_start.pdb_idealized.pdb" % prefix, "r") res_pdb_lines = res_pdb.readlines() res_pdb.close() for l in [ "HELIX 1 1 PRO A 3 ALA A 21 1 19\n", "HELIX 2 2 ARG A 23 GLN A 44 1 22\n", ]: assert l in res_pdb_lines, "'%s' not in pdb file." % l
def OnDisplayLog(self, event): if (self._result.log_file_name is not None): if (sys.platform == "darwin"): easy_run.call("open -a TextEdit %s" % self._result.log_file_name) else: pass
def run(): if (not libtbx.env.has_module("phenix")): print "phenix not configured, skipping" return elif (not libtbx.env.find_in_repositories("chem_data")): print "chem_data not configured, skipping" return f = file("l1r.pdb", "wb") f.write(l1r_pdb) f.close() f = file("l1r.cif", "wb") f.write(l1r_cif) f.close() cmd = 'phenix.geometry_minimization' cmd += " l1r.pdb l1r.cif use_neutron_distances=False" cmd += ' selection="element H or element D" write_geo_file=False' cmd += ' correct_hydrogens=True' print cmd ero = easy_run.fully_buffered(command=cmd) err = StringIO.StringIO() ero.show_stdout(out=err) cmd = "phenix.fmodel high_res=4.5 format=mtz label=FOBS type=real r_free=0.1 l1r.pdb generate_fake_p1_symmetry=1" easy_run.call(cmd) cmd = 'phenix.refine' cmd += " l1r.pdb l1r.pdb.mtz l1r.cif" cmd += " main.number_of_macro_cycles=1" cmd += ' correct_hydrogens=True' print cmd ero = easy_run.fully_buffered(command=cmd) err = StringIO.StringIO() ero.show_stdout(out=err) print "OK"
def run(prefix="tst_model_map"): """ Exercise phenix.model_map """ # original (zero-origin) map and model pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_str) pdb_inp.write_pdb_file(file_name="%s.pdb"%prefix) ph = pdb_inp.construct_hierarchy() xrs = pdb_inp.xray_structure_simple() fc0 = xrs.structure_factors(d_min=3.0).f_calc() # easy_run.call("phenix.model_map %s.pdb output_file_name_prefix=%s"%( prefix, prefix)) m1 = iotbx.ccp4_map.map_reader(file_name="%s.ccp4"%prefix).data.as_double() m2 = iotbx.xplor.map.reader(file_name="%s.xplor"%prefix).data # fc1 = fc0.structure_factors_from_map( map = m1, use_scale = True, anomalous_flag = False, use_sg = False) fc2 = fc0.structure_factors_from_map( map = m2, use_scale = True, anomalous_flag = False, use_sg = False) cc1 = flex.linear_correlation( x=abs(fc0).data(), y=abs(fc1).data()).coefficient() cc2 = flex.linear_correlation( x=abs(fc0).data(), y=abs(fc2).data()).coefficient() print cc1, cc2 assert cc1>0.9999 assert cc2>0.97 # WHY?
def run(prefix="tst_step_5"): """ Exercise phenix.cryo_fit step_5 with all defaults """ assert (os.path.isfile("data/input_for_all/1AKE.density.mrc") == True) assert ( os.path.isfile("data/input_for_all/regression_Adenylate.pdb") == True) cmd = " ".join([ "phenix.cryo_fit", "data/input_for_all/regression_Adenylate.pdb", "step_1=False", "step_2=False", "step_3=False", "step_4=False", "step_6=False", "step_7=False", "step_8=False", "data/input_for_all/1AKE.density.mrc" ]) print cmd easy_run.call(cmd) starting_dir = os.getcwd() new_path = starting_dir + "/steps/5_make_restraints" os.chdir(new_path) #the_step_was_successfully_ran = check_whether_the_step_was_successfully_ran("Step 5", "disre2.itp") # disre2.itp is easier file to make the_step_was_successfully_ran = check_whether_the_step_was_successfully_ran( "Step 5", "minimized_c_term_renamed_by_resnum_oc_including_disre2_itp.top") if (the_step_was_successfully_ran != 1): print "failed, sleep for 10,000 seconds" time.sleep(10000) # so that it is recognized instantly assert (the_step_was_successfully_ran != 0) os.chdir(starting_dir) shutil.rmtree("steps")
def run(prefix="tst_step_2"): """ Exercise phenix.cryo_fit step_2 with all defaults with """ assert (os.path.isfile("data/input_for_all/1AKE.density.mrc") == True) assert ( os.path.isfile("data/input_for_all/regression_Adenylate.pdb") == True) cmd = " ".join([ "phenix.cryo_fit", "data/input_for_all/regression_Adenylate.pdb", "step_1=False", "step_3=False", "step_4=False", "step_5=False", "step_6=False", "step_7=False", "step_8=False", "data/input_for_all/1AKE.density.mrc" ]) print cmd easy_run.call(cmd) starting_dir = os.getcwd() new_path = starting_dir + "/steps/2_clean_gro" os.chdir(new_path) the_step_was_successfully_ran = 0 for check_this_file in glob.glob( "*.gro"): # there will be only "will_be_minimized_cleaned.gro" the_step_was_successfully_ran = check_whether_the_step_was_successfully_ran( "Step 2", check_this_file) print "the_step_was_successfully_ran:", the_step_was_successfully_ran if (the_step_was_successfully_ran != 1): print "failed, sleep for 10,000 seconds" time.sleep(10000) # so that it is recognized instantly assert (the_step_was_successfully_ran != 0) os.chdir(starting_dir) shutil.rmtree("steps")
def fetch_pdb(code): if not os.path.exists("%s.pdb" % code): cmd = "phenix.fetch_pdb --mtz %s" % code easy_run.call(cmd) if not os.path.exists("%s.pdb" % code): return None return "%s.pdb" % code
def run(args): assert len(args)==1 mode = args[0] assert mode in ["cctbx", "xtb", "terachem", "mopac"] # if( mode=="cctbx"): cmd = cmd_cctbx elif(mode=="xtb"): cmd = cmd_xtb elif(mode=="terachem"): cmd = cmd_terachem elif(mode=="mopac"): cmd = cmd_mopac else: assert 0 # results_prefix = "./%s_opt"%mode perturbed_prefix = "./perturbed/" rmsd_dirs = ["0.3/","0.6/","0.9/","1.2/","1.5/"] base_names = ["0","1","2","3","4","5","6","7","8","9"] easy_run.call("rm -rf %s_opt"%mode) os.makedirs(results_prefix) os.chdir(results_prefix) for rmsd_dir in rmsd_dirs: print rmsd_dir os.makedirs(rmsd_dir) for bn in base_names: file_name = "../"+perturbed_prefix+rmsd_dir+bn+".pdb" if(not os.path.exists(file_name)): assert 0 cmd_full = cmd%(file_name,bn) print "running command:\n%s"%(cmd_full) easy_run.call(cmd_full) easy_run.call("cp pdb/%s_refined.pdb %s/%s.pdb"%(bn,rmsd_dir,bn)) easy_run.call("mv %s.log %s"%(bn,rmsd_dir)) easy_run.call("mv pdb %s/%s_pdb"%(rmsd_dir,bn))
def run(sf_file_name,pdb_file_name): # check if files exist if not isfile(sf_file_name): raise Sorry('{} is not a file'.format(sf_file_name)) if not isfile(pdb_file_name): raise Sorry('{} is not a file'.format(pdb_file_name)) # start processing file # convert cif to mtz and process mtz file file_name_mtz = sf_file_name + '.mtz' # creates file in current folder easy_run.call("phenix.cif_as_mtz %s"%sf_file_name) mtz_object = mtz.object(file_name=file_name_mtz) # Process the mtz_object miller_arrays_dict = mtz_object.as_miller_arrays_dict() miller_arrays = mtz_object.as_miller_arrays() for x in miller_arrays_dict: print x print '+'*60 #print miller_arrays_dict[x].show_array() print '='*60 # read pdb info pdb_inp = pdb.input(file_name=pdb_file_name) # read the pdb file data structure = pdb_inp.xray_structure_simple() xray_structure_simple = pdb_inp.xray_structures_simple() # a list of structure factors f_miller = xray_structure_simple[0].structure_factors(d_min=2.85).f_calc() # delete file os.remove(file_name_mtz) # print 'wait here'
def run(filename=None): assert filename is None hpdl_database = get_hpdl_database() if 0: print "HPDL" print hpdl_database for aa in sorted(hpdl_database): print " %s" % aa for key, value in sorted(hpdl_database[aa].items()): print " %s : %s" % (key, value) assert 0 # for pdb, lines in pdbs.items(): print pdb filename="hpdl_%s.pdb" % pdb f=file(filename, "wb") f.write(lines) f.close() cmd = "phenix.pdb_interpretation %s write_geo=1 hpdl=%s" % (filename, True) print cmd easy_run.call(cmd) if filename.find("his_double")>-1: key="ND1 and NE2 protonated" elif filename.find("his_nd1")>-1: key="Only ND1 protonated" elif filename.find("his_ne2")>-1: key="Only NE2 protonated" if refine_geo_parser: check_ideals("%s.geo" % filename, hpdl_database[key]) print "OK"
def call_refine(self, pdb_file, mtz_file, output_file_name, number_of_macro_cycles=3, pdb_file_symmetry_target=None): """ Run refinement and produce refined pdb file in current directory To set the number of refinement cycles change main.number_of_macro_cycles Argument: --------- pdb_file : pdb file to be refined mtz_file : mtz file from the target experiment f_obs output_file_name : the output file prefix pdb_file_symmetry_target : use if you want to force symmetry of a pdb file Output: ------- writing out refined model, complete refinement statistics and electron density maps in various formats. """ cmd = " ".join([ "phenix.refine", "{0} {1}".format(pdb_file,mtz_file), "strategy=individual_sites", "main.number_of_macro_cycles={}".format(number_of_macro_cycles), "output.prefix={}".format(output_file_name), "--overwrite", "--quiet"]) if pdb_file_symmetry_target: cmd = ' '.join([cmd,"--symmetry={}".format(pdb_file_symmetry_target)]) easy_run.call(cmd)
def run(prefix="tst_step_1"): """ Exercise phenix.cryo_fit step_1 with all defaults """ assert (os.path.isfile("data/input/GTPase_activation_center.map") == True) assert (os.path.isfile("data/input/regression_GAC.pdb") == True) cmd = " ".join([ "phenix.cryo_fit", "data/input/regression_GAC.pdb", "step_2=False", "step_3=False", "step_4=False", "step_5=False", "step_6=False", "step_7=False", "step_8=False", "data/input/GTPase_activation_center.map" ]) print cmd easy_run.call(cmd) starting_dir = os.getcwd() new_path = starting_dir + "/steps/1_make_gro" os.chdir(new_path) this_step_was_successfully_ran = check_whether_the_step_was_successfully_ran( "Step 1", "regression_GAC_cleaned_for_gromacs_by_pdb2gmx.gro") if (this_step_was_successfully_ran != 1): print "failed, sleep for 10,000 seconds" time.sleep(10000) # so that it is recognized instantly assert (this_step_was_successfully_ran != 0) os.chdir(starting_dir) shutil.rmtree("steps")
def exercise () : params = runtime_utils.process_master_phil.extract() i = 0 while True : output_dir = os.path.join(os.getcwd(), "simple_run%d" % i) if os.path.exists(output_dir) : i += 1 else : os.makedirs(output_dir) break run = runtime_utils.simple_run(output_dir) params.output_dir = output_dir params.buffer_stdout = False params.tmp_dir = output_dir # driver = runtime_utils.detached_process_driver(output_dir, run) params.run_file = os.path.join(output_dir, "run.pkl") eff_file = os.path.join(output_dir, "run.eff") working_phil = runtime_utils.process_master_phil.format(python_object=params) working_phil.show(out=open(eff_file, "w")) easy_pickle.dump(params.run_file, run) easy_run.call("libtbx.start_process %s &" % eff_file) #params.run_file) client = runtime_utils.simple_client(params) client.run() assert (client.out.getvalue() == """\ current is 44444.444444 current is 50000.000000 current is 57142.857143 current is 66666.666667 """) assert client.n_cb >= 5 # this is variable! assert ([ cb.message for cb in client._accumulated_callbacks ] == ['run 0', 'run 1', 'run 2', 'run 3'])
def exercise(): pdb_file_names = raw_input("pdb file name here:") p_f = pdb_file_names.split(' ') for pdb_file_name in p_f: easy_run.call("phenix.fetch_pdb {0}".format(pdb_file_name[0:4])) easy_run.call("phenix.ready_set {0}".format(pdb_file_name)) print(pdb_file_name, "-" * 50) cif_file_name = pdb_file_name[0:4] + ".ligands.cif" model = get_model(pdb_file_name=pdb_file_name, cif_file_name=cif_file_name) results = get_CNCO_bond_angle(model) for r in results: '''print dir(r.atom_1.chain()) MTN = {"id":["CSN values"],"O-N":[1.272],"C(L)-N":[1.482], "C(R)R-N":[1.482],"C-N-C":[115.232],"C(L)-N-O":[122.384], "C(R)-N-O":[122.384]} df = pd.DataFrame(MTN,columns = ["id","O-N","C(L)-N", "C(R)R-N","C-N-C","C(L)-N-O","C(R)-N-O"],index=["one"]) Series = pd.Series({"O-N":r.d23,"C(L)-N":r.d12, "C(R)R-N":r.d24,"C-N-C":r.a124,"C(L)-N-O":r.a123, "C(R)-N-O":r.a324}) data = pd.DataFrame() Series = [[r.d12, r.d23, r.d24, r.a123, r.a124, r.a324]] df = data.append(Series,ignore_index=True) print df ''' print("%s" % r.atom_1.id_str(), r.atom_2.id_str(), r.atom_3.id_str(), r.atom_4.id_str(), r.d_O_N, r.d_C_L_N, r.d_C_R_N, r.a_C_N_C, r.a_C_L_N_O, r.a_C_R_N_O)
def run_one_cmd(cmd_info): t0 = time.time() from libtbx import easy_run if (cmd_info.index == 0): print "command:", cmd_info.cmd sys.stdout.flush() try: easy_run.call(command=cmd_info.cmd) except: # intentional show_traceback(file=sys.stdout) print fmt_time(t0) print else: sys.stdout.flush() sio = None try: buffers = easy_run.fully_buffered( command=cmd_info.cmd, join_stdout_stderr=True, stdout_splitlines=False) except: # intentional from cStringIO import StringIO sio = StringIO() show_traceback(file=sio) buffers = None f = open(cmd_info.log, "w") if (buffers is not None): f.write(buffers.stdout_buffer) if (sio is not None): f.write(sio.getvalue()) print >> f, fmt_time(t0) del f sys.stdout.flush()
def run(prefix="tst_step_6"): """ Exercise phenix.cryo_fit step_6 with all defaults """ assert (os.path.isfile("data/input_for_all/1AKE.density.mrc") == True) assert ( os.path.isfile("data/input_for_all/regression_Adenylate.pdb") == True) cmd = " ".join([ "phenix.cryo_fit", "data/input_for_all/regression_Adenylate.pdb", "step_1=False", "step_2=False", "step_3=False", "step_4=False", "step_5=False", "step_7=False", "step_8=False", "data/input_for_all/1AKE.density.mrc" ]) print cmd easy_run.call(cmd) starting_dir = os.getcwd() new_path = starting_dir + "/steps/6_make_0_charge" os.chdir(new_path) the_step_was_successfully_ran = '' for check_this_file in glob.glob( "*_0_charge.top"): # there will be only one file like this the_step_was_successfully_ran = check_whether_the_step_was_successfully_ran( "Step 6", check_this_file) if (the_step_was_successfully_ran != 1): print "failed, sleep for 10,000 seconds" time.sleep(10000) # so that it is recognized instantly assert (the_step_was_successfully_ran != 0) os.chdir(starting_dir) shutil.rmtree("steps")
def run_and_check(cmd, pdbs_file, expected_out): abs_paths = [] for rel_path in open(op.join(dd, pdbs_file)).read().splitlines(): abs_paths.append(op.normpath(op.join(dd, rel_path))) list_of_pdbs = "list_of_pdbs_%d" % run_serial.next() print >> open(list_of_pdbs, "w"), "\n".join(abs_paths) cmd = cmd % list_of_pdbs if (valgrind): cmd = "valgrind " + cmd print cmd remove_files("out") if (not valgrind): buffers = easy_run.fully_buffered(command=cmd).raise_if_errors() if (expected_out is None): return buffers.stdout_lines else: easy_run.call(command=cmd) if (expected_out is None): return None filtered_lines = [] for line in open("out").read().splitlines(): sw = line.startswith if (sw("pole") or sw("members") or sw("min: ") or sw("max: ")): filtered_lines.append(line) assert not show_diff("\n".join(filtered_lines)+"\n", expected_out) print "OK"
def run(prefix="tst_step_7"): """ Exercise phenix.cryo_fit step_7 with all defaults """ assert (os.path.isfile("data/input_for_all/1AKE.density.mrc") == True) assert ( os.path.isfile("data/input_for_all/regression_Adenylate.pdb") == True) cmd = " ".join([ "phenix.cryo_fit", "data/input_for_all/regression_Adenylate.pdb", "step_1=False", "step_2=False", "step_3=False", "step_4=False", "step_5=False", "step_6=False", "step_8=False", "data/input_for_all/1AKE.density.mrc" ]) print cmd easy_run.call(cmd) starting_dir = os.getcwd() new_path = starting_dir + "/steps/7_make_tpr_with_disre2" os.chdir(new_path) the_step_was_successfully_ran = check_whether_the_step_was_successfully_ran( "Step 7", "for_cryo_fit.tpr") if (the_step_was_successfully_ran != 1): print "failed, sleep for 10,000 seconds" time.sleep(10000) # so that it is recognized instantly assert (the_step_was_successfully_ran != 0) os.chdir(starting_dir) shutil.rmtree("steps")
def run(prefix="tst_step_1"): """ Exercise phenix.cryo_fit step_1 with all defaults """ assert ( os.path.isfile("data/input_for_all/tRNA_EFTU_within_10.ccp4") == True) assert (os.path.isfile( "data/input_for_all/regression_tRNA_EFTU_within_10.pdb") == True) cmd = " ".join([ "phenix.cryo_fit", "data/input_for_all/regression_tRNA_EFTU_within_10.pdb", "data/input_for_all/tRNA_EFTU_within_10.ccp4", "step_2=False", "step_3=False", "step_4=False", "step_5=False", "step_6=False", "step_7=False", "step_8=False" ]) print cmd easy_run.call(cmd) starting_dir = os.getcwd() new_path = starting_dir + "/steps/1_make_gro" os.chdir(new_path) for check_this_file in glob.glob( "*_by_pdb2gmx.gro" ): # there will be only one *_by_pdb2gmx.gro file this_step_was_successfully_ran = check_whether_the_step_was_successfully_ran( "Step 1", check_this_file) if (this_step_was_successfully_ran != 1): print "failed, sleep for 10,000 seconds" time.sleep(10000) # so that it is recognized instantly assert (this_step_was_successfully_ran != 0) os.chdir(starting_dir) shutil.rmtree("steps")
def run(prefix="tst_step_4"): """ Exercise phenix.cryo_fit step_4 with all defaults with "few_RNAs.pdb" """ assert (os.path.isfile("data/input/GTPase_activation_center.map") == True) assert (os.path.isfile("data/input/regression_GAC.pdb") == True) cmd = " ".join([ "phenix.cryo_fit", "data/input/regression_GAC.pdb", "step_1=False", "step_2=False", "step_3=False", "step_5=False", "step_6=False", "step_7=False", "step_8=False", "data/input/GTPase_activation_center.map" ]) print cmd easy_run.call(cmd) starting_dir = os.getcwd() new_path = starting_dir + "/steps/4_minimize" os.chdir(new_path) the_step_was_successfully_ran = 0 for check_this_file in glob.glob( "*.gro"): # there will be only "will_be_minimized_cleaned.gro" the_step_was_successfully_ran = check_whether_the_step_was_successfully_ran( "Step 4", check_this_file) assert (the_step_was_successfully_ran != 0) if (the_step_was_successfully_ran != 1): print "failed, sleep for 10,000 seconds" time.sleep(10000) # so that it is recognized instantly os.chdir(starting_dir) shutil.rmtree("steps")
def run(file_name="a87_99_h.pdb"): path = "../" shutil.rmtree("perturbed") # BAD AND DANGEROUS os.mkdir("perturbed") os.chdir("perturbed") for p_size in [0.3, 0.6, 0.9, 1.2, 1.5]: p_size = str(p_size) os.mkdir(p_size) os.chdir(p_size) for trial in xrange(10): rs = random.randrange(1111111, 9999999) cmd = " ".join([ "phenix.dynamics", "../../%s"%file_name, "stop_at_diff=%s"%p_size, "number_of_steps=20000", "temperature=1000", "write_geo_file=False", "random_seed=%s"%str(rs), "use_neutron_distances=true", "output_file_name_prefix=%s"%str(trial), "> %s.log"%str(trial)]) easy_run.call(cmd) easy_run.call("rm -rf *.log") os.chdir("..")
def exercise_03(fobs_2, flags_2, prefix): mtz = fobs_2.as_mtz_dataset(column_root_label="FP1") mtz.mtz_object().write(prefix+"_3.mtz") flags_2.export_as_cns_hkl( file_object=open(prefix+"_3.cns", "w"), file_name=prefix+"_3.cns", info=["R-free-flags for FP1"]) # selection = "chain E and resseq 7" cmd = " ".join([ "phenix.polder", "tst_polder_1.cif", "%s_3.mtz" % prefix, "%s_3.cns" % prefix, "sphere_radius=5", "output_file_name_prefix=tst_polder_1_3", 'solvent_exclusion_mask_selection="%s"' % selection, "> %s_3.log" % prefix ]) print cmd easy_run.call(cmd) check( tuple_calc=[13.7, 20.3, 18.4], selection=selection, prefix = prefix + '_3_')
def exercise_02(fobs_1, flags_1, prefix): fobs_1.export_as_cns_hkl( file_object=open(prefix+"_2.cns", "w"), file_name=prefix+"_2.cns", info=["calculated structure factors FP1"]) # flags_1.export_as_cns_hkl( file_object=open(prefix+"_2_free"+".cns", "w"), file_name=prefix+"_2_free"+".cns", info=["R-free-flags for FP1"]) # selection = "chain E and resseq 14" cmd = " ".join([ "phenix.polder", "tst_polder_1.pdb", "%s_2.cns" % prefix, "%s_2_free.cns" % prefix, "sphere_radius=5", "output_file_name_prefix=tst_polder_1_2", 'solvent_exclusion_mask_selection="%s"' % selection, "> %s_2.log" % prefix ]) print cmd easy_run.call(cmd) check( tuple_calc=[10.7, 15.1, 13.4], selection=selection, prefix = prefix + '_2_')
def exercise_01(fobs_1, fobs_2, flags_1, flags_2, prefix): mtz = fobs_1.as_mtz_dataset(column_root_label="FP1") mtz.add_miller_array(fobs_2, column_root_label="FP2") mtz.add_miller_array(flags_1, column_root_label="R-free-flags-1") mtz.add_miller_array(flags_2, column_root_label="R-free-flags-2") mtz.mtz_object().write(prefix+"_1.mtz") # selection = "chain A" cmd = " ".join([ "phenix.polder", "tst_polder_1.pdb", "%s_1.mtz" % prefix, "sphere_radius=3", 'solvent_exclusion_mask_selection="%s"' % selection, "data_labels=FP1", "output_file_name_prefix=tst_polder_1_1", "r_free_flags_labels=R-free-flags-1", "> %s_1.log" % prefix ]) print cmd easy_run.call(cmd) # check( tuple_calc=[10.6, 16.0, 13.5], selection=selection, prefix = prefix + '_1_')
def exercise(): pdb_file_names = raw_input( "pdb file name here,space interval,such as : 2ona.pdb 2whb.pdb") p_f = pdb_file_names.split(' ') for pdb_file_name in p_f: easy_run.call("phenix.fetch_pdb {0}".format(pdb_file_name[0:4])) easy_run.call("phenix.ready_set {0}".format(pdb_file_name)) print(pdb_file_name, "-" * 50) cif_file_name = pdb_file_name[0:4] + ".ligands.cif" if os.path.exists(cif_file_name): cif_file_names = cif_file_name else: cif_file_names = None model = get_model(pdb_file_name=pdb_file_name, cif_file_name=cif_file_names) resnames = raw_input( 'list of resnames ,comma interval,such as: resname PHE,resname HIS' ) resn = resnames.split(',') ss = " or ".join(resn) m_sel = model.selection(ss) new_model = model.select(m_sel) hierarchy = new_model.get_hierarchy() crystal_symmetry = new_model.crystal_symmetry() hierarchy.write_pdb_file(file_name=pdb_file_name[0:4] + "new.pdb", crystal_symmetry=crystal_symmetry)
def exercise_003(file_name="tst_mtrix_biomt_cmdl_003.pdb"): """ Make sure SS is fine when expanding without BIOMT """ of = open(file_name, "w") print(pdb_str_2b, file=of) of.close() easy_run.call("phenix.pdb.biomt_reconstruction %s" % file_name) pdb_inp = iotbx.pdb.input( file_name="tst_mtrix_biomt_cmdl_003_BIOMT_expanded.pdb") a = pdb_inp.extract_secondary_structure() assert a.get_n_helices() == 1, a.get_n_helices() assert a.get_n_sheets() == 1, "%d" % a.get_n_sheets() # checking chain ids. If this part is failing, then something is changed in # chain expanding which made chain ids in hierarchy.py:join_roots() # not compatible with those used in secondary_structure.py:multiply_to_asu chain_ids = [h.start_chain_id for h in a.helices] assert chain_ids == ['A'], chain_ids # checking sheets for i, sh in enumerate(a.sheets): assert sh.n_strands == 2 assert sh.registrations[0] == None assert sh.registrations[1].cur_chain_id == 'B' assert sh.registrations[1].prev_chain_id == 'A' assert sh.strands[0].start_chain_id == 'A' assert sh.strands[0].end_chain_id == 'A' assert sh.strands[1].start_chain_id == 'B' assert sh.strands[1].end_chain_id == 'B'
def run(file_name="tst_tls_as_xyz.pdb"): of = open(file_name, "w") print(pdb_str, file=of) of.close() uc = iotbx.pdb.input(file_name=file_name).crystal_symmetry().unit_cell() #for n in range(10,100,10)+range(100,1000,100)+range(1000,10001,1000)+[15000,20000]: for n in [ 1000, ]: easy_run.call("phenix.tls_as_xyz %s n_models=%s > tst_tls_as_xyz.log" % (file_name, str(n))) for i in [0, 1]: u1 = iotbx.pdb.input( file_name="tst_tls_as_xyz_u_from_ensemble_%s.pdb" % str(i)).xray_structure_simple().scatterers().extract_u_cart(uc) u2 = iotbx.pdb.input( file_name="tst_tls_as_xyz_u_from_tls_%s.pdb" % str(i)).xray_structure_simple().scatterers().extract_u_cart(uc) u1, u2 = u1.as_double(), u2.as_double() cc = flex.linear_correlation(x=u1, y=u2).coefficient() r = flex.sum(flex.abs(flex.abs(u1)-flex.abs(u2)))/\ flex.sum(flex.abs(flex.abs(u1)+flex.abs(u2)))*2 print("%5d %6.4f %6.4f" % (n, cc, r)) assert cc > 0.99, cc assert r < 0.06, r
def run(args): if (len(args) == 0): n_iterations = 1000 elif (len(args) == 1): n_iterations = int(args[0]) assert n_iterations > 0 else: from libtbx.utils import Usage raise Usage("scitbx.show_exp_times [n_iterations]") evar = "LIBTBX_NO_LD_PRELOAD" evar_set = evar in os.environ if (evar_set): print("%s set:" % evar) else: print("%s not set:" % evar) from scitbx.math.tests.tst_exp_functions import \ exercise_with_random_arguments as exercise exercise(n_arguments=10000, n_iterations=n_iterations) print() sys.stdout.flush() if (not evar_set): if ("LD_PRELOAD" in os.environ): del os.environ["LD_PRELOAD"] os.environ[evar] = "1" from libtbx import easy_run easy_run.call(command="scitbx.show_exp_times %d" % n_iterations)
def run_one_cmd(cmd_info): t0 = time.time() from libtbx import easy_run if (cmd_info.index == 0): print("command:", cmd_info.cmd) sys.stdout.flush() try: easy_run.call(command=cmd_info.cmd) except: # intentional show_traceback(file=sys.stdout) print(fmt_time(t0)) print() else: sys.stdout.flush() sio = None try: buffers = easy_run.fully_buffered(command=cmd_info.cmd, join_stdout_stderr=True, stdout_splitlines=False) except: # intentional from six.moves import cStringIO as StringIO sio = StringIO() show_traceback(file=sio) buffers = None f = open(cmd_info.log, "w") if (buffers is not None): f.write(buffers.stdout_buffer) if (sio is not None): f.write(sio.getvalue()) print(fmt_time(t0), file=f) del f sys.stdout.flush()
def exercise_02(fobs_1, flags_1, prefix): with open(prefix + "_2.cns", "w") as file_object: fobs_1.export_as_cns_hkl(file_object=file_object, file_name=prefix + "_2.cns", info=["calculated structure factors FP1"]) # with open(prefix + "_2_free" + ".cns", "w") as file_object: flags_1.export_as_cns_hkl(file_object=file_object, file_name=prefix + "_2_free" + ".cns", info=["R-free-flags for FP1"]) # selection = "chain E and resseq 14" cmd = " ".join([ "phenix.polder", "tst_polder_1.pdb", "%s_2.cns" % prefix, "%s_2_free.cns" % prefix, "sphere_radius=5", "output_file_name_prefix=tst_polder_1_2", 'solvent_exclusion_mask_selection="%s"' % selection, "> %s_2.log" % prefix ]) print(cmd) easy_run.call(cmd) check(tuple_calc=[10.7, 15.1, 13.4], selection=selection, prefix=prefix + '_2_')
def run(prefix="tst_step_final"): """ Exercise phenix.cryo_fit step_final with all defaults """ assert (os.path.isfile("data/input_for_all/1AKE.density.mrc") == True) assert ( os.path.isfile("data/input_for_all/regression_Adenylate.pdb") == True) cmd = " ".join([ "phenix.cryo_fit", "data/input_for_all/regression_Adenylate.pdb", "step_1=False", "step_2=False", "step_3=False", "step_4=False", "step_5=False", "step_6=False", "step_7=False", "step_8=False", "data/input_for_all/1AKE.density.mrc" ]) print cmd easy_run.call(cmd) starting_dir = os.getcwd() new_path = starting_dir + "/output" os.chdir(new_path) #the_step_was_successfully_ran = check_whether_the_step_was_successfully_ran("Step final", "user_provided_cleaned_for_real_space_refine_molprobity.pdb") the_step_was_successfully_ran = check_whether_the_step_was_successfully_ran( "Step final", "extracted_0_target_step_0.0_target_ps_cleaned_for_real_space_refine_molprobity.pdb" ) if (the_step_was_successfully_ran != 1): print "failed, sleep for 10,000 seconds" time.sleep(10000) # so that it is recognized instantly assert (the_step_was_successfully_ran != 0) os.chdir(starting_dir) shutil.rmtree("steps") shutil.rmtree("output")
def run(): path = "../01d_fixSplit_GFA/" for i_f, f in enumerate(os.listdir(path)): if(f.endswith(".pdb")): prefix = f[:-4] os.mkdir(prefix) os.chdir(prefix) for p_size in [0.3, 0.6, 0.9, 1.2, 1.5]: p_size = str(p_size) os.mkdir(p_size) os.chdir(p_size) file_name = "../../"+path+f print i_f, file_name for trial in xrange(10): rs = random.randrange(1111111, 9999999) cmd = " ".join([ "phenix.dynamics", "%s"%file_name, "stop_at_diff=%s"%p_size, "number_of_steps=20000", "temperature=1000", "write_geo_file=False", "random_seed=%s"%str(rs), "output_file_name_prefix=%s"%str(trial), "> %s.log"%prefix]) easy_run.call(cmd) easy_run.call("rm -rf *.log") os.chdir("..") os.chdir("..")
def exercise(prefix="tst_models_to_from_chains"): # inputs expected_n = 5 xrs = iotbx.pdb.input(source_info=None, lines=pdb_str).xray_structure_simple() input_file_name = "%s.pdb"%prefix of = open(input_file_name,"w") print >> of, pdb_str of.close() mi = flex.miller_index(((0,0,1), )) ms = miller.set(xrs.crystal_symmetry(), mi, anomalous_flag=False) complete_set = ms.complete_set(d_min=3) fc = complete_set.structure_factors_from_scatterers( xray_structure=xrs).f_calc() # models -> chains easy_run.call("phenix.models_as_chains %s"%input_file_name) pdb_inp = iotbx.pdb.input(file_name="chains_"+input_file_name) h = pdb_inp.construct_hierarchy() assert len(list(h.chains()))==expected_n assert len(list(h.models()))==1 xrs_c = pdb_inp.xray_structure_simple() fc_c = complete_set.structure_factors_from_scatterers( xray_structure=xrs_c).f_calc() # easy_run.call("phenix.chains_as_models chains_%s"%input_file_name) pdb_inp = iotbx.pdb.input(file_name="models_chains_"+input_file_name) h = pdb_inp.construct_hierarchy() assert len(list(h.chains()))==expected_n assert len(list(h.models()))==expected_n xrs_m = pdb_inp.xray_structure_simple() fc_m = complete_set.structure_factors_from_scatterers( xray_structure=xrs_m).f_calc() # assert approx_equal(0, r(fc, fc_c) ) assert approx_equal(0, r(fc, fc_m) ) assert approx_equal(0, r(fc_c, fc_m))
def run(only_i=None, chunk_n=1, chunk_size=len(pdb_paths) ): try: only_i = int(only_i) except ValueError: only_i=None try: chunk_n = int(chunk_n) except ValueError: chunk_n=1 try: chunk_size = int(chunk_size) except ValueError: chunk_size=len(pdb_paths) assert chunk_size==len(pdb_paths) or chunk_n==1 assert chunk_n>0 assert chunk_size>0 if chunk_n!=1: chunk_size = (len(pdb_paths)-1)//chunk_n+1 elif chunk_size!=1: chunk_n = len(pdb_paths)%chunk_size+1 for i, pdb_path in enumerate(pdb_paths): pdb_code = get_pdb_code(pdb_path) #pdb_code = pdb_path cmd = get_cmd(pdb_path) if only_i is None: print i, cmd continue else: if chunk_n!=1 or chunk_size!=len(pdb_paths): if only_i!=i//chunk_size+1: continue else: if only_i!=i+1: continue print 'Running', i+1 print 'Command', cmd easy_run.call(cmd)
def run(prefix="tst_step_3"): """ Exercise phenix.cryo_fit step_3 with all defaults """ assert ( os.path.isfile("data/input_for_all/tRNA_EFTU_within_10.ccp4") == True) assert (os.path.isfile( "data/input_for_all/regression_tRNA_EFTU_within_10.pdb") == True) cmd = " ".join([ "phenix.cryo_fit", "data/input_for_all/regression_tRNA_EFTU_within_10.pdb", "data/input_for_all/tRNA_EFTU_within_10.ccp4", "step_1=False", "step_2=False", "step_4=False", "step_5=False", "step_6=False", "step_7=False", "step_8=False" ]) print cmd easy_run.call(cmd) starting_dir = os.getcwd() new_path = starting_dir + "/steps/3_make_tpr_to_minimize" os.chdir(new_path) the_step_was_successfully_ran = check_whether_the_step_was_successfully_ran( "Step 3", "to_minimize.tpr") if (the_step_was_successfully_ran != 1): print "failed, sleep for 10,000 seconds" time.sleep(10000) # so that it is recognized instantly assert (the_step_was_successfully_ran != 0) os.chdir(starting_dir) shutil.rmtree("steps")
def exercise_001(file_name="tst_mtrix_biomt_cmdl_001.pdb"): """ Make sure SS gets populated by MTRIX """ of = open(file_name,"w") print >> of, pdb_str_2b of.close() easy_run.call("phenix.pdb.mtrix_reconstruction %s"%file_name) pdb_inp = iotbx.pdb.input( file_name="tst_mtrix_biomt_cmdl_001_MTRIX_expanded.pdb") a = pdb_inp.extract_secondary_structure() assert a.get_n_helices() == 3, a.get_n_helices() assert a.get_n_sheets() == 3, "%d" % a.get_n_sheets() # checking chain ids. If this part is failing, then something is changed in # chain expanding which made chain ids in hierarchy.py:join_roots() # not compatible with those used in secondary_structure.py:multiply_to_asu chain_ids = [h.start_chain_id for h in a.helices] assert chain_ids == ['A1', 'A2', 'A3'], chain_ids # checking sheets for i, sh in enumerate(a.sheets): assert sh.n_strands == 2 assert sh.registrations[0] == None assert sh.registrations[1].cur_chain_id == 'B%d' % (i+1) assert sh.registrations[1].prev_chain_id == 'A%d' % (i+1) assert sh.strands[0].start_chain_id == 'A%d' % (i+1), sh.strands[0].start_chain_id assert sh.strands[0].end_chain_id == 'A%d' % (i+1) assert sh.strands[1].start_chain_id == 'B%d' % (i+1), sh.strands[1].start_chain_id assert sh.strands[1].end_chain_id == 'B%d' % (i+1)
def exercise_001(file_name="tst_mtrix_biomt_cmdl_001.pdb"): """ Make sure SS gets populated by MTRIX """ of = open(file_name, "w") print(pdb_str_2b, file=of) of.close() easy_run.call("phenix.pdb.mtrix_reconstruction %s" % file_name) pdb_inp = iotbx.pdb.input( file_name="tst_mtrix_biomt_cmdl_001_MTRIX_expanded.pdb") a = pdb_inp.extract_secondary_structure() assert a.get_n_helices() == 3, a.get_n_helices() assert a.get_n_sheets() == 3, "%d" % a.get_n_sheets() # checking chain ids. If this part is failing, then something is changed in # chain expanding which made chain ids in hierarchy.py:join_roots() # not compatible with those used in secondary_structure.py:multiply_to_asu chain_ids = [h.start_chain_id for h in a.helices] assert chain_ids == ['A', 'C', 'E'], chain_ids # checking sheets assert not show_diff( a.as_pdb_str(), """\ HELIX 1 1 THR A 1 THR A 2 1 6 HELIX 2 2 THR C 1 THR C 2 1 6 HELIX 3 3 THR E 1 THR E 2 1 6 SHEET 1 1 2 THR A 1 THR A 3 0 SHEET 2 1 2 THR B 4 THR B 5 -1 O THR B 4 N THR A 2 SHEET 1 2 2 THR C 1 THR C 3 0 SHEET 2 2 2 THR D 4 THR D 5 -1 O THR D 4 N THR C 2 SHEET 1 3 2 THR E 1 THR E 3 0 SHEET 2 3 2 THR F 4 THR F 5 -1 O THR F 4 N THR E 2""")
def run(): pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_str) model = mmtbx.model.manager(model_input=pdb_inp, log=null_out()) model.process(make_restraints=True) a = aev.AEV(model=model) print('forward AEVs') print(a.BAEVs) print('backward AEVs') print(a.EAEVs) gv = a.get_values() for key in gv: outl = key for cc in gv[key]: outl += ' %0.3f' % cc print(outl) # print('backward AEVs') # print(a.EAEVs) # print('middle AEVs') # print(a.MAEVs) b = aev.compare(a) print(b) assert b['GLY A 1']['E'] is None print(b['GLY A 5']) assert b['GLY A 5']['E'] > 0.99 assert b['GLY A 5']['M'] > 0.99 assert b['GLY A 5']['B'] > 0.99 assert b['GLY A 10']['B'] is None recs = aev.format_HELIX_records_from_AEV(b, 0.9) assert len(recs) == 1 r = "HELIX 1 1 GLY A 2 GLY A 9 8" assert r == recs[0] # with open("development.aev.pdb", "w") as fo: fo.write(pdb_str) easy_run.call("mmtbx.development.aev development.aev.pdb 0.9")
def exercise_set_seg_id () : input_pdb = """\ ATOM 1 O GLY A 3 1.434 1.460 2.496 1.00 6.04 O ATOM 2 O CYS A 7 2.196 4.467 3.911 1.00 4.51 O ATOM 3 O CYS A 1 -1.433 4.734 5.405 1.00 7.85 O TER ATOM 4 O SER B 4 0.297 0.843 7.226 1.00 7.65 O ATOM 5 OG ASER B 4 -2.625 1.057 4.064 0.50 5.46 O ATOM 6 OG BSER B 4 -0.885 0.189 3.843 0.50 11.74 O TER ATOM 7 O LEU 0 5.613 12.448 6.864 1.00 7.32 O TER END """ open("tmp_seg_id.pdb", "w").write(input_pdb) easy_run.call("phenix.pdbtools tmp_seg_id.pdb set_seg_id_to_chain_id=True --quiet") pdb_out_1 = open("tmp_seg_id.pdb_modified.pdb").read() assert not show_diff(pdb_out_1, """\ ATOM 1 O GLY A 3 1.434 1.460 2.496 1.00 6.04 A O ATOM 2 O CYS A 7 2.196 4.467 3.911 1.00 4.51 A O ATOM 3 O CYS A 1 -1.433 4.734 5.405 1.00 7.85 A O TER ATOM 4 O SER B 4 0.297 0.843 7.226 1.00 7.65 B O ATOM 5 OG ASER B 4 -2.625 1.057 4.064 0.50 5.46 B O ATOM 6 OG BSER B 4 -0.885 0.189 3.843 0.50 11.74 B O TER ATOM 7 O LEU 0 5.613 12.448 6.864 1.00 7.32 O TER END """) easy_run.call("phenix.pdbtools tmp_seg_id.pdb_modified.pdb clear_seg_id=True --quiet") pdb_out_2 = open("tmp_seg_id.pdb_modified.pdb_modified.pdb").read() assert (pdb_out_2 == input_pdb)
def run(args): if (len(args) == 0): n_iterations = 1000 elif (len(args) == 1): n_iterations = int(args[0]) assert n_iterations > 0 else: from libtbx.utils import Usage raise Usage("scitbx.show_exp_times [n_iterations]") evar = "LIBTBX_NO_LD_PRELOAD" evar_set = os.environ.has_key(evar) if (evar_set): print "%s set:" % evar else: print "%s not set:" % evar from scitbx.math.tests.tst_exp_functions import \ exercise_with_random_arguments as exercise exercise(n_arguments=10000, n_iterations=n_iterations) print sys.stdout.flush() if (not evar_set): if (os.environ.has_key("LD_PRELOAD")): del os.environ["LD_PRELOAD"] os.environ[evar] = "1" from libtbx import easy_run easy_run.call(command="scitbx.show_exp_times %d" % n_iterations)
def run(prefix="tst_step_8"): """ Exercise phenix.cryo_fit step_8 with all defaults with "partial_GTPase_activation_center.pdb" """ assert (os.path.isfile("data/input/GTPase_activation_center.map") == True) assert (os.path.isfile("data/input/regression_GAC.pdb") == True) cmd = " ".join([ "phenix.cryo_fit", "data/input/regression_GAC.pdb", "data/input/GTPase_activation_center.map", "step_1=False", "step_2=False", "step_3=False", "step_4=False", "step_5=False", "step_6=False", "step_7=False" ]) print cmd easy_run.call(cmd) starting_dir = os.getcwd() new_path = starting_dir + "/steps/8_cryo_fit" os.chdir(new_path) cc = check_cc("cc_record") assert (cc != 0.004804) the_step_was_successfully_ran = check_whether_the_step_was_successfully_ran( "Step 8", "cc_record") if ((cc == 0.004804) or (the_step_was_successfully_ran != 1)): print "failed step 8 for GAC, sleep for 10,000 seconds" time.sleep(10000) # so that it is recognized instantly assert (the_step_was_successfully_ran != 0) os.chdir(starting_dir) shutil.rmtree("steps")
def run(): phenix_dir = libtbx.env.dist_path("phenix") print '\n Phenix modules found :',phenix_dir amberhome = os.environ.get("AMBERHOME", None) if amberhome is None: raise Sorry("$AMBERHOME not set") print "\n $AMBERHOME set :",amberhome print "\n Linking AMBERHOME to Phenix modules" assert os.path.exists(amberhome) target = os.path.join(os.path.dirname(phenix_dir), "amber") if os.path.exists(target): if os.path.samefile(target, amberhome): print ''' Not linking $AMBERHOME into Phenix modules directory because there is already a link and it points to the same directory as $AMBERHOME. $AMBERHOME : %s Phenix link: %s ''' % (amberhome, target) else: print ''' Not linking $AMBERHOME into Phenix modules directory because there is already a link and it does not point to the same directory as $AMBERHOME. $AMBERHOME : %s Phenix link: %s Consider removing the Phenix link to update to a new $AMBERHOME. ''' % (amberhome, target) raise Sorry("$AMBERHOME and Phenix link mismatch") else: os.symlink(amberhome, target) build_dir = os.path.dirname(os.path.dirname(phenix_dir)) build_dir = os.path.join(build_dir, "build") if 0: # don't do this as the python version can change dispatcher_include = os.path.join(os.path.dirname(phenix_dir), "amber_adaptbx", "dispatcher_include_amber.sh", ) shutil.copyfile(dispatcher_include, os.path.join(build_dir, "dispatcher_include_amber.sh", ) ) else: os.chdir(build_dir) for filename in os.listdir(os.path.join(amberhome, "lib")): if filename.startswith("python"): break f=file("dispatcher_include_amber.sh", "wb") f.write(dispatcher_include_str % (filename, filename) ) f.close() print "Building amber_adaptbx" cmd = "libtbx.configure amber" print "\n ~> %s\n" % cmd easy_run.call(cmd) os.chdir(build_dir)
def run(prefix="tst_map_model_cc"): """ Make sure it works with map having origin != (0,0,0) """ # original (zero-origin) map and model pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_str) pdb_inp.write_pdb_file(file_name="%s_%s"%(prefix,"orig.pdb")) ph = pdb_inp.construct_hierarchy() xrs = pdb_inp.xray_structure_simple() fc = xrs.structure_factors(d_min=1.5).f_calc() fft_map = fc.fft_map(resolution_factor = 0.25) fft_map.apply_sigma_scaling() map_data = fft_map.real_map_unpadded() assert map_data.all() == (40, 45, 54) assert map_data.origin() == (0, 0, 0) assert map_data.focus() == (40, 45, 54) write_ccp4_map(map_data=map_data, cs=xrs.crystal_symmetry(), file_name="%s_%s"%(prefix,"orig.ccp4")) # shift origin of the map g = flex.grid((-20,-25,-27), (20,20,27)) map_data.reshape(g) assert map_data.all() == (40, 45, 54) assert map_data.origin() == (-20, -25, -27) assert map_data.focus() == (20, 20, 27) write_ccp4_map(map_data=map_data, cs=xrs.crystal_symmetry(), file_name="%s_%s"%(prefix,"shifted.ccp4")) # apply same shift to the model a,b,c = xrs.crystal_symmetry().unit_cell().parameters()[:3] N = map_data.all() O=map_data.origin() sites_cart = ph.atoms().extract_xyz() sx,sy,sz = a/N[0]*O[0], b/N[1]*O[1], c/N[2]*O[2] sites_cart_shifted = sites_cart+\ flex.vec3_double(sites_cart.size(), [sx,sy,sz]) ph.atoms().set_xyz(sites_cart_shifted) ph.write_pdb_file(file_name="%s_%s"%(prefix,"shifted.pdb")) # run phenix.real_space_refine checked = 0 for opt in ["","resolution=1.5"]: cmd = " ".join([ "phenix.map_model_cc", "%s_shifted.pdb"%prefix, "%s_shifted.ccp4"%prefix, "%s"%opt, "> %s.zlog"%prefix ]) print cmd easy_run.call(cmd) # check results fo = open("%s.zlog"%prefix,"r") for l in fo.readlines(): if(l.startswith("around atoms:")): cc = float(l.split()[2]) assert cc>0.989 checked+=1 fo.close() assert checked==2
def run(args): sit_reldir = os.environ.get("SIT_RELDIR") sit_release = os.environ.get("SIT_RELEASE") sit_arch = os.environ.get("SIT_ARCH") assert [sit_reldir, sit_release, sit_arch].count(None) == 0 pyana_path = os.path.join(sit_reldir,sit_release,"arch",sit_arch,"bin","psana") cmd = " ".join([pyana_path] + args) print cmd easy_run.call(cmd)
def run_multi(cmd): from libtbx import easy_run import traceback print cmd try: easy_run.call(command=cmd) except: # intentional sys.stdout.flush() print >> sys.stderr, "CAUGHT EXCEPTION: run_multi(%s)" % cmd traceback.print_exc() sys.stderr.flush()
def run(filename): print filename if 0: print "RDL" for aa in sorted(rdl_database): print " %s" % aa for key, value in rdl_database[aa].items(): print " %s" % key for names, values in rdl_database[aa][key].items(): print " %s : %s" % (names, values) assert 0 # if filename=="3sgs.pdb": from libtbx import easy_run f=file("mse.pdb", "wb") f.write(pdbs["mse.pdb"]) f.close() f=file("met.pdb", "wb") f.write(pdbs["met.pdb"]) f.close() cmd="phenix.pdb_interpretation rdl=True write_geo=1 mse.pdb" print cmd easy_run.call(cmd) cmd="phenix.pdb_interpretation rdl=True write_geo=1 met.pdb" print cmd easy_run.call(cmd) # pdb_inp = pdb.input(filename) pdb_hierarchy = pdb_inp.construct_hierarchy() geometry_restraints_manager = get_geometry_restraints_manager(filename) pdb_hierarchy.reset_i_seq_if_necessary() rdl.update_restraints(pdb_hierarchy, geometry_restraints_manager, assert_rotamer_found=True, verbose=True, ) print "OK" mmtbx_dir = libtbx.env.dist_path("mmtbx") props = os.path.join(mmtbx_dir,"rotamer","rotamer_names.props") f=file(props, "rb") props = f.readlines() f.close() for prop in props: print prop key = prop.split("=")[0] residue, rotamer_name = key.split() residue = residue.upper() if residue in ["MSE"]: continue assert residue in rdl_database assert rotamer_name in rdl_database[residue]
def exercise_set_charge () : from iotbx import file_reader input_pdb = """ ATOM 1 CL CL X 1 0.000 0.000 0.000 1.00 20.00 CL END """ open("tmp_cl.pdb", "w").write(input_pdb) easy_run.call('phenix.pdbtools tmp_cl.pdb charge_selection="element Cl" charge=-1 --quiet') pdb_in = file_reader.any_file("tmp_cl.pdb_modified.pdb").file_object hierarchy = pdb_in.hierarchy xrs = pdb_in.xray_structure_simple() assert (xrs.scatterers()[0].scattering_type == 'Cl1-') assert (hierarchy.atoms()[0].charge == '1-')
def run_function_as_detached_process_in_dialog ( parent, thread_function, title, message, tmp_dir, callback=None, project_id=None, job_id=None) : if (tmp_dir is None) : tmp_dir = os.getcwd() params = runtime_utils.process_master_phil.extract() params.tmp_dir = tmp_dir if (job_id is None) : job_id = str(os.getpid()) + "_" + str(int(random.random() * 1000)) params.prefix = str(job_id) target = runtime_utils.detached_process_driver(target=thread_function) run_file = os.path.join(tmp_dir, "libtbx_run_%s.pkl" % job_id) easy_pickle.dump(run_file, target) params.run_file = run_file eff_file = os.path.join(tmp_dir, "libtbx_run_%s.eff" % job_id) runtime_utils.write_params(params, eff_file) dlg = ProcessDialog( parent=parent, message=message, caption=title, callback=callback) setup_process_gui_events( window=dlg, OnExcept=dlg.OnError, OnAbort=dlg.OnAbort, OnComplete=dlg.OnComplete) agent = event_agent( window=dlg, project_id=project_id, job_id=job_id) process = detached_process(params, proxy=agent) cb = event_agent(dlg, project_id=project_id, job_id=job_id) easy_run.call("libtbx.start_process \"%s\" &" % eff_file) result = None abort = False if (dlg.run(process) == wx.ID_OK) : result = dlg.get_result() elif dlg.exception_raised() : dlg.handle_error() elif (dlg.was_aborted()) : abort = True wx.CallAfter(dlg.Destroy) if (abort) : raise Abort() return result
def exercise () : pdb_file_name_1 = libtbx.env.find_in_repositories( relative_path="phenix_regression/misc/1l3r_no_ligand.pdb", test=os.path.isfile) pdb_in_1 = iotbx.pdb.input(file_name = pdb_file_name_1) xrs1 = pdb_in_1.xray_structure_simple() ofn = "1l3r_rt.pdb" cmd = " ".join([ "phenix.pdbtools", "%s"%pdb_file_name_1, "rotate='90 10 20' translate='10 10 10'", "output.file_name=%s"%ofn, "--quiet"]) easy_run.call(cmd) pdb_in_rt = iotbx.pdb.input(file_name = ofn) xrs_rt = pdb_in_rt.xray_structure_simple() fft_map_1 = xrs1.structure_factors(d_min=1.5).f_calc().fft_map( resolution_factor = 1./3) fft_map_1.apply_sigma_scaling() map_data_1 = fft_map_1.real_map_unpadded() mmtbx.maps.utils.write_xplor_map(sites_cart = xrs1.sites_cart(), unit_cell = xrs1.unit_cell(), map_data = map_data_1, n_real = fft_map_1.n_real(), file_name = "1l3r.xplor") lsq_fit_obj = superpose.least_squares_fit( reference_sites=xrs_rt.sites_cart(), other_sites=xrs1.sites_cart().deep_copy()) f_o_r = common_frame_of_reference( all_sites_cart=[xrs1.sites_cart(),xrs_rt.sites_cart()], lsq_fits=[None, lsq_fit_obj]) hierarchy_rt = pdb_in_rt.construct_hierarchy() lsq_fit_obj = f_o_r.transformation_matrices[1] hierarchy_rt.atoms().set_xyz(f_o_r.shifted_sites[1]) open("1l3r_rt.pdb", "w").write(hierarchy_rt.as_pdb_string()) xrs_rt, map_data_rt = transform_map_by_lsq_fit( fft_map=fft_map_1, unit_cell=xrs1.unit_cell(), lsq_fit_obj=lsq_fit_obj.inverse(), pdb_hierarchy=hierarchy_rt, d_min=1.5, file_name="1l3r_rt.xplor", log=null_out()) f_o_r.inverse_transform_hierarchy(1, hierarchy_rt) open("1l3r.pdb", "w").write(hierarchy_rt.as_pdb_string()) #for sf1, sf2 in zip(xrs1.sites_frac(), xrs_rt.sites_frac()): # e1 = map_data_1.eight_point_interpolation(sf1) # e2 = map_data_rt.eight_point_interpolation(sf2) # print abs(e1-e2) # assert abs(e1-e2) < 1. print "OK"
def exercise( verbose, file_names_cpp, number_of_function_files=None, separate_files_main_namespace={}, separate_files_separate_namespace={}): if (verbose): print "next exercise" import libtbx.load_env test_valid = libtbx.env.under_dist( module_name="fable", path="test/valid", test=op.isdir) import fable.cout top_cpp = fable.cout.process( file_names=[op.join(test_valid, "subroutine_3.f")], top_procedures=["prog"], namespace="tst_separate_files", top_cpp_file_name=file_names_cpp[0], number_of_function_files=number_of_function_files, separate_files_main_namespace=separate_files_main_namespace, separate_files_separate_namespace=separate_files_separate_namespace) from fable import simple_compilation comp_env = simple_compilation.environment() from libtbx import easy_run file_names_obj = [] for file_name_cpp in file_names_cpp: obj = comp_env.file_name_obj(file_name_cpp=file_name_cpp) remove_file_if_necessary(file_name=obj) cmd = comp_env.compilation_command(file_name_cpp=file_name_cpp) if (verbose): print cmd easy_run.call(command=cmd) assert op.exists(obj) file_names_obj.append(obj) exe_root = "tst_separate_files" exe = comp_env.file_name_exe(exe_root=exe_root) remove_file_if_necessary(file_name=exe) cmd = comp_env.link_command(file_names_obj=file_names_obj, exe_root=exe_root) if (verbose): print cmd easy_run.call(command=cmd) cmd = op.join(".", exe) if (verbose): print cmd assert op.exists(cmd) stdout = easy_run.fully_buffered(command=cmd).raise_if_errors().stdout_lines text = "\n".join(stdout) if (verbose): print text from fable.tst_cout_compile import read_file_names_and_expected_cout info = read_file_names_and_expected_cout(test_valid=test_valid).get( "subroutine_3.f")[0] from libtbx.test_utils import show_diff assert not show_diff(text, "\n".join(info.out_lines)) if (verbose): print
def exercise(prefix="tst_helix_sheet_recs_as_pdb_files"): of = open(prefix+".pdb", "w") print >> of, pdb_str of.close() xrs1 = iotbx.pdb.input(file_name=prefix+".pdb").xray_structure_simple() easy_run.call("phenix.helix_sheet_recs_as_pdb_files %s"%(prefix+".pdb")) xrs2 = iotbx.pdb.input( file_name="HELIX_1_1_ALA_E_1_ALA_E_16_1_16.pdb").xray_structure_simple(crystal_symmetry=xrs1.crystal_symmetry()) fc1 = xrs1.structure_factors(d_min=3).f_calc() fc2 = fc1.structure_factors_from_scatterers( xray_structure=xrs2).f_calc() fc1=flex.abs(abs(fc1).data()) fc2=flex.abs(abs(fc2).data()) assert flex.sum(flex.abs(fc1-fc2))/flex.sum(flex.abs(fc1+fc2)) < 1.e-3
def run(): if (not libtbx.env.has_module("phenix")) : print "phenix not configured, skipping" return elif (not libtbx.env.find_in_repositories("chem_data")) : print "chem_data not configured, skipping" return f=file("l1r.pdb", "wb") f.write(l1r_pdb) f.close() f=file("l1r.cif", "wb") f.write(l1r_cif) f.close() cmd = 'phenix.geometry_minimization' cmd += " l1r.pdb l1r.cif use_neutron_distances=False" cmd += ' selection="element H or element D" write_geo_file=False' cmd += ' correct_hydrogens=True' print cmd ero = easy_run.fully_buffered(command=cmd) err = StringIO.StringIO() ero.show_stdout(out=err) for line in err.getvalue().split("\n"): if line.find("Number of hydrogens corrected")>-1: print line break else: assert 0 print "OK" cmd = "phenix.fmodel high_res=4.5 format=mtz label=FOBS type=real r_free=0.1 l1r.pdb generate_fake_p1_symmetry=1" easy_run.call(cmd) cmd = 'phenix.refine' cmd += " l1r.pdb l1r.pdb.mtz l1r.cif" cmd += " main.number_of_macro_cycles=1" cmd += ' correct_hydrogens=True' print cmd ero = easy_run.fully_buffered(command=cmd) err = StringIO.StringIO() ero.show_stdout(out=err) for line in err.getvalue().split("\n"): if line.find("Number of hydrogens corrected")>-1: print line break else: assert 0 print "OK"
def exercise_00(prefix="tst_molprobity_3_exercise_00"): for pdb_str in [pdb_str_1, pdb_str_2]: of = open("%s.pdb"%prefix, "w") print >> of, pdb_str of.close() cmd = " ".join([ "phenix.fmodel", "%s.pdb"%prefix, "high_res=10", "type=real r_free=0.1 label=F-obs", "output.file_name=%s.mtz"%prefix, "> %s.zlog"%prefix]) easy_run.call(cmd) cmd = "phenix.molprobity %s.pdb %s.mtz > %s.zlog"%(prefix,prefix,prefix) easy_run.call(cmd)
def exercise () : if (os.path.isfile("tst_fmodel_anomalous.mtz")) : os.remove("tst_fmodel_anomalous.mtz") pdb_file = make_fake_anomalous_data.write_pdb_input_cd_cl( file_base="tst_fmodel_anomalous") # phenix.fmodel (with wavelength) args = [ pdb_file, "high_resolution=1.0", "wavelength=1.116", "label=F", "type=real", "output.file_name=tst_fmodel_anomalous.mtz", "r_free_flags_fraction=0.1", ] fmodel.run(args=args, log=null_out()) assert os.path.isfile("tst_fmodel_anomalous.mtz") mtz_in = file_reader.any_file("tst_fmodel_anomalous.mtz") array = mtz_in.file_server.miller_arrays[0] assert (array.anomalous_flag()) anom_diffs = array.anomalous_differences() assert approx_equal(flex.max(anom_diffs.data()), 5.72, eps=0.01) # mmtbx.fmodel_simple result = easy_run.call( "mmtbx.fmodel_simple \"%s\" tst_fmodel_anomalous.mtz high_resolution=2.0" % pdb_file) print "OK"