add IntegralGen.jl
Browse files- generation/IntegralGen.jl +113 -0
generation/IntegralGen.jl
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
include("ShellGen.jl")
|
| 2 |
+
include("Integrals.jl")
|
| 3 |
+
|
| 4 |
+
"Alias for vectorized pair parameters"
|
| 5 |
+
const NPairParams = Vector{PairParams}
|
| 6 |
+
|
| 7 |
+
"Generate `n` mono-electronic integrals with pairs of momenta `(l1, l2)`."
|
| 8 |
+
function mono_integrals(l1::Int, l2::Int, n::Int)
|
| 9 |
+
dset = Vector{MonoIntegral}(undef, n)
|
| 10 |
+
map!(dset, 1:n) do _
|
| 11 |
+
p = PairParams()
|
| 12 |
+
basis = randPair(l1, l2, p)
|
| 13 |
+
mono_integral(basis)
|
| 14 |
+
end
|
| 15 |
+
end
|
| 16 |
+
|
| 17 |
+
"""Generate a random 2-electron sparse integral."""
|
| 18 |
+
function rand_bi_integral(l::Vector{Int}, param::Union{PairParams, QuadParams})
|
| 19 |
+
if size(l, 1) == 4
|
| 20 |
+
# sample 4-center basis set
|
| 21 |
+
l1, l2, l3, l4 = l
|
| 22 |
+
basis = randQuadruple(l1, l2, l3, l4, param, true)
|
| 23 |
+
elseif size(l, 1) == 2
|
| 24 |
+
l1, l2 = l
|
| 25 |
+
basis = randPair(l1, l2, param)
|
| 26 |
+
end
|
| 27 |
+
# compute integral
|
| 28 |
+
bi_integral(basis)
|
| 29 |
+
end
|
| 30 |
+
function rand_bi_integral(l::Vector{Int})
|
| 31 |
+
rand_bi_integral(l, size(l, 1) == 4 ? QuadParams() : PairParams())
|
| 32 |
+
end
|
| 33 |
+
|
| 34 |
+
"Generate `n` bi-electronic integrals with momenta quadruple `l`."
|
| 35 |
+
function bi_integrals(l::Vector{Int64}, n::Int)
|
| 36 |
+
dset = Vector{BiIntegral4c}(undef, n)
|
| 37 |
+
map!(dset, 1:n) do _
|
| 38 |
+
rand_bi_integral(l)
|
| 39 |
+
end
|
| 40 |
+
stack(dset)
|
| 41 |
+
end
|
| 42 |
+
|
| 43 |
+
"Enumerate quadruples `[l1, l2, l3, l4]`."
|
| 44 |
+
function bi_grid(lmax::Int)
|
| 45 |
+
out = Vector{Int64}[]
|
| 46 |
+
for l1 in 0:lmax
|
| 47 |
+
for l2 in l1:lmax
|
| 48 |
+
for l3 in l1:lmax
|
| 49 |
+
for l4 in l3:lmax
|
| 50 |
+
if l1 == l3 & l2 > l4
|
| 51 |
+
continue
|
| 52 |
+
end
|
| 53 |
+
l::Vector{Int64} = [l1, l2, l3, l4]
|
| 54 |
+
push!(out, l)
|
| 55 |
+
end
|
| 56 |
+
end
|
| 57 |
+
end
|
| 58 |
+
end
|
| 59 |
+
out
|
| 60 |
+
end
|
| 61 |
+
|
| 62 |
+
"Enumerate pairs `[l1, l2]`."
|
| 63 |
+
function mono_grid(lmax::Int)
|
| 64 |
+
out = Vector{Int64}[]
|
| 65 |
+
for l1 in 0:lmax
|
| 66 |
+
for l2 in l1:lmax
|
| 67 |
+
push!(out, [l1, l2])
|
| 68 |
+
end
|
| 69 |
+
end
|
| 70 |
+
out
|
| 71 |
+
end
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
"""
|
| 75 |
+
dump_mono_grid(lmax, n[, out[, h5=True]])
|
| 76 |
+
|
| 77 |
+
Dump mono-electronic integrals for `0 <= l1 <= l2 <= lmax`
|
| 78 |
+
"""
|
| 79 |
+
function dump_mono_grid(lmax::Int, n::Int, out::String, h5=true)
|
| 80 |
+
for (l1, l2) in mono_grid(lmax)
|
| 81 |
+
dset = stack(mono_integrals(l1, l2, n))
|
| 82 |
+
out_12 = out * "_$(l1)_$(l2)" * (h5 ? ".h5" : ".json")
|
| 83 |
+
h5 ? h5dump(out_12, dset) : dump(out_12, dset)
|
| 84 |
+
println("> $(out_12)")
|
| 85 |
+
end
|
| 86 |
+
end
|
| 87 |
+
function dump_mono_grid(lmax::Int, n::Int)
|
| 88 |
+
dump_mono_grid(lmax, n, "out/mono_$(n)")
|
| 89 |
+
end
|
| 90 |
+
|
| 91 |
+
"""
|
| 92 |
+
dump_bi_grid(lmax, n[, out[, h5=true]])
|
| 93 |
+
|
| 94 |
+
Dump bi-electronic integrals.
|
| 95 |
+
"""
|
| 96 |
+
function dump_bi_grid(grid::Vector{Vector{Int}}, n::Int, out::String, h5=true)
|
| 97 |
+
for l in grid
|
| 98 |
+
try
|
| 99 |
+
B = bi_integrals(l, n)
|
| 100 |
+
out_l = out * "_" * join(l, "_")
|
| 101 |
+
h5 ? h5dump(out_l * ".h5", B) : JSONdump(out_l * "*.json", B)
|
| 102 |
+
println("> " * out_l)
|
| 103 |
+
catch e
|
| 104 |
+
println(l, e)
|
| 105 |
+
throw(e)
|
| 106 |
+
end
|
| 107 |
+
end
|
| 108 |
+
end
|
| 109 |
+
function dump_bi_grid(lmax::Int, n::Int, out::String, h5::Bool=true, shells::Int64=4)
|
| 110 |
+
shells == 4 ?
|
| 111 |
+
dump_bi_grid(bi_grid(lmax), n, out, h5) :
|
| 112 |
+
dump_bi_grid(mono_grid(lmax), n, out, h5)
|
| 113 |
+
end
|