def exercise_1(): processed_pdb_file = pdb_interpretation.process( mon_lib_srv = server.server(), ener_lib = server.ener_lib(), raw_records = flex.std_string(pdb_str_1.splitlines()), strict_conflict_handling = True, force_symmetry = True, log = None) grm = processed_pdb_file.geometry_restraints_manager() pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy sites_cart = pdb_hierarchy.atoms().extract_xyz() # c-beta restraints are added by default!!! assert len(grm.get_c_beta_torsion_proxies()) == 4 #test global selection and removing c-beta restraints tst_boolsel = pdb_hierarchy.atom_selection_cache().selection("resname TYR") tst_iselection = tst_boolsel.iselection() #test global selection grm2 = grm.select(iselection=tst_iselection) assert len(grm2.get_c_beta_torsion_proxies()) == 2 grm2 = grm.select(selection=tst_boolsel) assert len(grm2.get_c_beta_torsion_proxies()) == 2 #remove a selection grm.remove_c_beta_torsion_restraints_in_place(selection=tst_iselection) assert len(grm.get_c_beta_torsion_proxies()) == 2 #add a selection grm.remove_c_beta_torsion_restraints_in_place() assert len(grm.get_c_beta_torsion_proxies()) == 0 c_beta_torsion_proxies = c_beta.get_c_beta_torsion_proxies( pdb_hierarchy, selection=tst_iselection, sigma=2.5) assert len(c_beta_torsion_proxies) == 2
def run(): pdb_file_name = libtbx.env.find_in_repositories( relative_path="phenix_regression/pdb/adp_restraints.pdb", test=os.path.isfile) processed_pdb_file = pdb_interpretation.process( mon_lib_srv=monomer_library.server.server(), ener_lib=monomer_library.server.ener_lib(), file_name=pdb_file_name) xray_structure = processed_pdb_file.xray_structure() grm = processed_pdb_file.geometry_restraints_manager( plain_pairs_radius=5.0) grm.pair_proxies(sites_cart=xray_structure.sites_cart()) class parameters: sphere_radius = 1.6 distance_power = 0.0 average_power = 0.0 min_u_sum = 1.e-6 sel = flex.bool(xray_structure.scatterers().size(), True) xray_structure.scatterers().flags_set_grad_u_iso(sel.iselection()) for use_hd in [True, False]: energies_adp = cctbx.adp_restraints.energies_iso( geometry_restraints_manager=grm, xray_structure=xray_structure, use_hd=use_hd, use_u_local_only=False, parameters=parameters) u_iso_restraints = grm.harmonic_restraints( variables=xray_structure.extract_u_iso_or_u_equiv(), type_indices=None, type_weights=1.0) assert approx_equal(u_iso_restraints.residual_sum, energies_adp.residual_sum) assert approx_equal(u_iso_restraints.gradients, energies_adp.gradients)
def test_solvent_model(): # correct values p = pdb.input(source_info='string',lines=test_pdb) sr = p.xray_structure_simple().scattering_type_registry() # test values p1 = pdb.input(source_info='string',lines=test_pdb) mls = server.server() el = server.ener_lib() ip = pdb_interpretation.process(mon_lib_srv=mls,ener_lib=el,pdb_inp=p1) sg = structure_generator() sg.add_species(p,1) sm = solvent_model() sm.interpreted_pdb = ip sm.xyz = sg.species[0].xyz new_sr = sm.add_bulk_solvent(sr) assert(new_sr.sum_of_scattering_factors_at_diffraction_angle_0() < sr.sum_of_scattering_factors_at_diffraction_angle_0()) sm.bulk_solvent_scale = 0.0 new_sr = sm.add_bulk_solvent(sr) assert(approx_equal(sr.sum_of_scattering_factors_at_diffraction_angle_0(), new_sr.sum_of_scattering_factors_at_diffraction_angle_0())) sm.boundary_layer_scale = 0.0 new_sr = sm.add_boundary_layer_solvent(new_sr) assert(approx_equal(sr.sum_of_scattering_factors_at_diffraction_angle_0(), new_sr.sum_of_scattering_factors_at_diffraction_angle_0())) sm.boundary_layer_scale = 0.6 new_sr = sm.add_boundary_layer_solvent(new_sr) assert(new_sr.sum_of_scattering_factors_at_diffraction_angle_0() > sr.sum_of_scattering_factors_at_diffraction_angle_0())
def run (args, out=sys.stdout, quiet=False) : from mmtbx.monomer_library import pdb_interpretation from mmtbx.monomer_library import server import iotbx.pdb cmdline = iotbx.phil.process_command_line_with_files( args=args, master_phil=get_master_phil(), pdb_file_def="model", usage_string=usage_string) params = cmdline.work.extract() if (params.model is None) : raise Usage(usage_string) pdb_in = iotbx.pdb.input(source_info=params.model, file_name=params.model) mon_lib_srv = server.server() ener_lib = server.ener_lib() processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, pdb_inp=pdb_in, substitute_non_crystallographic_unit_cell_if_necessary=True) pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy geometry = processed_pdb_file.geometry_restraints_manager() result = rna_validation( pdb_hierarchy=pdb_hierarchy, geometry_restraints_manager=geometry, params=params, outliers_only=params.outliers_only) result.show(out=out) return result
def run(): pdb_file_name = libtbx.env.find_in_repositories( relative_path="phenix_regression/pdb/adp_restraints.pdb", test=os.path.isfile) processed_pdb_file = pdb_interpretation.process( mon_lib_srv = monomer_library.server.server(), ener_lib = monomer_library.server.ener_lib(), file_name = pdb_file_name) xray_structure = processed_pdb_file.xray_structure() grm = processed_pdb_file.geometry_restraints_manager( plain_pairs_radius = 5.0) grm.pair_proxies(sites_cart=xray_structure.sites_cart()) class parameters: sphere_radius = 1.6 distance_power = 0.0 average_power = 0.0 min_u_sum = 1.e-6 sel = flex.bool(xray_structure.scatterers().size(), True) xray_structure.scatterers().flags_set_grad_u_iso(sel.iselection()) for use_hd in [True, False]: energies_adp = cctbx.adp_restraints.energies_iso( geometry_restraints_manager=grm, xray_structure=xray_structure, use_hd = use_hd, use_u_local_only = False, parameters=parameters) u_iso_restraints = grm.harmonic_restraints( variables = xray_structure.extract_u_iso_or_u_equiv(), type_indices = None, type_weights = 1.0) assert approx_equal(u_iso_restraints.residual_sum, energies_adp.residual_sum) assert approx_equal(u_iso_restraints.gradients, energies_adp.gradients)
def run(pdb_file, cif_file): from mmtbx.monomer_library import server import iotbx from mmtbx.monomer_library import pdb_interpretation pdb_inp = iotbx.pdb.input(file_name=pdb_file) pdb_hierarchy = pdb_inp.construct_hierarchy() raw_lines = pdb_hierarchy.as_pdb_string( crystal_symmetry=pdb_inp.crystal_symmetry()) f=file(cif_file, "rb") ligand_cif = f.read() f.close() cif_object = iotbx.cif.model.cif() iotbx.cif.reader(input_string=ligand_cif, cif_object=cif_object, strict=False) mon_lib_srv = server.server() ener_lib = server.ener_lib() for srv in [mon_lib_srv, ener_lib]: srv.process_cif_object(cif_object=cif_object, file_name="LIGAND") processed_pdb = pdb_interpretation.process( mon_lib_srv, ener_lib, raw_records=raw_lines) geometry_restraints_manager = processed_pdb.geometry_restraints_manager()
def run(args, out=sys.stdout, quiet=False): from mmtbx.monomer_library import pdb_interpretation from mmtbx.monomer_library import server import iotbx.pdb cmdline = iotbx.phil.process_command_line_with_files( args=args, master_phil=get_master_phil(), pdb_file_def="model", usage_string=usage_string) params = cmdline.work.extract() if (params.model is None): raise Usage(usage_string) pdb_in = iotbx.pdb.input(source_info=params.model, file_name=params.model) mon_lib_srv = server.server() ener_lib = server.ener_lib() processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, pdb_inp=pdb_in, substitute_non_crystallographic_unit_cell_if_necessary=True) pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy geometry = processed_pdb_file.geometry_restraints_manager() result = rna_validation( pdb_hierarchy=pdb_hierarchy, geometry_restraints_manager=geometry, params=params, outliers_only=params.outliers_only) result.show(out=out) return result
def run(args, command_name=libtbx.env.dispatcher_name): parser = argparse.ArgumentParser( prog=command_name, usage='%s pdb_file "atom_selection" [...]' % command_name) parser.add_argument("file_name", nargs=1, help="File name of the model file") parser.add_argument( "inselections", help="Atom selection strings", nargs='+', ) parser.add_argument("--write-pdb-file", action="store", help="write selected atoms to new PDB file", default=None) parser.add_argument( "--cryst1-replacement-buffer-layer", action="store", type=float, help="replace CRYST1 with pseudo unit cell covering the selected" " atoms plus a surrounding buffer layer", default=None) co = parser.parse_args(args) mon_lib_srv = server.server() ener_lib = server.ener_lib() processed_pdb_file = pdb_interpretation.process(mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, file_name=co.file_name[0], log=sys.stdout) print acp = processed_pdb_file.all_chain_proxies selection_cache = acp.pdb_hierarchy.atom_selection_cache() atoms = acp.pdb_atoms all_bsel = flex.bool(atoms.size(), False) for selection_string in co.inselections: print selection_string isel = acp.iselection(string=selection_string, cache=selection_cache) all_bsel.set_selected(isel, True) if (not co.write_pdb_file): print " %d atom%s selected" % plural_s(isel.size()) for atom in atoms.select(isel): print " %s" % atom.format_atom_record() print if (co.write_pdb_file): print "Writing file:", show_string(co.write_pdb_file) sel_hierarchy = acp.pdb_hierarchy.select(all_bsel) if (co.cryst1_replacement_buffer_layer is None): crystal_symmetry = acp.special_position_settings else: import cctbx.crystal crystal_symmetry = cctbx.crystal.non_crystallographic_symmetry( sites_cart=sel_hierarchy.atoms().extract_xyz(), buffer_layer=co.cryst1_replacement_buffer_layer) write_whole_pdb_file(file_name=co.write_pdb_file, processed_pdb_file=processed_pdb_file, pdb_hierarchy=sel_hierarchy, crystal_symmetry=crystal_symmetry) print
def exercise_1(mon_lib_srv, ener_lib): f = open("1.pdb", "w") f.write(pdb_str_1) f.close() log = cStringIO.StringIO() dihedral_proxies = utils.get_complete_dihedral_proxies( raw_records=pdb_str_1) assert len(dihedral_proxies) == 54, \ "Expected 54, got %d" % len(dihedral_proxies) # default run (1 residue is out of NCS) params = pdb_interpretation.master_params.extract() params.ncs_search.enabled=True ppf = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, params=params, raw_records=flex.split_lines(pdb_str_1)) ncs_manager = torsion_ncs.torsion_ncs( processed_pdb_file=ppf, ncs_obj=ppf.ncs_obj, log=log) nprox = ncs_manager.get_n_proxies() assert nprox == 28, "got %d instead of 28" % nprox # supply full NCS cuspars = iotbx.phil.parse(""" ncs_search.enabled=True ncs_group { reference = (chain A ) selection = (chain B ) } """) params = pdb_interpretation.master_params p = params.fetch(cuspars).extract() ppf = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, params=p, raw_records=flex.split_lines(pdb_str_1)) ncs_manager = torsion_ncs.torsion_ncs( processed_pdb_file=ppf, ncs_obj=ppf.ncs_obj, log=log) nprox = ncs_manager.get_n_proxies() assert nprox == 40, "got %d instead of 40" % nprox
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 = pdb_interpretation.master_params.fetch().extract() params.peptide_link.ramachandran_restraints = True processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, params=params, file_name=file_name, log=StringIO()) grm = processed_pdb_file.geometry_restraints_manager() # print grm.ramachandran_manager.get_n_proxies() # 47 is wrong here # simple selection params = pdb_interpretation.master_params.fetch().extract() params.peptide_link.ramachandran_restraints = True params.peptide_link.rama_selection = "chain A and resid 1:7" processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, params=params, file_name=file_name, log=StringIO()) grm = processed_pdb_file.geometry_restraints_manager() 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 params = pdb_interpretation.master_params.fetch().extract() params.peptide_link.ramachandran_restraints = True params.peptide_link.rama_selection = "chain A and resid 27:28" processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, params=params, file_name=file_name, log=StringIO()) grm = processed_pdb_file.geometry_restraints_manager()
def exercise_lbfgs_simple (mon_lib_srv, ener_lib, verbose=False) : # three peptides: # 1 = poly-ALA, favored # 2 = poly-ALA, outlier # 3 = poly-TRP, outlier # # Note that the ramalyze score for the first actually gets slightly worse, # but it's still good and we're starting from an excellent score anyway. # # residuals = [0.00024512, 307.616444, 294.913714] residuals = [0.00168766995882, 186.24718562, 177.259069807] for i, peptide in enumerate([pdb1, pdb2, pdb3]) : pdb_in = iotbx.pdb.input(source_info="peptide", lines=flex.split_lines(peptide)) params = pdb_interpretation.master_params.extract() processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, params=params, pdb_inp=pdb_in, log=StringIO()) log = StringIO() pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy atoms = pdb_hierarchy.atoms() sites_cart_1 = atoms.extract_xyz().deep_copy() gradients_fd = flex.vec3_double(sites_cart_1.size(), (0,0,0)) gradients_an = flex.vec3_double(sites_cart_1.size(), (0,0,0)) params = ramachandran.master_phil.fetch().extract() rama_manager = ramachandran.ramachandran_manager( pdb_hierarchy, None, params, log) assert rama_manager.get_n_proxies() == 1 residual_an = rama_manager.target_and_gradients( unit_cell=None, sites_cart=sites_cart_1, gradient_array=gradients_an) # print "comparing", residual_an assert approx_equal(residual_an, residuals[i], eps=0.00001) if verbose : print "" for i, peptide in enumerate([pdb1, pdb2, pdb3]) : pdb_in = iotbx.pdb.input(source_info="peptide", lines=flex.split_lines(peptide)) o = benchmark_structure(pdb_in, mon_lib_srv, ener_lib, verbose) phi0, psi0 = o.r0.results[0].phi, o.r0.results[0].psi phi1, psi1 = o.r1.results[0].phi, o.r1.results[0].psi phi2, psi2 = o.r2.results[0].phi, o.r2.results[0].psi r0 = o.r0.results[0].score r1 = o.r1.results[0].score r2 = o.r2.results[0].score if verbose : print "peptide %d" % (i+1) print " before: rmsd_bonds=%-6.4f rmsd_angles=%-6.3f" % (o.b0,o.a0) print " phi=%-6.1f psi=%-6.1f score=%-.2f" % (phi0, psi0, r0) print " simple: rmsd_bonds=%-6.4f rmsd_angles=%-6.3f" % (o.b1,o.a1) print " phi=%-6.1f psi=%-6.1f score=%-.2f" % (phi1, psi1, r1) print " + Rama: rmsd_bonds=%-6.4f rmsd_angles=%-6.3f" % (o.b2,o.a2) print " phi=%-6.1f psi=%-6.1f score=%-.2f" % (phi2, psi2, r2) print ""
def exercise_3(): pdb_raw = """\ ATOM 1 CA GLY A 1 -0.227 9.888 -15.197 1.00 54.04 C ATOM 2 CA GLY A 2 -0.227 9.888 -15.197 1.00 54.04 C ATOM 3 CA GLY A 3 -0.227 9.888 -15.197 1.00 54.04 C ATOM 4 CA GLY A 4 -0.227 9.888 -15.197 1.00 54.04 C ATOM 5 CA GLY A 5 -0.227 9.888 -15.197 1.00 54.04 C ATOM 6 CA GLY A 6 -0.227 9.888 -15.197 1.00 54.04 C ATOM 7 CA GLY A 7 -0.227 9.888 -15.197 1.00 54.04 C ATOM 8 CA GLY A 8 -0.227 9.888 -15.197 1.00 54.04 C ATOM 9 CA GLY A 9 -0.227 9.888 -15.197 1.00 54.04 C ATOM 10 CA GLY A 10 -0.227 9.888 -15.197 1.00 54.04 C HETATM 11 N SEP A 11 -2.112 0.368 -0.991 1.00 20.00 A N HETATM 12 CA SEP A 11 -0.692 0.284 -0.951 1.00 20.00 A C HETATM 13 CB SEP A 11 -0.234 0.166 0.485 1.00 20.00 A C HETATM 14 OG SEP A 11 1.130 -0.184 0.515 1.00 20.00 A O HETATM 15 C SEP A 11 -0.237 -0.930 -1.727 1.00 20.00 A C HETATM 16 O SEP A 11 -0.767 -2.051 -1.509 1.00 20.00 A O HETATM 18 P SEP A 11 1.922 -0.008 1.871 1.00 20.00 A P HETATM 19 O1P SEP A 11 2.139 1.462 2.140 1.00 20.00 A O HETATM 20 O2P SEP A 11 3.259 -0.703 1.767 1.00 20.00 A O-1 HETATM 21 O3P SEP A 11 1.127 -0.614 3.002 1.00 20.00 A O-1 END""" mon_lib_srv = server.server() ener_lib = server.ener_lib() pdb_in = iotbx.pdb.hierarchy.input(pdb_string=pdb_raw) xrs = pdb_in.input.xray_structure_simple() processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, raw_records=pdb_in.hierarchy.as_pdb_string(crystal_symmetry=xrs), crystal_symmetry=xrs, log=null_out()) pdb_in.hierarchy.atoms().reset_i_seq() ligand_sel = pdb_in.hierarchy.atom_selection_cache().selection( "resname SEP") mstats = model_properties.model_statistics( pdb_hierarchy=pdb_in.hierarchy, xray_structure=xrs, all_chain_proxies=processed_pdb_file.all_chain_proxies, ligand_selection=ligand_sel, ignore_hd=True) out = StringIO() mstats.show(out=out) assert (mstats.n_protein == 10) assert ("Ligands:" in out.getvalue()) assert approx_equal(mstats.macromolecules.b_mean, 54.04) # now with just the raw selection string mstats = model_properties.model_statistics( pdb_hierarchy=pdb_in.hierarchy, xray_structure=xrs, all_chain_proxies=processed_pdb_file.all_chain_proxies, ligand_selection="resname SEP", ignore_hd=True) out = StringIO() mstats.show(out=out) assert (mstats.n_protein == 10) assert ("Ligands:" in out.getvalue())
def run(args, residue_type, expected_results): verbose = "--verbose" in args debug = "--debug" in args pdb_files = libtbx.env.find_in_repositories( relative_path="phenix_regression/%s_pdb_files" % residue_type, test=os.path.isdir) if (pdb_files is None): print "Skipping tst_%s_interpretation: input files not available" \ % residue_type return mon_lib_srv = server.server() ener_lib = server.ener_lib() for file_name in os.listdir(pdb_files): if (file_name[-4:] not in [".ent", ".pdb"]): continue if (verbose): log = sys.stdout else: log = null_out() processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, file_name=os.path.join(pdb_files, file_name), log=log) for mm in processed_pdb_file.all_chain_proxies.all_monomer_mappings: residue_name = mm.residue_name if (mm.classification == "RNA"): for c in ["2", "3"]: expected_mod = "%rna" + c + "p_pur" if (mm.residue_name.find(expected_mod) > 0): residue_name = mm.residue_name.replace( expected_mod, "") break expected_mod = "%rna" + c + "p_pyr" if (mm.residue_name.find(expected_mod) > 0): residue_name = mm.residue_name.replace( expected_mod, "") break assert len(mm.duplicate_atoms) == 0 assert len(mm.ignored_atoms) == 0 assert not mm.is_unusual unexpected_names = [atom.name for atom in mm.unexpected_atoms] result = [ residue_name, len(mm.expected_atoms), unexpected_names, mm.classification, mm.is_terminus, mm.incomplete_info ] key = file_name[:-4] if (debug): print '"%s":' % key print " ", str(result) + "," print " ", str(expected_results[key]) + "," if (expected_results is not None): assert result == expected_results[key], "%s not %s" % ( result, expected_results[key], ) print "OK"
def run(args, residue_type, expected_results): verbose = "--verbose" in args debug = "--debug" in args pdb_files = libtbx.env.find_in_repositories( relative_path="phenix_regression/%s_pdb_files" % residue_type, test=os.path.isdir) if (pdb_files is None): print "Skipping tst_%s_interpretation: input files not available" \ % residue_type return mon_lib_srv = server.server() ener_lib = server.ener_lib() for file_name in os.listdir(pdb_files): if (file_name[-4:] not in [".ent", ".pdb"]): continue if (verbose): log = sys.stdout else: log = null_out() processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, file_name=os.path.join(pdb_files, file_name), log=log) for mm in processed_pdb_file.all_chain_proxies.all_monomer_mappings: residue_name = mm.residue_name if (mm.classification == "RNA"): for c in ["2", "3"]: expected_mod = "%rna"+c+"p_pur" if (mm.residue_name.find(expected_mod) > 0): residue_name = mm.residue_name.replace(expected_mod, "") break expected_mod = "%rna"+c+"p_pyr" if (mm.residue_name.find(expected_mod) > 0): residue_name = mm.residue_name.replace(expected_mod, "") break assert len(mm.duplicate_atoms) == 0 assert len(mm.ignored_atoms) == 0 assert not mm.is_unusual unexpected_names = [atom.name for atom in mm.unexpected_atoms] result = [ residue_name, len(mm.expected_atoms), unexpected_names, mm.classification, mm.is_terminus, mm.incomplete_info] key = file_name[:-4] if (debug): print '"%s":' % key print " ", str(result)+"," print " ", str(expected_results[key])+"," if (expected_results is not None): assert result == expected_results[key], "%s not %s" % ( result, expected_results[key], ) print "OK"
def exercise_3 () : pdb_raw = """\ ATOM 1 CA GLY A 1 -0.227 9.888 -15.197 1.00 54.04 C ATOM 2 CA GLY A 2 -0.227 9.888 -15.197 1.00 54.04 C ATOM 3 CA GLY A 3 -0.227 9.888 -15.197 1.00 54.04 C ATOM 4 CA GLY A 4 -0.227 9.888 -15.197 1.00 54.04 C ATOM 5 CA GLY A 5 -0.227 9.888 -15.197 1.00 54.04 C ATOM 6 CA GLY A 6 -0.227 9.888 -15.197 1.00 54.04 C ATOM 7 CA GLY A 7 -0.227 9.888 -15.197 1.00 54.04 C ATOM 8 CA GLY A 8 -0.227 9.888 -15.197 1.00 54.04 C ATOM 9 CA GLY A 9 -0.227 9.888 -15.197 1.00 54.04 C ATOM 10 CA GLY A 10 -0.227 9.888 -15.197 1.00 54.04 C HETATM 11 N SEP A 11 -2.112 0.368 -0.991 1.00 20.00 A N HETATM 12 CA SEP A 11 -0.692 0.284 -0.951 1.00 20.00 A C HETATM 13 CB SEP A 11 -0.234 0.166 0.485 1.00 20.00 A C HETATM 14 OG SEP A 11 1.130 -0.184 0.515 1.00 20.00 A O HETATM 15 C SEP A 11 -0.237 -0.930 -1.727 1.00 20.00 A C HETATM 16 O SEP A 11 -0.767 -2.051 -1.509 1.00 20.00 A O HETATM 18 P SEP A 11 1.922 -0.008 1.871 1.00 20.00 A P HETATM 19 O1P SEP A 11 2.139 1.462 2.140 1.00 20.00 A O HETATM 20 O2P SEP A 11 3.259 -0.703 1.767 1.00 20.00 A O-1 HETATM 21 O3P SEP A 11 1.127 -0.614 3.002 1.00 20.00 A O-1 END""" mon_lib_srv = server.server() ener_lib = server.ener_lib() pdb_in = iotbx.pdb.hierarchy.input(pdb_string=pdb_raw) xrs = pdb_in.input.xray_structure_simple() processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, raw_records=pdb_in.hierarchy.as_pdb_string(crystal_symmetry=xrs), crystal_symmetry=xrs, log=null_out()) pdb_in.hierarchy.atoms().reset_i_seq() ligand_sel = pdb_in.hierarchy.atom_selection_cache().selection("resname SEP") mstats = model_properties.model_statistics( pdb_hierarchy=pdb_in.hierarchy, xray_structure=xrs, all_chain_proxies=processed_pdb_file.all_chain_proxies, ligand_selection=ligand_sel, ignore_hd=True) out = StringIO() mstats.show(out=out) assert (mstats.n_protein == 10) assert ("Ligands:" in out.getvalue()) assert approx_equal(mstats.macromolecules.b_mean, 54.04) # now with just the raw selection string mstats = model_properties.model_statistics( pdb_hierarchy=pdb_in.hierarchy, xray_structure=xrs, all_chain_proxies=processed_pdb_file.all_chain_proxies, ligand_selection="resname SEP", ignore_hd=True) out = StringIO() mstats.show(out=out) assert (mstats.n_protein == 10) assert ("Ligands:" in out.getvalue())
def benchmark_structure (pdb_in, mon_lib_srv, ener_lib, verbose=False, w=1.0) : params = pdb_interpretation.master_params.extract() processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, params=params, pdb_inp=pdb_in, log=StringIO()) log = StringIO() pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy r0 = ramalyze(pdb_hierarchy=pdb_hierarchy, outliers_only=False) atoms = pdb_hierarchy.atoms() sites_cart_1 = atoms.extract_xyz().deep_copy() sites_cart_2 = sites_cart_1.deep_copy() grm = processed_pdb_file.geometry_restraints_manager() assert (grm is not None) e = grm.energies_sites(sites_cart=sites_cart_1) b0 = e.bond_deviations()[-1] a0 = e.angle_deviations()[-1] flags = cctbx.geometry_restraints.flags.flags(default=True) lbfgs = geometry_minimization.lbfgs( sites_cart=sites_cart_1, correct_special_position_tolerance=1.0, geometry_restraints_manager=grm, geometry_restraints_flags=flags, lbfgs_termination_params=scitbx.lbfgs.termination_parameters( max_iterations=500)) a1 = lbfgs.rmsd_angles b1 = lbfgs.rmsd_bonds atoms.set_xyz(sites_cart_1) r1 = ramalyze(pdb_hierarchy=pdb_hierarchy, outliers_only=False) rama_params = ramachandran.master_phil.fetch().extract() rama_manager = ramachandran.ramachandran_manager( pdb_hierarchy, None, rama_params, log) grm.set_ramachandran_restraints(rama_manager) lbfgs = geometry_minimization.lbfgs( sites_cart=sites_cart_2, correct_special_position_tolerance=1.0, geometry_restraints_manager=grm, geometry_restraints_flags=flags, lbfgs_termination_params=scitbx.lbfgs.termination_parameters( max_iterations=500)) a2 = lbfgs.rmsd_angles b2 = lbfgs.rmsd_bonds atoms.set_xyz(sites_cart_2) r2 = ramalyze(pdb_hierarchy=pdb_hierarchy, outliers_only=False) return group_args( a0=a0, a1=a1, a2=a2, b0=b0, b1=b1, b2=b2, r0=r0, r1=r1, r2=r2)
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 = pdb_interpretation.master_params.fetch().extract() params.peptide_link.ramachandran_restraints = True processed_pdb_file = pdb_interpretation.process(mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, params=params, file_name=file_name, log=StringIO()) grm = processed_pdb_file.geometry_restraints_manager() # print grm.ramachandran_manager.get_n_proxies() # 47 is wrong here # simple selection params = pdb_interpretation.master_params.fetch().extract() params.peptide_link.ramachandran_restraints = True params.peptide_link.rama_selection = "chain A and resid 1:7" processed_pdb_file = pdb_interpretation.process(mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, params=params, file_name=file_name, log=StringIO()) grm = processed_pdb_file.geometry_restraints_manager() 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 params = pdb_interpretation.master_params.fetch().extract() params.peptide_link.ramachandran_restraints = True params.peptide_link.rama_selection = "chain A and resid 27:28" processed_pdb_file = pdb_interpretation.process(mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, params=params, file_name=file_name, log=StringIO()) grm = processed_pdb_file.geometry_restraints_manager()
def exercise_1(mon_lib_srv, ener_lib): f = open("1.pdb", "w") f.write(pdb_str_1) f.close() log = cStringIO.StringIO() dihedral_proxies = utils.get_complete_dihedral_proxies( raw_records=pdb_str_1) assert len(dihedral_proxies) == 54, \ "Expected 54, got %d" % len(dihedral_proxies) # default run (1 residue is out of NCS) params = pdb_interpretation.master_params.extract() params.ncs_search.enabled = True ppf = pdb_interpretation.process(mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, params=params, raw_records=flex.split_lines(pdb_str_1)) ncs_manager = torsion_ncs.torsion_ncs(processed_pdb_file=ppf, ncs_obj=ppf.ncs_obj, log=log) nprox = ncs_manager.get_n_proxies() assert nprox == 28, "got %d instead of 28" % nprox # supply full NCS cuspars = iotbx.phil.parse(""" ncs_search.enabled=True ncs_group { reference = (chain A ) selection = (chain B ) } """) params = pdb_interpretation.master_params p = params.fetch(cuspars).extract() ppf = pdb_interpretation.process(mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, params=p, raw_records=flex.split_lines(pdb_str_1)) ncs_manager = torsion_ncs.torsion_ncs(processed_pdb_file=ppf, ncs_obj=ppf.ncs_obj, log=log) nprox = ncs_manager.get_n_proxies() assert nprox == 40, "got %d instead of 40" % nprox
def get_rna_pucker_ref(self, test_pucker=False): flags = geometry_restraints.flags.flags(default=True) mon_lib_srv = monomer_library.server.server() ener_lib = monomer_library.server.ener_lib() self.bond_dict = {} self.angle_dict = {} self.processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, file_name=None, raw_records=self.sample_bases) self.geometry = self.processed_pdb_file.geometry_restraints_manager() #confirm puckers are correct if test_pucker: r = rna_validate() r.pucker_evaluate(hierarchy=self.processed_pdb_file. all_chain_proxies.pdb_hierarchy) assert not r.pucker_states[0].is_2p assert r.pucker_states[1].is_2p i_seq_name_hash = utils.build_name_hash( pdb_hierarchy=self.processed_pdb_file.all_chain_proxies. pdb_hierarchy) pair_proxies = self.geometry.pair_proxies( flags=flags, sites_cart=self.processed_pdb_file.all_chain_proxies.sites_cart) bond_proxies = pair_proxies.bond_proxies for bond in bond_proxies.simple: atom1 = i_seq_name_hash[bond.i_seqs[0]][0:4] atom2 = i_seq_name_hash[bond.i_seqs[1]][0:4] if (atom1.strip() not in self.rna_backbone_atoms and atom2.strip() not in self.rna_backbone_atoms): continue key = atom1 + atom2 sigma = (1 / bond.weight)**(.5) try: self.bond_dict[key].append((bond.distance_ideal, sigma)) except Exception: self.bond_dict[key] = [] self.bond_dict[key].append((bond.distance_ideal, sigma)) for angle in self.geometry.angle_proxies: atom1 = i_seq_name_hash[angle.i_seqs[0]][0:4] atom2 = i_seq_name_hash[angle.i_seqs[1]][0:4] atom3 = i_seq_name_hash[angle.i_seqs[2]][0:4] if (atom1.strip() not in self.rna_backbone_atoms and atom2.strip() not in self.rna_backbone_atoms and atom3.strip() not in self.rna_backbone_atoms): continue key = atom1 + atom2 + atom3 sigma = (1 / angle.weight)**(.5) try: self.angle_dict[key].append((angle.angle_ideal, sigma)) except Exception: self.angle_dict[key] = [] self.angle_dict[key].append((angle.angle_ideal, sigma))
def benchmark_structure(pdb_in, mon_lib_srv, ener_lib, verbose=False, w=1.0): params = pdb_interpretation.master_params.extract() processed_pdb_file = pdb_interpretation.process(mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, params=params, pdb_inp=pdb_in, log=StringIO()) log = StringIO() pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy r0 = ramalyze(pdb_hierarchy=pdb_hierarchy, outliers_only=False) atoms = pdb_hierarchy.atoms() sites_cart_1 = atoms.extract_xyz().deep_copy() sites_cart_2 = sites_cart_1.deep_copy() grm = processed_pdb_file.geometry_restraints_manager() assert (grm is not None) e = grm.energies_sites(sites_cart=sites_cart_1) b0 = e.bond_deviations()[-1] a0 = e.angle_deviations()[-1] flags = cctbx.geometry_restraints.flags.flags(default=True) lbfgs = geometry_minimization.lbfgs( sites_cart=sites_cart_1, correct_special_position_tolerance=1.0, geometry_restraints_manager=grm, geometry_restraints_flags=flags, lbfgs_termination_params=scitbx.lbfgs.termination_parameters( max_iterations=500)) a1 = lbfgs.rmsd_angles b1 = lbfgs.rmsd_bonds atoms.set_xyz(sites_cart_1) r1 = ramalyze(pdb_hierarchy=pdb_hierarchy, outliers_only=False) rama_params = ramachandran.master_phil.fetch().extract() rama_manager = ramachandran.ramachandran_manager(pdb_hierarchy, None, rama_params, log) grm.set_ramachandran_restraints(rama_manager) lbfgs = geometry_minimization.lbfgs( sites_cart=sites_cart_2, correct_special_position_tolerance=1.0, geometry_restraints_manager=grm, geometry_restraints_flags=flags, lbfgs_termination_params=scitbx.lbfgs.termination_parameters( max_iterations=500)) a2 = lbfgs.rmsd_angles b2 = lbfgs.rmsd_bonds atoms.set_xyz(sites_cart_2) r2 = ramalyze(pdb_hierarchy=pdb_hierarchy, outliers_only=False) return group_args(a0=a0, a1=a1, a2=a2, b0=b0, b1=b1, b2=b2, r0=r0, r1=r1, r2=r2)
def get_rna_pucker_ref(self, test_pucker=False): flags = geometry_restraints.flags.flags(default=True) mon_lib_srv = monomer_library.server.server() ener_lib = monomer_library.server.ener_lib() self.bond_dict = {} self.angle_dict = {} self.processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, file_name=None, raw_records=self.sample_bases) self.geometry = self.processed_pdb_file.geometry_restraints_manager() #confirm puckers are correct if test_pucker: r = rna_validate() r.pucker_evaluate( hierarchy=self.processed_pdb_file.all_chain_proxies.pdb_hierarchy) assert not r.pucker_states[0].is_2p assert r.pucker_states[1].is_2p i_seq_name_hash = utils.build_name_hash( pdb_hierarchy=self.processed_pdb_file.all_chain_proxies.pdb_hierarchy) pair_proxies = self.geometry.pair_proxies( flags=flags, sites_cart=self.processed_pdb_file.all_chain_proxies.sites_cart) bond_proxies = pair_proxies.bond_proxies for bond in bond_proxies.simple: atom1 = i_seq_name_hash[bond.i_seqs[0]][0:4] atom2 = i_seq_name_hash[bond.i_seqs[1]][0:4] if (atom1.strip() not in self.rna_backbone_atoms and atom2.strip() not in self.rna_backbone_atoms): continue key = atom1+atom2 sigma = (1/bond.weight)**(.5) try: self.bond_dict[key].append((bond.distance_ideal, sigma)) except Exception: self.bond_dict[key] = [] self.bond_dict[key].append((bond.distance_ideal, sigma)) for angle in self.geometry.angle_proxies: atom1 = i_seq_name_hash[angle.i_seqs[0]][0:4] atom2 = i_seq_name_hash[angle.i_seqs[1]][0:4] atom3 = i_seq_name_hash[angle.i_seqs[2]][0:4] if (atom1.strip() not in self.rna_backbone_atoms and atom2.strip() not in self.rna_backbone_atoms and atom3.strip() not in self.rna_backbone_atoms): continue key = atom1+atom2+atom3 sigma = (1/angle.weight)**(.5) try: self.angle_dict[key].append((angle.angle_ideal, sigma)) except Exception: self.angle_dict[key] = [] self.angle_dict[key].append((angle.angle_ideal, sigma))
def read_dummy_type(file_name=None, pdb_inp=None): assert ((file_name is not None) or (pdb_inp is not None)) mon_lib_srv = server.server() ener_lib = server.ener_lib() if (pdb_inp is None): tmp_obj = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, file_name=file_name).all_chain_proxies else: tmp_obj = pdb_interpretation.process(mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, pdb_inp=pdb_inp).all_chain_proxies ats = tmp_obj.nonbonded_energy_type_registry.symbols els = tmp_obj.scattering_type_registry.symbols for i in range(ats.size()): if ats[i] == "": ats[i] = els[i] return ats
def reprocess_pdb (pdb_hierarchy, crystal_symmetry, cif_objects, out) : from mmtbx.monomer_library import pdb_interpretation from mmtbx.monomer_library import server mon_lib_srv = server.server() ener_lib = server.ener_lib() for cif_object in cif_objects : for srv in [mon_lib_srv, ener_lib]: srv.process_cif_object(cif_object=cif_object) return pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, raw_records=pdb_hierarchy.as_pdb_string(crystal_symmetry=crystal_symmetry), crystal_symmetry=crystal_symmetry, log=out)
def reprocess_pdb(pdb_hierarchy, crystal_symmetry, cif_objects, out): from mmtbx.monomer_library import pdb_interpretation from mmtbx.monomer_library import server mon_lib_srv = server.server() ener_lib = server.ener_lib() for cif_object in cif_objects: for srv in [mon_lib_srv, ener_lib]: srv.process_cif_object(cif_object=cif_object) return pdb_interpretation.process(mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, raw_records=pdb_hierarchy.as_pdb_string( crystal_symmetry=crystal_symmetry), crystal_symmetry=crystal_symmetry, log=out)
def exercise_1(mon_lib_srv, ener_lib): pdb_in = simple_pdb() params = pdb_interpretation.master_params.extract() processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, params=params, pdb_inp=pdb_in, log=StringIO()) grm = processed_pdb_file.geometry_restraints_manager() pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy sites_cart = pdb_hierarchy.atoms().extract_xyz() proxies = reference.add_coordinate_restraints(sites_cart=sites_cart) assert proxies.size() == 29, "expected 29, got %d" % proxies.size() import boost.python ext = boost.python.import_ext("mmtbx_reference_coordinate_ext") grads = flex.vec3_double(sites_cart.size(), (0.0,0.0,0.0)) residual = ext.reference_coordinate_residual_sum( sites_cart=sites_cart, proxies=proxies, gradient_array=grads) assert approx_equal(residual, 0.0) #test selection ca_selection = pdb_hierarchy.get_peptide_c_alpha_selection() ca_sites_cart = sites_cart.select(ca_selection) proxies = reference.add_coordinate_restraints( sites_cart=ca_sites_cart, selection=ca_selection) assert proxies.size() == 3, "expected 3, got %d" % proxies.size() tst_iselection = flex.size_t() for atom in pdb_hierarchy.atoms(): if atom.name == " CA " or atom.name == " N ": tst_iselection.append(atom.i_seq) tst_sites_cart = sites_cart.select(tst_iselection) proxies = reference.add_coordinate_restraints( sites_cart=tst_sites_cart, selection=tst_iselection) assert proxies.size() == 6, "expected 6, got %d" % proxies.size() #test remove selection = flex.bool([False]*29) proxies = proxies.proxy_remove(selection=selection) assert proxies.size() == 6, "expected 6, got %d" % proxies.size() proxies = proxies.proxy_remove(selection=ca_selection) assert proxies.size() == 3, "expected 3, got %d" % proxies.size() selection = flex.bool([True]*29) proxies = proxies.proxy_remove(selection=selection) assert proxies.size() == 0, "expected 0, got %d" % proxies.size()
def get_pdb_inputs(pdb_str): processed_pdb_file = pdb_interpretation.process( mon_lib_srv=server.server(), ener_lib=server.ener_lib(), raw_records=flex.std_string(pdb_str.splitlines()), strict_conflict_handling=True, force_symmetry=True, log=None) xrs = processed_pdb_file.xray_structure(show_summary=False) geometry_restraints_manager = geometry_minimization.\ get_geometry_restraints_manager(processed_pdb_file, xrs) pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy return group_args(ph=pdb_hierarchy, grm=geometry_restraints_manager, xrs=xrs)
def get_pdb_inputs(pdb_str): processed_pdb_file = pdb_interpretation.process( mon_lib_srv = server.server(), ener_lib = server.ener_lib(), raw_records = flex.std_string(pdb_str.splitlines()), strict_conflict_handling = True, force_symmetry = True, log = None) xrs = processed_pdb_file.xray_structure(show_summary = False) geometry_restraints_manager = geometry_minimization.\ get_geometry_restraints_manager(processed_pdb_file, xrs) pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy return group_args( ph = pdb_hierarchy, grm = geometry_restraints_manager, xrs = xrs)
def get_complete_dihedral_proxies( pdb_hierarchy=None, file_name=None, raw_records=None, mon_lib_srv=None, ener_lib=None, crystal_symmetry=None, log=None): # # This function is called only for reference files, that were not processed # yet. For the main file only get_dihedrals_and_phi_psi below is called. # assert [pdb_hierarchy, file_name, raw_records].count(None) == 2 from mmtbx.monomer_library import server, pdb_interpretation import cStringIO if log is None: log = sys.stdout if mon_lib_srv is None: mon_lib_srv = server.server() if ener_lib is None: ener_lib = server.ener_lib() if pdb_hierarchy is not None: raw_records = pdb_hierarchy.as_pdb_string() if raw_records is not None: if (isinstance(raw_records, str)): raw_records = flex.split_lines(raw_records) work_params = pdb_interpretation.master_params.extract() work_params.c_beta_restraints=False work_params.automatic_linking.link_none=True work_params.clash_guard.nonbonded_distance_threshold = None processed_pdb_file_local = \ pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, params=work_params, file_name=file_name, raw_records=raw_records, strict_conflict_handling=False, crystal_symmetry=crystal_symmetry, force_symmetry=True, log=cStringIO.StringIO(), substitute_non_crystallographic_unit_cell_if_necessary=True) return get_dihedrals_and_phi_psi(processed_pdb_file_local)
def exercise_1(mon_lib_srv, ener_lib): pdb_in = simple_pdb() params = pdb_interpretation.master_params.extract() processed_pdb_file = pdb_interpretation.process(mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, params=params, pdb_inp=pdb_in, log=StringIO()) grm = processed_pdb_file.geometry_restraints_manager() pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy sites_cart = pdb_hierarchy.atoms().extract_xyz() proxies = reference.add_coordinate_restraints(sites_cart=sites_cart) assert proxies.size() == 29, "expected 29, got %d" % proxies.size() import boost.python ext = boost.python.import_ext("mmtbx_reference_coordinate_ext") grads = flex.vec3_double(sites_cart.size(), (0.0, 0.0, 0.0)) residual = ext.reference_coordinate_residual_sum(sites_cart=sites_cart, proxies=proxies, gradient_array=grads) assert approx_equal(residual, 0.0) #test selection ca_selection = pdb_hierarchy.get_peptide_c_alpha_selection() ca_sites_cart = sites_cart.select(ca_selection) proxies = reference.add_coordinate_restraints(sites_cart=ca_sites_cart, selection=ca_selection) assert proxies.size() == 3, "expected 3, got %d" % proxies.size() tst_iselection = flex.size_t() for atom in pdb_hierarchy.atoms(): if atom.name == " CA " or atom.name == " N ": tst_iselection.append(atom.i_seq) tst_sites_cart = sites_cart.select(tst_iselection) proxies = reference.add_coordinate_restraints(sites_cart=tst_sites_cart, selection=tst_iselection) assert proxies.size() == 6, "expected 6, got %d" % proxies.size() #test remove selection = flex.bool([False] * 29) proxies = proxies.proxy_remove(selection=selection) assert proxies.size() == 6, "expected 6, got %d" % proxies.size() proxies = proxies.proxy_remove(selection=ca_selection) assert proxies.size() == 3, "expected 3, got %d" % proxies.size() selection = flex.bool([True] * 29) proxies = proxies.proxy_remove(selection=selection) assert proxies.size() == 0, "expected 0, got %d" % proxies.size()
def __init__(self, pdb_file_name=None, raw_records=None): # assert count(pdb_file_name, raw_records)==1 if pdb_file_name: self.pdb_inp = iotbx.pdb.input(file_name=pdb_file_name) else: self.pdb_inp = iotbx.pdb.input(lines=raw_records, source_info='raw_records') self.hierarchy = self.pdb_inp.construct_hierarchy() self.mon_lib_srv = server.server() self.ener_lib = server.ener_lib() self.processed_pdb = pdb_interpretation.process( self.mon_lib_srv, self.ener_lib, file_name=pdb_file_name, raw_records=raw_records) self.geometry_restraints_manager = self.processed_pdb.geometry_restraints_manager( ) self.atom_elements = {}
def get_mstats(pdb_raw): mon_lib_srv = server.server() ener_lib = server.ener_lib() pdb_in = iotbx.pdb.hierarchy.input(pdb_string=pdb_raw) xrs = pdb_in.input.xray_structure_simple() processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, raw_records=pdb_in.hierarchy.as_pdb_string(crystal_symmetry=xrs), crystal_symmetry=xrs, log=null_out()) pdb_in.hierarchy.atoms().reset_i_seq() mstats = model_properties.model_statistics( pdb_hierarchy=pdb_in.hierarchy, xray_structure=xrs, all_chain_proxies=processed_pdb_file.all_chain_proxies, ignore_hd=True) return mstats
def get_complete_dihedral_proxies(pdb_hierarchy=None, file_name=None, raw_records=None, mon_lib_srv=None, ener_lib=None, crystal_symmetry=None, log=None): # # This function is called only for reference files, that were not processed # yet. For the main file only get_dihedrals_and_phi_psi below is called. # Still used for reference model torsion restraints # assert [pdb_hierarchy, file_name, raw_records].count(None) == 2 from mmtbx.monomer_library import server, pdb_interpretation import cStringIO if log is None: log = sys.stdout if mon_lib_srv is None: mon_lib_srv = server.server() if ener_lib is None: ener_lib = server.ener_lib() if pdb_hierarchy is not None: raw_records = pdb_hierarchy.as_pdb_string() if raw_records is not None: if (isinstance(raw_records, str)): raw_records = flex.split_lines(raw_records) work_params = pdb_interpretation.master_params.extract() work_params.c_beta_restraints = False work_params.automatic_linking.link_none = True work_params.clash_guard.nonbonded_distance_threshold = None processed_pdb_file_local = \ pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, params=work_params, file_name=file_name, raw_records=raw_records, strict_conflict_handling=False, crystal_symmetry=crystal_symmetry, force_symmetry=True, log=cStringIO.StringIO(), substitute_non_crystallographic_unit_cell_if_necessary=True) return get_dihedrals_and_phi_psi(processed_pdb_file_local)
def get_geometry_restraints_manager(pdb_filename, #pdb_inp, #pdb_hierarchy, ): t0 = time.time() from mmtbx.monomer_library import server from mmtbx.monomer_library import pdb_interpretation #lines = pdb_hierarchy.as_pdb_string( # crystal_symmetry=pdb_inp.crystal_symmetry(), # ) mon_lib_srv = server.server() ener_lib = server.ener_lib() processed_pdb = pdb_interpretation.process( mon_lib_srv, ener_lib, #raw_records=lines, file_name=pdb_filename, ) geometry_restraints_manager = processed_pdb.geometry_restraints_manager() print 'time', time.time() - t0 return geometry_restraints_manager
def get_geometry_restraints_manager(pdb_filename, #pdb_inp, #pdb_hierarchy, ): t0=time.time() from mmtbx.monomer_library import server from mmtbx.monomer_library import pdb_interpretation #lines = pdb_hierarchy.as_pdb_string( # crystal_symmetry=pdb_inp.crystal_symmetry(), # ) mon_lib_srv = server.server() ener_lib = server.ener_lib() processed_pdb = pdb_interpretation.process( mon_lib_srv, ener_lib, #raw_records=lines, file_name=pdb_filename, ) geometry_restraints_manager = processed_pdb.geometry_restraints_manager() print 'time',time.time()-t0 return geometry_restraints_manager
def exercise_other(mon_lib_srv, ener_lib): file_name = libtbx.env.find_in_repositories( relative_path="phenix_regression/pdb/3mku.pdb", test=os.path.isfile) if (file_name is None): print "Skipping test." return params = pdb_interpretation.master_params.fetch().extract() params.peptide_link.ramachandran_restraints = True processed_pdb_file = pdb_interpretation.process(mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, params=params, pdb_inp=pdb_in, log=StringIO()) pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy params2 = ramachandran.refine_opt_params.fetch().extract() params2.exclude_secondary_structure = True ramachandran.process_refinement_settings( params=params2, pdb_hierarchy=pdb_hierarchy, secondary_structure_manager=ss_mgr, d_min=2.9, log=StringIO())
def run_validation(self) : # get required elements to run: # - pdb_hierarchy and geometry pdb_in = iotbx.pdb.input(file_name=self.pdb_file) mon_lib_srv = server.server() ener_lib = server.ener_lib() processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, pdb_inp=pdb_in, substitute_non_crystallographic_unit_cell_if_necessary=True) pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy geometry = processed_pdb_file.geometry_restraints_manager() # - params import mmtbx.command_line.rna_validate params = mmtbx.command_line.rna_validate.get_master_phil().extract() # run rna_validation self.result = rna_validation( pdb_hierarchy=pdb_hierarchy, geometry_restraints_manager=geometry, params=params, outliers_only=False)
def __init__(self, pdb_hierarchy, geometry_restraints_manager=None, params=None, outliers_only=True): if (geometry_restraints_manager is None): mon_lib_srv = monomer_library.server.server() ener_lib = monomer_library.server.ener_lib() processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, pdb_inp=pdb_hierarchy.as_pdb_input(), substitute_non_crystallographic_unit_cell_if_necessary=True) geometry_restraints_manager = \ processed_pdb_file.geometry_restraints_manager() pdb_hierarchy = \ processed_pdb_file.all_chain_proxies.pdb_hierarchy pdb_atoms = pdb_hierarchy.atoms() self.bonds = rna_bonds( pdb_hierarchy=pdb_hierarchy, pdb_atoms=pdb_atoms, geometry_restraints_manager=geometry_restraints_manager, outliers_only=outliers_only) self.angles = rna_angles( pdb_hierarchy=pdb_hierarchy, pdb_atoms=pdb_atoms, geometry_restraints_manager=geometry_restraints_manager, outliers_only=outliers_only) self.puckers = rna_puckers(pdb_hierarchy=pdb_hierarchy, params=getattr(params, "rna_sugar_pucker_analysis", None), outliers_only=outliers_only) self.suites = rna_suites( pdb_hierarchy=pdb_hierarchy, geometry_restraints_manager=geometry_restraints_manager, outliers_only=outliers_only)
def exercise_2 () : pdb_raw = """\ ATOM 6407 N GLY A 388 -0.783 9.368 -16.436 1.00 51.96 N ATOM 6408 CA GLY A 388 -0.227 9.888 -15.197 1.00 54.04 C ATOM 6409 C GLY A 388 -0.637 11.320 -14.897 1.00 55.86 C ATOM 6410 O GLY A 388 -1.728 11.738 -15.347 1.00 56.70 O ATOM 6411 OXT GLY A 388 0.129 12.024 -14.203 1.00 56.98 O ATOM 6412 D GLY A 388 -0.460 9.727 -17.309 1.00 51.44 D ATOM 6413 HA2 GLY A 388 -0.561 9.258 -14.385 1.00 54.07 H ATOM 6414 HA3 GLY A 388 0.843 9.835 -15.243 1.00 54.13 H TER 6415 GLY A 388 HETATM 6416 D D8U A 401 -12.236 -13.695 -42.992 1.00 15.23 D HETATM 6417 O DOD A1001 -4.151 -5.107 -38.592 1.00 13.40 O HETATM 6418 D1 DOD A1001 -4.760 -5.026 -39.326 1.00 15.45 D HETATM 6419 D2 DOD A1001 -4.625 -4.741 -37.845 1.00 14.81 D """ mon_lib_srv = server.server() ener_lib = server.ener_lib() pdb_in = iotbx.pdb.hierarchy.input(pdb_string=pdb_raw) xrs = pdb_in.input.xray_structure_simple() processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, raw_records=pdb_in.hierarchy.as_pdb_string(crystal_symmetry=xrs), crystal_symmetry=xrs, log=null_out()) pdb_in.hierarchy.atoms().reset_i_seq() mstats = model_properties.model_statistics( pdb_hierarchy=pdb_in.hierarchy, xray_structure=xrs, all_chain_proxies=processed_pdb_file.all_chain_proxies, ignore_hd=True) out = StringIO() mstats.show(out=out) assert ("Ligands:" in out.getvalue()) assert ("B_iso: mean = 15.2 max = 15.2 min = 15.2" in out.getvalue())
def exercise_other (mon_lib_srv, ener_lib) : file_name = libtbx.env.find_in_repositories( relative_path="phenix_regression/pdb/3mku.pdb", test=os.path.isfile) if (file_name is None) : print "Skipping test." return params = pdb_interpretation.master_params.fetch().extract() params.peptide_link.ramachandran_restraints = True processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, params=params, pdb_inp=pdb_in, log=StringIO()) pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy params2 = ramachandran.refine_opt_params.fetch().extract() params2.exclude_secondary_structure = True ramachandran.process_refinement_settings( params=params2, pdb_hierarchy=pdb_hierarchy, secondary_structure_manager=ss_mgr, d_min=2.9, log=StringIO())
def __init__(self, pdb_hierarchy, geometry_restraints_manager, params, outliers_only=True): if (geometry_restraints_manager is None) : mon_lib_srv = monomer_library.server.server() ener_lib = monomer_library.server.ener_lib() processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, pdb_inp=pdb_hierarchy.as_pdb_input(), substitute_non_crystallographic_unit_cell_if_necessary=True) geometry_restraints_manager = \ processed_pdb_file.geometry_restraints_manager() pdb_hierarchy = \ processed_pdb_file.all_chain_proxies.pdb_hierarchy pdb_atoms = pdb_hierarchy.atoms() self.bonds = rna_bonds( pdb_hierarchy=pdb_hierarchy, pdb_atoms=pdb_atoms, geometry_restraints_manager=geometry_restraints_manager, outliers_only=outliers_only) self.angles = rna_angles( pdb_hierarchy=pdb_hierarchy, pdb_atoms=pdb_atoms, geometry_restraints_manager=geometry_restraints_manager, outliers_only=outliers_only) self.puckers = rna_puckers( pdb_hierarchy=pdb_hierarchy, params=getattr(params, "rna_sugar_pucker_analysis", None), outliers_only=outliers_only) self.suites = rna_suites( pdb_hierarchy=pdb_hierarchy, geometry_restraints_manager=geometry_restraints_manager, outliers_only=outliers_only)
def exercise_3(mon_lib_srv, ener_lib): #test torsion restraints for use_reference in ['True', 'False', 'top_out', 'None']: processed_pdb_file = pdb_interpretation.process( mon_lib_srv = mon_lib_srv, ener_lib = ener_lib, raw_records = flex.std_string(pdb_str_2.splitlines()), strict_conflict_handling = True, force_symmetry = True, log = None) grm = processed_pdb_file.geometry_restraints_manager() xrs2 = processed_pdb_file.xray_structure(show_summary = False) awl2 = processed_pdb_file.all_chain_proxies.pdb_hierarchy.atoms_with_labels() pdb2 = processed_pdb_file.all_chain_proxies.pdb_hierarchy pdb_inp3 = iotbx.pdb.input(source_info=None, lines=pdb_str_3) xrs3 = pdb_inp3.xray_structure_simple() ph3 = pdb_inp3.construct_hierarchy() ph3.atoms().reset_i_seq() awl3 = ph3.atoms_with_labels() sites_cart_reference = flex.vec3_double() selection = flex.size_t() min_selection = flex.size_t() reference_names = ["N", "CA", "CB", "CG", "CD", "NE", "CZ", "NH1", "NH2"] minimize_names = ["CG", "CD", "NE", "CZ", "NH1", "NH2"] for a2,a3 in zip(tuple(awl2), tuple(awl3)): assert a2.resname == a3.resname assert a2.name == a3.name assert a2.i_seq == a3.i_seq if(a2.resname == "ARG" and a2.name.strip() in reference_names): selection.append(a2.i_seq) sites_cart_reference.append(a3.xyz) if a2.name.strip() in minimize_names: min_selection.append(a2.i_seq) assert selection.size() == len(reference_names) selection_bool = flex.bool(xrs2.scatterers().size(), min_selection) if(use_reference == 'True'): grm.add_chi_torsion_restraints_in_place( pdb_hierarchy = pdb2, sites_cart = sites_cart_reference, selection = selection, sigma = 2.5) elif(use_reference == 'top_out'): grm.add_chi_torsion_restraints_in_place( pdb_hierarchy = pdb2, sites_cart = sites_cart_reference, selection = selection, sigma = 2.5, limit = 180.0, top_out_potential=True) elif(use_reference == 'None'): grm.add_chi_torsion_restraints_in_place( pdb_hierarchy = pdb2, sites_cart = sites_cart_reference, selection = selection, sigma = 2.5) grm.remove_chi_torsion_restraints_in_place( selection = selection) d1 = flex.mean(flex.sqrt((xrs2.sites_cart().select(min_selection) - xrs3.sites_cart().select(min_selection)).dot())) print "distance start (use_reference: %s): %6.4f"%(str(use_reference), d1) assert d1>4.0 assert approx_equal( flex.max(flex.sqrt((xrs2.sites_cart().select(~selection_bool) - xrs3.sites_cart().select(~selection_bool)).dot())), 0) from cctbx import geometry_restraints import mmtbx.refinement.geometry_minimization import scitbx.lbfgs grf = geometry_restraints.flags.flags(default=True) grf.nonbonded = False sites_cart = xrs2.sites_cart() minimized = mmtbx.refinement.geometry_minimization.lbfgs( sites_cart = sites_cart, correct_special_position_tolerance=1.0, geometry_restraints_manager = grm, sites_cart_selection = flex.bool(sites_cart.size(), min_selection), geometry_restraints_flags = grf, lbfgs_termination_params = scitbx.lbfgs.termination_parameters( max_iterations=5000)) xrs2.set_sites_cart(sites_cart = sites_cart) d2 = flex.mean(flex.sqrt((xrs2.sites_cart().select(min_selection) - xrs3.sites_cart().select(min_selection)).dot())) print "distance final (use_reference: %s): %6.4f"%(str(use_reference), d2) if(use_reference in ['True', 'top_out']): assert d2<0.02, d2 else: assert d2>4.0, d2 assert approx_equal( flex.max(flex.sqrt((xrs2.sites_cart().select(~selection_bool) - xrs3.sites_cart().select(~selection_bool)).dot())), 0) #test torsion manipulation grm.remove_chi_torsion_restraints_in_place() grm.remove_chi_torsion_restraints_in_place() sites_cart_reference = [] selections_reference = [] for model in pdb2.models(): for chain in model.chains(): for residue in chain.residues(): sites_cart_reference.append(residue.atoms().extract_xyz()) selections_reference.append(residue.atoms().extract_i_seq()) #one residue at a time (effectively chi angles only) for sites_cart, selection in zip(sites_cart_reference, selections_reference): grm.add_chi_torsion_restraints_in_place( pdb_hierarchy = pdb2, sites_cart = sites_cart, selection = selection) assert grm.get_n_chi_torsion_proixes() == 6 grm.remove_chi_torsion_restraints_in_place() #all sites at once, chi angles only sites_cart = xrs2.sites_cart() grm.add_chi_torsion_restraints_in_place( pdb_hierarchy = pdb2, sites_cart = sites_cart, selection = None, chi_angles_only = True) assert grm.get_n_chi_torsion_proixes() == 6 #all sites at once, all torsions grm.add_chi_torsion_restraints_in_place( pdb_hierarchy = pdb2, sites_cart = sites_cart, selection = None, chi_angles_only = False) # grm.get_chi_torsion_proxies().show_sorted( # by_value='residual', # sites_cart=sites_cart, # site_labels=[atom.id_str() for atom in pdb2.atoms()]) assert grm.get_n_chi_torsion_proixes() == 12, grm.get_n_chi_torsion_proixes()
def run(args, command_name=libtbx.env.dispatcher_name): if (len(args) == 0): args = ["--help"] command_line = (option_parser( usage='%s pdb_file "atom_selection" [...]' % command_name).option( None, "--write_pdb_file", action="store", type="string", default=None, help="write selected atoms to new PDB file", metavar="FILE" ).option( None, "--cryst1_replacement_buffer_layer", action="store", type="float", default=None, help="replace CRYST1 with pseudo unit cell covering the selected" " atoms plus a surrounding buffer layer", metavar="WIDTH")).process(args=args, min_nargs=2) co = command_line.options mon_lib_srv = server.server() ener_lib = server.ener_lib() processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, file_name=command_line.args[0], log=sys.stdout) print acp = processed_pdb_file.all_chain_proxies hierarchy = acp.pdb_hierarchy asc = hierarchy.atom_selection_cache() sel = asc.selection(string="chain 'A' and resid 1 through 8 and icode ' '") h1 = hierarchy.select(sel) # keep original hierarchy too print h1.as_pdb_string() selection_cache = acp.pdb_hierarchy.atom_selection_cache() atoms = acp.pdb_atoms all_bsel = flex.bool(atoms.size(), False) for selection_string in command_line.args[1:]: print selection_string isel = acp.iselection(string=selection_string, cache=selection_cache) all_bsel.set_selected(isel, True) if (not co.write_pdb_file): print " %d atom%s selected" % plural_s(isel.size()) for atom in atoms.select(isel): print " %s" % atom.format_atom_record() print if (co.write_pdb_file): print "Writing file:", show_string(co.write_pdb_file) sel_hierarchy = acp.pdb_hierarchy.select(all_bsel) if (co.cryst1_replacement_buffer_layer is None): crystal_symmetry = acp.special_position_settings else: import cctbx.crystal crystal_symmetry = cctbx.crystal.non_crystallographic_symmetry( sites_cart=sel_hierarchy.atoms().extract_xyz(), buffer_layer=co.cryst1_replacement_buffer_layer) write_whole_pdb_file(file_name=co.write_pdb_file, processed_pdb_file=processed_pdb_file, pdb_hierarchy=sel_hierarchy, crystal_symmetry=crystal_symmetry) print
def exercise_2(mon_lib_srv, ener_lib): for use_reference in [True, False, None]: processed_pdb_file = pdb_interpretation.process( mon_lib_srv = mon_lib_srv, ener_lib = ener_lib, raw_records = flex.std_string(pdb_str_2.splitlines()), strict_conflict_handling = True, force_symmetry = True, log = None) grm = processed_pdb_file.geometry_restraints_manager() xrs2 = processed_pdb_file.xray_structure(show_summary = False) awl2 = processed_pdb_file.all_chain_proxies.pdb_hierarchy.atoms_with_labels() pdb_inp3 = iotbx.pdb.input(source_info=None, lines=pdb_str_3) xrs3 = pdb_inp3.xray_structure_simple() ph3 = pdb_inp3.construct_hierarchy() ph3.atoms().reset_i_seq() awl3 = ph3.atoms_with_labels() sites_cart_reference = flex.vec3_double() selection = flex.size_t() reference_names = ["CG", "CD", "NE", "CZ", "NH1", "NH2"] for a2,a3 in zip(tuple(awl2), tuple(awl3)): assert a2.resname == a3.resname assert a2.name == a3.name assert a2.i_seq == a3.i_seq if(a2.resname == "ARG" and a2.name.strip() in reference_names): selection.append(a2.i_seq) sites_cart_reference.append(a3.xyz) assert selection.size() == len(reference_names) selection_bool = flex.bool(xrs2.scatterers().size(), selection) if(use_reference): grm.adopt_reference_coordinate_restraints_in_place( reference.add_coordinate_restraints( sites_cart = sites_cart_reference, selection = selection, sigma = 0.01)) elif(use_reference is None): grm.adopt_reference_coordinate_restraints_in_place( reference.add_coordinate_restraints( sites_cart = sites_cart_reference, selection = selection, sigma = 0.01)) grm.remove_reference_coordinate_restraints_in_place( selection = selection) d1 = flex.mean(flex.sqrt((xrs2.sites_cart().select(selection) - xrs3.sites_cart().select(selection)).dot())) print "distance start (use_reference: %s): %6.4f"%(str(use_reference), d1) assert d1>4.0 assert approx_equal( flex.max(flex.sqrt((xrs2.sites_cart().select(~selection_bool) - xrs3.sites_cart().select(~selection_bool)).dot())), 0) from cctbx import geometry_restraints import mmtbx.refinement.geometry_minimization import scitbx.lbfgs grf = geometry_restraints.flags.flags(default=True) sites_cart = xrs2.sites_cart() minimized = mmtbx.refinement.geometry_minimization.lbfgs( sites_cart = sites_cart, correct_special_position_tolerance=1.0, geometry_restraints_manager = grm, sites_cart_selection = flex.bool(sites_cart.size(), selection), geometry_restraints_flags = grf, lbfgs_termination_params = scitbx.lbfgs.termination_parameters( max_iterations=5000)) xrs2.set_sites_cart(sites_cart = sites_cart) d2 = flex.mean(flex.sqrt((xrs2.sites_cart().select(selection) - xrs3.sites_cart().select(selection)).dot())) print "distance final (use_reference: %s): %6.4f"%(str(use_reference), d2) if(use_reference): assert d2<0.005, "failed: %f<0.05" % d2 else: assert d2>4.0, d2 assert approx_equal( flex.max(flex.sqrt((xrs2.sites_cart().select(~selection_bool) - xrs3.sites_cart().select(~selection_bool)).dot())), 0)
def morph_models (params, out=None, debug=False) : assert len(params.morph.pdb_file) > 1 assert (len(params.morph.frames) == (len(params.morph.pdb_file) - 1)) if (out is None) : out = sys.stdout from mmtbx.monomer_library import pdb_interpretation, server from iotbx import file_reader pdb_hierarchies = [] for pdb_file in params.morph.pdb_file : pdb_in = file_reader.any_file(pdb_file, force_type="pdb") pdb_in.check_file_type("pdb") hierarchy = pdb_in.file_object.hierarchy pdb_hierarchies.append(hierarchy) new_pdb = homogenize_structures( pdb_hierarchies=pdb_hierarchies, delete_waters=params.morph.delete_waters, debug=debug) mon_lib_srv = server.server() ener_lib = server.ener_lib() for cif_file in params.morph.cif_file : print "Loading CIF file %s" % cif_file cif_object = server.read_cif(file_name=cif_file) mon_lib_serv.process_cif_object(cif_object=cif_object, file_name=cif_file) ener_lib.process_cif_object(cif_object=cif_object, file_name=cif_file) if (params.morph.minimization.interpolate_dihedrals) : params.pdb_interpretation.peptide_link.discard_psi_phi = False processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, params=params.pdb_interpretation, pdb_inp=new_pdb[0], substitute_non_crystallographic_unit_cell_if_necessary=True) all_chain_proxies = processed_pdb_file.all_chain_proxies static_coords = [ all_chain_proxies.pdb_hierarchy.atoms().extract_xyz() ] for pdb_inp in new_pdb[1:] : sites = pdb_inp.atoms().extract_xyz() static_coords.append(sites) if (params.morph.fitting.align_atoms is not None) : print >> out, "Superposing on initial structure..." selection_cache = all_chain_proxies.pdb_hierarchy.atom_selection_cache() selection = selection_cache.selection(params.morph.fitting.align_atoms) if (selection.count(True) == 0) : raise Sorry("No atoms in alignment selection!") i_ref = params.morph.fitting.reference_structure sites_fixed = static_coords[i_ref] j = 0 while (j < len(static_coords)) : if (j != i_ref) : sites_moving = static_coords[j] assert (len(sites_moving) == len(sites_fixed) > 0) if (params.morph.fitting.sieve_fit) : from scitbx.math import superpose lsq_fit = superpose.sieve_fit( sites_fixed=sites_fixed, sites_moving=sites_moving, selection=selection) sites_moving_new = lsq_fit.r.elems * sites_moving + lsq_fit.t.elems else : sites_moving_new = fit_sites( sites_fixed=sites_fixed, sites_moving=sites_moving, selection=selection) assert (sites_moving_new.size() == sites_moving.size()) static_coords[j] = sites_moving_new j += 1 print >> out, "Ready to morph" morphs = [] restraints_manager = processed_pdb_file.geometry_restraints_manager() for i in range(len(params.morph.pdb_file) - 1) : morph = adiabatic_mapping( pdb_hierarchy=all_chain_proxies.pdb_hierarchy, restraints_manager=restraints_manager, start_coords = static_coords[i], end_coords = static_coords[i+1], params = params.morph.minimization, nsteps = params.morph.frames[i], out=out) morphs.append(morph) serial = 1 if (params.morph.output_directory is not None) : output_base = os.path.join(params.morph.output_directory, params.morph.output_prefix) else : output_base = params.morph.output_prefix for i, morph in enumerate(morphs) : serial = morph.write_pdb_files( output_base=output_base, serial=serial, serial_format=params.morph.serial_format, pause=params.morph.pause, pause_at_end=(i == (len(morphs) - 1)), log=out) f = open("%s.pml" % output_base, "w") for i in range(1, serial) : format_base = "%s_%s" % (output_base, params.morph.serial_format) print >> f, "load %s.pdb, morph" % (format_base % i) f.close() print >> out, "PyMOL script is %s.pml" % output_base
def exercise_3(mon_lib_srv, ener_lib): #test torsion restraints for use_reference in ['True', 'False', 'top_out', 'None']: processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, raw_records=flex.std_string(pdb_str_2.splitlines()), strict_conflict_handling=True, force_symmetry=True, log=None) grm = processed_pdb_file.geometry_restraints_manager() xrs2 = processed_pdb_file.xray_structure(show_summary=False) awl2 = processed_pdb_file.all_chain_proxies.pdb_hierarchy.atoms_with_labels( ) pdb2 = processed_pdb_file.all_chain_proxies.pdb_hierarchy pdb_inp3 = iotbx.pdb.input(source_info=None, lines=pdb_str_3) xrs3 = pdb_inp3.xray_structure_simple() ph3 = pdb_inp3.construct_hierarchy() ph3.atoms().reset_i_seq() awl3 = ph3.atoms_with_labels() sites_cart_reference = flex.vec3_double() selection = flex.size_t() min_selection = flex.size_t() reference_names = [ "N", "CA", "CB", "CG", "CD", "NE", "CZ", "NH1", "NH2" ] minimize_names = ["CG", "CD", "NE", "CZ", "NH1", "NH2"] for a2, a3 in zip(tuple(awl2), tuple(awl3)): assert a2.resname == a3.resname assert a2.name == a3.name assert a2.i_seq == a3.i_seq if (a2.resname == "ARG" and a2.name.strip() in reference_names): selection.append(a2.i_seq) sites_cart_reference.append(a3.xyz) if a2.name.strip() in minimize_names: min_selection.append(a2.i_seq) assert selection.size() == len(reference_names) selection_bool = flex.bool(xrs2.scatterers().size(), min_selection) if (use_reference == 'True'): grm.add_chi_torsion_restraints_in_place( pdb_hierarchy=pdb2, sites_cart=sites_cart_reference, selection=selection, sigma=2.5) elif (use_reference == 'top_out'): grm.add_chi_torsion_restraints_in_place( pdb_hierarchy=pdb2, sites_cart=sites_cart_reference, selection=selection, sigma=2.5, limit=180.0, top_out_potential=True) elif (use_reference == 'None'): grm.add_chi_torsion_restraints_in_place( pdb_hierarchy=pdb2, sites_cart=sites_cart_reference, selection=selection, sigma=2.5) grm.remove_chi_torsion_restraints_in_place(selection=selection) d1 = flex.mean( flex.sqrt((xrs2.sites_cart().select(min_selection) - xrs3.sites_cart().select(min_selection)).dot())) print "distance start (use_reference: %s): %6.4f" % ( str(use_reference), d1) assert d1 > 4.0 assert approx_equal( flex.max( flex.sqrt((xrs2.sites_cart().select(~selection_bool) - xrs3.sites_cart().select(~selection_bool)).dot())), 0) from cctbx import geometry_restraints import mmtbx.refinement.geometry_minimization import scitbx.lbfgs grf = geometry_restraints.flags.flags(default=True) grf.nonbonded = False sites_cart = xrs2.sites_cart() minimized = mmtbx.refinement.geometry_minimization.lbfgs( sites_cart=sites_cart, correct_special_position_tolerance=1.0, geometry_restraints_manager=grm, sites_cart_selection=flex.bool(sites_cart.size(), min_selection), geometry_restraints_flags=grf, lbfgs_termination_params=scitbx.lbfgs.termination_parameters( max_iterations=5000)) xrs2.set_sites_cart(sites_cart=sites_cart) d2 = flex.mean( flex.sqrt((xrs2.sites_cart().select(min_selection) - xrs3.sites_cart().select(min_selection)).dot())) print "distance final (use_reference: %s): %6.4f" % ( str(use_reference), d2) if (use_reference in ['True', 'top_out']): assert d2 < 0.02, d2 else: assert d2 > 4.0, d2 assert approx_equal( flex.max( flex.sqrt((xrs2.sites_cart().select(~selection_bool) - xrs3.sites_cart().select(~selection_bool)).dot())), 0) #test torsion manipulation grm.remove_chi_torsion_restraints_in_place() grm.remove_chi_torsion_restraints_in_place() sites_cart_reference = [] selections_reference = [] for model in pdb2.models(): for chain in model.chains(): for residue in chain.residues(): sites_cart_reference.append(residue.atoms().extract_xyz()) selections_reference.append(residue.atoms().extract_i_seq()) #one residue at a time (effectively chi angles only) for sites_cart, selection in zip(sites_cart_reference, selections_reference): grm.add_chi_torsion_restraints_in_place(pdb_hierarchy=pdb2, sites_cart=sites_cart, selection=selection) assert grm.get_n_chi_torsion_proixes() == 6 grm.remove_chi_torsion_restraints_in_place() #all sites at once, chi angles only sites_cart = xrs2.sites_cart() grm.add_chi_torsion_restraints_in_place(pdb_hierarchy=pdb2, sites_cart=sites_cart, selection=None, chi_angles_only=True) assert grm.get_n_chi_torsion_proixes() == 6 #all sites at once, all torsions grm.add_chi_torsion_restraints_in_place(pdb_hierarchy=pdb2, sites_cart=sites_cart, selection=None, chi_angles_only=False) # grm.get_chi_torsion_proxies().show_sorted( # by_value='residual', # sites_cart=sites_cart, # site_labels=[atom.id_str() for atom in pdb2.atoms()]) assert grm.get_n_chi_torsion_proixes( ) == 12, grm.get_n_chi_torsion_proixes()
def exercise_acs(mon_lib_srv, ener_lib): ac_pdb1 = """\ CRYST1 72.072 33.173 34.033 90.00 90.00 90.00 P 1 SCALE1 0.013875 0.000000 0.000000 0.00000 SCALE2 0.000000 0.030145 0.000000 0.00000 SCALE3 0.000000 0.000000 0.029383 0.00000 ATOM 519 N HIS B 1 5.000 8.515 18.112 1.00 20.00 N ATOM 520 CA HIS B 1 5.999 8.713 17.074 1.00 20.00 C ATOM 521 C HIS B 1 7.157 9.627 17.517 1.00 20.00 C ATOM 522 O HIS B 1 8.302 9.165 17.614 1.00 20.00 O ATOM 523 CB AHIS B 1 5.315 9.226 15.797 0.50 20.00 C ATOM 523 CB BHIS B 1 5.315 9.226 15.797 0.50 20.00 C ATOM 524 HA HIS B 1 6.434 7.742 16.835 1.00 20.00 H ATOM 525 N TRP B 2 6.845 10.900 17.805 1.00 20.00 N ATOM 526 CA TRP B 2 7.853 11.954 18.083 1.00 20.00 C ATOM 527 C TRP B 2 8.071 12.262 19.565 1.00 20.00 C ATOM 528 O TRP B 2 8.355 13.406 19.941 1.00 20.00 O ATOM 529 CB TRP B 2 7.516 13.257 17.336 1.00 20.00 C ATOM 530 HA TRP B 2 8.809 11.606 17.692 1.00 20.00 H ATOM 531 H ATRP B 2 5.886 11.243 17.855 0.50 20.00 H ATOM 532 D BTRP B 2 5.886 11.243 17.855 0.50 20.00 D ATOM 533 N GLU B 3 7.910 11.239 20.396 1.00 20.00 N ATOM 534 CA GLU B 3 8.310 11.284 21.798 1.00 20.00 C ATOM 535 C GLU B 3 9.344 10.190 21.979 1.00 20.00 C ATOM 536 O GLU B 3 10.197 10.267 22.867 1.00 20.00 O ATOM 537 CB GLU B 3 7.115 11.041 22.731 1.00 20.00 C ATOM 538 HA GLU B 3 8.761 12.248 22.034 1.00 20.00 H ATOM 539 H AGLU B 3 7.474 10.360 20.122 0.50 20.00 H ATOM 540 D BGLU B 3 7.474 10.360 20.122 0.50 20.00 D """ ac_pdb2 = """\ CRYST1 72.072 33.173 34.033 90.00 90.00 90.00 P 1 SCALE1 0.013875 0.000000 0.000000 0.00000 SCALE2 0.000000 0.030145 0.000000 0.00000 SCALE3 0.000000 0.000000 0.029383 0.00000 ATOM 519 N HIS B 1 5.000 8.515 18.112 1.00 20.00 N ATOM 520 CA HIS B 1 5.999 8.713 17.074 1.00 20.00 C ATOM 521 C HIS B 1 7.157 9.627 17.517 1.00 20.00 C ATOM 522 O HIS B 1 8.302 9.165 17.614 1.00 20.00 O ATOM 523 CB HIS B 1 5.315 9.226 15.797 1.00 20.00 C ATOM 524 HA HIS B 1 6.434 7.742 16.835 1.00 20.00 H ATOM 525 N TRP B 2 6.845 10.900 17.805 1.00 20.00 N ATOM 526 CA ATRP B 2 7.853 11.954 18.083 0.50 20.00 C ATOM 556 CA BTRP B 2 7.453 11.454 18.083 0.50 20.00 C ATOM 527 C TRP B 2 8.071 12.262 19.565 1.00 20.00 C ATOM 528 O TRP B 2 8.355 13.406 19.941 1.00 20.00 O ATOM 529 CB TRP B 2 7.516 13.257 17.336 1.00 20.00 C ATOM 530 HA TRP B 2 8.809 11.606 17.692 1.00 20.00 H ATOM 531 H ATRP B 2 5.886 11.243 17.855 0.50 20.00 H ATOM 532 D BTRP B 2 5.886 11.243 17.855 0.50 20.00 D ATOM 533 N GLU B 3 7.910 11.239 20.396 1.00 20.00 N ATOM 534 CA GLU B 3 8.310 11.284 21.798 1.00 20.00 C ATOM 535 C GLU B 3 9.344 10.190 21.979 1.00 20.00 C ATOM 536 O GLU B 3 10.197 10.267 22.867 1.00 20.00 O ATOM 537 CB GLU B 3 7.115 11.041 22.731 1.00 20.00 C ATOM 538 HA GLU B 3 8.761 12.248 22.034 1.00 20.00 H ATOM 539 H AGLU B 3 7.474 10.360 20.122 0.50 20.00 H ATOM 540 D BGLU B 3 7.474 10.360 20.122 0.50 20.00 D """ no_ac_pdb = """\ CRYST1 72.072 33.173 34.033 90.00 90.00 90.00 P 1 SCALE1 0.013875 0.000000 0.000000 0.00000 SCALE2 0.000000 0.030145 0.000000 0.00000 SCALE3 0.000000 0.000000 0.029383 0.00000 ATOM 519 N HIS B 1 5.000 8.515 18.112 1.00 20.00 N ATOM 520 CA HIS B 1 5.999 8.713 17.074 1.00 20.00 C ATOM 521 C HIS B 1 7.157 9.627 17.517 1.00 20.00 C ATOM 522 O HIS B 1 8.302 9.165 17.614 1.00 20.00 O ATOM 523 CB HIS B 1 5.315 9.226 15.797 1.00 20.00 C ATOM 525 N TRP B 2 6.845 10.900 17.805 1.00 20.00 N ATOM 556 CA TRP B 2 7.453 11.454 18.083 0.50 20.00 C ATOM 527 C TRP B 2 8.071 12.262 19.565 1.00 20.00 C ATOM 528 O TRP B 2 8.355 13.406 19.941 1.00 20.00 O ATOM 529 CB TRP B 2 7.516 13.257 17.336 1.00 20.00 C ATOM 533 N GLU B 3 7.910 11.239 20.396 1.00 20.00 N ATOM 534 CA GLU B 3 8.310 11.284 21.798 1.00 20.00 C ATOM 535 C GLU B 3 9.344 10.190 21.979 1.00 20.00 C ATOM 536 O GLU B 3 10.197 10.267 22.867 1.00 20.00 O ATOM 537 CB GLU B 3 7.115 11.041 22.731 1.00 20.00 C """ for correct_nprox, pdb_str in [ (1, ac_pdb1), (2, ac_pdb2), (1, no_ac_pdb), ]: params = pdb_interpretation.master_params.fetch().extract() params.peptide_link.ramachandran_restraints = True processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, params=params, raw_records=pdb_str.split("\n"), log=StringIO()) grm = processed_pdb_file.geometry_restraints_manager() nprox = grm.ramachandran_manager.get_n_proxies() assert nprox == correct_nprox, ""+\ "Want to get %d rama proxies, got %d" % (correct_nprox, nprox)
def run(args, command_name=libtbx.env.dispatcher_name): if (len(args) == 0): args = ["--help"] command_line = (option_parser( usage='%s pdb_file "atom_selection" [...]' % command_name) .option(None, "--write_pdb_file", action="store", type="string", default=None, help="write selected atoms to new PDB file", metavar="FILE") .option(None, "--cryst1_replacement_buffer_layer", action="store", type="float", default=None, help="replace CRYST1 with pseudo unit cell covering the selected" " atoms plus a surrounding buffer layer", metavar="WIDTH") ).process(args=args, min_nargs=2) co = command_line.options mon_lib_srv = server.server() ener_lib = server.ener_lib() processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, file_name=command_line.args[0], log=sys.stdout) print acp = processed_pdb_file.all_chain_proxies hierarchy=acp.pdb_hierarchy asc=hierarchy.atom_selection_cache() sel=asc.selection(string = "chain 'A' and resid 1 through 8 and icode ' '") h1=hierarchy.select(sel) # keep original hierarchy too print h1.as_pdb_string() selection_cache = acp.pdb_hierarchy.atom_selection_cache() atoms = acp.pdb_atoms all_bsel = flex.bool(atoms.size(), False) for selection_string in command_line.args[1:]: print selection_string isel = acp.iselection(string=selection_string, cache=selection_cache) all_bsel.set_selected(isel, True) if (not co.write_pdb_file): print " %d atom%s selected" % plural_s(isel.size()) for atom in atoms.select(isel): print " %s" % atom.format_atom_record() print if (co.write_pdb_file): print "Writing file:", show_string(co.write_pdb_file) sel_hierarchy = acp.pdb_hierarchy.select(all_bsel) if (co.cryst1_replacement_buffer_layer is None): crystal_symmetry = acp.special_position_settings else: import cctbx.crystal crystal_symmetry = cctbx.crystal.non_crystallographic_symmetry( sites_cart=sel_hierarchy.atoms().extract_xyz(), buffer_layer=co.cryst1_replacement_buffer_layer) write_whole_pdb_file( file_name=co.write_pdb_file, processed_pdb_file=processed_pdb_file, pdb_hierarchy=sel_hierarchy, crystal_symmetry=crystal_symmetry) print
def run(args, pdb_interpretation_params=None): if (len(args) == 0 or "--help" in args or "--h" in args or "-h" in args): raise Usage(usage()) pdbID = None master_phil = get_master_phil() import iotbx.utils input_objects = iotbx.utils.process_command_line_inputs( args=args, master_phil=master_phil, input_types=("pdb", "cif")) auto_cdl=True for po in input_objects["phil"]: if po.as_str().find(".cdl")>-1: auto_cdl=False break work_phil = master_phil.fetch(sources=input_objects["phil"]) work_params = work_phil.extract() if auto_cdl: work_params.kinemage.pdb_interpretation.restraints_library.cdl = Auto if work_params.kinemage.pdb == None: assert len(input_objects["pdb"]) == 1 file_obj = input_objects["pdb"][0] file_name = file_obj.file_name else: file_name = work_params.kinemage.pdb if file_name and os.path.exists(file_name): pdb_io = pdb.input(file_name) pdbID = os.path.basename(pdb_io.source_info().split(' ')[1]).split('.')[0] else : raise Sorry("PDB file does not exist") assert pdb_io is not None cif_file = None cif_object = None if len(work_params.kinemage.cif) == 0: if len(input_objects["cif"]) > 0: cif_file = [] for cif in input_objects["cif"]: cif_file.append(cif.file_name) else: cif_file = work_params.kinemage.cif mon_lib_srv = monomer_library.server.server() ener_lib = monomer_library.server.ener_lib() if cif_file != None: for cif in cif_file: try: cif_object = monomer_library.server.read_cif(file_name=cif) except Exception: raise Sorry("Unknown file format: %s" % show_string(cif)) if cif_object != None: for srv in [mon_lib_srv, ener_lib]: srv.process_cif_object(cif_object=cif_object) if pdb_interpretation_params is None: #pdb_int_work_params = pdb_interpretation.master_params.extract() pdb_int_work_params = work_params.kinemage.pdb_interpretation else: pdb_int_work_params = pdb_interpretation_params pdb_int_work_params.clash_guard.nonbonded_distance_threshold = None processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, pdb_inp=pdb_io, params=pdb_int_work_params, substitute_non_crystallographic_unit_cell_if_necessary=True) if work_params.kinemage.out_file is not None: outfile = work_params.kinemage.out_file else : outfile = pdbID+'.kin' outfile = make_multikin(f=outfile, processed_pdb_file=processed_pdb_file, pdbID=pdbID, keep_hydrogens=work_params.kinemage.keep_hydrogens) return outfile
def run(file_name): print "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" mon_lib_srv = monomer_library.server.server() ener_lib = monomer_library.server.ener_lib() processed = monomer_library.pdb_interpretation.process( mon_lib_srv = mon_lib_srv, ener_lib = ener_lib, file_name = file_name, keep_monomer_mappings = True, log = sys.stdout).all_chain_proxies total_missing = 0.0 still_missing = 0.0 still_missing_h = [] atom_number = 0 file_name_ = os.path.basename(file_name)+"_h" file = open(file_name_,"w") for monomer_mapping in processed.all_monomer_mappings: atom_number = write_atoms(monomer_mapping, atom_number, file) bond_list = monomer_mapping.monomer.bond_list angle_list = monomer_mapping.monomer.angle_list missing_h = monomer_mapping.missing_hydrogen_atoms.keys() residue_name = monomer_mapping.monomer.chem_comp.three_letter_code print print "Residue name: ", print monomer_mapping.residue_name, monomer_mapping.monomer.chem_comp.three_letter_code print "Missing hydrogen atoms: ", missing_h print total_missing += len(missing_h) unknown_h = [] n_missed = len(missing_h)-1 while n_missed > 0: n_missed -= 1 h = missing_h[0] for bl in bond_list: if(h == bl.atom_id_1 or h == bl.atom_id_2): for atom in (bl.atom_id_1,bl.atom_id_2): if(h != atom): target_atom_name = atom for atom_name,atom in monomer_mapping.expected_atoms.items(): if(atom_name == target_atom_name): target_site = atom.xyz bond_dist = bl.value_dist format="missing %4s: bond: %4s %4s bond distance = %5.3f" print format % (h, bl.atom_id_1, bl.atom_id_2, bl.value_dist) angles = [] for al in angle_list: if(h == al.atom_id_1 or h == al.atom_id_2 or h == al.atom_id_3): format=" %4s: angle: %4s %4s %4s = %5.3f" print format % (h, al.atom_id_1,al.atom_id_2,al.atom_id_3,al.value_angle) angles.append([al.value_angle,al.atom_id_1,al.atom_id_2,al.atom_id_3]) bonded_to_target_site = [] #for bl in bond_list: # if(target_atom_name in (bl.atom_id_1,bl.atom_id_2)): # for atom in (bl.atom_id_1,bl.atom_id_2): # if(atom != target_atom_name): # bonded_to_target_site.append(atom) #print "target_site, bonded_to_target_site ", target_atom_name, bonded_to_target_site ### ring hydrogens: TYR,PHE,HIS,TRP if(residue_name in ["PHE","TYR","HIS","TRP","ARG"]): ring_h = { "HE1":{"PHE":["CE1","CD1","CZ"], "TYR":["CE1","CD1","CZ"], "HIS":["CE1","ND1","NE2"], "TRP":["NE1","CD1","CE2"]}, "HE2":{"PHE":["CE2","CD2","CZ"], "TYR":["CE2","CD2","CZ"], "HIS":["NE2","CE1","CD2"]}, "HE3":{"TRP":["CE3","CZ3","CD2"]}, "HD1":{"PHE":["CD1","CE1","CG"], "TYR":["CD1","CE1","CG"], "HIS":["ND1","CG","CE1"], "TRP":["CD1","CG","NE1"]}, "HD2":{"PHE":["CD2","CE2","CG"], "TYR":["CD2","CE2","CG"], "HIS":["CD2","NE2","CG"]}, "HH2":{"TRP":["CH2","CZ2","CZ3"]}, "HZ" :{"PHE":["CZ","CE1","CE2"]}, "HZ2":{"TRP":["CZ2","CE2","CH2"]}, "HZ3":{"TRP":["CZ3","CH2","CE3"]}, "HE" :{"ARG":["NE","CZ","CD"]} } if(h in ring_h.keys()): if(residue_name in ring_h[h].keys()): targets = ring_h[h][residue_name] print "Building:", h, " ..." site_0 = None site_1 = None site_2 = None for atom_name,atom in monomer_mapping.expected_atoms.items(): if(atom_name == targets[0]): site_0 = atom.xyz if(atom_name == targets[1]): site_1 = atom.xyz if(atom_name == targets[2]): site_2 = atom.xyz alpha = angles[0][0] beta = angles[1][0] assert site_0 is not None and site_1 is not None and site_2 is not None xyz = add_ring_h(site_0,site_1,site_2,bond_dist,alpha,beta) atom_number = write_atoms(monomer_mapping, atom_number, file, new_atom_name = h, new_atom_coordinates = xyz) missing_h.remove(h) ### CA hydrogen(s): HA or/and HA1 or/and HA2 if(h == "HA" or h == "HA1" or h == "HA2"): build_one = False build_two = False if("HA" in missing_h): build_one = True if("HA1" in missing_h and "HA2" in missing_h): build_two = True if(("HA1" in missing_h or "HA2" in missing_h) and build_two == False): build_one = True assert build_one == True and build_two == False or \ build_one == False and build_two == True if(build_two == True): print "Building: HA1 and HA2" site_0 = None site_1 = None site_2 = None for atom_name,atom in monomer_mapping.expected_atoms.items(): if(atom_name == "CA"): site_0 = atom.xyz if(atom_name == "C"): site_1 = atom.xyz if(atom_name == "N"): site_2 = atom.xyz if(site_0 is not None and site_1 is not None and site_2 is not None): for angle in angles: if("C" in angle and "CA" in angle): alpha = angle[0] if("N" in angle and "CA" in angle): beta = angle[0] xyz = add_ca_ha1_and_ha2(site_0,site_1,site_2,bond_dist,alpha,beta) atom_number = write_atoms(monomer_mapping, atom_number, file, new_atom_name = "HA1", new_atom_coordinates = xyz[0]) atom_number = write_atoms(monomer_mapping, atom_number, file, new_atom_name = "HA2", new_atom_coordinates = xyz[1]) missing_h.remove("HA1") missing_h.remove("HA2") if(build_one == True): print "Building: ", h site_0 = None site_1 = None site_2 = None site_3 = None for atom_name,atom in monomer_mapping.expected_atoms.items(): if(atom_name == "CA"): site_0 = atom.xyz if(atom_name == "C"): site_1 = atom.xyz if(atom_name == "N"): site_2 = atom.xyz if(atom_name == "CB" or atom_name == "HA1" or atom_name == "HA2"): site_3 = atom.xyz cb_or_ha1_or_ha2 = atom_name if(site_0 is not None and site_1 is not None and site_2 is not None): for angle in angles: if("C" in angle and "CA" in angle): alpha = angle[0] if("N" in angle and "CA" in angle): beta = angle[0] if("CA" in angle and cb_or_ha1_or_ha2 in angle): gamma = angle[0] xyz = add_ca_ha1_or_ha2(site_0,site_1,site_2,site_3,bond_dist,alpha,beta,gamma) atom_number = write_atoms(monomer_mapping, atom_number, file, new_atom_name = h, new_atom_coordinates = xyz) missing_h.remove(h) ### CB hydrogen(s): HB1 or/and HB2 and similar cb_like_h = { "HB1":[["CB","CA","CG","HB2"],["CB","CA","OG","HB2"],["CB","CA","SG","HB2"]], "HB2":[["CB","CA","CG","HB1"],["CB","CA","OG","HB1"],["CB","CA","SG","HB1"]], "HG1":[["CG","CB","CD","HG2"],], "HG2":[["CG","CB","CD","HG1"],], "HD1":[["CD","CG","NE","HD2"],["CD","CG","CE","HD2"]], "HD2":[["CD","CG","NE","HD1"],["CD","CG","CE","HD1"]], "HE1":[["CE","CD","NZ","HE2"],], "HE2":[["CE","CD","NZ","HE1"],], "HG" :[["CG","CB","CD1","CD2"],], "HB" :[["CB","CG2","CA","CG1"],["CB","CG2","CA","OG1"]] } if(h in cb_like_h.keys()): if(h in missing_h): targets_ = cb_like_h[h] for targets in targets_: build_one = False build_two = False if(h in missing_h and targets[3] in missing_h): build_two = True if((h in missing_h or targets[3] in missing_h) and build_two == False): build_one = True if(build_one == True and build_two == False or \ build_one == False and build_two == True): if(build_two == True): print "Building: ", h," and ",targets[3] site_0 = None site_1 = None site_2 = None for atom_name,atom in monomer_mapping.expected_atoms.items(): if(atom_name == targets[0]): site_0 = atom.xyz if(atom_name == targets[1]): site_1 = atom.xyz if(atom_name == targets[2]): site_2 = atom.xyz if(site_0 is not None and site_1 is not None and site_2 is not None): for angle in angles: if(targets[1] in angle and targets[0] in angle): alpha = angle[0] if(targets[0] in angle and targets[2] in angle): beta = angle[0] xyz = add_ca_ha1_and_ha2(site_0,site_1,site_2,bond_dist,alpha,beta) atom_number = write_atoms(monomer_mapping, atom_number, file, new_atom_name = h, new_atom_coordinates = xyz[0]) atom_number = write_atoms(monomer_mapping, atom_number, file, new_atom_name = targets[3], new_atom_coordinates = xyz[1]) missing_h.remove(h) missing_h.remove(targets[3]) if(build_one == True): print "Building: ", h site_0 = None site_1 = None site_2 = None site_3 = None alpha = None beta = None gamma = None for atom_name,atom in monomer_mapping.expected_atoms.items(): if(atom_name == targets[0]): site_0 = atom.xyz if(atom_name == targets[1]): site_1 = atom.xyz if(atom_name == targets[2]): site_2 = atom.xyz if(atom_name == h or atom_name == targets[3]): site_3 = atom.xyz cb_or_ha1_or_ha2 = atom_name if(site_0 is not None and site_1 is not None and site_2 is not None and site_3 is not None): for angle in angles: if(targets[1] in angle and targets[0] in angle): alpha = angle[0] if(targets[0] in angle and targets[2] in angle): beta = angle[0] if(targets[0] in angle and cb_or_ha1_or_ha2 in angle): gamma = angle[0] if(alpha is not None and beta is not None and gamma is not None): xyz = add_ca_ha1_or_ha2(site_0,site_1,site_2,site_3,bond_dist,alpha,beta,gamma) atom_number = write_atoms(monomer_mapping, atom_number, file, new_atom_name = h, new_atom_coordinates = xyz) missing_h.remove(h) ### HT1,HT2,HT3 like hydrogens; rotational optimization is necessary hhh_like_h = { "HB1" :[["CB","CA","HB2","HB3"],], "HB2" :[["CB","CA","HB1","HB3"],], "HB3" :[["CB","CA","HB1","HB2"],], "HD11":[["CD1","CG","HD12","HD13"],["CD1","CG1","HD12","HD13"]], "HD12":[["CD1","CG","HD11","HD13"],["CD1","CG1","HD11","HD13"]], "HD13":[["CD1","CG","HD11","HD12"],["CD1","CG1","HD11","HD12"]], "HD21":[["CD2","CG","HD22","HD23"],], "HD22":[["CD2","CG","HD21","HD23"],], "HD23":[["CD2","CG","HD21","HD22"],], "HG21":[["CG2","CB","HG22","HG23"],], "HG22":[["CG2","CB","HG21","HG23"],], "HG23":[["CG2","CB","HG21","HG22"],], "HG11":[["CG1","CB","HG12","HG13"],], "HG12":[["CG1","CB","HG11","HG13"],], "HG13":[["CG1","CB","HG11","HG12"],], "HZ1" :[["NZ","CE","HZ2","HZ3"],], "HZ2" :[["NZ","CE","HZ1","HZ3"],], "HZ3" :[["NZ","CE","HZ1","HZ2"],] } hhh_residues = ["ALA","LEU","ILE","VAL","THR","LYS"] if(h in hhh_like_h.keys() and residue_name in hhh_residues and h in missing_h): targets = hhh_like_h[h] for target in targets: site_0 = None site_1 = None for atom_name,atom in monomer_mapping.expected_atoms.items(): if(atom_name == target[0]): site_0 = atom.xyz if(atom_name == target[1]): site_1 = atom.xyz alpha = angles[0][0] beta = angles[2][0] if(site_0 is not None and site_1 is not None): print "Building:", h, " ..." xyz = add_hhh(site_0,site_1,bond_dist,alpha,beta) for atom_name, coordinates in zip((h,target[2],target[3]),(xyz[0],xyz[1][0],xyz[1][1])): atom_number = write_atoms(monomer_mapping, atom_number, file, new_atom_name = atom_name, new_atom_coordinates = coordinates) if(h in missing_h): missing_h.remove(h) if(target[2] in missing_h): missing_h.remove(target[2]) if(target[3] in missing_h): missing_h.remove(target[3]) ### add ARG-like NH's: arg_like_h = { "HH11":[["NH1","CZ","NH2","HH12",2],], "HH12":[["NH1","CZ","NH2","HH11",2],], "HH21":[["NH2","CZ","NH1","HH22",2],], "HH22":[["NH2","CZ","NH1","HH21",2],], "HG" :[["OG","CB","CA","HG",1],["SG","CB","CA","HG",1]] , "HH" :[["OH","CZ","CE1","HH",1],] } residue_names = ["ARG","SER","TYR","CYS"] if(h in arg_like_h.keys() and residue_name in residue_names): targets = arg_like_h[h] for target in targets: site_0 = None site_1 = None site_2 = None for atom_name,atom in monomer_mapping.expected_atoms.items(): if(atom_name == target[0]): site_0 = atom.xyz if(atom_name == target[1]): site_1 = atom.xyz if(atom_name == target[2]): site_2 = atom.xyz alpha = angles[0][0] if(site_0 is not None and site_1 is not None and site_2 is not None): print "Building:", h, " ..." xyz = add_arg_like_h(site_0,site_1,site_2,bond_dist,alpha,flag = target[4]) if(target[4] == 1): atom_number = write_atoms(monomer_mapping, atom_number, file, new_atom_name = h, new_atom_coordinates = xyz) if(target[4] == 2): atom_number = write_atoms(monomer_mapping, atom_number, file, new_atom_name = h, new_atom_coordinates = xyz[0]) atom_number = write_atoms(monomer_mapping, atom_number, file, new_atom_name = target[3], new_atom_coordinates = xyz[1]) if(h in missing_h): missing_h.remove(h) if(target[3] in missing_h): missing_h.remove(target[3]) ### UNKNOWN H: if(h in missing_h): print "Unknown hydrogen type: ", h missing_h.remove(h) unknown_h.append(h) n_missed = len(missing_h) print print "Still missing: ", residue_name,unknown_h still_missing_h.append((residue_name,unknown_h)) still_missing += len(unknown_h) print "Build ", int(total_missing - still_missing), print " from ", int(total_missing), " % = ", print (total_missing - still_missing)*100./total_missing print for item in still_missing_h: print item file.close() file = open(file_name_,"r") processed_pdb_file = pdb_interpretation.process( mon_lib_srv = mon_lib_srv, ener_lib = ener_lib, file_name = file_name_, strict_conflict_handling = False, crystal_symmetry = processed.pdb_inp.crystal_symmetry(), force_symmetry = True, log = sys.stdout) file.close() assert processed_pdb_file.xray_structure() is not None assert processed_pdb_file.geometry_restraints_manager() is not None xray_structure = processed_pdb_file.xray_structure() geometry_restraints_manager = processed_pdb_file.geometry_restraints_manager() regularize_model(xray_structure = xray_structure, geometry_restraints_manager = geometry_restraints_manager, max_iterations = 50000) processed_pdb_file.all_chain_proxies.pdb_atoms.set_xyz( new_xyz=xray_structure.sites_cart()) processed_pdb_file.all_chain_proxies.pdb_hierarchy.write_pdb_file( file_name="out.pdb")
def exercise_1 () : pdb_raw = """\ ATOM 1134 N LYS A 82 5.933 36.285 21.572 1.00 70.94 N ATOM 1135 CA LYS A 82 6.564 37.423 20.931 1.00 76.69 C ATOM 1136 C LYS A 82 5.553 38.547 20.756 1.00 78.75 C ATOM 1137 O LYS A 82 5.325 39.038 19.654 1.00 86.47 O ATOM 1138 CB LYS A 82 7.179 37.024 19.583 1.00 82.32 C ATOM 1139 CG LYS A 82 8.190 38.035 19.048 0.00 70.34 C ATOM 1140 CD LYS A 82 9.429 38.129 19.944 0.00 67.69 C ATOM 1141 CE LYS A 82 9.983 39.545 20.014 0.00 64.44 C ATOM 1142 NZ LYS A 82 10.933 39.832 18.908 0.00 61.45 N ATOM 1143 H LYS A 82 5.139 36.115 21.291 1.00 85.12 H ATOM 1144 HA LYS A 82 7.279 37.749 21.501 1.00 92.03 H ATOM 1145 HB2 LYS A 82 6.469 36.939 18.928 1.00 98.78 H ATOM 1146 HB3 LYS A 82 7.636 36.175 19.687 1.00 98.78 H ATOM 1147 HG2 LYS A 82 8.476 37.762 18.163 0.00 84.41 H ATOM 1148 HG3 LYS A 82 7.775 38.912 19.011 0.00 84.41 H ATOM 1149 HD2 LYS A 82 9.193 37.853 20.843 0.00 81.23 H ATOM 1150 HD3 LYS A 82 10.122 37.551 19.589 0.00 81.23 H ATOM 1151 HE2 LYS A 82 9.249 40.177 19.952 0.00 77.33 H ATOM 1152 HE3 LYS A 82 10.453 39.662 20.854 0.00 77.33 H ATOM 1153 HZ1 LYS A 82 11.237 40.666 18.977 0.00 73.75 H ATOM 1154 HZ2 LYS A 82 10.523 39.738 18.123 0.00 73.75 H ATOM 1155 HZ3 LYS A 82 11.621 39.269 18.944 0.00 73.75 H ATOM 1156 N LYS A 83 4.936 38.927 21.866 1.00 75.79 N ATOM 1157 CA LYS A 83 4.177 40.172 21.966 1.00 82.80 C ATOM 1158 C LYS A 83 4.081 40.508 23.460 1.00 86.23 C ATOM 1159 O LYS A 83 2.978 40.521 24.017 1.00 79.81 O ATOM 1160 CB LYS A 83 2.790 40.044 21.332 1.00 79.16 C ATOM 1161 CG LYS A 83 2.038 41.342 21.175 0.00 70.42 C ATOM 1162 CD LYS A 83 2.072 41.803 19.735 0.00 66.90 C ATOM 1163 CE LYS A 83 1.295 43.089 19.552 0.00 62.46 C ATOM 1164 NZ LYS A 83 1.004 43.350 18.118 0.00 60.73 N ATOM 1165 H LYS A 83 4.940 38.470 22.594 1.00 90.95 H ATOM 1166 HA LYS A 83 4.658 40.885 21.518 1.00 99.36 H ATOM 1167 HB2 LYS A 83 2.251 39.459 21.887 1.00 95.00 H ATOM 1168 HB3 LYS A 83 2.890 39.655 20.449 1.00 95.00 H ATOM 1169 HG2 LYS A 83 1.113 41.213 21.435 0.00 84.51 H ATOM 1170 HG3 LYS A 83 2.453 42.024 21.726 0.00 84.51 H ATOM 1171 HD2 LYS A 83 2.992 41.962 19.471 0.00 80.28 H ATOM 1172 HD3 LYS A 83 1.672 41.123 19.171 0.00 80.28 H ATOM 1173 HE2 LYS A 83 0.452 43.024 20.027 0.00 74.95 H ATOM 1174 HE3 LYS A 83 1.818 43.830 19.896 0.00 74.95 H ATOM 1175 HZ1 LYS A 83 0.521 42.683 17.780 0.00 72.87 H ATOM 1176 HZ2 LYS A 83 1.764 43.417 17.661 0.00 72.87 H ATOM 1177 HZ3 LYS A 83 0.548 44.109 18.034 0.00 72.87 H ATOM 3630 N ASN A 242 -5.454 -3.027 1.145 0.00 67.69 N ATOM 3631 CA ASN A 242 -4.759 -2.535 -0.037 0.00 65.44 C ATOM 3632 C ASN A 242 -5.734 -2.397 -1.208 0.00 63.57 C ATOM 3633 O ASN A 242 -6.425 -3.357 -1.552 0.00 63.94 O ATOM 3634 CB ASN A 242 -3.626 -3.503 -0.392 0.00 63.13 C ATOM 3635 CG ASN A 242 -2.802 -3.044 -1.576 0.00 63.58 C ATOM 3636 OD1 ASN A 242 -2.524 -1.862 -1.731 0.00 65.52 O ATOM 3637 ND2 ASN A 242 -2.399 -3.988 -2.416 0.00 62.17 N ATOM 3638 H ASN A 242 -5.562 -3.880 1.129 0.00 81.22 H ATOM 3639 HA ASN A 242 -4.375 -1.665 0.151 0.00 78.53 H ATOM 3640 HB2 ASN A 242 -3.032 -3.587 0.370 0.00 75.76 H ATOM 3641 HB3 ASN A 242 -4.007 -4.368 -0.611 0.00 75.76 H ATOM 3642 HD21 ASN A 242 -1.929 -3.779 -3.104 0.00 74.60 H ATOM 3643 HD22 ASN A 242 -2.609 -4.810 -2.272 0.00 74.60 H ATOM 2 CA ALYS A 32 10.574 8.177 11.768 0.40 71.49 C ATOM 3 CB ALYS A 32 9.197 8.686 12.246 0.40 74.71 C ATOM 2 CA BLYS A 32 10.574 8.177 11.768 0.40 71.49 C ATOM 3 CB BLYS A 32 9.197 8.686 12.246 0.40 74.71 C ATOM 5 CA AVAL A 33 11.708 5.617 14.332 0.50 71.42 C ATOM 6 CB AVAL A 33 11.101 4.227 14.591 0.50 71.47 C ATOM 5 CA BVAL A 33 11.708 5.617 14.332 0.40 71.42 C ATOM 6 CB BVAL A 33 11.101 4.227 14.591 0.40 71.47 C TER ATOM 1 N GLU X 18 -13.959 12.159 -6.598 1.00260.08 N ATOM 2 CA GLU X 18 -13.297 13.465 -6.628 1.00269.83 C ATOM 3 C GLU X 18 -11.946 13.282 -7.309 1.00269.18 C ATOM 4 CB GLU X 18 -13.128 14.035 -5.210 1.00261.96 C ATOM 5 CG GLU X 18 -14.455 14.401 -4.522 1.00263.56 C ATOM 6 CD GLU X 18 -14.291 15.239 -3.242 1.00264.89 C ATOM 7 OE1 GLU X 18 -14.172 14.646 -2.143 1.00264.24 O ATOM 8 OE2 GLU X 18 -14.309 16.498 -3.306 1.00264.37 O1- HETATM 614 S SO4 B 101 14.994 20.601 10.862 0.00 7.02 S HETATM 615 O1 SO4 B 101 14.234 20.194 12.077 0.00 7.69 O HETATM 616 O2 SO4 B 101 14.048 21.062 9.850 0.00 9.28 O HETATM 617 O3 SO4 B 101 15.905 21.686 11.261 0.00 8.01 O HETATM 618 O4 SO4 B 101 15.772 19.454 10.371 0.00 8.18 O TER HETATM 122 O HOH S 1 5.334 8.357 8.032 1.00 0.00 O HETATM 123 O HOH S 2 5.396 15.243 10.734 1.00202.95 O HETATM 124 O HOH S 3 -25.334 18.357 18.032 0.00 20.00 O """ mon_lib_srv = server.server() ener_lib = server.ener_lib() pdb_in = iotbx.pdb.hierarchy.input(pdb_string=pdb_raw) xrs = pdb_in.input.xray_structure_simple() processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, raw_records=pdb_in.hierarchy.as_pdb_string(crystal_symmetry=xrs), crystal_symmetry=xrs, log=null_out()) pdb_in.hierarchy.atoms().reset_i_seq() mstats = model_properties.model_statistics( pdb_hierarchy=pdb_in.hierarchy, xray_structure=xrs, all_chain_proxies=processed_pdb_file.all_chain_proxies, ignore_hd=True) out = StringIO() mstats.show(out=out) #print out.getvalue() assert not show_diff(out.getvalue(), """\ Overall: Number of atoms = 50 (anisotropic = 0) B_iso: mean = 96.0 max = 269.8 min = 0.0 Occupancy: mean = 0.47 max = 1.00 min = 0.00 warning: 22 atoms with zero occupancy 67 total B-factor or occupancy problem(s) detected Atoms or residues with zero occupancy: LYS A 82 CG occ=0.00 LYS A 82 CD occ=0.00 LYS A 82 CE occ=0.00 LYS A 82 NZ occ=0.00 LYS A 83 CG occ=0.00 LYS A 83 CD occ=0.00 LYS A 83 CE occ=0.00 LYS A 83 NZ occ=0.00 ASN A 242 (all) occ=0.00 SO4 B 101 (all) occ=0.00 HOH S 3 O occ=0.00 Macromolecules: Number of atoms = 42 (anisotropic = 0) B_iso: mean = 108.0 max = 269.8 min = 60.7 Occupancy: mean = 0.51 max = 1.00 min = 0.00 warning: 16 atoms with zero occupancy 57 total B-factor or occupancy problem(s) detected Ligands: Number of atoms = 5 (anisotropic = 0) B_iso: mean = 8.0 max = 9.3 min = 7.0 Occupancy: mean = 0.00 max = 0.00 min = 0.00 warning: 5 atoms with zero occupancy 6 total B-factor or occupancy problem(s) detected Waters: Number of atoms = 3 (anisotropic = 0) B_iso: mean = 74.3 max = 202.9 min = 0.0 Occupancy: mean = 0.67 max = 1.00 min = 0.00 warning: 1 atoms with zero occupancy 4 total B-factor or occupancy problem(s) detected (Hydrogen atoms not included in overall counts.) """) assert (len(mstats.all.bad_adps) == 1) assert (mstats.all.n_zero_b == 1) mstats2 = loads(dumps(mstats)) out1 = StringIO() out2 = StringIO() mstats.show(out=out1) mstats2.show(out=out2) assert (out1.getvalue() == out2.getvalue()) # now with ignore_hd=False mstats3 = model_properties.model_statistics( pdb_hierarchy=pdb_in.hierarchy, xray_structure=xrs, all_chain_proxies=processed_pdb_file.all_chain_proxies, ignore_hd=False) out2 = StringIO() mstats3.show(out=out2) assert (out2.getvalue() != out.getvalue()) assert (""" LYS A 83 HZ3 occ=0.00""" in out2.getvalue()) outliers = mstats3.all.as_gui_table_data(include_zoom=True) assert (len(outliers) == 84) # test with all_chain_proxies undefined mstats4 = model_properties.model_statistics( pdb_hierarchy=pdb_in.hierarchy, xray_structure=xrs, all_chain_proxies=None, ignore_hd=False) outliers = mstats4.all.as_gui_table_data(include_zoom=True) assert (len(outliers) == 84)
import iotbx import time from iotbx import pdb from mmtbx import * from mmtbx.monomer_library import server from mmtbx.monomer_library import pdb_interpretation from mmtbx.conformation_dependent_library import generate_protein_fragments hierarchy = pdb_inp.construct_hierarchy() mon_lib_srv = server.server() ener_lib = server.ener_lib() processed_pdb = pdb_interpretation.process(self.mon_lib_srv, self.ener_lib, file_name=pdb_file_name, raw_records=raw_records) geometry_restraints_manager = processed_pdb.geometry_restraints_manager() # generate five ca def generate_ca(self): t0 = time.time() self.hierarchy.reset_atom_i_seqs() self.hierarchy.reset_i_seq_if_necessary() for five in generate_protein_fragments(self.hierarchy, self.geometry_restraints_manager, length=5): rc = [] for atom in five.atoms(): if atom.name == ' CA ': rc.append(atom) if len(rc) == 5:
def run(args): """ I suggest adding here: cctbx_project/mmtbx/validation/regression/tst_mp_geo.py test cases with just .pdb, without arguments, etc. """ master_phil = get_master_phil() import iotbx.phil input_objects = iotbx.phil.process_command_line_with_files( args=args, master_phil=master_phil, pdb_file_def="mp_geo.pdb") work_params = input_objects.work.extract() assert len(work_params.mp_geo.pdb) == 1, "Need a model file to run" file_name = work_params.mp_geo.pdb[0] out_file = None if work_params.mp_geo.out_file != None: out_file = work_params.mp_geo.out_file do_bonds_and_angles = work_params.mp_geo.bonds_and_angles do_kinemage = work_params.mp_geo.kinemage do_rna_backbone = work_params.mp_geo.rna_backbone outliers_only = work_params.mp_geo.outliers_only use_cdl = work_params.mp_geo.cdl log = StringIO() basename = os.path.basename(file_name) if out_file == None: import sys out = sys.stdout else: if do_bonds_and_angles: out = file(out_file, 'w') elif do_kinemage: out = file(out_file, 'a') elif do_rna_backbone: out = file(out_file, 'w') restraints_loading_flags = {} restraints_loading_flags["use_neutron_distances"] = False from mmtbx.validation import utils params = pdb_interpretation.master_params.extract() params.restraints_library.cdl = use_cdl params.clash_guard.nonbonded_distance_threshold = None processed_pdb_file = pdb_interpretation.process( params=params, mon_lib_srv=server.server(), ener_lib=server.ener_lib(), file_name=file_name, strict_conflict_handling=True, restraints_loading_flags=restraints_loading_flags, force_symmetry=True, substitute_non_crystallographic_unit_cell_if_necessary=True, log=log) grm = processed_pdb_file.geometry_restraints_manager() use_segids = utils.use_segids_in_place_of_chainids( hierarchy=processed_pdb_file.all_chain_proxies.pdb_hierarchy) if do_bonds_and_angles or do_kinemage: rc = get_bond_and_angle_outliers( pdb_hierarchy=processed_pdb_file.all_chain_proxies.pdb_hierarchy, xray_structure=processed_pdb_file.xray_structure(), geometry_restraints_manager=grm, use_segids=use_segids, outliers_only=outliers_only) #get chain types chain_types = {} for chain in processed_pdb_file.all_chain_proxies.\ pdb_hierarchy.models()[0].chains(): if use_segids: chain_id = utils.get_segid_as_chainid(chain=chain) else: chain_id = chain.id main_conf = chain.conformers()[0] if chain_types.get(chain_id) not in ["NA", "PROTEIN"]: if (main_conf.is_na()): chain_types[chain_id] = "NA" elif (main_conf.is_protein()): chain_types[chain_id] = "PROTEIN" else: chain_types[chain_id] = "UNK" outliers = [] #bonds #for result in rc.bonds.results: for result in sorted( rc.bonds.results, key=lambda x: (x.atoms_info[0].resseq, get_altloc(atoms_info=x.atoms_info), get_atoms_str(atoms_info=x.atoms_info))): atom_info = result.atoms_info[0] # label:chain:number:ins:alt:type:measure:value:sigmas:class atoms_str = get_atoms_str(atoms_info=result.atoms_info) altloc = get_altloc(atoms_info=result.atoms_info) chain_id = atom_info.chain_id outliers.append([ chain_id, atom_info.resseq, atom_info.icode, altloc, atom_info.resname, atoms_str, result.model, result.score, chain_types[atom_info.chain_id] ]) #angles #for result in rc.angles.results: for result in sorted( rc.angles.results, key=lambda x: (x.atoms_info[0].resseq, get_altloc(atoms_info=x.atoms_info), get_atoms_str(atoms_info=x.atoms_info))): atom_info = result.atoms_info[0] # label:chain:number:ins:alt:type:measure:value:sigmas:class atoms_str = get_atoms_str(atoms_info=result.atoms_info) altloc = get_altloc(atoms_info=result.atoms_info) chain_id = atom_info.chain_id outliers.append([ chain_id, atom_info.resseq, atom_info.icode, altloc, atom_info.resname, atoms_str, result.model, result.score, chain_types[atom_info.chain_id] ]) if do_bonds_and_angles: for outlier in outliers: print >> out, "%s:%2s:%s:%s:%s:%s:%s:%.3f:%.3f:%s" % ( basename, outlier[0], outlier[1], outlier[2], outlier[3], outlier[4], outlier[5], outlier[6], outlier[7], outlier[8]) elif do_kinemage: print >> out, rc.bonds.kinemage_header for result in rc.bonds.results: print >> out, result.as_kinemage() print >> out, rc.angles.kinemage_header for result in rc.angles.results: print >> out, result.as_kinemage() out.close() elif do_rna_backbone: from mmtbx.validation import utils rna_bb = utils.get_rna_backbone_dihedrals(processed_pdb_file) print >> out, rna_bb if out_file is not None: out.close()
def run(args): master_phil = get_master_phil() import iotbx.utils input_objects = iotbx.utils.process_command_line_inputs( args=args, master_phil=master_phil, input_types=("pdb",)) work_phil = master_phil.fetch(sources=input_objects["phil"]) work_params = work_phil.extract() file_name = work_params.mp_geo.pdb out_file = None if work_params.mp_geo.out_file != None: out_file = work_params.mp_geo.out_file do_bonds_and_angles = work_params.mp_geo.bonds_and_angles do_kinemage = work_params.mp_geo.kinemage do_rna_backbone = work_params.mp_geo.rna_backbone outliers_only = work_params.mp_geo.outliers_only use_cdl = work_params.mp_geo.cdl log = StringIO() basename = os.path.basename(file_name) if do_bonds_and_angles: out = file(out_file, 'w') elif do_kinemage: out = file(out_file, 'a') elif do_rna_backbone: if out_file == None: import sys out = sys.stdout else: out = file(out_file, 'w') restraints_loading_flags = {} restraints_loading_flags["use_neutron_distances"]=False from mmtbx.validation import utils params = pdb_interpretation.master_params.extract() params.restraints_library.cdl = use_cdl params.clash_guard.nonbonded_distance_threshold = None processed_pdb_file = pdb_interpretation.process( params = params, mon_lib_srv = server.server(), ener_lib = server.ener_lib(), file_name = file_name, strict_conflict_handling = True, restraints_loading_flags = restraints_loading_flags, force_symmetry = True, substitute_non_crystallographic_unit_cell_if_necessary=True, log = log) grm = processed_pdb_file.geometry_restraints_manager() use_segids = utils.use_segids_in_place_of_chainids( hierarchy=processed_pdb_file.all_chain_proxies.pdb_hierarchy) if do_bonds_and_angles or do_kinemage: rc = get_bond_and_angle_outliers( pdb_hierarchy=processed_pdb_file.all_chain_proxies.pdb_hierarchy, xray_structure=processed_pdb_file.xray_structure(), geometry_restraints_manager=grm, use_segids=use_segids, outliers_only=outliers_only) #get chain types chain_types = {} for chain in processed_pdb_file.all_chain_proxies.\ pdb_hierarchy.models()[0].chains() : if use_segids: chain_id = utils.get_segid_as_chainid(chain=chain) else: chain_id = chain.id main_conf = chain.conformers()[0] if chain_types.get(chain_id) not in ["NA", "PROTEIN"]: if (main_conf.is_na()) : chain_types[chain_id] = "NA" elif (main_conf.is_protein()): chain_types[chain_id] = "PROTEIN" else: chain_types[chain_id] = "UNK" outliers = [] #bonds for result in rc.bonds.results: atom_info = result.atoms_info[0] # label:chain:number:ins:alt:type:measure:value:sigmas:class atoms_str = get_atoms_str(atoms_info=result.atoms_info) altloc = get_altloc(atoms_info=result.atoms_info) chain_id = atom_info.chain_id outliers.append( [chain_id, atom_info.resseq, atom_info.icode, altloc, atom_info.resname, atoms_str, result.model, result.score, chain_types[atom_info.chain_id]] ) #angles for result in rc.angles.results: atom_info = result.atoms_info[0] # label:chain:number:ins:alt:type:measure:value:sigmas:class atoms_str = get_atoms_str(atoms_info=result.atoms_info) altloc = get_altloc(atoms_info=result.atoms_info) chain_id = atom_info.chain_id outliers.append( [chain_id, atom_info.resseq, atom_info.icode, altloc, atom_info.resname, atoms_str, result.model, result.score, chain_types[atom_info.chain_id]] ) if do_bonds_and_angles: for outlier in outliers: print >> out, "%s:%2s:%s:%s:%s:%s:%s:%.3f:%.3f:%s" % ( basename, outlier[0], outlier[1], outlier[2], outlier[3], outlier[4], outlier[5], outlier[6], outlier[7], outlier[8]) elif do_kinemage: print >> out, rc.bonds.kinemage_header for result in rc.bonds.results: print >> out, result.as_kinemage() print >> out, rc.angles.kinemage_header for result in rc.angles.results: print >> out, result.as_kinemage() out.close() elif do_rna_backbone: from mmtbx.validation import utils rna_bb = utils.get_rna_backbone_dihedrals(processed_pdb_file) print >> out, rna_bb if out_file is not None: out.close()
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"] if work_params.quiet : out = cStringIO.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 >> out, "Symmetry information is corrupted, " else: print >> out, "Symmetry information was not found, " print >> out, "putting molecule in P1 box." 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() from mmtbx.monomer_library import pdb_interpretation, server import mmtbx import mmtbx.command_line.geometry_minimization mon_lib_srv = server.server() ener_lib = server.ener_lib() defpars = mmtbx.command_line.geometry_minimization.master_params().extract() defpars.pdb_interpretation.automatic_linking.link_carbohydrates=False defpars.pdb_interpretation.c_beta_restraints=False defpars.pdb_interpretation.clash_guard.nonbonded_distance_threshold=None processed_pdb_file = pdb_interpretation.process( mon_lib_srv = mon_lib_srv, ener_lib = ener_lib, pdb_inp = pdb_structure, crystal_symmetry = cs, params = defpars.pdb_interpretation, force_symmetry = True) pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy geometry = processed_pdb_file.geometry_restraints_manager() geometry.pair_proxies(processed_pdb_file.xray_structure().sites_cart()) pdb_hierarchy.atoms().reset_i_seq() if len(pdb_hierarchy.models()) != 1 : raise Sorry("Multiple models not supported.") ss_from_file = None if hasattr(pdb_structure, "extract_secondary_structure"): 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 = cStringIO.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 >> result_out, comment if (prefix_scope != "") : print >> result_out, "%s {" % prefix_scope 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 >> result_out, "}" elif work_params.format == "pdb": print >> result_out, m.actual_sec_str.as_pdb_str() elif work_params.format == "phenix_bonds" : raise Sorry("Not yet implemented.") elif work_params.format in ["pymol", "refmac", "kinemage"] : m.show_summary(log=out) (hb_proxies, hb_angle_proxies, planarity_proxies, parallelity_proxies) = m.create_all_new_restraints( pdb_hierarchy=pdb_hierarchy, grm=geometry, log=out) if hb_proxies.size() > 0: if work_params.format == "pymol" : 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) else : bonds_in_format = hb_proxies.as_refmac_restraints( pdb_hierarchy=pdb_hierarchy) print >> result_out, bonds_in_format result = result_out.getvalue() filename = "%s_ss.eff" %os.path.basename(work_params.file_name[0]) outf = open(filename, "w") outf.write(result) outf.close() print >> out, result return os.path.abspath(filename)
def exercise_1(): pdb_raw = """\ ATOM 1134 N LYS A 82 5.933 36.285 21.572 1.00 70.94 N ATOM 1135 CA LYS A 82 6.564 37.423 20.931 1.00 76.69 C ATOM 1136 C LYS A 82 5.553 38.547 20.756 1.00 78.75 C ATOM 1137 O LYS A 82 5.325 39.038 19.654 1.00 86.47 O ATOM 1138 CB LYS A 82 7.179 37.024 19.583 1.00 82.32 C ATOM 1139 CG LYS A 82 8.190 38.035 19.048 0.00 70.34 C ATOM 1140 CD LYS A 82 9.429 38.129 19.944 0.00 67.69 C ATOM 1141 CE LYS A 82 9.983 39.545 20.014 0.00 64.44 C ATOM 1142 NZ LYS A 82 10.933 39.832 18.908 0.00 61.45 N ATOM 1143 H LYS A 82 5.139 36.115 21.291 1.00 85.12 H ATOM 1144 HA LYS A 82 7.279 37.749 21.501 1.00 92.03 H ATOM 1145 HB2 LYS A 82 6.469 36.939 18.928 1.00 98.78 H ATOM 1146 HB3 LYS A 82 7.636 36.175 19.687 1.00 98.78 H ATOM 1147 HG2 LYS A 82 8.476 37.762 18.163 0.00 84.41 H ATOM 1148 HG3 LYS A 82 7.775 38.912 19.011 0.00 84.41 H ATOM 1149 HD2 LYS A 82 9.193 37.853 20.843 0.00 81.23 H ATOM 1150 HD3 LYS A 82 10.122 37.551 19.589 0.00 81.23 H ATOM 1151 HE2 LYS A 82 9.249 40.177 19.952 0.00 77.33 H ATOM 1152 HE3 LYS A 82 10.453 39.662 20.854 0.00 77.33 H ATOM 1153 HZ1 LYS A 82 11.237 40.666 18.977 0.00 73.75 H ATOM 1154 HZ2 LYS A 82 10.523 39.738 18.123 0.00 73.75 H ATOM 1155 HZ3 LYS A 82 11.621 39.269 18.944 0.00 73.75 H ATOM 1156 N LYS A 83 4.936 38.927 21.866 1.00 75.79 N ATOM 1157 CA LYS A 83 4.177 40.172 21.966 1.00 82.80 C ATOM 1158 C LYS A 83 4.081 40.508 23.460 1.00 86.23 C ATOM 1159 O LYS A 83 2.978 40.521 24.017 1.00 79.81 O ATOM 1160 CB LYS A 83 2.790 40.044 21.332 1.00 79.16 C ATOM 1161 CG LYS A 83 2.038 41.342 21.175 0.00 70.42 C ATOM 1162 CD LYS A 83 2.072 41.803 19.735 0.00 66.90 C ATOM 1163 CE LYS A 83 1.295 43.089 19.552 0.00 62.46 C ATOM 1164 NZ LYS A 83 1.004 43.350 18.118 0.00 60.73 N ATOM 1165 H LYS A 83 4.940 38.470 22.594 1.00 90.95 H ATOM 1166 HA LYS A 83 4.658 40.885 21.518 1.00 99.36 H ATOM 1167 HB2 LYS A 83 2.251 39.459 21.887 1.00 95.00 H ATOM 1168 HB3 LYS A 83 2.890 39.655 20.449 1.00 95.00 H ATOM 1169 HG2 LYS A 83 1.113 41.213 21.435 0.00 84.51 H ATOM 1170 HG3 LYS A 83 2.453 42.024 21.726 0.00 84.51 H ATOM 1171 HD2 LYS A 83 2.992 41.962 19.471 0.00 80.28 H ATOM 1172 HD3 LYS A 83 1.672 41.123 19.171 0.00 80.28 H ATOM 1173 HE2 LYS A 83 0.452 43.024 20.027 0.00 74.95 H ATOM 1174 HE3 LYS A 83 1.818 43.830 19.896 0.00 74.95 H ATOM 1175 HZ1 LYS A 83 0.521 42.683 17.780 0.00 72.87 H ATOM 1176 HZ2 LYS A 83 1.764 43.417 17.661 0.00 72.87 H ATOM 1177 HZ3 LYS A 83 0.548 44.109 18.034 0.00 72.87 H ATOM 3630 N ASN A 242 -5.454 -3.027 1.145 0.00 67.69 N ATOM 3631 CA ASN A 242 -4.759 -2.535 -0.037 0.00 65.44 C ATOM 3632 C ASN A 242 -5.734 -2.397 -1.208 0.00 63.57 C ATOM 3633 O ASN A 242 -6.425 -3.357 -1.552 0.00 63.94 O ATOM 3634 CB ASN A 242 -3.626 -3.503 -0.392 0.00 63.13 C ATOM 3635 CG ASN A 242 -2.802 -3.044 -1.576 0.00 63.58 C ATOM 3636 OD1 ASN A 242 -2.524 -1.862 -1.731 0.00 65.52 O ATOM 3637 ND2 ASN A 242 -2.399 -3.988 -2.416 0.00 62.17 N ATOM 3638 H ASN A 242 -5.562 -3.880 1.129 0.00 81.22 H ATOM 3639 HA ASN A 242 -4.375 -1.665 0.151 0.00 78.53 H ATOM 3640 HB2 ASN A 242 -3.032 -3.587 0.370 0.00 75.76 H ATOM 3641 HB3 ASN A 242 -4.007 -4.368 -0.611 0.00 75.76 H ATOM 3642 HD21 ASN A 242 -1.929 -3.779 -3.104 0.00 74.60 H ATOM 3643 HD22 ASN A 242 -2.609 -4.810 -2.272 0.00 74.60 H ATOM 2 CA ALYS A 32 10.574 8.177 11.768 0.40 71.49 C ATOM 3 CB ALYS A 32 9.197 8.686 12.246 0.40 74.71 C ATOM 2 CA BLYS A 32 10.574 8.177 11.768 0.40 71.49 C ATOM 3 CB BLYS A 32 9.197 8.686 12.246 0.40 74.71 C ATOM 5 CA AVAL A 33 11.708 5.617 14.332 0.50 71.42 C ATOM 6 CB AVAL A 33 11.101 4.227 14.591 0.50 71.47 C ATOM 5 CA BVAL A 33 11.708 5.617 14.332 0.40 71.42 C ATOM 6 CB BVAL A 33 11.101 4.227 14.591 0.40 71.47 C TER ATOM 1 N GLU X 18 -13.959 12.159 -6.598 1.00260.08 N ATOM 2 CA GLU X 18 -13.297 13.465 -6.628 1.00269.83 C ATOM 3 C GLU X 18 -11.946 13.282 -7.309 1.00269.18 C ATOM 4 CB GLU X 18 -13.128 14.035 -5.210 1.00261.96 C ATOM 5 CG GLU X 18 -14.455 14.401 -4.522 1.00263.56 C ATOM 6 CD GLU X 18 -14.291 15.239 -3.242 1.00264.89 C ATOM 7 OE1 GLU X 18 -14.172 14.646 -2.143 1.00264.24 O ATOM 8 OE2 GLU X 18 -14.309 16.498 -3.306 1.00264.37 O1- HETATM 614 S SO4 B 101 14.994 20.601 10.862 0.00 7.02 S HETATM 615 O1 SO4 B 101 14.234 20.194 12.077 0.00 7.69 O HETATM 616 O2 SO4 B 101 14.048 21.062 9.850 0.00 9.28 O HETATM 617 O3 SO4 B 101 15.905 21.686 11.261 0.00 8.01 O HETATM 618 O4 SO4 B 101 15.772 19.454 10.371 0.00 8.18 O TER HETATM 122 O HOH S 1 5.334 8.357 8.032 1.00 0.00 O HETATM 123 O HOH S 2 5.396 15.243 10.734 1.00202.95 O HETATM 124 O HOH S 3 -25.334 18.357 18.032 0.00 20.00 O """ mon_lib_srv = server.server() ener_lib = server.ener_lib() pdb_in = iotbx.pdb.hierarchy.input(pdb_string=pdb_raw) xrs = pdb_in.input.xray_structure_simple() processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, raw_records=pdb_in.hierarchy.as_pdb_string(crystal_symmetry=xrs), crystal_symmetry=xrs, log=null_out()) pdb_in.hierarchy.atoms().reset_i_seq() mstats = model_properties.model_statistics( pdb_hierarchy=pdb_in.hierarchy, xray_structure=xrs, all_chain_proxies=processed_pdb_file.all_chain_proxies, ignore_hd=True) out = StringIO() mstats.show(out=out) #print out.getvalue() assert not show_diff( out.getvalue(), """\ Overall: Number of atoms = 50 (anisotropic = 0) B_iso: mean = 96.0 max = 269.8 min = 0.0 Occupancy: mean = 0.47 max = 1.00 min = 0.00 warning: 22 atoms with zero occupancy 69 total B-factor or occupancy problem(s) detected Atoms or residues with zero occupancy: LYS A 82 CG occ=0.00 LYS A 82 CD occ=0.00 LYS A 82 CE occ=0.00 LYS A 82 NZ occ=0.00 LYS A 83 CG occ=0.00 LYS A 83 CD occ=0.00 LYS A 83 CE occ=0.00 LYS A 83 NZ occ=0.00 ASN A 242 (all) occ=0.00 SO4 B 101 (all) occ=0.00 HOH S 3 O occ=0.00 Macromolecules: Number of atoms = 42 (anisotropic = 0) B_iso: mean = 108.0 max = 269.8 min = 60.7 Occupancy: mean = 0.51 max = 1.00 min = 0.00 warning: 16 atoms with zero occupancy 59 total B-factor or occupancy problem(s) detected Ligands: Number of atoms = 5 (anisotropic = 0) B_iso: mean = 8.0 max = 9.3 min = 7.0 Occupancy: mean = 0.00 max = 0.00 min = 0.00 warning: 5 atoms with zero occupancy 6 total B-factor or occupancy problem(s) detected Waters: Number of atoms = 3 (anisotropic = 0) B_iso: mean = 74.3 max = 202.9 min = 0.0 Occupancy: mean = 0.67 max = 1.00 min = 0.00 warning: 1 atoms with zero occupancy 4 total B-factor or occupancy problem(s) detected (Hydrogen atoms not included in overall counts.) """) assert (len(mstats.all.bad_adps) == 1) assert (mstats.all.n_zero_b == 1) mstats2 = loads(dumps(mstats)) out1 = StringIO() out2 = StringIO() mstats.show(out=out1) mstats2.show(out=out2) assert (out1.getvalue() == out2.getvalue()) # now with ignore_hd=False mstats3 = model_properties.model_statistics( pdb_hierarchy=pdb_in.hierarchy, xray_structure=xrs, all_chain_proxies=processed_pdb_file.all_chain_proxies, ignore_hd=False) out2 = StringIO() mstats3.show(out=out2) assert (out2.getvalue() != out.getvalue()) assert (""" LYS A 83 HZ3 occ=0.00""" in out2.getvalue()) outliers = mstats3.all.as_gui_table_data(include_zoom=True) assert (len(outliers) == 86) # test with all_chain_proxies undefined mstats4 = model_properties.model_statistics(pdb_hierarchy=pdb_in.hierarchy, xray_structure=xrs, all_chain_proxies=None, ignore_hd=False) outliers = mstats4.all.as_gui_table_data(include_zoom=True) assert (len(outliers) == 86)
def exercise_2(mon_lib_srv, ener_lib): for use_reference in [True, False, None]: processed_pdb_file = pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, raw_records=flex.std_string(pdb_str_2.splitlines()), strict_conflict_handling=True, force_symmetry=True, log=None) grm = processed_pdb_file.geometry_restraints_manager() xrs2 = processed_pdb_file.xray_structure(show_summary=False) awl2 = processed_pdb_file.all_chain_proxies.pdb_hierarchy.atoms_with_labels( ) pdb_inp3 = iotbx.pdb.input(source_info=None, lines=pdb_str_3) xrs3 = pdb_inp3.xray_structure_simple() ph3 = pdb_inp3.construct_hierarchy() ph3.atoms().reset_i_seq() awl3 = ph3.atoms_with_labels() sites_cart_reference = flex.vec3_double() selection = flex.size_t() reference_names = ["CG", "CD", "NE", "CZ", "NH1", "NH2"] for a2, a3 in zip(tuple(awl2), tuple(awl3)): assert a2.resname == a3.resname assert a2.name == a3.name assert a2.i_seq == a3.i_seq if (a2.resname == "ARG" and a2.name.strip() in reference_names): selection.append(a2.i_seq) sites_cart_reference.append(a3.xyz) assert selection.size() == len(reference_names) selection_bool = flex.bool(xrs2.scatterers().size(), selection) if (use_reference): grm.adopt_reference_coordinate_restraints_in_place( reference.add_coordinate_restraints( sites_cart=sites_cart_reference, selection=selection, sigma=0.01)) elif (use_reference is None): grm.adopt_reference_coordinate_restraints_in_place( reference.add_coordinate_restraints( sites_cart=sites_cart_reference, selection=selection, sigma=0.01)) grm.remove_reference_coordinate_restraints_in_place( selection=selection) d1 = flex.mean( flex.sqrt((xrs2.sites_cart().select(selection) - xrs3.sites_cart().select(selection)).dot())) print "distance start (use_reference: %s): %6.4f" % ( str(use_reference), d1) assert d1 > 4.0 assert approx_equal( flex.max( flex.sqrt((xrs2.sites_cart().select(~selection_bool) - xrs3.sites_cart().select(~selection_bool)).dot())), 0) from cctbx import geometry_restraints import mmtbx.refinement.geometry_minimization import scitbx.lbfgs grf = geometry_restraints.flags.flags(default=True) sites_cart = xrs2.sites_cart() minimized = mmtbx.refinement.geometry_minimization.lbfgs( sites_cart=sites_cart, correct_special_position_tolerance=1.0, geometry_restraints_manager=grm, sites_cart_selection=flex.bool(sites_cart.size(), selection), geometry_restraints_flags=grf, lbfgs_termination_params=scitbx.lbfgs.termination_parameters( max_iterations=5000)) xrs2.set_sites_cart(sites_cart=sites_cart) d2 = flex.mean( flex.sqrt((xrs2.sites_cart().select(selection) - xrs3.sites_cart().select(selection)).dot())) print "distance final (use_reference: %s): %6.4f" % ( str(use_reference), d2) if (use_reference): assert d2 < 0.005, "failed: %f<0.05" % d2 else: assert d2 > 4.0, d2 assert approx_equal( flex.max( flex.sqrt((xrs2.sites_cart().select(~selection_bool) - xrs3.sites_cart().select(~selection_bool)).dot())), 0)