Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
811804f
Arguments for cpx fp_style
Constant206462 Sep 13, 2025
77b0066
Implementation of make_fp_cpx
Constant206462 Sep 13, 2025
949951a
Implementation of run_fp for cpx fp_style
Constant206462 Sep 13, 2025
7f6c889
Implementation of post_fp_cpx
Constant206462 Sep 13, 2025
e28ffcf
Examples of template files needed for cpx fp_style
Constant206462 Sep 13, 2025
fb2ddd4
fixing mistake
Constant206462 Sep 13, 2025
1067da1
fixing mistakes
Constant206462 Sep 20, 2025
436bd2c
output in backward files for cpx
Constant206462 Sep 20, 2025
9a3b0c9
"output" file as flag for completion
Constant206462 Sep 20, 2025
2402b71
expected POSCAR examples
Constant206462 Sep 20, 2025
f3e95c6
tests are done
Constant206462 Sep 20, 2025
b9a6f77
example param and machine input files for dpgen run with cp.x
Constant206462 Sep 20, 2025
4db9559
Merge branch 'deepmodeling:devel' into devel
Constant206462 Sep 20, 2025
7c5c7ba
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 20, 2025
11919a7
better parallel setup example for cpx
Constant206462 Sep 21, 2025
c4ef20c
QE cp.x template should be configured for electron relaxation procedure
Constant206462 Sep 21, 2025
092181f
Merge branch 'devel' of https://github.com/Constant206462/dpgen into …
Constant206462 Sep 21, 2025
c1cacc4
Merge branch 'deepmodeling:devel' into devel
Constant206462 Sep 28, 2025
0ec4b24
Documentation information on cpx fp_style
Constant206462 Sep 28, 2025
b0a6ed4
Test cpx examples
Constant206462 Sep 28, 2025
99f73f1
path placeholder to pseudopotentials
Constant206462 Sep 28, 2025
9e20814
generalized relative paths
Constant206462 Sep 28, 2025
f072626
fix missing key "batch_type" in "resources"
Constant206462 Sep 28, 2025
f4f3552
fix mistake
Constant206462 Sep 28, 2025
e82cc3d
Complete test make_fp for cpx fp_style
Constant206462 Oct 4, 2025
8a79cdd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 4, 2025
0f6775d
Merge branch 'devel' into devel
Constant206462 Oct 4, 2025
f95833c
fix indexing
Constant206462 Oct 4, 2025
4a09966
fix mass_map
Constant206462 Oct 4, 2025
a78b356
absolute path for template file to pass the test
Constant206462 Oct 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/overview/supported-software.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ Configure the INPUT file properly with appropriate basis sets and k-point sampli

Ensure proper pseudopotential selection and k-point convergence for calculations. The extensive documentation and large user community provide good support for troubleshooting.

### CPMD (Quantum ESPRESSO)

{dargs:argument}`fp_style <run_jdata/fp_style>`: `cpx`

CPMD (Car-Parrinello Molecular Dynamics) is another integration from [Quantum ESPRESSO](https://www.quantum-espresso.org/) suite, specifically the `cp.x` executable. This interface is well-suited for calculating energies and forces of various types of structures, even large molecules, using Car-Parrinello method. It utilizes a plane-wave basis set and pseudopotentials, optimized for efficient molecular dynamics simulations.

To use it with DP-GEN, one must prepare a template for the `cp.x` program configured for an electron relaxation procedure to obtain accurate ground-state properties, which is usually achieved after several tens to several hundred minimization steps. Be cautious to set `iprint` equal to `nstep` to ensure the output contains the final relaxed structure and its properties. Other key configuration requirements for the template are: both `ATOMIC_POSITIONS` and `CELL_PARAMETERS` cards must contain the `{angstrom}` keyword; the `%POSITIONS%` string must be in place of actual atomic coordinates, while the `%CELL%` string must be in place of actual cell vectors. It is also recommended to use absolute path for pseudopotentials. Ensure proper pseudopotential selection and electron dynamics configuration for reliable results.

### PWmat

{dargs:argument}`fp_style <run_jdata/fp_style>`: `pwmat`
Expand Down
26 changes: 26 additions & 0 deletions dpgen/generator/arginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,31 @@ def fp_style_pwscf_args() -> list[Argument]:
]


def fp_style_cpx_args() -> list[Argument]:
"""Arguments for FP style cpx (Car-Parrinello Quantum Espresso).

Returns
-------
list[dargs.Argument]
list of cpx fp style arguments
"""
doc_fp_params_cpx = "Parameters for FP calculation."
doc_input_fn = "Input file name for cp.x without file extension (.in). Essentially must be the same as the prefix in the template."
doc_template = "Template file name. Is used for completing the input file. Should contain all necessary FP configurations besides ATOMIC_POSITIONS and CELL_PARAMETERS"
return [
Argument(
"fp_params",
dict,
optional=False,
doc=doc_fp_params_cpx,
sub_fields=[
Argument("input_fn", str, optional=False, doc=doc_input_fn),
Argument("template_fn", str, optional=False, doc=doc_template),
],
),
]


def fp_style_custom_args() -> list[Argument]:
"""Arguments for FP style custom.

Expand Down Expand Up @@ -990,6 +1015,7 @@ def fp_style_variant_type_args() -> Variant:
),
Argument("pwmat", dict, [], doc="TODO: add doc"),
Argument("pwscf", dict, fp_style_pwscf_args()),
Argument("cpx", dict, fp_style_cpx_args()),
Argument("custom", dict, fp_style_custom_args(), doc=doc_custom),
],
optional=False,
Expand Down
109 changes: 109 additions & 0 deletions dpgen/generator/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3902,6 +3902,53 @@ def make_fp_amber_diff(iter_index: int, jdata: dict):
os.chdir(cwd)


def make_fp_cpx(iter_index, jdata):
"""Make input file for Quantum Espresso Car-Parrinello (cp.x) run.

Convert the POSCAR file to cp.x input file using prepared template.

Parameters
----------
iter_index : int
iter index
jdata : dict
Run parameters.
"""
work_path = os.path.join(make_iter_name(iter_index), fp_name)
fp_tasks = glob.glob(os.path.join(work_path, "task.*"))
fp_params = jdata["fp_params"]
input_fn = fp_params["input_fn"]
template_fn = fp_params["template_fn"]

with open(template_fn) as tn:
template = tn.read()

for ii in fp_tasks:
itemp = copy.deepcopy(template)
with set_directory(Path(ii)):
system = dpdata.System("POSCAR", fmt="vasp/poscar")
# convert POSCAR to cp.in
cell_param = ""
for a in system["cells"][0]:
for v in a:
cell_param += f"{v:.16e} "
cell_param += "\n"
itemp = itemp.replace("%CELL%", cell_param)

pos = ""
ntypes = system.get_ntypes()
numbs = system.get_atom_numbs()
names = system.get_atom_names()
coords = system["coords"][0]
for t in range(ntypes):
ts = sum(numbs[:t])
for a in range(numbs[t]):
pos += f"{names[t]:2} {coords[a + ts, 0]:20.16f} {coords[a + ts, 1]:20.16f} {coords[a + ts, 2]:20.16f}\n"
itemp = itemp.replace("%POSITIONS%", pos)
with open(input_fn + ".in", "w") as fp:
fp.write(itemp)


def make_fp_custom(iter_index, jdata):
"""Make input file for customized FP style.

Expand Down Expand Up @@ -3973,6 +4020,8 @@ def make_fp_calculation(iter_index, jdata, mdata):
make_fp_pwmat(iter_index, jdata)
elif fp_style == "amber/diff":
make_fp_amber_diff(iter_index, jdata)
elif fp_style == "cpx":
make_fp_cpx(iter_index, jdata)
elif fp_style == "custom":
make_fp_custom(iter_index, jdata)
else:
Expand Down Expand Up @@ -4280,6 +4329,20 @@ def run_fp(iter_index, jdata, mdata):
log_file="output",
forward_common_files=forward_common_files,
)
elif fp_style == "cpx":
extensions = [".cel", ".evp", ".for", ".pos", ".str"]
input_fn = jdata["fp_params"]["input_fn"]
forward_files = [input_fn + ".in"]
backward_files = [input_fn + ext for ext in extensions] + ["output"]
run_fp_inner(
iter_index,
jdata,
mdata,
forward_files,
backward_files,
_qe_check_fin,
log_file="output",
)
elif fp_style == "custom":
fp_params = jdata["fp_params"]
forward_files = [fp_params["input_fn"]]
Expand Down Expand Up @@ -4750,6 +4813,50 @@ def post_fp_amber_diff(iter_index, jdata):
all_sys.to_deepmd_npy(sys_data_path, set_size=len(sys_output), prec=np.float64)


def post_fp_cpx(iter_index, jdata):
"""Post fp for cp.x. Collect data from qe/cp/traj labeled system.

Parameters
----------
iter_index : int
The index of the current iteration.
jdata : dict
The parameter data.
"""
model_devi_jobs = jdata["model_devi_jobs"]
assert iter_index < len(model_devi_jobs)

iter_name = make_iter_name(iter_index)
work_path = os.path.join(iter_name, fp_name)
fp_tasks = glob.glob(os.path.join(work_path, "task.*"))
fp_tasks.sort()
if len(fp_tasks) == 0:
return

system_index = []
for ii in fp_tasks:
system_index.append(os.path.basename(ii).split(".")[1])
system_index.sort()
set_tmp = set(system_index)
system_index = list(set_tmp)
system_index.sort()

fp_params = jdata["fp_params"]
input_fn = fp_params["input_fn"]

for ss in system_index:
sys_output = glob.glob(os.path.join(work_path, f"task.{ss}.*"))
sys_output.sort()
all_sys = dpdata.MultiSystems(type_map=jdata["type_map"])
for oo in sys_output:
if os.path.exists(os.path.join(oo, "output")):
sys = dpdata.LabeledSystem(os.path.join(oo, input_fn), fmt="qe/cp/traj")
all_sys.append(sys)
sys_data_path = os.path.join(work_path, f"data.{ss}")
all_sys.to_deepmd_raw(sys_data_path)
all_sys.to_deepmd_npy(sys_data_path, set_size=len(sys_output), prec=np.float64)


def post_fp_custom(iter_index, jdata):
"""Post fp for custom fp. Collect data from user-defined `output_fn`.

Expand Down Expand Up @@ -4813,6 +4920,8 @@ def post_fp(iter_index, jdata):
post_fp_pwmat(iter_index, jdata)
elif fp_style == "amber/diff":
post_fp_amber_diff(iter_index, jdata)
elif fp_style == "cpx":
post_fp_cpx(iter_index, jdata)
elif fp_style == "custom":
post_fp_custom(iter_index, jdata)
else:
Expand Down
78 changes: 78 additions & 0 deletions examples/qe-cpx/POSCAR_SiO2-phosph
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
PSiO2 70 atoms
1.0
9.712 0.0 0.0
0.0 7.284 0.0
0.0 0.0 25.0
Si O P
18 36 16
Cartesian
0.0 2.280860772 8.54401772
2.5751368 1.287570828 6.77198228
2.2808631999999998 3.7155684 5.0
0.0 7.1368632 8.54401772
2.5751368 6.143565971999999 6.77198228
7.1368632 1.287570828 5.0
4.856 4.708865628 8.54401772
7.4311368 3.7155684 6.77198228
7.1368632 6.143565971999999 5.0
0.0 2.280860772 13.86001772
2.5751368 1.287570828 12.087982279999999
2.2808631999999998 3.7155684 10.315999999999999
0.0 7.1368632 13.86001772
2.5751368 6.143565971999999 12.087982279999999
7.1368632 1.287570828 10.315999999999999
4.856 4.708865628 13.86001772
7.4311368 3.7155684 12.087982279999999
7.1368632 6.143565971999999 10.315999999999999
2.0069848 0.2940310428 5.6315408
4.1465384 0.7757459999999999 7.403523079999999
1.2975231999999999 1.358225628 7.91247692
0.7094616 3.2037435719999996 9.6844592
2.8490151999999997 2.7220307999999998 6.14044148
5.565461599999999 0.7757459999999999 9.6844592
7.7050152 0.2940310428 6.14044148
2.0069848 5.150028372 5.6315408
3.5584767999999998 3.7862232000000002 9.17555852
4.1465384 5.631748428 7.403523079999999
1.2975231999999999 6.214220772 7.91247692
6.8629847999999996 2.7220307999999998 5.6315408
8.4144768 1.358225628 9.17555852
9.0025384 3.2037435719999996 7.403523079999999
6.1535232 3.7862232000000002 7.91247692
5.565461599999999 5.631748428 9.6844592
7.7050152 5.150028372 6.14044148
8.4144768 6.214220772 9.17555852
2.0069848 0.2940310428 10.947540799999999
4.1465384 0.7757459999999999 12.719523079999998
1.2975231999999999 1.358225628 13.22847692
0.7094616 3.2037435719999996 15.0004592
2.8490151999999997 2.7220307999999998 11.45644148
5.565461599999999 0.7757459999999999 15.0004592
7.7050152 0.2940310428 11.45644148
2.0069848 5.150028372 10.947540799999999
3.5584767999999998 3.7862232000000002 14.49155852
4.1465384 5.631748428 12.719523079999998
1.2975231999999999 6.214220772 13.22847692
6.8629847999999996 2.7220307999999998 10.947540799999999
8.4144768 1.358225628 14.49155852
9.0025384 3.2037435719999996 12.719523079999998
6.1535232 3.7862232000000002 13.22847692
5.565461599999999 5.631748428 15.0004592
7.7050152 5.150028372 11.45644148
8.4144768 6.214220772 14.49155852
0.00476347936058176 0.0329022524829 18.956790026599506
1.492078463890618 1.6780148766279 18.956795481599528
2.2060016312005817 1.6780148766279 16.83262392826639
3.6933254206832253 0.0329022524829 16.83262392826639
4.407239783040581 0.0329022524829 18.956790026599506
5.894554767570618 1.6780148766279 18.956795481599528
6.608477934880581 1.6780148766279 16.83262392826639
8.095801724363225 0.0329022524829 16.83262392826639
0.00476347936058176 3.3231275007728995 18.956790026599506
1.492078463890618 4.9682401249179 18.956795481599528
2.2060016312005817 4.9682401249179 16.83262392826639
3.6933254206832253 3.3231275007728995 16.83262392826639
4.407239783040581 3.3231275007728995 18.956790026599506
5.894554767570618 4.9682401249179 18.956795481599528
6.608477934880581 4.9682401249179 16.83262392826639
8.095801724363225 3.3231275007728995 16.83262392826639
24 changes: 24 additions & 0 deletions examples/qe-cpx/POSCAR_phosphorene
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
P16
1.0
8.8051536400000000e+00 0.0000000000000000e+00 0.0000000000000000e+00
0.0000000000000000e+00 6.5802993500000000e+00 0.0000000000000000e+00
0.0000000000000000e+00 0.0000000000000000e+00 2.1819520480000000e+01
P
16
Cartesian
0.0047932879 0.0329221655 12.1379214560
1.4920806296 1.6779599686 12.1379256454
2.2061033938 1.6779553229 10.0134938897
3.6933908587 0.0329258241 10.0134877584
4.4073895408 0.0329264690 12.1379193395
5.8946802725 1.6779594027 12.1379136883
6.6086281312 1.6779562836 10.0134764995
8.0959086049 0.0329227774 10.0134900713
0.0048354294 3.3230308180 12.1379111354
1.4920256238 4.9681445314 12.1379043059
2.2061652764 4.9681443340 10.0134972717
3.6933414794 3.3230264750 10.0134912277
4.4074328798 3.3230248628 12.1379032804
5.8946135118 4.9681435707 12.1379085170
6.6086811470 4.9681455908 10.0134957444
8.0958607312 3.3230316405 10.0134979045
47 changes: 47 additions & 0 deletions examples/qe-cpx/qe_template_P.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
&CONTROL
calculation='cp',
restart_mode='from_scratch'
outdir='.',
prefix='P',
pseudo_dir='/your/path/to/pseudopotentials',
nstep=100,
iprint=100,
isave=200,
dt=5.0,
ndw=50,
tprnfor=.true.
tstress=.true.
etot_conv_thr=1.d-9
ekin_conv_thr=1.d-7
/

&SYSTEM
ibrav=0,
nat=16,
ntyp=1,
ecutwfc=60,
ecutrho=360,
nr1b=20, nr2b=20, nr3b=20,
/

&ELECTRONS
electron_dynamics='damp',
electron_damping=0.1,
emass=300,
orthogonalization='ortho',
ortho_eps=1d-11,
ortho_max=1000
/

&IONS
ion_dynamics='none'
/

ATOMIC_SPECIES
P 30.973762d0 P.pbesol-n-rrkjus_psl.1.0.0.UPF

ATOMIC_POSITIONS {angstrom}
%POSITIONS%

CELL_PARAMETERS {angstrom}
%CELL%
Loading