def test_rs_mapper(dials_regression, tmpdir): tmpdir.chdir() result = procrunner.run_process([ 'dials.rs_mapper', os.path.join(dials_regression, "centroid_test_data", "datablock.json"), 'map_file="junk.ccp4"', ]) assert result['exitcode'] == 0 assert result['stderr'] == '' assert os.path.exists('junk.ccp4') # load results from iotbx import ccp4_map from scitbx.array_family import flex m = ccp4_map.map_reader(file_name="junk.ccp4") assert len(m.data) == 7189057 assert m.header_min == -1.0 assert flex.min(m.data) == -1.0 assert m.header_max == 2052.75 assert flex.max(m.data) == 2052.75 assert m.header_mean == pytest.approx(0.018606403842568398, abs=1e-6) assert flex.mean(m.data) == pytest.approx(0.018606403842568398, abs=1e-6)
def test_rs_mapper(dials_data, tmpdir): result = procrunner.run( [ "dials.rs_mapper", dials_data("centroid_test_data").join("datablock.json").strpath, 'map_file="junk.ccp4"', ], working_directory=tmpdir.strpath, ) assert not result.returncode and not result.stderr assert tmpdir.join("junk.ccp4").check() # load results from iotbx import ccp4_map from scitbx.array_family import flex m = ccp4_map.map_reader(file_name=tmpdir.join("junk.ccp4").strpath) assert len(m.data) == 7189057 assert m.header_min == 0.0 assert flex.min(m.data) == 0.0 assert m.header_max == 2052.75 assert flex.max(m.data) == 2052.75 assert m.header_mean == pytest.approx(0.018905939534306526, abs=1e-6) assert flex.mean(m.data) == pytest.approx(0.018905939534306526, abs=1e-6)
def test1(): dials_regression = libtbx.env.find_in_repositories( relative_path="dials_regression", test=os.path.isdir) data_dir = os.path.join(dials_regression, "centroid_test_data") datablock_path = os.path.join(data_dir, "datablock.json") # work in a temporary directory cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory(suffix="tst_rs_mapper") os.chdir(tmp_dir) cmd = 'dials.rs_mapper ' + datablock_path + ' map_file="junk.ccp4"' result = easy_run.fully_buffered(command=cmd).raise_if_errors() # load results from iotbx import ccp4_map from scitbx.array_family import flex m = ccp4_map.map_reader(file_name="junk.ccp4") assert len(m.data) == 7189057 assert approx_equal(m.header_min, -1.0) assert approx_equal(flex.min(m.data), -1.0) assert approx_equal(m.header_max, 2052.75) assert approx_equal(flex.max(m.data), 2052.75) assert approx_equal(m.header_mean, 0.018606403842568398) assert approx_equal(flex.mean(m.data), 0.018606403842568398) print "OK" return
def test_masked(dials_data, tmp_path): procrunner.run( [ "dials.import", dials_data("thaumatin_eiger_screen", pathlib=True) / "Therm_6_1_master.h5", ], working_directory=tmp_path, ) result = procrunner.run( ["dials.rs_mapper", "imported.expt", "map_file=junk.ccp4"], working_directory=tmp_path, ) assert not result.returncode and not result.stderr assert (tmp_path / "junk.ccp4").is_file() # load results m = ccp4_map.map_reader(file_name=str(tmp_path / "junk.ccp4")) assert m.header_max == pytest.approx(6330.33350)
def ccp4_to_npy(map_name, save_name = None): """ Convert a ccp4 map to numpy format and optionally save to given path. Inputs: ------- map_name: path to .CCP4 map file save_name: path to output numpy file, optional Output: ------- f_as_npy: converted CCP4 map volume as numpy array """ f = ccp4_map.map_reader(file_name = map_name) shape = f.data.focus() f_as_npy = np.array(f.data).reshape(shape) if save_name is not None: np.save(save_name, f_as_npy) return f_as_npy
def test_masked(dials_data, tmpdir): procrunner.run( [ "dials.import", dials_data("thaumatin_eiger_screen").join( "Therm_6_1_master.h5").strpath, ], working_directory=tmpdir.strpath, ) result = procrunner.run( ["dials.rs_mapper", "imported.expt", "map_file=junk.ccp4"], working_directory=tmpdir.strpath, ) assert not result.returncode and not result.stderr assert tmpdir.join("junk.ccp4").check() # load results from iotbx import ccp4_map m = ccp4_map.map_reader(file_name=tmpdir.join("junk.ccp4").strpath) assert m.header_max == pytest.approx(6330.33350)
def test_rs_mapper(dials_data, tmp_path): result = procrunner.run( [ "dials.rs_mapper", dials_data("centroid_test_data", pathlib=True) / "imported_experiments.json", 'map_file="junk.ccp4"', ], working_directory=tmp_path, ) assert not result.returncode and not result.stderr assert (tmp_path / "junk.ccp4").is_file() # load results m = ccp4_map.map_reader(file_name=str(tmp_path / "junk.ccp4")) assert len(m.data) == 7189057 assert m.header_min == 0.0 assert flex.min(m.data) == 0.0 assert m.header_max == 2052.75 assert flex.max(m.data) == 2052.75 assert m.header_mean == pytest.approx(0.018924040719866753, abs=1e-6) assert flex.mean(m.data) == pytest.approx(0.01892407052218914, abs=1e-6)
def run(args, prefix="tst_00", validated=False): user_input_pdb = '' user_input_map = '' # very simple parsing of model and map for i, arg in enumerate(args): if arg.endswith('.cif') or arg.endswith('.ent') or arg.endswith('.pdb'): # EMD-3981 has 6exv.ent instead of .pdb user_input_pdb = arg if arg.find('=')==-1: args[i]='model=%s' % arg elif arg.endswith('.ccp4') or arg.endswith('.map'): user_input_map = arg if arg.find('=')==-1: args[i]='map=%s' % arg argument_interpreter = libtbx.phil.command_line.argument_interpreter( master_phil=master_phil, home_scope="cryo_fit2", ) user_input_pdb = clean_pdb_for_phenix(user_input_pdb) pdbs = [] maps = [] phils = [] phil_args = [] for arg in args: if os.path.isfile(arg) : if iotbx.pdb.is_pdb_file(arg): pdbs.append(arg) elif arg.endswith('.ccp4') or arg.endswith('.map'): # not the smartest maps.append(arg) else: try : file_phil = phil.parse(file_name=arg) except RuntimeError : pass else : phils.append(file_phil) else : phil_args.append(arg) phils.append(argument_interpreter.process(arg)) working_phil = master_phil.fetch(sources=phils) working_phil.show() working_params = working_phil.extract() if (not validated): validate_params(working_params) # Compute a target map from iotbx import ccp4_map ccp4_map = ccp4_map.map_reader(user_input_map) print('Map read from %s' %(user_input_map)) target_map_data = ccp4_map.map_data() # initial atomic model that we want to fit to an EM-map pdb_inp = iotbx.pdb.input(file_name=user_input_pdb) model = mmtbx.model.manager(model_input = pdb_inp) # Initialize states accumulator states = mmtbx.utils.states( pdb_hierarchy = model.get_hierarchy(), xray_structure = model.get_xray_structure()) states.add(sites_cart = model.get_xray_structure().sites_cart()) # params = sa.master_params().extract() params.start_temperature=2000 params.final_temperature=0 params.cool_rate = 100 params.number_of_steps = 1000 params.update_grads_shift = 0. params.interleave_minimization=False #Pavel will fix the error that occur when params.interleave_minimization=True print('CC: %s' %(calculate_cc(map_data=target_map_data, model=model, resolution=3.))) #STOP() result = sa.run( params = params, xray_structure = model.get_xray_structure(), restraints_manager = model.get_restraints_manager(), target_map = target_map_data, real_space = True, wx = 100, # wx=5 broke helix conformation of tst_00_poor.pdb, wx=100 kept helix well wc = 1, states_collector = states) states.write(file_name = "all_states.pdb") model.set_xray_structure(result.xray_structure) with open("refined.pdb", "w") as f: f.write(model.model_as_pdb())