def test(dials_regression): from iotbx.xds import xparm, integrate_hkl from dials.util import ioutil from dials.algorithms.spot_prediction import IndexGenerator import numpy from rstbx.cftbx.coordinate_frame_converter import \ coordinate_frame_converter from scitbx import matrix # The XDS files to read from integrate_filename = os.path.join(dials_regression, 'data', 'sim_mx', 'INTEGRATE.HKL') gxparm_filename = os.path.join(dials_regression, 'data', 'sim_mx', 'GXPARM.XDS') # Read the XDS files integrate_handle = integrate_hkl.reader() integrate_handle.read_file(integrate_filename) gxparm_handle = xparm.reader() gxparm_handle.read_file(gxparm_filename) # Get the parameters we need from the GXPARM file d_min = 1.6 space_group_type = ioutil.get_space_group_type_from_xparm(gxparm_handle) cfc = coordinate_frame_converter(gxparm_filename) a_vec = cfc.get('real_space_a') b_vec = cfc.get('real_space_b') c_vec = cfc.get('real_space_c') unit_cell = cfc.get_unit_cell() UB = matrix.sqr(a_vec + b_vec + c_vec).inverse() ub_matrix = UB # Generate the indices index_generator = IndexGenerator(unit_cell, space_group_type, d_min) miller_indices = index_generator.to_array() # Get individual generated hkl gen_h = [hkl[0] for hkl in miller_indices] gen_k = [hkl[1] for hkl in miller_indices] gen_l = [hkl[2] for hkl in miller_indices] # Get individual xds generated hkl xds_h = [hkl[0] for hkl in integrate_handle.hkl] xds_k = [hkl[1] for hkl in integrate_handle.hkl] xds_l = [hkl[2] for hkl in integrate_handle.hkl] # Get min/max generated hkl min_gen_h, max_gen_h = numpy.min(gen_h), numpy.max(gen_h) min_gen_k, max_gen_k = numpy.min(gen_k), numpy.max(gen_k) min_gen_l, max_gen_l = numpy.min(gen_l), numpy.max(gen_l) # Get min/max xds generated hkl min_xds_h, max_xds_h = numpy.min(xds_h), numpy.max(xds_h) min_xds_k, max_xds_k = numpy.min(xds_k), numpy.max(xds_k) min_xds_l, max_xds_l = numpy.min(xds_l), numpy.max(xds_l) # Ensure we have the whole xds range in the generated set assert min_gen_h <= min_xds_h and max_gen_h >= max_xds_h assert min_gen_k <= min_xds_k and max_gen_k >= max_xds_k assert min_gen_l <= min_xds_l and max_gen_l >= max_xds_l
class Test(object): def __init__(self): pass def run(self): from iotbx.xds import integrate_hkl import os import libtbx.load_env try: iotbx_dir = libtbx.env.dist_path('iotbx') except KeyError, e: print 'FAIL: dials_regression not configured' return filename = os.path.join(iotbx_dir, 'xds', 'tests', 'INTEGRATE.HKL') handle = integrate_hkl.reader() handle.read_file(filename) handle.space_group handle.unit_cell handle.detector_size handle.pixel_size handle.starting_frame handle.starting_angle handle.oscillation_range handle.rotation_axis handle.wavelength handle.beam_vector handle.detector_x_axis handle.detector_y_axis handle.detector_origin handle.detector_distance handle.unit_cell_a_axis handle.unit_cell_b_axis handle.unit_cell_c_axis handle.sigma_divergence handle.sigma_mosaicity handle.template handle.detector_type handle.minpk handle.cut handle.variance_model from iotbx.reflection_file_reader import any_reflection_file file_in = any_reflection_file(filename) assert file_in.file_type() == 'xds_integrate_hkl' miller_arrays = file_in.as_miller_arrays() assert len(miller_arrays) == 10 assert miller_arrays[0].space_group().type().number( ) == handle.space_group content = file_in.file_content() assert content.beam_vector == (-0.001316, 0.001644, 1.020927) assert content.wavelength == 0.9795 print 'OK'
def __call__(self, params, options): ''' Import the integrate.hkl file. ''' from iotbx.xds import integrate_hkl from dials.array_family import flex from dials.util.command_line import Command from cctbx import sgtbx # Get the unit cell to calculate the resolution uc = self._experiment.crystal.get_unit_cell() # Read the INTEGRATE.HKL file Command.start('Reading INTEGRATE.HKL') handle = integrate_hkl.reader() handle.read_file(self._integrate_hkl) hkl = flex.miller_index(handle.hkl) xyzcal = flex.vec3_double(handle.xyzcal) xyzobs = flex.vec3_double(handle.xyzobs) iobs = flex.double(handle.iobs) sigma = flex.double(handle.sigma) rlp = flex.double(handle.rlp) peak = flex.double(handle.peak) * 0.01 Command.end('Read %d reflections from INTEGRATE.HKL file.' % len(hkl)) # Derive the reindex matrix rdx = self.derive_reindex_matrix(handle) print 'Reindex matrix:\n%d %d %d\n%d %d %d\n%d %d %d' % (rdx.elems) # Reindex the reflections Command.start('Reindexing reflections') cb_op = sgtbx.change_of_basis_op(sgtbx.rt_mx(sgtbx.rot_mx(rdx.elems))) hkl = cb_op.apply(hkl) Command.end('Reindexed %d reflections' % len(hkl)) # Create the reflection list Command.start('Creating reflection table') table = flex.reflection_table() table['id'] = flex.int(len(hkl), 0) table['panel'] = flex.size_t(len(hkl), 0) table['miller_index'] = hkl table['xyzcal.px'] = xyzcal table['xyzobs.px.value'] = xyzobs table['intensity.cor.value'] = iobs table['intensity.cor.variance'] = sigma**2 table['intensity.prf.value'] = iobs * peak / rlp table['intensity.prf.variance'] = (sigma * peak / rlp)**2 table['lp'] = 1.0 / rlp table['d'] = flex.double(uc.d(h) for h in hkl) Command.end('Created table with {0} reflections'.format(len(table))) # Output the table to pickle file if params.output.filename is None: params.output.filename = 'integrate_hkl.pickle' Command.start('Saving reflection table to %s' % params.output.filename) table.as_pickle(params.output.filename) Command.end('Saved reflection table to %s' % params.output.filename)
def test(dials_regression): import numpy as np from iotbx.xds import integrate_hkl, xparm from rstbx.cftbx.coordinate_frame_converter import coordinate_frame_converter from dials.algorithms.spot_prediction import IndexGenerator from dials.util import ioutil # The XDS files to read from integrate_filename = os.path.join(dials_regression, "data", "sim_mx", "INTEGRATE.HKL") gxparm_filename = os.path.join(dials_regression, "data", "sim_mx", "GXPARM.XDS") # Read the XDS files integrate_handle = integrate_hkl.reader() integrate_handle.read_file(integrate_filename) gxparm_handle = xparm.reader() gxparm_handle.read_file(gxparm_filename) # Get the parameters we need from the GXPARM file d_min = 1.6 space_group_type = ioutil.get_space_group_type_from_xparm(gxparm_handle) cfc = coordinate_frame_converter(gxparm_filename) unit_cell = cfc.get_unit_cell() # Generate the indices index_generator = IndexGenerator(unit_cell, space_group_type, d_min) miller_indices = index_generator.to_array() # Get individual generated hkl gen_h = [hkl[0] for hkl in miller_indices] gen_k = [hkl[1] for hkl in miller_indices] gen_l = [hkl[2] for hkl in miller_indices] # Get individual xds generated hkl xds_h = [hkl[0] for hkl in integrate_handle.hkl] xds_k = [hkl[1] for hkl in integrate_handle.hkl] xds_l = [hkl[2] for hkl in integrate_handle.hkl] # Get min/max generated hkl min_gen_h, max_gen_h = np.min(gen_h), np.max(gen_h) min_gen_k, max_gen_k = np.min(gen_k), np.max(gen_k) min_gen_l, max_gen_l = np.min(gen_l), np.max(gen_l) # Get min/max xds generated hkl min_xds_h, max_xds_h = np.min(xds_h), np.max(xds_h) min_xds_k, max_xds_k = np.min(xds_k), np.max(xds_k) min_xds_l, max_xds_l = np.min(xds_l), np.max(xds_l) # Ensure we have the whole xds range in the generated set assert min_gen_h <= min_xds_h and max_gen_h >= max_xds_h assert min_gen_k <= min_xds_k and max_gen_k >= max_xds_k assert min_gen_l <= min_xds_l and max_gen_l >= max_xds_l
def __call__(self): from iotbx.xds import integrate_hkl from scipy.interpolate import griddata from scitbx import matrix from matplotlib import pylab import numpy # Read the file print("Read INTEGRATE.HKL") handle = integrate_hkl.reader() handle.read_file(self.integrate_file) # Get the data xyzcal = handle.xyzcal xyzobs = handle.xyzobs iobs = handle.iobs sigma = handle.sigma width, height = handle.detector_size print("Get Diff arrays") diff = [] x = [] y = [] for c, o, i, sig in zip(xyzcal, xyzobs, iobs, sigma): o = matrix.col(o) c = matrix.col(c) if o.length() > 0 and c[2] < 10: # Calculate the difference diff.append((c - o).length()) x.append(c[0]) y.append(c[1]) print("Create grid array") xp = numpy.arange(width * height, dtype=numpy.int32) % width yp = numpy.arange(width * height, dtype=numpy.int32) / width points = numpy.zeros(shape=(width * height, 2), dtype=numpy.int32) points[:, 0] = xp points[:, 1] = yp print("Grid data") grid = griddata((x, y), diff, points, "cubic", 0) grid.shape = (height, width) pylab.imshow(grid) pylab.scatter(x, y) pylab.show()
def __call__(self): from iotbx.xds import integrate_hkl from scipy.interpolate import griddata from scitbx import matrix from matplotlib import pylab import numpy # Read the file print "Read INTEGRATE.HKL" handle = integrate_hkl.reader() handle.read_file(self.integrate_file) # Get the data xyzcal = handle.xyzcal xyzobs = handle.xyzobs iobs = handle.iobs sigma = handle.sigma width, height = handle.detector_size print "Get Diff arrays" diff = [] x = [] y = [] for c, o, i, sig in zip(xyzcal, xyzobs, iobs, sigma): o = matrix.col(o) c = matrix.col(c) if o.length() > 0 and c[2] < 10: # Calculate the difference diff.append((c - o).length()) x.append(c[0]) y.append(c[1]) print "Create grid array" xp = numpy.arange(width * height, dtype=numpy.int32) % width yp = numpy.arange(width * height, dtype=numpy.int32) / width points = numpy.zeros(shape=(width * height, 2), dtype=numpy.int32) points[:,0] = xp points[:,1] = yp print "Grid data" grid = griddata((x, y), diff, points, 'cubic', 0) grid.shape = (height, width) pylab.imshow(grid) pylab.scatter(x, y) pylab.show()
def loadReflections(self): Arrays = {} for x in self.argList: if reader.is_integrate_hkl_file(x): Arrays[x] = reader().as_miller_arrays(x) else: hklFile = any_reflection_file(x) Arrays[x] = hklFile.as_miller_arrays() print('File %s has been loaded' % (x)) #Printing output file print('Labels', file=self.LogFile) for n in enumerate(self.argList): print('INPUT_FILE: %s %s' % (n[0], n[1]), file=self.LogFile) return Arrays
def __call__(self, params, options): ''' Import the integrate.hkl file. ''' from iotbx.xds import integrate_hkl from dials.array_family import flex from dials.util.command_line import Command from cctbx import sgtbx # Get the unit cell to calculate the resolution uc = self._experiment.crystal.get_unit_cell() # Read the INTEGRATE.HKL file Command.start('Reading INTEGRATE.HKL') handle = integrate_hkl.reader() handle.read_file(self._integrate_hkl) hkl = flex.miller_index(handle.hkl) xyzcal = flex.vec3_double(handle.xyzcal) xyzobs = flex.vec3_double(handle.xyzobs) iobs = flex.double(handle.iobs) sigma = flex.double(handle.sigma) rlp = flex.double(handle.rlp) peak = flex.double(handle.peak) * 0.01 if len(handle.iseg): panel = flex.size_t(handle.iseg) - 1 else: panel = flex.size_t(len(hkl), 0) Command.end('Read %d reflections from INTEGRATE.HKL file.' % len(hkl)) if len(self._experiment.detector) > 1: for p_id, p in enumerate(self._experiment.detector): sel = (panel == p_id) offset = p.get_raw_image_offset() xyzcal.set_selected( sel, xyzcal.select(sel) - (offset[0], offset[1], 0)) xyzobs.set_selected( sel, xyzobs.select(sel) - (offset[0], offset[1], 0)) # Derive the reindex matrix rdx = self.derive_reindex_matrix(handle) print('Reindex matrix:\n%d %d %d\n%d %d %d\n%d %d %d' % (rdx.elems)) # Reindex the reflections Command.start('Reindexing reflections') cb_op = sgtbx.change_of_basis_op(sgtbx.rt_mx(sgtbx.rot_mx(rdx.elems))) hkl = cb_op.apply(hkl) Command.end('Reindexed %d reflections' % len(hkl)) # Create the reflection list Command.start('Creating reflection table') table = flex.reflection_table() table['id'] = flex.int(len(hkl), 0) table['panel'] = panel table['miller_index'] = hkl table['xyzcal.px'] = xyzcal table['xyzobs.px.value'] = xyzobs table['intensity.cor.value'] = iobs table['intensity.cor.variance'] = sigma**2 table['intensity.prf.value'] = iobs * peak / rlp table['intensity.prf.variance'] = (sigma * peak / rlp)**2 table['lp'] = 1.0 / rlp table['d'] = flex.double(uc.d(h) for h in hkl) Command.end('Created table with {0} reflections'.format(len(table))) # Output the table to pickle file if params.output.filename is None: params.output.filename = 'integrate_hkl.pickle' Command.start('Saving reflection table to %s' % params.output.filename) table.as_pickle(params.output.filename) Command.end('Saved reflection table to %s' % params.output.filename)
def test(dials_regression, run_in_tmpdir): import dxtbx from iotbx.xds import integrate_hkl, xparm from rstbx.cftbx.coordinate_frame_converter import coordinate_frame_converter from dials.algorithms.spot_prediction import RotationAngles # The XDS files to read from integrate_filename = os.path.join(dials_regression, "data/sim_mx/INTEGRATE.HKL") gxparm_filename = os.path.join(dials_regression, "data/sim_mx/GXPARM.XDS") # Read the XDS files integrate_handle = integrate_hkl.reader() integrate_handle.read_file(integrate_filename) gxparm_handle = xparm.reader() gxparm_handle.read_file(gxparm_filename) # Get the parameters we need from the GXPARM file models = dxtbx.load(gxparm_filename) beam = models.get_beam() gonio = models.get_goniometer() scan = models.get_scan() # Get the crystal parameters cfc = coordinate_frame_converter(gxparm_filename) a_vec = cfc.get("real_space_a") b_vec = cfc.get("real_space_b") c_vec = cfc.get("real_space_c") UB = matrix.sqr(a_vec + b_vec + c_vec).inverse() ub_matrix = UB # Get the number of frames from the max z value xcal, ycal, zcal = zip(*integrate_handle.xyzcal) num_frames = int(math.ceil(max(zcal))) scan.set_image_range((scan.get_image_range()[0], scan.get_image_range()[0] + num_frames - 1)) # Create the rotation angle object ra = RotationAngles(beam.get_s0(), gonio.get_rotation_axis()) # Setup the matrices ub = matrix.sqr(ub_matrix) s0 = matrix.col(beam.get_s0()) m2 = matrix.col(gonio.get_rotation_axis()) # For all the miller indices for h in integrate_handle.hkl: h = matrix.col(h) # Calculate the angles angles = ra(h, ub) # For all the angles for phi in angles: r = m2.axis_and_angle_as_r3_rotation_matrix(angle=phi) pstar = r * ub * h s1 = s0 + pstar assert s1.length() == pytest.approx(s0.length(), abs=1e-7) # Create a dict of lists of xy for each hkl gen_phi = {} for h in integrate_handle.hkl: # Calculate the angles angles = ra(h, ub) gen_phi[h] = angles # for phi in angles: # try: # a = gen_phi[h] # a.append(phi) # gen_phi[h] = a # except KeyError: # gen_phi[h] = [phi] # For each hkl in the xds file for hkl, xyz in zip(integrate_handle.hkl, integrate_handle.xyzcal): # Calculate the XDS phi value xds_phi = (scan.get_oscillation(deg=False)[0] + xyz[2] * scan.get_oscillation(deg=False)[1]) # Select the nearest xy to use if there are 2 my_phi = gen_phi[hkl] if len(my_phi) == 2: my_phi0 = my_phi[0] my_phi1 = my_phi[1] diff0 = abs(xds_phi - my_phi0) diff1 = abs(xds_phi - my_phi1) if diff0 < diff1: my_phi = my_phi0 else: my_phi = my_phi1 else: my_phi = my_phi[0] # Check the Phi values are the same assert xds_phi == pytest.approx(my_phi, abs=0.1)
def __init__(self): from dials.algorithms.spot_prediction import IndexGenerator from dials.algorithms.spot_prediction import ScanStaticRayPredictor from iotbx.xds import xparm, integrate_hkl from dials.util import ioutil from math import ceil import dxtbx from rstbx.cftbx.coordinate_frame_converter import \ coordinate_frame_converter from scitbx import matrix # The XDS files to read from integrate_filename = join(dials_regression, 'data/sim_mx/INTEGRATE.HKL') gxparm_filename = join(dials_regression, 'data/sim_mx/GXPARM.XDS') # Read the XDS files self.integrate_handle = integrate_hkl.reader() self.integrate_handle.read_file(integrate_filename) self.gxparm_handle = xparm.reader() self.gxparm_handle.read_file(gxparm_filename) # Get the parameters we need from the GXPARM file models = dxtbx.load(gxparm_filename) self.beam = models.get_beam() self.gonio = models.get_goniometer() self.detector = models.get_detector() self.scan = models.get_scan() # Get crystal parameters self.space_group_type = ioutil.get_space_group_type_from_xparm( self.gxparm_handle) cfc = coordinate_frame_converter(gxparm_filename) a_vec = cfc.get('real_space_a') b_vec = cfc.get('real_space_b') c_vec = cfc.get('real_space_c') self.unit_cell = cfc.get_unit_cell() self.ub_matrix = matrix.sqr(a_vec + b_vec + c_vec).inverse() # Get the minimum resolution in the integrate file d = [self.unit_cell.d(h) for h in self.integrate_handle.hkl] self.d_min = min(d) # extend the resolution shell by epsilon>0 # to account for rounding artifacts on 32-bit platforms self.d_min = self.d_min - 1e-15 # Get the number of frames from the max z value xcal, ycal, zcal = zip(*self.integrate_handle.xyzcal) self.scan.set_image_range((self.scan.get_image_range()[0], self.scan.get_image_range()[0] + int(ceil(max(zcal))))) # Print stuff # print self.beam # print self.gonio # print self.detector # print self.scan # Create the index generator self.generate_indices = IndexGenerator(self.unit_cell, self.space_group_type, self.d_min) s0 = self.beam.get_s0() m2 = self.gonio.get_rotation_axis() fixed_rotation = self.gonio.get_fixed_rotation() setting_rotation = self.gonio.get_setting_rotation() UB = self.ub_matrix dphi = self.scan.get_oscillation_range(deg=False) # Create the ray predictor self.predict_rays = ScanStaticRayPredictor(s0, m2, fixed_rotation, setting_rotation, dphi) # Predict the spot locations self.reflections = self.predict_rays( self.generate_indices.to_array(), UB)
from __future__ import print_function from iotbx.xds import integrate_hkl import sys reader = integrate_hkl.reader() reader.read_file(sys.argv[1]) hkl = [] iobs = [] sigma = [] xyzcal = [] rlp = [] peak = [] corr = [] maxc = [] xyzobs = [] alfbet0 = [] alfbet1 = [] psi = [] for i in range(len(reader.xyzcal)): x, y, z = reader.xyzcal[i] if z >= 0 and z < 9: hkl.append(reader.hkl[i]) iobs.append(reader.iobs[i]) sigma.append(reader.sigma[i]) xyzcal.append(reader.xyzcal[i]) rlp.append(reader.rlp[i]) peak.append(reader.peak[i]) corr.append(reader.corr[i]) maxc.append(reader.maxc[i])
def __call__(self, params, options): """Import the integrate.hkl file.""" # Get the unit cell to calculate the resolution uc = self._experiment.crystal.get_unit_cell() # Read the INTEGRATE.HKL file Command.start("Reading INTEGRATE.HKL") handle = integrate_hkl.reader() handle.read_file(self._integrate_hkl) hkl = flex.miller_index(handle.hkl) xyzcal = flex.vec3_double(handle.xyzcal) xyzobs = flex.vec3_double(handle.xyzobs) iobs = flex.double(handle.iobs) sigma = flex.double(handle.sigma) rlp = flex.double(handle.rlp) peak = flex.double(handle.peak) * 0.01 if len(handle.iseg): panel = flex.size_t(handle.iseg) - 1 else: panel = flex.size_t(len(hkl), 0) Command.end(f"Read {len(hkl)} reflections from INTEGRATE.HKL file.") if len(self._experiment.detector) > 1: for p_id, p in enumerate(self._experiment.detector): sel = panel == p_id offset = p.get_raw_image_offset() xyzcal.set_selected(sel, xyzcal.select(sel) - (offset[0], offset[1], 0)) xyzobs.set_selected(sel, xyzobs.select(sel) - (offset[0], offset[1], 0)) # Derive the reindex matrix rdx = self.derive_reindex_matrix(handle) print("Reindex matrix:\n%d %d %d\n%d %d %d\n%d %d %d" % (rdx.elems)) # Reindex the reflections Command.start("Reindexing reflections") cb_op = sgtbx.change_of_basis_op(sgtbx.rt_mx(sgtbx.rot_mx(rdx.elems))) hkl = cb_op.apply(hkl) Command.end(f"Reindexed {len(hkl)} reflections") # Create the reflection list Command.start("Creating reflection table") table = flex.reflection_table() table["id"] = flex.int(len(hkl), 0) table["panel"] = panel table["miller_index"] = hkl table["xyzcal.px"] = xyzcal table["xyzobs.px.value"] = xyzobs table["intensity.cor.value"] = iobs table["intensity.cor.variance"] = flex.pow2(sigma) table["intensity.prf.value"] = iobs * peak / rlp table["intensity.prf.variance"] = flex.pow2(sigma * peak / rlp) table["lp"] = 1.0 / rlp table["d"] = flex.double(uc.d(h) for h in hkl) Command.end(f"Created table with {len(table)} reflections") # Output the table to pickle file if params.output.filename is None: params.output.filename = "integrate_hkl.refl" Command.start(f"Saving reflection table to {params.output.filename}") table.as_file(params.output.filename) Command.end(f"Saved reflection table to {params.output.filename}")
def run(): if not have_dials_regression: print "Skipping test: dials_regression not available." return from scitbx import matrix from iotbx.xds import xparm, integrate_hkl from dials.util import ioutil from math import ceil from dials.algorithms.spot_prediction import RotationAngles import dxtbx from rstbx.cftbx.coordinate_frame_converter import \ coordinate_frame_converter # The XDS files to read from integrate_filename = join(dials_regression, 'data/sim_mx/INTEGRATE.HKL') gxparm_filename = join(dials_regression, 'data/sim_mx/GXPARM.XDS') # Read the XDS files integrate_handle = integrate_hkl.reader() integrate_handle.read_file(integrate_filename) gxparm_handle = xparm.reader() gxparm_handle.read_file(gxparm_filename) # Get the parameters we need from the GXPARM file models = dxtbx.load(gxparm_filename) beam = models.get_beam() gonio = models.get_goniometer() detector = models.get_detector() scan = models.get_scan() # Get the crystal parameters space_group_type = ioutil.get_space_group_type_from_xparm(gxparm_handle) cfc = coordinate_frame_converter(gxparm_filename) a_vec = cfc.get('real_space_a') b_vec = cfc.get('real_space_b') c_vec = cfc.get('real_space_c') unit_cell = cfc.get_unit_cell() UB = matrix.sqr(a_vec + b_vec + c_vec).inverse() ub_matrix = UB # Get the minimum resolution in the integrate file d = [unit_cell.d(h) for h in integrate_handle.hkl] d_min = min(d) # Get the number of frames from the max z value xcal, ycal, zcal = zip(*integrate_handle.xyzcal) num_frames = int(ceil(max(zcal))) scan.set_image_range((scan.get_image_range()[0], scan.get_image_range()[0] + num_frames - 1)) # Create the rotation angle object ra = RotationAngles(beam.get_s0(), gonio.get_rotation_axis()) # Setup the matrices ub = matrix.sqr(ub_matrix) s0 = matrix.col(beam.get_s0()) m2 = matrix.col(gonio.get_rotation_axis()) # For all the miller indices for h in integrate_handle.hkl: h = matrix.col(h) # Calculate the angles angles = ra(h, ub) # For all the angles for phi in angles: r = m2.axis_and_angle_as_r3_rotation_matrix(angle=phi) pstar = r * ub * h s1 = s0 + pstar assert(abs(s1.length() - s0.length()) < 1e-7) print "OK" # Create a dict of lists of xy for each hkl gen_phi = {} for h in integrate_handle.hkl: # Calculate the angles angles = ra(h, ub) gen_phi[h] = angles # for phi in angles: # try: # a = gen_phi[h] # a.append(phi) # gen_phi[h] = a # except KeyError: # gen_phi[h] = [phi] # For each hkl in the xds file for hkl, xyz in zip(integrate_handle.hkl, integrate_handle.xyzcal): # Calculate the XDS phi value xds_phi = scan.get_oscillation(deg=False)[0] + \ xyz[2]*scan.get_oscillation(deg=False)[1] # Select the nearest xy to use if there are 2 my_phi = gen_phi[hkl] if len(my_phi) == 2: my_phi0 = my_phi[0] my_phi1 = my_phi[1] diff0 = abs(xds_phi - my_phi0) diff1 = abs(xds_phi - my_phi1) if diff0 < diff1: my_phi = my_phi0 else: my_phi = my_phi1 else: my_phi = my_phi[0] # Check the Phi values are the same assert(abs(xds_phi - my_phi) < 0.1) # Test Passed print "OK"
from iotbx.xds import integrate_hkl import sys reader = integrate_hkl.reader() reader.read_file(sys.argv[1]) hkl = [] iobs = [] sigma = [] xyzcal = [] rlp = [] peak = [] corr = [] maxc = [] xyzobs = [] alfbet0 = [] alfbet1 = [] psi = [] for i in range(len(reader.xyzcal)): x, y, z = reader.xyzcal[i] if z >= 0 and z < 9: hkl.append(reader.hkl[i]) iobs.append(reader.iobs[i]) sigma.append(reader.sigma[i]) xyzcal.append(reader.xyzcal[i]) rlp.append(reader.rlp[i]) peak.append(reader.peak[i]) corr.append(reader.corr[i]) maxc.append(reader.maxc[i])
def __init__(self, dials_regression): import dxtbx from iotbx.xds import integrate_hkl, xparm from rstbx.cftbx.coordinate_frame_converter import coordinate_frame_converter from dials.algorithms.spot_prediction import ( IndexGenerator, ScanStaticRayPredictor, ) from dials.util import ioutil # The XDS files to read from integrate_filename = os.path.join(dials_regression, "data", "sim_mx", "INTEGRATE.HKL") gxparm_filename = os.path.join(dials_regression, "data", "sim_mx", "GXPARM.XDS") # Read the XDS files self.integrate_handle = integrate_hkl.reader() self.integrate_handle.read_file(integrate_filename) self.gxparm_handle = xparm.reader() self.gxparm_handle.read_file(gxparm_filename) # Get the parameters we need from the GXPARM file models = dxtbx.load(gxparm_filename) self.beam = models.get_beam() self.gonio = models.get_goniometer() self.detector = models.get_detector() self.scan = models.get_scan() # Get crystal parameters self.space_group_type = ioutil.get_space_group_type_from_xparm( self.gxparm_handle) cfc = coordinate_frame_converter(gxparm_filename) a_vec = cfc.get("real_space_a") b_vec = cfc.get("real_space_b") c_vec = cfc.get("real_space_c") self.unit_cell = cfc.get_unit_cell() self.ub_matrix = matrix.sqr(a_vec + b_vec + c_vec).inverse() # Get the minimum resolution in the integrate file d = [self.unit_cell.d(h) for h in self.integrate_handle.hkl] self.d_min = min(d) # extend the resolution shell by epsilon>0 # to account for rounding artifacts on 32-bit platforms self.d_min = self.d_min - 1e-15 # Get the number of frames from the max z value xcal, ycal, zcal = zip(*self.integrate_handle.xyzcal) self.scan.set_image_range(( self.scan.get_image_range()[0], self.scan.get_image_range()[0] + int(math.ceil(max(zcal))), )) # Print stuff # print self.beam # print self.gonio # print self.detector # print self.scan # Create the index generator self.generate_indices = IndexGenerator(self.unit_cell, self.space_group_type, self.d_min) s0 = self.beam.get_s0() m2 = self.gonio.get_rotation_axis() fixed_rotation = self.gonio.get_fixed_rotation() setting_rotation = self.gonio.get_setting_rotation() UB = self.ub_matrix dphi = self.scan.get_oscillation_range(deg=False) # Create the ray predictor self.predict_rays = ScanStaticRayPredictor(s0, m2, fixed_rotation, setting_rotation, dphi) # Predict the spot locations self.reflections = self.predict_rays(self.generate_indices.to_array(), UB)
def __init__(self): from dials.algorithms.spot_prediction import IndexGenerator from dials.algorithms.spot_prediction import ScanStaticRayPredictor from dials.algorithms.spot_prediction import ray_intersection from iotbx.xds import xparm, integrate_hkl from dials.util import ioutil from math import ceil import dxtbx from rstbx.cftbx.coordinate_frame_converter import \ coordinate_frame_converter from scitbx import matrix # The XDS files to read from integrate_filename = join(dials_regression, 'data/sim_mx/INTEGRATE.HKL') gxparm_filename = join(dials_regression, 'data/sim_mx/GXPARM.XDS') # Read the XDS files self.integrate_handle = integrate_hkl.reader() self.integrate_handle.read_file(integrate_filename) self.gxparm_handle = xparm.reader() self.gxparm_handle.read_file(gxparm_filename) # Get the parameters we need from the GXPARM file models = dxtbx.load(gxparm_filename) self.beam = models.get_beam() self.gonio = models.get_goniometer() self.detector = models.get_detector() self.scan = models.get_scan() assert (len(self.detector) == 1) #print self.detector # Get crystal parameters self.space_group_type = ioutil.get_space_group_type_from_xparm( self.gxparm_handle) cfc = coordinate_frame_converter(gxparm_filename) a_vec = cfc.get('real_space_a') b_vec = cfc.get('real_space_b') c_vec = cfc.get('real_space_c') self.unit_cell = cfc.get_unit_cell() self.ub_matrix = matrix.sqr(a_vec + b_vec + c_vec).inverse() # Get the minimum resolution in the integrate file self.d_min = self.detector[0].get_max_resolution_at_corners( self.beam.get_s0()) # Get the number of frames from the max z value xcal, ycal, zcal = zip(*self.integrate_handle.xyzcal) self.scan.set_image_range( (self.scan.get_image_range()[0], self.scan.get_image_range()[0] + int(ceil(max(zcal))))) # Create the index generator generate_indices = IndexGenerator(self.unit_cell, self.space_group_type, self.d_min) s0 = self.beam.get_s0() m2 = self.gonio.get_rotation_axis() fixed_rotation = self.gonio.get_fixed_rotation() setting_rotation = self.gonio.get_setting_rotation() UB = self.ub_matrix dphi = self.scan.get_oscillation_range(deg=False) # Create the ray predictor self.predict_rays = ScanStaticRayPredictor(s0, m2, fixed_rotation, setting_rotation, dphi) # Predict the spot locations self.reflections = self.predict_rays(generate_indices.to_array(), UB) # Calculate the intersection of the detector and reflection frames success = ray_intersection(self.detector, self.reflections) self.reflections.select(success)
def run(): from iotbx.xds import xparm, integrate_hkl from dials.util import ioutil from dials.algorithms.spot_prediction import IndexGenerator from os.path import realpath, dirname, join import numpy from rstbx.cftbx.coordinate_frame_converter import \ coordinate_frame_converter from scitbx import matrix # The XDS files to read from test_path = dirname(dirname(dirname(realpath(__file__)))) integrate_filename = join(test_path, 'data/sim_mx/INTEGRATE.HKL') gxparm_filename = join(test_path, 'data/sim_mx/GXPARM.XDS') # Read the XDS files integrate_handle = integrate_hkl.reader() integrate_handle.read_file(integrate_filename) gxparm_handle = xparm.reader() gxparm_handle.read_file(gxparm_filename) # Get the parameters we need from the GXPARM file d_min = 1.6 space_group_type = ioutil.get_space_group_type_from_xparm(gxparm_handle) cfc = coordinate_frame_converter(gxparm_filename) a_vec = cfc.get('real_space_a') b_vec = cfc.get('real_space_b') c_vec = cfc.get('real_space_c') unit_cell = cfc.get_unit_cell() UB = matrix.sqr(a_vec + b_vec + c_vec).inverse() ub_matrix = UB # Generate the indices index_generator = IndexGenerator(unit_cell, space_group_type, d_min) miller_indices = index_generator.to_array() # Get individual generated hkl gen_h = [hkl[0] for hkl in miller_indices] gen_k = [hkl[1] for hkl in miller_indices] gen_l = [hkl[2] for hkl in miller_indices] # Get individual xds generated hkl xds_h = [hkl[0] for hkl in integrate_handle.hkl] xds_k = [hkl[0] for hkl in integrate_handle.hkl] xds_l = [hkl[0] for hkl in integrate_handle.hkl] # Get min/max generated hkl min_gen_h, max_gen_h = numpy.min(gen_h), numpy.max(gen_h) min_gen_k, max_gen_k = numpy.min(gen_k), numpy.max(gen_k) min_gen_l, max_gen_l = numpy.min(gen_l), numpy.max(gen_l) # Get min/max xds generated hkl min_xds_h, max_xds_h = numpy.min(xds_h), numpy.max(xds_h) min_xds_k, max_xds_k = numpy.min(xds_k), numpy.max(xds_k) min_xds_l, max_xds_l = numpy.min(xds_l), numpy.max(xds_l) # Ensure we have the whole xds range in the generated set assert(min_gen_h <= min_xds_h and max_gen_h >= max_xds_h) assert(min_gen_k <= min_xds_k and max_gen_k >= max_xds_k) assert(min_gen_l <= min_xds_l and max_gen_l >= max_xds_l) # Test Passed print "OK"
def __init__(self): from dials.algorithms.spot_prediction import IndexGenerator from dials.algorithms.spot_prediction import ScanStaticRayPredictor from dials.algorithms.spot_prediction import ray_intersection from iotbx.xds import xparm, integrate_hkl from dials.util import ioutil from math import ceil from os.path import realpath, dirname, join import dxtbx from rstbx.cftbx.coordinate_frame_converter import \ coordinate_frame_converter from scitbx import matrix # The XDS files to read from test_path = dirname(dirname(dirname(realpath(__file__)))) integrate_filename = join(test_path, 'data/sim_mx/INTEGRATE.HKL') gxparm_filename = join(test_path, 'data/sim_mx/GXPARM.XDS') # Read the XDS files self.integrate_handle = integrate_hkl.reader() self.integrate_handle.read_file(integrate_filename) self.gxparm_handle = xparm.reader() self.gxparm_handle.read_file(gxparm_filename) # Get the parameters we need from the GXPARM file models = dxtbx.load(gxparm_filename) self.beam = models.get_beam() self.gonio = models.get_goniometer() self.detector = models.get_detector() self.scan = models.get_scan() assert(len(self.detector) == 1) #print self.detector # Get crystal parameters self.space_group_type = ioutil.get_space_group_type_from_xparm( self.gxparm_handle) cfc = coordinate_frame_converter(gxparm_filename) a_vec = cfc.get('real_space_a') b_vec = cfc.get('real_space_b') c_vec = cfc.get('real_space_c') self.unit_cell = cfc.get_unit_cell() self.ub_matrix = matrix.sqr(a_vec + b_vec + c_vec).inverse() # Get the minimum resolution in the integrate file self.d_min = self.detector[0].get_max_resolution_at_corners( self.beam.get_s0()) # Get the number of frames from the max z value xcal, ycal, zcal = zip(*self.integrate_handle.xyzcal) self.scan.set_image_range((self.scan.get_image_range()[0], self.scan.get_image_range()[0] + int(ceil(max(zcal))))) # Create the index generator generate_indices = IndexGenerator(self.unit_cell, self.space_group_type, self.d_min) s0 = self.beam.get_s0() m2 = self.gonio.get_rotation_axis() fixed_rotation = self.gonio.get_fixed_rotation() UB = self.ub_matrix dphi = self.scan.get_oscillation_range(deg=False) # Create the ray predictor self.predict_rays = ScanStaticRayPredictor(s0, m2, fixed_rotation, dphi) # Predict the spot locations self.reflections = self.predict_rays( generate_indices.to_array(), UB) # Calculate the intersection of the detector and reflection frames success = ray_intersection(self.detector, self.reflections) self.reflections.select(success)