def create_refinement_view_script ( mtz_file_name, pdb_file_name, coot_script_name="view_in_coot.py", work_dir=None, show_symmetry=True, peaks_file_name=None, bad_ligand_list=None, placed_ligand_list=None) : from iotbx.file_reader import any_file from libtbx.utils import concatenate_python_script import libtbx.load_env have_anom_map = False have_anom_residual_map = False mtz_in = any_file(mtz_file_name).assert_file_type("hkl") have_anom_map = have_residual_map = False for array in mtz_in.file_server.miller_arrays : labels = array.info().labels if ("ANOM" in labels) : have_anom_map = True elif ("ANOMDIFF" in labels) : have_anom_residual_map = True f = open(coot_script_name, "w") print >> f, "import coot" print >> f, "import os" write_disable_nomenclature_errors(f) load_script = libtbx.env.find_in_repositories( relative_path="cctbx_project/cootbx/view_refinement.py", test=os.path.isfile) assert (load_script is not None) concatenate_python_script(out=f, file_name=load_script) zoom_ligand_script = libtbx.env.find_in_repositories( relative_path="cctbx_project/cootbx/simple_zoom_list.py", test=os.path.isfile) concatenate_python_script(out=f, file_name=zoom_ligand_script) if (work_dir is not None) : pdb_file_name = os.path.basename(pdb_file_name) mtz_file_name = os.path.basename(mtz_file_name) f.write("""load_refinement(\n""") f.write("""pdb_file="%s",\n""" % pdb_file_name) f.write("""map_file="%s",\n""" % mtz_file_name) f.write("""show_symmetry=%s,\n""" % show_symmetry) f.write("""have_anom_map=%s,\n""" % have_anom_map) f.write("""have_residual_map=%s,\n""" % have_residual_map) if (work_dir is not None) : f.write("""work_dir="%s",\n""" % work_dir) if (peaks_file_name is not None) : f.write("""peaks_file="%s",\n""" % peaks_file_name) f.write(")\n") if (bad_ligand_list is not None) and (len(bad_ligand_list) > 0) : print >> f, """draw_simple_zoom_list(""" print >> f, """ title="Residues in suspicious density",""" print >> f, """ items=%s)""" % str(bad_ligand_list) if (placed_ligand_list is not None) : print >> f, """draw_simple_zoom_list(""" print >> f, """ title="Placed ligands",""" print >> f, """ items=%s)""" % str(placed_ligand_list) f.close()
def create_refinement_view_script(mtz_file_name, pdb_file_name, coot_script_name="view_in_coot.py", work_dir=None, show_symmetry=True, peaks_file_name=None, bad_ligand_list=None, placed_ligand_list=None): from iotbx.file_reader import any_file from libtbx.utils import concatenate_python_script import libtbx.load_env have_anom_map = False have_anom_residual_map = False mtz_in = any_file(mtz_file_name).assert_file_type("hkl") have_anom_map = have_residual_map = False for array in mtz_in.file_server.miller_arrays: labels = array.info().labels if ("ANOM" in labels): have_anom_map = True elif ("ANOMDIFF" in labels): have_anom_residual_map = True f = open(coot_script_name, "w") print >> f, "import coot" print >> f, "import os" write_disable_nomenclature_errors(f) load_script = libtbx.env.find_in_repositories( relative_path="cctbx_project/cootbx/view_refinement.py", test=os.path.isfile) assert (load_script is not None) concatenate_python_script(out=f, file_name=load_script) zoom_ligand_script = libtbx.env.find_in_repositories( relative_path="cctbx_project/cootbx/simple_zoom_list.py", test=os.path.isfile) concatenate_python_script(out=f, file_name=zoom_ligand_script) if (work_dir is not None): pdb_file_name = os.path.basename(pdb_file_name) mtz_file_name = os.path.basename(mtz_file_name) f.write("""load_refinement(\n""") f.write("""pdb_file="%s",\n""" % pdb_file_name) f.write("""map_file="%s",\n""" % mtz_file_name) f.write("""show_symmetry=%s,\n""" % show_symmetry) f.write("""have_anom_map=%s,\n""" % have_anom_map) f.write("""have_residual_map=%s,\n""" % have_residual_map) if (work_dir is not None): f.write("""work_dir="%s",\n""" % work_dir) if (peaks_file_name is not None): f.write("""peaks_file="%s",\n""" % peaks_file_name) f.write(")\n") if (bad_ligand_list is not None) and (len(bad_ligand_list) > 0): print >> f, """draw_simple_zoom_list(""" print >> f, """ title="Residues in suspicious density",""" print >> f, """ items=%s)""" % str(bad_ligand_list) if (placed_ligand_list is not None): print >> f, """draw_simple_zoom_list(""" print >> f, """ title="Placed ligands",""" print >> f, """ items=%s)""" % str(placed_ligand_list) f.close()
def exercise_misc(): utils.host_and_user().show(prefix="### ") time_in_seconds = 1.1 for i_trial in range(55): time_in_seconds = time_in_seconds**1.1 time_units, time_unit = utils.human_readable_time( time_in_seconds=time_in_seconds) assert approx_equal( utils.human_readable_time_as_seconds(time_units, time_unit), time_in_seconds) # fts = utils.format_timestamp f12 = utils.format_timestamp_12_hour f24 = utils.format_timestamp_24_hour def check(string, expected): assert len(string) == len(expected) check(f12(1280007000), 'Jul 24 2010 02:30 PM') check(f24(1280007000), 'Jul 24 2010 14:30') check(f12(1280007000, True), '24-07-10 02:30 PM') check(f24(1280007000, True), '24-07-10 14:30') check(fts(1280007000), 'Jul 24 2010 02:30 PM') # nfs = utils.number_from_string for string in ["True", "False"]: try: nfs(string=string) except ValueError as e: assert str(e) == 'Error interpreting "%s" as a numeric expression.' % ( string) else: raise Exception_expected assert nfs(string="-42") == -42 assert approx_equal(nfs(string="3.14"), 3.14) assert approx_equal(nfs(string="cos(0)"), 1) try: nfs(string="xxx(0)") except ValueError as e: assert str(e).startswith( 'Error interpreting "xxx(0)" as a numeric expression: ') else: raise Exception_expected # s = "[0.143139, -0.125121, None, -0.308607]" assert numstr(values=eval(s)) == s # for s,i in {"2000000" : 2000000, "2k" : 2048, "2Kb" : 2048, "2 Kb" : 2048, "5Mb" : 5*1024*1024, "2.5Gb" : 2.5*1024*1024*1024, "1T": 1024*1024*1024*1024, 10000 : 10000, 5.5 : 5.5, }.items(): assert utils.get_memory_from_string(s) == i # assert utils.tupleize(1) == (1,) assert utils.tupleize("abcde") == ('a', 'b', 'c', 'd', 'e') assert utils.tupleize([1,2,3]) == (1,2,3) # sf = utils.search_for assert sf(pattern="fox", mode="==", lines=["fox", "foxes"]) \ == ["fox"] assert sf(pattern="o", mode="find", lines=["fox", "bird", "mouse"]) \ == ["fox", "mouse"] assert sf(pattern="fox", mode="startswith", lines=["fox", "foxes"]) \ == ["fox", "foxes"] assert sf(pattern="xes", mode="endswith", lines=["fox", "foxes"]) \ == ["foxes"] assert sf(pattern="es$", mode="re.search", lines=["geese", "foxes"]) \ == ["foxes"] assert sf(pattern="ge", mode="re.match", lines=["geese", "angel"]) \ == ["geese"] # nd1d = utils.n_dim_index_from_one_dim for size in range(1,5): for i1d in range(size): assert nd1d(i1d=i1d, sizes=(size,)) == [i1d] for sizes in [(1,1), (1,3), (3,1), (2,3)]: ni, nj = sizes for i in range(ni): for j in range(nj): i1d = i*nj+j assert nd1d(i1d=i1d, sizes=sizes) == [i,j] for sizes in [(1,1,1), (1,3,1), (3,2,1), (4,3,2)]: ni, nj, nk = sizes for i in range(ni): for j in range(nj): for k in range(nk): i1d = (i*nj+j)*nk+k assert nd1d(i1d=i1d, sizes=sizes) == [i,j,k] # from libtbx import easy_run b = easy_run.fully_buffered( command="libtbx.raise_exception_for_testing") for lines in [b.stdout_lines, b.stderr_lines]: assert lines[0].startswith("EXCEPTION_INFO: show_stack(0): ") assert lines[-1] == "EXCEPTION_INFO: RuntimeError: Just for testing." b = easy_run.fully_buffered( command="libtbx.raise_exception_for_testing silent") b.raise_if_errors_or_output() # frange = utils.frange samples = utils.samples assert approx_equal([i/10. for i in range(-2,2)], frange(-0.2,0.2,0.1)) assert approx_equal([i/10. for i in range(-2,2+1)], samples(-0.2,0.2,0.1)) assert approx_equal([i/10. for i in range(2,-2,-1)], frange(0.2,-0.2,-0.1)) assert approx_equal([i/10. for i in range(2,-2-1,-1)], samples(0.2,-0.2,-0.1)) assert approx_equal([i/4. for i in range(4,8)], frange(1, 2, 0.25)) assert approx_equal([i/4. for i in range(4,8+1)], samples(1, 2, 0.25)) assert approx_equal([0.2+i/3. for i in range(4)], frange(0.2, 1.3, 1./3)) assert approx_equal([0.2+i/3. for i in range(4)], samples(0.2, 1.3, 1./3)) assert approx_equal(list(range(5)) , frange(5)) assert approx_equal(list(range(5+1)) , samples(5)) assert approx_equal(list(range(-5)), frange(-5)) assert approx_equal(list(range(-5-1)), samples(-5)) assert approx_equal(list(range(1,3)), frange(1, 3)) assert approx_equal(list(range(1,3+1)), samples(1, 3)) assert approx_equal([i/10. for i in range(20,9,-2)], frange(2.0,0.9,-0.2)) assert approx_equal([i/10. for i in range(20,9,-2)], samples(2.0,0.9,-0.2)) # ff = utils.format_float_with_standard_uncertainty assert ff(21.234567, 0.0013) == "21.2346(13)" assert ff(21.234567, 0.0023) == "21.235(2)" assert ff(12345, 45) == "12350(50)" assert ff(12.3,1.2) == "12.3(12)" assert ff(-0.2451, 0.8135) == "-0.2(8)" assert ff(1.234, 0.196) == "1.2(2)" assert ff(1.234, 0.193) == "1.23(19)" # for n in range(4): assert len(utils.random_hex_code(number_of_digits=n)) == n # print("multiprocessing problem:", utils.detect_multiprocessing_problem()) # print("base36_timestamp():", utils.base36_timestamp(), "now") print("base36_timestamp():", utils.base36_timestamp( seconds_since_epoch=115855*365.2425*24*60*60), "year 115855 CE") # print("get_svn_revision():", utils.get_svn_revision()) print("get_build_tag():", utils.get_build_tag()) # concatenate_python_script # XXX the string concatenation here is required to trick libtbx.find_clutter, # which will warn about repetition of the future division import. script = """ from __future__ """ + """import division import os.path def foo(): print "bar" """ d = tempfile.mkdtemp() name = os.path.join(d, "tst_libtbx_utils_python_script.py") name2 = os.path.join(d, "tst_libtbx_utils_python_script2.py") open(name, "w").write(script) f = open(name2, "w") utils.concatenate_python_script(out=f, file_name=name) f.close() lines = open(name2).readlines() have_def = False for line in lines : assert (not "__future__" in line) if line.startswith("def foo"): have_def = True assert have_def
# print "get_svn_revision():", utils.get_svn_revision() print "get_build_tag():", utils.get_build_tag() # concatenate_python_script # XXX the string concatenation here is required to trick libtbx.find_clutter, # which will warn about repetition of the future division import. script = """ from __future__ """ + """import division import os.path def foo () : print "bar" """ open("tst_libtbx_utils_python_script.py", "w").write(script) f = open("tst_libtbx_utils_python_script2.py", "w") utils.concatenate_python_script( out=f, file_name="tst_libtbx_utils_python_script.py") f.close() lines = open("tst_libtbx_utils_python_script2.py").readlines() have_def = False for line in lines: assert (not "__future__" in line) if line.startswith("def foo"): have_def = True assert have_def def exercise_user_plus_sys_time(): s = StringIO() utils.user_plus_sys_time().show_elapsed(out=s, prefix="e: ") s = s.getvalue() assert s.startswith("e: ")
# concatenate_python_script # XXX the string concatenation here is required to trick libtbx.find_clutter, # which will warn about repetition of the future division import. script = """ from __future__ """ + """import division import os.path def foo () : print "bar" """ d = tempfile.mkdtemp() name = os.path.join(d, "tst_libtbx_utils_python_script.py") name2 = os.path.join(d, "tst_libtbx_utils_python_script2.py") open(name, "w").write(script) f = open(name2, "w") utils.concatenate_python_script(out=f, file_name=name) f.close() lines = open(name2).readlines() have_def = False for line in lines : assert (not "__future__" in line) if line.startswith("def foo") : have_def = True assert have_def def exercise_user_plus_sys_time(): s = StringIO() utils.user_plus_sys_time().show_elapsed(out=s, prefix="e: ") s = s.getvalue() assert s.startswith("e: ") assert s.endswith(" s")
# print "get_svn_revision():", utils.get_svn_revision() print "get_build_tag():", utils.get_build_tag() # concatenate_python_script # XXX the string concatenation here is required to trick libtbx.find_clutter, # which will warn about repetition of the future division import. script = """ from __future__ """ + """import division import os.path def foo () : print "bar" """ open("tst_libtbx_utils_python_script.py", "w").write(script) f = open("tst_libtbx_utils_python_script2.py", "w") utils.concatenate_python_script(out=f, file_name="tst_libtbx_utils_python_script.py") f.close() lines = open("tst_libtbx_utils_python_script2.py").readlines() have_def = False for line in lines : assert (not "__future__" in line) if line.startswith("def foo") : have_def = True assert have_def def exercise_user_plus_sys_time(): s = StringIO() utils.user_plus_sys_time().show_elapsed(out=s, prefix="e: ") s = s.getvalue() assert s.startswith("e: ") assert s.endswith(" s")