dos.py 3.03 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Copyright 2018 Markus Scheidgen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an"AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from .normalizer import Normalizer
16
import numpy as np
17

18
19
from nomad_dos_fingerprints import DOSFingerprint
import json
20
21
22
23

class DosNormalizer(Normalizer):

    def normalize(self, logger=None) -> None:
24

25
26
27
        if logger is not None:
            self.logger = logger.bind(normalizer=self.__class__.__name__)

28
29
30
31
        # Do nothing if section_run is not present
        if self.section_run is None:
            return

32
        # 'scc': single_configuration_calculation
33
34
35
        section_sccs = self.section_run.section_single_configuration_calculation
        if section_sccs is None:
            return
36

37
38
39
40
        for scc in section_sccs:
            section_dos = scc.section_dos
            if section_dos is None:
                continue
41

42
43
44
45
            for dos in section_dos:
                dos_values = dos.dos_values
                if dos_values is None:
                    # section dos without dos_values
46
                    continue
47

48
49
                system = scc.single_configuration_calculation_to_system_ref
                if system is None:
50
                    self.logger.error('referenced system for dos calculation could not be found')
51
52
53
54
55
56
                    continue

                atom_positions = system.atom_positions
                lattice_vectors = system.lattice_vectors
                if atom_positions is None:
                    self.logger.error('required quantity atom_positions is not available')
57
                    return
58
59
                if lattice_vectors is None:
                    self.logger.error('required quantity lattice_vectors is not available')
60
                    return
61

62
                number_of_atoms = np.shape(atom_positions)[0]
63
                unit_cell_volume = np.linalg.det(lattice_vectors.magnitude)
64

65
                # Final quantities
66
                dos_normed = dos_values / (number_of_atoms * unit_cell_volume)
67
68
69
70
71
                
                # Data for DOS fingerprint
                dos_energies = dos.dos_energies
                print(type(dos_energies))
                dos_fingerprint = json.dumps(DOSFingerprint().calculate(np.array(dos_energies), dos_normed).to_dict())
72

73
                # Add quantities to NOMAD's Metainfo
74
                scc_url = '/section_run/0/section_single_configuration_calculation/%d/section_dos/0' % scc.m_parent_index
75
                self._backend.openContext(scc_url)
76
                dos.dos_values_normalized = dos_normed
77
                dos.dos_fingerprint = dos_fingerprint
78
                self._backend.closeContext(scc_url)