Skip to content

Commit

Permalink
Merge pull request #42 from ZLI-afk/v1.2
Browse files Browse the repository at this point in the history
V1.2 to main
  • Loading branch information
ZLI-afk authored Oct 13, 2024
2 parents 28b34df + f50dad2 commit fadd74f
Show file tree
Hide file tree
Showing 26 changed files with 421 additions and 272 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/mirror_gitee.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Mirror to Gitee Repository

on: [ push, delete, create ]

# Ensures that only one mirror task will run at a time.
concurrency:
group: git-mirror

jobs:
git-mirror:
uses: deepmodeling/workflows/.github/workflows/mirror_gitee.yml@main
secrets:
SYNC_GITEE_PRIVATE_KEY: ${{ secrets.SYNC_GITEE_PRIVATE_KEY }}
269 changes: 151 additions & 118 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apex/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
__version__ = '1.2.0'
__version__ = '1.2.9'
LOCAL_PATH = os.getcwd()


Expand Down
9 changes: 6 additions & 3 deletions apex/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class Config:
email: str = None
password: str = None
program_id: int = None
job_type: str = "container"
platform: str = "ali"

# DispachterExecutor config
dispatcher_config: dict = None
Expand Down Expand Up @@ -57,6 +59,7 @@ class Config:
group_size: int = None
pool_size: int = None
upload_python_packages: list = field(default_factory=list)
exclude_upload_files: list = field(default_factory=list)
lammps_image_name: str = None
lammps_run_command: str = None
vasp_image_name: str = None
Expand Down Expand Up @@ -108,8 +111,8 @@ def __post_init__(self):
"password": self.password,
"program_id": self.program_id,
"input_data": {
"job_type": "container",
"platform": "ali",
"job_type": self.job_type,
"platform": self.platform,
"scass_type": self.scass_type,
},
},
Expand Down Expand Up @@ -280,7 +283,7 @@ def get_executor(
self,
dispatcher_config: dict
) -> DispatcherExecutor:
if not (self.context_type or self.machine):
if not (self.context_type or self.machine or self.dispatcher_config):
executor = None
else:
# get arguments for instantiation of the DispatcherExecutor
Expand Down
3 changes: 3 additions & 0 deletions apex/core/calculator/ABACUS.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ def make_input_file(self, output_dir, task_type, task_param):
elif [relax_pos, relax_shape, relax_vol] == [False, True, True]:
self.modify_input(incar, "calculation", "cell-relax")
fix_atom = [True, True, True]
elif [relax_pos, relax_shape, relax_vol] == [True, False, True]:
self.modify_input(incar, "calculation", "cell-relax")
self.modify_input(incar, "fixed_axes", "shape")
elif [relax_pos, relax_shape, relax_vol] == [False, False, True]:
raise RuntimeError(
"relax volume but fix shape is not supported for ABACUS"
Expand Down
28 changes: 19 additions & 9 deletions apex/core/calculator/Lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
upload_packages.append(__file__)

# LAMMPS_INTER_TYPE = ['deepmd', 'eam_alloy', 'meam', 'eam_fs', 'meam_spline', 'snap', 'gap', 'rann', 'mace']

MULTI_MODELS_INTER_TYPE = ["meam", "snap", "gap"]

class Lammps(Task):
def __init__(self, inter_parameter, path_to_poscar):
self.inter = inter_parameter
self.inter_type = inter_parameter["type"]
self.type_map = inter_parameter["type_map"]
self.in_lammps = inter_parameter.get("in_lammps", "auto")
if self.inter_type in ["meam", "snap"]:
if self.inter_type in MULTI_MODELS_INTER_TYPE:
self.model = list(map(os.path.abspath, inter_parameter["model"]))
else:
self.model = os.path.abspath(inter_parameter["model"])
Expand Down Expand Up @@ -76,6 +76,16 @@ def set_model_param(self):
"param_type": self.type_map,
"deepmd_version": deepmd_version,
}
elif self.inter_type == "gap":
model_name = list(map(os.path.basename, self.model))
self.model_param = {
"type": self.inter_type,
"model_name": model_name,
"param_type": self.type_map,
"init_string": self.inter.get("init_string", None),
"atomic_num_list": self.inter.get("atomic_num_list", None),
"deepmd_version": deepmd_version,
}
else:
model_name = os.path.basename(self.model)
self.model_param = {
Expand All @@ -101,10 +111,10 @@ def symlink_force(self, target, link_name):

def make_potential_files(self, output_dir):
parent_dir = os.path.join(output_dir, "../../")
if self.inter_type in ["meam", "snap"]:
model_lib, model_file = map(os.path.basename, self.model[:2])
targets = [self.model[0], self.model[1]]
link_names = [model_lib, model_file]
if self.inter_type in MULTI_MODELS_INTER_TYPE:
model_file = map(os.path.basename, self.model)
targets = self.model
link_names = list(model_file)
else:
model_file = os.path.basename(self.model)
targets = [self.model]
Expand Down Expand Up @@ -516,19 +526,19 @@ def _prepare_result_dict(self, atom_numbs, type_map_list, type_list, box, coord,
return result_dict

def forward_files(self, property_type="relaxation"):
if self.inter_type in ["meam", "snap"]:
if self.inter_type in MULTI_MODELS_INTER_TYPE:
return ["conf.lmp", "in.lammps"] + list(map(os.path.basename, self.model))
else:
return ["conf.lmp", "in.lammps", os.path.basename(self.model)]

def forward_common_files(self, property_type="relaxation"):
if property_type not in ["eos"]:
if self.inter_type in ["meam", "snap"]:
if self.inter_type in MULTI_MODELS_INTER_TYPE:
return ["in.lammps"] + list(map(os.path.basename, self.model))
else:
return ["in.lammps", os.path.basename(self.model)]
else:
if self.inter_type in ["meam", "snap"]:
if self.inter_type in MULTI_MODELS_INTER_TYPE:
return list(map(os.path.basename, self.model))
else:
return [os.path.basename(self.model)]
Expand Down
8 changes: 5 additions & 3 deletions apex/core/calculator/VASP.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ def make_input_file(self, output_dir, task_type, task_param):

# revise INCAR based on the INCAR provided in the "interaction"
else:
approach = None
if prop_type == "phonon":
approach = task_param.get("approach", "linear")
approach = task_param.get("approach")
logging.info(f"No specification of INCAR for {prop_type} calculation, will auto-generate")
if approach == "linear":
incar = incar_upper(Incar.from_str(
Expand Down Expand Up @@ -131,14 +132,15 @@ def make_input_file(self, output_dir, task_type, task_param):
)
incar["ISIF"] = isif

elif cal_type == "static":
elif cal_type == "static" and not approach == "linear":
nsw = 0
if not ("NSW" in incar and incar.get("NSW") == nsw):
logging.info(
"%s setting NSW to %d" % (self.make_input_file.__name__, nsw)
)
incar["NSW"] = nsw

elif cal_type == "static" and approach == "linear":
pass
else:
raise RuntimeError("not supported calculation type for VASP")

Expand Down
25 changes: 16 additions & 9 deletions apex/core/calculator/lib/abacus_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python3
import logging
import os, re
import os, re, glob

import dpdata
import numpy as np
Expand Down Expand Up @@ -410,16 +410,23 @@ def final_stru(abacus_path):
out_stru = bool(line.split()[1])
logf = os.path.join(abacus_path, "OUT.%s/running_%s.log" % (suffix, calculation))
if calculation in ["relax", "cell-relax"]:
if not out_stru:
if os.path.isfile(os.path.join(abacus_path, "OUT.%s/STRU_ION_D" % suffix)):
return "OUT.%s/STRU_ION_D" % suffix
else:
with open(logf) as f1:
lines = f1.readlines()
for i in range(1, len(lines)):
if lines[-i][36:41] == "istep":
max_step = int(lines[-i].split()[-1])
break
return "OUT.%s/STRU_ION%d_D" % (suffix, max_step)
# find the final name by STRU_ION*_D,
# for abacus version < v3.2.2, there has no STRU_ION_D file but has STRU_ION0_D STRU_ION1_D ... STRU_ION10_D ...
# so we need to find the last STRU_ION*_D file
stru_ions = glob.glob(
os.path.join(abacus_path, f"OUT.{suffix}/STRU_ION*_D")
)
if len(stru_ions) > 0:
# sort the file name by the number in the file name
stru_ions.sort(key=lambda x: int(x.split("_")[-2][3:]))
final_stru_ion = os.path.basename(stru_ions[-1])
return f"OUT.{suffix}/{final_stru_ion}"
else:
# if there has no STRU_ION_D, return the input STRU
return "STRU"
elif calculation == "md":
with open(logf) as f1:
lines = f1.readlines()
Expand Down
20 changes: 14 additions & 6 deletions apex/core/calculator/lib/lammps_utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#!/usr/bin/env python3

import os
import random
import subprocess as sp
import sys
import re

import dpdata
from dpdata.periodic_table import Element
from packaging.version import Version

from apex.core.lib import util
from apex.core.constants import PERIOD_ELEMENTS_BY_SYMBOL
from dflow.python import upload_packages
upload_packages.append(__file__)

Expand Down Expand Up @@ -153,11 +152,20 @@ def inter_snap(param):


def inter_gap(param):
init_string = param["init_string"]
atomic_num_list = param["atomic_num_list"]
if init_string is None:
with open(param["model_name"][0], "r") as fp:
xml_contents = fp.read()
init_string = re.search(r'label="([^"]*)"', xml_contents).group(1)
if atomic_num_list is None:
atomic_num_list = [PERIOD_ELEMENTS_BY_SYMBOL.index(e) + 1 for e in param["param_type"]]

ret = ""
line = "pair_style quip \n"
line += "pair_coeff * * %s " % param["model_name"][0]
for ii in param["param_type"]:
line += ii + " "
line += f'pair_coeff * * {param["model_name"][0]} "Potential xml_label={init_string}" '
for ii in atomic_num_list:
line += str(ii) + " "
line += "\n"
ret += line
return ret
Expand Down
13 changes: 12 additions & 1 deletion apex/core/common_equi.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,14 @@ def make_equi(confs, inter_param, relax_param):
sys.to("abacus/stru", stru)
else:
raise FileNotFoundError("No file %s" % stru)
if not os.path.exists(os.path.join(ii, POSCAR)):
sys = dpdata.System(stru, fmt="abacus/stru")
sys.to("vasp/poscar", os.path.join(ii, POSCAR))

shutil.copyfile(stru, os.path.join(ii, "STRU.bk"))
abacus_utils.modify_stru_path(stru, "pp_orb/", inter_param)
orig_poscar = poscar
orig_POSCAR = POSCAR
poscar = os.path.abspath(stru)
POSCAR = "STRU"
if not os.path.exists(poscar):
Expand All @@ -105,6 +110,8 @@ def make_equi(confs, inter_param, relax_param):
if os.path.isfile(POSCAR):
os.remove(POSCAR)
os.symlink(os.path.relpath(poscar), POSCAR)
if inter_param["type"] == "abacus":
os.symlink(os.path.relpath(orig_poscar), orig_POSCAR)
os.chdir(cwd)
task_dirs.sort()
# generate task files
Expand Down Expand Up @@ -189,7 +196,11 @@ def post_equi(confs, inter_param):
inter = make_calculator(inter_param, poscar)
res = inter.compute(ii)
contcar = os.path.join(ii, "CONTCAR")
ss = Structure.from_file(contcar)
try:
ss = Structure.from_file(contcar)
except FileNotFoundError:
logging.warning(f"No CONTCAR found in {ii}, skip")
continue
st = StructureInfo(ss)
struct_info_dict = {
"space_group_symbol": st.space_group_symbol,
Expand Down
14 changes: 14 additions & 0 deletions apex/core/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
PERIOD_ELEMENTS_BY_SYMBOL = [
"H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne",
"Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca",
"Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn",
"Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr",
"Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn",
"Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd",
"Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb",
"Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hg",
"Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th",
"Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm",
"Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds",
"Rg", "Cn", "Nh", "Fl", "Mc", "Lv", "Ts", "Og"
]
12 changes: 6 additions & 6 deletions apex/core/property/EOS.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(self, parameter, inter_param=None):
def make_confs(self, path_to_work, path_to_equi, refine=False):
path_to_work = os.path.abspath(path_to_work)
if os.path.exists(path_to_work):
logging.warning("%s already exists" % path_to_work)
logging.debug("%s already exists" % path_to_work)
else:
os.makedirs(path_to_work)
path_to_equi = os.path.abspath(path_to_equi)
Expand All @@ -84,7 +84,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
cwd = os.getcwd()
task_list = []
if self.reprod:
logging.info("eos reproduce starts")
print("eos reproduce starts")
if "init_data_path" not in self.parameter:
raise RuntimeError("please provide the initial data path to reproduce")
init_data_path = os.path.abspath(self.parameter["init_data_path"])
Expand All @@ -98,7 +98,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):

else:
if refine:
logging.info("eos refine starts")
print("eos refine starts")
task_list = make_refine(
self.parameter["init_from_suffix"],
self.parameter["output_suffix"],
Expand Down Expand Up @@ -127,7 +127,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
)

else:
logging.info(
print(
"gen eos from "
+ str(self.vol_start)
+ " to "
Expand All @@ -136,9 +136,9 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
+ str(self.vol_step)
)
if self.vol_abs:
logging.info("treat vol_start and vol_end as absolute volume")
print("treat vol_start and vol_end as absolute volume")
else:
logging.info("treat vol_start and vol_end as relative volume")
print("treat vol_start and vol_end as relative volume")

if self.inter_param["type"] == "abacus":
equi_contcar = os.path.join(
Expand Down
6 changes: 3 additions & 3 deletions apex/core/property/Elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, parameter, inter_param=None):
self.shear_deform = parameter["shear_deform"]
parameter.setdefault("conventional", False)
self.conventional = parameter["conventional"]
parameter.setdefault("ieee", True)
parameter.setdefault("ieee", False)
self.ieee = parameter["ieee"]
parameter.setdefault("cal_type", "relaxation")
self.cal_type = parameter["cal_type"]
Expand All @@ -55,7 +55,7 @@ def __init__(self, parameter, inter_param=None):
def make_confs(self, path_to_work, path_to_equi, refine=False):
path_to_work = os.path.abspath(path_to_work)
if os.path.exists(path_to_work):
logging.warning("%s already exists" % path_to_work)
logging.debug("%s already exists" % path_to_work)
else:
os.makedirs(path_to_work)
path_to_equi = os.path.abspath(path_to_equi)
Expand Down Expand Up @@ -96,7 +96,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
os.chdir(cwd)

if refine:
logging.info("elastic refine starts")
print("elastic refine starts")
task_list = make_refine(
self.parameter["init_from_suffix"],
self.parameter["output_suffix"],
Expand Down
Loading

0 comments on commit fadd74f

Please sign in to comment.