2015-02-13 21:58:42 +01:00
|
|
|
|
2015-02-19 21:22:51 +01:00
|
|
|
import itertools as it
|
2015-02-13 21:58:42 +01:00
|
|
|
import numpy as np
|
2015-10-22 16:15:49 +02:00
|
|
|
import vasp.atm.c_atm_dos as c_atm_dos
|
2015-02-13 21:58:42 +01:00
|
|
|
|
2015-10-16 18:10:48 +02:00
|
|
|
np.set_printoptions(suppress=True)
|
|
|
|
|
2015-08-10 13:52:29 +02:00
|
|
|
# 'simplejson' is supposed to be faster than 'json' in stdlib.
|
2015-09-21 11:59:04 +02:00
|
|
|
try:
|
|
|
|
import simplejson as json
|
|
|
|
except ImportError:
|
|
|
|
import json
|
2015-08-10 13:52:29 +02:00
|
|
|
|
2015-11-11 12:43:51 +01:00
|
|
|
def issue_warning(message):
|
|
|
|
"""
|
|
|
|
Issues a warning.
|
|
|
|
"""
|
|
|
|
print
|
|
|
|
print " !!! WARNING !!!: " + message
|
|
|
|
print
|
|
|
|
|
2015-02-13 21:58:42 +01:00
|
|
|
class Projector:
|
|
|
|
"""
|
|
|
|
Class describing a local-orbital projector.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, matrix, ib1=1, ib2=None, nion=1):
|
|
|
|
self.p_matrix = matrix.astype(np.complex128)
|
|
|
|
self.norb, self.nb = matrix.shape
|
|
|
|
self.nion = nion
|
|
|
|
self.ib1 = ib1 - 1
|
|
|
|
if not ib2 is None:
|
|
|
|
self.ib2 = ib2 - 1
|
|
|
|
else:
|
|
|
|
self.ib2 = self.nb - 1
|
|
|
|
|
|
|
|
def project_up(self, mat):
|
|
|
|
return np.dot(self.p_matrix.conj().T, np.dot(mat, self.p_matrix))
|
|
|
|
|
|
|
|
def project_down(self, mat):
|
|
|
|
assert mat.shape == (self.nb, self.nb), " Matrix must match projector in size"
|
|
|
|
return np.dot(self.p_matrix, np.dot(mat, self.p_matrix.conj().T))
|
|
|
|
|
|
|
|
def orthogonalize(self):
|
|
|
|
"""
|
|
|
|
Orthogonalizes a projector.
|
|
|
|
Returns an overlap matrix and its eigenvalues for initial projectors.
|
|
|
|
"""
|
|
|
|
self.p_matrix, overlap, over_eig = orthogonalize_projector(self.p_matrix)
|
|
|
|
|
|
|
|
return (overlap, over_eig)
|
|
|
|
|
|
|
|
################################################################################
|
2015-02-17 21:12:57 +01:00
|
|
|
#
|
|
|
|
# orthogonalize_projector_matrix()
|
|
|
|
#
|
2015-02-13 21:58:42 +01:00
|
|
|
################################################################################
|
2015-02-17 21:12:57 +01:00
|
|
|
def orthogonalize_projector_matrix(p_matrix):
|
2015-02-13 21:58:42 +01:00
|
|
|
"""
|
|
|
|
Orthogonalizes a projector defined by a rectangular matrix `p_matrix`.
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
|
|
|
|
p_matrix (numpy.array[complex]) : matrix `Nm x Nb`, where `Nm` is
|
|
|
|
the number of orbitals, `Nb` number of bands
|
|
|
|
|
|
|
|
Returns
|
|
|
|
-------
|
|
|
|
|
|
|
|
Orthogonalized projector matrix, initial overlap matrix and its eigenvalues.
|
|
|
|
"""
|
2015-02-17 21:12:57 +01:00
|
|
|
# Overlap matrix O_{m m'} = \sum_{v} P_{m v} P^{*}_{v m'}
|
2015-02-13 21:58:42 +01:00
|
|
|
overlap = np.dot(p_matrix, p_matrix.conj().T)
|
2015-02-17 21:12:57 +01:00
|
|
|
# Calculate [O^{-1/2}]_{m m'}
|
2015-02-13 21:58:42 +01:00
|
|
|
eig, eigv = np.linalg.eigh(overlap)
|
2015-02-17 21:12:57 +01:00
|
|
|
assert np.all(eig > 0.0), ("Negative eigenvalues of the overlap matrix:"
|
2015-02-13 21:58:42 +01:00
|
|
|
"projectors are ill-defined")
|
|
|
|
sqrt_eig = np.diag(1.0 / np.sqrt(eig))
|
|
|
|
shalf = np.dot(eigv, np.dot(sqrt_eig, eigv.conj().T))
|
2015-02-17 21:12:57 +01:00
|
|
|
# Apply \tilde{P}_{m v} = \sum_{m'} [O^{-1/2}]_{m m'} P_{m' v}
|
2015-02-13 21:58:42 +01:00
|
|
|
p_ortho = np.dot(shalf, p_matrix)
|
|
|
|
|
|
|
|
return (p_ortho, overlap, eig)
|
|
|
|
|
|
|
|
################################################################################
|
2015-03-01 11:42:18 +01:00
|
|
|
# check_data_consistency()
|
2015-02-13 21:58:42 +01:00
|
|
|
################################################################################
|
2015-03-01 11:42:18 +01:00
|
|
|
def check_data_consistency(pars, el_struct):
|
2015-02-13 21:58:42 +01:00
|
|
|
"""
|
|
|
|
Check the consistency of the VASP data.
|
|
|
|
"""
|
2015-09-16 11:40:01 +02:00
|
|
|
# Check that ions inside each shell are of the same sort
|
|
|
|
for sh in pars.shells:
|
2015-10-15 11:44:50 +02:00
|
|
|
assert max(sh['ion_list']) <= el_struct.natom, "Site index in the projected shell exceeds the number of ions in the structure"
|
2015-09-16 11:56:54 +02:00
|
|
|
sorts = set([el_struct.type_of_ion[io] for io in sh['ion_list']])
|
2015-09-16 11:40:01 +02:00
|
|
|
assert len(sorts) == 1, "Each projected shell must contain only ions of the same sort"
|
2015-02-13 21:58:42 +01:00
|
|
|
|
2015-10-14 19:32:12 +02:00
|
|
|
# Check that ion and orbital lists in shells match those of projectors
|
|
|
|
ion_list = sh['ion_list']
|
|
|
|
lshell = sh['lshell']
|
|
|
|
for ion in ion_list:
|
|
|
|
for par in el_struct.proj_params:
|
|
|
|
if par['isite'] - 1 == ion and par['l'] == lshell:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
errmsg = "Projector for isite = %s, l = %s does not match PROJCAR"%(ion + 1, lshell)
|
|
|
|
raise Exception(errmsg)
|
|
|
|
|
|
|
|
|
2015-02-13 21:58:42 +01:00
|
|
|
################################################################################
|
|
|
|
# select_bands()
|
|
|
|
################################################################################
|
|
|
|
def select_bands(eigvals, emin, emax):
|
|
|
|
"""
|
|
|
|
Select a subset of bands lying within a given energy window.
|
|
|
|
The band energies are assumed to be sorted in an ascending order.
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
|
|
|
|
eigvals (numpy.array) : all eigenvalues
|
|
|
|
emin, emax (float) : energy window
|
|
|
|
|
|
|
|
Returns
|
|
|
|
-------
|
|
|
|
|
|
|
|
ib_win, nb_min, nb_max :
|
|
|
|
"""
|
2015-02-19 16:18:01 +01:00
|
|
|
# Sanity check
|
|
|
|
if emin > eigvals.max() or emax < eigvals.min():
|
|
|
|
raise Exception("Energy window does not overlap with the band structure")
|
|
|
|
|
2015-02-13 21:58:42 +01:00
|
|
|
nk, nband, ns_band = eigvals.shape
|
|
|
|
ib_win = np.zeros((nk, ns_band, 2), dtype=np.int32)
|
|
|
|
|
2015-10-20 12:36:57 +02:00
|
|
|
ib_min = 10000000
|
|
|
|
ib_max = 0
|
2015-02-13 21:58:42 +01:00
|
|
|
for isp in xrange(ns_band):
|
|
|
|
for ik in xrange(nk):
|
|
|
|
for ib in xrange(nband):
|
|
|
|
en = eigvals[ik, ib, isp]
|
|
|
|
if en >= emin:
|
|
|
|
break
|
|
|
|
ib1 = ib
|
2015-02-19 16:18:01 +01:00
|
|
|
for ib in xrange(ib1, nband):
|
2015-02-13 21:58:42 +01:00
|
|
|
en = eigvals[ik, ib, isp]
|
2015-02-19 16:18:01 +01:00
|
|
|
if en > emax:
|
2015-02-13 21:58:42 +01:00
|
|
|
break
|
2015-02-19 16:18:01 +01:00
|
|
|
else:
|
|
|
|
# If we reached the last band add 1 to get the correct bound
|
|
|
|
ib += 1
|
|
|
|
ib2 = ib - 1
|
2015-02-13 21:58:42 +01:00
|
|
|
|
2015-10-16 18:10:48 +02:00
|
|
|
assert ib1 <= ib2, "No bands inside the window for ik = %s"%(ik)
|
|
|
|
|
2015-02-13 21:58:42 +01:00
|
|
|
ib_win[ik, isp, 0] = ib1
|
|
|
|
ib_win[ik, isp, 1] = ib2
|
|
|
|
|
2015-10-20 12:36:57 +02:00
|
|
|
ib_min = min(ib_min, ib1)
|
|
|
|
ib_max = max(ib_max, ib2)
|
2015-02-13 21:58:42 +01:00
|
|
|
|
2015-10-20 12:36:57 +02:00
|
|
|
return ib_win, ib_min, ib_max
|
2015-02-13 21:58:42 +01:00
|
|
|
|
2015-02-17 21:12:57 +01:00
|
|
|
################################################################################
|
2015-02-13 21:58:42 +01:00
|
|
|
################################################################################
|
|
|
|
#
|
2015-02-17 19:42:34 +01:00
|
|
|
# class ProjectorGroup
|
2015-02-13 21:58:42 +01:00
|
|
|
#
|
|
|
|
################################################################################
|
2015-02-17 21:12:57 +01:00
|
|
|
################################################################################
|
2015-02-17 19:42:34 +01:00
|
|
|
class ProjectorGroup:
|
2015-02-13 21:58:42 +01:00
|
|
|
"""
|
|
|
|
Container of projectors defined within a certain energy window.
|
|
|
|
|
|
|
|
The constructor selects a subset of projectors according to
|
|
|
|
the parameters from the config-file (passed in `pars`).
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
2015-02-17 21:12:57 +01:00
|
|
|
- gr_pars (dict) : group parameters from the config-file
|
|
|
|
- shells ([ProjectorShell]) : array of ProjectorShell objects
|
2015-02-13 21:58:42 +01:00
|
|
|
- eigvals (numpy.array) : array of KS eigenvalues
|
|
|
|
|
|
|
|
"""
|
2015-03-02 21:29:54 +01:00
|
|
|
def __init__(self, gr_pars, shells, eigvals, ferw):
|
2015-02-13 21:58:42 +01:00
|
|
|
"""
|
|
|
|
Constructor
|
|
|
|
"""
|
2015-11-11 18:58:38 +01:00
|
|
|
self.emin, self.emax = gr_pars['ewindow']
|
2015-02-17 21:12:57 +01:00
|
|
|
self.ishells = gr_pars['shells']
|
|
|
|
self.ortho = gr_pars['normalize']
|
|
|
|
self.normion = gr_pars['normion']
|
2015-02-13 21:58:42 +01:00
|
|
|
|
2015-02-17 21:12:57 +01:00
|
|
|
self.shells = shells
|
2015-02-13 21:58:42 +01:00
|
|
|
|
|
|
|
# Determine the minimum and maximum band numbers
|
2015-10-20 12:36:57 +02:00
|
|
|
ib_win, ib_min, ib_max = select_bands(eigvals, self.emin, self.emax)
|
2015-02-13 21:58:42 +01:00
|
|
|
self.ib_win = ib_win
|
2015-10-20 12:36:57 +02:00
|
|
|
self.ib_min = ib_min
|
|
|
|
self.ib_max = ib_max
|
|
|
|
self.nb_max = ib_max - ib_min + 1
|
2015-02-13 21:58:42 +01:00
|
|
|
|
2015-02-17 21:12:57 +01:00
|
|
|
# Select projectors within the energy window
|
|
|
|
for ish in self.ishells:
|
|
|
|
shell = self.shells[ish]
|
2015-10-20 12:36:57 +02:00
|
|
|
shell.select_projectors(ib_win, ib_min, ib_max)
|
2015-02-13 21:58:42 +01:00
|
|
|
|
2015-09-17 12:40:55 +02:00
|
|
|
|
|
|
|
|
2015-03-02 21:43:46 +01:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# 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):
|
2015-09-17 12:40:55 +02:00
|
|
|
ib1 = self.ib_win[ik, isp, 0]
|
|
|
|
ib2 = self.ib_win[ik, isp, 1]
|
2015-10-15 13:26:48 +02:00
|
|
|
occ = el_struct.ferw[isp, ik, ib1:ib2]
|
2015-03-02 21:43:46 +01:00
|
|
|
kwght = el_struct.kmesh['kweights'][ik]
|
|
|
|
self.nelect += occ.sum() * kwght * rspin
|
|
|
|
|
|
|
|
return self.nelect
|
2015-03-02 21:29:54 +01:00
|
|
|
|
2015-02-17 21:12:57 +01:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# orthogonalize
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
def orthogonalize(self):
|
|
|
|
"""
|
|
|
|
Orthogonalize a group of projectors.
|
|
|
|
"""
|
|
|
|
# Quick exit if no normalization is requested
|
|
|
|
if not self.ortho:
|
|
|
|
return
|
|
|
|
|
|
|
|
# TODO: add the case of 'normion = True'
|
|
|
|
assert not self.normion, "'NORMION = True' is not yet implemented"
|
|
|
|
|
|
|
|
# Determine the dimension of the projector matrix
|
|
|
|
# and map the blocks to the big matrix
|
|
|
|
i1_bl = 0
|
|
|
|
bl_map = [{} for ish in self.ishells]
|
|
|
|
for ish in self.ishells:
|
|
|
|
_shell = self.shells[ish]
|
|
|
|
nion, ns, nk, nlm, nb_max = _shell.proj_win.shape
|
|
|
|
bmat_bl = [] # indices corresponding to a big block matrix
|
|
|
|
for ion in xrange(nion):
|
|
|
|
i2_bl = i1_bl + nlm
|
|
|
|
bmat_bl.append((i1_bl, i2_bl))
|
|
|
|
i1_bl = i2_bl
|
|
|
|
bl_map[ish]['bmat_blocks'] = bmat_bl
|
|
|
|
|
2015-02-19 17:59:55 +01:00
|
|
|
ndim = i2_bl
|
2015-02-17 21:12:57 +01:00
|
|
|
p_mat = np.zeros((ndim, nb_max), dtype=np.complex128)
|
2015-02-13 21:58:42 +01:00
|
|
|
for isp in xrange(ns):
|
|
|
|
for ik in xrange(nk):
|
2015-02-17 21:12:57 +01:00
|
|
|
nb = self.ib_win[ik, isp, 1] - self.ib_win[ik, isp, 0] + 1
|
|
|
|
# Combine all projectors of the group to one block projector
|
|
|
|
for ish in self.ishells:
|
|
|
|
shell = self.shells[ish]
|
|
|
|
blocks = bl_map[ish]['bmat_blocks']
|
|
|
|
for ion in xrange(nion):
|
|
|
|
i1, i2 = blocks[ion]
|
|
|
|
p_mat[i1:i2, :nb] = shell.proj_win[ion, isp, ik, :nlm, :nb]
|
|
|
|
# Now orthogonalize the obtained block projector
|
|
|
|
p_orth, overl, eig = orthogonalize_projector_matrix(p_mat)
|
2015-10-22 16:15:49 +02:00
|
|
|
# print "ik = ", ik
|
|
|
|
# print overl.real
|
2015-02-17 21:12:57 +01:00
|
|
|
# Distribute back projectors in the same order
|
|
|
|
for ish in self.ishells:
|
|
|
|
shell = self.shells[ish]
|
|
|
|
blocks = bl_map[ish]['bmat_blocks']
|
|
|
|
for ion in xrange(nion):
|
|
|
|
i1, i2 = blocks[ion]
|
2015-10-20 17:37:17 +02:00
|
|
|
shell.proj_win[ion, isp, ik, :nlm, :nb] = p_orth[i1:i2, :nb]
|
2015-02-17 21:12:57 +01:00
|
|
|
|
2015-02-13 21:58:42 +01:00
|
|
|
|
2015-02-17 19:42:34 +01:00
|
|
|
################################################################################
|
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# class ProjectorShell
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
################################################################################
|
|
|
|
class ProjectorShell:
|
|
|
|
"""
|
|
|
|
Container of projectors related to a specific shell.
|
|
|
|
|
|
|
|
The constructor pre-selects a subset of projectors according to
|
|
|
|
the shell parameters passed from the config-file.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
2015-02-17 21:12:57 +01:00
|
|
|
- sh_pars (dict) : shell parameters from the config-file
|
2015-02-17 19:42:34 +01:00
|
|
|
- proj_raw (numpy.array) : array of raw projectors
|
|
|
|
|
|
|
|
"""
|
2015-11-11 20:30:49 +01:00
|
|
|
def __init__(self, sh_pars, proj_raw, proj_params, nc_flag):
|
2015-02-17 19:42:34 +01:00
|
|
|
self.lorb = sh_pars['lshell']
|
|
|
|
self.ion_list = sh_pars['ion_list']
|
2015-03-02 21:29:54 +01:00
|
|
|
self.user_index = sh_pars['user_index']
|
2015-11-11 20:30:49 +01:00
|
|
|
self.nc_flag = nc_flag
|
2015-11-11 12:43:51 +01:00
|
|
|
# try:
|
|
|
|
# self.tmatrix = sh_pars['tmatrix']
|
|
|
|
# except KeyError:
|
|
|
|
# self.tmatrix = None
|
2015-02-17 19:42:34 +01:00
|
|
|
|
|
|
|
self.lm1 = self.lorb**2
|
|
|
|
self.lm2 = (self.lorb+1)**2
|
|
|
|
|
2015-11-11 12:43:51 +01:00
|
|
|
self.ndim = self.extract_tmatrices(sh_pars)
|
|
|
|
# if self.tmatrix is None:
|
|
|
|
# self.ndim = self.lm2 - self.lm1
|
|
|
|
# else:
|
|
|
|
## TODO: generalize this to a tmatrix for every ion
|
|
|
|
# self.ndim = self.tmatrix.shape[0]
|
2015-08-13 12:29:41 +02:00
|
|
|
|
2015-02-17 21:12:57 +01:00
|
|
|
# Pre-select a subset of projectors (this should be an array view => no memory is wasted)
|
2015-02-19 17:59:55 +01:00
|
|
|
# !!! This sucks but I have to change the order of 'ib' and 'ilm' indices here
|
|
|
|
# This should perhaps be done right after the projector array is read from PLOCAR
|
2015-10-15 13:26:48 +02:00
|
|
|
# self.proj_arr = proj_raw[self.ion_list, :, :, :, self.lm1:self.lm2].transpose((0, 1, 2, 4, 3))
|
|
|
|
# We want to select projectors from 'proj_raw' and form an array
|
|
|
|
# self.proj_arr[nion, ns, nk, nlm, nb]
|
|
|
|
# TODO: think of a smart way of copying the selected projectors
|
|
|
|
# perhaps, by redesigning slightly the structure of 'proj_arr' and 'proj_win'
|
|
|
|
# or by storing only a mapping between site/orbitals and indices of 'proj_raw'
|
|
|
|
# iproj_l = []
|
|
|
|
nion = len(self.ion_list)
|
|
|
|
nlm = self.lm2 - self.lm1
|
|
|
|
_, ns, nk, nb = proj_raw.shape
|
|
|
|
self.proj_arr = np.zeros((nion, ns, nk, nlm, nb), dtype=np.complex128)
|
|
|
|
for io, ion in enumerate(self.ion_list):
|
|
|
|
for m in xrange(nlm):
|
|
|
|
# Here we search for the index of the projector with the given isite/l/m indices
|
|
|
|
for ip, par in enumerate(proj_params):
|
|
|
|
if par['isite'] - 1 == ion and par['l'] == self.lorb and par['m'] == m:
|
|
|
|
# iproj_l.append(ip)
|
|
|
|
self.proj_arr[io, :, :, m, :] = proj_raw[ip, :, :, :]
|
|
|
|
break
|
|
|
|
|
|
|
|
# self.proj_arr = proj_raw[iproj_l, :, :, :].transpose((1, 2, 0, 3))
|
2015-02-17 19:42:34 +01:00
|
|
|
|
2015-11-11 12:43:51 +01:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# extract_tmatrices
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
def extract_tmatrices(self, sh_pars):
|
|
|
|
"""
|
|
|
|
Extracts and interprets transformation matrices provided by the
|
|
|
|
config-parser.
|
|
|
|
There are two relevant options in 'sh_pars':
|
|
|
|
|
|
|
|
'tmatrix' : a transformation matrix applied to all ions in the shell
|
|
|
|
'tmatrices': interpreted as a set of transformation matrices for each ion.
|
|
|
|
|
|
|
|
If both of the options are present a warning is issued and 'tmatrices'
|
|
|
|
supersedes 'tmatrix'.
|
|
|
|
"""
|
|
|
|
nion = len(self.ion_list)
|
|
|
|
nm = self.lm2 - self.lm1
|
|
|
|
|
|
|
|
if 'tmatrices' in sh_pars:
|
|
|
|
if 'tmatrix' in sh_pars:
|
|
|
|
mess = "Both TRANSFORM and TRANSFILE are specified, TRANSFORM will be ignored."
|
|
|
|
issue_warning(mess)
|
|
|
|
|
|
|
|
raw_matrices = sh_pars['tmatrices']
|
|
|
|
nrow, ncol = raw_matrices.shape
|
|
|
|
|
|
|
|
assert nrow%nion == 0, "Number of rows in TRANSFILE must be divisible by the number of ions"
|
|
|
|
assert ncol%nm == 0, "Number of columns in TRANSFILE must be divisible by the number of orbitals 2*l + 1"
|
|
|
|
|
|
|
|
nr = nrow / nion
|
|
|
|
nsize = ncol / nm
|
|
|
|
assert nsize in (1, 2, 4), "Number of columns in TRANSFILE must be divisible by either 1, 2, or 4"
|
|
|
|
#
|
|
|
|
# Determine the spin-dimension and whether the matrices are real or complex
|
|
|
|
#
|
|
|
|
# if nsize == 1 or nsize == 2:
|
|
|
|
# Matrices (either real or complex) are spin-independent
|
|
|
|
# nls_dim = nm
|
|
|
|
# if msize == 2:
|
|
|
|
# is_complex = True
|
|
|
|
# else:
|
|
|
|
# is_complex = False
|
|
|
|
# elif nsize = 4:
|
|
|
|
# Matrices are complex and spin-dependent
|
|
|
|
# nls_dim = 2 * nm
|
|
|
|
# is_complex = True
|
|
|
|
#
|
|
|
|
is_complex = nsize > 1
|
|
|
|
ns_dim = max(1, nsize / 2)
|
|
|
|
|
|
|
|
# Dimension of the orbital subspace
|
|
|
|
assert nr%ns_dim == 0, "Number of rows in TRANSFILE is not compatible with the spin dimension"
|
|
|
|
ndim = nr / ns_dim
|
|
|
|
|
|
|
|
self.tmatrices = np.zeros((nion, nr, nm * ns_dim), dtype=np.complex128)
|
|
|
|
|
|
|
|
if is_complex:
|
|
|
|
raw_matrices = raw_matrices[:, ::2] + raw_matrices[:, 1::2] * 1j
|
|
|
|
|
|
|
|
for io in xrange(nion):
|
|
|
|
i1 = io * nr
|
|
|
|
i2 = (io + 1) * nr
|
|
|
|
self.tmatrices[io, :, :] = raw_matrices[i1:i2, :]
|
|
|
|
|
|
|
|
return ndim
|
|
|
|
|
|
|
|
if 'tmatrix' in sh_pars:
|
|
|
|
raw_matrix = sh_pars['tmatrix']
|
|
|
|
nrow, ncol = raw_matrix.shape
|
|
|
|
|
|
|
|
assert ncol%nm == 0, "Number of columns in TRANSFORM must be divisible by the number of orbitals 2*l + 1"
|
|
|
|
|
|
|
|
# Only spin-independent matrices are expected here
|
|
|
|
nsize = ncol / nm
|
|
|
|
assert nsize in (1, 2), "Number of columns in TRANSFORM must be divisible by either 1 or 2"
|
|
|
|
|
|
|
|
is_complex = nsize > 1
|
|
|
|
if is_complex:
|
|
|
|
matrix = raw_matrix[:, ::2] + raw_matrix[:, 1::2] * 1j
|
|
|
|
else:
|
|
|
|
matrix = raw_matrix
|
|
|
|
|
|
|
|
ndim = nrow
|
|
|
|
|
|
|
|
self.tmatrices = np.zeros((nion, nrow, nm), dtype=np.complex128)
|
|
|
|
for io in xrange(nion):
|
|
|
|
self.tmatrices[io, :, :] = raw_matrix
|
|
|
|
|
|
|
|
return ndim
|
|
|
|
|
|
|
|
# If no transformation matrices are provided define a default one
|
|
|
|
ns_dim = 2 if self.nc_flag else 1
|
|
|
|
ndim = nm * ns_dim
|
|
|
|
|
|
|
|
self.tmatrices = np.zeros((nion, ndim, ndim), dtype=np.complex128)
|
|
|
|
for io in xrange(nion):
|
|
|
|
self.tmatrices[io, :, :] = np.identity(ndim, dtype=np.complex128)
|
|
|
|
|
|
|
|
return ndim
|
|
|
|
|
2015-02-17 19:42:34 +01:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# select_projectors
|
|
|
|
#
|
|
|
|
################################################################################
|
2015-10-20 12:36:57 +02:00
|
|
|
def select_projectors(self, ib_win, ib_min, ib_max):
|
2015-02-17 19:42:34 +01:00
|
|
|
"""
|
|
|
|
Selects a subset of projectors corresponding to a given energy window.
|
|
|
|
"""
|
|
|
|
self.ib_win = ib_win
|
2015-10-20 12:36:57 +02:00
|
|
|
self.ib_min = ib_min
|
|
|
|
self.ib_max = ib_max
|
|
|
|
nb_max = ib_max - ib_min + 1
|
2015-02-17 19:42:34 +01:00
|
|
|
|
|
|
|
# Set the dimensions of the array
|
2015-02-19 17:59:55 +01:00
|
|
|
nion, ns, nk, nlm, nbtot = self.proj_arr.shape
|
2015-03-01 11:42:18 +01:00
|
|
|
# !!! Note that the order of the two last indices is different !!!
|
2015-10-20 12:36:57 +02:00
|
|
|
self.proj_win = np.zeros((nion, ns, nk, nlm, nb_max), dtype=np.complex128)
|
2015-02-17 19:42:34 +01:00
|
|
|
|
|
|
|
# Select projectors for a given energy window
|
|
|
|
ns_band = self.ib_win.shape[1]
|
|
|
|
for isp in xrange(ns):
|
|
|
|
for ik in xrange(nk):
|
|
|
|
# TODO: for non-collinear case something else should be done here
|
|
|
|
is_b = min(isp, ns_band)
|
|
|
|
ib1 = self.ib_win[ik, is_b, 0]
|
|
|
|
ib2 = self.ib_win[ik, is_b, 1] + 1
|
2015-10-20 17:37:17 +02:00
|
|
|
ib_win = ib2 - ib1
|
|
|
|
self.proj_win[:, isp, ik, :, :ib_win] = self.proj_arr[:, isp, ik, :, ib1:ib2]
|
2015-02-17 21:12:57 +01:00
|
|
|
|
2015-02-19 21:22:51 +01:00
|
|
|
################################################################################
|
|
|
|
#
|
2015-10-22 16:15:49 +02:00
|
|
|
# density_matrix
|
2015-02-19 21:22:51 +01:00
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
def density_matrix(self, el_struct, site_diag=True, spin_diag=True):
|
|
|
|
"""
|
|
|
|
Returns occupation matrix/matrices for the shell.
|
|
|
|
"""
|
|
|
|
nion, ns, nk, nlm, nbtot = self.proj_win.shape
|
|
|
|
|
|
|
|
assert site_diag, "site_diag = False is not implemented"
|
|
|
|
assert spin_diag, "spin_diag = False is not implemented"
|
|
|
|
|
|
|
|
occ_mats = np.zeros((ns, nion, nlm, nlm), dtype=np.float64)
|
2015-10-16 18:10:48 +02:00
|
|
|
overlaps = np.zeros((ns, nion, nlm, nlm), dtype=np.float64)
|
2015-02-19 21:22:51 +01:00
|
|
|
|
2015-11-10 12:24:14 +01:00
|
|
|
# self.proj_win = np.zeros((nion, ns, nk, nlm, nb_max), dtype=np.complex128)
|
2015-02-19 21:22:51 +01:00
|
|
|
kweights = el_struct.kmesh['kweights']
|
|
|
|
occnums = el_struct.ferw
|
2015-10-20 12:36:57 +02:00
|
|
|
ib1 = self.ib_min
|
|
|
|
ib2 = self.ib_max + 1
|
2015-02-19 21:22:51 +01:00
|
|
|
for isp in xrange(ns):
|
|
|
|
for ik, weight, occ in it.izip(it.count(), kweights, occnums[isp, :, :]):
|
|
|
|
for io in xrange(nion):
|
2015-11-10 12:24:14 +01:00
|
|
|
proj_k = self.proj_win[io, isp, ik, ...]
|
2015-10-14 19:32:12 +02:00
|
|
|
occ_mats[isp, io, :, :] += np.dot(proj_k * occ[ib1:ib2],
|
2015-02-19 21:22:51 +01:00
|
|
|
proj_k.conj().T).real * weight
|
2015-10-16 18:10:48 +02:00
|
|
|
overlaps[isp, io, :, :] += np.dot(proj_k,
|
|
|
|
proj_k.conj().T).real * weight
|
2015-02-19 21:22:51 +01:00
|
|
|
|
|
|
|
# if not symops is None:
|
|
|
|
# occ_mats = symmetrize_matrix_set(occ_mats, symops, ions, perm_map)
|
|
|
|
|
2015-10-16 18:10:48 +02:00
|
|
|
return occ_mats, overlaps
|
2015-02-19 21:22:51 +01:00
|
|
|
|
2015-10-22 16:15:49 +02:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# density_of_states
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
def density_of_states(self, el_struct, emesh):
|
|
|
|
"""
|
|
|
|
Returns projected DOS for the shell.
|
|
|
|
"""
|
|
|
|
nion, ns, nk, nlm, nbtot = self.proj_win.shape
|
|
|
|
|
|
|
|
# There is a problem with data storage structure of projectors that will
|
|
|
|
# make life more complicated. The problem is that band-indices of projectors
|
|
|
|
# for different k-points do not match because we store 'nb_max' values starting
|
|
|
|
# from 0.
|
|
|
|
nb_max = self.ib_max - self.ib_min + 1
|
|
|
|
ns_band = self.ib_win.shape[1]
|
|
|
|
|
|
|
|
ne = len(emesh)
|
|
|
|
dos = np.zeros((ne, ns, nion, nlm))
|
|
|
|
w_k = np.zeros((nk, nb_max, ns, nion, nlm), dtype=np.complex128)
|
|
|
|
for isp in xrange(ns):
|
|
|
|
for ik in xrange(nk):
|
|
|
|
is_b = min(isp, ns_band)
|
|
|
|
ib1 = self.ib_win[ik, is_b, 0]
|
|
|
|
ib2 = self.ib_win[ik, is_b, 1] + 1
|
|
|
|
for ib_g in xrange(ib1, ib2):
|
|
|
|
for io in xrange(nion):
|
|
|
|
# Note the difference between 'ib' and 'ibn':
|
|
|
|
# 'ib' counts from 0 to 'nb_k - 1'
|
|
|
|
# 'ibn' counts from 'ib1 - ib_min' to 'ib2 - ib_min'
|
|
|
|
ib = ib_g - ib1
|
|
|
|
ibn = ib_g - self.ib_min
|
2015-11-10 12:24:14 +01:00
|
|
|
proj_k = self.proj_win[io, isp, ik, :, ib]
|
2015-11-10 14:09:40 +01:00
|
|
|
w_k[ik, ib, isp, io, :] = proj_k * proj_k.conj()
|
2015-10-22 16:15:49 +02:00
|
|
|
|
|
|
|
# eigv_ef = el_struct.eigvals[ik, ib, isp] - el_struct.efermi
|
|
|
|
itt = el_struct.kmesh['itet'].T
|
|
|
|
# k-indices are starting from 0 in Python
|
|
|
|
itt[1:, :] -= 1
|
|
|
|
for isp in xrange(ns):
|
|
|
|
for ib, eigk in enumerate(el_struct.eigvals[:, self.ib_min:self.ib_max+1, isp].T):
|
|
|
|
for ie, e in enumerate(emesh):
|
|
|
|
eigk_ef = eigk - el_struct.efermi
|
|
|
|
cti = c_atm_dos.dos_weights_3d(eigk_ef, e, itt)
|
|
|
|
for im in xrange(nlm):
|
|
|
|
for io in xrange(nion):
|
|
|
|
dos[ie, isp, io, im] += np.sum((cti * w_k[itt[1:, :], ib, isp, io, im].real).sum(0) * itt[0, :])
|
|
|
|
|
|
|
|
dos *= 2 * el_struct.kmesh['volt']
|
|
|
|
# for isp in xrange(ns):
|
|
|
|
# for ik, weight, occ in it.izip(it.count(), kweights, occnums[isp, :, :]):
|
|
|
|
# for io in xrange(nion):
|
|
|
|
# proj_k = self.proj_win[isp, io, ik, ...]
|
|
|
|
# occ_mats[isp, io, :, :] += np.dot(proj_k * occ[ib1:ib2],
|
|
|
|
# proj_k.conj().T).real * weight
|
|
|
|
# overlaps[isp, io, :, :] += np.dot(proj_k,
|
|
|
|
# proj_k.conj().T).real * weight
|
|
|
|
|
|
|
|
# if not symops is None:
|
|
|
|
# occ_mats = symmetrize_matrix_set(occ_mats, symops, ions, perm_map)
|
|
|
|
|
|
|
|
return dos
|
|
|
|
|
2015-02-19 21:22:51 +01:00
|
|
|
|
2015-02-13 21:58:42 +01:00
|
|
|
|
2015-03-01 13:09:31 +01:00
|
|
|
################################################################################
|
|
|
|
#
|
2015-03-03 10:53:46 +01:00
|
|
|
# generate_plo()
|
2015-03-01 13:09:31 +01:00
|
|
|
#
|
|
|
|
################################################################################
|
2015-03-03 10:27:52 +01:00
|
|
|
def generate_plo(conf_pars, el_struct):
|
2015-02-13 21:58:42 +01:00
|
|
|
"""
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
|
|
|
|
conf_pars (dict) : dictionary of input parameters (from conf-file)
|
2015-03-01 11:42:18 +01:00
|
|
|
el_struct : ElectronicStructure object
|
2015-02-13 21:58:42 +01:00
|
|
|
"""
|
|
|
|
|
2015-03-01 11:42:18 +01:00
|
|
|
check_data_consistency(conf_pars, el_struct)
|
2015-02-13 21:58:42 +01:00
|
|
|
|
2015-03-01 11:42:18 +01:00
|
|
|
proj_raw = el_struct.proj_raw
|
2015-02-17 19:42:34 +01:00
|
|
|
try:
|
|
|
|
efermi = conf_pars.general['efermi']
|
2015-03-01 11:42:18 +01:00
|
|
|
except (KeyError, AttributeError):
|
|
|
|
efermi = el_struct.efermi
|
2015-02-17 19:42:34 +01:00
|
|
|
|
2015-02-13 21:58:42 +01:00
|
|
|
# eigvals(nktot, nband, ispin) are defined with respect to the Fermi level
|
2015-10-14 19:32:12 +02:00
|
|
|
eigvals = el_struct.eigvals - efermi
|
2015-02-13 21:58:42 +01:00
|
|
|
|
2015-11-10 12:24:14 +01:00
|
|
|
nshell = len(conf_pars.shells)
|
|
|
|
print
|
|
|
|
print " Generating %i shell%s..."%(nshell, '' if nshell == 1 else 's')
|
2015-03-01 11:42:18 +01:00
|
|
|
pshells = []
|
2015-02-17 19:42:34 +01:00
|
|
|
for sh_par in conf_pars.shells:
|
2015-11-11 20:30:49 +01:00
|
|
|
pshell = ProjectorShell(sh_par, proj_raw, el_struct.proj_params, el_struct.nc_flag)
|
2015-11-10 12:24:14 +01:00
|
|
|
print
|
|
|
|
print " Shell : %s"%(pshell.user_index)
|
|
|
|
print " Orbital l : %i"%(pshell.lorb)
|
|
|
|
print " Number of ions: %i"%(len(pshell.ion_list))
|
2015-11-11 18:58:38 +01:00
|
|
|
print " Dimension : %i"%(pshell.ndim)
|
2015-11-10 12:24:14 +01:00
|
|
|
pshells.append(pshell)
|
2015-02-17 19:42:34 +01:00
|
|
|
|
2015-03-01 11:42:18 +01:00
|
|
|
pgroups = []
|
2015-02-17 21:12:57 +01:00
|
|
|
for gr_par in conf_pars.groups:
|
2015-03-02 21:29:54 +01:00
|
|
|
pgroup = ProjectorGroup(gr_par, pshells, eigvals, el_struct.ferw)
|
2015-10-20 17:37:17 +02:00
|
|
|
pgroup.orthogonalize()
|
2015-10-16 18:10:48 +02:00
|
|
|
print "Density matrix:"
|
|
|
|
dm, ov = pshells[pgroup.ishells[0]].density_matrix(el_struct)
|
|
|
|
print dm
|
|
|
|
print
|
|
|
|
print "Overlap:"
|
|
|
|
print ov
|
2015-11-10 16:40:46 +01:00
|
|
|
if 'dosmesh' in conf_pars.general:
|
|
|
|
print
|
|
|
|
print "Evaluating DOS..."
|
|
|
|
mesh_pars = conf_pars.general['dosmesh']
|
|
|
|
if np.isnan(mesh_pars['emin']):
|
|
|
|
dos_emin = pgroup.emin
|
|
|
|
dos_emax = pgroup.emax
|
|
|
|
else:
|
|
|
|
dos_emin = mesh_pars['emin']
|
|
|
|
dos_emax = mesh_pars['emax']
|
|
|
|
n_points = mesh_pars['n_points']
|
|
|
|
|
|
|
|
emesh = np.linspace(dos_emin, dos_emax, n_points)
|
|
|
|
dos = pshells[pgroup.ishells[0]].density_of_states(el_struct, emesh)
|
|
|
|
de = emesh[1] - emesh[0]
|
|
|
|
ntot = (dos[1:,...] + dos[:-1,...]).sum(0) / 2 * de
|
|
|
|
print " Total number of states:", ntot
|
|
|
|
for io in xrange(dos.shape[2]):
|
|
|
|
np.savetxt('pdos_%i.dat'%(io), np.vstack((emesh.T, dos[:, 0, io, :].T)).T)
|
|
|
|
|
2015-03-01 11:42:18 +01:00
|
|
|
pgroups.append(pgroup)
|
2015-02-17 21:12:57 +01:00
|
|
|
|
2015-03-01 11:42:18 +01:00
|
|
|
return pshells, pgroups
|
2015-02-13 21:58:42 +01:00
|
|
|
|
2015-03-01 13:09:31 +01:00
|
|
|
|
2015-03-03 10:53:46 +01:00
|
|
|
# TODO: k-points with weights should be stored once and for all
|
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# kpoints_output
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
def kpoints_output(basename, el_struct):
|
|
|
|
"""
|
|
|
|
Outputs k-point data into a text file.
|
|
|
|
"""
|
|
|
|
|
|
|
|
kmesh = el_struct.kmesh
|
|
|
|
fname = basename + '.kpoints'
|
|
|
|
with open(fname, 'wt') as f:
|
|
|
|
f.write("# Number of k-points: nktot\n")
|
|
|
|
nktot = kmesh['nktot']
|
|
|
|
f.write("%i\n"%(nktot))
|
|
|
|
# TODO: add the output of reciprocal lattice vectors
|
|
|
|
f.write("# List of k-points with weights\n")
|
|
|
|
for ik in xrange(nktot):
|
|
|
|
kx, ky, kz = kmesh['kpoints'][ik, :]
|
|
|
|
kwght = kmesh['kweights'][ik]
|
|
|
|
f.write("%15.10f%15.10f%15.10f%20.10f\n"%(kx, ky, kz, kwght))
|
|
|
|
|
|
|
|
# Check if there are tetrahedra defined and if they are, output them
|
|
|
|
try:
|
|
|
|
ntet = kmesh['ntet']
|
|
|
|
volt = kmesh['volt']
|
|
|
|
f.write("\n# Number of tetrahedra and volume: ntet, volt\n")
|
|
|
|
f.write("%i %s\n"%(ntet, volt))
|
|
|
|
f.write("# List of tetrahedra: imult, ik1, ..., ik4\n")
|
|
|
|
for it in xrange(ntet):
|
|
|
|
f.write(' '.join(map("{0:d}".format, *kmesh['itet'][it, :])) + '\n')
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2015-08-12 17:09:30 +02:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# ctrl_output
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
def ctrl_output(conf_pars, el_struct, ng):
|
|
|
|
"""
|
|
|
|
Outputs a ctrl-file.
|
|
|
|
"""
|
|
|
|
ctrl_fname = conf_pars.general['basename'] + '.ctrl'
|
|
|
|
head_dict = {}
|
|
|
|
|
2015-08-13 11:50:49 +02:00
|
|
|
# TODO: Add output of tetrahedra
|
2015-08-12 17:09:30 +02:00
|
|
|
# Construct the header dictionary
|
|
|
|
head_dict['ngroups'] = ng
|
|
|
|
head_dict['nk'] = el_struct.kmesh['nktot']
|
|
|
|
head_dict['ns'] = el_struct.nspin
|
|
|
|
head_dict['nc_flag'] = 1 if el_struct.nc_flag else 0
|
|
|
|
# head_dict['efermi'] = conf_pars.general['efermi'] # We probably don't need Efermi
|
|
|
|
|
|
|
|
header = json.dumps(head_dict, indent=4, separators=(',', ': '))
|
|
|
|
|
2015-08-13 10:59:32 +02:00
|
|
|
print " Storing ctrl-file..."
|
2015-08-12 17:09:30 +02:00
|
|
|
with open(ctrl_fname, 'wt') as f:
|
2015-08-13 10:59:32 +02:00
|
|
|
f.write(header + "\n")
|
|
|
|
f.write("#END OF HEADER\n")
|
|
|
|
|
|
|
|
f.write("# k-points and weights\n")
|
|
|
|
labels = ['kx', 'ky', 'kz', 'kweight']
|
2015-10-15 13:26:48 +02:00
|
|
|
out = "".join(map(lambda s: s.center(15), labels))
|
2015-08-13 10:59:32 +02:00
|
|
|
f.write("#" + out + "\n")
|
|
|
|
for ik, kp in enumerate(el_struct.kmesh['kpoints']):
|
|
|
|
tmp1 = "".join(map("{0:15.10f}".format, kp))
|
|
|
|
out = tmp1 + "{0:16.10f}".format(el_struct.kmesh['kweights'][ik])
|
|
|
|
f.write(out + "\n")
|
|
|
|
|
2015-08-12 17:09:30 +02:00
|
|
|
|
2015-03-01 13:09:31 +01:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# plo_output
|
|
|
|
#
|
|
|
|
################################################################################
|
2015-08-12 17:09:30 +02:00
|
|
|
def plo_output(conf_pars, el_struct, pshells, pgroups):
|
2015-03-01 13:09:31 +01:00
|
|
|
"""
|
|
|
|
Outputs PLO groups into text files.
|
|
|
|
|
|
|
|
Filenames are defined by <basename> that is passed from config-file.
|
|
|
|
All necessary general parameters are stored in a file '<basename>.ctrl'.
|
|
|
|
|
|
|
|
Each group is stored in a '<basename>.plog<Ng>' file. The format is the
|
|
|
|
following:
|
|
|
|
|
|
|
|
# Energy window: emin, emax
|
|
|
|
ib_min, ib_max
|
2015-03-02 21:29:54 +01:00
|
|
|
nelect
|
2015-03-01 13:09:31 +01:00
|
|
|
# Eigenvalues
|
2015-03-02 21:29:54 +01:00
|
|
|
isp, ik1, kx, ky, kz, kweight
|
2015-03-01 13:09:31 +01:00
|
|
|
ib1, ib2
|
|
|
|
eig1
|
|
|
|
eig2
|
|
|
|
...
|
|
|
|
eigN
|
|
|
|
ik2, kx, ky, kz, kweight
|
|
|
|
...
|
|
|
|
|
|
|
|
# Projected shells
|
|
|
|
Nshells
|
|
|
|
# Shells: <shell indices>
|
2015-08-10 13:52:29 +02:00
|
|
|
# Shell <1>
|
2015-03-01 13:09:31 +01:00
|
|
|
Shell 1
|
|
|
|
ndim
|
|
|
|
# complex arrays: plo(ns, nion, ndim, nb)
|
|
|
|
...
|
|
|
|
# Shells: <shell indices>
|
2015-08-10 13:52:29 +02:00
|
|
|
# Shell <2>
|
2015-03-01 13:09:31 +01:00
|
|
|
Shell 2
|
|
|
|
...
|
|
|
|
|
|
|
|
"""
|
2015-08-13 12:29:41 +02:00
|
|
|
for ig, pgroup in enumerate(pgroups):
|
|
|
|
plo_fname = conf_pars.general['basename'] + '.pg%i'%(ig + 1)
|
|
|
|
print " Storing PLO-group file '%s'..."%(plo_fname)
|
|
|
|
head_dict = {}
|
|
|
|
|
|
|
|
head_dict['ewindow'] = (pgroup.emin, pgroup.emax)
|
|
|
|
head_dict['nb_max'] = pgroup.nb_max
|
|
|
|
|
2015-09-17 12:40:55 +02:00
|
|
|
# Number of electrons within the window
|
|
|
|
head_dict['nelect'] = pgroup.nelect_window(el_struct)
|
2015-10-15 13:26:48 +02:00
|
|
|
print " Density within window:", head_dict['nelect']
|
2015-09-17 12:40:55 +02:00
|
|
|
|
2015-08-13 12:29:41 +02:00
|
|
|
head_shells = []
|
2015-08-18 11:36:08 +02:00
|
|
|
for ish in pgroup.ishells:
|
|
|
|
shell = pgroup.shells[ish]
|
2015-08-13 12:29:41 +02:00
|
|
|
sh_dict = {}
|
2015-08-18 11:36:08 +02:00
|
|
|
sh_dict['shell_index'] = ish
|
2015-08-13 12:29:41 +02:00
|
|
|
sh_dict['lorb'] = shell.lorb
|
|
|
|
sh_dict['ndim'] = shell.ndim
|
|
|
|
# Convert ion indices from the internal representation (starting from 0)
|
|
|
|
# to conventional VASP representation (starting from 1)
|
|
|
|
ion_output = [io + 1 for io in shell.ion_list]
|
|
|
|
sh_dict['ion_list'] = ion_output
|
2015-09-16 11:56:54 +02:00
|
|
|
sh_dict['ion_sort'] = el_struct.type_of_ion[shell.ion_list[0]]
|
|
|
|
|
2015-08-13 12:29:41 +02:00
|
|
|
# TODO: add the output of transformation matrices
|
|
|
|
|
|
|
|
head_shells.append(sh_dict)
|
|
|
|
|
|
|
|
head_dict['shells'] = head_shells
|
|
|
|
|
|
|
|
header = json.dumps(head_dict, indent=4, separators=(',', ': '))
|
|
|
|
|
|
|
|
with open(plo_fname, 'wt') as f:
|
|
|
|
f.write(header + "\n")
|
2015-08-18 11:36:08 +02:00
|
|
|
f.write("#END OF HEADER\n")
|
2015-08-13 12:29:41 +02:00
|
|
|
|
2015-08-18 11:36:08 +02:00
|
|
|
# Eigenvalues within the window
|
|
|
|
f.write("# Eigenvalues within the energy window: %s, %s\n"%(pgroup.emin, pgroup.emax))
|
|
|
|
nk, nband, ns_band = el_struct.eigvals.shape
|
2015-03-02 21:29:54 +01:00
|
|
|
for isp in xrange(ns_band):
|
2015-08-18 11:36:08 +02:00
|
|
|
f.write("# is = %i\n"%(isp + 1))
|
2015-03-02 21:29:54 +01:00
|
|
|
for ik in xrange(nk):
|
2015-08-18 11:36:08 +02:00
|
|
|
ib1, ib2 = pgroup.ib_win[ik, isp, 0], pgroup.ib_win[ik, isp, 1]
|
|
|
|
f.write(" %i %i\n"%(ib1, ib2))
|
|
|
|
for ib in xrange(ib1, ib2 + 1):
|
2015-10-20 12:02:46 +02:00
|
|
|
eigv_ef = el_struct.eigvals[ik, ib, isp] - el_struct.efermi
|
|
|
|
f.write("%15.7f\n"%(eigv_ef))
|
2015-08-18 11:36:08 +02:00
|
|
|
|
|
|
|
# Projected shells
|
|
|
|
f.write("# Projected shells\n")
|
|
|
|
f.write("# Shells: %s\n"%(pgroup.ishells))
|
|
|
|
for ish in pgroup.ishells:
|
|
|
|
shell = pgroup.shells[ish]
|
|
|
|
f.write("# Shell %i\n"%(ish))
|
|
|
|
|
|
|
|
nion, ns, nk, nlm, nb = shell.proj_win.shape
|
|
|
|
for isp in xrange(ns):
|
|
|
|
f.write("# is = %i\n"%(isp + 1))
|
|
|
|
for ik in xrange(nk):
|
|
|
|
f.write("# ik = %i\n"%(ik + 1))
|
2015-03-02 21:29:54 +01:00
|
|
|
for ion in xrange(nion):
|
2015-08-18 11:36:08 +02:00
|
|
|
for ilm in xrange(nlm):
|
|
|
|
ib1, ib2 = pgroup.ib_win[ik, isp, 0], pgroup.ib_win[ik, isp, 1]
|
2015-10-20 17:37:17 +02:00
|
|
|
ib_win = ib2 - ib1 + 1
|
|
|
|
for ib in xrange(ib_win):
|
2015-08-18 11:36:08 +02:00
|
|
|
p = shell.proj_win[ion, isp, ik, ilm, ib]
|
|
|
|
f.write("{0:16.10f}{1:16.10f}\n".format(p.real, p.imag))
|
2015-03-02 21:29:54 +01:00
|
|
|
f.write("\n")
|
2015-08-18 11:36:08 +02:00
|
|
|
|
|
|
|
|
2015-08-13 11:50:49 +02:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# output_as_text
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
def output_as_text(pars, el_struct, pshells, pgroups):
|
|
|
|
"""
|
|
|
|
Output all information necessary for the converter as text files.
|
|
|
|
"""
|
2015-08-13 12:29:41 +02:00
|
|
|
ctrl_output(pars, el_struct, len(pgroups))
|
|
|
|
plo_output(pars, el_struct, pshells, pgroups)
|
2015-08-13 11:50:49 +02:00
|
|
|
|