def run(args, out=None, driver_class=None, require_single_conformer_starting_model=False): import mmtbx.utils if (out is None): out = sys.stdout usage_string = """phenix.alternator model.pdb data.mtz [selection=...] [options]""" cmdline = mmtbx.command_line.load_model_and_data(args=args, master_phil=master_phil(), process_pdb_file=True, usage_string=usage_string, out=out, create_log_buffer=True) params = cmdline.params if (params.output.output_dir is not None): os.chdir(params.output.output_dir) dir_name = os.getcwd() if (params.output.create_dir): dir_name = create_run_directory( "alt_confs", default_directory_number=params.output.directory_number) os.chdir(dir_name) log = cmdline.start_log_file("%s.log" % params.output.prefix) print >> log, "Output will be in %s" % dir_name #working_phil = master_phil.format(python_object=params) #make_sub_header("Final input parameters", out=log) #master_phil.fetch_diff(source=working_phil).show(out=log) if (driver_class is None): driver_class = build_and_refine multi_conf_selection = alternate_conformations.multi_conformer_selection( pdb_hierarchy=cmdline.pdb_hierarchy) if ((len(multi_conf_selection) != 0) and require_single_conformer_starting_model): atoms = cmdline.pdb_hierarchy.select(multi_conf_selection).atoms() print >> log, "First %d atoms with alternate conformations:" % min( 10, len(atoms)) for atom in atoms[0:10]: print >> log, atom.format_atom_record() raise Sorry( "Existing alternate conformations detected - this program " + "can only be run on a single-conformer model at present.") driver = driver_class(params=params.alt_confs, fmodel=cmdline.fmodel, pdb_hierarchy=cmdline.pdb_hierarchy, processed_pdb_file=cmdline.processed_pdb_file, geometry_restraints_manager=cmdline.geometry, cif_objects=[o for (f, o) in cmdline.cif_objects], cif_files=params.input.monomers.file_name, debug=params.output.debug, verbose=params.output.verbose, out=log) output_file_base = os.path.join(os.getcwd(), params.output.prefix) driver.write_pdb_file(output_file_base + ".pdb", remove_hd=params.output.remove_hydrogens) driver.write_map_file(output_file_base + ".mtz") # TODO final result object return driver.pdb_hierarchy
def run (args, out=None, driver_class=None, require_single_conformer_starting_model=False) : import mmtbx.utils if (out is None) : out = sys.stdout usage_string = """phenix.alternator model.pdb data.mtz [selection=...] [options]""" cmdline = mmtbx.command_line.load_model_and_data( args=args, master_phil=master_phil(), process_pdb_file=True, usage_string=usage_string, out=out, create_log_buffer=True) params = cmdline.params if (params.output.output_dir is not None) : os.chdir(params.output.output_dir) dir_name = os.getcwd() if (params.output.create_dir) : dir_name = create_run_directory("alt_confs", default_directory_number=params.output.directory_number) os.chdir(dir_name) log = cmdline.start_log_file("%s.log" % params.output.prefix) print >> log, "Output will be in %s" % dir_name #working_phil = master_phil.format(python_object=params) #make_sub_header("Final input parameters", out=log) #master_phil.fetch_diff(source=working_phil).show(out=log) if (driver_class is None) : driver_class = build_and_refine multi_conf_selection = alternate_conformations.multi_conformer_selection( pdb_hierarchy=cmdline.pdb_hierarchy) if ((len(multi_conf_selection) != 0) and require_single_conformer_starting_model) : atoms = cmdline.pdb_hierarchy.select(multi_conf_selection).atoms() print >> log, "First %d atoms with alternate conformations:" % min(10, len(atoms)) for atom in atoms[0:10] : print >> log, atom.format_atom_record() raise Sorry("Existing alternate conformations detected - this program "+ "can only be run on a single-conformer model at present.") driver = driver_class( params=params.alt_confs, fmodel=cmdline.fmodel, pdb_hierarchy=cmdline.pdb_hierarchy, processed_pdb_file=cmdline.processed_pdb_file, geometry_restraints_manager=cmdline.geometry, cif_objects=[ o for (f,o) in cmdline.cif_objects ], cif_files=params.input.monomers.file_name, debug=params.output.debug, verbose=params.output.verbose, out=log) output_file_base = os.path.join(os.getcwd(), params.output.prefix) driver.write_pdb_file(output_file_base + ".pdb", remove_hd=params.output.remove_hydrogens) driver.write_map_file(output_file_base + ".mtz") # TODO final result object return driver.pdb_hierarchy
def exercise_dir_utils(): dirs = ["tst_utils_1", "tst_utils_2", "tst_utils_45"] for dir_name in dirs : if (os.path.isdir(dir_name)) : os.rmdir(dir_name) dir_name = utils.create_run_directory("tst_utils") assert (os.path.basename(dir_name) == "tst_utils_1") dir_name = utils.create_run_directory("tst_utils") assert (os.path.basename(dir_name) == "tst_utils_2") dir_name = utils.create_run_directory("tst_utils", 45) assert (os.path.basename(dir_name) == "tst_utils_45") for dir_name in dirs : os.rmdir(dir_name) file_name = "/cctbx/%s/%s/XXXX.pdb" % (random.random(), random.random()) try : utils.check_if_output_directory_exists(file_name) except utils.Sorry : pass else : raise Exception_expected dir_name = os.getcwd() utils.check_if_output_directory_exists(dir_name=dir_name) dir_created = False if (not os.path.exists("Dropbox")): os.mkdir("Dropbox") dir_created = True dir_name = os.path.join(os.getcwd(), "Dropbox") with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") utils.check_if_output_directory_exists(dir_name=dir_name) assert len(w) == 1 assert "Dropbox directory" in str(w[-1].message) if (dir_created): os.rmdir("Dropbox") host_info = utils.host_and_user() assert not utils.allow_delete_directory(host_info.homedir) target_dir = os.path.join(host_info.homedir, "Downloads") assert not utils.allow_delete_directory(target_dir) target_dir = os.path.join(host_info.homedir, "data", "lysozyme") assert utils.allow_delete_directory(target_dir)
def exercise_dir_utils () : dirs = ["tst_utils_1", "tst_utils_2", "tst_utils_45"] for dir_name in dirs : if (os.path.isdir(dir_name)) : os.rmdir(dir_name) dir_name = utils.create_run_directory("tst_utils") assert (os.path.basename(dir_name) == "tst_utils_1") dir_name = utils.create_run_directory("tst_utils") assert (os.path.basename(dir_name) == "tst_utils_2") dir_name = utils.create_run_directory("tst_utils", 45) assert (os.path.basename(dir_name) == "tst_utils_45") for dir_name in dirs : os.rmdir(dir_name) file_name = "/cctbx/%s/%s/XXXX.pdb" % (random.random(), random.random()) try : utils.check_if_output_directory_exists(file_name) except utils.Sorry : pass else : raise Exception_expected dir_name = os.getcwd() utils.check_if_output_directory_exists(dir_name=dir_name) dir_created = False if (not os.path.exists("Dropbox")) : os.mkdir("Dropbox") dir_created = True dir_name = os.path.join(os.getcwd(), "Dropbox") with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") utils.check_if_output_directory_exists(dir_name=dir_name) assert len(w) == 1 assert "Dropbox directory" in str(w[-1].message) if (dir_created) : os.rmdir("Dropbox") host_info = utils.host_and_user() assert not utils.allow_delete_directory(host_info.homedir) target_dir = os.path.join(host_info.homedir, "Downloads") assert not utils.allow_delete_directory(target_dir) target_dir = os.path.join(host_info.homedir, "data", "lysozyme") assert utils.allow_delete_directory(target_dir)