-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathopti.py
More file actions
44 lines (35 loc) · 1.16 KB
/
opti.py
File metadata and controls
44 lines (35 loc) · 1.16 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
import numpy as np
from scipy.optimize import minimize
from subprocess import call
from termcolor import colored
import glob
prefix = "./inis/"
cnt = 0
def make_cfg(k):
with open(prefix + "example.cfg", "rt") as fin:
with open(prefix + "run.cfg", "wt") as fout:
for line in fin:
out_line = line.replace("%kx%", str(k[0]))
out_line = out_line.replace("%ky%", str(k[1]))
out_line = out_line.replace("%fphi%", str(k[2]))
out_line = out_line.replace("%ftheta%", str(k[3]))
fout.write(out_line)
def get_gap():
E = np.load("output/opti/band_E.npy")
# gap = np.max(E[1,:])
# print colored('max val = {}'.format(gap), 'green')
# return -gap
gap = np.min(E[2,:])
print colored('min val = {}'.format(gap), 'green')
return gap
def f(x):
make_cfg(x)
call(["./stb.x", "inis/run.cfg"])
print "x = {}".format(x)
return get_gap()
bnd =((None, None), #kx
(None, None), #ky
(-np.pi, np.pi),
(0.0, np.pi))
res = minimize(f, [0.1, 0.1, 0.3*np.pi, 0.2*np.pi], options={'disp': True}, bounds=bnd)
print "result: {}".format(res.x)