Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XAS: Enable Correct Parsing of Hubbard and Magnetic Data #969

Merged
merged 17 commits into from
Mar 29, 2024
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
4b1bae1
Enable Hubbard and Magnetic Moments for `XspectraCoreWorkChain` and `…
PNOGillespie Aug 30, 2023
1d17eaa
Tests: Fix minor errors in tests from previous commit
PNOGillespie Aug 30, 2023
7677a60
`get_xspectra_structures()`: Fix handling of marked structures
PNOGillespie Sep 7, 2023
d685dcd
`get_xspectra_structures()`: remove options for `initial_magnetization`
PNOGillespie Sep 14, 2023
7f82c72
`XspectraCrystalWorkChain`: Enable Hubbard and Magnetic Data
PNOGillespie Sep 21, 2023
96ff74f
Merge branch 'aiidateam:main' into fix/xs-crystal-wc-structures
PNOGillespie Sep 21, 2023
1d0782c
`XspectraCrystalWorkChain`: Fix handling of GIPAW pseudos
PNOGillespie Sep 22, 2023
9ae5570
Merge branch 'main' into fix/xs-crystal-wc-structures
superstar54 Nov 16, 2023
2448f63
XSpectra `WorkChain`s: Refinements and Improvements
PNOGillespie Nov 29, 2023
8b71067
Merge branch 'main' into fix/xs-crystal-wc-structures
PNOGillespie Nov 29, 2023
120ae6d
Merge branch 'main' into fix/xs-crystal-wc-structures
PNOGillespie Mar 4, 2024
c4701b3
`get_xspectra_structures`: Bugfixes and Improvements
PNOGillespie Mar 4, 2024
24524e5
Merge branch 'fix/xs-crystal-wc-structures' of https://github.com/PNO…
PNOGillespie Mar 4, 2024
1f1d8f5
Tests: Update `test_get_xspectra_structures`
PNOGillespie Mar 4, 2024
7f3842f
`get_xspectra_structures`: Consolidate Logic
PNOGillespie Mar 21, 2024
d34f16f
`get_xspectra_structures`: Reduce Use of `get_symmetry_dataset`
PNOGillespie Mar 28, 2024
24695da
Merge branch 'main' into fix/xs-crystal-wc-structures
superstar54 Mar 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ def get_xspectra_structures(structure, **kwargs): # pylint: disable=too-many-st
else:
standardize_structure = True
if 'absorbing_elements_list' in unwrapped_kwargs.keys():
elements_defined = True
abs_elements_list = unwrapped_kwargs['absorbing_elements_list'].get_list()
# confirm that the elements requested are actually in the input structure
for req_element in abs_elements_list:
Expand All @@ -106,7 +105,6 @@ def get_xspectra_structures(structure, **kwargs): # pylint: disable=too-many-st
f' {elements_present}'
)
else:
elements_defined = False
abs_elements_list = []
for kind in structure.kinds:
if kind.symbol not in abs_elements_list:
Expand Down Expand Up @@ -261,9 +259,9 @@ def get_xspectra_structures(structure, **kwargs): # pylint: disable=too-many-st
else:
new_i = i
cleaned_structure_tuple[2].append(new_i)
cleaned_symmetry_dataset = spglib.get_symmetry_dataset(cleaned_structure_tuple, **spglib_kwargs)

symmetry_dataset = spglib.get_symmetry_dataset(spglib_tuple, **spglib_kwargs)
symmetry_dataset = spglib.get_symmetry_dataset(cleaned_structure_tuple, **spglib_kwargs)
else:
symmetry_dataset = spglib.get_symmetry_dataset(spglib_tuple, **spglib_kwargs)

# if there is no symmetry to exploit, or no standardization is desired, then we just use
# the input structure in the following steps. This is done to account for the case where
Expand All @@ -282,42 +280,32 @@ def get_xspectra_structures(structure, **kwargs): # pylint: disable=too-many-st
symmetry_dataset = spglib.get_symmetry_dataset(standardized_structure_tuple, **spglib_kwargs)
structure_is_standardized = True

if use_element_types:
equivalent_atoms_array = cleaned_symmetry_dataset['equivalent_atoms']
else:
equivalent_atoms_array = symmetry_dataset['equivalent_atoms']
equivalent_atoms_array = symmetry_dataset['equivalent_atoms']

if structure_is_standardized:
element_types = symmetry_dataset['std_types']
else: # convert the 'std_types' from standardized to primitive cell
spglib_std_types = symmetry_dataset['std_types']
spglib_std_map_to_prim = symmetry_dataset['std_mapping_to_primitive']
# we generate the type-specific data on-the-fly since we need to
# know which type (and thus kind) *should* be at each site
# even if we "cleaned" the structure previously
spglib_std_types = spglib.get_symmetry_dataset(spglib_tuple, **spglib_kwargs)['std_types']
spglib_map_to_prim = spglib.get_symmetry_dataset(spglib_tuple, **spglib_kwargs)['mapping_to_primitive']
spglib_std_map_to_prim = spglib.get_symmetry_dataset(spglib_tuple,
**spglib_kwargs)['std_mapping_to_primitive']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change it to run get_symmetry_dataset only one time.


map_std_pos_to_type = {}
for position, atom_type in zip(spglib_std_map_to_prim, spglib_std_types):
map_std_pos_to_type[str(position)] = atom_type
primitive_types = []
for position in symmetry_dataset['mapping_to_primitive']:
for position in spglib_map_to_prim:
atom_type = map_std_pos_to_type[str(position)]
primitive_types.append(atom_type)
element_types = primitive_types

equivalency_dict = {}
for index, symmetry_types in enumerate(zip(equivalent_atoms_array, element_types)):
symmetry_value, element_type = symmetry_types
if elements_defined: # only process the elements given in the list
if f'site_{symmetry_value}' in equivalency_dict:
equivalency_dict[f'site_{symmetry_value}']['equivalent_sites_list'].append(index)
elif type_mapping_dict[str(element_type)].symbol not in abs_elements_list:
pass
else:
equivalency_dict[f'site_{symmetry_value}'] = {
'kind_name': type_mapping_dict[str(element_type)].name,
'symbol': type_mapping_dict[str(element_type)].symbol,
'site_index': symmetry_value,
'equivalent_sites_list': [symmetry_value]
}
else: # process everything in the system
if type_mapping_dict[str(element_type)].symbol in abs_elements_list:
if f'site_{symmetry_value}' in equivalency_dict:
equivalency_dict[f'site_{symmetry_value}']['equivalent_sites_list'].append(index)
else:
Expand All @@ -333,12 +321,8 @@ def get_xspectra_structures(structure, **kwargs): # pylint: disable=too-many-st

output_params['equivalent_sites_data'] = equivalency_dict

if use_element_types:
output_params['spacegroup_number'] = cleaned_symmetry_dataset['number']
output_params['international_symbol'] = cleaned_symmetry_dataset['international']
else:
output_params['spacegroup_number'] = symmetry_dataset['number']
output_params['international_symbol'] = symmetry_dataset['international']
output_params['spacegroup_number'] = symmetry_dataset['number']
output_params['international_symbol'] = symmetry_dataset['international']

output_params['structure_is_standardized'] = structure_is_standardized
if structure_is_standardized:
Expand Down Expand Up @@ -384,16 +368,13 @@ def get_xspectra_structures(structure, **kwargs): # pylint: disable=too-many-st
new_supercell = StructureData(ase=ase_supercell)

if is_hubbard_structure: # Scale up the hubbard parameters to match and return the HubbardStructureData
if multiples == [1, 1, 1]: # If no new supercell was made, just re-apply the incoming parameters
new_hubbard_supercell = HubbardStructureData.from_structure(new_supercell)
new_hubbard_supercell.hubbard = structure.hubbard
new_supercell = new_hubbard_supercell
supercell_hubbard_params = new_supercell.hubbard
else:
hubbard_manip = HubbardUtils(structure)
new_hubbard_supercell = hubbard_manip.get_hubbard_for_supercell(new_supercell)
new_supercell = new_hubbard_supercell
supercell_hubbard_params = new_supercell.hubbard
# we can exploit the fact that `get_hubbard_for_supercell` will return a HubbardStructureData node
# with the same hubbard parameters in the case where the input structure and the supercell are the
# same (i.e. multiples == [1, 1, 1])
hubbard_manip = HubbardUtils(structure)
new_hubbard_supercell = hubbard_manip.get_hubbard_for_supercell(new_supercell)
new_supercell = new_hubbard_supercell
supercell_hubbard_params = new_supercell.hubbard
result['supercell'] = new_supercell
else:
result['supercell'] = new_supercell
Expand All @@ -405,23 +386,19 @@ def get_xspectra_structures(structure, **kwargs): # pylint: disable=too-many-st
for value in equivalency_dict.values():
target_site = value['site_index']
marked_structure = StructureData()
supercell_kinds = {kind.name: kind for kind in new_supercell.kinds}
marked_structure.set_cell(new_supercell.cell)
new_kind_names = [kind.name for kind in new_supercell.kinds]

for index, site in enumerate(new_supercell.sites):
kind_at_position = new_supercell.kinds[new_kind_names.index(site.kind_name)]
if index == target_site:
kind_name_at_position = site.kind_name
for kind in new_supercell.kinds:
if kind_name_at_position == kind.name:
kind_at_position = kind
break
absorbing_kind = Kind(name=abs_atom_marker, symbols=kind_at_position.symbol)
absorbing_site = Site(kind_name=absorbing_kind.name, position=site.position)
marked_structure.append_kind(absorbing_kind)
marked_structure.append_site(absorbing_site)
else:
if site.kind_name not in [kind.name for kind in marked_structure.kinds]:
marked_structure.append_kind(supercell_kinds[site.kind_name])
if kind_at_position.name not in [kind.name for kind in marked_structure.kinds]:
marked_structure.append_kind(kind_at_position)
new_site = Site(kind_name=site.kind_name, position=site.position)
marked_structure.append_site(new_site)

Expand Down
Loading