-
Notifications
You must be signed in to change notification settings - Fork 0
/
lwann
executable file
·132 lines (111 loc) · 4.84 KB
/
lwann
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
#! /usr/bin/env python3
import sys
import os
import logging
import argparse
import numpy as np
import scipy.optimize
from structure.inout import h5output
from structure.wannier import Wannier90Calculation
from structure.wannier import wannier90hamiltonian # wannier90 hk file
from structure.wannier import hamiltonian_matrix # hk in matrix form
'''
lwann : Pre-processing of Wannier90 calculations
'''
def parse_args(args=None):
parser = argparse.ArgumentParser(
description='Argument parser for Wannier90 pre-processing of LRTC',
epilog="That's the end of the help")
parser.add_argument('system', help='Folder of Wannier90 calculation')
parser.add_argument('-c', '--charge', type=float, help='Number of electrons in the provided bands. If not provided determine it.')
parser.add_argument('-o', '--output', help='Outputname of hdf5 (default="lrtc-wann.hdf5")', default='lrtc-wann.hdf5')
parser.add_argument('--soc', help='Wannier90 calculation includes spin-orbit coupling. Necessary only for spin unpolarized calculations.', default=False, action='store_true')
group = parser.add_mutually_exclusive_group(required=False)
group.add_argument('--kmesh', nargs=3, help='Custom reducible momentum grid - must conform symmetries (8x8x5 -> 20x20x5)')
group.add_argument('--wien2k', help='Use Wien2K k grid instead (case.struct, case.klist must be present in Wannier90 folder)', default=False, action='store_true')
parser.add_argument('--nocorrection', help='Do not calculate the correction terms to the Peierls approximation', default=False, action='store_true')
parser.add_argument('--intraonly', help='Only output intra elements', default=False, action='store_true')
parser.add_argument('--debug', help=argparse.SUPPRESS, default=False, action='store_true')
return parser.parse_args(args)
class log_formatter(logging.Formatter):
def format(self, record):
if record.levelname == 'INFO':
return record.msg # so it looks like print
else:
return '{}: {}: {}'.format(record.filename, record.levelname,record.msg) # more information
def main():
error = lambda string: sys.exit('lwann: {}'.format(string))
args = parse_args()
debug = args.debug
''' define logging '''
logger = logging.getLogger()
logger.setLevel(logging.DEBUG if debug else logging.INFO)
console = logging.StreamHandler()
console.setFormatter(log_formatter())
console.setLevel(logging.DEBUG if debug else logging.INFO)
logger.addHandler(console)
if os.path.isfile(args.system):
try:
ham = wannier90hamiltonian(hk_file=args.system, charge=args.charge)
h5output(args.output, ham, ham, peierls=True)
except Exception as e:
error(str(e)+"\nExit.")
else:
try:
ham = Wannier90Calculation(args.system, args.charge, args.soc)
ham.readData()
if args.kmesh:
ham.expandKmesh(np.array(args.kmesh, dtype=int))
elif args.wien2k:
ham.readWien2k()
ham.computeHamiltonian(peierlscorrection = not args.nocorrection)
if args.charge:
ham.outputData(args.output, intraonly=args.intraonly)
else:
ham.outputData(args.output, mu=ham.efer, intraonly=args.intraonly)
except Exception as e:
error(str(e)+"\nExit.")
sys.exit(0)
# INTERFACE WITH hamiltonian arrays
if False:
hk = np.zeroes((8000,3,3), dtype=np.float64)
vk = np.zeroes((8000,3,3,3), dtype=np.float64)
ck = np.zeroes((8000,3,3,6), dtype=np.float64)
ham = hamiltonian_matrix(hk, vk, ck, charge=1)
fname = 'SVO.hdf5'
ham.outputData(fname)
plot = False
if plot:
try:
logging.getLogger("matplotlib").setLevel(logging.WARNING)
import matplotlib.pyplot as plt
except ImportError:
error('Debug option requires matplotlib library')
for iband in range(ham.energyBandMax):
plt.plot(ham.energies[0][:,iband], label='band {}'.format(iband+1), lw=2)
mean = np.mean(ham.energies[0][:,iband])
plt.axhline(ham.mu, label='mu_ham = {:.3f}'.format(ham.mu), color='black', lw=1, ls='--')
plt.xlabel(r'$k_i$')
plt.ylabel(r'$\varepsilon(k_i)$')
plt.legend(loc='best')
plt.show()
if plot:
ham.calcDOS(gamma=0.03, npoints=10000, windowsize=1.5)
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax2 = ax1.twinx()
for ispin in range(ham.spins):
ax1.plot(ham.dosaxis, ham.dos[ispin], label='dos', color='blue', lw=2)
ax2.plot(ham.dosaxis, ham.nos[ispin], label='nos', color='red', lw=2)
ax1.axvline(x=ham.mu, color='black', lw=1, ls='-')
ax1.set_ylim(ymin=0)
ax1.set_ylabel(r'$\mathrm{dos}$')
ax1.set_xlabel(r'$\mu$ [eV]')
ax1.legend(loc='center left')
ax2.axhline(y=ham.charge, color='black', lw=1, ls='-')
ax2.set_ylim(ymin=0)
ax2.set_ylabel(r'$\mathrm{nos}$')
ax2.legend(loc='center right')
plt.show()
if __name__ == '__main__':
main()