OpenMPCD
MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles.py
1 class MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles:
2  r"""
3  Interactions between two constant and identical magnetic dipoles.
4 
5  The general magnetic dipole-dipole interaction potential is given by
6  \f[
7  - \frac{ \mu_0 }{ 4 \pi r^3 }
8  \left(
9  3
10  \left(\vec{m_1} \cdot \hat{r} \right)
11  \left(\vec{m_2} \cdot \hat{r} \right)
12  -
13  \vec{m_1} \cdot \vec{m_2}
14  \right)
15  \f]
16  where \f$ \mu_0 \f$ is the vacuum permeability, \f$ \hat{r} \f$ and
17  \f$ r \f$ are, respectively, the unit vector and length of the vector
18  \f$ \vec{r} \f$ that points from one dipole's position to the other's,
19  \f$ \vec{m_1} \f$ and \f$ \vec{m_2} \f$ are the magnetic dipole moments, and
20  \f$ \cdot \f$ denotes the inner product.
21 
22  In the special case treated in this class, the magnetic dipole moments are
23  assumed to be constant throughout time in size and orientation. Therefore,
24  with \f$ m \f$ being the magnitude of the individual dipole moments and with
25  \f$ \hat{m} \f$ being the unit vector of the individual dipole moments, the
26  interaction potential is given by
27  \f[
28  - \frac{ \mu_0 m^2 }{ 4 \pi r^3 }
29  \left( 3 \left(\hat{m} \cdot \hat{r} \right)^2 - 1 \right)
30  \f]
31  """
32 
33  def __init__(self, prefactor, orientation):
34  r"""
35  The constructor.
36 
37  @throw TypeError
38  Throws if `prefactor` is neither `int` nor `float`.
39  @throw TypeError
40  Throws if `orientation` is not an instance of `Vector3DReal`.
41  @throw ValueError
42  Throws if `prefactor` is negative.
43  @throw ValueError
44  Throws if `orientation` is not a unit vector.
45 
46  @param[in] prefactor
47  The term \f$ \frac{\mu_0 m^2}{4 \pi} \f$, which must be
48  non-negative.
49  @param[in] orientation
50  The orientation unit vector \f$ \hat{m} \f$ of the dipole
51  moments.
52  """
53 
54  from MPCDAnalysis.Vector3DReal import Vector3DReal
55 
56  if not isinstance(prefactor, (int, float)):
57  raise TypeError()
58  if not isinstance(orientation, Vector3DReal):
59  raise TypeError()
60 
61  if prefactor < 0:
62  raise ValueError()
63  if orientation.getLengthSquared() != 1.0:
64  raise ValueError()
65 
66  import copy
67  self._prefactor = float(prefactor)
68  self._orientation = copy.deepcopy(orientation)
69 
70 
71  def getPrefactor(self):
72  r"""
73  Returns the term \f$ \frac{\mu_0 m^2}{4 \pi} \f$ as a `float`.
74  """
75 
76  return self._prefactor
77 
78 
79  def getOrientation(self):
80  r"""
81  Returns the orientation unit vector \f$ \hat{m} \f$ of the dipole
82  moments as an instance of `Vector3DReal`.
83  """
84 
85  return self._orientation
86 
87 
88  def getPotential(self, r):
89  r"""
90  Returns the potential for an input value of \f$ r \f$.
91 
92  @throw TypeError
93  Throws if `r` is neither `int` nor `float` or `Vector3DReal`.
94  @throw ValueError
95  Throws if `r` is the zero vector.
96 
97  @param[in] r
98  The input value, which must may be a non-zero vector of type
99  `Vector3DReal`.
100  """
101 
102  from MPCDAnalysis.Vector3DReal import Vector3DReal
103 
104  if not isinstance(r, Vector3DReal):
105  raise TypeError
106 
107  r2 = r.getLengthSquared()
108 
109  if r2 == 0:
110  raise ValueError()
111 
112  import math
113 
114  r_m2 = 1.0 / r2
115  r_m3 = r_m2 / math.sqrt(r2)
116  dot = r.dot(self.getOrientation())
117 
118  return -self.getPrefactor() * r_m3 * (3 * dot * dot * r_m2 - 1)
MPCDAnalysis.PairPotentials.MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles.MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles.getPotential
def getPotential(self, r)
Definition: MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles.py:105
MPCDAnalysis.PairPotentials.MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles.MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles._orientation
_orientation
Definition: MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles.py:70
MPCDAnalysis.PairPotentials.MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles.MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles.getPrefactor
def getPrefactor(self)
Definition: MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles.py:77
MPCDAnalysis.Vector3DReal
Definition: Vector3DReal.py:1
MPCDAnalysis.PairPotentials.MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles.MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles._prefactor
_prefactor
Definition: MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles.py:69
MPCDAnalysis.PairPotentials.MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles.MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles.__init__
def __init__(self, prefactor, orientation)
Definition: MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles.py:54
MPCDAnalysis.PairPotentials.MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles.MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles.getOrientation
def getOrientation(self)
Definition: MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles.py:87