Skip to content

Commit 2648d50

Browse files
wanghan-iapcmHan Wang
andauthored
fix: qe input blocks not seperated by empty lines (#724)
the qe support only parse input file, in which cell blocks are separated by empty lines, like ``` ATOMIC_SPECIES Na 22.989769 Na_ONCV_PBE-1.0.upf CELL_PARAMETERS {angstrom} 7.171683039200000 0.000000000000000 0.000000000000000 ``` however, the input file is valid when no empty line exists, like the following ``` ATOMIC_SPECIES Na 22.989769 Na_ONCV_PBE-1.0.upf CELL_PARAMETERS {angstrom} 7.171683039200000 0.000000000000000 0.000000000000000 ``` This pr fixes the issue <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Summary by CodeRabbit - **New Features** - Improved handling of Quantum Espresso output data for better parsing and clarity. - Enhanced error handling for missing force and stress data. - Added configuration parameters for self-consistent field (SCF) calculations for sodium. - **Bug Fixes** - Updated functions to prevent unwanted lines in data extraction, ensuring cleaner output. - **Tests** - Introduced a new test class to validate the functionality of the `dpdata.LabeledSystem` class with Quantum Espresso output, enhancing test coverage. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Han Wang <[email protected]>
1 parent a2fbdd8 commit 2648d50

File tree

4 files changed

+450
-3
lines changed

4 files changed

+450
-3
lines changed

dpdata/qe/scf.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,32 @@
1111
bohr2ang = 0.52917721067
1212
kbar2evperang3 = 1e3 / 1.602176621e6
1313

14+
_QE_BLOCK_KEYWORDS = [
15+
"ATOMIC_SPECIES",
16+
"ATOMIC_POSITIONS",
17+
"K_POINTS",
18+
"ADDITIONAL_K_POINTS",
19+
"CELL_PARAMETERS",
20+
"CONSTRAINTS",
21+
"OCCUPATIONS",
22+
"ATOMIC_VELOCITIES",
23+
"ATOMIC_FORCES",
24+
"SOLVENTS",
25+
"HUBBARD",
26+
]
27+
1428

1529
def get_block(lines, keyword, skip=0):
1630
ret = []
1731
for idx, ii in enumerate(lines):
1832
if keyword in ii:
1933
blk_idx = idx + 1 + skip
20-
while len(lines[blk_idx]) == 0:
34+
while len(lines[blk_idx].split()) == 0:
2135
blk_idx += 1
22-
while len(lines[blk_idx]) != 0 and blk_idx != len(lines):
36+
while (
37+
len(lines[blk_idx].split()) != 0
38+
and (lines[blk_idx].split()[0] not in _QE_BLOCK_KEYWORDS)
39+
) and blk_idx != len(lines):
2340
ret.append(lines[blk_idx])
2441
blk_idx += 1
2542
break
@@ -123,7 +140,7 @@ def get_force(lines, natoms):
123140
def get_stress(lines):
124141
blk = get_block(lines, "total stress")
125142
if len(blk) == 0:
126-
return
143+
return None
127144
ret = []
128145
for ii in blk:
129146
ret.append([float(jj) for jj in ii.split()[3:6]])

tests/qe.scf/na.in

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
&control
3+
calculation = 'scf'
4+
restart_mode = 'from_scratch',
5+
prefix = 'Na'
6+
outdir = './tmp'
7+
pseudo_dir = './'
8+
/
9+
&SYSTEM
10+
ibrav=0,
11+
nosym=.true.,
12+
nat=3,
13+
ntyp=1,
14+
occupations = 'smearing',
15+
smearing = 'gauss',
16+
degauss = 0.02,
17+
ecutwfc = 100,
18+
ecutrho = 960,
19+
lspinorb = .false.,
20+
noncolin = .false.,
21+
/
22+
&ELECTRONS
23+
conv_thr = 1.0d-9,
24+
mixing_beta = 0.7,
25+
electron_maxstep = 200,
26+
/
27+
&ions
28+
/
29+
&cell
30+
/
31+
ATOMIC_SPECIES
32+
Na 22.989769 Na_ONCV_PBE-1.0.upf
33+
CELL_PARAMETERS {angstrom}
34+
7.171683039200000 0.000000000000000 0.000000000000000
35+
-4.270578118300000 5.761527588200000 0.000000000000000
36+
-0.000000045600000 0.000000023000000 12.826457854999999
37+
ATOMIC_POSITIONS (crystal)
38+
39+
Na 0.940587444301534 0.397635863676890 0.059472381901808
40+
Na 0.059413515648061 0.602364552456546 0.559472465518034
41+
Na 0.602364619812068 0.059413062489401 0.059472381901808
42+
K_POINTS {automatic}
43+
8 8 4 0 0 0
44+

0 commit comments

Comments
 (0)