From b325028efd08832e81aa053969fde3a23e9d21fb Mon Sep 17 00:00:00 2001 From: Oleg Peil Date: Mon, 2 Mar 2015 21:43:46 +0100 Subject: [PATCH] Fixed the calculation of 'nelect' In the previous commit the calculation of 'nelect' was implemented incorrectly. The sum over k-points must also contain k-weights and a spin factor (2.0 for ns = 1). The calculation of 'nelect' is now implemented as a separate method of ProjectorGroup. --- python/converters/vasp/python/plotools.py | 29 ++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/python/converters/vasp/python/plotools.py b/python/converters/vasp/python/plotools.py index 7273cf4b..1593c9ca 100644 --- a/python/converters/vasp/python/plotools.py +++ b/python/converters/vasp/python/plotools.py @@ -166,18 +166,30 @@ class ProjectorGroup: self.nb_min = nb_min self.nb_max = nb_max -# Determine the total number of electrons within the window - self.nelect = 0 - nk, ns_band, _ = ib_win.shape - for isp in xrange(ns_band): - for ik in xrange(nk): - self.nelect += ferw[isp, ik, self.nb_min:self.nb_max+1].sum() - # Select projectors within the energy window for ish in self.ishells: shell = self.shells[ish] shell.select_projectors(ib_win, nb_min, nb_max) +################################################################################ +# +# nelect_window +# +################################################################################ + def nelect_window(self, el_struct): + """ + Determines the total number of electrons within the window. + """ + self.nelect = 0 + nk, ns_band, _ = self.ib_win.shape + rspin = 2.0 if ns_band == 1 else 1.0 + for isp in xrange(ns_band): + for ik in xrange(nk): + occ = el_struct.ferw[isp, ik, self.nb_min:self.nb_max+1] + kwght = el_struct.kmesh['kweights'][ik] + self.nelect += occ.sum() * kwght * rspin + + return self.nelect ################################################################################ # @@ -423,7 +435,8 @@ def plo_output(conf_pars, pshells, pgroups, el_struct): f.write("# Energy window: emin, emax\n") f.write("%i %i\n"%(gr.emin, gr.emax)) f.write("# Number of electrons within the window\n") - f.write("%s\n"%(gr.nelect)) + nelect = gr.nelect_window(el_struct) + f.write("%s\n"%(round(nelect, 5))) f.write("# Eigenvalues: is, ik, ib1, ib2 then list of values\n") nk, ns_band, _ = gr.ib_win.shape