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


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

Header


Content

Posted by edward on October 23, 2014 - 14:45:
Author: bugman
Date: Thu Oct 23 14:45:25 2014
New Revision: 26381

URL: http://svn.gna.org/viewcvs/relax?rev=26381&view=rev
Log:
The structure.write_pdb user function can now handle empty molecules.

This fixes bug #22861 (https://gna.org/bugs/?22861), the chain IDs in the 
structure.write_pdb user
function PDB files are incorrect after calling structure.delete.

To handle this consistently, the internal structural object 
ModelContainer.mol_loop() generator
method has been created.  This loops over the molecules, yielding those that 
are not empty.  The
MolContainer.is_empty() method has been fixed by not checking for the 
molecule name, as that remains
after the structure.delete user function call while all other information has 
been removed.  And
finally the write_pdb() structural object method has been modified to use the 
mol_loop() method
rather than performing the loop itself.


Modified:
    trunk/lib/structure/internal/models.py
    trunk/lib/structure/internal/molecules.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=26381&r1=26380&r2=26381&view=diff
==============================================================================
--- trunk/lib/structure/internal/models.py      (original)
+++ trunk/lib/structure/internal/models.py      Thu Oct 23 14:45:25 2014
@@ -263,3 +263,20 @@
 
         # The ModelContainer is unmodified.
         return True
+
+
+    def mol_loop(self):
+        """Generator method to loop over the molecules of this model.
+
+        @return:    The molecules of this model.
+        @rtype:     MolContainer instance
+        """
+
+        # Loop over all molecules.
+        for mol in self.mol:
+            # No data, so do not yield the molecule.
+            if mol.is_empty():
+                continue
+
+            # Yield the molecule.
+            yield mol

Modified: trunk/lib/structure/internal/molecules.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/lib/structure/internal/molecules.py?rev=26381&r1=26380&r2=26381&view=diff
==============================================================================
--- trunk/lib/structure/internal/molecules.py   (original)
+++ trunk/lib/structure/internal/molecules.py   Thu Oct 23 14:45:25 2014
@@ -453,7 +453,6 @@
         """Check if the container is empty."""
 
         # Set attributes.
-        if hasattr(self, 'mol_name'): return False
         if hasattr(self, 'file_name'): return False
         if hasattr(self, 'file_path'): return False
         if hasattr(self, 'file_mol_num'): return False

Modified: trunk/lib/structure/internal/object.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/lib/structure/internal/object.py?rev=26381&r1=26380&r2=26381&view=diff
==============================================================================
--- trunk/lib/structure/internal/object.py      (original)
+++ trunk/lib/structure/internal/object.py      Thu Oct 23 14:45:25 2014
@@ -2625,7 +2625,7 @@
 
         # Loop over the molecules of the first model.
         index = 0
-        for mol in self.structural_data[0].mol:
+        for mol in self.structural_data[0].mol_loop():
             # Check the validity of the data.
             self._validate_data_arrays(mol)
 
@@ -2813,7 +2813,7 @@
             # Loop over the molecules.
             index = 0
             atom_serial = 0
-            for mol in model.mol:
+            for mol in model.mol_loop():
                 # Print out.
                 print("ATOM, HETATM, TER")
 
@@ -2894,7 +2894,7 @@
         # The per molecule incremented atom counts.
         atom_counts = [0]
         index = 0
-        for mol in self.structural_data[0].mol:
+        for mol in self.structural_data[0].mol_loop():
             if index == 0:
                 atom_counts.append(len(mol.atom_name))
             else:
@@ -2903,7 +2903,7 @@
 
         # Loop over the molecules of the first model.
         index = 0
-        for mol in self.structural_data[0].mol:
+        for mol in self.structural_data[0].mol_loop():
             # Loop over the atoms.
             for i in range(len(mol.atom_name)):
                 # No bonded atoms, hence no CONECT record is required.




Related Messages


Powered by MHonArc, Updated Thu Oct 23 15:00:03 2014