3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-22 04:13:47 +01:00

Moved hamiltonians and set_operator_structure to pytriqs/operators.

Also cleaned up tests accordingly.
This commit is contained in:
Priyanka Seth 2014-09-27 00:10:30 +02:00
parent 17d58aacb4
commit cd64a89311
4 changed files with 3 additions and 180 deletions

View File

@ -25,11 +25,9 @@ from symmetry import Symmetry
from sumk_lda_tools import SumkLDATools from sumk_lda_tools import SumkLDATools
from U_matrix import * from U_matrix import *
from converters import * from converters import *
from hamiltonians import *
__all__=['SumkLDA','Symmetry','SumkLDATools','Wien2kConverter','HkConverter', __all__=['SumkLDA','Symmetry','SumkLDATools','Wien2kConverter','HkConverter',
'U_J_to_radial_integrals', 'U_matrix', 'U_matrix_kanamori', 'U_J_to_radial_integrals', 'U_matrix', 'U_matrix_kanamori',
'angular_matrix_element', 'clebsch_gordan', 'cubic_names', 'eg_submatrix', 'angular_matrix_element', 'clebsch_gordan', 'cubic_names', 'eg_submatrix',
'reduce_4index_to_2index', 'spherical_to_cubic', 't2g_submatrix', 'reduce_4index_to_2index', 'spherical_to_cubic', 't2g_submatrix',
'three_j_symbol', 'transform_U_matrix', 'three_j_symbol', 'transform_U_matrix']
'h_loc_slater','h_loc_kanamori','h_loc_density','get_mkind']

View File

@ -1,127 +0,0 @@
from pytriqs.operators.operators2 import *
from itertools import product
# Define commonly-used Hamiltonians here: Slater, Kanamori, density-density
def h_loc_slater(spin_names,orb_names,orb_hyb,U_matrix,H_dump=None):
if H_dump:
H_dump_file = open(H_dump,'w')
H = Operator()
mkind = get_mkind(orb_hyb)
for s1, s2 in product(spin_names,spin_names):
for a1, a2, a3, a4 in product(orb_names,orb_names,orb_names,orb_names):
U_val = U_matrix[orb_names.index(a1),orb_names.index(a2),orb_names.index(a3),orb_names.index(a4)]
if abs(U_val.imag) > 1e-10:
raise RuntimeError("Matrix elements of U are not real. Are you using a cubic basis?")
H_term = 0.5 * U_val.real * c_dag(*mkind(s1,a1)) * c_dag(*mkind(s2,a2)) * c(*mkind(s2,a4)) * c(*mkind(s1,a3))
H += H_term
# Dump terms of H
if H_dump and not H_term.is_zero():
H_dump_file.write(mkind(s1,a1)[0] + '\t')
H_dump_file.write(mkind(s2,a2)[0] + '\t')
H_dump_file.write(mkind(s2,a3)[0] + '\t')
H_dump_file.write(mkind(s1,a4)[0] + '\t')
H_dump_file.write(str(U_val.real) + '\n')
return H
def h_loc_kanamori(spin_names,orb_names,orb_hyb,U,Uprime,J_hund,H_dump=None):
if H_dump:
H_dump_file = open(H_dump,'w')
H = Operator()
mkind = get_mkind(orb_hyb)
# density terms:
for s1, s2 in product(spin_names,spin_names):
for a1, a2 in product(orb_names,orb_names):
if (s1==s2):
U_val = U[orb_names.index(a1),orb_names.index(a2)]
else:
U_val = Uprime[orb_names.index(a1),orb_names.index(a2)]
H_term = 0.5 * U_val * n(*mkind(s1,a1)) * n(*mkind(s2,a2))
H += H_term
# Dump terms of H
if H_dump and not H_term.is_zero():
H_dump_file.write("Density-density terms" + '\n')
H_dump_file.write(mkind(s1,a1)[0] + '\t')
H_dump_file.write(mkind(s2,a2)[0] + '\t')
H_dump_file.write(str(U_val) + '\n')
# spin-flip terms:
for s1, s2 in product(spin_names,spin_names):
if (s1==s2):
continue
for a1, a2 in product(orb_names,orb_names):
if (a1==a2):
continue
H_term = -0.5 * J_hund * c_dag(*mkind(s1,a1)) * c(*mkind(s2,a1)) * c_dag(*mkind(s2,a2)) * c(*mkind(s1,a2))
H += H_term
# Dump terms of H
if H_dump and not H_term.is_zero():
H_dump_file.write("Spin-flip terms" + '\n')
H_dump_file.write(mkind(s1,a1)[0] + '\t')
H_dump_file.write(mkind(s2,a2)[0] + '\t')
H_dump_file.write(mkind(s2,a3)[0] + '\t')
H_dump_file.write(mkind(s1,a4)[0] + '\t')
H_dump_file.write(str(-J_hund) + '\n')
# pair-hopping terms:
for s1, s2 in product(spin_names,spin_names):
if (s1==s2):
continue
for a1, a2 in product(orb_names,orb_names):
if (a1==a2):
continue
H_term = 0.5 * J_hund * c_dag(*mkind(s1,a1)) * c_dag(*mkind(s2,a1)) * c(*mkind(s2,a2)) * c(*mkind(s1,a2))
H += H_term
# Dump terms of H
if H_dump and not H_term.is_zero():
H_dump_file.write("Pair-hopping terms" + '\n')
H_dump_file.write(mkind(s1,a1)[0] + '\t')
H_dump_file.write(mkind(s2,a2)[0] + '\t')
H_dump_file.write(mkind(s2,a3)[0] + '\t')
H_dump_file.write(mkind(s1,a4)[0] + '\t')
H_dump_file.write(str(-J_hund) + '\n')
return H
def h_loc_density(spin_names,orb_names,orb_hyb,U,Uprime,H_dump=None):
if H_dump:
H_dump_file = open(H_dump,'w')
H = Operator()
mkind = get_mkind(orb_hyb)
for s1, s2 in product(spin_names,spin_names):
for a1, a2 in product(orb_names,orb_names):
if (s1==s2):
U_val = U[orb_names.index(a1),orb_names.index(a2)]
else:
U_val = Uprime[orb_names.index(a1),orb_names.index(a2)]
H_term = 0.5 * U_val * n(*mkind(s1,a1)) * n(*mkind(s2,a2))
H += H_term
# Dump terms of H
if H_dump and not H_term.is_zero():
H_dump_file.write(mkind(s1,a1)[0] + '\t')
H_dump_file.write(mkind(s2,a2)[0] + '\t')
H_dump_file.write(str(U_val) + '\n')
return H
# Set function to make index for GF blocks given spin sn and orbital name on
def get_mkind(orb_hyb):
if orb_hyb:
mkind = lambda sn, on: (sn, on)
else:
mkind = lambda sn, on: (sn+'_'+on, 0)
return mkind

View File

@ -1,41 +0,0 @@
from itertools import product
from hamiltonians import *
class LocalProblem():
def __init__(self,spin_names,orb_names,orb_hyb,h_loc_type,**h_loc_params):
self.spin_names = spin_names
self.orb_names = orb_names
self.orb_hyb = orb_hyb
self.h_loc_type = h_loc_type
self.h_loc_params = h_loc_params
self.gf_struct = self.get_gf_struct()
self.h_loc = self.get_h_loc()
# Set block structure of GF
def get_gf_struct(self):
gf_struct = {}
if self.orb_hyb: # outer blocks are spin blocks
for sn in self.spin_names:
gf_struct[sn] = [int(i) for i in self.orb_names]
else: # outer blocks are spin-orbital blocks
for sn, an in product(self.spin_names,self.orb_names):
gf_struct[sn+'_'+an] = [0]
return gf_struct
# Pick desired Hamiltonian
def get_h_loc(self):
if self.h_loc_type == "slater":
return h_loc_slater(self.spin_names,self.orb_names,self.orb_hyb,**self.h_loc_params) # h_loc_params must include U_matrix, and optionally H_dump
elif self.h_loc_type == "kanamori":
return h_loc_kanamori(self.spin_names,self.orb_names,self.orb_hyb,**self.h_loc_params) # h_loc_params must include U, Uprime, J_hund, and optionally H_dump
elif self.h_loc_type == "density":
return h_loc_density(self.spin_names,self.orb_names,self.orb_hyb,**self.h_loc_params) # h_loc_params must include U, Uprime, and optionally H_dump
elif self.h_loc_type == "other":
return self.h_loc_params["h_loc"] # user provides h_loc with argument h_loc
else:
raise RuntimeError("Hamiltonian type not implemented.")

View File

@ -22,13 +22,10 @@
from pytriqs.archive import * from pytriqs.archive import *
from pytriqs.applications.dft.sumk_lda import * from pytriqs.applications.dft.sumk_lda import *
from pytriqs.applications.dft.converters.wien2k_converter import * from pytriqs.applications.dft.converters.wien2k_converter import *
from pytriqs.applications.dft.solver_multiband import *
from pytriqs.applications.dft.U_matrix import *
from pytriqs.applications.impurity_solvers.cthyb import * from pytriqs.applications.impurity_solvers.cthyb import *
from pytriqs.operators.hamiltonians import set_operator_structure
# Basic input parameters # Basic input parameters
U = 4.0
J = 0.6
beta = 40 beta = 40
# Init the SumK class # Init the SumK class
@ -40,11 +37,7 @@ spin_names = ["up","down"]
orb_names = ["%s"%i for i in range(num_orbitals)] orb_names = ["%s"%i for i in range(num_orbitals)]
orb_hybridized = False orb_hybridized = False
# Construct U matrix for density-density calculations S = Solver(beta=beta, gf_struct=set_operator_structure(spin_names,orb_names,orb_hybridized))
Umat, Upmat = U_matrix_kanamori(n_orb=num_orbitals, U_int=U, J_hund=J)
L = LocalProblem(spin_names, orb_names, orb_hybridized, h_loc_type="density", U=Umat, Uprime=Upmat, H_dump="srvo3_Gloc_H.txt" )
S = Solver(beta=beta, gf_struct=L.gf_struct)
SK.put_Sigma([S.Sigma_iw]) SK.put_Sigma([S.Sigma_iw])
Gloc=SK.extract_G_loc() Gloc=SK.extract_G_loc()