mailr24422 - 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 July 03, 2014 - 11:35:
Author: bugman
Date: Thu Jul  3 11:35:50 2014
New Revision: 24422

URL: http://svn.gna.org/viewcvs/relax?rev=24422&view=rev
Log:
Improved model handling for the internal structural object.

The set_model() method has been added to allow either a model number to be 
set to the first
unnumbered model (in preparation for adding new models) or to allow models to 
be renumbered.
The logic of the add_model() has also been changed.  Rather than looping over 
all atoms of the first
model and copying them, which does not work due to the model validity checks, 
the entire MolList
(molecule list) data structure is copied using copy.deepcopy() to make a 
perfect copy of the
structural data.

The ModelList.add_item() method has also been modified to return the newly 
added or numbered model.
This is used by the add_model() structural object method to obtain the model 
object.


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=24422&r1=24421&r2=24422&view=diff
==============================================================================
--- trunk/lib/structure/internal/models.py      (original)
+++ trunk/lib/structure/internal/models.py      Thu Jul  3 11:35:50 2014
@@ -66,6 +66,8 @@
 
         @keyword model_num: The model number.
         @type model_num:    int
+        @return:            The model container.
+        @rtype:             ModelContainer instance
         """
 
         # If no model data exists, replace the empty first model with this 
model (just a renumbering).
@@ -83,6 +85,9 @@
 
         # Update the current model list.
         self.current_models.append(model_num)
+
+        # Return the model container.
+        return self[-1]
 
 
     def is_empty(self):

Modified: trunk/lib/structure/internal/object.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/lib/structure/internal/object.py?rev=24422&r1=24421&r2=24422&view=diff
==============================================================================
--- trunk/lib/structure/internal/object.py      (original)
+++ trunk/lib/structure/internal/object.py      Thu Jul  3 11:35:50 2014
@@ -1108,7 +1108,7 @@
     def add_model(self, model=None, coords_from=None):
         """Add a new model to the store.
 
-        The new model will be constructured with the structural information 
from the other models currently present.  The coords_from argument allows the 
atomic positions to be taken from a certain model.  If this argument is not 
set, then the atomic positions from the first model will be used.
+        The new model will be constructed with the structural information 
from the other models currently present.  The coords_from argument allows the 
atomic positions to be taken from a certain model.  If this argument is not 
set, then the atomic positions from the first model will be used.
 
         @keyword model:         The number of the model to create.
         @type model:            int or None
@@ -1125,16 +1125,19 @@
                     raise RelaxError("The model '%s' already exists." % 
model)
 
         # Add a new model.
-        self.structural_data.add_item(model_num=model)
+        model = self.structural_data.add_item(model_num=model)
 
         # The model to duplicate.
         if coords_from == None:
-            coords_from = self.structural_data[0].num
-
-        # Construct the structural data for the model from the other models.
-        for mol_name, res_num, res_name, atom_num, atom_name, element, pos 
in self.atom_loop(model_num=coords_from, mol_name_flag=True, 
res_num_flag=True, res_name_flag=True, atom_num_flag=True, 
atom_name_flag=True, element_flag=True, pos_flag=True):
-            # Add the atom.
-            self.add_atom(mol_name=mol_name, atom_name=atom_name, 
res_name=res_name, res_num=res_num, pos=pos, element=element, 
atom_num=atom_num)
+            model_from = self.structural_data[0]
+        else:
+            for i in range(len(self.structural_data)):
+                if self.structural_data[i].num == coords_from:
+                    model_from = self.structural_data[i]
+                    break
+
+        # Duplicate all data from the MolList object down.
+        model.mol = deepcopy(model_from.mol)
 
         # Return the model.
         return self.structural_data[-1]
@@ -2281,6 +2284,35 @@
                     mol.z[i] = pos[2]
 
 
+    def set_model(self, model_orig=None, model_new=None):
+        """Set or reset the model number.
+        @keyword model_orig:    The original model number.  Leave as None if 
no models are currently present.
+        @type model_orig:       None or int
+        @keyword model_new:     The new model number to set the model to.
+        @type model_new:        int
+        """
+
+        # Check.
+        if model_orig == None and self.num_models() != 1:
+            raise RelaxError("If the original model number is not supplied, 
only one model in the current structural object is allowed, but %s were 
found." % self.num_models())
+
+        # Set the single model number.
+        if model_orig == None:
+            self.structural_data[0].num = model_new
+            return
+
+        # Find the model and set the number.
+        set = False
+        for i in range(len(self.structural_data)):
+            if model_orig == self.structural_data[i].num:
+                self.structural_data[i].num = model_new
+                set = True
+
+        # Sanity check.
+        if not set:
+            raise RelaxError("The original model number %s could not be 
found in the structural object." % model_orig)
+
+
     def target_mol_name(self, set=None, target=None, index=None, 
mol_num=None, file=None):
         """Add the new molecule name to the target data structure.
 




Related Messages


Powered by MHonArc, Updated Thu Jul 03 12:00:02 2014