Skip to content

Commit

Permalink
Parse electric field outputs from XML
Browse files Browse the repository at this point in the history
  • Loading branch information
bastonero committed Jun 17, 2024
1 parent 2199f45 commit acf2d09
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from aiida.orm import Data

from aiida_quantumespresso.data.hubbard_structure import HubbardStructureData
from aiida_quantumespresso.utils.hubbard import HubbardUtils
from aiida_quantumespresso.utils.hubbard import is_intersite_hubbard


@calcfunction
Expand All @@ -27,6 +27,7 @@ def seekpath_structure_analysis(structure, **kwargs):
Note that exact parameters that are available and their defaults will depend on your Seekpath version.
"""
from aiida.tools import get_explicit_kpoints_path
import numpy as np

# All keyword arugments should be `Data` node instances of base type and so should have the `.value` attribute
unwrapped_kwargs = {key: node.value for key, node in kwargs.items() if isinstance(node, Data)}
Expand All @@ -36,9 +37,35 @@ def seekpath_structure_analysis(structure, **kwargs):
if not isinstance(structure, HubbardStructureData):
return result

primitive = result['primitive_structure']
hutils = HubbardUtils(structure)
primitive_hubbard = hutils.get_hubbard_for_supercell(primitive)
if is_intersite_hubbard(structure.hubbard):
ucell = structure.cell
pcell = result['primitive_structure'].cell
matrix = np.dot(np.linalg.inv(pcell), ucell)

result['primitive_structure'] = primitive_hubbard
kpoints_data = result['explicit_kpoints'].clone()
kpoints = np.dot(kpoints_data.get_kpoints(), matrix)
kpoints_data.set_kpoints(kpoints)

result['explicit_kpoints'] = kpoints_data
result['primitive_structure'] = structure.clone()
return result

result['primitive_structure'] = update_structure_with_hubbard(result['primitive_structure'], structure)
result['conv_structure'] = update_structure_with_hubbard(result['conv_structure'], structure)
return result


def update_structure_with_hubbard(structure, orig_structure):
"""Update the structure based on Hubbard parameters if the input structure is a HubbardStructureData."""
hubbard_structure = HubbardStructureData.from_structure(structure)

for parameter in orig_structure.hubbard.parameters:
hubbard_structure.initialize_onsites_hubbard(
atom_name=orig_structure.sites[parameter.atom_index].kind_name,
atom_manifold=parameter.atom_manifold,
value=parameter.value,
hubbard_type=parameter.hubbard_type,
use_kinds=True,
)

return hubbard_structure
8 changes: 7 additions & 1 deletion src/aiida_quantumespresso/parsers/parse_xml/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def parse_xml_post_6_2(xml):
[x * CONSTANTS.bohr_to_ang for x in outputs['atomic_structure']['cell']['a3']],
]

has_electric_field = inputs.get('electric_field', {}).get('electric_potential', None) == 'sawtooth_potential'
has_electric_field = 'electric_field' in outputs
has_dipole_correction = inputs.get('electric_field', {}).get('dipole_correction', False)

if 'occupations' in inputs.get('bands', {}):
Expand Down Expand Up @@ -608,3 +608,9 @@ def parse_step_to_trajectory(trajectory, data, skip_structure=False):
stress = np.array(data['stress']['$']) * 2 * CONSTANTS.ry_si / CONSTANTS.bohr_si**3 / 1.0e+9
dimensions = data['stress']['@dims'] # Like [3, 3], should be reversed to reshape the stress array
trajectory['stress'].append(stress.reshape(dimensions[::-1]))

if 'electric_field' in data and 'finiteElectricFieldInfo' in data['electric_field']:
electronic_dipole = np.array(data['electric_field']['finiteElectricFieldInfo']['electronicDipole'])
ionic_dipole = np.array(data['electric_field']['finiteElectricFieldInfo']['ionicDipole'])
trajectory['electronic_dipole_cartesian_axes'].append(electronic_dipole)
trajectory['ionic_dipole_cartesian_axes'].append(ionic_dipole)

0 comments on commit acf2d09

Please sign in to comment.