-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hamiltonian.jl
58 lines (46 loc) · 1.58 KB
/
Hamiltonian.jl
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
using AlgebraicPetri
using LinearAlgebra
function periodicHamiltonian(pn::AbstractLabelledReactionNet; rev=false)
tm = TransitionMatrices(pn)
scc = tm.output - tm.input
r = rates(pn)
c = concentrations(pn)
function H(k::Vector{Float64})
n = 2^rank(scc)
H = zeros(Complex{Float64}, n, n)
for i in 1:nt(pn)
for j in 1:n
H[j,j] -= r[i] * prod(c[k]^tm.input[i,k] for k in 1:ns(pn))
end
end
for i in 1:rank(scc)
for j in findall(x->(1<= x%(2^i) <= 2^(i-1)), collect(1:n))
H[j,j+2^(i-1)] += r[i] * prod(c[k]^tm.input[i,k] for k in 1:ns(pn))
H[j+2^(i-1),j] += r[i] * prod(c[k]^tm.input[i,k] for k in 1:ns(pn)) * exp(im*k[i])
end
if rev
rev_i = i + rank(scc)
for j in findall(x->(1<= x%(2^i) <= 2^(i-1)), collect(1:n))
H[j+2^(i-1), j] += r[rev_i] * prod(c[k]^tm.input[rev_i,k] for k in 1:ns(pn))
H[j, j+2^(i-1)] += r[rev_i] * prod(c[k]^tm.input[rev_i,k] for k in 1:ns(pn)) * exp(-im*k[i])
end
end
end
return H
end
return H
end
function bandplot(H, n::Int64)
k = collect(-π:0.01:π)
f(k, i) = begin
arg = zeros(n)
arg[1] += k
eigvals(H(arg))[i]
end
p = plot3d(k, real.(f.(k,1)), imag.(f.(k,1)), xlims=[-π, π])
for i in 2:2^n
plot3d!(p, k, real.(f.(k,i)), imag.(f.(k,i)), xlims=[-π, π])
end
p
# TODO: complex eigenvalue plotting
end