# Constructing an Mixed Unit-cell with three or more spins (Julia Version)

+1 vote

Hello ITensors team !

I'm trying to construct an ferrimagnetic model with three magnetic centers (1/2- 5/2 - 1/2) which interact through the Heisenberg Hamiltonian. I know its possibile to implement the S=5/2 operators, but i'm facing some errors when try to construct the siteinds like this :

site = siteinds(n->isodd(n) ? "S=1/2" : "S=5/2" : "S=1/2", N; conserve_qns=true)

With the following error :

"
ERROR: MethodError: no method matching zero(::String)
Closest candidates are:
zero(!Matched::Union{Type{P}, P}) where P<:Dates.Period at /buildworker/worker/packagelinux64/build/usr/share/julia/stdlib/v1.6/Dates/src/periods.jl:53
zero(!Matched::AbstractIrrational) at irrationals.jl:148
zero(!Matched::T) where T<:Dates.TimeType at /buildworker/worker/package
linux64/build/usr/share/julia/stdlib/v1.6/Dates/src/types.jl:423 "

So my question is, in general how can us construct an general unit-cell(more than 2 spins, mixed spins types) to construct an MPO correctly them perform an dmrg calculation ?

Thanks for any help !

+1 vote

Hi, thanks for the question. So I think the main problem is that

isodd(n) ? "S=1/2" : "S=5/2" : "S=1/2"

is not valid Julia syntax. Did you mean

isodd(n) ? "S=1/2" : "S=5/2"

commented by (340 points)
Hi Miles, thank you for the reply.

Yes, works only with 2 spins in an unit-cell. But i'm asking about an system with three spins in magnetic cell, i mean [ ...(s-S-s)-(s-S-s)...] structure. This is why i tried use three elements in siteinds syntax.
Using only two spins( isodd(n) ? "S=1/2" : "S=5/2") i can reproduce any cell, even with more then 2 elements of spins s=1/2 or S=5/2 ?

Again, Thank you !
commented by (70.1k points)
Hi Luis,
I see, thanks for clarifying - so what you need then is a function which will return various values based on a 3-site periodicity, and so using an inline if-else (? : ) type approach is going to be cumbersome.

Here is one solution that ought to work (I'd also suggest you double-check me and write a loop over n and print out the value of site_type(n) to verify and test it before using it inside of siteinds as I do below):

function site_type(n::Int)
if mod(n,3)==2
return "S=5/2"
else
return "S=1/2"
end
end

site = siteinds(n -> site_type(n), N; conserve_qns=true)

Hope that gives you what you need!

Best,
Miles
commented by (340 points)
Hello Miles,

yes works using this function structure, thank you !