forked from deepmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
295 lines (253 loc) · 9.67 KB
/
interface.yml
File metadata and controls
295 lines (253 loc) · 9.67 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
name: interface
on:
workflow_dispatch:
jobs:
wannier-interface:
name: "wannier interface — ${{ matrix.name }}"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: basic (LCAO)
script: example_basic.py
prefix: Bi2Se3_basic
basis: lcao
- name: pw (Plane Wave)
script: example_pw.py
prefix: Bi2Se3_pw
basis: pw
- name: advance (LCAO)
script: example_advance.py
prefix: Bi2Se3_advanced
basis: lcao
defaults:
run:
working-directory: interfaces/Wannier90_interface/examples_python
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install abacusw90
run: |
python -m pip install --upgrade pip
pip install -e ..
- name: Confirm no wannier90.x in environment
run: |
if command -v wannier90.x 2>/dev/null; then
echo "::error::wannier90.x found — CI must test WITHOUT external binaries"
exit 1
fi
echo "OK: no wannier90.x (dryrun mode)"
- name: Create mock data & patch script
env:
SCRIPT: ${{ matrix.script }}
PREFIX: ${{ matrix.prefix }}
run: |
python3 << 'PYEOF'
import os, re, textwrap
script = os.environ["SCRIPT"]
prefix = os.environ["PREFIX"]
# ── 1. Patch the example script ────────────────────────
with open(script) as f:
src = f.read()
src = src.replace("DRY_RUN = False", "DRY_RUN = True")
src = re.sub(
r"\s*job\.step0_run_scf\([^)]*\)",
" # [CI:skip] step0_run_scf — no ABACUS in this environment",
src,
flags=re.DOTALL,
)
src = src.replace(
"job.step1_generate_wannier_win()",
"# [CI:skip] step1_generate_wannier_win — no wannier90.x in this environment",
)
with open(script, "w") as f:
f.write(src)
print(f"[patch] {script}")
# ── 2. Create work directories ─────────────────────────
for d in [f"{prefix}/scf", f"{prefix}/wannier"]:
os.makedirs(d, exist_ok=True)
# ── 3. Mock STRU (scf/ + wannier/) ────────────────────
if basis == "pw":
atom_species = (
"ATOMIC_SPECIES\n"
"Bi 208.980 Bi_pbe_fr.upf\n"
"Se 78.960 Bi_pbe_fr.upf\n"
"\n"
)
else:
atom_species = (
"ATOMIC_SPECIES\n"
"Bi 208.980 Bi_pbe_fr.upf Bi_gga_10au_100Ry_2s2p2d.orb\n"
"Se 78.960 Bi_pbe_fr.upf Se_gga_10au_100Ry_2s2p2d.orb\n"
"\n"
)
lattice_block = textwrap.dedent("""\
LATTICE_CONSTANT
1.0
LATTICE_VECTORS
-2.069 -3.583614 0.0
2.069 -3.583614 0.0
0.000 2.389075 9.546667
ATOMIC_POSITIONS
Direct
Bi
0.399 0.399 0.697 1 1 1
0.601 0.601 0.303 1 1 1
Se
0.000 0.000 0.500 1 1 1
0.206 0.206 0.118 1 1 1
0.794 0.794 0.882 1 1 1
""")
stru = atom_species + lattice_block
for d in [f"{prefix}/scf", f"{prefix}/wannier"]:
p = os.path.join(d, "STRU")
with open(p, "w") as f:
f.write(stru)
print(f"[mock] {p}")
# ── 4. Mock wannier90.nnkp ────────────────────────────
nbands = 20
nk = 64 # 4 × 4 × 4
nntot = 14
lines = [
f" {nbands}", "! num_bands",
f" {nk}", "! num_kpts",
" 4 4 4", "! mp_grid",
]
for ix in range(4):
for iy in range(4):
for iz in range(4):
lines.append(f" {ix/4:.15f} {iy/4:.15f} {iz/4:.15f}")
lines.append(f" {nntot}")
lines.append("! nntot")
for ik in range(nk):
lines.append(f" {nntot}")
for ib in range(nntot):
lines.append(f" {(ik + ib) % nk + 1}")
lines.append(f" {nntot}")
for ib in range(nntot):
lines.append(" 0 0 0")
lines += [
f" {nbands}", "! num_exclude_bands",
" 30", "! num_wann",
" 6", "! num_proj",
]
for proj in ["Bi : pz","Bi : px","Bi : py",
"Se : pz","Se : px","Se : py"]:
lines.append(f" {proj}")
nnkp = os.path.join(prefix, "wannier", "wannier90.nnkp")
with open(nnkp, "w") as f:
f.write("\n".join(lines) + "\n")
print(f"[mock] {nnkp} ({len(lines)} lines)")
# ── 5. Mock PP & ORB files ─────────────────────────────
orb_dir = os.path.abspath("../../../tests/PP_ORB/")
os.makedirs(orb_dir, exist_ok=True)
for name in ["Bi_pbe_fr.upf", "Se_pbe_fr.upf", "Bi_gga_10au_100Ry_2s2p2d.orb", "Se_gga_10au_100Ry_2s2p2d.orb"]:
p = os.path.join(orb_dir, name)
with open(p, "w") as f:
f.write("# mock for CI dryrun\n")
print(f"[mock] {p}")
print("\n[done] all mocks ready")
PYEOF
- name: Run ${{ matrix.script }} — dryrun
run: python ${{ matrix.script }} 2>&1 | tee run.log
- name: Check dryrun completion banner
run: |
if grep -q "DRY RUN COMPLETE" run.log; then
echo " [OK] dryrun banner found"
else
echo " [FAIL] 'DRY RUN COMPLETE' not found — script may have crashed"
exit 1
fi
- name: Validate generated files (${{ matrix.name }})
run: |
W="${{ matrix.prefix }}/wannier"
ERR=0
check() {
if [ -f "$1" ]; then
echo " [OK] $1 ($(wc -c < "$1") bytes)"
else
echo " [FAIL] $1 (not found)"
ERR=1
fi
}
echo "=========================================="
echo " NSCF input files (from step2)"
echo "=========================================="
check "$W/INPUT"
check "$W/KPT"
check "$W/STRU"
if [ -f "$W/INPUT" ]; then
echo ""
echo "--- INPUT keyword checks ---"
for key in "calculation" "towannier90" "nspin"; do
if grep -qi "$key" "$W/INPUT"; then
echo " [OK] INPUT contains '$key'"
else
echo " [FAIL] INPUT missing '$key'"
ERR=1
fi
done
if grep -qi "gamma_only" "$W/INPUT"; then
echo " [FAIL] INPUT contains 'gamma_only' — forbidden!"
ERR=1
else
echo " [OK] INPUT does NOT contain 'gamma_only'"
fi
fi
echo ""
echo "--- Basis-specific checks (${{ matrix.basis }}) ---"
if [ "${{ matrix.basis }}" = "pw" ]; then
if grep -qi "orbital_file\|orbital_dir" "$W/INPUT"; then
echo " [FAIL] PW INPUT contains orbital_file/orbital_dir"
ERR=1
else
echo " [OK] PW INPUT does NOT contain orbital_file/orbital_dir"
fi
else
if grep -qi "orbital_file\|orbital_dir" "$W/INPUT"; then
echo " [OK] LCAO INPUT contains orbital_file/orbital_dir"
else
echo " [WARN] LCAO INPUT missing orbital references (may be in STRU)"
fi
fi
if [ -f "$W/KPT" ]; then
echo ""
klines=$(wc -l < "$W/KPT")
if [ "$klines" -gt 5 ]; then
echo " [OK] KPT has $klines lines (reasonable)"
else
echo " [FAIL] KPT too short ($klines lines)"
ERR=1
fi
fi
echo ""
if [ "$ERR" -ne 0 ]; then
echo "=========================================="
echo " VALIDATION FAILED"
echo "=========================================="
exit 1
fi
echo "=========================================="
echo " ALL CHECKS PASSED (${{ matrix.name }})"
echo "=========================================="
- name: Show full script output
if: always()
run: cat run.log
- name: Show generated INPUT
if: always()
run: |
f="${{ matrix.prefix }}/wannier/INPUT"
if [ -f "$f" ]; then echo "=== $f ==="; cat "$f"; else echo "$f not found"; fi
- name: Show generated KPT (first 20 lines)
if: always()
run: |
f="${{ matrix.prefix }}/wannier/KPT"
if [ -f "$f" ]; then echo "=== $f (first 20 lines) ==="; head -20 "$f"; else echo "$f not found"; fi
- name: List all generated files
if: always()
run: find ${{ matrix.prefix }} -type f | sort