Commit d35be7b3 authored by Pardini, Lorenzo (lopa)'s avatar Pardini, Lorenzo (lopa)
Browse files

added GW bandstructure

parent 87cdec0b
import xml.sax
import logging
import numpy as np
from nomadcore.unit_conversion import unit_conversion
class BandHandler(xml.sax.handler.ContentHandler):
def __init__(self, backend, spinTreat):
......@@ -34,7 +35,8 @@ class BandHandler(xml.sax.handler.ContentHandler):
self.energy.append([])
self.distance.append([])
elif name == "point" and self.inBand:
self.energy[-1].append(float(attrs.getValue('eval')))
fromH = unit_conversion.convert_unit_function("hartree", "J")
self.energy[-1].append(fromH(float(attrs.getValue('eval'))))
self.distance[-1].append(float(attrs.getValue('distance')))
elif name == "vertex" and self.inBand:
self.vertexCoord.append(attrs.getValue("coord"))
......
from builtins import object
import setup_paths
import xml.sax
from nomadcore.simple_parser import mainFunction, CachingLevel
from nomadcore.simple_parser import SimpleMatcher as SM
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
from nomadcore.unit_conversion import unit_conversion
import os, sys, json
################################################################
# This is the subparser for the WIEN2k input file (.in2)
################################################################
......@@ -18,6 +18,8 @@ class GWContext(object):
def __init__(self):
self.parser = None
self.spinTreat = None
self.vertexDist = []
self.vertexLabels = []
def initialize_values(self):
"""allows to reset values if the same superContext is used to parse different files"""
......@@ -34,7 +36,34 @@ class GWContext(object):
dirPath = os.path.dirname(self.parser.fIn.name)
eigvalGWFile = os.path.join(dirPath, "EVALQP.DAT")
dosGWFile = os.path.join(dirPath, "TDOS-QP.OUT")
bandGWFile = os.path.join(dirPath, "bandstructure-qp.dat")
vertexGWFile = os.path.join(dirPath, "BANDLINES.OUT")
vertexLabGWFile = os.path.join(dirPath, "bandstructure.xml")
if os.path.exists(vertexGWFile):
with open(vertexGWFile) as g:
while 1:
s = g.readline()
if not s: break
s = s.strip()
s = s.split()
if len(s) > 0:
if not self.vertexDist:
self.vertexDist.append(float(s[0]))
elif float(s[0]) != self.vertexDist[-1]:
self.vertexDist.append(float(s[0]))
if os.path.exists(vertexLabGWFile):
with open(vertexLabGWFile) as g:
while 1:
s = g.readline()
if not s: break
s = s.strip()
s = s.split()
if s[0] == "<vertex":
f = s[4].split("\"")
self.vertexLabels.append(f[1])
if os.path.exists(eigvalGWFile):
eigvalGWGIndex = backend.openSection("x_exciting_section_GW_qp_eigenvalues")
with open(eigvalGWFile) as g:
......@@ -88,6 +117,7 @@ class GWContext(object):
backend.closeSection("x_exciting_section_GW_self_energy",selfGWGIndex)
####################DOS######################
if os.path.exists(dosGWFile):
dosGWGIndex = backend.openSection("x_exciting_section_GW_dos")
with open(dosGWFile) as g:
......@@ -110,6 +140,105 @@ class GWContext(object):
backend.addValue("x_exciting_GW_number_of_dos_values", len(dosEnergies))
backend.closeSection("x_exciting_section_GW_dos",dosGWGIndex)
##################BANDSTRUCTURE#####################
if os.path.exists(bandGWFile):
bandGWGIndex = backend.openSection("x_exciting_section_GW_k_band")
bandGWSegmGIndex = backend.openSection("x_exciting_section_GW_k_band_segment")
fromH = unit_conversion.convert_unit_function("hartree", "J")
with open(bandGWFile) as g:
bandEnergies = [[],[]]
kpoint = []
dist = []
Kindex = [0]
segmK = []
segmLength = []
bandEnergiesSegm = []
bandGWBE = []
while 1:
s = g.readline()
if not s: break
s = s.strip()
s = s.split()
if not self.spinTreat:
if len(s) == 0:
for i in range(0,2):
bandEnergies[i].append([])
elif s[0] == "#":
for i in range(0,2):
bandEnergies[i].append([])
numBand = int(s[2])
numK = int(s[3])
elif len(s) > 0:
for i in range(0,2):
# ene = fromH(float(s[6]))
bandEnergies[i][-1].append(fromH(float(s[6])))
if int(s[0]) == 1:
kpoint.append([])
dist.append(float(s[5]))
kpoint[-1].append([float(s[2]),float(s[3]),float(s[4])])
else:
pass
for i in range(0,2):
bandEnergies[i].pop()
for i in range(1,numK):
# print("i=",i)
# print("dist[i-1]=",dist[i-1])
# print("dist[i]=",dist[i])
if dist[i] == dist[i-1]:
# pass
Kindex.append(i)
Kindex.append(numK)
# del dist[i]
for i in range(0,len(Kindex)-1):
segmK.append(dist[Kindex[i]:Kindex[i+1]])
for i in range(0,len(segmK)):
# print("i=",i)
# print("segmK[i]=",segmK[i])
segmLength.append(len(segmK[i]))
# bandEnergiesSegm.append([])
for i in range(0,2):
bandEnergiesSegm.append([])
for j in range(0,numBand):
bandEnergiesSegm[i].append([])
for k in range (0,len(Kindex)-1):
# print("l=",k)
# print("len(Kindex)=",len(Kindex))
# print("Kindex[l]=",Kindex[k])
# print("bandEnergies[Kindex[k]:Kindex[k+1]]=",bandEnergies[Kindex[k]:Kindex[k+1]])
bandEnergiesSegm[i][j].append(bandEnergies[i][j][Kindex[k]:Kindex[k+1]])
# print("i=",i)
# print("Kindex[i]=",Kindex[i])
# del dist[Kindex[i]]
# print("bandEnergies=",bandEnergies)
# print("self.vertexDist=",self.vertexDist)
# print("dist=",dist)
# print("len(dist)=",len(dist))
# print("segmK=",segmK)
# print("segmLength=",segmLength)
# print("bandEnergiesSegm=",bandEnergiesSegm)
# print("Kindex=",Kindex)
for i in range(0,len(Kindex)-1):
bandGWBE.append([])
for j in range(0,2):
bandGWBE[i].append([])
for k in range(0,segmLength[i]):
bandGWBE[i][j].append([])
for l in range(0,numBand):
bandGWBE[i][j][-1].append(bandEnergiesSegm[j][l][i][k])
# print("bandGWBE=",bandGWBE)
for i in range(0,len(Kindex)-1):
backend.addValue("x_exciting_GW_band_energies", bandGWBE[i])
backend.closeSection("x_exciting_section_GW_k_band_segment",bandGWSegmGIndex)
backend.closeSection("x_exciting_section_GW_k_band",bandGWGIndex)
# backend.closeSection("x_exciting_section_GW_k_band_segment",bandGWSegmGIndex)
def buildGWMatchers():
return SM(
......
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