@@ -111,7 +111,7 @@ Here, *number_atoms* :math:`N`, *epsilon* :math:`\epsilon`,
111
111
*sigma * :math: `\sigma `, and *atom_mass * :math: `m` must be provided as lists
112
112
where the elements have no units, kcal/mol, angstrom, and g/mol units,
113
113
respectively. The units will be enforced with the |Pint | unit registry, *ureg *,
114
- which must also be provided as a parameter.
114
+ which must also be provided as a parameter (more details later) .
115
115
116
116
.. |Pint | raw :: html
117
117
@@ -124,17 +124,17 @@ of positional and keyword arguments, respectively.
124
124
Calculate LJ units prefactors
125
125
-----------------------------
126
126
127
- Within the *Prepare * class, let us create a method called *calculate_LJunits_prefactors *
128
- that will be used to calculate the prefactors necessary to convert units from the * real *
129
- unit system to the *LJ * unit system:
127
+ Within the *Prepare * class, create a method called *calculate_LJunits_prefactors *
128
+ that will be used to calculate the prefactors necessary to convert units from the
129
+ * real * unit system to the *LJ * unit system:
130
130
131
131
.. label :: start_Prepare_class
132
132
133
133
.. code-block :: python
134
134
135
135
def calculate_LJunits_prefactors (self ):
136
136
""" Calculate the Lennard-Jones units prefactors."""
137
- # First define constants
137
+ # First define Boltzmann and Avogadro constants
138
138
kB = cst.Boltzmann* cst.Avogadro/ cst.calorie/ cst.kilo # kcal/mol/K
139
139
kB *= self .ureg.kcal/ self .ureg.mol/ self .ureg.kelvin
140
140
Na = cst.Avogadro/ self .ureg.mol
@@ -157,22 +157,24 @@ unit system to the *LJ* unit system:
157
157
# Calculate the prefactor for the pressure (in Atmosphere)
158
158
self .ref_pressure = (self .ref_energy \
159
159
/ self .ref_length** 3 / Na).to(self .ureg.atmosphere)
160
- # Regroup all the reference quantities in list, for practicality
160
+ # Group all the reference quantities into a list for practicality
161
161
self .ref_quantities = [self .ref_length, self .ref_energy,
162
162
self .ref_mass, self .ref_time, self .ref_pressure, self .ref_temperature]
163
163
self .ref_units = [ref.units for ref in self .ref_quantities]
164
164
165
165
.. label :: end_Prepare_class
166
166
167
- This method defines the reference distance as the first element in the
168
- *sigma * list, i.e., :math: `\sigma _{11 }`. Therefore, atoms of type one will
169
- always be used for the normalization. Similarly, the first element
170
- in the *epsilon * list (:math: `\epsilon _{11 }`) is used as the reference energy,
171
- and the first element in the *atom_mass * list (:math: `m_1 `) is used as the
172
- reference mass. Then, the reference_time in femtoseconds is calculated
173
- as :math: `\sqrt {m_1 \sigma _{11 }^2 / \epsilon _{11 }}`, the reference temperature
174
- in Kelvin as :math: `\epsilon _{11 } / k_\text {B}`, and the reference_pressure
175
- in atmospheres is calculated as :math: `\epsilon _{11 }/\sigma _{11 }^3 `.
167
+ This method defines the reference length as the first element in the
168
+ *sigma * list, i.e., :math: `\sigma _{11 }`. Therefore, atoms of type 1 will
169
+ always be used for normalization. Similarly, the first element in the
170
+ *epsilon * list (:math: `\epsilon _{11 }`) is used as the reference energy, and
171
+ the first element in the *atom_mass * list (:math: `m_1 `) is used as the
172
+ reference mass.
173
+
174
+ The reference time in femtoseconds is then calculated as
175
+ :math: `\sqrt {m_1 \sigma _{11 }^2 / \epsilon _{11 }}`, the reference
176
+ temperature in Kelvin as :math: `\epsilon _{11 } / k_\text {B}`, and the
177
+ reference pressure in atmospheres as :math: `\epsilon _{11 } / \sigma _{11 }^3 `.
176
178
177
179
Finally, let us ensure that the *calculate_LJunits_prefactors * method is
178
180
called systematically by adding the following line to the *__init__() * method:
@@ -233,11 +235,11 @@ class:
233
235
234
236
.. label :: end_Prepare_class
235
237
236
- The index * 0 * is used to differentiate this method from other methods that
237
- will be used to nondimensionalize units in future classes. We anticipate that
238
- * epsilon *, * sigma *, and * atom_mass * may contain more than one element, so
239
- each element is normalized with the corresponding reference value. The
240
- * zip() * function allows us to loop over all three lists at once .
238
+ When a * quantities_to_normalise * list containing parameter names is provided
239
+ to the * nondimensionalize_units * method, a loop is performed over all the
240
+ quantities. The value of each quantity is extracted using * getattr *. The units
241
+ of the quantity of interest are then detected and normalized by the appropriate
242
+ reference quantities defined by * calculate_LJunits_prefactors * .
241
243
242
244
Let us also call the *nondimensionalize_units * from the *__init__() * method
243
245
of the *Prepare * class:
@@ -253,22 +255,25 @@ of the *Prepare* class:
253
255
254
256
.. label :: end_Prepare_class
255
257
256
- Identify atom properties
258
+ Here, the *epsilon *, *sigma *, and *atom_mass * parameters will be
259
+ nondimensionalized.
260
+
261
+ Identify Atom Properties
257
262
------------------------
258
263
259
264
Anticipating the future use of multiple atom types, where each type will be
260
265
associated with its own :math: `\sigma `, :math: `\epsilon `, and :math: `m`, let
261
266
us create arrays containing the properties of each atom in the simulation. For
262
- instance, in the case of a simulation with two atoms of type 1 and three atoms
263
- of type 2, the corresponding *atoms_sigma * array will be:
267
+ instance, in a simulation with two atoms of type 1 and three atoms of type 2,
268
+ the corresponding *atoms_sigma * array will be:
264
269
265
270
.. math ::
266
271
267
272
\text {atoms_sigma} = [\sigma _{11 }, \sigma _{11 }, \sigma _{22 }, \sigma _{22 }, \sigma _{22 }]
268
273
269
274
where :math: `\sigma _{11 }` and :math: `\sigma _{22 }` are the sigma values for
270
- atoms of type 1 and 2, respectively. The *atoms_sigma * array will allow for
271
- future calculations of force .
275
+ atoms of type 1 and 2, respectively. The *atoms_sigma * array will facilitate
276
+ future calculations of forces .
272
277
273
278
Create a new method called *identify_atom_properties *, and place it
274
279
within the *Prepare * class:
@@ -318,7 +323,8 @@ Test the code
318
323
319
324
Let's test the *Prepare * class to make sure that it does what is expected.
320
325
Here, a system containing 2 atoms of type 1, and 3 atoms of type 2 is
321
- prepared. LJs parameters and masses for each groups are also defined.
326
+ prepared. LJs parameters and masses for each groups are also defined, and given
327
+ physical units thanks to the *UnitRegistry * of Pint.
322
328
323
329
.. label :: start_test_2a_class
324
330
@@ -351,7 +357,8 @@ prepared. LJs parameters and masses for each groups are also defined.
351
357
def test_atoms_epsilon ():
352
358
expected = np.array([1 ., 1 ., 2 ., 2 ., 2 .])
353
359
result = prep.atoms_epsilon
354
- assert np.array_equal(result, expected), f " Test failed: { result} != { expected} "
360
+ assert np.array_equal(result, expected), \
361
+ f " Test failed: { result} != { expected} "
355
362
print (" Test passed" )
356
363
357
364
# In the script is launched with Python, call Pytest
@@ -361,5 +368,6 @@ prepared. LJs parameters and masses for each groups are also defined.
361
368
362
369
.. label :: end_test_2a_class
363
370
364
- This test assert that the generated *atoms_epsilon * array is consistent with
365
- its expected value (see the previous paragraphs).
371
+ This test asserts that the generated *atoms_epsilon * array is consistent
372
+ with its expected value (see the previous paragraphs). Note that the expected
373
+ values are in LJ units, i.e., they have been nondimensionalized by :math: `\epsilon _1 `.
0 commit comments