forked from SebWouters/CheMPS2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest9.py
125 lines (110 loc) · 4.8 KB
/
test9.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#
# CheMPS2: a spin-adapted implementation of DMRG for ab initio quantum chemistry
# Copyright (C) 2013-2018 Sebastian Wouters
#
# This program 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 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
import numpy as np
import sys
import PyCheMPS2
import ctypes
# Set the seed of the random number generator and cout.precision
Initializer = PyCheMPS2.PyInitialize()
Initializer.Init()
########################################
### Square 2D Hubbard model with PBC ###
########################################
L_linear = 3 # Linear size
L_square = L_linear * L_linear # Number of orbitals
group = 0 # C1 symmetry
U = 5.0 # On-site repulsion
T = -1.0 # Hopping term
Nelec = 9 # Number of electrons
TwoS = 1 # Two times the spin
Irrep = 0 # Irrep = A (C1 symmetry)
# The Hamiltonian initializes all its matrix elements to 0.0
orbirreps = np.zeros([L_square], dtype=ctypes.c_int)
Ham = PyCheMPS2.PyHamiltonian(L_square, group, orbirreps)
# Fill with the site-basis matrix elements
for orb in range(L_square):
Ham.setVmat(orb,orb,orb,orb,U)
for ix in range(L_linear):
for iy in range(L_linear):
idx1 = ix + L_linear * iy # This site
idx2 = (( ix + 1 ) % L_linear) + L_linear * iy # Right neighbour (PBC)
idx3 = ix + L_linear * ((( iy + 1 ) % L_linear)) # Upper neighbour (PBC)
Ham.setTmat(idx1,idx2,T)
Ham.setTmat(idx1,idx3,T)
# Setting up the Problem
Prob = PyCheMPS2.PyProblem(Ham, TwoS, Nelec, Irrep)
# Setting up the ConvergenceScheme
# setInstruction(instruction, D, Econst, maxSweeps, noisePrefactor)
OptScheme = PyCheMPS2.PyConvergenceScheme(2) # 2 instructions
OptScheme.setInstruction(0, 500, 1e-10, 3, 0.05)
OptScheme.setInstruction(1, 1000, 1e-10, 10, 0.0 )
# Run ground state calculation
theDMRG = PyCheMPS2.PyDMRG(Prob, OptScheme)
EnergySite = theDMRG.Solve()
theDMRG.calc2DMandCorrelations()
# Clean-up DMRG
# theDMRG.deleteStoredMPS()
theDMRG.deleteStoredOperators()
del theDMRG
#################################################################################################################
### Hack: overwrite the matrix elements in momentum space (4-fold symmetry!!!) directly in the Problem object ###
#################################################################################################################
theDMRG = PyCheMPS2.PyDMRG(Prob, OptScheme) # Prob->construct_mxelem() is called in DMRG constructor
for orb1 in range(L_square):
k1x = orb1 % L_linear
k1y = orb1 / L_linear
Telem1 = 2*T*(np.cos((2*np.pi*k1x)/L_linear) + np.cos((2*np.pi*k1y)/L_linear))
for orb2 in range(L_square):
k2x = orb2 % L_linear
k2y = orb2 / L_linear
Telem2 = 2*T*(np.cos((2*np.pi*k2x)/L_linear) + np.cos((2*np.pi*k2y)/L_linear))
for orb3 in range(L_square):
k3x = orb3 % L_linear
k3y = orb3 / L_linear
for orb4 in range(L_square):
k4x = orb4 % L_linear
k4y = orb4 / L_linear
kx_conservation = False
if (((k1x+k2x) % L_linear) == ((k3x+k4x) % L_linear)):
kx_conservation = True
ky_conservation = False
if (((k1y+k2y) % L_linear) == ((k3y+k4y) % L_linear)):
ky_conservation = True
temp = 0.0
if ( kx_conservation and ky_conservation ):
temp += U/L_square
if (( orb1 == orb3 ) and ( orb2 == orb4 )):
temp += (Telem1+Telem2)/(Nelec-1)
Prob.setMxElement(orb1,orb2,orb3,orb4,temp)
theDMRG.PreSolve() # New matrix elements require reconstruction of complementary renormalized operators
EnergyMomentum = theDMRG.Solve()
theDMRG.calc2DMandCorrelations()
# Clean-up
# theDMRG.deleteStoredMPS()
theDMRG.deleteStoredOperators()
del theDMRG
del OptScheme
del Prob
del Ham
del Initializer
# Check whether the test succeeded
if (np.fabs(EnergySite - EnergyMomentum) < 1e-8):
print("================> Did test 9 succeed : yes")
else:
print("================> Did test 9 succeed : no")