Skip to content

Commit

Permalink
Merge pull request #17 from aiida-phonopy/phonopy-base
Browse files Browse the repository at this point in the history
Phonopy base
  • Loading branch information
atztogo committed Sep 23, 2021
2 parents 41f0439 + d6f4dfb commit 992e138
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 230 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
AiiDA Phonopy plugin
====================
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/aiida-phonopy/aiida-phonopy/develop.svg)](https://results.pre-commit.ci/latest/github/aiida-phonopy/aiida-phonopy/develop)

This a phonopy plugin for AiiDA. This plugin includes workflows to
calculate phonons with supercell and finite displacement approaches.
Currently it provides interfaces only to VASP.
# AiiDA Phonopy plugin

This a phonopy plugin for AiiDA. This plugin includes workflows to calculate
phonons with supercell and finite displacement approaches. Currently VASP and QE
are supported.
13 changes: 6 additions & 7 deletions aiida_phonopy/calcs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class BasePhonopyCalculation(CalcJob):
def define(cls, spec):
"""Define inputs, outputs, and outline."""
super().define(spec)
spec.input("settings", valid_type=Dict, help="Phonopy parameters")
spec.input("structure", valid_type=StructureData, help="Unit cell structure")
spec.input("settings", valid_type=Dict, help="Phonopy parameters.")
spec.input("structure", valid_type=StructureData, help="Unit cell structure.")
spec.input("symmetry_tolerance", valid_type=Float, default=lambda: Float(1e-5))
spec.input(
"fc_only",
Expand All @@ -41,19 +41,19 @@ def define(cls, spec):
help="Sets of forces in supercells",
)
spec.input(
"nac_params", valid_type=ArrayData, required=False, help="NAC parameters"
"nac_params", valid_type=ArrayData, required=False, help="NAC parameters."
)
spec.input(
"primitive",
valid_type=StructureData,
required=False,
help="Primitive cell structure",
help="Primitive cell structure only necessary NAC is applied.",
)
spec.input(
"dataset",
valid_type=(Dict, ArrayData),
required=False,
help="Displacements and forces dataset",
help="Displacements and forces dataset.",
)

def prepare_for_submission(self, folder):
Expand All @@ -73,8 +73,7 @@ def prepare_for_submission(self, folder):
not self.inputs.fc_only
and "nac_params" in self.inputs
and "primitive" in self.inputs
and "symmetry_tolerance" in self.inputs
): # noqa: E129
):
born_txt = get_BORN_txt(
self.inputs.nac_params,
self.inputs.primitive,
Expand Down
25 changes: 0 additions & 25 deletions aiida_phonopy/calcs/phonopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,6 @@ def define(cls, spec):
"""Define inputs, outputs, and outline."""
super().define(spec)

spec.input(
"projected_dos_filename",
valid_type=Str,
default=lambda: Str(cls._OUTPUT_PROJECTED_DOS),
)
spec.input(
"total_dos_filename",
valid_type=Str,
default=lambda: Str(cls._OUTPUT_TOTAL_DOS),
)
spec.input(
"thermal_properties_filename",
valid_type=Str,
default=lambda: Str(cls._OUTPUT_THERMAL_PROPERTIES),
)
spec.input(
"band_structure_filename",
valid_type=Str,
default=lambda: Str(cls._OUTPUT_BAND_STRUCTURE),
)
spec.input(
"force_constants_filename",
valid_type=Str,
default=lambda: Str(cls._INOUT_FORCE_CONSTANTS),
)
# parser_name has to be set to invoke parsing.
spec.inputs["metadata"]["options"]["parser_name"].default = "phonopy"
spec.inputs["metadata"]["options"]["output_filename"].default = "phonopy.yaml"
Expand Down
2 changes: 1 addition & 1 deletion aiida_phonopy/common/raw_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def parse_band_structure(f, label=None):
.replace("\\", "")
.replace("mathrm{", "")
.replace("}", "")
.upper() # noqa E501
.upper()
for x in pair
]
)
Expand Down
10 changes: 8 additions & 2 deletions aiida_phonopy/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,10 @@ def collect_forces_and_energies(ctx, ctx_supercells, prefix="force_calc"):
else:
calc_dict = calc.outputs
forces_dict["forces_%s" % num] = calc_dict["forces"]
forces_dict["energy_%s" % num] = calc_dict["energy"]
if "energy" in calc_dict:
forces_dict["energy_%s" % num] = calc_dict["energy"]
elif "total_energy" in calc_dict: # For CommonWorkflow
forces_dict["energy_%s" % num] = calc_dict["total_energy"]

return forces_dict

Expand Down Expand Up @@ -649,7 +652,10 @@ def _get_force_set(**forces_dict):
else:
force_sets[num - 1] = forces - forces_0
elif "energy" in key:
energies[num - 1] = value.get_array("energy")[-1]
if isinstance(value, Float): # For CommonWorkflow
energies[num - 1] = value.value
else:
energies[num - 1] = value.get_array("energy")[-1]

return force_sets, energies, forces_0_key, energy_0_key

Expand Down
12 changes: 7 additions & 5 deletions aiida_phonopy/parsers/phonopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from aiida.engine import ExitCode
from aiida.common.exceptions import NotExistent
from aiida.parsers.parser import Parser
from aiida.plugins import CalculationFactory
from aiida_phonopy.common.raw_parsers import (
parse_thermal_properties,
parse_FORCE_CONSTANTS,
Expand All @@ -15,6 +16,7 @@


Str = DataFactory("str")
PhonopyCalculation = CalculationFactory("phonopy.phonopy")


class PhonopyParser(Parser):
Expand All @@ -38,27 +40,27 @@ def parse(self, **kwargs):
# check what is inside the folder
list_of_files = output_folder.list_object_names()

fc_filename = self.node.inputs.force_constants_filename.value
fc_filename = PhonopyCalculation._INOUT_FORCE_CONSTANTS
if fc_filename in list_of_files:
with output_folder.open(fc_filename, "rb") as f:
self.out("force_constants", parse_FORCE_CONSTANTS(f))

projected_dos_filename = self.node.inputs.projected_dos_filename.value
projected_dos_filename = PhonopyCalculation._OUTPUT_PROJECTED_DOS
if projected_dos_filename in list_of_files:
with output_folder.open(projected_dos_filename) as f:
self.out("pdos", parse_projected_dos(f))

total_dos_filename = self.node.inputs.projected_dos_filename.value
total_dos_filename = PhonopyCalculation._OUTPUT_TOTAL_DOS
if total_dos_filename in list_of_files:
with output_folder.open(total_dos_filename) as f:
self.out("dos", parse_total_dos(f))

tp_filename = self.node.inputs.thermal_properties_filename.value
tp_filename = PhonopyCalculation._OUTPUT_THERMAL_PROPERTIES
if tp_filename in list_of_files:
with output_folder.open(tp_filename) as f:
self.out("thermal_properties", parse_thermal_properties(f))

band_filename = self.node.inputs.band_structure_filename.value
band_filename = PhonopyCalculation._OUTPUT_BAND_STRUCTURE
if band_filename in list_of_files:
if "symmetry" in self.node.inputs.settings.attributes:
sym_dataset = self.node.inputs.settings["symmetry"]
Expand Down
4 changes: 2 additions & 2 deletions aiida_phonopy/workflows/forces.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _get_forces(outputs, code_string):
if (
"output_trajectory" in outputs
and "forces" in outputs.output_trajectory.get_arraynames()
): # noqa: E129 E501
):
forces_data = get_qe_forces(outputs.output_trajectory)
else:
return None
Expand Down Expand Up @@ -73,7 +73,7 @@ def _get_energy(outputs, code_string):
if (
"output_parameters" in outputs
and "energy" in outputs.output_parameters.keys()
): # noqa: E129
):
energy_data = get_qe_energy(outputs.output_parameters)
return energy_data

Expand Down
Empty file.
File renamed without changes.
Empty file.

0 comments on commit 992e138

Please sign in to comment.