def tst_1(): ''' input model: bond lengths close to neutron but not quite input grm: neutron bond lengths ''' pdb_inp = iotbx.pdb.input(lines=pdb_str1.split("\n"), source_info=None) params = mmtbx.model.manager.get_default_pdb_interpretation_params() params.pdb_interpretation.use_neutron_distances = True model = mmtbx.model.manager(model_input=pdb_inp, pdb_interpretation_params=params, log=null_out(), build_grm=True) # request neutron bond lengths model.set_hydrogen_bond_length(use_neutron_distances=True, show=False, log=sys.stdout) model.process_input_model(make_restraints=True) compare_XH_bond_length_to_ideal(model=model) #STOP() # request X-ray bond lengths pdb_inp = iotbx.pdb.input(lines=pdb_str1.split("\n"), source_info=None) model = mmtbx.model.manager(model_input=pdb_inp, pdb_interpretation_params=params, log=null_out(), build_grm=False) model.set_hydrogen_bond_length(use_neutron_distances=False, show=False, log=sys.stdout) compare_XH_bond_length_to_ideal(model=model)
def exercise_allowed_outliers_emsley_filling(): file_name = libtbx.env.find_in_repositories( relative_path="phenix_regression/pdb/3ifk.pdb", test=os.path.isfile) if (file_name is None): print("Skipping test.") return params = mmtbx.model.manager.get_default_pdb_interpretation_params() params.pdb_interpretation.ramachandran_plot_restraints.enabled = True params.pdb_interpretation.ramachandran_plot_restraints.favored = "oldfield" params.pdb_interpretation.ramachandran_plot_restraints.allowed = "emsley" params.pdb_interpretation.ramachandran_plot_restraints.outlier = None params.pdb_interpretation.ramachandran_plot_restraints.inject_emsley8k_into_oldfield_favored = False pdb_inp = iotbx.pdb.input(file_name=file_name) model = mmtbx.model.manager(model_input=pdb_inp, pdb_interpretation_params=params, log=null_out(), build_grm=True) grm = model.get_restraints_manager().geometry assert grm.ramachandran_manager.get_n_proxies() == 167 assert grm.ramachandran_manager.get_n_oldfield_proxies() == 164 assert grm.ramachandran_manager.get_n_emsley_proxies() == 3 params.pdb_interpretation.ramachandran_plot_restraints.enabled = True params.pdb_interpretation.ramachandran_plot_restraints.favored = "oldfield" params.pdb_interpretation.ramachandran_plot_restraints.allowed = None params.pdb_interpretation.ramachandran_plot_restraints.outlier = None model.set_pdb_interpretation_params(params) model.process_input_model(make_restraints=True) grm = model.get_restraints_manager().geometry nprox = grm.ramachandran_manager.get_n_proxies() assert nprox == 164 assert grm.ramachandran_manager.get_n_oldfield_proxies() == 164 assert grm.ramachandran_manager.get_n_emsley_proxies() == 0
def exercise_ramachandran_selections(mon_lib_srv, ener_lib): # Just check overall rama proxies file_name = libtbx.env.find_in_repositories( # relative_path="phenix_regression/pdb/3mku.pdb", relative_path="phenix_regression/pdb/fab_a_cut.pdb", test=os.path.isfile) if (file_name is None): print("Skipping test.") return params = mmtbx.model.manager.get_default_pdb_interpretation_params() params.pdb_interpretation.ramachandran_plot_restraints.enabled = True params.pdb_interpretation.ramachandran_plot_restraints.inject_emsley8k_into_oldfield_favored = False pdb_inp = iotbx.pdb.input(file_name=file_name) model = mmtbx.model.manager(model_input=pdb_inp, pdb_interpretation_params=params, log=null_out(), build_grm=True) grm = model.get_restraints_manager().geometry n = grm.ramachandran_manager.get_n_proxies() assert n == 53, n # simple selection model = mmtbx.model.manager(model_input=pdb_inp, pdb_interpretation_params=params, log=null_out()) params.pdb_interpretation.ramachandran_plot_restraints.enabled = True params.pdb_interpretation.ramachandran_plot_restraints.inject_emsley8k_into_oldfield_favored = False params.pdb_interpretation.ramachandran_plot_restraints.selection = "chain A and resid 1:7" model.set_pdb_interpretation_params(params) model.process_input_model(make_restraints=True) grm = model.get_restraints_manager().geometry nprox = grm.ramachandran_manager.get_n_proxies() assert nprox == 5, ""+\ "Want to get 5 rama proxies, got %d" % nprox # 7 residues: there are insertion codes model = mmtbx.model.manager(model_input=pdb_inp, pdb_interpretation_params=params, log=null_out()) params.pdb_interpretation.ramachandran_plot_restraints.enabled = True params.pdb_interpretation.ramachandran_plot_restraints.inject_emsley8k_into_oldfield_favored = False params.pdb_interpretation.ramachandran_plot_restraints.selection = "chain A and resid 27:28" model.set_pdb_interpretation_params(params) model.process_input_model(make_restraints=True) grm = model.get_restraints_manager().geometry nprox = grm.ramachandran_manager.get_n_proxies() assert nprox == 5, ""+\ "Want to get 5 rama proxies, got %d" % nprox
def exercise_ss_creation_crash(): pdb_str = """ CRYST1 145.350 135.090 157.320 90.00 90.00 90.00 P 1 SCALE1 0.006880 0.000000 0.000000 0.00000 SCALE2 0.000000 0.007402 0.000000 0.00000 SCALE3 0.000000 0.000000 0.006356 0.00000 ATOM 1 N ASN A 1 47.095 160.279 31.220 1.00 30.00 N ATOM 2 CA ASN A 1 65.985 120.233 34.727 1.00 30.00 C ATOM 3 C ASN A 1 56.657 138.700 33.374 1.00 30.00 C ATOM 4 O ASN A 1 56.353 138.977 34.561 1.00 30.00 O ATOM 5 CB ASN A 1 65.238 120.133 36.068 1.00 30.00 C ATOM 6 CG ASN A 1 66.087 119.360 37.057 1.00 30.00 C ATOM 7 OD1 ASN A 1 65.746 118.217 37.441 1.00 30.00 O ATOM 8 ND2 ASN A 1 67.240 119.920 37.395 1.00 30.00 N ATOM 9 N ASN A 2 56.939 137.441 33.021 1.00 30.00 N ATOM 10 CA ASN A 2 67.135 117.384 35.354 1.00 30.00 C ATOM 11 C ASN A 2 74.935 104.398 35.546 1.00 30.00 C ATOM 12 O ASN A 2 74.423 104.166 34.444 1.00 30.00 O ATOM 13 CB ASN A 2 65.828 116.703 35.809 1.00 30.00 C ATOM 14 CG ASN A 2 66.092 115.518 36.718 1.00 30.00 C ATOM 15 OD1 ASN A 2 66.641 114.515 36.266 1.00 30.00 O ATOM 16 ND2 ASN A 2 65.744 115.556 38.000 1.00 30.00 N ATOM 17 N ASN A 3 76.102 103.886 35.920 1.00 30.00 N ATOM 18 CA ASN A 3 68.960 115.076 35.163 1.00 30.00 C ATOM 19 C ASN A 3 86.047 90.376 35.591 1.00 30.00 C ATOM 20 O ASN A 3 87.134 90.903 35.535 1.00 30.00 O ATOM 21 CB ASN A 3 70.251 115.882 34.903 1.00 30.00 C ATOM 22 CG ASN A 3 71.023 116.208 36.192 1.00 30.00 C ATOM 23 OD1 ASN A 3 70.637 117.096 36.957 1.00 30.00 O ATOM 24 ND2 ASN A 3 72.106 115.481 36.436 1.00 30.00 N ATOM 25 OXT ASN A 3 85.912 89.104 36.045 1.00 30.00 O TER END """ with open("exercise_ss_creation_crash_model.pdb","w") as fo: fo.write(pdb_str) from iotbx.data_manager import DataManager dm=DataManager() params = mmtbx.model.manager.get_default_pdb_interpretation_params() params.pdb_interpretation.secondary_structure.enabled=True model = dm.get_model('exercise_ss_creation_crash_model.pdb') model.set_pdb_interpretation_params(params) model.process_input_model(make_restraints=True)
def run_tst_grm_after_neutralize_scatterers(): # Look at nonbonded interaction CB - OE2 in Glu # OE2 has negative charge # vdw distance is 2.560 A when OE2 is neutral # vdw distance is 2.752 A when OE1 has O1- charge pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_str_2) model = mmtbx.model.manager(model_input=pdb_inp, log=null_out(), build_grm=True) atoms = model.get_hierarchy().atoms() grm = model.get_restraints_manager() # with open('1.geo', 'w') as f: # f.write(model.restraints_as_geo()) nonbonded_proxies = grm.geometry.pair_proxies().nonbonded_proxies.simple for nb_proxy in nonbonded_proxies: iseq, jseq = nb_proxy.i_seqs if (iseq == 4 and jseq == 8): vdw_distance1 = nb_proxy.vdw_distance assert (atoms[iseq].name.strip() == 'CB') assert (atoms[jseq].name.strip() == 'OE2') model = mmtbx.model.manager(model_input=pdb_inp, log=null_out(), build_grm=False) model.neutralize_scatterers() model.process_input_model(make_restraints=True) atoms2 = model.get_hierarchy().atoms() grm2 = model.get_restraints_manager() # with open('2.geo', 'w') as f: # f.write(model.restraints_as_geo()) nonbonded_proxies2 = grm2.geometry.pair_proxies().nonbonded_proxies.simple for nb_proxy in nonbonded_proxies2: iseq, jseq = nb_proxy.i_seqs if (iseq == 4 and jseq == 8): vdw_distance2 = nb_proxy.vdw_distance assert (atoms2[iseq].name.strip() == 'CB') assert (atoms2[jseq].name.strip() == 'OE2') assert (vdw_distance1 != vdw_distance2)
def run(args, log = sys.stdout): if(len(args)==0): parsed = defaults(log=log) parsed.show(prefix=" ", out=log) return parsed = defaults(log=log) processed_args = mmtbx.utils.process_command_line_args(args = args, log = sys.stdout, master_params = parsed) processed_args.params.show() params = processed_args.params.extract() if(len(processed_args.pdb_file_names)==0): raise Sorry("No PDB file found.") if(len(processed_args.pdb_file_names)>1): raise Sorry("More than one PDB file found.") pdb_file_name = processed_args.pdb_file_names[0] if(params.f_obs.f_calc.atomic_model.add_hydrogens): pdb_file_name_r = os.path.basename(pdb_file_name)+"_reduce" # easy_run.go("phenix.reduce %s > %s"% (pdb_file_name, pdb_file_name_r)) run_reduce_with_timeout(file_name=pdb_file_name, parameters=" > %s" % pdb_file_name_r) pdb_file_name = pdb_file_name_r pdbi_params = mmtbx.model.manager.get_default_pdb_interpretation_params() if(params.f_obs.f_calc.atomic_model.use_ramachandran_plot_restraints): pdbi_params.pdb_interpretation.ramachandran_plot_restraints.enabled=True model = mmtbx.model.manager( model_input = iotbx.pdb.input(file_name = pdb_file_name), pdb_interpretation_params = pdbi_params) model.process_input_model(make_restraints=True) root = iotbx.pdb.hierarchy.root() loop_1( params = params, root = root, xray_structure = model.get_xray_structure(), pdb_hierarchy = model.get_hierarchy(), restraints_manager = model.get_restraints_manager()) root.write_pdb_file( file_name = params.f_obs.f_calc.atomic_model.output_file_name, crystal_symmetry = model.crystal_symmetry()) simulate_f_obs(root=root, crystal_symmetry=model.crystal_symmetry(), params = params)
def exercise_reference_model_restraints(mon_lib_srv, ener_lib): # 1yjp pdb_str = """\ CRYST1 21.937 4.866 23.477 90.00 107.08 90.00 P 1 21 1 2 ATOM 1 N GLY A 1 -9.009 4.612 6.102 1.00 16.77 N ATOM 2 CA GLY A 1 -9.052 4.207 4.651 1.00 16.57 C ATOM 3 C GLY A 1 -8.015 3.140 4.419 1.00 16.16 C ATOM 4 O GLY A 1 -7.523 2.521 5.381 1.00 16.78 O ATOM 5 N ASN A 2 -7.656 2.923 3.155 1.00 15.02 N ATOM 6 CA ASN A 2 -6.522 2.038 2.831 1.00 14.10 C ATOM 7 C ASN A 2 -5.241 2.537 3.427 1.00 13.13 C ATOM 8 O ASN A 2 -4.978 3.742 3.426 1.00 11.91 O ATOM 9 CB ASN A 2 -6.346 1.881 1.341 1.00 15.38 C ATOM 10 CG ASN A 2 -7.584 1.342 0.692 1.00 14.08 C ATOM 11 OD1 ASN A 2 -8.025 0.227 1.016 1.00 17.46 O ATOM 12 ND2 ASN A 2 -8.204 2.155 -0.169 1.00 11.72 N ATOM 13 N ASN A 3 -4.438 1.590 3.905 1.00 12.26 N ATOM 14 CA ASN A 3 -3.193 1.904 4.589 1.00 11.74 C ATOM 15 C ASN A 3 -1.955 1.332 3.895 1.00 11.10 C ATOM 16 O ASN A 3 -1.872 0.119 3.648 1.00 10.42 O ATOM 17 CB ASN A 3 -3.259 1.378 6.042 1.00 12.15 C ATOM 18 CG ASN A 3 -2.006 1.739 6.861 1.00 12.82 C ATOM 19 OD1 ASN A 3 -1.702 2.925 7.072 1.00 15.05 O ATOM 20 ND2 ASN A 3 -1.271 0.715 7.306 1.00 13.48 N ATOM 21 N GLN A 4 -1.005 2.228 3.598 1.00 10.29 N ATOM 22 CA GLN A 4 0.384 1.888 3.199 1.00 10.53 C ATOM 23 C GLN A 4 1.435 2.606 4.088 1.00 10.24 C ATOM 24 O GLN A 4 1.547 3.843 4.115 1.00 8.86 O ATOM 25 CB GLN A 4 0.656 2.148 1.711 1.00 9.80 C ATOM 26 CG GLN A 4 1.944 1.458 1.213 1.00 10.25 C ATOM 27 CD GLN A 4 2.504 2.044 -0.089 1.00 12.43 C ATOM 28 OE1 GLN A 4 2.744 3.268 -0.190 1.00 14.62 O ATOM 29 NE2 GLN A 4 2.750 1.161 -1.091 1.00 9.05 N ATOM 30 N GLN A 5 2.154 1.821 4.871 1.00 10.38 N ATOM 31 CA GLN A 5 3.270 2.361 5.640 1.00 11.39 C ATOM 32 C GLN A 5 4.594 1.768 5.172 1.00 11.52 C ATOM 33 O GLN A 5 4.768 0.546 5.054 1.00 12.05 O ATOM 34 CB GLN A 5 3.056 2.183 7.147 1.00 11.96 C ATOM 35 CG GLN A 5 1.829 2.950 7.647 1.00 10.81 C ATOM 36 CD GLN A 5 1.344 2.414 8.954 1.00 13.10 C ATOM 37 OE1 GLN A 5 0.774 1.325 9.002 1.00 10.65 O ATOM 38 NE2 GLN A 5 1.549 3.187 10.039 1.00 12.30 N ATOM 39 N ASN A 6 5.514 2.664 4.856 1.00 11.99 N ATOM 40 CA ASN A 6 6.831 2.310 4.318 1.00 12.30 C ATOM 41 C ASN A 6 7.854 2.761 5.324 1.00 13.40 C ATOM 42 O ASN A 6 8.219 3.943 5.374 1.00 13.92 O ATOM 43 CB ASN A 6 7.065 3.016 2.993 1.00 12.13 C ATOM 44 CG ASN A 6 5.961 2.735 2.003 1.00 12.77 C ATOM 45 OD1 ASN A 6 5.798 1.604 1.551 1.00 14.27 O ATOM 46 ND2 ASN A 6 5.195 3.747 1.679 1.00 10.07 N ATOM 47 N TYR A 7 8.292 1.817 6.147 1.00 14.70 N ATOM 48 CA TYR A 7 9.159 2.144 7.299 1.00 15.18 C ATOM 49 C TYR A 7 10.603 2.331 6.885 1.00 15.91 C ATOM 50 O TYR A 7 11.041 1.811 5.855 1.00 15.76 O ATOM 51 CB TYR A 7 9.061 1.065 8.369 1.00 15.35 C ATOM 52 CG TYR A 7 7.665 0.929 8.902 1.00 14.45 C ATOM 53 CD1 TYR A 7 6.771 0.021 8.327 1.00 15.68 C ATOM 54 CD2 TYR A 7 7.210 1.756 9.920 1.00 14.80 C ATOM 55 CE1 TYR A 7 5.480 -0.094 8.796 1.00 13.46 C ATOM 56 CE2 TYR A 7 5.904 1.649 10.416 1.00 14.33 C ATOM 57 CZ TYR A 7 5.047 0.729 9.831 1.00 15.09 C ATOM 58 OH TYR A 7 3.766 0.589 10.291 1.00 14.39 O ATOM 59 OXT TYR A 7 11.358 2.999 7.612 1.00 17.49 O TER 60 TYR A 7 HETATM 61 O HOH A 8 -6.471 5.227 7.124 1.00 22.62 O HETATM 62 O HOH A 9 10.431 1.858 3.216 1.00 19.71 O HETATM 63 O HOH A 10 -11.286 1.756 -1.468 1.00 17.08 O HETATM 64 O HOH A 11 11.808 4.179 9.970 1.00 23.99 O HETATM 65 O HOH A 12 13.605 1.327 9.198 1.00 26.17 O HETATM 66 O HOH A 13 -2.749 3.429 10.024 1.00 39.15 O HETATM 67 O HOH A 14 -1.500 0.682 10.967 1.00 43.49 O MASTER 234 0 0 0 0 0 0 6 66 1 0 1 END """ work_params = mmtbx.model.manager.get_default_pdb_interpretation_params() work_params.reference_model.enabled = True work_params.reference_model.use_starting_model_as_reference = True model = mmtbx.model.manager(model_input=iotbx.pdb.input( source_info=None, lines=pdb_str.split('\n')), pdb_interpretation_params=work_params, build_grm=True, log=null_out()) n_ref_dih_prox = model.get_restraints_manager( ).geometry.get_n_reference_dihedral_proxies() assert n_ref_dih_prox == 34, "expected 34, got %d" % n_ref_dih_prox model = mmtbx.model.manager(model_input=iotbx.pdb.input( source_info=None, lines=pdb_str.split('\n')), pdb_interpretation_params=work_params, build_grm=False, log=null_out()) work_params = mmtbx.model.manager.get_default_pdb_interpretation_params() work_params.reference_model.enabled = True work_params.reference_model.use_starting_model_as_reference = True work_params.reference_model.main_chain = False model.set_pdb_interpretation_params(work_params) model.process_input_model(make_restraints=True) n_ref_dih_prox = model.get_restraints_manager( ).geometry.get_n_reference_dihedral_proxies() assert n_ref_dih_prox == 16, "expected 16, got %d" % n_ref_dih_prox model = mmtbx.model.manager(model_input=iotbx.pdb.input( source_info=None, lines=pdb_str.split('\n')), pdb_interpretation_params=work_params, build_grm=False, log=null_out()) work_params = mmtbx.model.manager.get_default_pdb_interpretation_params() work_params.reference_model.enabled = True work_params.reference_model.use_starting_model_as_reference = True work_params.reference_model.side_chain = False model.set_pdb_interpretation_params(work_params) model.process_input_model(make_restraints=True) n_ref_dih_prox = model.get_restraints_manager( ).geometry.get_n_reference_dihedral_proxies() assert n_ref_dih_prox == 18, "expected 18, got %d" % n_ref_dih_prox
def exercise_allowed_outliers(): file_name = libtbx.env.find_in_repositories( relative_path="phenix_regression/pdb/3ifk.pdb", test=os.path.isfile) if (file_name is None): print("Skipping test.") return params = mmtbx.model.manager.get_default_pdb_interpretation_params() params.pdb_interpretation.ramachandran_plot_restraints.enabled = True params.pdb_interpretation.ramachandran_plot_restraints.inject_emsley8k_into_oldfield_favored = False pdb_inp = iotbx.pdb.input(file_name=file_name) model = mmtbx.model.manager(model_input=pdb_inp, pdb_interpretation_params=params, log=null_out(), build_grm=True) grm = model.get_restraints_manager().geometry assert grm.ramachandran_manager.get_n_proxies( ) == 170, grm.ramachandran_manager.get_n_proxies() full_proxies_iseqs = list( tuple(x.get_i_seqs()) for x in grm.ramachandran_manager._oldfield_proxies) params.pdb_interpretation.ramachandran_plot_restraints.favored = "oldfield" params.pdb_interpretation.ramachandran_plot_restraints.allowed = "oldfield" params.pdb_interpretation.ramachandran_plot_restraints.outlier = None model = mmtbx.model.manager(model_input=pdb_inp, pdb_interpretation_params=params, log=null_out()) model.set_pdb_interpretation_params(params) model.process_input_model(make_restraints=True) grm = model.get_restraints_manager().geometry nprox = grm.ramachandran_manager.get_n_proxies() # print "without outliers", nprox assert nprox == 167, nprox no_out_proxies_iseqs = list( tuple(x.get_i_seqs()) for x in grm.ramachandran_manager._oldfield_proxies) # assert nprox == 5, ""+\ # "Want to get 5 rama proxies, got %d" % nprox sdif_list = sorted( list(set(full_proxies_iseqs) - set(no_out_proxies_iseqs))) outliers_txt_list = [ 'pdb=" N THR B 5 "', 'pdb=" N GLU B 6 "', 'pdb=" N SER B 81 "' ] # print "outliers" for a, answer in zip(sdif_list, outliers_txt_list): # print model.get_hierarchy().atoms()[a[1]].id_str() assert model.get_hierarchy().atoms()[a[1]].id_str() == answer model = mmtbx.model.manager(model_input=pdb_inp, pdb_interpretation_params=params, log=null_out()) params.pdb_interpretation.ramachandran_plot_restraints.favored = "oldfield" params.pdb_interpretation.ramachandran_plot_restraints.allowed = None params.pdb_interpretation.ramachandran_plot_restraints.outlier = "oldfield" model.set_pdb_interpretation_params(params) model.process_input_model(make_restraints=True) grm = model.get_restraints_manager().geometry nprox = grm.ramachandran_manager.get_n_proxies() # print "without allowed", nprox assert nprox == 167 no_all_proxies_iseqs = list( tuple(x.get_i_seqs()) for x in grm.ramachandran_manager._oldfield_proxies) sdif_list = sorted( list(set(full_proxies_iseqs) - set(no_all_proxies_iseqs))) allowed_txt_list = [ 'pdb=" N THR A 5 "', 'pdb=" N LEU B 4 "', 'pdb=" N SER B 38 "' ] # print "allowed" for a, answer in zip(sdif_list, allowed_txt_list): # print model.get_hierarchy().atoms()[a[1]].id_str() assert model.get_hierarchy().atoms()[a[1]].id_str() == answer params.pdb_interpretation.ramachandran_plot_restraints.favored = "oldfield" params.pdb_interpretation.ramachandran_plot_restraints.allowed = None params.pdb_interpretation.ramachandran_plot_restraints.outlier = None model = mmtbx.model.manager(model_input=pdb_inp, pdb_interpretation_params=params, log=null_out()) model.set_pdb_interpretation_params(params) model.process_input_model(make_restraints=True) grm = model.get_restraints_manager().geometry nprox = grm.ramachandran_manager.get_n_proxies() # print "without both", nprox assert nprox == 164 no_both_proxies_iseqs = list( tuple(x.get_i_seqs()) for x in grm.ramachandran_manager._oldfield_proxies) sdif_list = sorted( list(set(full_proxies_iseqs) - set(no_both_proxies_iseqs))) both_txt_list = [ 'pdb=" N THR A 5 "', 'pdb=" N LEU B 4 "', 'pdb=" N THR B 5 "', 'pdb=" N GLU B 6 "', 'pdb=" N SER B 38 "', 'pdb=" N SER B 81 "' ] # print "both" for a, answer in zip(sdif_list, both_txt_list): # print model.get_hierarchy().atoms()[a[1]].id_str() assert model.get_hierarchy().atoms()[a[1]].id_str() == answer
def run(args, params=None, out=sys.stdout, log=sys.stderr): # params keyword is for running program from GUI dialog if (((len(args) == 0) and (params is None)) or ((len(args) > 0) and ((args[0] == "-h") or (args[0] == "--help")))): show_usage() return # parse command-line arguments if (params is None): pcl = iotbx.phil.process_command_line_with_files( args=args, master_phil_string=master_phil_str, pdb_file_def="file_name") work_params = pcl.work.extract() # or use parameters defined by GUI else: work_params = params pdb_files = work_params.file_name work_params.secondary_structure.enabled = True assert work_params.format in [ "phenix", "phenix_refine", "phenix_bonds", "pymol", "refmac", "kinemage", "pdb", 'csv' ] if work_params.quiet: out = StringIO() pdb_combined = iotbx.pdb.combine_unique_pdb_files(file_names=pdb_files) pdb_structure = iotbx.pdb.input(source_info=None, lines=flex.std_string( pdb_combined.raw_records)) cs = pdb_structure.crystal_symmetry() corrupted_cs = False if cs is not None: if [cs.unit_cell(), cs.space_group()].count(None) > 0: corrupted_cs = True cs = None elif cs.unit_cell().volume() < 10: corrupted_cs = True cs = None if cs is None: if corrupted_cs: print("Symmetry information is corrupted, ", file=out) else: print("Symmetry information was not found, ", file=out) print("putting molecule in P1 box.", file=out) from cctbx import uctbx atoms = pdb_structure.atoms() box = uctbx.non_crystallographic_unit_cell_with_the_sites_in_its_center( sites_cart=atoms.extract_xyz(), buffer_layer=3) atoms.set_xyz(new_xyz=box.sites_cart) cs = box.crystal_symmetry() defpars = mmtbx.model.manager.get_default_pdb_interpretation_params() defpars.pdb_interpretation.automatic_linking.link_carbohydrates = False defpars.pdb_interpretation.c_beta_restraints = False defpars.pdb_interpretation.clash_guard.nonbonded_distance_threshold = None model = mmtbx.model.manager(model_input=pdb_structure, crystal_symmetry=cs, pdb_interpretation_params=defpars, stop_for_unknowns=False) pdb_hierarchy = model.get_hierarchy() geometry = None if pdb_hierarchy.contains_nucleic_acid(): model.process_input_model(make_restraints=True) geometry = model.get_restraints_manager().geometry if len(pdb_hierarchy.models()) != 1: raise Sorry("Multiple models not supported.") ss_from_file = None if (hasattr(pdb_structure, "extract_secondary_structure") and not work_params.ignore_annotation_in_file): ss_from_file = pdb_structure.extract_secondary_structure() m = manager(pdb_hierarchy=pdb_hierarchy, geometry_restraints_manager=geometry, sec_str_from_pdb_file=ss_from_file, params=work_params.secondary_structure, verbose=work_params.verbose) # bp_p = nucleic_acids.get_basepair_plane_proxies( # pdb_hierarchy, # m.params.secondary_structure.nucleic_acid.base_pair, # geometry) # st_p = nucleic_acids.get_stacking_proxies( # pdb_hierarchy, # m.params.secondary_structure.nucleic_acid.stacking_pair, # geometry) # hb_b, hb_a = nucleic_acids.get_basepair_hbond_proxies(pdb_hierarchy, # m.params.secondary_structure.nucleic_acid.base_pair) result_out = StringIO() # prefix_scope="refinement.pdb_interpretation" # prefix_scope="" prefix_scope = "" if work_params.format == "phenix_refine": prefix_scope = "refinement.pdb_interpretation" elif work_params.format == "phenix": prefix_scope = "pdb_interpretation" ss_phil = None working_phil = m.as_phil_str(master_phil=sec_str_master_phil) phil_diff = sec_str_master_phil.fetch_diff(source=working_phil) if work_params.format in ["phenix", "phenix_refine"]: comment = "\n".join([ "# These parameters are suitable for use in e.g. phenix.real_space_refine", "# or geometry_minimization. To use them in phenix.refine add ", "# 'refinement.' if front of pdb_interpretation." ]) if work_params.format == "phenix_refine": comment = "\n".join([ "# These parameters are suitable for use in phenix.refine only.", "# To use them in other Phenix tools remove ", "# 'refinement.' if front of pdb_interpretation." ]) print(comment, file=result_out) if (prefix_scope != ""): print("%s {" % prefix_scope, file=result_out) if work_params.show_all_params: working_phil.show(prefix=" ", out=result_out) else: phil_diff.show(prefix=" ", out=result_out) if (prefix_scope != ""): print("}", file=result_out) elif work_params.format == "pdb": print(m.actual_sec_str.as_pdb_str(), file=result_out) elif work_params.format == "phenix_bonds": raise Sorry("Not yet implemented.") elif work_params.format in ["pymol", "refmac", "kinemage", 'csv']: m.show_summary(log=out) model.process_input_model(make_restraints=True) (hb_proxies, hb_angle_proxies, planarity_proxies, parallelity_proxies) = m.create_all_new_restraints( pdb_hierarchy=pdb_hierarchy, grm=model.get_restraints_manager().geometry, log=out) if hb_proxies.size() > 0: if work_params.format == "pymol": file_load_add = "load %s" % work_params.file_name[0] # surprisingly, pymol handles filenames with whitespaces without quotes... print(file_load_add, file=result_out) bonds_in_format = hb_proxies.as_pymol_dashes( pdb_hierarchy=pdb_hierarchy) elif work_params.format == "kinemage": bonds_in_format = hb_proxies.as_kinemage( pdb_hierarchy=pdb_hierarchy) elif work_params.format == "csv": bonds_in_format = hb_proxies.as_csv( pdb_hierarchy=pdb_hierarchy) else: bonds_in_format = hb_proxies.as_refmac_restraints( pdb_hierarchy=pdb_hierarchy) print(bonds_in_format, file=result_out) if hb_angle_proxies.size() > 0: if work_params.format == "pymol": angles_in_format = hb_angle_proxies.as_pymol_dashes( pdb_hierarchy=pdb_hierarchy) print(angles_in_format, file=result_out) result = result_out.getvalue() out_prefix = os.path.basename(work_params.file_name[0]) if work_params.output_prefix is not None: out_prefix = work_params.output_prefix filename = "%s_ss.eff" % out_prefix if work_params.format == "pymol": filename = "%s_ss.pml" % out_prefix outf = open(filename, "w") outf.write(result) outf.close() print(result, file=out) return os.path.abspath(filename)
def stats(model, prefix, no_ticks=True): # Get rid of H, multi-model, no-protein and single-atom residue models if (model.percent_of_single_atom_residues() > 20): return None sel = model.selection(string="protein") if (sel.count(True) == 0): return None ssr = "protein and not (element H or element D or resname UNX or resname UNK or resname UNL)" sel = model.selection(string=ssr) model = model.select(sel) if (len(model.get_hierarchy().models()) > 1): return None # Add H; this looses CRYST1 ! rr = run_reduce_with_timeout( stdin_lines=model.get_hierarchy().as_pdb_string().splitlines(), file_name=None, parameters="-oh -his -flip -keep -allalt -pen9999 -", override_auto_timeout_with=None) # Create model; this is a single-model pure protein with new H added pdb_inp = iotbx.pdb.input(source_info=None, lines=rr.stdout_lines) model = mmtbx.model.manager( model_input=pdb_inp, #build_grm = True, #pdb_hierarchy = pdb_inp.construct_hierarchy(), #process_input = True, log=null_out()) if (model.crystal_symmetry() is None): box = uctbx.non_crystallographic_unit_cell_with_the_sites_in_its_center( sites_cart=model.get_sites_cart(), buffer_layer=5) model.set_sites_cart(box.sites_cart) model._crystal_symmetry = box.crystal_symmetry() model.process_input_model(make_restraints=True) # N = 10 # import cctbx.geometry_restraints.process_nonbonded_proxies as pnp h_bond_params = pnp.h_bond() h_bond_params.a_DHA_cutoff = 90 # SS = get_ss_selections(hierarchy=model.get_hierarchy()) HB_all = find(model=model.select(flex.bool(model.size(), True)), h_bond_params=h_bond_params).get_params_as_arrays( replace_with_empty_threshold=N) HB_alpha = find(model=model.select(SS.both.h_sel), h_bond_params=h_bond_params).get_params_as_arrays( replace_with_empty_threshold=N) HB_beta = find(model=model.select(SS.both.s_sel), h_bond_params=h_bond_params).get_params_as_arrays( replace_with_empty_threshold=N) print(HB_all.d_HA.size()) result_dict = {} result_dict["all"] = HB_all result_dict["alpha"] = HB_alpha result_dict["beta"] = HB_beta # result_dict["loop"] = get_selected(sel=loop_sel) # Load histograms for reference high-resolution d_HA and a_DHA pkl_fn = libtbx.env.find_in_repositories( relative_path="mmtbx") + "/nci/d_HA_and_a_DHA_high_res.pkl" assert os.path.isfile(pkl_fn) ref = easy_pickle.load(pkl_fn) # import matplotlib as mpl mpl.use('Agg') import matplotlib.pyplot as plt fig = plt.figure(figsize=(10, 10)) kwargs = dict(histtype='bar', bins=20, range=[1.6, 3.0], alpha=.8) for j, it in enumerate([["alpha", 1], ["beta", 3], ["all", 5]]): key, i = it ax = plt.subplot(int("32%d" % i)) if (no_ticks): #ax.set_xticks([]) ax.set_yticks([]) if (j in [0, 1]): ax.tick_params(bottom=False) ax.set_xticklabels([]) ax.tick_params(axis="x", labelsize=12) ax.tick_params(axis="y", labelsize=12, left=False, pad=-2) ax.text(0.98, 0.92, key, size=12, horizontalalignment='right', transform=ax.transAxes) HB = result_dict[key] if HB is None: continue w1 = np.ones_like(HB.d_HA) / HB.d_HA.size() ax.hist(HB.d_HA, color="orangered", weights=w1, rwidth=0.3, **kwargs) # start, end1, end2 = 0, max(ref.distances[key].vals), \ round(max(ref.distances[key].vals),2) if (not no_ticks): plt.yticks([0.01, end1], ["0", end2], visible=True, rotation="horizontal") if (key == "alpha"): plt.ylim(0, end2 + 0.02) elif (key == "beta"): plt.ylim(0, end2 + 0.02) elif (key == "all"): plt.ylim(0, end2 + 0.02) else: assert 0 # if (j == 0): ax.set_title("Distance", size=15) bins = list(flex.double(ref.distances[key].bins)) ax.bar(bins, ref.distances[key].vals, alpha=.3, width=0.07) # kwargs = dict(histtype='bar', bins=20, range=[90, 180], alpha=.8) for j, it in enumerate([["alpha", 2], ["beta", 4], ["all", 6]]): key, i = it ax = plt.subplot(int("32%d" % i)) if (j in [0, 1]): ax.tick_params(bottom=False) ax.set_xticklabels([]) if (no_ticks): #ax.set_xticks([]) ax.set_yticks([]) ax.tick_params(axis="x", labelsize=12) ax.tick_params(axis="y", labelsize=12, left=False, pad=-2) ax.text(0.98, 0.92, key, size=12, horizontalalignment='right', transform=ax.transAxes) ax.text(0.98, 0.92, key, size=12, horizontalalignment='right', transform=ax.transAxes) #if(j in [0,1]): ax.plot_params(bottom=False) HB = result_dict[key] if HB is None: continue w1 = np.ones_like(HB.a_DHA) / HB.a_DHA.size() ax.hist(HB.a_DHA, color="orangered", weights=w1, rwidth=0.3, **kwargs) # start, end1, end2 = 0, max(ref.angles[key].vals), \ round(max(ref.angles[key].vals),2) if (not no_ticks): plt.yticks([0.01, end1], ["0", end2], visible=True, rotation="horizontal") if (key == "alpha"): plt.ylim(0, end2 + 0.02) elif (key == "beta"): plt.ylim(0, end2 + 0.02) elif (key == "all"): plt.ylim(0, end2 + 0.02) else: assert 0 # if (j == 0): ax.set_title("Angle", size=15) ax.bar(ref.angles[key].bins, ref.angles[key].vals, width=4.5, alpha=.3) plt.subplots_adjust(wspace=0.12, hspace=0.025) if (no_ticks): plt.subplots_adjust(wspace=0.025, hspace=0.025) #fig.savefig("%s.png"%prefix, dpi=1000) fig.savefig("%s.pdf" % prefix)