Package target_functions :: Module potential
[hide private]
[frames] | no frames]

Source Code for Module target_functions.potential

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2009-2012 Edward d'Auvergne                                   # 
 4  #                                                                             # 
 5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
 6  #                                                                             # 
 7  # This program is free software: you can redistribute it and/or modify        # 
 8  # it under the terms of the GNU General Public License as published by        # 
 9  # the Free Software Foundation, either version 3 of the License, or           # 
10  # (at your option) any later version.                                         # 
11  #                                                                             # 
12  # This program is distributed in the hope that it will be useful,             # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
15  # GNU General Public License for more details.                                # 
16  #                                                                             # 
17  # You should have received a copy of the GNU General Public License           # 
18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
19  #                                                                             # 
20  ############################################################################### 
21   
22  # Module docstring. 
23  """Functions for calculating various optimisation potentials.""" 
24   
25   
26 -def quad_pot(values, pot, lower, upper):
27 """Calculate the flat-bottom quadratic energy potential. 28 29 The formula used is:: 30 31 / (x - x+)^2 if x > x+, 32 | 33 V_pQuad(x;x+,x-) = < (x - x-)^2 if x < x-, 34 | 35 \ 0 otherwise. 36 37 Where x+ and x- are the absolute bounds. 38 39 40 @param values: An array of values of x. 41 @type values: numpy float array 42 @param pot: The array to place the potential values (V_pQuad) into. This should have the 43 same dimensions as the values array. 44 @type pot: numpy float array 45 @param lower: The array of lower bounds. This should have the same dimensions as the values 46 array. 47 @type lower: numpy float array 48 @param upper: The array of upper bounds. This should have the same dimensions as the values 49 array. 50 @type upper: numpy float array 51 """ 52 53 # Loop over the x values. 54 for i in range(len(values)): 55 # First condition. 56 if values[i] > upper[i]: 57 pot[i] = (values[i] - upper[i])**2 58 59 # Second contition. 60 elif values[i] < lower[i]: 61 pot[i] = (values[i] - lower[i])**2 62 63 # Otherwise clear the array element. 64 else: 65 pot[i] = 0.0
66