OpenMPCD
FENE.py
1 class FENE:
2  r"""
3  Models the FENE potential, which is given by
4  \f[ V_{\textrm{FENE}}(r) = - 0.5 K R^2 \log (1 - (\frac{r - l_0}{R})^2) \f]
5  """
6 
7  def __init__(self, K, l_0, R):
8  r"""
9  The constructor.
10 
11  @throw TypeError
12  Throws if `K`, `l_0`, or `R` are neither `int` nor `float`.
13  @throw ValueError
14  Throws if `R` is `0` or negative.
15 
16  @param[in] K
17  The \f$ K \f$ potential parameter.
18  @param[in] l_0
19  The \f$ l_0 \f$ potential parameter.
20  @param[in] R
21  The \f$ R \f$ potential parameter, which must be positive.
22  """
23 
24  for var in [K, l_0, R]:
25  if not isinstance(var, (int, float)):
26  raise TypeError()
27 
28  if R <= 0:
29  raise ValueError()
30 
31 
32  self._K = float(K)
33  self._l_0 = float(l_0)
34  self._R = float(R)
35 
36 
37  def getK(self):
38  r"""
39  Returns the \f$ K \f$ potential parameter as a `float`.
40  """
41 
42  return self._K
43 
44 
45  def get_l_0(self):
46  r"""
47  Returns the \f$ l_0 \f$ potential parameter as a `float`.
48  """
49 
50  return self._l_0
51 
52 
53  def getR(self):
54  r"""
55  Returns the \f$ R \f$ potential parameter as a `float`.
56  """
57 
58  return self._R
59 
60 
61  def getPotential(self, r):
62  r"""
63  Returns the potential for an input value of \f$ r \f$.
64 
65  @throw TypeError
66  Throws if `r` is neither `int` nor `float` or `Vector3DReal`.
67  @throw ValueError
68  Throws if `r` is negative.
69  @throw ValueError
70  Throws if `r` is such that, in combination with the used
71  potential parameters, the result is undefined.
72 
73  @param[in] r
74  The input value. It may be either an `int` or `float`, in
75  which case it must be non-negative. Alternatively, it may be
76  of type `Vector3DReal`, which is then euqivalent to calling
77  `getPotential(r.getLength())` instead.
78  """
79 
80  from MPCDAnalysis.Vector3DReal import Vector3DReal
81  if isinstance(r, Vector3DReal):
82  r = r.getLength()
83  else:
84  if not isinstance(r, (int, float)):
85  raise TypeError()
86  if r < 0:
87  raise ValueError()
88 
89  R = self.getR()
90  prefactor = -0.5 * self.getK() * R * R
91  frac = (r - self.get_l_0()) / R
92 
93  frac2 = frac * frac
94 
95  if frac2 >= 1:
96  raise ValueError()
97 
98  import math
99  return prefactor * math.log(1 - frac2)
MPCDAnalysis.PairPotentials.FENE.FENE.getPotential
def getPotential(self, r)
Definition: FENE.py:84
MPCDAnalysis.PairPotentials.FENE.FENE.get_l_0
def get_l_0(self)
Definition: FENE.py:52
MPCDAnalysis.PairPotentials.FENE.FENE.__init__
def __init__(self, K, l_0, R)
Definition: FENE.py:24
MPCDAnalysis.PairPotentials.FENE.FENE.getR
def getR(self)
Definition: FENE.py:61
MPCDAnalysis.PairPotentials.FENE.FENE._l_0
_l_0
Definition: FENE.py:35
MPCDAnalysis.Vector3DReal
Definition: Vector3DReal.py:1
MPCDAnalysis.PairPotentials.FENE.FENE.getK
def getK(self)
Definition: FENE.py:43
MPCDAnalysis.PairPotentials.FENE.FENE._R
_R
Definition: FENE.py:36
MPCDAnalysis.PairPotentials.FENE.FENE._K
_K
Definition: FENE.py:34