@@ -66,33 +66,51 @@ between atoms. Although more complicated options exist, potentials are usually
6666defined as functions of the distance :math: `r` between two atoms.
6767
6868Within a dedicated folder, create the first file named *potentials.py *. This
69- file will contain a function named *LJ_potential * for the Lennard-Jones
70- potential (LJ). Copy the following into *potentials.py *:
69+ file will contain a function called *potentials *. Two types of potential can
70+ be returned by this function: the Lennard-Jones potential (LJ), and the
71+ hard-sphere potential.
72+
73+ Copy the following lines into *potentials.py *:
7174
7275.. label :: start_potentials_class
7376
7477.. code-block :: python
7578
76- def LJ_potential (epsilon , sigma , r , derivative = False ):
77- if derivative:
78- return 48 * epsilon* ((sigma/ r)** 12 - 0.5 * (sigma/ r)** 6 )/ r
79+ def potentials (potential_type , epsilon , sigma , r , derivative = False ):
80+ if potential_type == " Lennard-Jones" :
81+ if derivative:
82+ return 48 * epsilon * ((sigma / r) ** 12 - 0.5 * (sigma / r) ** 6 ) / r
83+ else :
84+ return 4 * epsilon * ((sigma / r) ** 12 - (sigma / r) ** 6 )
85+ elif potential_type == " Hard-Sphere" :
86+ if derivative:
87+ raise ValueError (" Derivative is not defined for Hard-Sphere potential." )
88+ else :
89+ return 1000 if r < sigma else 0
7990 else :
80- return 4 * epsilon * ((sigma / r) ** 12 - (sigma / r) ** 6 )
91+ raise ValueError ( f " Unknown potential type: { potential_type } " )
8192
8293 .. label :: end_potentials_class
8394
84- Depending on the value of the optional argument *derivative *, which can be
85- either *False * or *True *, the *LJ_potential * function will return the force:
95+ The hard-sphere potential either returns a value of 0 when the distance between
96+ the two particles is larger than the parameter, :math: `r > \sigma `, or 1000 when
97+ :math: `r < \sigma `. The value of *1000 * was chosen to be large enough to ensure
98+ that any Monte Carlo move that would lead to the two particles to overlap will
99+ be rejected.
100+
101+ In the case of the LJ potential, depending on the value of the optional
102+ argument *derivative *, which can be either *False * or *True *, the *LJ_potential *
103+ function will return the force:
86104
87105.. math ::
88106
89- F_\text {LJ} = 48 \dfrac {\epsilon }{r} \left [ \left ( \frac {\sigma }{r} \right )^{12 }- \frac {1 }{2 } \left ( \frac {\sigma }{r} \right )^6 \right ],
107+ F_\text {LJ} = 48 \dfrac {\epsilon }{r} \left [ \left ( \frac {\sigma }{r} \right )^{12 } - \frac {1 }{2 } \left ( \frac {\sigma }{r} \right )^6 \right ],
90108
91109 or the potential energy:
92110
93111.. math ::
94112
95- U_\text {LJ} = 4 \epsilon \left [ \left ( \frac {\sigma }{r} \right )^{12 }- \left ( \frac {\sigma }{r} \right )^6 \right ].
113+ U_\text {LJ} = 4 \epsilon \left [ \left ( \frac {\sigma }{r} \right )^{12 } - \left ( \frac {\sigma }{r} \right )^6 \right ].
96114
97115 Create the Classes
98116------------------
@@ -124,7 +142,7 @@ copy the following lines:
124142
125143.. code-block :: python
126144
127- from potentials import LJ_potential
145+ from potentials import potentials
128146
129147
130148 class Utilities :
0 commit comments