Skip to content

Commit f475b58

Browse files
authored
👌 Parser: add exit codes for diverging Hubbard parameters (#110)
Fixes #102 When the value of an Hubbard parameter is too large, fortran converts it into a string such as `*****`. This makes it impossible to parse. At the same time, it is a signature that the Hubbard parameter is diverging, and therefore one should stop the self-consistent cycle as early as possible.
1 parent c7614e8 commit f475b58

12 files changed

Lines changed: 1933 additions & 4 deletions

File tree

src/aiida_hubbard/calculations/hp.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ def define(cls, spec):
200200
message='The code failed to reconstruct the full chi matrix as some chi matrices were missing')
201201
spec.exit_code(495, 'ERROR_INCOMPATIBLE_FFT_GRID',
202202
message='The code failed due an incompatible FFT grid.')
203+
spec.exit_code(600, 'ERROR_DIVERGING_HUBBARD_PARAMETERS',
204+
message='The linear response calculation returned diverging parameters.')
203205
# yapf: enable
204206

205207
@classproperty

src/aiida_hubbard/parsers/hp.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ def parse(self, **kwargs):
5252
# If the `HUBBARD.dat` is not produced, it means it is an "only Hubbard U" calculation,
5353
# thus we set the Hubbard parameters from the ``hubbard`` output, which contains the onsite U.
5454
try:
55-
self.parse_hubbard_dat(kwargs['retrieved_temporary_folder'])
55+
exit_code = self.parse_hubbard_dat(kwargs['retrieved_temporary_folder'])
56+
if exit_code:
57+
return exit_code
5658
except (KeyError, FileNotFoundError):
5759
self.get_hubbard_structure()
5860

@@ -151,7 +153,10 @@ def parse_hubbard(self):
151153
try:
152154
with self.retrieved.base.repository.open(filename, 'r') as handle:
153155
parsed_data = self.parse_hubbard_content(handle)
154-
except IOError:
156+
except (IOError, ValueError) as exc:
157+
if isinstance(exc, ValueError):
158+
return self.exit_codes.ERROR_DIVERGING_HUBBARD_PARAMETERS
159+
155160
if self.is_complete_calculation:
156161
return self.exit_codes.ERROR_OUTPUT_HUBBARD_MISSING
157162
else:
@@ -219,7 +224,10 @@ def parse_hubbard_dat(self, folder_path):
219224

220225
hubbard_structure.clear_hubbard_parameters()
221226
hubbard_utils = HubbardUtils(hubbard_structure)
222-
hubbard_utils.parse_hubbard_dat(filepath=filepath)
227+
try:
228+
hubbard_utils.parse_hubbard_dat(filepath=filepath)
229+
except ValueError:
230+
return self.exit_codes.ERROR_DIVERGING_HUBBARD_PARAMETERS
223231

224232
if intersites is None:
225233
self.out('hubbard_structure', hubbard_utils.hubbard_structure)
@@ -318,6 +326,12 @@ def parse_hubbard_content(self, handle):
318326
if subline:
319327
subline_number += 1
320328
subdata = subline.split()
329+
330+
try:
331+
value = float(subdata[7])
332+
except ValueError as exc:
333+
raise ValueError(f'could not parse `{subdata[7]}` value from line `{subline}`') from exc
334+
321335
result['hubbard_U']['sites'].append({
322336
'index': int(subdata[0]) - 1, # QE indices start from 1
323337
'type': int(subdata[1]),
@@ -326,7 +340,7 @@ def parse_hubbard_content(self, handle):
326340
'new_type': int(subdata[4]),
327341
'new_kind': subdata[5],
328342
'manifold': subdata[6],
329-
'value': float(subdata[7]),
343+
'value': value,
330344
})
331345
else:
332346
parsed = True
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
=-------------------------------------------------------------------=
3+
4+
Hubbard U parameters:
5+
6+
site n. type label spin new_type new_label manifold Hubbard U (eV)
7+
1 1 Co 1 1 Co 3d *****
8+
9+
=-------------------------------------------------------------------=
10+
11+
12+
chi0 matrix :
13+
-0.270848
14+
15+
16+
chi matrix :
17+
-0.086463
18+
19+
20+
chi0^{-1} matrix :
21+
-3.692112
22+
23+
24+
chi^{-1} matrix :
25+
-11.565582
26+
27+
28+
Hubbard matrix :
29+
7.873470
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
chi0 :
2+
-0.270847692461309
3+
4+
chi :
5+
-0.086463439940486
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
&INPUTHP
2+
conv_thr_chi = 1.0000000000d-06
3+
iverbosity = 2
4+
nq1 = 1
5+
nq2 = 1
6+
nq3 = 1
7+
outdir = 'out'
8+
prefix = 'aiida'
9+
/

0 commit comments

Comments
 (0)