-
Notifications
You must be signed in to change notification settings - Fork 1
/
write_sh.py
165 lines (160 loc) · 6.29 KB
/
write_sh.py
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
import os
import math
def good_proc(nproc, ncore):
if ncore == 24:
if nproc == 5:
nproc = 4
elif nproc == 7:
nproc = 6
elif 8 < nproc < 12:
nproc = 8
elif 12 < nproc < 24:
nproc = 12
else: # ncore == 40
if nproc == 3:
nproc = 2
elif 5 < nproc < 8:
nproc = 5
elif nproc == 9:
nproc = 8
elif 10 < nproc < 20:
nproc = 10
elif 20 < nproc < 40:
nproc = 20
return nproc
def write_sh(nks, nkd, nk_path, atom, prefix, atomwfc_dict, queue):
pw = "~/program/QE/qe-6.2.1/bin/pw.x"
proj = "~/program/QE/qe-6.2.1/bin/projwfc.x"
vf = "~/program/QE/qe-6.2.1/bin/fermi_velocity.x"
bands = "~/program/QE/qe-6.2.1/bin/bands.x"
sumpdos = "~/program/QE/qe-6.2.1/bin/sumpdos.x"
fproj = "~/program/QE/qe-6.2.1/bin/fermi_proj.x"
typ = set(atom)
#
if queue == "F4cpus":
maxnode = 4
ncore = 24
elif queue == "F4cpue":
maxnode = 4
ncore = 40
elif queue == "F36cpus":
maxnode = 36
ncore = 24
elif queue == "F9cpue":
maxnode = 9
ncore = 40
elif queue == "F36cpue":
maxnode = 36
ncore = 40
else: # queue == "F144cpus":
maxnode = 144
ncore = 24
#
# Structure optimization
#
nk = min(ncore*maxnode, nks)
ntg = good_proc(int(ncore*maxnode / nk), ncore)
nproc = nk*ntg
node = math.ceil(nproc / ncore)
if not os.path.isfile("rx.sh"):
with open("rx.sh", 'w') as f:
print("#!/bin/sh", file=f)
print("#QSUB -queue", queue[0:len(queue) - 1], file=f)
print("#QSUB -node", node, file=f)
print("#PBS -l walltime=8:00:00", file=f)
print("source ~/.bashrc", file=f)
print("cd $PBS_O_WORKDIR", file=f)
print("mpijob -n %d %s -nk %d -ntg %d -in rx.in > rx_s.out"
% (nproc, pw, nk, ntg), file=f)
print("sed -n -e '/occupations/c occupations=\"tetrahedra_opt\"' -e '1,/CELL_PARAMETERS/p' rx.in > rx_t.in",
file=f)
print("grep -A 3 CELL_PARAMETERS rx_s.out | tail -n 3 >> rx_t.in", file=f)
print("awk '/ATOMIC_SPECIES/,/ATOMIC_POSITIONS/' rx.in >> rx_t.in", file=f)
print("grep -A %d ATOMIC_POSITIONS rx_s.out |tail -n %d >> rx_t.in" % (len(atom), len(atom)), file=f)
print("sed -n -e '/K_POINTS/,$p' rx.in >> rx_t.in", file=f)
print("sed -i -e '/occupations/c occupations=\"tetrahedra_opt\"' rx_t.in", file=f)
print("mpijob -n %d %s -nk %d -ntg %d -in rx_t.in > rx_t.out"
% (nproc, pw, nk, ntg), file=f)
#
# Charge optimization
#
if not os.path.isfile("scf.sh"):
with open("scf.sh", 'w') as f:
print("#!/bin/sh", file=f)
print("#QSUB -queue", queue[0:len(queue) - 1], file=f)
print("#QSUB -node", node, file=f)
print("#PBS -l walltime=8:00:00", file=f)
print("source ~/.bashrc", file=f)
print("cd $PBS_O_WORKDIR", file=f)
print("mpijob -n %d %s -nk %d -ntg %d -in scf.in > scf.out"
% (nproc, pw, nk, ntg), file=f)
#
# Projected DOS
#
nk = min(ncore*maxnode, nkd)
ntg = good_proc(int(ncore*maxnode / nk), ncore)
nproc = nk * ntg
node = math.ceil(nproc / ncore)
#
# Atomwfc dictionary for fermi_proj.x
#
pfermi = {ityp: [[] for il in range(len(atomwfc_dict[ityp][0]))] for ityp in typ}
ii = 0
for iat in atom:
for il in range(len(atomwfc_dict[iat][0])):
for im in range(atomwfc_dict[iat][0][il]):
ii += 1
pfermi[iat][il].append(ii)
#
if not os.path.isfile("proj.sh"):
with open("proj.sh", 'w') as f:
print("#!/bin/sh", file=f)
print("#QSUB -queue", queue[0:len(queue) - 1], file=f)
print("#QSUB -node", node, file=f)
print("#PBS -l walltime=8:00:00", file=f)
print("source ~/.bashrc", file=f)
print("cd $PBS_O_WORKDIR", file=f)
print("mpijob -n %d %s -nk %d -ntg %d -in nscf.in > nscf.out"
% (nproc, pw, nk, ntg), file=f)
print("mpijob -n 1 %s -in nscf.in > vfermi.out" % vf, file=f)
print("ef=`grep Fermi nscf.out| awk '{print $5}'`", file=f)
print("sed -i -e '/emin/c emin = '${ef}'' -e '/emax/c emax = '${ef}'' proj.in", file=f)
print("mpijob -n %d %s -nk %d -ntg %d -in proj.in > proj.out"
% (nproc, proj, nk, ntg), file=f)
#
# Sum PDOS at each Atom and L
#
for ityp in typ:
for il in range(len(atomwfc_dict[ityp][1])):
print("%s %s.pdos_atm*\\(%s\\)_wfc#%d* > %s.pdos_%s%s"
% (sumpdos, prefix, ityp, il+1, prefix, ityp, atomwfc_dict[ityp][1][il]), file=f)
#
# Fermi surface with atomic projection
#
for ityp in typ:
for il in range(len(atomwfc_dict[ityp][1])):
print("sed -e '$a %d\\n" % len(pfermi[ityp][il]), end="", file=f)
for ii in pfermi[ityp][il]:
print(" %d" % ii, end="", file=f)
print("' proj.in > proj_f.in", file=f)
print("mpijob -n 1 %s -in proj_f.in" % fproj, file=f)
print("mv proj.frmsf %s%s.frmsf" % (ityp, atomwfc_dict[ityp][1][il]), file=f)
#
# Band
#
nk = min(ncore*maxnode, nk_path)
ntg = good_proc(int(ncore*maxnode / nk), ncore)
nproc = nk * ntg
node = math.ceil(nproc / ncore)
if not os.path.isfile("band.sh"):
with open("band.sh", 'w') as f:
print("#!/bin/sh", file=f)
print("#QSUB -queue", queue[0:len(queue) - 1], file=f)
print("#QSUB -node", node, file=f)
print("#PBS -l walltime=8:00:00", file=f)
print("source ~/.bashrc", file=f)
print("cd $PBS_O_WORKDIR", file=f)
print("mpijob -n %d %s -nk %d -ntg %d -in band.in > band.out"
% (nproc, pw, nk, ntg), file=f)
print("mpijob -n %d %s -nk %d -ntg %d -in bands.in > bands.out"
% (nproc, bands, nk_path, ntg), file=f)