nep框架重构

This commit is contained in:
2025-12-09 09:39:32 +08:00
parent 4aacef331e
commit 2ed55d77be

View File

@@ -47,52 +47,58 @@ class Workflow:
# ========================== # ==========================
# Step: 00.md # Step: 00.md
# ========================== # ==========================
# --- 第一轮初始化POSCAR -> model.xyz --- if step_name == "00.md":
if iter_id == 0: # 1. 【修正点】先定义 step_dir确保后续都能访问到
os.makedirs(step_dir, exist_ok=True) step_dir = os.path.join(iter_path, "00.md")
# 1. 获取文件名和路径 # --- 第一轮初始化POSCAR -> model.xyz ---
poscar_name = self.param['files']['poscar'] if iter_id == 0:
poscar_src = os.path.join(self.data_dir, poscar_name) # 2. 现在使用 step_dir 是安全的
os.makedirs(step_dir, exist_ok=True)
# 2. 复制原始 POSCAR 到 step_dir # 获取文件名和路径
if not os.path.exists(poscar_src): poscar_name = self.param['files']['poscar']
self.logger.error(f"Initial POSCAR not found: {poscar_src}") poscar_src = os.path.join(self.data_dir, poscar_name)
return # 或者抛出异常
shutil.copy(poscar_src, os.path.join(step_dir, poscar_name))
# 3. 获取原子标签 Label # 复制原始 POSCAR
# 假设 config/param.yaml 里是: label: "Li Ge P S" if not os.path.exists(poscar_src):
atom_labels = self.param['files'].get('label', '') self.logger.error(f"Initial POSCAR not found: {poscar_src}")
if not atom_labels: return
self.logger.error("Missing 'label' in param.yaml files section.") shutil.copy(poscar_src, os.path.join(step_dir, poscar_name))
return
# 4. 构建 gpumdkit 命令 # 获取标签
# 命令格式: gpumdkit.sh -addlabel filename Li Ge P S atom_labels = self.param['files'].get('label', '')
# 注意:这里我们假设 machine.yaml 里定义了一个叫 'gpumdkit' 的 executor if not atom_labels:
# 或者我们直接构建 shell 命令,因为这通常是一个轻量级操作 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') kit_path = self.machine.config['paths'].get('gpumdkit', 'gpumdkit.sh')
cmd = f"{kit_path} -addlabel {poscar_name} {atom_labels}" # 确保使用绝对路径,防止 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}"
# 执行转化 self.logger.info(f"Initializing model.xyz with command: {cmd}")
try: try:
# 必须在 step_dir 下执行,以便生成 model.xyz 在当前目录 subprocess.check_call(cmd, shell=True, cwd=step_dir)
subprocess.check_call(cmd, shell=True, cwd=step_dir) except subprocess.CalledProcessError as e:
except subprocess.CalledProcessError as e: self.logger.error(f"Failed to convert POSCAR: {e}")
self.logger.error(f"Failed to convert POSCAR to model.xyz: {e}") return
return
# 检查生成结果 if not os.path.exists(os.path.join(step_dir, "model.xyz")):
if not os.path.exists(os.path.join(step_dir, "model.xyz")): self.logger.error("model.xyz was not generated.")
self.logger.error("model.xyz was not generated. Check gpumdkit.sh.") return
return else:
else: self.logger.info("Successfully generated model.xyz")
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 # Step: 01.select