OpenMM 8 安装与上手指南
OpenMM 8简介
OpenMM 支持多种主流力场(如 AMBER、CHARMM、OPLS-AA 等),并可通过 Python 脚本方便地定义体系、设定模拟参数、执行能量最小化与分子动力学计算。它同时提供可定制的积分器(Integrator)与力场插件(Force Plugins),允许研究人员轻松实现新算法或自定义势能函数。
OpenMM 8 在前一版本的基础上进行了显著优化:
-
增强了 CUDA、OpenCL 与 ROCm 的 GPU 后端性能;
-
引入了 新的分子约束与虚拟位点算法,提升了大型体系的稳定性与能量守恒;
-
改进了 序列化(serialization)与插件加载机制,简化了跨平台部署;
-
提供了与 OpenMMTools、MDTraj、ParmEd、PyTorch 等生态系统的更紧密集成,使其能无缝结合深度学习或自由能计算框架。
此外,OpenMM 可直接读取 PDB、AMBER、GROMACS 等常用分子拓扑文件,并可输出标准的 DCD、PDB、XTC 等轨迹格式,方便后续可视化与分析。结合 Jupyter Notebook 或 Python 环境,研究人员能够快速构建、运行并分析从纳米到微秒级的分子动力学模拟。
凭借其开源、跨平台、高性能的特性,OpenMM 已成为分子模拟领域中广受欢迎的核心计算引擎之一,既适用于基础教学与研究,也能支撑高水平的并行化计算与深度学习驱动的分子建模研究。
OpenMM 8 安装
- Python 3.12
- CUDA 12
- OpenMM 8.2.0
安装
conda create -n openmm8.2
conda activate openmm8.2
conda install -c conda-forge pdbfixer
conda install -c conda-forge openmm cuda-version=12
测试安装
python -m openmm.testInstallation
OpenMM 8 上手指南
from openmm.app import *
from openmm import *
from openmm.unit import *
import mdtraj as md
import numpy as np
import matplotlib.pyplot as plt
import sys
import os
import pandas as pd# Load the PDB structure file
pdb = PDBFile('data/1bna.pdb')# Define the force field (AMBER14 for protein + TIP3P for water)
forcefield = ForceField('amber14-all.xml', 'amber14/tip3p.xml')# Create a modeller and add hydrogens and solvent box
modeller = Modeller(pdb.topology, pdb.positions)
modeller.addHydrogens(forcefield)
modeller.addSolvent(forcefield, model='tip3p', boxSize=Vec3(8, 8, 8)*nanometers, ionicStrength=0.1*molar)# Create the system using Particle Mesh Ewald (PME) for electrostatics,
# constrain all hydrogen bonds, and apply a 1.0 nm cutoff
system = forcefield.createSystem(modeller.topology, nonbondedMethod=PME, constraints=HBonds, nonbondedCutoff=1.0*nanometer)# Define thermodynamic parameters and integrator
temperature = 300*kelvin
pressure = 1*atmosphere
timestep = 2*femtoseconds
integrator = LangevinIntegrator(temperature, 1/picosecond, timestep)# Add a barostat to maintain constant pressure (NPT ensemble)
barostat = MonteCarloBarostat(pressure, temperature)
system.addForce(barostat)# Create the simulation object
simulation = Simulation(modeller.topology, system, integrator)
simulation.context.setPositions(modeller.positions)# --- Energy minimization ---
print("Minimizing energy...")
simulation.minimizeEnergy()# --- Equilibration phase ---
print("Equilibrating the system...")
simulation.context.setVelocitiesToTemperature(temperature)
simulation.step(1000) # 1000 steps for equilibration# --- Production run ---
print("Running production simulation...")
simulation.reporters.append(StateDataReporter('data/output.log', 1000, step=True, potentialEnergy=True,temperature=True, density=True))
simulation.reporters.append(PDBReporter('data/trajectory.pdb', 1000))
simulation.step(5000) # Production run: 5000 steps (adjust as needed)# --- Analyze potential energy ---
file_path = 'data/output.log'
column_names = ["Step", "Potential Energy (kJ/mole)", "Temperature (K)", "Density (g/mL)"]# Load the log file as a CSV
data = pd.read_csv(file_path, skiprows=1, names=column_names)# Extract Step and Potential Energy columns
steps = data["Step"]
potential_energy = data["Potential Energy (kJ/mole)"]# Plot potential energy vs step
plt.figure(figsize=(10, 6))
plt.plot(steps, potential_energy, marker='o', linestyle='-', color='b', label='Potential Energy')
plt.title('Potential Energy vs. Step', fontsize=16)
plt.xlabel('Step', fontsize=14)
plt.ylabel('Potential Energy (kJ/mole)', fontsize=14)
plt.grid(True, linestyle='--', alpha=0.6)
plt.legend(fontsize=12)
plt.tight_layout()# Show the plot
plt.show()
参考资料
- https://openmm.org/
- https://github.com/openmm/openmm
- https://anaconda.org/conda-forge/pdbfixer
- https://anaconda.org/conda-forge/openmm
- Eastman, Peter, Raimondas Galvelis, Raúl P. Peláez, Charlles RA Abreu, Stephen E. Farr, Emilio Gallicchio, Anton Gorenko et al. "OpenMM 8: molecular dynamics simulation with machine learning potentials." The Journal of Physical Chemistry B 128, no. 1 (2023): 109-116.