Skip to content

Commit ff91e21

Browse files
committed
simplify force definitino and fix tests
1 parent 476926f commit ff91e21

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

docs/source/chapters/chapter4.rst

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ Compute_potential
264264
Computing the potential energy of the system is central to the energy minimizer,
265265
as the value of the potential is used to decide if the trial is accepted or
266266
rejected. Add the following method called *compute_potential()* to the *Utilities*
267-
class.
267+
class:
268268

269269
.. label:: start_Utilities_class
270270

@@ -289,6 +289,10 @@ class.
289289
290290
.. label:: end_Utilities_class
291291

292+
Measuring the distance is an important step of computing the potential. Let us
293+
do it using a dedicated method. Add the following method to the *Utilities*
294+
class as well:
295+
292296
.. label:: start_Utilities_class
293297

294298
.. code-block:: python
@@ -308,6 +312,10 @@ class.
308312
309313
.. label:: end_Utilities_class
310314

315+
Finally, the energy minimization requires the computation of the minimum
316+
force in the system. Although not very different from the potential measurement,
317+
let us create a new method that is dedicated solely to measuring forces:
318+
311319
.. label:: start_Utilities_class
312320

313321
.. code-block:: python
@@ -345,11 +353,10 @@ class.
345353
346354
.. label:: end_Utilities_class
347355

348-
Here, the method is a little bit complicated, because three types of outputs can
349-
be requested by the user: *force-vector*, *force-matrix*, and *potential*. The last
350-
one, *potential*, simply returns the value of the potential energy for the entire system.
351-
If *force-vector* or *force-matrix* are selected instead, then the individual forces
352-
between atoms are returned.
356+
Here, two types of outputs can
357+
be requested by the user: *force-vector*, and *force-matrix*.
358+
The *force-matrix* option will be useful for pressure calculation, see
359+
:ref:`chapter7-label`.
353360

354361
Wrap in box
355362
-----------

docs/source/chapters/chapter5.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ All quantities are re-dimensionalized before getting outputed.
8484
if code.thermo_period is not None:
8585
if code.step % code.thermo_period == 0:
8686
if code.step == 0:
87-
Epot = code.compute_potential(output="potential") \
87+
Epot = code.compute_potential() \
8888
* code.reference_energy # kcal/mol
8989
else:
9090
Epot = code.Epot * code.reference_energy # kcal/mol

docs/source/chapters/chapter6.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Let us add a method named *monte_carlo_move* to the *MonteCarlo* class:
5050
try: # try using the last saved Epot, if it exists
5151
initial_Epot = self.Epot
5252
except: # If self.Epot does not exists yet, calculate it
53-
initial_Epot = self.compute_potential(output="potential")
53+
initial_Epot = self.compute_potential()
5454
# Make a copy of the initial atoms positions
5555
initial_positions = copy.deepcopy(self.atoms_positions)
5656
# Pick an atom id randomly
@@ -63,7 +63,7 @@ Let us add a method named *monte_carlo_move* to the *MonteCarlo* class:
6363
move = np.append((np.random.random(2) - 0.5) * self.displace_mc, 0)
6464
self.atoms_positions[atom_id] += move
6565
# Measure the optential energy of the new configuration
66-
trial_Epot = self.compute_potential(output="potential")
66+
trial_Epot = self.compute_potential()
6767
# Evaluate whether the new configuration should be kept or not
6868
beta = 1/self.desired_temperature
6969
delta_E = trial_Epot-initial_Epot

docs/source/chapters/chapter7.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Let us add the following method to the *Utilities* class.
4949
temperature = self.desired_temperature # for MC, simply use the desired temperature
5050
p_ideal = Ndof*temperature/(volume*self.dimensions)
5151
# Compute the non-ideal contribution
52-
distances_forces = np.sum(self.compute_potential(output="force-matrix")*self.evaluate_rij_matrix())
52+
distances_forces = np.sum(self.compute_force(return_vector = False)*self.evaluate_rij_matrix())
5353
p_nonideal = distances_forces/(volume*self.dimensions)
5454
# Final pressure
5555
self.pressure = p_ideal+p_nonideal

tests/build-documentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
os.mkdir("generated-codes/")
1919

2020
# loop on the different chapter
21-
for chapter_id in [1, 2, 3, 4]: #, 5, 6, 7]:
21+
for chapter_id in [1, 2, 3, 4, 5, 6, 7]:
2222
# for each chapter, create the corresponding code
2323
RST_EXISTS, created_tests, folder = sphinx_to_python(path_to_docs, chapter_id)
2424
if RST_EXISTS:

0 commit comments

Comments
 (0)