using Random using Distributions using StaticArrays using GaussianBasis using Molecules using PeriodicTable using Printf """Type of `GaussianBasis.BasisSet` parameters""" const Basis = Tuple{Vector{A}, Vector{S}} where {A<:Atom, S<:SphericalShell} """ atom([Z, [xyz]]) Return a `Molecules.Atom` instance at specified position. When called with no arguments, `atom()` will return a mass 1 ghost atom with zero electric charge. # Arguments - `Z::Union{Integer, String}=0` atomic number or symbol. - `xyz::SVector{3, Float64}` atom position, defaults to zero. # Examples ```jldoctest julia> H = atom("H"); # hydrogen atom at 0 julia> He = atom(2, SVector(0.76, 0., 0.)) # Helium-like center julia> ghost = atom(); # ghost center at 0 ``` """ atom(Z::Integer) = Molecules.Atom(Z, Float64(Z), SVector(0., 0., 0.)) atom(symbol::String) = GaussianBasis.parse_string(symbol * " 0 0 0")[1] atom() = Molecules.Atom(0, 1.0, SVector(0., 0., 0.)) atom(symbol::Union{Integer, String}, xyz::SVector{3, Float64}) = move(atom(symbol), xyz) atom(xyz::SVector{3, Float64}) = move(atom(), xyz) """ Move an atom to a new position. """ move(atom::Molecules.Atom, xyz::SVector{3, Float64})::Molecules.Atom = Molecules.Atom(atom.Z, atom.mass, xyz) """ center(atoms[, offset]) Move a vector of atoms to a desired barycenter. All atoms are treated as mass 1. """ function center(atoms::Vector{<:Atom}, offset::SVector{3, <:Real}) ctr = sum(a.xyz for a in atoms) / length(atoms) map(atoms) do a move(a, offset - ctr) end end function center(atoms::Vector{<:Atom}) center(atoms, SVector{3, Float64}([0, 0, 0])) end #--- Parse H atom once for all HYDROGEN = atom("H") """ Patch `string_repr(A::Atom)` to accept ghost centers. """ Molecules.string_repr(A::Atom) = begin name = haskey(elements, A.Z) ? elements[A.Z].symbol * " " : "∅ " out = name * "(Z = $(A.Z))" out = out * @sprintf " : %.2f %.2f %.2f" A.xyz... end Base.show(io::IO, ::MIME"text/plain", at::Atom) = begin show(io, Molecules.string_repr(at)) end