Skip to content

Commit

Permalink
merge devel to master (v0.12.1) (#1507)
Browse files Browse the repository at this point in the history
  • Loading branch information
njzjz authored Apr 10, 2024
2 parents 042ea32 + 53668e6 commit 47a23b3
Show file tree
Hide file tree
Showing 38 changed files with 1,135 additions and 218 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
target-branch: "devel"
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ jobs:
run: pip install -e .[test]
- name: Test
run: coverage run --source=./dpgen -m unittest -v && coverage report
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
pass:
needs: [build]
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Jinzhe Zeng <[email protected]>
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
# there are many log files in tests
# TODO: seperate py files and log files
Expand All @@ -28,7 +28,7 @@ repos:

# Python
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.3
rev: v0.3.5
hooks:
- id: ruff
args: ["--fix"]
Expand Down
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
prune conda
prune doc
prune tests
prune examples
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ Yuzhi Zhang, Haidi Wang, Weijie Chen, Jinzhe Zeng, Linfeng Zhang, Han Wang, and

## Download and Install

DP-GEN only supports Python 3.9 and above. You can use one of the following methods to install DP-GEN:
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:

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

To test if the installation is successful, you may execute
Expand Down
4 changes: 1 addition & 3 deletions dpgen/auto_test/lib/lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ def make_lammps_eval(conf, type_map, interaction, param):
ret += (
"thermo_style custom step pe pxx pyy pzz pxy pxz pyz lx ly lz vol c_mype\n"
)
ret += (
"dump 1 all custom 100 dump.relax id type xs ys zs fx fy fz\n"
) # 06/09 give dump.relax
ret += "dump 1 all custom 100 dump.relax id type xs ys zs fx fy fz\n" # 06/09 give dump.relax
ret += "run 0\n"
ret += "variable N equal count(all)\n"
ret += "variable V equal vol\n"
Expand Down
15 changes: 2 additions & 13 deletions dpgen/auto_test/lib/mfp_eosfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1441,16 +1441,7 @@ def ext_velp(
)
for i in range(ndata):
fw.write(
"{: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(
vv[i],
ee[i],
cellaa[i],
cellbb[i],
cellcc[i],
cellbaba[i],
cellcaca[i],
cellca_cal[i],
)
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"
)
fw.flush()
fw.close()
Expand Down Expand Up @@ -1662,9 +1653,7 @@ def lsqfit_eos(
)
for i in range(len(vol)):
fve.write(
"{:20f}\t{:20f}\t{:20f}\t{:20f}\n".format(
vol[i], repro_en[i], en[i], 100 * np.abs((en[i] - repro_en[i]) / en[i])
)
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"
)
fve.flush()
p_tmp = repro_press[i]
Expand Down
7 changes: 1 addition & 6 deletions dpgen/auto_test/lib/pwscf.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,7 @@ def _make_pwscf_03_config(sys_data):
cc = 0
for ii in range(ntypes):
for jj in range(atom_numbs[ii]):
ret += "{} {:f} {:f} {:f}\n".format(
atom_names[ii],
coordinates[cc][0],
coordinates[cc][1],
coordinates[cc][2],
)
ret += f"{atom_names[ii]} {coordinates[cc][0]:f} {coordinates[cc][1]:f} {coordinates[cc][2]:f}\n"
cc += 1
return ret

Expand Down
7 changes: 1 addition & 6 deletions dpgen/auto_test/reproduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,7 @@ def post_repro(
output_ener_tot.extend(output_task_result["energies"])

init_epa = init_ener[jj - idid] / natoms
ptr_data += "{} {:7.3f} {:7.3f} {:7.3f}\n".format(
ii,
init_epa,
output_epa,
output_epa - init_epa,
)
ptr_data += f"{ii} {init_epa:7.3f} {output_epa:7.3f} {output_epa - init_epa:7.3f}\n"
idid += nframe
output_ener = np.array(output_ener)
output_ener = np.reshape(output_ener, [-1, 1])
Expand Down
5 changes: 4 additions & 1 deletion dpgen/collect/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dpdata

from dpgen.generator.run import data_system_fmt
from dpgen.util import expand_sys_str


def collect_data(
Expand All @@ -18,7 +19,8 @@ def collect_data(
# goto input
cwd = os.getcwd()
os.chdir(target_folder)
jdata = json.load(open(param_file))
with open(param_file) as fp:
jdata = json.load(fp)
sys_configs_prefix = jdata.get("sys_configs_prefix", "")
sys_configs = jdata.get("sys_configs", [])
if verbose:
Expand Down Expand Up @@ -46,6 +48,7 @@ def collect_data(
for ii in range(len(iters)):
iter_data = glob.glob(os.path.join(iters[ii], "02.fp", "data.[0-9]*[0-9]"))
iter_data.sort()
iter_data = sum([expand_sys_str(ii) for ii in iter_data], [])
for jj in iter_data:
sys = dpdata.LabeledSystem(jj, fmt="deepmd/npy")
if merge:
Expand Down
5 changes: 4 additions & 1 deletion dpgen/data/surf.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,10 @@ def poscar_scale(poscar_in, poscar_out, scale):
except AttributeError:
poscar = Poscar.from_str("".join(lines))
with open(poscar_out, "w") as fout:
fout.write(poscar.get_string(direct=False))
try:
fout.write(poscar.get_string(direct=False))
except AttributeError:
fout.write(poscar.get_str(direct=False))


def make_scale(jdata):
Expand Down
2 changes: 1 addition & 1 deletion dpgen/data/tools/bcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def poscar_unit(latt):
ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n"
ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n"
ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n"
ret += "Type\n"
ret += "X\n"
ret += "%d\n" % numb_atoms()
ret += "Direct\n"
ret += f"{0.0:.16f} {0.0:.16f} {0.0:.16f}\n"
Expand Down
2 changes: 1 addition & 1 deletion dpgen/data/tools/diamond.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def poscar_unit(latt):
ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n"
ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n"
ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n"
ret += "Type\n"
ret += "X\n"
ret += "%d\n" % numb_atoms()
ret += "Direct\n"
ret += f"{0.12500000000000:.16f} {0.12500000000000:.16f} {0.12500000000000:.16f}\n"
Expand Down
2 changes: 1 addition & 1 deletion dpgen/data/tools/fcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def poscar_unit(latt):
ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n"
ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n"
ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n"
ret += "Type\n"
ret += "X\n"
ret += "%d\n" % numb_atoms()
ret += "Direct\n"
ret += f"{0.0:.16f} {0.0:.16f} {0.0:.16f}\n"
Expand Down
2 changes: 1 addition & 1 deletion dpgen/data/tools/hcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def poscar_unit(latt):
ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n"
ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n"
ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n"
ret += "Type\n"
ret += "X\n"
ret += "%d\n" % numb_atoms()
ret += "Direct\n"
ret += f"{0:.16f} {0:.16f} {0:.16f}\n"
Expand Down
1 change: 1 addition & 0 deletions dpgen/data/tools/ovito_file_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""This Script is adapted from Alexander Stukowski, the author of OVITO.
See: http://forum.ovito.org/index.php?topic=131.0 for details.
"""

import argparse

from ovito.io import export_file, import_file
Expand Down
2 changes: 1 addition & 1 deletion dpgen/data/tools/sc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def poscar_unit(latt):
ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n"
ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n"
ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n"
ret += "Type\n"
ret += "X\n"
ret += "%d\n" % numb_atoms()
ret += "Direct\n"
ret += f"{0.0:.16f} {0.0:.16f} {0.0:.16f}\n"
Expand Down
53 changes: 46 additions & 7 deletions dpgen/generator/arginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def training_args() -> list[Argument]:
doc_numb_models = "Number of models to be trained in 00.train. 4 is recommend."
doc_training_iter0_model_path = "The model used to init the first iter training. Number of element should be equal to numb_models."
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."
doc_default_training_param = "Training parameters for deepmd-kit in 00.train. You can find instructions from here: (https://github.com/deepmodeling/deepmd-kit)."
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/>`_."
doc_dp_train_skip_neighbor_stat = "Append --skip-neighbor-stat flag to dp train."
doc_dp_compress = "Use dp compress to compress the model."
doc_training_reuse_iter = "The minimal index of iteration that continues training models from old models of last iteration."
Expand Down Expand Up @@ -221,8 +221,8 @@ def model_devi_jobs_template_args() -> Argument:
"Through user-defined template, any freedom (function) that is permitted by the engine "
"software could be inherited (invoked) in the workflow."
)
doc_template_lmp = "The path to input.lammps template"
doc_template_plm = "The path to input.plumed template"
doc_template_lmp = "The path to input.lammps template. Instructions can be found in `LAMMPS documentation <https://docs.lammps.org/>`_."
doc_template_plm = "The path to input.plumed template. Instructions can be found in `PLUMED documentation <https://www.plumed.org/doc>`_."

args = [
Argument("lmp", str, optional=True, doc=doc_template_lmp),
Expand Down Expand Up @@ -325,10 +325,12 @@ def model_devi_lmp_args() -> list[Argument]:
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."
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."
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."
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\
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\
- 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\
- 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\
The union of the two sets is made as candidate dataset."
)
doc_model_devi_numb_candi_f = "See model_devi_adapt_trust_lo."
doc_model_devi_numb_candi_v = "See model_devi_adapt_trust_lo."
doc_model_devi_perc_candi_f = "See model_devi_adapt_trust_lo."
Expand Down Expand Up @@ -790,13 +792,14 @@ def fp_style_cp2k_args() -> list[Argument]:
]


# amber/diff
def fp_style_amber_diff_args() -> list[Argument]:
"""Arguments for FP style amber/diff.
Returns
-------
list[dargs.Argument]
list of Gaussian fp style arguments
list of amber/diff fp style arguments
"""
doc_fp_params_gaussian = "Parameters for FP calculation."
doc_high_level = (
Expand Down Expand Up @@ -827,13 +830,49 @@ def fp_style_amber_diff_args() -> list[Argument]:
]


# pwscf
def fp_style_pwscf_args() -> list[Argument]:
"""Arguments for FP style pwscf (Quantum Espresso).
Returns
-------
list[dargs.Argument]
list of pwscf fp style arguments
"""
doc_fp_pp_path = "Directory of psuedo-potential file to be used for 02.fp exists."
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."
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."
doc_fp_params = (
"Parameters for pwscf calculation. It has lower priority than user_fp_params."
)
doc_ecut = "ecutwfc in pwscf."
doc_ediff = "conv_thr and ts_vdw_econv_thr in pwscf."
doc_kspacing = "The spacing between kpoints. Helps to determin KPOINTS in pwscf."
doc_smearing = "smearing in pwscf."
doc_sigma = "degauss in pwscf."

args = [
Argument("ecut", float, optional=False, doc=doc_ecut),
Argument("ediff", float, optional=False, doc=doc_ediff),
Argument("smearing", str, optional=False, doc=doc_smearing),
Argument("sigma", float, optional=False, doc=doc_sigma),
Argument("kspacing", float, optional=False, doc=doc_kspacing),
]
return [
Argument("fp_pp_path", str, optional=False, doc=doc_fp_pp_path),
Argument("fp_pp_files", list[str], optional=False, doc=doc_fp_pp_files),
Argument("fp_params", dict, args, [], optional=True, doc=doc_fp_params),
Argument("user_fp_params", dict, optional=True, doc=doc_user_fp_params),
]


def fp_style_custom_args() -> list[Argument]:
"""Arguments for FP style custom.
Returns
-------
list[dargs.Argument]
list of Gaussian fp style arguments
list of custom fp style arguments
"""
doc_fp_params_custom = "Parameters for FP calculation."
doc_input_fmt = "Input dpdata format of the custom FP code. Such format should only need the first argument as the file name."
Expand Down Expand Up @@ -883,7 +922,7 @@ def fp_style_variant_type_args() -> Variant:
"amber/diff", dict, fp_style_amber_diff_args(), doc=doc_amber_diff
),
Argument("pwmat", dict, [], doc="TODO: add doc"),
Argument("pwscf", dict, [], doc="TODO: add doc"),
Argument("pwscf", dict, fp_style_pwscf_args()),
Argument("custom", dict, fp_style_custom_args(), doc=doc_custom),
],
optional=False,
Expand Down
6 changes: 3 additions & 3 deletions dpgen/generator/lib/abacus_scf.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,9 @@ def get_abacus_STRU(STRU, INPUT=None, n_ele=None):
data["atom_types"] = types
data["cells"] = cell
data["coords"] = coords
data[
"atom_masses"
] = masses # Notice that this key is not defined in dpdata system.
data["atom_masses"] = (
masses # Notice that this key is not defined in dpdata system.
)
data["pp_files"] = pp_files
data["orb_files"] = orb_files
data["dpks_descriptor"] = dpks_descriptor
Expand Down
Loading

0 comments on commit 47a23b3

Please sign in to comment.