Skip to content

Commit 199a099

Browse files
committed
continue simplify parameter import
1 parent a612c41 commit 199a099

File tree

6 files changed

+45
-49
lines changed

6 files changed

+45
-49
lines changed

docs/source/chapters/chapter1.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ Within the *InitializeSimulation.py* file, copy the following lines:
167167

168168
.. code-block:: python
169169
170+
import os
170171
import numpy as np
171172
from Prepare import Prepare
172173
from Utilities import Utilities
@@ -298,12 +299,14 @@ and copy the following lines into it:
298299
299300
# Make sure that MonteCarlo correctly inherits from Utilities
300301
def test_montecarlo_inherits_from_utilities():
301-
assert issubclass(MonteCarlo, Utilities), "MonteCarlo should inherit from Utilities"
302+
assert issubclass(MonteCarlo, Utilities), \
303+
"MonteCarlo should inherit from Utilities"
302304
print("MonteCarlo correctly inherits from Utilities")
303305
304306
# Make sure that Utilities does not inherit from MonteCarlo
305307
def test_utilities_does_not_inherit_from_montecarlo():
306-
assert not issubclass(Utilities, MonteCarlo), "Utilities should not inherit from MonteCarlo"
308+
assert not issubclass(Utilities, MonteCarlo), \
309+
"Utilities should not inherit from MonteCarlo"
307310
print("Utilities does not inherit from MonteCarlo, as expected")
308311
309312
# In the script is launched with Python, call Pytest

docs/source/chapters/chapter2.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ unit system to the *LJ* unit system:
163163
/self.ref_length**3/Na).to(self.ureg.atmosphere)
164164
# Regroup all the reference quantities in list, for practicality
165165
self.ref_quantities = [self.ref_length, self.ref_energy,
166-
self.ref_mass, self.ref_time, self.ref_pressure]
166+
self.ref_mass, self.ref_time, self.ref_pressure, self.ref_temperature]
167167
self.ref_units = [ref.units for ref in self.ref_quantities]
168168
169169
.. label:: end_Prepare_class

docs/source/chapters/chapter4.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,10 @@ Then, let us fill the *__init__()* method:
6969
def __init__(self,
7070
maximum_steps,
7171
thermo_outputs="MaxF",
72-
data_folder="Outputs/",
7372
*args,
7473
**kwargs):
7574
self.maximum_steps = maximum_steps
7675
self.thermo_outputs = thermo_outputs
77-
self.data_folder = data_folder
78-
if os.path.exists(self.data_folder) is False:
79-
os.mkdir(self.data_folder)
8076
super().__init__(*args, **kwargs)
8177
8278
.. label:: end_MinimizeEnergy_class

docs/source/chapters/chapter5.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ parameters are passed the InitializeSimulation method:
208208
thermo_period = None,
209209
dumping_period = None,
210210
thermo_outputs = None,
211+
data_folder="Outputs/",
211212
212213
.. label:: end_InitializeSimulation_class
213214

@@ -221,6 +222,9 @@ parameters are passed the InitializeSimulation method:
221222
self.thermo_period = thermo_period
222223
self.dumping_period = dumping_period
223224
self.thermo_outputs = thermo_outputs
225+
self.data_folder = data_folder
226+
if os.path.exists(self.data_folder) is False:
227+
os.mkdir(self.data_folder)
224228
225229
.. label:: end_InitializeSimulation_class
226230

docs/source/chapters/chapter6.rst

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -96,44 +96,17 @@ and the desired temperature (:math:`T`). Let us add these parameters to the
9696
class MonteCarlo(Measurements):
9797
def __init__(self,
9898
maximum_steps,
99-
cut_off = 9,
99+
desired_temperature,
100100
displace_mc = None,
101-
neighbor = 1,
102-
desired_temperature = 300,
103101
thermo_outputs = "press",
104-
data_folder = None,
105102
*args,
106103
**kwargs):
107104
self.maximum_steps = maximum_steps
108-
self.cut_off = cut_off
109105
self.displace_mc = displace_mc
110-
self.neighbor = neighbor
111106
self.desired_temperature = desired_temperature
112107
self.thermo_outputs = thermo_outputs
113-
self.data_folder = data_folder
114-
if self.data_folder is not None:
115-
if os.path.exists(self.data_folder) is False:
116-
os.mkdir(self.data_folder)
117108
super().__init__(*args, **kwargs)
118-
self.nondimensionalize_units_3()
119-
120-
.. label:: end_MonteCarlo_class
121-
122-
Here, we anticipate that some of the parameters have to be nondimensionalized, which
123-
is done with the *nondimensionalize_units_3* method that must also be added to
124-
the *MonteCarlo* class:
125-
126-
.. label:: start_MonteCarlo_class
127-
128-
.. code-block:: python
129-
130-
def nondimensionalize_units_3(self):
131-
"""Use LJ prefactors to convert units into non-dimensional."""
132-
self.cut_off = self.cut_off/self.reference_distance
133-
self.desired_temperature = self.desired_temperature \
134-
/self.reference_temperature
135-
if self.displace_mc is not None:
136-
self.displace_mc /= self.reference_distance
109+
self.nondimensionalize_units(["desired_temperature", "displace_mc"])
137110
138111
.. label:: end_MonteCarlo_class
139112

@@ -201,21 +174,41 @@ One can use a similar test as previously. Let us use a displace distance of
201174

202175
.. code-block:: python
203176
204-
import os
205177
from MonteCarlo import MonteCarlo
178+
from pint import UnitRegistry
179+
ureg = UnitRegistry()
180+
import os
206181
207-
mc = MonteCarlo(maximum_steps=1000,
208-
dumping_period=100,
182+
# Define atom number of each group
183+
nmb_1= 50
184+
# Define LJ parameters (sigma)
185+
sig_1 = 3*ureg.angstrom
186+
# Define LJ parameters (epsilon)
187+
eps_1 = 0.1*ureg.kcal/ureg.mol
188+
# Define atom mass
189+
mss_1 = 10*ureg.gram/ureg.mol
190+
# Define box size
191+
L = 20*ureg.angstrom
192+
# Define a cut off
193+
rc = 2.5*sig_1
194+
# Pick the desired temperature
195+
T = 300*ureg.kelvin
196+
197+
# Initialize the prepare object
198+
mc = MonteCarlo(
199+
ureg = ureg,
200+
maximum_steps=1000,
209201
thermo_period=100,
210-
thermo_outputs = "Epot",
211-
displace_mc = 0.5,
212-
number_atoms=[50],
213-
epsilon=[0.1], # kcal/mol
214-
sigma=[3], # A
215-
atom_mass=[10], # g/mol
216-
box_dimensions=[20, 20, 20], # A
217-
data_folder="Outputs/",
218-
)
202+
dumping_period=100,
203+
number_atoms=[nmb_1],
204+
epsilon=[eps_1], # kcal/mol
205+
sigma=[sig_1], # A
206+
atom_mass=[mss_1], # g/mol
207+
box_dimensions=[L, L, L], # A
208+
cut_off=rc,
209+
thermo_outputs="Epot",
210+
desired_temperature=T, # K
211+
)
219212
mc.run()
220213
221214
.. label:: end_test_6a_class

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]:
21+
for chapter_id in [1, 2, 3, 4, 5, 6]:
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)