Skip to content

Commit 6da9abe

Browse files
committed
New chain correlation callback
1 parent 71cafe2 commit 6da9abe

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/molecules.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,24 @@ function compute_energy_particle(system::Molecules, i, neighbour_list::CellList)
166166
end
167167
end
168168
return energy_i
169+
end
170+
171+
function compute_chain_correlation(system::Molecules)
172+
chain_length = system.length_mol[1]
173+
@assert all(x -> x == chain_length, system.length_mol) "All chains must have the same length"
174+
@assert chain_length > 1 "Chains must have at least two particles"
175+
polymer_array = zeros(system.Nmol, chain_length)
176+
for i in 1:system.Nmol
177+
start = system.start_mol[i]
178+
polymer_array[i, :] = system.species[start:start+chain_length-1]
179+
end
180+
polymer_array[polymer_array .== 2] .= -1
181+
correlation_array = Float64[]
182+
for i in 1:chain_length-1
183+
for j in i+1:chain_length
184+
cross = sum(polymer_array[:, i] .* polymer_array[:, j]) / system.Nmol
185+
push!(correlation_array, cross)
186+
end
187+
end
188+
return sum(correlation_array.^2)
169189
end

src/utils.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ function callback_energy(simulation)
4848
return mean(system.energy[1] / length(system) for system in simulation.chains)
4949
end
5050

51+
function callback_chain_correlation(simulation)
52+
return mean(compute_chain_correlation(system) for system in simulation.chains)
53+
end
5154

5255
function volume_sphere(r, d::Int)
5356
d == 0 && return 1

0 commit comments

Comments
 (0)