让大模型一键生成分子动力学代码并回答专业问题
MDAgent2: Large Language Model for Code Generation and Knowledge Q&A in Molecular Dynamics
- 构建三类高质量数据集,分阶段训练专用模型
- 用模拟结果做奖励信号,自动优化代码生成质量
- 支持代码自执行、自纠错,适合科研与工业仿真场景
分子动力学(MD)模拟在材料科学中至关重要,但编写LAMMPS脚本仍需高度专业知识且耗时。尽管大语言模型在代码生成和问答任务中展现潜力,但在MD领域受限于领域数据稀缺、先进模型部署成本高及代码可执行性差。基于前期工作MDAgent,我们提出MDAgent2,首个端到端支持MD领域知识问答与代码生成的框架。构建覆盖MD知识、问答与代码生成的三类高质量数据集,采用三阶段后训练策略(持续预训练、监督微调、强化学习),训练出MD-Instruct与MD-Code两个领域适配模型。引入MD-GRPO——一种闭环强化学习方法,利用模拟结果作为奖励信号,并循环优化低回报轨迹。构建可部署的多智能体系统MDAgent2-RUNTIME,集成代码生成、执行、评估与自修正功能。结合本文提出的首个针对LAMMPS代码生成与问答的基准测试MD-EvalBench,所提模型与系统性能超越多个强基线。本工作系统验证了大模型在工业级模拟任务中的适应性与泛化能力,为科学计算中自动化代码生成提供方法论基础。
原文摘要 · Abstract (English)
Molecular dynamics (MD) simulations are essential for understanding atomic-scale behaviors in materials science, yet writing LAMMPS scripts remains highly specialized and time-consuming tasks. Although LLMs show promise in code generation and domain-specific question answering, their performance in MD scenarios is limited by scarce domain data, the high deployment cost of state-of-the-art LLMs, and low code executability. Building upon our prior MDAgent, we present MDAgent2, the first end-to-end framework capable of performing both knowledge Q&A and code generation within the MD domain. We construct a domain-specific data-construction pipeline that yields three high-quality datasets spanning MD knowledge, question answering, and code generation. Based on these datasets, we adopt a three stage post-training strategy--continued pre-training (CPT), supervised fine-tuning (SFT), and reinforcement learning (RL)--to train two domain-adapted models, MD-Instruct and MD-Code. Furthermore, we introduce MD-GRPO, a closed-loop RL method that leverages simulation outcomes as reward signals and recycles low-reward trajectories for continual refinement. We further build MDAgent2-RUNTIME, a deployable multi-agent system that integrates code generation, execution, evaluation, and self-correction. Together with MD-EvalBench proposed in this work, the first benchmark for LAMMPS code generation and question answering, our models and system achieve performance surpassing several strong baselines.This work systematically demonstrates the adaptability and generalization capability of large language models in industrial simulation tasks, laying a methodological foundation for automatic code generation in AI for Science and industrial-scale simulations. URL: https://github.com/FredericVAN/PKU_MDAgent2
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。