mailr16673 - /1.3/generic_fns/relax_data.py


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

Header


Content

Posted by edward on June 05, 2012 - 18:04:
Author: bugman
Date: Tue Jun  5 18:04:02 2012
New Revision: 16673

URL: http://svn.gna.org/viewcvs/relax?rev=16673&view=rev
Log:
The relax_data.delete user function is now finally properly implemented!

This was reported by Martin Ballaschk <ballaschk att fmp-berlin dott de> as 
bug #19785
(https://gna.org/bugs/?19785), and the mail message at
http://www.mail-archive.com/relax-users@xxxxxxx/msg01183.html (Message-Id:
<EED32F2B-B78F-4D23-9E0B-3DDE8B661F48@xxxxxxxxxxxxx>).

The problem was that this was not being checked by the test suite, and no one 
had tried to delete
relaxation data before (well, at least it was never reported).


Modified:
    1.3/generic_fns/relax_data.py

Modified: 1.3/generic_fns/relax_data.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/generic_fns/relax_data.py?rev=16673&r1=16672&r2=16673&view=diff
==============================================================================
--- 1.3/generic_fns/relax_data.py (original)
+++ 1.3/generic_fns/relax_data.py Tue Jun  5 18:04:02 2012
@@ -478,15 +478,40 @@
     if not exists_mol_res_spin_data():
         raise RelaxNoSequenceError
 
+    # Check the ID.
+    if ri_id == None:
+        raise RelaxError("The relaxation data ID string must be supplied.")
+
     # Test if data exists.
     if not hasattr(cdp, 'ri_ids') or ri_id not in cdp.ri_ids:
         raise RelaxNoRiError(ri_id)
 
-    # Loop over the spins.
+    # Pop the ID, and remove it from the frequency and type lists.
+    cdp.ri_ids.pop(cdp.ri_ids.index(ri_id))
+    del cdp.frq[ri_id]
+    del cdp.ri_type[ri_id]
+
+    # Prune empty structures.
+    if len(cdp.ri_ids) == 0:
+        del cdp.ri_ids
+    if len(cdp.frq) == 0:
+        del cdp.frq
+    if len(cdp.ri_type) == 0:
+        del cdp.ri_type
+
+    # Loop over the spins, deleting the relaxation data and errors when 
present.
     for spin in spin_loop():
-        # Relaxation data and errors.
-        del spin.ri_data[ri_id]
-        del spin.ri_data_err[ri_id]
+        # Data deletion.
+        if hasattr(spin, 'ri_data') and spin.ri_data.has_key(ri_id):
+            del spin.ri_data[ri_id]
+        if hasattr(spin, 'ri_data_err') and spin.ri_data_err.has_key(ri_id):
+            del spin.ri_data_err[ri_id]
+
+        # Prune empty structures.
+        if hasattr(spin, 'ri_data') and len(spin.ri_data) == 0:
+            del spin.ri_data
+        if hasattr(spin, 'ri_data_err') and len(spin.ri_data_err) == 0:
+            del spin.ri_data_err
 
 
 def display(ri_id=None):




Related Messages


Powered by MHonArc, Updated Tue Jun 05 18:20:02 2012