@@ -39,32 +39,32 @@ containing either Python functions or classes:
3939
4040 * - File Name
4141 - Content
42- * - * Prepare.py *
42+ * - Prepare.py
4343 - *Prepare * class: Methods for preparing the non-dimensionalization of the
4444 units
45- * - * Utilities.py *
45+ * - Utilities.py
4646 - *Utilities * class: General-purpose methods, inherited by all other
4747 classes
48- * - * InitializeSimulation.py *
48+ * - InitializeSimulation.py
4949 - *InitializeSimulation * class: Methods necessary to set up the system and
5050 prepare the simulation, inherited by all the classes below
51- * - * MinimizeEnergy.py *
51+ * - MinimizeEnergy.py
5252 - *MinimizeEnergy * class: Methods for performing energy minimization
53- * - * MonteCarlo.py *
53+ * - MonteCarlo.py
5454 - *MonteCarlo * class: Methods for performing Monte Carlo simulations in
5555 different ensembles (e.g., Grand Canonical, Canonical)
56- * - * MolecularDynamics.py *
56+ * - MolecularDynamics.py
5757 - *MolecularDynamics * class: Methods for performing molecular dynamics in
5858 different ensembles (NVE, NPT, NVT)
59- * - * measurements .py*
60- - Functions for performing specific measurements on the system
59+ * - Measurements .py
60+ - * Measurements * class: Methods for for performing specific measurements on the system
6161 * - *potentials.py *
6262 - Functions for calculating the potentials and forces between atoms
63- * - * logger.py *
63+ * - logger.py
6464 - Functions for outputting data into text files
65- * - * dumper.py *
65+ * - dumper.py
6666 - Functions for outputting data into trajectory files for visualization
67- * - * reader.py *
67+ * - reader.py
6868 - Functions for importing data from text files
6969
7070Some of these files are created in this chapter; others will be created later
@@ -73,31 +73,25 @@ on. All of these files must be created within the same folder.
7373Potential for Inter-Atomic Interaction
7474--------------------------------------
7575
76- In molecular simulations, potential functions are used to mimic the interaction
77- between atoms. Although more complicated options exist, potentials are usually
76+ In molecular simulations, potential functions are used to model the interaction
77+ between atoms. Although more complex options exist, potentials are usually
7878defined as functions of the distance :math: `r` between two atoms.
7979
80- Create the first file named *potentials.py *. This file will contain a function
81- called *potentials *. For the moment, the only potential that can be returned by
82- this function is the Lennard-Jones potential (LJ). This may change in the
83- future.
80+ Create a file named *potentials.py *. This file will contain a function called
81+ *potentials *. For now, the only potential that can be returned by this function
82+ is the Lennard-Jones (LJ) potential, but this may change in the future.
8483
8584Copy the following lines into *potentials.py *:
8685
8786.. label :: start_potentials_class
8887
8988.. code-block :: python
9089
91- import numpy as np
92-
93- def potentials (potential_type , epsilon , sigma , r , derivative = False ):
94- if potential_type == " Lennard-Jones" :
95- if derivative:
96- return 48 * epsilon * ((sigma / r) ** 12 - 0.5 * (sigma / r) ** 6 ) / r
97- else :
98- return 4 * epsilon * ((sigma / r) ** 12 - (sigma / r) ** 6 )
90+ def potentials (epsilon , sigma , r , derivative = False ):
91+ if derivative:
92+ return 48 * epsilon * ((sigma / r) ** 12 - 0.5 * (sigma / r) ** 6 ) / r
9993 else :
100- raise ValueError ( f " Unknown potential type: { potential_type } " )
94+ return 4 * epsilon * ((sigma / r) ** 12 - (sigma / r) ** 6 )
10195
10296 .. label :: end_potentials_class
10397
@@ -108,14 +102,19 @@ i.e., the force, :math:`F_\text{LJ} = - \mathrm{d} U_\text{LJ} / \mathrm{d} r`:
108102.. math ::
109103
110104 F_\text {LJ} = 48 \dfrac {\epsilon }{r} \left [ \left ( \frac {\sigma }{r} \right )^{12 }
111- - \frac {1 }{2 } \left ( \frac {\sigma }{r} \right )^6 \right ],
105+ - \frac {1 }{2 } \left ( \frac {\sigma }{r} \right )^6 \right ], ~ \text {for} ~ r < r_ \text {c},
112106
113107 or the potential energy:
114108
115109.. math ::
116110
117111 U_\text {LJ} = 4 \epsilon \left [ \left ( \frac {\sigma }{r} \right )^{12 }
118- - \left ( \frac {\sigma }{r} \right )^6 \right ].
112+ - \left ( \frac {\sigma }{r} \right )^6 \right ], ~ \text {for} ~ r < r_\text {c}.
113+
114+ Here, :math: `\sigma ` is the distance at which the potential :math: `U_\text {LJ}`
115+ is zero, :math: `\epsilon ` is the depth of the potential well, and
116+ :math: `r_\text {c}` is a cutoff distance. For :math: `r > r_\text {c}`,
117+ :math: `U_\text {LJ} = 0 ` and :math: `F_\text {LJ} = 0 `.
119118
120119Create the Classes
121120------------------
@@ -183,8 +182,14 @@ Within the *InitializeSimulation.py* file, copy the following lines:
183182 .. label :: end_InitializeSimulation_class
184183
185184The *InitializeSimulation * class inherits from the previously created
186- *Prepare * and Utilities classes. Additionally, we anticipate that *NumPy * will
187- be required.
185+ *Prepare * and *Utilities * classes. Additionally, we anticipate that |NumPy |
186+ will be required :cite: `harris2020array `. We also anticipate that the *os *
187+ module, which provides a way to interact with the operating system, will
188+ be required :cite: `Rossum2009Python3 `.
189+
190+ .. |NumPy | raw :: html
191+
192+ <a href="https://numpy.org/" target="_blank">NumPy</a>
188193
189194Within the *Measurements.py * file, copy the following lines:
190195
@@ -204,13 +209,13 @@ Within the *Measurements.py* file, copy the following lines:
204209
205210 .. label :: end_Measurements_class
206211
207- The *Measurements * class inherits both the *InitializeSimulation * and
208- * Utilities * classes.
212+ The *Measurements * class inherits from *InitializeSimulation * ( and thus
213+ also inherits from the * Prepare * and * Utilities * classes).
209214
210- Finally, let us create the three remaining classes, named *MinimizeEnergy *,
211- *MonteCarlo *, and *MolecularDynamics *. Each of these three classes inherits
212- from the *Measurements * class, and thus from the classes inherited by
213- * Measurements * .
215+ Finally, let us create the three remaining classes: *MinimizeEnergy *,
216+ *MonteCarlo *, and *MolecularDynamics *. Each of these classes inherits
217+ from the *Measurements * class ( and thus also from the * Prepare *, * Utilities *,
218+ and * InitializeSimulation * classes) .
214219
215220Within the *MinimizeEnergy.py * file, copy the following lines:
216221
@@ -219,6 +224,8 @@ Within the *MinimizeEnergy.py* file, copy the following lines:
219224.. code-block :: python
220225
221226 from Measurements import Measurements
227+ import numpy as np
228+ import copy
222229 import os
223230
224231
@@ -230,19 +237,17 @@ Within the *MinimizeEnergy.py* file, copy the following lines:
230237
231238 .. label :: end_MinimizeEnergy_class
232239
233- We anticipate that the * os * module , which provides a way to interact with the
234- operating system, will be required :cite: ` Rossum2009Python3 ` .
240+ The * copy * library , which provides functions to create shallow or deep copies of
241+ objects, is imported, along with * NumPy * and * os * .
235242
236243Within the *MonteCarlo.py * file, copy the following lines:
237244
238245.. label :: start_MonteCarlo_class
239246
240247.. code-block :: python
241248
242- from scipy import constants as cst
243249 import numpy as np
244250 import copy
245- import os
246251 from Measurements import Measurements
247252
248253 import warnings
@@ -257,12 +262,10 @@ Within the *MonteCarlo.py* file, copy the following lines:
257262
258263 .. label :: end_MonteCarlo_class
259264
260- Several libraries were imported, namely *Constants * from *SciPy *, *NumPy *, *copy *
261- and *os *.
262-
263- The *warnings * was placed to avoid the anoying message "*RuntimeWarning: overflow
264- encountered in exp *" that is sometimes triggered by the exponential of the
265- *acceptation_probability * (see :ref: `chapter6-label `).
265+ The *ignore warnings * commands are optional; they were added to avoid the
266+ annoying message "*RuntimeWarning: overflow encountered in exp *" that is sometimes
267+ triggered by the exponential function of *acceptation_probability * (see the
268+ :ref: `chapter6-label ` chapter).
266269
267270Finally, within the *MolecularDynamics.py * file, copy the following lines:
268271
@@ -331,9 +334,9 @@ Alternatively, this test can also be launched using *Pytest* by typing in a term
331334
332335 pytest .
333336
334- We can also test that calling the *__init__ *
335- method of the * MonteCarlo * class does not return any error. In new Python file
336- called * test_1b.py *, copy the following lines:
337+ We can also test that calling the *__init__ * method of the * MonteCarlo * class
338+ does not return any error. In new Python file called * test_1b.py *, copy the
339+ following lines:
337340
338341.. label :: start_test_1b_class
339342
0 commit comments