Skip to content

Examples QM MM with OpenMM

Juvenal Yosa edited this page Nov 30, 2026 · 8 revisions

MOPAC computes the QM region (PM7, MOZYME, with HB-SMOOTH) in the field of the MM charges; OpenMM does everything else (force field, water, constraints, integrator, thermostat, reporters). Requirements: OpenMM ≥ 8.4, NumPy, SciPy, optionally CuPy, and build/libmopac.so from the GPU build. Units in run_qmmm_md.py: --padding in nm, --ron/--roff in Å, --dt in fs. Details: docs/QMMM_OPENMM.md.

Defaults worth knowing:

  • QM regions of up to 20 atoms (link atoms included) run MOPAC on the CPU, larger ones on the GPU; MOPAC_FORCEGPU=1 sends small regions to the GPU too. For 10 QM atoms the CPU was faster (0.022 against 0.033 s per step on an A100 machine).
  • All bonds inside the QM region are free: the force field's constraints between QM atoms are removed. Keep the default time step of 0.5 fs. --qm-constraints keeps the X–H constraints inside the QM region, as Amber's qmshake=1 does; --qm-free E:57:HD1 leaves chosen atoms free all the same.
  • On the CUDA platform OpenMM runs in mixed precision (--precision); its default single precision made the energy drift by itself (+11 kJ/mol/ps for trypsin–BPTI with MM only).
  • --tolerance is MOPAC's relative SCF criterion (default 0.01). For NVE or anything that needs energy conservation use 0.001: at 0.01 the forces are not exact derivatives of the energy and the total energy falls (trypsin–BPTI: −4 to −8 kJ/mol/ps).
  • --guess (previous, linear, aspc) sets where each step's SCF starts; keep the default previous (the LMOs of the last step). The extrapolations halve the SCF iterations, but on the GPU they made the step slower and in NVE runs of trypsin–BPTI they heated the system in episodes (see the guide).

Figures: calculations with the CPU build of v1.2.1-gpu, laptop (Intel Core i7-8850H), one core unless a caption says otherwise, or published numbers where the caption says so. Scripts: scripts/wiki_figures.

53. A side chain as the QM region

run_qmmm_md.py adds hydrogens and a water box, equilibrates the MM system, cuts the QM region (here the side chain of residue 2, with a link atom on CA–CB) and runs NVT. This QM region is under 20 atoms, so MOPAC runs on the CPU; OpenMM still uses the GPU.

python3 scripts/qmmm/run_qmmm_md.py 1UAO_opt.pdb --libmopac build/libmopac.so \
    --qm-residues 2 --qm-sidechain --steps 1000 --dt 0.5 --platform CUDA

Checked: 10 steps plus 10 NVE steps with OpenMM 8.6.1 on its CPU platform (--platform CPU --mm-equil-ps 0.2) and the CPU library of release v1.2-gpu (commit 323b6076); QM region 15 atoms + 1 link atom.

The QM region (thick, orange carbons), and the total energy of the whole system (3 992 atoms) in the NVE check: 200 NVT and 400 NVE steps with MOPAC and OpenMM on the CPU, default --tolerance 0.01

The QM region (thick, orange carbons), and the total energy of the whole system (3 992 atoms) in the NVE check: 200 NVT and 400 NVE steps with MOPAC and OpenMM on the CPU, default --tolerance 0.01. The driver reports a drift of 0.39 kJ/mol over the 400 steps and an rms deviation of 0.80 kJ/mol from a linear fit; docs/QMMM_OPENMM.md explains the sources and recommends 0.001 for NVE.

54. A whole peptide as the QM region, with an NVE check

Residues 1–10 of chignolin (138 QM atoms, about 12 100 atoms in all; on the GPU: 0.031 s per 0.5-fs step on an A100 at --tolerance 0.01, commit e6fddf48). --nve 400 adds 400 NVE steps at the end and reports the energy change; --tolerance 0.001 makes that check meaningful (see the defaults above).

python3 scripts/qmmm/run_qmmm_md.py 1UAO_opt.pdb --libmopac build/libmopac.so \
    --qm-residues 1,2,3,4,5,6,7,8,9,10 --padding 2.5 --ron 6 --roff 8 \
    --tolerance 0.001 --steps 400 --nve 400 --platform CUDA
Whole peptide as QM region: total energy of the whole system (12 095 atoms) in the NVE check after 100 NVT steps, at --tolerance 0.001, MOPAC and OpenMM on the CPU

Whole peptide as QM region: total energy of the whole system (12 095 atoms) in the NVE check after 100 NVT steps, at --tolerance 0.001, MOPAC and OpenMM on the CPU. 200 steps are too few for a drift rate; the driver reports a change of 1.17 kJ/mol and an rms deviation of 1.48 kJ/mol from a linear fit.

55. An enzyme active site with protonation states and distances

Trypsin–BPTI (PDB 2PTC): the side chains of the catalytic triad (E:57:sc = chain E, residue 57, side chain) and two residues of the inhibitor as QM region (54 atoms + 5 link atoms, about 46 900 atoms in all), His57 as HID, and three distances followed during the run. On an A100 a 0.5-fs step took 0.021 s at --tolerance 0.01 and 0.027 s at 0.001 (commit e6fddf48): 1 ns in about 15 hours at 0.001.

wget https://files.rcsb.org/download/2PTC.pdb
python3 scripts/qmmm/run_qmmm_md.py 2PTC.pdb --libmopac build/libmopac.so \
    --qm-residues E:57:sc,E:102:sc,E:195:sc,I:15,I:16 --variants E:57=HID \
    --padding 1.0 --ron 10 --roff 12 --tolerance 0.001 \
    --distances E:195:OG-I:15:C,E:57:NE2-E:195:OG,E:57:HD1-E:102:OD2 \
    --steps 2000 --nve 400 --platform CUDA
The QM region in trypsin–BPTI (PDB 2PTC), and three distances with and without the long-range QM–MM term: means of three 5-ps replicas each

The QM region in trypsin–BPTI (PDB 2PTC), and three distances with and without the long-range QM–MM term: means of three 5-ps replicas each; numbers published in docs/QMMM_OPENMM.md.

56. Long-range QM–MM electrostatics on or off

By default the Mulliken charges of the QM atoms see all MM charges and their periodic images through PME. --no-pme keeps only the switched cut-off; --cutoff-test compares the forces on the QM atoms for several cut-offs on snapshots of the run.

# cut-off only
python3 scripts/qmmm/run_qmmm_md.py 2PTC.pdb --libmopac build/libmopac.so --qm-residues E:57:sc,E:102:sc,E:195:sc,I:15,I:16 --no-pme
# PME, with a force comparison against cut-offs of 8-24 A
python3 scripts/qmmm/run_qmmm_md.py 2PTC.pdb --libmopac build/libmopac.so --qm-residues E:57:sc,E:102:sc,E:195:sc,I:15,I:16 \
    --cutoff-test 8,12,16,20,24 --snapshots 8
Forces on the QM atoms against the cut-off, without and with the long-range term (trypsin–BPTI, 8 snapshots, reference PME at 24 Å)

Forces on the QM atoms against the cut-off, without and with the long-range term (trypsin–BPTI, 8 snapshots, reference PME at 24 Å); numbers published in docs/QMMM_OPENMM.md.

57. QM/MM in your own OpenMM script

add_qmmm turns an OpenMM System into a QM/MM one: it switches off the MM terms inside the QM region, adds link atoms and the MOPAC force. Any OpenMM integrator, thermostat and reporter works with it.

import sys; sys.path.insert(0, "scripts/qmmm")
import openmm as mm, openmm.app as app, openmm.unit as u
from openmm_mopac import add_qmmm

pdb = app.PDBFile("solvated.pdb")
ff = app.ForceField("amber14-all.xml", "amber14/tip3p.xml")
system = ff.createSystem(pdb.topology, nonbondedMethod=app.PME, nonbondedCutoff=1*u.nanometer,
                         constraints=app.HBonds)
qm_atoms = [a.index for a in pdb.topology.atoms() if a.residue.index in (1, 2)]
qmmm = add_qmmm(system, pdb.topology, pdb.positions, qm_atoms, qm_charge=0,
                libmopac="build/libmopac.so", ron=8.0, roff=10.0, tolerance=0.01)
integrator = mm.LangevinMiddleIntegrator(300*u.kelvin, 1/u.picosecond, 0.5*u.femtoseconds)
sim = app.Simulation(pdb.topology, system, integrator, mm.Platform.getPlatformByName("CUDA"))
sim.context.setPositions(pdb.positions)
sim.reporters.append(app.StateDataReporter("log.csv", 10, step=True, potentialEnergy=True, temperature=True))
sim.step(1000)
qmmm.close()
What add_qmmm does to an OpenMM system (scripts/qmmm/openmm_mopac.py).

What add_qmmm does to an OpenMM system (scripts/qmmm/openmm_mopac.py).

58. MM point charges from a file: MM_CHARGES

New keyword. Without OpenMM, a single MOZYME job can be embedded in point charges: one charge per line (x y z q, Å and e) in the file named by MM_CHARGES. Only with MOZYME: without it the job stops with MM_CHARGES AND NO MOZYME. The output says how many charges were read (QM/MM: 3 MM point charges, total charge 0.0000 from 'charges.txt'); a header or comment line in the file ends the list. There is no cut-off and no periodic image, and COSMO does not screen the charges. Full description: MM_CHARGES.

Copy next to the input: tests/data/mozyme_gpu_reference/1UAO_opt.pdb

PM7 MOZYME 1SCF GRADIENTS MM_CHARGES="charges.txt" GEO_DAT="1UAO_opt.pdb"
Chignolin in point charges

charges.txt, for example (a TIP3P water 20 Å from the origin):

  20.0  0.0  0.0  -0.834
  20.6  0.8  0.0   0.417
  20.6 -0.8  0.0   0.417

Checked: runs with the CPU build of release v1.2-gpu (commit 323b6076, 2026-11-20); 3 charges read, MM_GRAD lines for each.

QM/MM electrostatic energy of chignolin with one TIP3P water as point charges at increasing distance (one job per distance).

QM/MM electrostatic energy of chignolin with one TIP3P water as point charges at increasing distance (one job per distance).

59. An enzyme reaction: attack of Ser195 on the substrate in trypsin

The first step of peptide hydrolysis by a serine protease: the OG oxygen of Ser195 adds to the carbonyl carbon of the scissile bond while His57, hydrogen-bonded to Asp102, takes the Ser195 proton. In trypsin–BPTI (PDB 2PTC) the Lys15–Ala16 bond of BPTI sits in the active site the way a substrate's would. scripts/qmmm/qmmm_scan.py maps the potential energy by adiabatic mapping: it prepares the system as run_qmmm_md.py does (example 55), minimizes it with QM/MM (the reactant), then holds two coordinates with harmonic restraints (--k, 2000 kJ/mol/Ų) at the points of a grid and minimizes at each point, starting from the point before:

  • --scan E:195:OG-I:15:C: the OG···C distance, from its value in the reactant to --to in steps of --step;
  • --scan2 E:195:OG-E:195:HG-E:57:NE2: the proton coordinate d(OG–HG) − d(HG–NE2), about −1.1 Å with the proton on Ser195 and +1 Å with it on His57, from --from2 to --to2.
wget https://files.rcsb.org/download/2PTC.pdb
python3 scripts/qmmm/qmmm_scan.py 2PTC.pdb --libmopac build/libmopac.so \
    --qm-residues E:57:sc,E:102:sc,E:195:sc,I:15,I:16 --variants E:57=HID \
    --scan E:195:OG-I:15:C --to 1.45 --step 0.1 \
    --scan2 E:195:OG-E:195:HG-E:57:NE2 --from2 -1.1 --to2 1.1 --step2 0.2 --back --release --hessian \
    --watch E:195:OG-E:195:HG,E:195:HG-E:57:NE2,I:15:C-I:15:O,I:15:C-I:16:N,E:57:HD1-E:102:OD2 \
    --tolerance 0.001 --mm-equil-ps 50 --seed 1 --platform CUDA

Only the residues within 10 Å of the QM region (--free-radius) move; the other atoms stay fixed where the MM preparation left them (an MM minimization, --mm-equil-ps of MD and another MM minimization of the whole system). Every minimization, MM or QM/MM, uses the script's own L-BFGS: no atom moves more than --max-step (0.1 Å) per iteration, the steps are kept on the forces rather than on the energy, and its sums are added in a fixed order, so that one --seed gives the same MM preparation on CUDA. A window has converged when the largest force on a moving atom is below --fmax (10 kJ/mol/nm). The grid is run row by row, in alternating directions. --back then returns to the reactant along the edge of the grid (the rest of the last row when the scan ended at its far end, then the first column), so that the energies there and back at the same targets show how much the map depends on the path. --release removes the two scan restraints and minimizes again from each point of the last row and from each grid point lower than all its neighbours: a structure that stays near where the scan left it lies in a local minimum of the energy, one that moves away does not. The lowest of these structures in the reactant region is the zero of the energies below. --hessian gives the frequencies of the QM atoms, everything else fixed, at each of them. scan.csv has one row per point (targets and values reached, the energy without the restraints, the QM heat, the forces left, the lowest frequencies, the distances of --watch) and scan_frames.pdb the residues within 5 Å of the QM region at each point.

The Colab notebook runs a short test and then the command for five seeds at once, each with its own MM equilibration, and draws the maps. On an NVIDIA L4 each replica took 20–24 minutes of minimization, about 0.12 s per QM/MM evaluation with the five running at once (0.037 s for the test alone), plus 2.4–3.1 minutes of MM preparation. A replica has 120 or 132 grid points, depending on the OG···C distance of its reactant, 9 or 21 on the way back, and 13 or 14 minimizations without the restraints. All 740 minimizations of the five replicas converged, no SCF failed, and every line search kept a step. The test and replica 1, both seed 1, gave the same positions after each of the four steps of the MM preparation.

What the five replicas give:

  • Restraining the OG···C distance alone is not enough: in a one-coordinate scan the proton stayed on Ser195 (HG···NE2 2.1–2.2 Å) down to OG···C 1.62 Å.
  • The minimized reactants have OG···C 2.35–2.40 Å and HG···NE2 2.11–2.30 Å, no imaginary frequency (the lowest 69–79 cm⁻¹), and lie 0.00–0.08 kcal/mol above the lowest structure of their reactant region.
  • Without the attack (first row) the energy rises all the way as the proton moves to His57: 23.8–27.2 kcal/mol at a proton coordinate of +0.44 Å, 40.6–44.5 kcal/mol at +1.05 Å. Bringing OG to 1.56–1.60 Å of the carbon with the proton held on Ser195 (first column) costs 18.6–20.0 kcal/mol.
  • With the proton on Ser195 the adduct is not a minimum. From every point of the last row with a proton coordinate of −0.1 Å or less (six per replica), the minimization without the restraints went back to the reactant region (OG···C 2.34–2.40 Å, within 0.2 kcal/mol of its lowest structure).
  • Replicas 1, 3 and 5 have the tetrahedral adduct with the proton on His57. From the points of the last row with a proton coordinate of +0.3 Å or more (in replicas 3 and 5 from +0.1 Å as well), the structures stayed there without the restraints:
    • geometry: OG···C 1.48–1.57 Å, HG–NE2 1.08–1.14 Å, the carbonyl C–O of Lys15 1.27–1.28 Å (1.24 Å in the reactant), the scissile C–N bond 1.45–1.49 Å (1.37 Å), His57 HD1···Asp102 OD2 1.75–1.80 Å (1.80–1.86 Å in those reactants);
    • no imaginary frequency (the lowest 78–88 cm⁻¹);
    • energy: the lowest adduct lies 23.4, 20.9 and 20.2 kcal/mol above the reactant. The highest point of the lowest path through the grid points into its basin is only 0.3, 0.4 and 0.6 kcal/mol higher (23.7, 21.3 and 20.8 kcal/mol).
  • In replicas 2 and 4 every structure minimized without the restraints went back to the reactant region, also from the points with the proton on His57, and their grids have no local minimum near the adduct either. In these two replicas the adduct is not a minimum.
  • Going there and back changes the energy at the same targets by −0.09 to +0.12 kcal/mol along the first column of all five replicas. Replica 3, whose scan ended at the far end of its last row, came back along that row too. There, at OG···C 1.44–1.47 Å with the proton on His57, beyond its adduct, the way back was 1.64 and 0.64 kcal/mol lower at two points and 0.49 higher at a third. None of these points is on its lowest path.
  • A run on an A100 used the same MOPAC code and QM/MM minimizer (commit d6a5cdb1). Its MM preparation still used OpenMM's minimizer, so its replicas start from other structures. It found the adduct in four of five replicas, at 19.6, 23.0, 18.6 and 22.3 kcal/mol, 0.1–0.8 kcal/mol below the highest point of the lowest path into it. In its replica 3 every structure went back to the reactant.
  • Over the ten replicas of the two runs, seven have the adduct, at 18.6–23.4 kcal/mol (mean 21.1, standard deviation 1.8).

Limits of such a map:

  • Each energy belongs to one minimized structure on one path: no sampling, no entropy, no zero-point energy. The highest point of the path is not a free-energy barrier and cannot be compared directly with a measured rate.
  • The energies, and whether the adduct is a minimum at all, depend on the MM snapshot a replica starts from (three of five and four of five replicas in the two runs above).
  • The QM/MM minimizations are not reproducible to the last digit, because the MOZYME SCF on the GPU is not deterministic (see Running on the GPU). With the same MM preparation, the QM/MM reactants of the test and of replica 1 came out 0.08 kJ/mol apart in total energy and at most 0.021 Å apart in the active site.
  • PM7 for a 54-atom QM region; the map has not been compared with a higher-level method.
  • The restraints do not reach their targets exactly (the map is drawn against the values reached). The grid steps of 0.1 and 0.2 Å place the highest point of a path only to within a step, and the 0.1–0.8 kcal/mol between it and the adduct is measured at that resolution.
  • BPTI is an inhibitor, not a substrate; its Lys15–Ala16 bond is used here because it sits in the active site the way a substrate's would.

Run: the notebook on Colab with an NVIDIA L4 (commit a5569b79, 2026-11-30), seeds 1–5; the A100 run, commit d6a5cdb1 (2026-11-30). The one-coordinate scan: CPU build of v1.2.1-gpu with OpenMM on OpenCL, an earlier version of the script.

Trypsin–BPTI: PM7 QM/MM map of the attack of Ser195 on Lys15 of BPTI, replica 1 of 5, run by the notebook on a Colab L4 GPU (commit a5569b79)

Trypsin–BPTI: PM7 QM/MM map of the attack of Ser195 on Lys15 of BPTI, replica 1 of 5, run by the notebook on a Colab L4 GPU (commit a5569b79). A: the minimized reactant; B: the adduct, minimized without the scan restraints, the proton (green) on His57 and Ser195 OG bonded to the carbonyl carbon. Map: energy of the minimized structures against the coordinates reached, relative to the lowest structure of the reactant region minimized without the restraints, contours every 4 kcal/mol, the lowest path through the grid points into the basin of the adduct (orange) and, from each point of the last row and from the local minima of the grid, the minimization without the scan restraints (arrows, dots where it stopped): with the proton coordinate at +0.3 Å or more the structures stay at the adduct, with the proton on Ser195 or midway they return to the reactant. Right: the energy along that path in the three replicas that have an adduct, whose highest point is 23.7, 21.3 and 20.8 kcal/mol, and the adduct (open circles: 23.4, 20.9 and 20.2 kcal/mol); in replicas 2 and 4 every structure minimized without the restraints went back to the reactant. Potential energies of single minimized structures, not free energies.

Clone this wiki locally