2014-11-08 23:51:24 +01:00
|
|
|
|
2016-05-09 10:19:56 +02:00
|
|
|
##########################################################################
|
2014-11-08 23:51:24 +01:00
|
|
|
#
|
|
|
|
# TRIQS: a Toolbox for Research in Interacting Quantum Systems
|
|
|
|
#
|
|
|
|
# Copyright (C) 2011 by M. Aichhorn
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
#
|
2016-05-09 10:19:56 +02:00
|
|
|
##########################################################################
|
2020-05-27 17:30:24 +02:00
|
|
|
import triqs.utility.mpi as mpi
|
2014-11-20 14:25:07 +01:00
|
|
|
|
2014-11-08 23:51:24 +01:00
|
|
|
class ConverterTools:
|
|
|
|
|
2016-05-05 16:32:16 +02:00
|
|
|
def __init__(self):
|
|
|
|
pass
|
|
|
|
|
2016-05-09 10:19:56 +02:00
|
|
|
def read_fortran_file(self, filename, to_replace):
|
2015-03-12 00:01:12 +01:00
|
|
|
"""
|
|
|
|
Returns a generator that yields all numbers in the Fortran file as float, with possible replacements.
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
filename : string
|
|
|
|
Name of Fortran-produced file.
|
|
|
|
to_replace : dict of str:str
|
|
|
|
Dictionary defining old_char:new_char.
|
2016-05-09 10:19:56 +02:00
|
|
|
|
2015-03-12 00:01:12 +01:00
|
|
|
Yields
|
|
|
|
------
|
|
|
|
string
|
|
|
|
The next number in file.
|
|
|
|
|
|
|
|
"""
|
2014-11-08 23:51:24 +01:00
|
|
|
import os.path
|
|
|
|
import string
|
2016-05-09 10:19:56 +02:00
|
|
|
if not(os.path.exists(filename)):
|
2020-04-08 21:35:59 +02:00
|
|
|
raise IOError("File %s does not exist." % filename)
|
2016-05-09 10:19:56 +02:00
|
|
|
for line in open(filename, 'r'):
|
2020-04-08 21:35:59 +02:00
|
|
|
for old, new in to_replace.items():
|
2016-05-09 10:19:56 +02:00
|
|
|
line = line.replace(old, new)
|
|
|
|
for x in line.split():
|
2020-04-08 21:57:21 +02:00
|
|
|
yield float(x)
|
2014-11-08 23:51:24 +01:00
|
|
|
|
2014-11-19 18:50:53 +01:00
|
|
|
def repack(self):
|
2015-03-12 00:01:12 +01:00
|
|
|
"""
|
|
|
|
Calls the h5repack routine in order to reduce the file size of the hdf5 archive.
|
|
|
|
|
|
|
|
Note
|
|
|
|
----
|
|
|
|
Should only be used before the first invokation of HDFArchive in the program,
|
|
|
|
otherwise the hdf5 linking will be broken.
|
|
|
|
|
|
|
|
"""
|
2014-11-08 23:51:24 +01:00
|
|
|
|
|
|
|
import subprocess
|
|
|
|
|
2016-05-09 10:19:56 +02:00
|
|
|
if not (mpi.is_master_node()):
|
|
|
|
return
|
|
|
|
mpi.report("Repacking the file %s" % self.hdf_file)
|
2014-11-08 23:51:24 +01:00
|
|
|
|
2016-05-09 10:19:56 +02:00
|
|
|
retcode = subprocess.call(
|
2018-01-22 23:34:20 +01:00
|
|
|
["h5repack", "-i%s" % self.hdf_file, "-otemphgfrt.h5"])
|
2014-11-19 18:50:53 +01:00
|
|
|
if retcode != 0:
|
2014-11-08 23:51:24 +01:00
|
|
|
mpi.report("h5repack failed!")
|
|
|
|
else:
|
2016-05-09 10:19:56 +02:00
|
|
|
subprocess.call(["mv", "-f", "temphgfrt.h5", "%s" % self.hdf_file])
|
2014-11-08 23:51:24 +01:00
|
|
|
|
2016-05-09 10:19:56 +02:00
|
|
|
def det_shell_equivalence(self, corr_shells):
|
2014-11-08 23:51:24 +01:00
|
|
|
"""
|
2015-03-12 00:01:12 +01:00
|
|
|
Determine the equivalence of correlated shells.
|
2014-11-08 23:51:24 +01:00
|
|
|
|
2015-03-12 00:01:12 +01:00
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
corr_shells : list of dicts
|
|
|
|
See documentation of necessary hdf5 elements.
|
2016-05-09 10:19:56 +02:00
|
|
|
|
2015-03-12 00:01:12 +01:00
|
|
|
Returns
|
|
|
|
-------
|
|
|
|
n_inequiv_shells : integer
|
|
|
|
Number of inequivalent shells.
|
|
|
|
corr_to_inequiv : list
|
|
|
|
Mapping between correlated shell index and inequivalent shell index.
|
|
|
|
corr_to_inequiv(i_corr_shells) = i_inequiv_shells
|
|
|
|
inequiv_to_corr : list
|
|
|
|
Mapping between inequivalent shell index and correlated shell index.
|
|
|
|
inequiv_to_corr(i_inequiv_shells) = i_corr_shells
|
|
|
|
|
|
|
|
Note
|
|
|
|
----
|
|
|
|
This is needed to set the self energies of all equivalent shells and to extract G_loc.
|
|
|
|
|
|
|
|
"""
|
2014-11-26 16:24:02 +01:00
|
|
|
corr_to_inequiv = [0 for i in range(len(corr_shells))]
|
2014-11-15 18:15:45 +01:00
|
|
|
inequiv_to_corr = [0]
|
|
|
|
n_inequiv_shells = 1
|
2014-11-26 16:24:02 +01:00
|
|
|
|
|
|
|
if len(corr_shells) > 1:
|
2016-05-09 10:19:56 +02:00
|
|
|
inequiv_sort = [corr_shells[0]['sort']]
|
|
|
|
inequiv_l = [corr_shells[0]['l']]
|
|
|
|
for i in range(len(corr_shells) - 1):
|
2014-11-26 16:24:02 +01:00
|
|
|
is_equiv = False
|
2014-11-15 18:15:45 +01:00
|
|
|
for j in range(n_inequiv_shells):
|
2016-05-09 10:19:56 +02:00
|
|
|
if (inequiv_sort[j] == corr_shells[i + 1]['sort']) and (inequiv_l[j] == corr_shells[i + 1]['l']):
|
2014-11-26 16:24:02 +01:00
|
|
|
is_equiv = True
|
2016-05-09 10:19:56 +02:00
|
|
|
corr_to_inequiv[i + 1] = j
|
|
|
|
if is_equiv == False:
|
|
|
|
corr_to_inequiv[i + 1] = n_inequiv_shells
|
2014-11-15 18:15:45 +01:00
|
|
|
n_inequiv_shells += 1
|
2016-05-09 10:19:56 +02:00
|
|
|
inequiv_sort.append(corr_shells[i + 1]['sort'])
|
|
|
|
inequiv_l.append(corr_shells[i + 1]['l'])
|
|
|
|
inequiv_to_corr.append(i + 1)
|
2014-11-15 18:15:45 +01:00
|
|
|
|
2014-11-26 16:24:02 +01:00
|
|
|
return n_inequiv_shells, corr_to_inequiv, inequiv_to_corr
|