def exercise_3(): if not have_dials_regression: print "Skipping exercise(): dials_regression not available." return data_dir = os.path.join(dials_regression, "indexing_test_data", "phi_scan") pickle_path = os.path.join(data_dir, "strong.pickle") datablock_path = os.path.join(data_dir, "datablock.json") args = ["dials.discover_better_experimental_model", datablock_path, pickle_path] command = " ".join(args) print command cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory() os.chdir(tmp_dir) result = easy_run.fully_buffered(command=command).raise_if_errors() assert os.path.exists('optimized_datablock.json') from dxtbx.serialize import load datablocks = load.datablock(datablock_path, check_format=False) original_imageset = datablocks[0].extract_imagesets()[0] optimized_datablock = load.datablock('optimized_datablock.json', check_format=False) detector_1 = original_imageset.get_detector() detector_2 = optimized_datablock[0].unique_detectors()[0] shift = (matrix.col(detector_1[0].get_origin()) - matrix.col(detector_2[0].get_origin())) assert approx_equal(shift.elems, (-1.1091, 2.1695, 0.0), eps=1e-1) os.chdir(cwd)
def test1(): dials_regression = libtbx.env.find_in_repositories( relative_path="dials_regression", test=os.path.isdir) data_dir = os.path.join(dials_regression, "misc_test_data") experiments_path = os.path.join(data_dir, "i04-indexed.json") pickle_path = os.path.join(data_dir, "i04-indexed.pickle") for path in (experiments_path, pickle_path): assert os.path.exists(path) cmd = "dials.check_indexing_symmetry " + \ "%s %s d_min=4 d_max=10 symop_threshold=0.6" % \ (experiments_path, pickle_path) # work in a temporary directory cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory(suffix="test_dials_refine") os.chdir(tmp_dir) try: result = easy_run.fully_buffered(command=cmd).raise_if_errors() finally: os.chdir(cwd) print "OK" return
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 run (args) : if (len(args) == 0) : raise Usage("""libtbx.run_tests_parallel [module=NAME] [directory=path]""") user_phil = [] for arg in args : if os.path.isdir(arg) : user_phil.append(libtbx.phil.parse("directory=%s" % arg)) else : try : arg_phil = libtbx.phil.parse(arg) except RuntimeError : raise Sorry("Unrecognized argument '%s'" % arg) else : user_phil.append(arg_phil) params = master_phil.fetch(sources=user_phil).extract() if params.run_in_tmp_dir: from libtbx.test_utils import open_tmp_directory run_dir = open_tmp_directory() print 'Running tests in %s' % run_dir os.chdir(run_dir) else: cwd = os.getcwd() cwd_files = os.listdir(cwd) if (len(cwd_files) > 0) : raise Sorry("Please run this program in an empty directory.") if params.output_junit_xml: try: import junit_xml except ImportError, e: raise Sorry( "Cannot import junit_xml. Try running with output_junit_xml=False")
def run_indexing(datablock, strong_spots, crystal_model, rmsds): cwd = os.path.abspath(os.curdir) tmp_dir = os.path.abspath(open_tmp_directory(suffix="test_dials_index")) os.chdir(tmp_dir) sweep_path = os.path.join(tmp_dir, "datablock.json") pickle_path = os.path.join(tmp_dir, "strong.pickle") dump.datablock(datablock, sweep_path) easy_pickle.dump(pickle_path, strong_spots) from dials.test.algorithms.indexing.tst_index import run_one_indexing space_group_info = crystal_model.get_space_group() symmetry = crystal.symmetry(unit_cell=crystal_model.get_unit_cell(), space_group=crystal_model.get_space_group()) expected_rmsds = [1.1*r for r in rmsds] imageset = datablock[0].extract_imagesets()[0] pixel_size = imageset.get_detector()[0].get_pixel_size() phi_width = imageset.get_scan().get_oscillation()[1] * math.pi/180 expected_rmsds = [1.1 * rmsds[0] * pixel_size[0], 1.1 * rmsds[1] * pixel_size[1], 1.1 * rmsds[2] * phi_width] run_one_indexing(pickle_path=pickle_path, sweep_path=sweep_path, extra_args=[], expected_unit_cell=symmetry.minimum_cell().unit_cell(), expected_rmsds=expected_rmsds, #expected_hall_symbol=crystal_model.get_space_group().type().hall_symbol(), expected_hall_symbol=' P 1', )
def run(self): from iotbx.xds import xds_inp import os import libtbx.load_env iotbx_dir = libtbx.env.dist_path('iotbx') filename = os.path.join(iotbx_dir, 'xds', 'tests', 'XDS.INP') handle = xds_inp.reader() handle.read_file(filename) assert handle.detector == 'PILATUS' assert handle.minimum_valid_pixel_value == 0 assert handle.overload == 1048500 assert handle.corrections == 'ALL' assert handle.direction_of_detector_x_axis == [1.0, 0.0, 0.0] assert handle.direction_of_detector_y_axis == [0.0, 1.0, 0.0] assert handle.trusted_region == [0.0, 1.41] assert handle.sensor_thickness == 0.32 assert handle.untrusted_rectangle == [ [487, 495, 0, 2528], [981, 989, 0, 2528], [1475, 1483, 0, 2528], [1969, 1977, 0, 2528], [0, 2464, 195, 213], [0, 2464, 407, 425], [0, 2464, 619, 637], [0, 2464, 831, 849], [0, 2464, 1043, 1061], [0, 2464, 1255, 1273], [0, 2464, 1467, 1485], [0, 2464, 1679, 1697], [0, 2464, 1891, 1909], [0, 2464, 2103, 2121], [0, 2464, 2315, 2333]] assert handle.maximum_number_of_processor == 16 assert (handle.nx, handle.ny, handle.px, handle.py) == (2463, 2527, 0.172, 0.172) assert (handle.orgx, handle.orgy) == (1279.1, 1235.3) assert handle.rotation_axis == [1.0, 0.0, 0.0] assert handle.detector_distance == 190.18 assert handle.xray_wavelength == 0.9795 assert handle.incident_beam_direction == [0.0, 0.0, 1.0] assert handle.fraction_of_polarization == 0.99 assert handle.polarization_plane_normal == [0.0, 1.0, 0.0] assert handle.friedels_law assert len(handle.name_template_of_data_frames) == 1 assert handle.name_template_of_data_frames[0].endswith( 'X4_lots_M1S4_1_????.cbf') assert handle.starting_angle == 0 assert handle.starting_frame == 1 assert handle.include_resolution_range == [30.0, 1.27] assert handle.unit_cell_constants == [42.45, 42.45, 39.8, 90.0, 90.0, 90.0] assert handle.space_group_number == 89 assert handle.max_fac_rmeas == 3.0 assert handle.data_range == [1,900] filename_1 = os.path.join(iotbx_dir, 'xds', 'tests', 'XDS_2.INP') tmp_dir = open_tmp_directory() filename_2 = os.path.join(tmp_dir, 'XDS.INP') with open(filename_2, 'wb') as f: print >> f, open(filename_1, 'rb').read() handle = xds_inp.reader() handle.read_file(filename_2) assert handle.corrections is None assert handle.incident_beam_direction == [-0.003, 0.001, 1.032] assert len(handle.name_template_of_data_frames) == 2 assert handle.name_template_of_data_frames[0] == '/blah/xtal1_1_????.cbf' assert handle.name_template_of_data_frames[1] == 'CBF' print 'OK'
def test1(): dials_regression = libtbx.env.find_in_repositories( relative_path="dials_regression", test=os.path.isdir) data_dir = os.path.join(dials_regression, "misc_test_data") experiments_path = os.path.join(data_dir, "i04-indexed.json") pickle_path = os.path.join(data_dir, "i04-indexed.pickle") for path in (experiments_path, pickle_path): assert os.path.exists(path) cmd = "dials.check_indexing_symmetry " + \ "%s %s d_min=4 d_max=10 symop_threshold=0.6" % \ (experiments_path, pickle_path) # work in a temporary directory cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory(suffix="test_dials_refine") os.chdir(tmp_dir) try: result = easy_run.fully_buffered(command=cmd).raise_if_errors() finally: os.chdir(cwd) shutil.rmtree(tmp_dir) print "OK" return
def exercise_1(): if not have_dials_regression: print "Skipping exercise(): dials_regression not available." return data_dir = os.path.join(dials_regression, "indexing_test_data", "trypsin") pickle_path1 = os.path.join(data_dir, "strong_P1_X6_1_0-1.pickle") pickle_path2 = os.path.join(data_dir, "strong_P1_X6_2_0-1.pickle") datablock_path1 = os.path.join(data_dir, "datablock_P1_X6_1.json") datablock_path2 = os.path.join(data_dir, "datablock_P1_X6_2.json") args = [ "dials.discover_better_experimental_model", datablock_path1, datablock_path2, pickle_path1, pickle_path2 ] command = " ".join(args) print command cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory() os.chdir(tmp_dir) result = easy_run.fully_buffered(command=command).raise_if_errors() assert os.path.exists('optimized_datablock.json') from dxtbx.serialize import load datablocks = load.datablock(datablock_path1, check_format=False) original_imageset = datablocks[0].extract_imagesets()[0] optimized_datablock = load.datablock('optimized_datablock.json', check_format=False) detector_1 = original_imageset.get_detector() detector_2 = optimized_datablock[0].unique_detectors()[0] shift = (matrix.col(detector_1[0].get_origin()) - matrix.col(detector_2[0].get_origin())) assert approx_equal(shift.elems, (0.037, 0.061, 0.0), eps=1e-1) os.chdir(cwd)
def run(args): tmp_dir = open_tmp_directory(suffix="example_cif_parser") cur_dir = os.path.abspath(os.path.curdir) os.chdir(os.path.abspath(tmp_dir)) try: exercise_compilation() finally: os.chdir(cur_dir)
def generate_processing_detail_text_ccp4(): """Generate the text for CCP4-versions of detail processing tutorial""" # Move to a temporary directory for processing cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory(suffix="generate_tutorial_text_ccp4") os.chdir(tmp_dir) # Find/validate the data input - until we've decided to integrate this # into the main release, have a DLS default or otherwise let it be # specified via a CCP4_TUTORIAL_DATA environment variable. DATA_PATH = "/dls/i03/data/2017/mx19576-1/tutorial_data/summed/summed/C2sum_1*.cbf.gz" DATA_PATH = os.environ.get("CCP4_TUTORIAL_DATA", DATA_PATH) if not any(glob.glob(DATA_PATH)): print("Error: Could not find CCP4-2017 data; skipping text generation") return # Work out where we are writing the output files to; in-source dials_dir = libtbx.env.find_in_repositories("dials") OUTPUT_DIR = os.path.join(dials_dir, "doc", "sphinx", "documentation", "tutorials", "logs_detail_betalactamase") # Ensure this output path exists if not os.path.isdir(OUTPUT_DIR): os.makedirs(OUTPUT_DIR) # Make an ordered list of named steps and associated commands commands = [ ("dials.import", "dials.import {}".format(DATA_PATH)), ("dials.find_spots", "dials.find_spots datablock.json nproc=4"), ("dials.index", "dials.index datablock.json strong.pickle"), ("dials.refine_bravais_settings", "dials.refine_bravais_settings experiments.json indexed.pickle"), ("dials.reindex", "dials.reindex indexed.pickle change_of_basis_op=a+b,-a+b,c"), ("dials.refine", "dials.refine bravais_setting_2.json reindexed_reflections.pickle"), ("dials.sv_refine", "dials.refine refined_experiments.json refined.pickle scan_varying=true"), ("dials.integrate", "dials.integrate refined_experiments.json refined.pickle nproc=4"), ("dials.report", "dials.report integrated_experiments.json integrated.pickle"), ("dials.export", "dials.export integrated.pickle integrated_experiments.json"), ] job_writer = JobWriter(OUTPUT_DIR) # Protect against errors so we can tidy up afterwards try: # Run each step, and write an output log for name, command in commands: result = Job.run_process(command)["stdout"] # Write a copy of the command, and the output log job_writer("{}.cmd".format(name), "{}.log".format(name),{'cmd':command,'result': result}) # Report step is special; we want the dials-report.html file instead shutil.copy("dials-report.html", OUTPUT_DIR) print "Updated result files written to {0}".format(OUTPUT_DIR) finally: # Remove our intermediatary files os.chdir(cwd) shutil.rmtree(tmp_dir)
def test3(): """Strict check for scan-varying refinement using automated outlier rejection block width and interval width setting""" dials_regression = libtbx.env.find_in_repositories( relative_path="dials_regression", test=os.path.isdir) # use the i04_weak_data for this test data_dir = os.path.join(dials_regression, "refinement_test_data", "centroid") experiments_path = os.path.join(data_dir, "experiments_XPARM_REGULARIZED.json") pickle_path = os.path.join(data_dir, "spot_all_xds.pickle") for pth in (experiments_path, pickle_path): assert os.path.exists(pth) cmd1 = ( "dials.refine " + experiments_path + " " + pickle_path + " scan_varying=true max_iterations=5 output.history=history.pickle " "crystal.orientation.smoother.interval_width_degrees=auto " "crystal.unit_cell.smoother.interval_width_degrees=auto") # work in a temporary directory cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory(suffix="test_dials_refine") os.chdir(tmp_dir) try: print cmd1 result1 = easy_run.fully_buffered(command=cmd1).raise_if_errors() # load and check results import cPickle as pickle history = pickle.load(open("history.pickle", "r")) expected_rmsds = [[0.619507829, 0.351326044, 0.006955399], [0.174024575, 0.113486044, 0.004704006], [0.098351363, 0.084052519, 0.002660408], [0.069202909, 0.072796782, 0.001451734], [0.064305277, 0.071560831, 0.001165639], [0.062955462, 0.071315612, 0.001074453]] assert approx_equal(history['rmsd'], expected_rmsds) # check the refined unit cell ref_exp = ExperimentListFactory.from_json_file( "refined_experiments.json", check_format=False)[0] unit_cell = ref_exp.crystal.get_unit_cell().parameters() assert approx_equal( unit_cell, [42.27482, 42.27482, 39.66893, 90.00000, 90.00000, 90.00000], eps=1e-3) finally: os.chdir(cwd) print "OK" return
def __init__(self): dials_regression = libtbx.env.find_in_repositories(relative_path="dials_regression", test=os.path.isdir) self._data_dir = os.path.join(dials_regression, "refinement_test_data", "multi_narrow_wedges") # set up a temporary directory self._cwd = os.path.abspath(os.curdir) self._tmp_dir = open_tmp_directory(suffix="tst_refine_multi_wedges") os.chdir(self._tmp_dir)
def generate_processing_detail_text_thaumatin(): cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory(suffix="generate_tutorial_text") os.chdir(tmp_dir) try: import_job = Processing_Tutorial.dials_import()() find_spots_job = Processing_Tutorial.dials_find_spots()() index_job = Processing_Tutorial.dials_index()() refine_bravais_settings_job = ( Processing_Tutorial.dials_refine_bravais_settings()()) reindex_job = Processing_Tutorial.dials_reindex()() refine_job = Processing_Tutorial.dials_refine()() sv_refine_job = Processing_Tutorial.dials_sv_refine()() integrate_job = Processing_Tutorial.dials_integrate()() report_html_job = Processing_Tutorial.dials_report()() export_job = Processing_Tutorial.dials_export()() # if we got this far, assume it is okay to overwrite the logs dials_dir = libtbx.env.find_in_repositories("dials") result_dir = os.path.join(dials_dir, "doc", "sphinx", "documentation", "tutorials", "logs") job_writer = JobWriter(result_dir) job_writer("dials.import.cmd", "dials.import.log", import_job) job_writer("dials.find_spots.cmd", "dials.find_spots.log", find_spots_job) job_writer("dials.index.cmd", "dials.index.log", index_job) job_writer( "dials.refine_bravais_settings.cmd", "dials.refine_bravais_settings.log", refine_bravais_settings_job, ) job_writer("dials.reindex.cmd", "dials.reindex.log", reindex_job) job_writer("dials.refine.cmd", "dials.refine.log", refine_job) job_writer("dials.sv_refine.cmd", "dials.sv_refine.log", sv_refine_job) job_writer("dials.integrate.cmd", "dials.integrate.log", integrate_job) job_writer("dials.report.cmd", "dials-report.html", report_html_job) job_writer("dials.export.cmd", "dials.export.log", export_job) print("Updated result files written to {}".format(result_dir)) finally: os.chdir(cwd) # clean up tmp dir shutil.rmtree(tmp_dir)
def tst_dxtbx_compressed(): import libtbx.load_env try: dials_regression = libtbx.env.dist_path('dials_regression') except KeyError: print 'FAIL: dials_regression not configured' return import os from dxtbx.format.Registry import Registry from dials_regression.image_examples.get_all_working_images import \ get_all_working_images # test that reading gz or bz2 compressed files works: it doesn't! from libtbx import smart_open from libtbx.test_utils import open_tmp_directory import shutil tmp_dir = open_tmp_directory() print tmp_dir for directory, image in get_all_working_images(): file_path = os.path.join(dials_regression, 'image_examples', directory, image) for ext in ('.gz', '.bz2')[:]: compressed_path = os.path.join(tmp_dir, os.path.basename(file_path)) + ext with open(file_path, 'rb') as f_in, smart_open.for_writing( compressed_path) as f_out: shutil.copyfileobj(f_in, f_out) print file_path, compressed_path format = Registry.find(compressed_path) try: i = format(compressed_path) except Exception: print 'Error reading compressed file: %s' % compressed_path import traceback traceback.print_exc() else: print 'Successfully read compressed file: %s' % compressed_path det = i.get_detector() if det is not None: size = det[0].get_image_size() b = i.get_beam() g = i.get_goniometer() s = i.get_scan() try: d = i.get_raw_data() except IOError: pass print 'OK'
def exercise_mosflm_indexer(): if not have_dials_regression: print "Skipping exercise_mosflm_indexer(): dials_regression not configured" return xia2_demo_data = os.path.join(dials_regression, "xia2_demo_data") template = os.path.join(xia2_demo_data, "insulin_1_###.img") cwd = os.path.abspath(os.curdir) tmp_dir = os.path.abspath(open_tmp_directory()) os.chdir(tmp_dir) from xia2.Modules.Indexer.MosflmIndexer import MosflmIndexer indexer = MosflmIndexer() indexer.set_working_directory(tmp_dir) from dxtbx.datablock import DataBlockTemplateImporter importer = DataBlockTemplateImporter([template]) datablocks = importer.datablocks imageset = datablocks[0].extract_imagesets()[0] indexer.add_indexer_imageset(imageset) indexer.index() assert approx_equal(indexer.get_indexer_cell(), (78.6657, 78.6657, 78.6657, 90.0, 90.0, 90.0), eps=1e-3) experiment = indexer.get_indexer_experiment_list()[0] sgi = experiment.crystal.get_space_group().info() assert sgi.type().number() == 197 beam_centre = indexer.get_indexer_beam_centre() assert approx_equal(beam_centre, (94.34, 94.57), eps=1e-2) assert indexer.get_indexer_images() == [(1, 1), (22, 22), (45, 45)] print indexer.get_indexer_experiment_list()[0].crystal print indexer.get_indexer_experiment_list()[0].detector # test serialization of indexer json_str = indexer.as_json() print json_str indexer2 = MosflmIndexer.from_json(string=json_str) indexer2.index() assert approx_equal(indexer.get_indexer_cell(), indexer2.get_indexer_cell()) assert approx_equal( indexer.get_indexer_beam_centre(), indexer2.get_indexer_beam_centre()) assert approx_equal( indexer.get_indexer_images(), indexer2.get_indexer_images()) indexer.eliminate() indexer2.eliminate() assert approx_equal(indexer.get_indexer_cell(), indexer2.get_indexer_cell()) assert indexer.get_indexer_lattice() == 'hR' assert indexer2.get_indexer_lattice() == 'hR'
def __init__(self): dials_regression = libtbx.env.find_in_repositories( relative_path="dials_regression", test=os.path.isdir) self._data_dir = os.path.join(dials_regression, "refinement_test_data", "i23_as_24_panel_barrel") # set up a temporary directory self._cwd = os.path.abspath(os.curdir) self._tmp_dir = open_tmp_directory() os.chdir(self._tmp_dir)
def __init__(self): dials_regression = libtbx.env.find_in_repositories( relative_path="dials_regression", test=os.path.isdir) self._data_dir = os.path.join(dials_regression, "refinement_test_data", "multi_narrow_wedges") # set up a temporary directory self._cwd = os.path.abspath(os.curdir) self._tmp_dir = open_tmp_directory(suffix="tst_refine_multi_wedges") os.chdir(self._tmp_dir)
def export_xds(): from libtbx import easy_run import libtbx.load_env try: dials_regression = libtbx.env.dist_path('dials_regression') except KeyError: print "skipping exercise_export_xds: dials_regression not available" return cwd = os.path.abspath(os.curdir) tmp_dir = os.path.abspath(open_tmp_directory(suffix="export_xds")) os.chdir(tmp_dir) args = [ "dials.find_spots", os.path.join(dials_regression, "centroid_test_data", "datablock.json") ] command = " ".join(args) print command result = easy_run.fully_buffered(command=command).raise_if_errors() pickle_path = os.path.join(tmp_dir, "strong.pickle") assert os.path.exists(pickle_path) args = [ "dials.export", "format=xds", os.path.join(dials_regression, "centroid_test_data", "experiments.json"), pickle_path ] command = " ".join(args) print command result = easy_run.fully_buffered(command=command).raise_if_errors() assert os.path.exists("xds/XDS.INP") assert os.path.exists("xds/XPARM.XDS") assert os.path.exists("xds/SPOT.XDS") os.remove("xds/XDS.INP") os.remove("xds/XPARM.XDS") assert not os.path.exists("xds/XDS.INP") assert not os.path.exists("xds/XPARM.XDS") args = [ "dials.export", "format=xds", os.path.join(dials_regression, "centroid_test_data", "experiments.json") ] command = " ".join(args) print command result = easy_run.fully_buffered(command=command).raise_if_errors() assert os.path.exists("xds/XDS.INP") assert os.path.exists("xds/XPARM.XDS") os.chdir(cwd)
def exercise_spots_xds(): txt = """\ 2411.40 1000.70 25.00 16384. 0 0 0 1328.60 2170.40 20.57 7326. 0 0 0 177.56 2191.30 24.94 6779. 0 0 0 1231.34 1220.04 24.99 1952. 0 0 0 1227.07 1230.56 24.81 349. 0 0 0 1341.63 1243.25 5.64 321. 2 -2 11 1125.23 1197.72 12.14 231. -1 2 -10 1317.52 1171.59 19.28 120. 6 -4 6 1260.25 1300.55 13.67 116. -4 2 6 1090.27 1199.47 41.49 114. -2 3 -13 """ tmp_dir = os.path.abspath(open_tmp_directory()) with open(os.path.join(tmp_dir, "SPOT.XDS"), mode="wb") as f: f.write(txt) output_pickle = "%s.pickle" % f.name[:-4] args = [ "dials.import_xds", f.name, #xparm_file, "input.method=reflections", "output.filename='%s'" % output_pickle, "remove_invalid=True" ] command = " ".join(args) print command result = easy_run.fully_buffered(command=command).raise_if_errors() assert os.path.exists(output_pickle) with open(output_pickle, "rb") as f: reflections = pickle.load(f) assert len(reflections) == 5 os.remove(os.path.join(tmp_dir, "SPOT.XDS")) assert not os.path.exists(os.path.join(tmp_dir, "SPOT.XDS")) # now test we can export it args = ["dials.export format=xds", output_pickle] command = " ".join(args) print command result = easy_run.fully_buffered(command=command).raise_if_errors() assert os.path.exists(os.path.join("xds", "SPOT.XDS")) with open(os.path.join("xds", "SPOT.XDS"), "rb") as f: txt = f.read() assert not show_diff( "\n".join([l.rstrip() for l in txt.split("\n")]), """\ 1341.63 1243.25 5.64 321.00 2 -2 11 1125.23 1197.72 12.14 231.00 -1 2 -10 1317.52 1171.59 19.28 120.00 6 -4 6 1260.25 1300.55 13.67 116.00 -4 2 6 1090.27 1199.47 41.49 114.00 -2 3 -13 """)
def test1(): dials_regression = libtbx.env.find_in_repositories( relative_path="dials_regression", test=os.path.isdir) data_dir = os.path.join(dials_regression, "refinement_test_data", "multi_stills") experiments_path = os.path.join(data_dir, "combined_experiments.json") reflections_path = os.path.join(data_dir, "combined_reflections.pickle") cmd = "dials.refine " + experiments_path + " " + reflections_path print cmd # work in a temporary directory cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory(suffix="tst_refine_multi_stills1") os.chdir(tmp_dir) try: result = easy_run.fully_buffered(command=cmd).raise_if_errors() # load results reg_exp = ExperimentListFactory.from_json_file( os.path.join(data_dir, "regression_experiments.json"), check_format=False) ref_exp = ExperimentListFactory.from_json_file("refined_experiments.json", check_format=False) finally: os.chdir(cwd) # clean up tmp dir shutil.rmtree(tmp_dir) print "OK" # compare results tol = 1e-5 for b1, b2 in zip(reg_exp.beams(), ref_exp.beams()): assert b1.is_similar_to(b2, wavelength_tolerance=tol, direction_tolerance=tol, polarization_normal_tolerance=tol, polarization_fraction_tolerance=tol) s0_1 = matrix.col(b1.get_unit_s0()) s0_2 = matrix.col(b2.get_unit_s0()) assert s0_1.accute_angle(s0_2, deg=True) < 0.0057 # ~0.1 mrad for c1, c2 in zip(reg_exp.crystals(), ref_exp.crystals()): assert c1.is_similar_to(c2) for d1, d2 in zip(reg_exp.detectors(), ref_exp.detectors()): assert d1.is_similar_to(d2, fast_axis_tolerance=1e-4, slow_axis_tolerance=1e-4, origin_tolerance=1e-2) print "OK" return
def test1(): dials_regression = libtbx.env.find_in_repositories( relative_path="dials_regression", test=os.path.isdir) data_dir = os.path.join(dials_regression, "refinement_test_data", "multi_stills") experiments_path = os.path.join(data_dir, "combined_experiments.json") reflections_path = os.path.join(data_dir, "combined_reflections.pickle") cmd = "dials.refine " + experiments_path + " " + reflections_path print cmd # work in a temporary directory cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory(suffix="tst_refine_multi_stills1") os.chdir(tmp_dir) try: result = easy_run.fully_buffered(command=cmd).raise_if_errors() # load results reg_exp = ExperimentListFactory.from_json_file(os.path.join( data_dir, "regression_experiments.json"), check_format=False) ref_exp = ExperimentListFactory.from_json_file( "refined_experiments.json", check_format=False) finally: os.chdir(cwd) print "OK" # compare results tol = 1e-5 for b1, b2 in zip(reg_exp.beams(), ref_exp.beams()): assert b1.is_similar_to(b2, wavelength_tolerance=tol, direction_tolerance=tol, polarization_normal_tolerance=tol, polarization_fraction_tolerance=tol) s0_1 = matrix.col(b1.get_unit_s0()) s0_2 = matrix.col(b2.get_unit_s0()) assert s0_1.accute_angle(s0_2, deg=True) < 0.0057 # ~0.1 mrad for c1, c2 in zip(reg_exp.crystals(), ref_exp.crystals()): assert c1.is_similar_to(c2) for d1, d2 in zip(reg_exp.detectors(), ref_exp.detectors()): assert d1.is_similar_to(d2, fast_axis_tolerance=1e-4, slow_axis_tolerance=1e-4, origin_tolerance=1e-2) print "OK" return
def exercise_spots_xds(): txt = """\ 2411.40 1000.70 25.00 16384. 0 0 0 1328.60 2170.40 20.57 7326. 0 0 0 177.56 2191.30 24.94 6779. 0 0 0 1231.34 1220.04 24.99 1952. 0 0 0 1227.07 1230.56 24.81 349. 0 0 0 1341.63 1243.25 5.64 321. 2 -2 11 1125.23 1197.72 12.14 231. -1 2 -10 1317.52 1171.59 19.28 120. 6 -4 6 1260.25 1300.55 13.67 116. -4 2 6 1090.27 1199.47 41.49 114. -2 3 -13 """ tmp_dir = os.path.abspath(open_tmp_directory()) f = open(os.path.join(tmp_dir, "SPOT.XDS"), mode="wb") f.write(txt) f.close() output_pickle = "%s.pickle" %f.name[:-4] args = ["dev.dials.import_xds", f.name, #xparm_file, "input.method=reflections", "output.filename='%s'" %output_pickle, "remove_invalid=True"] command = " ".join(args) print command result = easy_run.fully_buffered(command=command).raise_if_errors() assert os.path.exists(output_pickle) with open(output_pickle, "rb") as f: reflections = pickle.load(f) assert len(reflections) == 5 os.remove(os.path.join(tmp_dir, "SPOT.XDS")) assert not os.path.exists(os.path.join(tmp_dir, "SPOT.XDS")) # now test we can export it args = ["dials.export format=xds", output_pickle] command = " ".join(args) print command result = easy_run.fully_buffered(command=command).raise_if_errors() assert os.path.exists(os.path.join("xds", "SPOT.XDS")) with open(os.path.join("xds", "SPOT.XDS"), "rb") as f: txt = f.read() assert not show_diff( "\n".join([l.rstrip() for l in txt.split("\n")]), """\ 1341.63 1243.25 5.64 321.00 2 -2 11 1125.23 1197.72 12.14 231.00 -1 2 -10 1317.52 1171.59 19.28 120.00 6 -4 6 1260.25 1300.55 13.67 116.00 -4 2 6 1090.27 1199.47 41.49 114.00 -2 3 -13 """)
def exercise_mosflm_index(): if not have_dials_regression: print 'SKIP: dials_regression not configured' exit(0) xia2_demo_data = os.path.join(dials_regression, "xia2_demo_data") template = os.path.join(xia2_demo_data, "insulin_1_%03i.img") cwd = os.path.abspath(os.curdir) tmp_dir1 = os.path.abspath(open_tmp_directory()) os.chdir(tmp_dir1) from xia2.Modules.Indexer.MosflmIndexer import MosflmIndexer m1 = MosflmIndexer() m1.set_working_directory(tmp_dir1) m1.setup_from_image(template % 1) m1.index() os.chdir(cwd) tmp_dir2 = os.path.abspath(open_tmp_directory()) os.chdir(tmp_dir2) from Original import Mosflm m2 = Mosflm() m2.set_working_directory(tmp_dir2) m2.setup_from_image(template % 1) m2.index() assert m1.get_indexer_beam_centre() == m2.get_indexer_beam_centre() assert m1.get_indexer_distance() == m2.get_indexer_distance() assert m1.get_indexer_cell() == m2.get_indexer_cell() assert m1.get_indexer_lattice() == m2.get_indexer_lattice() assert m1.get_indexer_mosaic() == m2.get_indexer_mosaic() os.chdir(cwd) return
def exercise_14(): from glob import glob data_dir = os.path.join(dials_regression, "xia2_demo_data") cwd = os.path.abspath(os.curdir) tmp_dir = os.path.abspath(open_tmp_directory()) os.chdir(tmp_dir) print tmp_dir import shutil for i, image_path in enumerate(("insulin_1_001.img", "insulin_1_045.img")): shutil.copyfile(os.path.join(data_dir, image_path), "image_00%i.img" % (i + 1)) args = [ "dials.import", ' '.join(glob(os.path.join(tmp_dir, "image_00*.img"))), "output.datablock=datablock.json", "allow_multiple_sweeps=True" ] command = " ".join(args) #print command result = easy_run.fully_buffered(command=command).raise_if_errors() datablock_json = os.path.join(tmp_dir, "datablock.json") args = ["dials.find_spots", datablock_json] command = " ".join(args) print command result = easy_run.fully_buffered(command=command).raise_if_errors() pickle_path = os.path.join(tmp_dir, "strong.pickle") assert os.path.exists(pickle_path) expected_unit_cell = uctbx.unit_cell( (78.163, 78.163, 78.163, 90.000, 90.000, 90.000)) expected_hall_symbol = ' I 2 2 3' expected_rmsds = (0.05, 0.06, 0.01) for method in ("fft3d", "fft1d", "real_space_grid_search"): extra_args = [] extra_args.append("known_symmetry.unit_cell=\"%s %s %s %s %s %s\"" % expected_unit_cell.parameters()) extra_args.append("known_symmetry.space_group=\"Hall: %s\"" % expected_hall_symbol) extra_args.append("indexing.method=%s" % method) extra_args.append("treat_single_image_as_still=False") result = run_one_indexing(pickle_path, datablock_json, extra_args, expected_unit_cell, expected_rmsds, expected_hall_symbol)
def exercise(): data_dir = os.path.join(dials_regression, "centroid_test_data") cwd = os.path.abspath(os.curdir) tmp_dir = os.path.abspath(open_tmp_directory()) print tmp_dir os.chdir(tmp_dir) g = glob.glob(os.path.join(data_dir, "*.cbf")) assert len(g) == 9 cmd = "dials.merge_cbf %s merge_n_images=3" %(" ".join(g)) print cmd result = easy_run.fully_buffered(cmd).raise_if_errors() g = glob.glob(os.path.join(tmp_dir, "sum_*.cbf")) assert len(g) == 3
def exercise(): data_dir = os.path.join(dials_regression, "centroid_test_data") cwd = os.path.abspath(os.curdir) tmp_dir = os.path.abspath(open_tmp_directory()) print tmp_dir os.chdir(tmp_dir) g = glob.glob(os.path.join(data_dir, "*.cbf")) assert len(g) == 9 cmd = "dials.merge_cbf %s merge_n_images=3" % (" ".join(g)) print cmd result = easy_run.fully_buffered(cmd).raise_if_errors() g = glob.glob(os.path.join(tmp_dir, "sum_*.cbf")) assert len(g) == 3
def exercise_refine_bravais_settings(): if not have_dials_regression: print "Skipping exercise_refine_bravais_settings(): dials_regression not available." return data_dir = os.path.join(dials_regression, "indexing_test_data", "i04_weak_data") pickle_path = os.path.join(data_dir, "indexed.pickle") experiments_path = os.path.join(data_dir, "experiments.json") commands = ["dials.refine_bravais_settings", pickle_path, experiments_path, "reflections_per_degree=5", "minimum_sample_size=500", "beam.fix=all", "detector.fix=all", "prefix=tst_"] command = " ".join(commands) print command cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory() os.chdir(tmp_dir) result = easy_run.fully_buffered(command=command).raise_if_errors() for i in range(1, 10): assert os.path.exists("tst_bravais_setting_%i.json" %i) from dxtbx.serialize import load experiments_list = load.experiment_list( "tst_bravais_setting_9.json", check_format=False) assert len(experiments_list) == 1 assert experiments_list[0].crystal.get_unit_cell().is_similar_to( uctbx.unit_cell((57.782, 57.782, 150.011, 90, 90, 90))) assert experiments_list[0].crystal.get_space_group().type().hall_symbol() \ == ' P 4' assert os.path.exists("tst_bravais_summary.json") from json import load bravais_summary = load(open("tst_bravais_summary.json", "rb")) assert bravais_summary.keys() == [ '1', '3', '2', '5', '4', '7', '6', '9', '8'] bravais_summary['9'].keys() == [ 'bravais', 'max_angular_difference', 'unit_cell', 'rmsd', 'nspots'] assert approx_equal( bravais_summary['9']['unit_cell'], [57.78, 57.78, 150.0, 90.0, 90.0, 90.0], eps=1e-1) assert bravais_summary['9']['bravais'] == 'tP' assert bravais_summary['9']['recommended'] == True assert approx_equal(bravais_summary['9']['rmsd'], 0.047, eps=1e-2) os.chdir(cwd)
def exercise_11(): return # disable test until a better image and/or parameters are available image_path = os.path.join(dials_regression, "spotfinding_test_data", "idx-s00-20131106040304531.cbf") cwd = os.path.abspath(os.curdir) tmp_dir = os.path.abspath(open_tmp_directory(suffix="test_dials_index")) os.chdir(tmp_dir) print tmp_dir args = ["dials.import", image_path, "output.datablock=datablock.json"] command = " ".join(args) #print command result = easy_run.fully_buffered(command=command).raise_if_errors() datablock_json = os.path.join(tmp_dir, "datablock.json") args = ["dials.find_spots", datablock_json, "threshold.xds.sigma_strong=7", "min_spot_size=6", ] command = " ".join(args) #print command result = easy_run.fully_buffered(command=command).raise_if_errors() pickle_path = os.path.join(tmp_dir, "strong.pickle") assert os.path.exists(pickle_path) extra_args = ["indexing.method=real_space_grid_search", "n_macro_cycles=3", "known_symmetry.unit_cell=78,78,39,90,90,90", "known_symmetry.space_group=P43212", "beam.fix=all", "detector.fix=all", "hkl_tolerance=0.5", ] expected_unit_cell = uctbx.unit_cell((78, 78, 39, 90, 90, 90)) expected_rmsds = (0.31, 0.38) # XXX these rmsds really aren't great expected_hall_symbol = ' P 4nw 2abw' n_expected_lattices = 1 result = run_one_indexing(pickle_path, datablock_json, extra_args, expected_unit_cell, expected_rmsds, expected_hall_symbol, n_expected_lattices=n_expected_lattices, relative_length_tolerance=0.05, absolute_angle_tolerance=1)
def exercise_labelit_indexerii(): if not have_dials_regression: print "Skipping exercise_labelit_indexerii(): dials_regression not configured" return xia2_demo_data = os.path.join(dials_regression, "xia2_demo_data") template = os.path.join(xia2_demo_data, "insulin_1_###.img") cwd = os.path.abspath(os.curdir) tmp_dir = os.path.abspath(open_tmp_directory()) os.chdir(tmp_dir) from xia2.Modules.Indexer.LabelitIndexerII import LabelitIndexerII from xia2.DriverExceptions.NotAvailableError import NotAvailableError try: ls = LabelitIndexerII(indxr_print=True) except NotAvailableError: print "Skipping exercise_labelit_indexerii(): labelit not found" return ls.set_working_directory(tmp_dir) from dxtbx.datablock import DataBlockTemplateImporter importer = DataBlockTemplateImporter([template]) datablocks = importer.datablocks imageset = datablocks[0].extract_imagesets()[0] ls.add_indexer_imageset(imageset) ls.set_indexer_input_cell((78,78,78,90,90,90)) ls.set_indexer_user_input_lattice(True) ls.set_indexer_input_lattice('cI') ls.index() assert approx_equal(ls.get_indexer_cell(), (78.52, 78.52, 78.52, 90, 90, 90)) solution = ls.get_solution() assert approx_equal(solution['rmsd'], 0.079, eps=5e-3) assert solution['metric'] <= 0.1762 assert solution['number'] == 22 assert solution['lattice'] == 'cI' assert solution['mosaic'] <= 0.075 assert abs(solution['nspots'] - 5509) <= 50 beam_centre = ls.get_indexer_beam_centre() assert approx_equal(beam_centre, (94.3286, 94.4662), eps=5e-2) assert ls.get_indexer_images() == [ (1, 1), (3, 3), (5, 5), (7, 7), (9, 9), (11, 11), (13, 13), (15, 15), (17, 17), (19, 19), (21, 21), (23, 23), (25, 25), (27, 27), (29, 29), (31, 31), (33, 33), (35, 35), (37, 37), (39, 39)] print ls.get_indexer_experiment_list()[0].crystal print ls.get_indexer_experiment_list()[0].detector
def test2(): """Compare results of multiprocess vs single process refinement to ensure they are the same""" dials_regression = libtbx.env.find_in_repositories( relative_path="dials_regression", test=os.path.isdir) data_dir = os.path.join(dials_regression, "refinement_test_data", "multi_stills") experiments_path = os.path.join(data_dir, "combined_experiments.json") reflections_path = os.path.join(data_dir, "combined_reflections.pickle") cmd = "dials.refine " + experiments_path + " " + reflections_path + \ " outlier.algorithm=null engine=LBFGScurvs output.reflections=None " cmd1 = cmd + "output.experiments=refined_experiments_nproc1.json nproc=1" print cmd1 cmd2= cmd + "output.experiments=refined_experiments_nproc4.json nproc=4" print cmd2 # work in a temporary directory cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory(suffix="tst_refine_multi_stills2") os.chdir(tmp_dir) try: result1 = easy_run.fully_buffered(command=cmd1).raise_if_errors() result2 = easy_run.fully_buffered(command=cmd2).raise_if_errors() # load results nproc1 = ExperimentListFactory.from_json_file( "refined_experiments_nproc1.json", check_format=False) nproc4 = ExperimentListFactory.from_json_file( "refined_experiments_nproc4.json", check_format=False) finally: os.chdir(cwd) # clean up tmp dir shutil.rmtree(tmp_dir) print "OK" # compare results for b1, b2 in zip(nproc1.beams(), nproc4.beams()): assert b1.is_similar_to(b2) for c1, c2 in zip(nproc1.crystals(), nproc4.crystals()): assert c1.is_similar_to(c2) for d1, d2 in zip(nproc1.detectors(), nproc4.detectors()): assert d1.is_similar_to(d2, fast_axis_tolerance=5e-5, slow_axis_tolerance=5e-5, origin_tolerance=5e-5) print "OK" return
def test1(): dials_regression = libtbx.env.find_in_repositories( relative_path="dials_regression", test=os.path.isdir) # use multiple scan small molecule data for this test data_dir = os.path.join(dials_regression, "xia2-28") prefix = ["20", "25", "30", "35"] exp_path = [e + "_integrated_experiments.json" for e in prefix] exp_path = [os.path.join(data_dir, e) for e in exp_path] pkl_path = [e + "_integrated.pickle" for e in prefix] pkl_path = [os.path.join(data_dir, e) for e in pkl_path] for pth in exp_path + pkl_path: assert os.path.exists(pth), "%s missing" % pth cmd = "dials.two_theta_refine " + " ".join(exp_path) + " " + \ " ".join(pkl_path) + " cif=refined_cell.cif" + " " \ "output.correlation_plot.filename=corrplot.png" print cmd # work in a temporary directory cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory(suffix="test_dials_two_theta_refine") os.chdir(tmp_dir) try: result = easy_run.fully_buffered(command=cmd).raise_if_errors() ref_exp = ExperimentListFactory.from_json_file("refined_cell.json", check_format=False) finally: os.chdir(cwd) xls = ref_exp.crystals() assert len(xls) == 1 # crystal models should have been combined xl = xls[0] # test refined crystal model against expected values assert approx_equal( xl.get_unit_cell().parameters(), (5.428022880, 8.144145476, 12.039666971, 90.0, 90.0, 90.0)) assert approx_equal(xl.get_cell_parameter_sd(), (9.58081e-5, 0.000149909, 0.000215765, 0, 0, 0)) assert approx_equal(xl.get_cell_volume_sd(), 0.0116254298) print "OK" return
def exercise_refine_bravais_settings(): if not have_dials_regression: print "Skipping exercise_refine_bravais_settings(): dials_regression not available." return data_dir = os.path.join(dials_regression, "indexing_test_data", "i04_weak_data") pickle_path = os.path.join(data_dir, "indexed.pickle") experiments_path = os.path.join(data_dir, "experiments.json") commands = ["dials.refine_bravais_settings", pickle_path, experiments_path, "reflections_per_degree=5", "minimum_sample_size=500", "beam.fix=all", "detector.fix=all"] command = " ".join(commands) print command cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory() os.chdir(tmp_dir) result = easy_run.fully_buffered(command=command).raise_if_errors() for i in range(1, 10): assert os.path.exists("bravais_setting_%i.json" %i) from dxtbx.serialize import load experiments_list = load.experiment_list( "bravais_setting_9.json", check_format=False) assert len(experiments_list) == 1 assert experiments_list[0].crystal.get_unit_cell().is_similar_to( uctbx.unit_cell((57.782, 57.782, 150.011, 90, 90, 90))) assert experiments_list[0].crystal.get_space_group().type().hall_symbol() \ == ' P 4' assert os.path.exists("bravais_summary.json") from json import load bravais_summary = load(open("bravais_summary.json", "rb")) assert bravais_summary.keys() == [ '1', '3', '2', '5', '4', '7', '6', '9', '8'] bravais_summary['9'].keys() == [ 'bravais', 'max_angular_difference', 'unit_cell', 'rmsd', 'nspots'] assert approx_equal( bravais_summary['9']['unit_cell'], [57.78, 57.78, 150.0, 90.0, 90.0, 90.0], eps=1e-1) assert bravais_summary['9']['bravais'] == 'tP' assert bravais_summary['9']['recommended'] == True assert approx_equal(bravais_summary['9']['rmsd'], 0.047, eps=1e-2) os.chdir(cwd)
def test1(): dials_regression = libtbx.env.find_in_repositories( relative_path="dials_regression", test=os.path.isdir) # use the i04_weak_data for this test data_dir = os.path.join(dials_regression, "refinement_test_data", "i04_weak_data") experiments_path = os.path.join(data_dir, "experiments.json") pickle_path = os.path.join(data_dir, "indexed_strong.pickle") for pth in (experiments_path, pickle_path): assert os.path.exists(pth) # set some old defaults cmd = "dials.refine close_to_spindle_cutoff=0.05 reflections_per_degree=100 " + \ "outlier.separate_blocks=False " + experiments_path + " " + pickle_path print cmd # work in a temporary directory cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory(suffix="test_dials_refine") os.chdir(tmp_dir) try: result = easy_run.fully_buffered(command=cmd).raise_if_errors() # load results reg_exp = ExperimentListFactory.from_json_file(os.path.join( data_dir, "regression_experiments.json"), check_format=False)[0] ref_exp = ExperimentListFactory.from_json_file( "refined_experiments.json", check_format=False)[0] finally: os.chdir(cwd) # test refined models against expected assert reg_exp.crystal == ref_exp.crystal assert reg_exp.detector == ref_exp.detector assert reg_exp.beam == ref_exp.beam # test cell parameter esds assert approx_equal(ref_exp.crystal.get_cell_parameter_sd(), (0.0009903, 0.0009903, 0.0021227, 0.0, 0.0, 0.0)) assert approx_equal(ref_exp.crystal.get_cell_volume_sd(), 23.8063382) print "OK" return
def test2(): """Compare results of multiprocess vs single process refinement to ensure they are the same""" dials_regression = libtbx.env.find_in_repositories( relative_path="dials_regression", test=os.path.isdir) data_dir = os.path.join(dials_regression, "refinement_test_data", "multi_stills") experiments_path = os.path.join(data_dir, "combined_experiments.json") reflections_path = os.path.join(data_dir, "combined_reflections.pickle") cmd = "dials.refine " + experiments_path + " " + reflections_path + \ " outlier.algorithm=null engine=LBFGScurvs output.reflections=None " cmd1 = cmd + "output.experiments=refined_experiments_nproc1.json nproc=1" print cmd1 cmd2 = cmd + "output.experiments=refined_experiments_nproc4.json nproc=4" print cmd2 # work in a temporary directory cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory(suffix="tst_refine_multi_stills2") os.chdir(tmp_dir) try: result1 = easy_run.fully_buffered(command=cmd1).raise_if_errors() result2 = easy_run.fully_buffered(command=cmd2).raise_if_errors() # load results nproc1 = ExperimentListFactory.from_json_file( "refined_experiments_nproc1.json", check_format=False) nproc4 = ExperimentListFactory.from_json_file( "refined_experiments_nproc4.json", check_format=False) finally: os.chdir(cwd) print "OK" # compare results for b1, b2 in zip(nproc1.beams(), nproc4.beams()): assert b1.is_similar_to(b2) for c1, c2 in zip(nproc1.crystals(), nproc4.crystals()): assert c1.is_similar_to(c2) for d1, d2 in zip(nproc1.detectors(), nproc4.detectors()): assert d1.is_similar_to(d2, fast_axis_tolerance=5e-5, slow_axis_tolerance=5e-5, origin_tolerance=5e-5) print "OK" return
def exercise_dials_multi_indexer(nproc=None): template = "/Volumes/touro/data/i19/4sweep/56_Reza-H2-normalhem_100K_3.75mmAl/56-RezaH2-hem_%02i_#####.cbf" cwd = os.path.abspath(os.curdir) tmp_dir = os.path.abspath(open_tmp_directory()) os.chdir(tmp_dir) cryst = None wav = None samp = None from xia2.Handlers.Phil import PhilIndex PhilIndex.params.xia2.settings.trust_beam_centre = True from xia2.Modules.Indexer.DialsIndexer import DialsIndexer from xia2.Modules.Indexer.DialsIndexer import DialsIndexer indexer = DialsIndexer() indexer.set_working_directory(tmp_dir) for i in range(4): from dxtbx.datablock import DataBlockTemplateImporter importer = DataBlockTemplateImporter([template % (i + 1)]) datablocks = importer.datablocks imageset = datablocks[0].extract_imagesets()[0] indexer.add_indexer_imageset(imageset) from xia2.Schema.XCrystal import XCrystal from xia2.Schema.XWavelength import XWavelength from xia2.Schema.XSweep import XSweep from xia2.Schema.XSample import XSample if cryst is None or wav is None: cryst = XCrystal("CRYST1", None) wav = XWavelength("WAVE1", cryst, imageset.get_beam().get_wavelength()) samp = XSample("X1", cryst) directory, image = os.path.split(imageset.get_path(1)) sweep = XSweep('SWEEP1', wav, samp, directory=directory, image=image) indexer.add_indexer_sweep(sweep) indexer.index() assert approx_equal(indexer.get_indexer_cell(), (9.088, 12.415, 17.420, 90.000, 90.000, 90.000), eps=1e-2)
def exercise_xds_split(): tmp_dir = os.path.abspath(open_tmp_directory()) xinfo_file = os.path.join(tmp_dir, 'split.xinfo') with open(xinfo_file, 'wb') as f: print >> f, split_xinfo_template command_line_args = ['pipeline=3di', 'nproc=1', 'njob=2', 'mode=parallel', 'trust_beam_centre=True', 'xinfo=%s' %xinfo_file] expected_data_files = [ 'AUTOMATIC_DEFAULT_free.mtz', 'AUTOMATIC_DEFAULT_scaled.sca', 'AUTOMATIC_DEFAULT_scaled_unmerged.mtz', 'AUTOMATIC_DEFAULT_scaled_unmerged.sca'] run_xia2_tolerant("X4_wide_split.xds", command_line_args, expected_data_files=expected_data_files)
def exercise_dials_multi_indexer(nproc=None): template = "/Volumes/touro/data/i19/4sweep/56_Reza-H2-normalhem_100K_3.75mmAl/56-RezaH2-hem_%02i_#####.cbf" cwd = os.path.abspath(os.curdir) tmp_dir = os.path.abspath(open_tmp_directory()) os.chdir(tmp_dir) cryst = None wav = None samp = None from xia2.Handlers.Phil import PhilIndex PhilIndex.params.xia2.settings.trust_beam_centre = True from xia2.Modules.Indexer.DialsIndexer import DialsIndexer from xia2.Modules.Indexer.DialsIndexer import DialsIndexer indexer = DialsIndexer() indexer.set_working_directory(tmp_dir) for i in range(4): from dxtbx.datablock import DataBlockTemplateImporter importer = DataBlockTemplateImporter([template %(i+1)]) datablocks = importer.datablocks imageset = datablocks[0].extract_imagesets()[0] indexer.add_indexer_imageset(imageset) from xia2.Schema.XCrystal import XCrystal from xia2.Schema.XWavelength import XWavelength from xia2.Schema.XSweep import XSweep from xia2.Schema.XSample import XSample if cryst is None or wav is None: cryst = XCrystal("CRYST1", None) wav = XWavelength("WAVE1", cryst, imageset.get_beam().get_wavelength()) samp = XSample("X1", cryst) directory, image = os.path.split(imageset.get_path(1)) sweep = XSweep('SWEEP1', wav, samp, directory=directory, image=image) indexer.add_indexer_sweep(sweep) indexer.index() assert approx_equal( indexer.get_indexer_cell(), (9.088, 12.415, 17.420, 90.000, 90.000, 90.000), eps=1e-2)
def exercise_14(): from glob import glob data_dir = os.path.join(dials_regression, "xia2_demo_data") cwd = os.path.abspath(os.curdir) tmp_dir = os.path.abspath(open_tmp_directory()) os.chdir(tmp_dir) print tmp_dir import shutil for i, image_path in enumerate(("insulin_1_001.img", "insulin_1_045.img")): shutil.copyfile( os.path.join(data_dir, image_path), "image_00%i.img" %(i+1)) args = ["dials.import", ' '.join(glob(os.path.join(tmp_dir, "image_00*.img"))), "output.datablock=datablock.json", "allow_multiple_sweeps=True"] command = " ".join(args) #print command result = easy_run.fully_buffered(command=command).raise_if_errors() datablock_json = os.path.join(tmp_dir, "datablock.json") args = ["dials.find_spots", datablock_json] command = " ".join(args) print command result = easy_run.fully_buffered(command=command).raise_if_errors() pickle_path = os.path.join(tmp_dir, "strong.pickle") assert os.path.exists(pickle_path) expected_unit_cell = uctbx.unit_cell((78.163, 78.163, 78.163, 90.000, 90.000, 90.000)) expected_hall_symbol = ' I 2 2 3' expected_rmsds = (0.05, 0.06, 0.01) for method in ("fft3d", "fft1d", "real_space_grid_search"): extra_args = [] extra_args.append( "known_symmetry.unit_cell=\"%s %s %s %s %s %s\"" %expected_unit_cell.parameters()) extra_args.append("known_symmetry.space_group=\"Hall: %s\"" %expected_hall_symbol) extra_args.append("indexing.method=%s" %method) extra_args.append("treat_single_image_as_still=False") result = run_one_indexing(pickle_path, datablock_json, extra_args, expected_unit_cell, expected_rmsds, expected_hall_symbol)
def exercise_1(): data_dir = os.path.join(xia2_regression, "test_data", "X4_wide") cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory() os.chdir(tmp_dir) print tmp_dir g = sorted(glob.glob(os.path.join(data_dir, "X4_wide_M1S4_2_00*.cbf"))) assert len(g) == 90, len(g) commands = [ "dials.import %s" %" ".join(g), "dials.slice_sweep datablock.json scan_range=80,90", "dials.find_spots datablock_80_90.json", "dials.index datablock_80_90.json strong.pickle space_group=P41212", "dials.refine experiments.json indexed.pickle scan_varying=True", "dials.integrate refined_experiments.json indexed.pickle", "dials.export refined_experiments.json integrated.pickle" ] for cmd in commands: # print cmd result = easy_run.fully_buffered(cmd).raise_if_errors() integrated_mtz = "integrated.mtz" assert os.path.exists(integrated_mtz) from iotbx.reflection_file_reader import any_reflection_file reader = any_reflection_file(integrated_mtz) mtz_object = reader.file_content() assert mtz_object.column_labels()[:14] == ['H', 'K', 'L', 'M_ISYM', 'BATCH', 'IPR', 'SIGIPR', 'I', 'SIGI', 'BG', 'SIGBG', 'FRACTIONCALC', 'XDET', 'YDET'] assert len(mtz_object.batches()) == 11 batch = mtz_object.batches()[0] expected_unit_cell = uctbx.unit_cell( (42.5787, 42.5787, 40.2983, 90, 90, 90)) assert expected_unit_cell.is_similar_to(uctbx.unit_cell(list(batch.cell()))), ( expected_unit_cell.parameters(), list(batch.cell())) assert mtz_object.space_group().type().lookup_symbol() == "P 41 21 2" assert approx_equal(mtz_object.n_reflections(), 7446, eps=2e3) os.chdir(cwd)
def exercise_1(): if not have_dials_regression: print "Skipping exercise(): dials_regression not available." return data_dir = os.path.join(dials_regression, "indexing_test_data", "trypsin") pickle_path1 = os.path.join(data_dir, "strong_P1_X6_1_0-1.pickle") pickle_path2 = os.path.join(data_dir, "strong_P1_X6_2_0-1.pickle") datablock_path1 = os.path.join(data_dir, "datablock_P1_X6_1.json") datablock_path2 = os.path.join(data_dir, "datablock_P1_X6_2.json") args = ["dials.discover_better_experimental_model", datablock_path1, datablock_path2, pickle_path1, pickle_path2] command = " ".join(args) print command cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory() os.chdir(tmp_dir) result = easy_run.fully_buffered(command=command).raise_if_errors() assert os.path.exists('optimized_datablock.json') from dxtbx.serialize import load datablocks = load.datablock(datablock_path1, check_format=False) original_imageset = datablocks[0].extract_imagesets()[0] optimized_datablock = load.datablock('optimized_datablock.json', check_format=False) detector_1 = original_imageset.get_detector() detector_2 = optimized_datablock[0].unique_detectors()[0] shift = (matrix.col(detector_1[0].get_origin()) - matrix.col(detector_2[0].get_origin())) assert approx_equal(shift.elems, (-0.242, -0.125, 0.0), eps=1e-2) # This produces these two different solutions. # The two corresponding origin vectors are: # "origin": [ -208.507324496093, 209.20518907699287, -266.11 ] # "origin": [ -208.50831812992388, 209.20211805759828, -266.11 ] # The remainder of the optimized_datablock.json is identical. # # TODO: I don't know if both of these are legitimate, or if # this is a bug in discover_better_experimental_model. os.chdir(cwd)
def exercise_refine_bravais_settings_3(): if not have_dials_regression: print "Skipping exercise_refine_bravais_settings(): dials_regression not available." return data_dir = os.path.join(dials_regression, "indexing_test_data", "trypsin") pickle_path = os.path.join(data_dir, "indexed.pickle") experiments_path = os.path.join(data_dir, "experiments.json") commands = ["dials.refine_bravais_settings", pickle_path, experiments_path, "crystal_id=1"] command = " ".join(commands) print command cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory() os.chdir(tmp_dir) result = easy_run.fully_buffered(command=command).raise_if_errors() for i in range(1, 10): assert os.path.exists("bravais_setting_%i.json" %i) from dxtbx.serialize import load experiments_list = load.experiment_list( "bravais_setting_5.json", check_format=False) assert len(experiments_list) == 1 assert experiments_list[0].crystal.get_unit_cell().is_similar_to( uctbx.unit_cell((54.37, 58.29, 66.51, 90.00, 90.00, 90.00))) assert experiments_list[0].crystal.get_space_group().type().hall_symbol() \ == ' P 2 2' assert os.path.exists("bravais_summary.json") from json import load bravais_summary = load(open("bravais_summary.json", "rb")) assert bravais_summary.keys() == [ '1', '3', '2', '5', '4', '7', '6', '9', '8'] assert approx_equal( bravais_summary['5']['unit_cell'], [54.37, 58.29, 66.51, 90.00, 90.00, 90.00], eps=1e-1) assert bravais_summary['5']['bravais'] == 'oP' assert approx_equal(bravais_summary['5']['rmsd'], 0.1200, eps=1e-2) assert bravais_summary['5']['recommended'] == True assert bravais_summary['9']['recommended'] == False os.chdir(cwd)
def test1(): dials_regression = libtbx.env.find_in_repositories( relative_path="dials_regression", test=os.path.isdir) # use the i04_weak_data for this test data_dir = os.path.join(dials_regression, "refinement_test_data", "i04_weak_data") experiments_path = os.path.join(data_dir, "experiments.json") pickle_path = os.path.join(data_dir, "indexed_strong.pickle") for pth in (experiments_path, pickle_path): assert os.path.exists(pth) # set close_to_spindle_cutoff to old default cmd = "dials.refine close_to_spindle_cutoff=0.05 reflections_per_degree=100 " + \ experiments_path + " " + pickle_path print cmd # work in a temporary directory cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory(suffix="test_dials_refine") os.chdir(tmp_dir) try: result = easy_run.fully_buffered(command=cmd).raise_if_errors() # load results reg_exp = ExperimentListFactory.from_json_file( os.path.join(data_dir, "regression_experiments.json"), check_format=False)[0] ref_exp = ExperimentListFactory.from_json_file("refined_experiments.json", check_format=False)[0] finally: os.chdir(cwd) # clean up tmp dir shutil.rmtree(tmp_dir) # test refined models against expected assert reg_exp.crystal == ref_exp.crystal assert reg_exp.detector == ref_exp.detector assert reg_exp.beam == ref_exp.beam print "OK" return
def exercise_1(): data_dir = os.path.join(xia2_regression, "test_data", "X4_wide") cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory() os.chdir(tmp_dir) print tmp_dir g = sorted(glob.glob(os.path.join(data_dir, "X4_wide_M1S4_2_00*.cbf"))) assert len(g) == 90, len(g) commands = [ "dials.import %s" %" ".join(g), "dials.slice_sweep datablock.json scan_range=80,90", "dials.find_spots datablock_80_90.json", "dials.index datablock_80_90.json strong.pickle space_group=P41212", "dials.refine experiments.json indexed.pickle scan_varying=True", "dials.integrate refined_experiments.json indexed.pickle", "dials.export refined_experiments.json integrated.pickle" ] for cmd in commands: # print cmd result = easy_run.fully_buffered(cmd).raise_if_errors() integrated_mtz = "hklout.mtz" assert os.path.exists(integrated_mtz) from iotbx.reflection_file_reader import any_reflection_file reader = any_reflection_file(integrated_mtz) mtz_object = reader.file_content() assert mtz_object.column_labels()[:14] == ['H', 'K', 'L', 'M_ISYM', 'BATCH', 'IPR', 'SIGIPR', 'I', 'SIGI', 'BG', 'SIGBG', 'FRACTIONCALC', 'XDET', 'YDET'] assert len(mtz_object.batches()) == 11 batch = mtz_object.batches()[0] expected_unit_cell = uctbx.unit_cell( (42.5787, 42.5787, 40.2983, 90, 90, 90)) assert expected_unit_cell.is_similar_to(uctbx.unit_cell(list(batch.cell()))), ( expected_unit_cell.parameters(), list(batch.cell())) assert mtz_object.space_group().type().lookup_symbol() == "P 41 21 2" assert approx_equal(mtz_object.n_reflections(), 7446, eps=2e3) os.chdir(cwd)
def exercise_1(): if not have_dials_regression: print "Skipping exercise(): dials_regression not available." return data_dir = os.path.join(dials_regression, "indexing_test_data", "trypsin") pickle_path1 = os.path.join(data_dir, "strong_P1_X6_1_0-1.pickle") pickle_path2 = os.path.join(data_dir, "strong_P1_X6_2_0-1.pickle") datablock_path1 = os.path.join(data_dir, "datablock_P1_X6_1.json") datablock_path2 = os.path.join(data_dir, "datablock_P1_X6_2.json") args = [ "dials.discover_better_experimental_model", datablock_path1, datablock_path2, pickle_path1, pickle_path2 ] command = " ".join(args) print command cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory() os.chdir(tmp_dir) result = easy_run.fully_buffered(command=command).raise_if_errors() assert os.path.exists('optimized_datablock.json') from dxtbx.serialize import load datablocks = load.datablock(datablock_path1, check_format=False) original_imageset = datablocks[0].extract_imagesets()[0] optimized_datablock = load.datablock('optimized_datablock.json', check_format=False) detector_1 = original_imageset.get_detector() detector_2 = optimized_datablock[0].unique_detectors()[0] shift = (matrix.col(detector_1[0].get_origin()) - matrix.col(detector_2[0].get_origin())) assert approx_equal(shift.elems, (-0.242, -0.125, 0.0), eps=1e-2) # This produces these two different solutions. # The two corresponding origin vectors are: # "origin": [ -208.507324496093, 209.20518907699287, -266.11 ] # "origin": [ -208.50831812992388, 209.20211805759828, -266.11 ] # The remainder of the optimized_datablock.json is identical. # # TODO: I don't know if both of these are legitimate, or if # this is a bug in discover_better_experimental_model. os.chdir(cwd)
def test1(): dials_regression = libtbx.env.find_in_repositories(relative_path="dials_regression", test=os.path.isdir) # use multiple scan small molecule data for this test data_dir = os.path.join(dials_regression, "xia2-28") prefix = ["20", "25", "30", "35"] exp_path = [e + "_integrated_experiments.json" for e in prefix] exp_path = [os.path.join(data_dir, e) for e in exp_path] pkl_path = [e + "_integrated.pickle" for e in prefix] pkl_path = [os.path.join(data_dir, e) for e in pkl_path] for pth in exp_path + pkl_path: assert os.path.exists(pth), "%s missing" % pth cmd = "dials.two_theta_refine " + " ".join(exp_path) + " " + " ".join(pkl_path) + " cif=refined_cell.cif" print cmd # work in a temporary directory cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory(suffix="test_dials_two_theta_refine") os.chdir(tmp_dir) try: result = easy_run.fully_buffered(command=cmd).raise_if_errors() ref_exp = ExperimentListFactory.from_json_file("refined_cell.json", check_format=False) finally: os.chdir(cwd) xls = ref_exp.crystals() assert len(xls) == 1 # crystal models should have been combined xl = xls[0] # test refined crystal model against expected values assert approx_equal(xl.get_unit_cell().parameters(), (5.428022880, 8.144145476, 12.039666971, 90.0, 90.0, 90.0)) assert approx_equal(xl.get_cell_parameter_sd(), (9.58081e-5, 0.000149909, 0.000215765, 0, 0, 0)) assert approx_equal(xl.get_cell_volume_sd(), 0.0116254298) print "OK" return
def exercise_smart_load(show_timings=False, exercise_url=False): from libtbx.test_utils import open_tmp_directory from libtbx.utils import time_log import libtbx import os, shutil name = ["cif_core.dic", "cif_mm.dic"][0] url = [cif_core_dic_url, cif_mm_dic_url][0] # from gz gz_timer = time_log("from gz").start() cd = validation.smart_load_dictionary(name=name) gz_timer.stop() if exercise_url: tempdir = open_tmp_directory() store_dir = libtbx.env.under_dist(module_name='iotbx', path='cif/dictionaries') file_path = os.path.join(store_dir, name) + '.gz' shutil.copy(os.path.join(store_dir, name) + '.gz', tempdir) # from url url_timer = time_log("from url").start() cd = validation.smart_load_dictionary(url=url, store_dir=tempdir) url_timer.stop() # from url to file url_to_file_timer = time_log("url to file").start() cd = validation.smart_load_dictionary(url=url, save_local=True, store_dir=tempdir) url_to_file_timer.stop() # read local file file_timer = time_log("from file").start() cd = validation.smart_load_dictionary( file_path=os.path.join(tempdir, name)) file_timer.stop() if show_timings: print(time_log.legend) print(gz_timer.report()) if exercise_url: print(url_timer.report()) print(url_to_file_timer.report()) print(file_timer.report())
def test1(): dials_regression = libtbx.env.find_in_repositories( relative_path="dials_regression", test=os.path.isdir) # use the i04_weak_data for this test data_dir = os.path.join(dials_regression, "refinement_test_data", "i04_weak_data") experiments_path = os.path.join(data_dir, "experiments.json") pickle_path = os.path.join(data_dir, "indexed_strong.pickle") for pth in (experiments_path, pickle_path): assert os.path.exists(pth) cmd = "dials.slice_sweep " + experiments_path + " " + pickle_path + \ ' "image_range=1 20"' print cmd # work in a temporary directory cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory(suffix="test_dials_slice_sweep") os.chdir(tmp_dir) try: result = easy_run.fully_buffered(command=cmd).raise_if_errors() # load results sliced_exp = ExperimentListFactory.from_json_file( "experiments_1_20.json", check_format=False)[0] with open("indexed_strong_1_20.pickle", "r") as f: sliced_refs = pickle.load(f) finally: os.chdir(cwd) # simple test of results assert sliced_exp.scan.get_image_range() == (1, 20) assert len(sliced_refs) == 3670 print "OK" return
def test1(): dials_regression = libtbx.env.find_in_repositories( relative_path="dials_regression", test=os.path.isdir) # use the i04_weak_data for this test data_dir = os.path.join(dials_regression, "refinement_test_data", "i04_weak_data") experiments_path = os.path.join(data_dir, "experiments.json") pickle_path = os.path.join(data_dir, "indexed_strong.pickle") for pth in (experiments_path, pickle_path): assert os.path.exists(pth) cmd = "dials.slice_sweep " + experiments_path + " " + pickle_path + \ ' "scan_range=1 20"' print cmd # work in a temporary directory cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory(suffix="test_dials_slice_sweep") os.chdir(tmp_dir) try: result = easy_run.fully_buffered(command=cmd).raise_if_errors() # load results sliced_exp = ExperimentListFactory.from_json_file("experiments_1_20.json", check_format=False)[0] with open("indexed_strong_1_20.pickle", "r") as f: sliced_refs = pickle.load(f) finally: os.chdir(cwd) # simple test of results assert sliced_exp.scan.get_image_range() == (1, 20) assert len(sliced_refs) == 3670 print "OK" return
def test1(): # work in a temporary directory cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory(suffix="test_dials_filter_reflections") os.chdir(tmp_dir) # make a dummy reflection table for the test, setting some flags from dials.array_family import flex rt = flex.reflection_table.empty_standard(6) rt["iobs"] = flex.size_t_range(len(rt)) mask1 = flex.bool([True] * 3 + [False] * 3) mask2 = flex.bool([True, False] * 3) rt.set_flags(mask1, rt.flags.integrated) rt.set_flags(mask2, rt.flags.bad_spot) rt_name = "test_refs.pickle" rt.as_pickle(rt_name) cmd = "dev.dials.filter_reflections " + rt_name + " inclusions.flag=integrated" + " exclusions.flag=bad_spot" print cmd try: result = easy_run.fully_buffered(command=cmd).raise_if_errors() # load results ref = flex.reflection_table.from_pickle("filtered.pickle") finally: os.chdir(cwd) # clean up tmp dir shutil.rmtree(tmp_dir) # The test selects only 1 reflection assert len(ref) == 1 assert list(ref["iobs"]) == [1] print "OK" return
def exercise_refine_bravais_settings_2(): if not have_dials_regression: print "Skipping exercise_refine_bravais_settings(): dials_regression not available." return data_dir = os.path.join(dials_regression, "indexing_test_data", "multi_sweep") pickle_path = os.path.join(data_dir, "indexed.pickle") experiments_path = os.path.join(data_dir, "experiments.json") commands = ["dials.refine_bravais_settings", pickle_path, experiments_path] command = " ".join(commands) print command cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory() os.chdir(tmp_dir) result = easy_run.fully_buffered(command=command).raise_if_errors() for i in range(1, 10): assert os.path.exists("bravais_setting_%i.json" %i) from dxtbx.serialize import load experiments_list = load.experiment_list( "bravais_setting_9.json", check_format=False) assert len(experiments_list) == 4 assert len(experiments_list.crystals()) == 1 assert experiments_list[0].crystal.get_unit_cell().is_similar_to( uctbx.unit_cell((7.31, 7.31, 6.82, 90.00, 90.00, 90.00))) assert experiments_list[0].crystal.get_space_group().type().hall_symbol() \ == ' I 4' assert os.path.exists("bravais_summary.json") from json import load bravais_summary = load(open("bravais_summary.json", "rb")) for i in range(1, 23): assert str(i) in bravais_summary.keys() assert approx_equal( bravais_summary['9']['unit_cell'], [7.31, 7.31, 6.82, 90.00, 90.00, 90.00], eps=1e-1) assert bravais_summary['9']['bravais'] == 'tI' assert approx_equal(bravais_summary['9']['rmsd'], 0.103, eps=1e-2) assert bravais_summary['9']['recommended'] == True os.chdir(cwd)
def run_indexing(datablock, strong_spots, crystal_model, rmsds): cwd = os.path.abspath(os.curdir) tmp_dir = os.path.abspath(open_tmp_directory(suffix="test_dials_index")) os.chdir(tmp_dir) sweep_path = os.path.join(tmp_dir, "datablock.json") pickle_path = os.path.join(tmp_dir, "strong.pickle") dump.datablock(datablock, sweep_path) easy_pickle.dump(pickle_path, strong_spots) from dials.test.algorithms.indexing.tst_index import run_one_indexing space_group_info = crystal_model.get_space_group() symmetry = crystal.symmetry(unit_cell=crystal_model.get_unit_cell(), space_group=crystal_model.get_space_group()) expected_rmsds = [1.1 * r for r in rmsds] imageset = datablock[0].extract_imagesets()[0] pixel_size = imageset.get_detector()[0].get_pixel_size() phi_width = imageset.get_scan().get_oscillation()[1] * math.pi / 180 expected_rmsds = [ 1.1 * rmsds[0] * pixel_size[0], 1.1 * rmsds[1] * pixel_size[1], 1.1 * rmsds[2] * phi_width ] run_one_indexing( pickle_path=pickle_path, sweep_path=sweep_path, extra_args=[], expected_unit_cell=symmetry.minimum_cell().unit_cell(), expected_rmsds=expected_rmsds, #expected_hall_symbol=crystal_model.get_space_group().type().hall_symbol(), expected_hall_symbol=' P 1', )
def exercise_smart_load(show_timings=False, exercise_url=False): from libtbx.test_utils import open_tmp_directory from libtbx.utils import time_log import libtbx import os, shutil name = ["cif_core.dic", "cif_mm.dic"][0] url = [cif_core_dic_url, cif_mm_dic_url][0] # from gz gz_timer = time_log("from gz").start() cd = validation.smart_load_dictionary(name=name) gz_timer.stop() if exercise_url: tempdir = open_tmp_directory() store_dir = libtbx.env.under_dist( module_name='iotbx', path='cif/dictionaries') file_path = os.path.join(store_dir, name) + '.gz' shutil.copy(os.path.join(store_dir, name) + '.gz', tempdir) # from url url_timer = time_log("from url").start() cd = validation.smart_load_dictionary(url=url, store_dir=tempdir) url_timer.stop() # from url to file url_to_file_timer = time_log("url to file").start() cd = validation.smart_load_dictionary( url=url, save_local=True, store_dir=tempdir) url_to_file_timer.stop() # read local file file_timer = time_log("from file").start() cd = validation.smart_load_dictionary(file_path=os.path.join(tempdir, name)) file_timer.stop() if show_timings: print time_log.legend print gz_timer.report() if exercise_url: print url_timer.report() print url_to_file_timer.report() print file_timer.report()
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") strong_pickle = os.path.join(data_dir, "strong.pickle") # work in a temporary directory cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory(suffix="rl_png_test1") os.chdir(tmp_dir) cmd = 'dials.rl_png %s %s' % (datablock_path, strong_pickle) result = easy_run.fully_buffered(command=cmd).raise_if_errors() for s in ('beam_vector', 'e3', 'rotation_axis', 'solution_1', 'solution_2', 'solution_3'): assert os.path.exists('rl_%s.png' % s), s os.chdir(cwd) return
def test1(): # work in a temporary directory cwd = os.path.abspath(os.curdir) tmp_dir = open_tmp_directory(suffix="test_dials_filter_reflections") os.chdir(tmp_dir) # make a dummy reflection table for the test, setting some flags from dials.array_family import flex rt = flex.reflection_table.empty_standard(6) rt['iobs'] = flex.size_t_range(len(rt)) mask1 = flex.bool([True] * 3 + [False] * 3) mask2 = flex.bool([True, False] * 3) rt.set_flags(mask1, rt.flags.integrated) rt.set_flags(mask2, rt.flags.bad_spot) rt_name = "test_refs.pickle" rt.as_pickle(rt_name) cmd = "dev.dials.filter_reflections " + rt_name + " inclusions.flag=integrated" + \ " exclusions.flag=bad_spot" print cmd try: result = easy_run.fully_buffered(command=cmd).raise_if_errors() # load results ref = flex.reflection_table.from_pickle("filtered.pickle") finally: os.chdir(cwd) # The test selects only 1 reflection assert len(ref) == 1 assert list(ref['iobs']) == [1] print "OK" return