mailr28095 - in /trunk/lib/structure/internal: 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 November 25, 2015 - 18:09:
Author: bugman
Date: Wed Nov 25 18:09:01 2015
New Revision: 28095

URL: http://svn.gna.org/viewcvs/relax?rev=28095&view=rev
Log:
Modified the internal structural object to be less influenced by the format 
of the PDB.

The PDB serial number is now intelligently handled, in that it is reset to 1 
when a new model is
created.  This information is still kept for supporting the logic of the 
reading of the CONECT
records, and will be eliminated in the future.

The chain ID information is now no longer stored in the internal structural 
object, as this
information is recreated by the structure.write_pdb user function based on 
how the internal
structural object has been created.

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

Modified: trunk/lib/structure/internal/molecules.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/lib/structure/internal/molecules.py?rev=28095&r1=28094&r2=28095&view=diff
==============================================================================
--- trunk/lib/structure/internal/molecules.py   (original)
+++ trunk/lib/structure/internal/molecules.py   Wed Nov 25 18:09:01 2015
@@ -384,18 +384,21 @@
             self.atom_add(atom_name=atom_name, atom_num=atom_number, pos=[x, 
y, z], element=atom_name)
 
 
-    def fill_object_from_pdb(self, records, alt_loc_select=None):
+    def fill_object_from_pdb(self, records, alt_loc_select=None, 
reset_serial=True):
         """Method for generating a complete Structure_container object from 
the given PDB records.
 
         @param records:             A list of structural PDB records.
         @type records:              list of str
         @keyword alt_loc_select:    The PDB ATOM record 'Alternate location 
indicator' field value to select which coordinates to use.
         @type alt_loc_select:       str or None
+        @keyword reset_serial:      A flag which if True will cause the 
first serial number (or atom number) to be reset to 1, and all other numbers 
shifted.
+        @type reset_serial:         bool
         """
 
         # Loop over the records.
         water = []
         missing_connect = []
+        number_offset = None
         for record in records:
             # Nothing to do.
             if not record or record == '\n':
@@ -409,6 +412,15 @@
                 if record[:6] == 'HETATM':
                     record_type, serial, name, alt_loc, res_name, chain_id, 
res_seq, icode, x, y, z, occupancy, temp_factor, element, charge = 
pdb_read.hetatm(record)
 
+                # The serial number.
+                if reset_serial:
+                    # The first number.
+                    if number_offset == None:
+                        number_offset = serial - 1
+
+                    # Reset.
+                    serial -= number_offset
+
                 # Skip waters.
                 if res_name == 'HOH':
                     water.append(res_seq)
@@ -429,12 +441,23 @@
                     element = self._det_pdb_element(name)
 
                 # Add.
-                self.atom_add(pdb_record=record_type, atom_num=serial, 
atom_name=name, res_name=res_name, chain_id=chain_id, res_num=res_seq, 
pos=[x, y, z], element=element)
+                self.atom_add(pdb_record=record_type, atom_num=serial, 
atom_name=name, res_name=res_name, res_num=res_seq, pos=[x, y, z], 
element=element)
 
             # Connect atoms.
             if record[:6] == 'CONECT':
                 # Parse the record.
                 record_type, serial, bonded1, bonded2, bonded3, bonded4 = 
pdb_read.conect(record)
+
+                # Reset the serial numbers.
+                if reset_serial:
+                    serial -= number_offset
+                    bonded1 -= number_offset
+                    if bonded2 != None:
+                        bonded2 -= number_offset
+                    if bonded3 != None:
+                        bonded3 -= number_offset
+                    if bonded4 != None:
+                        bonded4 -= number_offset
 
                 # Loop over the atoms of the record.
                 for bonded in [bonded1, bonded2, bonded3, bonded4]:

Modified: trunk/lib/structure/internal/object.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/lib/structure/internal/object.py?rev=28095&r1=28094&r2=28095&view=diff
==============================================================================
--- trunk/lib/structure/internal/object.py      (original)
+++ trunk/lib/structure/internal/object.py      Wed Nov 25 18:09:01 2015
@@ -2080,6 +2080,7 @@
             orig_mol_num.append([])
             mol_index = 0
             new_mol_name = []
+            reset_serial = True
             for mol_num, mol_records in self._parse_mols_pdb(model_records):
                 # Only load the desired model.
                 if read_mol and mol_num not in read_mol:
@@ -2109,7 +2110,7 @@
                 mol = MolContainer()
 
                 # Fill the molecular data object.
-                mol.fill_object_from_pdb(mol_records, alt_loc_select=alt_loc)
+                mol.fill_object_from_pdb(mol_records, 
alt_loc_select=alt_loc, reset_serial=reset_serial)
 
                 # Store the molecule container.
                 mol_conts[model_index].append(mol)
@@ -2119,6 +2120,9 @@
 
                 # Increment the molecule index.
                 mol_index = mol_index + 1
+
+                # No longer reset the serial number to 1.
+                reset_serial = False
 
             # Increment the model index.
             model_index = model_index + 1




Related Messages


Powered by MHonArc, Updated Wed Nov 25 18:20:21 2015