From 493696edb6184c898e9bcf246afdeb1ce9d0d4e1 Mon Sep 17 00:00:00 2001 From: Rashid Rafeek Date: Sat, 7 Dec 2024 10:41:41 +0530 Subject: [PATCH] Update to AtomsBase v0.5 (#10) * 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 --- .github/workflows/CI.yml | 3 ++- .github/workflows/documentation.yml | 2 +- Project.toml | 6 +++--- src/AtomsToolbox.jl | 4 ++-- src/atomsbase.jl | 6 +++--- src/build.jl | 6 +++--- src/getters.jl | 22 +++++++++++----------- src/pbc_utils.jl | 4 ++-- src/transform.jl | 14 +++++++------- test/runtests.jl | 2 +- 10 files changed, 35 insertions(+), 34 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index e2df742..1006460 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -18,8 +18,9 @@ jobs: fail-fast: false matrix: version: - - '1.6' + - '1.9' - '1.10' + - '1.11' - 'nightly' os: - ubuntu-latest diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index f22ee05..a667c39 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -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()' diff --git a/Project.toml b/Project.toml index 0113719..c7af703 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "AtomsToolbox" uuid = "f386ec8f-7408-45ea-aa1c-e80969af901e" authors = ["Rashid Rafeek and contributors"] -version = "0.1.1" +version = "0.1.2" [deps] AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a" @@ -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" diff --git a/src/AtomsToolbox.jl b/src/AtomsToolbox.jl index 01ca6a6..2db9d1f 100644 --- a/src/AtomsToolbox.jl +++ b/src/AtomsToolbox.jl @@ -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 diff --git a/src/atomsbase.jl b/src/atomsbase.jl index 175d78b..b15aa80 100644 --- a/src/atomsbase.jl +++ b/src/atomsbase.jl @@ -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 diff --git a/src/build.jl b/src/build.jl index 09ab05c..879bcb6 100644 --- a/src/build.jl +++ b/src/build.jl @@ -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 diff --git a/src/getters.jl b/src/getters.jl index c4faab7..47eddef 100644 --- a/src/getters.jl +++ b/src/getters.jl @@ -17,7 +17,7 @@ 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) @@ -25,7 +25,7 @@ cell_lengths(sys::AbstractSystem) = norm.(bounding_box(sys)) 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((bv⋅cv)/(b*c))u"°" @@ -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((bv⋅cv)/(b*c))u"°" @@ -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 @@ -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 @@ -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 @@ -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 @@ -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' @@ -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 """ diff --git a/src/pbc_utils.jl b/src/pbc_utils.jl index 00d52cb..30169b6 100644 --- a/src/pbc_utils.jl +++ b/src/pbc_utils.jl @@ -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 @@ -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) diff --git a/src/transform.jl b/src/transform.jl index 2d5a248..0f15c22 100644 --- a/src/transform.jl +++ b/src/transform.jl @@ -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 @@ -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 @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index 62919de..ffc47a2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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