11module MolecularMinimumDistances
22
3- import TestItems: @testitem
4- import DocStringExtensions: TYPEDEF, TYPEDFIELDS
3+ using TestItems: @testitem
4+ using DocStringExtensions: TYPEDEF, TYPEDFIELDS
55
6- import LinearAlgebra: diag
6+ using LinearAlgebra: diag
7+ using StaticArrays: SVector
8+ using CellListMap: ParticleSystem, pairwise!, update!
79import PDBTools: distance
8- import StaticArrays: SVector
9- import CellListMap: _uround # interal function, used for showing the unitcell
10- import CellListMap: ParticleSystem, map_pairwise, map_pairwise!,
11- update_cutoff!, update_unitcell!
1210
1311export MinimumDistance
1412export SelfPairs, CrossPairs, AllPairs
@@ -205,7 +203,7 @@ julia> init_list(x, i -> (i-1)÷2 + 1)
205203
206204```
207205
208- The above annonymous function `i -> (i-1)÷2 + 1` is equivalent to `i -> mol_indices(i,2)`,
206+ The above anonymous function `i -> (i-1)÷2 + 1` is equivalent to `i -> mol_indices(i,2)`,
209207and can be generalized if the the number of atoms of each molecule is not the same.
210208
211209=#
@@ -231,7 +229,7 @@ init_list(::Type{T}, n::Integer) where {T} = fill(zero(MinimumDistance{T}), n)
231229# Note that we have two types of output variables here: List, and a tuple of List.
232230# The List is simply an array of `MinimumDistance{T}`, and we have defined above
233231# `copy` and `zero` methods for this type, such that we only need to define
234- # that reseting this variable consists of returing its zero, and set up the reducer.
232+ # that resetting this variable consists of returning its zero, and set up the reducer.
235233# The methods for abstract arrays will take care of the rest.
236234#
237235# For the Tuple of lists, we need to be more explicit, and define appropriate copy_output,
263261Function that computes the minimum distances for an initialized system,
264262of `SelfPairs`, `CrossPairs`, or `AllPairs` types.
265263
266- The function returs a `Vector{MinimumDistance}` cor `SelfPairs` and `CrossPairs`
264+ The function returns a `Vector{MinimumDistance}` cor `SelfPairs` and `CrossPairs`
267265inputs, and a Tuple of two of such vectors for the `AllPairs` input types.
268266
269267This function is used as an advanced alternative from preallocated system inputs. Only a few allocations
@@ -303,10 +301,7 @@ julia> @btime minimum_distances!(\$sys);
303301
304302"""
305303function minimum_distances! (sys)
306- map_pairwise! (
307- (x, y, i, j, d2, list) -> update_list! (i, j, d2, list, sys),
308- sys. system
309- )
304+ pairwise! ((pair, list) -> update_list! (pair, list, sys), sys. system)
310305 return sys. minimum_distances
311306end
312307
@@ -482,24 +477,12 @@ abstract type SystemPairs end
482477
483478import Base: getproperty, propertynames
484479getproperty (sys:: SystemPairs , s:: Symbol ) = getproperty (sys, Val (s))
480+ getproperty (sys:: SystemPairs , :: Val{:minimum_distances} ) = sys. system. output
485481getproperty (sys:: SystemPairs , :: Val{:system} ) = getfield (sys, :system )
486482getproperty (sys:: SystemPairs , :: Val{:mol_indices} ) = getfield (sys, :mol_indices )
487483getproperty (sys:: SystemPairs , :: Val{:xmol_indices} ) = getfield (sys, :xmol_indices )
488484getproperty (sys:: SystemPairs , :: Val{:ymol_indices} ) = getfield (sys, :ymol_indices )
489- getproperty (sys:: SystemPairs , :: Val{:minimum_distances} ) = sys. system. output
490- getproperty (sys:: SystemPairs , :: Val{:xpositions} ) = sys. system. xpositions
491- getproperty (sys:: SystemPairs , :: Val{:ypositions} ) = sys. system. ypositions
492- getproperty (sys:: SystemPairs , :: Val{:cutoff} ) = sys. system. cutoff
493- getproperty (sys:: SystemPairs , :: Val{:unitcell} ) = sys. system. unitcell
494- getproperty (sys:: SystemPairs , :: Val{:parallel} ) = sys. system. parallel
495- propertynames (sys:: SystemPairs , private:: Bool ) =
496- (:system , :mol_indices , :minimum_distances , :xpositions , :ypositions , :unitcell , :cutoff )
497-
498- import Base: setproperty!
499- setproperty! (sys:: SystemPairs , s:: Symbol , value) = setproperty! (sys, Val (s), value)
500- setproperty! (sys:: SystemPairs , :: Val{:cutoff} , cutoff) = update_cutoff! (sys. system, cutoff)
501- setproperty! (sys:: SystemPairs , :: Val{:unitcell} , unitcell) = update_unitcell! (sys. system, unitcell)
502- setproperty! (sys:: SystemPairs , :: Val{:parallel} , parallel) = sys. system. parallel = parallel
485+ propertynames (sys:: SystemPairs , private:: Bool ) = (:system , :minimum_distances )
503486
504487#
505488# Functions for when the lists of minimum-distances is that of a single
0 commit comments