Skip to content

Commit 1b12e2e

Browse files
Merge pull request #20 from KennethQNgo/main
Reviewed final chapters
2 parents 57a57a9 + 66de8fc commit 1b12e2e

File tree

4 files changed

+88
-10
lines changed

4 files changed

+88
-10
lines changed

Diff for: docs/source/chapters/chapter6.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. _chapter6-label:
22

3-
Monte Carlo dispace
4-
===================
3+
Monte Carlo displace
4+
====================
55

66
.. figure:: ../projects/project1/avatar-dm.webp
77
:alt: The fluid made of argon atoms and simulated using monte carlo and python.
@@ -16,7 +16,7 @@ Monte Carlo dispace
1616
:class: only-light
1717

1818
Here, a Monte Carlo simulation is implemented where the only allowed move
19-
is a dispacement of the particles. The principle of such Monte Carlo
19+
is a displacement of the particles. The principle of such Monte Carlo
2020
simulation is the following:
2121

2222
- 1) We start from a given intial configuration, and measure the potential

Diff for: docs/source/chapters/chapter8.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Let us also normalize the "desired_mu":
175175

176176
.. code-block:: python
177177
178-
class MonteCarlo(Outputs):
178+
class MonteCarlo(Measurements):
179179
def __init__(self,
180180
(...)
181181
self.nondimensionalize_units(["desired_temperature", "displace_mc"])
@@ -238,7 +238,7 @@ Test the code
238238
One can use a similar test as previously, but with an imposed chemical
239239
potential *desired_mu*:
240240

241-
.. label:: start_test_9a_class
241+
.. label:: start_test_8a_class
242242

243243
.. code-block:: python
244244
@@ -297,7 +297,7 @@ potential *desired_mu*:
297297
# Run pytest programmatically
298298
pytest.main(["-s", __file__])
299299
300-
.. label:: end_test_9a_class
300+
.. label:: end_test_8a_class
301301

302302
The evolution of the potential energy as a function of the
303303
number of steps is written in the *Outputs/Epot.dat*.

Diff for: docs/source/chapters/chapter9.rst

+81-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Let us initialise swap counter:
7676

7777
.. code-block:: python
7878
79-
class MonteCarlo(Outputs):
79+
class MonteCarlo(Measurements):
8080
def __init__(self,
8181
(...)
8282
self.failed_move = 0
@@ -91,7 +91,7 @@ Complete the *__init__* method as follows:
9191

9292
.. code-block:: python
9393
94-
class MonteCarlo(Outputs):
94+
class MonteCarlo(Measurements):
9595
def __init__(self,
9696
(...)
9797
displace_mc = None,
@@ -105,7 +105,7 @@ and
105105

106106
.. code-block:: python
107107
108-
class MonteCarlo(Outputs):
108+
class MonteCarlo(Measurements):
109109
def __init__(self,
110110
(...)
111111
self.displace_mc = displace_mc
@@ -125,3 +125,81 @@ Finally, the *monte_carlo_exchange()* method must be included in the run:
125125
self.monte_carlo_swap()
126126
127127
.. label:: end_MonteCarlo_class
128+
129+
Test the code
130+
-------------
131+
132+
Let's test the Monte Carlo swap.
133+
134+
.. label:: start_test_9a_class
135+
136+
.. code-block:: python
137+
138+
from MonteCarlo import MonteCarlo
139+
from pint import UnitRegistry
140+
ureg = UnitRegistry()
141+
import os
142+
143+
# Define atom number of each group
144+
nmb_1 = 50
145+
nmb_2 = 50 # New group for testing swaps
146+
# Define LJ parameters (sigma)
147+
sig_1 = 3 * ureg.angstrom
148+
sig_2 = 4 * ureg.angstrom # Different sigma for group 2
149+
# Define LJ parameters (epsilon)
150+
eps_1 = 0.1 * ureg.kcal / ureg.mol
151+
eps_2 = 0.15 * ureg.kcal / ureg.mol # Different epsilon for group 2
152+
# Define atom mass
153+
mss_1 = 10 * ureg.gram / ureg.mol
154+
mss_2 = 12 * ureg.gram / ureg.mol # Different mass for group 2
155+
# Define box size
156+
L = 20 * ureg.angstrom
157+
# Define a cut off
158+
rc = 2.5 * sig_1
159+
# Pick the desired temperature
160+
T = 300 * ureg.kelvin
161+
162+
# Initialize the prepare object
163+
mc = MonteCarlo(
164+
ureg=ureg,
165+
maximum_steps=100,
166+
thermo_period=10,
167+
dumping_period=10,
168+
number_atoms=[nmb_1, nmb_2], # Include two groups of atoms for swap
169+
epsilon=[eps_1, eps_2], # kcal/mol
170+
sigma=[sig_1, sig_2], # A
171+
atom_mass=[mss_1, mss_2], # g/mol
172+
box_dimensions=[L, L, L], # A
173+
cut_off=rc,
174+
thermo_outputs="Epot-press",
175+
desired_temperature=T, # K
176+
neighbor=1,
177+
swap_type=[0, 1] # Enable Monte Carlo swap between groups 1 and 2
178+
)
179+
180+
# Run the Monte Carlo simulation
181+
mc.run()
182+
183+
# Test function using pytest
184+
def test_output_files():
185+
assert os.path.exists("Outputs/dump.mc.lammpstrj"), \
186+
"Test failed: dump file was not created"
187+
assert os.path.exists("Outputs/simulation.log"), \
188+
"Test failed: log file was not created"
189+
print("Test passed")
190+
191+
# Test the swap counters
192+
def test_swap_counters():
193+
assert mc.successful_swap + mc.failed_swap > 0, \
194+
"Test failed: No swaps were attempted"
195+
print("Swap test passed")
196+
197+
# If the script is run directly, execute the tests
198+
if __name__ == "__main__":
199+
import pytest
200+
# Run pytest programmatically
201+
pytest.main(["-s", __file__])
202+
203+
.. label:: end_test_9a_class
204+
205+

Diff for: docs/source/projects/project1.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ at the same time (if your computer has enough CPU core, if not, perform these
261261
calculations in serial):
262262

263263
.. code-block:: python
264-
A
264+
265265
if __name__ == "__main__":
266266
tau_values = np.round(np.logspace(-0.126, 0.882, 10),2)
267267
pool = multiprocessing.Pool()

0 commit comments

Comments
 (0)