Skip to content

Commit beee99a

Browse files
feat: support virial in qe/traj (#859)
1 parent 268d825 commit beee99a

File tree

14 files changed

+287
-0
lines changed

14 files changed

+287
-0
lines changed

dpdata/qe/traj.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
if TYPE_CHECKING:
1212
from dpdata.utils import FileType
1313

14+
import os
15+
1416
from ..unit import (
1517
EnergyConversion,
1618
ForceConversion,
@@ -20,6 +22,7 @@
2022

2123
ry2ev = EnergyConversion("rydberg", "eV").value()
2224
kbar2evperang3 = PressureConversion("kbar", "eV/angstrom^3").value()
25+
gpa2evperbohr = PressureConversion("GPa", "eV/bohr^3").value()
2326

2427
length_convert = LengthConversion("bohr", "angstrom").value()
2528
energy_convert = EnergyConversion("hartree", "eV").value()
@@ -228,6 +231,29 @@ def to_system_data(input_name, prefix, begin=0, step=1):
228231
)
229232
except FileNotFoundError:
230233
data["cells"] = np.tile(cell, (data["coords"].shape[0], 1, 1))
234+
235+
# handle virial
236+
stress_fname = prefix + ".str"
237+
if os.path.exists(stress_fname):
238+
# 1. Read stress tensor (in GPa) for each structure
239+
stress, vsteps = load_data(stress_fname, 3, begin=begin, step=step, convert=1.0)
240+
if csteps != vsteps:
241+
csteps.append(None)
242+
vsteps.append(None)
243+
for int_id in range(len(csteps)):
244+
if csteps[int_id] != vsteps[int_id]:
245+
break
246+
step_id = begin + int_id * step
247+
raise RuntimeError(
248+
f"the step key between files are not consistent. "
249+
f"The difference locates at step: {step_id}, "
250+
f".pos is {csteps[int_id]}, .str is {vsteps[int_id]}"
251+
)
252+
# 2. Calculate volume from cell. revert unit to bohr before taking det
253+
volumes = np.linalg.det(data["cells"] / length_convert).reshape(-1)
254+
# 3. Calculate virials for each structure, shape [nf x 3 x 3]
255+
data["virials"] = gpa2evperbohr * volumes[:, None, None] * stress
256+
231257
return data, csteps
232258

233259

tests/qe.traj/si.wrongstr/si.cel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
20 0.00241888
2+
10.64076206 0.00000000 0.00000000
3+
0.00000000 10.64076206 0.00000000
4+
0.00000000 0.00000000 10.64076206
5+
30 0.00362833
6+
10.64076206 0.00000000 0.00000000
7+
0.00000000 10.64076206 0.00000000
8+
0.00000000 0.00000000 10.64076206

tests/qe.traj/si.wrongstr/si.evp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# nfi time(ps) ekinc T_cell(K) Tion(K) etot enthal econs econt Volume Pressure(GPa) EXX EVDW
2+
20 2.418884E-03 2.666551E-08 0.000000E+00 1.400063E-01 -45.33322432 -45.33322432 -45.33321900 -45.33321908 1.204809E+03 0.27729
3+
30 3.628326E-03 8.130638E-08 0.000000E+00 3.362418E-01 -45.33323102 -45.33323102 -45.33321824 -45.33321907 1.204809E+03 0.27691

tests/qe.traj/si.wrongstr/si.for

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
20 0.00241888
2+
0.79213120739417E-03 0.17846941660539E-02 0.25659395900843E-02
3+
0.12296860773369E-02 -0.17575294070971E-02 -0.12077752684736E-02
4+
0.53449804771536E-03 0.15716728646909E-02 0.11885992380187E-02
5+
-0.20546369136946E-02 -0.31469738318253E-03 -0.13292260295548E-02
6+
0.92996278884107E-03 -0.19904509183874E-02 -0.94000783512887E-03
7+
0.25825132715153E-02 -0.17883694381162E-02 0.11238432666008E-02
8+
0.63315248883314E-03 0.14328752516010E-02 -0.24575206497776E-02
9+
-0.77380112683612E-03 -0.11964478769743E-02 0.14594402556008E-02
10+
30 0.00362833
11+
0.79771922134157E-03 0.17499394041424E-02 0.25186776447507E-02
12+
0.12196024429585E-02 -0.17540520532661E-02 -0.12026567384908E-02
13+
0.55342117414254E-03 0.15344688593791E-02 0.11794075108087E-02
14+
-0.20168463577813E-02 -0.33437869352471E-03 -0.13161886410156E-02
15+
0.92254287169080E-03 -0.19521664753444E-02 -0.92530766852405E-03
16+
0.25425245627026E-02 -0.17646733377723E-02 0.11236784179976E-02
17+
0.62964311964633E-03 0.14348901801160E-02 -0.24175435226922E-02
18+
-0.77656387976694E-03 -0.11736525993363E-02 0.14442073730829E-02

tests/qe.traj/si.wrongstr/si.in

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
&control
2+
calculation = 'cp'
3+
restart_mode = 'reset_counters'
4+
prefix = 'si'
5+
outdir = './outdir'
6+
pseudo_dir='./'
7+
nstep=3000
8+
iprint=10
9+
isave=100
10+
dt=5.0
11+
ndr=51, ndw=52 !folder for reading and writing
12+
tstress=.true., tprnfor=.true.
13+
!etot_conv_thr=1.d-9
14+
!ekin_conv_thr=1.d-7
15+
/
16+
17+
&system
18+
ibrav=8,
19+
celldm(1)=10.6407620646
20+
celldm(2) = 1
21+
celldm(3) = 1
22+
nat=8
23+
ntyp=1
24+
ecutwfc=50
25+
ecutrho=400,
26+
nr1b=20, nr2b=20, nr3b=20 !For US PP specify no. of points for FFT of aug. Charge
27+
/
28+
29+
&electrons
30+
electron_dynamics = 'verlet'
31+
electron_velocities = 'zero'
32+
emass=300
33+
orthogonalization='ortho'
34+
ortho_eps=1d-11
35+
/
36+
37+
&ions
38+
ion_dynamics = 'verlet'
39+
ion_velocities='zero'
40+
ion_temperature='nose'
41+
fnosep=25.0
42+
tempw=40.0
43+
/
44+
45+
ATOMIC_SPECIES
46+
Si 28.0855 Si.pbe-n-rrkjus_psl.1.0.0.UPF
47+
48+
ATOMIC_POSITIONS (crystal)
49+
Si 0.0000 0.0000 0.000 1 1 1
50+
Si 0.0000 0.5000 0.5000 1 1 1
51+
Si 0.5000 0.5000 0.0000 1 1 1
52+
Si 0.5000 0.0000 0.5000 1 1 1
53+
Si 0.25000 0.2500 0.2500 1 1 1
54+
Si 0.25000 0.7500 0.7500 1 1 1
55+
Si 0.75000 0.7500 0.2500 1 1 1
56+
Si 0.75000 0.2500 0.7500 1 1 1

tests/qe.traj/si.wrongstr/si.pos

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
20 0.00241888
2+
-0.55955613343180E-03 -0.13280468681160E-01 -0.12170559744533E-01
3+
-0.13498425299770E-01 0.53348556364374E+01 0.53265822820792E+01
4+
0.53177169488520E+01 0.53125521646402E+01 -0.13687957707679E-02
5+
0.53300642326909E+01 0.90214941469176E-04 0.53336756691314E+01
6+
0.26530964223874E+01 0.26670146882442E+01 0.26685063320998E+01
7+
0.26474643772774E+01 0.79813721194718E+01 0.79737688869610E+01
8+
0.79764012327704E+01 0.79748937809524E+01 0.26729378003260E+01
9+
0.79873283657577E+01 0.26616463190589E+01 0.79793202591917E+01
10+
30 0.00362833
11+
-0.52107908654115E-03 -0.13021934024520E-01 -0.11855267397130E-01
12+
-0.13404740927597E-01 0.53346716430867E+01 0.53264251309777E+01
13+
0.53177219927670E+01 0.53127844169680E+01 -0.12267029514939E-02
14+
0.53297463825603E+01 0.86918798429361E-04 0.53335032260915E+01
15+
0.26531522876578E+01 0.26668005206457E+01 0.26683824157731E+01
16+
0.26477271882324E+01 0.79811839520919E+01 0.79739025595218E+01
17+
0.79764197425739E+01 0.79751074086469E+01 0.26726239769995E+01
18+
0.79871718245254E+01 0.26615315288521E+01 0.79794965352588E+01

tests/qe.traj/si.wrongstr/si.str

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
20 0.00241888
2+
0.27927908 -0.02926875 -0.02277043
3+
-0.02926875 0.27823138 0.03779023
4+
-0.02277043 0.03779026 0.27434825
5+
30 0.00362833
6+
0.27885067 -0.02827892 -0.02066094
7+
-0.02827892 0.27775865 0.03660021
8+
-0.02066094 0.03660025 0.27411244
9+
40 0.00362833
10+
0.27885067 -0.02827892 -0.02066094
11+
-0.02827892 0.27775865 0.03660021
12+
-0.02066094 0.03660025 0.27411244

tests/qe.traj/si/si.cel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
20 0.00241888
2+
10.64076206 0.00000000 0.00000000
3+
0.00000000 10.64076206 0.00000000
4+
0.00000000 0.00000000 10.64076206
5+
30 0.00362833
6+
10.64076206 0.00000000 0.00000000
7+
0.00000000 10.64076206 0.00000000
8+
0.00000000 0.00000000 10.64076206

tests/qe.traj/si/si.evp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# nfi time(ps) ekinc T_cell(K) Tion(K) etot enthal econs econt Volume Pressure(GPa) EXX EVDW
2+
20 2.418884E-03 2.666551E-08 0.000000E+00 1.400063E-01 -45.33322432 -45.33322432 -45.33321900 -45.33321908 1.204809E+03 0.27729
3+
30 3.628326E-03 8.130638E-08 0.000000E+00 3.362418E-01 -45.33323102 -45.33323102 -45.33321824 -45.33321907 1.204809E+03 0.27691

tests/qe.traj/si/si.for

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
20 0.00241888
2+
0.79213120739417E-03 0.17846941660539E-02 0.25659395900843E-02
3+
0.12296860773369E-02 -0.17575294070971E-02 -0.12077752684736E-02
4+
0.53449804771536E-03 0.15716728646909E-02 0.11885992380187E-02
5+
-0.20546369136946E-02 -0.31469738318253E-03 -0.13292260295548E-02
6+
0.92996278884107E-03 -0.19904509183874E-02 -0.94000783512887E-03
7+
0.25825132715153E-02 -0.17883694381162E-02 0.11238432666008E-02
8+
0.63315248883314E-03 0.14328752516010E-02 -0.24575206497776E-02
9+
-0.77380112683612E-03 -0.11964478769743E-02 0.14594402556008E-02
10+
30 0.00362833
11+
0.79771922134157E-03 0.17499394041424E-02 0.25186776447507E-02
12+
0.12196024429585E-02 -0.17540520532661E-02 -0.12026567384908E-02
13+
0.55342117414254E-03 0.15344688593791E-02 0.11794075108087E-02
14+
-0.20168463577813E-02 -0.33437869352471E-03 -0.13161886410156E-02
15+
0.92254287169080E-03 -0.19521664753444E-02 -0.92530766852405E-03
16+
0.25425245627026E-02 -0.17646733377723E-02 0.11236784179976E-02
17+
0.62964311964633E-03 0.14348901801160E-02 -0.24175435226922E-02
18+
-0.77656387976694E-03 -0.11736525993363E-02 0.14442073730829E-02

0 commit comments

Comments
 (0)