def test_crystal_with_scan_points(example_crystal): c1 = Crystal(**example_crystal) A = c1.get_A() c1.set_A_at_scan_points([A for i in range(5)]) # Set the B covariance. The values are nonsense, just ensure they are # all different cov_B = flex.double(range(9 * 9)) * 1e-5 c1.set_B_covariance(cov_B) cov_B.reshape(flex.grid(1, 9, 9)) cov_B_array = flex.double(flex.grid(5, 9, 9)) for i in range(5): cov_B_array[i:(i + 1), :, :] = cov_B c1.set_B_covariance_at_scan_points(cov_B_array) cov_B = c1.get_B_covariance() d = c1.to_dict() c2 = CrystalFactory.from_dict(d) eps = 1e-9 for Acomp in d["A_at_scan_points"]: for e1, e2 in zip(A, Acomp): assert abs(e1 - e2) <= eps for covBcomp in d["B_covariance_at_scan_points"]: for e1, e2 in zip(cov_B, covBcomp): assert abs(e1 - e2) <= eps assert c1 == c2
def tst_crystal_with_scan_points(self): from dxtbx.model import Crystal, CrystalFactory from scitbx import matrix real_space_a = matrix.col( (35.2402102454, -7.60002142787, 22.080026774)) real_space_b = matrix.col( (22.659572494, 1.47163505925, -35.6586361881)) real_space_c = matrix.col( (5.29417246554, 38.9981792999, 4.97368666613)) c1 = Crystal(real_space_a=real_space_a, real_space_b=real_space_b, real_space_c=real_space_c, space_group_symbol="P 1 2/m 1") A = c1.get_A() c1.set_A_at_scan_points([A for i in range(5)]) d = c1.to_dict() c2 = CrystalFactory.from_dict(d) eps = 1e-9 for Acomp in (d['A_at_scan_points']): for e1, e2 in zip(A, Acomp): assert (abs(e1 - e2) <= eps) assert (c1 == c2) print 'OK'
def tst_crystal(self): from dxtbx.model import Crystal, CrystalFactory from scitbx import matrix real_space_a = matrix.col( (35.2402102454, -7.60002142787, 22.080026774)) real_space_b = matrix.col( (22.659572494, 1.47163505925, -35.6586361881)) real_space_c = matrix.col( (5.29417246554, 38.9981792999, 4.97368666613)) c1 = Crystal(real_space_a=real_space_a, real_space_b=real_space_b, real_space_c=real_space_c, space_group_symbol="P 1 2/m 1") c1.set_mosaicity(0.1) d = c1.to_dict() c2 = CrystalFactory.from_dict(d) eps = 1e-7 assert (abs(matrix.col(d['real_space_a']) - real_space_a) <= eps) assert (abs(matrix.col(d['real_space_b']) - real_space_b) <= eps) assert (abs(matrix.col(d['real_space_c']) - real_space_c) <= eps) assert (d['space_group_hall_symbol'] == "-P 2y") assert (d['mosaicity'] == 0.1) assert (c1 == c2) print 'OK'
def test_crystal(mosaic): from dxtbx.model import CrystalFactory from scitbx import matrix real_space_a = matrix.col((35.2402102454, -7.60002142787, 22.080026774)) real_space_b = matrix.col((22.659572494, 1.47163505925, -35.6586361881)) real_space_c = matrix.col((5.29417246554, 38.9981792999, 4.97368666613)) if mosaic: from dxtbx.model import MosaicCrystalKabsch2010 c1 = MosaicCrystalKabsch2010( real_space_a=real_space_a, real_space_b=real_space_b, real_space_c=real_space_c, space_group_symbol="P 1 2/m 1") c1.set_mosaicity(0.1) else: from dxtbx.model import Crystal c1 = Crystal( real_space_a=real_space_a, real_space_b=real_space_b, real_space_c=real_space_c, space_group_symbol="P 1 2/m 1") d = c1.to_dict() c2 = CrystalFactory.from_dict(d) eps = 1e-7 assert abs(matrix.col(d['real_space_a']) - real_space_a) <= eps assert abs(matrix.col(d['real_space_b']) - real_space_b) <= eps assert abs(matrix.col(d['real_space_c']) - real_space_c) <= eps assert d['space_group_hall_symbol'] == "-P 2y" if mosaic: assert d['mosaicity'] == 0.1 assert c1 == c2
def test_crystal(example_crystal): c1 = Crystal(**example_crystal) d = c1.to_dict() c2 = CrystalFactory.from_dict(d) for direction in ("real_space_a", "real_space_b", "real_space_c"): assert abs(matrix.col(d[direction]) - example_crystal[direction]) <= 1e-7 assert d["space_group_hall_symbol"] == "-P 2y" assert c1 == c2
def test_mosaic_crystal(example_crystal): c1 = MosaicCrystalKabsch2010(**example_crystal) c1.set_mosaicity(0.1) d = c1.to_dict() c2 = CrystalFactory.from_dict(d) for direction in ("real_space_a", "real_space_b", "real_space_c"): assert abs(matrix.col(d[direction]) - example_crystal[direction]) <= 1e-7 assert d["space_group_hall_symbol"] == "-P 2y" assert d["mosaicity"] == 0.1 assert c1 == c2
def crystal(self): crystal = None # dxtbx crystal description if self.Amatrix is not None: A = sqr(self.Amatrix).inverse().elems # is this always P-1 ? real_a = A[0], A[3], A[6] real_b = A[1], A[4], A[7] real_c = A[2], A[5], A[8] cryst_dict = {'__id__': 'crystal', 'real_space_a': real_a, 'real_space_b': real_b, 'real_space_c': real_c, 'space_group_hall_symbol': ' P 1'} crystal = CrystalFactory.from_dict(cryst_dict) return crystal
def test_crystal_with_recalculated_cell(crystal_class, example_crystal): c1 = crystal_class(**example_crystal) uc = c1.get_unit_cell() c1.set_recalculated_unit_cell(uc) c1.set_recalculated_cell_parameter_sd((0.1, ) * 6) c1.set_recalculated_cell_volume_sd(0.001) d = c1.to_dict() c2 = CrystalFactory.from_dict(d) c3 = pickle.loads(pickle.dumps(c1)) for c in (c2, c3): assert c.get_recalculated_unit_cell() is not None assert c1.get_recalculated_unit_cell().is_similar_to( c.get_recalculated_unit_cell()) assert c1 == c assert c.get_recalculated_cell_parameter_sd() == (0.1, 0.1, 0.1, 0.1, 0.1, 0.1) assert c.get_recalculated_cell_volume_sd() == 0.001
def test_crystal_with_scan_points(): from dxtbx.model import Crystal, CrystalFactory from scitbx import matrix real_space_a = matrix.col((35.2402102454, -7.60002142787, 22.080026774)) real_space_b = matrix.col((22.659572494, 1.47163505925, -35.6586361881)) real_space_c = matrix.col((5.29417246554, 38.9981792999, 4.97368666613)) c1 = Crystal( real_space_a=real_space_a, real_space_b=real_space_b, real_space_c=real_space_c, space_group_symbol="P 1 2/m 1", ) A = c1.get_A() c1.set_A_at_scan_points([A for i in range(5)]) # Set the B covariance. The values are nonsense, just ensure they are # all different from scitbx.array_family import flex cov_B = flex.double(range((9 * 9))) * 1e-5 c1.set_B_covariance(cov_B) cov_B.reshape(flex.grid(1, 9, 9)) cov_B_array = flex.double(flex.grid(5, 9, 9)) for i in range(5): cov_B_array[i : (i + 1), :, :] = cov_B c1.set_B_covariance_at_scan_points(cov_B_array) cov_B = c1.get_B_covariance() d = c1.to_dict() c2 = CrystalFactory.from_dict(d) eps = 1e-9 for Acomp in d["A_at_scan_points"]: for e1, e2 in zip(A, Acomp): assert abs(e1 - e2) <= eps for covBcomp in d["B_covariance_at_scan_points"]: for e1, e2 in zip(cov_B, covBcomp): assert abs(e1 - e2) <= eps assert c1 == c2
def as_explist(self, fname=None, toggle_conventions=False): """ return experiment list for simulated image """ C = self.crystal if toggle_conventions: # switch to DIALS convention before writing CBF # also change basis of crystal CURRENT_CONV = self.beamcenter_convention FSO = sqr(self.fdet_vector + self.sdet_vector + self.pix0_vector_mm) self.beamcenter_convention = DIALS FSO2 = sqr(self.fdet_vector + self.sdet_vector + self.dials_origin_mm) xtal_transform = FSO.inverse() * FSO2 # transform the crystal vectors a, b, c = map(lambda x: xtal_transform * col(x), C.get_real_space_vectors()) Cdict = C.to_dict() Cdict['real_space_a'] = a Cdict['real_space_b'] = b Cdict['real_space_b'] = c C = CrystalFactory.from_dict(Cdict) exp = Experiment() exp.crystal = C exp.beam = self.beam exp.detector = self.detector exp.imageset = self.imageset explist = ExperimentList() explist.append(exp) if fname is not None: explist.as_file(fname) if toggle_conventions: self.beamcenter_convention = CURRENT_CONV return explist
def _crystal_from_dict(obj): ''' Get the crystal from a dictionary. ''' from dxtbx.model import CrystalFactory return CrystalFactory.from_dict(obj)
def test_experiment(): d = { "__id__": "crystal", "real_space_a": [14.963210089244596, -22.599814679318, 51.02946725220764], "real_space_b": [-19.963976860932235, -51.503385430151205, -16.955728379753463], "real_space_c": [135.29560393219694, -34.371677531924206, -54.89475471853507], "space_group_hall_symbol": " P 4", "A_at_scan_points": [[ 0.004481726844090139, -0.005980612987053365, 0.006013325470974739, -0.006768741824936281, -0.015428970379357122, -0.0015280122438480544, 0.01528745348419002, -0.005078101688718203, -0.0024394384982453095, ]], } crystal = CrystalFactory.from_dict(d) beam_d = { "direction": [-2.4882593300783137e-06, -0.0, 0.9999999999969044], "transmission": 1.0, "polarization_normal": [0.0, 1.0, 0.0], "divergence": 0.0, "polarization_fraction": 0.999, "flux": 0.0, "sigma_divergence": 0.0, "wavelength": 0.9762499999999994, } beam = BeamFactory.from_dict(beam_d) scan = Scan(image_range=[0, 1], oscillation=[0.0, 0.01]) detector_dict = { "hierarchy": { "origin": [0.0, 0.0, 0.0], "fast_axis": [1.0, 0.0, 0.0], "name": "", "raw_image_offset": [0, 0], "slow_axis": [0.0, 1.0, 0.0], "material": "", "mask": [], "thickness": 0.0, "mu": 0.0, "gain": 1.0, "trusted_range": [0.0, 0.0], "image_size": [0, 0], "px_mm_strategy": { "type": "SimplePxMmStrategy" }, "identifier": "", "type": "", "children": [{ "panel": 0 }], "pixel_size": [0.0, 0.0], }, "panels": [{ "origin": [-210.66631009735772, 205.7063614421482, -263.8386975038205], "fast_axis": [ 0.9999973940105483, -0.0016357501034268717, -0.0015925745544149894, ], "name": "Panel", "raw_image_offset": [0, 0], "slow_axis": [ -0.0016426481736367285, -0.999989234013669, -0.004339765400707805, ], "material": "Si", "mask": [ [488, 1, 494, 2527], [982, 1, 988, 2527], [1476, 1, 1482, 2527], [1970, 1, 1976, 2527], [1, 196, 2463, 212], [1, 408, 2463, 424], [1, 620, 2463, 636], [1, 832, 2463, 848], [1, 1044, 2463, 1060], [1, 1256, 2463, 1272], [1, 1468, 2463, 1484], [1, 1680, 2463, 1696], [1, 1892, 2463, 1908], [1, 2104, 2463, 2120], [1, 2316, 2463, 2332], ], "thickness": 0.32, "mu": 3.9220322752480934, "gain": 1.0, "trusted_range": [-1.0, 161977.0], "image_size": [2463, 2527], "px_mm_strategy": { "type": "ParallaxCorrectedPxMmStrategy" }, "identifier": "", "type": "SENSOR_PAD", "pixel_size": [0.17200000000000001, 0.17200000000000001], }], } detector = DetectorFactory.from_dict(detector_dict) expt = Experiment(beam=beam, crystal=crystal, scan=scan, detector=detector) return expt
def _crystal_from_dict(obj): """ Get the crystal from a dictionary. """ return CrystalFactory.from_dict(obj)