## Learn to Use ITensor

# DMRG Calculation with Mixed Local Hilbert Space Types

The following fully-working example shows how to set up a calculation mixing S=1/2 and S=1 spins on every other site of a 1D system. The Hamiltonian involves Heisenberg spin interactions with adjustable couplings between sites of the same spin or different spin.

Note that the only difference from a regular ITensor DMRG calculation
is that the `sites`

array has Index objects which alternate in dimension
and in which physical tag type they carry, whether `"S=1/2"`

or `"S=1"`

.
(Try printing out the sites array to see!)
These tags tell the AutoMPO system which local operators to use for these
sites when building the Hamiltonian MPO.

```
using ITensors
let
N = 100
# Make an array of N Index objects with alternating
# "S=1/2" and "S=1" tags on odd versus even sites
# (The first argument n->isodd(n) ... is an
# on-the-fly function mapping integers to strings)
sites = siteinds(n->isodd(n) ? "S=1/2" : "S=1",N)
# Couplings between spin-half and
# spin-one sites:
Jho = 1.0 # half-one coupling
Jhh = 0.5 # half-half coupling
Joo = 0.5 # one-one coupling
ampo = AutoMPO()
for j=1:N-1
ampo += 0.5*Jho,"S+",j,"S-",j+1
ampo += 0.5*Jho,"S-",j,"S+",j+1
ampo += Jho,"Sz",j,"Sz",j+1
end
for j=1:2:N-2
ampo += 0.5*Jhh,"S+",j,"S-",j+2
ampo += 0.5*Jhh,"S-",j,"S+",j+2
ampo += Jhh,"Sz",j,"Sz",j+2
end
for j=2:2:N-2
ampo += 0.5*Joo,"S+",j,"S-",j+2
ampo += 0.5*Joo,"S-",j,"S+",j+2
ampo += Joo,"Sz",j,"Sz",j+2
end
H = MPO(ampo,sites)
sweeps = Sweeps(10)
maxdim!(sweeps,10,10,20,40,80,100,140,180,200)
cutoff!(sweeps,1E-8)
psi0 = randomMPS(sites,4)
energy,psi = dmrg(H,psi0,sweeps)
return
end
```

Back to Formulas

Back to Main