Author: bugman Date: Wed Aug 11 23:03:37 2010 New Revision: 11474 URL: http://svn.gna.org/viewcvs/relax?rev=11474&view=rev Log: Implemented the rotor frame order matrix model. This includes the addition of the target function and a unit test. Modified: 1.3/maths_fns/frame_order.py 1.3/maths_fns/frame_order_matrix_ops.py 1.3/test_suite/unit_tests/_maths_fns/test_frame_order_matrix_ops.py Modified: 1.3/maths_fns/frame_order.py URL: http://svn.gna.org/viewcvs/relax/1.3/maths_fns/frame_order.py?rev=11474&r1=11473&r2=11474&view=diff ============================================================================== --- 1.3/maths_fns/frame_order.py (original) +++ 1.3/maths_fns/frame_order.py Wed Aug 11 23:03:37 2010 @@ -367,6 +367,30 @@ return chi2(self.red_tensors, self.red_tensors_bc, self.red_errors) + def func_rotor(self, params): + """Target function for rotor model optimisation. + + This function optimises against alignment tensors. The Euler angles for the tensor rotation are the first 3 parameters optimised in this model, followed by the polar and azimuthal angles of the cone axis and the torsion angle restriction. + + @param params: The vector of parameter values. These are the tensor rotation angles {alpha, beta, gamma, theta, phi, sigma_max}. + @type params: list of float + @return: The chi-squared or SSE value. + @rtype: float + """ + + # Unpack the parameters. + ave_pos_alpha, ave_pos_beta, ave_pos_gamma, axis_theta, axis_phi, sigma_max = params + + # Generate the 2nd degree Frame Order super matrix. + frame_order_2nd = compile_2nd_matrix_rotor(self.frame_order_2nd, self.rot, self.z_axis, self.cone_axis, axis_theta, axis_phi, sigma_max) + + # Reduce and rotate the tensors. + self.reduce_and_rot(ave_pos_alpha, ave_pos_beta, ave_pos_gamma, frame_order_2nd) + + # Return the chi-squared value. + return chi2(self.red_tensors, self.red_tensors_bc, self.red_errors) + + def reduce_and_rot(self, ave_pos_alpha=None, ave_pos_beta=None, ave_pos_gamma=None, daeg=None): """Reduce and rotate the alignments tensors using the frame order matrix and Euler angles. Modified: 1.3/maths_fns/frame_order_matrix_ops.py URL: http://svn.gna.org/viewcvs/relax/1.3/maths_fns/frame_order_matrix_ops.py?rev=11474&r1=11473&r2=11474&view=diff ============================================================================== --- 1.3/maths_fns/frame_order_matrix_ops.py (original) +++ 1.3/maths_fns/frame_order_matrix_ops.py Wed Aug 11 23:03:37 2010 @@ -349,6 +349,64 @@ # Average position rotation. euler_to_R_zyz(eigen_alpha, eigen_beta, eigen_gamma, R) + + # Rotate and return the frame order matrix. + return rotate_daeg(matrix, R) + + +def compile_2nd_matrix_rotor(matrix, R, z_axis, cone_axis, theta_axis, phi_axis, smax): + """Generate the rotated 2nd degree Frame Order matrix for the rotor model. + + The cone axis is assumed to be parallel to the z-axis in the eigenframe. + + + @param matrix: The Frame Order matrix, 2nd degree to be populated. + @type matrix: numpy 9D, rank-2 array + @param R: The rotation matrix to be populated. + @type R: numpy 3D, rank-2 array + @param z_axis: The molecular frame z-axis from which the cone axis is rotated from. + @type z_axis: numpy 3D, rank-1 array + @param cone_axis: The storage structure for the cone axis. + @type cone_axis: numpy 3D, rank-1 array + @param theta_axis: The cone axis polar angle. + @type theta_axis: float + @param phi_axis: The cone axis azimuthal angle. + @type phi_axis: float + @param smax: The maximum torsion angle. + @type smax: float + """ + + # Zeros. + for i in range(9): + for j in range(9): + matrix[i, j] = 0.0 + + # Repetitive trig calculations. + sinc_smax = sinc(smax/pi) + sinc_2smax = sinc(2.0*smax/pi) + + # Diagonal. + matrix[0, 0] = (sinc_2smax + 1.0) / 2.0 + matrix[1, 1] = matrix[0, 0] + matrix[2, 2] = sinc_smax + matrix[3, 3] = matrix[0, 0] + matrix[4, 4] = matrix[0, 0] + matrix[5, 5] = matrix[2, 2] + matrix[6, 6] = matrix[2, 2] + matrix[7, 7] = matrix[2, 2] + matrix[8, 8] = 1.0 + + # Off diagonal set 1. + matrix[0, 4] = matrix[4, 0] = -(sinc_2smax - 1.0) / 2.0 + + # Off diagonal set 2. + matrix[1, 3] = matrix[3, 1] = -matrix[0, 4] + + # Generate the cone axis from the spherical angles. + spherical_to_cartesian([1.0, theta_axis, phi_axis], cone_axis) + + # Average position rotation. + two_vect_to_R(z_axis, cone_axis, R) # Rotate and return the frame order matrix. return rotate_daeg(matrix, R) Modified: 1.3/test_suite/unit_tests/_maths_fns/test_frame_order_matrix_ops.py URL: http://svn.gna.org/viewcvs/relax/1.3/test_suite/unit_tests/_maths_fns/test_frame_order_matrix_ops.py?rev=11474&r1=11473&r2=11474&view=diff ============================================================================== --- 1.3/test_suite/unit_tests/_maths_fns/test_frame_order_matrix_ops.py (original) +++ 1.3/test_suite/unit_tests/_maths_fns/test_frame_order_matrix_ops.py Wed Aug 11 23:03:37 2010 @@ -811,6 +811,39 @@ self.assertAlmostEqual(f2a[i, j], f2b[i, j]) + def test_compile_2nd_matrix_rotor(self): + """Check the operation of the compile_2nd_matrix_rotor() function.""" + + # The real 2nd degree frame order matrix. + real = array( + [[ 0.7069, -0.0002, 0, -0.0002, 0.2931, 0, 0, 0, 0], + [ 0.0002, 0.7069, 0, -0.2931, -0.0002, 0, 0, 0, 0], + [ 0, 0, 0.8271, 0, 0, -0.0003, 0, 0, 0], + [ 0.0002, -0.2931, 0, 0.7069, -0.0002, 0, 0, 0, 0], + [ 0.2931, 0.0002, 0, 0.0002, 0.7069, 0, 0, 0, 0], + [ 0, 0, 0.0003, 0, 0, 0.8271, 0, 0, 0], + [ 0, 0, 0, 0, 0, 0, 0.8271, -0.0003, 0], + [ 0, 0, 0, 0, 0, 0, 0.0003, 0.8271, 0], + [ 0, 0, 0, 0, 0, 0, 0, 0, 1.0000]]) + + # Init. + sigma_max = 60.0 / 180.0 * pi + + # Calculate the matrix. + f2 = compile_2nd_matrix_rotor(self.f2_temp, self.R_temp, self.z_axis, self.cone_axis, 0.0, 0.0, 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_reduce_alignment_tensor_order(self): """Test the alignment tensor reduction for the order identity matrix."""