mailr25977 - in /trunk: lib/structure/internal/object.py pipe_control/structure/main.py specific_analyses/frame_order/uf.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on September 23, 2014 - 18:43:
Author: bugman
Date: Tue Sep 23 18:43:56 2014
New Revision: 25977

URL: http://svn.gna.org/viewcvs/relax?rev=25977&view=rev
Log:
Converted the rotate() and translate() structural object methods to use the 
new selection object.

The atom_id arguments have been replaced with selection arguments.  Therefore 
all parts of relax
which call these methods must first call selection() to obtain the 
Internal_selection instance.


Modified:
    trunk/lib/structure/internal/object.py
    trunk/pipe_control/structure/main.py
    trunk/specific_analyses/frame_order/uf.py

Modified: trunk/lib/structure/internal/object.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/lib/structure/internal/object.py?rev=25977&r1=25976&r2=25977&view=diff
==============================================================================
--- trunk/lib/structure/internal/object.py      (original)
+++ trunk/lib/structure/internal/object.py      Tue Sep 23 18:43:56 2014
@@ -2278,7 +2278,7 @@
                 mol.file_model = orig_model_num[i]
 
 
-    def rotate(self, R=None, origin=None, model=None, atom_id=None):
+    def rotate(self, R=None, origin=None, model=None, selection=None):
         """Rotate the structural information about the given origin.
 
         @keyword R:         The forwards rotation matrix.
@@ -2287,40 +2287,27 @@
         @type origin:       numpy 3D, rank-1 array
         @keyword model:     The model to rotate.  If None, all models will 
be rotated.
         @type model:        int
-        @keyword atom_id:   The molecule, residue, and atom identifier 
string.  Only atoms matching this selection will be used.
-        @type atom_id:      str or None
-        """
-
-        # Generate the selection object.
-        sel_obj = None
-        if atom_id:
-            sel_obj = Selection(atom_id)
+        @keyword selection: The internal structural selection object.  This 
is obtained by calling the selection() method with the atom ID string.
+        @type selection:    lib.structure.internal.Internal_selection 
instance
+        """
 
         # Loop over the models.
         for model_cont in self.model_loop(model):
-            # Loop over the molecules.
-            for mol in model_cont.mol:
-                # Skip non-matching molecules.
-                if sel_obj and not sel_obj.contains_mol(mol.mol_name):
-                    continue
-
-                # Loop over the atoms.
-                for i in range(len(mol.atom_num)):
-                    # Skip non-matching atoms.
-                    if sel_obj and not 
sel_obj.contains_spin(mol.atom_num[i], mol.atom_name[i], mol.res_num[i], 
mol.res_name[i], mol.mol_name):
-                        continue
-
-                    # 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]
+            # Loop over all molecules and atoms in the selection.
+            for mol_index, i in selection.loop():
+                mol = model_cont.mol[mol_index]
+
+                # 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 selection(self, atom_id=None):
@@ -2353,7 +2340,7 @@
             # Skip non-matching molecules.
             if sel_obj and not sel_obj.contains_mol(mol.mol_name):
                 continue
-            
+
             # Add the molecule index.
             selection.add_mol(mol_index=mol_index)
 
@@ -2422,40 +2409,27 @@
             target.append(file_root(file) + '_mol' + repr(mol_num))
 
 
-    def translate(self, T=None, model=None, atom_id=None):
+    def translate(self, T=None, model=None, selection=None):
         """Displace the structural information by the given translation 
vector.
 
         @keyword T:         The translation vector.
         @type T:            numpy 3D, rank-1 array
         @keyword model:     The model to rotate.  If None, all models will 
be rotated.
         @type model:        int
-        @keyword atom_id:   The molecule, residue, and atom identifier 
string.  Only atoms matching this selection will be used.
-        @type atom_id:      str or None
-        """
-
-        # Generate the selection object.
-        sel_obj = None
-        if atom_id:
-            sel_obj = Selection(atom_id)
+        @keyword selection: The internal structural selection object.  This 
is obtained by calling the selection() method with the atom ID string.
+        @type selection:    lib.structure.internal.Internal_selection 
instance
+        """
 
         # Loop over the models.
         for model_cont in self.model_loop(model):
-            # Loop over the molecules.
-            for mol in model_cont.mol:
-                # Skip non-matching molecules.
-                if sel_obj and not sel_obj.contains_mol(mol.mol_name):
-                    continue
-
-                # Loop over the atoms.
-                for i in range(len(mol.atom_num)):
-                    # Skip non-matching atoms.
-                    if sel_obj and not 
sel_obj.contains_spin(mol.atom_num[i], mol.atom_name[i], mol.res_num[i], 
mol.res_name[i], mol.mol_name):
-                        continue
-
-                    # Translate.
-                    mol.x[i] = mol.x[i] + T[0]
-                    mol.y[i] = mol.y[i] + T[1]
-                    mol.z[i] = mol.z[i] + T[2]
+            # Loop over all molecules and atoms in the selection.
+            for mol_index, i in selection.loop():
+                mol = model_cont.mol[mol_index]
+
+                # Translate.
+                mol.x[i] = mol.x[i] + T[0]
+                mol.y[i] = mol.y[i] + T[1]
+                mol.z[i] = mol.z[i] + T[2]
 
 
     def to_xml(self, doc, element):

Modified: trunk/pipe_control/structure/main.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/pipe_control/structure/main.py?rev=25977&r1=25976&r2=25977&view=diff
==============================================================================
--- trunk/pipe_control/structure/main.py        (original)
+++ trunk/pipe_control/structure/main.py        Tue Sep 23 18:43:56 2014
@@ -818,7 +818,8 @@
     origin = array(origin, float64)
 
     # Call the specific code.
-    cdp.structure.rotate(R=R, origin=origin, model=model, atom_id=atom_id)
+    selection = cdp.structure.selection(atom_id=atom_id)
+    cdp.structure.rotate(R=R, origin=origin, model=model, 
selection=selection)
 
 
 def set_vector(spin=None, xh_vect=None):
@@ -922,7 +923,8 @@
     T = array(T, float64)
 
     # Call the specific code.
-    cdp.structure.translate(T=T, model=model, atom_id=atom_id)
+    selection = cdp.structure.selection(atom_id=atom_id)
+    cdp.structure.translate(T=T, model=model, selection=selection)
 
 
 def vectors(spin_id1=None, spin_id2=None, model=None, verbosity=1, ave=True, 
unit=True):

Modified: trunk/specific_analyses/frame_order/uf.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/specific_analyses/frame_order/uf.py?rev=25977&r1=25976&r2=25977&view=diff
==============================================================================
--- trunk/specific_analyses/frame_order/uf.py   (original)
+++ trunk/specific_analyses/frame_order/uf.py   Tue Sep 23 18:43:56 2014
@@ -99,6 +99,9 @@
     # Make a copy of the structural object (so as to preserve the original 
structure).
     structure = deepcopy(cdp.structure)
 
+    # The internal structural selection object.
+    selection = structure.selection(atom_id=domain_moving())
+
     # First rotate the moving domain to the average position.
     R = zeros((3, 3), float64)
     if hasattr(cdp, 'ave_pos_alpha'):
@@ -109,11 +112,11 @@
         origin = pipe_centre_of_mass(atom_id=domain_moving(), verbosity=0)
     else:
         origin = array([cdp.pivot_x, cdp.pivot_y, cdp.pivot_z])
-    structure.rotate(R=R, origin=origin, atom_id=domain_moving())
+    structure.rotate(R=R, origin=origin, selection=selection)
 
     # Then translate the moving domain.
     if not translation_fixed():
-        structure.translate(T=[cdp.ave_pos_x, cdp.ave_pos_y, cdp.ave_pos_z], 
atom_id=domain_moving())
+        structure.translate(T=[cdp.ave_pos_x, cdp.ave_pos_y, cdp.ave_pos_z], 
selection=selection)
 
     # Write out the PDB file.
     file = open_write_file(file_name=file, dir=dir, force=force)




Related Messages


Powered by MHonArc, Updated Tue Sep 23 19:00:04 2014