科研 Skill

分子动力学轨迹后处理分析

md-analysis

Covers quantitative post-processing of atomistic MD trajectories: loading LAMMPS/GROMACS/ASE trajectories and computing RDF, coordination numbers. Use for structural MD trajectory analysis.

发布者 Codar安全审核通过v0.1.0更新于 2026-11-18

SKILL.md

MD Trajectory Analysis

Description

This skill covers quantitative post-processing of atomistic molecular dynamics trajectories: loading and preprocessing trajectories from LAMMPS, GROMACS, or ASE; computing structural observables (RDF, coordination numbers, angular distributions, bond orientational order, common-neighbor analysis, centrosymmetry parameter); computing dynamical observables (MSD, diffusion coefficient, velocity autocorrelation, residence time, relaxation times); extracting thermodynamic observables from simulation logs (temperature, pressure, energy drift, stress, density); analyzing interfaces and defects; and applying statistical methods (block averaging, autocorrelation, equilibration trimming) to obtain reliable estimates with uncertainty bounds. Covers MDAnalysis, OVITO, ASE, pandas, and matplotlib. Invoke this skill after a production MD run is complete, or during a run to compute rolling diagnostics.

Domain Context

A molecular dynamics trajectory is a time-ordered sequence of configurations — positions, and optionally velocities and forces — generated by integrating Newton's equations of motion. Post-processing transforms this sequence into physically interpretable observables. Several subtleties govern what can and cannot be concluded from trajectory analysis:

  • Ensemble vs. time average: MD computes time averages, which equal ensemble averages only if the system is ergodic on the simulation timescale. For solid-state systems with slow structural relaxation, diffusion-limited processes, or configurations separated by large barriers, the time average may not have converged to the ensemble average within the simulation length. Quoting an observable from a non-ergodic trajectory as an equilibrium property is a fundamental error.
  • Equilibration contamination: Frames collected during equilibration do not belong to the target ensemble. They must be excluded from all analysis averages. The equilibration period is not fixed by the simulation protocol; it must be verified from the data (see md-equilibration). Including even 10–20% of a typical equilibration phase in a production average can shift observables by several percent.
  • Periodic boundary conditions and unwrapping: MD codes write wrapped coordinates — atom positions are mapped into the primary simulation box. This is correct for most structural observables but corrupts center-of-mass–based quantities such as MSD and diffusion coefficient. Unwrapping must be applied before any displacement-based analysis.
  • Statistical uncertainty: A single MD trajectory is a single realization of a stochastic process. Successive frames are correlated over a timescale τ (the autocorrelation time of the observable). Treating N correlated frames as N independent measurements underestimates the statistical error by √(N/N_eff) where N_eff = N / (2τ/dt). Block averaging and autocorrelation analysis are required for honest error estimates.
  • Topology vs. trajectory: Many analysis codes (MDAnalysis, GROMACS) separate the static topology (atom types, masses, bond connectivity) from the time-varying trajectory (coordinates, velocities). The topology must be consistent with the trajectory — mismatched atom counts, types, or connectivity produce silently wrong results rather than informative errors.
  • Force-field vs. MLP trajectories: Classical force-field MD and MLP-driven MD produce trajectories in identical formats, but MLP trajectories may contain configurations with elevated committee uncertainty (extrapolation). Uncertainty-aware post-processing — tagging frames by committee force std — is required before reporting thermodynamic averages from MLP trajectories when the training set coverage is not established.

When to Use This Skill

  • After any production MD run to extract structural, dynamical, or thermodynamic observables and their uncertainties.
  • When computing transport properties (diffusion coefficients, viscosity, thermal conductivity) from Green-Kubo integrals or Einstein relations.
  • When characterizing phase transitions, structural ordering, or defect dynamics from trajectories generated by either classical potentials or MLPs.
  • When performing uncertainty-aware averaging over MLP committee trajectories to identify frames that may be extrapolating outside the training set.
  • When validating that a simulation was well-equilibrated before production by analyzing structural and thermodynamic convergence in the trajectory itself.
  • When diagnosing anomalous simulation behavior — unexpected melting, phase transitions, structural collapse — from trajectory-level observables.

When Not to Use This Skill

  • As a substitute for equilibration diagnostics during a running simulation. Online analysis of a running simulation (to decide when to stop or when to switch ensembles) requires real-time monitoring, which is covered in md-equilibration.
  • For observables that require quantum-mechanical treatment — electronic density of states, optical spectra, NMR chemical shifts — even if the trajectory was generated by AIMD. These require electronic structure post-processing (VESTA, Wannier90, CRITIC2) outside the scope of this skill.
  • For free energy calculations. Time-averaging does not produce free energies. Enhanced sampling methods (metadynamics, umbrella sampling) with their own WHAM/MBAR analysis are required; plain MD post-processing gives structural averages, not free energy surfaces.
  • For reactive MD trajectories (ReaxFF, COMB) without species-tracking. Bond breaking and forming changes the topology during the run; standard MDAnalysis topology-based selections break when atom types or bonding connectivity change. Use OpenBabel or ChemTraYzer for reaction tracking in ReaxFF trajectories.
  • When the trajectory has not been validated for equilibration. Running this skill's analysis on an unequilibrated trajectory produces numbers that look plausible but represent the relaxation transient rather than the target ensemble. Always confirm equilibration with md-equilibration first.

Core Concepts

  • Wrapped vs. unwrapped coordinates: Wrapped: all atom positions are in the primary simulation box (the format written by most MD codes). Unwrapped: positions are continuous across periodic boundaries, so that |r(t) - r(0)| is the true displacement. Unwrapping is required for MSD and VACF; wrapped coordinates are correct for RDF and order parameters.
  • Radial distribution function (RDF) / g(r): The probability of finding an atom of species β at distance r from an atom of species α, normalized to the ideal gas density at the same composition. g(r) encodes the local structure: first peak position = nearest-neighbor distance; first peak height ≈ coordination number × (normalization factor); g(r) → 1 for r >> correlation length (liquid), oscillates for crystalline. Requires wrapped or minimum-image coordinates.
  • Coordination number (CN): Integral of g(r) from 0 to the first minimum after the first peak: CN = 4π ρ ∫₀^{r_min} r² g(r) dr. CN is sensitive to the choice of r_min; always quote r_min alongside CN. An alternative: Voronoi tessellation gives a geometry-based CN without a cutoff.
  • Mean square displacement (MSD): MSD(t) = ⟨|r(t+t₀) - r(t₀)|²⟩ averaged over all origin times t₀. For a liquid above T_g: MSD ∝ t at long time (Fickian diffusion); D = MSD(t) / (2d t) where d = 3 (3D). For a solid: MSD → plateau (Debye-Waller factor) = 3 k_B T / (m ω²). A linearly growing MSD in a nominally solid simulation signals melting, ion migration, or a runaway trajectory.
  • Velocity autocorrelation function (VACF): C(t) = ⟨v(t₀) · v(t+t₀)⟩ / ⟨v(t₀)²⟩. Its Fourier transform is the vibrational density of states (VDOS). The Green-Kubo diffusion coefficient D = (1/3) ∫₀^∞ C(t) dt is an alternative to the Einstein (MSD) relation, useful when MSD is not yet in the diffusive regime. VACF requires velocities to be written to the trajectory dump.
  • Common-neighbor analysis (CNA): Classifies each atom's local environment as FCC, BCC, HCP, icosahedral, or other based on the connectivity pattern of its nearest-neighbor shell. Used to identify crystalline grains, grain boundaries, and phase fractions in metallic simulations. Implemented in OVITO's CommonNeighborAnalysisModifier and MDAnalysis.
  • Centrosymmetry parameter (CSP): CSP = Σᵢ |rᵢ + r_{i+N/2}|² summed over N/2 pairs of nearest-neighbor vectors. CSP ≈ 0 for a centrosymmetric environment (perfect FCC); large CSP indicates distortion, defect, or surface. Sensitive to stacking faults, partial dislocations, and vacancy clusters.
  • Steinhardt bond orientational order parameters (Q_l): Rotationally invariant order parameters computed from spherical harmonics of the neighbor-bond vectors. Q_6 ≈ 0.574 for FCC, ≈ 0.510 for BCC, ≈ 0.485 for HCP, ≈ 0 for liquid/amorphous. Useful for crystalline vs. amorphous discrimination and for detecting nucleation events in supercooled liquids. [EXPERT REVIEW NEEDED: threshold values are sensitive to temperature and force field]
  • Block averaging: Divide the production trajectory into B blocks of equal length. Compute the observable mean in each block. The block means are approximately independent if the block length ≫ autocorrelation time τ. The standard error of the block mean converges to the true statistical error as the block length increases. A plateau in the block std vs. block length plot indicates the blocks are statistically independent.
  • Autocorrelation time: τ = Σ_{k=0}^∞ C_k where C_k = corr(x_t, x_{t+k}) is the normalized autocorrelation of observable x. N_eff = N / (1 + 2τ/dt) is the effective number of independent samples. Computing τ explicitly is required before quoting a standard error for any observable with significant temporal correlation (pressure, potential energy in NVT, order parameters near transitions).
  • Minimum image convention: For periodic systems, the distance between atoms i and j is taken as the distance to the nearest image of j, not necessarily the atom at its stored position. r_ij = r_j - r_i - round(r_ij / L) * L (for orthogonal box). Failure to apply this convention produces incorrect RDFs near r = L/2 and wrong short-range forces.

Key Workflows

Full steps for each part are in references/key-workflows/; open the one you need:

Common Failure Modes

Moved to references/common-failure-modes.md to keep this file short; read it when this part is needed.

Best Practices

  • Always specify and justify the equilibration cutoff. Report the total trajectory length, the number of frames discarded as equilibration, and the criterion used (block-mean stationarity, energy plateau, density convergence). Do not rely on the input-script equilibration stage alone — verify from the trajectory data.
  • Compute block-averaged standard errors, not standard deviations of all frames. A 10 ns trajectory with 2 ps autocorrelation time has only N_eff ≈ 2,500 independent samples, not 5,000,000 frames. Standard deviations from all frames underestimate the true error by a factor of √(5,000,000 / 2,500) ≈ 45.
  • Verify r_max < L_min / 2 before computing RDFs. The minimum-image convention is valid only up to half the box length; beyond that, g(r) is contaminated by periodic images. Check this automatically or add an assertion at the start of RDF analysis.
  • Never use wrapped coordinates for MSD or diffusion analysis. Always either use dump_modify ... unwrap yes in LAMMPS, or apply post-processing unwrapping before any displacement-based calculation. Verify by checking that a solid-state MSD plateaus at the expected Debye-Waller value (≈ 3kT / mω²) rather than growing.
  • Cross-validate structural observables against literature or DFT-MD where possible. The first-peak position in g(r) should match the experimental or DFT nearest-neighbor distance within 0.1–0.2 Å. Coordination numbers should match crystal structure topology at low T. Discrepancies indicate force-field problems, not just statistical errors.
  • For MLP-driven MD, always tag frames by committee uncertainty before analysis. A few extrapolation events per nanosecond can bias thermodynamic averages by amounts larger than the statistical uncertainty. Report what fraction of frames were excluded and at what σ_F threshold.
  • Report trajectory provenance alongside every observable. Record: force field or MLP model path and checksum, timestep, dump frequency, production run length, equilibration length discarded, thermostat and barostat types, and software versions. Without this, results from the same simulation cannot be reproduced and the analysis cannot be peer-reviewed.
  • For dynamical properties, verify with at least two independent initial conditions. MSD, VACF, and residence times from a single trajectory are subject to sampling bias in the initial velocity distribution. Two independent trajectories with different random seeds provide a minimal estimate of run-to-run variability. [EXPERT REVIEW NEEDED: three or more runs are preferred for publication-quality results]
  • Use OVITO for CNA and per-atom analysis rather than manual implementations. OVITO's CNA, CSP, and Voronoi modifiers are validated against known reference structures, handle triclinic PBC correctly, and provide a scriptable pipeline with GPU acceleration. Manual implementations may have subtle PBC or normalization errors that are not obvious from the output.
  • Distinguish interface sites from bulk sites before computing order parameters. Atoms in surface layers or at grain boundaries have inherently low Q_6 and anomalous CNA types by construction. Including them in a bulk crystal analysis reduces the apparent order parameter and inflates the "defect fraction" without representing a physical defect concentration.

Integration with Other Skills

  • lammps-workflow: The LAMMPS dump format, unit conventions, and trajectory-writing settings (dump_modify sort id, dump_modify unwrap yes) established in that skill determine what data is available for analysis. The thermo_style output written to log.lammps is the primary source for thermodynamic observables in Workflow 4 here.
  • md-equilibration: This skill's equilibration trimming (Workflows 4 and 6) implements the diagnostic criteria defined in that skill. The quantitative equilibration checks (temperature stability, energy drift, block-mean stationarity) from that skill must be passed before any production analysis proceeds. That skill also covers the flying-ice-cube detection that informs the subtract_com correction in Workflow 3.
  • md-force-fields: The structural observables computed here (RDF first-peak position, coordination number, melting temperature from CNA) are the primary benchmarks for validating force-field transferability outside the fitting database. Discrepancies between computed and reference observables indicate force-field failures that must be diagnosed in that skill.
  • gromacs-workflow: GROMACS trajectories are loaded via the .tpr/.xtc/.trr interface. This skill's MDAnalysis workflows apply directly; only the loader call changes. The GROMACS .edr parser (panedr) replaces the LAMMPS log parser for thermodynamic observables. GROMACS has native tools (gmx rdf, gmx msd, gmx dos) that can cross-check MDAnalysis results.
  • reactive-md: ReaxFF and COMB trajectories require additional analysis not covered here: bond-order tracking, species inventory over time, and reaction event detection. This skill's structural and dynamical observables apply to the non-reactive epochs between bond events, but the full reactive analysis requires dedicated tools (OpenBabel, ChemTraYzer).
  • enhanced-sampling: Free energy surfaces from metadynamics or umbrella sampling use the same RDF, coordination number, and order parameter analysis tools described here, applied to biased trajectories with reweighting. The statistical analysis (block averaging, autocorrelation) changes because biased trajectories have non-uniform statistical weights — MBAR/WHAM must be applied before this skill's plain averaging.
  • mlp-validation: The MSD-based NVE energy conservation test and the finite-temperature RDF comparison from that skill are computed using the tools in Workflows 2 and 3 here. The equilibration protocol before an NVE test run must follow md-equilibration; the analysis of energy drift and RDF comparison follows this skill.
  • mlp-to-lammps: MLP-driven LAMMPS trajectories use the same dump format as classical LAMMPS runs. Workflow 1 here applies identically. The no_domain_decomposition constraint affects parallel performance but not the trajectory format or analysis.
  • active-learning-mlp: Workflow 7 here (uncertainty-aware frame tagging) is a post-processing step that identifies structures for the active learning query. Frames with σ_F above the threshold are candidates for DFT single-point calculations to expand the training set. The committee uncertainty trajectory produced during MACE active learning MD is the input to Workflow 7.
  • scientific-visualization: OVITO's render pipeline (surface meshes, dislocation analysis, grain boundary visualization, color-mapped per-atom CSP or Q_6) extends the scalar analysis in Workflow 5 to publication-quality figures and movies. That skill covers OVITO scripting for batch rendering, color maps, and animation of defect dynamics.
  • reproducibility-workflow: The analysis provenance exported by export_results (Workflow 8) — software versions, trajectory metadata, analysis parameters — maps directly to the reproducibility record described in that skill. Trajectory files, analysis scripts, and results should be versioned and archived together following that skill's DVC-based protocol.

Key References

  1. Michaud-Agrawal, N., et al. (2011). MDAnalysis: A toolkit for the analysis of molecular dynamics simulations. Journal of Computational Chemistry, 32(10), 2319–2327. https://doi.org/10.1002/jcc.21787
  2. Ong, S. P., et al. (2013). Python Materials Genomics (pymatgen): A robust, open-source python library for materials analysis. Computational Materials Science, 68, 314–319. https://doi.org/10.1016/j.commatsci.2012.10.028
  3. Stukowski, A. (2010). Visualization and analysis of atomistic simulation data with OVITO — the Open Visualization Tool. Modelling and Simulation in Materials Science and Engineering, 18(1), 015012. https://doi.org/10.1088/0965-0393/18/1/015012
  4. Frenkel, D. & Smit, B. (2002). Understanding Molecular Simulation: From Algorithms to Applications. 2nd ed. Academic Press. (Chapters 4, 7, 8: integrators, structural properties, dynamical properties.)
  5. Impey, R. W., Madden, P. A., & McDonald, I. R. (1983). Hydration and mobility of ions in solution. Journal of Physical Chemistry, 87(25), 5071–5083. https://doi.org/10.1021/j150643a008
  6. Bevan Dewar, M. J. S., et al. — see Flyvbjerg, H. & Petersen, H. G. (1989). Error estimates on averages of correlated data. Journal of Chemical Physics, 91(1), 461–466. https://doi.org/10.1063/1.457480
  7. Steinhardt, P. J., Nelson, D. R., & Ronchetti, M. (1983). Bond-orientational order in liquids and glasses. Physical Review B, 28(2), 784–805. https://doi.org/10.1103/PhysRevB.28.784

示例提示词

帮我从这条LAMMPS轨迹计算径向分布函数和配位数分布。

所属插件

计算材料学:第一性原理与原子模拟面向计算材料研究:DFT 与第一性原理(VASP、Quantum ESPRESSO、CP2K、AiiDA)、缺陷/表面/声子/弹性常数、机器学习势函数训练与验证、分子动力学与增强采样、晶体性质图神经网络与生成模型。

安装该插件会一并获得同领域的 35 个 Skill / MCP。

同插件的其他科研 Skill

常见问题

分子动力学轨迹后处理分析能做什么?

Covers quantitative post-processing of atomistic MD trajectories: loading LAMMPS/GROMACS/ASE trajectories and computing RDF, coordination numbers. Use for structural MD trajectory analysis。

如何安装分子动力学轨迹后处理分析?

在科搭 Codar 左侧点击「插件」,在「组件」页签搜索「分子动力学轨迹后处理分析」并安装;在 Claude Code 或 Codex 中可以发送本页的安装提示词,或下载 Skill 包后解压到 ~/.claude/skills 或 ~/.codex/skills。

分子动力学轨迹后处理分析需要哪些权限?

该科研 Skill没有声明额外权限;执行具体操作时仍由 Agent 按自身规则请求确认。

分子动力学轨迹后处理分析经过官方审核吗?

是。SpeedSkills 收录的每个版本都会记录内容摘要与权限声明,当前版本已通过安全审核。