mailr27059 - in /trunk: pipe_control/structure/main.py user_functions/structure.py


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

Header


Content

Posted by edward on December 10, 2014 - 17:03:
Author: bugman
Date: Wed Dec 10 17:03:24 2014
New Revision: 27059

URL: http://svn.gna.org/viewcvs/relax?rev=27059&view=rev
Log:
Implemented the new molecules argument for the structure.rmsd user function.

This allows the RMSD between different molecules rather than different models 
to be calculated,
extending the functionality of this user function.


Modified:
    trunk/pipe_control/structure/main.py
    trunk/user_functions/structure.py

Modified: trunk/pipe_control/structure/main.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/pipe_control/structure/main.py?rev=27059&r1=27058&r2=27059&view=diff
==============================================================================
--- trunk/pipe_control/structure/main.py        (original)
+++ trunk/pipe_control/structure/main.py        Wed Dec 10 17:03:24 2014
@@ -1108,13 +1108,15 @@
     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 rmsd(atom_id=None, models=None):
+def rmsd(atom_id=None, models=None, molecules=None):
     """Calculate the RMSD between the loaded models.
 
     @keyword atom_id:   The molecule, residue, and atom identifier string.  
Only atoms matching this selection will be used.
     @type atom_id:      str or None
-    @keyword models:    The list of models to calculate the RMDS of.  If set 
to None, then all models will be used.
+    @keyword models:    The list of models to calculate the RMSD of.  If set 
to None, then all models will be used.
     @type models:       list of int or None
+    @keyword molecules: The list of molecules to calculate the RMSD between. 
 This overrides the models.
+    @type molecules:    None or list of str
     @return:            The RMSD value.
     @rtype:             float
     """
@@ -1122,22 +1124,53 @@
     # Test if the current data pipe exists.
     check_pipe()
 
-    # Create a list of all models.
-    if models == None:
-        models = []
-        for model in cdp.structure.model_loop():
-            models.append(model.num)
-
     # The selection object.
     selection = cdp.structure.selection(atom_id=atom_id)
 
-    # Assemble the atomic coordinates of all models.
-    coord = []
-    for model in models:
-        coord.append([])
-        for pos in cdp.structure.atom_loop(selection=selection, 
model_num=model, pos_flag=True):
+    # RMSD between models.
+    if molecules == None:
+        # Create a list of all models.
+        if models == None:
+            models = []
+            for model in cdp.structure.model_loop():
+                models.append(model.num)
+
+        # Assemble the atomic coordinates of all models.
+        coord = []
+        for model in models:
+            coord.append([])
+            for pos in cdp.structure.atom_loop(selection=selection, 
model_num=model, pos_flag=True):
+                coord[-1].append(pos[0])
+            coord[-1] = array(coord[-1])
+
+    # RMSD between structures.
+    else:
+        # No models allowed.
+        if cdp.structure.num_models() > 1:
+            raise RelaxError("When calculating the RMSD between different 
molecules, no models are allowed to be present.")
+
+        # Assemble the atomic coordinates of all molecules.
+        coord = []
+        current_mol = ''
+        for mol_name, pos in cdp.structure.atom_loop(selection=selection, 
mol_name_flag=True, pos_flag=True):
+            # No molecule match, so skip.
+            if mol_name not in molecules:
+                continue
+
+            # A new molecule.
+            if mol_name != current_mol:
+                # Change the current molecule name.
+                current_mol = mol_name
+
+                # Extend the coordinates.
+                coord.append([])
+
+            # Append the coordinate.
             coord[-1].append(pos[0])
-        coord[-1] = array(coord[-1])
+
+        # Numpy conversion.
+        for i in range(len(coord)):
+            coord[i] = array(coord[i])
 
     # Calculate the RMSD.
     cdp.structure.rmsd = atomic_rmsd(coord, verbosity=1)

Modified: trunk/user_functions/structure.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/user_functions/structure.py?rev=27059&r1=27058&r2=27059&view=diff
==============================================================================
--- trunk/user_functions/structure.py   (original)
+++ trunk/user_functions/structure.py   Wed Dec 10 17:03:24 2014
@@ -1041,17 +1041,25 @@
     desc = "The atom identification string.",
     can_be_none = True
 )
+uf.add_keyarg(
+    name = "molecules",
+    py_type = "str_list",
+    desc_short = "molecule list",
+    desc = "The optional molecule list to perform the RMSD calculation on 
rather than the models.  The RMSD will only be calculated for atoms with 
identical residue name and number and atom name.",
+    can_be_none = True
+)
 # Description.
 uf.desc.append(Desc_container())
 uf.desc[-1].add_paragraph("This allows the root mean squared deviation 
(RMSD) between all models to be calculated.")
 uf.desc[-1].add_paragraph("The atom ID, which uses the same notation as the 
spin ID strings, can be used to restrict the RMSD calculation to certain 
molecules, residues, or atoms.")
+uf.desc[-1].add_paragraph("If the optional molecules list is supplied, then 
the RMSD calculation will be between the molecules in the list rather than 
the models.  Therefore no models are allowed to be present in the current 
data pipe.")
 # Prompt examples.
 uf.desc.append(Desc_container("Prompt examples"))
 uf.desc[-1].add_paragraph("To determine the RMSD, simply type:")
 uf.desc[-1].add_prompt("relax> structure.rmsd()")
 uf.backend = pipe_control.structure.main.rmsd
 uf.menu_text = "&rmsd"
-uf.wizard_size = (700, 500)
+uf.wizard_size = (800, 600)
 uf.wizard_image = WIZARD_IMAGE_PATH + 'structure' + sep + '2JK4.png'
 
 




Related Messages


Powered by MHonArc, Updated Wed Dec 10 17:20:02 2014