def fixme_test_compile_2nd_matrix_pseudo_ellipse_free_rotor_order(self): """Check if compile_2nd_matrix_pseudo_ellipse_free_rotor() can return the identity matrix for order.""" # The Kronecker product of the eigenframe rotation. Rx2_eigen = self.calc_Rx2_eigen_full(0.0, 0.0, 0.0) # Calculate the frame order matrix. f2 = compile_2nd_matrix_pseudo_ellipse_free_rotor(self.f2_temp, Rx2_eigen, 1e-10, 1e-10) # Print outs. print_frame_order_2nd_degree(self.I_order_free_rotor, "Free rotor identity for order") print_frame_order_2nd_degree(f2, "Compiled frame order") # Check the values. for i in range(9): for j in range(9): print("Element %s, %s." % (i, j)) self.assertAlmostEqual(f2[i, j], self.I_order_free_rotor[i, j])
def test_compile_2nd_matrix_iso_cone_order2(self): """2nd check if compile_2nd_matrix_iso_cone() can return the identity matrix for order.""" # The Kronecker product of the eigenframe rotation. Rx2_eigen = self.calc_Rx2_eigen_axis(0.0, 0.0) # Calculate the frame order matrix. f2 = compile_2nd_matrix_iso_cone(self.f2_temp, Rx2_eigen, 0.0, 0.0) # Print outs. print_frame_order_2nd_degree(self.I_order, "Identity for order") print_frame_order_2nd_degree(f2, "Compiled frame order") # Check the values. for i in range(9): for j in range(9): print("Element %s, %s." % (i, j)) self.assertAlmostEqual(f2[i, j], self.I_order[i, j])
def test_compile_2nd_matrix_iso_cone_free_rotor_half_cone(self): """Check if compile_2nd_matrix_iso_cone_free_rotor() can return the matrix for a half cone.""" # The Kronecker product of the eigenframe rotation. Rx2_eigen = self.calc_Rx2_eigen_axis(0.0, 1.0) # Calculate the frame order matrix. f2 = compile_2nd_matrix_iso_cone_free_rotor(self.f2_temp, Rx2_eigen, pi/2.0) # Print outs. print_frame_order_2nd_degree(self.f2_half_cone, "The half cone frame order matrix") print_frame_order_2nd_degree(f2, "Compiled frame order") # Check the values. for i in range(9): for j in range(9): print("Element %s, %s." % (i, j)) self.assertAlmostEqual(f2[i, j], self.f2_half_cone[i, j])
def test_compile_2nd_matrix_pseudo_ellipse_free_rotor_half_cone_90_y(self): """Check if compile_2nd_matrix_pseudo_ellipse() can return the matrix for a half cone rotated 90 degrees about y.""" # The Kronecker product of the eigenframe rotation. Rx2_eigen = self.calc_Rx2_eigen_full(pi, pi/2.0, pi) # Calculate the frame order matrix (rotated about z by 2pi). f2 = compile_2nd_matrix_pseudo_ellipse_free_rotor(self.f2_temp, Rx2_eigen, pi/2.0, pi/2.0) # Print outs. print_frame_order_2nd_degree(self.f2_half_cone_90_y, "The half cone frame order matrix") print_frame_order_2nd_degree(f2, "Compiled frame order") # Check the values. for i in range(9): for j in range(9): print("Element %s, %s." % (i, j)) self.assertAlmostEqual(f2[i, j], self.f2_half_cone_90_y[i, j])
def test_compile_2nd_matrix_iso_cone_free_rotor_disorder(self): """Check if compile_2nd_matrix_iso_cone_free_rotor() can return the identity matrix for disorder.""" # The Kronecker product of the eigenframe rotation. Rx2_eigen = self.calc_Rx2_eigen_axis(0.0, 1.0) # Calculate the frame order matrix. f2 = compile_2nd_matrix_iso_cone_free_rotor(self.f2_temp, Rx2_eigen, pi) # Cannot differentiate full disorder from the half cone in this model! f2_ref = self.f2_half_cone # Print outs. print_frame_order_2nd_degree(self.I_disorder, "Identity for disorder") print_frame_order_2nd_degree(f2, "Compiled frame order") # Check the values. for i in range(9): for j in range(9): print("Element %s, %s." % (i, j)) self.assertAlmostEqual(f2[i, j], self.I_disorder[i, j])
def test_compile_2nd_matrix_rotor_point1(self): """Check the operation of the compile_2nd_matrix_rotor() function.""" # The simulated in frame rotor 2nd degree frame order matrix (1e7 ensembles). real = array( [[ 7.06775425e-01, 1.36710179e-04, 0.00000000e+00, 1.36710179e-04, 2.93224575e-01, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00], [ -1.36710179e-04, 7.06775425e-01, 0.00000000e+00, -2.93224575e-01, 1.36710179e-04, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00], [ 0.00000000e+00, 0.00000000e+00, 8.27014112e-01, 0.00000000e+00, 0.00000000e+00, 2.19539417e-04, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00], [ -1.36710179e-04, -2.93224575e-01, 0.00000000e+00, 7.06775425e-01, 1.36710179e-04, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00], [ 2.93224575e-01, -1.36710179e-04, 0.00000000e+00, -1.36710179e-04, 7.06775425e-01, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00], [ 0.00000000e+00, 0.00000000e+00, -2.19539417e-04, 0.00000000e+00, 0.00000000e+00, 8.27014112e-01, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00], [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 8.27014112e-01, 2.19539417e-04, 0.00000000e+00], [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, -2.19539417e-04, 8.27014112e-01, 0.00000000e+00], [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.00000000e+00]]) # Init. sigma_max = 60.0 / 180.0 * pi # The Kronecker product of the eigenframe rotation. Rx2_eigen = self.calc_Rx2_eigen_axis(0.0, 0.0) # Calculate the matrix. f2 = compile_2nd_matrix_rotor(self.f2_temp, Rx2_eigen, sigma_max) # Print out. print_frame_order_2nd_degree(real, "real") print_frame_order_2nd_degree(f2, "calculated") print_frame_order_2nd_degree(real-f2, "difference") # Check the values. for i in range(9): for j in range(9): print("Element %s, %s." % (i, j)) self.assert_(abs(f2[i, j] - real[i, j]) < 1e-3)
def test_compile_2nd_matrix_free_rotor_point2(self): """Check the operation of the compile_2nd_matrix_free_rotor() function.""" # The simulated free rotor 2nd degree frame order matrix (1e6 ensembles, axis=[2,1,3]). real = array( [[ 0.3367, -0.0100, -0.0307, -0.0100, 0.3521, -0.0152, -0.0307, -0.0152, 0.3112], [ -0.0104, 0.3520, -0.0152, -0.2908, -0.0559, 0.2602, 0.1989, -0.1685, 0.0664], [ -0.0306, -0.0155, 0.3112, 0.1991, -0.1683, 0.0666, 0.2399, 0.2092, 0.1989], [ -0.0104, -0.2908, 0.1989, 0.3520, -0.0559, -0.1685, -0.0152, 0.2602, 0.0664], [ 0.3520, -0.0563, -0.1684, -0.0563, 0.4362, -0.0841, -0.1684, -0.0841, 0.2118], [ -0.0153, 0.2602, 0.0661, -0.1684, -0.0844, 0.2117, 0.2093, -0.0740, 0.0997], [ -0.0306, 0.1991, 0.2399, -0.0155, -0.1683, 0.2092, 0.3112, 0.0666, 0.1989], [ -0.0153, -0.1684, 0.2093, 0.2602, -0.0844, -0.0740, 0.0661, 0.2117, 0.0997], [ 0.3113, 0.0663, 0.1991, 0.0663, 0.2117, 0.0993, 0.1991, 0.0993, 0.4770]]) # The cone axis. r, theta, phi = cartesian_to_spherical([2, 1, 3]) # The Kronecker product of the eigenframe rotation. Rx2_eigen = self.calc_Rx2_eigen_axis(theta, phi) # Calculate the matrix. f2 = compile_2nd_matrix_free_rotor(self.f2_temp, Rx2_eigen) # Print out. print_frame_order_2nd_degree(real, "real") print_frame_order_2nd_degree(f2, "calculated") print_frame_order_2nd_degree(real-f2, "difference") # Check the values. for i in range(9): for j in range(9): print("Element %s, %s; diff %s." % (i, j, f2[i, j] - real[i, j])) self.assert_(abs(f2[i, j] - real[i, j]) < 1e-3)
def test_compile_2nd_matrix_free_rotor_point1(self): """Check the operation of the compile_2nd_matrix_free_rotor() function.""" # The simulated in frame free rotor 2nd degree frame order matrix (1e6 ensembles). real = array( [[ 0.5001, 0.0001, 0, 0.0001, 0.4999, 0, 0, 0, 0], [ -0.0001, 0.5001, 0, -0.4999, 0.0001, 0, 0, 0, 0], [ 0, 0, 0.0006, 0, 0, -0.0005, 0, 0, 0], [ -0.0001, -0.4999, 0, 0.5001, 0.0001, 0, 0, 0, 0], [ 0.4999, -0.0001, 0, -0.0001, 0.5001, 0, 0, 0, 0], [ 0, 0, 0.0005, 0, 0, 0.0006, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0.0006, -0.0005, 0], [ 0, 0, 0, 0, 0, 0, 0.0005, 0.0006, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 1.0000]]) # The Kronecker product of the eigenframe rotation. Rx2_eigen = self.calc_Rx2_eigen_axis(0.0, 0.0) # Calculate the matrix. f2 = compile_2nd_matrix_free_rotor(self.f2_temp, Rx2_eigen) # Print out. print_frame_order_2nd_degree(real, "real") print_frame_order_2nd_degree(f2, "calculated") print_frame_order_2nd_degree(real-f2, "difference") # Check the values. for i in range(9): for j in range(9): print("Element %s, %s; diff %s." % (i, j, f2[i, j] - real[i, j])) self.assert_(abs(f2[i, j] - real[i, j]) < 1e-3)
def test_compile_2nd_matrix_pseudo_ellipse_free_rotor_point1(self): """Check the operation of the compile_2nd_matrix_pseudo_ellipse_free_rotor() function.""" # The simulated out of frame free rotor pseudo-ellipse 2nd degree frame order matrix (1e6 ensembles). real = array( [[ 0.3428, -0.0193, 0.0389, -0.0193, 0.3137, -0.0194, 0.0389, -0.0194, 0.3435], [ -0.0225, 0.2313, 0.0034, -0.1413, 0.0449, 0.2309, -0.1830, -0.1412, -0.0224], [ 0.0417, 0.0091, 0.2142, -0.1767, -0.0838, 0.0092, 0.1211, -0.1770, 0.0421], [ -0.0225, -0.1413, -0.1830, 0.2313, 0.0449, -0.1412, 0.0034, 0.2309, -0.0224], [ 0.3124, 0.0418, -0.0840, 0.0418, 0.3758, 0.0418, -0.0840, 0.0418, 0.3118], [ -0.0193, 0.2251, 0.0151, -0.1476, 0.0389, 0.2251, -0.1706, -0.1468, -0.0196], [ 0.0417, -0.1767, 0.1211, 0.0091, -0.0838, -0.1770, 0.2142, 0.0092, 0.0421], [ -0.0193, -0.1476, -0.1706, 0.2251, 0.0389, -0.1468, 0.0151, 0.2251, -0.0196], [ 0.3448, -0.0225, 0.0450, -0.0225, 0.3104, -0.0224, 0.0450, -0.0224, 0.3447]], float64) # Init. x = pi/4.0 y = 50.0 / 360.0 * 2.0 * pi # The Kronecker product of the eigenframe rotation. Rx2_eigen = self.calc_Rx2_eigen_full(self.out_of_frame_alpha, self.out_of_frame_beta, self.out_of_frame_gamma) # Calculate the matrix. f2 = compile_2nd_matrix_pseudo_ellipse_free_rotor(self.f2_temp, Rx2_eigen, x, y) # Print out. print_frame_order_2nd_degree(real, "real") print_frame_order_2nd_degree(f2, "calculated") print_frame_order_2nd_degree(real-f2, "difference") # Check the values. for i in range(9): for j in range(9): print("Element %s, %s." % (i, j)) self.assert_(abs(f2[i, j] - real[i, j]) < 1e-3)
def test_compile_2nd_matrix_pseudo_ellipse_free_rotor_point2(self): """Check the operation of the compile_2nd_matrix_pseudo_ellipse_free_rotor() function.""" # The simulated out of frame free rotor pseudo-ellipse 2nd degree frame order matrix (1e6 ensembles). real = array( [[ 0.3251, 0.0163, -0.0324, 0.0163, 0.3493, 0.0164, -0.0324, 0.0164, 0.3256], [ -0.0248, 0.1481, -0.0480, -0.0500, 0.0492, 0.1475, -0.1472, -0.0500, -0.0244], [ 0.0079, 0.0328, 0.0572, -0.0661, -0.0163, 0.0331, 0.0074, -0.0662, 0.0084], [ -0.0248, -0.0500, -0.1472, 0.1481, 0.0492, -0.0500, -0.0480, 0.1475, -0.0244], [ 0.3289, 0.0081, -0.0167, 0.0081, 0.3426, 0.0080, -0.0167, 0.0080, 0.3285], [ 0.0163, 0.0669, 0.1139, -0.1322, -0.0324, 0.0662, 0.0157, -0.1307, 0.0161], [ 0.0079, -0.0661, 0.0074, 0.0328, -0.0163, -0.0662, 0.0572, 0.0331, 0.0084], [ 0.0163, -0.1322, 0.0157, 0.0669, -0.0324, -0.1307, 0.1139, 0.0662, 0.0161], [ 0.3459, -0.0245, 0.0491, -0.0245, 0.3081, -0.0244, 0.0491, -0.0244, 0.3460]], float64) # Init. x = pi / 4.0 y = 150.0 / 360.0 * 2.0 * pi # The Kronecker product of the eigenframe rotation. Rx2_eigen = self.calc_Rx2_eigen_full(self.out_of_frame_alpha, self.out_of_frame_beta, self.out_of_frame_gamma) # Calculate the matrix. f2 = compile_2nd_matrix_pseudo_ellipse_free_rotor(self.f2_temp, Rx2_eigen, x, y) # Print out. print_frame_order_2nd_degree(real, "real") print_frame_order_2nd_degree(f2, "calculated") print_frame_order_2nd_degree(real-f2, "difference") # Check the values. for i in range(9): for j in range(9): print("Element %s, %s." % (i, j)) self.assert_(abs(f2[i, j] - real[i, j]) < 1e-2)
def test_compile_2nd_matrix_pseudo_ellipse_free_rotor_restriction_test(self): """Check if compile_2nd_matrix_pseudo_ellipse_free_rotor() can approximate compile_2nd_matrix_iso_cone_free_rotor().""" # The Kronecker product of the eigenframe rotation. Rx2_eigen_a = self.calc_Rx2_eigen_full(0.0, 0.0, 0.0) Rx2_eigen_b = self.calc_Rx2_eigen_axis(0.0, 1.0) # Calculate the frame order matrix. f2a = compile_2nd_matrix_pseudo_ellipse_free_rotor(self.f2_temp, Rx2_eigen_a, pi/4.6, pi/4.6) f2b = compile_2nd_matrix_iso_cone_free_rotor(self.f2_temp, Rx2_eigen_b, pi/4.6) # Print outs. print_frame_order_2nd_degree(f2a, "Free rotor pseudo-ellipse frame order") print_frame_order_2nd_degree(f2b, "Free rotor isotropic cone frame order") print_frame_order_2nd_degree(f2b-f2a, "difference") # Check the values. for i in range(9): for j in range(9): print("Element %s, %s." % (i, j)) self.assertAlmostEqual(f2a[i, j], f2b[i, j])
def test_compile_2nd_matrix_pseudo_ellipse_restriction_test3(self): """Check if compile_2nd_matrix_pseudo_ellipse() can approximate compile_2nd_matrix_pseudo_ellipse_torsionless().""" # The Kronecker product of the eigenframe rotation. Rx2_eigen_a = self.calc_Rx2_eigen_full(0.0, 0.0, 0.0) Rx2_eigen_b = self.calc_Rx2_eigen_full(0.0, 0.0, 0.0) # Calculate the frame order matrix. f2a = compile_2nd_matrix_pseudo_ellipse(self.f2_temp, Rx2_eigen_a, pi/2.1, pi/4.6, 0) f2b = compile_2nd_matrix_pseudo_ellipse_torsionless(self.f2_temp, Rx2_eigen_b, pi/2.1, pi/4.6) # Print outs. print_frame_order_2nd_degree(f2a, "Pseudo-ellipse frame order") print_frame_order_2nd_degree(f2b, "Torsionless pseudo-ellipse frame order") print_frame_order_2nd_degree(f2b-f2a, "difference") # Check the values. for i in range(9): for j in range(9): print("Element %s, %s; diff %s." % (i, j, f2b[i, j] - f2a[i, j])) self.assertAlmostEqual(f2a[i, j], f2b[i, j])
def test_compile_2nd_matrix_pseudo_ellipse_point1(self): """Check the operation of the compile_2nd_matrix_pseudo_ellipse() function.""" # The simulated in frame pseudo-ellipse 2nd degree frame order matrix. real = array( [[ 0.7901, 0, 0, 0, 0.7118, 0, 0, 0, 0.6851], [ 0, 0.0816, 0, -0.0606, 0, 0, 0, 0, 0], [ 0, 0, 0.1282, 0, 0, 0, -0.1224, 0, 0], [ 0, -0.0606, 0, 0.0708, 0, 0, 0, 0, 0], [ 0.7118, 0, 0, 0, 0.6756, 0, 0, 0, 0.6429], [ 0, 0, 0, 0, 0, 0.2536, 0, -0.2421, 0], [ 0, 0, -0.1224, 0, 0, 0, 0.1391, 0, 0], [ 0, 0, 0, 0, 0, -0.2421, 0, 0.2427, 0], [ 0.6851, 0, 0, 0, 0.6429, 0, 0, 0, 0.6182]], float64) transpose_23(real) # Init. x = pi/4.0 y = 3.0*pi/8.0 z = pi/6.0 # The Kronecker product of the eigenframe rotation. Rx2_eigen = self.calc_Rx2_eigen_full(0.0, 0.0, 0.0) # Calculate the matrix. f2 = compile_2nd_matrix_pseudo_ellipse(self.f2_temp, Rx2_eigen, x, y, z) # Print out. print_frame_order_2nd_degree(real, "real") print_frame_order_2nd_degree(f2, "calculated") print_frame_order_2nd_degree(real-f2, "difference") # Check the values. for i in range(9): for j in range(9): print("Element %s, %s; diff %s." % (i, j, f2[i, j] - real[i, j])) self.assert_(abs(f2[i, j] - real[i, j]) < 1e-4)
def test_compile_2nd_matrix_pseudo_ellipse_point3(self): """Check the operation of the compile_2nd_matrix_pseudo_ellipse() function.""" # The simulated out of frame pseudo-ellipse 2nd degree frame order matrix (1e6 ensembles). real = array( [[ 0.6314, 0.0232, -0.0344, 0.0232, 0.1558, -0.0222, -0.0344, -0.0222, 0.2128], [ 0.0220, 0.6366, 0.0069, -0.1352, 0.0243, -0.0722, 0.0206, -0.0277, -0.0464], [ -0.0332, 0.0097, 0.6137, 0.0222, 0.0668, 0.0173, -0.1967, 0.0489, -0.0336], [ 0.0220, -0.1352, 0.0206, 0.6366, 0.0243, -0.0277, 0.0069, -0.0722, -0.0464], [ 0.1554, 0.0233, 0.0669, 0.0233, 0.6775, 0.0113, 0.0669, 0.0113, 0.1671], [ -0.0222, -0.0738, 0.0188, -0.0286, 0.0113, 0.6310, 0.0507, -0.1502, 0.0109], [ -0.0332, 0.0222, -0.1967, 0.0097, 0.0668, 0.0489, 0.6137, 0.0173, -0.0336], [ -0.0222, -0.0286, 0.0507, -0.0738, 0.0113, -0.1502, 0.0188, 0.6310, 0.0109], [ 0.2132, -0.0465, -0.0324, -0.0465, 0.1667, 0.0110, -0.0324, 0.0110, 0.6201]], float64) # Init. x = 60.0 / 360.0 * 2.0 * pi y = 3.0 * pi / 8.0 z = pi / 6.0 # The Kronecker product of the eigenframe rotation. Rx2_eigen = self.calc_Rx2_eigen_full(self.out_of_frame_alpha, self.out_of_frame_beta, self.out_of_frame_gamma) # Calculate the matrix. f2 = compile_2nd_matrix_pseudo_ellipse(self.f2_temp, Rx2_eigen, x, y, z) # Print out. print_frame_order_2nd_degree(real, "real") print_frame_order_2nd_degree(f2, "calculated") print_frame_order_2nd_degree(real-f2, "difference") # Check the values. for i in range(9): for j in range(9): print("Element %s, %s; diff %s." % (i, j, f2[i, j] - real[i, j])) self.assert_(abs(f2[i, j] - real[i, j]) < 1e-3)
def test_compile_2nd_matrix_pseudo_ellipse_point2(self): """Check the operation of the compile_2nd_matrix_pseudo_ellipse() function.""" # The simulated in frame pseudo-ellipse 2nd degree frame order matrix (1e6 ensembles). real = array( [[ 0.7379, 0, 0, 0, 0.1338, 0, 0, 0, 0.1284], [ 0, 0.6637, 0, -0.1085, 0, 0, 0, 0, 0], [ 0, 0, 0.6603, 0, 0, 0, -0.1181, 0, 0], [ 0, -0.1085, 0, 0.6637, 0, 0, 0, 0, 0], [ 0.1154, 0, 0, 0, 0.6309, 0, 0, 0, 0.2536], [ 0, 0, 0, 0, 0, 0.6196, 0, -0.2336, 0], [ 0, 0, -0.1181, 0, 0, 0, 0.6603, 0, 0], [ 0, 0, 0, 0, 0, -0.2336, 0, 0.6196, 0], [ 0.1467, 0, 0, 0, 0.2353, 0, 0, 0, 0.6180]], float64) # Init. x = pi/4.0 y = 3.0*pi/8.0 z = 40.0 / 360.0 * 2.0 * pi # The Kronecker product of the eigenframe rotation. Rx2_eigen = self.calc_Rx2_eigen_full(0.0, 0.0, 0.0) # Calculate the matrix. f2 = compile_2nd_matrix_pseudo_ellipse(self.f2_temp, Rx2_eigen, x, y, z) # Print out. print_frame_order_2nd_degree(real, "real") print_frame_order_2nd_degree(f2, "calculated") print_frame_order_2nd_degree(real-f2, "difference") # Check the values. for i in range(9): for j in range(9): print("Element %s, %s; diff %s." % (i, j, f2[i, j] - real[i, j])) self.assert_(abs(f2[i, j] - real[i, j]) < 1e-3)
def _calculate_rdc(self): """Calculate the averaged RDC for all states.""" # Open the output files. if self.ROT_FILE: rot_file = open_write_file('rotations', dir=self.save_path, compress_type=1, force=True) # Printout. sys.stdout.write("\n\nRotating %s states for the RDC:\n\n" % locale.format("%d", self.N**self.MODES, grouping=True)) # Turn off the relax interpreter echoing to allow the progress meter to be shown correctly. self.interpreter.off() # Set up some data structures for faster calculations. interatoms = [] vectors = [] d = [] for interatom in interatomic_loop(): # Nothing to do. if not hasattr(interatom, 'vector'): continue # Initialise the RDC structure (as a 1D numpy.float128 array for speed and minimising truncation artifacts). interatom.rdc = {} for tag in self._tensors: interatom.rdc[tag] = zeros(1, float128) # Pack the interatomic containers and vectors. interatoms.append(interatom) vectors.append(interatom.vector) # Get the spins. spin1 = return_spin(interatom.spin_id1) spin2 = return_spin(interatom.spin_id2) # Gyromagnetic ratios. g1 = periodic_table.gyromagnetic_ratio(spin1.isotope) g2 = periodic_table.gyromagnetic_ratio(spin2.isotope) # Calculate the RDC dipolar constant (in Hertz, and the 3 comes from the alignment tensor), and append it to the list. d.append(3.0/(2.0*pi) * dipolar_constant(g1, g2, interatom.r)) # Repackage the data for speed. vectors = transpose(array(vectors, float64)) d = array(d, float64) num_interatoms = len(vectors) # Store the alignment tensors. A = [] for i in range(len(self._tensors)): A.append(cdp.align_tensors[i].A) # Loop over each position. for global_index, mode_indices in self._state_loop(): # The progress meter. self._progress(global_index) # Total rotation matrix (for construction of the frame order matrix). total_R = eye(3) # Data initialisation. new_vect = vectors # Loop over each motional mode. for motion_index in range(self.MODES): # Generate the distribution specific rotation. self.rotation(mode_indices[motion_index], motion_index=motion_index) # Rotate the NH vector. new_vect = dot(self.R, new_vect) # Decompose the rotation into Euler angles and store them. if self.ROT_FILE: a, b, g = R_to_euler_zyz(self.R) rot_file.write('Mode %i: %10.7f %10.7f %10.7f\n' % (motion_index, a, b, g)) # Contribution to the total rotation. total_R = dot(self.R, total_R) # Loop over each alignment. for i in range(len(self._tensors)): # Calculate the RDC as quickly as possible. rdcs = d * tensordot(transpose(new_vect), tensordot(A[i], new_vect, axes=1), axes=1) # Store the values. for j in range(len(interatoms)): interatoms[j].rdc[self._tensors[i]][0] += rdcs[j, j] # The frame order matrix component. self.daeg += kron_prod(total_R, total_R) # Print out. sys.stdout.write('\n\n') # Frame order matrix averaging. self.daeg = self.daeg / self.N**self.MODES # Write out the frame order matrix. file = open(self.save_path+sep+'frame_order_matrix', 'w') print_frame_order_2nd_degree(self.daeg, file=file, places=8) # Reactive the interpreter echoing. self.interpreter.on() # Average the RDC and write the data. for tag in self._tensors: # Average. for interatom in interatomic_loop(): interatom.rdc[tag] = interatom.rdc[tag][0] / self.N**self.MODES # Save. self.interpreter.rdc.write(align_id=tag, file='rdc_%s.txt'%tag, dir=self.save_path, force=True)
# # ############################################################################### # Module docstring. """Script for calculating the frame order matrix from the rotation matrices.""" # Python module imports. from numpy import float64, zeros # relax module imports. from lib.linear_algebra.kronecker_product import kron_prod from lib.frame_order.format import print_frame_order_2nd_degree # Load the matrices. exec( compile( open('rotation_matrices.py').read(), 'rotation_matrices.py', 'exec')) # Init the matrix. matrix = zeros((9, 9), float64) # Loop over the structures. for i in range(len(R)): matrix += kron_prod(R[i], R[i]) # Average. matrix = matrix / len(R) # Print out. print_frame_order_2nd_degree(matrix)
# Init the frame order matrix. daeg = zeros((9, 9), float64) # Loop over the structures, and build the frame order matrix. for i in range(len(R)): # Kronecker product. kron = kron_prod(R[i], R[i]) # Sum daeg += kron # Average. daeg = daeg / len(R) # The relax calculated matrix. fo_calc = array( [[ 0.3410, -0.0370, 0.0333, -0.0370, 0.3252, 0.0411, 0.0333, 0.0411, 0.3338], [ -0.0322, 0.3148, 0.0367, -0.0035, 0.0343, -0.3163, -0.3170, -0.0302, -0.0021], [ 0.0264, 0.0490, 0.3115, -0.3046, -0.0282, -0.0166, -0.0813, 0.3011, 0.0017], [ -0.0322, -0.0035, -0.3170, 0.3148, 0.0343, -0.0302, 0.0367, -0.3163, -0.0021], [ 0.3272, 0.0296, -0.0266, 0.0296, 0.3399, -0.0329, -0.0266, -0.0329, 0.3329], [ 0.0327, -0.3010, -0.0166, -0.0150, -0.0349, 0.3044, 0.3011, 0.0474, 0.0022], [ 0.0264, -0.3046, -0.0813, 0.0490, -0.0282, 0.3011, 0.3115, -0.0166, 0.0017], [ 0.0327, -0.0150, 0.3011, -0.3010, -0.0349, 0.0474, -0.0166, 0.3044, 0.0022], [ 0.3318, 0.0074, -0.0067, 0.0074, 0.3350, -0.0082, -0.0067, -0.0082, 0.3332]], float64) # Print outs. print_frame_order_2nd_degree(daeg) print_frame_order_2nd_degree(fo_calc) print_frame_order_2nd_degree(daeg - fo_calc)
], [ -0.0322, -0.0035, -0.3170, 0.3148, 0.0343, -0.0302, 0.0367, -0.3163, -0.0021 ], [ 0.3272, 0.0296, -0.0266, 0.0296, 0.3399, -0.0329, -0.0266, -0.0329, 0.3329 ], [ 0.0327, -0.3010, -0.0166, -0.0150, -0.0349, 0.3044, 0.3011, 0.0474, 0.0022 ], [ 0.0264, -0.3046, -0.0813, 0.0490, -0.0282, 0.3011, 0.3115, -0.0166, 0.0017 ], [ 0.0327, -0.0150, 0.3011, -0.3010, -0.0349, 0.0474, -0.0166, 0.3044, 0.0022 ], [ 0.3318, 0.0074, -0.0067, 0.0074, 0.3350, -0.0082, -0.0067, -0.0082, 0.3332 ]], float64) # Print outs. print_frame_order_2nd_degree(daeg) print_frame_order_2nd_degree(fo_calc) print_frame_order_2nd_degree(daeg - fo_calc)
def _create_distribution(self): """Generate the distribution of structures.""" # Create a data pipe. self.interpreter.pipe.create('distribution', 'N-state') # Load the original PDB. self.interpreter.structure.read_pdb('1J7P_1st_NH.pdb', dir=self.path, set_mol_name='C-dom') # Set up the 15N and 1H spins. self.interpreter.structure.load_spins(spin_id='@N', ave_pos=False) self.interpreter.structure.load_spins(spin_id='@H', ave_pos=False) self.interpreter.spin.isotope(isotope='15N', spin_id='@N') self.interpreter.spin.isotope(isotope='1H', spin_id='@H') # Define the magnetic dipole-dipole relaxation interaction. self.interpreter.interatom.define(spin_id1='@N', spin_id2='@H', direct_bond=True) self.interpreter.interatom.set_dist(spin_id1='@N', spin_id2='@H', ave_dist=1.041 * 1e-10) self.interpreter.interatom.unit_vectors() # Back up the original positional data. self._backup_pos() # Init a rotation matrix and the frame order matrix. self.R = zeros((3, 3), float16) self.daeg = zeros((9, 9), float64) # Open the output files. rot_file = open_write_file('rotations', dir=self.save_path, compress_type=1, force=True) # Printout. sys.stdout.write("\n\nRotating %s states:\n\n" % self.N) # Load N copies of the original C-domain. for i in range(self.N): # Print out. self._progress(i) # Generate the distribution specific rotation. self.rotation(i) # Rotate the atomic position. for spin in spin_loop(): if hasattr(spin, 'pos'): spin.pos[i] = dot(self.R, (spin.orig_pos[0] - self.pivot)) + self.pivot # Rotate the NH vector. for interatom in interatomic_loop(): if hasattr(interatom, 'vector'): interatom.vector[i] = dot(self.R, interatom.orig_vect) # Decompose the rotation into Euler angles and store them. a, b, g = R_to_euler_zyz(self.R) rot_file.write('%10.7f %10.7f %10.7f\n' % (a, b, g)) # The frame order matrix component. self.daeg += kron_prod(self.R, self.R) # Print out. sys.stdout.write('\n\n') # Frame order matrix averaging. self.daeg = self.daeg / self.N # Write out the frame order matrix. file = open(self.save_path+sep+'frame_order_matrix', 'w') print_frame_order_2nd_degree(self.daeg, file=file)
def _calculate_rdc(self): """Calculate the averaged RDC for all states.""" # Open the output files. if self.ROT_FILE: rot_file = open_write_file('rotations', dir=self.save_path, compress_type=1, force=True) # Printout. sys.stdout.write("\n\nRotating %s states for the RDC:\n\n" % locale.format("%d", self.N**self.MODES, grouping=True)) # Turn off the relax interpreter echoing to allow the progress meter to be shown correctly. self.interpreter.off() # Set up some data structures for faster calculations. interatoms = [] vectors = [] d = [] for interatom in interatomic_loop(): # Nothing to do. if not hasattr(interatom, 'vector'): continue # Initialise the RDC structure (as a 1D numpy.float128 array for speed and minimising truncation artifacts). interatom.rdc = {} for tag in self._tensors: interatom.rdc[tag] = zeros(1, float128) # Pack the interatomic containers and vectors. interatoms.append(interatom) vectors.append(interatom.vector) # Get the spins. spin1 = return_spin(spin_id=interatom.spin_id1) spin2 = return_spin(spin_id=interatom.spin_id2) # Gyromagnetic ratios. g1 = periodic_table.gyromagnetic_ratio(spin1.isotope) g2 = periodic_table.gyromagnetic_ratio(spin2.isotope) # Calculate the RDC dipolar constant (in Hertz, and the 3 comes from the alignment tensor), and append it to the list. d.append(3.0/(2.0*pi) * dipolar_constant(g1, g2, interatom.r)) # Repackage the data for speed. vectors = transpose(array(vectors, float64)) d = array(d, float64) num_interatoms = len(vectors) # Store the alignment tensors. A = [] for i in range(len(self._tensors)): A.append(cdp.align_tensors[i].A) # Loop over each position. for global_index, mode_indices in self._state_loop(): # The progress meter. self._progress(global_index) # Total rotation matrix (for construction of the frame order matrix). total_R = eye(3) # Data initialisation. new_vect = vectors # Loop over each motional mode. for motion_index in range(self.MODES): # Generate the distribution specific rotation. self.rotation(mode_indices[motion_index], motion_index=motion_index) # Rotate the NH vector. new_vect = dot(self.R, new_vect) # Decompose the rotation into Euler angles and store them. if self.ROT_FILE: a, b, g = R_to_euler_zyz(self.R) rot_file.write('Mode %i: %10.7f %10.7f %10.7f\n' % (motion_index, a, b, g)) # Contribution to the total rotation. total_R = dot(self.R, total_R) # Loop over each alignment. for i in range(len(self._tensors)): # Calculate the RDC as quickly as possible. rdcs = d * tensordot(transpose(new_vect), tensordot(A[i], new_vect, axes=1), axes=1) # Store the values. for j in range(len(interatoms)): interatoms[j].rdc[self._tensors[i]][0] += rdcs[j, j] # The frame order matrix component. self.daeg += kron_prod(total_R, total_R) # Print out. sys.stdout.write('\n\n') # Frame order matrix averaging. self.daeg = self.daeg / self.N**self.MODES # Write out the frame order matrix. file = open(self.save_path+sep+'frame_order_matrix', 'w') print_frame_order_2nd_degree(self.daeg, file=file, places=8) # Reactive the interpreter echoing. self.interpreter.on() # Average the RDC and write the data. for tag in self._tensors: # Average. for interatom in interatomic_loop(): interatom.rdc[tag] = interatom.rdc[tag][0] / self.N**self.MODES # Save. self.interpreter.rdc.write(align_id=tag, file='rdc_%s.txt'%tag, dir=self.save_path, force=True)
# Script for calculating the frame order matrix from the rotation matrices. # Python module imports. from numpy import float64, zeros # relax module imports. from lib.linear_algebra.kronecker_product import kron_prod from lib.frame_order.format import print_frame_order_2nd_degree # Load the matrices. exec(compile(open('rotation_matrices.py').read(), 'rotation_matrices.py', 'exec')) # Init the matrix. matrix = zeros((9, 9), float64) # Loop over the structures. for i in range(len(R)): matrix += kron_prod(R[i], R[i]) # Average. matrix = matrix / len(R) # Print out. print_frame_order_2nd_degree(matrix)