mailr18868 - in /trunk: generic_fns/structure/ user_functions/


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

Header


Content

Posted by edward on March 19, 2013 - 11:04:
Author: bugman
Date: Tue Mar 19 11:04:15 2013
New Revision: 18868

URL: http://svn.gna.org/viewcvs/relax?rev=18868&view=rev
Log:
Sections of molecules can now be deleted using the structure.delete user 
function.

The atom ID argument has been added and this is now propagated into the 
internal structural object.
This ID string can be used to delete subsets of the 3D structural data in the 
relax data store.


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

Modified: trunk/generic_fns/structure/api_base.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/generic_fns/structure/api_base.py?rev=18868&r1=18867&r2=18868&view=diff
==============================================================================
--- trunk/generic_fns/structure/api_base.py (original)
+++ trunk/generic_fns/structure/api_base.py Tue Mar 19 11:04:15 2013
@@ -251,8 +251,12 @@
         raise RelaxImplementError
 
 
-    def delete(self):
-        """Prototype method stub for deleting all structural data from the 
current data pipe."""
+    def delete(self, atom_id=None):
+        """Prototype method stub for deleting structural data from the 
current data pipe.
+
+        @keyword atom_id:   The molecule, residue, and atom identifier 
string.  This matches the spin ID string format.  If not given, then all 
structural data will be deleted.
+        @type atom_id:      str or None
+        """
 
         # Raise the error.
         raise RelaxImplementError

Modified: trunk/generic_fns/structure/internal.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/generic_fns/structure/internal.py?rev=18868&r1=18867&r2=18868&view=diff
==============================================================================
--- trunk/generic_fns/structure/internal.py (original)
+++ trunk/generic_fns/structure/internal.py Tue Mar 19 11:04:15 2013
@@ -956,7 +956,7 @@
                     return False
 
 
-    def atom_loop(self, atom_id=None, str_id=None, model_num=None, 
model_num_flag=False, mol_name_flag=False, res_num_flag=False, 
res_name_flag=False, atom_num_flag=False, atom_name_flag=False, 
element_flag=False, pos_flag=False, ave=False):
+    def atom_loop(self, atom_id=None, str_id=None, model_num=None, 
model_num_flag=False, mol_name_flag=False, res_num_flag=False, 
res_name_flag=False, atom_num_flag=False, atom_name_flag=False, 
element_flag=False, pos_flag=False, index_flag=False, ave=False):
         """Generator function for looping over all atoms in the internal 
relax structural object.
 
         @keyword atom_id:           The molecule, residue, and atom 
identifier string.  Only atoms matching this selection will be yielded.
@@ -981,6 +981,8 @@
         @type element_flag:         bool
         @keyword pos_flag:          A flag which if True will cause the 
atomic position to be yielded.
         @type pos_flag:             bool
+        @keyword index_flag:        A flag which if True will cause the 
atomic index to be yielded.
+        @type index_flag:           bool
         @keyword ave:               A flag which if True will result in this 
method returning the average atom properties across all loaded structures.
         @type ave:                  bool
         @return:                    A tuple of atomic information, as 
described in the docstring.
@@ -1063,8 +1065,12 @@
                         atomic_tuple = atomic_tuple + (element,)
                     if pos_flag:
                         atomic_tuple = atomic_tuple + (pos,)
+                    if index_flag:
+                        atomic_tuple += (i,)
 
                     # Yield the information.
+                    if len(atomic_tuple) == 1:
+                        atomic_tuple = atomic_tuple[0]
                     yield atomic_tuple
 
             # Break out of the loop if the ave flag is set, as data from 
only one model is used.
@@ -1182,18 +1188,62 @@
             mol.atom_connect(index1=index1, index2=index2)
 
 
-    def delete(self):
-        """Delete all the structural information."""
-
-        # Print out.
-        print("Deleting the following structural data:\n")
-        print(self.structural_data)
-
-        # Delete the structural data.
-        del self.structural_data
-
-        # Initialise the empty model list.
-        self.structural_data = ModelList()
+    def delete(self, atom_id=None):
+        """Deletion of structural information.
+
+        @keyword atom_id:   The molecule, residue, and atom identifier 
string.  This matches the spin ID string format.  If not given, then all 
structural data will be deleted.
+        @type atom_id:      str or None
+        """
+
+        # All data.
+        if atom_id == None:
+            # Print out.
+            print("Deleting the following structural data:\n")
+            print(self.structural_data)
+
+            # Delete the structural data.
+            del self.structural_data
+
+            # Initialise the empty model list.
+            self.structural_data = ModelList()
+
+        # Atom subset deletion.
+        else:
+            # Generate the selection object.
+            sel_obj = None
+            if atom_id:
+                sel_obj = Selection(atom_id)
+
+            # Loop over the models.
+            for model in self.model_loop():
+                # Loop over the molecules.
+                for mol_index in range(len(model.mol)):
+                    mol = model.mol[mol_index]
+
+                    # Skip non-matching molecules.
+                    if sel_obj and not sel_obj.contains_mol(mol.mol_name):
+                        continue
+
+                    # Loop over the atoms.
+                    indices = []
+                    for i in self.atom_loop(atom_id=atom_id, 
model_num=model.num, index_flag=True):
+                        indices.append(i)
+
+                    # Loop over the reverse indices and pop out the data.
+                    indices.reverse()
+                    for i in indices:
+                        mol.atom_num.pop(i)
+                        mol.atom_name.pop(i)
+                        mol.bonded.pop(i)
+                        mol.chain_id.pop(i)
+                        mol.element.pop(i)
+                        mol.pdb_record.pop(i)
+                        mol.res_name.pop(i)
+                        mol.res_num.pop(i)
+                        mol.seg_id.pop(i)
+                        mol.x.pop(i)
+                        mol.y.pop(i)
+                        mol.z.pop(i)
 
 
     def get_molecule(self, molecule, model=None):

Modified: trunk/generic_fns/structure/main.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/generic_fns/structure/main.py?rev=18868&r1=18867&r2=18868&view=diff
==============================================================================
--- trunk/generic_fns/structure/main.py (original)
+++ trunk/generic_fns/structure/main.py Tue Mar 19 11:04:15 2013
@@ -124,29 +124,33 @@
     cdp.structure.connect_atom(index1=index1, index2=index2)
 
 
-def delete():
-    """Simple function for deleting all structural data."""
+def delete(atom_id=None):
+    """Delete structural data.
+    
+    @keyword atom_id:   The molecule, residue, and atom identifier string.  
This matches the spin ID string format.  If not given, then all structural 
data will be deleted.
+    @type atom_id:      str or None
+    """
 
     # Test if the current data pipe exists.
     pipes.test()
 
     # Run the object method.
     if hasattr(cdp, 'structure'):
-        print("Deleting all structural data from the current pipe.")
-        cdp.structure.delete()
+        print("Deleting structural data from the current pipe.")
+        cdp.structure.delete(atom_id=atom_id)
     else:
         print("No structures are present.")
 
     # Then remove any spin specific structural info.
     print("Deleting all spin specific structural info.")
-    for spin in spin_loop():
+    for spin in spin_loop(selection=atom_id):
         # Delete positional information.
         if hasattr(spin, 'pos'):
             del spin.pos
 
     # Then remove any interatomic vector structural info.
     print("Deleting all interatomic vectors.")
-    for interatom in interatomic_loop():
+    for interatom in interatomic_loop(selection1=atom_id):
         # Delete bond vectors.
         if hasattr(interatom, 'vector'):
             del interatom.vector

Modified: trunk/user_functions/structure.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/user_functions/structure.py?rev=18868&r1=18867&r2=18868&view=diff
==============================================================================
--- trunk/user_functions/structure.py (original)
+++ trunk/user_functions/structure.py Tue Mar 19 11:04:15 2013
@@ -418,19 +418,29 @@
 
 # The structure.delete user function.
 uf = uf_info.add_uf('structure.delete')
-uf.title = "Delete all structural information."
+uf.title = "Delete structural information."
 uf.title_short = "Structure deletion."
-# Description.
-uf.desc.append(Desc_container())
-uf.desc[-1].add_paragraph("This will delete all the structural information 
from the current data pipe.  All spin and sequence information loaded from 
these structures will be preserved - this only affects the structural data.")
+uf.add_keyarg(
+    name = "atom_id",
+    py_type = "str",
+    desc_short = "atom ID string",
+    desc = "The atom identification string.",
+    can_be_none = True
+)
+# Description.
+uf.desc.append(Desc_container())
+uf.desc[-1].add_paragraph("This will delete structural information from the 
current data pipe.  All spin and sequence information loaded from these 
structures will be preserved - this only affects the structural data.  The 
atom ID argument can be used to restrict deletion to parts of the loaded 
molecules.")
 # Prompt examples.
 uf.desc.append(Desc_container("Prompt examples"))
-uf.desc[-1].add_paragraph("Simply type:")
+uf.desc[-1].add_paragraph("To delete everything, simply type:")
 uf.desc[-1].add_prompt("relax> structure.delete()")
+uf.desc[-1].add_paragraph("To delete residues 50 to 100 of the molecule 
called 'Ap4Aase', type one of:")
+uf.desc[-1].add_prompt("relax> structure.delete(':50-100')")
+uf.desc[-1].add_prompt("relax> structure.delete(atom_id=':50-100')")
 uf.backend = generic_fns.structure.main.delete
 uf.menu_text = "&delete"
 uf.gui_icon = "oxygen.actions.list-remove"
-uf.wizard_size = (600, 400)
+uf.wizard_size = (700, 500)
 uf.wizard_apply_button = False
 uf.wizard_image = WIZARD_IMAGE_PATH + 'structure' + sep + '2JK4.png'
 




Related Messages


Powered by MHonArc, Updated Tue Mar 19 11:20:03 2013