-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathtest_espresso_new.py
More file actions
161 lines (139 loc) · 4.41 KB
/
Copy pathtest_espresso_new.py
File metadata and controls
161 lines (139 loc) · 4.41 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
"""
Tests for QE DFT calculations using the explicit interface.
"""
# pylint: disable=redefined-outer-name,unused-argument,protected-access
import os
import shutil
import tempfile
import numpy as np
import pytest
import z2pack
@pytest.fixture
def qe_system_new(sample):
"""
Create QE system with explicit interface.
"""
def inner(build_dir, num_wcc=None):
sample_dir = sample("espresso_new")
shutil.copytree(os.path.join(sample_dir, "scf"), os.path.join(build_dir, "scf"))
input_files = [
os.path.join(sample_dir, "input/") + name
for name in ["bi.nscf.in", "bi.pw2wan.in", "bi.win"]
]
qedir = "/home/greschd/software/qe-6.0/bin/"
wandir = "/home/greschd/software/wannier90-2.1.0"
mpirun = "mpirun -np 4 "
pwcmd = mpirun + qedir + "/pw.x "
pw2wancmd = mpirun + qedir + "/pw2wannier90.x "
wancmd = wandir + "/wannier90.x"
z2cmd = (
wancmd
+ " bi -pp;"
+ pwcmd
+ "< bi.nscf.in >& pw.log;"
+ pw2wancmd
+ "< bi.pw2wan.in >& pw2wan.log;"
)
return z2pack.fp.System(
input_files=input_files,
kpt_fct=[z2pack.fp.kpoint.qe_explicit, z2pack.fp.kpoint.wannier90_full],
kpt_path=["bi.nscf.in", "bi.win"],
command=z2cmd,
executable="/bin/bash",
mmn_path="bi.mmn",
build_folder=build_dir + "/build",
num_wcc=num_wcc,
)
return inner
SURFACE_FCTS = [
lambda s, t: [0, s / 2, t],
lambda s, t: [t, s, s],
lambda s, t: [t, t, s / 2],
z2pack.shape.Sphere(center=(0.1, 0.2, 0.3), radius=0.1),
]
@pytest.mark.qe
@pytest.mark.parametrize("surface_fct", SURFACE_FCTS)
def test_bismuth(qe_system_new, compare_wcc, surface_fct):
"""
Test bismuth with explicit QE interface.
"""
# don't want to remove it if the test failed
build_dir = tempfile.mkdtemp()
system = qe_system_new(build_dir)
save_file = os.path.join(build_dir, "result.json")
result = z2pack.surface.run(
system=system,
surface=surface_fct,
num_lines=4,
save_file=save_file,
pos_tol=None,
gap_tol=None,
move_tol=None,
)
compare_wcc(result.wcc)
res2 = z2pack.io.load(save_file)
assert np.isclose(result.wcc, res2.wcc).all()
shutil.rmtree(build_dir)
@pytest.mark.qe
@pytest.mark.parametrize("surface_fct", [SURFACE_FCTS[0]])
def test_bismuth_wrong_num_wcc(qe_system_new, compare_wcc, surface_fct):
"""
Test that bismuth run raises if the wrong num_wcc is set.
"""
# don't want to remove it if the test failed
build_dir = tempfile.mkdtemp()
system = qe_system_new(build_dir, num_wcc=12)
with pytest.raises(ValueError):
z2pack.surface.run(
system=system,
surface=surface_fct,
num_lines=4,
save_file=os.path.join(build_dir, "result"),
pos_tol=None,
gap_tol=None,
move_tol=None,
)
@pytest.mark.qe
@pytest.mark.parametrize("surface_fct", [SURFACE_FCTS[0]])
def test_bismuth_correct_num_wcc(qe_system_new, compare_wcc, surface_fct):
"""
Test bismuth run with correct num_wcc set.
"""
# don't want to remove it if the test failed
build_dir = tempfile.mkdtemp()
system = qe_system_new(build_dir, num_wcc=10)
save_file = os.path.join(build_dir, "result.json")
result = z2pack.surface.run(
system=system,
surface=surface_fct,
num_lines=4,
save_file=save_file,
pos_tol=None,
gap_tol=None,
move_tol=None,
)
compare_wcc(result.wcc)
res2 = z2pack.io.load(save_file)
assert np.isclose(result.wcc, res2.wcc).all()
shutil.rmtree(build_dir)
def test_broken(qe_system_new):
"""
Test that restart does not work when the fp.System is broken.
"""
surface_fct = lambda s, t: [0, s, t]
build_dir = tempfile.mkdtemp()
system = qe_system_new(build_dir)
save_file = os.path.join(build_dir, "result.json")
# breaking the system
system._executable = "echo foo"
with pytest.raises(FileNotFoundError):
z2pack.surface.run(
system=system,
surface=surface_fct,
num_lines=3,
save_file=save_file,
pos_tol=None,
gap_tol=None,
move_tol=None,
)
shutil.rmtree(build_dir)