Skip to content

Commit 042742f

Browse files
committed
fixed Monte Carlo units import
1 parent 199a099 commit 042742f

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

docs/source/chapters/chapter4.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,9 @@ Then, let us fill the *__init__()* method:
6868
class MinimizeEnergy(Measurements):
6969
def __init__(self,
7070
maximum_steps,
71-
thermo_outputs="MaxF",
7271
*args,
7372
**kwargs):
7473
self.maximum_steps = maximum_steps
75-
self.thermo_outputs = thermo_outputs
7674
super().__init__(*args, **kwargs)
7775
7876
.. label:: end_MinimizeEnergy_class

docs/source/chapters/chapter5.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ All quantities are re-dimensionalized before getting outputed.
9696
elif code.thermo_outputs == "Epot-press":
9797
logger.info(f"step Epot press")
9898
if code.thermo_outputs == "Epot":
99-
logger.info(f"{code.step} {Epot:.2f}")
99+
logger.info(f"{code.step} {Epot.magnitude:.2f}")
100100
elif code.thermo_outputs == "Epot-MaxF":
101-
logger.info(f"{code.step} {Epot:.2f} {code.MaxF:.2f}")
101+
logger.info(f"{code.step} {Epot.magnitude:.2f} {code.MaxF:.2f}")
102102
elif code.thermo_outputs == "Epot-press":
103103
code.calculate_pressure()
104104
press = code.pressure * code.ref_pressure # Atm
105-
logger.info(f"{code.step} {Epot:.2f} {press:.2f}")
105+
logger.info(f"{code.step} {Epot.magnitude:.2f} {press.magnitude:.2f}")
106106
107107
.. label:: end_logger_class
108108

docs/source/chapters/chapter6.rst

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,17 @@ Let us add a method named *monte_carlo_move* to the *MonteCarlo* class:
4949
if self.displace_mc is not None: # only trigger if displace_mc was provided by the user
5050
# If needed, recalculate neighbor/coeff lists
5151
self.update_neighbor_lists()
52-
self.identify_atom_properties()
5352
self.update_cross_coefficients()
54-
try: # try using the last saved Epot, if it exists
55-
initial_Epot = self.Epot
56-
except: # If self.Epot does not exists yet, calculate it
57-
initial_Epot = self.compute_potential()
53+
if hasattr(self, 'Epot') is False: # If self.Epot does not exists yet, calculate it
54+
self.Epot = self.compute_potential()
55+
initial_Epot = self.Epot
5856
# Make a copy of the initial atoms positions
5957
initial_positions = copy.deepcopy(self.atoms_positions)
6058
# Pick an atom id randomly
61-
atom_id = np.random.randint(self.total_number_atoms)
59+
atom_id = np.random.randint(np.sum(self.number_atoms))
6260
# Move the chosen atom in a random direction
6361
# The maximum displacement is set by self.displace_mc
64-
if self.dimensions == 3:
65-
move = (np.random.random(3)-0.5)*self.displace_mc
66-
elif self.dimensions == 2: # the third value will be 0
67-
move = np.append((np.random.random(2) - 0.5) * self.displace_mc, 0)
62+
move = (np.random.random(3)-0.5)*self.displace_mc
6863
self.atoms_positions[atom_id] += move
6964
# Measure the optential energy of the new configuration
7065
trial_Epot = self.compute_potential()
@@ -76,7 +71,6 @@ Let us add a method named *monte_carlo_move* to the *MonteCarlo* class:
7671
if random_number <= acceptation_probability: # Accept new position
7772
self.Epot = trial_Epot
7873
else: # Reject new position
79-
self.Epot = initial_Epot
8074
self.atoms_positions = initial_positions # Revert to initial positions
8175
8276
.. label:: end_MonteCarlo_class
@@ -98,13 +92,11 @@ and the desired temperature (:math:`T`). Let us add these parameters to the
9892
maximum_steps,
9993
desired_temperature,
10094
displace_mc = None,
101-
thermo_outputs = "press",
10295
*args,
10396
**kwargs):
10497
self.maximum_steps = maximum_steps
10598
self.displace_mc = displace_mc
10699
self.desired_temperature = desired_temperature
107-
self.thermo_outputs = thermo_outputs
108100
super().__init__(*args, **kwargs)
109101
self.nondimensionalize_units(["desired_temperature", "displace_mc"])
110102
@@ -193,6 +185,8 @@ One can use a similar test as previously. Let us use a displace distance of
193185
rc = 2.5*sig_1
194186
# Pick the desired temperature
195187
T = 300*ureg.kelvin
188+
# choose the displace_mc
189+
displace_mc = sig_1/4
196190
197191
# Initialize the prepare object
198192
mc = MonteCarlo(
@@ -208,6 +202,8 @@ One can use a similar test as previously. Let us use a displace distance of
208202
cut_off=rc,
209203
thermo_outputs="Epot",
210204
desired_temperature=T, # K
205+
neighbor=20,
206+
displace_mc = displace_mc,
211207
)
212208
mc.run()
213209

0 commit comments

Comments
 (0)