Beispiel #1
0
def check_channel(strspin):
    spindict = {'up': 0, 'down': 1}
    try:
        if strspin.lower() in spindict.keys(): return spindict[strspin.lower()]
        else:
            raise err.InputError(
                "Specified spin unknown. Must be either 'up' oder 'down'")
    except:
        raise
        sys.exit()
Beispiel #2
0
def check_yrange(strrange):
    try:
        strrange = str(strrange)
        if not ':' in strrange:
            raise err.InputError(
                "Type of yrange must be min:max with max > min or only :")
        elif strrange == ':':
            ranges = [0, -1]
        else:
            ranges = strrange.split(':')
            ranges = [float(ranges[0]), float(ranges[1])]
            if ranges[0] >= ranges[1]:
                raise err.InputError(
                    "Type of yrange must be min:max with max > min > 0 or only :"
                )
    except:
        raise
        sys.exit()
    else:
        return ranges
Beispiel #3
0
def check_xrange(strrange):
    try:
        strrange = str(strrange)
        if strrange == ':':
            ranges = [0, -1]
        else:
            maxval = float(strrange)
            if maxval <= 0: raise err.InputError("xrange value must be > 0")
            ranges = [-maxval, maxval]
    except:
        raise
        sys.exit()
    else:
        return ranges
    sys.exit()

### load hamiltonian
print("Loading hamiltonian on hk and kpoints on kpoints from file:" + filename)
hk, kpoints = rw.read_hk_wannier(filename, spin=spin)

print("hk.shape", hk.shape)
print("kpoints.shape", kpoints.shape)

### get number of k-points
Nk = kpoints.shape[0]
print("Number of k points: ", Nk)

try:
    if hk.shape[1] < Natoms * Nbands:
        raise err.InputError(
            "Input hkfile does not have spin entries! Please use -s False.")
    if hk.shape[1] > Natoms * Nbands:
        raise err.InputError(
            "Input hkfile does have spin entries! Please use -s True.")
except err.InputError:
    raise
    sys.exit()

#load umatrix
#checking if ufile is spin dependent
print("Loading Umatrix from file:" + ufilename)
ufile = open(ufilename, 'r')
rw.readaline(ufile)
line = rw.readaline(ufile)

try:
Beispiel #5
0
def check_hamiltonian(hamiltonian):
    possibles = ["Density", "Kanamori", "ReadUmatrix", "ReadNormalUmatrix"]
    hamiltonian = str(hamiltonian)
    if hamiltonian not in possibles:
        raise err.InputError("Found not allowed Hamiltonian")
    return hamiltonian
Beispiel #6
0
basetitle = args.basetitle
atoms = set(args.Atoms)
maxatom = max(atoms)
searchpatterns = []
spin = args.Spin
svg = args.svg
maxentdir = args.maxentdir
lambdas = args.Lambdas
ylabels = args.ylabels
xi = args.xi

plotbetas = True
plotlambdas = False

if lambdas != None and args.Betas == None:
    raise err.InputError('Please specify --Betas as well')
    sys.exit()

if lambdas != None and args.Betas != None:
    if len(lambdas) > 1 and len(args.Betas) > 1:
        raise err.InputError(
            'If both Betas and Lambdas are specified one of both must be only one value'
        )
        sys.exit()
    elif len(args.Betas) == 1:
        plotlambdas = True
        plotbetas = False

if args.Betas is not None:
    searchpatterns += [['general.beta', args.Betas]]
for atom in atoms:
hkfile = args.hkfile
Natoms = args.Natoms
Nbands = args.Nbands
hdf5file = args.hdf5file
atoms = args.Atoms
toDIAG = args.toDIAG
rotate_gtau = args.notgtau
rotate_ftau = args.ftau
rotate_giw = args.giw
rotate_siw = args.siw
iteration = args.iteration
Nspins = int(args.spin) + 1

for atom in atoms:
    if atom < 0 or atom > Natoms-1:
        raise err.InputError("Atom list out of range!")
        sys.exit()

if rotate_gtau == False:
    rot_objs = []
else:
    rot_objs = ["gtau"]
if rotate_ftau == True:
    rot_objs.append("ftau")
if rotate_giw == True:
    rot_objs.append("giw")
if rotate_siw == True:
    rot_objs.append("siw")

if Nspins == 2:
    print("Loading spin dependent hamiltonian on hk and kpoints on kpoints.")
Beispiel #8
0
def read_umatrix(filename, spin):
    '''Function to read a umatrix from a .dat file. 2 possible Formats
	   1.: 1 1 1 1 value (spin==False)
	   2.: 1u 1d 1u 1d value (spin==True)
        '''
    try:
        if type(filename) is not str:
            raise TypeError("1. argument (filename) must be of type str")
        if type(spin) is not bool:
            raise TypeError("2. argument (spin) must be of type bool:")
    except TypeError:
        raise
        sys.exit()

    f = open(filename, 'r')
    firstline = readaline(f).split()
    try:
        Nbands = int(firstline[0])
        if firstline[1].lower() != "bands":
            raise err.InputError(
                "Expecting first non comment line to be of the form: # BANDS")
    except err.InputError:
        raise
        sys.exit()

    Nspin = int(spin) + 1
    if spin:
        umatrix = np.zeros((Nbands, 2, Nbands, 2, Nbands, 2, Nbands, 2))
    else:
        umatrix = np.zeros((Nbands, Nbands, Nbands, Nbands))

    spindict = {'u': 0, 'd': 1}
    spininfile = False
    try:
        for line in f:
            splitline = line.split()
            newsplitline = []
            for element in splitline[0:-1]:
                newsplitline.append(list(element))
            splitline = [y for x in newsplitline for y in x] + [splitline[-1]]
            index = np.zeros((Nspin * 4, ), dtype=int)
            for i in range(0, (len(splitline) - 1)):
                element = splitline[i]
                if element in spindict:
                    index[i] = int(spindict[element])
                    spininfile = True
                else:
                    index[i] = int(element) - 1
            umatrix[tuple(index)] = float(splitline[-1])
    except IndexError:
        raise err.InputError(
            "Specifiefied spin dependency does not match ufile spin dependency"
        )
        sys.exit()

    try:
        if spininfile != spin:
            raise err.InputError(
                "Specifiefied spin dependency does not match ufile spin dependency"
            )
    except err.InputError:
        raise
        sys.exit()

    return umatrix
### load hamiltonian
print("Loading hamiltonian on hk and kpoints on kpoints.")
hkfile = file(filename)
hk, kpoints = rw.read_hk_wannier(filename, spin=spin)

print("hk.shape", hk.shape)
print("kpoints.shape", kpoints.shape)

### get number of k-points
Nk = kpoints.shape[0]
print("Number of k points: ", Nk)

try:
    if hk.shape[1] < Natoms * Nbands:
        raise err.InputError(
            "Input hkfile does not have spin entries! Please don't use -s.")
    if hk.shape[1] > Natoms * Nbands:
        raise err.InputError(
            "Input hkfile does have spin entries! Please use -s.")
except err.InputError:
    raise
    sys.exit()

#Building hkmean
print("Building hkmean i.e. averaging over all k points")
hkmean = 1. / Nk * np.sum(hk, axis=0)
print("hkmean.shape", hkmean.shape)

#reshape hkmean
hkmean = hkmean.reshape(Nspins * Nbands * Natoms, Nspins * Nbands * Natoms)
print("hkmean.shape", hkmean.shape)
Beispiel #10
0
#################################################

##########################################################################################
#usage: python giw_trace.py <hdf5 file to use> <number of atom for which the trace should be calculated> <iteration for which to perform trace, default: last>
##########################################################################################
from __future__ import print_function, division, absolute_import
import numpy as np
import h5py
import sys 
sys.path.insert(0,sys.argv[0].replace('/InputOutputManipulators/giw_trace.py','/General'))
import hdf5_stuff as h5s
import custom_errors as err
import readwrite as rw

try:
    if len(sys.argv) < 3: raise err.InputError("Error reading input.", "Not enough arguments found.")
    filename = sys.argv[1]
    at = int(sys.argv[2])
    if at > 999: raise ValueError
    at = "%03i"%at
    if filename[-5:] != ".hdf5": raise err.InputError("Error reading input.", "No hdf5 file found as second argument")
except err.InputError as error:
    print(error.expression)
    print(error.message)
    print("usage: python giw_trace.py <hdf5 file to use> <number of atom for which the trace should be calculated> <iteration for which to perform trace, default: last>")
    sys.exit()
except ValueError:
    print("Error assigning atom number to " + sys.argv[2])
    print("Must be integer smaller 999")
except:
    print("Some unkown error occourd during opening input file")