Ejemplo n.º 1
0
    def convert_rotor(self, theta=None, phi=None, pivot=None, com=None):
        """Convert the rotor axis spherical angles to the axis alpha notation.

        The pivot will be shifted to the point on the axis closest to the CoM, and the alpha angle set.


        @keyword theta: The polar spherical angle.
        @type theta:    float
        @keyword phi:   The azimuthal spherical angle.
        @type phi:      float
        @keyword pivot: The pivot point on the rotation axis.
        @type pivot:    numpy rank-1 3D array
        @keyword com:   The pivot point on the rotation axis.
        @type com:      numpy rank-1 3D array
        """

        # The axis.
        axis = zeros(3, float64)
        spherical_to_cartesian([1.0, theta, phi], axis)

        # Reset the pivot to the closest point on the line to the CoM (shift the pivot).
        self.PIVOT = closest_point_ax(line_pt=pivot, axis=axis, point=com)

        # The CoM-pivot unit vector (for the shifted pivot).
        piv_com = com - self.PIVOT
        piv_com = piv_com / norm(piv_com)

        # The vector perpendicular to the CoM-pivot vector.
        z_axis = array([0, 0, 1], float64)
        perp_vect = cross(piv_com, z_axis)
        perp_vect = perp_vect / norm(perp_vect)

        # Set the alpha angle (the angle between the perpendicular vector and the axis).
        self.AXIS_ALPHA = vector_angle_normal(perp_vect, axis, piv_com)
Ejemplo n.º 2
0
    def convert_rotor(self, theta=None, phi=None, pivot=None, com=None):
        """Convert the rotor axis spherical angles to the axis alpha notation.

        The pivot will be shifted to the point on the axis closest to the CoM, and the alpha angle set.


        @keyword theta: The polar spherical angle.
        @type theta:    float
        @keyword phi:   The azimuthal spherical angle.
        @type phi:      float
        @keyword pivot: The pivot point on the rotation axis.
        @type pivot:    numpy rank-1 3D array
        @keyword com:   The pivot point on the rotation axis.
        @type com:      numpy rank-1 3D array
        """

        # The axis.
        axis = zeros(3, float64)
        spherical_to_cartesian([1.0, theta, phi], axis)

        # Reset the pivot to the closest point on the line to the CoM (shift the pivot).
        self.PIVOT = closest_point_ax(line_pt=pivot, axis=axis, point=com)

        # The CoM-pivot unit vector (for the shifted pivot).
        piv_com = com - self.PIVOT
        piv_com = piv_com / norm(piv_com)

        # The vector perpendicular to the CoM-pivot vector.
        z_axis = array([0, 0, 1], float64)
        perp_vect = cross(piv_com, z_axis)
        perp_vect = perp_vect / norm(perp_vect)

        # Set the alpha angle (the angle between the perpendicular vector and the axis).
        self.AXIS_ALPHA = vector_angle_normal(perp_vect, axis, piv_com)
Ejemplo n.º 3
0
    def calc_Rx2_eigen_axis(self, axis_theta, axis_phi):
        """Calculate the Kronecker product of the eigenframe rotation for the z-axis based frame."""

        # Generate the cone axis from the spherical angles.
        spherical_to_cartesian([1.0, axis_theta, axis_phi], self.cone_axis)

        # Pre-calculate the eigenframe rotation matrix.
        two_vect_to_R(self.z_axis, self.cone_axis, self.R_temp)

        # The Kronecker product of the eigenframe rotation.
        return kron_prod(self.R_temp, self.R_temp)
Ejemplo n.º 4
0
    def calc_Rx2_eigen_axis(self, axis_theta, axis_phi):
        """Calculate the Kronecker product of the eigenframe rotation for the z-axis based frame."""

        # Generate the cone axis from the spherical angles.
        spherical_to_cartesian([1.0, axis_theta, axis_phi], self.cone_axis)

        # Pre-calculate the eigenframe rotation matrix.
        two_vect_to_R(self.z_axis, self.cone_axis, self.R_temp)

        # The Kronecker product of the eigenframe rotation.
        return kron_prod(self.R_temp, self.R_temp)
Ejemplo n.º 5
0
def create_rotor_axis_spherical(theta=None, phi=None):
    """Create the rotor axis from the spherical coordinates.

    @keyword theta: The polar spherical angle.
    @type theta:    float
    @keyword phi:   The azimuthal spherical angle.
    @type phi:      float
    @return:        The rotor axis as a unit vector.
    @rtype:         numpy rank-1 3D float64 array
    """

    # Initialise the axis.
    axis = zeros(3, float64)

    # Parameter conversion.
    spherical_to_cartesian([1.0, theta, phi], axis)

    # Return the new axis.
    return axis
Ejemplo n.º 6
0
def create_rotor_axis_spherical(theta=None, phi=None):
    """Create the rotor axis from the spherical coordinates.

    @keyword theta: The polar spherical angle.
    @type theta:    float
    @keyword phi:   The azimuthal spherical angle.
    @type phi:      float
    @return:        The rotor axis as a unit vector.
    @rtype:         numpy rank-1 3D float64 array
    """

    # Initialise the axis.
    axis = zeros(3, float64)

    # Parameter conversion.
    spherical_to_cartesian([1.0, theta, phi], axis)

    # Return the new axis.
    return axis
Ejemplo n.º 7
0
    def get_spheroid(self, Dpar=None, Dper=None, theta=None, phi=None):
        """Return all the diffusion tensor info about the given spheroid tensor."""

        # The tensor info.
        Diso = (Dpar + 2*Dper) / 3.0
        tm = 1.0/(6.0 * Diso)
        Da = Dpar - Dper
        Dratio = Dpar / Dper

        # The eigenvalues and unique axis in the eigenframe.
        if Dpar > Dper:
            Dx, Dy, Dz = Dper, Dper, Dpar
            axis = array([0, 0, 1], float64)
        else:
            Dx, Dy, Dz = Dpar, Dper, Dper
            axis = array([1, 0, 0], float64)

        # The actual tensor in the PDB frame.
        R = zeros((3, 3), float64)
        spher_vect = array([1, theta, phi], float64)
        diff_axis = zeros(3, float64)
        spherical_to_cartesian(spher_vect, diff_axis)
        two_vect_to_R(diff_axis, axis, R)

        # The tensor in the eigenframe.
        D_prime = zeros((3, 3), float64)
        D_prime[0, 0] = Dx
        D_prime[1, 1] = Dy
        D_prime[2, 2] = Dz

        # Rotate a little about the unique axis!
        twist = zeros((3, 3), float64)
        axis_angle_to_R(axis, 0.3, twist)
        D = dot(twist, dot(D_prime, transpose(twist)))

        # The tensor in the PDB frame.
        D = dot(R, dot(D, transpose(R)))

        # Return the data.
        return tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R
Ejemplo n.º 8
0
    def get_spheroid(self, Dpar=None, Dper=None, theta=None, phi=None):
        """Return all the diffusion tensor info about the given spheroid tensor."""

        # The tensor info.
        Diso = (Dpar + 2*Dper) / 3.0
        tm = 1.0/(6.0 * Diso)
        Da = Dpar - Dper
        Dratio = Dpar / Dper

        # The eigenvalues and unique axis in the eigenframe.
        if Dpar > Dper:
            Dx, Dy, Dz = Dper, Dper, Dpar
            axis = array([0, 0, 1], float64)
        else:
            Dx, Dy, Dz = Dpar, Dper, Dper
            axis = array([1, 0, 0], float64)

        # The actual tensor in the PDB frame.
        R = zeros((3, 3), float64)
        spher_vect = array([1, theta, phi], float64)
        diff_axis = zeros(3, float64)
        spherical_to_cartesian(spher_vect, diff_axis)
        two_vect_to_R(diff_axis, axis, R)

        # The tensor in the eigenframe.
        D_prime = zeros((3, 3), float64)
        D_prime[0, 0] = Dx
        D_prime[1, 1] = Dy
        D_prime[2, 2] = Dz

        # Rotate a little about the unique axis!
        twist = zeros((3, 3), float64)
        axis_angle_to_R(axis, 0.3, twist)
        D = dot(twist, dot(D_prime, transpose(twist)))

        # The tensor in the PDB frame.
        D = dot(R, dot(D, transpose(R)))

        # Return the data.
        return tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R
Ejemplo n.º 9
0
    print("%-20s%s" % ("New pivot:", pivot_new))

    # Return the shifted pivot.
    return pivot_new


# The real parameter values.
AVE_POS_X, AVE_POS_Y, AVE_POS_Z = [ -21.269217407269576,   -3.122610661328414,   -2.400652421655998]
AVE_POS_ALPHA, AVE_POS_BETA, AVE_POS_GAMMA = [5.623469076122531, 0.435439405668396, 5.081265529106499]
AXIS_THETA = 0.9600799785953431
AXIS_PHI = 4.0322755062196229
CONE_SIGMA_MAX = 1.0 / 360.0 * 2.0 * pi

# Reconstruct the rotation axis.
AXIS = zeros(3, float64)
spherical_to_cartesian([1, AXIS_THETA, AXIS_PHI], AXIS)
print("Rotation axis: %s" % AXIS)

# Create the data pipe.
pipe.create(pipe_name='frame order', pipe_type='frame order')

# Read the structures.
structure.read_pdb('1J7O_1st_NH.pdb', dir='..', set_mol_name='N-dom')
structure.read_pdb('1J7P_1st_NH_rot.pdb', dir='..', set_mol_name='C-dom')

# Set up the 15N and 1H spins.
structure.load_spins(spin_id='@N', ave_pos=False)
structure.load_spins(spin_id='@H', ave_pos=False)
spin.isotope(isotope='15N', spin_id='@N')
spin.isotope(isotope='1H', spin_id='@H')
Ejemplo n.º 10
0
from lib.text.sectioning import section

# The real rotor parameter values.
AVE_POS_X, AVE_POS_Y, AVE_POS_Z = [
    -21.269217407269576, -3.122610661328414, -2.400652421655998
]
AVE_POS_ALPHA, AVE_POS_BETA, AVE_POS_GAMMA = [
    5.623469076122531, 0.435439405668396, 5.081265529106499
]
AXIS_THETA = 0.9600799785953431
AXIS_PHI = 4.0322755062196229
CONE_SIGMA_MAX = 30.0 / 360.0 * 2.0 * pi

# Reconstruct the rotation axis.
AXIS = zeros(3, float64)
spherical_to_cartesian([1, AXIS_THETA, AXIS_PHI], AXIS)

# Printout.
print("Torsion angle: %s" % CONE_SIGMA_MAX)
print("Rotation axis: %s" % AXIS)

# Load the optimised rotor state for creating the iso cone data pipes.
state.load(state='frame_order_true', dir='..')

# Set up the dynamic system.
value.set(param='ave_pos_x', val=AVE_POS_X)
value.set(param='ave_pos_y', val=AVE_POS_Y)
value.set(param='ave_pos_z', val=AVE_POS_Z)
value.set(param='ave_pos_alpha', val=AVE_POS_ALPHA)
value.set(param='ave_pos_beta', val=AVE_POS_BETA)
value.set(param='ave_pos_gamma', val=AVE_POS_GAMMA)
Ejemplo n.º 11
0
def calc_rotation(diff_type, *args):
    """Function for calculating the rotation matrix.

    Spherical diffusion
    ===================

    As the orientation of the diffusion tensor within the structural frame is undefined when the molecule diffuses as a sphere, the rotation matrix is simply the identity matrix::

              | 1  0  0 |
        R  =  | 0  1  0 |.
              | 0  0  1 |


    Spheroidal diffusion
    ====================

    The rotation matrix required to shift from the diffusion tensor frame to the structural frame is generated from the unique axis of the diffusion tensor.


    Ellipsoidal diffusion
    =====================

    The rotation matrix required to shift from the diffusion tensor frame to the structural frame is equal to::

        R  =  | Dx_unit  Dy_unit  Dz_unit |,

              | Dx_unit[0]  Dy_unit[0]  Dz_unit[0] |
           =  | Dx_unit[1]  Dy_unit[1]  Dz_unit[1] |.
              | Dx_unit[2]  Dy_unit[2]  Dz_unit[2] |

    @param args:        All the function arguments.  For the spheroid, this includes the spheroid_type (str), the azimuthal angle theta in radians (float), and the polar angle phi in radians (float).  For the ellipsoid, this includes the Dx unit vector (numpy 3D, rank-1 array), the Dy unit vector (numpy 3D, rank-1 array), and the Dz unit vector (numpy 3D, rank-1 array).
    @type args:         tuple
    @return:            The rotation matrix.
    @rtype:             numpy 3x3 array
    """

    # The rotation matrix for the sphere.
    if diff_type == 'sphere':
        return identity(3, float64)

    # The rotation matrix for the spheroid.
    elif diff_type == 'spheroid':
        # Unpack the arguments.
        spheroid_type, theta, phi = args

        # Initialise the rotation matrix.
        R = zeros((3, 3), float64)

        # The unique axis in the diffusion frame.
        if spheroid_type == 'prolate':
            axis = array([0, 0, 1], float64)
        else:
            axis = array([1, 0, 0], float64)

        # The spherical coordinate vector.
        spher_vect = array([1, theta, phi], float64)

        # The diffusion tensor axis in the PDB frame.
        diff_axis = zeros(3, float64)
        spherical_to_cartesian(spher_vect, diff_axis)

        # The rotation matrix.
        two_vect_to_R(diff_axis, axis, R)

        # Return the rotation.
        return R

    # The rotation matrix for the ellipsoid.
    elif diff_type == 'ellipsoid':
        # Unpack the arguments.
        Dx_unit, Dy_unit, Dz_unit = args

        # Initialise the rotation matrix.
        rotation = identity(3, float64)

        # First column of the rotation matrix.
        rotation[:, 0] = Dx_unit

        # Second column of the rotation matrix.
        rotation[:, 1] = Dy_unit

        # Third column of the rotation matrix.
        rotation[:, 2] = Dz_unit

        # Return the tensor.
        return rotation

    # Raise an error.
    else:
        raise RelaxError('The diffusion tensor has not been specified')
Ejemplo n.º 12
0
def calc_rotation(diff_type, *args):
    """Function for calculating the rotation matrix.

    Spherical diffusion
    ===================

    As the orientation of the diffusion tensor within the structural frame is undefined when the molecule diffuses as a sphere, the rotation matrix is simply the identity matrix::

              | 1  0  0 |
        R  =  | 0  1  0 |.
              | 0  0  1 |


    Spheroidal diffusion
    ====================

    The rotation matrix required to shift from the diffusion tensor frame to the structural frame is generated from the unique axis of the diffusion tensor.


    Ellipsoidal diffusion
    =====================

    The rotation matrix required to shift from the diffusion tensor frame to the structural frame is equal to::

        R  =  | Dx_unit  Dy_unit  Dz_unit |,

              | Dx_unit[0]  Dy_unit[0]  Dz_unit[0] |
           =  | Dx_unit[1]  Dy_unit[1]  Dz_unit[1] |.
              | Dx_unit[2]  Dy_unit[2]  Dz_unit[2] |

    @param args:        All the function arguments.  For the spheroid, this includes the spheroid_type (str), the azimuthal angle theta in radians (float), and the polar angle phi in radians (float).  For the ellipsoid, this includes the Dx unit vector (numpy 3D, rank-1 array), the Dy unit vector (numpy 3D, rank-1 array), and the Dz unit vector (numpy 3D, rank-1 array).
    @type args:         tuple
    @return:            The rotation matrix.
    @rtype:             numpy 3x3 array
    """

    # The rotation matrix for the sphere.
    if diff_type == 'sphere':
        return identity(3, float64)

    # The rotation matrix for the spheroid.
    elif diff_type == 'spheroid':
        # Unpack the arguments.
        spheroid_type, theta, phi = args

        # Initialise the rotation matrix.
        R = zeros((3, 3), float64)

        # The unique axis in the diffusion frame.
        if spheroid_type == 'prolate':
            axis = array([0, 0, 1], float64)
        else:
            axis = array([1, 0, 0], float64)

        # The spherical coordinate vector.
        spher_vect = array([1, theta, phi], float64)

        # The diffusion tensor axis in the PDB frame.
        diff_axis = zeros(3, float64)
        spherical_to_cartesian(spher_vect, diff_axis)

        # The rotation matrix.
        two_vect_to_R(diff_axis, axis, R)

        # Return the rotation.
        return R

    # The rotation matrix for the ellipsoid.
    elif diff_type == 'ellipsoid':
        # Unpack the arguments.
        Dx_unit, Dy_unit, Dz_unit = args

        # Initialise the rotation matrix.
        rotation = identity(3, float64)

        # First column of the rotation matrix.
        rotation[:, 0] = Dx_unit

        # Second column of the rotation matrix.
        rotation[:, 1] = Dy_unit

        # Third column of the rotation matrix.
        rotation[:, 2] = Dz_unit

        # Return the tensor.
        return rotation

    # Raise an error.
    else:
        raise RelaxError('The diffusion tensor has not been specified')
Ejemplo n.º 13
0
    def print_results(self):
        """Print out the optimisation results for the current data pipe."""

        # Header.
        sys.stdout.write("\nFinal optimisation results:\n")

        # Formatting string.
        format_float = "    %-20s %20.15f\n"
        format_vect = "    %-20s %20s\n"

        # Average position.
        if hasattr(cdp, 'ave_pos_x') or hasattr(cdp, 'ave_pos_alpha') or hasattr(cdp, 'ave_pos_beta') or hasattr(cdp, 'ave_pos_gamma'):
            sys.stdout.write("\nAverage moving domain position:\n")
        if hasattr(cdp, 'ave_pos_x'):
            sys.stdout.write(format_float % ('x:', cdp.ave_pos_x))
        if hasattr(cdp, 'ave_pos_y'):
            sys.stdout.write(format_float % ('y:', cdp.ave_pos_y))
        if hasattr(cdp, 'ave_pos_z'):
            sys.stdout.write(format_float % ('z:', cdp.ave_pos_z))
        if hasattr(cdp, 'ave_pos_alpha'):
            sys.stdout.write(format_float % ('alpha:', cdp.ave_pos_alpha))
        if hasattr(cdp, 'ave_pos_beta'):
            sys.stdout.write(format_float % ('beta:', cdp.ave_pos_beta))
        if hasattr(cdp, 'ave_pos_gamma'):
            sys.stdout.write(format_float % ('gamma:', cdp.ave_pos_gamma))

        # Frame order eigenframe.
        if hasattr(cdp, 'eigen_alpha') or hasattr(cdp, 'eigen_beta') or hasattr(cdp, 'eigen_gamma') or hasattr(cdp, 'axis_theta') or hasattr(cdp, 'axis_phi'):
            sys.stdout.write("\nFrame order eigenframe:\n")
        if hasattr(cdp, 'eigen_alpha'):
            sys.stdout.write(format_float % ('eigen alpha:', cdp.eigen_alpha))
        if hasattr(cdp, 'eigen_beta'):
            sys.stdout.write(format_float % ('eigen beta:', cdp.eigen_beta))
        if hasattr(cdp, 'eigen_gamma'):
            sys.stdout.write(format_float % ('eigen gamma:', cdp.eigen_gamma))

        # The cone axis.
        if hasattr(cdp, 'axis_theta'):
            # The angles.
            sys.stdout.write(format_float % ('axis theta:', cdp.axis_theta))
            sys.stdout.write(format_float % ('axis phi:', cdp.axis_phi))

            # The axis.
            axis = zeros(3, float64)
            spherical_to_cartesian([1.0, cdp.axis_theta, cdp.axis_phi], axis)
            sys.stdout.write(format_vect % ('axis:', axis))

        # Frame ordering.
        if hasattr(cdp, 'cone_theta_x') or hasattr(cdp, 'cone_theta_y') or hasattr(cdp, 'cone_theta') or hasattr(cdp, 'cone_s1') or hasattr(cdp, 'cone_sigma_max'):
            sys.stdout.write("\nFrame ordering:\n")
        if hasattr(cdp, 'cone_theta_x'):
            sys.stdout.write(format_float % ('cone theta_x:', cdp.cone_theta_x))
        if hasattr(cdp, 'cone_theta_y'):
            sys.stdout.write(format_float % ('cone theta_y:', cdp.cone_theta_y))
        if hasattr(cdp, 'cone_theta'):
            sys.stdout.write(format_float % ('cone theta:', cdp.cone_theta))
        if hasattr(cdp, 'cone_s1'):
            sys.stdout.write(format_float % ('cone s1:', cdp.cone_s1))
        if hasattr(cdp, 'cone_sigma_max'):
            sys.stdout.write(format_float % ('sigma_max:', cdp.cone_sigma_max))

        # Minimisation statistics.
        if hasattr(cdp, 'chi2'):
            sys.stdout.write("\nMinimisation statistics:\n")
        if hasattr(cdp, 'chi2'):
            sys.stdout.write(format_float % ('chi2:', cdp.chi2))

        # Final spacing.
        sys.stdout.write("\n")