


                                     relax repository checkout

                              Molecular dynamics by NMR data analysis

                             Copyright (C) 2001-2006 Edward d'Auvergne
                         Copyright (C) 2006-2011 the relax development team

This is free software which you are welcome to modify and redistribute under the conditions of the
GNU General Public License (GPL).  This program, including all modules, is licensed under the GPL
and comes with absolutely no warranty.  For details type 'GPL' within the relax prompt.

Assistance in using the relax prompt and scripting interface can be accessed by typing 'help' within
the prompt.

Processor fabric:  Uni-processor.

script = 'rotate.py'
----------------------------------------------------------------------------------------------------
# Script for shifting the C-domain to be out of the average rigid body position.

# Python module imports.
from numpy import array, dot, float64, zeros
from numpy.linalg import norm
from sys import stdout

# relax module imports.
from float import floatAsByteArray
from maths_fns.rotation_matrix import axis_angle_to_R, R_random_axis


def to_ieee_754(R):
    """Convert and return the rotation matrix as the full precision IEEE 754 byte array."""

    array = []

    for i in range(3):
        array.append([])
        for j in range(3):
            array[i].append(floatAsByteArray(R[i, j]))

    return array


# Init.
PIVOT_ANGLE = 200.0 / 3.0
PIVOT_ANGLE = PIVOT_ANGLE * (2.0*pi) / 360
PIVOT = array([ 37.254, 0.5, 16.7465])
R_PIVOT = zeros((3, 3), float64)

TORSION_ANGLE = 100 / 3.0
COM_C = array([ 26.83678091, -12.37906417,  28.34154128])
R_TORSION = zeros((3, 3), float64)
VECT_TORSION = COM_C - PIVOT
VECT_TORSION = VECT_TORSION / norm(VECT_TORSION)


# 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)
for i in range(3):
    print(float_array[i])

# Create a data pipe.
pipe.create('rot', 'N-state')

# Load the C-domain PDB file.
structure.read_pdb('1J7P_1st_NH.pdb')

# Rotate all atoms.
structure.rotate(R=R, origin=[ 37.254, 0.5, 16.7465])

# Save the rotated PDB file.
structure.write_pdb('1J7P_1st_NH_rot_new.pdb', force=True)
----------------------------------------------------------------------------------------------------

The pivot rotation angle is: 1.1635528346628865037359901180025190114975
The pivot rotation angle is: [28, 185, 192, 147, 233, 157, 242, 63]

The pivot rotation matrix is:
[[ 0.94362558 -0.32261441 -0.07409926]
 [ 0.07417985  0.42425993 -0.90249701]
 [ 0.32259589  0.8461226   0.42427402]]
Or:
[[50, 144, 193, 70, 46, 50, 238, 63], [20, 226, 242, 237, 182, 165, 212, 191], [186, 246, 92, 83, 43, 248, 178, 191]]
[[58, 194, 151, 108, 115, 253, 178, 63], [172, 96, 219, 34, 19, 39, 219, 63], [196, 113, 90, 106, 65, 225, 236, 191]]
[[242, 101, 13, 63, 105, 165, 212, 63], [50, 198, 13, 178, 111, 19, 235, 63], [205, 235, 128, 52, 78, 39, 219, 63]]

The torsion rotation matrix is:
[[ 0.01589352 -0.09970727 -0.99488987]
 [ 0.9789945   0.20383041 -0.00478817]
 [ 0.20326622 -0.97391562  0.10085245]]
Or:
[[128, 201, 194, 7, 100, 70, 144, 63], [160, 250, 209, 98, 106, 134, 185, 191], [24, 152, 178, 72, 35, 214, 239, 191]]
[[220, 59, 87, 72, 236, 83, 239, 63], [140, 208, 234, 93, 29, 23, 202, 63], [192, 18, 211, 106, 195, 156, 115, 191]]
[[26, 230, 62, 166, 160, 4, 202, 63], [96, 107, 207, 20, 81, 42, 239, 191], [168, 128, 140, 89, 119, 209, 185, 63]]

The full rotation matrix is:
[[-0.31334613 -0.88922808 -0.33329811]
 [ 0.93737972 -0.23341205 -0.2585306 ]
 [ 0.15209688 -0.39343645  0.90668313]]
Or:
[[141, 60, 4, 233, 220, 13, 212, 191], [103, 126, 203, 113, 142, 116, 236, 191], [62, 176, 27, 150, 193, 84, 213, 191]]
[[1, 19, 253, 194, 3, 255, 237, 63], [170, 54, 95, 40, 114, 224, 205, 191], [15, 10, 120, 237, 195, 139, 208, 191]]
[[3, 166, 36, 16, 233, 119, 195, 63], [89, 32, 75, 19, 16, 46, 217, 191], [21, 155, 147, 87, 140, 3, 237, 63]]

relax> pipe.create(pipe_name='rot', pipe_type='N-state')

relax> structure.read_pdb(file='1J7P_1st_NH.pdb', dir=None, read_mol=None, set_mol_name=None, read_model=None, set_model_num=None, parser='internal')

Internal relax PDB parser.
Opening the file '1J7P_1st_NH.pdb' for reading.
Adding molecule '1J7P_1st_NH_mol1' to model None (from the original molecule number 1 of model None)

relax> structure.rotate(R=array([[-0.31334613, -0.88922808, -0.33329811],
       [ 0.93737972, -0.23341205, -0.2585306 ],
       [ 0.15209688, -0.39343645,  0.90668313]]), origin=[37.254, 0.5, 16.7465])

relax> structure.write_pdb(file='1J7P_1st_NH_rot_new.pdb', dir=None, model_num=None, force=True)
Opening the file '1J7P_1st_NH_rot_new.pdb' for writing.

Creating the PDB records

REMARK
HET
HETNAM
FORMUL
ATOM, HETATM, TER
CONECT

MASTER
END

