def test_get_clashscore_internal(self): """ check that we get CCTBX clashscores """ print sys._getframe().f_code.co_name fn = '1G9W' # fetch pdb file fn = fetch.get_pdb (fn,'pdb',mirror='rcsb',log=null_out()) self.file_to_delete.append(fn) simple,sym,solv,all = cvp.get_cctbx_clashscores(file_name=fn) self.assertEqual(round(simple+sym+solv),round(all))
def test_get_probe_clashscore(self): """ check that we get PROBE clashscores """ print sys._getframe().f_code.co_name fn = '1G9W' # fetch pdb file fn = fetch.get_pdb (fn,'pdb',mirror='rcsb',log=null_out()) self.file_to_delete.append(fn) clashscore = cvp.get_probe_clashscore(file_name=fn) self.assertEqual(round(clashscore),0)
def test_1nl0(self): '''Compare to published value''' fn = '1nl0' pdb_fn = fetch.get_pdb (fn,data_type='pdb',mirror='rcsb',log=null_out()) ph = pdb.input(file_name=pdb_fn).construct_hierarchy() fab = fab_elbow_angle(pdb_hierarchy=ph,limit_light=107,limit_heavy=113) calculated = fab.fab_elbow_angle expected = 220 msg = 'FAB angle for {0} is {1:3.0f} instead of {2}'.format(fn,calculated,expected) self.assertAlmostEqual(calculated,expected,delta=self.delta,msg=msg)
def get_cif_file(pdb_id): """ get the cif file """ try: fetched_file = fetch.get_pdb( id=pdb_id, data_type='xray', mirror='rcsb',quiet=True,log=null_out()) return fetched_file except: # avoid error if file already exist pass return False
def test_get_updated_file_name(self): """ check updating file using phenix.reduce """ print sys._getframe().f_code.co_name fn_start = '2H77' # fetch pdb file fn = fetch.get_pdb (fn_start,'pdb',mirror='rcsb',log=null_out()) self.file_to_delete.append(fn) update_fn = cvp.get_updated_file_name(file_name=fn) expected = fn_start + '.updated.pdb' self.assertEqual(expected,update_fn) self.file_to_delete.append(update_fn)
def get_pdb_file_info(self,pdb_id): """ Collect pdb file NCS and header info if there are NCS relations and reslution >= 3 Args: pdb_id (str): collect info for a single pdb file Return: new_rec (File_records object): object containing the collected info """ new_rec = File_records() new_rec.pdb_id = pdb_id fetched_file = pdb_id + '.pdb' if not os.path.isfile(fetched_file): fetched_file = fetch.get_pdb ( id=pdb_id, data_type='pdb', mirror='rcsb',quiet=True,log=null_out()) else: print 'file exist in local folder, did not fetch it..' fn = os.path.realpath(fetched_file) pdb_inp = iotbx.pdb.input(file_name=fn) mtrix_info = pdb_inp.process_mtrix_records(eps=0.01) t = (mtrix_info.as_pdb_string() == '') t |= (not ncs_only(mtrix_info)) new_rec.only_master_in_pdb = not t if len(mtrix_info.r) > 0 and new_rec.only_master_in_pdb: m = multimer(file_name=fn,reconstruction_type='cau') m.write( pdb_output_file_name=fn, crystal_symmetry=pdb_inp.crystal_symmetry()) # note that now the fn is a complete ASU ncs_obj = iotbx.ncs.input(file_name=fn) if (ncs_obj.number_of_ncs_groups == 0): os.remove(fn) return None new_rec.n_ncs_groups = ncs_obj.number_of_ncs_groups new_rec.n_ncs_copies = len(ncs_obj.ncs_transform) pio = pdb_inp.get_r_rfree_sigma() new_rec.resolution = pio.resolution if new_rec.resolution and (new_rec.resolution < 3): os.remove(fn) return None new_rec.year = pdb_inp.extract_header_year() new_rec.experiment_type = pdb_inp.get_experiment_type() new_rec.r_work_header = pio.r_work new_rec.r_free_header = pio.r_free try: shutil.move(fn,self.asu_dir) except: # avoid error if file already exist pass return new_rec
def get_pdb_file(file_name): from iotbx.pdb import fetch class null_out(object): """Pseudo-filehandle for suppressing printed output.""" def isatty(self): return False def close(self): pass def flush(self): pass def write(self, str): pass def writelines(self, sequence): pass log = null_out() file_name = get_file_name(file_name) return fetch.get_pdb (file_name,'pdb',mirror='rcsb',log=log)
def get_file_from_rcsb(pdb_id,data_type='pdb'): """ (file_name) -> file_path fetch pdb or structure factor file for pdb_id from the RCSB website Args: file_name: a pdb file name data_type (str): 'pdb' -> pdb 'xray' -> structure factor Returns: a file path for the pdb file_name """ try: file_name = fetch.get_pdb(pdb_id,data_type,mirror='rcsb',log=null_out()) except Sorry: file_name = '' return file_name
def get_pdb_file(file_name,fetch_file=False,print_out=True): ''' (file_name) -> file_path This function will check if a pdb file_name exist. If it is not, it will either fetch it from the RCSB website or find it on LBLs pdb mirror folder Argument: file_name: a pdb file name Return: a file path for the pdb file_name ''' from iotbx.pdb import fetch class null_out(object): """Pseudo-filehandle for suppressing printed output.""" def isatty(self): return False def close(self): pass def flush(self): pass def write(self, str): pass def writelines(self, sequence): pass log = null_out() if not os.path.isfile(file_name): # get a clean pdb file name if print_out: print 'No such file in working directory. Trying to fetch {} file from RCSB web site'.format(file_name) file_name = get_file_name(file_name) osType = sys.platform if osType.startswith('win') or fetch_file==True: # fetch pdb file file_name = fetch.get_pdb (file_name,'pdb',mirror='rcsb',log=log) else: # find the file in LBL pdb mirror folder pdb_dir = os.environ["PDB_MIRROR_PDB"] pdb_files = open(os.path.join(pdb_dir, "INDEX"), "r").read().splitlines() for i,p in enumerate(pdb_files): if file_name in p: break file_name = os.path.join(pdb_dir,pdb_files[i]) elif print_out: print 'Using the file {} found in the working directory'.format(file_name) return file_name
def get_pdb_file(file_name, print_out=True): """ (file_name) -> file_path This function will check if a pdb file_name exist. If it is not, it will either fetch it from the RCSB website or find it on LBLs pdb mirror folder Args: file_name (str): a pdb file name Returns: file_name (str): the location, path, of the file """ if not os.path.isfile(file_name): # get a clean pdb file name if print_out: s = 'No such file in working directory. ' \ 'Trying to fetch {} file from RCSB web site' print s.format(file_name) file_name = get_4_letters_pdb_id(file_name) osType = sys.platform if osType.startswith('win'): from iotbx.pdb import fetch # fetch pdb file from intenet file_name = fetch.get_pdb (file_name,'pdb',mirror='rcsb',log=null_out()) else: # find the file in LBL pdb mirror folder pdb_dir = os.environ["PDB_MIRROR_PDB"] pdb_files = open(os.path.join(pdb_dir, "INDEX"), "r").read().splitlines() for i,p in enumerate(pdb_files): if file_name in p: break file_name = os.path.join(pdb_dir,pdb_files[i]) # # Second method # f = 'pdb{}.ent.gz'.format(file_name) # file_name = [] # for root, _, files in os.walk(pdb_dir): # if f in files: # file_name = os.path.join(root, f) # break elif print_out: print 'Using the file {} found in the working directory'.format(file_name) return file_name
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
from iotbx.pdb.fetch import get_pdb import sys get_pdb(id="3nd4", data_type="xray", mirror="rcsb", format="cif", log=sys.stdout)
def run2(args, log=sys.stdout): """ Fetches pdb files and/or reflection data from the PDB. Parameters ---------- args : list of str log : file, optional Returns ------- str or list of str List of file names that were downloaded. """ if len(args) < 1: raise Usage("""\ phenix.fetch_pdb [-x|-f|--all] [--mtz] [-q] ID1 [ID2, ...] Command-line options: -x Get structure factors (mmCIF file) -c Get model file in mmCIF format -f Get sequence (FASTA file) --all Download all available data --mtz Download structure factors and PDB file, and generate MTZ -q suppress printed output """) from iotbx.pdb.fetch import get_pdb quiet = False convert_to_mtz = False data_type = "pdb" format = "pdb" mirror = "rcsb" ids = [] for arg in args: if (arg == "--all"): data_type = "all" elif (arg == "-x"): data_type = "xray" elif (arg == "-f"): data_type = "fasta" elif (arg == "-q"): quiet = True elif (arg == "--mtz"): convert_to_mtz = True data_type = "all" elif (arg == "-c"): format = "cif" elif (arg.startswith("--mirror=")): mirror = arg.split("=")[1] if (not mirror in ["rcsb", "pdbe", "pdbj", "pdb-redo"]): raise Sorry( "Unrecognized mirror site '%s' (choices: rcsb, pdbe, pdbj, pdb-redo)" % mirror) else: ids.append(arg) if (len(ids) == 0): raise Sorry("No PDB IDs specified.") if (data_type != "all"): #mirror = "rcsb" files = [] for id in ids: files.append(get_pdb(id, data_type, mirror, log, format=format)) if (len(files) == 1): return files[0] return files else: files = [] for id in ids: for data_type_, data_format in [("pdb", "pdb"), ("fasta", "pdb"), ("xray", "pdb"), ("pdb", "cif")]: files.append( get_pdb(id, data_type_, mirror, log, format=data_format)) if (convert_to_mtz): misc_args = [ "--merge", "--map_to_asu", "--extend_flags", "--ignore_bad_sigmas" ] easy_run.call("phenix.cif_as_mtz %s-sf.cif %s" % (id, " ".join(misc_args))) if os.path.isfile("%s-sf.mtz" % id): os.rename("%s-sf.mtz" % id, "%s.mtz" % id) print >> log, "Converted structure factors saved to %s.mtz" % id # os.remove("%s-sf.cif" % id) files[-1] = os.path.abspath("%s.mtz" % id) if (not os.path.isfile("%s.mtz" % id)): raise Sorry( "MTZ conversion failed - try running phenix.cif_as_mtz " + "manually (and check %s-sf.cif for format errors)." % id) from iotbx.file_reader import any_file mtz_in = any_file("%s.mtz" % id) mtz_in.assert_file_type("hkl") for array in mtz_in.file_server.miller_arrays: if (array.anomalous_flag()): print >> log, " %s is anomalous" % array.info( ).label_string() return files
def get_file(fn): if not os.path.isfile(fn + '.pdb'): sf_fn = fetch.get_pdb (fn,data_type='pdb',mirror='rcsb',log=sys.stdout)
# Description: Fetch pdb file from RCSB in PDB format. # Source: NA """ from iotbx.pdb.fetch import get_pdb import sys get_pdb(id="${1:3nd4}",data_type="pdb", mirror="rcsb", format="pdb", log=sys.stdout) """ from iotbx.pdb.fetch import get_pdb import sys get_pdb(id="3nd4",data_type="pdb", mirror="rcsb", format="pdb", log=sys.stdout)
def run2(args, log=sys.stdout): """ Fetches pdb files and/or reflection data from the PDB. Parameters ---------- args : list of str log : file, optional Returns ------- str or list of str List of file names that were downloaded. """ if len(args) < 1: raise Usage( """\ phenix.fetch_pdb [-x|-f|--all] [--mtz] [-q] ID1 [ID2, ...] Command-line options: -x Get structure factors (mmCIF file) -c Get model file in mmCIF format -f Get sequence (FASTA file) --all Download all available data --mtz Download structure factors and PDB file, and generate MTZ -q suppress printed output """ ) from iotbx.pdb.fetch import get_pdb quiet = False convert_to_mtz = False data_type = "pdb" format = "pdb" mirror = "rcsb" ids = [] for arg in args: if arg == "--all": data_type = "all" elif arg == "-x": data_type = "xray" elif arg == "-f": data_type = "fasta" elif arg == "-q": quiet = True elif arg == "--mtz": convert_to_mtz = True data_type = "all" elif arg == "-c": format = "cif" elif arg.startswith("--mirror="): mirror = arg.split("=")[1] if not mirror in ["rcsb", "pdbe", "pdbj"]: raise Sorry("Unrecognized mirror site '%s' (choices: rcsb, pdbe, pdbj)" % mirror) else: ids.append(arg) if len(ids) == 0: raise Sorry("No PDB IDs specified.") if data_type != "all": # mirror = "rcsb" files = [] for id in ids: files.append(get_pdb(id, data_type, mirror, log, format=format)) if len(files) == 1: return files[0] return files else: files = [] for id in ids: for data_type_, data_format in [("pdb", "pdb"), ("fasta", "pdb"), ("xray", "pdb"), ("pdb", "cif")]: files.append(get_pdb(id, data_type_, mirror, log, format=data_format)) if convert_to_mtz: misc_args = ["--merge", "--map_to_asu", "--extend_flags", "--ignore_bad_sigmas"] easy_run.call("phenix.cif_as_mtz %s-sf.cif %s" % (id, " ".join(misc_args))) if os.path.isfile("%s-sf.mtz" % id): os.rename("%s-sf.mtz" % id, "%s.mtz" % id) print >> log, "Converted structure factors saved to %s.mtz" % id # os.remove("%s-sf.cif" % id) files[-1] = os.path.abspath("%s.mtz" % id) if not os.path.isfile("%s.mtz" % id): raise Sorry( "MTZ conversion failed - try running phenix.cif_as_mtz " + "manually (and check %s-sf.cif for format errors)." % id ) from iotbx.file_reader import any_file mtz_in = any_file("%s.mtz" % id) mtz_in.assert_file_type("hkl") for array in mtz_in.file_server.miller_arrays: if array.anomalous_flag(): print >> log, " %s is anomalous" % array.info().label_string() return files
def get_file(fn): if len(fn)==4: fn = fn + '.pdb' if not os.path.isfile(fn): fn = fetch.get_pdb (fn,data_type='pdb',mirror='rcsb',log=sys.stdout) return fn
def __init__(self, pdb_file_name, chain_ID_light='L', chain_ID_heavy='H', limit_light=107, limit_heavy=113): ''' Get elbow angle for Fragment antigen-binding (Fab) - Default heavy and light chains IDs are: H : heavy, L : light - Default limit (cutoff) between variable and constant parts is residue number 107/113 for light/heavy chains - Variable domain si from residue 1 to limit. Constant domain form limit+1 to end. - Method of calculating angle is based on Stanfield, et al., JMB 2006 Argument: --------- pdb_file_name : 4 characters string, a PDB name chain_ID_heavy : The heavy protion of the protein, chain ID chain_ID_light : The light protion of the protein, chain ID limit_heavy : the number of the cutoff residue, between the variable and constant portions in the heavy chian limit_light : the number of the cutoff residue, between the variable and constant portions in the light chian Main attributes: ---------------- self.FAB_elbow_angle : the elbow angle calculated as the dot product of the VL-VH pseudodyade axie and the CL-CH pseudodyade axie The angle always computes between 90 and 180 Test program at: cctbx_project\mmtbx\regression\tst_FAB_elbow_angle.py Example: -------- >>>fab = FAB_elbow_angle( pdb_file_name='1bbd', chain_ID_light='L', chain_ID_heavy='H', limit_light=114, limit_heavy=118) >>> print fab.FAB_elbow_angle 133 >>>fab = FAB_elbow_angle(pdb_file_name='1bbd') >>> print fab.FAB_elbow_angle 126 (127 in Stanfield, et al., JMB 2006) >>> print fab.var_L 'VL from N ASP L 1 to O GLY L 107 ' >>> print fab.var_L_nAtoms 826 @author Youval Dar (LBL 2014) ''' # abolute path and test that file exist pdb_file_name = self.get_pdb_file_name_and_path(pdb_file_name) # Devide to variable and constant part, and get the hirarchy for # H : heavy, L : light # start_to_limit : Constant # limit_to_end : Variable pdb_var_H,pdb_const_H = self.get_pdb_protions( pdb_file_name=pdb_file_name, chain_ID=chain_ID_heavy, limit=limit_heavy) pdb_var_L,pdb_const_L = self.get_pdb_protions( pdb_file_name=pdb_file_name, chain_ID=chain_ID_light, limit=limit_light) # Collect info about FAB segments self.var_L,self.var_L_nAtoms = self.get_segment_info(pdb_var_L,'VL') self.var_H,self.var_H_nAtoms = self.get_segment_info(pdb_var_H,'VH') self.const_L,self.const_L_nAtoms = self.get_segment_info(pdb_const_L,'CL') self.const_H,self.const_H_nAtoms = self.get_segment_info(pdb_const_H,'CH') # get 1bbd currnet_dir = os.getcwd() tempdir = tempfile.mkdtemp('tempdir') os.chdir(tempdir) fetch.get_pdb ('1bbd',data_type='pdb',mirror='rcsb',log=null_out()) # seperate chains for testing and referance test_var_H,test_const_H = self.get_pdb_protions( pdb_file_name=pdb_file_name, chain_ID=chain_ID_heavy, limit=limit_heavy) pdb_ref_var_H,pdb_ref_const_H = self.get_pdb_protions( pdb_file_name='1bbd.pdb', chain_ID=chain_ID_heavy, limit=limit_heavy) # clean temp folder os.chdir(currnet_dir) shutil.rmtree(tempdir) # get rotation and translation tranformation_const = self.get_transformation( pdb_hierarchy_fixed=pdb_const_H, pdb_hierarchy_moving=pdb_const_L) tranformation_var = self.get_transformation( pdb_hierarchy_fixed=pdb_var_H, pdb_hierarchy_moving=pdb_var_L) tranformation_ref_const = self.get_transformation( pdb_hierarchy_fixed=pdb_ref_const_H, pdb_hierarchy_moving=test_const_H) # Apply transformation on the variable portion of the tesed protein new_sites = tranformation_ref_const.r.elems*test_var_H.atoms().extract_xyz() + tranformation_ref_const.t test_var_H.atoms().set_xyz(new_sites) # get rotation and translation tranformation_ref_var = self.get_transformation( pdb_hierarchy_fixed=pdb_ref_var_H, pdb_hierarchy_moving=test_var_H) # Get the angle and eigenvalues eigen_const = eigensystem.real_symmetric(tranformation_const.r.as_sym_mat3()) eigen_var = eigensystem.real_symmetric(tranformation_var.r.as_sym_mat3()) eigen_ref = eigensystem.real_symmetric(tranformation_ref_var.r.as_sym_mat3()) # eigen_vectors_const = self.get_eigenvector(eigen_const) eigen_vectors_var = self.get_eigenvector(eigen_var) eigen_vectors_var_ref = self.get_eigenvector(eigen_ref) # angle = self.get_angle(vec1=eigen_vectors_const, vec2=eigen_vectors_var) print '+'*30 ref_angle = self.get_angle(vec1=eigen_vectors_var_ref, vec2=eigen_vectors_var,larger=False) # Resolve ambiguity with angle if ref_angle > 90: ref_angle = 180 - ref_angle if angle + ref_angle > 180: # Choose angle smaller than 180 angle = 360 - angle self.FAB_elbow_angle = angle