@@ -76,7 +76,7 @@ Let us initialise swap counter:
76
76
77
77
.. code-block :: python
78
78
79
- class MonteCarlo (Outputs ):
79
+ class MonteCarlo (Measurements ):
80
80
def __init__ (self ,
81
81
(...)
82
82
self .failed_move = 0
@@ -91,7 +91,7 @@ Complete the *__init__* method as follows:
91
91
92
92
.. code-block :: python
93
93
94
- class MonteCarlo (Outputs ):
94
+ class MonteCarlo (Measurements ):
95
95
def __init__ (self ,
96
96
(...)
97
97
displace_mc = None ,
105
105
106
106
.. code-block :: python
107
107
108
- class MonteCarlo (Outputs ):
108
+ class MonteCarlo (Measurements ):
109
109
def __init__ (self ,
110
110
(...)
111
111
self .displace_mc = displace_mc
@@ -125,3 +125,81 @@ Finally, the *monte_carlo_exchange()* method must be included in the run:
125
125
self .monte_carlo_swap()
126
126
127
127
.. 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
+
0 commit comments