Datasets:

Modalities:
Image
Size:
< 1K
Libraries:
Datasets
License:
File size: 2,057 Bytes
d4fc45a
 
 
 
 
 
 
 
 
c22034c
d4fc45a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c22034c
 
 
 
 
 
 
 
d4fc45a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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