Skip to content

Commit 1a421e6

Browse files
Fix virial (#324)
* fix a bug, now ck2p/aimd_output can generate virial.raw * Delete test.py * Update output.py Signed-off-by: HuangJiameng <[email protected]> * Update output.py Signed-off-by: HuangJiameng <[email protected]> * add unittest for aimd_output with stress * add cp2k.log Co-authored-by: Han Wang <[email protected]>
1 parent 400e198 commit 1a421e6

File tree

12 files changed

+2157
-1
lines changed

12 files changed

+2157
-1
lines changed

dpdata/cp2k/output.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,22 @@ def handle_single_log_frame(self, lines):
120120
print_level_flag = 0
121121
atomic_kinds_pattern = re.compile(r'\s+\d+\. Atomic kind:\s+(?P<akind>\S+)')
122122
atomic_kinds = []
123+
stress_sign = 'STRESS'
124+
stress_flag = 0
125+
stress = []
126+
123127
for line in lines:
128+
if stress_flag == 3 :
129+
if (line == '\n') :
130+
stress_flag = 0
131+
else :
132+
stress.append(line.split()[1:4])
133+
if stress_flag == 2 :
134+
stress_flag = 3
135+
if stress_flag == 1 :
136+
stress_flag = 2
137+
if (stress_sign in line):
138+
stress_flag = 1
124139
if force_start_pattern.match(line):
125140
force_flag=True
126141
if force_end_pattern.match(line):
@@ -214,7 +229,18 @@ def handle_single_log_frame(self, lines):
214229
#atom_names=list(element_dict.keys())
215230
atom_names=self.atomic_kinds
216231
atom_numbs=[]
217-
232+
233+
GPa = PressureConversion("eV/angstrom^3", "GPa").value()
234+
if stress:
235+
stress = np.array(stress)
236+
stress = stress.astype('float32')
237+
stress = stress[np.newaxis, :, :]
238+
# stress to virial conversion, default unit in cp2k is GPa
239+
# note the stress is virial = stress * volume
240+
virial = stress * np.linalg.det(self.cell)/GPa
241+
virial = virial.squeeze()
242+
else:
243+
virial = None
218244
for ii in element_dict.keys():
219245
atom_numbs.append(element_dict[ii][1])
220246
#print(atom_numbs)
@@ -225,6 +251,8 @@ def handle_single_log_frame(self, lines):
225251
info_dict['cells'] = np.asarray([self.cell]).astype('float32')
226252
info_dict['energies'] = np.asarray([energy]).astype('float32')
227253
info_dict['forces'] = np.asarray([forces_list]).astype('float32')
254+
if(virial is not None ):
255+
info_dict['virials'] = np.asarray([virial]).astype('float32')
228256
return info_dict
229257

230258
def handle_single_xyz_frame(self, lines):
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
5
2+
i = 0, time = 0.000, E = -8.07218972206
3+
H 5.70191 3.8096 4.38845
4+
H 4.44601 4.65681 5.38195
5+
H 4.49216 4.90991 3.57756
6+
H 5.83825 5.62228 4.61068
7+
C 5.11666 4.75533 4.46123

tests/cp2k/aimd_stress/cp2k.log

Lines changed: 1992 additions & 0 deletions
Large diffs are not rendered by default.

tests/cp2k/aimd_stress/deepmd/box.raw

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.000000000000000000e+01 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000000e+01 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000000e+01
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5.701910018920898438e+00 3.809600114822387695e+00 4.388450145721435547e+00 4.446010112762451172e+00 4.656809806823730469e+00 5.381949901580810547e+00 4.492159843444824219e+00 4.909910202026367188e+00 3.577559947967529297e+00 5.838250160217285156e+00 5.622280120849609375e+00 4.610680103302001953e+00 5.116660118103027344e+00 4.755330085754394531e+00 4.461229801177978516e+00
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-2.196554718017578125e+02
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-2.743706703186035156e-01 4.712709188461303711e-01 -1.367179006338119507e-01 7.652513980865478516e-01 2.514204978942871094e-01 -1.059429287910461426e+00 2.538656070828437805e-02 1.183478906750679016e-02 -1.267343163490295410e-01 -8.532900810241699219e-01 -9.029597043991088867e-01 -1.871660351753234863e-01 3.367811143398284912e-01 1.687173396348953247e-01 1.509592533111572266e+00
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
0
2+
0
3+
0
4+
0
5+
1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
H
2+
C
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-1.305763244628906250e+00 -5.517681837081909180e-01 5.745944380760192871e-01 -5.517681837081909180e-01 -1.251762151718139648e+00 5.180240049958229065e-02 5.745944380760192871e-01 5.180240049958229065e-02 -8.817730545997619629e-01

0 commit comments

Comments
 (0)