File: absorption.py

package info (click to toggle)
python-emmet-core 0.84.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 77,220 kB
  • sloc: python: 16,355; makefile: 30
file content (86 lines) | stat: -rw-r--r-- 2,684 bytes parent folder | download
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
from typing import List, Optional
from pydantic import Field
from emmet.core.material_property import PropertyDoc
import numpy as np
from emmet.core.mpid import MPID
from pymatgen.core import Structure


class AbsorptionDoc(PropertyDoc):
    """Absorption spectrum based on frequency dependent dielectric function calculations."""

    property_name: str = "Optical absorption spectrum"

    task_id: str = Field(..., description="Calculation id")

    energies: List[float] = Field(
        ..., description="Absorption energy in eV starting from 0"
    )

    energy_max: float = Field(..., description="Maximum energy")

    absorption_coefficient: List[float] = Field(
        ..., description="Absorption coefficient in cm^-1"
    )

    average_imaginary_dielectric: List[float] = Field(
        ...,
        description="Imaginary part of the dielectric function corresponding to the "
        "energies",
    )

    average_real_dielectric: List[float] = Field(
        ...,
        description="Real part of the dielectric function corresponding to the energies",
    )

    bandgap: Optional[float] = Field(None, description="The electronic band gap")

    nkpoints: Optional[float] = Field(
        None, description="The number of kpoints used in the calculation"
    )

    @classmethod
    def _convert_list_to_tensor(cls, l):
        l = np.array(l)
        a = np.array([[l[0], l[3], l[4]], [l[3], l[1], l[5]], [l[4], l[5], l[2]]])
        return a

    @classmethod
    def from_structure(
        cls,
        material_id: MPID,
        energies: List,
        task_id: str,
        real_d: List[np.ndarray],
        imag_d: List[np.ndarray],
        absorption_co: List,
        bandgap: float,
        structure: Structure,
        nkpoints: float,
        **kwargs,
    ):
        real_d_average = [
            np.average(np.diagonal(cls._convert_list_to_tensor(t))) for t in real_d
        ]
        imag_d_average = [
            np.average(np.diagonal(cls._convert_list_to_tensor(t))) for t in imag_d
        ]
        absorption_co = list(np.array(absorption_co))
        energy_max = np.array(energies).max()

        return super().from_structure(
            meta_structure=structure,
            material_id=material_id,
            **{
                "energies": energies,
                "energy_max": energy_max,
                "absorption_coefficient": absorption_co,
                "average_imaginary_dielectric": imag_d_average,
                "average_real_dielectric": real_d_average,
                "bandgap": bandgap,
                "nkpoints": nkpoints,
                "task_id": task_id,
            },
            **kwargs,
        )