Skip to content

Commit 8009dd6

Browse files
Merge pull request #39 from TheDisorderedOrganization/nanenergy
Infinite energy
2 parents 25d1492 + 9be5d72 commit 8009dd6

2 files changed

Lines changed: 17 additions & 29 deletions

File tree

src/moves.jl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
using ComponentArrays
22

3+
function Arianna.perform_action!(system::Particles, action::Action)
4+
e₁, e₂ = perform_action!(system, action)
5+
if isinf(e₂)
6+
action.δe = zero(typeof(system.energy[1]))
7+
else
8+
action.δe = e₂ - e₁
9+
system.energy[1] += action.δe
10+
end
11+
return e₁, e₂
12+
end
13+
314
###############################################################################
415
# SIMPLE DISPLACEMENT
516

@@ -22,7 +33,7 @@ function update_position!(system::Particles, action::Displacement)
2233
@inbounds system.position[action.i] = system.position[action.i] + action.δ
2334
end
2435

25-
function Arianna.perform_action!(system::Particles, action::Displacement)
36+
function perform_action!(system::Particles, action::Displacement)
2637
neighbour_list = get_neighbour_list(system)
2738
e₁ = destroy_particle!(system, action.i, neighbour_list)
2839
update_position!(system, action)
@@ -32,7 +43,6 @@ function Arianna.perform_action!(system::Particles, action::Displacement)
3243
end
3344
e₂ = create_particle!(system, action.i, neighbour_list)
3445
action.δe = e₂ - e₁
35-
system.energy[1] += action.δe
3646
return e₁, e₂
3747
end
3848

@@ -92,12 +102,11 @@ function update_species_list!(species_list, swap_species, i, j)
92102
species_list.sp_heads[i], species_list.sp_heads[j] = species_list.sp_heads[j], species_list.sp_heads[i]
93103
end
94104

95-
function Arianna.perform_action!(system::Particles, action::DiscreteSwap)
105+
function perform_action!(system::Particles, action::DiscreteSwap)
96106
i, j = action.i, action.j
97107
spi, spj = get_species(system, i), get_species(system, j)
98108
e₁, e₂ = swap_particle_species!(system, spi, i, spj, j)
99109
action.δe = e₂ - e₁
100-
system.energy[1] += action.δe
101110
update_species_list!(system.species_list, action.species, i, j)
102111
return e₁, e₂
103112
end
@@ -157,12 +166,11 @@ mutable struct MoleculeFlip{F<:AbstractFloat} <: Action
157166
δe::F
158167
end
159168

160-
function Arianna.perform_action!(system::Particles, action::MoleculeFlip)
169+
function perform_action!(system::Particles, action::MoleculeFlip)
161170
i, j = action.i, action.j
162171
spi, spj = system.species[i], system.species[j]
163172
e₁, e₂ = swap_particle_species!(system, spi, i, spj, j)
164173
action.δe = e₂ - e₁
165-
system.energy[1] += action.δe
166174
return e₁, e₂
167175
end
168176

test/molecules_test.jl

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,6 @@ Length = 3
1414
d = 3
1515
temperature = 2.0
1616
density = 1.2
17-
box = @SVector fill(typeof(temperature)((N / density)^(1 / d)), d)
18-
position_1 = [box .* @SVector rand(rng, d) for i in 1:Int(N // Length), m in 1:M]
19-
position = []
20-
for r in position_1
21-
push!(position, r)
22-
push!(position, r .+ @SVector [0.1, 0.1, 0.1])
23-
push!(position, r .- @SVector [0.1, 0.1, 0.1])
24-
end
25-
position = Vector{SVector{3,Float64}}(position)
26-
molecule = Vector{Int}()
27-
species = Vector{Int}()
28-
for i in 1:Int(N // Length)
29-
push!(species, 1)
30-
push!(species, 2)
31-
push!(species, 3)
32-
push!(molecule, i)
33-
push!(molecule, i)
34-
push!(molecule, i)
35-
end
3617

3718
function create_bond_matrix(N::Int)
3819
# Create a vector to store the SVectors, each containing a pair of integers
@@ -46,16 +27,15 @@ function create_bond_matrix(N::Int)
4627
return matrix
4728
end
4829

30+
chains = load_chains("test/molecule.xyz", args=Dict("temperature" => [temperature], "model" => ["Trimer"], "list_type" => "LinkedList", "bonds" => create_bond_matrix(N)))
4931

5032
model_matrix = Trimer()
51-
bonds = create_bond_matrix(N)
52-
chains = [System(position, species, molecule, density, temperature, model_matrix, bonds; list_type=LinkedList) for _ in 1:M]
53-
## Define moves and combine them into a pool
33+
5434
pswap = 0.2
5535
displacement_policy = SimpleGaussian()
5636
displacement_parameters = ComponentArray=0.05)
5737
pool = (
58-
Move(Displacement(0, zero(box), 0.0), displacement_policy, displacement_parameters, 1.0),
38+
Move(Displacement(0, zero(chains[1].box), 0.0), displacement_policy, displacement_parameters, 1.0),
5939
)
6040
## Define the simulation struct
6141
steps = 1000

0 commit comments

Comments
 (0)