Author: bugman Date: Mon Sep 14 13:59:44 2009 New Revision: 9524 URL: http://svn.gna.org/viewcvs/relax?rev=9524&view=rev Log: Renamed the frame order target function module. Added: 1.3/maths_fns/frame_order.py - copied unchanged from r9489, 1.3/maths_fns/frame_order_models.py Removed: 1.3/maths_fns/frame_order_models.py Modified: 1.3/maths_fns/__init__.py 1.3/specific_fns/frame_order.py Modified: 1.3/maths_fns/__init__.py URL: http://svn.gna.org/viewcvs/relax/1.3/maths_fns/__init__.py?rev=9524&r1=9523&r2=9524&view=diff ============================================================================== --- 1.3/maths_fns/__init__.py (original) +++ 1.3/maths_fns/__init__.py Mon Sep 14 13:59:44 2009 @@ -29,8 +29,8 @@ 'consistency_tests', 'correlation_time', 'direction_cosine', + 'frame_order', 'frame_order_matrix_ops', - 'frame_order_models', 'jw_mapping', 'jw_mf_comps', 'jw_mf', Removed: 1.3/maths_fns/frame_order_models.py URL: http://svn.gna.org/viewcvs/relax/1.3/maths_fns/frame_order_models.py?rev=9523&view=auto ============================================================================== --- 1.3/maths_fns/frame_order_models.py (original) +++ 1.3/maths_fns/frame_order_models.py (removed) @@ -1,314 +1,0 @@ -############################################################################### -# # -# Copyright (C) 2009 Edward d'Auvergne # -# # -# This file is part of the program relax. # -# # -# relax is free software; you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation; either version 2 of the License, or # -# (at your option) any later version. # -# # -# relax is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with relax; if not, write to the Free Software # -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# # -############################################################################### - -# Module docstring. -"""Module containing the target functions of the Frame Order theories.""" - -# Python module imports. -from copy import deepcopy -from numpy import array, dot, float64, ones, transpose, zeros - -# relax module imports. -from generic_fns.frame_order import print_frame_order_2nd_degree -from maths_fns.alignment_tensor import to_5D, to_tensor -from maths_fns.chi2 import chi2 -from maths_fns.frame_order_matrix_ops import compile_2nd_matrix_iso_cone, reduce_alignment_tensor -from maths_fns.rotation_matrix import euler_zyz_to_R -from relax_errors import RelaxError - - -class Frame_order: - """Class containing the target function of the optimisation of Frame Order matrix components.""" - - def __init__(self, model=None, init_params=None, full_tensors=None, red_tensors=None, red_errors=None, full_in_ref_frame=None, frame_order_2nd=None): - """Set up the target functions for the Frame Order theories. - - @keyword model: The name of the Frame Order model. - @type model: str - @keyword init_params: The initial parameter values. - @type init_params: numpy float64 array - @keyword full_tensors: An array of the {Sxx, Syy, Sxy, Sxz, Syz} values for all full - alignment tensors. The format is [Sxx1, Syy1, Sxy1, Sxz1, Syz1, - Sxx2, Syy2, Sxy2, Sxz2, Syz2, ..., Sxxn, Syyn, Sxyn, Sxzn, - Syzn]. - @type full_tensors: numpy nx5D, rank-1 float64 array - @keyword red_tensors: An array of the {Sxx, Syy, Sxy, Sxz, Syz} values for all reduced - tensors. The array format is the same as for full_tensors. - @type red_tensors: numpy nx5D, rank-1 float64 array - @keyword red_errors: An array of the {Sxx, Syy, Sxy, Sxz, Syz} errors for all reduced - tensors. The array format is the same as for full_tensors. - @type red_errors: numpy nx5D, rank-1 float64 array - @keyword full_in_ref_frame: An array of flags specifying if the tensor in the reference - frame is the full or reduced tensor. - @type full_in_ref_frame: numpy rank-1 array - @keyword frame_order_2nd: The numerical values of the 2nd degree Frame Order matrix. If - supplied, the target functions will optimise directly to these - values. - @type frame_order_2nd: None or numpy 9D, rank-2 array - """ - - # Model test. - if not model: - raise RelaxError("The type of Frame Order model must be specified.") - - # Store the initial parameter (as a copy). - self.params = deepcopy(init_params) - - # The rigid model. - if model == 'rigid': - # Tensor optimisation. - self.__init_tensors(full_tensors, red_tensors, red_errors, full_in_ref_frame) - - # Alias the target function. - self.func = self.func_rigid - - - # Isotropic cone model. - if model == 'iso cone': - # Mix up. - if full_tensors != None and frame_order_2nd != None: - raise RelaxError("Tensors and Frame Order matrices cannot be supplied together.") - - # Tensor setup. - if full_tensors != None: - self.__init_tensors(full_tensors, red_tensors, red_errors, full_in_ref_frame) - - # Optimisation to the 2nd degree Frame Order matrix components directly. - elif frame_order_2nd != None: - self.__init_iso_cone_elements(frame_order_2nd) - - # Badly supplied arguments. - else: - raise RelaxError("The arguments have been incorrectly supplied, cannot determine the optimisation mode.") - - # The cone axis storage and molecular frame z-axis. - self.cone_axis = zeros(3, float64) - self.z_axis = array([0, 0, 1], float64) - - # Alias the target function. - self.func = self.func_iso_cone - - - def __init_tensors(self, full_tensors, red_tensors, red_errors, full_in_ref_frame): - """Set up isotropic cone optimisation against the alignment tensor data. - - @keyword full_tensors: An array of the {Sxx, Syy, Sxy, Sxz, Syz} values for all full - alignment tensors. The format is [Sxx1, Syy1, Sxy1, Sxz1, Syz1, - Sxx2, Syy2, Sxy2, Sxz2, Syz2, ..., Sxxn, Syyn, Sxyn, Sxzn, - Syzn]. - @type full_tensors: numpy nx5D, rank-1 float64 array - @keyword red_tensors: An array of the {Sxx, Syy, Sxy, Sxz, Syz} values for all reduced - tensors. The array format is the same as for full_tensors. - @type red_tensors: numpy nx5D, rank-1 float64 array - @keyword red_errors: An array of the {Sxx, Syy, Sxy, Sxz, Syz} errors for all reduced - tensors. The array format is the same as for full_tensors. - @type red_errors: numpy nx5D, rank-1 float64 array - """ - - # Some checks. - if full_tensors == None or not len(full_tensors): - raise RelaxError("The full_tensors argument " + repr(full_tensors) + " must be supplied.") - if red_tensors == None or not len(red_tensors): - raise RelaxError("The red_tensors argument " + repr(red_tensors) + " must be supplied.") - if red_errors == None or not len(red_errors): - raise RelaxError("The red_errors argument " + repr(red_errors) + " must be supplied.") - if full_in_ref_frame == None or not len(full_in_ref_frame): - raise RelaxError("The full_in_ref_frame argument " + repr(full_in_ref_frame) + " must be supplied.") - - # Tensor set up. - self.num_tensors = len(full_tensors) / 5 - self.full_tensors = full_tensors - self.red_tensors = red_tensors - self.red_errors = red_errors - self.red_tensors_bc = zeros(self.num_tensors*5, float64) - self.full_in_ref_frame = full_in_ref_frame - - # The rotation to the Frame Order eigenframe. - self.rot = zeros((3, 3), float64) - self.tensor_3D = zeros((3, 3), float64) - - # Initialise the Frame Order matrices. - self.frame_order_2nd = zeros((9, 9), float64) - - - def __init_iso_cone_elements(self, frame_order_2nd): - """Set up isotropic cone optimisation against the 2nd degree Frame Order matrix elements. - - @keyword frame_order_2nd: The numerical values of the 2nd degree Frame Order matrix. If - supplied, the target functions will optimise directly to these - values. - @type frame_order_2nd: numpy 9D, rank-2 array - """ - - # Store the real matrix components. - self.data = frame_order_2nd - - # The errors. - self.errors = ones((9, 9), float64) - - # The cone axis storage and molecular frame z-axis. - self.cone_axis = zeros(3, float64) - self.z_axis = array([0, 0, 1], float64) - - # The rotation. - self.rot = zeros((3, 3), float64) - - # Initialise the Frame Order matrices. - self.frame_order_2nd = zeros((9, 9), float64) - - # Alias the target function. - self.func = self.func_iso_cone_elements - - - def func_rigid(self, params): - """Target function for rigid model optimisation using the alignment tensors. - - This function optimises against alignment tensors. The Euler angles for the tensor rotation - are the 3 parameters optimised in this model. - - @param params: The vector of parameter values. These are the tensor rotation angles - {alpha, beta, gamma}. - @type params: list of float - @return: The chi-squared or SSE value. - @rtype: float - """ - - # Unpack the parameters. - alpha, beta, gamma = params - - # Alignment tensor rotation. - euler_zyz_to_R(alpha, beta, gamma, self.rot) - - # Back calculate the rotated tensors. - for i in range(self.num_tensors): - # Tensor indices. - index1 = i*5 - index2 = i*5+5 - - # Convert the original tensor to 3D, rank-2 form. - to_tensor(self.tensor_3D, self.full_tensors[index1:index2]) - - # Rotate the tensor (normal R.X.RT rotation). - if self.full_in_ref_frame[i]: - self.tensor_3D = dot(self.rot, dot(self.tensor_3D, transpose(self.rot))) - - # Rotate the tensor (inverse RT.X.R rotation). - else: - self.tensor_3D = dot(transpose(self.rot), dot(self.tensor_3D, self.rot)) - - # Convert the tensor back to 5D, rank-1 form, as the back-calculated reduced tensor. - to_5D(self.red_tensors_bc[index1:index2], self.tensor_3D) - - # Return the chi-squared value. - return chi2(self.red_tensors, self.red_tensors_bc, self.red_errors) - - - def func_iso_cone(self, params): - """Target function for isotropic cone model optimisation using the alignment tensors. - - This function optimises against alignment tensors. The cone axis spherical angles theta and - phi and the cone angle theta are the 3 parameters optimised in this model. - - @param params: The vector of parameter values {alpha, beta, gamma, theta, phi, theta_cone} - where the first 3 are the tensor rotation Euler angles, the next two are the - polar and azimuthal angles of the cone axis theta_cone is the isotropic cone - angle. - @type params: list of float - @return: The chi-squared or SSE value. - @rtype: float - """ - - # Unpack the parameters. - alpha, beta, gamma, theta, phi, theta_cone = params - - # Generate the 2nd degree Frame Order super matrix. - self.frame_order_2nd = compile_2nd_matrix_iso_cone(self.frame_order_2nd, self.rot, self.z_axis, self.cone_axis, theta, phi, theta_cone) - - # Reduced alignment tensor rotation. - euler_zyz_to_R(alpha, beta, gamma, self.rot) - - # Back calculate the reduced tensors. - for i in range(self.num_tensors): - # Tensor indices. - index1 = i*5 - index2 = i*5+5 - - # Reduce the tensor. - reduce_alignment_tensor(self.frame_order_2nd, self.full_tensors[index1:index2], self.red_tensors_bc[index1:index2]) - - # Convert the tensor to 3D, rank-2 form. - to_tensor(self.tensor_3D, self.red_tensors_bc[index1:index2]) - - # Rotate the tensor (normal R.X.RT rotation). - if self.full_in_ref_frame[i]: - self.tensor_3D = dot(self.rot, dot(self.tensor_3D, transpose(self.rot))) - - # Rotate the tensor (inverse RT.X.R rotation). - else: - self.tensor_3D = dot(transpose(self.rot), dot(self.tensor_3D, self.rot)) - - # Convert the tensor back to 5D, rank-1 form. - to_5D(self.red_tensors_bc[index1:index2], self.tensor_3D) - - # Return the chi-squared value. - return chi2(self.red_tensors, self.red_tensors_bc, self.red_errors) - - - def func_iso_cone_elements(self, params): - """Target function for isotropic cone model optimisation using the Frame Order matrix. - - This function optimises by directly matching the elements of the 2nd degree Frame Order - super matrix. The cone axis spherical angles theta and phi and the cone angle theta are the - 3 parameters optimised in this model. - - @param params: The vector of parameter values {theta, phi, theta_cone} where the first two - are the polar and azimuthal angles of the cone axis theta_cone is the - isotropic cone angle. - @type params: list of float - @return: The chi-squared or SSE value. - @rtype: float - """ - - # Break up the parameters. - theta, phi, theta_cone = params - - # Generate the 2nd degree Frame Order super matrix. - self.frame_order_2nd = compile_2nd_matrix_iso_cone(self.frame_order_2nd, self.rot, self.z_axis, self.cone_axis, theta, phi, theta_cone) - - # Make the Frame Order matrix contiguous. - self.frame_order_2nd = self.frame_order_2nd.copy() - - # Reshape the numpy arrays for use in the chi2() function. - self.data.shape = (81,) - self.frame_order_2nd.shape = (81,) - self.errors.shape = (81,) - - # Get the chi-squared value. - val = chi2(self.data, self.frame_order_2nd, self.errors) - - # Reshape the arrays back to normal. - self.data.shape = (9, 9) - self.frame_order_2nd.shape = (9, 9) - self.errors.shape = (9, 9) - - # Return the chi2 value. - return val Modified: 1.3/specific_fns/frame_order.py URL: http://svn.gna.org/viewcvs/relax/1.3/specific_fns/frame_order.py?rev=9524&r1=9523&r2=9524&view=diff ============================================================================== --- 1.3/specific_fns/frame_order.py (original) +++ 1.3/specific_fns/frame_order.py Mon Sep 14 13:59:44 2009 @@ -37,7 +37,7 @@ from generic_fns.angles import wrap_angles from generic_fns.structure.geometric import cone_edge, generate_vector_dist, generate_vector_residues, stitch_cone_to_edge from generic_fns.structure.internal import Internal -from maths_fns import frame_order_models +from maths_fns import frame_order from maths_fns.frame_order_matrix_ops import generate_vector from maths_fns.rotation_matrix import two_vect_to_R from relax_errors import RelaxError, RelaxInfError, RelaxNaNError, RelaxNoModelError @@ -311,7 +311,7 @@ full_tensors, red_tensors, red_tensor_err, full_in_ref_frame = self.__minimise_setup_tensors() # Set up the optimisation function. - target = frame_order_models.Frame_order(model=cdp.model, full_tensors=full_tensors, red_tensors=red_tensors, red_errors=red_tensor_err, full_in_ref_frame=full_in_ref_frame) + target = frame_order.Frame_order(model=cdp.model, full_tensors=full_tensors, red_tensors=red_tensors, red_errors=red_tensor_err, full_in_ref_frame=full_in_ref_frame) # Make a single function call. This will cause back calculation and the data will be stored in the class instance. target.func(param_vector) @@ -347,7 +347,7 @@ full_tensors, red_tensors, red_tensor_err, full_in_ref_frame = self.__minimise_setup_tensors() # Set up the optimisation function. - target = frame_order_models.Frame_order(model=cdp.model, full_tensors=full_tensors, red_tensors=red_tensors, red_errors=red_tensor_err, full_in_ref_frame=full_in_ref_frame) + target = frame_order.Frame_order(model=cdp.model, full_tensors=full_tensors, red_tensors=red_tensors, red_errors=red_tensor_err, full_in_ref_frame=full_in_ref_frame) # Make a single function call. This will cause back calculation and the data will be stored in the class instance. chi2 = target.func(param_vector) @@ -691,7 +691,7 @@ full_tensors, red_tensors, red_tensor_err, full_in_ref_frame = self.__minimise_setup_tensors(sim_index) # Set up the optimisation function. - target = frame_order_models.Frame_order(model=cdp.model, full_tensors=full_tensors, red_tensors=red_tensors, red_errors=red_tensor_err, full_in_ref_frame=full_in_ref_frame) + target = frame_order.Frame_order(model=cdp.model, full_tensors=full_tensors, red_tensors=red_tensors, red_errors=red_tensor_err, full_in_ref_frame=full_in_ref_frame) # Minimisation. results = generic_minimise(func=target.func, args=(), x0=param_vector, min_algor=min_algor, min_options=min_options, func_tol=func_tol, grad_tol=grad_tol, maxiter=max_iterations, full_output=True, print_flag=verbosity)