From 5b16e53da9df5a4f51e61a0c03995a0d56b8e73e Mon Sep 17 00:00:00 2001 From: Romain Simon <93144534+romainljsimon@users.noreply.github.com> Date: Wed, 23 Apr 2025 11:19:15 +0200 Subject: [PATCH 1/4] Simplify molecule test --- test/molecules_test.jl | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/test/molecules_test.jl b/test/molecules_test.jl index 804cc27..f5084a0 100644 --- a/test/molecules_test.jl +++ b/test/molecules_test.jl @@ -14,25 +14,6 @@ Length = 3 d = 3 temperature = 2.0 density = 1.2 -box = @SVector fill(typeof(temperature)((N / density)^(1 / d)), d) -position_1 = [box .* @SVector rand(rng, d) for i in 1:Int(N // Length), m in 1:M] -position = [] -for r in position_1 - push!(position, r) - push!(position, r .+ @SVector [0.1, 0.1, 0.1]) - push!(position, r .- @SVector [0.1, 0.1, 0.1]) -end -position = Vector{SVector{3,Float64}}(position) -molecule = Vector{Int}() -species = Vector{Int}() -for i in 1:Int(N // Length) - push!(species, 1) - push!(species, 2) - push!(species, 3) - push!(molecule, i) - push!(molecule, i) - push!(molecule, i) -end function create_bond_matrix(N::Int) # Create a vector to store the SVectors, each containing a pair of integers @@ -45,12 +26,10 @@ function create_bond_matrix(N::Int) end return matrix end - +chains = load_chains("test/molecule.xyz", args=Dict("temperature" => [temperature], "model" => ["Trimer"], "list_type" => "LinkedList", "bonds" => create_bond_matrix(N))) model_matrix = Trimer() -bonds = create_bond_matrix(N) -chains = [System(position, species, molecule, density, temperature, model_matrix, bonds; list_type=LinkedList) for _ in 1:M] -## Define moves and combine them into a pool + pswap = 0.2 displacement_policy = SimpleGaussian() displacement_parameters = ComponentArray(σ=0.05) From 5f544306bff43a40f00f02a6e4bdb675afca501c Mon Sep 17 00:00:00 2001 From: Romain Simon <93144534+romainljsimon@users.noreply.github.com> Date: Wed, 23 Apr 2025 11:19:55 +0200 Subject: [PATCH 2/4] Add perform action wrapper --- src/moves.jl | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/moves.jl b/src/moves.jl index 305bb27..cfc499d 100644 --- a/src/moves.jl +++ b/src/moves.jl @@ -1,5 +1,16 @@ using ComponentArrays +function Arianna.perform_action!(system::Particles, action::Action) + e₁, e₂ = perform_action!(system, action) + if isinf(e₁) || isinf(e₂) + action.δe = zero(typeof(system.energy[1])) + else + action.δe = e₂ - e₁ + system.energy[1] += action.δe + end + return e₁, e₂ +end + ############################################################################### # SIMPLE DISPLACEMENT @@ -22,7 +33,7 @@ function update_position!(system::Particles, action::Displacement) @inbounds system.position[action.i] = system.position[action.i] + action.δ end -function Arianna.perform_action!(system::Particles, action::Displacement) +function perform_action!(system::Particles, action::Displacement) neighbour_list = get_neighbour_list(system) e₁ = destroy_particle!(system, action.i, neighbour_list) update_position!(system, action) @@ -32,7 +43,6 @@ function Arianna.perform_action!(system::Particles, action::Displacement) end e₂ = create_particle!(system, action.i, neighbour_list) action.δe = e₂ - e₁ - system.energy[1] += action.δe return e₁, e₂ end @@ -92,12 +102,11 @@ function update_species_list!(species_list, swap_species, i, j) species_list.sp_heads[i], species_list.sp_heads[j] = species_list.sp_heads[j], species_list.sp_heads[i] end -function Arianna.perform_action!(system::Particles, action::DiscreteSwap) +function perform_action!(system::Particles, action::DiscreteSwap) i, j = action.i, action.j spi, spj = get_species(system, i), get_species(system, j) e₁, e₂ = swap_particle_species!(system, spi, i, spj, j) action.δe = e₂ - e₁ - system.energy[1] += action.δe update_species_list!(system.species_list, action.species, i, j) return e₁, e₂ end @@ -157,12 +166,11 @@ mutable struct MoleculeFlip{F<:AbstractFloat} <: Action δe::F end -function Arianna.perform_action!(system::Particles, action::MoleculeFlip) +function perform_action!(system::Particles, action::MoleculeFlip) i, j = action.i, action.j spi, spj = system.species[i], system.species[j] e₁, e₂ = swap_particle_species!(system, spi, i, spj, j) action.δe = e₂ - e₁ - system.energy[1] += action.δe return e₁, e₂ end From f06a5e5fbe984b73d3131bb56f7f40ce6d05a39e Mon Sep 17 00:00:00 2001 From: Romain Simon <93144534+romainljsimon@users.noreply.github.com> Date: Wed, 23 Apr 2025 15:35:34 +0200 Subject: [PATCH 3/4] Trivie --- test/molecules_test.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/molecules_test.jl b/test/molecules_test.jl index f5084a0..9cb5006 100644 --- a/test/molecules_test.jl +++ b/test/molecules_test.jl @@ -26,6 +26,7 @@ function create_bond_matrix(N::Int) end return matrix end + chains = load_chains("test/molecule.xyz", args=Dict("temperature" => [temperature], "model" => ["Trimer"], "list_type" => "LinkedList", "bonds" => create_bond_matrix(N))) model_matrix = Trimer() @@ -34,7 +35,7 @@ pswap = 0.2 displacement_policy = SimpleGaussian() displacement_parameters = ComponentArray(σ=0.05) pool = ( - Move(Displacement(0, zero(box), 0.0), displacement_policy, displacement_parameters, 1.0), + Move(Displacement(0, zero(chains[1].box), 0.0), displacement_policy, displacement_parameters, 1.0), ) ## Define the simulation struct steps = 1000 From 9be5d72dbcf2c93eca28f3d82c6423a332bc20f0 Mon Sep 17 00:00:00 2001 From: Romain Simon <93144534+romainljsimon@users.noreply.github.com> Date: Thu, 24 Apr 2025 17:06:18 +0200 Subject: [PATCH 4/4] Infinite only for e2 --- src/moves.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/moves.jl b/src/moves.jl index cfc499d..2eeb88e 100644 --- a/src/moves.jl +++ b/src/moves.jl @@ -2,7 +2,7 @@ using ComponentArrays function Arianna.perform_action!(system::Particles, action::Action) e₁, e₂ = perform_action!(system, action) - if isinf(e₁) || isinf(e₂) + if isinf(e₂) action.δe = zero(typeof(system.energy[1])) else action.δe = e₂ - e₁