Skip to content

Commit

Permalink
update interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ArrogantGao committed Dec 17, 2024
1 parent 89d0024 commit 4cf9d44
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 9 deletions.
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "EwaldSummations"
uuid = "329efeb5-5dc7-45f3-8303-d0bcfeef1c8a"
authors = ["Xuanzhao Gao <[email protected]>"]
version = "0.1.3"
version = "0.2.0"

[deps]
CellListMap = "69e1c6dd-3888-40e6-b3c8-31ac5f578864"
Expand All @@ -24,6 +24,7 @@ julia = "1.10"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[targets]
test = ["Test"]
test = ["Test", "Random"]
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Here is an example for calculating energy of 3D systems, via Ewald3D or directio

```julia
# Init the system
using ExTinyMD, EwaldSummations

n_atoms = 100
L = 100.0
boundary = Boundary((L, L, L), (1, 1, 1))
Expand Down Expand Up @@ -117,8 +119,8 @@ n_atoms = 100
L = 100.0
boundary = ExTinyMD.Q2dBoundary(L, L, L)

s = 6.0
alpha = 2.0
s = 3.0
alpha = 0.2
γ = (0.9, 0.9)
N_img = 10
N_pad = 20
Expand Down Expand Up @@ -147,8 +149,17 @@ ICMEwald2D_interaction = IcmEwald2DInteraction(n_atoms, s, alpha, γ, (L, L, L),
energy_icmewald2d = ICM_Ewald2D_energy(ICMEwald2D_interaction, coords, charge)

# ICM-Ewald3D, consider 20 layers of image charges and 40 layers of padding
ICMEwald3D_interaction = IcmEwald3DInteraction(n_atoms, s, alpha, γ, (L, L, L), N_pad, N_img)
energy_icmewald3d = ICMEwald3D_energy(ICMEwald3D_interaction, coords, charge)
ICMEwald3D_interaction = IcmEwald3DInteraction(n_atoms, s, alpha, γ, (L, L, L), N_img, N_pad)
energy_icmewald3d = ICM_Ewald3D_energy(ICMEwald3D_interaction, coords, charge)
```

## Citation

If you use this package in your research, please cite at least one of the following paper:

```
```

## How to Contribute
Expand Down
10 changes: 9 additions & 1 deletion src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ struct Ewald2DInteraction{T} <: ExTinyMD.AbstractInteraction
k_set::Vector{Tuple{T, T, T}}
end

Base.show(io::IO, interaction::Ewald2DInteraction) = print(io, "Ewald2DInteraction(n_atoms = $(interaction.n_atoms), ϵ = $(interaction.ϵ), α = $(interaction.α), r_c = $(interaction.r_c), k_c = $(interaction.k_c), L = $(interaction.L))")

struct Ewald3DInteraction{T} <: ExTinyMD.AbstractInteraction
n_atoms::Int
ϵ::T
Expand All @@ -19,6 +21,8 @@ struct Ewald3DInteraction{T} <: ExTinyMD.AbstractInteraction
k_set::Vector{Tuple{T, T, T, T}}
end

Base.show(io::IO, interaction::Ewald3DInteraction) = print(io, "Ewald3DInteraction(n_atoms = $(interaction.n_atoms), ϵ = $(interaction.ϵ), ϵ_inf = $(interaction.ϵ_inf), α = $(interaction.α), r_c = $(interaction.r_c), k_c = $(interaction.k_c), L = $(interaction.L))")

struct IcmEwald2DInteraction{T} <: ExTinyMD.AbstractInteraction
n_atoms::Int
ϵ::T
Expand All @@ -31,6 +35,8 @@ struct IcmEwald2DInteraction{T} <: ExTinyMD.AbstractInteraction
k_set::Vector{Tuple{T, T, T}}
end

Base.show(io::IO, interaction::IcmEwald2DInteraction) = print(io, "IcmEwald2DInteraction(n_atoms = $(interaction.n_atoms), ϵ = $(interaction.ϵ), α = $(interaction.α), r_c = $(interaction.r_c), k_c = $(interaction.k_c), γ = $(interaction.γ), L = $(interaction.L), N_image = $(interaction.N_image))")

struct IcmEwald3DInteraction{T} <: ExTinyMD.AbstractInteraction
n_atoms::Int
ϵ::T
Expand All @@ -42,4 +48,6 @@ struct IcmEwald3DInteraction{T} <: ExTinyMD.AbstractInteraction
N_image::Int # layer of the image charges
N_pad::Int # layer of the z padding, L_z_pad = (2 * N_pad + 1) * L_z
k_set::Vector{Tuple{T, T, T, T}}
end
end

Base.show(io::IO, interaction::IcmEwald3DInteraction) = print(io, "IcmEwald3DInteraction(n_atoms = $(interaction.n_atoms), ϵ = $(interaction.ϵ), α = $(interaction.α), r_c = $(interaction.r_c), k_c = $(interaction.k_c), γ = $(interaction.γ), L = $(interaction.L), N_image = $(interaction.N_image), N_pad = $(interaction.N_pad))")
2 changes: 2 additions & 0 deletions test/Ewald2D.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using ExTinyMD, EwaldSummations
using Test
using Random
Random.seed!(1234)

@testset "compare Ewald2D energy with ICM" begin
@info "Test for Ewald2D energy"
Expand Down
2 changes: 2 additions & 0 deletions test/Ewald3D.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using ExTinyMD, EwaldSummations
using Test
using Random
Random.seed!(1234)

@testset "Compare Ewald3D energy with direct sum" begin
@info "Test for Ewald3D energy"
Expand Down
6 changes: 4 additions & 2 deletions test/ICM_Ewald2D.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using EwaldSummations
using Test
using Random
Random.seed!(1234)

@testset "ICM_Ewald2D vs Ewald2D" begin
@info "Test for ICM_Ewald2D energy and force"
Expand Down Expand Up @@ -72,10 +74,10 @@ end
energy_direct_sum = Energy_Q2D(sys_q2d, coords, charge, ref_pos, ref_charge)
force_direct_sum = Force_Q2D(sys_q2d, coords, charge, ref_pos, ref_charge)

@test isapprox(energy_direct_sum, energy_ewald, atol = 1e-3)
@test isapprox(energy_direct_sum, energy_ewald, atol = 1e-2)
for i in 1:n_atoms
for j in 1:3
@test isapprox(force_direct_sum[i][j], force_ewald[i][j], atol = 1e-3)
@test isapprox(force_direct_sum[i][j], force_ewald[i][j], atol = 1e-2)
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions test/ICM_Ewald3D.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using ExTinyMD, EwaldSummations
using Test
using Random
Random.seed!(1234)

@testset "ICM_Ewald3D_ELC vs Ewald2D" begin
@info "Test for ICM_Ewald3D energy and force"
Expand Down

0 comments on commit 4cf9d44

Please sign in to comment.