-
Notifications
You must be signed in to change notification settings - Fork 41
/
phonons.py
91 lines (73 loc) · 2.37 KB
/
phonons.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""Summarizer for phonopy."""
from __future__ import annotations
from importlib.util import find_spec
from typing import TYPE_CHECKING
from monty.dev import requires
from quacc import SETTINGS, __version__
from quacc.schemas.atoms import atoms_to_metadata
from quacc.utils.dicts import finalize_dict
from quacc.utils.files import get_uri
has_phonopy = bool(find_spec("phonopy"))
if TYPE_CHECKING:
from pathlib import Path
from typing import Any
from ase.atoms import Atoms
from maggma.core import Store
from quacc.schemas._aliases.phonons import PhononSchema
if has_phonopy:
from phonopy import Phonopy
_DEFAULT_SETTING = ()
@requires(has_phonopy, "This schema relies on phonopy")
def summarize_phonopy(
phonon: Phonopy,
input_atoms: Atoms,
directory: str | Path,
parameters: dict[str, Any] | None = None,
additional_fields: dict[str, Any] | None = None,
store: Store | None = _DEFAULT_SETTING,
) -> PhononSchema:
"""
Summarize a Phonopy object.
Parameters
----------
phonon
Phonopy object
input_atoms
Input atoms object
directory
Directory where the results are stored.
parameters
Calculator parameters used to generate the phonon object.
additional_fields
Additional fields to add to the document.
store
Whether to store the document in the database.
Returns
-------
PhononSchema
The PhononSchema.
"""
additional_fields = additional_fields or {}
store = SETTINGS.STORE if store == _DEFAULT_SETTING else store
uri = get_uri(directory)
directory = ":".join(uri.split(":")[1:])
inputs = {
"parameters": parameters,
"nid": uri.split(":")[0],
"dir_name": directory,
"phonopy_metadata": {"version": phonon.version},
"quacc_version": __version__,
}
results = {
"results": {
"thermal_properties": phonon.get_thermal_properties_dict(),
"mesh_properties": phonon.get_mesh_dict(),
"total_dos": phonon.get_total_dos_dict(),
"force_constants": phonon.force_constants,
}
}
atoms_metadata = atoms_to_metadata(input_atoms)
unsorted_task_doc = atoms_metadata | inputs | results | additional_fields
return finalize_dict(
unsorted_task_doc, directory, gzip_file=SETTINGS.GZIP_FILES, store=store
)