OpenMPCD
test_WeeksChandlerAndersen_DistanceOffset.py
2  import WeeksChandlerAndersen_DistanceOffset as WCAD
3 
4 def test_constructor_get_parameters():
5  import pytest
6 
7  with pytest.raises(TypeError):
8  WCAD([1], 1, 1)
9 
10  with pytest.raises(TypeError):
11  WCAD(1, [1], 1)
12 
13  with pytest.raises(TypeError):
14  WCAD(1, 1, [1])
15 
16 
17  with pytest.raises(ValueError):
18  WCAD(-1, 0.1, 2.3)
19 
20  with pytest.raises(ValueError):
21  WCAD(1, -0.1, 2.3)
22 
23  with pytest.raises(ValueError):
24  WCAD(1, 0.1, -2.3)
25 
26 
27  pot = WCAD(1, 2.5, 3)
28 
29 
30  assert isinstance(pot.getEpsilon(), float)
31  assert pot.getEpsilon() == 1.0
32 
33  assert isinstance(pot.getSigma(), float)
34  assert pot.getSigma() == 2.5
35 
36  assert isinstance(pot.getD(), float)
37  assert pot.getD() == 3.0
38 
39 
40 def test_getPotential():
41  import pytest
42 
43  from MPCDAnalysis.Vector3DReal import Vector3DReal
44 
45  epsilon = 10.0
46  sigma = 2.0
47  d = 1.2
48  pot = WCAD(epsilon, sigma, d)
49 
50  def expected(r):
51  if isinstance(r, Vector3DReal):
52  r = r.getLength()
53 
54  if r <= d:
55  return None
56 
57  ret = 0.0
58  if 2 ** (1.0 / 6.0) * sigma - r + d > 0:
59  frac = sigma / (r - d)
60  ret = 1.0 / 4.0
61  ret += frac ** 12
62  ret -= frac ** 6
63  ret *= 4 * epsilon
64 
65  return ret
66 
67 
68  with pytest.raises(TypeError):
69  pot.getPotential([1])
70  with pytest.raises(ValueError):
71  pot.getPotential(-1)
72 
73  r = Vector3DReal(0, 0, 0)
74  with pytest.raises(ValueError):
75  pot.getPotential(r)
76  with pytest.raises(ValueError):
77  pot.getPotential(r.getLength())
78 
79  for i in range(0, 100):
80  r = Vector3DReal(-0.1 + i, i * 0.1, 2 * i)
81 
82  e = expected(r)
83  if e is None:
84  with pytest.raises(ValueError):
85  pot.getPotential(r)
86  continue
87 
88  assert pot.getPotential(r) == pytest.approx(e)
89  assert pot.getPotential(r.getLength()) == pytest.approx(e)
MPCDAnalysis.PairPotentials.WeeksChandlerAndersen_DistanceOffset
Definition: WeeksChandlerAndersen_DistanceOffset.py:1
MPCDAnalysis.Vector3DReal
Definition: Vector3DReal.py:1