-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support calculating the XPS spectra of the atoms specific by indices (#…
…958) Implements the XPS workchain to support calculating the XPS spectra of the atoms specific by indices. This is useful for large systems with low symmetry, e.g. supported nanoparticles.
- Loading branch information
1 parent
17e173f
commit fc1a940
Showing
3 changed files
with
172 additions
and
67 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/aiida_quantumespresso/workflows/functions/get_marked_structures.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# -*- coding: utf-8 -*- | ||
"""CalcFunction to create structures with a marked atom for each site in a list.""" | ||
from aiida import orm | ||
from aiida.common import ValidationError | ||
from aiida.engine import calcfunction | ||
from aiida.orm.nodes.data.structure import Kind, Site, StructureData | ||
|
||
|
||
@calcfunction | ||
def get_marked_structures(structure, atoms_list, marker='X'): | ||
"""Read a StructureData object and return structures for XPS calculations. | ||
:param atoms_list: the atoms_list of atoms to be marked. | ||
:param marker: a Str node defining the name of the marked atom Kind. Default is 'X'. | ||
:returns: StructureData objects for the generated structure. | ||
""" | ||
marker = marker.value | ||
elements_present = [kind.symbol for kind in structure.kinds] | ||
if marker in elements_present: | ||
raise ValidationError( | ||
f'The marker ("{marker}") should not match an existing Kind in ' | ||
f'the input structure ({elements_present}.' | ||
) | ||
|
||
output_params = {} | ||
result = {} | ||
|
||
for index in atoms_list.get_list(): | ||
marked_structure = StructureData() | ||
kinds = {kind.name: kind for kind in structure.kinds} | ||
marked_structure.set_cell(structure.cell) | ||
|
||
for i, site in enumerate(structure.sites): | ||
if i == index: | ||
marked_kind = Kind(name=marker, symbols=site.kind_name) | ||
marked_site = Site(kind_name=marked_kind.name, position=site.position) | ||
marked_structure.append_kind(marked_kind) | ||
marked_structure.append_site(marked_site) | ||
output_params[f'site_{index}'] = {'symbol': site.kind_name, 'multiplicity': 1} | ||
else: | ||
if site.kind_name not in [kind.name for kind in marked_structure.kinds]: | ||
marked_structure.append_kind(kinds[site.kind_name]) | ||
new_site = Site(kind_name=site.kind_name, position=site.position) | ||
marked_structure.append_site(new_site) | ||
result[f'site_{index}'] = marked_structure | ||
|
||
result['output_parameters'] = orm.Dict(dict=output_params) | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Tests for the `get_marked_structure` class.""" | ||
|
||
|
||
def test_get_marked_structure(): | ||
"""Test the get_marked_structure function.""" | ||
from aiida.orm import List, StructureData | ||
from ase.build import molecule | ||
|
||
from aiida_quantumespresso.workflows.functions.get_marked_structures import get_marked_structures | ||
|
||
mol = molecule('CH3CH2OH') | ||
mol.center(vacuum=2.0) | ||
structure = StructureData(ase=mol) | ||
indices = List(list=[0, 1, 2]) | ||
output = get_marked_structures(structure, indices) | ||
assert len(output) == 4 | ||
assert output['site_0'].get_site_kindnames() == ['X', 'C', 'O', 'H', 'H', 'H', 'H', 'H', 'H'] | ||
assert output['site_1'].get_site_kindnames() == ['C', 'X', 'O', 'H', 'H', 'H', 'H', 'H', 'H'] |