Skip to content

Commit

Permalink
build based on a1ee913
Browse files Browse the repository at this point in the history
  • Loading branch information
Documenter.jl committed Oct 30, 2024
1 parent e06ac6f commit 5195eb5
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 180 deletions.
2 changes: 1 addition & 1 deletion dev/.documenter-siteinfo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documenter":{"julia_version":"1.11.1","generation_timestamp":"2024-10-30T11:27:34","documenter_version":"1.7.0"}}
{"documenter":{"julia_version":"1.11.1","generation_timestamp":"2024-10-30T14:53:08","documenter_version":"1.7.0"}}
141 changes: 73 additions & 68 deletions dev/api/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dev/development/index.html

Large diffs are not rendered by default.

48 changes: 20 additions & 28 deletions dev/differentiable/index.html

Large diffs are not rendered by default.

99 changes: 73 additions & 26 deletions dev/documentation/index.html

Large diffs are not rendered by default.

80 changes: 29 additions & 51 deletions dev/examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
boundary=boundary,
velocities=velocities,
pairwise_inters=(inter,),
loggers=(coords=CoordinateLogger(typeof(1.0u"km"), 10),),
loggers=(coords=CoordinatesLogger(typeof(1.0u"km"), 10),),
force_units=u"kg * km * d^-2",
energy_units=u"kg * km^2 * d^-2",
)
Expand Down Expand Up @@ -125,8 +125,8 @@
ϵ::Float64
end

# Custom PairwiseInteraction
struct SIRInteraction <: PairwiseInteraction
# Custom pairwise interaction
struct SIRInteraction
dist_infection::Float64
prob_infection::Float64
prob_recovery::Float64
Expand All @@ -135,11 +135,9 @@
# Custom force function
function Molly.force(inter::SIRInteraction,
vec_ij,
coord_i,
coord_j,
atom_i,
atom_j,
boundary)
args...)
if (atom_i.status == infected && atom_j.status == susceptible) ||
(atom_i.status == susceptible && atom_j.status == infected)
# Infect close people randomly
Expand All @@ -156,11 +154,11 @@
atom_i.status = recovered
end
end
return zero(coord_i)
return zero(vec_ij)
end

# Custom logger
function fracs_SIR(s::System, neighbors=nothing; n_threads::Integer=Threads.nthreads())
function fracs_SIR(s::System, args...; kwargs...)
counts_sir = [
count(p -> p.status == susceptible, s.atoms),
count(p -> p.status == infected , s.atoms),
Expand All @@ -180,12 +178,7 @@
coords = place_atoms(n_people, boundary; min_dist=0.1)
velocities = [random_velocity(1.0, temp; dims=2) for i in 1:n_people]

lj = LennardJones(
cutoff=DistanceCutoff(1.6),
use_neighbors=true,
force_units=NoUnits,
energy_units=NoUnits,
)
lj = LennardJones(cutoff=DistanceCutoff(1.6), use_neighbors=true)
sir = SIRInteraction(0.5, 0.06, 0.01)
pairwise_inters = (LennardJones=lj, SIR=sir)
neighbor_finder = DistanceNeighborFinder(
Expand All @@ -206,7 +199,7 @@
pairwise_inters=pairwise_inters,
neighbor_finder=neighbor_finder,
loggers=(
coords=CoordinateLogger(Float64, 10; dims=2),
coords=CoordinatesLogger(Float64, 10; dims=2),
SIR=SIRLogger(10),
),
force_units=NoUnits,
Expand Down Expand Up @@ -321,7 +314,7 @@
pairwise_inters=(lj,),
specific_inter_lists=(bonds, angles),
neighbor_finder=neighbor_finder,
loggers=(coords=CoordinateLogger(200),),
loggers=(coords=CoordinatesLogger(200),),
)

sim = Langevin(dt=0.002u"ps", temperature=300.0u"K", friction=1.0u"ps^-1")
Expand Down Expand Up @@ -504,7 +497,7 @@
coords = [SVector(1/8, 1/8, 1/8), SVector(-1/8, -1/8, -1/8)]
velocities = [randn(SVector{3, Float64}) * 0.1 for _ in 1:2]
boundary = CubicBoundary(Inf)
loggers = (coords=CoordinateLogger(Float64, 1),)
loggers = (coords=CoordinatesLogger(Float64, 1),)

sys = System(
atoms=atoms,
Expand All @@ -524,7 +517,7 @@
values(sys.loggers.coords)[end]
# 2-element Vector{SVector{3, Float64}}:
# [0.12060853912863925, 0.12292128337998731, 0.13100409788691614]
# [-0.13352575661477334, -0.11473039463130282, -0.13189544838731393]</code></pre><h2 id="Making-and-breaking-bonds"><a class="docs-heading-anchor" href="#Making-and-breaking-bonds">Making and breaking bonds</a><a id="Making-and-breaking-bonds-1"></a><a class="docs-heading-anchor-permalink" href="#Making-and-breaking-bonds" title="Permalink"></a></h2><p>There is an example of mutable atom properties in the main documentation, but what if you want to make and break bonds during the simulation? In this case you can use a <a href="../api/#Molly.PairwiseInteraction"><code>PairwiseInteraction</code></a> to make, break and apply the bonds. The partners of the atom can be stored in the atom type. We make a logger to record when the bonds are present, allowing us to visualize them with the <code>connection_frames</code> keyword argument to <a href="../api/#Molly.visualize"><code>visualize</code></a> (this can take a while to plot).</p><pre><code class="language-julia hljs">using Molly
# [-0.13352575661477334, -0.11473039463130282, -0.13189544838731393]</code></pre><h2 id="Making-and-breaking-bonds"><a class="docs-heading-anchor" href="#Making-and-breaking-bonds">Making and breaking bonds</a><a id="Making-and-breaking-bonds-1"></a><a class="docs-heading-anchor-permalink" href="#Making-and-breaking-bonds" title="Permalink"></a></h2><p>There is an example of mutable atom properties in the main documentation, but what if you want to make and break bonds during the simulation? In this case you can use a pairwise interaction to make, break and apply the bonds. The partners of the atom can be stored in the atom type. We make a logger to record when the bonds are present, allowing us to visualize them with the <code>connection_frames</code> keyword argument to <a href="../api/#Molly.visualize"><code>visualize</code></a> (this can take a while to plot).</p><pre><code class="language-julia hljs">using Molly
using GLMakie
using LinearAlgebra

Expand All @@ -536,7 +529,7 @@
partners::Set{Int}
end

struct BondableInteraction &lt;: PairwiseInteraction
struct BondableInteraction
prob_formation::Float64
prob_break::Float64
dist_formation::Float64
Expand All @@ -548,11 +541,9 @@

function Molly.force(inter::BondableInteraction,
dr,
coord_i,
coord_j,
atom_i,
atom_j,
boundary)
args...)
# Break bonds randomly
if atom_j.i in atom_i.partners &amp;&amp; rand() &lt; inter.prob_break
delete!(atom_i.partners, atom_j.i)
Expand All @@ -570,11 +561,11 @@
fdr = -c * normalize(dr)
return fdr
else
return zero(coord_i)
return zero(dr)
end
end

function bonds(sys::System, neighbors=nothing; n_threads::Integer=Threads.nthreads())
function bonds(sys::System, args...; kwargs...)
bonds = BitVector()
for i in 1:length(sys)
for j in 1:(i - 1)
Expand All @@ -595,12 +586,7 @@
coords = place_atoms(n_atoms, boundary; min_dist=0.1)
velocities = [random_velocity(1.0, temp; dims=2) for i in 1:n_atoms]
pairwise_inters = (
SoftSphere(
cutoff=DistanceCutoff(2.0),
use_neighbors=true,
force_units=NoUnits,
energy_units=NoUnits,
),
SoftSphere(cutoff=DistanceCutoff(2.0), use_neighbors=true),
BondableInteraction(0.1, 0.1, 1.1, 2.0, 0.1),
)
neighbor_finder = DistanceNeighborFinder(
Expand All @@ -621,7 +607,7 @@
pairwise_inters=pairwise_inters,
neighbor_finder=neighbor_finder,
loggers=(
coords=CoordinateLogger(Float64, 20; dims=2),
coords=CoordinatesLogger(Float64, 20; dims=2),
bonds=BondLogger(20),
),
force_units=NoUnits,
Expand All @@ -648,15 +634,15 @@
using Zygote
using GLMakie

inter = LennardJones(force_units=NoUnits, energy_units=NoUnits)
inter = LennardJones()
boundary = CubicBoundary(5.0)
a1, a2 = Atom(σ=0.3, ϵ=0.5), Atom(σ=0.3, ϵ=0.5)

function force_direct(dist)
c1 = SVector(1.0, 1.0, 1.0)
c2 = SVector(dist + 1.0, 1.0, 1.0)
vec = vector(c1, c2, boundary)
F = force(inter, vec, c1, c2, a1, a2, boundary)
F = force(inter, vec, a1, a2, NoUnits)
return F[1]
end

Expand All @@ -665,7 +651,7 @@
c1 = SVector(1.0, 1.0, 1.0)
c2 = SVector(dist + 1.0, 1.0, 1.0)
vec = vector(c1, c2, boundary)
potential_energy(inter, vec, c1, c2, a1, a2, boundary)
potential_energy(inter, vec, a1, a2, NoUnits)
end
return -grad[1]
end
Expand Down Expand Up @@ -698,7 +684,7 @@
[0.0 , 0.0 , 1.7928950]]u&quot;Å&quot;,
)

coul = Coulomb(coulomb_const=2.307e-21u&quot;kJ*Å&quot;, force_units=u&quot;kJ/Å&quot;, energy_units=u&quot;kJ&quot;)
coul = Coulomb(coulomb_const=2.307e-21u&quot;kJ*Å&quot;)
calc = MollyCalculator(pairwise_inters=(coul,), force_units=u&quot;kJ/Å&quot;, energy_units=u&quot;kJ&quot;)

AtomsCalculators.potential_energy(ab_sys, calc)</code></pre><pre><code class="nohighlight hljs">9.112207692184968e-21 kJ</code></pre><pre><code class="language-julia hljs">AtomsCalculators.forces(ab_sys, calc)</code></pre><pre><code class="nohighlight hljs">5-element Vector{SVector{3, Quantity{Float64, 𝐋 𝐌 𝐓^-2, Unitful.FreeUnits{(Å^-1, kJ), 𝐋 𝐌 𝐓^-2, nothing}}}}:
Expand Down Expand Up @@ -756,7 +742,7 @@
c1 = SVector(1.0, 1.0, 1.0)
c2 = SVector(dist + 1.0, 1.0, 1.0)
vec = vector(c1, c2, boundary)
potential_energy(inter, vec, c1, c2, a1, a2, boundary)
potential_energy(inter, vec, a1, a2, NoUnits)
end
end

Expand Down Expand Up @@ -793,7 +779,7 @@
c1 = SVector(1.0, 1.0, 1.0)
c2 = SVector(dist + 1.0, 1.0, 1.0)
vec = vector(c1, c2, boundary)
potential_energy(inter, vec, c1, c2, a1, a2, boundary)
potential_energy(inter, vec, a1, a2, NoUnits)
end
end

Expand Down Expand Up @@ -836,11 +822,7 @@
sys = System(
fcc_crystal;
velocities=velocities,
pairwise_inters=(LennardJones(
cutoff=ShiftedForceCutoff(r_cut),
energy_units=u&quot;kJ * mol^-1&quot;,
force_units=u&quot;kJ * mol^-1 * nm^-1&quot;,
),),
pairwise_inters=(LennardJones(cutoff=ShiftedForceCutoff(r_cut)),),
loggers=(
kinetic_eng=KineticEnergyLogger(100),
pot_eng=PotentialEnergyLogger(100),
Expand All @@ -852,8 +834,9 @@
updated_atoms = []

for i in eachindex(sys)
push!(updated_atoms, Atom(index=sys.atoms[i].index, charge=sys.atoms[i].charge,
mass=sys.atoms[i].mass, σ=σ, ϵ=ϵ, solute=sys.atoms[i].solute))
push!(updated_atoms, Atom(index=sys.atoms[i].index, atom_type=sys.atoms[i].atom_type,
mass=sys.atoms[i].mass, charge=sys.atoms[i].charge,
σ=σ, ϵ=ϵ))
end

sys = System(sys; atoms=[updated_atoms...])</code></pre><p>Now the system can be simulated using any of the available simulators:</p><pre><code class="language-julia hljs">simulator = Langevin(
Expand All @@ -873,12 +856,7 @@
max_coord = 200.0u&quot;Å&quot;
coords = [max_coord .* rand(SVector{3}) for i in 1:n_atoms_half]
boundary = CubicBoundary(200.0u&quot;Å&quot;)
lj = LennardJones(
cutoff=ShiftedPotentialCutoff(r_cut),
use_neighbors=true,
energy_units=u&quot;kcal * mol^-1&quot;,
force_units=u&quot;kcal * mol^-1 * Å^-1&quot;,
)
lj = LennardJones(cutoff=ShiftedPotentialCutoff(r_cut), use_neighbors=true)

# Add bonded atoms
bond_length = 0.74u&quot;Å&quot; # Hydrogen bond length
Expand Down Expand Up @@ -916,4 +894,4 @@

# Check that the constraints are satisfied at the end of the simulation
@test check_position_constraints(sys, shake)
@test check_velocity_constraints(sys, shake)</code></pre></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../differentiable/">« Differentiable simulation</a><a class="docs-footer-nextpage" href="../exercises/">Exercises »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.7.0 on <span class="colophon-date" title="Wednesday 30 October 2024 11:27">Wednesday 30 October 2024</span>. Using Julia version 1.11.1.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
@test check_velocity_constraints(sys, shake)</code></pre></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../differentiable/">« Differentiable simulation</a><a class="docs-footer-nextpage" href="../exercises/">Exercises »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.7.0 on <span class="colophon-date" title="Wednesday 30 October 2024 14:53">Wednesday 30 October 2024</span>. Using Julia version 1.11.1.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
Loading

0 comments on commit 5195eb5

Please sign in to comment.