Skip to content

Commit 694644b

Browse files
committed
imporved text and grammar
1 parent cc4b43f commit 694644b

File tree

5 files changed

+91
-84
lines changed

5 files changed

+91
-84
lines changed

docs/source/chapters/chapter1.rst

Lines changed: 52 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -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

7070
Some 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.
7373
Potential 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
7878
defined 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

8584
Copy 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

120119
Create the Classes
121120
------------------
@@ -183,8 +182,14 @@ Within the *InitializeSimulation.py* file, copy the following lines:
183182
.. label:: end_InitializeSimulation_class
184183

185184
The *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

189194
Within 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

215220
Within 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

236243
Within 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

267270
Finally, 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

docs/source/chapters/chapter2.rst

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The *real* unit system follows the conventions outlined in the |lammps-unit-syst
2929
- Forces are in (kcal/mol)/Ångström,
3030
- Temperature is in Kelvin,
3131
- Pressure is in atmospheres,
32-
- Density is in g/cm\ :sup:`3` (in 3D).
32+
- Density is in g/cm\ :sup:`3`.
3333

3434
.. |lammps-unit-systems| raw:: html
3535

@@ -56,12 +56,8 @@ where :math:`k_\text{B}` is the Boltzmann constant.
5656
Start coding
5757
------------
5858

59-
Let's fill in the previously created class named Prepare. To facilitate unit
60-
conversion, we will import |NumPy| and the constants module from |SciPy|.
61-
62-
.. |NumPy| raw:: html
63-
64-
<a href="https://numpy.org/" target="_blank">NumPy</a>
59+
Let's fill in the previously created class named *Prepare*. To facilitate unit
60+
conversion, we will import NumPy and the constants module from |SciPy|.
6561

6662
.. |SciPy| raw:: html
6763

@@ -78,7 +74,7 @@ In the file named *Prepare.py*, add the following lines:
7874
7975
.. label:: end_Prepare_class
8076

81-
Four parameters are provided to the *Prepare* class:
77+
Four atom parameters are provided to the *Prepare* class:
8278

8379
- the atom masses :math:`m`,
8480
- the LJ parameters :math:`\sigma` and :math:`\epsilon`,
@@ -100,26 +96,26 @@ Modify the *Prepare* class as follows:
10096
epsilon, # List - Kcal/mol
10197
sigma, # List - Angstrom
10298
atom_mass, # List - g/mol
103-
potential_type="Lennard-Jones",
10499
*args,
105100
**kwargs):
106101
self.ureg = ureg
107102
self.number_atoms = number_atoms
108103
self.epsilon = epsilon
109104
self.sigma = sigma
110105
self.atom_mass = atom_mass
111-
self.potential_type = potential_type
112106
super().__init__(*args, **kwargs)
113107
114108
.. label:: end_Prepare_class
115109

116-
Here, the four lists *number_atoms* :math:`N`, *epsilon* :math:`\epsilon`,
117-
*sigma* :math:`\sigma`, and *atom_mass* :math:`m` are given default values of
118-
:math:`10`, :math:`0.1~\text{[Kcal/mol]}`, :math:`3~\text{[Å]}`, and
119-
:math:`10~\text{[g/mol]}`, respectively.
110+
Here, *number_atoms* :math:`N`, *epsilon* :math:`\epsilon`,
111+
*sigma* :math:`\sigma`, and *atom_mass* :math:`m` must be provided as lists
112+
where the elements have no units, kcal/mol, angstrom, and g/mol units,
113+
respectively. The units will be enforced with the |Pint| unit registry, *ureg*,
114+
which must also be provided as a parameter.
115+
116+
.. |Pint| raw:: html
120117

121-
The type of potential is also specified, with Lennard-Jones being chosen as
122-
the default option.
118+
<a href="https://pint.readthedocs.io" target="_blank">Pint</a>
123119

124120
All the parameters are assigned to *self*, allowing other methods to access
125121
them. The *args* and *kwargs* parameters are used to accept an arbitrary number

docs/source/chapters/chapter4.rst

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,7 @@ minimized energy state.
4747
Prepare the minimization
4848
------------------------
4949

50-
Let us start by importing NumPy and the copy libraries. Add the following
51-
to the beginning of the *MinimizeEnergy.py* file:
52-
53-
.. label:: start_MinimizeEnergy_class
54-
55-
.. code-block:: python
56-
57-
import numpy as np
58-
import copy
59-
60-
.. label:: end_MinimizeEnergy_class
61-
62-
Then, let us fill the *__init__()* method:
50+
Let us fill the *__init__()* method:
6351

6452
.. label:: start_MinimizeEnergy_class
6553

@@ -154,8 +142,7 @@ class:
154142
# Measure potential using information about cross coefficients
155143
sigma_ij = self.sigma_ij_list[Ni]
156144
epsilon_ij = self.epsilon_ij_list[Ni]
157-
energy_potential += np.sum(potentials(self.potential_type,
158-
epsilon_ij, sigma_ij, rij))
145+
energy_potential += np.sum(potentials(epsilon_ij, sigma_ij, rij))
159146
return energy_potential
160147
161148
.. label:: end_Utilities_class
@@ -207,8 +194,7 @@ let us create a new method that is dedicated solely to measuring forces:
207194
# Measure force using information about cross coefficients
208195
sigma_ij = self.sigma_ij_list[Ni]
209196
epsilon_ij = self.epsilon_ij_list[Ni]
210-
fij_xyz = potentials(self.potential_type, epsilon_ij,
211-
sigma_ij, rij, derivative = True)
197+
fij_xyz = potentials(epsilon_ij, sigma_ij, rij, derivative = True)
212198
if return_vector:
213199
# Add the contribution to both Ni and its neighbors
214200
force_vector[Ni] += np.sum((fij_xyz*rij_xyz.T/rij).T, axis=0)

docs/source/chapters/chapter8.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ We need to calculate Lambda:
215215
216216
def calculate_Lambda(self, mass):
217217
"""Estimate the de Broglie wavelength."""
218-
m = mass/cst.Avogadro*cst.milli # kg
219218
T = self.desired_temperature # N
220219
return 1/np.sqrt(2*np.pi*mass*T)
221220

docs/source/journal-article.bib

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,27 @@ @book{Rossum2009Python3
6161
isbn = {1441412697},
6262
publisher = {CreateSpace},
6363
address = {Scotts Valley, CA}
64-
}
64+
}
65+
66+
@article{ harris2020array,
67+
title = {Array programming with {NumPy}},
68+
author = {Charles R. Harris and K. Jarrod Millman and St{\'{e}}fan J.
69+
van der Walt and Ralf Gommers and Pauli Virtanen and David
70+
Cournapeau and Eric Wieser and Julian Taylor and Sebastian
71+
Berg and Nathaniel J. Smith and Robert Kern and Matti Picus
72+
and Stephan Hoyer and Marten H. van Kerkwijk and Matthew
73+
Brett and Allan Haldane and Jaime Fern{\'{a}}ndez del
74+
R{\'{i}}o and Mark Wiebe and Pearu Peterson and Pierre
75+
G{\'{e}}rard-Marchant and Kevin Sheppard and Tyler Reddy and
76+
Warren Weckesser and Hameer Abbasi and Christoph Gohlke and
77+
Travis E. Oliphant},
78+
year = {2020},
79+
month = sep,
80+
journal = {Nature},
81+
volume = {585},
82+
number = {7825},
83+
pages = {357--362},
84+
doi = {10.1038/s41586-020-2649-2},
85+
publisher = {Springer Science and Business Media {LLC}},
86+
url = {https://doi.org/10.1038/s41586-020-2649-2}
87+
}

0 commit comments

Comments
 (0)