To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit a09f3bd9 authored by Bastian Telgen's avatar Bastian Telgen
Browse files

ad k path utilitites

parent e3ac211f
import sys
import numpy as np
from k_path_for_lattice import k_path_for
output = sys.argv[2]
first = int(sys.argv[3])
last = int(sys.argv[4])
input = np.loadtxt(
sys.argv[1],
skiprows=1 + first,
max_rows=last,
delimiter=",",
usecols=(4, 5, 6, 7, 8, 9, 10, 11, 12),
ndmin=2,
)
names = np.loadtxt(
sys.argv[1],
skiprows=1 + first,
max_rows=last,
delimiter=",",
usecols=(13),
dtype=str,
ndmin=2,
)
for i in range(last - first):
kpath = k_path_for(np.reshape(input[i, :], (3, 3)))
f = open(output + names[i][0] + ".kpath", "w")
for label, k in zip(kpath[1], kpath[0]):
f.write(str(k[0]) + "," + str(k[1]) + "," + str(k[2]))
if label:
f.write("," + label)
f.write("\n")
f.close()
from pymatgen.core.structure import Structure
from pymatgen.symmetry.bandstructure import HighSymmKpath
import numpy as np
lattice = np.loadtxt('lattice.txt')
# scaling factor to satisfy pymatgen
fac =1
s = Structure(np.nan_to_num(lattice) / fac, [1], [[0, 0, 0]])
print(s)
h = HighSymmKpath(s, symprec=0.001, angle_tolerance=1, atol=1e-06)
kpath = h.get_kpoints(line_density=1)
kpath = ([k / fac for k in kpath[0]], kpath[1]) # back scale
f = open('kpath.txt', 'w')
for label, k in zip(kpath[1], kpath[0]):
f.write(str(k[0]) + "," + str(k[1]) + "," + str(k[2]))
if label:
f.write("," + label)
f.write("\n")
f.close()
def k_path_for(lattice):
from pymatgen.core.structure import Structure
from pymatgen.symmetry.bandstructure import HighSymmKpath
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
import numpy as np
s = Structure(np.nan_to_num(lattice), [1], [[0, 0, 0]])
sa = SpacegroupAnalyzer(s)
ps = sa.get_primitive_standard_structure(international_monoclinic=False)
h = HighSymmKpath(ps, symprec=0.001, angle_tolerance=1, atol=1e-06)
return h.get_kpoints(line_density=20)
\ No newline at end of file
import numpy as np
from matplotlib import pyplot as plt
def plot_dispersion(kpath, eigfreq):
from matplotlib import pyplot as plt
import numpy as np
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
# klabel = np.array(kpath[1])
# idx = np.where(klabel <> u'')[0]
#
il = range(0, len(kpath))
# for i in range(len(idx) - 1):
#
# if idx[i + 1] == idx[i] + 1:
#
# il[idx[i] + 1:] = [l - 1 for l in il[idx[i] + 1:]]
#
# if klabel[idx[i]] <> klabel[idx[i + 1]]:
# klabel[idx[i]] = klabel[idx[i]] + klabel[idx[i + 1]]
# klabel[idx[i + 1]] = klabel[idx[i]]
plt.plot(il, eigfreq)
#for i in [il[j] for j in idx]:
# plt.axvline(x=i, color='black')
plt.xlim(0, np.max(il))
#plt.xticks([il[j] for j in idx], klabel[idx])
plt.show()
name = "cube"
path = "/mnt/io/"
#path = "/home/bastian/Workspace/cppPNCOpt/build/Applications/"
fkpath = path+"data/"+name+'.kpath'
fdpath = path+name+".dispersion"
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
dispersion = np.loadtxt(fdpath,delimiter=',')
with open(fkpath, "r") as f:
kpath = [x.split(",") for x in f.readlines()]
klabel=[]
il=[]
for i, k in enumerate(kpath):
if len(k) > 3:
klabel.append(k[3].rstrip())
il.append(i)
np.set_printoptions(precision=8, edgeitems=50, linewidth=2)
eigfreq = dispersion[:,3:]
kpath = dispersion[:,:3]
#plt.rc('text', usetex=True)
from matplotlib.patches import Rectangle
currentAxis = plt.gca()
i_klabel = []
for i in range(0,len(il),2):
idb = il[i]
idu = il[i+1]
plt.axvline(x=idb - i, color='black', linestyle='--',linewidth=0.8)
plt.plot(range(idb - i, idu - i), eigfreq[range(idb, idu)], color='black',marker=",",linestyle="None")
# plt.gca().set_prop_cycle(None)
i_klabel.append(idb - i)
fu = np.nanmin(eigfreq[idb:idu], axis=0)[1:]
fl = np.nanmax(eigfreq[idb:idu], axis=0)[:-1]
pb= fu-fl
# print pb
#
for j,b in enumerate(pb):
if b>2e-2:
w = idu - idb -1
h = fu[j] - fl[j]
currentAxis.add_patch(Rectangle((idb-i, fl[j]), w, h, alpha=1,color="#98FB98"))
i_klabel.append(idu - i-1)
fu = np.nanmin(eigfreq, axis=0)[1:]
fl = np.nanmax(eigfreq, axis=0)[:-1]
full_bandgap = fu - fl
for j, b in enumerate(full_bandgap):
if b > 2e-2:
w = i_klabel[-1]
h = fu[j] - fl[j]
currentAxis.add_patch(Rectangle((0, fl[j]), w, h, alpha=1, color="#6B8E23"))
# # k-path labelling
klabel2 =[]
double = False
for i in range(len(klabel)-1):
idb = i
idu = i+1
if il[idb] == il[idu]-1:
if klabel[idb] != klabel[idu]:
klabel2.append("$"+klabel[idb]+r"\vert "+klabel[idb+1]+"$")
double = True
else:
if not double:
klabel2.append("$"+klabel[idb]+"$")
else:
double = False
klabel2.append("$"+klabel[idu]+"$")
plt.xticks(i_klabel, klabel2)
plt.xlim(0,len(kpath)-len(klabel))
plt.ylim(0,7000)
# plt.title('dispersion curve')
plt.xlabel('k-space position')
plt.ylabel('frequency $[Hz]$')
plt.savefig("test3.svg")
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment