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
翻译:分子动力学(MD)模拟是理解材料科学中原子尺度行为的关键工具,然而编写LAMMPS脚本仍然是高度专业化且耗时的工作。尽管大语言模型(LLM)在代码生成和领域特定问答中展现出潜力,但其在MD场景中的性能受限于稀缺的领域数据、前沿大语言模型的高部署成本以及较低的代码可执行性。基于我们先前开发的MDAgent,本文提出MDAgent2——首个能够在MD领域内同时执行知识问答与代码生成的端到端框架。我们构建了领域专用的数据构建流程,产生了涵盖MD知识、问答与代码生成的三个高质量数据集。基于这些数据集,我们采用三阶段后训练策略——持续预训练(CPT)、监督微调(SFT)与强化学习(RL)——训练出两个领域适配模型:MD-Instruct与MD-Code。此外,我们提出了MD-GRPO,一种利用模拟结果作为奖励信号并循环利用低奖励轨迹以持续优化的闭环强化学习方法。我们进一步构建了MDAgent2-RUNTIME,一个可部署的多智能体系统,集成了代码生成、执行、评估与自我修正功能。结合本文提出的首个面向LAMMPS代码生成与问答的基准测试MD-EvalBench,我们的模型与系统在多项性能指标上超越了多个强基线模型。本工作系统性地展示了大语言模型在工业仿真任务中的适应性与泛化能力,为“AI for Science”及工业级模拟中的自动代码生成奠定了方法论基础。