M-Chem database (.db) format
An M-Chem .db file is a standard SQLite 3 database that stores a
parameterized molecular system: global force-field metadata, per-particle
state, and bonded / non-bonded force terms. M-Chem reads these files as the
primary input for MD simulations.
Conceptually, a .db is the output of force-field parameterization for one
specific structure, rather than the type-based force field definition. It holds
system-assigned atom types, enumerated bonded and non-bonded terms, coordinates,
and simulation metadata for that instance. This is analogous to a GROMACS
.tpr file, an OpenMM System object, or the AMBER prmtop + inpcrd
pair combined: each encodes a ready-to-run parameterized system.
Overview
Every mchem database contains:
A `meta` table — one row of system-wide force-field settings (AMOEBA polynomial coefficients, VdW combining rules, etc.).
A `class` table — maps each term table name to the Python dataclass used to deserialize rows.
One or more term tables — each row is one force term; column names match dataclass field names in
mchem.terms.Optional `box` table (class
Box) holds periodic cell lengths and angles from PDBCRYST1when a box was present at conversion time.
Example file
tests/data/DHFR.db is a full AMOEBA-parameterized dihydrofolate reductase
system produced from tests/data/DHFR.pdb. It illustrates a production-sized
database:
Table |
Rows |
|---|---|
|
23,558 |
|
16,569 |
|
23,558 |
|
625 |
|
1 |
Inspect it with any SQLite client:
sqlite3 tests/data/DHFR.db ".schema"
sqlite3 tests/data/DHFR.db "SELECT * FROM meta;"
sqlite3 tests/data/DHFR.db "SELECT tablename, clsname FROM class;"
Programmatic access:
from mchem.system import System
system = System("tests/data/DHFR.db")
print(system.meta["name"]) # DHFR
print(len(system["Particle"])) # 23558
print(system["box"][0].a) # 61.645 (Angstroms)
Required system tables
meta
Exactly one row. Columns are created dynamically from keys passed to
mchem.system.System.addMeta() when the system is built (typically from
force-field XML via mchem.forcefield.base.ForceField.createSystem()).
For DHFR.db, columns include:
Column |
Meaning (typical) |
|---|---|
|
System / topology name (e.g. |
|
AMOEBA bond cubic coefficient |
|
AMOEBA bond quartic coefficient |
|
AMOEBA angle cubic coefficient |
|
AMOEBA angle quartic coefficient |
|
AMOEBA angle quintic coefficient |
|
AMOEBA angle sextic coefficient |
|
Out-of-plane bend type (e.g. |
|
Out-of-plane bend cubic coefficient |
|
Out-of-plane bend quartic coefficient |
|
Out-of-plane bend quintic coefficient |
|
Out-of-plane bend sextic coefficient |
|
Non-bonded type label (e.g. |
|
VdW radius combining rule (e.g. |
|
Radius definition (e.g. |
|
Radius size convention (e.g. |
|
Epsilon combining rule (e.g. |
|
1-3 VdW scale factor |
|
1-4 VdW scale factor |
|
1-5 VdW scale factor |
|
Urey-Bradley cubic coefficient |
|
Urey-Bradley quartic coefficient |
Exact columns depend on which force generators ran for that system.
class
Maps SQLite table name → Python class name (must exist in
mchem.system’s internal registry or be registered explicitly).
Example from DHFR.db:
tablename clsname
--------------------- ------------------------
Particle Particle
AmoebaBond AmoebaBond
box Box
...
The table name used in SQL may differ from clsname when terms are stored
under a custom name (e.g. CMAPTable1 mapping to CMAPTable). Always use
the name in class.tablename when querying.
Term tables
Each term table corresponds to one mchem.terms.base.TermList in memory.
Column names equal dataclass field names; SQLite types are inferred from
Python types:
Python type |
SQLite type |
|---|---|
|
|
On load, list fields (e.g. IsotropicPolarization.grp) are split from
space-separated text back into integers.
Particle indices
Bonded terms reference particles by integer indices p0, p1, … that
match Particle.idx. Per-particle terms use idx.
Common term types (AMOEBA / DHFR.db)
Table / class |
Role |
|---|---|
|
Atom index, name, element, mass, residue, coordinates, velocities |
|
Bond stretch ( |
|
Valence angle |
|
In-plane valence angle (4 atoms) |
|
Out-of-plane bend |
|
Fourier dihedral (up to 6 terms) |
|
Pi-system torsion (6 atoms) |
|
Stretch–bend coupling |
|
Urey–Bradley 1–3 distance term |
|
Torsion–torsion coupling (links to grid) |
|
2D grid points ( |
|
Buffered 14-7 VdW per particle |
|
Charge, dipole, quadrupole, axis frame |
|
Polarizability, Thole, group list |
|
Cell lengths and angles (Å, degrees) |
Field-level definitions live in mchem.terms.bonded and
mchem.terms.nonbonded (also exposed in the API Reference).
Other term classes (HarmonicBond, CMAP, PairList, MBUCB terms, etc.)
produce additional tables when present in a system; their schemas follow the
same dataclass-column rule.
Sample rows (DHFR.db)
Periodic box (cubic 61.645 Å, 90° angles):
a=61.645 b=61.645 c=61.645 alpha=90 beta=90 gamma=90
First particle (MET N):
idx=0 name=N element=N mass=14.0067 resnum=1 resname=MET
xx=35.334 xy=19.608 xz=36.364 vx=vy=vz=0
First bond (particles 0–1):
p0=0 p1=1 b0=0.1015 kb=193258.96 cubic=-25.5 quartic=379.3125 paramIdx=69
Writing and reading
Create via CLI:
mchem-tools convert -i structure.pdb -o system.db -f amoebabio18.xml
Create / update in Python:
from mchem.forcefield import ForceField
from mchem.fileformats import load_pdb, read_pdb_box
from mchem.system import System, Box
top = load_pdb("structure.pdb")
system = ForceField("amoebabio18.xml").createSystem(top)
box = read_pdb_box("structure.pdb")
if box is not None:
system.addTerm(Box(*box), "box")
system.save("system.db", overwrite=True)
Load:
system = System("system.db")
bonds = system["AmoebaBond"]
Custom term types: define a dataclass, call
mchem.system.register_term_class() before System(path), and ensure
the class table’s clsname matches the registered class name.
Implementation notes
On save, mchem uses a transaction, sets
PRAGMA journal_mode=WALandPRAGMA synchronous=OFF, then commits.Term rows are sorted before insert by particle columns
p0,p1, … (oridxwhen nop*fields exist) for stable, diff-friendly ordering.Saving with
overwrite=False(default) raises if the output file already exists.The loader requires
metaandclasstables; unknownclsnamevalues raise unless registered.
See also
Example: Solvate and Parameterize — solvate and
convertworkflowmchem.system.System— load/save implementationmchem.terms— term dataclass definitions