|
| 1 | +## DMFF Codebase High-Level Architecture Overview |
| 2 | + |
| 3 | +This document targets humans/agents who need to develop, refactor, test, or debug in the DMFF codebase. It summarizes the project purpose, core architecture, build and test flows, and configuration/security information that is explicitly present in the repository. |
| 4 | + |
| 5 | +> All descriptions here are derived from this repository itself (for example `README.md`, `docs/`, `dmff/`, `backend/`), without introducing external or generic development practices. |
| 6 | +
|
| 7 | +--- |
| 8 | + |
| 9 | +### 1. Project Overview |
| 10 | + |
| 11 | +- **Goal and Scope** |
| 12 | + - DMFF (Differentiable Molecular Force Field) is a JAX-based Python package that provides a fully differentiable implementation of molecular force-field models, enabling parameter optimization and efficient energy/force evaluation for systems such as water, biomacromolecules, organic polymers, and small organic molecules `README.md:5`, `docs/index.md:5`. |
| 13 | + - It supports conventional point-charge models (OPLS/AMBER-like) and multipolar polarizable models (AMOEBA/MPID-like), and is designed to integrate modern machine-learning optimization techniques for automated parameterization and trajectory-based optimization `README.md:7-10`, `docs/dev_guide/introduction.md:11-19`. |
| 14 | + |
| 15 | +- **Core Layered Architecture (Python)** |
| 16 | + - **Top-level package entry `dmff`** |
| 17 | + - `dmff/__init__.py:1-6` re-exports key objects: |
| 18 | + - Global settings: `dmff.settings` (numeric precision, JIT flag, debug flag); |
| 19 | + - Neighbor-list utilities: `dmff.common.nblist.NeighborList` / `NeighborListFreud`; |
| 20 | + - Force-field generators: `dmff.generators`; |
| 21 | + - System Hamiltonian: `dmff.api.Hamiltonian`; |
| 22 | + - Topology operators and MD tools: `dmff.operators`, `dmff.mdtools`. |
| 23 | + - **API layer: Hamiltonian & topology** |
| 24 | + - `dmff/api/__init__.py:1-2` exposes two core classes: `Hamiltonian` and `DMFFTopology`. |
| 25 | + - `Hamiltonian` encapsulates total energy/force, etc.; |
| 26 | + - `DMFFTopology` represents topology and parameter data for a system. |
| 27 | + - **Generators and Calculators** |
| 28 | + - `dmff/generators/__init__.py:1-4` aggregates the submodules `classical`, `admp`, `ml`, and `qeq`, each corresponding to a particular potential form. |
| 29 | + - `docs/dev_guide/introduction.md:11-18` describes the division of responsibilities: |
| 30 | + - `Generator` loads and organizes parameters from force-field XML files; |
| 31 | + - **Calculators** are pure, heavy-duty functions that take atomic positions and force-field parameters as input and return energies; they are JAX-differentiable and JIT-compilable. |
| 32 | + - **Runtime settings** |
| 33 | + - `dmff/settings.py:3-7` defines: |
| 34 | + - `PRECISION` (e.g. `'double'`) controlling JAX 64-bit precision; |
| 35 | + - `DO_JIT` controlling whether to JIT-compile core computations; |
| 36 | + - `DEBUG` controlling debug behavior; |
| 37 | + - `update_jax_precision()` updates the global JAX `jax_enable_x64` flag at import time `dmff/settings.py:10-19`. |
| 38 | + - **Operators pipeline** |
| 39 | + - `dmff/operators/base.py:4-12` defines `BaseOperator`: |
| 40 | + - `__call__` accepts a `DMFFTopology` and delegates to `operate`; |
| 41 | + - subclasses in `dmff/operators/` implement topology/parameter transformations (e.g. typing, virtual sites, AM1 charges) in a pipeline-like fashion. |
| 42 | + - **Neighbor list and backend acceleration** |
| 43 | + - Python-level neighbor list: `dmff/common/nblist.py` (not expanded here, but exported in `dmff/__init__.py:2`). |
| 44 | + - C++/CUDA backend: `dmff/dpnblist/` provides a high-performance neighbor-list library with CPU/GPU scheduling algorithms and doctest-based tests `dmff/dpnblist/tests/CMakeLists.txt:1-38`. |
| 45 | + |
| 46 | +- **ADMP and Classical force-field architecture (from docs)** |
| 47 | + - `docs/assets/DMFF_arch.md:1-26` outlines a three-part architecture: |
| 48 | + - **Parser & typification**: |
| 49 | + - Input: force-field XML file; |
| 50 | + - `parseElement` parses XML and builds **Generators**; |
| 51 | + - `createPotential` produces an intermediate representation containing atomic/topological parameters. |
| 52 | + - **Calculators layer**: |
| 53 | + - ADMP: General Pairwise Calculator, Multipole PME Calculator, Dispersion PME Calculator; |
| 54 | + - Classical: Intramolecular and Intermolecular calculators; |
| 55 | + - All calculators expose a unified energy API `potential(pos, box, pairs, params)` which is JAX-differentiable. |
| 56 | + - **Neighbor list and parameter coupling**: |
| 57 | + - Neighbor pairs `pairs` come from a jax-md-style neighbor list (edge `J -> I` in the diagram); |
| 58 | + - Generator outputs (differentiable parameters) feed into the calculators. |
| 59 | + |
| 60 | +- **OpenMM plugin backend** |
| 61 | + - `backend/openmm_dmff_plugin/README.md:1-4` describes an OpenMM plugin that embeds a trained DMFF JAX model as an OpenMM `Force` for molecular dynamics. |
| 62 | + - Installation requires `libtensorflow_cc`, `cppflow`, and CMake; the plugin builds `DMFFForce`-related kernels under `backend/openmm_dmff_plugin/openmmapi/` and `backend/openmm_dmff_plugin/platforms/` (file-level details are omitted here). |
| 63 | + |
| 64 | +- **Documentation and examples** |
| 65 | + - Documentation: MkDocs-based site with navigation defined in `mkdocs.yml:1-27` and `docs/index.md:17-39`. |
| 66 | + - Examples: `examples/` provides runnable examples for Classical, ADMP, MLForce, OpenMM plugin, DiffTraj, etc. `README.md:48-57`, `docs/user_guide/3.usage.md`. |
| 67 | + |
| 68 | +Currently there is no existing `AGENT.md` / `AGENTS.md`, and no `.cursor/rules/`, `.trae/rules/`, or `.github/copilot-instructions.md` files have been detected in this repository. |
| 69 | + |
| 70 | +--- |
| 71 | + |
| 72 | +### 2. Build & Commands |
| 73 | + |
| 74 | +This section lists only commands and tools that appear explicitly in the repository. |
| 75 | + |
| 76 | +- **Install from source (Python package)** |
| 77 | + - Installing DMFF from source `docs/user_guide/2.installation.md:35-40`: |
| 78 | + - `git clone https://github.com/deepmodeling/DMFF.git` |
| 79 | + - `cd DMFF` |
| 80 | + - `pip install . --user` |
| 81 | + - Dependency installation (partial): |
| 82 | + - Conda environment creation and installation of JAX, mdtraj, optax, jaxopt, pymbar, OpenMM, RDKit, etc. See `docs/user_guide/2.installation.md:3-33` for exact commands. |
| 83 | + |
| 84 | +- **Python tests (pytest)** |
| 85 | + - The root `Makefile:1-31` defines per-module pytest targets, all using `pytest --disable-warnings`: |
| 86 | + - `make test_admp` → `pytest --disable-warnings tests/test_admp`; |
| 87 | + - `make test_classical` → `pytest --disable-warnings tests/test_classical`; |
| 88 | + - `make test_common` → `pytest --disable-warnings tests/test_common`; |
| 89 | + - `make test_difftraj` → `pytest --disable-warnings tests/test_difftraj`; |
| 90 | + - `make test_dimer` → `pytest --disable-warnings tests/test_dimer`; |
| 91 | + - `make test_frontend` → `pytest --disable-warnings tests/test_frontend`; |
| 92 | + - `make test_mbar` → `pytest --disable-warnings tests/test_mbar`; |
| 93 | + - `make test_sgnn` → `pytest --disable-warnings tests/test_sgnn`; |
| 94 | + - `make test_energy` → `pytest --disable-warnings tests/test_energy.py`; |
| 95 | + - `make test_utils` → `pytest --disable-warnings tests/test_utils.py`. |
| 96 | + |
| 97 | +- **C++ neighbor-list backend (dpnblist) build & tests** |
| 98 | + - `dmff/dpnblist/CMakeLists.txt` (not expanded here) defines how to build the C++/CUDA neighbor-list library. |
| 99 | + - Test executable `dpnblist_test` is defined in `dmff/dpnblist/tests/CMakeLists.txt:1-38`: |
| 100 | + - `add_executable(dpnblist_test ...)` with multiple `test_*.cpp` sources; |
| 101 | + - `find_package(doctest)` or a bundled `doctest.cmake` is used to enable doctest-based unit tests. |
| 102 | + |
| 103 | +- **OpenMM DMFF plugin build & tests** |
| 104 | + - Environment setup and build commands are documented in `backend/openmm_dmff_plugin/README.md:9-56`: |
| 105 | + - Install `python`, `openmm`, `cudatoolkit`, and `libtensorflow_cc` via conda; |
| 106 | + - Download TensorFlow sources and copy `tensorflow/c` headers into the conda environment to satisfy `cppflow` requirements; |
| 107 | + - Set `OPENMM_INSTALLED_DIR`, `CPPFLOW_INSTALLED_DIR`, `LIBTENSORFLOW_INSTALLED_DIR`; |
| 108 | + - In `backend/openmm_dmff_plugin/build`, run `cmake .. -DOPENMM_DIR=... -DCPPFLOW_DIR=... -DTENSORFLOW_DIR=...` and then `make && make install && make PythonInstall`. |
| 109 | + - Python-level plugin tests `backend/openmm_dmff_plugin/README.md:58-62`: |
| 110 | + - `python -m OpenMMDMFFPlugin.tests.test_dmff_plugin_nve -n 100` |
| 111 | + - `python -m OpenMMDMFFPlugin.tests.test_dmff_plugin_nvt -n 100 --platform CUDA` |
| 112 | + |
| 113 | +- **Docs development & preview (MkDocs)** |
| 114 | + - Documentation framework: MkDocs `docs/dev_guide/write_docs.md:5`. |
| 115 | + - Preview command `docs/dev_guide/write_docs.md:27-31`: |
| 116 | + - In the directory containing `mkdocs.yml`, run `mkdocs serve` to start a local dev server with auto-reload. |
| 117 | + |
| 118 | +--- |
| 119 | + |
| 120 | +### 3. Code Style |
| 121 | + |
| 122 | +This section collects only style guidelines that are explicitly stated in the repository. |
| 123 | + |
| 124 | +- **Code organization** |
| 125 | + - Root layout `docs/dev_guide/convention.md:10-15`: |
| 126 | + - `dmff/`: project source code; |
| 127 | + - `docs/`: Markdown documentation; |
| 128 | + - `examples/`: standalone examples; |
| 129 | + - `tests/`: unit and integration tests. |
| 130 | + - Within `dmff/` `docs/dev_guide/convention.md:17-22`: |
| 131 | + - `api.py`: API (frontend modules); |
| 132 | + - `settings.py`: global settings; |
| 133 | + - `utils.py`: basic utilities; |
| 134 | + - each subdirectory corresponds to a potential form (e.g. `admp`, `classical`). |
| 135 | + |
| 136 | +- **Docstrings and comments** |
| 137 | + - DMFF adopts **NumPy-style docstrings**: |
| 138 | + - `docs/dev_guide/convention.md:24-27` states: |
| 139 | + - methods and classes should use NumPy-style docstrings, combined with `typing` annotations, to support API documentation generation; |
| 140 | + - an extended example is provided via the Napoleon NumPy-style sample `docs/dev_guide/convention.md:30-387`. |
| 141 | + - Documentation system: MkDocs; authoring guidelines in `docs/dev_guide/write_docs.md`: |
| 142 | + - new docs are added as Markdown files in the appropriate directories; |
| 143 | + - images should be placed under `docs/assets/` and referenced via relative paths `docs/dev_guide/write_docs.md:21-23`. |
| 144 | + |
| 145 | +- **Language and dependencies** |
| 146 | + - Python version and runtime dependencies: |
| 147 | + - `setup.py:47-53` requires Python `~=3.8`, and `setup.py:21-30` lists core dependencies such as `numpy>=1.18`, `jax>=0.4.1`, `openmm>=7.6.0`, `freud-analysis`, `networkx>=3.0`, `optax>=0.1.4`, `jaxopt>=0.8.0`, `pymbar>=4.0.0`, and `tqdm`. |
| 148 | + - Docs-related dependencies: `requirements.txt:1-15` lists documentation tooling (`mkdocs`, `mkdocs-autorefs`, `mkdocs-gen-files`, `mkdocs-literate-nav`, `mkdocstrings`, `mkdocstrings-python`, `pygments`) and runtime libraries (`jax`, `jaxlib`, `pymbar`, `rdkit`, `ase`). |
| 149 | + |
| 150 | +--- |
| 151 | + |
| 152 | +### 4. Testing |
| 153 | + |
| 154 | +DMFF uses both Python-level unit/integration tests and C++-level backend tests. |
| 155 | + |
| 156 | +- **Python test layout** |
| 157 | + - All Python tests live under `tests/`, covering: frontend API, classical force fields (`tests/test_classical/`), ADMP module (`tests/test_admp/`), neighbor-list utilities (`tests/test_common/`), DiffTraj, MBAR, SGNN, EANN, and others (see the directory tree under `tests/`). |
| 158 | + - The `Makefile:1-31` provides per-module pytest entry points, making it easy to run only a subset of tests. |
| 159 | + - `tests/conftest.py:1` is currently empty; there are no repository-wide pytest fixtures or hooks defined. |
| 160 | + |
| 161 | +- **Installation sanity checks (Python)** |
| 162 | + - User guide installation check `docs/user_guide/2.installation.md:42-52`: |
| 163 | + - In an interactive Python session, import `dmff` and `dmff.admp` to ensure the package is available; |
| 164 | + - run `examples/water_fullpol/run.py` to confirm example scripts execute successfully. |
| 165 | + |
| 166 | +- **C++ backend tests (dpnblist)** |
| 167 | + - `dmff/dpnblist/tests/CMakeLists.txt:1-38`: |
| 168 | + - defines the `dpnblist_test` executable combining multiple `test_*.cpp` files; |
| 169 | + - uses doctest for unit tests; when an external doctest installation is not found, it pulls in `external/doctest-2.4.11` and uses `doctest.cmake`; |
| 170 | + - `doctest_discover_tests` registers tests with CTest. |
| 171 | + |
| 172 | +- **OpenMM plugin tests** |
| 173 | + - Python-level tests `backend/openmm_dmff_plugin/README.md:58-62`: |
| 174 | + - `python -m OpenMMDMFFPlugin.tests.test_dmff_plugin_nve -n 100`; |
| 175 | + - `python -m OpenMMDMFFPlugin.tests.test_dmff_plugin_nvt -n 100 --platform CUDA`. |
| 176 | + - C++-level tests include `TestDMFFPlugin4CUDA.cpp` and `TestDMFFPlugin4Reference.cpp` with corresponding `CMakeLists.txt` under `backend/openmm_dmff_plugin/platforms/*/tests/`, used to validate force and energy consistency across platforms. |
| 177 | + |
| 178 | +--- |
| 179 | + |
| 180 | +### 5. Security |
| 181 | + |
| 182 | +The repository does not contain a dedicated security design document or explicit security policies. This section lists only direct, observable facts related to data and dependencies, without adding generic recommendations. |
| 183 | + |
| 184 | +- **Data and file types** |
| 185 | + - Force fields and topologies: many XML and PDB files under `tests/data/` and `examples/` provide input for topology and parameter construction (`tests/data/*.xml`, `examples/*/*.xml`, `*.pdb`, etc.). |
| 186 | + - Trained models and parameters: |
| 187 | + - ML force-field parameters are stored in files such as `*.pickle` and `*.pt`, e.g. `examples/eann/eann_model.pickle`, `examples/sgnn/test_backend/model1.pth`, `tests/data/water_eann.pickle`; |
| 188 | + - the OpenMM plugin uses `backend/save_dmff2tf.py` to export JAX models into a TensorFlow-compatible format consumed by the plugin `backend/openmm_dmff_plugin/README.md:4-5`. |
| 189 | + |
| 190 | +- **Dependencies and runtime environment** |
| 191 | + - Core numerical dependencies include `jax`, `jaxlib`, `numpy`, `openmm`, `rdkit`, etc., with version constraints specified in `setup.py:21-30`, `requirements.txt:1-15`, and `docs/user_guide/2.installation.md:3-33`. |
| 192 | + - The OpenMM plugin depends on `libtensorflow_cc` and `cppflow`; TensorFlow headers under `tensorflow/c` must be copied from upstream sources into the conda environment `backend/openmm_dmff_plugin/README.md:18-27`. |
| 193 | + |
| 194 | +- **Access control and encryption** |
| 195 | + - No additional access-control, authentication, or encryption mechanisms are defined in this repository; |
| 196 | + - Configuration example `config/freud.ini:2-41` is for a third-party tool (layout, key bindings, DB filename, color scheme) and is not coupled to DMFF’s internal numerical logic. |
| 197 | + |
| 198 | +More fine-grained security policies (data isolation, permission control, etc.) need to be handled by the systems that integrate DMFF; this repository itself does not impose additional constraints. |
| 199 | + |
| 200 | +--- |
| 201 | + |
| 202 | +### 6. Configuration & Environment |
| 203 | + |
| 204 | +- **Python environment and dependencies** |
| 205 | + - Recommended setup in `docs/user_guide/2.installation.md:3-33`: |
| 206 | + - create a conda environment named `dmff` (example uses Python 3.9); |
| 207 | + - install specific versions of JAX (CPU or CUDA builds), mdtraj, optax, jaxopt, pymbar, OpenMM, RDKit, etc. |
| 208 | + - Package-level dependencies are centralized in `setup.py:21-30` and `requirements.txt:1-15` to aid environment reproduction. |
| 209 | + |
| 210 | +- **Global numerical and debug settings** |
| 211 | + - `dmff/settings.py:3-19` defines runtime configuration: |
| 212 | + - `PRECISION`: controls whether JAX double precision is enabled (via `update_jax_precision` updating `jax_enable_x64`); |
| 213 | + - `DO_JIT`: controls JIT compilation of core computations; |
| 214 | + - `DEBUG`: toggles debug behavior; |
| 215 | + - these are exported via `dmff/__init__.py:1` and can be imported and modified by user code. |
| 216 | + |
| 217 | +- **Documentation system configuration** |
| 218 | + - `mkdocs.yml:1-47`: |
| 219 | + - defines the site name (`DMFF`) and navigation (User Guide, Developer Guide, module docs, etc.); |
| 220 | + - uses the `readthedocs` theme and `pymdownx.arithmatex` for math rendering; |
| 221 | + - enables `gen-files`, `literate-nav`, and `mkdocstrings` plugins to generate API references and SUMMARY-based navigation. |
| 222 | + |
| 223 | +- **Docker environments (packaging & development)** |
| 224 | + - `package/docker/develop_cpu.dockerfile` and `package/docker/develop_gpu.dockerfile` describe CPU/GPU development images (system dependencies plus Python environment) for reproducible development inside containers. |
| 225 | + |
| 226 | +- **External tool configuration example** |
| 227 | + - `config/freud.ini:2-41` configures a third-party tool (likely an HTTP/requests inspector) with layout, key bindings, database filename, and style settings; it is independent of DMFF’s core simulation logic and can be treated as optional tooling. |
| 228 | + |
| 229 | +--- |
| 230 | + |
| 231 | +The above content is intended to let developers or agents grasp DMFF’s overall design, build process, and testing/configuration strategy without fully reading the code. For concrete implementation or refactoring tasks, combine this overview with the corresponding module-specific docs (for example `docs/dev_guide/` and `docs/user_guide/4.*.md`) and nearby tests to drive detailed understanding and validation. |
| 232 | + |
0 commit comments