mailr22049 - in /trunk/lib/structure/internal: models.py object.py


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

Header


Content

Posted by edward on January 27, 2014 - 18:54:
Author: bugman
Date: Mon Jan 27 18:54:08 2014
New Revision: 22049

URL: http://svn.gna.org/viewcvs/relax?rev=22049&view=rev
Log:
Large speed up for the internal structural object for when many models are 
present.

The new ModelList.current_models object keeps track of all the models already 
present in the
structural object.  This simplifies the checks of the pack_structs() internal 
structural object
method by removing expensive looping.  This allows the loading of PDB files 
to continue to be fast
even with many tens or hundreds of thousands of models already loaded.


Modified:
    trunk/lib/structure/internal/models.py
    trunk/lib/structure/internal/object.py

Modified: trunk/lib/structure/internal/models.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/lib/structure/internal/models.py?rev=22049&r1=22048&r2=22049&view=diff
==============================================================================
--- trunk/lib/structure/internal/models.py (original)
+++ trunk/lib/structure/internal/models.py Mon Jan 27 18:54:08 2014
@@ -1,6 +1,6 @@
-###############################################################################
-#                                                                            
 #
-# Copyright (C) 2008-2013 Edward d'Auvergne                                  
 #
+0##############################################################################
+#                                                                            
 #
+# Copyright (C) 2008-2014 Edward d'Auvergne                                  
 #
 #                                                                            
 #
 # This file is part of the program relax (http://www.nmr-relax.com).         
 #
 #                                                                            
 #
@@ -36,6 +36,16 @@
 
     Here different models are defined as the same molecule but with 
different conformations.
     """
+
+    def __init__(self):
+        """Set up the class."""
+
+        # Execute the base class method.
+        super(ModelList, self).__init__()
+
+        # The current model list (used for speed).
+        self.current_models = []
+
 
     def __repr__(self):
         """The string representation of the object.
@@ -71,6 +81,9 @@
 
             # Append an empty ModelContainer.
             self.append(ModelContainer(model_num))
+
+        # Update the current model list.
+        self.current_models.append(model_num)
 
         # Store the model indices.
         if not hasattr(self, 'model_indices'):

Modified: trunk/lib/structure/internal/object.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/lib/structure/internal/object.py?rev=22049&r1=22048&r2=22049&view=diff
==============================================================================
--- trunk/lib/structure/internal/object.py (original)
+++ trunk/lib/structure/internal/object.py Mon Jan 27 18:54:08 2014
@@ -2107,32 +2107,34 @@
             raise RelaxError("Failure of the mapping of new molecule names, 
%s new molecule names verses %s molecules in the structural data." % 
(len(set_mol_name), len(data_matrix[0])))
 
         # Test that the target models and structures are absent, and get the 
already existing model numbers.
-        current_models = []
-        for i in range(len(self.structural_data)):
-            # Create a list of current models.
-            current_models.append(self.structural_data[i].num)
+        for i in range(len(set_model_num)):
+            # Merging flag is set, so skip the checks.
+            if merge:
+                continue
+
+            # A new model, so no need to check.
+            if not set_model_num[i] in self.structural_data.current_models:
+                continue
 
             # Loop over the structures.
-            for j in range(len(self.structural_data[i].mol)):
-                if not merge and self.structural_data[i].num in 
set_model_num and self.structural_data[i].mol[j].mol_name in set_mol_name:
+            index = 
self.structural_data.current_models.index(set_model_num[i])
+            for j in range(len(self.structural_data[index].mol)):
+                if self.structural_data[index].mol[j].mol_name in 
set_mol_name:
                     raise RelaxError("The molecule '%s' of model %s already 
exists." % (self.structural_data[i].mol[j].mol_name, 
self.structural_data[i].num))
 
         # Loop over the models.
         for i in range(len(set_model_num)):
             # The model doesn't currently exist.
-            if set_model_num[i] not in current_models:
+            if set_model_num[i] not in self.structural_data.current_models:
                 # Create the model.
                 self.structural_data.add_item(set_model_num[i])
 
-                # Add the model number to the current_models list.
-                current_models.append(set_model_num[i])
-
                 # Get the model.
                 model = self.structural_data[-1]
 
             # Otherwise get the pre-existing model.
             else:
-                model = 
self.structural_data[current_models.index(set_model_num[i])]
+                model = 
self.structural_data[self.structural_data.current_models.index(set_model_num[i])]
 
             # Loop over the molecules.
             for j in range(len(set_mol_name)):




Related Messages


Powered by MHonArc, Updated Mon Jan 27 19:00:01 2014