-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathtest_ti_gen_lammps_input.py
More file actions
148 lines (140 loc) · 5.46 KB
/
test_ti_gen_lammps_input.py
File metadata and controls
148 lines (140 loc) · 5.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import textwrap
import unittest
from unittest.mock import MagicMock, patch
from potential_common import meam_model
from dpti import ti
class TestTiGenLammpsInput(unittest.TestCase):
def setUp(self):
self.maxDiff = None
@patch("numpy.random.default_rng")
def test_deepmd(self, patch_random):
patch_random.return_value = MagicMock(integers=MagicMock(return_value=7858))
input = {
"conf_file": "conf.lmp",
"mass_map": [
118.71,
],
"model": "graph.pb",
"nsteps": 200000,
"timestep": 0.002,
"ens": "npt",
"temp": 200,
"pres": 50000,
"tau_t": 0.1,
"tau_p": 0.5,
"thermo_freq": 10,
"dump_freq": 10,
"copies": None,
"if_meam": False,
"meam_model": None,
}
ret1 = textwrap.dedent(
"""\
clear
# --------------------- VARIABLES-------------------------
variable NSTEPS equal 200000
variable THERMO_FREQ equal 10
variable DUMP_FREQ equal 10
variable TEMP equal 200.000000
variable PRES equal 50000.000000
variable TAU_T equal 0.100000
variable TAU_P equal 0.500000
# ---------------------- INITIALIZAITION ------------------
units metal
boundary p p p
atom_style atomic
# --------------------- ATOM DEFINITION ------------------
box tilt large
read_data conf.lmp
change_box all triclinic
mass 1 118.710000
# --------------------- FORCE FIELDS ---------------------
pair_style deepmd graph.pb
pair_coeff * *
# --------------------- MD SETTINGS ----------------------
neighbor 1.0 bin
timestep 0.002
thermo ${THERMO_FREQ}
compute allmsd all msd
thermo_style custom step ke pe etotal enthalpy temp press vol c_allmsd[*]
thermo_modify format float %20.6f
dump 1 all custom ${DUMP_FREQ} traj.dump id type x y z
fix 1 all npt temp ${TEMP} ${TEMP} ${TAU_T} iso ${PRES} ${PRES} ${TAU_P}
fix mzero all momentum 10 linear 1 1 1
# --------------------- INITIALIZE -----------------------
velocity all create ${TEMP} 7858
velocity all zero linear
# --------------------- RUN ------------------------------
run ${NSTEPS}
write_data final.lmp
"""
)
ret2 = ti._gen_lammps_input(**input)
self.assertEqual(ret1, ret2)
@patch("numpy.random.default_rng")
def test_meam(self, patch_random):
patch_random.return_value = MagicMock(integers=MagicMock(return_value=7858))
input = {
"conf_file": "conf.lmp",
"mass_map": [
118.71,
],
"model": "graph.pb",
"nsteps": 200000,
"timestep": 0.002,
"ens": "npt",
"temp": 200,
"pres": 50000,
"tau_t": 0.1,
"tau_p": 0.5,
"thermo_freq": 10,
"dump_freq": 10,
"copies": None,
"if_meam": True,
"meam_model": meam_model,
}
ret1 = textwrap.dedent(
"""\
clear
# --------------------- VARIABLES-------------------------
variable NSTEPS equal 200000
variable THERMO_FREQ equal 10
variable DUMP_FREQ equal 10
variable TEMP equal 200.000000
variable PRES equal 50000.000000
variable TAU_T equal 0.100000
variable TAU_P equal 0.500000
# ---------------------- INITIALIZAITION ------------------
units metal
boundary p p p
atom_style atomic
# --------------------- ATOM DEFINITION ------------------
box tilt large
read_data conf.lmp
change_box all triclinic
mass 1 118.710000
# --------------------- FORCE FIELDS ---------------------
pair_style meam
pair_coeff * * library_18Metals.meam Sn Sn_18Metals.meam Sn
# --------------------- MD SETTINGS ----------------------
neighbor 1.0 bin
timestep 0.002
thermo ${THERMO_FREQ}
compute allmsd all msd
thermo_style custom step ke pe etotal enthalpy temp press vol c_allmsd[*]
thermo_modify format float %20.6f
dump 1 all custom ${DUMP_FREQ} traj.dump id type x y z
fix 1 all npt temp ${TEMP} ${TEMP} ${TAU_T} iso ${PRES} ${PRES} ${TAU_P}
fix mzero all momentum 10 linear 1 1 1
# --------------------- INITIALIZE -----------------------
velocity all create ${TEMP} 7858
velocity all zero linear
# --------------------- RUN ------------------------------
run ${NSTEPS}
write_data final.lmp
"""
)
ret2 = ti._gen_lammps_input(**input)
self.assertEqual(ret1, ret2)
if __name__ == "__main__":
unittest.main()