def exercise(): from mmtbx.regression.make_fake_anomalous_data import generate_zinc_inputs base = "tst_pick_approx_zn" mtz_file, pdb_file = generate_zinc_inputs(file_base=base, anonymize=True) time.sleep(2) args = [ "\"%s\"" % pdb_file, "\"%s\"" % mtz_file, "wavelength=1.54", "nproc=1", "elements=CA,ZN", "use_phaser=False" ] result = easy_run.fully_buffered("mmtbx.water_screen %s" % " ".join(args)).raise_if_errors() n_zn = 0 for line in result.stdout_lines: if "Probable cation: ZN+2" in line: n_zn += 1 if n_zn != 1: print "\n".join(result.stdout_lines) raise RuntimeError("Expected 1 ZN+2, found %d" % n_zn) os.remove(pdb_file) os.remove(mtz_file) # "zn_frag_hoh.pdb" => "zn_frag_fmodel.eff" os.remove(os.path.splitext(pdb_file)[0][:-4] + ".pdb") os.remove(os.path.splitext(pdb_file)[0][:-4] + "_fmodel.eff") print "OK"
def exercise(): wavelength = 1.025 mtz_file, pdb_file = generate_zinc_inputs(anonymize=False) null_out = libtbx.utils.null_out() cmdline = mmtbx.command_line.load_model_and_data(args=[ pdb_file, mtz_file, "wavelength={}".format(wavelength), "use_phaser=False", "use_svm=True" ], master_phil=master_phil(), out=null_out, process_pdb_file=True, create_fmodel=True, prefer_anomalous=True) os.remove(pdb_file) os.remove(mtz_file) os.remove(os.path.splitext(pdb_file)[0] + "_fmodel.eff") cmdline.xray_structure.set_inelastic_form_factors( photon=cmdline.params.input.wavelength, table="sasaki") cmdline.fmodel.update_xray_structure(cmdline.xray_structure, update_f_calc=True) manager = ions.identify.create_manager( pdb_hierarchy=cmdline.pdb_hierarchy, fmodel=cmdline.fmodel, geometry_restraints_manager=cmdline.geometry, wavelength=cmdline.params.input.wavelength, params=cmdline.params, nproc=cmdline.params.nproc, log=null_out) manager.validate_ions(out=null_out) for atom_props in manager.atoms_to_props.values(): i_seq = atom_props.i_seq chem_env = ChemicalEnvironment( i_seq, manager.find_nearby_atoms(i_seq, far_distance_cutoff=3.5), manager) scatter_env = ScatteringEnvironment( i_seq, manager, fo_density=manager.get_map_gaussian_fit("mFo", i_seq), fofc_density=manager.get_map_gaussian_fit("mFo-DFc", i_seq), anom_density=manager.get_map_gaussian_fit("anom", i_seq), ) vector = ion_vector(chem_env, scatter_env) resname = ion_class(chem_env) assert vector is not None assert resname != "" print "OK"
def exercise () : from mmtbx.regression.make_fake_anomalous_data import generate_zinc_inputs base = "tst_validate_zn" mtz_file, pdb_file = generate_zinc_inputs(file_base=base, anonymize=False) time.sleep(2) args = ["\"%s\"" % pdb_file, "\"%s\"" % mtz_file, "wavelength=1.54", "nproc=1"] result = easy_run.fully_buffered("mmtbx.validate_ions %s" % " ".join(args) ).raise_if_errors() n_zn, n_bad = 0, 0 for line in result.stdout_lines: if "| ZN" in line: n_zn += 1 if "!!!" in line: n_bad += 1 assert n_zn == 1 and n_bad == 2 for ext in [".pdb", ".mtz", "_fmodel.eff"]: os.remove(base + ext) print "OK"
def exercise(): wavelength = 1.025 mtz_file, pdb_file = generate_zinc_inputs(anonymize=True) args = [ "input.pdb.file_name=" + pdb_file, "input.xray_data.file_name=" + mtz_file, "wavelength={}".format(wavelength), ] fully_buffered( "phenix.python -m mmtbx.ions.svm.dump_sites " + " ".join(args), ).raise_if_errors() os.remove(pdb_file) os.remove(os.path.splitext(pdb_file)[0][:-4] + ".pdb") os.remove(mtz_file) # "zn_frag_hoh.pdb" => "zn_frag_fmodel.eff" os.remove(os.path.splitext(pdb_file)[0][:-4] + "_fmodel.eff") sites_path = os.path.splitext(pdb_file)[0] + "_sites.pkl" sites = load(sites_path) os.remove(sites_path) assert len(sites) == 7 for chem_env, scatter_env in sites: assert chem_env is not None assert scatter_env is not None for name in chem_env.__slots__: if getattr(chem_env, name) is None: print "Error: chem_env.{} is not set".format(name) sys.exit() for name in scatter_env.__slots__: # f' is not set by phaser if name in ["fp"]: continue # Only check f'' for heavy metals if name != "fpp" or ion_class(chem_env) != "HOH": if getattr(scatter_env, name) is None: print "Error: scatter_env.{} is not set".format(name) sys.exit() print "OK"
def exercise () : from mmtbx.regression.make_fake_anomalous_data import generate_zinc_inputs base = "tst_pick_approx_zn" mtz_file, pdb_file = generate_zinc_inputs(file_base=base, anonymize = True) time.sleep(2) args = ["\"%s\"" % pdb_file, "\"%s\"" % mtz_file, "wavelength=1.54", "nproc=1", "elements=CA,ZN", "use_phaser=False"] result = easy_run.fully_buffered("mmtbx.water_screen %s" % " ".join(args) ).raise_if_errors() n_zn = 0 for line in result.stdout_lines: if "Probable cation: ZN+2" in line: n_zn += 1 if n_zn != 1: print "\n".join(result.stdout_lines) raise RuntimeError("Expected 1 ZN+2, found %d" % n_zn) os.remove(pdb_file) os.remove(mtz_file) # "zn_frag_hoh.pdb" => "zn_frag_fmodel.eff" os.remove(os.path.splitext(pdb_file)[0][:-4] + ".pdb") os.remove(os.path.splitext(pdb_file)[0][:-4] + "_fmodel.eff") print "OK"
def exercise(): wavelength = 1.025 mtz_file, pdb_file = generate_zinc_inputs(anonymize = False) null_out = libtbx.utils.null_out() cmdline = mmtbx.command_line.load_model_and_data( args = [pdb_file, mtz_file, "wavelength={}".format(wavelength), "use_phaser=False"], master_phil = master_phil(), out = null_out, process_pdb_file = True, create_fmodel = True, prefer_anomalous = True ) os.remove(pdb_file) os.remove(mtz_file) cmdline.xray_structure.set_inelastic_form_factors( photon = cmdline.params.input.wavelength, table = "sasaki" ) cmdline.fmodel.update_xray_structure( cmdline.xray_structure, update_f_calc = True ) manager = ions.identify.create_manager( pdb_hierarchy = cmdline.pdb_hierarchy, fmodel = cmdline.fmodel, geometry_restraints_manager = cmdline.geometry, wavelength = cmdline.params.input.wavelength, params = cmdline.params, nproc = cmdline.params.nproc, log = null_out ) manager.validate_ions( out = null_out ) fo_map = manager.get_map("mFo") fofc_map = manager.get_map("mFo-DFc") for atom_props in manager.atoms_to_props.values(): chem_env = environment.ChemicalEnvironment( atom_props.i_seq, manager.find_nearby_atoms(atom_props.i_seq, far_distance_cutoff = 3.5), manager ) new_chem_env = loads(dumps(chem_env)) for attr in dir(chem_env): if attr == "atom": # The two won't be directly comparable, but we will trust atom_labels is # tested fully in its own module assert chem_env.atom.id_str() == new_chem_env.atom.id_str() elif not attr.startswith("_") and \ not isinstance(getattr(chem_env, attr), MethodType): assert getattr(chem_env, attr) == getattr(new_chem_env, attr) scatter_env = environment.ScatteringEnvironment( atom_props.i_seq, manager, fo_map, fofc_map ) new_scatter_env = loads(dumps(scatter_env)) for attr in dir(scatter_env): if not attr.startswith("_") and \ not isinstance(getattr(scatter_env, attr), MethodType): assert getattr(scatter_env, attr) == getattr(new_scatter_env, attr) del fo_map del fofc_map print "OK"
def exercise(): wavelength = 1.025 mtz_file, pdb_file = generate_zinc_inputs(anonymize = False) null_out = libtbx.utils.null_out() cmdline = mmtbx.command_line.load_model_and_data( args = [pdb_file, mtz_file, "wavelength={}".format(wavelength), "use_phaser=False", "use_svm=True"], master_phil = master_phil(), out = null_out, process_pdb_file = True, create_fmodel = True, prefer_anomalous = True ) os.remove(pdb_file) os.remove(mtz_file) os.remove(os.path.splitext(pdb_file)[0] + "_fmodel.eff") cmdline.xray_structure.set_inelastic_form_factors( photon = cmdline.params.input.wavelength, table = "sasaki" ) cmdline.fmodel.update_xray_structure( cmdline.xray_structure, update_f_calc = True ) manager = ions.identify.create_manager( pdb_hierarchy = cmdline.pdb_hierarchy, fmodel = cmdline.fmodel, geometry_restraints_manager = cmdline.geometry, wavelength = cmdline.params.input.wavelength, params = cmdline.params, nproc = cmdline.params.nproc, log = null_out ) manager.validate_ions( out = null_out ) for atom_props in manager.atoms_to_props.values(): i_seq = atom_props.i_seq chem_env = ChemicalEnvironment( i_seq, manager.find_nearby_atoms(i_seq, far_distance_cutoff = 3.5), manager ) scatter_env = ScatteringEnvironment( i_seq, manager, fo_density = manager.get_map_gaussian_fit("mFo", i_seq), fofc_density = manager.get_map_gaussian_fit("mFo-DFc", i_seq), anom_density = manager.get_map_gaussian_fit("anom", i_seq), ) vector = ion_vector(chem_env, scatter_env) resname = ion_class(chem_env) assert vector is not None assert resname != "" print "OK"