Skip to content

Commit 47a23b3

Browse files
authored
merge devel to master (v0.12.1) (#1507)
2 parents 042ea32 + 53668e6 commit 47a23b3

38 files changed

+1135
-218
lines changed

.github/dependabot.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
target-branch: "devel"

.github/workflows/test.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ jobs:
2121
run: pip install -e .[test]
2222
- name: Test
2323
run: coverage run --source=./dpgen -m unittest -v && coverage report
24-
- uses: codecov/codecov-action@v3
24+
- uses: codecov/codecov-action@v4
25+
env:
26+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2527
pass:
2628
needs: [build]
2729
runs-on: ubuntu-latest

.mailmap

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Jinzhe Zeng <[email protected]>

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.5.0
5+
rev: v4.6.0
66
hooks:
77
# there are many log files in tests
88
# TODO: seperate py files and log files
@@ -28,7 +28,7 @@ repos:
2828

2929
# Python
3030
- repo: https://github.com/astral-sh/ruff-pre-commit
31-
rev: v0.1.3
31+
rev: v0.3.5
3232
hooks:
3333
- id: ruff
3434
args: ["--fix"]

MANIFEST.in

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
prune conda
2+
prune doc
3+
prune tests
4+
prune examples

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ Yuzhi Zhang, Haidi Wang, Weijie Chen, Jinzhe Zeng, Linfeng Zhang, Han Wang, and
2323

2424
## Download and Install
2525

26-
DP-GEN only supports Python 3.9 and above. You can use one of the following methods to install DP-GEN:
26+
DP-GEN only supports Python 3.9 and above. You can [setup a conda/pip environment](https://docs.deepmodeling.com/faq/conda.html), and then use one of the following methods to install DP-GEN:
2727

2828
- Install via pip: `pip install dpgen`
29-
- Install via conda: `conda install -c conda-forge dpgen``
29+
- Install via conda: `conda install -c conda-forge dpgen`
3030
- Install from source code: `git clone https://github.com/deepmodeling/dpgen && pip install ./dpgen`
3131

3232
To test if the installation is successful, you may execute

dpgen/auto_test/lib/lammps.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,7 @@ def make_lammps_eval(conf, type_map, interaction, param):
189189
ret += (
190190
"thermo_style custom step pe pxx pyy pzz pxy pxz pyz lx ly lz vol c_mype\n"
191191
)
192-
ret += (
193-
"dump 1 all custom 100 dump.relax id type xs ys zs fx fy fz\n"
194-
) # 06/09 give dump.relax
192+
ret += "dump 1 all custom 100 dump.relax id type xs ys zs fx fy fz\n" # 06/09 give dump.relax
195193
ret += "run 0\n"
196194
ret += "variable N equal count(all)\n"
197195
ret += "variable V equal vol\n"

dpgen/auto_test/lib/mfp_eosfit.py

+2-13
Original file line numberDiff line numberDiff line change
@@ -1441,16 +1441,7 @@ def ext_velp(
14411441
)
14421442
for i in range(ndata):
14431443
fw.write(
1444-
"{:12.6f}\t{:12.6f}\t{:12.6f}\t{:12.6f}\t{:12.6f}\t{:12.6f}\t{:12.6f}\t{:12.6f}\n".format(
1445-
vv[i],
1446-
ee[i],
1447-
cellaa[i],
1448-
cellbb[i],
1449-
cellcc[i],
1450-
cellbaba[i],
1451-
cellcaca[i],
1452-
cellca_cal[i],
1453-
)
1444+
f"{vv[i]:12.6f}\t{ee[i]:12.6f}\t{cellaa[i]:12.6f}\t{cellbb[i]:12.6f}\t{cellcc[i]:12.6f}\t{cellbaba[i]:12.6f}\t{cellcaca[i]:12.6f}\t{cellca_cal[i]:12.6f}\n"
14541445
)
14551446
fw.flush()
14561447
fw.close()
@@ -1662,9 +1653,7 @@ def lsqfit_eos(
16621653
)
16631654
for i in range(len(vol)):
16641655
fve.write(
1665-
"{:20f}\t{:20f}\t{:20f}\t{:20f}\n".format(
1666-
vol[i], repro_en[i], en[i], 100 * np.abs((en[i] - repro_en[i]) / en[i])
1667-
)
1656+
f"{vol[i]:20f}\t{repro_en[i]:20f}\t{en[i]:20f}\t{100 * np.abs((en[i] - repro_en[i]) / en[i]):20f}\n"
16681657
)
16691658
fve.flush()
16701659
p_tmp = repro_press[i]

dpgen/auto_test/lib/pwscf.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,7 @@ def _make_pwscf_03_config(sys_data):
7272
cc = 0
7373
for ii in range(ntypes):
7474
for jj in range(atom_numbs[ii]):
75-
ret += "{} {:f} {:f} {:f}\n".format(
76-
atom_names[ii],
77-
coordinates[cc][0],
78-
coordinates[cc][1],
79-
coordinates[cc][2],
80-
)
75+
ret += f"{atom_names[ii]} {coordinates[cc][0]:f} {coordinates[cc][1]:f} {coordinates[cc][2]:f}\n"
8176
cc += 1
8277
return ret
8378

dpgen/auto_test/reproduce.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,7 @@ def post_repro(
153153
output_ener_tot.extend(output_task_result["energies"])
154154

155155
init_epa = init_ener[jj - idid] / natoms
156-
ptr_data += "{} {:7.3f} {:7.3f} {:7.3f}\n".format(
157-
ii,
158-
init_epa,
159-
output_epa,
160-
output_epa - init_epa,
161-
)
156+
ptr_data += f"{ii} {init_epa:7.3f} {output_epa:7.3f} {output_epa - init_epa:7.3f}\n"
162157
idid += nframe
163158
output_ener = np.array(output_ener)
164159
output_ener = np.reshape(output_ener, [-1, 1])

dpgen/collect/collect.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import dpdata
99

1010
from dpgen.generator.run import data_system_fmt
11+
from dpgen.util import expand_sys_str
1112

1213

1314
def collect_data(
@@ -18,7 +19,8 @@ def collect_data(
1819
# goto input
1920
cwd = os.getcwd()
2021
os.chdir(target_folder)
21-
jdata = json.load(open(param_file))
22+
with open(param_file) as fp:
23+
jdata = json.load(fp)
2224
sys_configs_prefix = jdata.get("sys_configs_prefix", "")
2325
sys_configs = jdata.get("sys_configs", [])
2426
if verbose:
@@ -46,6 +48,7 @@ def collect_data(
4648
for ii in range(len(iters)):
4749
iter_data = glob.glob(os.path.join(iters[ii], "02.fp", "data.[0-9]*[0-9]"))
4850
iter_data.sort()
51+
iter_data = sum([expand_sys_str(ii) for ii in iter_data], [])
4952
for jj in iter_data:
5053
sys = dpdata.LabeledSystem(jj, fmt="deepmd/npy")
5154
if merge:

dpgen/data/surf.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,10 @@ def poscar_scale(poscar_in, poscar_out, scale):
415415
except AttributeError:
416416
poscar = Poscar.from_str("".join(lines))
417417
with open(poscar_out, "w") as fout:
418-
fout.write(poscar.get_string(direct=False))
418+
try:
419+
fout.write(poscar.get_string(direct=False))
420+
except AttributeError:
421+
fout.write(poscar.get_str(direct=False))
419422

420423

421424
def make_scale(jdata):

dpgen/data/tools/bcc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def poscar_unit(latt):
1717
ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n"
1818
ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n"
1919
ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n"
20-
ret += "Type\n"
20+
ret += "X\n"
2121
ret += "%d\n" % numb_atoms()
2222
ret += "Direct\n"
2323
ret += f"{0.0:.16f} {0.0:.16f} {0.0:.16f}\n"

dpgen/data/tools/diamond.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def poscar_unit(latt):
2222
ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n"
2323
ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n"
2424
ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n"
25-
ret += "Type\n"
25+
ret += "X\n"
2626
ret += "%d\n" % numb_atoms()
2727
ret += "Direct\n"
2828
ret += f"{0.12500000000000:.16f} {0.12500000000000:.16f} {0.12500000000000:.16f}\n"

dpgen/data/tools/fcc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def poscar_unit(latt):
1717
ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n"
1818
ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n"
1919
ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n"
20-
ret += "Type\n"
20+
ret += "X\n"
2121
ret += "%d\n" % numb_atoms()
2222
ret += "Direct\n"
2323
ret += f"{0.0:.16f} {0.0:.16f} {0.0:.16f}\n"

dpgen/data/tools/hcp.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def poscar_unit(latt):
2020
ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n"
2121
ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n"
2222
ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n"
23-
ret += "Type\n"
23+
ret += "X\n"
2424
ret += "%d\n" % numb_atoms()
2525
ret += "Direct\n"
2626
ret += f"{0:.16f} {0:.16f} {0:.16f}\n"

dpgen/data/tools/ovito_file_convert.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""This Script is adapted from Alexander Stukowski, the author of OVITO.
33
See: http://forum.ovito.org/index.php?topic=131.0 for details.
44
"""
5+
56
import argparse
67

78
from ovito.io import export_file, import_file

dpgen/data/tools/sc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def poscar_unit(latt):
1717
ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n"
1818
ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n"
1919
ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n"
20-
ret += "Type\n"
20+
ret += "X\n"
2121
ret += "%d\n" % numb_atoms()
2222
ret += "Direct\n"
2323
ret += f"{0.0:.16f} {0.0:.16f} {0.0:.16f}\n"

dpgen/generator/arginfo.py

+46-7
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def training_args() -> list[Argument]:
9090
doc_numb_models = "Number of models to be trained in 00.train. 4 is recommend."
9191
doc_training_iter0_model_path = "The model used to init the first iter training. Number of element should be equal to numb_models."
9292
doc_training_init_model = "Iteration > 0, the model parameters will be initilized from the model trained at the previous iteration. Iteration == 0, the model parameters will be initialized from training_iter0_model_path."
93-
doc_default_training_param = "Training parameters for deepmd-kit in 00.train. You can find instructions from here: (https://github.com/deepmodeling/deepmd-kit)."
93+
doc_default_training_param = "Training parameters for deepmd-kit in 00.train. You can find instructions from `DeePMD-kit documentation <https://docs.deepmodeling.org/projects/deepmd/>`_."
9494
doc_dp_train_skip_neighbor_stat = "Append --skip-neighbor-stat flag to dp train."
9595
doc_dp_compress = "Use dp compress to compress the model."
9696
doc_training_reuse_iter = "The minimal index of iteration that continues training models from old models of last iteration."
@@ -221,8 +221,8 @@ def model_devi_jobs_template_args() -> Argument:
221221
"Through user-defined template, any freedom (function) that is permitted by the engine "
222222
"software could be inherited (invoked) in the workflow."
223223
)
224-
doc_template_lmp = "The path to input.lammps template"
225-
doc_template_plm = "The path to input.plumed template"
224+
doc_template_lmp = "The path to input.lammps template. Instructions can be found in `LAMMPS documentation <https://docs.lammps.org/>`_."
225+
doc_template_plm = "The path to input.plumed template. Instructions can be found in `PLUMED documentation <https://www.plumed.org/doc>`_."
226226

227227
args = [
228228
Argument("lmp", str, optional=True, doc=doc_template_lmp),
@@ -325,10 +325,12 @@ def model_devi_lmp_args() -> list[Argument]:
325325
doc_model_devi_f_trust_hi = "Upper bound of forces for the selection. If list or dict, should be set for each index in sys_configs, respectively."
326326
doc_model_devi_v_trust_lo = "Lower bound of virial for the selection. If list or dict, should be set for each index in sys_configs, respectively. Should be used with DeePMD-kit v2.x."
327327
doc_model_devi_v_trust_hi = "Upper bound of virial for the selection. If list or dict, should be set for each index in sys_configs, respectively. Should be used with DeePMD-kit v2.x."
328-
doc_model_devi_adapt_trust_lo = "Adaptively determines the lower trust levels of force and virial. This option should be used together with model_devi_numb_candi_f, model_devi_numb_candi_v and optionally with model_devi_perc_candi_f and model_devi_perc_candi_v. dpgen will make two sets:\n\n\
328+
doc_model_devi_adapt_trust_lo = (
329+
"Adaptively determines the lower trust levels of force and virial. This option should be used together with model_devi_numb_candi_f, model_devi_numb_candi_v and optionally with model_devi_perc_candi_f and model_devi_perc_candi_v. dpgen will make two sets:\n\n\
329330
- 1. From the frames with force model deviation lower than model_devi_f_trust_hi, select max(model_devi_numb_candi_f, model_devi_perc_candi_f*n_frames) frames with largest force model deviation. \n\n\
330331
- 2. From the frames with virial model deviation lower than model_devi_v_trust_hi, select max(model_devi_numb_candi_v, model_devi_perc_candi_v*n_frames) frames with largest virial model deviation. \n\n\
331332
The union of the two sets is made as candidate dataset."
333+
)
332334
doc_model_devi_numb_candi_f = "See model_devi_adapt_trust_lo."
333335
doc_model_devi_numb_candi_v = "See model_devi_adapt_trust_lo."
334336
doc_model_devi_perc_candi_f = "See model_devi_adapt_trust_lo."
@@ -790,13 +792,14 @@ def fp_style_cp2k_args() -> list[Argument]:
790792
]
791793

792794

795+
# amber/diff
793796
def fp_style_amber_diff_args() -> list[Argument]:
794797
"""Arguments for FP style amber/diff.
795798
796799
Returns
797800
-------
798801
list[dargs.Argument]
799-
list of Gaussian fp style arguments
802+
list of amber/diff fp style arguments
800803
"""
801804
doc_fp_params_gaussian = "Parameters for FP calculation."
802805
doc_high_level = (
@@ -827,13 +830,49 @@ def fp_style_amber_diff_args() -> list[Argument]:
827830
]
828831

829832

833+
# pwscf
834+
def fp_style_pwscf_args() -> list[Argument]:
835+
"""Arguments for FP style pwscf (Quantum Espresso).
836+
837+
Returns
838+
-------
839+
list[dargs.Argument]
840+
list of pwscf fp style arguments
841+
"""
842+
doc_fp_pp_path = "Directory of psuedo-potential file to be used for 02.fp exists."
843+
doc_fp_pp_files = "Psuedo-potential file to be used for 02.fp. Note that the order of elements should correspond to the order in type_map."
844+
doc_user_fp_params = "Parameters for pwscf calculation. Find details at https://www.quantum-espresso.org/Doc/INPUT_PW.html. When user_fp_params is set, the settings in fp_params will be ignored. If one wants to use user_fp_params, kspacing must be set in user_fp_params. kspacing is the spacing between kpoints, and helps to determin KPOINTS in pwscf."
845+
doc_fp_params = (
846+
"Parameters for pwscf calculation. It has lower priority than user_fp_params."
847+
)
848+
doc_ecut = "ecutwfc in pwscf."
849+
doc_ediff = "conv_thr and ts_vdw_econv_thr in pwscf."
850+
doc_kspacing = "The spacing between kpoints. Helps to determin KPOINTS in pwscf."
851+
doc_smearing = "smearing in pwscf."
852+
doc_sigma = "degauss in pwscf."
853+
854+
args = [
855+
Argument("ecut", float, optional=False, doc=doc_ecut),
856+
Argument("ediff", float, optional=False, doc=doc_ediff),
857+
Argument("smearing", str, optional=False, doc=doc_smearing),
858+
Argument("sigma", float, optional=False, doc=doc_sigma),
859+
Argument("kspacing", float, optional=False, doc=doc_kspacing),
860+
]
861+
return [
862+
Argument("fp_pp_path", str, optional=False, doc=doc_fp_pp_path),
863+
Argument("fp_pp_files", list[str], optional=False, doc=doc_fp_pp_files),
864+
Argument("fp_params", dict, args, [], optional=True, doc=doc_fp_params),
865+
Argument("user_fp_params", dict, optional=True, doc=doc_user_fp_params),
866+
]
867+
868+
830869
def fp_style_custom_args() -> list[Argument]:
831870
"""Arguments for FP style custom.
832871
833872
Returns
834873
-------
835874
list[dargs.Argument]
836-
list of Gaussian fp style arguments
875+
list of custom fp style arguments
837876
"""
838877
doc_fp_params_custom = "Parameters for FP calculation."
839878
doc_input_fmt = "Input dpdata format of the custom FP code. Such format should only need the first argument as the file name."
@@ -883,7 +922,7 @@ def fp_style_variant_type_args() -> Variant:
883922
"amber/diff", dict, fp_style_amber_diff_args(), doc=doc_amber_diff
884923
),
885924
Argument("pwmat", dict, [], doc="TODO: add doc"),
886-
Argument("pwscf", dict, [], doc="TODO: add doc"),
925+
Argument("pwscf", dict, fp_style_pwscf_args()),
887926
Argument("custom", dict, fp_style_custom_args(), doc=doc_custom),
888927
],
889928
optional=False,

dpgen/generator/lib/abacus_scf.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,9 @@ def get_abacus_STRU(STRU, INPUT=None, n_ele=None):
401401
data["atom_types"] = types
402402
data["cells"] = cell
403403
data["coords"] = coords
404-
data[
405-
"atom_masses"
406-
] = masses # Notice that this key is not defined in dpdata system.
404+
data["atom_masses"] = (
405+
masses # Notice that this key is not defined in dpdata system.
406+
)
407407
data["pp_files"] = pp_files
408408
data["orb_files"] = orb_files
409409
data["dpks_descriptor"] = dpks_descriptor

0 commit comments

Comments
 (0)