Datasets:

Modalities:
Image
Size:
< 1K
Libraries:
Datasets
License:
opeltre commited on
Commit
d4fc45a
·
1 Parent(s): 5b0cbb5

add licence, Shells.jl and ShellGen.jl

Browse files
Files changed (3) hide show
  1. LICENSE.md +9 -0
  2. generation/ShellGen.jl +125 -0
  3. generation/Shells.jl +69 -0
LICENSE.md ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Astrid Klipfel, Bastien Casier and Olivier Peltre
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
generation/ShellGen.jl ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ include("Shells.jl")
2
+
3
+ #--- Sample Basis sets ---
4
+
5
+ """
6
+ PairParams(atom, normalize=false[, logdev_rate, logdev_max])
7
+
8
+ Sampling parameters for 2-center 2-shell basis sets.
9
+
10
+ # Note
11
+
12
+ When called as `PairParams(normalize::Bool)`, will sample random atomic numbers
13
+ within `1:10`.
14
+
15
+ # Arguments
16
+ - `atom::Vector{Int64}`: length-2 vector of atomic numbers
17
+ - `normalize::Bool`: whether to normalize integral outputs (if used?)
18
+ - `logdev_rate::Real`: exponential decay rate of the wavelength logarithm distribution
19
+ - `logdev_max::Real`: logarithm of the greatest wavelength
20
+ """
21
+ struct PairParams
22
+ atom::Vector{Int64}
23
+ normalize::Bool
24
+ logdev_rate::Real
25
+ logdev_max::Real
26
+ end
27
+ function PairParams(atom::Vector{Int64}, norm::Bool = false)
28
+ PairParams(atom, norm, 2, .6)
29
+ end
30
+ function PairParams(normalize::Bool = false)
31
+ Z = rand(1:10, 2)
32
+ return PairParams(Z, normalize)
33
+ end
34
+
35
+ """
36
+ randPair(l1, l2[, params])
37
+
38
+ Sample a random 2-shell `Basis`.
39
+ """
40
+ function randPair(l1::Int, l2::Int, params::PairParams)::Basis
41
+ # sample exponents
42
+ exps = begin
43
+ max, rate = params.logdev_max, params.logdev_rate
44
+ log_devs = max .- rand(Exponential(rate), 2)
45
+ devs = exp.(log_devs)
46
+ 1 ./ (2 .* devs .^ 2)
47
+ end
48
+ exp_1 = SVector{1, Float64}(exps[1])
49
+ exp_2 = SVector{1, Float64}(exps[2])
50
+ # sample 2nd atomic position
51
+ xyz = begin
52
+ exp_12 = exps[1] * exps[2] / (exps[1] + exps[2])
53
+ dev_12 = 1 / sqrt(2exp_12)
54
+ SVector{3, Float64}(dev_12 * randn((3)))
55
+ end
56
+ # atom charges
57
+ origin = SVector{3, Float64}(0., 0., 0.)
58
+ pos = (origin, xyz)
59
+ mol = map(zip(params.atom, pos)) do A
60
+ Za, ra = A
61
+ move(atom(Za), ra)
62
+ end
63
+ # basis sets
64
+ coef :: SMatrix{2, 1, Float64} =
65
+ params.normalize ?
66
+ vcat(exp_1, exp_2) ./ 2pi .^ (3 / 4 ) :
67
+ [1., 1.]
68
+ shells = [BasisFunction(l1, coef[1,:], exp_1, mol[1]),
69
+ BasisFunction(l2, coef[2,:], exp_2, mol[2])]
70
+ return (mol, shells)::Basis
71
+ return basis
72
+ end
73
+ randPair(l1::Int, l2::Int, atom::Vector{Int64}) = randPair(l1, l2, PairParams(atom))
74
+ randPair(l1::Int, l2::Int) = begin p = PairParams(); randPair(l1, l2, p); end
75
+ randPair(l::Int, params::PairParams) = randPair(l, l, params)
76
+ randPair(l::Int) = randPair(l, l)
77
+
78
+ """
79
+ QuadParams(r12_dev[, pair])
80
+
81
+ Sampling parameters for 4-center basis sets.
82
+
83
+ # Arguments
84
+ - `r12_dev::Float64`: typical distance between pairwise barycenters
85
+ - `pair::Vector{PairParams}`: sampling parameters for center pairs
86
+ """
87
+ struct QuadParams
88
+ r12_dev::Float64
89
+ pair::Vector{PairParams}
90
+ end
91
+ QuadParams(r12_dev::Float64) = begin
92
+ p = PairParams([1, 1])
93
+ QuadParams(r12_dev, [p, p])
94
+ end
95
+ QuadParams() = QuadParams(.05)
96
+
97
+ """
98
+ randQuadruple(l1, l2, l3, l4[, params, shuflle=false)
99
+
100
+ Sample a random quadruple of shells.
101
+ """
102
+ function randQuadruple(l1::Int, l2::Int, l3::Int, l4::Int, params::QuadParams, shuffle::Bool=false)
103
+ if shuffle
104
+ p = randperm(4)
105
+ p_1 = sortperm(p)
106
+ mol, shells = randQuadruple([l1, l2, l3, l4][p]..., params, false)
107
+ return mol[p_1], shells[p_1]
108
+ end
109
+ # sample offset between the two R³ factors
110
+ r12 = SVector{3, Float64}(params.r12_dev * randn(3))
111
+ # sample pairs and move them
112
+ AB, shells_AB = randPair(l1, l2, params.pair[1])
113
+ CD, shells_CD = randPair(l3, l4, params.pair[2])
114
+ ABCD = append!(center(AB), center(CD, r12))
115
+ shells = append!(shells_AB, shells_CD)
116
+ shells_ABCD = map(zip(ABCD, shells)) do pair
117
+ atom, shell = pair
118
+ BasisFunction(shell.l, shell.coef, shell.exp, atom)
119
+ end
120
+ return ABCD, shells_ABCD
121
+ end
122
+ function randQuadruple(l1::Int, l2::Int, l3::Int, l4::Int, ps...)
123
+ p = QuadParams(ps...)
124
+ randQuadruple(l1, l2, l3, l4, p)
125
+ end
generation/Shells.jl ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using Random
2
+ using Distributions
3
+ using StaticArrays
4
+ using GaussianBasis
5
+ using Molecules
6
+ using PeriodicTable
7
+ using Printf
8
+
9
+ """Type of `GaussianBasis.BasisSet` parameters"""
10
+ const Basis = Tuple{Atom, Vector{BasisFunction}}
11
+
12
+ """
13
+ atom([Z, [xyz]])
14
+
15
+ Return a `Molecules.Atom` instance at specified position.
16
+
17
+ When called with no arguments, `atom()` will return a mass 1 ghost
18
+ atom with zero electric charge.
19
+
20
+ # Arguments
21
+ - `Z::Union{Integer, String}=0` atomic number or symbol.
22
+ - `xyz::SVector{3, Float64}` atom position, defaults to zero.
23
+
24
+ # Examples
25
+ ```jldoctest
26
+ julia> H = atom("H"); # hydrogen atom at 0
27
+ julia> He = atom(2, SVector(0.76, 0., 0.)) # Helium-like center
28
+ julia> ghost = atom(); # ghost center at 0
29
+ ```
30
+ """
31
+ atom(Z::Integer) = Molecules.Atom(Z, Float64(Z), SVector(0., 0., 0.))
32
+ atom(symbol::String) = GaussianBasis.parse_string(symbol * " 0 0 0")[1]
33
+ atom() = Molecules.Atom(0, 1.0, SVector(0., 0., 0.))
34
+ atom(symbol::Union{Integer, String}, xyz::SVector{3, Float64}) = move(atom(symbol), xyz)
35
+ atom(xyz::SVector{3, Float64}) = move(atom(), xyz)
36
+
37
+ """
38
+ Move an atom to a new position.
39
+ """
40
+ move(atom::Molecules.Atom, xyz::SVector{3, Float64})::Molecules.Atom =
41
+ Molecules.Atom(atom.Z, atom.mass, xyz)
42
+
43
+ """
44
+ center(atoms[, offset])
45
+
46
+ Move a vector of atoms to a desired barycenter.
47
+
48
+ All atoms are treated as mass 1.
49
+ """
50
+ function center(atoms::Vector{Molecules.Atom{T, X}}) where T<:Real where X<:Real
51
+ center(atoms, SVector{3, X}([0, 0, 0]))
52
+ end
53
+
54
+ #--- Parse H atom once for all
55
+ HYDROGEN = atom("H")
56
+
57
+ """
58
+ Patch `string_repr(A::Atom)` to accept ghost centers.
59
+ """
60
+ Molecules.string_repr(A::Atom) = begin
61
+ name = haskey(elements, A.Z) ? elements[A.Z].symbol * " " : "∅ "
62
+ out = name * "(Z = $(A.Z))"
63
+ out = out * @sprintf " : %.2f %.2f %.2f" A.xyz...
64
+ end
65
+ Base.show(io::IO, ::MIME"text/plain", at::Atom) = begin
66
+ show(io, Molecules.string_repr(at))
67
+ end
68
+
69
+