Skip to content

Commit 57e1936

Browse files
Merge pull request #83 from deepmodeling/devel-1.2.0
Devel 1.2.0
2 parents 34f1acd + c69b55a commit 57e1936

20 files changed

+261
-168
lines changed

README.md

Lines changed: 149 additions & 116 deletions
Large diffs are not rendered by default.

apex/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
__version__ = '1.2.6'
2+
__version__ = '1.2.9'
33
LOCAL_PATH = os.getcwd()
44

55

apex/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class Config:
5959
group_size: int = None
6060
pool_size: int = None
6161
upload_python_packages: list = field(default_factory=list)
62+
exclude_upload_files: list = field(default_factory=list)
6263
lammps_image_name: str = None
6364
lammps_run_command: str = None
6465
vasp_image_name: str = None

apex/core/calculator/ABACUS.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ def make_input_file(self, output_dir, task_type, task_param):
148148
elif [relax_pos, relax_shape, relax_vol] == [False, True, True]:
149149
self.modify_input(incar, "calculation", "cell-relax")
150150
fix_atom = [True, True, True]
151+
elif [relax_pos, relax_shape, relax_vol] == [True, False, True]:
152+
self.modify_input(incar, "calculation", "cell-relax")
153+
self.modify_input(incar, "fixed_axes", "shape")
151154
elif [relax_pos, relax_shape, relax_vol] == [False, False, True]:
152155
raise RuntimeError(
153156
"relax volume but fix shape is not supported for ABACUS"

apex/core/calculator/Lammps.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
upload_packages.append(__file__)
2323

2424
# LAMMPS_INTER_TYPE = ['deepmd', 'eam_alloy', 'meam', 'eam_fs', 'meam_spline', 'snap', 'gap', 'rann', 'mace']
25-
25+
MULTI_MODELS_INTER_TYPE = ["meam", "snap", "gap"]
2626

2727
class Lammps(Task):
2828
def __init__(self, inter_parameter, path_to_poscar):
2929
self.inter = inter_parameter
3030
self.inter_type = inter_parameter["type"]
3131
self.type_map = inter_parameter["type_map"]
3232
self.in_lammps = inter_parameter.get("in_lammps", "auto")
33-
if self.inter_type in ["meam", "snap"]:
33+
if self.inter_type in MULTI_MODELS_INTER_TYPE:
3434
self.model = list(map(os.path.abspath, inter_parameter["model"]))
3535
else:
3636
self.model = os.path.abspath(inter_parameter["model"])
@@ -76,6 +76,16 @@ def set_model_param(self):
7676
"param_type": self.type_map,
7777
"deepmd_version": deepmd_version,
7878
}
79+
elif self.inter_type == "gap":
80+
model_name = list(map(os.path.basename, self.model))
81+
self.model_param = {
82+
"type": self.inter_type,
83+
"model_name": model_name,
84+
"param_type": self.type_map,
85+
"init_string": self.inter.get("init_string", None),
86+
"atomic_num_list": self.inter.get("atomic_num_list", None),
87+
"deepmd_version": deepmd_version,
88+
}
7989
else:
8090
model_name = os.path.basename(self.model)
8191
self.model_param = {
@@ -101,10 +111,10 @@ def symlink_force(self, target, link_name):
101111

102112
def make_potential_files(self, output_dir):
103113
parent_dir = os.path.join(output_dir, "../../")
104-
if self.inter_type in ["meam", "snap"]:
105-
model_lib, model_file = map(os.path.basename, self.model[:2])
106-
targets = [self.model[0], self.model[1]]
107-
link_names = [model_lib, model_file]
114+
if self.inter_type in MULTI_MODELS_INTER_TYPE:
115+
model_file = map(os.path.basename, self.model)
116+
targets = self.model
117+
link_names = list(model_file)
108118
else:
109119
model_file = os.path.basename(self.model)
110120
targets = [self.model]
@@ -516,19 +526,19 @@ def _prepare_result_dict(self, atom_numbs, type_map_list, type_list, box, coord,
516526
return result_dict
517527

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

524534
def forward_common_files(self, property_type="relaxation"):
525535
if property_type not in ["eos"]:
526-
if self.inter_type in ["meam", "snap"]:
536+
if self.inter_type in MULTI_MODELS_INTER_TYPE:
527537
return ["in.lammps"] + list(map(os.path.basename, self.model))
528538
else:
529539
return ["in.lammps", os.path.basename(self.model)]
530540
else:
531-
if self.inter_type in ["meam", "snap"]:
541+
if self.inter_type in MULTI_MODELS_INTER_TYPE:
532542
return list(map(os.path.basename, self.model))
533543
else:
534544
return [os.path.basename(self.model)]

apex/core/calculator/VASP.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ def make_input_file(self, output_dir, task_type, task_param):
7878

7979
# revise INCAR based on the INCAR provided in the "interaction"
8080
else:
81+
approach = None
8182
if prop_type == "phonon":
82-
approach = task_param.get("approach", "linear")
83+
approach = task_param.get("approach")
8384
logging.info(f"No specification of INCAR for {prop_type} calculation, will auto-generate")
8485
if approach == "linear":
8586
incar = incar_upper(Incar.from_str(
@@ -131,14 +132,15 @@ def make_input_file(self, output_dir, task_type, task_param):
131132
)
132133
incar["ISIF"] = isif
133134

134-
elif cal_type == "static":
135+
elif cal_type == "static" and not approach == "linear":
135136
nsw = 0
136137
if not ("NSW" in incar and incar.get("NSW") == nsw):
137138
logging.info(
138139
"%s setting NSW to %d" % (self.make_input_file.__name__, nsw)
139140
)
140141
incar["NSW"] = nsw
141-
142+
elif cal_type == "static" and approach == "linear":
143+
pass
142144
else:
143145
raise RuntimeError("not supported calculation type for VASP")
144146

apex/core/calculator/lib/abacus_utils.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/python3
22
import logging
3-
import os, re
3+
import os, re, glob
44

55
import dpdata
66
import numpy as np
@@ -410,16 +410,23 @@ def final_stru(abacus_path):
410410
out_stru = bool(line.split()[1])
411411
logf = os.path.join(abacus_path, "OUT.%s/running_%s.log" % (suffix, calculation))
412412
if calculation in ["relax", "cell-relax"]:
413-
if not out_stru:
413+
if os.path.isfile(os.path.join(abacus_path, "OUT.%s/STRU_ION_D" % suffix)):
414414
return "OUT.%s/STRU_ION_D" % suffix
415415
else:
416-
with open(logf) as f1:
417-
lines = f1.readlines()
418-
for i in range(1, len(lines)):
419-
if lines[-i][36:41] == "istep":
420-
max_step = int(lines[-i].split()[-1])
421-
break
422-
return "OUT.%s/STRU_ION%d_D" % (suffix, max_step)
416+
# find the final name by STRU_ION*_D,
417+
# for abacus version < v3.2.2, there has no STRU_ION_D file but has STRU_ION0_D STRU_ION1_D ... STRU_ION10_D ...
418+
# so we need to find the last STRU_ION*_D file
419+
stru_ions = glob.glob(
420+
os.path.join(abacus_path, f"OUT.{suffix}/STRU_ION*_D")
421+
)
422+
if len(stru_ions) > 0:
423+
# sort the file name by the number in the file name
424+
stru_ions.sort(key=lambda x: int(x.split("_")[-2][3:]))
425+
final_stru_ion = os.path.basename(stru_ions[-1])
426+
return f"OUT.{suffix}/{final_stru_ion}"
427+
else:
428+
# if there has no STRU_ION_D, return the input STRU
429+
return "STRU"
423430
elif calculation == "md":
424431
with open(logf) as f1:
425432
lines = f1.readlines()

apex/core/calculator/lib/lammps_utils.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#!/usr/bin/env python3
22

33
import os
4-
import random
5-
import subprocess as sp
6-
import sys
4+
import re
75

86
import dpdata
97
from dpdata.periodic_table import Element
108
from packaging.version import Version
119

1210
from apex.core.lib import util
11+
from apex.core.constants import PERIOD_ELEMENTS_BY_SYMBOL
1312
from dflow.python import upload_packages
1413
upload_packages.append(__file__)
1514

@@ -153,11 +152,20 @@ def inter_snap(param):
153152

154153

155154
def inter_gap(param):
155+
init_string = param["init_string"]
156+
atomic_num_list = param["atomic_num_list"]
157+
if init_string is None:
158+
with open(param["model_name"][0], "r") as fp:
159+
xml_contents = fp.read()
160+
init_string = re.search(r'label="([^"]*)"', xml_contents).group(1)
161+
if atomic_num_list is None:
162+
atomic_num_list = [PERIOD_ELEMENTS_BY_SYMBOL.index(e) + 1 for e in param["param_type"]]
163+
156164
ret = ""
157165
line = "pair_style quip \n"
158-
line += "pair_coeff * * %s " % param["model_name"][0]
159-
for ii in param["param_type"]:
160-
line += ii + " "
166+
line += f'pair_coeff * * {param["model_name"][0]} "Potential xml_label={init_string}" '
167+
for ii in atomic_num_list:
168+
line += str(ii) + " "
161169
line += "\n"
162170
ret += line
163171
return ret

apex/core/common_equi.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,14 @@ def make_equi(confs, inter_param, relax_param):
8585
sys.to("abacus/stru", stru)
8686
else:
8787
raise FileNotFoundError("No file %s" % stru)
88+
if not os.path.exists(os.path.join(ii, POSCAR)):
89+
sys = dpdata.System(stru, fmt="abacus/stru")
90+
sys.to("vasp/poscar", os.path.join(ii, POSCAR))
8891

8992
shutil.copyfile(stru, os.path.join(ii, "STRU.bk"))
9093
abacus_utils.modify_stru_path(stru, "pp_orb/", inter_param)
94+
orig_poscar = poscar
95+
orig_POSCAR = POSCAR
9196
poscar = os.path.abspath(stru)
9297
POSCAR = "STRU"
9398
if not os.path.exists(poscar):
@@ -105,6 +110,8 @@ def make_equi(confs, inter_param, relax_param):
105110
if os.path.isfile(POSCAR):
106111
os.remove(POSCAR)
107112
os.symlink(os.path.relpath(poscar), POSCAR)
113+
if inter_param["type"] == "abacus":
114+
os.symlink(os.path.relpath(orig_poscar), orig_POSCAR)
108115
os.chdir(cwd)
109116
task_dirs.sort()
110117
# generate task files

apex/core/constants.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
PERIOD_ELEMENTS_BY_SYMBOL = [
2+
"H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne",
3+
"Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca",
4+
"Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn",
5+
"Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr",
6+
"Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn",
7+
"Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd",
8+
"Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb",
9+
"Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hg",
10+
"Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th",
11+
"Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm",
12+
"Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds",
13+
"Rg", "Cn", "Nh", "Fl", "Mc", "Lv", "Ts", "Og"
14+
]

0 commit comments

Comments
 (0)