From e8dff08fcff15a0dddebebcb7f7e391a86d145ab Mon Sep 17 00:00:00 2001 From: "Oleg E. Peil" Date: Fri, 18 Dec 2015 17:45:12 +0100 Subject: [PATCH] Added a possibility to read EFERMI from LOCPROJ Noramlly, the Fermi energy is read from DOSCAR. However, this does not work in case of a self-consistent calculation in which DOSCAR is not written between iterations. One of the options is to modify slightly the output to LOCPROJ and add EFERMI to the first line. --- python/converters/__init__.py | 3 ++- python/converters/plovasp/elstruct.py | 6 +++++- python/converters/plovasp/vaspio.py | 18 ++++++++++++++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/python/converters/__init__.py b/python/converters/__init__.py index 8553e770..fc589b9f 100644 --- a/python/converters/__init__.py +++ b/python/converters/__init__.py @@ -22,7 +22,8 @@ from wien2k_converter import Wien2kConverter from hk_converter import HkConverter +from vasp_converter import VaspConverter -__all__ =['Wien2kConverter','HkConverter'] +__all__ =['Wien2kConverter','HkConverter','VaspConverter'] diff --git a/python/converters/plovasp/elstruct.py b/python/converters/plovasp/elstruct.py index c90c92ee..105212b5 100644 --- a/python/converters/plovasp/elstruct.py +++ b/python/converters/plovasp/elstruct.py @@ -47,7 +47,10 @@ class ElectronicStructure: # Note that one should not subtract this Fermi level from eigenvalues # here because the true Fermi level might be provided by conf-file # (for instance, for spaghetti calculations) - self.efermi = vasp_data.doscar.efermi + try: + self.efermi = vasp_data.doscar.efermi + except AttributeError: + pass # Note that the number of spin-components of projectors might be different from those # of bands in case of non-collinear calculations @@ -74,6 +77,7 @@ class ElectronicStructure: print "eigvals from LOCPROJ" self.eigvals = vasp_data.plocar.eigs self.ferw = vasp_data.plocar.ferw.transpose((2, 0, 1)) + self.efermi = vasp_data.plocar.efermi # For later use it is more convenient to use a different order of indices # [see ProjectorGroup.orthogonalization()] diff --git a/python/converters/plovasp/vaspio.py b/python/converters/plovasp/vaspio.py index 10b4cb4b..d7f6c0e2 100644 --- a/python/converters/plovasp/vaspio.py +++ b/python/converters/plovasp/vaspio.py @@ -40,7 +40,7 @@ class VaspData: """ Container class for all VASP data. """ - def __init__(self, vasp_dir, read_all=True): + def __init__(self, vasp_dir, read_all=True, efermi_required=True): self.vasp_dir = vasp_dir self.plocar = Plocar() @@ -59,8 +59,16 @@ class VaspData: self.eigenval.eigs = None self.eigenval.ferw = None print "!!! WARNING !!!: Error reading from EIGENVAL, trying LOCPROJ" - pass - self.doscar.from_file(vasp_dir) + try: + self.doscar.from_file(vasp_dir) + except (IOError, StopIteration): + if efermi_required: +# raise Exception("Efermi cannot be read from DOSCAR") + pass + else: +# TODO: This a hack. Find out a way to determine ncdij without DOSCAR + print "!!! WARNING !!!: Error reading from DOSCAR, taking Efermi from config" + self.doscar.ncdij = self.plocar.nspin ################################################################################ ################################################################################ @@ -202,7 +210,9 @@ class Plocar: with open(locproj_filename, 'rt') as f: line = f.readline() line = line.split("#")[0] - self.nspin, nk, self.nband, nproj = map(int, line.split()) + sline = line.split() + self.nspin, nk, self.nband, nproj = map(int, sline[:4]) + self.efermi = float(sline[4]) plo = np.zeros((nproj, self.nspin, nk, self.nband), dtype=np.complex128) proj_params = [{} for i in xrange(nproj)]