Monte Carlo exploration
Monte Carlo exploration
A. Monte-Carlo exploration
This loads the global configuration from the global.json file of the parent directory.
import deMonPy
deMonPy.configure_from_file("../global.json")
This reads the MOLECULES data file that defines the cluster: WAT keeps the first molecule and BZZ the second.
from deMonPy.molden import read_XYZ
images, comm = read_XYZ("./data/MOLECULES")
WAT = images[0]
BZZ = images[1]
This defines the Monte Carlo calculation of the WAT-BZZ-WAT cluster: the molecule types are declared with MOLECULES and placed with QUATERNION, each molecule being a rigid body characterized by its center of mass and its orientation, at the SCC-DFTB level with the DISP=2 dispersion correction. The PTMC module runs 100 Monte Carlo steps at 300 K (TMC) with a single replica (NTEMP=1), i.e. without parallel tempering.
import copy
import shutil
import numpy as np
from deMonPy.deMonNano import deMonNano
WORKDIR = ".run/tutorial-5/A/"
parameters_ptmc = {
"DEMON_EXECUTABLE": EXECUTABLE,
"BASIS": {"PTYPE": "MAT", "SKFILE": BASIS},
"DEMON_PARAMETERS": {
"ACTIVE": {
"DFTB": {"SCC": True, "DISP": 2},
"MOLECULES": {"NAMES": ["WAT", "BZZ", "WAT"]},
"QUATERNION": {
"RIGID": True,
"COORDS": np.array(
[
[1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
[0.0, -3.0, 0.0, 0.7, 0.7, 0.0, 0.0],
[1.0, -3.0, -4.0, 1.0, 0.0, 0.0, 0.0],
]
),
},
},
},
"DEMON_MODULE": {
"ACTIVE": {
"PTMC": {
"MC": {"MAX": 100, "WALL": 6.0},
"MCTEMP": {
"TMC": 300,
"NTEMP": 1,
},
}
}
},
}
parameters = copy.deepcopy(parameters_ptmc)
dem = deMonNano(title="CALCULATION DEMONANO", workdir=WORKDIR, **(parameters_ptmc.copy()))
# Move MOLECULES from data/ repository
shutil.copy2("./data/MOLECULES", f"{WORKDIR}/MOLECULES")
dem.calculate(
symbols=WAT.symbols, # IGNORE -> MOLECULES
positions=WAT.positions, # IGNORE -> MOLECULES
clean_repository=False,
)
B. Parallel tempering
This reuses the cluster parameters and switches MCTEMP to the parallel-tempering scheme: 10 temperatures between 40 and 300 K on a geometric pattern, 500 Monte Carlo steps, with the swap-debug information printed (SDBG).
WORKDIR = ".run/tutorial-5/B/"
params = parameters.copy()
params["DEMON_MODULE"]["ACTIVE"].update(
{
"PTMC": {
"MC": {"MAX": 500, "WALL": 6.0},
"MCTEMP": {
"GEOM": True,
"NTEMP": 10,
"TEMPMIN": 40,
"TEMPMAX": 300,
"SMOD": 20,
"SDBG": True,
},
}
}
)
dem = deMonNano(title="CALCULATION DEMONANO", workdir=WORKDIR, **params)
# Move MOLECULES from data/ repository
shutil.copy2("./data/MOLECULES", f"{WORKDIR}/MOLECULES")
dem.calculate(
symbols=WAT.symbols, # IGNORE -> MOLECULES
positions=WAT.positions, # IGNORE -> MOLECULES
clean_repository=True,
)
This reads the debug_swap.dat file and plots the temperature of each of the 10 replicas during the run — the evolution shown below.
import os
import matplotlib.pyplot as plt
src = os.path.join(WORKDIR, "debug_swap.dat")
with open(src, "r") as fd:
lines = fd.readlines()
table = []
for line in lines:
table.append([float(l) for l in line.split()])
table = np.array(table)
for i in range(1, 11):
plt.plot(table[:, i])
plt.show()
Evolution of the 10 temperatures during the Monte Carlo parallel tempering of the WAT-BZZ-WAT cluster (debug_swap.dat).
C. MEMO-SCC parallel tempering
Same parallel-tempering scheme as in section B, with the swap probability controlled by SPERCENT (here 100 %) instead of the SMOD step count.
WORKDIR = ".run/tutorial-5/C/"
params = parameters.copy()
params["DEMON_MODULE"]["ACTIVE"].update(
{
"PTMC": {
"MC": {"MAX": 500, "WALL": 6.0},
"MCTEMP": {
"GEOM": True,
"NTEMP": 10,
"TEMPMIN": 40,
"TEMPMAX": 300,
"SMOD": 7,
"SPERCENT": 100,
},
}
}
)
dem = deMonNano(title="CALCULATION DEMONANO", workdir=WORKDIR, **params)
# Move MOLECULES from data/ repository
shutil.copy2("./data/MOLECULES", f"{WORKDIR}/MOLECULES")
dem.calculate(
symbols=WAT.symbols, # IGNORE -> MOLECULES
positions=WAT.positions, # IGNORE -> MOLECULES
clean_repository=True,
)
Next steps
This is the last tutorial of the series. To revisit the environment setup, see the DeMonNanoPy Quickstart; the MONTECARLO and MCTEMP keyword pages document the Monte Carlo and parallel-tempering options used here, and the DeMonNanoPy Examples section shows shorter standalone calculations.