diff --git a/src/workflow.py b/src/workflow.py index 94cd6f9..e6a05d4 100644 --- a/src/workflow.py +++ b/src/workflow.py @@ -47,52 +47,58 @@ class Workflow: # ========================== # Step: 00.md # ========================== - # --- 第一轮初始化:POSCAR -> model.xyz --- - if iter_id == 0: - os.makedirs(step_dir, exist_ok=True) + if step_name == "00.md": + # 1. 【修正点】先定义 step_dir,确保后续都能访问到 + step_dir = os.path.join(iter_path, "00.md") - # 1. 获取文件名和路径 - poscar_name = self.param['files']['poscar'] - poscar_src = os.path.join(self.data_dir, poscar_name) + # --- 第一轮初始化:POSCAR -> model.xyz --- + if iter_id == 0: + # 2. 现在使用 step_dir 是安全的 + os.makedirs(step_dir, exist_ok=True) - # 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)) + # 获取文件名和路径 + poscar_name = self.param['files']['poscar'] + poscar_src = os.path.join(self.data_dir, poscar_name) - # 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 + # 复制原始 POSCAR + 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)) - # 4. 构建 gpumdkit 命令 - # 命令格式: gpumdkit.sh -addlabel filename Li Ge P S - # 注意:这里我们假设 machine.yaml 里定义了一个叫 'gpumdkit' 的 executor - # 或者我们直接构建 shell 命令,因为这通常是一个轻量级操作 + # 获取标签 + atom_labels = self.param['files'].get('label', '') + if not atom_labels: + self.logger.error("Missing 'label' in param.yaml files section.") + return - # 方法 A: 如果 machine.yaml 里配置了 gpumdkit 的路径 - kit_path = self.machine.config['paths'].get('gpumdkit', 'gpumdkit.sh') - cmd = f"{kit_path} -addlabel {poscar_name} {atom_labels}" + # 执行转换 + kit_path = self.machine.config['paths'].get('gpumdkit', 'gpumdkit.sh') + # 确保使用绝对路径,防止 subprocess 找不到 + if not os.path.isabs(kit_path): + # 假设相对于项目根目录,或者在 PATH 中 + pass - self.logger.info(f"Initializing model.xyz with command: {cmd}") + cmd = f"{kit_path} -addlabel {poscar_name} {atom_labels}" - # 执行转化 - 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 + self.logger.info(f"Initializing model.xyz with command: {cmd}") + try: + subprocess.check_call(cmd, shell=True, cwd=step_dir) + except subprocess.CalledProcessError as e: + self.logger.error(f"Failed to convert POSCAR: {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") + if not os.path.exists(os.path.join(step_dir, "model.xyz")): + self.logger.error("model.xyz was not generated.") + return + else: + self.logger.info("Successfully generated model.xyz") + + # --- 遍历子任务 (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) # ========================== # Step: 01.select