mailr8620 - /branches/multi_structure/generic_fns/structure/scientific.py


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

Header


Content

Posted by edward on January 22, 2009 - 18:34:
Author: bugman
Date: Thu Jan 22 18:34:54 2009
New Revision: 8620

URL: http://svn.gna.org/viewcvs/relax?rev=8620&view=rev
Log:
Created the MolContainer.reload_pdb() method to be used by from_xml().


Modified:
    branches/multi_structure/generic_fns/structure/scientific.py

Modified: branches/multi_structure/generic_fns/structure/scientific.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/multi_structure/generic_fns/structure/scientific.py?rev=8620&r1=8619&r2=8620&view=diff
==============================================================================
--- branches/multi_structure/generic_fns/structure/scientific.py (original)
+++ branches/multi_structure/generic_fns/structure/scientific.py Thu Jan 22 
18:34:54 2009
@@ -30,7 +30,7 @@
 from math import sqrt
 from numpy import array, dot, float64, zeros
 import os
-from os import F_OK, access
+from os import F_OK, access, sep
 if dep_check.scientific_pdb_module:
     import Scientific.IO.PDB
 from warnings import warn
@@ -41,7 +41,7 @@
 from generic_fns import pipes, relax_re
 from generic_fns.mol_res_spin import Selection, parse_token, tokenise
 from relax_errors import RelaxError, RelaxPdbLoadError
-from relax_warnings import RelaxWarning, RelaxNoAtomWarning, 
RelaxZeroVectorWarning
+from relax_warnings import RelaxWarning, RelaxNoAtomWarning, 
RelaxNoPDBFileWarning, RelaxZeroVectorWarning
 
 
 class Scientific_data(Base_struct_API):
@@ -623,6 +623,64 @@
         # Recreate the current molecule container.
         xml_to_object(mol_node, self)
 
+        # Re-load the data.
+        self.reload_pdb()
+
+
+    def reload_pdb(self):
+        """Reload the PDB from the original file."""
+
+        # The file path.
+        if self.file_path:
+            file_path = self.file_path + sep + self.file_name
+        else:
+            file_path = self.file_name
+
+        # Test if the file exists.
+        if not access(file_path, F_OK):
+            warn(RelaxNoPDBFileWarning(file_path))
+            return
+
+        # Load the PDB file.
+        model = Scientific.IO.PDB.Structure(file_path, self.file_model)
+
+        # Index for finding the molecule.
+        mol_index = 0
+
+        # First add the peptide chains.
+        if hasattr(model, 'peptide_chains'):
+            for mol in model.peptide_chains:
+                # Pack if the molecule index matches.
+                if mol_index == self.file_mol_num:
+                    self.data = mol
+                    return
+
+                mol_index = mol_index + 1
+
+        # Then the nucleotide chains.
+        if hasattr(model, 'nucleotide_chains'):
+            for mol in model.nucleotide_chains:
+                # Pack if the molecule index matches.
+                if mol_index == self.file_mol_num:
+                    self.data = mol
+                    return
+
+                mol_index = mol_index + 1
+
+        # Finally all other molecules.
+        if hasattr(model, 'molecules'):
+            for key in model.molecules.keys():
+                # Pack if the molecule index matches.
+                if mol_index == self.file_mol_num:
+                    # Loop over the molecules.
+                    self.data = []
+                    for mol in model.molecules[key]:
+                        self.data.append(mol)
+
+                    return
+
+                mol_index = mol_index + 1
+
 
     def to_xml(self, doc, element):
         """Create XML elements for the contents of this molecule container.




Related Messages


Powered by MHonArc, Updated Thu Jan 22 19:00:04 2009