コード例 #1
0
def create_rotor_axis_alpha(alpha=None, pivot=None, point=None):
    """Create the rotor axis from the axis alpha angle.

    @keyword alpha: The axis alpha angle, defined as the angle between a vector perpendicular to the pivot-CoM vector in the xy-plane and the rotor axis.
    @type alpha:    float
    @keyword pivot: The pivot point on the rotation axis.
    @type pivot:    numpy rank-1 3D array
    @keyword point: The reference point in space.
    @type point:    numpy rank-1 3D array
    @return:        The rotor axis as a unit vector.
    @rtype:         numpy rank-1 3D float64 array
    """

    # The CoM-pivot unit vector - the norm of the system (the pivot is defined as the point on the axis closest to the point).
    n = point - pivot
    n /= norm(n)

    # The vector perpendicular to the CoM-pivot vector and in the xy plane.
    mu_xy = cross(Z_AXIS, n)
    mu_xy /= norm(mu_xy)

    # Rotate the vector about the CoM-pivot axis by the angle alpha.
    axis_angle_to_R(n, alpha, R)
    axis = dot(R, mu_xy)

    # Return the new axis.
    return axis
コード例 #2
0
ファイル: conversions.py プロジェクト: pombredanne/relax
def create_rotor_axis_alpha(alpha=None, pivot=None, point=None):
    """Create the rotor axis from the axis alpha angle.

    @keyword alpha: The axis alpha angle, defined as the angle between a vector perpendicular to the pivot-CoM vector in the xy-plane and the rotor axis.
    @type alpha:    float
    @keyword pivot: The pivot point on the rotation axis.
    @type pivot:    numpy rank-1 3D array
    @keyword point: The reference point in space.
    @type point:    numpy rank-1 3D array
    @return:        The rotor axis as a unit vector.
    @rtype:         numpy rank-1 3D float64 array
    """

    # The CoM-pivot unit vector - the norm of the system (the pivot is defined as the point on the axis closest to the point).
    n = point - pivot
    n /= norm(n)

    # The vector perpendicular to the CoM-pivot vector and in the xy plane.
    mu_xy = cross(Z_AXIS, n)
    mu_xy /= norm(mu_xy)

    # Rotate the vector about the CoM-pivot axis by the angle alpha.
    axis_angle_to_R(n, alpha, R)
    axis = dot(R, mu_xy)

    # Return the new axis.
    return axis
コード例 #3
0
    def rotation(self, i):
        """Set up the rotation for state i."""

        # The rotation angle.
        angle = (i - (self.N-1)/2) * self.INC / 360.0 * 2.0 * pi

        # The rotation matrix.
        axis_angle_to_R(self.axes[:, 2], angle, self.R)
コード例 #4
0
    def rotation(self, i, motion_index=0):
        """Set up the rotation for state i."""

        # The rotation angle.
        angle = (i - self.N/2) * self.INC[motion_index] / 360.0 * 2.0 * pi

        # The rotation matrix.
        axis_angle_to_R(self.axes[:, 2], angle, self.R)
コード例 #5
0
    def rotation(self, i, motion_index=0):
        """Set up the rotation for state i."""

        # The rotation angle.
        angle = i * self.INC[motion_index] / 360.0 * 2.0 * pi

        # The rotation matrix.
        axis_angle_to_R(self.axes[:, 2], angle, self.R)
コード例 #6
0
    def rotation(self, i, motion_index=0):
        """Set up the rotation for state i."""

        # The rotation angle.
        angle = (i - 0.5) * 10.0 / 360.0 * 2.0 * pi
        print("Rotation angle: %s" % angle)

        # The rotation matrix.
        axis_angle_to_R(self.axes[:, 2], angle, self.R)
        print("Rotation matrix:\n%s\n" % self.R)
コード例 #7
0
    def rotation(self, i):
        """Set up the rotation for state i."""

        # The rotation angle.
        angle = (i - 0.5) * 10.0 / 360.0 * 2.0 * pi
        print("Rotation angle: %s" % angle)

        # The rotation matrix.
        axis_angle_to_R(self.axes[:, 2], angle, self.R)
        print("Rotation matrix:\n%s\n" % self.R)
コード例 #8
0
    def rotation_double_xy_axes(self):
        """Random double rotation around the x- and y-axes and return of torsion-tilt angles"""

        # First a random angle between -pi and pi for the y-axis.
        sigma1 = uniform(-pi, pi)
        axis_angle_to_R(self.y_axis, sigma1, self.rot)

        # Second a random angle between -pi and pi for the x-axis.
        sigma2 = uniform(-pi, pi)
        axis_angle_to_R(self.x_axis, sigma2, self.rot2)

        # Construct the frame.
        frame = dot(self.rot2, self.rot)

        # Rotate the frame.
        self.rot = dot(EIG_FRAME, dot(frame, self.eig_frame_T))

        # Return the two torsion angles, and zero.
        return sigma1, sigma2, 0.0
コード例 #9
0
ファイル: inf_frame_order.py プロジェクト: pombredanne/relax
    def rotation_double_xy_axes(self):
        """Random double rotation around the x- and y-axes and return of torsion-tilt angles"""

        # First a random angle between -pi and pi for the y-axis.
        sigma1 = uniform(-pi, pi)
        axis_angle_to_R(self.y_axis, sigma1, self.rot)

        # Second a random angle between -pi and pi for the x-axis.
        sigma2 = uniform(-pi, pi)
        axis_angle_to_R(self.x_axis, sigma2, self.rot2)

        # Construct the frame.
        frame = dot(self.rot2, self.rot)

        # Rotate the frame.
        self.rot = dot(EIG_FRAME, dot(frame, self.eig_frame_T))

        # Return the two torsion angles, and zero.
        return sigma1, sigma2, 0.0
コード例 #10
0
    def rotation_z_axis(self):
        """Random rotation around the z-axis and return of torsion-tilt angles"""

        # Random angle between -pi and pi.
        angle = uniform(-pi, pi)

        # Generate the rotation matrix.
        axis_angle_to_R(self.z_axis, angle, self.rot)

        # Decompose the rotation into the zyz Euler angles.
        alpha, beta, gamma = R_to_euler_zyz(self.rot)

        # Rotate the frame.
        self.rot = dot(EIG_FRAME, dot(self.rot, self.eig_frame_T))

        # Convert to tilt and torsion angles (properly wrapped) and return them.
        theta = beta
        phi = wrap_angles(gamma, -pi, pi)
        sigma = wrap_angles(alpha + gamma, -pi, pi)
        return theta, phi, sigma
コード例 #11
0
ファイル: inf_frame_order.py プロジェクト: pombredanne/relax
    def rotation_z_axis(self):
        """Random rotation around the z-axis and return of torsion-tilt angles"""

        # Random angle between -pi and pi.
        angle = uniform(-pi, pi)

        # Generate the rotation matrix.
        axis_angle_to_R(self.z_axis, angle, self.rot)

        # Decompose the rotation into the zyz Euler angles.
        alpha, beta, gamma = R_to_euler_zyz(self.rot)

        # Rotate the frame.
        self.rot = dot(EIG_FRAME, dot(self.rot, self.eig_frame_T))

        # Convert to tilt and torsion angles (properly wrapped) and return them.
        theta = beta
        phi = wrap_angles(gamma, -pi, pi)
        sigma = wrap_angles(alpha + gamma, -pi, pi)
        return theta, phi, sigma
コード例 #12
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
コード例 #13
0
ファイル: diffusion_tensor.py プロジェクト: pombredanne/relax
    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
コード例 #14
0
ファイル: generate_base.py プロジェクト: tlinnet/relax
    def build_axes_alt(self):
        """An alternative axis system for the CaM system."""

        # The z-axis for the rotations (the pivot point to CoM axis).
        axis_z = self.COM - self.PIVOT
        axis_z = axis_z / norm(axis_z)

        # The y-axis (to check the torsion angle).
        axis_y = cross(axis_z, array([0, 0, 1]))
        axis_y = axis_y / norm(axis_y)

        # The x-axis.
        axis_x = cross(axis_y, axis_z)
        axis_x = axis_x / norm(axis_x)

        # The eigenframe.
        axes = transpose(array([axis_x, axis_y, axis_z]))

        # Init a rotation matrix.
        R = zeros((3, 3), float64)

        # Tilt the axes system by x degrees.
        tilt_axis = cross(axis_z, array([0, 0, 1]))
        tilt_axis = tilt_axis / norm(tilt_axis)
        axis_angle_to_R(tilt_axis, self.TILT_ANGLE * 2.0 * pi / 360.0, R)

        # Rotate the eigenframe.
        self.axes = dot(R, axes)
        alpha, beta, gamma = R_to_euler_zyz(self.axes)

        # Printout.
        print("Tilt axis: %s, norm = %s" % (repr(tilt_axis), norm(tilt_axis)))
        print("CoM-pivot axis: %s, norm = %s" % (repr(axis_z), norm(axis_z)))
        print("Rotation axis: %s, norm = %s" % (repr(self.axes[:, 2]), norm(self.axes[:, 2])))
        print("Full axis system:\n%s" % self.axes)
        print("Full axis system Euler angles:\n\talpha: %s\n\tbeta: %s\n\tgamma: %s" % (repr(alpha), repr(beta), repr(gamma)))
コード例 #15
0
    def build_axes_alt(self):
        """An alternative axis system for the CaM system."""

        # The z-axis for the rotations (the pivot point to CoM axis).
        axis_z = self.com - self.pivot
        axis_z = axis_z / norm(axis_z)

        # The y-axis (to check the torsion angle).
        axis_y = cross(axis_z, array([0, 0, 1]))
        axis_y = axis_y / norm(axis_y)

        # The x-axis.
        axis_x = cross(axis_y, axis_z)
        axis_x = axis_x / norm(axis_x)

        # The eigenframe.
        axes = transpose(array([axis_x, axis_y, axis_z]))

        # Init a rotation matrix.
        R = zeros((3, 3), float64)

        # Tilt the axes system by x degrees.
        tilt_axis = cross(axis_z, array([0, 0, 1]))
        tilt_axis = tilt_axis / norm(tilt_axis)
        axis_angle_to_R(tilt_axis, self.TILT_ANGLE * 2.0 * pi / 360.0, R)

        # Rotate the eigenframe.
        self.axes = dot(R, axes)
        alpha, beta, gamma = R_to_euler_zyz(self.axes)

        # Print out.
        print("Tilt axis: %s, norm = %s" % (repr(tilt_axis), norm(tilt_axis)))
        print("CoM-pivot axis: %s, norm = %s" % (repr(axis_z), norm(axis_z)))
        print("Rotation axis: %s, norm = %s" % (repr(self.axes[:, 2]), norm(self.axes[:, 2])))
        print("Full axis system:\n%s" % self.axes)
        print("Full axis system Euler angles:\n\talpha: %s\n\tbeta: %s\n\tgamma: %s" % (repr(alpha), repr(beta), repr(gamma)))
コード例 #16
0
ファイル: generate_data.py プロジェクト: tlinnet/relax
def tensor_setup(Dx=None, Dy=None, Dz=None, alpha=None, beta=None, gamma=None):
    """Set up the diffusion tensor according to the correct Euler angle convention."""

    # Print out.
    print("\n\n")
    print("# Angles to diff tensor.")
    print("########################")

    # Init.
    ROT = False

    # The rotation matrix (in the rotating axis system).
    R = zeros((3, 3), float64)
    R_rev = zeros((3, 3), float64)
    euler_to_R_zyz(gamma, beta, alpha, R)
    R_rev = transpose(R)
    print("\nEuler angels: [%s, %s, %s]" % (alpha, beta, gamma))
    print("R:\n%s" % R)
    print("R_rev:\n%s" % R_rev)
    print("X x Y: %s" % cross(R[:, 0], R[:, 1]))

    # Axis rotations.
    if ROT:
        R_x180 = zeros((3, 3), float64)
        R_y180 = zeros((3, 3), float64)
        R_z180 = zeros((3, 3), float64)
        axis_angle_to_R(R_rev[:, 0], pi, R_x180)
        axis_angle_to_R(R_rev[:, 1], pi, R_y180)
        axis_angle_to_R(R_rev[:, 2], pi, R_z180)
        print("\nR (x 180):\n%s" % R_x180)
        print("\nR (y 180):\n%s" % R_y180)
        print("\nR (z 180):\n%s" % R_z180)

    # A test vector.
    mu = array([1, 2, -3], float64)
    mu = mu / norm(mu)

    # Tensor in eigenframe.
    D_prime = zeros((3, 3), float64)
    D_prime[0, 0] = Dx
    D_prime[1, 1] = Dy
    D_prime[2, 2] = Dz
    print("\nD':\n%s" % D_prime)

    # Rotate tensor from the eigenframe to the ref frame.
    D = dot(R_rev, dot(D_prime, transpose(R_rev)))
    print("\nD:\n%s" % D)
    print("\n\n")

    # Return the forward and reverse rotation, and the diffusion tensors.
    return R, R_rev, D_prime, D
コード例 #17
0
ファイル: generate_data.py プロジェクト: pombredanne/relax
def tensor_setup(Dx=None, Dy=None, Dz=None, alpha=None, beta=None, gamma=None):
    """Set up the diffusion tensor according to the correct Euler angle convention."""

    # Print out.
    print("\n\n")
    print("# Angles to diff tensor.")
    print("########################")

    # Init.
    ROT = False

    # The rotation matrix (in the rotating axis system).
    R = zeros((3, 3), float64)
    R_rev = zeros((3, 3), float64)
    euler_to_R_zyz(gamma, beta, alpha, R)
    R_rev = transpose(R)
    print("\nEuler angels: [%s, %s, %s]" % (alpha, beta, gamma))
    print("R:\n%s" % R)
    print("R_rev:\n%s" % R_rev)
    print("X x Y: %s" % cross(R[:, 0], R[:, 1]))

    # Axis rotations.
    if ROT:
        R_x180 = zeros((3, 3), float64)
        R_y180 = zeros((3, 3), float64)
        R_z180 = zeros((3, 3), float64)
        axis_angle_to_R(R_rev[:, 0], pi, R_x180)
        axis_angle_to_R(R_rev[:, 1], pi, R_y180)
        axis_angle_to_R(R_rev[:, 2], pi, R_z180)
        print("\nR (x 180):\n%s" % R_x180)
        print("\nR (y 180):\n%s" % R_y180)
        print("\nR (z 180):\n%s" % R_z180)

    # A test vector.
    mu = array([1, 2, -3], float64)
    mu = mu / norm(mu)

    # Tensor in eigenframe.
    D_prime = zeros((3, 3), float64)
    D_prime[0, 0] = Dx
    D_prime[1, 1] = Dy
    D_prime[2, 2] = Dz
    print("\nD':\n%s" % D_prime)

    # Rotate tensor from the eigenframe to the ref frame.
    D = dot(R_rev, dot(D_prime, transpose(R_rev)))
    print("\nD:\n%s" % D)
    print("\n\n")

    # Return the forward and reverse rotation, and the diffusion tensors.
    return R, R_rev, D_prime, D
コード例 #18
0
ファイル: rotate.py プロジェクト: belisario21/relax_trunk

# Generate a random pivot rotation.
R_random_axis(R_PIVOT, PIVOT_ANGLE)

# Print out.
print("\nThe pivot rotation angle is: %20.40f" % PIVOT_ANGLE)
print("The pivot rotation angle is: %s" % floatAsByteArray(PIVOT_ANGLE))
print("\nThe pivot rotation matrix is:\n%s" % R_PIVOT)
print("Or:")
float_array = to_ieee_754(R_PIVOT)
for i in range(3):
    print(float_array[i])

# Generate the torsion angle rotation.
axis_angle_to_R(VECT_TORSION, TORSION_ANGLE, R_TORSION)

# Print out.
print("\nThe torsion rotation matrix is:\n%s" % R_TORSION)
print("Or:")
float_array = to_ieee_754(R_TORSION)
for i in range(3):
    print(float_array[i])

# Combine the rotations.
R = dot(R_TORSION, R_PIVOT)

# Print out.
print("\nThe full rotation matrix is:\n%s" % R)
print("Or:")
float_array = to_ieee_754(R)
コード例 #19
0
ファイル: rotor.py プロジェクト: belisario21/relax_trunk
def rotor_propellers(mol=None, rotor_angle=None, centre=None, axis=None, blade_length=5.0, staggered=False):
    """Create a PDB representation of a rotor motional model.

    @keyword mol:           The internal structural object molecule container to add the atoms to.
    @type mol:              MolContainer instance
    @keyword rotor_angle:   The angle of the rotor motion in radians.
    @type rotor_angle:      float
    @keyword centre:        The central point of the propeller.
    @type centre:           numpy rank-1, 3D array
    @keyword axis:          The vector defining the rotor axis.
    @type axis:             numpy rank-1, 3D array
    @keyword blade_length:  The length of the representative rotor blades in Angstrom.
    @type blade_length:     float
    @keyword staggered:     A flag which if True will cause the rotor blades to be staggered.  This is used to avoid blade overlap.
    @type staggered:        bool
    """

    # Init.
    step_angle = 2.0 / 360.0 * 2.0 * pi
    R = zeros((3, 3), float64)
    res_num = mol.last_residue() + 1

    # Blade vectors.
    blades = zeros((4, 3), float64)
    if abs(dot(axis, array([0, 0, 1], float64))) == 1.0:    # Avoid failures in artificial situations.
        blades[0] = cross(axis, array([1, 0, 0], float64))
    else:
        blades[0] = cross(axis, array([0, 0, 1], float64))
    blades[0] = blades[0] / norm(blades[0])
    blades[1] = cross(axis, blades[0])
    blades[1] = blades[1] / norm(blades[1])
    blades[2] = -blades[0]
    blades[3] = -blades[1]

    # Create the 4 blades.
    for i in range(len(blades)):
        # Staggering.
        if staggered and i % 2:
            blade_origin = centre - axis * 2

        # Non-staggered.
        else:
            blade_origin = centre

        # Add an atom for the blage origin.
        blade_origin_index = mol.atom_add(pdb_record='HETATM', atom_name='BLO', res_name='PRB', res_num=res_num, pos=blade_origin, element='O')

        # The centre edge point of the blade.
        mid_point = blade_origin + blades[i] * blade_length
        mid_pt_index = mol.atom_add(pdb_record='HETATM', atom_name='BLD', res_name='PRB', res_num=res_num, pos=mid_point, element='N')
        mol.atom_connect(index1=mid_pt_index, index2=blade_origin_index)

        # Build the blade.
        angle = 0.0
        pos_last_index = mid_pt_index
        neg_last_index = mid_pt_index
        while True:
            # Increase the angle.
            angle += step_angle

            # The edge rotation.
            if angle > rotor_angle:
                axis_angle_to_R(axis, rotor_angle, R)

            # The normal rotation matrix.
            else:
                axis_angle_to_R(axis, angle, R)

            # The positive edge.
            pos_point = dot(R, mid_point - blade_origin) + blade_origin
            pos_index = mol.atom_add(pdb_record='HETATM', atom_name='BLD', res_name='PRB', res_num=res_num, pos=pos_point, element='N')
            mol.atom_connect(index1=pos_index, index2=pos_last_index)
            mol.atom_connect(index1=pos_index, index2=blade_origin_index)

            # The negative edge.
            neg_point = dot(transpose(R), mid_point - blade_origin) + blade_origin
            neg_index = mol.atom_add(pdb_record='HETATM', atom_name='BLD', res_name='PRB', res_num=res_num, pos=neg_point, element='N')
            mol.atom_connect(index1=neg_index, index2=neg_last_index)
            mol.atom_connect(index1=neg_index, index2=blade_origin_index)

            # Update the indices.
            pos_last_index = pos_index
            neg_last_index = neg_index

            # Finish.
            if angle > rotor_angle:
                break

        # Increment the residue number.
        res_num += 1
コード例 #20
0
ファイル: simulation.py プロジェクト: pombredanne/relax
def brownian(file=None, model=None, structure=None, parameters={}, eigenframe=None, pivot=None, atom_id=None, step_size=2.0, snapshot=10, total=1000):
    """Pseudo-Brownian dynamics simulation of the frame order motions.

    @keyword file:          The opened and writable file object to place the snapshots into.
    @type file:             str
    @keyword structure:     The internal structural object containing the domain to simulate as a single model.
    @type structure:        lib.structure.internal.object.Internal instance
    @keyword model:         The frame order model to simulate.
    @type model:            str
    @keyword parameters:    The dictionary of model parameter values.  The key is the parameter name and the value is the value.
    @type parameters:       dict of float
    @keyword eigenframe:    The full 3D eigenframe of the frame order motions.
    @type eigenframe:       numpy rank-2, 3D float64 array
    @keyword pivot:         The list of pivot points of the frame order motions.
    @type pivot:            numpy rank-2 (N, 3) float64 array
    @keyword atom_id:       The atom ID string for the atoms in the structure to rotate - i.e. the moving domain.
    @type atom_id:          None or str
    @keyword step_size:     The rotation will be of a random direction but with this fixed angle.  The value is in degrees.
    @type step_size:        float
    @keyword snapshot:      The number of steps in the simulation when snapshots will be taken.
    @type snapshot:         int
    @keyword total:         The total number of snapshots to take before stopping the simulation.
    @type total:            int
    """

    # Check the structural object.
    if structure.num_models() > 1:
        raise RelaxError("Only a single model is supported.")

    # Set the model number.
    structure.set_model(model_orig=None, model_new=1)

    # Generate the internal structural selection object.
    selection = structure.selection(atom_id)

    # The initial states and motional limits.
    num_states = len(pivot)
    states = zeros((num_states, 3, 3), float64)
    theta_max = []
    sigma_max = []
    for i in range(num_states):
        states[i] = eye(3)
        theta_max.append(None)
        sigma_max.append(None)

    # Initialise the rotation matrix data structures.
    vector = zeros(3, float64)
    R = eye(3, dtype=float64)
    step_size = step_size / 360.0 * 2.0 * pi

    # Axis permutations.
    perm = [None]
    if model == MODEL_DOUBLE_ROTOR:
        perm = [[2, 0, 1], [1, 2, 0]]
        perm_rev = [[1, 2, 0], [2, 0, 1]]

    # The maximum cone opening angles (isotropic cones).
    if 'cone_theta' in parameters:
        theta_max[0] = parameters['cone_theta']

    # The maximum cone opening angles (isotropic cones).
    theta_x = None
    theta_y = None
    if 'cone_theta_x' in parameters:
        theta_x = parameters['cone_theta_x']
        theta_y = parameters['cone_theta_y']

    # The maximum torsion angle.
    if 'cone_sigma_max' in parameters:
        sigma_max[0] = parameters['cone_sigma_max']
    elif 'free rotor' in model:
        sigma_max[0] = pi

    # The second torsion angle.
    if 'cone_sigma_max_2' in parameters:
        sigma_max[1] = parameters['cone_sigma_max_2']

    # Printout.
    print("\nRunning the simulation:")

    # Simulate.
    current_snapshot = 1
    step = 1
    while True:
        # End the simulation.
        if current_snapshot == total:
            print("\nEnd of simulation.")
            break

        # Loop over each state, or motional mode.
        for i in range(num_states):
            # The random vector.
            random_unit_vector(vector)

            # The rotation matrix.
            axis_angle_to_R(vector, step_size, R)

            # Shift the current state.
            states[i] = dot(R, states[i])

            # Rotation in the eigenframe.
            R_eigen = dot(transpose(eigenframe), dot(states[i], eigenframe))

            # Axis permutation to shift each rotation axis to Z.
            if perm[i] != None:
                for j in range(3):
                    R_eigen[:, j] = R_eigen[perm[i], j]
                for j in range(3):
                    R_eigen[j, :] = R_eigen[j, perm[i]]

            # The angles.
            phi, theta, sigma = R_to_tilt_torsion(R_eigen)
            sigma = wrap_angles(sigma, -pi, pi)

            # Determine theta_max for the pseudo-ellipse models.
            if theta_x != None:
                theta_max[i] = 1.0 / sqrt((cos(phi) / theta_x)**2 + (sin(phi) / theta_y)**2)

            # Set the cone opening angle to the maximum if outside of the limit.
            if theta_max[i] != None:
                if theta > theta_max[i]:
                    theta = theta_max[i]

            # No tilt component.
            else:
                theta = 0.0
                phi = 0.0

            # Set the torsion angle to the maximum if outside of the limits.
            if sigma_max[i] != None:
                if sigma > sigma_max[i]:
                    sigma = sigma_max[i]
                elif sigma < -sigma_max[i]:
                    sigma = -sigma_max[i]
            else:
                sigma = 0.0

            # Reconstruct the rotation matrix, in the eigenframe, without sigma.
            tilt_torsion_to_R(phi, theta, sigma, R_eigen)

            # Reverse axis permutation to shift each rotation z-axis back.
            if perm[i] != None:
                for j in range(3):
                    R_eigen[:, j] = R_eigen[perm_rev[i], j]
                for j in range(3):
                    R_eigen[j, :] = R_eigen[j, perm_rev[i]]

            # Rotate back out of the eigenframe.
            states[i] = dot(eigenframe, dot(R_eigen, transpose(eigenframe)))

        # Take a snapshot.
        if step == snapshot:
            # Progress.
            sys.stdout.write('.')
            sys.stdout.flush()

            # Increment the snapshot number.
            current_snapshot += 1

            # Copy the original structural data.
            structure.add_model(model=current_snapshot, coords_from=1)

            # Rotate the model.
            for i in range(num_states):
                structure.rotate(R=states[i], origin=pivot[i], model=current_snapshot, selection=selection)

            # Reset the step counter.
            step = 0

        # Increment.
        step += 1

    # Save the result.
    structure.write_pdb(file=file)
コード例 #21
0
ファイル: simulation.py プロジェクト: tlinnet/relax
def mode_distribution(file=None,
                      structure=None,
                      axis=None,
                      angle=None,
                      pivot=None,
                      atom_id=None,
                      angle_inc=2 * pi / 360):
    """Linear distribution of a single component of the frame order motions.

    @keyword file:          The opened and writable file object to place the PDB models of the representation into.
    @type file:             str
    @keyword structure:     The internal structural object to convert into an ensemble along the mode of motion.
    @type structure:        lib.structure.internal.object.Internal instance
    @keyword axis:          The rotation axis.
    @type axis:             numpy 3D float64 array
    @keyword angle:         The rotation angle in radian (structures will be rotated +/- this angle).
    @type angle:            float
    @keyword pivot:         The pivot point for the given motional mode.
    @type pivot:            numpy 3D float64 array
    @keyword atom_id:       The atom ID string for the atoms in the structure to rotate - i.e. the moving domain.
    @type atom_id:          None or str
    @keyword angle_inc:     The angle between rotated representations.  The default is 1 degree.
    @type angle_inc:        float
    """

    # Check the structural object.
    if structure.num_models() > 1:
        raise RelaxError("Only a single model is supported.")

    # Set the model number.
    structure.set_model(model_orig=None, model_new=1)

    # Generate the internal structural selection object.
    selection = structure.selection(atom_id)

    # Initialise the rotation matrix data structures.
    R = eye(3, dtype=float64)

    # The range of angles.
    count = int(angle / angle_inc)
    inner = arange(-count * angle_inc, (count + 1) * angle_inc, angle_inc)
    if inner[-1] > angle:
        inner = inner[:-1]
    if modf(angle / angle_inc)[0] > 1e-7:
        print("Bracketing the representation.")
        angles = zeros(len(inner) + 2, float64)
        angles[0] = -angle
        angles[1:-1] = inner
        angles[-1] = angle
    else:
        print("No bracketing of the representation required.")
        angles = inner

    # Generate the structures.
    current_model = 1
    for i in range(len(angles)):
        # The rotation matrix.
        axis_angle_to_R(axis, angles[i], R)

        # Increment the snapshot number.
        current_model += 1

        # Copy the original structural data.
        structure.add_model(model=current_model, coords_from=1)

        # Rotate the model.
        structure.rotate(R=R,
                         origin=pivot,
                         model=current_model,
                         selection=selection)

    # Save the result.
    structure.write_pdb(file=file)
    print("")
コード例 #22
0
ファイル: simulation.py プロジェクト: bopopescu/relax
def mode_distribution(file=None,
                      structure=None,
                      axis=None,
                      angle=None,
                      pivot=None,
                      atom_id=None,
                      angle_inc=2 * pi / 360,
                      total=None,
                      reverse=False,
                      mirror=False):
    """Linear distribution of a single component of the frame order motions.

    @keyword file:          The opened and wrlib/frame_order/simulation.pyitable file object to place the PDB models of the representation into.
    @type file:             str
    @keyword structure:     The internal structural object to convert into an ensemble along the mode of motion.
    @type structure:        lib.structure.internal.object.Internal instance
    @keyword axis:          The rotation axis.
    @type axis:             numpy 3D float64 array
    @keyword angle:         The rotation angle in radian (structures will be rotated +/- this angle).
    @type angle:            float
    @keyword pivot:         The pivot point for the given motional mode.
    @type pivot:            numpy 3D float64 array
    @keyword atom_id:       The atom ID string for the atoms in the structure to rotate - i.e. the moving domain.
    @type atom_id:          None or str
    @keyword angle_inc:     The angle between rotated representations.  The default is 1 degree.
    @type angle_inc:        float
    @keyword total:         The total number of structures to distribute along the motional modes.  This overrides angle_inc.
    @type total:            int
    @keyword reverse:       Set this to reverse the ordering of the models distributed along the motional mode.  Use a list of Booleans to selectively reverse each motional mode.
    @type reverse:          bool or list of bool
    @keyword mirror:        Set this to have the models distributed along the motional mode shift from the negative angle to positive angle, and then return to the negative angle.
    @type mirror:           bool
    """

    # Check the structural object.
    if structure.num_models() > 1:
        raise RelaxError("Only a single model is supported.")

    # Set the model number.
    structure.set_model(model_orig=None, model_new=1)

    # Generate the internal structural selection object.
    selection = structure.selection(atom_id)

    # Initialise the rotation matrix data structures.
    R = eye(3, dtype=float64)

    # No angle handling.
    if angle == 0.0 or total == 1:
        angles = array([0.0])

    # Range of angles for a fixed number of structures.
    elif total != None:
        if mirror:
            total = int(total / 2) + 1
        angles = linspace(-angle, angle, total)

    # Range of angles for a fixed angle between structures.
    else:
        angles = linspace(-angle, angle, int(angle / angle_inc))
        if not len(angles):
            angles = array([-angle, 0.0, angle])

    # Angle reversal.
    if reverse:
        angles = angles[::-1]

    # Angle mirroring.
    if mirror:
        angles2 = angles[:-1]
        angles2 = angles2[::-1]
        angles = concatenate((angles, angles2))

    # Generate the structures.
    current_model = 1
    for i in range(len(angles)):
        # The rotation matrix.
        axis_angle_to_R(axis, angles[i], R)

        # Increment the snapshot number.
        current_model += 1

        # Copy the original structural data.
        structure.add_model(model=current_model, coords_from=1)

        # Rotate the model.
        structure.rotate(R=R,
                         origin=pivot,
                         model=current_model,
                         selection=selection)

    # Delete the first model.
    structure.delete(model=1)

    # Save the result.
    structure.write_pdb(file=file)
    print("")
コード例 #23
0
ファイル: rotate.py プロジェクト: tlinnet/relax

# Generate a random pivot rotation.
R_random_axis(R_PIVOT, PIVOT_ANGLE)

# Print out.
print("\nThe pivot rotation angle is: %20.40f" % PIVOT_ANGLE)
print("The pivot rotation angle is: %s" % floatAsByteArray(PIVOT_ANGLE))
print("\nThe pivot rotation matrix is:\n%s" % R_PIVOT)
print("Or:")
float_array = to_ieee_754(R_PIVOT)
for i in range(3):
    print(float_array[i])

# Generate the torsion angle rotation.
axis_angle_to_R(VECT_TORSION, TORSION_ANGLE, R_TORSION)

# Print out.
print("\nThe torsion rotation matrix is:\n%s" % R_TORSION)
print("Or:")
float_array = to_ieee_754(R_TORSION)
for i in range(3):
    print(float_array[i])

# Combine the rotations.
R = dot(R_TORSION, R_PIVOT)

# Print out.
print("\nThe full rotation matrix is:\n%s" % R)
print("Or:")
float_array = to_ieee_754(R)
コード例 #24
0
ファイル: simulation.py プロジェクト: bopopescu/relax
def brownian(file=None,
             model=None,
             structure=None,
             parameters={},
             eigenframe=None,
             pivot=None,
             atom_id=None,
             step_size=2.0,
             snapshot=10,
             total=1000):
    """Pseudo-Brownian dynamics simulation of the frame order motions.

    @keyword file:          The opened and writable file object to place the snapshots into.
    @type file:             str
    @keyword structure:     The internal structural object containing the domain to simulate as a single model.
    @type structure:        lib.structure.internal.object.Internal instance
    @keyword model:         The frame order model to simulate.
    @type model:            str
    @keyword parameters:    The dictionary of model parameter values.  The key is the parameter name and the value is the value.
    @type parameters:       dict of float
    @keyword eigenframe:    The full 3D eigenframe of the frame order motions.
    @type eigenframe:       numpy rank-2, 3D float64 array
    @keyword pivot:         The list of pivot points of the frame order motions.
    @type pivot:            numpy rank-2 (N, 3) float64 array
    @keyword atom_id:       The atom ID string for the atoms in the structure to rotate - i.e. the moving domain.
    @type atom_id:          None or str
    @keyword step_size:     The rotation will be of a random direction but with this fixed angle.  The value is in degrees.
    @type step_size:        float
    @keyword snapshot:      The number of steps in the simulation when snapshots will be taken.
    @type snapshot:         int
    @keyword total:         The total number of snapshots to take before stopping the simulation.
    @type total:            int
    """

    # Check the structural object.
    if structure.num_models() > 1:
        raise RelaxError("Only a single model is supported.")

    # Set the model number.
    structure.set_model(model_orig=None, model_new=1)

    # Generate the internal structural selection object.
    selection = structure.selection(atom_id)

    # The initial states and motional limits.
    num_states = len(pivot)
    states = zeros((num_states, 3, 3), float64)
    theta_max = []
    sigma_max = []
    for i in range(num_states):
        states[i] = eye(3)
        theta_max.append(None)
        sigma_max.append(None)

    # Initialise the rotation matrix data structures.
    vector = zeros(3, float64)
    R = eye(3, dtype=float64)
    step_size = step_size / 360.0 * 2.0 * pi

    # Axis permutations.
    perm = [None]
    if model == MODEL_DOUBLE_ROTOR:
        perm = [[2, 0, 1], [1, 2, 0]]
        perm_rev = [[1, 2, 0], [2, 0, 1]]

    # The maximum cone opening angles (isotropic cones).
    if 'cone_theta' in parameters:
        theta_max[0] = parameters['cone_theta']

    # The maximum cone opening angles (isotropic cones).
    theta_x = None
    theta_y = None
    if 'cone_theta_x' in parameters:
        theta_x = parameters['cone_theta_x']
        theta_y = parameters['cone_theta_y']

    # The maximum torsion angle.
    if 'cone_sigma_max' in parameters:
        sigma_max[0] = parameters['cone_sigma_max']
    elif 'free rotor' in model:
        sigma_max[0] = pi

    # The second torsion angle.
    if 'cone_sigma_max_2' in parameters:
        sigma_max[1] = parameters['cone_sigma_max_2']

    # Printout.
    print("\nRunning the simulation:")

    # Simulate.
    current_snapshot = 1
    step = 1
    while True:
        # End the simulation.
        if current_snapshot == total:
            print("\nEnd of simulation.")
            break

        # Loop over each state, or motional mode.
        for i in range(num_states):
            # The random vector.
            random_unit_vector(vector)

            # The rotation matrix.
            axis_angle_to_R(vector, step_size, R)

            # Shift the current state.
            states[i] = dot(R, states[i])

            # Rotation in the eigenframe.
            R_eigen = dot(transpose(eigenframe), dot(states[i], eigenframe))

            # Axis permutation to shift each rotation axis to Z.
            if perm[i] != None:
                for j in range(3):
                    R_eigen[:, j] = R_eigen[perm[i], j]
                for j in range(3):
                    R_eigen[j, :] = R_eigen[j, perm[i]]

            # The angles.
            phi, theta, sigma = R_to_tilt_torsion(R_eigen)
            sigma = wrap_angles(sigma, -pi, pi)

            # Determine theta_max for the pseudo-ellipse models.
            if theta_x != None:
                theta_max[i] = 1.0 / sqrt((cos(phi) / theta_x)**2 +
                                          (sin(phi) / theta_y)**2)

            # Set the cone opening angle to the maximum if outside of the limit.
            if theta_max[i] != None:
                if theta > theta_max[i]:
                    theta = theta_max[i]

            # No tilt component.
            else:
                theta = 0.0
                phi = 0.0

            # Set the torsion angle to the maximum if outside of the limits.
            if sigma_max[i] != None:
                if sigma > sigma_max[i]:
                    sigma = sigma_max[i]
                elif sigma < -sigma_max[i]:
                    sigma = -sigma_max[i]
            else:
                sigma = 0.0

            # Reconstruct the rotation matrix, in the eigenframe, without sigma.
            tilt_torsion_to_R(phi, theta, sigma, R_eigen)

            # Reverse axis permutation to shift each rotation z-axis back.
            if perm[i] != None:
                for j in range(3):
                    R_eigen[:, j] = R_eigen[perm_rev[i], j]
                for j in range(3):
                    R_eigen[j, :] = R_eigen[j, perm_rev[i]]

            # Rotate back out of the eigenframe.
            states[i] = dot(eigenframe, dot(R_eigen, transpose(eigenframe)))

        # Take a snapshot.
        if step == snapshot:
            # Progress.
            sys.stdout.write('.')
            sys.stdout.flush()

            # Increment the snapshot number.
            current_snapshot += 1

            # Copy the original structural data.
            structure.add_model(model=current_snapshot, coords_from=1)

            # Rotate the model.
            for i in range(num_states):
                structure.rotate(R=states[i],
                                 origin=pivot[i],
                                 model=current_snapshot,
                                 selection=selection)

            # Reset the step counter.
            step = 0

        # Increment.
        step += 1

    # Save the result.
    structure.write_pdb(file=file)
コード例 #25
0
ファイル: rotor.py プロジェクト: tlinnet/relax
def rotor_propellers(mol=None,
                     rotor_angle=None,
                     centre=None,
                     axis=None,
                     blade_length=5.0,
                     step_angle=2.0,
                     staggered=False):
    """Create a PDB representation of a rotor motional model.

    This function will create a fixed number of atoms, placing the propeller blade steps outside of the rotor angle on the edge.  This is to allow for model support whereby the rotor angle between models can be different but the atomic count and connectivity must be the same in all models.


    @keyword mol:           The internal structural object molecule container to add the atoms to.
    @type mol:              MolContainer instance
    @keyword rotor_angle:   The angle of the rotor motion in radians.
    @type rotor_angle:      float
    @keyword centre:        The central point of the propeller.
    @type centre:           numpy rank-1, 3D array
    @keyword axis:          The vector defining the rotor axis.
    @type axis:             numpy rank-1, 3D array
    @keyword blade_length:  The length of the representative rotor blades in Angstrom.
    @type blade_length:     float
    @keyword step_angle:    The angle between propeller blades, in degrees.
    @type step_angle:       float
    @keyword staggered:     A flag which if True will cause the rotor blades to be staggered.  This is used to avoid blade overlap.
    @type staggered:        bool
    """

    # Init.
    step_angle = step_angle / 360.0 * 2.0 * pi
    step_num = int(pi / step_angle)
    R = zeros((3, 3), float64)
    res_num = mol.last_residue() + 1

    # Blade vectors.
    blades = zeros((4, 3), float64)
    if abs(dot(axis, array(
        [0, 0, 1],
            float64))) == 1.0:  # Avoid failures in artificial situations.
        blades[0] = cross(axis, array([1, 0, 0], float64))
    else:
        blades[0] = cross(axis, array([0, 0, 1], float64))
    blades[0] = blades[0] / norm(blades[0])
    blades[1] = cross(axis, blades[0])
    blades[1] = blades[1] / norm(blades[1])
    blades[2] = -blades[0]
    blades[3] = -blades[1]

    # Create the 4 blades.
    for i in range(len(blades)):
        # Staggering.
        if staggered and i % 2:
            blade_origin = centre - axis * 2

        # Non-staggered.
        else:
            blade_origin = centre

        # Add an atom for the blage origin.
        blade_origin_index = mol.atom_add(pdb_record='HETATM',
                                          atom_name='BLO',
                                          res_name='RTB',
                                          res_num=res_num,
                                          pos=blade_origin,
                                          element='O')

        # The centre edge point of the blade.
        mid_point = blade_origin + blades[i] * blade_length
        mid_pt_index = mol.atom_add(pdb_record='HETATM',
                                    atom_name='BLD',
                                    res_name='RTB',
                                    res_num=res_num,
                                    pos=mid_point,
                                    element='N')
        mol.atom_connect(index1=mid_pt_index, index2=blade_origin_index)

        # Build the blade.
        angle = 0.0
        pos_last_index = mid_pt_index
        neg_last_index = mid_pt_index
        for j in range(step_num):
            # Increase the angle.
            angle += step_angle

            # The edge rotation (place all points outside of the rotor angle on the edge).
            if angle > rotor_angle:
                axis_angle_to_R(axis, rotor_angle, R)

            # The normal rotation matrix.
            else:
                axis_angle_to_R(axis, angle, R)

            # The positive edge.
            pos_point = dot(R, mid_point - blade_origin) + blade_origin
            pos_index = mol.atom_add(pdb_record='HETATM',
                                     atom_name='BLD',
                                     res_name='RTB',
                                     res_num=res_num,
                                     pos=pos_point,
                                     element='N')
            mol.atom_connect(index1=pos_index, index2=pos_last_index)
            mol.atom_connect(index1=pos_index, index2=blade_origin_index)

            # The negative edge.
            neg_point = dot(transpose(R),
                            mid_point - blade_origin) + blade_origin
            neg_index = mol.atom_add(pdb_record='HETATM',
                                     atom_name='BLD',
                                     res_name='RTB',
                                     res_num=res_num,
                                     pos=neg_point,
                                     element='N')
            mol.atom_connect(index1=neg_index, index2=neg_last_index)
            mol.atom_connect(index1=neg_index, index2=blade_origin_index)

            # Update the indices.
            pos_last_index = pos_index
            neg_last_index = neg_index

        # Increment the residue number.
        res_num += 1