Author: bugman Date: Sun Oct 23 18:58:00 2011 New Revision: 14886 URL: http://svn.gna.org/viewcvs/relax?rev=14886&view=rev Log: Created the back end for the structure.rotate user function. Modified: 1.3/generic_fns/structure/api_base.py 1.3/generic_fns/structure/internal.py 1.3/generic_fns/structure/main.py Modified: 1.3/generic_fns/structure/api_base.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/structure/api_base.py?rev=14886&r1=14885&r2=14886&view=diff ============================================================================== --- 1.3/generic_fns/structure/api_base.py (original) +++ 1.3/generic_fns/structure/api_base.py Sun Oct 23 18:58:00 2011 @@ -1,6 +1,6 @@ ############################################################################### # # -# Copyright (C) 2008-2010 Edward d'Auvergne # +# Copyright (C) 2008-2011 Edward d'Auvergne # # # # This file is part of the program relax. # # # @@ -459,6 +459,18 @@ model.mol[-1].file_model = orig_model_num[i] + def rotate(self, R=None, origin=None): + """Method stub for rotating a structure. + + @keyword R: The forwards rotation matrix. + @type R: numpy 3D, rank-2 array + @keyword origin: The origin of the rotation. + @type origin: numpy 3D, rank-1 array + """ + + # Raise the error. + raise RelaxImplementError + def target_mol_name(self, set=None, target=None, index=None, mol_num=None, file=None): """Add the new molecule name to the target data structure. Modified: 1.3/generic_fns/structure/internal.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/structure/internal.py?rev=14886&r1=14885&r2=14886&view=diff ============================================================================== --- 1.3/generic_fns/structure/internal.py (original) +++ 1.3/generic_fns/structure/internal.py Sun Oct 23 18:58:00 2011 @@ -1,6 +1,6 @@ ############################################################################### # # -# Copyright (C) 2003-2010 Edward d'Auvergne # +# Copyright (C) 2003-2011 Edward d'Auvergne # # # # This file is part of the program relax. # # # @@ -24,7 +24,7 @@ """Module containing the internal relax structural object.""" # Python module imports. -from numpy import array, float64, linalg, zeros +from numpy import array, dot, float64, linalg, zeros import os from os import F_OK, access from re import search @@ -1020,6 +1020,34 @@ return True + def rotate(self, R=None, origin=None): + """Rotate the structural information about the given origin. + + @keyword R: The forwards rotation matrix. + @type R: numpy 3D, rank-2 array + @keyword origin: The origin of the rotation. + @type origin: numpy 3D, rank-1 array + """ + + # Loop over the models. + for model in self.model_loop(): + # Loop over the molecules. + for mol in model.mol: + # Loop over the atoms. + for i in range(len(mol.atom_num)): + # The origin to atom vector. + vect = array([mol.x[i], mol.y[i], mol.z[i]], float64) - origin + + # Rotation. + rot_vect = dot(R, vect) + + # The new position. + pos = rot_vect + origin + mol.x[i] = pos[0] + mol.y[i] = pos[1] + mol.z[i] = pos[2] + + def write_pdb(self, file, model_num=None): """Method for the creation of a PDB file from the structural data. Modified: 1.3/generic_fns/structure/main.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/structure/main.py?rev=14886&r1=14885&r2=14886&view=diff ============================================================================== --- 1.3/generic_fns/structure/main.py (original) +++ 1.3/generic_fns/structure/main.py Sun Oct 23 18:58:00 2011 @@ -387,6 +387,34 @@ cdp.structure.load_xyz(file_path, read_mol=read_mol, set_mol_name=set_mol_name, read_model=read_model, set_model_num=set_model_num, verbosity=verbosity) +def rotate(R=None, origin=None): + """Rotate the structural data about the origin by the specified forwards rotation. + + @keyword R: The forwards rotation matrix. + @type R: numpy 3D, rank-2 array or a 3x3 list of floats + @keyword origin: The origin of the rotation. If not supplied, the origin will be set to [0, 0, 0]. + @type origin: numpy 3D, rank-1 array or list of len 3 or None + """ + + # Test if the current data pipe exists. + pipes.test() + + # Test if the structure exists. + if not hasattr(cdp, 'structure') or not cdp.structure.num_models() or not cdp.structure.num_molecules(): + raise RelaxNoPdbError + + # Set the origin if not supplied. + if origin == None: + origin = [0, 0, 0] + + # Convert the args to numpy float data structures. + R = array(R, float64) + origin = array(origin, float64) + + # Call the specific code. + cdp.structure.rotate(R=R, origin=origin) + + def set_vector(spin=None, xh_vect=None): """Place the XH unit vector into the spin container object.