mailr11172 - in /1.3/generic_fns/structure: api_base.py internal.py scientific.py


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

Header


Content

Posted by edward on May 03, 2010 - 00:52:
Author: bugman
Date: Mon May  3 00:52:26 2010
New Revision: 11172

URL: http://svn.gna.org/viewcvs/relax?rev=11172&view=rev
Log:
Bug fix for when structural models are loaded out of order.

Now the API generator method model_loop() is being used by the scientific 
python and internal
structural objects.  The bond vectors and atomic positions are now loaded 
into the spin containers
in correct numerical model order.


Modified:
    1.3/generic_fns/structure/api_base.py
    1.3/generic_fns/structure/internal.py
    1.3/generic_fns/structure/scientific.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=11172&r1=11171&r2=11172&view=diff
==============================================================================
--- 1.3/generic_fns/structure/api_base.py (original)
+++ 1.3/generic_fns/structure/api_base.py Mon May  3 00:52:26 2010
@@ -1,6 +1,6 @@
 
###############################################################################
 #                                                                            
 #
-# Copyright (C) 2008-2009 Edward d'Auvergne                                  
 #
+# Copyright (C) 2008-2010 Edward d'Auvergne                                  
 #
 #                                                                            
 #
 # This file is part of the program relax.                                    
 #
 #                                                                            
 #
@@ -276,6 +276,46 @@
         raise RelaxImplementError
 
 
+    def model_loop(self, model=None):
+        """Generator method for looping over the models in numerical order.
+
+        @keyword model: Limit the loop to a single number.
+        @type model:    int
+        @return:        The model structural object.
+        @rtype:         ModelContainer container
+        """
+
+        # A single model.
+        if model:
+            for i in range(len(self.structural_data)):
+                if self.structural_data[i].num == model:
+                    yield self.structural_data[i]
+
+        # All models.
+        else:
+            # The models.
+            model_nums = []
+            for i in range(len(self.structural_data)):
+                if self.structural_data[i].num != None:
+                    model_nums.append(self.structural_data[i].num)
+
+            # Sort.
+            if model_nums:
+                model_nums.sort()
+
+            # Loop over the models in order.
+            for model_num in model_nums:
+                # Find the model.
+                for i in range(len(self.structural_data)):
+                    # Yield the model.
+                    if self.structural_data[i].num == model_num:
+                        yield self.structural_data[i]
+
+            # No models, so just yield the single container.
+            if not model_nums:
+                yield self.structural_data[0]
+
+
     def num_models(self):
         """Method for returning the number of models.
 

Modified: 1.3/generic_fns/structure/internal.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/generic_fns/structure/internal.py?rev=11172&r1=11171&r2=11172&view=diff
==============================================================================
--- 1.3/generic_fns/structure/internal.py (original)
+++ 1.3/generic_fns/structure/internal.py Mon May  3 00:52:26 2010
@@ -1,6 +1,6 @@
 
###############################################################################
 #                                                                            
 #
-# Copyright (C) 2003-2009 Edward d'Auvergne                                  
 #
+# Copyright (C) 2003-2010 Edward d'Auvergne                                  
 #
 #                                                                            
 #
 # This file is part of the program relax.                                    
 #
 #                                                                            
 #
@@ -430,10 +430,8 @@
         # Generate the selection object.
         sel_obj = Selection(atom_id)
 
-        # Loop over the models.
-        for model_index in range(len(self.structural_data)):
-            model = self.structural_data[model_index]
-
+        # Model loop.
+        for model in self.model_loop():
             # Loop over the molecules.
             for mol_index in range(len(model.mol)):
                 mol = model.mol[mol_index]
@@ -459,9 +457,9 @@
                     # The atom position.
                     if ave:
                         # Loop over the models.
-                        for model_index2 in range(len(self.structural_data)):
+                        for model in self.model_loop():
                             # Alias.
-                            mol = 
self.structural_data[model_index2].mol[mol_index]
+                            mol = model.mol[mol_index]
 
                             # Some sanity checks.
                             if mol.atom_num[i] != atom_num:
@@ -539,11 +537,7 @@
         warnings = None
 
         # Loop over the models.
-        for model in self.structural_data:
-            # Single model.
-            if model_num and model_num != model.num:
-                continue
-
+        for model in self.model_loop(model_num):
             # Loop over the molecules.
             for mol in model.mol:
                 # Skip non-matching molecules.
@@ -760,7 +754,7 @@
 
         # Determine if model records will be created.
         model_records = False
-        for model in self.structural_data:
+        for model in self.model_loop():
             if hasattr(model, 'num') and model.num != None:
                 model_records = True
 
@@ -912,11 +906,7 @@
         ######################
 
         # Loop over the models.
-        for model in self.structural_data:
-            # Single model.
-            if model_num and model_num != model.num:
-                continue
-
+        for model in self.model_loop(model_num):
             # MODEL record, for multiple models.
             ####################################
 

Modified: 1.3/generic_fns/structure/scientific.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/generic_fns/structure/scientific.py?rev=11172&r1=11171&r2=11172&view=diff
==============================================================================
--- 1.3/generic_fns/structure/scientific.py (original)
+++ 1.3/generic_fns/structure/scientific.py Mon May  3 00:52:26 2010
@@ -1,6 +1,6 @@
 
###############################################################################
 #                                                                            
 #
-# Copyright (C) 2003-2009 Edward d'Auvergne                                  
 #
+# Copyright (C) 2003-2010 Edward d'Auvergne                                  
 #
 #                                                                            
 #
 # This file is part of the program relax.                                    
 #
 #                                                                            
 #
@@ -198,10 +198,8 @@
         # Generate the selection object.
         sel_obj = Selection(atom_id)
 
-        # Loop over the models.
-        for model_index in range(len(self.structural_data)):
-            model = self.structural_data[model_index]
-
+        # Model loop.
+        for model in self.model_loop():
             # Loop over the molecules.
             for mol_index in range(len(model.mol)):
                 mol = model.mol[mol_index]
@@ -304,13 +302,9 @@
         pos_array = []
 
         # Loop over the models.
-        for model in self.structural_data:
+        for model in self.model_loop(model):
             # Init.
             atom_found = False
-
-            # Skip non-matching models.
-            if model != None and model != model.num:
-                continue
 
             # Loop over each individual molecule.
             for mol in model.mol:
@@ -364,7 +358,7 @@
         pos = zeros(3, float64)
 
         # Loop over the models.
-        for model in self.structural_data:
+        for model in self.model_loop():
             # The exact molecule.
             mol = model.mol[mol_index]
 
@@ -424,11 +418,7 @@
         warnings = None
 
         # Loop over the models.
-        for model in self.structural_data:
-            # Single model.
-            if model_num and model_num != model.num:
-                continue
-
+        for model in self.model_loop(model_num):
             # Init.
             atom_found = False
 




Related Messages


Powered by MHonArc, Updated Mon May 03 01:00:03 2010