2020-04-01 17:13:28 +02:00
|
|
|
|
2015-08-24 18:50:24 +02:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# TRIQS: a Toolbox for Research in Interacting Quantum Systems
|
|
|
|
#
|
2016-02-01 14:06:41 +01:00
|
|
|
# Copyright (C) 2011 by M. Ferrero, O. Parcollet
|
|
|
|
#
|
|
|
|
# DFT tools: Copyright (C) 2011 by M. Aichhorn, L. Pourovskii, V. Vildosola
|
|
|
|
#
|
|
|
|
# PLOVasp: Copyright (C) 2015 by O. E. Peil
|
2015-08-24 18:50:24 +02:00
|
|
|
#
|
|
|
|
# TRIQS is free software: you can redistribute it and/or modify it under the
|
|
|
|
# terms of the GNU General Public License as published by the Free Software
|
|
|
|
# Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
# version.
|
|
|
|
#
|
|
|
|
# TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
# TRIQS. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
################################################################################
|
2022-03-01 23:51:39 +01:00
|
|
|
"""
|
|
|
|
Vasp converter
|
|
|
|
"""
|
2015-08-24 18:50:24 +02:00
|
|
|
|
|
|
|
from types import *
|
|
|
|
import numpy
|
2020-04-08 21:47:15 +02:00
|
|
|
from h5 import *
|
2020-04-08 21:35:59 +02:00
|
|
|
from .converter_tools import *
|
2015-08-24 18:50:24 +02:00
|
|
|
import os.path
|
2015-09-21 12:10:07 +02:00
|
|
|
try:
|
|
|
|
import simplejson as json
|
|
|
|
except ImportError:
|
|
|
|
import json
|
2015-08-24 18:50:24 +02:00
|
|
|
|
|
|
|
class VaspConverter(ConverterTools):
|
|
|
|
"""
|
|
|
|
Conversion from VASP output to an hdf5 file that can be used as input for the SumkDFT class.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, filename, hdf_filename = None,
|
|
|
|
dft_subgrp = 'dft_input', symmcorr_subgrp = 'dft_symmcorr_input',
|
|
|
|
parproj_subgrp='dft_parproj_input', symmpar_subgrp='dft_symmpar_input',
|
|
|
|
bands_subgrp = 'dft_bands_input', misc_subgrp = 'dft_misc_input',
|
2019-07-01 10:51:33 +02:00
|
|
|
transp_subgrp = 'dft_transp_input', repacking = False,
|
|
|
|
proj_or_hk='proj'):
|
2015-08-24 18:50:24 +02:00
|
|
|
"""
|
2020-04-01 17:13:28 +02:00
|
|
|
Init of the class. Variable filename gives the root of all filenames, e.g. case.ctqmcout, case.h5, and so on.
|
2019-07-03 13:06:50 +02:00
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
filename : string
|
|
|
|
Base name of DFT files.
|
|
|
|
hdf_filename : string, optional
|
|
|
|
Name of hdf5 archive to be created.
|
|
|
|
dft_subgrp : string, optional
|
|
|
|
Name of subgroup storing necessary DFT data.
|
|
|
|
symmcorr_subgrp : string, optional
|
|
|
|
Name of subgroup storing correlated-shell symmetry data.
|
|
|
|
parproj_subgrp : string, optional
|
|
|
|
Name of subgroup storing partial projector data.
|
|
|
|
symmpar_subgrp : string, optional
|
|
|
|
Name of subgroup storing partial-projector symmetry data.
|
|
|
|
bands_subgrp : string, optional
|
|
|
|
Name of subgroup storing band data.
|
|
|
|
misc_subgrp : string, optional
|
|
|
|
Name of subgroup storing miscellaneous DFT data.
|
|
|
|
transp_subgrp : string, optional
|
|
|
|
Name of subgroup storing transport data.
|
|
|
|
repacking : boolean, optional
|
|
|
|
Does the hdf5 archive need to be repacked to save space?
|
|
|
|
proj_or_hk : string, optional
|
|
|
|
Select scheme to convert between KS bands and localized orbitals.
|
|
|
|
|
2015-08-24 18:50:24 +02:00
|
|
|
"""
|
|
|
|
|
2020-04-08 21:55:39 +02:00
|
|
|
assert isinstance(filename, str), "Please provide the DFT files' base name as a string."
|
2015-08-24 18:50:24 +02:00
|
|
|
if hdf_filename is None: hdf_filename = filename+'.h5'
|
|
|
|
self.hdf_file = hdf_filename
|
|
|
|
self.basename = filename
|
|
|
|
self.ctrl_file = filename+'.ctrl'
|
|
|
|
# self.pmat_file = filename+'.pmat'
|
|
|
|
self.dft_subgrp = dft_subgrp
|
|
|
|
self.symmcorr_subgrp = symmcorr_subgrp
|
|
|
|
self.parproj_subgrp = parproj_subgrp
|
|
|
|
self.symmpar_subgrp = symmpar_subgrp
|
|
|
|
self.bands_subgrp = bands_subgrp
|
|
|
|
self.misc_subgrp = misc_subgrp
|
|
|
|
self.transp_subgrp = transp_subgrp
|
2019-07-01 10:51:33 +02:00
|
|
|
assert (proj_or_hk == 'proj') or (proj_or_hk == 'hk'), "proj_or_hk has to be 'proj' of 'hk'"
|
|
|
|
self.proj_or_hk = proj_or_hk
|
2020-04-01 17:13:28 +02:00
|
|
|
|
2015-08-24 18:50:24 +02:00
|
|
|
# Checks if h5 file is there and repacks it if wanted:
|
|
|
|
if (os.path.exists(self.hdf_file) and repacking):
|
|
|
|
ConverterTools.repack(self)
|
|
|
|
|
2019-07-03 08:12:18 +02:00
|
|
|
# this is to test pull request
|
2015-08-24 18:50:24 +02:00
|
|
|
def read_data(self, fh):
|
|
|
|
"""
|
|
|
|
Generator for reading plain data.
|
2020-04-01 17:13:28 +02:00
|
|
|
|
2019-07-03 13:06:50 +02:00
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
fh : file object
|
|
|
|
file object which is read in.
|
2015-08-24 18:50:24 +02:00
|
|
|
"""
|
2015-08-24 19:10:29 +02:00
|
|
|
for line in fh:
|
|
|
|
line_ = line.strip()
|
2015-09-21 20:18:37 +02:00
|
|
|
if not line or (line_ == '' or line_[0] == '#'):
|
2015-08-24 19:10:29 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
for val in map(float, line.split()):
|
|
|
|
yield val
|
2015-08-24 18:50:24 +02:00
|
|
|
|
|
|
|
def read_header_and_data(self, filename):
|
|
|
|
"""
|
|
|
|
Opens a file and returns a JSON-header and the generator for the plain data.
|
2020-04-01 17:13:28 +02:00
|
|
|
|
2019-07-03 13:06:50 +02:00
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
filename : string
|
|
|
|
file name of the file to read.
|
2015-08-24 18:50:24 +02:00
|
|
|
"""
|
2015-08-24 19:10:29 +02:00
|
|
|
fh = open(filename, 'rt')
|
|
|
|
header = ""
|
|
|
|
for line in fh:
|
2015-09-21 20:18:37 +02:00
|
|
|
if not "#END" in line:
|
2015-08-24 19:10:29 +02:00
|
|
|
header += line
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
|
|
|
f_gen = self.read_data(fh)
|
|
|
|
|
|
|
|
return header, f_gen
|
|
|
|
|
2015-08-24 18:50:24 +02:00
|
|
|
def convert_dft_input(self):
|
|
|
|
"""
|
|
|
|
Reads the input files, and stores the data in the HDFfile
|
|
|
|
"""
|
2015-09-17 12:45:37 +02:00
|
|
|
energy_unit = 1.0 # VASP interface always uses eV
|
2015-09-21 12:10:07 +02:00
|
|
|
k_dep_projection = 1
|
2015-09-21 11:37:40 +02:00
|
|
|
# Symmetries are switched off for the moment
|
|
|
|
# TODO: implement symmetries
|
|
|
|
symm_op = 0 # Use symmetry groups for the k-sum
|
2015-09-17 12:45:37 +02:00
|
|
|
|
2015-08-24 18:50:24 +02:00
|
|
|
# Read and write only on the master node
|
|
|
|
if not (mpi.is_master_node()): return
|
2015-09-21 20:18:37 +02:00
|
|
|
mpi.report("Reading input from %s..."%self.ctrl_file)
|
2015-08-24 18:50:24 +02:00
|
|
|
|
|
|
|
# R is a generator : each R.Next() will return the next number in the file
|
2015-09-17 12:45:37 +02:00
|
|
|
jheader, rf = self.read_header_and_data(self.ctrl_file)
|
2020-04-08 21:35:59 +02:00
|
|
|
print(jheader)
|
2015-08-27 11:36:19 +02:00
|
|
|
ctrl_head = json.loads(jheader)
|
|
|
|
|
|
|
|
ng = ctrl_head['ngroups']
|
2015-09-17 12:45:37 +02:00
|
|
|
n_k = ctrl_head['nk']
|
|
|
|
# Note the difference in name conventions!
|
2015-09-21 20:18:37 +02:00
|
|
|
SP = ctrl_head['ns'] - 1
|
2015-09-17 12:45:37 +02:00
|
|
|
SO = ctrl_head['nc_flag']
|
2015-08-27 11:36:19 +02:00
|
|
|
|
2020-08-03 12:39:34 +02:00
|
|
|
# load reciprocal basis
|
|
|
|
kpt_basis = numpy.zeros((3,3))
|
|
|
|
kpt_basis[:,0] = ctrl_head['kvec1']
|
|
|
|
kpt_basis[:,1] = ctrl_head['kvec2']
|
|
|
|
kpt_basis[:,2] = ctrl_head['kvec3']
|
|
|
|
|
2015-09-21 20:18:37 +02:00
|
|
|
kpts = numpy.zeros((n_k, 3))
|
2019-11-21 21:34:37 +01:00
|
|
|
kpts_cart = numpy.zeros((n_k, 3))
|
2015-09-21 20:18:37 +02:00
|
|
|
bz_weights = numpy.zeros(n_k)
|
2020-08-03 12:39:34 +02:00
|
|
|
kpt_weights = numpy.zeros(n_k)
|
2015-08-27 11:36:19 +02:00
|
|
|
try:
|
2020-04-08 21:35:59 +02:00
|
|
|
for ik in range(n_k):
|
|
|
|
kx, ky, kz = next(rf), next(rf), next(rf)
|
2015-08-27 11:36:19 +02:00
|
|
|
kpts[ik, :] = kx, ky, kz
|
2020-04-08 21:35:59 +02:00
|
|
|
bz_weights[ik] = next(rf)
|
2020-08-03 12:39:34 +02:00
|
|
|
# bz_weights soon to be removed, and replaced by kpt_weights
|
|
|
|
kpt_weights[ik] = bz_weights[ik]
|
2020-04-08 21:35:59 +02:00
|
|
|
for ik in range(n_k):
|
|
|
|
kx, ky, kz = next(rf), next(rf), next(rf)
|
2019-11-21 21:34:37 +01:00
|
|
|
kpts_cart[ik, :] = kx, ky, kz
|
2015-08-27 11:36:19 +02:00
|
|
|
except StopIteration:
|
|
|
|
raise "VaspConverter: error reading %s"%self.ctrl_file
|
|
|
|
|
2015-09-17 12:45:37 +02:00
|
|
|
# if nc_flag:
|
|
|
|
## TODO: check this
|
|
|
|
# n_spin_blocs = 1
|
|
|
|
# else:
|
|
|
|
# n_spin_blocs = ns
|
|
|
|
n_spin_blocs = SP + 1 - SO
|
|
|
|
|
2015-08-27 11:36:19 +02:00
|
|
|
# Read PLO groups
|
2015-09-17 12:45:37 +02:00
|
|
|
# First, we read everything into a temporary data structure
|
|
|
|
# TODO: think about multiple shell groups and how to map them on h5 structures
|
|
|
|
assert ng == 1, "Only one group is allowed at the moment"
|
2015-08-27 11:36:19 +02:00
|
|
|
|
2019-07-02 14:06:12 +02:00
|
|
|
try:
|
2020-04-08 21:35:59 +02:00
|
|
|
for ig in range(ng):
|
2015-09-17 12:45:37 +02:00
|
|
|
gr_file = self.basename + '.pg%i'%(ig + 1)
|
|
|
|
jheader, rf = self.read_header_and_data(gr_file)
|
|
|
|
gr_head = json.loads(jheader)
|
2020-04-01 17:13:28 +02:00
|
|
|
|
2015-09-17 12:45:37 +02:00
|
|
|
|
|
|
|
nb_max = gr_head['nb_max']
|
|
|
|
p_shells = gr_head['shells']
|
|
|
|
density_required = gr_head['nelect']
|
|
|
|
charge_below = 0.0 # This is not defined in VASP interface
|
|
|
|
|
|
|
|
# Note that in the DftTools convention each site gives a separate correlated shell!
|
2019-06-28 15:14:12 +02:00
|
|
|
n_shells = sum([len(sh['ion_list']) for sh in p_shells])
|
2015-09-17 12:45:37 +02:00
|
|
|
n_corr_shells = sum([len(sh['ion_list']) for sh in p_shells])
|
|
|
|
|
2019-06-28 15:14:12 +02:00
|
|
|
shells = []
|
2015-09-17 12:45:37 +02:00
|
|
|
corr_shells = []
|
2020-04-08 21:35:59 +02:00
|
|
|
shion_to_shell = [[] for ish in range(len(p_shells))]
|
|
|
|
cr_shion_to_shell = [[] for ish in range(len(p_shells))]
|
|
|
|
shorbs_to_globalorbs = [[] for ish in range(len(p_shells))]
|
2019-07-02 11:00:21 +02:00
|
|
|
last_dimension = 0
|
2019-06-28 15:14:12 +02:00
|
|
|
crshorbs_to_globalorbs = []
|
2015-09-17 12:45:37 +02:00
|
|
|
icsh = 0
|
|
|
|
for ish, sh in enumerate(p_shells):
|
|
|
|
ion_list = sh['ion_list']
|
|
|
|
for i, ion in enumerate(ion_list):
|
|
|
|
pars = {}
|
|
|
|
pars['atom'] = ion
|
2015-11-10 19:16:41 +01:00
|
|
|
# We set all sites inequivalent
|
2018-05-04 16:10:36 +02:00
|
|
|
pars['sort'] = sh['ion_sort'][i]
|
2015-09-17 12:45:37 +02:00
|
|
|
pars['l'] = sh['lorb']
|
2019-07-01 11:34:34 +02:00
|
|
|
#pars['corr'] = sh['corr']
|
2015-09-17 12:45:37 +02:00
|
|
|
pars['dim'] = sh['ndim']
|
2019-07-02 11:00:21 +02:00
|
|
|
#pars['ion_list'] = sh['ion_list']
|
2015-09-17 12:45:37 +02:00
|
|
|
pars['SO'] = SO
|
|
|
|
# TODO: check what 'irep' entry does (it seems to be very specific to dmftproj)
|
|
|
|
pars['irep'] = 0
|
2019-06-28 15:14:12 +02:00
|
|
|
shells.append(pars)
|
2020-04-01 17:13:28 +02:00
|
|
|
shion_to_shell[ish].append(i)
|
2019-07-02 11:00:21 +02:00
|
|
|
shorbs_to_globalorbs[ish].append([last_dimension,
|
|
|
|
last_dimension+sh['ndim']])
|
|
|
|
last_dimension = last_dimension+sh['ndim']
|
2019-07-01 11:34:34 +02:00
|
|
|
if sh['corr']:
|
2019-06-28 15:14:12 +02:00
|
|
|
corr_shells.append(pars)
|
2019-07-02 11:00:21 +02:00
|
|
|
|
2019-07-02 14:06:12 +02:00
|
|
|
|
2015-09-21 20:18:37 +02:00
|
|
|
# TODO: generalize this to the case of multiple shell groups
|
2019-06-28 15:14:12 +02:00
|
|
|
n_corr_shells = len(corr_shells)
|
2019-07-02 11:00:21 +02:00
|
|
|
|
2019-07-01 10:51:33 +02:00
|
|
|
n_orbs = sum([sh['dim'] for sh in shells])
|
2019-07-03 11:16:30 +02:00
|
|
|
|
2015-09-17 12:45:37 +02:00
|
|
|
# FIXME: atomic sorts in Wien2K are not the same as in VASP.
|
|
|
|
# A symmetry analysis from OUTCAR or symmetry file should be used
|
|
|
|
# to define equivalence classes of sites.
|
|
|
|
n_inequiv_shells, corr_to_inequiv, inequiv_to_corr = ConverterTools.det_shell_equivalence(self, corr_shells)
|
|
|
|
|
2015-11-10 19:16:41 +01:00
|
|
|
if mpi.is_master_node():
|
2020-04-08 21:35:59 +02:00
|
|
|
print(" No. of inequivalent shells:", n_inequiv_shells)
|
2015-11-10 19:16:41 +01:00
|
|
|
|
2015-09-17 12:45:37 +02:00
|
|
|
# NB!: these rotation matrices are specific to Wien2K! Set to identity in VASP
|
2015-08-24 18:50:24 +02:00
|
|
|
use_rotations = 1
|
2023-01-23 21:40:57 +01:00
|
|
|
rot_mat = [numpy.identity(corr_shells[icrsh]['dim'],complex) for icrsh in range(n_corr_shells)]
|
2015-08-24 18:50:24 +02:00
|
|
|
rot_mat_time_inv = [0 for i in range(n_corr_shells)]
|
|
|
|
|
2015-09-17 12:45:37 +02:00
|
|
|
# TODO: implement transformation matrices
|
2015-08-24 18:50:24 +02:00
|
|
|
n_reps = [1 for i in range(n_inequiv_shells)]
|
|
|
|
dim_reps = [0 for i in range(n_inequiv_shells)]
|
|
|
|
T = []
|
|
|
|
for ish in range(n_inequiv_shells):
|
2015-09-17 12:45:37 +02:00
|
|
|
n_reps[ish] = 1 # Always 1 in VASP
|
|
|
|
ineq_first = inequiv_to_corr[ish]
|
2015-09-21 20:18:37 +02:00
|
|
|
dim_reps[ish] = [corr_shells[ineq_first]['dim']] # Just the dimension of the shell
|
2020-04-01 17:13:28 +02:00
|
|
|
|
2015-08-24 18:50:24 +02:00
|
|
|
# The transformation matrix:
|
|
|
|
# is of dimension 2l+1 without SO, and 2*(2l+1) with SO!
|
2015-09-17 12:45:37 +02:00
|
|
|
ll = 2 * corr_shells[inequiv_to_corr[ish]]['l']+1
|
2015-08-24 18:50:24 +02:00
|
|
|
lmax = ll * (corr_shells[inequiv_to_corr[ish]]['SO'] + 1)
|
2015-09-17 12:45:37 +02:00
|
|
|
# TODO: at the moment put T-matrices to identities
|
2023-01-23 21:40:57 +01:00
|
|
|
T.append(numpy.identity(lmax, complex))
|
2020-04-01 17:13:28 +02:00
|
|
|
|
2015-09-17 12:45:37 +02:00
|
|
|
# if nc_flag:
|
|
|
|
## TODO: implement the noncollinear part
|
|
|
|
# raise NotImplementedError("Noncollinear calculations are not implemented")
|
|
|
|
# else:
|
2023-01-23 21:40:57 +01:00
|
|
|
hopping = numpy.zeros([n_k, n_spin_blocs, nb_max, nb_max], complex)
|
|
|
|
f_weights = numpy.zeros([n_k, n_spin_blocs, nb_max], float)
|
2020-04-08 21:35:59 +02:00
|
|
|
band_window = [numpy.zeros((n_k, 2), dtype=int) for isp in range(n_spin_blocs)]
|
2023-01-23 21:40:57 +01:00
|
|
|
n_orbitals = numpy.zeros([n_k, n_spin_blocs], int)
|
2015-09-17 12:45:37 +02:00
|
|
|
|
2020-04-01 17:13:28 +02:00
|
|
|
|
2020-04-08 21:35:59 +02:00
|
|
|
for isp in range(n_spin_blocs):
|
|
|
|
for ik in range(n_k):
|
|
|
|
ib1, ib2 = int(next(rf)), int(next(rf))
|
2015-09-17 12:45:37 +02:00
|
|
|
band_window[isp][ik, :2] = ib1, ib2
|
|
|
|
nb = ib2 - ib1 + 1
|
|
|
|
n_orbitals[ik, isp] = nb
|
2020-04-08 21:35:59 +02:00
|
|
|
for ib in range(nb):
|
|
|
|
hopping[ik, isp, ib, ib] = next(rf)
|
|
|
|
f_weights[ik, isp, ib] = next(rf)
|
2020-04-01 17:13:28 +02:00
|
|
|
|
2019-07-01 10:51:33 +02:00
|
|
|
if self.proj_or_hk == 'hk':
|
2023-01-23 21:40:57 +01:00
|
|
|
hopping = numpy.zeros([n_k, n_spin_blocs, n_orbs, n_orbs], complex)
|
2019-07-01 10:51:33 +02:00
|
|
|
# skip header lines
|
|
|
|
hk_file = self.basename + '.hk%i'%(ig + 1)
|
|
|
|
f_hk = open(hk_file, 'rt')
|
|
|
|
# skip the header (1 line for n_kpoints, n_electrons, n_shells)
|
|
|
|
# and one line per shell
|
|
|
|
count = 0
|
|
|
|
while count < 3 + n_shells:
|
|
|
|
f_hk.readline()
|
|
|
|
count += 1
|
|
|
|
rf_hk = self.read_data(f_hk)
|
2020-04-08 21:35:59 +02:00
|
|
|
for isp in range(n_spin_blocs):
|
|
|
|
for ik in range(n_k):
|
2019-07-03 11:16:30 +02:00
|
|
|
n_orbitals[ik, isp] = n_orbs
|
2020-04-08 21:35:59 +02:00
|
|
|
for ib in range(n_orbs):
|
|
|
|
for jb in range(n_orbs):
|
|
|
|
hopping[ik, isp, ib, jb] = next(rf_hk)
|
|
|
|
for ib in range(n_orbs):
|
|
|
|
for jb in range(n_orbs):
|
|
|
|
hopping[ik, isp, ib, jb] += 1j*next(rf_hk)
|
2019-07-02 11:00:21 +02:00
|
|
|
rf_hk.close()
|
2015-09-17 12:45:37 +02:00
|
|
|
|
|
|
|
# Projectors
|
2015-10-22 20:13:58 +02:00
|
|
|
# print n_orbitals
|
|
|
|
# print [crsh['dim'] for crsh in corr_shells]
|
2023-01-23 21:40:57 +01:00
|
|
|
proj_mat_csc = numpy.zeros([n_k, n_spin_blocs, sum([sh['dim'] for sh in shells]), numpy.max(n_orbitals)], complex)
|
2019-07-02 14:06:12 +02:00
|
|
|
|
2015-09-17 12:45:37 +02:00
|
|
|
# TODO: implement reading from more than one projector group
|
|
|
|
# In 'dmftproj' each ion represents a separate correlated shell.
|
|
|
|
# In my interface a 'projected shell' includes sets of ions.
|
|
|
|
# How to reconcile this? Two options:
|
|
|
|
#
|
|
|
|
# 1. Redefine 'projected shell' in my interface to make it correspond to one site only.
|
|
|
|
# In this case the list of ions must be defined at the level of the projector group.
|
|
|
|
#
|
|
|
|
# 2. Split my 'projected shell' to several 'correlated shells' here in the converter.
|
|
|
|
#
|
|
|
|
# At the moment I choose i.2 for its simplicity. But one should consider possible
|
|
|
|
# use cases and decide which solution is to be made permanent.
|
2020-04-01 17:13:28 +02:00
|
|
|
#
|
2015-09-17 12:45:37 +02:00
|
|
|
for ish, sh in enumerate(p_shells):
|
2020-04-08 21:35:59 +02:00
|
|
|
for isp in range(n_spin_blocs):
|
|
|
|
for ik in range(n_k):
|
|
|
|
for ion in range(len(sh['ion_list'])):
|
|
|
|
for ilm in range(shorbs_to_globalorbs[ish][ion][0],shorbs_to_globalorbs[ish][ion][1]):
|
|
|
|
for ib in range(n_orbitals[ik, isp]):
|
2015-09-17 12:45:37 +02:00
|
|
|
# This is to avoid confusion with the order of arguments
|
2020-04-08 21:35:59 +02:00
|
|
|
pr = next(rf)
|
|
|
|
pi = next(rf)
|
2019-07-02 11:00:21 +02:00
|
|
|
proj_mat_csc[ik, isp, ilm, ib] = complex(pr, pi)
|
2019-06-28 15:14:12 +02:00
|
|
|
|
|
|
|
# now save only projectors with flag 'corr' to proj_mat
|
2023-01-23 21:40:57 +01:00
|
|
|
proj_mat = numpy.zeros([n_k, n_spin_blocs, n_corr_shells, max([crsh['dim'] for crsh in corr_shells]), numpy.max(n_orbitals)], complex)
|
2020-04-01 17:13:28 +02:00
|
|
|
if self.proj_or_hk == 'proj':
|
2019-07-02 11:00:21 +02:00
|
|
|
for ish, sh in enumerate(p_shells):
|
|
|
|
if sh['corr']:
|
2020-04-08 21:35:59 +02:00
|
|
|
for isp in range(n_spin_blocs):
|
|
|
|
for ik in range(n_k):
|
|
|
|
for ion in range(len(sh['ion_list'])):
|
2019-07-02 11:00:21 +02:00
|
|
|
icsh = shion_to_shell[ish][ion]
|
2020-04-08 21:35:59 +02:00
|
|
|
for iclm,ilm in enumerate(range(shorbs_to_globalorbs[ish][ion][0],shorbs_to_globalorbs[ish][ion][1])):
|
|
|
|
for ib in range(n_orbitals[ik, isp]):
|
2019-07-02 11:00:21 +02:00
|
|
|
proj_mat[ik,isp,icsh,iclm,ib] = proj_mat_csc[ik,isp,ilm,ib]
|
2019-07-01 10:51:33 +02:00
|
|
|
elif self.proj_or_hk == 'hk':
|
2019-07-02 14:06:12 +02:00
|
|
|
|
2019-07-02 11:00:21 +02:00
|
|
|
for ish, sh in enumerate(p_shells):
|
|
|
|
if sh['corr']:
|
2020-04-08 21:35:59 +02:00
|
|
|
for ion in range(len(sh['ion_list'])):
|
2019-07-02 11:00:21 +02:00
|
|
|
icsh = shion_to_shell[ish][ion]
|
2020-04-08 21:35:59 +02:00
|
|
|
for isp in range(n_spin_blocs):
|
|
|
|
for ik in range(n_k):
|
|
|
|
for iclm,ilm in enumerate(range(shorbs_to_globalorbs[ish][ion][0],shorbs_to_globalorbs[ish][ion][1])):
|
2019-07-02 11:00:21 +02:00
|
|
|
proj_mat[ik,isp,icsh,iclm,ilm] = 1.0
|
2019-07-02 14:06:12 +02:00
|
|
|
|
2019-07-02 11:00:21 +02:00
|
|
|
#corr_shell.pop('ion_list')
|
2020-04-01 17:13:28 +02:00
|
|
|
things_to_set = ['n_shells','shells','n_corr_shells','corr_shells','n_spin_blocs','n_orbitals','n_k','SO','SP','energy_unit']
|
2015-09-21 20:18:37 +02:00
|
|
|
for it in things_to_set:
|
2015-10-22 20:13:58 +02:00
|
|
|
# print "%s:"%(it), locals()[it]
|
2015-09-21 20:18:37 +02:00
|
|
|
setattr(self,it,locals()[it])
|
2015-08-24 18:50:24 +02:00
|
|
|
|
2019-07-02 14:06:12 +02:00
|
|
|
except StopIteration:
|
|
|
|
raise "VaspConverter: error reading %s"%self.gr_file
|
2015-09-17 12:45:37 +02:00
|
|
|
|
|
|
|
rf.close()
|
|
|
|
|
2019-07-02 11:10:08 +02:00
|
|
|
|
|
|
|
proj_or_hk = self.proj_or_hk
|
2020-04-01 17:13:28 +02:00
|
|
|
|
2015-08-24 18:50:24 +02:00
|
|
|
# Save it to the HDF:
|
2018-12-06 23:28:49 +01:00
|
|
|
with HDFArchive(self.hdf_file,'a') as ar:
|
2020-04-01 17:13:28 +02:00
|
|
|
if not (self.dft_subgrp in ar): ar.create_group(self.dft_subgrp)
|
2018-12-06 23:28:49 +01:00
|
|
|
# The subgroup containing the data. If it does not exist, it is created. If it exists, the data is overwritten!
|
|
|
|
things_to_save = ['energy_unit','n_k','k_dep_projection','SP','SO','charge_below','density_required',
|
2020-08-03 12:39:34 +02:00
|
|
|
'symm_op','n_shells','shells','n_corr_shells','corr_shells','use_rotations','rot_mat',
|
|
|
|
'rot_mat_time_inv','n_reps','dim_reps','T','n_orbitals','proj_mat','bz_weights',
|
|
|
|
'hopping','n_inequiv_shells', 'corr_to_inequiv', 'inequiv_to_corr','proj_or_hk',
|
|
|
|
'kpts','kpt_weights', 'kpt_basis']
|
|
|
|
if self.proj_or_hk == 'hk' or self.proj_or_hk == True:
|
2019-07-02 11:00:21 +02:00
|
|
|
things_to_save.append('proj_mat_csc')
|
2018-12-06 23:28:49 +01:00
|
|
|
for it in things_to_save: ar[self.dft_subgrp][it] = locals()[it]
|
2015-08-24 18:50:24 +02:00
|
|
|
|
2018-12-06 23:28:49 +01:00
|
|
|
# Store Fermi weights to 'dft_misc_input'
|
|
|
|
if not (self.misc_subgrp in ar): ar.create_group(self.misc_subgrp)
|
|
|
|
ar[self.misc_subgrp]['dft_fermi_weights'] = f_weights
|
2020-08-03 12:39:34 +02:00
|
|
|
ar[self.misc_subgrp]['kpts_cart'] = kpts_cart
|
2018-12-06 23:28:49 +01:00
|
|
|
ar[self.misc_subgrp]['band_window'] = band_window
|
2020-04-01 17:13:28 +02:00
|
|
|
|
2015-08-24 18:50:24 +02:00
|
|
|
# Symmetries are used, so now convert symmetry information for *correlated* orbitals:
|
2015-09-21 11:37:40 +02:00
|
|
|
self.convert_symmetry_input(ctrl_head, orbits=self.corr_shells, symm_subgrp=self.symmcorr_subgrp)
|
2018-12-06 23:28:49 +01:00
|
|
|
|
2015-09-21 11:37:40 +02:00
|
|
|
# TODO: Implement misc_input
|
|
|
|
# self.convert_misc_input(bandwin_file=self.bandwin_file,struct_file=self.struct_file,outputs_file=self.outputs_file,
|
|
|
|
# misc_subgrp=self.misc_subgrp,SO=self.SO,SP=self.SP,n_k=self.n_k)
|
2015-08-24 18:50:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
def convert_misc_input(self, bandwin_file, struct_file, outputs_file, misc_subgrp, SO, SP, n_k):
|
|
|
|
"""
|
|
|
|
Reads input for the band window from bandwin_file, which is case.oubwin,
|
|
|
|
structure from struct_file, which is case.struct,
|
|
|
|
symmetries from outputs_file, which is case.outputs.
|
2020-04-01 17:13:28 +02:00
|
|
|
|
2019-07-03 13:06:50 +02:00
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
bandwin_file : string
|
|
|
|
filename of .oubwin/up/dn file.
|
|
|
|
struct_file : string
|
|
|
|
filename of .struct file.
|
|
|
|
outputs_file : string
|
|
|
|
filename of .outputs file.
|
|
|
|
misc_subgrp : string
|
|
|
|
name of the subgroup in which to save
|
|
|
|
SO : boolean
|
|
|
|
spin-orbit switch
|
|
|
|
SP : int
|
|
|
|
spin
|
|
|
|
n_k : int
|
|
|
|
number of k-points
|
2020-04-01 17:13:28 +02:00
|
|
|
|
2015-08-24 18:50:24 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
if not (mpi.is_master_node()): return
|
|
|
|
things_to_save = []
|
|
|
|
|
|
|
|
# Read relevant data from .oubwin/up/dn files
|
|
|
|
#############################################
|
|
|
|
# band_window: Contains the index of the lowest and highest band within the
|
|
|
|
# projected subspace (used by dmftproj) for each k-point.
|
|
|
|
|
2015-09-21 12:10:07 +02:00
|
|
|
if (SP == 0 or SO == 1):
|
2015-08-24 18:50:24 +02:00
|
|
|
files = [self.bandwin_file]
|
|
|
|
elif SP == 1:
|
|
|
|
files = [self.bandwin_file+'up', self.bandwin_file+'dn']
|
|
|
|
else: # SO and SP can't both be 1
|
|
|
|
assert 0, "convert_transport_input: Reding oubwin error! Check SP and SO!"
|
2020-04-01 17:13:28 +02:00
|
|
|
|
2015-08-24 18:50:24 +02:00
|
|
|
band_window = [numpy.zeros((n_k, 2), dtype=int) for isp in range(SP + 1 - SO)]
|
|
|
|
for isp, f in enumerate(files):
|
|
|
|
if os.path.exists(f):
|
|
|
|
mpi.report("Reading input from %s..."%f)
|
|
|
|
R = ConverterTools.read_fortran_file(self, f, self.fortran_to_replace)
|
2020-04-08 21:35:59 +02:00
|
|
|
assert int(next(R)) == n_k, "convert_misc_input: Number of k-points is inconsistent in oubwin file!"
|
|
|
|
assert int(next(R)) == SO, "convert_misc_input: SO is inconsistent in oubwin file!"
|
|
|
|
for ik in range(n_k):
|
|
|
|
next(R)
|
|
|
|
band_window[isp][ik,0] = next(R) # lowest band
|
|
|
|
band_window[isp][ik,1] = next(R) # highest band
|
|
|
|
next(R)
|
2015-08-24 18:50:24 +02:00
|
|
|
things_to_save.append('band_window')
|
|
|
|
|
|
|
|
R.close() # Reading done!
|
|
|
|
|
|
|
|
# Read relevant data from .struct file
|
|
|
|
######################################
|
|
|
|
# lattice_type: bravais lattice type as defined by Wien2k
|
|
|
|
# lattice_constants: unit cell parameters in a. u.
|
|
|
|
# lattice_angles: unit cell angles in rad
|
|
|
|
|
|
|
|
if (os.path.exists(self.struct_file)):
|
|
|
|
mpi.report("Reading input from %s..."%self.struct_file)
|
2020-04-01 17:13:28 +02:00
|
|
|
|
2015-08-24 18:50:24 +02:00
|
|
|
with open(self.struct_file) as R:
|
|
|
|
try:
|
|
|
|
R.readline()
|
|
|
|
lattice_type = R.readline().split()[0]
|
|
|
|
R.readline()
|
|
|
|
temp = R.readline()
|
2015-10-22 20:13:58 +02:00
|
|
|
# print temp
|
2015-08-24 18:50:24 +02:00
|
|
|
lattice_constants = numpy.array([float(temp[0+10*i:10+10*i].strip()) for i in range(3)])
|
|
|
|
lattice_angles = numpy.array([float(temp[30+10*i:40+10*i].strip()) for i in range(3)]) * numpy.pi / 180.0
|
|
|
|
things_to_save.extend(['lattice_type', 'lattice_constants', 'lattice_angles'])
|
|
|
|
except IOError:
|
|
|
|
raise "convert_misc_input: reading file %s failed" %self.struct_file
|
|
|
|
|
|
|
|
# Read relevant data from .outputs file
|
|
|
|
#######################################
|
|
|
|
# rot_symmetries: matrix representation of all (space group) symmetry operations
|
2020-04-01 17:13:28 +02:00
|
|
|
|
2015-08-24 18:50:24 +02:00
|
|
|
if (os.path.exists(self.outputs_file)):
|
|
|
|
mpi.report("Reading input from %s..."%self.outputs_file)
|
2020-04-01 17:13:28 +02:00
|
|
|
|
2015-08-24 18:50:24 +02:00
|
|
|
rot_symmetries = []
|
|
|
|
with open(self.outputs_file) as R:
|
|
|
|
try:
|
|
|
|
while 1:
|
|
|
|
temp = R.readline().strip(' ').split()
|
|
|
|
if (temp[0] =='PGBSYM:'):
|
|
|
|
n_symmetries = int(temp[-1])
|
|
|
|
break
|
|
|
|
for i in range(n_symmetries):
|
|
|
|
while 1:
|
|
|
|
if (R.readline().strip().split()[0] == 'Symmetry'): break
|
|
|
|
sym_i = numpy.zeros((3, 3), dtype = float)
|
|
|
|
for ir in range(3):
|
|
|
|
temp = R.readline().strip().split()
|
|
|
|
for ic in range(3):
|
|
|
|
sym_i[ir, ic] = float(temp[ic])
|
|
|
|
R.readline()
|
|
|
|
rot_symmetries.append(sym_i)
|
|
|
|
things_to_save.extend(['n_symmetries', 'rot_symmetries'])
|
|
|
|
things_to_save.append('rot_symmetries')
|
|
|
|
except IOError:
|
|
|
|
raise "convert_misc_input: reading file %s failed" %self.outputs_file
|
|
|
|
|
|
|
|
# Save it to the HDF:
|
2018-12-06 23:28:49 +01:00
|
|
|
with HDFArchive(self.hdf_file,'a') as ar:
|
|
|
|
if not (misc_subgrp in ar): ar.create_group(misc_subgrp)
|
|
|
|
for it in things_to_save: ar[misc_subgrp][it] = locals()[it]
|
2015-08-24 18:50:24 +02:00
|
|
|
|
|
|
|
|
2015-09-21 11:37:40 +02:00
|
|
|
def convert_symmetry_input(self, ctrl_head, orbits, symm_subgrp):
|
2015-08-24 18:50:24 +02:00
|
|
|
"""
|
|
|
|
Reads input for the symmetrisations from symm_file, which is case.sympar or case.symqmc.
|
2020-04-01 17:13:28 +02:00
|
|
|
|
2019-07-03 13:06:50 +02:00
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
ctrl_head : dict
|
|
|
|
dictionary of header of .ctrl file
|
|
|
|
orbits : list of shells
|
2020-04-01 17:13:28 +02:00
|
|
|
contains all shells
|
2019-07-03 13:06:50 +02:00
|
|
|
symm_subgrp : name of symmetry group in h5 archive
|
2020-04-01 17:13:28 +02:00
|
|
|
|
2015-08-24 18:50:24 +02:00
|
|
|
"""
|
|
|
|
|
2015-09-21 11:37:40 +02:00
|
|
|
# In VASP interface the symmetries are read directly from *.ctrl file
|
|
|
|
# For the moment the symmetry parameters are just stubs
|
|
|
|
n_symm = 0
|
2015-09-21 20:18:37 +02:00
|
|
|
n_atoms = 1
|
|
|
|
perm = [0]
|
2015-08-24 18:50:24 +02:00
|
|
|
n_orbits = len(orbits)
|
2015-09-21 11:37:40 +02:00
|
|
|
SP = ctrl_head['ns']
|
|
|
|
SO = ctrl_head['nc_flag']
|
2015-09-21 20:18:37 +02:00
|
|
|
time_inv = [0]
|
|
|
|
mat = [numpy.identity(1)]
|
|
|
|
mat_tinv = [numpy.identity(1)]
|
2015-08-24 18:50:24 +02:00
|
|
|
|
|
|
|
# Save it to the HDF:
|
2018-12-06 23:28:49 +01:00
|
|
|
with HDFArchive(self.hdf_file,'a') as ar:
|
|
|
|
if not (symm_subgrp in ar): ar.create_group(symm_subgrp)
|
|
|
|
things_to_save = ['n_symm','n_atoms','perm','orbits','SO','SP','time_inv','mat','mat_tinv']
|
|
|
|
for it in things_to_save:
|
|
|
|
ar[symm_subgrp][it] = locals()[it]
|