From 4aacef331e2c7a888d72f55217bf0187a391d5d8 Mon Sep 17 00:00:00 2001 From: koko <1429659362@qq.com> Date: Tue, 9 Dec 2025 09:34:36 +0800 Subject: [PATCH] =?UTF-8?q?nep=E6=A1=86=E6=9E=B6=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/param.yaml | 1 + src/workflow.py | 63 ++++++++++++++++++++++++++++++----------------- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/config/param.yaml b/config/param.yaml index cd9e86f..7f0190c 100644 --- a/config/param.yaml +++ b/config/param.yaml @@ -7,6 +7,7 @@ files: poscar: "LGPS.vasp" potcar: "POTCAR" initial_pot: "nep89.txt" # 第一轮 MD 用的势函数 + label: "Li Ge P S" # 2. 迭代流程控制 iterations: diff --git a/src/workflow.py b/src/workflow.py index c11438c..94cd6f9 100644 --- a/src/workflow.py +++ b/src/workflow.py @@ -47,35 +47,52 @@ class Workflow: # ========================== # Step: 00.md # ========================== - if step_name == "00.md": - step_dir = os.path.join(iter_path, "00.md") + # --- 第一轮初始化:POSCAR -> model.xyz --- + if iter_id == 0: + os.makedirs(step_dir, exist_ok=True) - # 只有第一轮且有init需求时,才进行 POSCAR -> model.xyz 转化 - # 这里为了 Local 测试,我们简单处理:直接把 POSCAR 拷过去当 model.xyz (仅作演示) - # 实际上你应该调用 gpumdkit 转化 - if iter_id == 0: - os.makedirs(step_dir, exist_ok=True) - shutil.copy(os.path.join(self.data_dir, self.param['files']['poscar']), - os.path.join(step_dir, "model.xyz")) + # 1. 获取文件名和路径 + poscar_name = self.param['files']['poscar'] + poscar_src = os.path.join(self.data_dir, poscar_name) - # 遍历子任务 (preheat, production...) - for sub in step_conf.get('sub_tasks', []): - template_sub_name = sub['template_sub'] - sub_work_dir = os.path.join(step_dir, template_sub_name) - template_path = os.path.join(self.template_dir, "00.md", template_sub_name) + # 2. 复制原始 POSCAR 到 step_dir + if not os.path.exists(poscar_src): + self.logger.error(f"Initial POSCAR not found: {poscar_src}") + return # 或者抛出异常 + shutil.copy(poscar_src, os.path.join(step_dir, poscar_name)) - # 实例化并运行 - md_task = MDStep(f"MD-{template_sub_name}", sub_work_dir, self.machine, self.config) + # 3. 获取原子标签 Label + # 假设 config/param.yaml 里是: label: "Li Ge P S" + atom_labels = self.param['files'].get('label', '') + if not atom_labels: + self.logger.error("Missing 'label' in param.yaml files section.") + return - # 关键:要把上一级准备好的 model.xyz 拷进来 - if iter_id == 0: - shutil.copy(os.path.join(step_dir, "model.xyz"), os.path.join(sub_work_dir, "model.xyz")) - # 如果是后续轮次,应该用上一轮选好的结构,这里暂略,先跑通第一轮 + # 4. 构建 gpumdkit 命令 + # 命令格式: gpumdkit.sh -addlabel filename Li Ge P S + # 注意:这里我们假设 machine.yaml 里定义了一个叫 'gpumdkit' 的 executor + # 或者我们直接构建 shell 命令,因为这通常是一个轻量级操作 - md_task.run(self.current_nep_pot, template_path) + # 方法 A: 如果 machine.yaml 里配置了 gpumdkit 的路径 + kit_path = self.machine.config['paths'].get('gpumdkit', 'gpumdkit.sh') + cmd = f"{kit_path} -addlabel {poscar_name} {atom_labels}" - # 记录最后生成的 dump.xyz 路径,供下一步使用 - self.last_dump_path = os.path.join(sub_work_dir, "dump.xyz") + self.logger.info(f"Initializing model.xyz with command: {cmd}") + + # 执行转化 + try: + # 必须在 step_dir 下执行,以便生成 model.xyz 在当前目录 + subprocess.check_call(cmd, shell=True, cwd=step_dir) + except subprocess.CalledProcessError as e: + self.logger.error(f"Failed to convert POSCAR to model.xyz: {e}") + return + + # 检查生成结果 + if not os.path.exists(os.path.join(step_dir, "model.xyz")): + self.logger.error("model.xyz was not generated. Check gpumdkit.sh.") + return + else: + self.logger.info("Successfully generated model.xyz") # ========================== # Step: 01.select