nep框架重构
This commit is contained in:
@@ -7,6 +7,7 @@ files:
|
|||||||
poscar: "LGPS.vasp"
|
poscar: "LGPS.vasp"
|
||||||
potcar: "POTCAR"
|
potcar: "POTCAR"
|
||||||
initial_pot: "nep89.txt" # 第一轮 MD 用的势函数
|
initial_pot: "nep89.txt" # 第一轮 MD 用的势函数
|
||||||
|
label: "Li Ge P S"
|
||||||
|
|
||||||
# 2. 迭代流程控制
|
# 2. 迭代流程控制
|
||||||
iterations:
|
iterations:
|
||||||
|
|||||||
@@ -47,35 +47,52 @@ class Workflow:
|
|||||||
# ==========================
|
# ==========================
|
||||||
# Step: 00.md
|
# Step: 00.md
|
||||||
# ==========================
|
# ==========================
|
||||||
if step_name == "00.md":
|
# --- 第一轮初始化:POSCAR -> model.xyz ---
|
||||||
step_dir = os.path.join(iter_path, "00.md")
|
|
||||||
|
|
||||||
# 只有第一轮且有init需求时,才进行 POSCAR -> model.xyz 转化
|
|
||||||
# 这里为了 Local 测试,我们简单处理:直接把 POSCAR 拷过去当 model.xyz (仅作演示)
|
|
||||||
# 实际上你应该调用 gpumdkit 转化
|
|
||||||
if iter_id == 0:
|
if iter_id == 0:
|
||||||
os.makedirs(step_dir, exist_ok=True)
|
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"))
|
|
||||||
|
|
||||||
# 遍历子任务 (preheat, production...)
|
# 1. 获取文件名和路径
|
||||||
for sub in step_conf.get('sub_tasks', []):
|
poscar_name = self.param['files']['poscar']
|
||||||
template_sub_name = sub['template_sub']
|
poscar_src = os.path.join(self.data_dir, poscar_name)
|
||||||
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
|
||||||
md_task = MDStep(f"MD-{template_sub_name}", sub_work_dir, self.machine, self.config)
|
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))
|
||||||
|
|
||||||
# 关键:要把上一级准备好的 model.xyz 拷进来
|
# 3. 获取原子标签 Label
|
||||||
if iter_id == 0:
|
# 假设 config/param.yaml 里是: label: "Li Ge P S"
|
||||||
shutil.copy(os.path.join(step_dir, "model.xyz"), os.path.join(sub_work_dir, "model.xyz"))
|
atom_labels = self.param['files'].get('label', '')
|
||||||
# 如果是后续轮次,应该用上一轮选好的结构,这里暂略,先跑通第一轮
|
if not atom_labels:
|
||||||
|
self.logger.error("Missing 'label' in param.yaml files section.")
|
||||||
|
return
|
||||||
|
|
||||||
md_task.run(self.current_nep_pot, template_path)
|
# 4. 构建 gpumdkit 命令
|
||||||
|
# 命令格式: gpumdkit.sh -addlabel filename Li Ge P S
|
||||||
|
# 注意:这里我们假设 machine.yaml 里定义了一个叫 'gpumdkit' 的 executor
|
||||||
|
# 或者我们直接构建 shell 命令,因为这通常是一个轻量级操作
|
||||||
|
|
||||||
# 记录最后生成的 dump.xyz 路径,供下一步使用
|
# 方法 A: 如果 machine.yaml 里配置了 gpumdkit 的路径
|
||||||
self.last_dump_path = os.path.join(sub_work_dir, "dump.xyz")
|
kit_path = self.machine.config['paths'].get('gpumdkit', 'gpumdkit.sh')
|
||||||
|
cmd = f"{kit_path} -addlabel {poscar_name} {atom_labels}"
|
||||||
|
|
||||||
|
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
|
# Step: 01.select
|
||||||
|
|||||||
Reference in New Issue
Block a user