Example 4 — QMMM: glycine + 3 water
QMMM single point + optimization of glycine solvated in 3 water molecules. Glycine (10 atoms) is the QM region (DFTB, 3OB basis), the 3 water molecules (9 atoms) are the MM region (OPLS-AA force field), with electrostatic coupling.
Prerequisites: a deMonNano installation + global.json (see the
DeMonNanoPy Quickstart page).
Run with:
python3 example_qmmm.py <3OB-basis-directory> <path-to-FFDS>
Requires a 3OB Slater-Koster parameters directory and an OPLS-AA
FFDS file, e.g. the DeMonNanoPy example/data_test/FFDS-OPLS.
The code below is the full script, split by part. Runnable version: demonnano/examples/example_qmmm.py.
System: glycine + 3 water
Glycine (10 atoms) is the QM region (DFTB, 3OB basis), the 3 water molecules (9 atoms) are the MM region (OPLS-AA force field), with electrostatic coupling. The geometry comes from the DeMonNanoPy test set (glycine solvated in water), reduced to 3 waters. The slice defines the 19 atomic symbols (glycine first, then the three waters), their positions, and the per-atom partial charges taken from the mb6 table.
"""QMMM single point + optimization of glycine solvated in 3 water molecules.
Glycine (10 atoms) is the QM region (DFTB, 3OB basis), the 3 water molecules
(9 atoms) are the MM region (OPLS-AA force field), with electrostatic
coupling. The geometry comes from the DeMonNanoPy test set
(glycine solvated in water), reduced to 3 waters.
Run with:
python3 example_qmmm.py <3OB-basis-directory> <path-to-FFDS-file>
Requires a deMonNano installation and a global.json file (see the
DeMonNanoPy README).
"""
import shutil
import sys
from pathlib import Path
import numpy as np
import deMonPy
from deMonPy.deMonNano import deMonNano
deMonPy.configure_from_file("global.json")
WORKDIR = ".run/example-qmmm"
symbols = ["O", "O", "C", "N", "H", "H", "C", "H", "H", "H"] + ["O", "H", "H"] * 3
# Glycine + 3 waters, from DeMonNanoPy test/data_test/qmmm/mb6 (lines 1-19)
positions = np.array(
[
[2.210390, -1.892224, -0.600702],
[1.872993, -2.139475, 1.602119],
[1.668122, -1.474914, 0.491786],
[0.922634, 0.426967, -0.819990],
[-0.145946, -0.394692, 0.875462],
[1.398432, 0.454654, 1.260187],
[0.871350, -0.190766, 0.506281],
[2.090472, -1.309222, -1.404190],
[1.709055, 1.058352, -0.822536],
[0.120236, 1.044274, -0.946981],
[-7.365167, -5.889925, -6.268144],
[-7.229411, -5.886250, -5.288454],
[-8.235436, -6.302180, -6.336702],
[-6.840293, -6.447978, -3.727011],
[-5.876667, -6.464420, -3.829580],
[-6.911444, -6.543826, -2.754523],
[-6.873193, -6.651091, -1.135000],
[-7.262993, -6.995530, -0.317656],
[-5.914222, -6.644741, -0.930368],
]
)
# Partial charges of the 19 atoms, from the mb6 table (charge column)
charges = np.array(
[
-0.381522, -0.894183, 0.766589, -0.509009, 0.147569,
0.084066, -0.091682, 0.417994, 0.224449, 0.235728,
-0.834, 0.417, 0.417, -0.834, 0.417,
0.417, -0.834, 0.417, 0.417,
]
)
QMMM calculation
Set the QMMM parameters, copy the FFDS file into the working directory, and run the calculation: deMon reads the force-field data file FFDS from the working directory. The third-order correction (3ord_param data file) is omitted to keep the example data-free. The QMMM block selects the electrostatic coupling, the force-field MM charges (CHR=FF), the per-atom OPLS-AA atom types, and the QM (atoms 1-10) and MM (atoms 11-19) regions; DEMON_MODULE adds the geometry optimization (up to 5000 steps), and the final energy is printed in Hartree.
def example_qmmm_glycine(basis_3ob, ffds):
if not Path(basis_3ob).is_dir():
raise SystemExit(f" > 3OB basis directory not found : {basis_3ob}")
if not Path(ffds).is_file():
raise SystemExit(f" > FFDS file not found : {ffds}")
parameters = {
"BASIS": {"PTYPE": "3OB", "SKFILE": basis_3ob},
"DEMON_PARAMETERS": {
"ACTIVE": {
"DFTB": {"SCC": True},
"QMMM": {
"COUPLING": "ELECTROSTATIC",
"CHR": "FF",
"CHARGES": charges,
"TYPEMM": [784, 784, 782, 783, 780, 780, 781, 64, 785, 785]
+ [63, 64, 64] * 3,
"QM": "1-10",
"MM": "11-19",
"FORCEFIELD": {"FF": "OPLS-AA"},
},
},
},
"DEMON_MODULE": {
"ACTIVE": {
"OPT": {"MAX": 5000, "TRAJECTORY": True},
},
},
}
# deMon reads the force-field data file FFDS from the working directory
# The third-order correction (3ord_param data file) is omitted to keep the example data-free
mod = deMonNano(title="CALCULATION DEMONANO", workdir=WORKDIR, **parameters)
shutil.copy2(ffds, f"{WORKDIR}/FFDS")
mod.calculate(symbols=symbols, positions=positions)
energy = mod.results["energy"]["energy"]
print(f" > Energy (Hartree) : {energy}")
Command line
The command line expects the 3OB basis directory and the FFDS file path, then runs the QMMM calculation. If the number of arguments is not 2, a usage message ends the run.
if __name__ == "__main__":
if len(sys.argv) != 3:
raise SystemExit(
"Usage: python3 example_qmmm.py <3OB-basis-directory> <path-to-FFDS-file>"
)
example_qmmm_glycine(sys.argv[1], sys.argv[2])
Summary
The script runs the QMMM single point and geometry optimization of glycine (10 atoms, QM region, DFTB with the 3OB basis) solvated in 3 water molecules (9 atoms, MM region, OPLS-AA force field) with electrostatic coupling, in the working directory .run/example-qmmm, using the FFDS file copied into it. The final energy is printed in Hartree.