mailr18856 - in /trunk/generic_fns/structure: api_base.py internal.py


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

Header


Content

Posted by edward on March 18, 2013 - 14:49:
Author: bugman
Date: Mon Mar 18 14:48:59 2013
New Revision: 18856

URL: http://svn.gna.org/viewcvs/relax?rev=18856&view=rev
Log:
Implemented the merging of structural objects.

This allows the merge flag of the structure.read_pdb user function to work.


Modified:
    trunk/generic_fns/structure/api_base.py
    trunk/generic_fns/structure/internal.py

Modified: trunk/generic_fns/structure/api_base.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/generic_fns/structure/api_base.py?rev=18856&r1=18855&r2=18856&view=diff
==============================================================================
--- trunk/generic_fns/structure/api_base.py (original)
+++ trunk/generic_fns/structure/api_base.py Mon Mar 18 14:48:59 2013
@@ -1411,6 +1411,35 @@
             self[-1].from_xml(mol_node, file_version=file_version)
 
 
+    def merge_item(self, mol_name=None, mol_cont=None):
+        """Mege the given MolContainer instance into a pre-existing molecule 
container.
+
+        @keyword mol_name:      The molecule number.
+        @type mol_name:         int
+        @keyword mol_cont:      The data structure for the molecule.
+        @type mol_cont:         MolContainer instance
+        @return:                The new molecule container.
+        @rtype:                 MolContainer instance
+        """
+
+        # Find the molecule to merge.
+        index = None
+        for i in range(len(self)):
+            if self[i].mol_name == mol_name:
+                index = i
+                break
+
+        # No molecule found.
+        if index == None:
+            raise RelaxError("The molecule '%s' to merge with cannot be 
found." % mol_name)
+
+        # Merge the molecules.
+        self[index].merge(mol_cont)
+
+        # Return the container.
+        return self[index]
+
+
     def to_xml(self, doc, element):
         """Create XML elements for each molecule.
 

Modified: trunk/generic_fns/structure/internal.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/generic_fns/structure/internal.py?rev=18856&r1=18855&r2=18856&view=diff
==============================================================================
--- trunk/generic_fns/structure/internal.py (original)
+++ trunk/generic_fns/structure/internal.py Mon Mar 18 14:48:59 2013
@@ -2323,6 +2323,26 @@
         return self.res_num[-1]
 
 
+    def merge(self, mol_cont=None):
+        """Merge the contents of the given molecule container into here.
+
+        @keyword mol_cont:      The data structure for the molecule to merge.
+        @type mol_cont:         MolContainer instance
+        """
+
+        # The current index.
+        curr_index = len(self.atom_num)
+
+        # Loop over all data.
+        for i in range(len(mol_cont.atom_num)):
+            # Add the atom.
+            self.atom_add(atom_num=curr_index+i+1, 
atom_name=mol_cont.atom_name[i], res_name=mol_cont.res_name[i], 
res_num=mol_cont.res_num[i], pos=[mol_cont.x[i], mol_cont.y[i], 
mol_cont.z[i]], element=mol_cont.element[i], chain_id=mol_cont.chain_id[i], 
pdb_record=mol_cont.pdb_record[i])
+
+            # Connect the atoms.
+            for j in range(len(mol_cont.bonded[i])):
+                self.atom_connect(index1=i+curr_index+1, 
index2=mol_cont.bonded[i][j]+curr_index+1)
+
+
     def to_xml(self, doc, element):
         """Create XML elements for the contents of this molecule container.
 




Related Messages


Powered by MHonArc, Updated Mon Mar 18 15:20:02 2013