Package lib :: Package structure :: Module angles
[hide private]
[frames] | no frames]

Source Code for Module lib.structure.angles

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2003-2010,2012-2014 Edward d'Auvergne                         # 
 4  # Copyright (C) 2008 Sebastien Morin                                          # 
 5  #                                                                             # 
 6  # This file is part of the program relax (http://www.nmr-relax.com).          # 
 7  #                                                                             # 
 8  # This program is free software: you can redistribute it and/or modify        # 
 9  # it under the terms of the GNU General Public License as published by        # 
10  # the Free Software Foundation, either version 3 of the License, or           # 
11  # (at your option) any later version.                                         # 
12  #                                                                             # 
13  # This program is distributed in the hope that it will be useful,             # 
14  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
16  # GNU General Public License for more details.                                # 
17  #                                                                             # 
18  # You should have received a copy of the GNU General Public License           # 
19  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
20  #                                                                             # 
21  ############################################################################### 
22   
23  # Python module imports. 
24  from math import pi 
25  from numpy import arccos, float64, zeros 
26   
27   
28 -def angles_regular(inc=None):
29 """Determine the spherical angles for a regular sphere point distribution. 30 31 @keyword inc: The number of increments in the distribution. 32 @type inc: int 33 @return: The phi angle array and the theta angle array. 34 @rtype: array of float, array of float 35 """ 36 37 # Generate the increment values of u. 38 u = zeros(inc, float64) 39 val = 1.0 / float(inc) 40 for i in range(inc): 41 u[i] = float(i) * val 42 43 # Generate the increment values of v. 44 v = zeros(int(inc/2.0+1.0), float64) 45 val = 1.0 / float(inc/2.0) 46 for i in range(int(inc/2.0+1.0)): 47 v[i] = float(i) * val 48 49 # Generate the distribution of spherical angles theta. 50 theta = 2.0 * pi * u 51 52 # Generate the distribution of spherical angles phi (from bottom to top). 53 phi = zeros(len(v), float64) 54 for i in range(len(v)): 55 phi[len(v)-1-i] = pi * v[i] 56 57 # Return the angle arrays. 58 return phi, theta
59 60
61 -def angles_uniform(inc=None):
62 """Determine the spherical angles for a uniform sphere point distribution. 63 64 @keyword inc: The number of increments in the distribution. 65 @type inc: int 66 @return: The phi angle array and the theta angle array. 67 @rtype: array of float, array of float 68 """ 69 70 # Generate the increment values of u. 71 u = zeros(inc, float64) 72 val = 1.0 / float(inc) 73 for i in range(inc): 74 u[i] = float(i) * val 75 76 # Generate the increment values of v. 77 v = zeros(int(inc/2.0+2.0), float64) 78 val = 1.0 / float(inc/2.0) 79 for i in range(1, int(inc/2.0)+1): 80 v[i] = float(i-1) * val + val/2.0 81 v[-1] = 1.0 82 83 # Generate the distribution of spherical angles theta. 84 theta = 2.0 * pi * u 85 86 # Generate the distribution of spherical angles phi. 87 phi = arccos(2.0 * v - 1.0) 88 89 # Return the angle arrays. 90 return phi, theta
91