-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move calcfunctions to
aiida_quantumespresso.calculations.functions
Since they are calculation functions they do not belong in the workflow module. To not break backwards-compatibility the original modules import the functions from their new location and emit a `Warning`. Note that we explicitly do not use a `DeprecationWarning` since those are automatically filtered in Python 3.
- Loading branch information
Showing
8 changed files
with
91 additions
and
69 deletions.
There are no files selected for viewing
Empty file.
37 changes: 37 additions & 0 deletions
37
aiida_quantumespresso/calculations/functions/create_kpoints_from_distance.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,37 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Calculation function to compute a k-point mesh for a structure with a guaranteed minimum k-point distance.""" | ||
from aiida.engine import calcfunction | ||
|
||
|
||
@calcfunction | ||
def create_kpoints_from_distance(structure, distance, force_parity): | ||
"""Generate a uniformly spaced kpoint mesh for a given structure. | ||
The spacing between kpoints in reciprocal space is guaranteed to be at least the defined distance. | ||
:param structure: the StructureData to which the mesh should apply | ||
:param distance: a Float with the desired distance between kpoints in reciprocal space | ||
:param force_parity: a Bool to specify whether the generated mesh should maintain parity | ||
:returns: a KpointsData with the generated mesh | ||
""" | ||
from numpy import linalg | ||
from aiida.orm import KpointsData | ||
|
||
epsilon = 1E-5 | ||
|
||
kpoints = KpointsData() | ||
kpoints.set_cell_from_structure(structure) | ||
kpoints.set_kpoints_mesh_from_density(distance.value, force_parity=force_parity.value) | ||
|
||
lengths_vector = [linalg.norm(vector) for vector in structure.cell] | ||
lengths_kpoint = kpoints.get_kpoints_mesh()[0] | ||
|
||
is_symmetric_cell = all(abs(length - lengths_vector[0]) < epsilon for length in lengths_vector) | ||
is_symmetric_mesh = all(length == lengths_kpoint[0] for length in lengths_kpoint) | ||
|
||
# If the vectors of the cell all have the same length, the kpoint mesh should be isotropic as well | ||
if is_symmetric_cell and not is_symmetric_mesh: | ||
nkpoints = max(lengths_kpoint) | ||
kpoints.set_kpoints_mesh([nkpoints, nkpoints, nkpoints]) | ||
|
||
return kpoints |
31 changes: 31 additions & 0 deletions
31
aiida_quantumespresso/calculations/functions/seekpath_structure_analysis.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,31 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Calcfunction to primitivize a structure and return high symmetry k-point path through its Brillouin zone.""" | ||
from aiida.engine import calcfunction | ||
from aiida.orm import Data | ||
|
||
|
||
@calcfunction | ||
def seekpath_structure_analysis(structure, **kwargs): | ||
"""Primitivize the structure with SeeKpath and generate the high symmetry k-point path through its Brillouin zone. | ||
This calcfunction will take a structure and pass it through SeeKpath to get the normalized primitive cell and the | ||
path of high symmetry k-points through its Brillouin zone. Note that the returned primitive cell may differ from the | ||
original structure in which case the k-points are only congruent with the primitive cell. | ||
The keyword arguments can be used to specify various Seekpath parameters, such as: | ||
with_time_reversal: True | ||
reference_distance: 0.025 | ||
recipe: 'hpkot' | ||
threshold: 1e-07 | ||
symprec: 1e-05 | ||
angle_tolerance: -1.0 | ||
Note that exact parameters that are available and their defaults will depend on your Seekpath version. | ||
""" | ||
from aiida.tools import get_explicit_kpoints_path | ||
|
||
# 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)} | ||
|
||
return get_explicit_kpoints_path(structure, **unwrapped_kwargs) |
43 changes: 8 additions & 35 deletions
43
aiida_quantumespresso/workflows/functions/create_kpoints_from_distance.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 |
---|---|---|
@@ -1,37 +1,10 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Calculation function to compute a k-point mesh for a structure with a guaranteed minimum k-point distance.""" | ||
from aiida.engine import calcfunction | ||
|
||
|
||
@calcfunction | ||
def create_kpoints_from_distance(structure, distance, force_parity): | ||
"""Generate a uniformly spaced kpoint mesh for a given structure. | ||
The spacing between kpoints in reciprocal space is guaranteed to be at least the defined distance. | ||
:param structure: the StructureData to which the mesh should apply | ||
:param distance: a Float with the desired distance between kpoints in reciprocal space | ||
:param force_parity: a Bool to specify whether the generated mesh should maintain parity | ||
:returns: a KpointsData with the generated mesh | ||
""" | ||
from numpy import linalg | ||
from aiida.orm import KpointsData | ||
|
||
epsilon = 1E-5 | ||
|
||
kpoints = KpointsData() | ||
kpoints.set_cell_from_structure(structure) | ||
kpoints.set_kpoints_mesh_from_density(distance.value, force_parity=force_parity.value) | ||
|
||
lengths_vector = [linalg.norm(vector) for vector in structure.cell] | ||
lengths_kpoint = kpoints.get_kpoints_mesh()[0] | ||
|
||
is_symmetric_cell = all(abs(length - lengths_vector[0]) < epsilon for length in lengths_vector) | ||
is_symmetric_mesh = all(length == lengths_kpoint[0] for length in lengths_kpoint) | ||
|
||
# If the vectors of the cell all have the same length, the kpoint mesh should be isotropic as well | ||
if is_symmetric_cell and not is_symmetric_mesh: | ||
nkpoints = max(lengths_kpoint) | ||
kpoints.set_kpoints_mesh([nkpoints, nkpoints, nkpoints]) | ||
|
||
return kpoints | ||
# pylint: disable=unused-import | ||
import warnings | ||
from aiida_quantumespresso.calculations.functions.create_kpoints_from_distance import create_kpoints_from_distance | ||
|
||
warnings.warn( | ||
'This module is deprecated and will be removed soon. Please use thw module' | ||
'aiida_quantumespresso.calculations.functions.create_kpoints_from_distance instead', Warning | ||
) |
37 changes: 8 additions & 29 deletions
37
aiida_quantumespresso/workflows/functions/seekpath_structure_analysis.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 |
---|---|---|
@@ -1,31 +1,10 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Calcfunction to primitivize a structure and return high symmetry k-point path through its Brillouin zone.""" | ||
from aiida.engine import calcfunction | ||
from aiida.orm import Data | ||
|
||
|
||
@calcfunction | ||
def seekpath_structure_analysis(structure, **kwargs): | ||
"""Primitivize the structure with SeeKpath and generate the high symmetry k-point path through its Brillouin zone. | ||
This calcfunction will take a structure and pass it through SeeKpath to get the normalized primitive cell and the | ||
path of high symmetry k-points through its Brillouin zone. Note that the returned primitive cell may differ from the | ||
original structure in which case the k-points are only congruent with the primitive cell. | ||
The keyword arguments can be used to specify various Seekpath parameters, such as: | ||
with_time_reversal: True | ||
reference_distance: 0.025 | ||
recipe: 'hpkot' | ||
threshold: 1e-07 | ||
symprec: 1e-05 | ||
angle_tolerance: -1.0 | ||
Note that exact parameters that are available and their defaults will depend on your Seekpath version. | ||
""" | ||
from aiida.tools import get_explicit_kpoints_path | ||
|
||
# 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)} | ||
|
||
return get_explicit_kpoints_path(structure, **unwrapped_kwargs) | ||
# pylint: disable=unused-import | ||
import warnings | ||
from aiida_quantumespresso.calculations.functions.seekpath_structure_analysis import seekpath_structure_analysis | ||
|
||
warnings.warn( | ||
'This module is deprecated and will be removed soon. Please use the module' | ||
'aiida_quantumespresso.calculations.functions.seekpath_structure_analysis instead', Warning | ||
) |
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
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