From ba88d156854346ebdcfce02cfddfcb0cd38800ba Mon Sep 17 00:00:00 2001 From: Rashid Rafeek Date: Sat, 7 Dec 2024 13:16:39 +0530 Subject: [PATCH] Add system level property definitions removed in AtomsBase 0.5 --- src/AtomsToolbox.jl | 10 ++++++++-- src/getters.jl | 11 ----------- src/piracy.jl | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 src/piracy.jl diff --git a/src/AtomsToolbox.jl b/src/AtomsToolbox.jl index 2db9d1f..62945ea 100644 --- a/src/AtomsToolbox.jl +++ b/src/AtomsToolbox.jl @@ -2,7 +2,8 @@ module AtomsToolbox using Distances: Distances, pairwise, euclidean, peuclidean, Euclidean, PeriodicEuclidean -using AtomsBase: AbstractSystem, +using AtomsBase: AtomsBase, + AbstractSystem, FastSystem, FlexibleSystem, Atom, @@ -12,13 +13,18 @@ using AtomsBase: AbstractSystem, atomic_symbol, atomic_mass, cell_vectors, - periodicity + periodicity, + species using Unitful: Unitful, ustrip, @u_str, unit import Graphs using LinearAlgebra: LinearAlgebra, ⋅, det, norm, lu, × using StaticArrays: StaticMatrix, Size import Base: angle, sort # To extend for AbstractSystem +# Some type piracy to deal with other packages +# Should be upstreamed or removed eventually +include("piracy.jl") + # Constants include("constants.jl") diff --git a/src/getters.jl b/src/getters.jl index 47eddef..6b190b5 100644 --- a/src/getters.jl +++ b/src/getters.jl @@ -1,14 +1,3 @@ -# Workaround for Unitful StaticMatrix not working. -# See: https://github.com/PainterQubits/Unitful.jl/issues/538 -function Base.inv(x::StaticMatrix{N,M,T}) where {N,M,T <: Unitful.AbstractQuantity} - m = inv(ustrip.(x)) - iq = eltype(m) - reinterpret( - Unitful.Quantity{iq, inv(Unitful.dimension(T)), typeof(inv(unit(T)))}, - m - ) -end - # Functions to find shortest distance accounting for PBC, from pymatgen. include("pbc_utils.jl") diff --git a/src/piracy.jl b/src/piracy.jl new file mode 100644 index 0000000..d004a0d --- /dev/null +++ b/src/piracy.jl @@ -0,0 +1,15 @@ +# Workaround for Unitful StaticMatrix not working. +# See: https://github.com/PainterQubits/Unitful.jl/issues/538 +function Base.inv(x::StaticMatrix{N,M,T}) where {N,M,T <: Unitful.AbstractQuantity} + m = inv(ustrip.(x)) + iq = eltype(m) + reinterpret( + Unitful.Quantity{iq, inv(Unitful.dimension(T)), typeof(inv(unit(T)))}, + m + ) +end + +# These were removed in the AtomsBase 0.4 update +Base.position(sys::AbstractSystem) = position.(sys, :) +AtomsBase.atomic_symbol(sys::AbstractSystem) = atomic_symbol.(species(sys, :)) +AtomsBase.atomic_number(sys::AbstractSystem) = atomic_number.(species(sys, :))