Hello, I am writing this function where I need to combine all terms in this structure (called Basis):
struct GaussianBasisSet <: AbstractBasisSet
R
α::Matrix{Float64}
d::Matrix{Float64}
ℓ::Int
m::Int
n::Int
end
Example:
13-element Vector{BasisSets.GaussianBasisSet}:
BasisSets.GaussianBasisSet([0.0 -0.007156 0.965491], [5484.67166 825.234946 … 16.8975704 5.79963534], [0.00183107443 0.0139501722 … 0.470192898 0.358520853], 0, 0, 0)
BasisSets.GaussianBasisSet([0.0 -0.007156 0.965491], [15.53961625 3.599933586 1.01376175], [-0.1107775495 -0.1480262627 1.130767015], 0, 0, 0)
BasisSets.GaussianBasisSet([0.0 -0.007156 0.965491], [15.53961625 3.599933586 1.01376175], [0.07087426823 0.3397528391 0.7271585773], 1, 0, 0)
BasisSets.GaussianBasisSet([0.0 -0.007156 0.965491], [15.53961625 3.599933586 1.01376175], [0.07087426823 0.3397528391 0.7271585773], 0, 1, 0)
BasisSets.GaussianBasisSet([0.0 -0.007156 0.965491], [15.53961625 3.599933586 1.01376175], [0.07087426823 0.3397528391 0.7271585773], 0, 0, 1)
BasisSets.GaussianBasisSet([0.0 -0.007156 0.965491], [0.2700058226;;], [1.0;;], 0, 0, 0)
BasisSets.GaussianBasisSet([0.0 -0.007156 0.965491], [0.2700058226;;], [1.0;;], 1, 0, 0)
BasisSets.GaussianBasisSet([0.0 -0.007156 0.965491], [0.2700058226;;], [1.0;;], 0, 1, 0)
BasisSets.GaussianBasisSet([0.0 -0.007156 0.965491], [0.2700058226;;], [1.0;;], 0, 0, 1)
BasisSets.GaussianBasisSet([0.0 0.001486 -0.003471], [18.73113696 2.825394365 0.6401216923], [0.03349460434 0.2347269535 0.8137573261], 0, 0, 0)
BasisSets.GaussianBasisSet([0.0 0.001486 -0.003471], [0.1612777588;;], [1.0;;], 0, 0, 0)
BasisSets.GaussianBasisSet([0.0 0.931026 1.207929], [18.73113696 2.825394365 0.6401216923], [0.03349460434 0.2347269535 0.8137573261], 0, 0, 0)
BasisSets.GaussianBasisSet([0.0 0.931026 1.207929], [0.1612777588;;], [1.0;;], 0, 0, 0)
function overlap(basis)
K = length(basis)
S = zeros(K, K)
for (i, basisᵢ) in enumerate(basis)
for (j, basisⱼ) in enumerate(basis)
for (αᵢ, dᵢ) in zip(basisᵢ.α, basisᵢ.d)
for (αⱼ, dⱼ) in zip(basisⱼ.α, basisⱼ.d)
Rᵢ = basisᵢ.R
Rⱼ = basisⱼ.R
ℓᵢ, mᵢ, nᵢ = basisᵢ.ℓ, basisᵢ.m, basisᵢ.n
ℓⱼ, mⱼ, nⱼ = basisⱼ.ℓ, basisⱼ.m, basisⱼ.n
S[i, j] += (
exp(-αᵢ * αⱼ * distance(Rᵢ, Rⱼ) / (αᵢ + αⱼ)) *
normalization(αᵢ, ℓᵢ, mᵢ, nᵢ) *
normalization(αⱼ, ℓⱼ, mⱼ, nⱼ) *
dᵢ *
dⱼ *
Sxyz(Rᵢ, Rⱼ, αᵢ, αⱼ, ℓᵢ, ℓⱼ, mᵢ, mⱼ, nᵢ, nⱼ)
)
end
end
end
end
return S
end
However, this is expensive and I would like to reduce the number of for loops to make it more performant. Any tips?