How matthew-j-liu/amber-ff works
1. Repository purpose
This is a C++17 molecular mechanics project centered on computing AMBER/GAFF-style force-field energies for small organic molecules. The current implementation is strongest for saturated hydrocarbons, with partial support extended to additional molecule classes through atom typing and parameter expansion.
2. Top-level data model
The core input is an annotated .xyz file: coordinates plus an explicit bond list appended after the atom block. That bond information is used to build a molecule as a graph rather than inferring connectivity only from geometry. The parameter side is a reduced AMBER parameter file format, specialized into hydrocarbons.dat and selected_atoms.dat for the subset of atom types the code can handle.
3. Parsing boundary
src/read_xyz.cpp and src/read_params.cpp are the main ingestion layer, with src/parsing.hpp consolidating the public parse interface. Their job is to convert file-based chemistry data into in-memory structures: a molecule graph plus force-field parameter maps.
4. Molecule representation
src/molecule.hpp/.cpp defines the molecular graph abstraction: atoms as nodes, bonds as edges, and neighbor lists used throughout the rest of the pipeline. src/mol_utils.cpp/.hpp appears to own chemistry-specific graph utilities such as bond detection and AMBER atom-type assignment.
5. Atom typing as a separate stage
Atom typing is explicitly separated from parsing and energy evaluation. The README shows the typing logic is rule-based: halogens first, then carbon backbone by coordination, then oxygen/nitrogen, then hydrogens based on attachment. This stage is important because the force-field parameters are keyed by atom types, not just element symbols.
6. Geometry computation
src/geom_util.cpp/.hpp provides the low-level measurements needed by the force field: bond lengths, bond angles, and dihedral angles derived from coordinates and graph connectivity. This is the bridge between the molecule graph and the energy formulas.
7. Force-field engine
src/ff.cpp/.hpp is the energy core. It computes the bonded and nonbonded terms used in the project’s AMBER-style model: bonds, angles, dihedrals, and van der Waals. Parameter lookup is done through force-field maps populated from the parsed parameter file. The README notes that electrostatics are not implemented and the explicit hydrogen-bond term is omitted for simplicity.
8. Parameter format and scope
params/gaff2.dat is the source parameter archive, while params/hydrocarbons.dat is a reduced, easier-to-parse subset. params/selected_atoms.dat expands coverage to more molecules while keeping the same parser contract. params/param_file_format.md documents the expected sectioned file structure, which matters because the parser depends on those bracketed section boundaries.
9. Execution entry points
src/main.cpp is the general driver for loading one molecule and one parameter set, then printing/using the parsed structures and computed values. src/dihedral_scan_main.cpp supports a more specialized workflow for scanning a torsion and generating result data for one molecule.
10. Analysis and benchmarking layer
The benchmarks/ directory is a separate evaluation subsystem. It contains scripts to run parity checks against reference outputs, and plotting code to visualize error distributions and class-based comparisons. This is the repo’s main validation boundary against AMBER outputs rather than a production runtime feature.
11. Dihedral-scan workflow
dihedral_scan/scan_dihedral.py and the dihedral_scan/results/ CSV output form a small analysis pipeline for torsion energy curves. That workflow is likely used to compare the project’s dihedral term against known reference behavior for a specific molecule such as but-1-ene.
12. Tests and confidence boundaries
The tests/ directory mixes C++ unit tests and a Python test, covering parameter loading, XYZ parsing, force-field calculations, and a basic smoke test. This shows the repo’s confidence model is split across file parsing correctness, chemistry typing correctness, and numeric energy correctness.
13. Build and run infrastructure
The repo uses CMake plus shell wrappers (build_and_run.sh, interactive.sh, run_AMBER_benchmarking.sh, run_AMBER_custom.sh, test.sh) to simplify compilation and comparison workflows. The code also links against Armadillo, so linear-algebra and vector math are part of the runtime dependencies.
14. Representative project flow
The end-to-end data path is: annotated molecule file and parameter file in → parsing → graph construction → atom typing → geometry extraction → force-field term evaluation → output/benchmark comparison. The repo’s structure is aligned around that pipeline, with datasets, parsing, chemistry logic, energy computation, and validation kept in distinct folders.
Main entry points: ff.cpp Energy core · read_xyz.cpp Read XYZ · read_params.cpp Read params · main.cpp Main driver
Components 18
Core engine
C++17 parsing, molecule modeling, geometry, and force-field evaluation.
- Parsing API · Public parse boundary that exposes XYZ and parameter ingestion.
src/parsing.hpp - Read XYZ · Loads annotated coordinates and appended bond lists into molecule data.
src/read_xyz.cpp - Read params · Loads reduced AMBER-style parameter sections into lookup maps.
src/read_params.cpp - Molecule graph · Atom-and-bond representation with neighbor lists used across the pipeline.
src/molecule.hpp - Chem utils · Graph utilities for connectivity handling and atom typing support.
src/mol_utils.cpp - Geometry · Computes bond lengths, angles, and dihedrals from coordinates and connectivity.
src/geom_util.cpp - FF params · In-memory force-field tables keyed by atom types and interaction classes.
src/ff_params.hpp - Energy core · Evaluates AMBER-style bonded and nonbonded terms for a molecule.
src/ff.cpp - Main driver · General entry point for loading one molecule and one parameter set.
src/main.cpp - Torsion driver · Specialized entry point for dihedral scan workflows.
src/dihedral_scan_main.cpp
Parameter data
Force-field archives and the file-format contract they follow.
- GAFF2 archive · Primary source parameter set used to derive supported subsets.
params/gaff2.dat - Hydrocarbon set · Reduced parameter file for the simpler supported chemistry class.
params/hydrocarbons.dat - Selected atoms · Expanded subset that broadens molecule coverage while keeping parser compatibility.
params/selected_atoms.dat - Format spec · Sectioned parameter-file format contract consumed by the parser.
params/param_file_format.md
Molecule datasets
Annotated input molecules used by the runtime and benchmarks.
- Molecule set · Annotated XYZ examples spanning alkanes, functional groups, and benchmark molecules.
input_molecules_copy
Analysis
Benchmarking, parity plots, and dihedral scan workflow.
- Benchmarks · Parity scripts and plots comparing outputs against reference behavior.
benchmarks - Dihedral scan · Scripted torsion-energy sweep and resulting CSV data.
dihedral_scan
Validation
Unit and smoke tests spanning parsing, typing, and energy evaluation.
- Tests · C++ and Python tests for parsing, typing, and force-field calculations.
tests
Connections 22
- Read XYZ → Molecule graph: builds · Converts annotated coordinates into a molecule graph.
- Read params → FF params: populates · Creates parameter maps from the reduced AMBER-style file.
- Parsing API → Read XYZ: exposes · Public parsing interface for XYZ ingestion.
- Parsing API → Read params: exposes · Public parsing interface for parameter ingestion.
- Molecule graph → Chem utils: used by · Graph utilities operate on the molecular representation.
- Chem utils → Energy core: atom types · Provides typing and connectivity information needed by the energy engine.
- Molecule graph → Geometry: feeds · Geometry routines consume coordinates and bond connectivity.
- Geometry → Energy core: measures · Supplies lengths, angles, and dihedrals to energy formulas.
- FF params → Energy core: lookups · Force-field terms are evaluated from parsed parameter tables.
- Main driver → Parsing API: loads · Main runtime starts by reading molecule and parameter inputs.
- Main driver → Chem utils: types · Performs atom typing before energy evaluation.
- Main driver → Energy core: computes · Runs the force-field energy calculation.
- Torsion driver → Dihedral scan: drives · Specialized executable supports torsion scanning workflows.
- GAFF2 archive → Hydrocarbon set: derives · Reduced subset is derived from the broader GAFF2 archive.
- GAFF2 archive → Selected atoms: derives · Expanded selected-atom coverage is based on the source archive.
- Format spec → Read params: specifies · Parser depends on the bracketed section structure.
- Molecule set → Read XYZ: sample data · Annotated XYZ molecules are the primary runtime inputs.
- Benchmarks → Energy core: validates · Parity and plots assess energy-output agreement.
- Dihedral scan → Energy core: analyzes · Dihedral scan workflow evaluates torsion energy behavior.
- Tests → Read XYZ: covers · Tests parsing of annotated XYZ inputs.
- Tests → Read params: covers · Tests parameter loading behavior.
- Tests → Energy core: covers · Tests force-field numeric calculations.