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和工业级模拟中的自动代码生成奠定了方法论基础。URL: https://github.com/FredericVAN/PKU_MDAgent2