mailr22509 - /trunk/lib/structure/internal/object.py


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

Header


Content

Posted by edward on March 19, 2014 - 08:53:
Author: bugman
Date: Wed Mar 19 08:53:20 2014
New Revision: 22509

URL: http://svn.gna.org/viewcvs/relax?rev=22509&view=rev
Log:
Fix for bug #21814 (https://gna.org/bugs/?21814).

This is the PDB reading failure when the PDB records are not padded to 80 
spaces.  The fix is
simple, all PDB records are pre-validated.  This includes removing all 
newline characters and
padding each PDB record to 80 spaces when needed.  This will however add an 
overhead cost -- the
internal PDB reader will now be slower.  However corrupted PDB files, 
produced by MODELLER for
example, not padded to 80 spaces will now be better supported.


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

Modified: trunk/lib/structure/internal/object.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/lib/structure/internal/object.py?rev=22509&r1=22508&r2=22509&view=diff
==============================================================================
--- trunk/lib/structure/internal/object.py      (original)
+++ trunk/lib/structure/internal/object.py      Wed Mar 19 08:53:20 2014
@@ -760,6 +760,31 @@
         # Check the other lengths.
         if len(struct.bonded) != num and len(struct.chain_id) != num and 
len(struct.element) != num and len(struct.pdb_record) != num and 
len(struct.res_name) != num and len(struct.res_num) != num and 
len(struct.seg_id) != num and len(struct.x) != num and len(struct.y) != num 
and len(struct.z) != num:
             raise RelaxError("The structural data is invalid.")
+
+
+    def _validate_records(self, lines):
+        """Make sure all PDB records are 80 char in length, padding with 
whitespace when needed.
+
+        All newline characters are stripped from the records as well.
+
+
+        @param lines:       All lines of the PDB file.
+        @type lines:        list of str
+        @return:            The padded PDB lines.
+        @rtype:             list of str
+        """
+
+        # Loop over the lines.
+        for i in range(len(lines)):
+            # Strip the newline character.
+            lines[i] = lines[i].rstrip('\r\n')
+
+            # Pad if needed.
+            if len(lines[i]) != 80:
+                lines[i] = "%-80s" % lines[i]
+
+        # Return the fixed lines.
+        return lines
 
 
     def _mol_type(self, mol):
@@ -1806,6 +1831,9 @@
         if pdb_lines == []:
             raise RelaxError("The PDB file is empty.")
 
+        # Pre-process the lines, fixing PDB violations.
+        pdb_lines = self._validate_records(pdb_lines)
+
         # Process the different sections.
         pdb_lines = self._parse_pdb_title(pdb_lines)
         pdb_lines = self._parse_pdb_prim_struct(pdb_lines)




Related Messages


Powered by MHonArc, Updated Wed Mar 19 09:00:02 2014