Skip to content

Commit

Permalink
Update to AtomsBase v0.5 (#10)
Browse files Browse the repository at this point in the history
* Add scaled_position for `AtomView`

* Replace bounding_box to cell_vectors, boundary_conditions to
periodicity, remove AtomsBase 0.3 support

* Remove julia 0.6 support, update CI to newer versions, update test

* Update documentation CI julia version to 1.11
  • Loading branch information
rashidrafeek authored Dec 7, 2024
1 parent a429789 commit 493696e
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 34 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6'
- '1.9'
- '1.10'
- '1.11'
- 'nightly'
os:
- ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: '1.6'
version: '1.11'
- uses: julia-actions/cache@v1
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
Expand Down
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AtomsToolbox"
uuid = "f386ec8f-7408-45ea-aa1c-e80969af901e"
authors = ["Rashid Rafeek <rashidrafeek@gmail.com> and contributors"]
version = "0.1.1"
version = "0.1.2"

[deps]
AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a"
Expand All @@ -13,13 +13,13 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[compat]
AtomsBase = "0.3, 0.4"
AtomsBase = "0.5"
PeriodicTable = "1"
StaticArrays = "1"
Graphs = "1"
Distances = "0.10"
Unitful = "1"
julia = "1.6"
julia = "1.9"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
4 changes: 2 additions & 2 deletions src/AtomsToolbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ using AtomsBase: AbstractSystem,
FastSystem,
FlexibleSystem,
Atom,
AtomView,
position,
atomic_number,
atomic_symbol,
atomic_mass,
bounding_box,
boundary_conditions,
cell_vectors,
periodicity
using Unitful: Unitful, ustrip, @u_str, unit
import Graphs
Expand Down
6 changes: 3 additions & 3 deletions src/atomsbase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
# function Base.getindex(system::AbstractSystem, range::AbstractVector)
# particles = collect(system)
# return _getconstructor(system)(particles[range],
# bounding_box(system),
# boundary_conditions(system))
# cell_vectors(system),
# periodicity(system))
# # _getconstructor(system)(
# # bounding_box(system), boundary_conditions(system),
# # cell_vectors(system), periodicity(system),
# # position(system)[range], atomic_symbol(system)[range],
# # atomic_number(system)[range], atomic_mass(system)[range])
# end
6 changes: 3 additions & 3 deletions src/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ function interpolate_systems(sys1::FastSystem, sys2::FastSystem, nimg::Int)
particles2 = collect(sys2)
pos1 = position(sys1)
pos2 = position(sys2)
bcs = boundary_conditions(sys1)
box = bounding_box(sys1)
bcs = periodicity(sys1)
box = cell_vectors(sys1)
syms, nums, masses = atomic_symbol.(particles1),
atomic_number.(particles1),
atomic_mass.(particles1)

if !(box == bounding_box(sys2))
if !(box == cell_vectors(sys2))
error("Can't interpolate systems with different cells.")
end

Expand Down
22 changes: 11 additions & 11 deletions src/getters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ include("pbc_utils.jl")
Obtain the cell lengths as a Vector, [a,b,c].
"""
cell_lengths(sys::AbstractSystem) = norm.(bounding_box(sys))
cell_lengths(sys::AbstractSystem) = norm.(cell_vectors(sys))

"""
cell_parameters(sys::AbstractSystem)
Obtain the cell lengths and angles as a Vector, [a,b,c,α,β,γ].
"""
function cell_parameters(sys::AbstractSystem)
av,bv,cv = bounding_box(sys)
av,bv,cv = cell_vectors(sys)
a,b,c = norm.((av,bv,cv))

α = acosd((bvcv)/(b*c))u"°"
Expand All @@ -41,7 +41,7 @@ end
Obtain the cell angles as a Vector, [α,β,γ].
"""
function cell_angles(sys::AbstractSystem)
av,bv,cv = bounding_box(sys)
av,bv,cv = cell_vectors(sys)
a,b,c = norm.((av,bv,cv))

α = acosd((bvcv)/(b*c))u"°"
Expand Down Expand Up @@ -83,9 +83,9 @@ number of atoms in the given `system`.
"""
function distance_matrix(system::AbstractSystem; pbc=all(periodicity(system)))
if pbc
dists = pbc_shortest_vectors(system, position(system), Val(true), Val(false))
dists = pbc_shortest_vectors(system, position(system, :), Val(true), Val(false))
else
dists = pairwise(Euclidean(), position(system))
dists = pairwise(Euclidean(), position(system, :))
end

return dists
Expand All @@ -108,7 +108,7 @@ function angle(
system::AbstractSystem, pos1::T, pos2::T, pos3::T; pbc=all(periodicity(system))
) where {T <: AbstractVector{<:Unitful.Length}}
if pbc
cell = reduce(hcat, bounding_box(system))'
cell = reduce(hcat, cell_vectors(system))'
icell = inv(cell)
frpos1 = pos1' * icell
frpos2 = pos2' * icell
Expand Down Expand Up @@ -149,7 +149,7 @@ function dihedral(
# Source: Blondel and Karplus, J. Comp. Chem., Vol. 17, No. 9, 1
# 132-1 141 (1 996).
# if pbc
# cell = reduce(hcat, bounding_box(system))'
# cell = reduce(hcat, cell_vectors(system))'
# icell = inv(cell)
# frpos1 = pos1' * icell
# frpos2 = pos2' * icell
Expand All @@ -174,7 +174,7 @@ function dihedral(

# Obtained from pymatgen
if pbc
cell = reduce(hcat, bounding_box(system))'
cell = reduce(hcat, cell_vectors(system))'
icell = inv(cell)
frpos1 = pos1' * icell
frpos2 = pos2' * icell
Expand Down Expand Up @@ -289,12 +289,12 @@ matrix for the given system or `atom`.
"""
function scaled_position(sys::AbstractSystem)
cellmat = cell_matrix(sys)
frpos = reduce(hcat, position(sys))' * inv(cellmat')
frpos = reduce(hcat, position(sys, :))' * inv(cellmat')

Vector.(eachrow(frpos))
end
scaled_position(sys::AbstractSystem, index) = scaled_position(sys[index], cell_matrix(sys))
function scaled_position(atom::Atom, cellmat)
function scaled_position(atom::Union{Atom,AtomView}, cellmat)
frpos = position(atom)' * inv(cellmat')

frpos'
Expand All @@ -304,7 +304,7 @@ end
# Cell utils
#

@inline cell_matrix(sys::AbstractSystem) = reduce(hcat, bounding_box(sys))
@inline cell_matrix(sys::AbstractSystem) = reduce(hcat, cell_vectors(sys))
# lu is required as unitful matrices are erroring without it
# when the cell matrix is diagonal
"""
Expand Down
4 changes: 2 additions & 2 deletions src/pbc_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function pbc_shortest_vectors(
system::AbstractSystem, pos1::T, pos2::U,
return_dists::Val{RD}=Val(false), return_vects::Val{RV}=Val(true)
) where {T <: AbstractVector{<: Unitful.Length}, U <: AbstractVector{<: Unitful.Length}, RD, RV}
cell = reduce(hcat, bounding_box(system))'
cell = reduce(hcat, cell_vectors(system))'
icell = inv(cell)
frpos1 = pos1' * icell
frpos2 = pos2' * icell
Expand All @@ -61,7 +61,7 @@ function pbc_shortest_vectors(
return_dists::Val{RD}=Val(false),
return_vects::Val{RV}=Val(true)
) where {T <: Vector{<: AbstractVector{<: Unitful.Length}}, RD, RV}
cell = reduce(hcat, bounding_box(system))'
cell = reduce(hcat, cell_vectors(system))'
pos = reduce(hcat, posvec)'
frpos = pos * inv(cell)

Expand Down
14 changes: 7 additions & 7 deletions src/transform.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function _getdefaultdata(system::AbstractSystem)
particles = collect(system)
positions = position(system)
box = bounding_box(system)
bc = boundary_conditions(system)
box = cell_vectors(system)
bc = periodicity(system)

return particles, positions, box, bc
end
Expand All @@ -15,9 +15,9 @@ system.
"""
# function transformpositions(f::Function, system::AbstractSystem)
# positions = map(f, position(system))
# cell = bounding_box(system)
# cell = cell_vectors(system)
# at = species(system)
# bc = boundary_conditions(system)
# bc = periodicity(system)
#
# typeof(system)(cell, positions, at)
# end
Expand Down Expand Up @@ -76,16 +76,16 @@ function supercell(system::AbstractSystem, supercellvec::Vector{Int}; sorted=fal
end

system_props = Dict{Symbol, Any}()
# All system properties except bounding_box is copied to the new system
# All system properties except cell_vectors is copied to the new system
for (k,v) in pairs(system)
if k != :bounding_box
if k != :cell_vectors
system_props[k] = v
end
end

cellmat = cell_matrix(system)
newcellmat = cellmat .* supercellvec'
system_props[:bounding_box] = collect(eachcol(newcellmat))
system_props[:cell_vectors] = collect(eachcol(newcellmat))

particles = collect(system)
newparticles = copy(particles)
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using AtomsIO
@test distance(si_primitive, 1, 2) 2.35719227u"Å"
@test distance(si_primitive, 1, 2; pbc=false) 7.07157681u"Å"

box = bounding_box(si_primitive)
box = cell_vectors(si_primitive)
for i in 1:3
@test distance(si_primitive, zeros(3)u"Å", box[i]) 0.0u"Å" atol=1e-8u"Å"
end
Expand Down

2 comments on commit 493696e

@rashidrafeek
Copy link
Owner Author

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/120882

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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.1.2 -m "<description of version>" 493696edb6184c898e9bcf246afdeb1ce9d0d4e1
git push origin v0.1.2

Please sign in to comment.