mailr26103 - in /trunk: lib/structure/internal/object.py pipe_control/structure/main.py


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

Header


Content

Posted by edward on September 30, 2014 - 18:08:
Author: bugman
Date: Tue Sep 30 18:08:57 2014
New Revision: 26103

URL: http://svn.gna.org/viewcvs/relax?rev=26103&view=rev
Log:
Implemented the backend of the structure.mean user function.

This primarily occurs within the internal structural object in the new mean() 
method.  The
pipe_control.structure.main.mean() function simply checks if the current data 
pipe is correctly set
up and then calls the structural object mean() method.


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

Modified: trunk/lib/structure/internal/object.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/lib/structure/internal/object.py?rev=26103&r1=26102&r2=26103&view=diff
==============================================================================
--- trunk/lib/structure/internal/object.py      (original)
+++ trunk/lib/structure/internal/object.py      Tue Sep 30 18:08:57 2014
@@ -2100,6 +2100,41 @@
         return True
 
 
+    def mean(self):
+        """Calculate the mean structure from all models in the structural 
data object."""
+
+        # Create a new model for the mean structure.
+        num = self.num_models()
+        self.add_model()
+        mean_model = self.structural_data[-1]
+
+        # The selection object.
+        selection = self.selection()
+
+        # Loop over the molecules and atoms.
+        for mol_index, i in selection.loop():
+            # Set the mean structure coordinate to zero.
+            mean_model.mol[mol_index].x[i] = 0.0
+            mean_model.mol[mol_index].y[i] = 0.0
+            mean_model.mol[mol_index].z[i] = 0.0
+
+            # Loop over the models and sum the coordinates.
+            for model_index in range(num):
+                model_cont = self.structural_data[model_index]
+                mean_model.mol[mol_index].x[i] += 
model_cont.mol[mol_index].x[i]
+                mean_model.mol[mol_index].y[i] += 
model_cont.mol[mol_index].y[i]
+                mean_model.mol[mol_index].z[i] += 
model_cont.mol[mol_index].z[i]
+
+            # Averages.
+            mean_model.mol[mol_index].x[i] /= num
+            mean_model.mol[mol_index].y[i] /= num
+            mean_model.mol[mol_index].z[i] /= num
+
+        # Delete all models but the mean.
+        for model_index in reversed(range(num)):
+            self.delete(model=self.structural_data[model_index].num)
+
+
     def model_loop(self, model=None):
         """Generator method for looping over the models in numerical order.
 

Modified: trunk/pipe_control/structure/main.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/pipe_control/structure/main.py?rev=26103&r1=26102&r2=26103&view=diff
==============================================================================
--- trunk/pipe_control/structure/main.py        (original)
+++ trunk/pipe_control/structure/main.py        Tue Sep 30 18:08:57 2014
@@ -622,8 +622,12 @@
 def mean():
     """Calculate the mean structure from all models in the structural data 
object."""
 
-    # Test if the current data pipe exists.
-    check_pipe()
+    # Checks.
+    check_pipe()
+    check_structure()
+
+    # Call the specific code.
+    cdp.structure.mean()
 
 
 def read_gaussian(file=None, dir=None, set_mol_name=None, 
set_model_num=None, verbosity=1, fail=True):




Related Messages


Powered by MHonArc, Updated Tue Sep 30 18:20:03 2014