2014-11-15 18:15:45 +01:00
|
|
|
from pytriqs.archive import HDFArchive
|
2014-11-03 14:47:55 +01:00
|
|
|
import h5py
|
|
|
|
import sys
|
|
|
|
import numpy
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
if len(sys.argv) < 2:
|
|
|
|
print "Usage: python update_archive.py old_archive"
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
print """
|
|
|
|
This script is an attempt to update your archive to TRIQS 1.2.
|
|
|
|
Please keep a copy of your old archive as this script is
|
|
|
|
** not guaranteed ** to work for your archive.
|
|
|
|
If you encounter any problem please report it on github!
|
|
|
|
"""
|
|
|
|
|
2014-11-15 18:15:45 +01:00
|
|
|
def det_shell_equivalence(lst):
|
|
|
|
corr_to_inequiv = [0 for i in range(len(lst))]
|
|
|
|
inequiv_to_corr = [0]
|
|
|
|
n_inequiv_shells = 1
|
|
|
|
tmp = [ lst[0][1:3] ]
|
|
|
|
if (len(lst)>1):
|
|
|
|
for i in range(len(lst)-1):
|
|
|
|
fnd = False
|
|
|
|
for j in range(n_inequiv_shells):
|
|
|
|
if (tmp[j]==lst[i+1][1:3]):
|
|
|
|
fnd = True
|
|
|
|
corr_to_inequiv[i+1] = j
|
|
|
|
if (fnd==False):
|
|
|
|
corr_to_inequiv[i+1] = n_inequiv_shells
|
|
|
|
n_inequiv_shells += 1
|
|
|
|
tmp.append( lst[i+1][1:3] )
|
|
|
|
inequiv_to_corr.append(i+1)
|
|
|
|
return [n_inequiv_shells, corr_to_inequiv, inequiv_to_corr]
|
|
|
|
|
|
|
|
### Main ###
|
|
|
|
|
2014-11-03 14:47:55 +01:00
|
|
|
filename = sys.argv[1]
|
|
|
|
A = h5py.File(filename)
|
|
|
|
|
2014-11-14 18:13:43 +01:00
|
|
|
# Rename groups
|
2014-11-18 11:30:26 +01:00
|
|
|
old_to_new = {'SumK_LDA':'dft_input', 'SumK_LDA_ParProj':'dft_parproj_input',
|
|
|
|
'SymmCorr':'dft_symmcorr_input', 'SymmPar':'dft_symmpar_input', 'SumK_LDA_Bands':'dft_bands_input'}
|
2014-11-03 14:47:55 +01:00
|
|
|
|
|
|
|
for old, new in old_to_new.iteritems():
|
|
|
|
if old not in A.keys(): continue
|
|
|
|
print "Changing %s to %s ..."%(old, new)
|
|
|
|
A.copy(old,new)
|
|
|
|
del(A[old])
|
2014-11-07 00:55:40 +01:00
|
|
|
|
2014-11-18 11:30:26 +01:00
|
|
|
# Move output items from dft_input to dft_output
|
2014-11-07 00:55:40 +01:00
|
|
|
move_to_output = ['gf_struct_solver','map_inv','map',
|
|
|
|
'chemical_potential','dc_imp','dc_energ','deg_shells',
|
|
|
|
'h_field']
|
|
|
|
for obj in move_to_output:
|
2014-11-18 11:30:26 +01:00
|
|
|
if obj in A['dft_input'].keys():
|
|
|
|
if not 'dft_output' in A: A.create_group('dft_output')
|
|
|
|
print "Moving %s to dft_output ..."%obj
|
|
|
|
A.copy('dft_input/'+obj,'dft_output/'+obj)
|
|
|
|
del(A['dft_input'][obj])
|
2014-11-07 00:55:40 +01:00
|
|
|
|
2014-11-15 18:15:45 +01:00
|
|
|
# Add shell equivalency quantities
|
2014-11-18 11:30:26 +01:00
|
|
|
B = A['dft_input']
|
|
|
|
corr_shells = HDFArchive(filename,'r')['dft_input']['corr_shells']
|
2014-11-15 18:15:45 +01:00
|
|
|
equiv_shell_info = det_shell_equivalence(corr_shells)
|
|
|
|
B['n_inequiv_shells'] = equiv_shell_info[0]
|
|
|
|
B['corr_to_inequiv'] = equiv_shell_info[1]
|
|
|
|
B['inequiv_to_corr'] = equiv_shell_info[2]
|
|
|
|
|
2014-11-14 18:13:43 +01:00
|
|
|
# Rename variables
|
2014-11-18 11:30:26 +01:00
|
|
|
groups = ['dft_symmcorr_input','dft_symmpar_input']
|
2014-11-14 18:13:43 +01:00
|
|
|
|
|
|
|
for group in groups:
|
|
|
|
if group not in A.keys(): continue
|
|
|
|
print "Changing n_s to n_symm ..."
|
|
|
|
A[group].move('n_s','n_symm')
|
|
|
|
|
2014-11-03 14:47:55 +01:00
|
|
|
A.close()
|
|
|
|
|
|
|
|
# Repack to reclaim disk space
|
|
|
|
retcode = subprocess.call(["h5repack","-i%s"%filename, "-otemphgfrt.h5"])
|
|
|
|
if retcode != 0:
|
|
|
|
print "h5repack failed!"
|
|
|
|
else:
|
|
|
|
subprocess.call(["mv","-f","temphgfrt.h5","%s"%filename])
|