Skip to content

Commit

Permalink
fix dmin reducer
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiq committed Oct 8, 2024
1 parent 0e295f4 commit 5358cc1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/interatomic_distance_fg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ end
function reducer(x::InteratomicDistanceFG, y::InteratomicDistanceFG)
x.f += y.f
x.g += y.g
x.dmin = min(x.dmin, y.dmin)
x.dmin = max(x.dmin, y.dmin)
x.fmol .+= y.fmol
x.gxcar .+= y.gxcar
return x
end

# Updates the function and gradient of the system given a pair of
# particles within the cutoff.
function interatomic_fg!(x::T, y::T, i, j, d2, fg::InteratomicDistanceFG, packmol_system) where {T}
function cartesian_fg!(x::T, y::T, i, j, d2, fg::InteratomicDistanceFG, packmol_system) where {T}
iatom = packmol_system.atoms[i]
jatom = packmol_system.atoms[j]
if iatom.molecule_index == jatom.molecule_index
Expand All @@ -70,12 +70,12 @@ end

# Function that computes the function and gradient, and returns the function
# value and mutates the gradient array, to conform with the interface of SPGBox
function fg!(g, system, packmol_system)
fg = system.fg
# This function mutates the system.fg field.
function fg!(system::PeriodicSystem, packmol_system::PackmolSystem)
# Compute the function value and component of the gradient relative to the cartesian
# coordinates for each atom
map_pairwise!(
(x, y, i, j, d2, fg) -> interatomic_fg!(x, y, i, j, d2, fg, packmol_system),
(x, y, i, j, d2, output) -> cartesian_fg!(x, y, i, j, d2, output, packmol_system),
system,
)
# Use the chain rule to compute the gradient relative to the rotations
Expand Down
2 changes: 1 addition & 1 deletion src/mono_atomic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end
function reducer(x::MonoAtomicFG, y::MonoAtomicFG)
x.f += y.f
x.g .+= y.g
x.dmin = min(x.dmin, y.dmin)
x.dmin = max(x.dmin, y.dmin)
return x
end

Expand Down

0 comments on commit 5358cc1

Please sign in to comment.