def validate_single_model(self, i_model): hierarchy = self.pdb_hierarchies[i_model] rama_validation = ramalyze.ramalyze(pdb_hierarchy=hierarchy, outliers_only=False) rota_validation = rotalyze.rotalyze(pdb_hierarchy=hierarchy, outliers_only=False) return rama_validation, rota_validation
def worker(in_queue, out_queue): while True: if in_queue.empty(): exit(0) pdb_id = in_queue.get() decompress_pdb_redo_dir(pdb_id, suffixes={0}) pdb_path = os.path.join(PDB_REDO_DATA_DIR, pdb_id, pdb_id + '_0cyc.pdb') pdb_in = file_reader.any_file(file_name=pdb_path) hierarchy = pdb_in.file_object.hierarchy rota_analysis = rotalyze.rotalyze(pdb_hierarchy=hierarchy, outliers_only=False) out = StringIO() rota_analysis.show_old_output(out=out, verbose=False) output = out.getvalue() results = {} for pair in CLASSIFICATION_PAIRS: results[pair] = 0 for line in output.split('\n'): if len(line) == 0: continue chain_id = line[:2].strip() seqnum = int(line[2:6].strip()) splitline = [x.strip() for x in line[6:].split(':')] code = splitline[0] chis = [float(x) for x in splitline[3:7] if len(x) > 0] iris_class_int = rotamer.get_classification(code, chis) if iris_class_int == None: continue mp_class_char = splitline[-2][0].upper() mp_class_int = CLASSIFICATIONS[mp_class_char] results[(iris_class_int, mp_class_int)] += 1 cleanup_pdb_redo_dir(pdb_id) out_queue.put((pdb_id, results))
def exercise(): tst_build_simple.prepare_inputs("tst_altconfs_cmdline") assert os.path.isfile("tst_altconfs_cmdline_start.pdb") assert os.path.isfile("tst_altconfs_cmdline.mtz") args = [ "tst_altconfs_cmdline_start.pdb", "tst_altconfs_cmdline.mtz", "selection='chain A and resseq 3'", "output.file_name=tst_altconfs_cmdline_out.pdb", "expected_occupancy=0.4", "window_size=2", "nproc=1", "rsr_fofc_map_target=False", "create_dir=False", "prefix=tst_altconfs_cmdline_out", "--verbose", ] build_alternate_conformations.run(args=args, out=null_out()) pdb_out = file_reader.any_file("tst_altconfs_cmdline_out.pdb") hierarchy = pdb_out.file_object.construct_hierarchy() validate = rotalyze.rotalyze(pdb_hierarchy=hierarchy, data_version="8000", outliers_only=False) rota_out = [(r.id_str(), r.rotamer_name) for r in validate.results] #print rota_in assert (((' A 3 AASN', 't0') in rota_out) and ((' A 3 BASN', 'm-40') in rota_out))
def get_rotamers (file_name) : pdb_in = file_reader.any_file(file_name) hierarchy = pdb_in.file_object.hierarchy validate = rotalyze.rotalyze(pdb_hierarchy=hierarchy, data_version="8000", outliers_only=False) return [ (r.id_str(), r.rotamer_name) for r in validate.results ]
def get_rotamers(file_name): pdb_in = file_reader.any_file(file_name) hierarchy = pdb_in.file_object.hierarchy validate = rotalyze.rotalyze(pdb_hierarchy=hierarchy, data_version="8000", outliers_only=False) return [(r.id_str(), r.rotamer_name) for r in validate.results]
def rotamer(self): if self.cached_rota is None: self.cached_rota = rotalyze(pdb_hierarchy=self.pdb_hierarchy, outliers_only=False) return group_args( outliers=self.cached_rota.percent_outliers, rotalyze=self.cached_rota #XXX Bulky object -- REMOVE! )
def exercise_cmdline(): from mmtbx.command_line import extend_sidechains from mmtbx.regression import model_1yjp import iotbx.pdb.hierarchy pdb_file = "tst_extend_sidechains.pdb" mtz_file = "tst_extend_sidechains.mtz" pdb_in = iotbx.pdb.hierarchy.input(pdb_string=model_1yjp) xrs = pdb_in.input.xray_structure_simple() f_calc = abs(xrs.structure_factors(d_min=1.5).f_calc()) sel = pdb_in.hierarchy.atom_selection_cache().selection( "not (resname TYR and not (name c or name o or name n or name oxt or name ca or name cb))" ) hierarchy = pdb_in.hierarchy.select(sel) f = open(pdb_file, "w") f.write(hierarchy.as_pdb_string(crystal_symmetry=xrs)) f.close() flags = f_calc.generate_r_free_flags(fraction=0.1) mtz = f_calc.as_mtz_dataset(column_root_label="F") mtz.add_miller_array(flags, column_root_label="FreeR_flag") mtz.mtz_object().write(mtz_file) pdb_out = "tst_extend_sidechains_out.pdb" if os.path.isfile(pdb_out): os.remove(pdb_out) out = StringIO() extend_sidechains.run( args=[pdb_file, mtz_file, "output_model=%s" % pdb_out], out=out) assert ("1 sidechains extended." in out.getvalue()), out.getvalue() from mmtbx.validation import rotalyze pdb_new = iotbx.pdb.hierarchy.input(file_name=pdb_out) r1 = rotalyze.rotalyze(pdb_hierarchy=pdb_in.hierarchy, outliers_only=False) r2 = rotalyze.rotalyze(pdb_hierarchy=pdb_new.hierarchy, outliers_only=False) for o1, o2 in zip(r1.results, r2.results): assert o1.rotamer_name == o2.rotamer_name # Part 2: with sequence corrections seq_file = "tst_extend_sidechains.fa" with open(seq_file, "w") as f: f.write(">1yjp_new\nGNDQQNY") pdb_out = "tst_extend_sidechains_out2.pdb" extend_sidechains.run( args=[pdb_file, mtz_file, seq_file, "output_model=%s" % pdb_out], out=out) assert ("1 sidechains extended." in out.getvalue())
def validate_single_model (self, i_model) : hierarchy = self.pdb_hierarchies[i_model] rama_validation = ramalyze.ramalyze( pdb_hierarchy=hierarchy, outliers_only=False) rota_validation = rotalyze.rotalyze( pdb_hierarchy=hierarchy, outliers_only=False) return rama_validation, rota_validation
def exercise_cmdline () : from mmtbx.command_line import extend_sidechains from mmtbx.regression import model_1yjp import iotbx.pdb.hierarchy pdb_file = "tst_extend_sidechains.pdb" mtz_file = "tst_extend_sidechains.mtz" pdb_in = iotbx.pdb.hierarchy.input(pdb_string=model_1yjp) xrs = pdb_in.input.xray_structure_simple() f_calc = abs(xrs.structure_factors(d_min=1.5).f_calc()) sel = pdb_in.hierarchy.atom_selection_cache().selection( "not (resname TYR and not (name c or name o or name n or name oxt or name ca or name cb))") hierarchy = pdb_in.hierarchy.select(sel) f = open(pdb_file, "w") f.write(hierarchy.as_pdb_string(crystal_symmetry=xrs)) f.close() flags = f_calc.generate_r_free_flags(fraction=0.1) mtz = f_calc.as_mtz_dataset(column_root_label="F") mtz.add_miller_array(flags, column_root_label="FreeR_flag") mtz.mtz_object().write(mtz_file) pdb_out = "tst_extend_sidechains_out.pdb" if os.path.isfile(pdb_out) : os.remove(pdb_out) out = StringIO() extend_sidechains.run( args=[pdb_file, mtz_file, "output_model=%s" % pdb_out], out=out) assert ("1 sidechains extended." in out.getvalue()) from mmtbx.validation import rotalyze pdb_new = iotbx.pdb.hierarchy.input(file_name=pdb_out) r1 = rotalyze.rotalyze(pdb_hierarchy=pdb_in.hierarchy, outliers_only=False) r2 = rotalyze.rotalyze(pdb_hierarchy=pdb_new.hierarchy, outliers_only=False) for o1, o2 in zip(r1.results, r2.results) : assert o1.rotamer_name == o2.rotamer_name # Part 2: with sequence corrections seq_file = "tst_extend_sidechains.fa" open(seq_file, "w").write(">1yjp_new\nGNDQQNY") pdb_out = "tst_extend_sidechains_out2.pdb" extend_sidechains.run( args=[pdb_file, mtz_file, seq_file, "output_model=%s" % pdb_out], out=out) assert ("2 sidechains extended." in out.getvalue())
def run_rotalyze(self) : from mmtbx.validation import rotalyze rotalyze_result = rotalyze.rotalyze(self.hierarchy) for result in rotalyze_result.results : resd = mdb_utils.get_resd(self.pdb_code,result) MDBRes = mdb_utils.MDBResidue(**resd) reskey = MDBRes.get_residue_key() if reskey not in self.residues.keys(): # alternates likely exist reskeys = self.get_alternate_keys(resd) for k in reskeys : self.residues[k].add_rotalyze_result(result) else : # No alternates self.residues[reskey].add_rotalyze_result(result)
def generate_rotamer_data( pdb_hierarchy, exclude_outliers=True, data_version="8000", ): assert data_version == "8000", "data_version not recognized." r = rotalyze.rotalyze(pdb_hierarchy=pdb_hierarchy, data_version=data_version) for rot in r.results: #if rot.outlier: # print (rot.resname, # rot.id_str(), # rot.chain_id, # rot.altloc, # rot.rotamer_name) # assert 0 if exclude_outliers and rot.outlier: continue yield (rot.resname, rot.id_str(), rot.chain_id, rot.altloc, rot.rotamer_name)
def __init__( self, pdb_hierarchy, molprobity_scores=False, ): self.pdb_hierarchy = pdb_hierarchy self.clashscore = None self.ramachandran_outliers = None self.ramachandran_allowed = None self.ramachandran_favored = None self.rotamer_outliers = None self.c_beta_dev = None self.mpscore = None self.omglz = None self.n_cis_proline = None self.n_cis_general = None self.n_twisted_proline = None self.n_twisted_general = None if(molprobity_scores): self.ramalyze_obj = ramalyze(pdb_hierarchy=pdb_hierarchy, outliers_only=False) self.ramachandran_outliers = self.ramalyze_obj.percent_outliers self.ramachandran_allowed = self.ramalyze_obj.percent_allowed self.ramachandran_favored = self.ramalyze_obj.percent_favored self.rotalyze_obj = rotalyze(pdb_hierarchy=pdb_hierarchy, outliers_only=False) self.rotamer_outliers = self.rotalyze_obj.percent_outliers self.cbetadev_obj = cbetadev( pdb_hierarchy = pdb_hierarchy, outliers_only = True, out = null_out()) self.c_beta_dev = self.cbetadev_obj.get_outlier_count() self.clashscore = clashscore(pdb_hierarchy=pdb_hierarchy).get_clashscore() self.mpscore = molprobity_score( clashscore = self.clashscore, rota_out = self.rotamer_outliers, rama_fav = self.ramachandran_favored) self.omglz = omegalyze.omegalyze( pdb_hierarchy=self.pdb_hierarchy, quiet=True) self.n_cis_proline = self.omglz.n_cis_proline() self.n_cis_general = self.omglz.n_cis_general() self.n_twisted_proline = self.omglz.n_twisted_proline() self.n_twisted_general = self.omglz.n_twisted_general()
def run(self): hierarchy = self.data_manager.get_model().get_hierarchy() result = rotalyze( pdb_hierarchy=hierarchy, data_version="8000",#was 'params.data_version', no options currently show_errors=self.params.show_errors, outliers_only=self.params.outliers_only, out=self.logger, quiet=False) if self.params.verbose: result.show_old_output(out=self.logger, verbose=True) if self.params.wxplot : try : import wxtbx.app except ImportError as e : raise Sorry("wxPython not available.") else : app = wxtbx.app.CCTBXApp(0) result.display_wx_plots() app.MainLoop()
def generate_rotamer_data(pdb_hierarchy, exclude_outliers=True, data_version="8000", ): assert data_version == "8000","data_version not recognized." r = rotalyze.rotalyze(pdb_hierarchy=pdb_hierarchy, data_version=data_version) for rot in r.results: #if rot.outlier: # print (rot.resname, # rot.id_str(), # rot.chain_id, # rot.altloc, # rot.rotamer_name) # assert 0 if exclude_outliers and rot.outlier: continue yield (rot.resname, rot.id_str(), rot.chain_id, rot.altloc, rot.rotamer_name)
def get_scores(self, model): rama_fav = ramalyze(pdb_hierarchy=model.get_hierarchy(), outliers_only=False).percent_favored cbeta = cbetadev(pdb_hierarchy=model.get_hierarchy(), outliers_only=True, out=null_out()).get_outlier_percent() rota = rotalyze(pdb_hierarchy=model.get_hierarchy(), outliers_only=False).percent_outliers b_rmsd = get_bonds_rmsd( restraints_manager=self.geometry_rmsd_manager.geometry, xrs=model.get_xray_structure()) clash = clashscore(pdb_hierarchy=model.get_hierarchy(), keep_hydrogens=False, fast=True, condensed_probe=True).get_clashscore() print "DEV: b_rmsd= %7.4f clash= %6.4f rota= %6.4f rama_fav= %5.4f cbeta= %6.4f" % ( b_rmsd, clash, rota, rama_fav, cbeta) return group_args(rama_fav=rama_fav, cbeta=cbeta, rota=rota, b_rmsd=b_rmsd, clash=clash)
def exercise(): tst_build_simple.prepare_inputs("tst_altconfs_cmdline") assert os.path.isfile("tst_altconfs_cmdline_start.pdb") assert os.path.isfile("tst_altconfs_cmdline.mtz") args = [ "tst_altconfs_cmdline_start.pdb", "tst_altconfs_cmdline.mtz", "selection='chain A and resseq 3'", "output.file_name=tst_altconfs_cmdline_out.pdb", "expected_occupancy=0.4", "window_size=2", "nproc=1", "rsr_fofc_map_target=False", "create_dir=False", "prefix=tst_altconfs_cmdline_out", "--verbose", ] build_alternate_conformations.run(args=args, out=null_out()) pdb_out = file_reader.any_file("tst_altconfs_cmdline_out.pdb") hierarchy = pdb_out.file_object.construct_hierarchy() validate = rotalyze.rotalyze(pdb_hierarchy=hierarchy, data_version="8000", outliers_only=False) rota_out = [(r.id_str(), r.rotamer_name) for r in validate.results] # print rota_in assert ((" A 3 AASN", "t0") in rota_out) and ((" A 3 BASN", "m-40") in rota_out)
def exercise_rotalyze(): regression_pdb = libtbx.env.find_in_repositories( relative_path="phenix_regression/pdb/jcm.pdb", test=os.path.isfile) if (regression_pdb is None): print "Skipping exercise_rotalyze(): input pdb (jcm.pdb) not available" return if (find_rotarama_data_dir(optional=True) is None): print "Skipping exercise_rotalyze(): rotarama_data directory not available" return pdb_in = file_reader.any_file(file_name=regression_pdb) hierarchy = pdb_in.file_object.hierarchy pdb_io = pdb.input(file_name=regression_pdb) r = rotalyze.rotalyze(pdb_hierarchy=hierarchy, outliers_only=True) out = StringIO() r.show_old_output(out=out, verbose=False) output = out.getvalue() assert output.count("OUTLIER") == 246, output.count("OUTLIER") assert output.count(":") == 984, output.count(":") output_lines = output.splitlines() assert len(output_lines) == 123 for lines in output_lines: assert float(lines[12:15]) <= 1.0 r = rotalyze.rotalyze(pdb_hierarchy=hierarchy, outliers_only=False) for unpickle in [False, True]: if unpickle: r = loads(dumps(r)) out = StringIO() r.show_old_output(out=out, verbose=False) for outlier in r.results: assert (len(outlier.xyz) == 3) output = out.getvalue() assert output.count("OUTLIER") == 246 assert output.count(":") == 5144, output.count(":") assert output.count("p") == 120 assert output.count("m") == 324 assert output.count("t") == 486 output_lines = output.splitlines() #for line in output_lines: # print line #STOP() assert len(output_lines) == 643 line_indices = [0, 1, 2, 42, 43, 168, 169, 450, 587, 394, 641, 642] # top500 version line_values = [ " A 14 MET:1.00:3.3:29.2:173.3:287.9::Favored:ptm", " A 15 SER:1.00:0.1:229.0::::OUTLIER:OUTLIER", " A 16 SER:1.00:4.2:277.9::::Favored:m", " A 58 ASN:1.00:2.0:252.4:343.6:::Favored:m-20", " A 59 ILE:1.00:2.0:84.2:186.7:::Allowed:pt", " A 202 GLU:1.00:0.4:272.7:65.9:287.8::OUTLIER:OUTLIER", " A 203 ILE:1.00:5.0:292.9:199.6:::Favored:mt", " B 154 THR:1.00:0.1:356.0::::OUTLIER:OUTLIER", " B 316 TYR:1.00:5.4:153.7:68.6:::Favored:t80", " B 86 ASP:1.00:2.2:321.4:145.1:::Favored:m-20", " B 377 GLU:1.00:45.3:311.7:166.2:160.1::Favored:mt-10", " B 378 THR:1.00:23.5:309.4::::Favored:m" ] # top8000 version line_values = [ " A 14 MET:1.00:1.3:29.2:173.3:287.9::Allowed:ptm", " A 15 SER:1.00:0.1:229.0::::OUTLIER:OUTLIER", " A 16 SER:1.00:3.0:277.9::::Favored:m", " A 58 ASN:1.00:1.0:252.4:343.6:::Allowed:m-40", " A 59 ILE:1.00:0.5:84.2:186.7:::Allowed:pt", " A 202 GLU:1.00:0.0:272.7:65.9:287.8::OUTLIER:OUTLIER", " A 203 ILE:1.00:1.0:292.9:199.6:::Allowed:mt", " B 154 THR:1.00:0.0:356.0::::OUTLIER:OUTLIER", " B 316 TYR:1.00:4.1:153.7:68.6:::Favored:t80", " B 86 ASP:1.00:0.4:321.4:145.1:::Allowed:m-30", " B 377 GLU:1.00:15.0:311.7:166.2:160.1::Favored:mt-10", " B 378 THR:1.00:17.0:309.4::::Favored:m", ] for idx, val in zip(line_indices, line_values): assert (output_lines[idx] == val), (idx, output_lines[idx]) regression_pdb = libtbx.env.find_in_repositories( relative_path="phenix_regression/pdb/pdb1jxt.ent", test=os.path.isfile) if (regression_pdb is None): print "Skipping exercise_ramalyze(): input pdb (pdb1jxt.ent) not available" return pdb_in = file_reader.any_file(file_name=regression_pdb) hierarchy = pdb_in.file_object.hierarchy pdb_io = pdb.input(file_name=regression_pdb) r = rotalyze.rotalyze(pdb_hierarchy=hierarchy, outliers_only=True) out = StringIO() r.show_old_output(out=out, verbose=False) output = out.getvalue().strip() assert output == "" r = rotalyze.rotalyze(pdb_hierarchy=hierarchy, outliers_only=False) for unpickle in [False, True]: if unpickle: r = loads(dumps(r)) out = StringIO() r.show_old_output(out=out, verbose=False) output = out.getvalue() assert not show_diff( output, """\ A 1 THR:1.00:95.4:299.5::::Favored:m A 2 ATHR:0.67:49.5:56.1::::Favored:p A 2 BTHR:0.33:90.4:298.1::::Favored:m A 3 CYS:1.00:12.9:310.5::::Favored:m A 4 CYS:1.00:91.6:293.1::::Favored:m A 5 PRO:1.00:78.8:30.2:319.7:33.8::Favored:Cg_endo A 6 SER:1.00:90.1:68.4::::Favored:p A 7 AILE:0.45:49.6:290.8:178.2:::Favored:mt A 7 BILE:0.55:6.5:284.4:298.4:::Favored:mm A 8 AVAL:0.50:1.1:156.7::::Allowed:t A 8 BVAL:0.30:5.1:71.3::::Favored:p A 8 CVAL:0.20:69.8:172.1::::Favored:t A 10 AARG:0.65:24.7:176.8:66.5:63.9:180.0:Favored:tpp-160 A 10 BARG:0.35:17.5:176.8:72.8:66.4:171.9:Favored:tpp-160 A 11 SER:1.00:51.6:300.9::::Favored:m A 12 AASN:0.50:93.9:286.1:343.8:::Favored:m-40 A 12 BASN:0.50:98.9:288.4:337.6:::Favored:m-40 A 13 APHE:0.65:45.1:187.2:276.4:::Favored:t80 A 13 BPHE:0.35:86.1:179.6:263.1:::Favored:t80 A 14 ASN:1.00:95.2:289.6:333.0:::Favored:m-40 A 15 VAL:1.00:42.3:168.2::::Favored:t A 16 CYS:1.00:40.8:176.5::::Favored:t A 17 ARG:1.00:21.4:289.7:282.8:288.6:158.7:Favored:mmm160 A 18 LEU:1.00:65.0:287.2:173.3:::Favored:mt A 19 PRO:1.00:43.6:24.4:324.8:31.6::Favored:Cg_endo A 21 THR:1.00:5.7:314.0::::Favored:m A 22 APRO:0.55:87.5:333.5:34.0:333.8::Favored:Cg_exo A 23 AGLU:0.50:86.9:290.9:187.1:341.8::Favored:mt-10 A 23 BGLU:0.50:91.7:292.0:183.8:339.2::Favored:mt-10 A 25 ALEU:0.50:95.7:294.4:173.6:::Favored:mt A 26 CYS:1.00:83.0:295.0::::Favored:m A 28 THR:1.00:29.6:52.9::::Favored:p A 29 ATYR:0.65:18.5:161.8:67.8:::Favored:t80 A 29 BTYR:0.35:0.4:191.3:322.7:::Allowed:t80 A 30 ATHR:0.70:60.8:57.4::::Favored:p A 30 BTHR:0.30:6.6:78.1::::Favored:p A 32 CYS:1.00:61.4:301.7::::Favored:m A 33 ILE:1.00:36.6:66.5:173.4:::Favored:pt A 34 AILE:0.70:60.9:303.6:167.6:::Favored:mt A 34 BILE:0.30:31.4:308.5:296.8:::Favored:mm A 35 ILE:1.00:45.6:62.4:170.0:::Favored:pt A 36 PRO:1.00:36.2:22.5:330.5:24.8::Favored:Cg_endo A 39 ATHR:0.70:14.0:311.0::::Favored:m A 39 BTHR:0.30:13.1:288.8::::Favored:m A 40 CYS:1.00:81.4:294.4::::Favored:m A 41 PRO:1.00:35.4:34.4:317.5:33.1::Favored:Cg_endo A 43 AASP:0.75:24.8:56.5:340.3:::Favored:p0 A 43 BASP:0.25:43.2:59.6:349.3:::Favored:p0 A 44 TYR:1.00:85.3:290.9:85.1:::Favored:m-80 A 46 ASN:1.00:38.7:301.6:117.9:::Favored:m110 """)
def __init__( self, pdb_hierarchy, restraints_manager, molprobity_scores=False, n_histogram_slots=10, cdl_restraints=False, ignore_hydrogens=False, #only used by amber ): self.cdl_restraints=cdl_restraints sites_cart = pdb_hierarchy.atoms().extract_xyz() energies_sites = \ restraints_manager.energies_sites( sites_cart = sites_cart, compute_gradients = False) # molprobity scores self.clashscore = None self.ramachandran_outliers = None self.ramachandran_allowed = None self.ramachandran_favored = None self.rotamer_outliers = None self.c_beta_dev = None self.mpscore = None if(molprobity_scores): self.ramalyze_obj = ramalyze(pdb_hierarchy=pdb_hierarchy, outliers_only=False) self.ramachandran_outliers = self.ramalyze_obj.percent_outliers self.ramachandran_allowed = self.ramalyze_obj.percent_allowed self.ramachandran_favored = self.ramalyze_obj.percent_favored self.rotalyze_obj = rotalyze(pdb_hierarchy=pdb_hierarchy, outliers_only=False) self.rotamer_outliers = self.rotalyze_obj.percent_outliers self.cbetadev_obj = cbetadev( pdb_hierarchy = pdb_hierarchy, outliers_only = True, out = null_out()) self.c_beta_dev = self.cbetadev_obj.get_outlier_count() self.clashscore = clashscore(pdb_hierarchy=pdb_hierarchy).get_clashscore() self.mpscore = molprobity_score( clashscore = self.clashscore, rota_out = self.rotamer_outliers, rama_fav = self.ramachandran_favored) # if(hasattr(energies_sites, "geometry")): esg = energies_sites.geometry else: esg = energies_sites self.a = None self.b = None if not hasattr(esg, "angle_deviations"): return if hasattr(esg, "amber"): amber_parm = restraints_manager.amber_structs.parm self.a, angle_deltas = esg.angle_deviations(sites_cart, amber_parm, ignore_hd=ignore_hydrogens, get_deltas=True) self.b, bond_deltas = esg.bond_deviations(sites_cart, amber_parm, ignore_hd=ignore_hydrogens, get_deltas=True) self.a_number = esg.n_angle_proxies(amber_parm, ignore_hd=ignore_hydrogens) self.b_number = esg.n_bond_proxies(amber_parm, ignore_hd=ignore_hydrogens) self.c, self.p, self.ll, self.d, self.n = None, None, None, None, None self.c_number=0 self.p_number=0 self.d_number=0 self.bond_deltas_histogram = \ flex.histogram(data = flex.abs(bond_deltas), n_slots = n_histogram_slots) self.angle_deltas_histogram = \ flex.histogram(data = flex.abs(angle_deltas), n_slots = n_histogram_slots) # nonbonded_distances = esg.nonbonded_distances() # self.nonbonded_distances_histogram = flex.histogram( # data = flex.abs(nonbonded_distances), n_slots = n_histogram_slots) for restraint_type in ["b", "a", "c", "p", "ll", "d", "n"] : for value_type in [("mean",2), ("max",1), ("min",0)] : name = "%s_%s" % (restraint_type, value_type[0]) if getattr(self, restraint_type) is None: setattr(self, name, None) continue setattr(self, name, getattr(self, restraint_type)[value_type[1]]) return self.a = esg.angle_deviations() self.b = esg.bond_deviations() self.a_number = esg.get_filtered_n_angle_proxies() self.b_number = esg.get_filtered_n_bond_proxies() self.c = esg.chirality_deviations() self.d = esg.dihedral_deviations() self.p = esg.planarity_deviations() self.ll = esg.parallelity_deviations() self.n = esg.nonbonded_deviations() self.c_number = esg.n_chirality_proxies self.d_number = esg.n_dihedral_proxies self.p_number = esg.n_planarity_proxies self.n_number = esg.n_nonbonded_proxies # for restraint_type in ["b", "a", "c", "p", "ll", "d", "n"] : for value_type in [("mean",2), ("max",1), ("min",0)] : name = "%s_%s" % (restraint_type, value_type[0]) if getattr(self, restraint_type) is None: continue setattr(self, name, getattr(self, restraint_type)[value_type[1]]) # if(hasattr(restraints_manager, "geometry")): rmg = restraints_manager.geometry else: rmg = restraints_manager bond_deltas = geometry_restraints.bond_deltas( sites_cart = sites_cart, sorted_asu_proxies = rmg.pair_proxies().bond_proxies) angle_deltas = geometry_restraints.angle_deltas( sites_cart = sites_cart, proxies = rmg.angle_proxies) nonbonded_distances = esg.nonbonded_distances() self.bond_deltas_histogram = \ flex.histogram(data = flex.abs(bond_deltas), n_slots = n_histogram_slots) self.angle_deltas_histogram = \ flex.histogram(data = flex.abs(angle_deltas), n_slots = n_histogram_slots) self.nonbonded_distances_histogram = flex.histogram( data = flex.abs(nonbonded_distances), n_slots = n_histogram_slots) # assert approx_equal( esg.target, esg.angle_residual_sum+ esg.bond_residual_sum+ esg.chirality_residual_sum+ esg.dihedral_residual_sum+ esg.nonbonded_residual_sum+ esg.planarity_residual_sum+ esg.parallelity_residual_sum+ esg.reference_coordinate_residual_sum+ esg.reference_dihedral_residual_sum+ esg.ncs_dihedral_residual_sum+ esg.den_residual_sum+ esg.ramachandran_residual_sum) del energies_sites, esg # we accumulate this object, so make it clean asap
ATOM 475 CE LYS A 49 1.571 5.402 13.292 1.00 18.19 C ATOM 476 NZ LYS A 49 0.899 4.110 12.980 1.00 19.97 N """ pdb_io = pdb.input(source_info=None, lines=pdb_str) hierarchy = pdb_io.construct_hierarchy() try: rotalyze.rotalyze(pdb_hierarchy=hierarchy) except Sorry, e: assert ("GLY A 262" in str(e)) else: raise Exception_expected pdb_io = pdb.input(source_info=None, lines=pdb_str2) hierarchy = pdb_io.construct_hierarchy() r = rotalyze.rotalyze(pdb_hierarchy=hierarchy) out = StringIO() r.show_old_output(out=out, verbose=False) output = out.getvalue() assert output == """\ A 47 PRO:1.00:86.4:329.3:41.3:324.9::Favored:Cg_exo A 48 MSE:0.70:0.3:287.6:214.8:138.3::OUTLIER:OUTLIER A 49 LYS:1.00:0.1:288.6:263.2:251.7:233.0:OUTLIER:OUTLIER """, output r = rotalyze.rotalyze(pdb_hierarchy=hierarchy, data_version="8000") out = StringIO() r.show_old_output(out=out, verbose=False) assert (out.getvalue() == """\ A 47 PRO:1.00:86.4:329.3:41.3:324.9::Favored:Cg_exo A 48 MSE:0.70:0.3:287.6:214.8:138.3::OUTLIER:OUTLIER
def exercise_2 () : pdb_str = """\ ATOM 2527 N LEU A 261 -31.022 -24.808 107.479 1.00 28.22 N ATOM 2528 CA LEU A 261 -30.054 -23.719 107.237 1.00 21.77 C ATOM 2529 C LEU A 261 -30.582 -22.773 106.168 1.00 27.64 C ATOM 2530 O LEU A 261 -29.841 -21.977 105.561 1.00 26.70 O ATOM 2531 CB LEU A 261 -28.696 -24.276 106.874 1.00 22.58 C ATOM 2532 CG LEU A 261 -28.135 -25.066 108.060 1.00 40.89 C ATOM 2533 CD1 LEU A 261 -26.892 -25.858 107.664 1.00 46.72 C ATOM 2534 CD2 LEU A 261 -27.806 -24.109 109.202 1.00 38.88 C ATOM 2535 H LEU A 261 -31.201 -25.277 106.781 1.00 33.87 H ATOM 2536 HA LEU A 261 -29.950 -23.204 108.064 1.00 26.12 H ATOM 2537 HB2 LEU A 261 -28.781 -24.874 106.115 1.00 27.10 H ATOM 2538 HB3 LEU A 261 -28.088 -23.548 106.670 1.00 27.10 H ATOM 2539 HG LEU A 261 -28.806 -25.693 108.373 1.00 49.07 H ATOM 2540 HD11 LEU A 261 -26.570 -26.338 108.430 1.00 56.07 H ATOM 2541 HD12 LEU A 261 -27.124 -26.473 106.965 1.00 56.07 H ATOM 2542 HD13 LEU A 261 -26.219 -25.247 107.353 1.00 56.07 H ATOM 2543 HD21 LEU A 261 -28.608 -23.653 109.468 1.00 46.66 H ATOM 2544 HD22 LEU A 261 -27.455 -24.612 109.941 1.00 46.66 H ATOM 2545 HD23 LEU A 261 -27.153 -23.474 108.899 1.00 46.66 H ATOM 2546 N GLY A 262 -31.887 -22.863 105.948 1.00 23.68 N ATOM 2547 CA GLY A 262 -32.572 -21.935 105.075 1.00 21.87 85 C ATOM 2548 C GLY A 262 -33.718 -22.620 104.386 1.00 27.32 C ATOM 2549 O GLY A 262 -33.943 -23.822 104.556 1.00 23.10 O ATOM 2550 H GLY A 262 -32.399 -23.459 106.298 1.00 28.42 H ATOM 2551 HA2 GLY A 262 -32.916 -21.189 105.591 1.00 26.25 85 H ATOM 2552 HA3 GLY A 262 -31.958 -21.598 104.405 1.00 26.25 85 H ATOM 2553 N SER A 263 -34.460 -21.830 103.628 1.00 24.62 N ATOM 2554 CA SER A 263 -35.631 -22.290 102.921 1.00 27.15 C ATOM 2555 C SER A 263 -35.594 -21.761 101.492 1.00 22.14 C ATOM 2556 O SER A 263 -34.723 -20.945 101.159 1.00 21.01 O ATOM 2557 CB SER A 263 -36.839 -21.713 103.619 1.00 25.73 C ATOM 2558 OG SER A 263 -36.907 -22.232 104.922 1.00 26.84 O ATOM 2559 H SER A 263 -34.296 -20.995 103.507 1.00 29.54 H ATOM 2560 HA SER A 263 -35.680 -23.269 102.917 1.00 32.58 H ATOM 2561 HB2 SER A 263 -36.754 -20.747 103.661 1.00 30.87 H ATOM 2562 HB3 SER A 263 -37.641 -21.960 103.132 1.00 30.87 H ATOM 2563 HG SER A 263 -37.560 -21.925 105.312 1.00 32.20 H """ pdb_str2 = """ ATOM 453 N PRO A 47 8.633 6.370 5.022 1.00 13.79 N ATOM 454 CA PRO A 47 7.915 7.571 5.496 1.00 14.61 C ATOM 455 C PRO A 47 7.612 7.481 6.994 1.00 15.06 C ATOM 456 O PRO A 47 7.289 6.377 7.439 1.00 14.39 O ATOM 457 CB PRO A 47 6.639 7.559 4.651 1.00 16.24 C ATOM 458 CG PRO A 47 7.089 6.901 3.338 1.00 15.52 C ATOM 459 CD PRO A 47 7.990 5.773 3.833 1.00 14.40 C ATOM 460 N MSE A 48 7.754 8.528 7.779 1.00 15.13 N ATOM 461 CA MSE A 48 7.482 8.456 9.201 1.00 16.17 C ATOM 462 C MSE A 48 6.040 8.750 9.517 1.00 15.23 C ATOM 463 O MSE A 48 5.417 9.418 8.735 1.00 14.77 O ATOM 464 CB MSE A 48 8.165 9.538 10.023 1.00 19.62 C ATOM 465 CG MSE A 48 9.630 9.466 10.238 1.00 21.70 C ATOM 466 SE MSE A 48 10.022 10.161 12.050 0.70 37.95 SE ATOM 467 CE MSE A 48 11.268 8.720 12.235 1.00 28.72 C ATOM 468 N LYS A 49 5.519 8.291 10.645 1.00 13.93 N ATOM 469 CA LYS A 49 4.167 8.624 11.045 1.00 13.79 C ATOM 470 C LYS A 49 4.022 10.138 11.202 1.00 14.66 C ATOM 471 O LYS A 49 5.011 10.853 11.351 1.00 15.69 O ATOM 472 CB LYS A 49 3.797 7.915 12.349 1.00 13.33 C ATOM 473 CG LYS A 49 3.593 6.416 12.204 1.00 14.35 C ATOM 474 CD LYS A 49 2.121 6.071 12.044 1.00 16.45 C ATOM 475 CE LYS A 49 1.571 5.402 13.292 1.00 18.19 C ATOM 476 NZ LYS A 49 0.899 4.110 12.980 1.00 19.97 N """ pdb_io = pdb.input(source_info=None, lines=pdb_str) hierarchy = pdb_io.construct_hierarchy() try : rotalyze.rotalyze(pdb_hierarchy=hierarchy) except Sorry, e : assert ("GLY A 262" in str(e))
def set_rotamer_to_reference(self, xray_structure, mon_lib_srv=None, log=None, quiet=False): if self.mon_lib_srv is None: self.mon_lib_srv = mon_lib_srv assert isinstance(self.mon_lib_srv, mmtbx.monomer_library.server.server) if (log is None): log = sys.stdout make_sub_header("Correcting rotamer outliers to match reference model", out=log) sa = SidechainAngles(False) r = rotalyze.rotalyze(pdb_hierarchy=self.pdb_hierarchy) rot_list_reference = {} coot_reference = {} for key in self.pdb_hierarchy_ref.keys(): hierarchy = self.pdb_hierarchy_ref[key] rot_list_reference[key] = \ rotalyze.rotalyze(pdb_hierarchy=hierarchy) model_hash = {} model_chis = {} reference_hash = {} reference_chis = {} model_outliers = 0 for rot in r.results: model_hash[rot.id_str()] = rot.rotamer_name if rot.rotamer_name == "OUTLIER": model_outliers += 1 for key in rot_list_reference.keys(): reference_hash[key] = {} for rot in rot_list_reference[key].results: reference_hash[key][rot.id_str()] = rot.rotamer_name print >> log, "** evaluating rotamers for working model **" for model in self.pdb_hierarchy.models(): for chain in model.chains(): for residue_group in chain.residue_groups(): all_dict = rotalyze.construct_complete_sidechain( residue_group) for atom_group in residue_group.atom_groups(): try: atom_dict = all_dict.get(atom_group.altloc) chis = sa.measureChiAngles(atom_group, atom_dict) if chis is not None: key = utils.id_str(chain_id=chain.id, resseq=residue_group.resseq, resname=atom_group.resname, icode=residue_group.icode, altloc=atom_group.altloc) model_chis[key] = chis except Exception: print >> log, \ ' %s%5s %s is missing some sidechain atoms, **skipping**' % ( chain.id, residue_group.resid(), atom_group.altloc+atom_group.resname) if model_outliers == 0: print >> log, "No rotamer outliers detected in working model" return else: print >> log, "Number of rotamer outliers: %d" % model_outliers print >> log, "\n** evaluating rotamers for reference model **" for file in self.pdb_hierarchy_ref.keys(): hierarchy = self.pdb_hierarchy_ref[file] reference_chis[file] = {} for model in hierarchy.models(): for chain in model.chains(): for residue_group in chain.residue_groups(): all_dict = rotalyze.construct_complete_sidechain( residue_group) for atom_group in residue_group.atom_groups(): try: atom_dict = all_dict.get(atom_group.altloc) chis = sa.measureChiAngles( atom_group, atom_dict) if chis is not None: key = utils.id_str( chain_id=chain.id, resseq=residue_group.resseq, resname=atom_group.resname, icode=residue_group.icode, altloc=atom_group.altloc) reference_chis[file][key] = chis except Exception: print >> log, \ ' %s%5s %s is missing some sidechain atoms, **skipping**' % ( chain.id, residue_group.resid(), atom_group.altloc+atom_group.resname) print >> log, "\n** fixing outliers **" sites_cart_start = xray_structure.sites_cart() for model in self.pdb_hierarchy.models(): for chain in model.chains(): for residue_group in chain.residue_groups(): if len(residue_group.conformers()) > 1: print >> log, " %s%5s %s has multiple conformations, **skipping**" % ( chain.id, residue_group.resid(), " " + residue_group.atom_groups()[0].resname) continue for conformer in residue_group.conformers(): for residue in conformer.residues(): if residue.resname == "PRO": continue key = utils.id_str( chain_id=chain.id, resseq=residue_group.resseq, resname=residue_group.atom_groups()[0].resname, icode=residue_group.icode, altloc=conformer.altloc) if len(chain.id) == 1: chain_id = " " + chain.id else: chain_id = chain.id file_key = '%s%s%s' % (residue.resname, chain_id, residue_group.resid()) file_key = file_key.strip() file_match = self.residue_match_hash.get(file_key) if file_match is not None: file = file_match[0] else: continue model_rot = model_hash.get(key) reference_rot = reference_hash[file].get( self.one_key_to_another(file_match[1])) m_chis = model_chis.get(key) r_chis = reference_chis[file].get( self.one_key_to_another(file_match[1])) if model_rot is not None and reference_rot is not None and \ m_chis is not None and r_chis is not None: if (model_rot == 'OUTLIER' and \ reference_rot != 'OUTLIER'): # or \ #atom_group.resname in ["LEU", "VAL", "THR"]: self.change_residue_rotamer_in_place( sites_cart_start, residue, m_chis, r_chis, self.mon_lib_srv) xray_structure.set_sites_cart( sites_cart_start) elif self.params.strict_rotamer_matching and \ (model_rot != 'OUTLIER' and reference_rot != 'OUTLIER'): if model_rot != reference_rot: self.change_residue_rotamer_in_place( sites_cart_start, residue, m_chis, r_chis, self.mon_lib_srv) xray_structure.set_sites_cart( sites_cart_start)
def get_model_stat(file_name): pdb_inp = iotbx.pdb.input(file_name=file_name) atoms = pdb_inp.atoms() box = uctbx.non_crystallographic_unit_cell_with_the_sites_in_its_center( sites_cart=atoms.extract_xyz(), buffer_layer=5) atoms.set_xyz(new_xyz=box.sites_cart) ph = pdb_inp.construct_hierarchy() if (all_single_atom_residues(ph=ph)): return None raw_recs = ph.as_pdb_string( crystal_symmetry=box.crystal_symmetry()).splitlines() # params = monomer_library.pdb_interpretation.master_params.extract() params.clash_guard.nonbonded_distance_threshold = None params.disable_uc_volume_vs_n_atoms_check = False params.use_neutron_distances = True params.restraints_library.cdl = False processed_pdb_file = monomer_library.pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, raw_records=raw_recs, params=params, log=null_out()) xrs = processed_pdb_file.xray_structure() sctr_keys = xrs.scattering_type_registry().type_count_dict().keys() has_hd = "H" in sctr_keys or "D" in sctr_keys restraints_manager = processed_pdb_file.geometry_restraints_manager( show_energies=False, assume_hydrogens_all_missing=not has_hd, plain_pairs_radius=5.0) a_mean, b_mean = get_bonds_angles_rmsd( restraints_manager=restraints_manager, xrs=xrs) energies_sites = \ restraints_manager.energies_sites( sites_cart = xrs.sites_cart(), compute_gradients = False) nonbonded_distances = energies_sites.nonbonded_distances() number_of_worst_clashes = (nonbonded_distances < 0.5).count(True) # ramalyze_obj = ramalyze(pdb_hierarchy=ph, outliers_only=False) ramachandran_outliers = ramalyze_obj.percent_outliers rotamer_outliers = rotalyze(pdb_hierarchy=ph, outliers_only=False).percent_outliers c_beta_dev = cbetadev(pdb_hierarchy=ph, outliers_only=True, out=null_out()).get_outlier_count() omglz = omegalyze.omegalyze(pdb_hierarchy=ph, quiet=True) n_cis_proline = omglz.n_cis_proline() n_cis_general = omglz.n_cis_general() n_twisted_proline = omglz.n_twisted_proline() n_twisted_general = omglz.n_twisted_general() # clsc = clashscore(pdb_hierarchy=ph).get_clashscore() mpscore = molprobity_score(clashscore=clsc, rota_out=rotamer_outliers, rama_fav=ramalyze_obj.percent_favored) # occ = atoms.extract_occ() bs = atoms.extract_b() # return group_args(b_mean=b_mean, a_mean=a_mean, number_of_worst_clashes=number_of_worst_clashes, ramachandran_outliers=ramachandran_outliers, rotamer_outliers=rotamer_outliers, c_beta_dev=c_beta_dev, n_cis_proline=n_cis_proline, n_cis_general=n_cis_general, n_twisted_proline=n_twisted_proline, n_twisted_general=n_twisted_general, o=occ.min_max_mean().as_tuple(), b=bs.min_max_mean().as_tuple(), mpscore=mpscore, clsc=clsc, n_atoms=atoms.size())
def __init__(self, pdb_hierarchy, xray_structure=None, fmodel=None, fmodel_neutron=None, geometry_restraints_manager=None, crystal_symmetry=None, sequences=None, flags=None, header_info=None, raw_data=None, unmerged_data=None, all_chain_proxies=None, keep_hydrogens=True, nuclear=False, save_probe_unformatted_file=None, show_hydrogen_outliers=False, min_cc_two_fofc=0.8, n_bins_data=10, count_anomalous_pairs_separately=False, use_internal_variance=True, outliers_only=True, use_pdb_header_resolution_cutoffs=False, file_name=None, ligand_selection=None, rotamer_library="8000", map_params=None): assert rotamer_library == "8000", "data_version given to RotamerEval not recognized." for name in self.__slots__: setattr(self, name, None) # very important - the i_seq attributes may be extracted later pdb_hierarchy.atoms().reset_i_seq() self.pdb_hierarchy = pdb_hierarchy if (xray_structure is None): if (fmodel is not None): xray_structure = fmodel.xray_structure elif (crystal_symmetry is not None): xray_structure = pdb_hierarchy.extract_xray_structure( crystal_symmetry=crystal_symmetry) self.crystal_symmetry = crystal_symmetry if (crystal_symmetry is None) and (fmodel is not None): self.crystal_symmetry = fmodel.f_obs().crystal_symmetry() self.header_info = header_info if (flags is None): flags = molprobity_flags() if pdb_hierarchy.contains_protein(): self.find_missing_atoms(out=null_out()) if (flags.ramalyze): self.ramalyze = ramalyze.ramalyze(pdb_hierarchy=pdb_hierarchy, outliers_only=outliers_only, out=null_out(), quiet=True) ##### omegalyze ################################################################ if (flags.omegalyze): self.omegalyze = omegalyze.omegalyze( pdb_hierarchy=pdb_hierarchy, nontrans_only=outliers_only, out=null_out(), quiet=True) ##### omegalyze ################################################################ if (flags.rotalyze): self.rotalyze = rotalyze.rotalyze(pdb_hierarchy=pdb_hierarchy, data_version=rotamer_library, outliers_only=outliers_only, out=null_out(), quiet=True) if (flags.cbetadev): self.cbetadev = cbetadev.cbetadev(pdb_hierarchy=pdb_hierarchy, outliers_only=outliers_only, out=null_out(), quiet=True) if (flags.nqh): self.nqh_flips = clashscore.nqh_flips( pdb_hierarchy=pdb_hierarchy) if (pdb_hierarchy.contains_rna() and flags.rna and libtbx.env.has_module(name="suitename")): if (geometry_restraints_manager is not None): self.rna = rna_validate.rna_validation( pdb_hierarchy=pdb_hierarchy, geometry_restraints_manager=geometry_restraints_manager, outliers_only=outliers_only, params=None) if (flags.clashscore): self.clashes = clashscore.clashscore( pdb_hierarchy=pdb_hierarchy, save_probe_unformatted_file=save_probe_unformatted_file, nuclear=nuclear, keep_hydrogens=keep_hydrogens, out=null_out(), verbose=False) if (flags.model_stats) and (xray_structure is not None): self.model_stats = model_properties.model_statistics( pdb_hierarchy=pdb_hierarchy, xray_structure=xray_structure, all_chain_proxies=all_chain_proxies, ignore_hd=(not nuclear), ligand_selection=ligand_selection) if (geometry_restraints_manager is not None) and (flags.restraints): assert (xray_structure is not None) self.restraints = restraints.combined( pdb_hierarchy=pdb_hierarchy, xray_structure=xray_structure, geometry_restraints_manager=geometry_restraints_manager, ignore_hd=(not nuclear), cdl=getattr(all_chain_proxies, "use_cdl", None)) if (sequences is not None) and (flags.seq): self.sequence = sequence.validation( pdb_hierarchy=pdb_hierarchy, sequences=sequences, log=null_out(), include_secondary_structure=True, extract_coordinates=True) # use maps (fmodel is not used) use_maps = False if (map_params is not None): use_maps = ((map_params.input.maps.map_file_name) or ((map_params.input.maps.map_coefficients_file_name) and (map_params.input.maps.map_coefficients_label))) if (use_maps): if (flags.real_space): self.real_space = experimental.real_space( fmodel=None, pdb_hierarchy=pdb_hierarchy, cc_min=min_cc_two_fofc, molprobity_map_params=map_params.input.maps) if (flags.waters): self.waters = waters.waters( pdb_hierarchy=pdb_hierarchy, xray_structure=xray_structure, fmodel=None, collect_all=True, molprobity_map_params=map_params.input.maps) if (fmodel is not None): if (use_pdb_header_resolution_cutoffs) and (header_info is not None): fmodel = fmodel.resolution_filter(d_min=header_info.d_min, d_max=header_info.d_max) if (flags.rfactors): self.data_stats = experimental.data_statistics( fmodel, raw_data=raw_data, n_bins=n_bins_data, count_anomalous_pairs_separately= count_anomalous_pairs_separately) if (not use_maps): # if maps are used, keep previous results if (flags.real_space): self.real_space = experimental.real_space( fmodel=fmodel, pdb_hierarchy=pdb_hierarchy, cc_min=min_cc_two_fofc) if (flags.waters): self.waters = waters.waters(pdb_hierarchy=pdb_hierarchy, xray_structure=xray_structure, fmodel=fmodel, collect_all=True) if (unmerged_data is not None): self.merging = experimental.merging_and_model_statistics( f_obs=fmodel.f_obs(), f_model=fmodel.f_model(), r_free_flags=fmodel.r_free_flags(), unmerged_i_obs=unmerged_data, anomalous=count_anomalous_pairs_separately, use_internal_variance=use_internal_variance, n_bins=n_bins_data) if (flags.xtriage): import mmtbx.scaling.xtriage f_model = abs( fmodel.f_model()).set_observation_type_xray_amplitude() if (raw_data is not None): f_model, obs = f_model.common_sets(other=raw_data) else: obs = fmodel.f_obs() self.xtriage = mmtbx.scaling.xtriage.xtriage_analyses( miller_obs=obs, miller_calc=f_model, unmerged_obs=unmerged_data, # XXX some redundancy here... text_out=null_out()) if (fmodel_neutron is not None) and (flags.rfactors): self.neutron_stats = experimental.data_statistics( fmodel_neutron, n_bins=n_bins_data, count_anomalous_pairs_separately=False) if (pdb_hierarchy.models_size() == 1): self._multi_criterion = multi_criterion_view(pdb_hierarchy)
def exercise_2(): pdb_str = """\ ATOM 2527 N LEU A 261 -31.022 -24.808 107.479 1.00 28.22 N ATOM 2528 CA LEU A 261 -30.054 -23.719 107.237 1.00 21.77 C ATOM 2529 C LEU A 261 -30.582 -22.773 106.168 1.00 27.64 C ATOM 2530 O LEU A 261 -29.841 -21.977 105.561 1.00 26.70 O ATOM 2531 CB LEU A 261 -28.696 -24.276 106.874 1.00 22.58 C ATOM 2532 CG LEU A 261 -28.135 -25.066 108.060 1.00 40.89 C ATOM 2533 CD1 LEU A 261 -26.892 -25.858 107.664 1.00 46.72 C ATOM 2534 CD2 LEU A 261 -27.806 -24.109 109.202 1.00 38.88 C ATOM 2535 H LEU A 261 -31.201 -25.277 106.781 1.00 33.87 H ATOM 2536 HA LEU A 261 -29.950 -23.204 108.064 1.00 26.12 H ATOM 2537 HB2 LEU A 261 -28.781 -24.874 106.115 1.00 27.10 H ATOM 2538 HB3 LEU A 261 -28.088 -23.548 106.670 1.00 27.10 H ATOM 2539 HG LEU A 261 -28.806 -25.693 108.373 1.00 49.07 H ATOM 2540 HD11 LEU A 261 -26.570 -26.338 108.430 1.00 56.07 H ATOM 2541 HD12 LEU A 261 -27.124 -26.473 106.965 1.00 56.07 H ATOM 2542 HD13 LEU A 261 -26.219 -25.247 107.353 1.00 56.07 H ATOM 2543 HD21 LEU A 261 -28.608 -23.653 109.468 1.00 46.66 H ATOM 2544 HD22 LEU A 261 -27.455 -24.612 109.941 1.00 46.66 H ATOM 2545 HD23 LEU A 261 -27.153 -23.474 108.899 1.00 46.66 H ATOM 2546 N GLY A 262 -31.887 -22.863 105.948 1.00 23.68 N ATOM 2547 CA GLY A 262 -32.572 -21.935 105.075 1.00 21.87 85 C ATOM 2548 C GLY A 262 -33.718 -22.620 104.386 1.00 27.32 C ATOM 2549 O GLY A 262 -33.943 -23.822 104.556 1.00 23.10 O ATOM 2550 H GLY A 262 -32.399 -23.459 106.298 1.00 28.42 H ATOM 2551 HA2 GLY A 262 -32.916 -21.189 105.591 1.00 26.25 85 H ATOM 2552 HA3 GLY A 262 -31.958 -21.598 104.405 1.00 26.25 85 H ATOM 2553 N SER A 263 -34.460 -21.830 103.628 1.00 24.62 N ATOM 2554 CA SER A 263 -35.631 -22.290 102.921 1.00 27.15 C ATOM 2555 C SER A 263 -35.594 -21.761 101.492 1.00 22.14 C ATOM 2556 O SER A 263 -34.723 -20.945 101.159 1.00 21.01 O ATOM 2557 CB SER A 263 -36.839 -21.713 103.619 1.00 25.73 C ATOM 2558 OG SER A 263 -36.907 -22.232 104.922 1.00 26.84 O ATOM 2559 H SER A 263 -34.296 -20.995 103.507 1.00 29.54 H ATOM 2560 HA SER A 263 -35.680 -23.269 102.917 1.00 32.58 H ATOM 2561 HB2 SER A 263 -36.754 -20.747 103.661 1.00 30.87 H ATOM 2562 HB3 SER A 263 -37.641 -21.960 103.132 1.00 30.87 H ATOM 2563 HG SER A 263 -37.560 -21.925 105.312 1.00 32.20 H """ pdb_str2 = """ ATOM 453 N PRO A 47 8.633 6.370 5.022 1.00 13.79 N ATOM 454 CA PRO A 47 7.915 7.571 5.496 1.00 14.61 C ATOM 455 C PRO A 47 7.612 7.481 6.994 1.00 15.06 C ATOM 456 O PRO A 47 7.289 6.377 7.439 1.00 14.39 O ATOM 457 CB PRO A 47 6.639 7.559 4.651 1.00 16.24 C ATOM 458 CG PRO A 47 7.089 6.901 3.338 1.00 15.52 C ATOM 459 CD PRO A 47 7.990 5.773 3.833 1.00 14.40 C ATOM 460 N MSE A 48 7.754 8.528 7.779 1.00 15.13 N ATOM 461 CA MSE A 48 7.482 8.456 9.201 1.00 16.17 C ATOM 462 C MSE A 48 6.040 8.750 9.517 1.00 15.23 C ATOM 463 O MSE A 48 5.417 9.418 8.735 1.00 14.77 O ATOM 464 CB MSE A 48 8.165 9.538 10.023 1.00 19.62 C ATOM 465 CG MSE A 48 9.630 9.466 10.238 1.00 21.70 C ATOM 466 SE MSE A 48 10.022 10.161 12.050 0.70 37.95 SE ATOM 467 CE MSE A 48 11.268 8.720 12.235 1.00 28.72 C ATOM 468 N LYS A 49 5.519 8.291 10.645 1.00 13.93 N ATOM 469 CA LYS A 49 4.167 8.624 11.045 1.00 13.79 C ATOM 470 C LYS A 49 4.022 10.138 11.202 1.00 14.66 C ATOM 471 O LYS A 49 5.011 10.853 11.351 1.00 15.69 O ATOM 472 CB LYS A 49 3.797 7.915 12.349 1.00 13.33 C ATOM 473 CG LYS A 49 3.593 6.416 12.204 1.00 14.35 C ATOM 474 CD LYS A 49 2.121 6.071 12.044 1.00 16.45 C ATOM 475 CE LYS A 49 1.571 5.402 13.292 1.00 18.19 C ATOM 476 NZ LYS A 49 0.899 4.110 12.980 1.00 19.97 N """ pdb_io = pdb.input(source_info=None, lines=pdb_str) hierarchy = pdb_io.construct_hierarchy() try: rotalyze.rotalyze(pdb_hierarchy=hierarchy) except Sorry, e: assert ("GLY A 262" in str(e))
def exercise_rotalyze(): regression_pdb = libtbx.env.find_in_repositories( relative_path="phenix_regression/pdb/jcm.pdb", test=os.path.isfile) if (regression_pdb is None): print "Skipping exercise_rotalyze(): input pdb (jcm.pdb) not available" return if (find_rotarama_data_dir(optional=True) is None): print "Skipping exercise_rotalyze(): rotarama_data directory not available" return pdb_in = file_reader.any_file(file_name=regression_pdb) hierarchy = pdb_in.file_object.hierarchy pdb_io = pdb.input(file_name=regression_pdb) r = rotalyze.rotalyze( pdb_hierarchy=hierarchy, outliers_only=True) out = StringIO() r.show_old_output(out=out, verbose=False) output = out.getvalue() assert output.count("OUTLIER") == 246, output.count("OUTLIER") assert output.count(":") == 984, output.count(":") output_lines = output.splitlines() assert len(output_lines) == 123 for lines in output_lines: assert float(lines[12:15]) <= 1.0 r = rotalyze.rotalyze( pdb_hierarchy=hierarchy, outliers_only=False) for unpickle in [False, True] : if unpickle : r = loads(dumps(r)) out = StringIO() r.show_old_output(out=out, verbose=False) for outlier in r.results : assert (len(outlier.xyz) == 3) output = out.getvalue() assert output.count("OUTLIER") == 246 assert output.count(":") == 5144, output.count(":") assert output.count("p") == 120 assert output.count("m") == 324 assert output.count("t") == 486 output_lines = output.splitlines() #for line in output_lines: # print line #STOP() assert len(output_lines) == 643 line_indices = [0,1,2,42,43,168,169,450,587,394,641,642] # top500 version line_values = [ " A 14 MET:1.00:3.3:29.2:173.3:287.9::Favored:ptm", " A 15 SER:1.00:0.1:229.0::::OUTLIER:OUTLIER", " A 16 SER:1.00:4.2:277.9::::Favored:m", " A 58 ASN:1.00:2.0:252.4:343.6:::Favored:m-20", " A 59 ILE:1.00:2.0:84.2:186.7:::Allowed:pt", " A 202 GLU:1.00:0.4:272.7:65.9:287.8::OUTLIER:OUTLIER", " A 203 ILE:1.00:5.0:292.9:199.6:::Favored:mt", " B 154 THR:1.00:0.1:356.0::::OUTLIER:OUTLIER", " B 316 TYR:1.00:5.4:153.7:68.6:::Favored:t80", " B 86 ASP:1.00:2.2:321.4:145.1:::Favored:m-20", " B 377 GLU:1.00:45.3:311.7:166.2:160.1::Favored:mt-10", " B 378 THR:1.00:23.5:309.4::::Favored:m"] # top8000 version line_values = [ " A 14 MET:1.00:1.3:29.2:173.3:287.9::Allowed:ptm", " A 15 SER:1.00:0.1:229.0::::OUTLIER:OUTLIER", " A 16 SER:1.00:3.0:277.9::::Favored:m", " A 58 ASN:1.00:1.0:252.4:343.6:::Allowed:m-40", " A 59 ILE:1.00:0.5:84.2:186.7:::Allowed:pt", " A 202 GLU:1.00:0.0:272.7:65.9:287.8::OUTLIER:OUTLIER", " A 203 ILE:1.00:1.0:292.9:199.6:::Allowed:mt", " B 154 THR:1.00:0.0:356.0::::OUTLIER:OUTLIER", " B 316 TYR:1.00:4.1:153.7:68.6:::Favored:t80", " B 86 ASP:1.00:0.4:321.4:145.1:::Allowed:m-30", " B 377 GLU:1.00:15.0:311.7:166.2:160.1::Favored:mt-10", " B 378 THR:1.00:17.0:309.4::::Favored:m", ] for idx, val in zip(line_indices, line_values) : assert (output_lines[idx] == val), (idx, output_lines[idx]) regression_pdb = libtbx.env.find_in_repositories( relative_path="phenix_regression/pdb/pdb1jxt.ent", test=os.path.isfile) if (regression_pdb is None): print "Skipping exercise_ramalyze(): input pdb (pdb1jxt.ent) not available" return pdb_in = file_reader.any_file(file_name=regression_pdb) hierarchy = pdb_in.file_object.hierarchy pdb_io = pdb.input(file_name=regression_pdb) r = rotalyze.rotalyze( pdb_hierarchy=hierarchy, outliers_only=True) out = StringIO() r.show_old_output(out=out, verbose=False) output = out.getvalue().strip() assert output == "" r = rotalyze.rotalyze( pdb_hierarchy=hierarchy, outliers_only=False) for unpickle in [False, True] : if unpickle : r = loads(dumps(r)) out = StringIO() r.show_old_output(out=out, verbose=False) output = out.getvalue() assert not show_diff(output,"""\ A 1 THR:1.00:95.4:299.5::::Favored:m A 2 ATHR:0.67:49.5:56.1::::Favored:p A 2 BTHR:0.33:90.4:298.1::::Favored:m A 3 CYS:1.00:12.9:310.5::::Favored:m A 4 CYS:1.00:91.6:293.1::::Favored:m A 5 PRO:1.00:78.8:30.2:319.7:33.8::Favored:Cg_endo A 6 SER:1.00:90.1:68.4::::Favored:p A 7 AILE:0.45:49.6:290.8:178.2:::Favored:mt A 7 BILE:0.55:6.5:284.4:298.4:::Favored:mm A 8 AVAL:0.50:1.1:156.7::::Allowed:t A 8 BVAL:0.30:5.1:71.3::::Favored:p A 8 CVAL:0.20:69.8:172.1::::Favored:t A 10 AARG:0.65:24.7:176.8:66.5:63.9:180.0:Favored:tpp-160 A 10 BARG:0.35:17.5:176.8:72.8:66.4:171.9:Favored:tpp-160 A 11 SER:1.00:51.6:300.9::::Favored:m A 12 AASN:0.50:93.9:286.1:343.8:::Favored:m-40 A 12 BASN:0.50:98.9:288.4:337.6:::Favored:m-40 A 13 APHE:0.65:45.1:187.2:276.4:::Favored:t80 A 13 BPHE:0.35:86.1:179.6:263.1:::Favored:t80 A 14 ASN:1.00:95.2:289.6:333.0:::Favored:m-40 A 15 VAL:1.00:42.3:168.2::::Favored:t A 16 CYS:1.00:40.8:176.5::::Favored:t A 17 ARG:1.00:21.4:289.7:282.8:288.6:158.7:Favored:mmm160 A 18 LEU:1.00:65.0:287.2:173.3:::Favored:mt A 19 PRO:1.00:43.6:24.4:324.8:31.6::Favored:Cg_endo A 21 THR:1.00:5.7:314.0::::Favored:m A 22 APRO:0.55:87.5:333.5:34.0:333.8::Favored:Cg_exo A 23 AGLU:0.50:86.9:290.9:187.1:341.8::Favored:mt-10 A 23 BGLU:0.50:91.7:292.0:183.8:339.2::Favored:mt-10 A 25 ALEU:0.50:95.7:294.4:173.6:::Favored:mt A 26 CYS:1.00:83.0:295.0::::Favored:m A 28 THR:1.00:29.6:52.9::::Favored:p A 29 ATYR:0.65:18.5:161.8:67.8:::Favored:t80 A 29 BTYR:0.35:0.4:191.3:322.7:::Allowed:t80 A 30 ATHR:0.70:60.8:57.4::::Favored:p A 30 BTHR:0.30:6.6:78.1::::Favored:p A 32 CYS:1.00:61.4:301.7::::Favored:m A 33 ILE:1.00:36.6:66.5:173.4:::Favored:pt A 34 AILE:0.70:60.9:303.6:167.6:::Favored:mt A 34 BILE:0.30:31.4:308.5:296.8:::Favored:mm A 35 ILE:1.00:45.6:62.4:170.0:::Favored:pt A 36 PRO:1.00:36.2:22.5:330.5:24.8::Favored:Cg_endo A 39 ATHR:0.70:14.0:311.0::::Favored:m A 39 BTHR:0.30:13.1:288.8::::Favored:m A 40 CYS:1.00:81.4:294.4::::Favored:m A 41 PRO:1.00:35.4:34.4:317.5:33.1::Favored:Cg_endo A 43 AASP:0.75:24.8:56.5:340.3:::Favored:p0 A 43 BASP:0.25:43.2:59.6:349.3:::Favored:p0 A 44 TYR:1.00:85.3:290.9:85.1:::Favored:m-80 A 46 ASN:1.00:38.7:301.6:117.9:::Favored:m110 """)
def set_rotamer_to_reference(self, xray_structure, mon_lib_srv=None, log=None, quiet=False): if self.mon_lib_srv is None: self.mon_lib_srv = mon_lib_srv assert isinstance(self.mon_lib_srv, mmtbx.monomer_library.server.server) if(log is None): log = sys.stdout make_sub_header( "Correcting rotamer outliers to match reference model", out=log) sa = SidechainAngles(False) r = rotalyze.rotalyze(pdb_hierarchy=self.pdb_hierarchy) rot_list_reference = {} coot_reference = {} for key in self.pdb_hierarchy_ref.keys(): hierarchy = self.pdb_hierarchy_ref[key] rot_list_reference[key] = \ rotalyze.rotalyze(pdb_hierarchy=hierarchy) model_hash = {} model_chis = {} reference_hash = {} reference_chis = {} model_outliers = 0 for rot in r.results: model_hash[rot.id_str()] = rot.rotamer_name if rot.rotamer_name == "OUTLIER": model_outliers += 1 for key in rot_list_reference.keys(): reference_hash[key] = {} for rot in rot_list_reference[key].results: reference_hash[key][rot.id_str()] = rot.rotamer_name print >> log, "** evaluating rotamers for working model **" for model in self.pdb_hierarchy.models(): for chain in model.chains(): for residue_group in chain.residue_groups(): all_dict = rotalyze.construct_complete_sidechain(residue_group) for atom_group in residue_group.atom_groups(): try: atom_dict = all_dict.get(atom_group.altloc) chis = sa.measureChiAngles(atom_group, atom_dict) if chis is not None: key = utils.id_str( chain_id=chain.id, resseq=residue_group.resseq, resname=atom_group.resname, icode=residue_group.icode, altloc=atom_group.altloc) model_chis[key] = chis except Exception: print >> log, \ ' %s%5s %s is missing some sidechain atoms, **skipping**' % ( chain.id, residue_group.resid(), atom_group.altloc+atom_group.resname) if model_outliers == 0: print >> log, "No rotamer outliers detected in working model" return else: print >> log, "Number of rotamer outliers: %d" % model_outliers print >> log, "\n** evaluating rotamers for reference model **" for file in self.pdb_hierarchy_ref.keys(): hierarchy = self.pdb_hierarchy_ref[file] reference_chis[file] = {} for model in hierarchy.models(): for chain in model.chains(): for residue_group in chain.residue_groups(): all_dict = rotalyze.construct_complete_sidechain(residue_group) for atom_group in residue_group.atom_groups(): try: atom_dict = all_dict.get(atom_group.altloc) chis = sa.measureChiAngles(atom_group, atom_dict) if chis is not None: key = utils.id_str( chain_id=chain.id, resseq=residue_group.resseq, resname=atom_group.resname, icode=residue_group.icode, altloc=atom_group.altloc) reference_chis[file][key] = chis except Exception: print >> log, \ ' %s%5s %s is missing some sidechain atoms, **skipping**' % ( chain.id, residue_group.resid(), atom_group.altloc+atom_group.resname) print >> log, "\n** fixing outliers **" sites_cart_start = xray_structure.sites_cart() for model in self.pdb_hierarchy.models(): for chain in model.chains(): for residue_group in chain.residue_groups(): if len(residue_group.conformers()) > 1: print >> log, " %s%5s %s has multiple conformations, **skipping**" % ( chain.id, residue_group.resid(), " "+residue_group.atom_groups()[0].resname) continue for conformer in residue_group.conformers(): for residue in conformer.residues(): if residue.resname == "PRO": continue key = utils.id_str( chain_id=chain.id, resseq=residue_group.resseq, resname=residue_group.atom_groups()[0].resname, icode=residue_group.icode, altloc=conformer.altloc) if len(chain.id) == 1: chain_id = " "+chain.id else: chain_id = chain.id file_key = '%s%s%s' %(residue.resname, chain_id, residue_group.resid()) file_key = file_key.strip() file_match = self.residue_match_hash.get(file_key) if file_match is not None: file = file_match[0] else: continue model_rot = model_hash.get(key) reference_rot = reference_hash[file].get(self.one_key_to_another(file_match[1])) m_chis = model_chis.get(key) r_chis = reference_chis[file].get(self.one_key_to_another(file_match[1])) if model_rot is not None and reference_rot is not None and \ m_chis is not None and r_chis is not None: if (model_rot == 'OUTLIER' and \ reference_rot != 'OUTLIER'): # or \ #atom_group.resname in ["LEU", "VAL", "THR"]: self.change_residue_rotamer_in_place( sites_cart_start,residue, m_chis,r_chis,self.mon_lib_srv) xray_structure.set_sites_cart(sites_cart_start) elif self.params.strict_rotamer_matching and \ (model_rot != 'OUTLIER' and reference_rot != 'OUTLIER'): if model_rot != reference_rot: self.change_residue_rotamer_in_place( sites_cart_start,residue, m_chis,r_chis,self.mon_lib_srv) xray_structure.set_sites_cart(sites_cart_start)
def load_refinement(self, ref): self._pdb_file = ref.replace('.dat', '.pdb') self._ins_file = ref.replace('.dat', '.ins') self._lst_file = ref.replace('.dat', '.lst') lst = LSTParser(self._lst_file) pdb_io = pdb.input(file_name=self._pdb_file) self._chain_lookup = PDBTools().get_chains(self._pdb_file) r = clashscore() self._clash_score, self._clashes = clashscore.analyze_clashes(r,pdb_io)# verbose=True) self._clashes = self._clashes[''].split('\n') rama = ramalyze() output, self._rama_data = rama.analyze_pdb(pdb_io=pdb_io, outliers_only=False) rota = rotalyze() output, self._rotamer_data = rota.analyze_pdb(pdb_io, outliers_only=False) r = cbetadev() output, summary, self._cb_data = cbetadev.analyze_pdb(r,pdb_io=pdb_io,outliers_only=True) self.sizer = wx.BoxSizer(wx.VERTICAL) self._rmsds = lst.get_stats() # Summary self.stats_sizer = wx.FlexGridSizer(cols=3, rows=0, vgap=5, hgap=5) self.stats_sizer.Add(wx.StaticText(self, -1, 'RMSD Bonds')) self.stats_sizer.Add(wx.StaticText(self, -1, '%.3f' % (self._rmsds[0]))) self.stats_sizer.Add(wx.StaticText(self, -1, '')) self.stats_sizer.Add(wx.StaticText(self, -1, 'RMSD Angles')) self.stats_sizer.Add(wx.StaticText(self, -1, '%.3f' % (self._rmsds[1]))) self.stats_sizer.Add(wx.StaticText(self, -1, ''), 0, wx.EXPAND|wx.BOTTOM, 10) self.stats_sizer.Add(wx.StaticText(self, -1, 'B Factor (Protein)')) self.stats_sizer.Add(wx.StaticText(self, -1, '%.2f' % (self._residues['avg']['pro']))) self.stats_sizer.Add(wx.StaticText(self, -1, ''), 0, wx.EXPAND|wx.BOTTOM) self.stats_sizer.Add(wx.StaticText(self, -1, 'B Factor (Solvent)')) self.stats_sizer.Add(wx.StaticText(self, -1, '%.2f' % (self._residues['avg']['sol']))) self.stats_sizer.Add(wx.StaticText(self, -1, ''), 0, wx.EXPAND|wx.BOTTOM) self.stats_sizer.Add(wx.StaticText(self, -1, 'B Factor (All)')) self.stats_sizer.Add(wx.StaticText(self, -1, '%.2f' % (self._residues['avg']['all']))) self.stats_sizer.Add(wx.StaticText(self, -1, ''), 0, wx.EXPAND|wx.BOTTOM, 10) self.stats_sizer.Add(wx.StaticText(self, -1, 'Ramachandran Outliers')) self.stats_sizer.Add(wx.StaticText(self, -1, '%.1f' % (rama.get_outliers_count_and_fraction()[1]*100) + '%')) self.stats_sizer.Add(wx.StaticText(self, -1, '(Goal ' + rama.get_outliers_goal()+')')) self.stats_sizer.Add(wx.StaticText(self, -1, 'Ramachandran Favoured')) self.stats_sizer.Add(wx.StaticText(self, -1, '%.1f' % (rama.get_favored_count_and_fraction()[1]*100) + '%')) self.stats_sizer.Add(wx.StaticText(self, -1, '(Goal ' + rama.get_favored_goal()+')'), 0, wx.EXPAND|wx.BOTTOM, 10) self.stats_sizer.Add(wx.StaticText(self, -1, 'Rotamer Outliers')) self.stats_sizer.Add(wx.StaticText(self, -1, '%.1f' % (rota.get_outliers_count_and_fraction()[1]*100) + '%')) self.stats_sizer.Add(wx.StaticText(self, -1, '(Goal ' + rota.get_outliers_goal()+')')) self.stats_sizer.Add(wx.StaticText(self, -1, 'C-beta Outliers')) self.stats_sizer.Add(wx.StaticText(self, -1, '%d' % len(self._cb_data))) self.stats_sizer.Add(wx.StaticText(self, -1, '(Goal 0)')) self.stats_sizer.Add(wx.StaticText(self, -1, 'Clashscore')) self.stats_sizer.Add(wx.StaticText(self, -1, '%d' % self._clash_score[''])) self.sizer.Add(self.stats_sizer, 0, wx.ALL, 10) # Ramachandran Outliers self.rama_sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Ramachandran Outliers'),wx.VERTICAL) if rama.get_outliers_count_and_fraction()[1] > 0: rama_list = wx.ListCtrl(self, -1, style=wx.LC_REPORT) self.Bind(wx.EVT_LIST_ITEM_SELECTED, self._show_rama, rama_list) sizes = [50, 50, 150, 80, 80, 80] for i, item in enumerate(['Chain', 'No', 'Residue', 'Score', 'Phi', 'Psi']): rama_list.InsertColumn(i, item, width = sizes[i]) i = 0 self._rama_outliers = [] for r in self._rama_data: (chain_id,resseq,resname,quality,phi,psi,status,pos_name,xyz) = r if status == 'OUTLIER': self._rama_outliers.append(r) rama_list.InsertStringItem(i, str(chain_id)) rama_list.SetStringItem(i, 1, str(resseq)) rama_list.SetStringItem(i, 2, resname) rama_list.SetStringItem(i, 3, '%.2f' % quality) rama_list.SetStringItem(i, 4, '%.1f' % phi) rama_list.SetStringItem(i, 5, '%.1f' % psi) i += 1 self.rama_sizer.Add(wx.StaticText(self, -1, '%d Ramachandran outliers found' % i), 0) self.rama_sizer.Add(rama_list, 0, wx.EXPAND|wx.ALL, 10) self.rama_list = rama_list else: self.rama_sizer.Add(wx.StaticText(self, -1, 'No Ramachandran Outliers'), 0) self.rama_sizer.Add(wx.Button(self, 0, 'Show Ramachandran Plot'), 0) self.Bind(wx.EVT_BUTTON, self.show_ramachandran, id=0) self.sizer.Add(self.rama_sizer, 0, wx.EXPAND|wx.ALL, 10) # Rotamer Outliers self.rota_sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Rotamer Outliers'),wx.VERTICAL) if rota.get_outliers_count_and_fraction()[1] > 0: rota_list = wx.ListCtrl(self, -1, style=wx.LC_REPORT) self.Bind(wx.EVT_LIST_ITEM_SELECTED, self._show_rota, rota_list) sizes = [50, 50, 150, 80, 80, 80, 80, 80] for i, item in enumerate(['Chain', 'No', 'Residue', 'Score', 'Chi1', 'Chi2', 'Chi3', 'Chi4']): rota_list.InsertColumn(i, item, width = sizes[i]) i = 0 self._rota_outliers = [] for r in self._rotamer_data: (chain_id,resseq,resname,quality,chi1,chi2,chi3,chi4,status,xyz) = r if status == 'OUTLIER': self._rota_outliers.append(r) rota_list.InsertStringItem(i, str(chain_id)) rota_list.SetStringItem(i, 1, str(resseq)) rota_list.SetStringItem(i, 2, resname) rota_list.SetStringItem(i, 3, '%.2f' % quality) rota_list.SetStringItem(i, 4, '%.1f' % chi1) rota_list.SetStringItem(i, 5, '%.1f' % chi2 if chi2 is not None else 'None') rota_list.SetStringItem(i, 6, '%.1f' % chi3 if chi3 is not None else 'None') rota_list.SetStringItem(i, 7, '%.1f' % chi4 if chi4 is not None else 'None') i += 1 self.rota_sizer.Add(wx.StaticText(self, -1, '%d rotamer outliers found' % i), 0) self.rota_sizer.Add(rota_list, 1, wx.EXPAND|wx.ALL, 5) self.rota_list = rota_list else: self.rota_sizer.Add(wx.StaticText(self, -1, 'No Rotamer Outliers')) self.rota_sizer.Add(wx.Button(self, 1, 'Show Chi1-Chi2 Plots')) self.Bind(wx.EVT_BUTTON, self.show_rotamer, id=1) self.sizer.Add(self.rota_sizer, 0, wx.EXPAND|wx.ALL, 10) # C-beta Outliers self.cb_sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'C-beta Outliers'),wx.VERTICAL) if len(self._cb_data) > 0: cb_list = wx.ListCtrl(self, -1, style=wx.LC_REPORT) self.Bind(wx.EVT_LIST_ITEM_SELECTED, self._show_cb, cb_list) sizes = [50, 50, 150, 100, 100] for i, item in enumerate(['Chain', 'No', 'Residue', 'Deviation', 'Angle']): cb_list.InsertColumn(i, item, width = sizes[i]) for i,r in enumerate(self._cb_data): (pdbf, alt, resname, chain_id, resseq, resseq2, dev, diheral, occ, altchar, xyz) = r cb_list.InsertStringItem(i, str(chain_id)) cb_list.SetStringItem(i, 1, str(resseq+resseq2)) cb_list.SetStringItem(i, 2, resname.upper()) cb_list.SetStringItem(i, 3, '%.3f' % dev) cb_list.SetStringItem(i, 4, '%.2f' % diheral) self.cb_sizer.Add(wx.StaticText(self, -1, '%d C-beta outliers found' % len(self._cb_data)), 0) self.cb_sizer.Add(cb_list, 1, wx.EXPAND|wx.ALL, 5) self.cb_list = cb_list else: self.cb_sizer.Add(wx.StaticText(self, -1, 'No C-beta Outliers')) self.sizer.Add(self.cb_sizer, 0, wx.EXPAND|wx.ALL, 10) # Bad Clashes self.clash_sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'All Atom Contacts'), wx.VERTICAL) if len(self._clashes) > 0: clash_list = wx.ListCtrl(self, -1, style=wx.LC_REPORT) self.Bind(wx.EVT_LIST_ITEM_SELECTED, self._show_clash, clash_list) sizes = [50, 50, 80, 80, 50, 50, 80, 80, 100] for i, item in enumerate(['Chain', 'No', 'Residue', 'Atom', 'Chain', 'No', 'Residue', 'Atom', 'Overlap']): clash_list.InsertColumn(i, item, width = sizes[i]) for i,r in enumerate(self._clashes): ' 78 ILE CD1 83 LEU HD21 :-0.402' clash_list.InsertStringItem(i, r[0:2].strip()) clash_list.SetStringItem(i, 1, r[2:6].strip()) clash_list.SetStringItem(i, 2, r[7:10].strip()) clash_list.SetStringItem(i, 3, r[11:15].strip()) clash_list.SetStringItem(i, 4, r[16:18].strip()) clash_list.SetStringItem(i, 5, r[19:22].strip()) clash_list.SetStringItem(i, 6, r[23:26].strip()) clash_list.SetStringItem(i, 7, r[28:32].strip()) clash_list.SetStringItem(i, 8, r[34:39].strip()) self.clash_sizer.Add(wx.StaticText(self, -1, '%d bad clashes found' % i), 0) self.clash_sizer.Add(clash_list, 1, wx.EXPAND|wx.ALL, 5) self.clash_list = clash_list else: self.clash_sizer.Add(wx.StaticText(self, -1, 'No Bad Clashes')) self.sizer.Add(self.clash_sizer, 0, wx.EXPAND|wx.ALL, 10) self._split_sites, self._npds = lst.get_site_info() # Split Sites self.split_sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Split Sites'), wx.VERTICAL) if len(self._split_sites) > 0: split_list = wx.ListCtrl(self, -1, style=wx.LC_REPORT) self.Bind(wx.EVT_LIST_ITEM_SELECTED, self._show_split, split_list) sizes = [100,100,100,50,80,100] for i, item in enumerate(['U1', 'U2', 'U3', 'No', 'Residue', 'Atom']): split_list.InsertColumn(i, item, width=sizes[i]) i = 0 for j,s in enumerate(self._split_sites): if '_' in s[3]: split_list.InsertStringItem(i, str(s[0])) split_list.SetStringItem(i, 1, str(s[1])) split_list.SetStringItem(i, 2, str(s[2])) atom,id = s[3].split('_') split_list.SetStringItem(i, 3, str(id)) split_list.SetStringItem(i, 4, str()) split_list.SetStringItem(i, 5, str(atom)) i += 1 self.split_sizer.Add(wx.StaticText(self, -1, '%d possible split sites found' % len(self._split_sites))) self.split_sizer.Add(split_list, 0, wx.EXPAND|wx.ALL, 5) self.split_list = split_list else: self.split_sizer.Add(wx.StaticText(self, -1, 'No split sites found')) self.sizer.Add(self.split_sizer, 0, wx.EXPAND|wx.ALL, 10) # NPDs self.npd_sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Non Positive Definites'), wx.VERTICAL) if len(self._npds) > 0: npd_list = wx.ListCtrl(self, -1, style=wx.LC_REPORT) self.Bind(wx.EVT_LIST_ITEM_SELECTED, self._show_npd, npd_list) sizes = [100,100,100,50,80,100] for i, item in enumerate(['U1', 'U2', 'U3', 'No', 'Residue', 'Atom']): npd_list.InsertColumn(i, item, width=sizes[i]) for i, s in enumerate(self._npds): npd_list.InsertStringItem(i, str(s[0])) npd_list.SetStringItem(i, 1, str(s[1])) npd_list.SetStringItem(i, 2, str(s[2])) atom, id = s[3].split('_') npd_list.SetStringItem(i, 3, str(id)) npd_list.SetStringItem(i, 4, str()) npd_list.SetStringItem(i, 5, str(atom)) self.npd_sizer.Add(wx.StaticText(self, -1, '%d non positive definite sites found' % len(self._npds))) self.npd_sizer.Add(npd_list, 0, wx.EXPAND|wx.ALL, 5) self.npd_list = npd_list else: self.npd_sizer.Add(wx.StaticText(self, -1, 'No non positive definite sites found')) self.sizer.Add(self.npd_sizer, 0, wx.EXPAND|wx.ALL, 10) self.SetSizer(self.sizer) self.SetAutoLayout(1) self.SetupScrolling()
def exercise_2(): pdb_str = """\ ATOM 2527 N LEU A 261 -31.022 -24.808 107.479 1.00 28.22 N ATOM 2528 CA LEU A 261 -30.054 -23.719 107.237 1.00 21.77 C ATOM 2529 C LEU A 261 -30.582 -22.773 106.168 1.00 27.64 C ATOM 2530 O LEU A 261 -29.841 -21.977 105.561 1.00 26.70 O ATOM 2531 CB LEU A 261 -28.696 -24.276 106.874 1.00 22.58 C ATOM 2532 CG LEU A 261 -28.135 -25.066 108.060 1.00 40.89 C ATOM 2533 CD1 LEU A 261 -26.892 -25.858 107.664 1.00 46.72 C ATOM 2534 CD2 LEU A 261 -27.806 -24.109 109.202 1.00 38.88 C ATOM 2535 H LEU A 261 -31.201 -25.277 106.781 1.00 33.87 H ATOM 2536 HA LEU A 261 -29.950 -23.204 108.064 1.00 26.12 H ATOM 2537 HB2 LEU A 261 -28.781 -24.874 106.115 1.00 27.10 H ATOM 2538 HB3 LEU A 261 -28.088 -23.548 106.670 1.00 27.10 H ATOM 2539 HG LEU A 261 -28.806 -25.693 108.373 1.00 49.07 H ATOM 2540 HD11 LEU A 261 -26.570 -26.338 108.430 1.00 56.07 H ATOM 2541 HD12 LEU A 261 -27.124 -26.473 106.965 1.00 56.07 H ATOM 2542 HD13 LEU A 261 -26.219 -25.247 107.353 1.00 56.07 H ATOM 2543 HD21 LEU A 261 -28.608 -23.653 109.468 1.00 46.66 H ATOM 2544 HD22 LEU A 261 -27.455 -24.612 109.941 1.00 46.66 H ATOM 2545 HD23 LEU A 261 -27.153 -23.474 108.899 1.00 46.66 H ATOM 2546 N GLY A 262 -31.887 -22.863 105.948 1.00 23.68 N ATOM 2547 CA GLY A 262 -32.572 -21.935 105.075 1.00 21.87 85 C ATOM 2548 C GLY A 262 -33.718 -22.620 104.386 1.00 27.32 C ATOM 2549 O GLY A 262 -33.943 -23.822 104.556 1.00 23.10 O ATOM 2550 H GLY A 262 -32.399 -23.459 106.298 1.00 28.42 H ATOM 2551 HA2 GLY A 262 -32.916 -21.189 105.591 1.00 26.25 85 H ATOM 2552 HA3 GLY A 262 -31.958 -21.598 104.405 1.00 26.25 85 H ATOM 2553 N SER A 263 -34.460 -21.830 103.628 1.00 24.62 N ATOM 2554 CA SER A 263 -35.631 -22.290 102.921 1.00 27.15 C ATOM 2555 C SER A 263 -35.594 -21.761 101.492 1.00 22.14 C ATOM 2556 O SER A 263 -34.723 -20.945 101.159 1.00 21.01 O ATOM 2557 CB SER A 263 -36.839 -21.713 103.619 1.00 25.73 C ATOM 2558 OG SER A 263 -36.907 -22.232 104.922 1.00 26.84 O ATOM 2559 H SER A 263 -34.296 -20.995 103.507 1.00 29.54 H ATOM 2560 HA SER A 263 -35.680 -23.269 102.917 1.00 32.58 H ATOM 2561 HB2 SER A 263 -36.754 -20.747 103.661 1.00 30.87 H ATOM 2562 HB3 SER A 263 -37.641 -21.960 103.132 1.00 30.87 H ATOM 2563 HG SER A 263 -37.560 -21.925 105.312 1.00 32.20 H """ pdb_str2 = """ ATOM 453 N PRO A 47 8.633 6.370 5.022 1.00 13.79 N ATOM 454 CA PRO A 47 7.915 7.571 5.496 1.00 14.61 C ATOM 455 C PRO A 47 7.612 7.481 6.994 1.00 15.06 C ATOM 456 O PRO A 47 7.289 6.377 7.439 1.00 14.39 O ATOM 457 CB PRO A 47 6.639 7.559 4.651 1.00 16.24 C ATOM 458 CG PRO A 47 7.089 6.901 3.338 1.00 15.52 C ATOM 459 CD PRO A 47 7.990 5.773 3.833 1.00 14.40 C ATOM 460 N MSE A 48 7.754 8.528 7.779 1.00 15.13 N ATOM 461 CA MSE A 48 7.482 8.456 9.201 1.00 16.17 C ATOM 462 C MSE A 48 6.040 8.750 9.517 1.00 15.23 C ATOM 463 O MSE A 48 5.417 9.418 8.735 1.00 14.77 O ATOM 464 CB MSE A 48 8.165 9.538 10.023 1.00 19.62 C ATOM 465 CG MSE A 48 9.630 9.466 10.238 1.00 21.70 C ATOM 466 SE MSE A 48 10.022 10.161 12.050 0.70 37.95 SE ATOM 467 CE MSE A 48 11.268 8.720 12.235 1.00 28.72 C ATOM 468 N LYS A 49 5.519 8.291 10.645 1.00 13.93 N ATOM 469 CA LYS A 49 4.167 8.624 11.045 1.00 13.79 C ATOM 470 C LYS A 49 4.022 10.138 11.202 1.00 14.66 C ATOM 471 O LYS A 49 5.011 10.853 11.351 1.00 15.69 O ATOM 472 CB LYS A 49 3.797 7.915 12.349 1.00 13.33 C ATOM 473 CG LYS A 49 3.593 6.416 12.204 1.00 14.35 C ATOM 474 CD LYS A 49 2.121 6.071 12.044 1.00 16.45 C ATOM 475 CE LYS A 49 1.571 5.402 13.292 1.00 18.19 C ATOM 476 NZ LYS A 49 0.899 4.110 12.980 1.00 19.97 N """ pdb_io = pdb.input(source_info=None, lines=pdb_str) hierarchy = pdb_io.construct_hierarchy() try : rotalyze.rotalyze(pdb_hierarchy=hierarchy) except Sorry as e : assert ("GLY A 262" in str(e)) else : raise Exception_expected pdb_io = pdb.input(source_info=None, lines=pdb_str2) hierarchy = pdb_io.construct_hierarchy() r = rotalyze.rotalyze(pdb_hierarchy=hierarchy) out = StringIO() r.show_old_output(out=out, verbose=False) output = out.getvalue() assert output == """\ A 47 PRO:1.00:86.4:329.3:41.3:324.9::Favored:Cg_exo A 48 MSE:0.70:0.3:287.6:214.8:138.3::OUTLIER:OUTLIER A 49 LYS:1.00:0.1:288.6:263.2:251.7:233.0:OUTLIER:OUTLIER """, output r = rotalyze.rotalyze(pdb_hierarchy=hierarchy, data_version="8000") out = StringIO() r.show_old_output(out=out, verbose=False) assert (out.getvalue() == """\ A 47 PRO:1.00:86.4:329.3:41.3:324.9::Favored:Cg_exo A 48 MSE:0.70:0.3:287.6:214.8:138.3::OUTLIER:OUTLIER A 49 LYS:1.00:0.1:288.6:263.2:251.7:233.0:OUTLIER:OUTLIER """), out.getvalue() try : r = rotalyze.rotalyze(pdb_hierarchy=hierarchy, data_version="9000") except ValueError : pass else : raise Exception_expected from mmtbx.rotamer.rotamer_eval import RotamerEval rotamer_manager = RotamerEval() results = [] for model in hierarchy.models(): for chain in model.chains(): for residue in chain.residues(): cur_rot = rotamer_manager.evaluate_residue(residue) results.append(cur_rot) assert results == ['Cg_exo', 'OUTLIER', 'OUTLIER']
def __init__( self, pdb_hierarchy, molprobity_scores=False, ): """ This class is being pickled. Try not to introduce huge members, e.g. self.hierarchy, etc. This is the reason ramalyze_obj, rotalyze_obj etc are not members of the class (not self.ramalyze_obj). """ self.clashscore = None self.ramachandran_outliers = None self.ramachandran_allowed = None self.ramachandran_favored = None self.rotamer_outliers = None self.c_beta_dev = None self.mpscore = None self.omglz = None self.n_cis_proline = None self.n_cis_general = None self.n_twisted_proline = None self.n_twisted_general = None if(molprobity_scores): ramalyze_obj = ramalyze(pdb_hierarchy=pdb_hierarchy, outliers_only=False) self.ramachandran_outliers = ramalyze_obj.percent_outliers self.ramachandran_outliers_cf = ramalyze_obj.get_outliers_count_and_fraction() self.ramachandran_allowed = ramalyze_obj.percent_allowed self.ramachandran_allowed_cf = ramalyze_obj.get_allowed_count_and_fraction() self.ramachandran_favored = ramalyze_obj.percent_favored self.ramachandran_favored_cf = ramalyze_obj.get_favored_count_and_fraction() rotalyze_obj = rotalyze(pdb_hierarchy=pdb_hierarchy, outliers_only=False) self.rotamer_outliers = rotalyze_obj.percent_outliers self.rotamer_cf = rotalyze_obj.get_outliers_count_and_fraction() cbetadev_obj = cbetadev( pdb_hierarchy = pdb_hierarchy, outliers_only = True, out = null_out()) self.c_beta_dev = cbetadev_obj.get_outlier_count() self.c_beta_dev_percent = cbetadev_obj.get_weighted_outlier_percent() self.clashscore = clashscore(pdb_hierarchy=pdb_hierarchy).get_clashscore() self.mpscore = molprobity_score( clashscore = self.clashscore, rota_out = self.rotamer_outliers, rama_fav = self.ramachandran_favored) omglz = omegalyze.omegalyze( pdb_hierarchy=pdb_hierarchy, quiet=True) self.n_proline = omglz.n_proline() self.n_general = omglz.n_general() self.n_cis_proline = omglz.n_cis_proline() self.n_cis_general = omglz.n_cis_general() self.n_twisted_proline = omglz.n_twisted_proline() self.n_twisted_general = omglz.n_twisted_general() self.cis_general = 0 self.twisted_general = 0 self.cis_proline = 0 self.twisted_proline = 0 if self.n_proline != 0: self.cis_proline = self.n_cis_proline*100./self.n_proline self.twisted_proline = self.n_twisted_proline*100./self.n_proline if self.n_general != 0: self.cis_general = self.n_cis_general*100./self.n_general self.twisted_general = self.n_twisted_general*100./self.n_general self.cablam_outliers=None self.cablam_disfavored=None self.cablam_ca_outliers=None try: cablam_results = cablam.cablamalyze(pdb_hierarchy, outliers_only=False, out=null_out(), quiet=True) self.cablam_outliers = cablam_results.percent_outliers() self.cablam_disfavored = cablam_results.percent_disfavored() self.cablam_ca_outliers = cablam_results.percent_ca_outliers() except Exception as e: print "CaBLAM failed with exception:" print " %s" % str(e) pass
def __init__ (self, pdb_hierarchy, xray_structure=None, fmodel=None, fmodel_neutron=None, geometry_restraints_manager=None, crystal_symmetry=None, sequences=None, flags=None, header_info=None, raw_data=None, unmerged_data=None, all_chain_proxies=None, keep_hydrogens=True, nuclear=False, save_probe_unformatted_file=None, show_hydrogen_outliers=False, min_cc_two_fofc=0.8, n_bins_data=10, count_anomalous_pairs_separately=False, use_internal_variance=True, outliers_only=True, use_pdb_header_resolution_cutoffs=False, file_name=None, ligand_selection=None, rotamer_library="8000", map_params=None) : assert rotamer_library == "8000", "data_version given to RotamerEval not recognized." for name in self.__slots__ : setattr(self, name, None) # very important - the i_seq attributes may be extracted later pdb_hierarchy.atoms().reset_i_seq() self.pdb_hierarchy = pdb_hierarchy if (xray_structure is None) : if (fmodel is not None) : xray_structure = fmodel.xray_structure elif (crystal_symmetry is not None) : xray_structure = pdb_hierarchy.extract_xray_structure( crystal_symmetry=crystal_symmetry) self.crystal_symmetry = crystal_symmetry if (crystal_symmetry is None) and (fmodel is not None) : self.crystal_symmetry = fmodel.f_obs().crystal_symmetry() self.header_info = header_info if (flags is None) : flags = molprobity_flags() if pdb_hierarchy.contains_protein() : if (flags.ramalyze) : self.ramalyze = ramalyze.ramalyze( pdb_hierarchy=pdb_hierarchy, outliers_only=outliers_only, out=null_out(), quiet=True) ##### omegalyze ################################################################ if (flags.omegalyze) : self.omegalyze = omegalyze.omegalyze( pdb_hierarchy=pdb_hierarchy, nontrans_only=outliers_only, out=null_out(), quiet=True) ##### omegalyze ################################################################ if (flags.rotalyze) : self.rotalyze = rotalyze.rotalyze( pdb_hierarchy=pdb_hierarchy, data_version=rotamer_library, outliers_only=outliers_only, out=null_out(), quiet=True) if (flags.cbetadev) : self.cbetadev = cbetadev.cbetadev( pdb_hierarchy=pdb_hierarchy, outliers_only=outliers_only, out=null_out(), quiet=True) if (flags.nqh) : self.nqh_flips = clashscore.nqh_flips( pdb_hierarchy=pdb_hierarchy) if (pdb_hierarchy.contains_rna() and flags.rna and libtbx.env.has_module(name="suitename")) : if (geometry_restraints_manager is not None) : self.rna = rna_validate.rna_validation( pdb_hierarchy=pdb_hierarchy, geometry_restraints_manager=geometry_restraints_manager, outliers_only=outliers_only, params=None) if (flags.clashscore) : self.clashes = clashscore.clashscore( pdb_hierarchy=pdb_hierarchy, save_probe_unformatted_file=save_probe_unformatted_file, nuclear=nuclear, keep_hydrogens=keep_hydrogens, out=null_out(), verbose=False) if (flags.model_stats) and (xray_structure is not None) : self.model_stats = model_properties.model_statistics( pdb_hierarchy=pdb_hierarchy, xray_structure=xray_structure, all_chain_proxies=all_chain_proxies, ignore_hd=(not nuclear), ligand_selection=ligand_selection) if (geometry_restraints_manager is not None) and (flags.restraints) : assert (xray_structure is not None) self.restraints = restraints.combined( pdb_hierarchy=pdb_hierarchy, xray_structure=xray_structure, geometry_restraints_manager=geometry_restraints_manager, ignore_hd=(not nuclear), cdl=getattr(all_chain_proxies, "use_cdl", None)) if (sequences is not None) and (flags.seq) : self.sequence = sequence.validation( pdb_hierarchy=pdb_hierarchy, sequences=sequences, log=null_out(), include_secondary_structure=True, extract_coordinates=True) # use maps (fmodel is not used) use_maps = False if (map_params is not None): use_maps = ( (map_params.input.maps.map_file_name) or ( (map_params.input.maps.map_coefficients_file_name) and (map_params.input.maps.map_coefficients_label) ) ) if (use_maps): if (flags.real_space): self.real_space = experimental.real_space( fmodel=None, pdb_hierarchy=pdb_hierarchy, cc_min=min_cc_two_fofc, molprobity_map_params=map_params.input.maps) if (flags.waters): self.waters = waters.waters( pdb_hierarchy=pdb_hierarchy, xray_structure=xray_structure, fmodel=None, collect_all=True, molprobity_map_params=map_params.input.maps) if (fmodel is not None) : if (use_pdb_header_resolution_cutoffs) and (header_info is not None) : fmodel = fmodel.resolution_filter( d_min=header_info.d_min, d_max=header_info.d_max) if (flags.rfactors) : self.data_stats = experimental.data_statistics(fmodel, raw_data=raw_data, n_bins=n_bins_data, count_anomalous_pairs_separately=count_anomalous_pairs_separately) if (not use_maps): # if maps are used, keep previous results if (flags.real_space): self.real_space = experimental.real_space( fmodel=fmodel, pdb_hierarchy=pdb_hierarchy, cc_min=min_cc_two_fofc) if (flags.waters) : self.waters = waters.waters( pdb_hierarchy=pdb_hierarchy, xray_structure=xray_structure, fmodel=fmodel, collect_all=True) if (unmerged_data is not None) : self.merging = experimental.merging_and_model_statistics( f_obs=fmodel.f_obs(), f_model=fmodel.f_model(), r_free_flags=fmodel.r_free_flags(), unmerged_i_obs=unmerged_data, anomalous=count_anomalous_pairs_separately, use_internal_variance=use_internal_variance, n_bins=n_bins_data) if (flags.xtriage) : import mmtbx.scaling.xtriage f_model = abs(fmodel.f_model()).set_observation_type_xray_amplitude() if (raw_data is not None) : f_model, obs = f_model.common_sets(other=raw_data) else : obs = fmodel.f_obs() self.xtriage = mmtbx.scaling.xtriage.xtriage_analyses( miller_obs=obs, miller_calc=f_model, unmerged_obs=unmerged_data, # XXX some redundancy here... text_out=null_out()) if (fmodel_neutron is not None) and (flags.rfactors) : self.neutron_stats = experimental.data_statistics(fmodel_neutron, n_bins=n_bins_data, count_anomalous_pairs_separately=False) if (pdb_hierarchy.models_size() == 1) : self._multi_criterion = multi_criterion_view(pdb_hierarchy)
def make_multikin(f, processed_pdb_file, pdbID=None, keep_hydrogens=False): if pdbID == None: pdbID = "PDB" hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy i_seq_name_hash = build_name_hash(pdb_hierarchy=hierarchy) sites_cart=processed_pdb_file.all_chain_proxies.sites_cart geometry = processed_pdb_file.geometry_restraints_manager() flags = geometry_restraints.flags.flags(default=True) angle_proxies = geometry.angle_proxies pair_proxies = geometry.pair_proxies(flags=flags, sites_cart=sites_cart) bond_proxies = pair_proxies.bond_proxies quick_bond_hash = {} for bp in bond_proxies.simple: if (i_seq_name_hash[bp.i_seqs[0]][9:14] == i_seq_name_hash[bp.i_seqs[1]][9:14]): if quick_bond_hash.get(bp.i_seqs[0]) is None: quick_bond_hash[bp.i_seqs[0]] = [] quick_bond_hash[bp.i_seqs[0]].append(bp.i_seqs[1]) kin_out = get_default_header() altid_controls = get_altid_controls(hierarchy=hierarchy) if altid_controls != "": kin_out += altid_controls kin_out += "@group {%s} dominant animate\n" % pdbID initiated_chains = [] rot_outliers = rotalyze(pdb_hierarchy=hierarchy, outliers_only=True) cb = cbetadev( pdb_hierarchy=hierarchy, outliers_only=True) rama = ramalyze(pdb_hierarchy=hierarchy, outliers_only=True) counter = 0 for model in hierarchy.models(): for chain in model.chains(): if chain.id not in initiated_chains: kin_out += "@subgroup {%s} dominant master= {chain %s}\n" % ( pdbID, chain.id) initiated_chains.append(chain.id) kin_out += get_kin_lots(chain=chain, bond_hash=quick_bond_hash, i_seq_name_hash=i_seq_name_hash, pdbID=pdbID, index=counter) if (chain.is_protein()) : kin_out += rotamer_outliers(chain=chain, pdbID=pdbID, rot_outliers=rot_outliers) kin_out += rama_outliers(chain=chain, pdbID=pdbID, ram_outliers=rama) # TODO use central methods in mmtbx.validation.restraints kin_out += get_angle_outliers(angle_proxies=angle_proxies, chain=chain, sites_cart=sites_cart, hierarchy=hierarchy) kin_out += get_bond_outliers(bond_proxies=bond_proxies, chain=chain, sites_cart=sites_cart, hierarchy=hierarchy) if (chain.is_protein()) : kin_out += cbeta_dev(chain_id=chain.id, outliers=cb.results) kin_out += pperp_outliers(hierarchy=hierarchy, chain=chain) counter += 1 kin_out += omegalyze.omegalyze(pdb_hierarchy=hierarchy,nontrans_only=True, out=None,quiet=False).as_kinemage() kin_out += make_probe_dots(hierarchy=hierarchy, keep_hydrogens=keep_hydrogens) kin_out += get_footer() outfile = file(f, 'w') for line in kin_out: outfile.write(line) outfile.close() return f
ATOM 475 CE LYS A 49 1.571 5.402 13.292 1.00 18.19 C ATOM 476 NZ LYS A 49 0.899 4.110 12.980 1.00 19.97 N """ pdb_io = pdb.input(source_info=None, lines=pdb_str) hierarchy = pdb_io.construct_hierarchy() try : rotalyze.rotalyze(pdb_hierarchy=hierarchy) except Sorry, e : assert ("GLY A 262" in str(e)) else : raise Exception_expected pdb_io = pdb.input(source_info=None, lines=pdb_str2) hierarchy = pdb_io.construct_hierarchy() r = rotalyze.rotalyze(pdb_hierarchy=hierarchy) out = StringIO() r.show_old_output(out=out, verbose=False) output = out.getvalue() assert output == """\ A 47 PRO:1.00:86.4:329.3:41.3:324.9::Favored:Cg_exo A 48 MSE:0.70:0.3:287.6:214.8:138.3::OUTLIER:OUTLIER A 49 LYS:1.00:0.1:288.6:263.2:251.7:233.0:OUTLIER:OUTLIER """, output r = rotalyze.rotalyze(pdb_hierarchy=hierarchy, data_version="8000") out = StringIO() r.show_old_output(out=out, verbose=False) assert (out.getvalue() == """\ A 47 PRO:1.00:86.4:329.3:41.3:324.9::Favored:Cg_exo