-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support custom variables for the LAMMPS input files #70
Changes from all commits
af4b42c
18c572c
7855b6d
ecf600c
d71a97c
5fb7623
4c129d1
41fea68
16aba07
1cb585b
e354206
45be98d
fa17be3
5015ed9
34d720c
c265112
b2d679d
fc6b103
2ff53e7
da907f8
cedf2d0
097f127
e91826e
ab7986c
4e2e504
e732e08
bac44be
7abcbe5
f2a63b9
9933e9a
37d5667
d439608
be2f272
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,16 @@ | |
# def gen_equi_header(nsteps, prt_freq, dump_freq, temp, pres, tau_t, tau_p, mass_map, conf_file): | ||
# def gen_equi_header(nsteps, prt_freq, dump_freq, temp, pres, tau_t, tau_p, mass_map, conf_file): | ||
def gen_equi_header( | ||
nsteps, thermo_freq, dump_freq, mass_map, temp, tau_t, tau_p, equi_conf, pres=None | ||
nsteps, | ||
thermo_freq, | ||
dump_freq, | ||
mass_map, | ||
temp, | ||
tau_t, | ||
tau_p, | ||
equi_conf, | ||
pres=None, | ||
custom_variables=None, | ||
): | ||
ret = "" | ||
ret += "clear\n" | ||
|
@@ -45,6 +54,9 @@ | |
ret += "variable DUMP_FREQ equal %d\n" % dump_freq | ||
ret += "variable NREPEAT equal ${NSTEPS}/${DUMP_FREQ}\n" | ||
ret += f"variable TEMP equal {temp:.6f}\n" | ||
if custom_variables is not None: | ||
for key, value in custom_variables.items(): | ||
ret += f"variable {key} equal {value}\n" | ||
Comment on lines
+57
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder: Add tests for The new code for handling Do you want me to generate the unit testing code or open a GitHub issue to track this task? ToolsGitHub Check: codecov/patch
|
||
# if equi_settings['pres'] is not None : | ||
if pres is not None: | ||
ret += f"variable PRES equal {pres:.6f}\n" | ||
|
@@ -64,7 +76,7 @@ | |
|
||
|
||
# def gen_equi_force_field(model, if_meam=None): | ||
def gen_equi_force_field(model, if_meam=False, meam_model=None): | ||
def gen_equi_force_field(model, if_meam=False, meam_model=None, append=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder: Add tests for The new code for handling the Do you want me to generate the unit testing code or open a GitHub issue to track this task? ToolsGitHub Check: codecov/patch
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yi-FanLi, here are the unit tests for the import unittest
from dpti.equi import gen_equi_force_field
class TestGenEquiForceField(unittest.TestCase):
def test_gen_equi_force_field_with_append(self):
model = "model.pb"
append = "extra_params"
expected_output = "pair_style deepmd model.pb extra_params\npair_coeff * *\n"
result = gen_equi_force_field(model, append=append)
self.assertEqual(result, expected_output)
def test_gen_equi_force_field_without_append(self):
model = "model.pb"
expected_output = "pair_style deepmd model.pb\npair_coeff * *\n"
result = gen_equi_force_field(model)
self.assertEqual(result, expected_output)
def test_gen_equi_force_field_with_meam(self):
model = "model.pb"
meam_model = {
"library": "library.meam",
"potential": "potential.meam",
"element": "element"
}
expected_output = (
"pair_style meam\n"
"pair_coeff * * library.meam element potential.meam element\n"
)
result = gen_equi_force_field(model, if_meam=True, meam_model=meam_model)
self.assertEqual(result, expected_output)
if __name__ == "__main__":
unittest.main() This test suite covers the following scenarios:
These tests ensure that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you commit these changes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yi-FanLi, I cannot commit the changes directly. However, you can easily add the provided unit tests to your codebase. Here are the steps:
If you need any further assistance, feel free to ask! Learnings added
Learnings used
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder: Add tests for The new code for handling the Do you want me to generate the unit testing code or open a GitHub issue to track this task? ToolsGitHub Check: codecov/patch
|
||
# equi_settings = | ||
# model = equi_settings['model'] | ||
# assert type(model) is dict, f"equi_settings['model] must be a dict. model:{model}" | ||
|
@@ -82,7 +94,10 @@ | |
ret = "" | ||
ret += "# --------------------- FORCE FIELDS ---------------------\n" | ||
if not if_meam: | ||
ret += f"pair_style deepmd {model}\n" | ||
ret += f"pair_style deepmd {model}" | ||
if append is not None: | ||
ret += " " + append | ||
ret += "\n" | ||
ret += "pair_coeff * *\n" | ||
else: | ||
meam_library = meam_model["library"] | ||
|
@@ -161,6 +176,8 @@ | |
pres=None, | ||
if_meam=False, | ||
meam_model=None, | ||
custom_variables=None, | ||
append=None, | ||
Comment on lines
+179
to
+180
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder: Add tests for new parameters. The new parameters Do you want me to generate the unit testing code or open a GitHub issue to track this task? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yi-FanLi, I've added the following unit tests to cover the new
|
||
): | ||
if dump_freq is None: | ||
dump_freq = thermo_freq | ||
|
@@ -174,9 +191,10 @@ | |
tau_p=tau_p, | ||
equi_conf=equi_conf, | ||
pres=pres, | ||
custom_variables=custom_variables, | ||
) | ||
equi_force_field = gen_equi_force_field( | ||
model, if_meam=if_meam, meam_model=meam_model | ||
model, if_meam=if_meam, meam_model=meam_model, append=append | ||
) | ||
equi_thermo_settings = gen_equi_thermo_settings(timestep=timestep) | ||
equi_dump_settings = gen_equi_dump_settings(if_dump_avg_posi=if_dump_avg_posi) | ||
|
@@ -422,6 +440,8 @@ | |
pres=equi_settings["pres"], | ||
if_meam=equi_settings["if_meam"], | ||
meam_model=equi_settings["meam_model"], | ||
custom_variables=equi_settings.get("custom_variables", None), | ||
append=equi_settings.get("append", None), | ||
) | ||
|
||
with open(os.path.join(task_abs_dir, "in.lammps"), "w") as fp: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,7 +68,7 @@ | |
return ret | ||
|
||
|
||
def _ff_deep_on(lamb, model, sparam, if_meam=False, meam_model=None): | ||
def _ff_deep_on(lamb, model, sparam, if_meam=False, meam_model=None, append=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder: Add tests for The function Do you want me to generate the unit testing code or open a GitHub issue to track this task? Also applies to: 91-94 ToolsGitHub Check: codecov/patch
|
||
nn = sparam["n"] | ||
alpha_lj = sparam["alpha_lj"] | ||
rcut = sparam["rcut"] | ||
|
@@ -88,9 +88,11 @@ | |
ret += f"pair_style hybrid/overlay meam lj/cut/soft {nn:f} {alpha_lj:f} {rcut:f}\n" | ||
ret += f'pair_coeff * * meam {meam_model["library"]} {meam_model["element"]} {meam_model["potential"]} {meam_model["element"]}\n' | ||
else: | ||
ret += f"pair_style hybrid/overlay deepmd {model} lj/cut/soft {nn:f} {alpha_lj:f} {rcut:f}\n" | ||
if append: | ||
ret += f"pair_style hybrid/overlay deepmd {model:s} {append:s} lj/cut/soft {nn:f} {alpha_lj:f} {rcut:f}\n" | ||
else: | ||
ret += f"pair_style hybrid/overlay deepmd {model:s} lj/cut/soft {nn:f} {alpha_lj:f} {rcut:f}\n" | ||
ret += "pair_coeff * * deepmd\n" | ||
|
||
element_num = sparam.get("element_num", 1) | ||
sigma_key_index = filter( | ||
lambda t: t[0] <= t[1], | ||
|
@@ -155,7 +157,7 @@ | |
# return ret | ||
|
||
|
||
def _ff_lj_off(lamb, model, sparam, if_meam=False, meam_model=None): | ||
def _ff_lj_off(lamb, model, sparam, if_meam=False, meam_model=None, append=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder: Add tests for The function Do you want me to generate the unit testing code or open a GitHub issue to track this task? Also applies to: 181-184 ToolsGitHub Check: codecov/patch
|
||
nn = sparam["n"] | ||
alpha_lj = sparam["alpha_lj"] | ||
rcut = sparam["rcut"] | ||
|
@@ -176,7 +178,10 @@ | |
ret += f'pair_coeff * * meam {meam_model["library"]} {meam_model["element"]} {meam_model["potential"]} {meam_model["element"]}\n' | ||
# ret += f'pair_coeff * * meam {meam_model[0]} {meam_model[2]} {meam_model[1]} {meam_model[2]}\n' | ||
else: | ||
ret += f"pair_style hybrid/overlay deepmd {model} lj/cut/soft {nn:f} {alpha_lj:f} {rcut:f}\n" | ||
if append: | ||
ret += f"pair_style hybrid/overlay deepmd {model:s} {append:s} lj/cut/soft {nn:f} {alpha_lj:f} {rcut:f}\n" | ||
else: | ||
ret += f"pair_style hybrid/overlay deepmd {model:s} lj/cut/soft {nn:f} {alpha_lj:f} {rcut:f}\n" | ||
ret += "pair_coeff * * deepmd\n" | ||
|
||
element_num = sparam.get("element_num", 1) | ||
|
@@ -252,19 +257,25 @@ | |
return ret | ||
|
||
|
||
def _ff_soft_lj(lamb, model, m_spring_k, step, sparam, if_meam=False, meam_model=None): | ||
def _ff_soft_lj( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder: Add tests for The function Do you want me to generate the unit testing code or open a GitHub issue to track this task? Also applies to: 270-271, 276-277 ToolsGitHub Check: codecov/patch
|
||
lamb, model, m_spring_k, step, sparam, if_meam=False, meam_model=None, append=None | ||
): | ||
Comment on lines
+260
to
+262
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder: Add tests for The function Do you want me to generate the unit testing code or open a GitHub issue to track this task? |
||
ret = "" | ||
ret += "# --------------------- FORCE FIELDS ---------------------\n" | ||
if step == "lj_on": | ||
ret += _ff_lj_on(lamb, model, sparam) | ||
var_spring = False | ||
elif step == "deep_on": | ||
# ret += _ff_meam_on(lamb, model, sparam) | ||
ret += _ff_deep_on(lamb, model, sparam, if_meam=if_meam, meam_model=meam_model) | ||
ret += _ff_deep_on( | ||
lamb, model, sparam, if_meam=if_meam, meam_model=meam_model, append=append | ||
) | ||
var_spring = False | ||
elif step == "spring_off": | ||
# ret += _ff_meam_lj_off(lamb, model, sparam) | ||
ret += _ff_lj_off(lamb, model, sparam, if_meam=if_meam, meam_model=meam_model) | ||
ret += _ff_lj_off( | ||
lamb, model, sparam, if_meam=if_meam, meam_model=meam_model, append=append | ||
) | ||
var_spring = True | ||
else: | ||
raise RuntimeError("unkown step", step) | ||
|
@@ -274,10 +285,13 @@ | |
return ret | ||
|
||
|
||
def _ff_two_steps(lamb, model, m_spring_k, step): | ||
def _ff_two_steps(lamb, model, m_spring_k, step, append=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder: Add tests for The function Do you want me to generate the unit testing code or open a GitHub issue to track this task? Also applies to: 291-294 ToolsGitHub Check: codecov/patch
|
||
ret = "" | ||
ret += "# --------------------- FORCE FIELDS ---------------------\n" | ||
ret += f"pair_style deepmd {model}\n" | ||
if append: | ||
ret += f"pair_style deepmd {model:s} {append:s}\n" | ||
else: | ||
ret += f"pair_style deepmd {model:s}\n" | ||
ret += "pair_coeff * *\n" | ||
|
||
if step == "both" or step == "spring_off": | ||
|
@@ -323,6 +337,8 @@ | |
step="both", | ||
if_meam=False, | ||
meam_model=None, | ||
custom_variables=None, | ||
append=None, | ||
Comment on lines
+340
to
+341
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder: Add tests for The function Do you want me to generate the unit testing code or open a GitHub issue to track this task? Also applies to: 355-357, 373-373 |
||
): | ||
ret = "" | ||
ret += "clear\n" | ||
|
@@ -336,6 +352,9 @@ | |
ret += f"variable TAU_P equal {tau_p:f}\n" | ||
ret += f"variable LAMBDA equal {lamb:.10e}\n" | ||
ret += "variable INV_LAMBDA equal %.10e\n" % (1 - lamb) | ||
if custom_variables is not None: | ||
for key, value in custom_variables.items(): | ||
ret += f"variable {key} equal {value}\n" | ||
Comment on lines
+355
to
+357
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder: Add tests for Ensure that the logic for handling Do you want me to generate the unit testing code or open a GitHub issue to track this task? |
||
ret += "# ---------------------- INITIALIZAITION ------------------\n" | ||
ret += "units metal\n" | ||
ret += "boundary p p p\n" | ||
|
@@ -351,7 +370,7 @@ | |
|
||
# force field setting | ||
if switch == "one-step" or switch == "two-step": | ||
ret += _ff_two_steps(lamb, model, m_spring_k, step) | ||
ret += _ff_two_steps(lamb, model, m_spring_k, step, append) | ||
elif switch == "three-step": | ||
ret += _ff_soft_lj( | ||
lamb, | ||
|
@@ -361,6 +380,7 @@ | |
sparam, | ||
if_meam=if_meam, | ||
meam_model=meam_model, | ||
append=append, | ||
) | ||
else: | ||
raise RuntimeError("unknow switch", switch) | ||
|
@@ -666,6 +686,8 @@ | |
# timestep = jdata['timestep'] | ||
timestep = get_first_matched_key_from_dict(jdata, ["timestep", "dt"]) | ||
spring_k = jdata["spring_k"] | ||
custom_variables = jdata.get("custom_variables", None) | ||
append = jdata.get("append", None) | ||
Comment on lines
+689
to
+690
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder: Add tests for The function Do you want me to generate the unit testing code or open a GitHub issue to track this task? ToolsGitHub Check: codecov/patch
|
||
|
||
sparam = jdata.get("soft_param", {}) | ||
if sparam: | ||
|
@@ -783,6 +805,8 @@ | |
crystal=crystal, | ||
if_meam=if_meam, | ||
meam_model=meam_model, | ||
custom_variables=custom_variables, | ||
append=append, | ||
) | ||
elif ref == "ideal": | ||
raise RuntimeError("choose hti_liq.py") | ||
|
@@ -1375,9 +1399,12 @@ | |
|
||
|
||
def run_task(task_dir, machine_file, task_name, no_dp=False): | ||
job_work_dir_ = glob.glob(os.path.join(task_dir, task_name + "*")) | ||
assert len(job_work_dir_) == 1 | ||
job_work_dir = job_work_dir_[0] | ||
if task_name == "00" or task_name == "01" or task_name == "02": | ||
job_work_dir_ = glob.glob(os.path.join(task_dir, task_name + "*")) | ||
assert len(job_work_dir_) == 1 | ||
job_work_dir = job_work_dir_[0] | ||
elif task_name == "one-step": | ||
job_work_dir = task_dir | ||
Comment on lines
+1402
to
+1407
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder: Add tests for The function Do you want me to generate the unit testing code or open a GitHub issue to track this task? ToolsGitHub Check: codecov/patch
|
||
task_dir_list = glob.glob(os.path.join(job_work_dir, "task*")) | ||
task_dir_list = sorted(task_dir_list) | ||
work_base_dir = os.getcwd() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,8 @@ | |
copies=None, | ||
if_meam=False, | ||
meam_model=None, | ||
custom_variables=None, | ||
append=None, | ||
): | ||
ret = "" | ||
ret += "clear\n" | ||
|
@@ -70,6 +72,9 @@ | |
ret += f"variable PRES equal {pres:f}\n" | ||
ret += f"variable TAU_T equal {tau_t:f}\n" | ||
ret += f"variable TAU_P equal {tau_p:f}\n" | ||
if custom_variables is not None: | ||
for key, value in custom_variables.items(): | ||
ret += f"variable {key} equal {value}\n" | ||
Comment on lines
+75
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder: Add tests for The new code for handling Do you want me to generate the unit testing code or open a GitHub issue to track this task? |
||
ret += "# ---------------------- INITIALIZAITION ------------------\n" | ||
ret += "units metal\n" | ||
ret += "boundary p p p\n" | ||
|
@@ -90,8 +95,12 @@ | |
ret += "pair_style meam\n" | ||
ret += f'pair_coeff * * {meam_model["library"]} {meam_model["element"]} {meam_model["potential"]} {meam_model["element"]}\n' | ||
else: | ||
ret += f"pair_style deepmd {model}\n" | ||
ret += "pair_coeff * *\n" | ||
if append: | ||
ret += f"pair_style deepmd {model:s} {append:s}\n" | ||
ret += "pair_coeff * *\n" | ||
else: | ||
ret += f"pair_style deepmd {model:s}\n" | ||
ret += "pair_coeff * *\n" | ||
Comment on lines
+98
to
+103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder: Add tests for The new code for handling the Do you want me to generate the unit testing code or open a GitHub issue to track this task? |
||
ret += "# --------------------- MD SETTINGS ----------------------\n" | ||
ret += "neighbor 1.0 bin\n" | ||
ret += f"timestep {timestep}\n" | ||
|
@@ -143,6 +152,8 @@ | |
if "copies" in jdata: | ||
copies = jdata["copies"] | ||
model = jdata["model"] | ||
custom_variables = jdata.get("custom_variables", None) | ||
append = jdata.get("append", None) | ||
Comment on lines
+155
to
+156
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder: Add tests for new parameters. The new parameters Do you want me to generate the unit testing code or open a GitHub issue to track this task? |
||
meam_model = jdata.get("meam_model", None) | ||
# model = os.path.abspath(model) | ||
# mass_map = jdata['mass_map'] | ||
|
@@ -266,6 +277,8 @@ | |
copies=copies, | ||
if_meam=if_meam, | ||
meam_model=meam_model, | ||
custom_variables=custom_variables, | ||
append=append, | ||
) | ||
thermo_out = temp_list[ii] | ||
# with open('thermo.out', 'w') as fp : | ||
|
@@ -287,6 +300,8 @@ | |
copies=copies, | ||
if_meam=if_meam, | ||
meam_model=meam_model, | ||
custom_variables=custom_variables, | ||
append=append, | ||
) | ||
thermo_out = temp_list[ii] | ||
# with open('thermo.out', 'w') as fp : | ||
|
@@ -308,6 +323,8 @@ | |
copies=copies, | ||
if_meam=if_meam, | ||
meam_model=meam_model, | ||
custom_variables=custom_variables, | ||
append=append, | ||
) | ||
thermo_out = pres_list[ii] | ||
else: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reminder: Add tests for
custom_variables
handling.The new code for handling
custom_variables
is not covered by tests.Do you want me to generate the unit testing code or open a GitHub issue to track this task?
Tools
GitHub Check: codecov/patch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Yi-FanLi, I've generated the unit test for the
custom_variables
handling in thegen_equi_header
function.Here is the new unit test code:
This test case verifies that the
gen_equi_header
function correctly includes custom variables in the generated output string.Learnings added
Learnings used