Skip to content

Commit 53e8961

Browse files
committed
parse multiple epsilon values for lj/cut/soft
1 parent 12b6649 commit 53e8961

File tree

1 file changed

+39
-56
lines changed

1 file changed

+39
-56
lines changed

dpti/hti_liq.py

Lines changed: 39 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -27,46 +27,56 @@
2727
def make_iter_name(iter_index):
2828
return "task_hti." + ("%04d" % iter_index)
2929

30+
def parse_lj_sigma_epsilon(ret, sparam):
31+
element_num = sparam.get("element_num", 1)
32+
sigma_key_index = filter(
33+
lambda t: t[0] <= t[1],
34+
((i, j) for i in range(element_num) for j in range(element_num)),
35+
)
36+
activation = sparam["activation"]
37+
epsilon = sparam.get("epsilon", None)
38+
epsilon_0_0 = sparam.get("epsilon_0_0", None)
39+
if epsilon is not None:
40+
assert epsilon_0_0 is None, "epsilon and epsilon_0_0 cannot be set at the same time"
41+
ret += f"variable EPSILON equal {epsilon:f}\n"
42+
for i, j in sigma_key_index:
43+
ret += "pair_coeff {} {} ${{EPSILON}} {:f} {:f}\n".format(
44+
i + 1,
45+
j + 1,
46+
sparam["sigma_" + str(i) + "_" + str(j)],
47+
activation,
48+
)
49+
else:
50+
assert epsilon_0_0 is not None, "epsilon or epsilon_0_0 must be set"
51+
for i, j in sigma_key_index:
52+
ret += "pair_coeff {} {} {:f} {:f} {:f}\n".format(
53+
i + 1,
54+
j + 1,
55+
sparam["epsilon_" + str(i) + "_" + str(j)],
56+
sparam["sigma_" + str(i) + "_" + str(j)],
57+
activation,
58+
)
59+
return ret
3060

3161
def _ff_soft_on(lamb, sparam):
3262
nn = sparam["n"]
3363
alpha_lj = sparam["alpha_lj"]
3464
rcut = sparam["rcut"]
35-
epsilon = sparam["epsilon"]
36-
# sigma = sparam['sigma']
37-
activation = sparam["activation"]
3865
ret = ""
39-
ret += f"variable EPSILON equal {epsilon:f}\n"
4066
ret += f"pair_style lj/cut/soft {nn:f} {alpha_lj:f} {rcut:f}\n"
67+
ret = parse_lj_sigma_epsilon(ret, sparam)
4168

42-
element_num = sparam.get("element_num", 1)
43-
sigma_key_index = filter(
44-
lambda t: t[0] <= t[1],
45-
((i, j) for i in range(element_num) for j in range(element_num)),
46-
)
47-
for i, j in sigma_key_index:
48-
ret += "pair_coeff {} {} ${{EPSILON}} {:f} {:f}\n".format(
49-
i + 1,
50-
j + 1,
51-
sparam["sigma_" + str(i) + "_" + str(j)],
52-
activation,
53-
)
54-
55-
# ret += 'pair_coeff * * ${EPSILON} %f %f\n' % (sigma, activation)
5669
ret += "fix tot_pot all adapt/fep 0 pair lj/cut/soft epsilon * * v_LAMBDA scale yes\n"
57-
ret += "compute e_diff all fep ${TEMP} pair lj/cut/soft epsilon * * v_EPSILON\n"
70+
ret += "compute lj_pe all pair lj/cut/soft\n"
71+
ret += "variable e_diff equal c_lj_pe/v_LAMBDA\n"
5872
return ret
5973

6074

6175
def _ff_deep_on(lamb, sparam, model, if_meam=False, meam_model=None):
6276
nn = sparam["n"]
6377
alpha_lj = sparam["alpha_lj"]
6478
rcut = sparam["rcut"]
65-
epsilon = sparam["epsilon"]
66-
# sigma = sparam['sigma']
67-
activation = sparam["activation"]
6879
ret = ""
69-
ret += f"variable EPSILON equal {epsilon:f}\n"
7080
ret += "variable ONE equal 1\n"
7181
if if_meam:
7282
ret += f"pair_style hybrid/overlay meam lj/cut/soft {nn:f} {alpha_lj:f} {rcut:f}\n"
@@ -76,20 +86,8 @@ def _ff_deep_on(lamb, sparam, model, if_meam=False, meam_model=None):
7686
ret += f"pair_style hybrid/overlay deepmd {model} lj/cut/soft {nn:f} {alpha_lj:f} {rcut:f}\n"
7787
ret += "pair_coeff * * deepmd\n"
7888

79-
element_num = sparam.get("element_num", 1)
80-
sigma_key_index = filter(
81-
lambda t: t[0] <= t[1],
82-
((i, j) for i in range(element_num) for j in range(element_num)),
83-
)
84-
for i, j in sigma_key_index:
85-
ret += "pair_coeff {} {} lj/cut/soft ${{EPSILON}} {:f} {:f}\n".format(
86-
i + 1,
87-
j + 1,
88-
sparam["sigma_" + str(i) + "_" + str(j)],
89-
activation,
90-
)
89+
ret = parse_lj_sigma_epsilon(ret, sparam)
9190

92-
# ret += 'pair_coeff * * lj/cut/soft ${EPSILON} %f %f\n' % (sigma, activation)
9391
if if_meam:
9492
ret += "fix tot_pot all adapt/fep 0 pair meam scale * * v_LAMBDA\n"
9593
ret += "compute e_diff all fep ${TEMP} pair meam scale * * v_ONE\n"
@@ -98,20 +96,16 @@ def _ff_deep_on(lamb, sparam, model, if_meam=False, meam_model=None):
9896
"fix tot_pot all adapt/fep 0 pair deepmd scale * * v_LAMBDA\n"
9997
)
10098
ret += "compute e_diff all fep ${TEMP} pair deepmd scale * * v_ONE\n"
99+
ret += "variable e_diff equal c_e_diff[1]\n"
101100
return ret
102101

103102

104103
def _ff_soft_off(lamb, sparam, model, if_meam=False, meam_model=None):
105104
nn = sparam["n"]
106105
alpha_lj = sparam["alpha_lj"]
107106
rcut = sparam["rcut"]
108-
epsilon = sparam["epsilon"]
109-
# sigma = sparam['sigma']
110-
activation = sparam["activation"]
111107
ret = ""
112108
ret += "variable INV_LAMBDA equal 1-${LAMBDA}\n"
113-
ret += f"variable EPSILON equal {epsilon:f}\n"
114-
ret += "variable INV_EPSILON equal -${EPSILON}\n"
115109
if if_meam:
116110
ret += f"pair_style hybrid/overlay meam lj/cut/soft {nn:f} {alpha_lj:f} {rcut:f}\n"
117111
ret += f'pair_coeff * * meam {meam_model["library"]} {meam_model["element"]} {meam_model["potential"]} {meam_model["element"]}\n'
@@ -120,22 +114,11 @@ def _ff_soft_off(lamb, sparam, model, if_meam=False, meam_model=None):
120114
ret += f"pair_style hybrid/overlay deepmd {model} lj/cut/soft {nn:f} {alpha_lj:f} {rcut:f}\n"
121115
ret += "pair_coeff * * deepmd\n"
122116

123-
element_num = sparam.get("element_num", 1)
124-
sigma_key_index = filter(
125-
lambda t: t[0] <= t[1],
126-
((i, j) for i in range(element_num) for j in range(element_num)),
127-
)
128-
for i, j in sigma_key_index:
129-
ret += "pair_coeff {} {} lj/cut/soft ${{EPSILON}} {:f} {:f}\n".format(
130-
i + 1,
131-
j + 1,
132-
sparam["sigma_" + str(i) + "_" + str(j)],
133-
activation,
134-
)
117+
ret = parse_lj_sigma_epsilon(ret, sparam)
135118

136-
# ret += 'pair_coeff * * lj/cut/soft ${EPSILON} %f %f\n' % (sigma, activation)
137119
ret += "fix tot_pot all adapt/fep 0 pair lj/cut/soft epsilon * * v_INV_LAMBDA scale yes\n"
138-
ret += "compute e_diff all fep ${TEMP} pair lj/cut/soft epsilon * * v_INV_EPSILON\n"
120+
ret += "compute lj_pe all pair lj/cut/soft\n"
121+
ret += "variable e_diff equal -c_lj_pe/v_INV_LAMBDA\n"
139122
return ret
140123

141124

@@ -202,7 +185,7 @@ def _gen_lammps_input_ideal(
202185
ret += f"timestep {timestep}\n"
203186
ret += "compute allmsd all msd\n"
204187
ret += "thermo ${THERMO_FREQ}\n"
205-
ret += "thermo_style custom step ke pe etotal enthalpy temp press vol c_e_diff[1] c_allmsd[*]\n"
188+
ret += "thermo_style custom step ke pe etotal enthalpy temp press vol v_e_diff c_allmsd[*]\n"
206189
ret += "thermo_modify format 9 %.16e\n"
207190
ret += "dump 1 all custom ${DUMP_FREQ} dump.hti id type x y z vx vy vz\n"
208191
if ens == "nvt":

0 commit comments

Comments
 (0)