Skip to content

Commit

Permalink
- Flesh out business logic in OpenMX parser
Browse files Browse the repository at this point in the history
- Rewrite business logic to use `n_excited_electrons` in the `VASP` parser
  • Loading branch information
[email protected] committed Dec 14, 2023
1 parent bb85d7e commit c3dab05
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
38 changes: 28 additions & 10 deletions electronicparsers/openmx/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

core_hole_parser = TextParser(quantities=[
Quantity('core_hole', rf'(\d+)\s+({element})\s+(\d+)',
repeats=True),
repeats=False), # TODO: consider `repeats = True` case
])


Expand Down Expand Up @@ -326,17 +326,35 @@ def parse_species(self, definitions: list[str], logger: logging.Logger) -> tuple
logger.error(f'Unknown exchange-correlation functional: {_definitions[2]}')

# evaluate core_hole
try:
nq, lq = _extract_core_hole(_definitions[1]).groups()
quantum_nums_flag = _extract_core_hole(_definitions[1]) # this checks the PAO, the PP is only necessary for the final state
if quantum_nums_flag:
quantum_nums = quantum_nums_flag.groups()
core_hole = CoreHole(
n_quantum_number = int(nq),
l_quantum_number = l_mapping[lq],
occupation = 0.,
n_quantum_number=int(quantum_nums[0]),
)
except AttributeError:
pass
except KeyError:
logger.error(f'Unknown l-quantum symbol: {lq}')
try:
core_hole.l_quantum_number = l_mapping[quantum_nums[1]]
except KeyError:
logger.error(f'Unknown l-quantum symbol: {quantum_nums[1]}')

core_hole_flags = mainfile_parser.results.get('core_hole')
if core_hole_flags:
core_hole.dscf_state = 'final'
spinpol = mainfile_parser.get('scf.SpinPolarization', '').lower()
if spinpol == 'on':
core_hole.n_electrons_excited = 1.
core_hole.ms_quantum_bool = not bool(int(core_hole_flags.results['core_hole'][2] / core_hole.degeneracy))
elif spinpol == 'off':
core_hole.n_electrons_excited = 2. # TODO: verify
logger.warning('''
Unexpected spin-restricted setting when using final-state core-hole computation.
This is not recommended by the manual. For now assuming double electron (bosonic) excitation.
''')
else:
logger.warning('Could not set all quantum numbers: non-collinear calculations not yet supported')
else:
core_hole.dscf_state = 'initial' # this will be a hook in $\Delta$-SCF
core_hole.n_electrons_excited = 0.

return pseudopotential, core_hole

Expand Down
23 changes: 8 additions & 15 deletions electronicparsers/vasp/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1377,27 +1377,19 @@ def parse_core_hole(self) -> (Union[CoreHole, None], Union[AtomsGroup, None], in

source = self.parser.incar

# setup `CoreHole` parameters
corehole_map = {
'n_quantum_number': source.get('CLN', 1),
'l_quantum_number': source.get('CLL', 0),
'occupation': source.get('CLZ', 0.), # tested with VASP 6.4.1
}

core_hole = CoreHole(**corehole_map)
core_hole.occupation = core_hole.degeneracy - core_hole.occupation
if core_hole.occupation < 0.:
self.logger.warning('Core hole occupation is negative. Setting to 0.') # TODO: check if this is correct
core_hole.occupation = 0.

# setup `AtomsGroup` parameters
elem_id = source.get('CLNT', 1) - 1
elem_ids = [int(x) for x in self.parser.atom_info['atomtypes']['atomspertype']]
lower_range = elem_ids[elem_id - 1] if elem_id > 1 else 0
atom_ids = list(range(lower_range, elem_ids[elem_id]))

return (
core_hole,
CoreHole(
n_quantum_number=source.get('CLN', 1),
l_quantum_number=source.get('CLL', 0),
n_electrons_excited=source.get('CLZ', 0.), # tested with VASP 6.4.1
dscf_state='final',
),
AtomsGroup(
label='core-hole',
type='active_orbital',
Expand Down Expand Up @@ -1552,7 +1544,7 @@ def parse_method(self) -> dict[str, Any]:
except AttributeError:
break
try:
species_electrons += param.core_hole.degeneracy - param.core_hole.occupation # same, regardless of spin-orbital or not
species_electrons -= param.core_hole.n_electrons_excited
except AttributeError:
pass
neutral_count += species_electrons * n_atoms
Expand Down Expand Up @@ -1640,6 +1632,7 @@ def parse_system(n_calc):
sec_system.x_vasp_nose_thermostat = nose

# Check for core-holes
## note that this check should be added to `parse_core_hole` if other kinds of atom_parameters are set
if self.parser.incar.get('ICORELEVEL', 0) == 2:
core_hole, core_hole_group, corehole_id = self.parse_core_hole()
self.archive.run[-1].method[-1].atom_parameters[corehole_id].core_hole = core_hole
Expand Down

0 comments on commit c3dab05

Please sign in to comment.