mailr16971 - /branches/interatomic/data/mol_res_spin.py


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

Header


Content

Posted by edward on June 19, 2012 - 20:15:
Author: bugman
Date: Tue Jun 19 20:15:04 2012
New Revision: 16971

URL: http://svn.gna.org/viewcvs/relax?rev=16971&view=rev
Log:
Added a backwards compatibility hook for converting old XML files to the 
interatomic data design.

This will convert the variable names, deleting the old, and create proton 
spins and interatomic data
containers populating them with the old spin parameters.


Modified:
    branches/interatomic/data/mol_res_spin.py

Modified: branches/interatomic/data/mol_res_spin.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/interatomic/data/mol_res_spin.py?rev=16971&r1=16970&r2=16971&view=diff
==============================================================================
--- branches/interatomic/data/mol_res_spin.py (original)
+++ branches/interatomic/data/mol_res_spin.py Tue Jun 19 20:15:04 2012
@@ -25,7 +25,7 @@
 
 # Python module imports.
 import numpy
-from re import match
+from re import match, search
 from string import lower
 
 # relax module imports.
@@ -619,6 +619,61 @@
         return text
 
 
+    def _back_compat_hook(self, file_version=None):
+        """Method for converting the old data structures to the new ones.
+
+        @keyword file_version:  The relax XML version of the XML file.
+        @type file_version:     int
+        """
+
+        # Loop over the residues.
+        for res in self.res:
+            # Loop over the spins.
+            for spin in res.spin:
+                # The interatomic data container design.
+                if hasattr(spin, 'heteronuc_type'):
+                    # Rename the nuclear isotope.
+                    spin.isotope = spin.heteronuc_type
+
+                    # Name the spin if needed.
+                    if spin.name == None:
+                        if search('N', spin.isotope):
+                            spin.name = 'N'
+                        elif search('C', spin.isotope):
+                            spin.name = 'C'
+
+                    # Create a new spin container for the proton, then set 
up a dipole interaction between the two spins.
+                    h_spin = 
generic_fns.mol_res_spin.create_spin(mol_name=self.name, res_num=res.num, 
res_name=res.name, spin_name='H')
+                    spin_id1 = 
generic_fns.mol_res_spin.generate_spin_id(mol_name=self.name, 
res_num=res.num, res_name=res.name, spin_name=spin.name, spin_num=spin.num)
+                    spin_id2 = 
generic_fns.mol_res_spin.generate_spin_id(mol_name=self.name, 
res_num=res.num, res_name=res.name, spin_name='H')
+                    generic_fns.dipole_pair.define(spin_id1, spin_id2, 
verbose=False)
+
+                    # Get the interatomic data container.
+                    interatom = 
generic_fns.interatomic.return_interatom(spin_id1=spin_id1, spin_id2=spin_id2)
+                    if len(interatom) != 1:
+                        raise RelaxError("Only one interatomic interaction 
is allowed.")
+
+                    # Set the interatomic distance.
+                    if hasattr(spin, 'r'):
+                        interatom[0].r = spin.r
+
+                    # Set the interatomic unit vectors.
+                    if hasattr(spin, 'xh_vect'):
+                        interatom[0].vector = spin.xh_vect
+
+                # Delete the old structures.
+                if hasattr(spin, 'heteronuc_type'):
+                    del spin.heteronuc_type
+                if hasattr(spin, 'proton_type'):
+                    del spin.proton_type
+                if hasattr(spin, 'attached_proton'):
+                    del spin.attached_proton
+                if hasattr(spin, 'r'):
+                    del spin.r
+                if hasattr(spin, 'xh_vect'):
+                    del spin.xh_vect
+
+
     def is_empty(self):
         """Method for testing if this MoleculeContainer object is empty.
 
@@ -749,6 +804,9 @@
             # Recreate the residue data structures for the current molecule.
             self[-1].res.from_xml(res_nodes, file_version=file_version)
 
+            # Backwards compatibility transformations.
+            self[-1]._back_compat_hook(file_version)
+
 
     def to_xml(self, doc, element):
         """Create XML elements for each molecule.




Related Messages


Powered by MHonArc, Updated Tue Jun 19 20:20:13 2012