def test_ortho_cell(self): cell = UnitCell(25.14, 39.50, 45.07, 90, 90, 90) pos = Position(5, -6, 7) frac = cell.fractionalize(pos) self.assertAlmostEqual(frac.x, 0.198886, delta=1e-6) self.assertAlmostEqual(frac.y, -0.151899, delta=1e-6) self.assertAlmostEqual(frac.z, 0.155314, delta=1e-6) pos2 = cell.orthogonalize(frac) self.assertAlmostEqual(pos.x, pos2.x, delta=1e-12) self.assertAlmostEqual(pos.y, pos2.y, delta=1e-12) self.assertAlmostEqual(pos.z, pos2.z, delta=1e-12) corner = cell.orthogonalize(gemmi.Fractional(1, 1, 1)) self.assertAlmostEqual(corner.x, cell.a, delta=1e-12) self.assertAlmostEqual(corner.y, cell.b, delta=1e-12) self.assertAlmostEqual(corner.z, cell.c, delta=1e-12) rec = cell.reciprocal() self.assertEqual([rec.alpha, rec.beta, rec.gamma], [90, 90, 90]) self.assertAlmostEqual(rec.a, 1 / cell.a, delta=1e-17)
def test_triclinic_cell(self): cell = UnitCell(35.996, 41.601, 45.756, 67.40, 66.90, 74.85) pos = Position(-15, -17, 190) frac = cell.fractionalize(pos) pos2 = cell.orthogonalize(frac) self.assertAlmostEqual(pos.x, pos2.x, delta=1e-12) self.assertAlmostEqual(pos.y, pos2.y, delta=1e-12) self.assertAlmostEqual(pos.z, pos2.z, delta=1e-12) # tested against values from uctbx: # from cctbx import uctbx # uc = uctbx.unit_cell((35.996, 41.601, 45.756, 67.40, 66.90, 74.85)) # uc.d_star_sq((-3, -2, 1)) # uc.d((3, 4, 5)) self.assertAlmostEqual(cell.calculate_1_d2(-3, -2, 1), 0.0128229081865688, delta=1e-17) self.assertAlmostEqual(cell.calculate_d(3, 4, 5), 7.7319559244298, delta=1e-13)
def test_triclinic_cell(self): cell = UnitCell(35.996, 41.601, 45.756, 67.40, 66.90, 74.85) # this would give syntax error with Python < 3.5 #o_f = cell.orthogonalization_matrix @ cell.fractionalization_matrix o_f = cell.orthogonalization_matrix.multiply( cell.fractionalization_matrix) self.assertTrue(o_f.approx(gemmi.Mat33(), 1e-15)) pos = Position(-15, -17, 190) frac = cell.fractionalize(pos) pos2 = cell.orthogonalize(frac) self.assertAlmostEqual(pos.x, pos2.x, delta=1e-12) self.assertAlmostEqual(pos.y, pos2.y, delta=1e-12) self.assertAlmostEqual(pos.z, pos2.z, delta=1e-12) # tested against values from uctbx: # from cctbx import uctbx # uc = uctbx.unit_cell((35.996, 41.601, 45.756, 67.40, 66.90, 74.85)) # uc.d_star_sq((-3, -2, 1)) # uc.d((3, 4, 5)) self.assertAlmostEqual(cell.calculate_1_d2([-3, -2, 1]), 0.0128229081865688, delta=1e-17) self.assertAlmostEqual(cell.calculate_d([3, 4, 5]), 7.7319559244298, delta=1e-13) # uc.metrical_matrix() cctbx_mm = [ 1295.712016, 1730.643201, 2093.611536, 391.3591013825865, 646.1921687548228, 731.5043620154578 ] mt = cell.metric_tensor() assert_almost_equal_seq(self, mt.elements_pdb(), cctbx_mm, delta=1e-12) # uc.reciprocal_metrical_matrix() cctbx_rmm = [ 0.00092792089082916, 0.000689632633981, 0.0006277651322979, -0.000104162588996, -0.000250008091601, -0.000208806754807 ] rmt = cell.reciprocal_metric_tensor() assert_almost_equal_seq(self, rmt.elements_pdb(), cctbx_rmm, delta=1e-15)
M = np.array(missetting_matrix, dtype=float).reshape((3,3)) o1 = np.deg2rad(float(omega_polar_orientation[0])) o2 = np.deg2rad(float(omega_polar_orientation[1])) gonio_phi = np.deg2rad(float(goniometer[2])) cell = UnitCell(*[float(i) for i in unit_cell]) # i is an iterating variable # Get rotation matrix from B to U R = get_rotation_matrix(np.array([0., 0., -1.]), o1) temp = get_rotation_matrix(np.array([0., 1., 0.]), o2) R = temp@R temp = get_rotation_matrix(([email protected]([0., 1., 0.])[:,None])[:,0], gonio_phi) R = temp@R # Create transposed orthogonalization matrix O = np.vstack(( cell.orthogonalize(Fractional(1., 0., 0.)).tolist(), cell.orthogonalize(Fractional(0., 1., 0.)).tolist(), cell.orthogonalize(Fractional(0., 0., 1.)).tolist(), )).T # Compute U, B, A matrices precog2mosflm = np.array([ [ 0, 0, 1], [ 0, -1, 0], [ 1, 0, 0]]) # Change from Precognition to MOSFLM convention (this is a left operator) precog_A = precog2mosflm@(R@[email protected](O)) # precog_A = precog_U@precog_B # This is a lie # U is a properly oriented real-space crystallographic basis for frame in lab coordinate system # So is B