conftest.py 7.47 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 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.

import pytest

17
18
from ase import Atoms

19
20
from nomad.parsing.legacy import Backend
from nomad.datamodel import EntryArchive
21
22
23
24
25
26
from nomad.normalizing import normalizers

from tests.test_parsing import parsed_vasp_example  # pylint: disable=unused-import
from tests.test_parsing import parsed_template_example  # pylint: disable=unused-import
from tests.test_parsing import parsed_example  # pylint: disable=unused-import
from tests.test_parsing import parse_file
27
from tests.test_parsing import parsed_template_no_system  # pylint: disable=unused-import
28
29


30
def run_normalize(backend: Backend) -> Backend:
31
32
33
34
35
36
37
38
39
40
41
    status, _ = backend.status

    assert status == 'ParseSuccess'

    for normalizer_class in normalizers:
        normalizer = normalizer_class(backend)
        normalizer.normalize()
    return backend


@pytest.fixture
42
43
def normalized_vasp_example(parsed_vasp_example: Backend) -> EntryArchive:
    return run_normalize(parsed_vasp_example).entry_archive
44
45
46


@pytest.fixture
47
48
def normalized_example(parsed_example: Backend) -> EntryArchive:
    return run_normalize(parsed_example).entry_archive
49
50
51


@pytest.fixture
52
53
def normalized_template_example(parsed_template_example) -> EntryArchive:
    return run_normalize(parsed_template_example).entry_archive
54
55


56
def run_normalize_for_structure(atoms: Atoms) -> EntryArchive:
57
58
59
60
61
62
63
64
65
66
    template = parsed_template_no_system()

    # Fill structural information
    gid = template.openSection("section_system")
    template.addArrayValues("atom_positions", atoms.get_positions() * 1E-10)
    template.addArrayValues("atom_labels", atoms.get_chemical_symbols())
    template.addArrayValues("simulation_cell", atoms.get_cell() * 1E-10)
    template.addArrayValues("configuration_periodic_dimensions", atoms.get_pbc())
    template.closeSection("section_system", gid)

67
    return run_normalize(template).entry_archive
68
69


Lauri Himanen's avatar
Lauri Himanen committed
70
@pytest.fixture(scope='session')
71
def single_point(two_d) -> EntryArchive:
Lauri Himanen's avatar
Lauri Himanen committed
72
73
74
    return two_d


75
@pytest.fixture(scope='session')
76
def gw(two_d) -> EntryArchive:
77
78
79
80
    parser_name = "parsers/template"
    filepath = "tests/data/normalizers/gw.json"
    backend = parse_file((parser_name, filepath))
    backend = run_normalize(backend)
81
    return backend.entry_archive
82
83


84
@pytest.fixture(scope='session')
85
def geometry_optimization() -> EntryArchive:
86
87
88
89
    parser_name = "parsers/template"
    filepath = "tests/data/normalizers/fcc_crystal_structure.json"
    backend = parse_file((parser_name, filepath))
    backend = run_normalize(backend)
90
    return backend.entry_archive
91
92


93
@pytest.fixture(scope='session')
94
def molecular_dynamics(bulk) -> EntryArchive:
95
    return bulk
96
97


98
@pytest.fixture(scope='session')
99
def phonon() -> EntryArchive:
100
    parser_name = "parsers/phonopy"
101
    filepath = "tests/data/parsers/phonopy/phonopy-FHI-aims-displacement-01/control.in"
102
103
    backend = parse_file((parser_name, filepath))
    backend = run_normalize(backend)
104
    return backend.entry_archive
Lauri Himanen's avatar
Lauri Himanen committed
105
106


107
@pytest.fixture(scope='session')
108
def bulk() -> EntryArchive:
109
110
    parser_name = "parsers/cp2k"
    filepath = "tests/data/normalizers/cp2k_bulk_md/si_md.out"
111
112
    backend = parse_file((parser_name, filepath))
    backend = run_normalize(backend)
113
    return backend.entry_archive
114
115
116


@pytest.fixture(scope='session')
117
def two_d() -> EntryArchive:
Lauri Himanen's avatar
Lauri Himanen committed
118
    parser_name = "parsers/fhi-aims"
119
    filepath = "tests/data/normalizers/fhiaims_2d_singlepoint/aims.out"
Lauri Himanen's avatar
Lauri Himanen committed
120
121
    backend = parse_file((parser_name, filepath))
    backend = run_normalize(backend)
122
    return backend.entry_archive
Lauri Himanen's avatar
Lauri Himanen committed
123
124
125


@pytest.fixture(scope='session')
126
def surface() -> EntryArchive:
Lauri Himanen's avatar
Lauri Himanen committed
127
    parser_name = "parsers/fhi-aims"
128
129
130
    filepath = "tests/data/normalizers/fhiaims_surface_singlepoint/PBE-light+tight-rho2.out"
    backend = parse_file((parser_name, filepath))
    backend = run_normalize(backend)
131
    return backend.entry_archive
132
133
134


@pytest.fixture(scope='session')
135
def molecule() -> EntryArchive:
136
137
138
139
    parser_name = "parsers/fhi-aims"
    filepath = "tests/data/normalizers/fhiaims_molecule_singlepoint/aims.out"
    backend = parse_file((parser_name, filepath))
    backend = run_normalize(backend)
140
    return backend.entry_archive
141
142
143


@pytest.fixture(scope='session')
144
def atom() -> EntryArchive:
145
146
147
148
    parser_name = "parsers/gaussian"
    filepath = "tests/data/normalizers/gaussian_atom_singlepoint/m9b7.out"
    backend = parse_file((parser_name, filepath))
    backend = run_normalize(backend)
149
    return backend.entry_archive
150
151
152


@pytest.fixture(scope='session')
153
def one_d() -> EntryArchive:
154
155
    parser_name = "parsers/exciting"
    filepath = "tests/data/normalizers/exciting_1d_singlepoint/INFO.OUT"
Lauri Himanen's avatar
Lauri Himanen committed
156
157
    backend = parse_file((parser_name, filepath))
    backend = run_normalize(backend)
158
    return backend.entry_archive
159
160
161


@pytest.fixture(scope='session')
162
def bands_unpolarized_gap_indirect() -> EntryArchive:
163
    parser_name = "parsers/vasp"
164
    filepath = "tests/data/normalizers/band_structure/unpolarized_gap/vasprun.xml.bands.xz"
165
166
    backend = parse_file((parser_name, filepath))
    backend = run_normalize(backend)
167
    return backend.entry_archive
168
169
170


@pytest.fixture(scope='session')
171
def bands_polarized_no_gap() -> EntryArchive:
172
    parser_name = "parsers/vasp"
173
    filepath = "tests/data/normalizers/band_structure/polarized_no_gap/vasprun.xml.bands.xz"
174
175
    backend = parse_file((parser_name, filepath))
    backend = run_normalize(backend)
176
    return backend.entry_archive
177
178
179


@pytest.fixture(scope='session')
180
def bands_unpolarized_no_gap() -> EntryArchive:
181
    parser_name = "parsers/vasp"
182
    filepath = "tests/data/normalizers/band_structure/unpolarized_no_gap/vasprun.xml.bands.xz"
183
184
    backend = parse_file((parser_name, filepath))
    backend = run_normalize(backend)
185
    return backend.entry_archive
186
187
188


@pytest.fixture(scope='session')
189
def bands_polarized_gap_indirect() -> EntryArchive:
190
    parser_name = "parsers/vasp"
191
    filepath = "tests/data/normalizers/band_structure/polarized_gap/vasprun.xml.bands.xz"
192
193
    backend = parse_file((parser_name, filepath))
    backend = run_normalize(backend)
194
    return backend.entry_archive
195
196
197


@pytest.fixture(scope='session')
198
def dos_polarized_vasp() -> EntryArchive:
199
200
201
202
    parser_name = "parsers/vasp"
    filepath = "tests/data/normalizers/dos/polarized_vasp/vasprun.xml.relax2.xz"
    backend = parse_file((parser_name, filepath))
    backend = run_normalize(backend)
203
    return backend.entry_archive
204
205
206


@pytest.fixture(scope='session')
207
def dos_unpolarized_vasp() -> EntryArchive:
208
209
210
211
    parser_name = "parsers/vasp"
    filepath = "tests/data/normalizers/dos/unpolarized_vasp/vasprun.xml.xz"
    backend = parse_file((parser_name, filepath))
    backend = run_normalize(backend)
212
    return backend.entry_archive
213
214
215


@pytest.fixture(scope='session')
216
def hash_exciting() -> EntryArchive:
217
218
219
220
    parser_name = "parsers/exciting"
    filepath = "tests/data/normalizers/hashes/exciting/INFO.OUT"
    backend = parse_file((parser_name, filepath))
    backend = run_normalize(backend)
221
    return backend.entry_archive
222
223
224


@pytest.fixture(scope='session')
225
def hash_vasp(bands_unpolarized_gap_indirect) -> EntryArchive:
226
    return bands_unpolarized_gap_indirect