OpenMPCD
test_MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles.py
2  import MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles as Potential
3 
4 def test_constructor_get_parameters():
5  from MPCDAnalysis.Vector3DReal import Vector3DReal
6 
7  import pytest
8 
9  orientation = Vector3DReal(1, 0, 0)
10 
11  with pytest.raises(TypeError):
12  Potential([1], orientation)
13 
14  with pytest.raises(TypeError):
15  Potential(1, [1, 0, 0])
16 
17 
18  with pytest.raises(ValueError):
19  Potential(-1, orientation)
20 
21  with pytest.raises(ValueError):
22  Potential(1, orientation * 2)
23 
24 
25  pot = Potential(2.5, orientation)
26 
27 
28  assert isinstance(pot.getPrefactor(), float)
29  assert pot.getPrefactor() == 2.5
30 
31  assert pot.getOrientation() == orientation
32 
33  orientation.x = 2
34  assert pot.getOrientation() == Vector3DReal(1, 0, 0)
35 
36 
37 def test_getPotential():
38  from MPCDAnalysis.Vector3DReal import Vector3DReal
39 
40  import pytest
41 
42  prefactor = 2.5
43  orientation = Vector3DReal(0, 1, 0)
44  pot = Potential(prefactor, orientation)
45 
46  def expected(r):
47  ret = -prefactor
48  ret *= 3 * orientation.dot(r.getNormalized()) ** 2 - 1
49  ret /= r.getLength() ** 3
50 
51  return ret
52 
53 
54  with pytest.raises(TypeError):
55  pot.getPotential([1])
56  with pytest.raises(TypeError):
57  pot.getPotential(1)
58 
59  r = Vector3DReal(0, 0, 0)
60  with pytest.raises(ValueError):
61  pot.getPotential(r)
62 
63  for i in range(0, 100):
64  r = Vector3DReal(-0.1 + i, i * 0.1, 2 * i)
65 
66  assert pot.getPotential(r) == pytest.approx(expected(r))
MPCDAnalysis.PairPotentials.MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles
Definition: MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles.py:1
MPCDAnalysis.Vector3DReal
Definition: Vector3DReal.py:1