def export(self): ''' Export the files ''' from dials.util.mosflm import dump dump(self.experiments, self.params.mosflm.directory)
def export(self): ''' Export the files ''' from dials.util.xds import dump dump(self.experiments, self.reflections, self.params.xds.directory)
def export(self): ''' Export the files ''' from dials.util.nexus import dump dump(self.experiments, self.reflections, self.params.nxs.hklout)
def export(self): ''' Export the files ''' from dials.util.mosflm import dump dump( self.experiments, self.params.mosflm.directory)
def export(self): ''' Export the files ''' from dials.util.xds import dump dump( self.experiments, self.reflections, self.params.xds.directory)
def export(self): ''' Export the files ''' from dials.util.nexus import dump dump( self.experiments, self.reflections, self.params.nxs.hklout)
def export_nexus(params, experiments, reflections): """ Export data in Nexus format :param params: The phil parameters :param experiments: The experiment list :param reflections: The reflection tables """ _check_input(experiments, reflections) from dials.util.nexus import dump dump(experiments, reflections[0], params.nxs)
def export_mosflm(params, experiments, reflections): """ Export stuff in mosflm format :param params: The phil parameters :param experiments: The experiment list :param reflections: The reflection tables """ _check_input(experiments, [None]) if reflections: sys.exit("Mosflm exporter does not need a reflection table") from dials.util.mosflm import dump dump(experiments, params.mosflm.directory)
def export_xds(params, experiments, reflections): """ Export stuff in xds format :param params: The phil parameters :param experiments: The experiment list :param reflections: The reflection tables """ # Check the input if len(reflections) > 1: sys.exit("XDS exporter requires 0 or 1 reflection table") if reflections: reflections = reflections[0] from dials.util.xds import dump dump(experiments, reflections, params.xds.directory)
def test_run(dials_regression, run_in_tmpdir): from os.path import join from dxtbx.model.experiment_list import ExperimentListFactory from dials.array_family import flex from dials.command_line.export import phil_scope from dials.util.nexus import dump, load path = join(dials_regression, "nexus_test_data") # Read the experiments experiments1 = ExperimentListFactory.from_json_file( join(path, "refined_experiments.json")) # Read the reflections reflections1 = flex.reflection_table.from_file( join(path, "integrated.pickle")) # Delete some columns for the test del reflections1["s1"] del reflections1["zeta"] del reflections1["background.mse"] # Dump the reflections params = phil_scope.extract() params.nxs.hklout = "hklout.nxs" dump(experiments1, reflections1, params.nxs) # Load them again experiments2, reflections2 = load("hklout.nxs") EPS = 1e-7 # Check the reflections are OK assert reflections1.nrows() == reflections2.nrows() assert reflections1.ncols() == reflections2.ncols() for key in reflections1.keys(): data1 = reflections1[key] data2 = reflections2[key] assert data1.__class__ == data2.__class__ if isinstance(data1, flex.double): assert data1.all_approx_equal(data2) elif isinstance(data1, flex.int6): for p1, p2 in zip(data1.parts(), data2.parts()): assert p1.all_eq(p2) elif isinstance(data1, flex.vec3_double): for p1, p2 in zip(data1.parts(), data2.parts()): assert p1.all_approx_equal(p2) else: assert data1.all_eq(data2) # Test passed # Check the experiments are ok assert len(experiments1) == len(experiments2) exp1 = experiments1[0] exp2 = experiments2[0] # Check the beam b1 = exp1.beam b2 = exp2.beam assert all( abs(d1 - d2) < EPS for d1, d2 in zip(b1.get_sample_to_source_direction(), b2.get_sample_to_source_direction())) assert abs(b1.get_wavelength() - b2.get_wavelength()) < EPS assert abs(b1.get_polarization_fraction() - b2.get_polarization_fraction()) < EPS assert all( abs(d1 - d2) < EPS for d1, d2 in zip(b1.get_polarization_normal(), b2.get_polarization_normal())) # Check the goniometer g1 = exp1.goniometer g2 = exp2.goniometer assert all( abs(d1 - d2) < EPS for d1, d2 in zip(g1.get_rotation_axis(), g2.get_rotation_axis())) assert all( abs(d1 - d2) < EPS for d1, d2 in zip(g1.get_fixed_rotation(), g2.get_fixed_rotation())) assert all( abs(d1 - d2) < EPS for d1, d2 in zip(g1.get_setting_rotation(), g2.get_setting_rotation())) # Check the scan s1 = exp1.scan s2 = exp2.scan assert len(s1) == len(s2) assert s1.get_image_range() == s2.get_image_range() assert abs(s1.get_oscillation()[0] - s1.get_oscillation()[0]) < EPS assert abs(s1.get_oscillation()[1] - s1.get_oscillation()[1]) < EPS for e1, e2 in zip(s1.get_exposure_times(), s2.get_exposure_times()): assert abs(e1 - e2) < EPS for e1, e2 in zip(s1.get_epochs(), s2.get_epochs()): assert abs(e1 - e2) < EPS # Check the detector d1 = exp1.detector d2 = exp2.detector assert len(d1) == len(d2) for p1, p2 in zip(d1, d2): assert p1.get_type() == p2.get_type() assert p1.get_material() == p2.get_material() assert p1.get_thickness() == p2.get_thickness() assert p1.get_image_size() == p2.get_image_size() assert p1.get_pixel_size() == p2.get_pixel_size() assert p1.get_trusted_range() == p2.get_trusted_range() for x1, x2 in zip(p1.get_fast_axis(), p2.get_fast_axis()): assert abs(x1 - x2) < EPS for x1, x2 in zip(p1.get_slow_axis(), p2.get_slow_axis()): assert abs(x1 - x2) < EPS for x1, x2 in zip(p1.get_origin(), p2.get_origin()): assert abs(x1 - x2) < EPS # Check the crystal c1 = exp1.crystal c2 = exp2.crystal assert c1.get_space_group() == c2.get_space_group() for p1, p2 in zip(c1.get_unit_cell().parameters(), c2.get_unit_cell().parameters()): assert abs(p1 - p2) < EPS for p1, p2 in zip(c1.get_A(), c2.get_A()): assert abs(p1 - p2) < EPS assert c1.num_scan_points == c2.num_scan_points for i in range(c1.num_scan_points): A1 = c1.get_A_at_scan_point(i) A2 = c2.get_A_at_scan_point(i) for a1, a2 in zip(A1, A2): assert abs(a1 - a2) < EPS uc1 = c1.get_unit_cell_at_scan_point(i) uc2 = c2.get_unit_cell_at_scan_point(i) for p1, p2 in zip(uc1.parameters(), uc2.parameters()): assert abs(p1 - p2) < EPS
# Read the experiments experiments1 = ExperimentListFactory.from_json_file( join(path, "refined_experiments.json")) # Read the reflections reflections1 = flex.reflection_table.from_pickle( join(path, "integrated.pickle")) # Delete some columns for the test del reflections1['s1'] del reflections1['zeta'] del reflections1['background.mse'] # Dump the reflections dump(experiments1, reflections1, "hklout.nxs") # Load them again experiments2, reflections2 = load("hklout.nxs") EPS = 1e-7 # Check the reflections are OK assert (reflections1.nrows() == reflections2.nrows()) assert (reflections1.ncols() == reflections2.ncols()) for key in reflections1.keys(): data1 = reflections1[key] data2 = reflections2[key] assert (data1.__class__ == data2.__class__) if isinstance(data1, flex.double): assert (data1.all_approx_equal(data2))
def run_single(experiments1, filename): from dials.util.nexus import dump, load from math import pi from scitbx import matrix EPS = 1e-7 try: run_single.count += 1 except Exception: run_single.count = 0 # Dump the file dump(experiments1, None, filename) # Load the file experiments2, reflections = load(filename) assert(experiments2 is not None) assert(reflections is None) assert(len(experiments2) == len(experiments1)) index1 = [] index2 = [] for exp1, exp2 in zip(experiments1, experiments2): # Check the beam b1 = exp1.beam b2 = exp2.beam assert(all(abs(d1 - d2) < EPS for d1, d2 in zip(b1.get_direction(), b2.get_direction()))) assert(abs(b1.get_wavelength() - b2.get_wavelength()) < EPS) assert(abs(b1.get_polarization_fraction() - b2.get_polarization_fraction()) < EPS) n1 = matrix.col(b1.get_polarization_normal()) n2 = matrix.col(b2.get_polarization_normal()) angle = n2.angle(n1) assert(abs(angle) < EPS or abs(angle - pi) < EPS or abs(angle-2*pi) < EPS) # Check the goniometer g1 = exp1.goniometer g2 = exp2.goniometer if g1 is not None: assert(all(abs(d1 - d2) < EPS for d1, d2 in zip(g1.get_rotation_axis(), g2.get_rotation_axis()))) assert(all(abs(d1 - d2) < EPS for d1, d2 in zip(g1.get_fixed_rotation(), g2.get_fixed_rotation()))) assert(all(abs(d1 - d2) < EPS for d1, d2 in zip(g1.get_setting_rotation(), g2.get_setting_rotation()))) else: assert(g2 is None) # Check the scan s1 = exp1.scan s2 = exp2.scan if s1 is not None: assert(len(s1) == len(s2)) assert(s1.get_image_range() == s2.get_image_range()) assert(abs(s1.get_oscillation()[0] - s1.get_oscillation()[0]) < EPS) assert(abs(s1.get_oscillation()[1] - s1.get_oscillation()[1]) < EPS) for e1, e2 in zip(s1.get_exposure_times(), s2.get_exposure_times()): assert(abs(e1 - e2) < EPS) for e1, e2 in zip(s1.get_epochs(), s2.get_epochs()): assert(abs(e1 - e2) < EPS) else: assert(s2 is None) # Check the detector d1 = exp1.detector d2 = exp2.detector assert(len(d1) == len(d2)) for p1, p2 in zip(d1, d2): assert(p1.get_type() == p2.get_type()) assert(p1.get_material() == p2.get_material()) assert(p1.get_thickness() == p2.get_thickness()) assert(p1.get_image_size() == p2.get_image_size()) assert(p1.get_pixel_size() == p2.get_pixel_size()) assert(p1.get_trusted_range() == p2.get_trusted_range()) for x1, x2 in zip(p1.get_fast_axis(), p2.get_fast_axis()): assert(abs(x1 - x2) < EPS) for x1, x2 in zip(p1.get_slow_axis(), p2.get_slow_axis()): assert(abs(x1 - x2) < EPS) for x1, x2 in zip(p1.get_origin(), p2.get_origin()): assert(abs(x1 - x2) < EPS) # Check the crystal c1 = exp1.crystal c2 = exp2.crystal assert(c1.get_space_group() == c2.get_space_group()) for p1, p2 in zip(c1.get_unit_cell().parameters(), c2.get_unit_cell().parameters()): assert(abs(p1 -p2) < EPS) for p1, p2 in zip(c1.get_A(), c2.get_A()): assert(abs(p1 -p2) < EPS) assert(c1.num_scan_points == c2.num_scan_points) for i in range(c1.num_scan_points): A1 = c1.get_A_at_scan_point(i) A2 = c2.get_A_at_scan_point(i) for a1, a2 in zip(A1, A2): assert(abs(a1 - a2) < EPS) uc1 = c1.get_unit_cell_at_scan_point(i) uc2 = c2.get_unit_cell_at_scan_point(i) for p1, p2 in zip(uc1.parameters(), uc2.parameters()): assert(abs(p1-p2) < EPS) index1.append(( id(exp1.beam), id(exp1.detector), id(exp1.goniometer), id(exp1.scan), id(exp1.crystal))) index2.append(( id(exp2.beam), id(exp2.detector), id(exp2.goniometer), id(exp2.scan), id(exp2.crystal))) # Get a list of all beam etc beam1, detector1, goniometer1, scan1, crystal1 = zip(*index1) beam2, detector2, goniometer2, scan2, crystal2 = zip(*index2) # If any models are shared then check they are shard in both num = len(beam1) for i in range(0,num-1): for j in range(1,num): if (beam1[i] == beam1[j]): assert(beam2[i] == beam2[j]) else: assert(beam2[i] != beam2[j]) if (detector1[i] == detector1[j]): assert(detector2[i] == detector2[j]) else: assert(detector2[i] != detector2[j]) if (goniometer1[i] == goniometer1[j]): assert(goniometer2[i] == goniometer2[j]) else: assert(goniometer2[i] != goniometer2[j]) if (scan1[i] == scan1[j]): assert(scan2[i] == scan2[j]) else: assert(scan2[i] != scan2[j]) if (crystal1[i] == crystal1[j]): assert(crystal2[i] == crystal2[j]) else: assert(crystal2[i] != crystal2[j]) print 'OK'
def run_single(experiments1, filename): from dials.util.nexus import dump, load from math import pi from scitbx import matrix EPS = 1e-7 try: run_single.count += 1 except Exception: run_single.count = 0 # Dump the file dump(experiments1, None, filename) # Load the file experiments2, reflections = load(filename) assert (experiments2 is not None) assert (reflections is None) assert (len(experiments2) == len(experiments1)) index1 = [] index2 = [] for exp1, exp2 in zip(experiments1, experiments2): # Check the beam b1 = exp1.beam b2 = exp2.beam assert (all( abs(d1 - d2) < EPS for d1, d2 in zip(b1.get_direction(), b2.get_direction()))) assert (abs(b1.get_wavelength() - b2.get_wavelength()) < EPS) assert (abs(b1.get_polarization_fraction() - b2.get_polarization_fraction()) < EPS) n1 = matrix.col(b1.get_polarization_normal()) n2 = matrix.col(b2.get_polarization_normal()) angle = n2.angle(n1) assert (abs(angle) < EPS or abs(angle - pi) < EPS or abs(angle - 2 * pi) < EPS) # Check the goniometer g1 = exp1.goniometer g2 = exp2.goniometer if g1 is not None: assert (all( abs(d1 - d2) < EPS for d1, d2 in zip(g1.get_rotation_axis(), g2.get_rotation_axis()))) assert (all( abs(d1 - d2) < EPS for d1, d2 in zip(g1.get_fixed_rotation(), g2.get_fixed_rotation()))) assert (all( abs(d1 - d2) < EPS for d1, d2 in zip(g1.get_setting_rotation(), g2.get_setting_rotation()))) else: assert (g2 is None) # Check the scan s1 = exp1.scan s2 = exp2.scan if s1 is not None: assert (len(s1) == len(s2)) assert (s1.get_image_range() == s2.get_image_range()) assert (abs(s1.get_oscillation()[0] - s1.get_oscillation()[0]) < EPS) assert (abs(s1.get_oscillation()[1] - s1.get_oscillation()[1]) < EPS) for e1, e2 in zip(s1.get_exposure_times(), s2.get_exposure_times()): assert (abs(e1 - e2) < EPS) for e1, e2 in zip(s1.get_epochs(), s2.get_epochs()): assert (abs(e1 - e2) < EPS) else: assert (s2 is None) # Check the detector d1 = exp1.detector d2 = exp2.detector assert (len(d1) == len(d2)) for p1, p2 in zip(d1, d2): assert (p1.get_type() == p2.get_type()) assert (p1.get_material() == p2.get_material()) assert (p1.get_thickness() == p2.get_thickness()) assert (p1.get_image_size() == p2.get_image_size()) assert (p1.get_pixel_size() == p2.get_pixel_size()) assert (p1.get_trusted_range() == p2.get_trusted_range()) for x1, x2 in zip(p1.get_fast_axis(), p2.get_fast_axis()): assert (abs(x1 - x2) < EPS) for x1, x2 in zip(p1.get_slow_axis(), p2.get_slow_axis()): assert (abs(x1 - x2) < EPS) for x1, x2 in zip(p1.get_origin(), p2.get_origin()): assert (abs(x1 - x2) < EPS) # Check the crystal c1 = exp1.crystal c2 = exp2.crystal assert (c1.get_space_group() == c2.get_space_group()) for p1, p2 in zip(c1.get_unit_cell().parameters(), c2.get_unit_cell().parameters()): assert (abs(p1 - p2) < EPS) for p1, p2 in zip(c1.get_A(), c2.get_A()): assert (abs(p1 - p2) < EPS) assert (c1.num_scan_points == c2.num_scan_points) for i in range(c1.num_scan_points): A1 = c1.get_A_at_scan_point(i) A2 = c2.get_A_at_scan_point(i) for a1, a2 in zip(A1, A2): assert (abs(a1 - a2) < EPS) uc1 = c1.get_unit_cell_at_scan_point(i) uc2 = c2.get_unit_cell_at_scan_point(i) for p1, p2 in zip(uc1.parameters(), uc2.parameters()): assert (abs(p1 - p2) < EPS) index1.append((id(exp1.beam), id(exp1.detector), id(exp1.goniometer), id(exp1.scan), id(exp1.crystal))) index2.append((id(exp2.beam), id(exp2.detector), id(exp2.goniometer), id(exp2.scan), id(exp2.crystal))) # Get a list of all beam etc beam1, detector1, goniometer1, scan1, crystal1 = zip(*index1) beam2, detector2, goniometer2, scan2, crystal2 = zip(*index2) # If any models are shared then check they are shard in both num = len(beam1) for i in range(0, num - 1): for j in range(1, num): if beam1[i] == beam1[j]: assert (beam2[i] == beam2[j]) else: assert (beam2[i] != beam2[j]) if detector1[i] == detector1[j]: assert (detector2[i] == detector2[j]) else: assert (detector2[i] != detector2[j]) if goniometer1[i] == goniometer1[j]: assert (goniometer2[i] == goniometer2[j]) else: assert (goniometer2[i] != goniometer2[j]) if scan1[i] == scan1[j]: assert (scan2[i] == scan2[j]) else: assert (scan2[i] != scan2[j]) if crystal1[i] == crystal1[j]: assert (crystal2[i] == crystal2[j]) else: assert (crystal2[i] != crystal2[j]) print 'OK'
def run(): from dials.util.nexus import dump, load from dxtbx.model.experiment_list import ExperimentListFactory from dials.array_family import flex from os.path import join import libtbx.load_env try: dials_regression = libtbx.env.dist_path('dials_regression') except KeyError: print 'Skipped: dials_regression not configured' exit(0) path = join(dials_regression, "nexus_test_data") # Read the experiments experiments1 = ExperimentListFactory.from_json_file( join(path, "refined_experiments.json")) # Read the reflections reflections1 = flex.reflection_table.from_pickle( join(path, "integrated.pickle")) # Delete some columns for the test del reflections1['s1'] del reflections1['zeta'] del reflections1['background.mse'] # Dump the reflections dump(experiments1, reflections1, "hklout.nxs") # Load them again experiments2, reflections2 = load("hklout.nxs") EPS = 1e-7 # Check the reflections are OK assert(reflections1.nrows() == reflections2.nrows()) assert(reflections1.ncols() == reflections2.ncols()) for key in reflections1.keys(): data1 = reflections1[key] data2 = reflections2[key] assert(data1.__class__ == data2.__class__) if isinstance(data1, flex.double): assert(data1.all_approx_equal(data2)) elif isinstance(data1, flex.int6): for p1, p2 in zip(data1.parts(), data2.parts()): assert(p1.all_eq(p2)) elif isinstance(data1, flex.vec3_double): for p1, p2 in zip(data1.parts(), data2.parts()): assert(p1.all_approx_equal(p2)) else: assert(data1.all_eq(data2)) # Test passed print 'OK' # Check the experiments are ok assert(len(experiments1) == len(experiments2)) exp1 = experiments1[0] exp2 = experiments2[0] # Check the beam b1 = exp1.beam b2 = exp2.beam assert(all(abs(d1 - d2) < EPS for d1, d2 in zip(b1.get_direction(), b2.get_direction()))) assert(abs(b1.get_wavelength() - b2.get_wavelength()) < EPS) assert(abs(b1.get_polarization_fraction() - b2.get_polarization_fraction()) < EPS) assert(all(abs(d1 - d2) < EPS for d1, d2 in zip(b1.get_polarization_normal(), b2.get_polarization_normal()))) print 'OK' # Check the goniometer g1 = exp1.goniometer g2 = exp2.goniometer assert(all(abs(d1 - d2) < EPS for d1, d2 in zip(g1.get_rotation_axis(), g2.get_rotation_axis()))) assert(all(abs(d1 - d2) < EPS for d1, d2 in zip(g1.get_fixed_rotation(), g2.get_fixed_rotation()))) assert(all(abs(d1 - d2) < EPS for d1, d2 in zip(g1.get_setting_rotation(), g2.get_setting_rotation()))) print 'OK' # Check the scan s1 = exp1.scan s2 = exp2.scan assert(len(s1) == len(s2)) assert(s1.get_image_range() == s2.get_image_range()) assert(abs(s1.get_oscillation()[0] - s1.get_oscillation()[0]) < EPS) assert(abs(s1.get_oscillation()[1] - s1.get_oscillation()[1]) < EPS) for e1, e2 in zip(s1.get_exposure_times(), s2.get_exposure_times()): assert(abs(e1 - e2) < EPS) for e1, e2 in zip(s1.get_epochs(), s2.get_epochs()): assert(abs(e1 - e2) < EPS) print 'OK' # Check the detector d1 = exp1.detector d2 = exp2.detector assert(len(d1) == len(d2)) for p1, p2 in zip(d1, d2): assert(p1.get_type() == p2.get_type()) assert(p1.get_material() == p2.get_material()) assert(p1.get_thickness() == p2.get_thickness()) assert(p1.get_image_size() == p2.get_image_size()) assert(p1.get_pixel_size() == p2.get_pixel_size()) assert(p1.get_trusted_range() == p2.get_trusted_range()) for x1, x2 in zip(p1.get_fast_axis(), p2.get_fast_axis()): assert(abs(x1 - x2) < EPS) for x1, x2 in zip(p1.get_slow_axis(), p2.get_slow_axis()): assert(abs(x1 - x2) < EPS) for x1, x2 in zip(p1.get_origin(), p2.get_origin()): assert(abs(x1 - x2) < EPS) print 'OK' # Check the crystal c1 = exp1.crystal c2 = exp2.crystal assert(c1.get_space_group() == c2.get_space_group()) for p1, p2 in zip(c1.get_unit_cell().parameters(), c2.get_unit_cell().parameters()): assert(abs(p1 -p2) < EPS) for p1, p2 in zip(c1.get_A(), c2.get_A()): assert(abs(p1 -p2) < EPS) assert(c1.num_scan_points == c2.num_scan_points) for i in range(c1.num_scan_points): A1 = c1.get_A_at_scan_point(i) A2 = c2.get_A_at_scan_point(i) for a1, a2 in zip(A1, A2): assert(abs(a1 - a2) < EPS) uc1 = c1.get_unit_cell_at_scan_point(i) uc2 = c2.get_unit_cell_at_scan_point(i) for p1, p2 in zip(uc1.parameters(), uc2.parameters()): assert(abs(p1-p2) < EPS) print 'OK'
# Read the experiments experiments1 = ExperimentListFactory.from_json_file( join(path, "refined_experiments.json")) # Read the reflections reflections1 = flex.reflection_table.from_pickle( join(path, "integrated.pickle")) # Delete some columns for the test del reflections1['s1'] del reflections1['zeta'] del reflections1['background.mse'] # Dump the reflections dump(experiments1, reflections1, "hklout.nxs") # Load them again experiments2, reflections2 = load("hklout.nxs") EPS = 1e-7 # Check the reflections are OK assert(reflections1.nrows() == reflections2.nrows()) assert(reflections1.ncols() == reflections2.ncols()) for key in reflections1.keys(): data1 = reflections1[key] data2 = reflections2[key] assert(data1.__class__ == data2.__class__) if isinstance(data1, flex.double): assert(data1.all_approx_equal(data2))