Author: bugman Date: Thu Sep 11 19:16:52 2014 New Revision: 25746 URL: http://svn.gna.org/viewcvs/relax?rev=25746&view=rev Log: Added support for the isotopic cone models to the frame_order.permute_axes user function. This is a simpler setup, but it uses the same permutation algorithm as derived for the pseudo-ellipse models. Instead of setting the x and y cone angles separately, they are instead averaged. And as the cone axis is undefined in the xy plane, the axis has been randomly selected as being the axis perpendicular to both the z-axis and the reference frame x-axis. Modified: branches/frame_order_cleanup/specific_analyses/frame_order/uf.py Modified: branches/frame_order_cleanup/specific_analyses/frame_order/uf.py URL: http://svn.gna.org/viewcvs/relax/branches/frame_order_cleanup/specific_analyses/frame_order/uf.py?rev=25746&r1=25745&r2=25746&view=diff ============================================================================== --- branches/frame_order_cleanup/specific_analyses/frame_order/uf.py (original) +++ branches/frame_order_cleanup/specific_analyses/frame_order/uf.py Thu Sep 11 19:16:52 2014 @@ -23,19 +23,22 @@ """Module for all of the frame order specific user functions.""" # Python module imports. -from numpy import array, float64, ones, transpose, zeros +from math import pi +from numpy import array, cross, float64, ones, transpose, zeros +from numpy.linalg import norm from warnings import warn # relax module imports. from lib.arg_check import is_float_array from lib.check_types import is_float from lib.errors import RelaxError, RelaxFault +from lib.geometry.coord_transform import cartesian_to_spherical, spherical_to_cartesian from lib.geometry.rotations import euler_to_R_zyz, R_to_euler_zyz from lib.warnings import RelaxWarning from pipe_control import pipes from specific_analyses.frame_order.geometric import create_ave_pos, create_distribution, create_geometric_rep from specific_analyses.frame_order.parameters import update_model -from specific_analyses.frame_order.variables import MODEL_LIST, MODEL_PSEUDO_ELLIPSE, MODEL_PSEUDO_ELLIPSE_TORSIONLESS, MODEL_RIGID +from specific_analyses.frame_order.variables import MODEL_ISO_CONE, MODEL_ISO_CONE_FREE_ROTOR, MODEL_ISO_CONE_TORSIONLESS, MODEL_LIST, MODEL_LIST_FREE_ROTORS, MODEL_LIST_ISO_CONE, MODEL_LIST_PSEUDO_ELLIPSE, MODEL_LIST_RESTRICTED_TORSION, MODEL_PSEUDO_ELLIPSE, MODEL_PSEUDO_ELLIPSE_TORSIONLESS, MODEL_RIGID def num_int_pts(num=200000): @@ -109,34 +112,74 @@ """ # Check that the model is valid. - if cdp.model not in [MODEL_PSEUDO_ELLIPSE, MODEL_PSEUDO_ELLIPSE_TORSIONLESS]: - raise RelaxError("The permutation of the motional eigenframe is only valid for the '%s' and '%s' frame order models." % (MODEL_PSEUDO_ELLIPSE, MODEL_PSEUDO_ELLIPSE_TORSIONLESS)) + allowed = MODEL_LIST_ISO_CONE + MODEL_LIST_PSEUDO_ELLIPSE + if cdp.model not in allowed: + raise RelaxError("The permutation of the motional eigenframe is only valid for the frame order models %s." % allowed) # Check that the model parameters are setup. - if not hasattr(cdp, 'cone_theta_y') or not is_float(cdp.cone_theta_y): - raise RelaxError("The parameter values are not set up.") + if cdp.model in MODEL_LIST_ISO_CONE: + if not hasattr(cdp, 'cone_theta') or not is_float(cdp.cone_theta): + raise RelaxError("The parameter values are not set up.") + else: + if not hasattr(cdp, 'cone_theta_y') or not is_float(cdp.cone_theta_y): + raise RelaxError("The parameter values are not set up.") + + # The iso cones only have one permutation. + if cdp.model in MODEL_LIST_ISO_CONE and permutation == 'B': + raise RelaxError("The isotropic cones only have one permutation.") # The angles. cone_sigma_max = 0.0 - if cdp.model == MODEL_PSEUDO_ELLIPSE: + if cdp.model in MODEL_LIST_RESTRICTED_TORSION: cone_sigma_max = cdp.cone_sigma_max - angles = array([cdp.cone_theta_x, cdp.cone_theta_y, cone_sigma_max], float64) + elif cdp.model in MODEL_LIST_FREE_ROTORS: + cone_sigma_max = pi + if cdp.model in MODEL_LIST_ISO_CONE: + angles = array([cdp.cone_theta, cdp.cone_theta, cone_sigma_max], float64) + else: + angles = array([cdp.cone_theta_x, cdp.cone_theta_y, cone_sigma_max], float64) x, y, z = angles - # Generate the eigenframe of the motion. - frame = zeros((3, 3), float64) - euler_to_R_zyz(cdp.eigen_alpha, cdp.eigen_beta, cdp.eigen_gamma, frame) - - # Start printout. - print("\nOriginal parameters:") - print("%-20s %20.10f" % ("cone_theta_x", cdp.cone_theta_x)) - print("%-20s %20.10f" % ("cone_theta_y", cdp.cone_theta_y)) - print("%-20s %20.10f" % ("cone_sigma_max", cone_sigma_max)) - print("%-20s %20.10f" % ("eigen_alpha", cdp.eigen_alpha)) - print("%-20s %20.10f" % ("eigen_beta", cdp.eigen_beta)) - print("%-20s %20.10f" % ("eigen_gamma", cdp.eigen_gamma)) - print("%-20s\n%s" % ("eigenframe", frame)) - print("\nPermutation '%s':" % permutation) + # The system for the isotropic cones. + if cdp.model in MODEL_LIST_ISO_CONE: + # Reconstruct the rotation axis. + axis = zeros(3, float64) + spherical_to_cartesian([1, cdp.axis_theta, cdp.axis_phi], axis) + + # Create a full normalised axis system. + x_ax = array([1, 0, 0], float64) + y_ax = cross(axis, x_ax) + y_ax /= norm(y_ax) + x_ax = cross(y_ax, axis) + x_ax /= norm(x_ax) + axes = transpose(array([x_ax, y_ax, axis], float64)) + + # Start printout. + print("\nOriginal parameters:") + print("%-20s %20.10f" % ("cone_theta", cdp.cone_theta)) + print("%-20s %20.10f" % ("cone_sigma_max", cone_sigma_max)) + print("%-20s %20.10f" % ("axis_theta", cdp.axis_theta)) + print("%-20s %20.10f" % ("axis_phi", cdp.axis_phi)) + print("%-20s\n%s" % ("cone axis", axis)) + print("%-20s\n%s" % ("full axis system", axes)) + print("\nPermutation '%s':" % permutation) + + # The system for the pseudo-ellipses. + else: + # Generate the eigenframe of the motion. + frame = zeros((3, 3), float64) + euler_to_R_zyz(cdp.eigen_alpha, cdp.eigen_beta, cdp.eigen_gamma, frame) + + # Start printout. + print("\nOriginal parameters:") + print("%-20s %20.10f" % ("cone_theta_x", cdp.cone_theta_x)) + print("%-20s %20.10f" % ("cone_theta_y", cdp.cone_theta_y)) + print("%-20s %20.10f" % ("cone_sigma_max", cone_sigma_max)) + print("%-20s %20.10f" % ("eigen_alpha", cdp.eigen_alpha)) + print("%-20s %20.10f" % ("eigen_beta", cdp.eigen_beta)) + print("%-20s %20.10f" % ("eigen_gamma", cdp.eigen_gamma)) + print("%-20s\n%s" % ("eigenframe", frame)) + print("\nPermutation '%s':" % permutation) # The axis inversion structure. inv = ones(3, float64) @@ -164,6 +207,7 @@ if permutation == 'A': perm_angles = [0, 2, 1] perm_axes = [2, 1, 0] + inv[perm_axes[2]] = -1.0 else: perm_angles = [2, 1, 0] perm_axes = [0, 2, 1] @@ -192,27 +236,48 @@ print("%-20s %-20s" % ("Axes permutation", perm_axes)) # Permute the angles. - cdp.cone_theta_x = angles[perm_angles[0]] - cdp.cone_theta_y = angles[perm_angles[1]] - if cdp.model == MODEL_PSEUDO_ELLIPSE: + if cdp.model in MODEL_LIST_ISO_CONE: + cdp.cone_theta = (angles[perm_angles[0]] + angles[perm_angles[1]]) / 2.0 + else: + cdp.cone_theta_x = angles[perm_angles[0]] + cdp.cone_theta_y = angles[perm_angles[1]] + if cdp.model in MODEL_LIST_RESTRICTED_TORSION: cdp.cone_sigma_max = angles[perm_angles[2]] - - # Permute the axes. - frame_new = transpose(array([inv[0]*frame[:, perm_axes[0]], inv[1]*frame[:, perm_axes[1]], inv[2]*frame[:, perm_axes[2]]], float64)) - - # Convert the permuted frame to Euler angles and store them. - cdp.eigen_alpha, cdp.eigen_beta, cdp.eigen_gamma = R_to_euler_zyz(frame_new) + elif cdp.model in MODEL_LIST_FREE_ROTORS: + cdp.cone_sigma_max = pi + + # Permute the axes (iso cone). + if cdp.model in MODEL_LIST_ISO_CONE: + # Convert the y-axis to spherical coordinates (the x-axis would be ok too, or any vector in the x-y plane due to symmetry of the original permutation). + axis_new = axes[:, 1] + r, cdp.axis_theta, cdp.axis_phi = cartesian_to_spherical(axis_new) + + # Permute the axes (pseudo-ellipses). + else: + frame_new = transpose(array([inv[0]*frame[:, perm_axes[0]], inv[1]*frame[:, perm_axes[1]], inv[2]*frame[:, perm_axes[2]]], float64)) + + # Convert the permuted frame to Euler angles and store them. + cdp.eigen_alpha, cdp.eigen_beta, cdp.eigen_gamma = R_to_euler_zyz(frame_new) # End printout. - print("\nPermuted parameters:") - print("%-20s %20.10f" % ("cone_theta_x", cdp.cone_theta_x)) - print("%-20s %20.10f" % ("cone_theta_y", cdp.cone_theta_y)) - if cdp.model == MODEL_PSEUDO_ELLIPSE: - print("%-20s %20.10f" % ("cone_sigma_max", cdp.cone_sigma_max)) - print("%-20s %20.10f" % ("eigen_alpha", cdp.eigen_alpha)) - print("%-20s %20.10f" % ("eigen_beta", cdp.eigen_beta)) - print("%-20s %20.10f" % ("eigen_gamma", cdp.eigen_gamma)) - print("%-20s\n%s" % ("eigenframe", frame_new)) + if cdp.model in MODEL_LIST_ISO_CONE: + print("\nPermuted parameters:") + print("%-20s %20.10f" % ("cone_theta", cdp.cone_theta)) + if cdp.model == MODEL_ISO_CONE: + print("%-20s %20.10f" % ("cone_sigma_max", cdp.cone_sigma_max)) + print("%-20s %20.10f" % ("axis_theta", cdp.axis_theta)) + print("%-20s %20.10f" % ("axis_phi", cdp.axis_phi)) + print("%-20s\n%s" % ("cone axis", axis_new)) + else: + print("\nPermuted parameters:") + print("%-20s %20.10f" % ("cone_theta_x", cdp.cone_theta_x)) + print("%-20s %20.10f" % ("cone_theta_y", cdp.cone_theta_y)) + if cdp.model == MODEL_PSEUDO_ELLIPSE: + print("%-20s %20.10f" % ("cone_sigma_max", cdp.cone_sigma_max)) + print("%-20s %20.10f" % ("eigen_alpha", cdp.eigen_alpha)) + print("%-20s %20.10f" % ("eigen_beta", cdp.eigen_beta)) + print("%-20s %20.10f" % ("eigen_gamma", cdp.eigen_gamma)) + print("%-20s\n%s" % ("eigenframe", frame_new)) def pivot(pivot=None, order=1, fix=False):