mailr16985 - /branches/interatomic/generic_fns/dipole_pair.py


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

Header


Content

Posted by edward on June 20, 2012 - 00:11:
Author: bugman
Date: Wed Jun 20 00:11:50 2012
New Revision: 16985

URL: http://svn.gna.org/viewcvs/relax?rev=16985&view=rev
Log:
The dipole_pair user functions now fail if nothing could be done.

This is for the dipole_pair.define, dipole_pair.read_dist, and 
dipole_pair.set_dist user functions.


Modified:
    branches/interatomic/generic_fns/dipole_pair.py

Modified: branches/interatomic/generic_fns/dipole_pair.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/interatomic/generic_fns/dipole_pair.py?rev=16985&r1=16984&r2=16985&view=diff
==============================================================================
--- branches/interatomic/generic_fns/dipole_pair.py (original)
+++ branches/interatomic/generic_fns/dipole_pair.py Wed Jun 20 00:11:50 2012
@@ -86,8 +86,28 @@
             # Store the IDs for the print out.
             ids.append([repr(id1), repr(id2)])
 
+    # No matches, so fail!
+    if not len(ids):
+        # Find the problem.
+        count1 = 0
+        count2 = 0
+        for spin in spin_loop(spin_id1):
+            count1 += 1
+        for spin in spin_loop(spin_id2):
+            count2 += 1
+
+        # Report the problem.
+        if count1 == 0 and count2 == 0:
+            raise RelaxError("Both spin IDs '%s' and '%s' match no spins." % 
(spin_id1, spin_id2))
+        elif count1 == 0:
+            raise RelaxError("The spin ID '%s' matches no spins." % spin_id1)
+        elif count2 == 0:
+            raise RelaxError("The spin ID '%s' matches no spins." % spin_id2)
+        else:
+            raise RelaxError("Unknown error.")
+
     # Print out.
-    if verbose and len(ids):
+    if verbose:
         write_data(out=sys.stdout, headings=["Spin_ID_1", "Spin_ID_2"], 
data=ids)
 
 
@@ -156,6 +176,10 @@
         # Store the data for the print out.
         data.append([repr(interatom.spin_id1), repr(interatom.spin_id2), 
repr(ave_dist)])
 
+    # No data, so fail!
+    if not len(data):
+        raise RelaxError("No data could be extracted from the file.")
+
     # Print out.
     write_data(out=sys.stdout, headings=["Spin_ID_1", "Spin_ID_2", 
"Ave_distance"], data=data)
 
@@ -191,6 +215,10 @@
 
         # Store the data for the print out.
         data.append([repr(interatom.spin_id1), repr(interatom.spin_id2), 
repr(ave_dist)])
+
+    # No data, so fail!
+    if not len(data):
+        raise RelaxError("No data could be set.")
 
     # Print out.
     write_data(out=sys.stdout, headings=["Spin_ID_1", "Spin_ID_2", 
"Ave_distance"], data=data)




Related Messages


Powered by MHonArc, Updated Wed Jun 20 00:40:02 2012