def fetch_pdb_data ( pdb_id, pdb_dir=None, sf_dir=None, log=None, verbose=False) : """ Copy data from local repository if defined and available, or download it from the PDB, and run cif_as_mtz. """ from mmtbx.command_line import fetch_pdb from mmtbx.command_line import cif_as_mtz if (log is None) : if (verbose) : log = sys.stdout else : log = null_out() pdb_file = "%s.pdb" % pdb_id cif_file = "%s-sf.cif" % pdb_id mtz_file = "%s.mtz" % pdb_id fetch_pdb.run2(args=[pdb_id], log=log) assert (os.path.isfile(pdb_file)) fetch_pdb.run2(args=["-x", pdb_id], log=log) if (not os.path.isfile("%s-sf.cif" % pdb_id)) : raise Sorry("Structure factors are not available for %s." % pdb_id) cif_as_mtz.run(args=[ cif_file, "--symmetry=%s" % pdb_file, "--merge", "--output_file_name=%s" % mtz_file]) if (not os.path.isfile(mtz_file)) : raise RuntimeError("Missing %s!\ncif_as_mtz stderr:\n%s" % (mtz_file, "\n".join(import_out.stderr_lines))) return os.path.abspath(pdb_file), os.path.abspath(mtz_file)
def fetch_pdb_data(pdb_id, pdb_dir=None, sf_dir=None, log=None, verbose=False): """ Copy data from local repository if defined and available, or download it from the PDB, and run cif_as_mtz. """ from mmtbx.command_line import fetch_pdb from mmtbx.command_line import cif_as_mtz if (log is None): if (verbose): log = sys.stdout else: log = null_out() pdb_file = "%s.pdb" % pdb_id cif_file = "%s-sf.cif" % pdb_id mtz_file = "%s.mtz" % pdb_id fetch_pdb.run2(args=[pdb_id], log=log) assert (os.path.isfile(pdb_file)) fetch_pdb.run2(args=["-x", pdb_id], log=log) if (not os.path.isfile("%s-sf.cif" % pdb_id)): raise Sorry("Structure factors are not available for %s." % pdb_id) cif_as_mtz.run(args=[ cif_file, "--symmetry=%s" % pdb_file, "--merge", "--output_file_name=%s" % mtz_file ]) if (not os.path.isfile(mtz_file)): raise RuntimeError("Missing %s!\ncif_as_mtz stderr:\n%s" % (mtz_file, "\n".join(import_out.stderr_lines))) return os.path.abspath(pdb_file), os.path.abspath(mtz_file)
def combine_split_structure( pdb_file, pdb_id, base_dir=None, log=None): """ Assembles complete structures from split PDB files (e.g. ribosomes), preserving the original file name. Return value is a list of IDs which were added to the current model (or None). """ from mmtbx.command_line import fetch_pdb from iotbx import pdb if (log is None) : log = sys.stdout pdb_in = pdb.input(file_name=pdb_file) title = pdb_in.title_section() other_ids = None for line in title : if (line.startswith("SPLIT")): fields = line.strip().lower().split() other_ids = fields[1:] assert (len(other_ids) > 0) if (other_ids is not None): pdb_files = [pdb_file] combined_ids = [] for other_id in other_ids : if (other_id.lower() == pdb_id.lower()): continue dest_dir_2 = os.path.join(base_dir, other_id) if (not os.path.isdir(dest_dir_2)): dest_dir_2 = os.getcwd() pdb_file_2 = os.path.join(dest_dir_2, "%s.pdb" % other_id) if (not os.path.isfile(pdb_file_2)): fetch_pdb.run2(args=[other_id]) if (not os.path.isfile(pdb_file_2)): break pdb_files.append(pdb_file_2) combined_ids.append(other_id) if (len(pdb_files) > 1): pdb_all = os.path.join(base_dir, "%s_new.pdb" % pdb_id) print >> log, "Joining multi-part structure: %s %s" % (pdb_id, " ".join(other_ids)) easy_run.call("iotbx.pdb.join_fragment_files %s > %s" % (" ".join(pdb_files), pdb_all)) os.remove(pdb_file) os.rename(pdb_all, pdb_file) return combined_ids return None
def combine_split_structure ( pdb_file, pdb_id, base_dir=None, log=None) : """ Assembles complete structures from split PDB files (e.g. ribosomes), preserving the original file name. Return value is a list of IDs which were added to the current model (or None). """ from mmtbx.command_line import fetch_pdb from iotbx import pdb if (log is None) : log = sys.stdout pdb_in = pdb.input(file_name=pdb_file) title = pdb_in.title_section() other_ids = None for line in title : if (line.startswith("SPLIT")) : fields = line.strip().lower().split() other_ids = fields[1:] assert (len(other_ids) > 0) if (other_ids is not None) : pdb_files = [pdb_file] combined_ids = [] for other_id in other_ids : if (other_id.lower() == pdb_id.lower()) : continue dest_dir_2 = os.path.join(base_dir, other_id) if (not os.path.isdir(dest_dir_2)) : dest_dir_2 = os.getcwd() pdb_file_2 = os.path.join(dest_dir_2, "%s.pdb" % other_id) if (not os.path.isfile(pdb_file_2)) : fetch_pdb.run2(args=[other_id]) if (not os.path.isfile(pdb_file_2)) : break pdb_files.append(pdb_file_2) combined_ids.append(other_id) if (len(pdb_files) > 1) : pdb_all = os.path.join(base_dir, "%s_new.pdb" % pdb_id) print >> log, "Joining multi-part structure: %s %s" % (pdb_id, " ".join(other_ids)) easy_run.call("iotbx.pdb.join_fragment_files %s > %s" % (" ".join(pdb_files), pdb_all)) os.remove(pdb_file) os.rename(pdb_all, pdb_file) return combined_ids return None
def get_pdb_files(pdb_code,pdbcif=False) : from mmtbx.command_line import fetch_pdb # note that mtz and pdb cif can't be done simultaneously if pdbcif : args=["-c", pdb_code] else : args=["--mtz", pdb_code] data_files = fetch_pdb.run2(args) if pdbcif : return {"pdbcif":data_files} d = {} for df in data_files : df_input_file = any_file(df) if df_input_file.file_type == "hkl" : if df.endswith('.mtz') : d["hklmtz"] = df elif df.endswith('.cif') : d["hklcif"] = df elif df_input_file.file_type == "pdb": d["pdb"] = df elif df_input_file.file_type == "seq": d["seq"] = df return d
def download_coords(struct): if not os.path.isfile(struct + ".pdb"): from mmtbx.command_line.fetch_pdb import run2 run2([struct])
def create_reference_results_from_pdb(): from mmtbx.command_line.fetch_pdb import run2 run2(["1m2a"]) pdb_lines = open("1m2a.pdb").read() return pdb_lines