Skip to content

Commit

Permalink
Merge branch 'main' into release-0.4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiq committed Aug 25, 2023
2 parents df5f78e + 480a2cd commit 0c54fb7
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 115 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe"

[compat]
Aqua = "0.6"
CellListMap = "0.8.14"
DocStringExtensions = "0.8, 0.9"
StaticArrays = "1"
TestItems = "0.1"
julia = "1.6"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"

[targets]
test = ["Test", "StaticArrays", "TestItemRunner"]
test = ["Test", "StaticArrays", "TestItemRunner", "Aqua"]
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://m3g.github.io/MolecularMinimumDistances.jl/stable)
[![Tests](https://img.shields.io/badge/build-passing-green)](https://github.com/m3g/MolecularMinimumDistances.jl/actions)
[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)

# MolecularMinimumDistances

## Documentation
Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MolecularMinimumDistances

This package computes the minimum distance between *molecules*, which are represented as arrays of coordinates in two or three dimensions.
[MolecularMinimumDistancs.jl](http://github.com/m3g/MolecularMinimumDistances.jl) computes the minimum distance between *molecules*, which are represented as arrays of coordinates in two or three dimensions.

To understand the utility and purpose of this package, consider the image below:

Expand Down
41 changes: 18 additions & 23 deletions src/AllPairs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ end

import Base.show
function Base.show(io::IO, mime::MIME"text/plain", sys::AllPairs)
print(io,"""
print(io,chomp("""
AllPairs system with:
Number of atoms of first set: $(length(sys.system.xpositions))
Expand All @@ -25,22 +25,20 @@ function Base.show(io::IO, mime::MIME"text/plain", sys::AllPairs)
Number of molecules in second set: $(_number_of_molecules(sys.ymol_indices, sys.system.ypositions))
Cutoff: $(sys.system._box.cutoff)
unitcell: [$(join(CellListMap._uround.(sys.system._box.unit_cell.matrix),", "))]""")
unitcell: [$(join(CellListMap._uround.(sys.system._box.unit_cell.matrix),", "))]
"""))
end

"""
```
AllPairs(;
xpositions::AbstractVector{<:SVector{N,T}},
ypositions::AbstractVector{<:SVector{N,T}},
cutoff::T,
unitcell::AbstractVecOrMat,
xn_atoms_per_molecule::Int,
yn_atoms_per_molecule::Int,
parallel::Bool=true
) where T<:Real
```
AllPairs(;
xpositions::AbstractVector{<:SVector{N,T}},
ypositions::AbstractVector{<:SVector{N,T}},
cutoff::T,
unitcell::AbstractVecOrMat,
xn_atoms_per_molecule::Int,
yn_atoms_per_molecule::Int,
parallel::Bool=true
) where T<:Real
Initializes a particle system for the calculation of minimum distances
between one molecule and a set of other molecules. Returns a list
Expand Down Expand Up @@ -111,15 +109,12 @@ function AllPairs(;
end

"""
```
function update_list!(
i, j, d2,
mol_indices_i::Fi,
mol_indices_j::Fj,
lists::Tuple{T,T}
) where {Fi<:Function, Fj<:Function, T<:AbstractVector{<:MinimumDistance}}
```
function update_list!(
i, j, d2,
mol_indices_i::Fi,
mol_indices_j::Fj,
lists::Tuple{T,T}
) where {Fi<:Function, Fj<:Function, T<:AbstractVector{<:MinimumDistance}}
$(INTERNAL)
Expand Down
24 changes: 11 additions & 13 deletions src/CrossPairs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,26 @@ CrossPairs(system::S, mol_indices::F) where {S,F} = CrossPairs{S,F,:minimum_dist

import Base.show
function Base.show(io::IO, mime::MIME"text/plain", sys::CrossPairs)
print(io,"""
print(io,chomp("""
CrossPairs system with:
Number of atoms of set x: $(length(sys.system.xpositions))
Number of molecules in set x: $(_number_of_molecules(sys.mol_indices, sys.system.xpositions))
Number of atoms of target structure y: $(length(sys.system.ypositions))
Cutoff: $(sys.cutoff)
unitcell: [$(join(CellListMap._uround.(sys.system._box.input_unit_cell.matrix),", "))]""")
unitcell: [$(join(CellListMap._uround.(sys.system._box.input_unit_cell.matrix),", "))]
"""))
end

"""
```
CrossPairs(;
xpositions::AbstractVector{<:SVector{N,T}},
ypositions::AbstractVector{<:SVector{N,T}},
cutoff::T,
unitcell::AbstractVecOrMat,
xn_atoms_per_molecule::Int,
parallel::Bool=true
) where T<:Real
```
CrossPairs(;
xpositions::AbstractVector{<:SVector{N,T}},
ypositions::AbstractVector{<:SVector{N,T}},
cutoff::T,
unitcell::AbstractVecOrMat,
xn_atoms_per_molecule::Int,
parallel::Bool=true
) where T<:Real
Initializes a particle system for the calculation of minimum distances
between one molecule and a set of other molecules. Returns a list
Expand Down
67 changes: 25 additions & 42 deletions src/MolecularMinimumDistances.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ using .CellListMap.PeriodicSystems
export MinimumDistance
export SelfPairs, CrossPairs, AllPairs
export minimum_distances, minimum_distances!
export getlist

"""
```
MinimumDistance{T}
```
MinimumDistance{T}
The lists of minimum-distances are stored in arrays of type `Vector{MinimumDistance{T}}`. The index
of this vector corresponds to the index of the molecule in the original array.
Expand Down Expand Up @@ -56,20 +52,18 @@ copy(md::MinimumDistance) = MinimumDistance(md.within_cutoff, md.i, md.j, md.d)

import Base.show
function Base.show(io::IO, mime::MIME"text/plain", md::MinimumDistance{T}) where T
print(io,"""
print(io,chomp("""
$(md)
Distance within cutoff, within_cutoff = $(md.within_cutoff)
x atom of pair, i = $(md.i)
y atom of pair, j = $(md.j)
Distance found, d = $(md.d)""")
Distance found, d = $(md.d)
"""))
end

"""
```
_mol_indices(i_atom,n_atoms_per_molecule) = (i_atom-1) ÷ n_atoms_per_molecule + 1
```
_mol_indices(i_atom,n_atoms_per_molecule) = (i_atom-1) ÷ n_atoms_per_molecule + 1
$(INTERNAL)
Expand Down Expand Up @@ -100,10 +94,7 @@ List{T} = Vector{<:MinimumDistance{T}}
ListTuple{T} = Tuple{Vector{<:MinimumDistance{T}}, Vector{<:MinimumDistance{T}}}

"""
```
init_list(x, mol_indices::F) where F<:Function
```
init_list(x, mol_indices::F) where F<:Function
$(INTERNAL)
Expand All @@ -114,9 +105,7 @@ molecules. `x` must be provided so that the type of variable of the coordinates
propagated to the distances, and `mol_indices` is the function that given an atomic index `i`
returns the index of the molecule.
```
init_list(::Type{T}, number_of_molecules::Int)
```
init_list(::Type{T}, number_of_molecules::Int)
Given the type of the coordinates of the vector of atomic coordinates and the number of molecules,
returns the initialized array of minimum distances.
Expand Down Expand Up @@ -207,10 +196,7 @@ function reducer(l1::ListTuple, l2::ListTuple)
end

"""
```
minimum_distances!(system)
```
minimum_distances!(system)
Function that computes the minimum distances for an initialized system,
of `SelfPairs`, `CrossPairs`, or `AllPairs` types.
Expand Down Expand Up @@ -263,18 +249,15 @@ function minimum_distances!(sys)
end

"""
```
function minimum_distances(
xpositions=rand(SVector{3,Float64},10^5),
# or xpositions *and* ypositions (CrossPairs or AllPairs)
cutoff=0.1,
unitcell=[1,1,1],
xn_atoms_per_molecule=5
# or xn_atoms_per_molecule (CrossPairs)
# or xn_atoms_per_molecule *and* yn_atoms_per_molecule (AllPairs)
)
```
function minimum_distances(
xpositions::AbstractVector{<:SVector},
# or xpositions *and* ypositions (CrossPairs or AllPairs)
cutoff=0.1,
unitcell=[1,1,1],
xn_atoms_per_molecule=5
# or xn_atoms_per_molecule (CrossPairs)
# or xn_atoms_per_molecule *and* yn_atoms_per_molecule (AllPairs)
)
This function computes directly the minimum distances in a set of particles.
Depending on the number of input position arrays provided and on the number
Expand Down Expand Up @@ -379,17 +362,17 @@ julia> lists[2]
"""
function minimum_distances(;
xpositions::Union{Nothing,AbstractVector{<:SVector{N,T}}}=nothing,
ypositions::Union{Nothing,AbstractVector{<:SVector{N,T}}}=nothing,
cutoff::T,
xpositions=nothing,
ypositions=nothing,
cutoff::Real,
unitcell::AbstractVecOrMat,
mol_indices::Union{Nothing,Function}=nothing,
xmol_indices::Union{Nothing,Function}=nothing,
ymol_indices::Union{Nothing,Function}=nothing,
mol_indices=nothing,
xmol_indices=nothing,
ymol_indices=nothing,
xn_atoms_per_molecule::Union{Nothing,Int}=nothing,
yn_atoms_per_molecule::Union{Nothing,Int}=nothing,
parallel=true
) where {N,T}
parallel::Bool=true,
)
# SelfPairs
if isnothing(ypositions)
mol_indices = _get_mol_indices(mol_indices, xn_atoms_per_molecule)
Expand Down
22 changes: 10 additions & 12 deletions src/SelfPairs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,24 @@ end

import Base.show
function Base.show(io::IO, mime::MIME"text/plain", sys::SelfPairs)
print(io,"""
print(io,chomp("""
SelfPairs system with:
Number of atoms: $(length(sys.system.xpositions))
Cutoff: $(sys.system._box.cutoff)
unitcell: [$(join(CellListMap._uround.(sys.system._box.unit_cell.matrix),", "))]
Number of molecules: $(_number_of_molecules(sys.mol_indices, sys.system.xpositions))""")
Number of molecules: $(_number_of_molecules(sys.mol_indices, sys.system.xpositions))
"""))
end

"""
```
SelfPairs(;
xpositions::AbstractVector{<:SVector{N,T}},
cutoff::T,
unitcell::AbstractVecOrMat,
xn_atoms_per_molecule::Int,
parallel::Bool=true
) where T<:Real
```
SelfPairs(;
xpositions::AbstractVector{<:SVector{N,T}},
cutoff::T,
unitcell::AbstractVecOrMat,
xn_atoms_per_molecule::Int,
parallel::Bool=true
) where T<:Real
Initializes a particle system for the calculation of minimum distances
within a single set of molecules. The shortest distance of each molecule
Expand Down
34 changes: 17 additions & 17 deletions src/testing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,19 @@ end
# inspection and visualization
#
function plot_mol!(
p,
x;
p,
x;
cycle=false,
markercolor=nothing
)
for i in 1:length(x)-1
xat = [ x[i][1], x[i+1][1] ]
yat = [ x[i][2], x[i+1][2] ]
xat = [x[i][1], x[i+1][1]]
yat = [x[i][2], x[i+1][2]]
Main.plot!(p, xat, yat, label=:none, linewidth=2, color=:black)
end
if cycle
xat = [ x[end][1], x[1][1] ]
yat = [ x[end][2], x[1][2] ]
xat = [x[end][1], x[1][1]]
yat = [x[end][2], x[1][2]]
Main.plot!(p, xat, yat, label=:none, linewidth=2, color=:black)
end
if isnothing(markercolor)
Expand All @@ -142,40 +142,40 @@ function plot_mol!(
end

function plot_mol!(
p,
x,
n_atoms_per_molecule::Int;
p,
x,
n_atoms_per_molecule::Int;
cycle=false,
markercolor=nothing
)
for i in 1:n_atoms_per_molecule:length(x)
plot_mol!(
p,
@view(x[i:i+n_atoms_per_molecule-1]);
cycle=cycle,
p,
@view(x[i:i+n_atoms_per_molecule-1]);
cycle=cycle,
markercolor=markercolor
)
if isnothing(markercolor)
markercolor = p.series_list[end][:markercolor]
markercolor = p.series_list[end][:markercolor]
end
end
return p
end

function plot_md!(
p,
x,
x,
xn_atoms_per_molecule::Int,
y,
y,
yn_atoms_per_molecule::Int,
md::List;
x_cycle=false,
y_cycle=false
)
for pair in md
!pair.within_cutoff && continue
xp = [ x[pair.i][1], y[pair.j][1] ]
yp = [ x[pair.i][2], y[pair.j][2] ]
xp = [x[pair.i][1], y[pair.j][1]]
yp = [x[pair.i][2], y[pair.j][2]]
Main.plot!(p, xp, yp, label=:none, linewidth=2, color=:black, alpha=0.3)
end
plot_mol!(p, x, xn_atoms_per_molecule; cycle=x_cycle, markercolor=:red)
Expand Down
Loading

2 comments on commit 0c54fb7

@lmiq
Copy link
Member Author

@lmiq lmiq commented on 0c54fb7 Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/90276

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.4 -m "<description of version>" 0c54fb74d152beffc70259a9a12b62282de38903
git push origin v0.4.4

Please sign in to comment.