mailr10940 - /1.3/generic_fns/angles.py


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

Header


Content

Posted by edward on February 25, 2010 - 14:59:
Author: bugman
Date: Thu Feb 25 14:59:08 2010
New Revision: 10940

URL: http://svn.gna.org/viewcvs/relax?rev=10940&view=rev
Log:
Bug fix and updates to the generic_fns.angles.wrap_angles() function.

This was not wrapping correctly when the window was not between 0 and 2pi.  
Epydoc tags have been
added to the docstring, the window size can now be specified and is checked 
against the bounds as a
sanity check, and comments have been added all over.


Modified:
    1.3/generic_fns/angles.py

Modified: 1.3/generic_fns/angles.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/generic_fns/angles.py?rev=10940&r1=10939&r2=10940&view=diff
==============================================================================
--- 1.3/generic_fns/angles.py (original)
+++ 1.3/generic_fns/angles.py Thu Feb 25 14:59:08 2010
@@ -1,6 +1,6 @@
 
###############################################################################
 #                                                                            
 #
-# Copyright (C) 2003-2005, 2007-2009 Edward d'Auvergne                       
 #
+# Copyright (C) 2003-2005, 2007-2010 Edward d'Auvergne                       
 #
 #                                                                            
 #
 # This file is part of the program relax.                                    
 #
 #                                                                            
 #
@@ -24,7 +24,7 @@
 """Module for the manipulation of angular information."""
 
 # Python module imports.
-from math import acos, sin
+from math import acos, pi, sin
 from numpy import dot
 from warnings import warn
 
@@ -116,15 +116,38 @@
         spin.alpha = acos(dot(cdp.diff_tensor.Dpar_unit, spin.xh_vect))
 
 
-def wrap_angles(angle, lower, upper):
-    """Convert the given angle to be between the lower and upper values."""
+def wrap_angles(angle, lower, upper, window=2*pi):
+    """Convert the given angle to be between the lower and upper values.
 
+    @param angle:   The starting angle.
+    @type angle:    float
+    @param lower:   The lower bound.
+    @type lower:    float
+    @param upper:   The upper bound.
+    @type upper:    float
+    @param window:  The size of the window where symmetry exists (defaults 
to 2pi).
+    @type window:   float
+    @return:        The wrapped angle.
+    @rtype:         float
+    """
+
+    # Check the bounds and window.
+    if window - (upper - lower) > 1e-7:
+        raise RelaxError, "The lower and upper bounds [%s, %s] do not match 
the window size of %s." % (lower, upper, window)
+
+    # Keep wrapping until the angle is within the limits.
     while True:
+        # The angle is too big.
         if angle > upper:
-            angle = angle - upper
+            angle = angle - window
+
+        # The angle is too small.
         elif angle < lower:
-            angle = angle + upper
+            angle = angle + window
+
+        # Inside the window, so stop wrapping.
         else:
             break
 
+    # Return the wrapped angle.
     return angle




Related Messages


Powered by MHonArc, Updated Thu Feb 25 15:20:05 2010