Skip to content

Commit

Permalink
Fix cp2k inp (#270)
Browse files Browse the repository at this point in the history
* Fix logic loophole when no `.inp` files are recuperated, but still requested.

This reverts commit b31578d.

---------

Co-authored-by: ndaelman <[email protected]>
  • Loading branch information
ndaelman-hu and ndaelman authored Dec 17, 2024
1 parent 6e57d16 commit 563e5c1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
23 changes: 11 additions & 12 deletions electronicparsers/cp2k/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1570,24 +1570,23 @@ def parse(name, data, section):
input_files = get_files(
input_filename, self.filepath, self.mainfile, deep=False
)
if not input_files:
self.logger.warning(
'Input *.inp file not found. We will attempt finding the restart file from '
'the project_name appending a -1, <project_name>-1.restart.',
data={'project_name': project_name},
)
# Patch to check if the input is .restart and CP2K appended a -1 after the name
if not input_files: # ? what is the purpose of this recovery logic
self.logger.warning('Input (*.inp) file not found.')
if project_name:
project_filename = f'{project_name}-1.restart'
self.logger.warning(
f'Will attempt from restart file ({project_filename})'
)
input_files = get_files(
project_filename, self.filepath, self.mainfile, deep=False
)
else:
return
if len(input_files) > 1:
if len(input_files) == 0:
return
elif len(input_files) > 1:
self.logger.warning(
f'Multiple input files found. We will parse the first read file.'
)
f'Multiple input files found. Will parse the first file retrieved.'
) # ! TODO: employ better heuristic OR parse all
# cover single or multiple `input_files`
self.inp_parser.mainfile = input_files[0]

parse('x_cp2k_section_input', self.inp_parser.tree, self.archive.run[-1])
Expand Down
18 changes: 10 additions & 8 deletions electronicparsers/wien2k/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1127,18 +1127,20 @@ def parse_method(self):
atom_obj = AtomParameters()
atom_obj.atom_index = atom_index
atom_obj.core_hole = CoreHole(
j_quantum_number = j_quantum_number,
l_quantum_number = l_quantum_number,
n_quantum_number = n_quantum_number,
n_electrons_excited = electrons_excited,
occupation = occupancy,
dscf_state = 'final',
j_quantum_number=j_quantum_number,
l_quantum_number=l_quantum_number,
n_quantum_number=n_quantum_number,
n_electrons_excited=electrons_excited,
occupation=occupancy,
dscf_state='final',
)
atom_par.append(atom_obj)
break
else:
self.logger.warning("inc file is missing, no corehole information "
"will be parsed if corehole present.")
self.logger.warning(
'inc file is missing, no corehole information '
'will be parsed if corehole present.'
)
# basis
if self.in1_parser.mainfile:
self.in1_parser.parse()
Expand Down
2 changes: 2 additions & 0 deletions tests/test_wien2kparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
CoreHole,
)


def approx(value, abs=0, rel=1e-6):
return pytest.approx(value, abs=abs, rel=rel)

Expand Down Expand Up @@ -125,6 +126,7 @@ def test_dos(parser, caplog):
2.7395685667470246e17
)


def test_core_hole(parser, caplog):
archive = EntryArchive()
parser.parse('tests/data/wien2k/TiN-corehole/TiN-corehole.scf', archive, None)
Expand Down

0 comments on commit 563e5c1

Please sign in to comment.