text:
using DandelionWebSockets:
    HTTPHandshakeLogic, getrequestheaders, validateresponse, issuccessful
using Base64

function defaulthandshakelogic(
        rng::FakeRNG{UInt8} = FakeRNG{UInt8}(b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"))
    HTTPHandshakeLogic(rng)
end

@testset "Handshake logic        " begin
    @testset "Requests" begin
        @testset "Sec-WebSocket-Version; Version is 13" begin
            h = defaulthandshakelogic()

            headers = getrequestheaders(h)
            headersdict = Dict(headers)

            @test headersdict["Sec-WebSocket-Version"] == "13"
        end

        @testset "Upgrade header; Upgrade header is 'websocket'" begin
            h = defaulthandshakelogic()

            headers = getrequestheaders(h)
            headersdict = Dict(headers)

            @test headersdict["Upgrade"] == "websocket"
        end

        @testset "Connection header; Has value 'Upgrade'" begin
            h = defaulthandshakelogic()

            headers = getrequestheaders(h)
            headersdict = Dict(headers)

            @test headersdict["Connection"] == "Upgrade"
        end

        @testset "Make two handshakes with different RNGs; Their Sec-WebSocket-Key are different" begin
            rng1 = FakeRNG{UInt8}(b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10")
            h1 = HTTPHandshakeLogic(rng1)
            rng2 = FakeRNG{UInt8}(b"\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x01")
            h2 = HTTPHandshakeLogic(rng2)

            headers1 = getrequestheaders(h1)
            headersdict1 = Dict(headers1)
            headers2 = getrequestheaders(h2)
            headersdict2 = Dict(headers2)

            @test headersdict1["Sec-WebSocket-Key"] != headersdict2["Sec-WebSocket-Key"]
        end

        @testset "Sec-WebSocket-Key; Is 16 bytes when base64 decoded" begin
            h = defaulthandshakelogic()

            headers = getrequestheaders(h)
            headersdict = Dict(headers)

            @test length(base64decode(headersdict["Sec-WebSocket-Key"])) == 16
        end

        # This is an example Sec-WebSocket-Key from the specification, section 4.1.
        @testset "Sec-WebSocket-Key uses nonce 0x01->0x10; Sec-WebSocket-Key is AQIDBAUGBwgJCgsMDQ4PEA==" begin
            h = defaulthandshakelogic()

            headers = getrequestheaders(h)
            headersdict = Dict(headers)

            @test headersdict["Sec-WebSocket-Key"] == "AQIDBAUGBwgJCgsMDQ4PEA=="
        end
    end

    @testset "Validation" begin
        @testset "Response status code is 101; Validation is successful" begin
            h = defaulthandshakelogic()

            responseheaders = [
                "Connection" => "Upgrade",
                "Upgrade" => "websocket",
                "Sec-WebSocket-Accept" => "C/0nmHhBztSRGR1CwL6Tf4ZjwpY=" ]
            result = validateresponse(h, 101, responseheaders)

            @test issuccessful(result)
        end

        @testset "Response status code is 200; Validation is not successful" begin
            h = defaulthandshakelogic()

            responseheaders = [
                "Connection" => "Upgrade",
                "Upgrade" => "websocket",
                "Sec-WebSocket-Accept" => "C/0nmHhBztSRGR1CwL6Tf4ZjwpY="]
            result = validateresponse(h, 200, responseheaders)

            @test !issuccessful(result)
        end

        @testset "Response status code is 500; Validation is not successful" begin
            h = defaulthandshakelogic()

            responseheaders = ["Connection" => "Upgrade",
                "Upgrade" => "websocket",
                "Sec-WebSocket-Accept" => "C/0nmHhBztSRGR1CwL6Tf4ZjwpY="]
            result = validateresponse(h, 500, responseheaders)

            @test !issuccessful(result)
        end

        @testset "Upgrade header has value 'websocket' and Connection is 'Upgrade'; Validation is successful" begin
            h = defaulthandshakelogic()

            responseheaders = [
                "Connection" => "Upgrade",
                "Upgrade" => "websocket",
                "Sec-WebSocket-Accept" => "C/0nmHhBztSRGR1CwL6Tf4ZjwpY=" ]
            result = validateresponse(h, 101, responseheaders)

            @test issuccessful(result)
        end

        @testset "Upgrade header is missing; Validation is not successful" begin
            h = defaulthandshakelogic()

            responseheaders = [
                "Connection" => "Upgrade",
                "Sec-WebSocket-Accept" => "C/0nmHhBztSRGR1CwL6Tf4ZjwpY=" ]
            result = validateresponse(h, 101, responseheaders)

            @test !issuccessful(result)
        end

        @testset "Upgrade header has value 'WEBSOCKET'; Validation is successful" begin
            h = defaulthandshakelogic()

            responseheaders = [
                "Connection" => "Upgrade",
                "Upgrade" => "WEBSOCKET",
                "Sec-WebSocket-Accept" => "C/0nmHhBztSRGR1CwL6Tf4ZjwpY=" ]
            result = validateresponse(h, 101, responseheaders)

            @test issuccessful(result)
        end

        @testset "Upgrade header has a value that is not 'websocket'; Validation is unsuccessful" begin
            h = defaulthandshakelogic()

            responseheaders = [
                "Connection" => "Upgrade",
                "Upgrade" => "Something else",
                "Sec-WebSocket-Accept" => "C/0nmHhBztSRGR1CwL6Tf4ZjwpY=" ]
            result = validateresponse(h, 101, responseheaders)

            @test !issuccessful(result)
        end

        @testset "Connection header is missing; Validation is not successful" begin
            h = defaulthandshakelogic()

            responseheaders = [
                "Upgrade" => "websocket",
                "Sec-WebSocket-Accept" => "C/0nmHhBztSRGR1CwL6Tf4ZjwpY=" ]
            result = validateresponse(h, 101, responseheaders)

            @test !issuccessful(result)
        end

        @testset "Connection header has a value different than 'Upgrade'; Validation is not successful" begin
            h = defaulthandshakelogic()

            responseheaders = [
                "Upgrade" => "websocket",
                "Connection" => "Something else",
                "Sec-WebSocket-Accept" => "C/0nmHhBztSRGR1CwL6Tf4ZjwpY=" ]
            result = validateresponse(h, 101, responseheaders)

            @test !issuccessful(result)
        end

        @testset "Sec-WebSocket-Accept has unexpected value '2jmj7l5rSw0yVb/vlWAYkK/YBwk='; Validation is not successful" begin
            h = defaulthandshakelogic()

            responseheaders = [
                "Upgrade" => "websocket",
                "Connection" => "Upgrade",
                "Sec-Websocket-Accept" => "2jmj7l5rSw0yVb/vlWAYkK/YBwk=" ]
            result = validateresponse(h, 101, responseheaders)

            @test !issuccessful(result)
        end

        @testset "Sec-WebSocket-Accept has the correct value 's3pPLMBiTxaQ9kYGzzhZRbK+xOo='; Validation is successful" begin
            h = defaulthandshakelogic(FakeRNG{UInt8}(
                b"\x74\x68\x65\x20\x73\x61\x6d\x70\x6c\x65\x20\x6e\x6f\x6e\x63\x65"))

            responseheaders = [
                "Connection" => "Upgrade",
                "Upgrade" => "websocket",
                "Sec-WebSocket-Accept" => "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=" ]
            result = validateresponse(h, 101, responseheaders)

            @test issuccessful(result)
        end

        @testset "Headers use correct but lower case headers; Validation is successful" begin
            h = defaulthandshakelogic()

            responseheaders = [
                "connection" => "Upgrade",
                "upgrade" => "websocket",
                "sec-websocket-accept" => "C/0nmHhBztSRGR1CwL6Tf4ZjwpY=" ]
            result = validateresponse(h, 101, responseheaders)

            @test issuccessful(result)
        end
    end
end


text:
using Documenter
using Configurations
using DocThemeIndigo

indigo = DocThemeIndigo.install(Configurations)

makedocs(;
    modules = [Configurations],
    format = Documenter.HTML(
        prettyurls = !("local" in ARGS),
        canonical="https://Roger-luo.github.io/Configurations.jl",
        assets=String[indigo],
    ),
    pages = [
        "Home" => "index.md",
        "Quick Start" => "quick-start.md",
        "Type Conversion" => "convert.md",
        "Advanced Usage" => "advance.md",
        "References" => "ref.md",
    ],
    repo = "https://github.com/Roger-luo/Configurations.jl",
    sitename = "Configurations.jl",
)

deploydocs(; repo = "github.com/Roger-luo/Configurations.jl")

ext: jl


text:
# ModelingToolkit -> SymbolicUtils
SymbolicUtils.istree(x::Operation) = true
function SymbolicUtils.operation(x::Operation)
    if x.op isa Variable
        T = FnType{NTuple{length(x.args), Any}, vartype(x.op)}
        SymbolicUtils.Variable{T}(x.op.name)
    else
        x.op
    end
end

# This is required to infer the right type for
# Operation(Variable{Parameter{Number}}(:foo), [])
# While keeping the metadata that the variable is a parameter.
SymbolicUtils.promote_symtype(f::SymbolicUtils.Sym{FnType{X,Parameter{Y}}},
                              xs...) where {X, Y} = Y

SymbolicUtils.arguments(x::Operation) = x.args

# SymbolicUtils wants raw numbers
SymbolicUtils.to_symbolic(x::Constant) = x.value
SymbolicUtils.to_symbolic(x::Variable{T}) where {T} = SymbolicUtils.Sym{T}(x.name)

# Optional types of vars
# Once converted to SymbolicUtils Variable, a Parameter needs to hide its metadata
_vartype(x::Variable{<:Parameter{T}}) where {T} = T
_vartype(x::Variable{T}) where {T} = T
SymbolicUtils.symtype(x::Variable) = _vartype(x) # needed for a()
SymbolicUtils.symtype(x::SymbolicUtils.Sym{<:Parameter{T}}) where {T} = T

# returning Any causes SymbolicUtils to infer the type using `promote_symtype`
# But we are OK with Number here for now I guess
SymbolicUtils.symtype(x::Expression) = Number

# SymbolicUtils -> ModelingToolkit

simplify(expr::Expression) = SymbolicUtils.simplify(expr) |> to_mtk
simplify(x::Equation) = simplify(x.lhs) ~ simplify(x.rhs)
simplify(expr) = expr |> to_mtk

@deprecate simplify_constants(ex) simplify(ex)

to_mtk(x) = x
to_mtk(x::Number) = Constant(x)
to_mtk(v::SymbolicUtils.Sym{T}) where {T} = Variable{T}(nameof(v))
to_mtk(v::SymbolicUtils.Sym{FnType{X,Y}}) where {X,Y} = Variable{Y}(nameof(v))
function to_mtk(expr::SymbolicUtils.Term)
    Operation(to_mtk(SymbolicUtils.operation(expr)),
              map(to_mtk, SymbolicUtils.arguments(expr)))
end


text:
using Documenter, ICD10Utilities

makedocs(
	 sitename = "ICD-10 Utilities",
	 modules=[ICD10Utilities],
   pages=[
     "ICD-10" => "index.md",
     "icdo3.md",
     "icd10am.md",
     "icd10cm.md"
   ])

deploydocs(
    repo = "github.com/timbp/ICD10Utilities.jl.git",
    devbranch = "main",
)


text:
__precompile__(false)
module SpikeSorting

using StatsBase,Interpolations, Distributions,Flux,FileIO,Dates,Plots,DataStructures,Statistics

export SpikeDetection,FeatureExtraction,Clustering,unitscolor

abstract type SpikeDetection end
abstract type FeatureExtraction end
abstract type Clustering end

unitscolor=[:black,:red,:yellow,:lime,:deepskyblue,:magenta,:darkblue,:orange,:darkgreen,:deeppink,:coral,:cyan,:brown,:plum,:orangered,:darkgoldenrod]

include("FeatureExtraction.jl")
include("Clustering.jl")
include("NeuralNetwork.jl")

end # module

max_stars_repo_name: Experica/SpikeSorting

max_issues_repo_name: Experica/SpikeSorting

max_forks_repo_name: Experica/SpikeSorting


text:
## TODO
# Fix directory to defult to file location

module SIGIL

using Cxx
using Libdl

WINDOW_OPEN = false
include("SIGIL_CORE.jl")

export
# main functions
    slWindow,
    slShowCursor,
    slClose,
    slShouldClose,
    slGetKey,
    slGetMouseButton,
    slGetMouseX,
    slGetMouseY,
    slGetDeltaTime,
    slGetTime,
    slRender,
    slSetBackColor,
    slSetForeColor,
    slSetAdditiveBlend,
    slPush,
    slPop,
    slTranslate,
    slRotate,
    slScale,
    slLoadTexture,
    slLoadWAV,
    slSoundPlay,
    slSoundLoop,
    slSoundPause,
    slSoundStop,
    slSoundPauseAll,
    slSoundResumeAll,
    slSoundStopAll,
    slSoundPlaying,
    slSoundLooping,
    slTriangleFill,
    slTriangleOutline,
    slRectangleFill,
    slRectangleOutline,
    slCircleFill,
    slCircleOutline,
    slSemiCircleFill,
    slSemiCircleOutline,
    slPoint,
    slLine,
    slSetSpriteTiling,
    slSetSpriteScroll,
    slSprite,
    slSetTextAlign,
    slGetTextWidth,
    slGetTextHeight,
    slLoadFont,
    slSetFont,
    slSetFontSize,
    slText

end # module


text:
#### new scheme.

#STR_file_root = "/home/roy/MEGAsync/data/NMR/GISSMO_str_files"

include("../src/GISSMOReader.jl")
import .GISSMOReader

import JSON
import InfoZIP

base_URL = "http://gissmo.nmrfam.wisc.edu/"
unique_cs_tol = 1e-6
zero_tol_sigdigits = 6

#JLD_save_folder = "/home/roy/Documents/repo/NMRData/input/compounds"
coupling_info_folder = "/home/roy/Documents/repo/NMRData/intput/coupling_info"
edata_save_folder = "/home/roy/MEGAsync/data/NMR/GISSMO_edata"

JSON_folder = "/home/roy/Documents/repo/GISSMOReader.jl/GISSMO_info"
JSON_filename = "GISSMO_entries_metadata_Jan_2022.json"
JSON_load_path = joinpath(JSON_folder, JSON_filename)

db_dict = JSON.parse(open(JSON_load_path))

# ###### single entry.
#
# #entry_key = "http://gissmo.nmrfam.wisc.edu/entry/bmse000861/simulation_1"
# entry_key = "http://gissmo.nmrfam.wisc.edu/entry/Maybridge_Ro3_Fragment_10_A08/simulation_1"
# dict = db_dict[entry_key]
#
# molecule_name = dict["molecule_name"]
# eData_URL = "$(base_URL)$(dict["GISSMO experiment URL"])"
#
# simulation_label = split(entry_key, "/")[end]
# entry_label = split(entry_key, "/")[end-1]
#
# coupling_info_folder = "/home/roy/Documents/repo/NMRData/intput/coupling_info"
# edata_save_folder = "/home/roy/MEGAsync/data/NMR/GISSMO_edata"
#
# GISSMOReader.downloadGISSMOedata(molecule_name,
#     simulation_label,
#     entry_label,
#     coupling_info_folder,
#     edata_save_folder,
#     eData_URL;
#     unique_cs_tol = 1e-6,
#     zero_tol_sigdigits = 6)
#
#
# # test loading.
# load_path = "/home/roy/Documents/repo/NMRData/coupling_info/Maybridge_Ro3_Fragment_10_A08_simulation_1.json"
# H_IDs, H_css, J_IDs, J_vals = GISSMOReader.loadcouplinginfojson(load_path)
#
# @assert 1==2

############# all entries in the json.

function getedatakeys(JSON_load_path)

    db_dict = JSON.parse(open(JSON_load_path))

    entry_keys = Vector{String}(undef, 0)
    for (entry_key, dict) in db_dict
        push!(entry_keys, entry_key)
    end

    return entry_keys
end

function batchdownloadGISSMOedata(JSON_load_path,
    entry_keys::Vector{String},
    start_index::Int,
    coupling_info_folder,
    edata_save_folder;
    unique_cs_tol = 1e-6,
    zero_tol_sigdigits = 6,
    keep_zip_file = false)

    db_dict = JSON.parse(open(JSON_load_path))

    for i = start_index:length(entry_keys)

        println("Starting entry_key $(i)")

        entry_key = entry_keys[i]
        dict = db_dict[entry_key]

        molecule_name = dict["molecule_name"]
        eData_URL = "$(base_URL)$(dict["GISSMO experiment URL"])"

        simulation_label = split(entry_key, "/")[end]
        entry_label = split(entry_key, "/")[end-1]

        GISSMOReader.downloadGISSMOedata(molecule_name,
            simulation_label,
            entry_label,
            coupling_info_folder,
            edata_save_folder,
            eData_URL;
            unique_cs_tol = unique_cs_tol,
            zero_tol_sigdigits = zero_tol_sigdigits,
            keep_zip_file = keep_zip_file)
    end
end

key_list = getedatakeys(JSON_load_path)

st_ind = 1
batchdownloadGISSMOedata(JSON_load_path,
    key_list,
    st_ind,
    coupling_info_folder,
    edata_save_folder;
    unique_cs_tol = 1e-6,
    zero_tol_sigdigits = 6,
    keep_zip_file = false)


text:
export basis_data, h2, h2o, ch4, c6h6, lih, ethane

# TODO: Move these into appropriate places, e.g. a data directory

sto3g = [
    # H
    [("S",
      [(3.4252509099999999, 0.15432897000000001),
       (0.62391373000000006, 0.53532813999999995),
       (0.16885539999999999, 0.44463454000000002)])],
    # He
    [("S",
      [(6.3624213899999997, 0.15432897000000001),
       (1.1589229999999999, 0.53532813999999995),
       (0.31364978999999998, 0.44463454000000002)])],
    # Li
    [("S",
      [(16.119575000000001, 0.15432897000000001),
       (2.9362007000000001, 0.53532813999999995),
       (0.79465050000000004, 0.44463454000000002)]),
     ("S",
      [(0.63628969999999996, -0.099967230000000004),
       (0.14786009999999999, 0.39951282999999999),
       (0.048088699999999998, 0.70011546999999996)]),
     ("P",
      [(0.63628969999999996, 0.15591627),
       (0.14786009999999999, 0.60768372000000004),
       (0.048088699999999998, 0.39195739000000002)])],
    # Be
    [("S",
      [(30.167871000000002, 0.15432897000000001),
       (5.4951153000000001, 0.53532813999999995),
       (1.4871927, 0.44463454000000002)]),
     ("S",
      [(1.3148331, -0.099967230000000004),
       (0.3055389, 0.39951282999999999),
       (0.099370700000000006, 0.70011546999999996)]),
     ("P",
      [(1.3148331, 0.15591627),
       (0.3055389, 0.60768372000000004),
       (0.099370700000000006, 0.39195739000000002)])],
    # B
    [("S",
      [(48.791113000000003, 0.15432897000000001),
       (8.8873622000000001, 0.53532813999999995),
       (2.4052669999999998, 0.44463454000000002)]),
     ("S",
      [(2.2369561, -0.099967230000000004),
       (0.51982050000000002, 0.39951282999999999),
       (0.16906180000000001, 0.70011546999999996)]),
     ("P",
      [(2.2369561, 0.15591627),
       (0.51982050000000002, 0.60768372000000004),
       (0.16906180000000001, 0.39195739000000002)])],
    # C
    [("S",
      [(71.616837000000004, 0.15432897000000001),
       (13.045095999999999, 0.53532813999999995),
       (3.5305122, 0.44463454000000002)]),
     ("S",
      [(2.9412493999999998, -0.099967230000000004),
       (0.68348310000000001, 0.39951282999999999),
       (0.22228990000000001, 0.70011546999999996)]),
     ("P",
      [(2.9412493999999998, 0.15591627),
       (0.68348310000000001, 0.60768372000000004),
       (0.22228990000000001, 0.39195739000000002)])],
    # N
    [("S",
      [(99.106168999999994, 0.15432897000000001),
       (18.052312000000001, 0.53532813999999995),
       (4.8856602000000002, 0.44463454000000002)]),
     ("S",
      [(3.7804559000000002, -0.099967230000000004),
       (0.87849659999999996, 0.39951282999999999),
       (0.28571439999999998, 0.70011546999999996)]),
     ("P",
      [(3.7804559000000002, 0.15591627),
       (0.87849659999999996, 0.60768372000000004),
       (0.28571439999999998, 0.39195739000000002)])],
    # O
    [("S",
      [(130.70931999999999, 0.15432897000000001),
       (23.808861, 0.53532813999999995),
       (6.4436083000000002, 0.44463454000000002)]),
     ("S",
      [(5.0331513000000001, -0.099967230000000004),
       (1.1695960999999999, 0.39951282999999999),
       (0.38038899999999998, 0.70011546999999996)]),
     ("P",
      [(5.0331513000000001, 0.15591627),
       (1.1695960999999999, 0.60768372000000004),
       (0.38038899999999998, 0.39195739000000002)])],
    # F
    [("S",
      [(166.67912999999999, 0.15432897000000001),
       (30.360811999999999, 0.53532813999999995),
       (8.2168206999999995, 0.44463454000000002)]),
     ("S",
      [(6.4648032000000004, -0.099967230000000004),
       (1.5022812000000001, 0.39951282999999999),
       (0.48858849999999998, 0.70011546999999996)]),
     ("P",
      [(6.4648032000000004, 0.15591627),
       (1.5022812000000001, 0.60768372000000004),
       (0.48858849999999998, 0.39195739000000002)])],
    # Ne
    [("S",
       [(207.01561000000001, 0.15432897000000001),
        (37.708151000000001, 0.53532813999999995),
        (10.205297, 0.44463454000000002)]),
      ("S",
       [(8.2463151000000003, -0.099967230000000004),
        (1.9162661999999999, 0.39951282999999999),
        (0.62322929999999999, 0.70011546999999996)]),
      ("P",
       [(8.2463151000000003, 0.15591627),
        (1.9162661999999999, 0.60768372000000004),
            (0.62322929999999999, 0.39195739000000002)])]
]

g631ss = [
    # H
    [("S",
      [(18.731137, 0.033494599999999999),
       (2.8253936999999998, 0.23472694999999999),
       (0.64012170000000002, 0.81375732999999995)]),
     ("S", [(0.1612778, 1.0)]),
     ("P", [(1.1000000000000001, 1.0)])],
    # He
    [("S",
      [(38.421633999999997, 0.023765999999999999),
       (5.7780300000000002, 0.15467900000000001),
       (1.2417739999999999, 0.46962999999999999)]),
     ("S", [(0.29796400000000001, 1.0)]),
     ("P", [(1.1000000000000001, 1.0)])],
    # Li
    [("S",
      [(642.41891999999996, 0.0021426000000000001),
       (96.798514999999995, 0.016208899999999998),
       (22.091121000000001, 0.077315599999999998),
       (6.2010702999999996, 0.245786),
       (1.9351176999999999, 0.47018900000000002),
       (0.63673579999999996, 0.34547080000000002)]),
     ("S",
      [(2.3249184000000001, -0.035091700000000003),
       (0.63243059999999995, -0.19123280000000001),
       (0.079053399999999996, 1.0839878000000001)]),
     ("P",
      [(2.3249184000000001, 0.0089414999999999998),
       (0.63243059999999995, 0.14100950000000001),
       (0.079053399999999996, 0.94536370000000003)]),
     ("S", [(0.035962000000000001, 1.0)]),
     ("P", [(0.035962000000000001, 1.0)]),
     ("D", [(0.20000000000000001, 1.0)])],
    # Be
    [("S",
      [(1264.5857000000001, 0.0019448),
       (189.93681000000001, 0.0148351),
       (43.159089000000002, 0.072090600000000005),
       (12.098663, 0.23715420000000001),
       (3.8063232, 0.46919870000000002),
       (1.2728903, 0.35652020000000001)]),
     ("S",
      [(3.1964630999999999, -0.1126487),
       (0.74781330000000001, -0.2295064),
       (0.2199663, 1.1869167)]),
     ("P",
      [(3.1964630999999999, 0.055980200000000001),
       (0.74781330000000001, 0.26155060000000002),
       (0.2199663, 0.79397229999999996)]),
     ("S", [(0.082309900000000005, 1.0)]),
     ("P", [(0.082309900000000005, 1.0)]),
     ("D", [(0.40000000000000002, 1.0)])],
    # B
    [("S",
      [(2068.8823000000002, 0.0018663),
       (310.64956999999998, 0.0142515),
       (70.683032999999995, 0.069551600000000005),
       (19.861080000000001, 0.2325729),
       (6.2993047999999998, 0.46707870000000001),
       (2.127027, 0.36343140000000002)]),
     ("S",
      [(4.7279710000000001, -0.1303938),
       (1.1903376999999999, -0.13078890000000001),
       (0.3594117, 1.1309444)]),
     ("P",
      [(4.7279710000000001, 0.0745976),
       (1.1903376999999999, 0.30784669999999997),
       (0.3594117, 0.74345680000000003)]),
     ("S", [(0.12675120000000001, 1.0)]),
     ("P", [(0.12675120000000001, 1.0)]),
     ("D", [(0.59999999999999998, 1.0)])],
    # C
    [("S",
      [(3047.5248999999999, 0.0018347000000000001),
       (457.36950999999999, 0.014037300000000001),
       (103.94869, 0.068842600000000004),
       (29.210155, 0.23218440000000001),
       (9.2866630000000008, 0.4679413),
       (3.1639270000000002, 0.36231200000000002)]),
     ("S",
      [(7.8682724000000004, -0.11933240000000001),
       (1.8812884999999999, -0.1608542),
       (0.54424930000000005, 1.1434564)]),
     ("P",
      [(7.8682724000000004, 0.068999099999999994),
       (1.8812884999999999, 0.31642399999999998),
       (0.54424930000000005, 0.74430830000000003)]),
     ("S", [(0.16871439999999999, 1.0)]),
     ("P", [(0.16871439999999999, 1.0)]),
     ("D", [(0.80000000000000004, 1.0)])],
    # N
    [("S",
      [(4173.5110000000004, 0.0018347999999999999),
       (627.4579, 0.013995),
       (142.90209999999999, 0.068586999999999995),
       (40.23433, 0.232241),
       (12.820209999999999, 0.46906999999999999),
       (4.3904370000000004, 0.36045500000000003)]),
     ("S",
      [(11.626358, -0.11496099999999999),
       (2.7162799999999998, -0.16911799999999999),
       (0.77221799999999996, 1.1458520000000001)]),
     ("P",
      [(11.626358, 0.067580000000000001),
       (2.7162799999999998, 0.323907),
       (0.77221799999999996, 0.74089499999999997)]),
     ("S", [(0.21203130000000001, 1.0)]),
     ("P", [(0.21203130000000001, 1.0)]),
     ("D", [(0.80000000000000004, 1.0)])],
    # O
    [("S",
      [(5484.6716999999999, 0.0018311),
       (825.23495000000003, 0.0139501),
       (188.04696000000001, 0.068445099999999995),
       (52.964500000000001, 0.23271430000000001),
       (16.897570000000002, 0.47019300000000003),
       (5.7996353000000003, 0.35852089999999998)]),
     ("S",
      [(15.539616000000001, -0.1107775),
       (3.5999336, -0.1480263),
       (1.0137617999999999, 1.1307670000000001)]),
     ("P",
      [(15.539616000000001, 0.070874300000000001),
       (3.5999336, 0.33975280000000002),
       (1.0137617999999999, 0.72715859999999999)]),
     ("S", [(0.27000580000000002, 1.0)]),
     ("P", [(0.27000580000000002, 1.0)]),
     ("D", [(0.80000000000000004, 1.0)])],
    # F
    [("S",
      [(7001.7130900000002, 0.0018196168999999999),
       (1051.36609, 0.013916079600000001),
       (239.28568999999999, 0.068405324500000003),
       (67.397445300000001, 0.23318575999999999),
       (21.519957300000002, 0.47126743900000001),
       (7.4031013000000003, 0.35661854599999998)]),
     ("S",
      [(20.847952800000002, -0.10850697500000001),
       (4.80830834, -0.14645165800000001),
       (1.3440698600000001, 1.1286885799999999)]),
     ("P",
      [(20.847952800000002, 0.071628724300000002),
       (4.80830834, 0.34591210300000003),
       (1.3440698600000001, 0.72246995700000005)]),
     ("S", [(0.35815139299999998, 1.0)]),
     ("P", [(0.35815139299999998, 1.0)]),
     ("D", [(0.80000000000000004, 1.0)])],
    # Ne
    [("S",
       [(8425.8515299999999, 0.0018843480999999999),
        (1268.5193999999999, 0.0143368994),
        (289.62141400000002, 0.070109623300000007),
        (81.859003999999999, 0.237373266),
        (26.2515079, 0.473007126),
        (9.0947205100000001, 0.34840124099999997)]),
      ("S",
       [(26.532131, -0.10711828700000001),
        (6.1017550099999998, -0.146163821),
        (1.69627153, 1.1277735)]),
      ("P",
       [(26.532131, 0.071909588499999996),
        (6.1017550099999998, 0.34951337199999999),
        (1.69627153, 0.71994051199999998)]),
      ("S", [(0.44581870000000001, 1.0)]),
      ("P", [(0.44581870000000001, 1.0)]),
     ("D", [(0.80000000000000004, 1.0)])]
]

g631 = [
    # H
    [("S",
      [(18.731137, 0.033494599999999999),
       (2.8253936999999998, 0.23472694999999999),
       (0.64012170000000002, 0.81375732999999995)]),
     ("S", [(0.1612778, 1.0)])],
    # He
    [("S",
      [(38.421633999999997, 0.023765999999999999),
       (5.7780300000000002, 0.15467900000000001),
       (1.2417739999999999, 0.46962999999999999)]),
     ("S", [(0.29796400000000001, 1.0)])],
    # Li
    [("S",
      [(642.41891999999996, 0.0021426000000000001),
       (96.798514999999995, 0.016208899999999998),
       (22.091121000000001, 0.077315599999999998),
       (6.2010702999999996, 0.245786),
       (1.9351176999999999, 0.47018900000000002),
       (0.63673579999999996, 0.34547080000000002)]),
     ("S",
      [(2.3249184000000001, -0.035091700000000003),
       (0.63243059999999995, -0.19123280000000001),
       (0.079053399999999996, 1.0839878000000001)]),
     ("P",
      [(2.3249184000000001, 0.0089414999999999998),
       (0.63243059999999995, 0.14100950000000001),
       (0.079053399999999996, 0.94536370000000003)]),
     ("S", [(0.035962000000000001, 1.0)]),
     ("P", [(0.035962000000000001, 1.0)])],
    # Be
    [("S",
      [(1264.5857000000001, 0.0019448),
       (189.93681000000001, 0.0148351),
       (43.159089000000002, 0.072090600000000005),
       (12.098663, 0.23715420000000001),
       (3.8063232, 0.46919870000000002),
       (1.2728903, 0.35652020000000001)]),
     ("S",
      [(3.1964630999999999, -0.1126487),
       (0.74781330000000001, -0.2295064),
       (0.2199663, 1.1869167)]),
     ("P",
      [(3.1964630999999999, 0.055980200000000001),
       (0.74781330000000001, 0.26155060000000002),
       (0.2199663, 0.79397229999999996)]),
     ("S", [(0.082309900000000005, 1.0)]),
     ("P", [(0.082309900000000005, 1.0)])],
    # B
    [("S",
      [(2068.8823000000002, 0.0018663),
       (310.64956999999998, 0.0142515),
       (70.683032999999995, 0.069551600000000005),
       (19.861080000000001, 0.2325729),
       (6.2993047999999998, 0.46707870000000001),
       (2.127027, 0.36343140000000002)]),
     ("S",
      [(4.7279710000000001, -0.1303938),
       (1.1903376999999999, -0.13078890000000001),
       (0.3594117, 1.1309444)]),
     ("P",
      [(4.7279710000000001, 0.0745976),
       (1.1903376999999999, 0.30784669999999997),
       (0.3594117, 0.74345680000000003)]),
     ("S", [(0.12675120000000001, 1.0)]),
     ("P", [(0.12675120000000001, 1.0)])],
    # C
    [("S",
      [(3047.5248999999999, 0.0018347000000000001),
       (457.36950999999999, 0.014037300000000001),
       (103.94869, 0.068842600000000004),
       (29.210155, 0.23218440000000001),
       (9.2866630000000008, 0.4679413),
       (3.1639270000000002, 0.36231200000000002)]),
     ("S",
      [(7.8682724000000004, -0.11933240000000001),
       (1.8812884999999999, -0.1608542),
       (0.54424930000000005, 1.1434564)]),
     ("P",
      [(7.8682724000000004, 0.068999099999999994),
       (1.8812884999999999, 0.31642399999999998),
       (0.54424930000000005, 0.74430830000000003)]),
     ("S", [(0.16871439999999999, 1.0)]),
     ("P", [(0.16871439999999999, 1.0)])],
    # N
    [("S",
      [(4173.5110000000004, 0.0018347999999999999),
       (627.4579, 0.013995),
       (142.90209999999999, 0.068586999999999995),
       (40.23433, 0.232241),
       (12.820209999999999, 0.46906999999999999),
       (4.3904370000000004, 0.36045500000000003)]),
     ("S",
      [(11.626358, -0.11496099999999999),
       (2.7162799999999998, -0.16911799999999999),
       (0.77221799999999996, 1.1458520000000001)]),
     ("P",
      [(11.626358, 0.067580000000000001),
       (2.7162799999999998, 0.323907),
       (0.77221799999999996, 0.74089499999999997)]),
     ("S", [(0.21203130000000001, 1.0)]),
     ("P", [(0.21203130000000001, 1.0)])],
    # O
    [("S",
      [(5484.6716999999999, 0.0018311),
       (825.23495000000003, 0.0139501),
       (188.04696000000001, 0.068445099999999995),
       (52.964500000000001, 0.23271430000000001),
       (16.897570000000002, 0.47019300000000003),
       (5.7996353000000003, 0.35852089999999998)]),
     ("S",
      [(15.539616000000001, -0.1107775),
       (3.5999336, -0.1480263),
       (1.0137617999999999, 1.1307670000000001)]),
     ("P",
      [(15.539616000000001, 0.070874300000000001),
       (3.5999336, 0.33975280000000002),
       (1.0137617999999999, 0.72715859999999999)]),
     ("S", [(0.27000580000000002, 1.0)]),
     ("P", [(0.27000580000000002, 1.0)])],
    # F
    [("S",
      [(7001.7130900000002, 0.0018196168999999999),
       (1051.36609, 0.013916079600000001),
       (239.28568999999999, 0.068405324500000003),
       (67.397445300000001, 0.23318575999999999),
       (21.519957300000002, 0.47126743900000001),
       (7.4031013000000003, 0.35661854599999998)]),
     ("S",
      [(20.847952800000002, -0.10850697500000001),
       (4.80830834, -0.14645165800000001),
       (1.3440698600000001, 1.1286885799999999)]),
     ("P",
      [(20.847952800000002, 0.071628724300000002),
       (4.80830834, 0.34591210300000003),
       (1.3440698600000001, 0.72246995700000005)]),
     ("S", [(0.35815139299999998, 1.0)]),
     ("P", [(0.35815139299999998, 1.0)])],
    # Ne
    [("S",
      [(8425.8515299999999, 0.0018843480999999999),
       (1268.5193999999999, 0.0143368994),
       (289.62141400000002, 0.070109623300000007),
       (81.859003999999999, 0.237373266),
       (26.2515079, 0.473007126),
       (9.0947205100000001, 0.34840124099999997)]),
     ("S",
      [(26.532131, -0.10711828700000001),
       (6.1017550099999998, -0.146163821),
       (1.69627153, 1.1277735)]),
     ("P",
      [(26.532131, 0.071909588499999996),
       (6.1017550099999998, 0.34951337199999999),
       (1.69627153, 0.71994051199999998)]),
     ("S", [(0.44581870000000001, 1.0)]),
     ("P", [(0.44581870000000001, 1.0)])]
]

ccpvdz = [
  # H
  [("S",
    [(13.01, 0.019685000000000001),
      (1.962, 0.13797699999999999),
      (0.4446, 0.47814800000000002),
      (0.122, 0.50124000000000002)]),
    ("S", [(0.122, 1.0)]),
    ("P", [(0.72699999999999998, 1.0)])],
     # He
    [("S",
      [(38.359999999999999, 0.023809),
       (5.7699999999999996, 0.154891),
       (1.24, 0.46998699999999999),
       (0.29759999999999998, 0.51302700000000001)]),
     ("S", [(0.29759999999999998, 1.0)]),
     ("P", [(1.2749999999999999, 1.0)])],
     # Li
    [("S",
      [(1469.0, 0.00076599999999999997),
       (220.5, 0.0058919999999999997),
       (50.259999999999998, 0.029670999999999999),
       (14.24, 0.10918),
       (4.5810000000000004, 0.28278900000000001),
       (1.5800000000000001, 0.453123),
       (0.56399999999999995, 0.27477400000000002),
       (0.073450000000000001, 0.0097509999999999993),
       (0.028049999999999999, -0.0031800000000000001)])],
     [("S",
      [(1469.0, -0.00012),
       (220.5, -0.00092299999999999999),
       (50.259999999999998, -0.0046889999999999996),
       (14.24, -0.017682),
       (4.5810000000000004, -0.048902000000000001),
       (1.5800000000000001, -0.096008999999999997),
       (0.56399999999999995, -0.13638),
       (0.073450000000000001, 0.575102),
       (0.028049999999999999, 0.51766100000000004)]),
     ("S", [(0.028049999999999999, 1.0)]),
     ("P",
      [(1.534, 0.022783999999999999),
       (0.27489999999999998, 0.13910700000000001),
       (0.073620000000000005, 0.50037500000000001),
       (0.024029999999999999, 0.50847399999999998)]),
     ("P", [(0.024029999999999999, 1.0)]),
     ("D", [(0.1239, 1.0)])],
     # Be
    [("S",
      [(2940.0, 0.00068000000000000005),
       (441.19999999999999, 0.0052360000000000002),
       (100.5, 0.026606000000000001),
       (28.43, 0.099992999999999999),
       (9.1690000000000005, 0.269702),
       (3.1960000000000002, 0.45146900000000001),
       (1.159, 0.295074),
       (0.18110000000000001, 0.012586999999999999),
       (0.058900000000000001, -0.0037559999999999998)]),
     ("S",
      [(2940.0, -0.00012300000000000001),
       (441.19999999999999, -0.00096599999999999995),
       (100.5, -0.0048310000000000002),
       (28.43, -0.019314000000000001),
       (9.1690000000000005, -0.053280000000000001),
       (3.1960000000000002, -0.120723),
       (1.159, -0.133435),
       (0.18110000000000001, 0.53076699999999999),
       (0.058900000000000001, 0.58011699999999999)]),
     ("S", [(0.058900000000000001, 1.0)]),
     ("P",
      [(3.6190000000000002, 0.029111000000000001),
       (0.71099999999999997, 0.16936499999999999),
       (0.1951, 0.51345799999999997),
       (0.060179999999999997, 0.47933799999999999)]),
     ("P", [(0.060179999999999997, 1.0)]),
     ("D", [(0.23799999999999999, 1.0)])],
     # B
    [("S",
      [(4570.0, 0.000696),
       (685.89999999999998, 0.0053530000000000001),
       (156.5, 0.027133999999999998),
       (44.469999999999999, 0.10138),
       (14.48, 0.27205499999999999),
       (5.1310000000000002, 0.448403),
       (1.8979999999999999, 0.29012300000000002),
       (0.33289999999999997, 0.014322),
       (0.1043, -0.0034859999999999999)]),
     ("S",
      [(4570.0, -0.00013899999999999999),
       (685.89999999999998, -0.0010970000000000001),
       (156.5, -0.0054440000000000001),
       (44.469999999999999, -0.021916000000000001),
       (14.48, -0.059750999999999999),
       (5.1310000000000002, -0.13873199999999999),
       (1.8979999999999999, -0.13148199999999999),
       (0.33289999999999997, 0.53952599999999995),
       (0.1043, 0.58077400000000001)]),
     ("S", [(0.1043, 1.0)]),
     ("P",
      [(6.0010000000000003, 0.035480999999999999),
       (1.2410000000000001, 0.198072),
       (0.33639999999999998, 0.50522999999999996),
       (0.095380000000000006, 0.47949900000000001)]),
     ("P", [(0.095380000000000006, 1.0)]),
     ("D", [(0.34300000000000003, 1.0)])],
     # C
    [("S",
      [(6665.0, 0.00069200000000000002),
       (1000.0, 0.0053290000000000004),
       (228.0, 0.027077),
       (64.709999999999994, 0.101718),
       (21.059999999999999, 0.27473999999999998),
       (7.4950000000000001, 0.44856400000000002),
       (2.7970000000000002, 0.28507399999999999),
       (0.52149999999999996, 0.015204000000000001),
       (0.15959999999999999, -0.0031909999999999998)]),
     ("S",
      [(6665.0, -0.000146),
       (1000.0, -0.0011540000000000001),
       (228.0, -0.0057250000000000001),
       (64.709999999999994, -0.023311999999999999),
       (21.059999999999999, -0.063954999999999998),
       (7.4950000000000001, -0.149981),
       (2.7970000000000002, -0.12726199999999999),
       (0.52149999999999996, 0.54452900000000004),
       (0.15959999999999999, 0.58049600000000001)]),
     ("S", [(0.15959999999999999, 1.0)]),
     ("P",
      [(9.4390000000000001, 0.038108999999999997),
       (2.0019999999999998, 0.20948),
       (0.54559999999999997, 0.50855700000000004),
       (0.1517, 0.46884199999999998)]),
     ("P", [(0.1517, 1.0)]),
     ("D", [(0.55000000000000004, 1.0)])],
     # N
    [("S",
      [(9046.0, 0.00069999999999999999),
       (1357.0, 0.0053889999999999997),
       (309.30000000000001, 0.027406),
       (87.730000000000004, 0.10320699999999999),
       (28.559999999999999, 0.278723),
       (10.210000000000001, 0.44853999999999999),
       (3.8380000000000001, 0.27823799999999999),
       (0.74660000000000004, 0.015440000000000001),
       (0.2248, -0.0028639999999999998)]),
     ("S",
      [(9046.0, -0.00015300000000000001),
       (1357.0, -0.0012080000000000001),
       (309.30000000000001, -0.0059919999999999999),
       (87.730000000000004, -0.024544),
       (28.559999999999999, -0.067459000000000005),
       (10.210000000000001, -0.158078),
       (3.8380000000000001, -0.12183099999999999),
       (0.74660000000000004, 0.54900300000000002),
       (0.2248, 0.57881499999999997)]),
     ("S", [(0.2248, 1.0)]),
     ("P",
      [(13.550000000000001, 0.039919000000000003),
       (2.9169999999999998, 0.217169),
       (0.79730000000000001, 0.51031899999999997),
       (0.2185, 0.46221400000000001)]),
     ("P", [(0.2185, 1.0)]),
     ("D", [(0.81699999999999995, 1.0)])],
     # O
    [("S",
      [(11720.0, 0.00071000000000000002),
       (1759.0, 0.00547),
       (400.80000000000001, 0.027837000000000001),
       (113.7, 0.1048),
       (37.030000000000001, 0.28306199999999998),
       (13.27, 0.44871899999999998),
       (5.0250000000000004, 0.27095200000000003),
       (1.0129999999999999, 0.015458),
       (0.30230000000000001, -0.0025850000000000001)]),
     ("S",
      [(11720.0, -0.00016000000000000001),
       (1759.0, -0.001263),
       (400.80000000000001, -0.006267),
       (113.7, -0.025715999999999999),
       (37.030000000000001, -0.070924000000000001),
       (13.27, -0.165411),
       (5.0250000000000004, -0.116955),
       (1.0129999999999999, 0.55736799999999997),
       (0.30230000000000001, 0.57275900000000002)]),
     ("S", [(0.30230000000000001, 1.0)]),
     ("P",
      [(17.699999999999999, 0.043018000000000001),
       (3.8540000000000001, 0.22891300000000001),
       (1.046, 0.50872799999999996),
       (0.27529999999999999, 0.46053100000000002)]),
     ("P", [(0.27529999999999999, 1.0)]),
     ("D", [(1.1850000000000001, 1.0)])],
     # F
    [("S",
      [(14710.0, 0.00072099999999999996),
       (2207.0, 0.0055529999999999998),
       (502.80000000000001, 0.028267),
       (142.59999999999999, 0.106444),
       (46.469999999999999, 0.28681400000000001),
       (16.699999999999999, 0.44864100000000001),
       (6.3559999999999999, 0.26476100000000002),
       (1.3160000000000001, 0.015332999999999999),
       (0.38969999999999999, -0.0023319999999999999)]),
     ("S",
      [(14710.0, -0.000165),
       (2207.0, -0.0013079999999999999),
       (502.80000000000001, -0.0064949999999999999),
       (142.59999999999999, -0.026690999999999999),
       (46.469999999999999, -0.073690000000000005),
       (16.699999999999999, -0.17077600000000001),
       (6.3559999999999999, -0.112327),
       (1.3160000000000001, 0.56281400000000004),
       (0.38969999999999999, 0.56877800000000001)]),
     ("S", [(0.38969999999999999, 1.0)]),
     ("P",
      [(22.670000000000002, 0.044878000000000001),
       (4.9770000000000003, 0.23571800000000001),
       (1.347, 0.508521),
       (0.34710000000000002, 0.45812000000000003)]),
     ("P", [(0.34710000000000002, 1.0)]),
     ("D", [(1.6399999999999999, 1.0)])],
     #Ne
    [("S",
       [(17880.0, 0.00073800000000000005),
        (2683.0, 0.0056769999999999998),
        (611.5, 0.028882999999999999),
        (173.5, 0.10854),
        (56.640000000000001, 0.29090700000000003),
        (20.420000000000002, 0.448324),
        (7.8099999999999996, 0.25802599999999998),
        (1.653, 0.015063),
        (0.4869, -0.0020999999999999999)]),
      ("S",
       [(17880.0, -0.00017200000000000001),
        (2683.0, -0.0013569999999999999),
        (611.5, -0.0067369999999999999),
        (173.5, -0.027663),
        (56.640000000000001, -0.076207999999999998),
        (20.420000000000002, -0.17522699999999999),
        (7.8099999999999996, -0.10703799999999999),
        (1.653, 0.56705000000000005),
        (0.4869, 0.56521600000000005)]),
      ("S", [(0.4869, 1.0)]),
      ("P",
       [(28.390000000000001, 0.046087000000000003),
        (6.2699999999999996, 0.24018100000000001),
        (1.6950000000000001, 0.50874399999999997),
        (0.43169999999999997, 0.45566000000000001)]),
      ("P", [(0.43169999999999997, 1.0)]),
      ("D", [(2.202, 1.0)])],
      # Na
    [("S",
       [(31700.0, 0.00045887800000000002),
        (4755.0, 0.0035506999999999999),
        (1082.0, 0.018261800000000002),
        (306.39999999999998, 0.071665000000000006),
        (99.530000000000001, 0.21234600000000001),
        (35.420000000000002, 0.41620299999999999),
        (13.300000000000001, 0.37302000000000002),
        (4.3920000000000003, 0.062505400000000003),
        (1.6759999999999999, -0.0062453200000000004),
        (0.58889999999999998, 0.0024337400000000002),
        (0.056399999999999999, -0.00044238099999999999),
        (0.02307, 0.000241924)]),
      ("S",
       [(31700.0, -0.000112162),
        (4755.0, -0.00086851199999999999),
        (1082.0, -0.0045132999999999996),
        (306.39999999999998, -0.018143599999999999),
        (99.530000000000001, -0.058079899999999997),
        (35.420000000000002, -0.137653),
        (13.300000000000001, -0.193908),
        (4.3920000000000003, 0.085800899999999999),
        (1.6759999999999999, 0.60441900000000004),
        (0.58889999999999998, 0.44171899999999997),
        (0.056399999999999999, 0.013054700000000001),
        (0.02307, -0.0056808500000000003)]),
      ("S",
       [(31700.0, 1.7016000000000001e-05),
        (4755.0, 0.000130693),
        (1082.0, 0.00068778399999999999),
        (306.39999999999998, 0.0027235900000000001),
        (99.530000000000001, 0.0089552899999999994),
        (35.420000000000002, 0.020783200000000002),
        (13.300000000000001, 0.031938000000000001),
        (4.3920000000000003, -0.019136799999999999),
        (1.6759999999999999, -0.10259500000000001),
        (0.58889999999999998, -0.19894500000000001),
        (0.056399999999999999, 0.65595199999999998),
        (0.02307, 0.43115300000000001)]),
      ("S", [(0.02307, 1.0)]),
      ("P",
       [(138.09999999999999, 0.0057964100000000001),
        (32.240000000000002, 0.041575599999999997),
        (9.9849999999999994, 0.16287299999999999),
        (3.484, 0.35940100000000003),
        (1.2310000000000001, 0.449988),
        (0.41770000000000002, 0.22750699999999999),
        (0.065129999999999993, 0.0080824699999999996),
        (0.02053, -0.0019629299999999999)]),
      ("P",
       [(138.09999999999999, -0.00058153100000000004),
        (32.240000000000002, -0.0040730599999999999),
        (9.9849999999999994, -0.016793700000000002),
        (3.484, -0.035326799999999998),
        (1.2310000000000001, -0.052197100000000003),
        (0.41770000000000002, -0.016835900000000001),
        (0.065129999999999993, 0.43461300000000003),
        (0.02053, 0.65821799999999997)]),
      ("P", [(0.02053, 1.0)]),
      ("D", [(0.097299999999999998, 1.0)])],
    [("S",
       [(47390.0, 0.00034602299999999999),
        (7108.0, 0.0026807699999999999),
        (1618.0, 0.0138367),
        (458.39999999999998, 0.055176700000000002),
        (149.30000000000001, 0.16966000000000001),
        (53.590000000000003, 0.364703),
        (20.699999999999999, 0.406856),
        (8.3840000000000003, 0.13508899999999999),
        (2.5419999999999998, 0.0049088400000000003),
        (0.87870000000000004, 0.00028645999999999999),
        (0.1077, 2.6458999999999999e-05),
        (0.039989999999999998, -1.1270800000000001e-05)]),
      ("S",
       [(47390.0, -8.7783900000000005e-05),
        (7108.0, -0.00067472500000000004),
        (1618.0, -0.00355603),
        (458.39999999999998, -0.0142154),
        (149.30000000000001, -0.047674800000000003),
        (53.590000000000003, -0.11489199999999999),
        (20.699999999999999, -0.20067599999999999),
        (8.3840000000000003, -0.034122399999999997),
        (2.5419999999999998, 0.57045400000000002),
        (0.87870000000000004, 0.54230900000000004),
        (0.1077, 0.0218128),
        (0.039989999999999998, -0.0082769999999999996)]),
      ("S",
       [(47390.0, 1.69628e-05),
        (7108.0, 0.000129865),
        (1618.0, 0.00068883099999999999),
        (458.39999999999998, 0.0027353299999999998),
        (149.30000000000001, 0.0093122399999999994),
        (53.590000000000003, 0.022326499999999999),
        (20.699999999999999, 0.041119500000000003),
        (8.3840000000000003, 0.00545642),
        (2.5419999999999998, -0.13401199999999999),
        (0.87870000000000004, -0.25617600000000001),
        (0.1077, 0.60585599999999995),
        (0.039989999999999998, 0.50944599999999995)]),
      ("S", [(0.039989999999999998, 1.0)]),
      ("P",
       [(179.90000000000001, 0.0053816100000000002),
        (42.140000000000001, 0.0392418),
        (13.130000000000001, 0.157445),
        (4.6280000000000001, 0.35853499999999999),
        (1.6699999999999999, 0.45722600000000002),
        (0.5857, 0.215918),
        (0.13109999999999999, 0.0066494800000000001),
        (0.041119999999999997, -0.00012530399999999999)]),
      ("P",
       [(179.90000000000001, -0.00086594799999999996),
        (42.140000000000001, -0.0061597800000000001),
        (13.130000000000001, -0.026151899999999999),
        (4.6280000000000001, -0.057064700000000003),
        (1.6699999999999999, -0.087390599999999999),
        (0.5857, -0.012298999999999999),
        (0.13109999999999999, 0.502085),
        (0.041119999999999997, 0.59724500000000003)]),
      ("P", [(0.041119999999999997, 1.0)]),
      ("D", [(0.187, 1.0)])],
    [("S",
       [(64150.0, 0.00029024999999999998),
        (9617.0, 0.0022506399999999999),
        (2189.0, 0.011645900000000001),
        (620.5, 0.0467377),
        (202.69999999999999, 0.14629900000000001),
        (73.150000000000006, 0.33028299999999999),
        (28.550000000000001, 0.41586099999999998),
        (11.77, 0.189253),
        (3.2999999999999998, 0.011588899999999999),
        (1.173, -0.00128385),
        (0.17519999999999999, 0.000425883),
        (0.064729999999999996, -0.00019928)]),
      ("S",
       [(64150.0, -7.5804799999999996e-05),
        (9617.0, -0.00058179100000000001),
        (2189.0, -0.0030811300000000001),
        (620.5, -0.0123112),
        (202.69999999999999, -0.041978099999999997),
        (73.150000000000006, -0.103371),
        (28.550000000000001, -0.19630800000000001),
        (11.77, -0.083000199999999996),
        (3.2999999999999998, 0.54103999999999997),
        (1.173, 0.57879599999999998),
        (0.17519999999999999, 0.028814699999999999),
        (0.064729999999999996, -0.0095379499999999999)]),
      ("S",
       [(64150.0, 1.7507799999999999e-05),
        (9617.0, 0.000134208),
        (2189.0, 0.00071244199999999998),
        (620.5, 0.0028433),
        (202.69999999999999, 0.0097684199999999999),
        (73.150000000000006, 0.024185000000000002),
        (28.550000000000001, 0.047499300000000001),
        (11.77, 0.020362100000000001),
        (3.2999999999999998, -0.15878800000000001),
        (1.173, -0.31169400000000003),
        (0.17519999999999999, 0.620147),
        (0.064729999999999996, 0.52094300000000004)]),
      ("S", [(0.064729999999999996, 1.0)]),
      ("P",
       [(258.80000000000001, 0.0040684700000000002),
        (60.890000000000001, 0.0306815),
        (19.140000000000001, 0.12914900000000001),
        (6.8810000000000002, 0.32083099999999998),
        (2.5739999999999998, 0.45381500000000002),
        (0.95720000000000005, 0.27506599999999998),
        (0.2099, 0.019080699999999999),
        (0.059859999999999997, -0.0031284799999999999)]),
      ("P",
       [(258.80000000000001, -0.00074805300000000004),
        (60.890000000000001, -0.0054579600000000004),
        (19.140000000000001, -0.024537099999999999),
        (6.8810000000000002, -0.058213800000000003),
        (2.5739999999999998, -0.098375599999999994),
        (0.95720000000000005, -0.026006399999999999),
        (0.2099, 0.46401999999999999),
        (0.059859999999999997, 0.64886999999999995)]),
      ("P", [(0.059859999999999997, 1.0)]),
      ("D", [(0.189, 1.0)])],
    [("S",
       [(78860.0, 0.00027044299999999999),
        (11820.0, 0.0020971700000000002),
        (2692.0, 0.0108506),
        (763.39999999999998, 0.043675400000000003),
        (249.59999999999999, 0.137653),
        (90.280000000000001, 0.31664399999999998),
        (35.289999999999999, 0.41858099999999998),
        (14.51, 0.21021200000000001),
        (4.0529999999999999, 0.0144952),
        (1.482, -0.0020359000000000002),
        (0.25169999999999998, 0.00062418599999999999),
        (0.092429999999999998, -0.00028287199999999998)]),
      ("S",
       [(78860.0, -7.23177e-05),
        (11820.0, -0.00055511600000000003),
        (2692.0, -0.0029380500000000002),
        (763.39999999999998, -0.0117687),
        (249.59999999999999, -0.040290699999999999),
        (90.280000000000001, -0.100609),
        (35.289999999999999, -0.19652800000000001),
        (14.51, -0.102382),
        (4.0529999999999999, 0.52719000000000005),
        (1.482, 0.59325099999999997),
        (0.25169999999999998, 0.033265200000000002),
        (0.092429999999999998, -0.0097366199999999997)]),
      ("S",
       [(78860.0, 1.85113e-05),
        (11820.0, 0.00014223600000000001),
        (2692.0, 0.00075218500000000005),
        (763.39999999999998, 0.00302279),
        (249.59999999999999, 0.010367700000000001),
        (90.280000000000001, 0.0262563),
        (35.289999999999999, 0.052398899999999998),
        (14.51, 0.029095900000000001),
        (4.0529999999999999, -0.17800299999999999),
        (1.482, -0.34687400000000002),
        (0.25169999999999998, 0.62302000000000002),
        (0.092429999999999998, 0.53771199999999997)]),
      ("S", [(0.092429999999999998, 1.0)]),
      ("P",
       [(315.89999999999998, 0.0039265599999999999),
        (74.420000000000002, 0.029881100000000001),
        (23.48, 0.12721199999999999),
        (8.4879999999999995, 0.32094299999999998),
        (3.2170000000000001, 0.45542899999999997),
        (1.2290000000000001, 0.268563),
        (0.2964, 0.018833599999999999),
        (0.087679999999999994, -0.0026243099999999999)]),
      ("P",
       [(315.89999999999998, -0.00085830200000000002),
        (74.420000000000002, -0.0063032799999999996),
        (23.48, -0.0288255),
        (8.4879999999999995, -0.069456000000000004),
        (3.2170000000000001, -0.119493),
        (1.2290000000000001, -0.019958099999999999),
        (0.2964, 0.51026800000000005),
        (0.087679999999999994, 0.60038199999999997)]),
      ("P", [(0.087679999999999994, 1.0)]),
      ("D", [(0.27500000000000002, 1.0)])],
    [("S",
       [(94840.0, 0.00025550900000000001),
        (14220.0, 0.0019819299999999998),
        (3236.0, 0.010276),
        (917.10000000000002, 0.0414823),
        (299.5, 0.13198399999999999),
        (108.09999999999999, 0.30866199999999999),
        (42.18, 0.42064699999999999),
        (17.280000000000001, 0.22287799999999999),
        (4.8579999999999997, 0.016403500000000001),
        (1.8180000000000001, -0.0025425500000000002),
        (0.3372, 0.00074805),
        (0.1232, -0.00033096299999999998)]),
      ("S",
       [(94840.0, -6.9693899999999994e-05),
        (14220.0, -0.00053526599999999995),
        (3236.0, -0.00283709),
        (917.10000000000002, -0.0113983),
        (299.5, -0.039292899999999999),
        (108.09999999999999, -0.0996364),
        (42.18, -0.19798299999999999),
        (17.280000000000001, -0.11486),
        (4.8579999999999997, 0.51859500000000003),
        (1.8180000000000001, 0.60184700000000002),
        (0.3372, 0.036861199999999997),
        (0.1232, -0.0097075900000000003)]),
      ("S",
       [(94840.0, 1.91199e-05),
        (14220.0, 0.00014722300000000001),
        (3236.0, 0.00077791199999999996),
        (917.10000000000002, 0.0031454600000000001),
        (299.5, 0.01082),
        (108.09999999999999, 0.027995699999999998),
        (42.18, 0.056397799999999998),
        (17.280000000000001, 0.035818999999999997),
        (4.8579999999999997, -0.193387),
        (1.8180000000000001, -0.37209700000000001),
        (0.3372, 0.62424599999999997),
        (0.1232, 0.55172100000000002)]),
      ("S", [(0.1232, 1.0)]),
      ("P",
       [(370.5, 0.0039500500000000001),
        (87.329999999999998, 0.0302492),
        (27.59, 0.129554),
        (10.0, 0.327594),
        (3.8250000000000002, 0.45699200000000001),
        (1.494, 0.25308599999999998),
        (0.3921, 0.0168798),
        (0.1186, -0.0020709299999999999)]),
      ("P",
       [(370.5, -0.00095983199999999998),
        (87.329999999999998, -0.0071117699999999999),
        (27.59, -0.032712199999999997),
        (10.0, -0.079578399999999994),
        (3.8250000000000002, -0.135016),
        (1.494, -0.0091058500000000004),
        (0.3921, 0.537802),
        (0.1186, 0.56906599999999996)]),
      ("P", [(0.1186, 1.0)]),
      ("D", [(0.373, 1.0)])],
    [("S",
       [(110800.0, 0.00024763500000000001),
        (16610.0, 0.00192026),
        (3781.0, 0.0099619200000000008),
        (1071.0, 0.0402975),
        (349.80000000000001, 0.128604),
        (126.3, 0.30348000000000003),
        (49.259999999999998, 0.42143199999999997),
        (20.16, 0.23078099999999999),
        (5.7199999999999998, 0.017897099999999999),
        (2.1819999999999999, -0.0029751600000000001),
        (0.43269999999999997, 0.00084952200000000002),
        (0.157, -0.00036793600000000002)]),
      ("S",
       [(110800.0, -6.8703900000000005e-05),
        (16610.0, -0.00052768100000000001),
        (3781.0, -0.00279671),
        (1071.0, -0.0112651),
        (349.80000000000001, -0.038883399999999999),
        (126.3, -0.099502499999999994),
        (49.259999999999998, -0.19974),
        (20.16, -0.12336),
        (5.7199999999999998, 0.51319400000000004),
        (2.1819999999999999, 0.60711999999999999),
        (0.43269999999999997, 0.039675299999999997),
        (0.157, -0.0094686400000000004)]),
      ("S",
       [(110800.0, 1.9907699999999999e-05),
        (16610.0, 0.00015348299999999999),
        (3781.0, 0.00080950300000000005),
        (1071.0, 0.0032897400000000002),
        (349.80000000000001, 0.0112967),
        (126.3, 0.029638500000000002),
        (49.259999999999998, 0.0599851),
        (20.16, 0.041324800000000002),
        (5.7199999999999998, -0.20747399999999999),
        (2.1819999999999999, -0.39288899999999999),
        (0.43269999999999997, 0.63283999999999996),
        (0.157, 0.55692399999999997)]),
      ("S", [(0.157, 1.0)]),
      ("P",
       [(399.69999999999999, 0.00447541),
        (94.189999999999998, 0.034170800000000001),
        (29.75, 0.14424999999999999),
        (10.77, 0.35392800000000002),
        (4.1189999999999998, 0.45908500000000002),
        (1.625, 0.20638300000000001),
        (0.47260000000000002, 0.0102141),
        (0.14069999999999999, -6.0312200000000002e-05)]),
      ("P",
       [(399.69999999999999, -0.0011625100000000001),
        (94.189999999999998, -0.0086566400000000002),
        (29.75, -0.039088600000000001),
        (10.77, -0.093462500000000004),
        (4.1189999999999998, -0.14799399999999999),
        (1.625, 0.030190399999999999),
        (0.47260000000000002, 0.56157299999999999),
        (0.14069999999999999, 0.53477600000000003)]),
      ("P", [(0.14069999999999999, 1.0)]),
      ("D", [(0.47899999999999998, 1.0)])],
    [("S",
       [(127900.0, 0.000241153),
        (19170.0, 0.0018709499999999999),
        (4363.0, 0.0097082699999999997),
        (1236.0, 0.039315299999999997),
        (403.60000000000002, 0.12593199999999999),
        (145.69999999999999, 0.29934100000000002),
        (56.810000000000002, 0.42188599999999998),
        (23.23, 0.237201),
        (6.6440000000000001, 0.019153099999999999),
        (2.5750000000000002, -0.0033479199999999999),
        (0.53710000000000002, 0.00092988299999999995),
        (0.1938, -0.00039637899999999998)]),
      ("S",
       [(127900.0, -6.7892199999999993e-05),
        (19170.0, -0.00052183600000000002),
        (4363.0, -0.0027651300000000002),
        (1236.0, -0.011153700000000001),
        (403.60000000000002, -0.038591899999999998),
        (145.69999999999999, -0.099484799999999998),
        (56.810000000000002, -0.20139199999999999),
        (23.23, -0.13031300000000001),
        (6.6440000000000001, 0.50944299999999998),
        (2.5750000000000002, 0.61072499999999996),
        (0.53710000000000002, 0.042154900000000002),
        (0.1938, -0.0092342699999999993)]),
      ("S",
       [(127900.0, 2.0498600000000001e-05),
        (19170.0, 0.00015829799999999999),
        (4363.0, 0.00083363899999999995),
        (1236.0, 0.0033988),
        (403.60000000000002, 0.0116738),
        (145.69999999999999, 0.030962199999999999),
        (56.810000000000002, 0.062953300000000004),
        (23.23, 0.046025700000000003),
        (6.6440000000000001, -0.21931200000000001),
        (2.5750000000000002, -0.408773),
        (0.53710000000000002, 0.63846499999999995),
        (0.1938, 0.56236200000000003)]),
      ("S", [(0.1938, 1.0)]),
      ("P",
       [(417.60000000000002, 0.0052598200000000001),
        (98.329999999999998, 0.039833199999999999),
        (31.039999999999999, 0.164655),
        (11.19, 0.387322),
        (4.2489999999999997, 0.45707199999999998),
        (1.6240000000000001, 0.15163599999999999),
        (0.53220000000000001, 0.0018161500000000001),
        (0.16200000000000001, 0.0018829599999999999)]),
      ("P",
       [(417.60000000000002, -0.0014357),
        (98.329999999999998, -0.0107796),
        (31.039999999999999, -0.047007500000000001),
        (11.19, -0.11103),
        (4.2489999999999997, -0.15327499999999999),
        (1.6240000000000001, 0.089460899999999996),
        (0.53220000000000001, 0.57944399999999996),
        (0.16200000000000001, 0.48327199999999998)]),
      ("P", [(0.16200000000000001, 1.0)]),
      ("D", [(0.59999999999999998, 1.0)])],
    [("S",
       [(145700.0, 0.00023670000000000001),
        (21840.0, 0.00183523),
        (4972.0, 0.0095285999999999999),
        (1408.0, 0.038628299999999997),
        (459.69999999999999, 0.124081),
        (165.90000000000001, 0.29647099999999998),
        (64.689999999999998, 0.422068),
        (26.440000000000001, 0.24171100000000001),
        (7.6280000000000001, 0.0200509),
        (2.996, -0.0036099999999999999),
        (0.65039999999999998, 0.00097560699999999997),
        (0.23369999999999999, -0.000411316)]),
      ("S",
       [(145700.0, -6.7490999999999995e-05),
        (21840.0, -0.00051852199999999999),
        (4972.0, -0.0027482499999999998),
        (1408.0, -0.0111007),
        (459.69999999999999, -0.038482000000000002),
        (165.90000000000001, -0.099759899999999999),
        (64.689999999999998, -0.20308799999999999),
        (26.440000000000001, -0.13560800000000001),
        (7.6280000000000001, 0.50719499999999995),
        (2.996, 0.61289800000000005),
        (0.65039999999999998, 0.044296799999999997),
        (0.23369999999999999, -0.0089927800000000006)]),
      ("S",
       [(145700.0, 2.1045700000000001e-05),
        (21840.0, 0.00016256500000000001),
        (4972.0, 0.00085546299999999999),
        (1408.0, 0.00349745),
        (459.69999999999999, 0.0120156),
        (165.90000000000001, 0.0321368),
        (64.689999999999998, 0.0655279),
        (26.440000000000001, 0.049937000000000002),
        (7.6280000000000001, -0.229769),
        (2.996, -0.42100599999999999),
        (0.65039999999999998, 0.64233099999999999),
        (0.23369999999999999, 0.56754000000000004)]),
      ("S", [(0.23369999999999999, 1.0)]),
      ("P",
       [(453.69999999999999, 0.0057055500000000002),
        (106.8, 0.043046000000000001),
        (33.729999999999997, 0.176591),
        (12.130000000000001, 0.40686299999999997),
        (4.5940000000000003, 0.45254899999999998),
        (1.6779999999999999, 0.12280099999999999),
        (0.59089999999999998, -0.0044599599999999998),
        (0.1852, 0.0020522499999999998)]),
      ("P",
       [(453.69999999999999, -0.00160655),
        (106.8, -0.012171400000000001),
        (33.729999999999997, -0.052078899999999997),
        (12.130000000000001, -0.123737),
        (4.5940000000000003, -0.151619),
        (1.6779999999999999, 0.142425),
        (0.59089999999999998, 0.58450100000000005),
        (0.1852, 0.43753999999999998)]),
      ("P", [(0.1852, 1.0)]),
      ("D", [(0.73799999999999999, 1.0)])]
]

basis_data = Dict("sto3g" => sto3g,
      "6-31G**" => g631ss, "6-31G" => g631,
      "cc-pvdz" => ccpvdz)

# Sample molecules for tests
h2 = [atom(1,  0.00000000,     0.00000000,     0.36628549),
      atom(1,  0.00000000,     0.00000000,    -0.36628549)]

h2o = [atom(8,   0.00000000,     0.00000000,     0.04851804),
      atom(1,   0.75300223,     0.00000000,    -0.51923377),
      atom(1,  -0.75300223,     0.00000000,    -0.51923377)]

ch4 = [atom(6,   0.00000000,     0.00000000,     0.00000000),
      atom(1,   0.62558332,    -0.62558332,     0.62558332),
      atom(1,  -0.62558332,     0.62558332,     0.62558332),
      atom(1,   0.62558332,     0.62558332,    -0.62558332),
      atom(1,  -0.62558332,    -0.62558332,    -0.62558332)]

c6h6 = [ atom(6,  0.98735329,     0.98735329,     0.00000000),
        atom(6,  1.34874967,    -0.36139639,     0.00000000),
        atom(6,  0.36139639,    -1.34874967,     0.00000000),
        atom(6, -0.98735329,    -0.98735329,     0.00000000),
        atom(6, -1.34874967,     0.36139639,     0.00000000),
        atom(6, -0.36139639,     1.34874967,     0.00000000),
        atom(1,  1.75551741,     1.75551741,     0.00000000),
        atom(1,  2.39808138,    -0.64256397,     0.00000000),
        atom(1,  0.64256397,    -2.39808138,     0.00000000),
        atom(1, -1.75551741,    -1.75551741,     0.00000000),
        atom(1, -2.39808138,     0.64256397,     0.00000000),
        atom(1, -0.64256397,     2.39808138,     0.00000000)]

lih = [atom(3,    0.00000000,     0.00000000,    -0.53999756),
              atom(1,    0.00000000,     0.00000000,     1.08999756)]

ethane = [atom(6,   -0.759130,   0.027045,  -0.000000),
          atom(6,    0.759130,  -0.027045,  -0.000000),
          atom(1,   -1.125990,   0.306235,   1.010150),
          atom(1,   -1.171340,  -0.966695,  -0.274750),
          atom(1,   -1.109050,   0.781825,  -0.735390),
          atom(1,    1.109040,  -0.781815,   0.735390),
          atom(1,    1.171340,   0.966695,   0.274760),
          atom(1,    1.125990,  -0.306235,  -1.010150)]


text:
platforms_and_sources = Dict(
    Platform("x86_64", "linux") => [
        ArchiveSource("https://developer.nvidia.com/compute/cudnn/secure/8.3.1/local_installers/11.5/cudnn-linux-x86_64-8.3.1.22_cuda11.5-archive.tar.xz",
                      "f5ff3c69b6a8a9454289b42eca1dd41c3527f70fcf49428eb80502bcf6b02f6e")],
    Platform("powerpc64le", "linux") => [
        ArchiveSource("https://developer.nvidia.com/compute/cudnn/secure/8.3.1/local_installers/11.5/cudnn-linux-ppc64le-8.3.1.22_cuda11.5-archive.tar.xz",
                      "1d2419a20ee193dc6a3a0ba87e79f408286d3d317c9831cbc1f0b7a268c100b0")],
    Platform("aarch64", "linux") => [
        ArchiveSource("https://developer.nvidia.com/compute/cudnn/secure/8.3.1/local_installers/11.5/cudnn-linux-sbsa-8.3.1.22_cuda11.5-archive.tar.xz",
                      "ff23a881366c0ee79b973a8921c6dd400628a321557550ad4e0a26a21caad263")],
    Platform("x86_64", "windows") => [
        ArchiveSource("https://developer.nvidia.com/compute/cudnn/secure/8.3.1/local_installers/11.5/cudnn-windows-x86_64-8.3.1.22_cuda11.5-archive.zip",
                      "f0d5cb8d899e5405c00c3ea3925d9143a832ea6239bc70309bb2ded2bfb8d824")],
)

max_stars_repo_name: AbhimanyuAryan/Yggdrasil

max_issues_repo_name: AbhimanyuAryan/Yggdrasil

max_forks_repo_name: AbhimanyuAryan/Yggdrasil


text:
#!/bin/julia

using DataFrames
using CSV
using JSON
using Dates
using Distributions
using StatsBase
using Random

#####

include("moveSim_config")
const EPOCH = Date(1970,1,1)
const EPOCH_START = Dates.value((START_DATE - EPOCH) * 2)
const DAYS = Dates.value(END_DATE - START_DATE)

######

### Load data
println("Loading data...")

#commuter network
cnet = DataFrame(CSV.File(CNET_FILE))

#population estimates
pop = DataFrame(CSV.File(POP_FILE))

#generated population
population = DataFrame(CSV.File(OUT_DIR*"population_data.csv"))

if DAMPEN
    mobility = DataFrame(CSV.File(MOBILITY_FILE))
end

function edate(t)
    return EPOCH+Day(div(t,2))
end

######

### Get fast lookup tables for simualtion
print("Generating looukp tables... ")
tic = now()
locs = pop.RefArea

function generate_destination_lookup(population,locs)
    movers = population[.!ismissing.(population.Destination),:]
    lookup = Dict(loc => Array{Int,1}() for loc in locs)
    for r in 1:nrow(movers)
        push!(lookup[movers[r,:Destination]], movers[r,:PersonID])
    end
    return lookup
end
destination_lookup = generate_destination_lookup(population,locs)

function generate_origin_lookup(population)
    return Dict(population[r,:PersonID]=>population[r,:Origin] for r in 1:nrow(population))
end
origin_lookup = generate_origin_lookup(population)

non_movers = population[ismissing.(population.Destination),:PersonID]

if DAMPEN
    mobility_lookup = Dict(mobility[r,1]=>mobility[r,2] for r in 1:nrow(mobility))
else
    mobility_lookup = nothing
end
println(Dates.value(now()-tic)/1000,"s")

#####

### For each day of the simulation
#start day = 0, t_Stamp = EPOCH_START, 2 time intervals per day, handles 1 day per call
function simDay(day, t_stamp, destination_lookup, origin_lookup, non_movers, locs, mobility_lookup)
    println("Generating day ",day)
    ##Initialise data structures
    step_morn = Dict("step"=>t_stamp,"locs"=>[])
    step_eve = Dict("step"=>t_stamp+1,"locs"=>[])
    eve_movers = Dict(loc => Array{Int,1}() for loc in locs)

    ##shuffle non_movers
    non_movers_pool = shuffle(non_movers)

    ##Generate movers for each location
    for dest in locs
        #tic = now()
        #sample all morning movers
        morn_movers = destination_lookup[dest]
        l = length(morn_movers) #lambda number of movers
        if STOCH
            ss = rand(Poisson(l)) #sample size
        else
            ss = l
        end
        if DAMPEN
            d = mobility_lookup[edate(t_stamp)] #dampening factor for date
            ss = round(Int, ss * (1 + (d/100))) #dampen sample size
        end
        if TRIM
            ss = rand(Binomial(ss,1/5)) #Trim 4 in 5 moves (on average)
        end
        if ss < l #less than usual
            sampled_movers = sample(morn_movers,ss,replace=false)
        elseif ss == l #usual
            sampled_movers = morn_movers
        else #extra movers required
            ess = ss - l
            sampled_movers = vcat(morn_movers, [pop!(non_movers_pool) for _ in 1:ess])
        end
        #add to output structure
        push!(step_morn["locs"], Dict("loc"=>dest, "ani"=>sampled_movers))
        #collect return movers
        for p in sampled_movers
            push!(eve_movers[origin_lookup[p]], p)
        end
        #println(dest," in ",Dates.value(now()-tic),"ms")
    end

    ##Add return movers to output structure
    for loc in locs
        push!(step_eve["locs"], Dict("loc"=>loc, "ani"=>eve_movers[loc]))
    end

    ##Write to JSON files
    file_morn = open(string(OUT_DIR,"/moveSim_step_",t_stamp,".json"),"w")
    write(file_morn,json(step_morn))
    close(file_morn)
    file_eve = open(string(OUT_DIR,"/moveSim_step_",t_stamp+1,".json"),"w")
    write(file_eve,json(step_eve))
    close(file_eve)
end

### Run sim days (single-core)
for day in 0:DAYS-1
    @time simDay(day, (EPOCH_START+(day*2)), destination_lookup, origin_lookup, non_movers, locs, mobility_lookup)
end

####>>>>TODO<<<<< Parrallelise

max_stars_repo_name: Kao-Group/SCoVMod

max_issues_repo_name: Kao-Group/SCoVMod

max_forks_repo_name: Kao-Group/SCoVMod


text:
function build_nabla2_y(LF)

  D2jl = LF.LFy.D2jl

  Nx = LF.Nx
  Ny = LF.Ny
  Nz = LF.Nz

  Npoints = Nx*Ny*Nz

  # initialize with
  rowval = zeros(Int64,Ny*Npoints)
  colptr = zeros(Int64,Npoints+1)
  colptr[1] = 1
  nzval = zeros(Float64,Ny*Npoints)

  # XXX Move these arrays here ?
  rowGbl_init = zeros(Int64,Ny)
  rowGbl = zeros(Int64,Ny)

  idx = 0
  idxCol = 1

  for ix = 1:Nx

    rowGbl_init[1] = 1 + (ix-1)*Ny*Nz
    for i = 2:Ny
      rowGbl_init[i] = rowGbl_init[i-1] + Nz
    end

    for colLoc = 1:Ny
      colGbl_start = (colLoc-1)*Nz + 1 + (ix-1)*Ny*Nz
      colGbl_stop = colLoc*Nz + (ix-1)*Ny*Nz
      for colGbl = colGbl_start:colGbl_stop
        for rowLoc = 1:Ny
          idx = idx + 1
          rowval[idx] = rowGbl_init[rowLoc] + colGbl - 1 - (colLoc-1)*Nz - (ix-1)*Ny*Nz
          nzval[idx] = D2jl[colLoc,rowLoc]
        end
        idxCol = idxCol + 1
        colptr[idxCol] = colptr[idxCol-1] + Ny
      end
    end

  end # ix = 1:Nx

  return SparseMatrixCSC( Npoints, Npoints, colptr, rowval, nzval )
end


text:
"""
This file defines functions for interacting with the environment, such as `withenv()` and
`which()`. They all automatically resolve first.
"""

"""
    activate!(env)

"Activate" the Conda environment by modifying the given dict of environment variables.
"""
function activate!(e)
    old_path = get(e, "PATH", "")
    d = envdir()
    path_sep = Sys.iswindows() ? ';' : ':'
    new_path = join(bindirs(), path_sep)
    if backend() == :MicroMamba
        e["MAMBA_ROOT_PREFIX"] = MicroMamba.root_dir()
        new_path = "$(new_path)$(path_sep)$(dirname(MicroMamba.executable()))"
    end
    if old_path != ""
        new_path = "$(new_path)$(path_sep)$(old_path)"
    end
    e["PATH"] = new_path
    e["CONDA_PREFIX"] = d
    e["CONDA_DEFAULT_ENV"] = d
    e["CONDA_SHLVL"] = "1"
    e["CONDA_PROMPT_MODIFIER"] = "($d) "
    e
end

"""
    withenv(f::Function)

Call `f()` while the Conda environment is active.
"""
function withenv(f::Function)
    old_env = copy(ENV)
    # shell("activate")
    activate!(ENV)
    frozen = STATE.frozen
    STATE.frozen = true
    try
        return f()
    finally
        STATE.frozen = frozen
        # copy!(ENV, old_env) does not work (empty!(ENV) not implemented)
        for k in collect(keys(ENV))
            if !haskey(old_env, k)
                delete!(ENV, k)
            end
        end
        for (k, v) in old_env
            ENV[k] = v
        end
    end
end

"""
    envdir(...)

The root directory of the Conda environment.

Any additional arguments are joined to the path.
"""
function envdir(args...)
    resolve()
    joinpath(STATE.meta_dir, "env", args...)
end

"""
    bindirs()

The directories containing binaries in the Conda environment.
"""
function bindirs()
    e = envdir()
    if Sys.iswindows()
        ("$e", "$e\\Library\\mingw-w64\\bin", "$e\\Library\\usr\\bin", "$e\\Library\\bin", "$e\\Scripts", "$e\\bin")
    else
        ("$e/bin", "$e/condabin")
    end
end

"""
    which(progname)

Find the binary called `progname` in the Conda environment.
"""
function which(progname)
    # Set the PATH to dirs in the environment, then use Sys.which().
    old_path = get(ENV, "PATH", nothing)
    ENV["PATH"] = join(bindirs(), Sys.iswindows() ? ';' : ':')
    try
        Sys.which(progname)
    finally
        if old_path === nothing
            delete!(ENV, "PATH")
        else
            ENV["PATH"] = old_path
        end
    end
end

"""
    gc()

Remove unused packages and caches.
"""
function gc(; io::IO=stderr)
    resolve()
    cmd = conda_cmd(`clean -y --all`, io=io)
    _run(io, cmd, "Removing unused caches")
    nothing
end


text:
function flashserver()
    println("running diskutil list")
    run(`diskutil list`)
    println("Which disk would you like to format?")
    disknum = readline()
    yesno = "y"
    if Meta.parse(disknum) < 2
        println("WARNING: this might be a system disk, proceed? y/n")
        yesno = readline()
    elseif yesno == "y" && disknum == "2"
        println("unzipping tar")
        run(`tar -xzf $(ENV["HOME"])/ft2k/Software/Server/2017-07-05-raspbian-jessie.zip`)
        println("unmounting and flashing disk")
        run(`diskutil unmountDisk /dev/disk$disknum`)
        run(`dd bs=1m if=$(ENV["HOME"])/ft2k/Software/Server/setup_scripts/2017-07-05-raspbian-jessie.img of=/dev/disk$disknum conv=sync`)
        # enable uart
        sleep(1)
        f = open("/Volumes/boot/config.txt", "a")
        write(f, "enable_uart=1")
        close(f)
        run(`rm -rf $(ENV["HOME"])/ft2k/Software/Server/setup_scripts/2017-07-05-raspbian-jessie.img`)
        println("finished")
    end
end

function pulldb()
    domain = conf["Watchman"]["domain"]
	while true
		run(`/usr/bin/rsync -avze "ssh -i /home/pi/.ssh/watchman.pem" ubuntu@$domain:/home/ubuntu/ft2k/Software/Server/db.sqlite /home/pi/ft2k/Software/Server/`)
		sleep(3)
	end
end


text:
module Transforms
	using Base.Threads
	using Interpolations
	using StaticArrays
	using LinearAlgebra
	using QuadGK
	using ProgressMeter

	export line_segment, interpolate_array, line_segment_2D, LineFilterTransform, OrientationFilterTransform

	function interpolate_array(array::AbstractArray, interp_scheme::BSpline)
		interpolant = interpolate(array, interp_scheme)
		interpolant_padded = extrapolate(interpolant, 0)

		return interpolant_padded
	end

	function line_segment(i::Integer, j::Integer, θ::T, S::SVector{N, T}) where {N, T<:Real}

		x = SVector{N, T}(i+s*cos(θ) for s in S)
		y = SVector{N, T}(j+s*sin(θ) for s in S)

		return x, y
	end

	function line_segment(i::Integer, j::Integer, k::Integer, θ::T, ϕ::T, S::SVector{N, T}) where {N, T<:Real}

		x = SVector{N, T}(i+s*sin(θ)*cos(ϕ) for s in S)
		y = SVector{N, T}(j+s*sin(θ)*sin(ϕ) for s in S)
		z = SVector{N, T}(k+s*cos(θ) for s in S)

		return x, y, z
	end

	function LFT_point(i, j, Θ, array_interpolant, quad_points, quad_weights)

		function LFT_integrand(θ)
			line_seg = line_segment(i, j, θ, quad_points)
			array_vals = SVector([array_interpolant(c...) for c in zip(line_seg...)])
			return array_vals ⋅ quad_weights
		end

		LFT_θ = map(LFT_integrand, Θ)
		max_val, ind = findmax(LFT_θ)

		return max_val, Θ[ind]
	end

	function LFT_point_faster(i, j, Θ, array_interpolant, quad_points, quad_weights)

		function LFT_integrand(θ)
			sθ, cθ = sincos(θ)
			sum = zero(θ)
			for (s, w) in zip(quad_points, quad_weights)
				f = array_interpolant(i+s*cθ, j+s*sθ)
				sum = muladd(f, w, sum)
			end
			return sum
		end

		LFT_θ = map(LFT_integrand, Θ)
		max_val, ind = findmax(LFT_θ)

		return max_val, Θ[ind]
	end

	function LFT_point(i, j, k, angles, array_interpolant, quad_points, quad_weights)

		function LFT_integrand(angle)
			line_seg = line_segment(i, j, k, angle..., quad_points)
			array_vals = SVector([array_interpolant(c...) for c in zip(line_seg...)])
			return array_vals ⋅ quad_weights
		end

		LFT_angles = map(LFT_integrand, angles)
		max_val, ind = findmax(LFT_angles)

		return max_val, angles[ind][1], angles[ind][2]
	end

	function LFT_point_faster(i, j, k, angles, array_interpolant, quad_points, quad_weights)

		function LFT_integrand(angle)
			sθ, cθ = sincos(angle[1])
			sϕ, cϕ = sincos(angle[2])
			sθcϕ, sθsϕ = sθ*cϕ, sθ*sϕ
			sum = zero(angle[1])

			for (s, w) in zip(quad_points, quad_weights)
				f = array_interpolant(i+s*sθcϕ, j+s*sθsϕ, k+s*cθ)
				sum = muladd(f, w, sum)
			end
			return sum
		end

		LFT_angles = map(LFT_integrand, angles)
		max_val, ind = findmax(LFT_angles)

		return max_val, angles[ind][1], angles[ind][2]
	end

	function LFT_point(i, j, k, angles, array_interpolant, quad_points, quad_weights)

		function LFT_integrand(angle)
			line_seg = line_segment(i, j, k, angle..., quad_points)
			array_vals = SVector([array_interpolant(c...) for c in zip(line_seg...)])
			return array_vals ⋅ quad_weights
		end

		LFT_angles = map(LFT_integrand, angles)
		max_val, ind = findmax(LFT_angles)

		return max_val, angles[ind][1], angles[ind][2]
	end

	function LineFilterTransform(array::AbstractArray{T, 2}, N::Integer, r::Integer, Nr::Integer; interp_scheme::BSpline = BSpline(Constant())) where {T<:Real}
		array_interpolant = interpolate_array(array, interp_scheme)
		intensity, orientation = zero(array), zero(array)

		angles = SVector{N, T}(LinRange(-π/2, π/2, N))
		quad_points, quad_weights = gauss(Nr, -r, r)
		quad_points = SVector{Nr, T}(quad_points)
		quad_weights = SVector{Nr, T}(quad_weights)

		p = Progress(length(array))
		@threads for ind in CartesianIndices(array)
			intensity[ind], orientation[ind] = @fastmath LFT_point_faster(ind.I..., angles, array_interpolant, quad_points, quad_weights)
			next!(p)
		end

		return intensity, orientation
	end

	function LineFilterTransform(array::AbstractArray{T, 3}, N::Integer, r::Integer, Nr::Integer; interp_scheme::BSpline = BSpline(Constant())) where {T<:Real}
		array_interpolant = interpolate_array(array, interp_scheme)
		intensity, orientation = zero(array), zeros(T, size(array)..., 2)

		angles = SVector{2N^2, Tuple{T, T}}(collect(Iterators.product(LinRange(-π/2, π/2, N), LinRange(-π, π, 2N))))
		quad_points, quad_weights = gauss(Nr, -r, r)
		quad_points = SVector{Nr, T}(quad_points)
		quad_weights = SVector{Nr, T}(quad_weights)

		p = Progress(length(array))
		@threads for ind in CartesianIndices(array)
			intensity[ind], orientation[ind,1], orientation[ind,2] = @fastmath LFT_point_faster(ind.I..., angles, array_interpolant, quad_points, quad_weights)
			next!(p)
		end

		return intensity, orientation
	end

	function OFT_point(i, j, Α, intensity_field, orientation_field, quad_points, quad_weights)

		function OFT_integrand(α)
			line_seg = line_segment(i, j, α, quad_points)
			ρ_line = SVector([intensity_field(c...) for c in zip(line_seg...)])
			θ_line = SVector([orientation_field(c...) for c in zip(line_seg...)])

			orientation_functional = ρ_line.*cos.(2(θ_line .- α))
			return orientation_functional ⋅ quad_weights
		end

		OFT_α = map(OFT_integrand, Α)
		ind = argmax(abs.(OFT_α))

		return OFT_α[ind]
	end

	function OFT_point_faster(i, j, Α, intensity_field, orientation_field, quad_points, quad_weights)

		function OFT_integrand(α)
			sα, cα = sincos(α)

			sum = zero(α)
			@inbounds for (s, w) in zip(quad_points, quad_weights)
				x, y = i+s*cα, j+s*sα
				ρ, θ = intensity_field(x, y), orientation_field(x, y)
				f = ρ*cos(2(θ-α))

				sum = muladd(f, w, sum)
			end

			return sum
		end

		OFT_α = map(OFT_integrand, Α)
		ind = argmax(abs.(OFT_α))

		return OFT_α[ind]
	end

	function OFT_point(i, j, k, angles, intensity_field, θ_field, ϕ_field, quad_points, quad_weights)

		function OFT_integrand(angle)
			line_seg = line_segment(i, j, k, angle..., quad_points)
			ρ_line = SVector([intensity_field(c...) for c in zip(line_seg...)])
			θ_line = SVector([θ_field(c...) for c in zip(line_seg...)])
			ϕ_line = SVector([ϕ_field(c...) for c in zip(line_seg...)])

			α₁, α₂ = angle
			inner = sin.(θ_line)*sin(α₁).*cos.(ϕ_line.-α₂).+cos.(θ_line)*cos(α₁)
			orientation_functional = ρ_line.*(2inner.^2 .- 1)
			return orientation_functional ⋅ quad_weights
		end

		OFT_angles = map(OFT_integrand, angles)
		ind = argmax(abs.(OFT_angles))

		return OFT_angles[ind]
	end

	function OFT_point_faster(i, j, k, angles, intensity_field, θ_field, ϕ_field, quad_points, quad_weights)

		function OFT_integrand(angle)
			sα₁, cα₁ = sincos(angle[1])
			sα₂, cα₂ = sincos(angle[2])
			sα₁cα₂, sα₁sα₂ = sα₁*cα₂, sα₁*sα₂
			sum = zero(angle[1])
			for (s, w) in zip(quad_points, quad_weights)
				x, y, z = i+s*sα₁cα₂, j+s*sα₁sα₂, k+s*cα₁
				ρ, θ, ϕ = intensity_field(x, y, z), θ_field(x, y, z), ϕ_field(x, y, z)
				sθ, cθ = sincos(θ)
				aligned = sθ*sα₁*cos(ϕ-angle[2]) + cθ*cα₁
				f = ρ*(2aligned^2-1)

				sum = muladd(f, w, sum)
			end

			return sum
		end

		OFT_angles = map(OFT_integrand, angles)
		ind = argmax(abs.(OFT_angles))

		return OFT_angles[ind]
	end

	function OrientationFilterTransform(LFT_intensity::AbstractArray{T, 2}, LFT_orientation::AbstractArray{T, 2}, N::Integer, r::Integer, Nr::Integer, interp_scheme::BSpline = BSpline(Constant())) where {T<:Real}
		ρ = interpolate_array(LFT_intensity, interp_scheme)
		θ = interpolate_array(LFT_orientation, interp_scheme)
		OFT = zero(LFT_intensity)

		angles = SVector{N, T}(LinRange(-π/2, π/2, N))
		quad_points, quad_weights = gauss(Nr, -r, r)
		quad_points = SVector{Nr, T}(quad_points)
		quad_weights = SVector{Nr, T}(quad_weights)

		p = Progress(length(LFT_intensity))
		@threads for ind in CartesianIndices(LFT_intensity)
			OFT[ind] = @fastmath OFT_point_faster(ind.I..., angles, ρ, θ, quad_points, quad_weights)
			next!(p)
		end

		return OFT
	end

	function OrientationFilterTransform(LFT_intensity::AbstractArray{T, 3}, LFT_orientation::AbstractArray{T, 4}, N::Integer, r::Integer, Nr::Integer, interp_scheme::BSpline = BSpline(Constant())) where {T<:Real}
		ρ = interpolate_array(LFT_intensity, interp_scheme)
		θ = interpolate_array(LFT_orientation[:,:,:, 1], interp_scheme)
		ϕ = interpolate_array(LFT_orientation[:,:,:, 2], interp_scheme)
		OFT = zero(LFT_intensity)

		angles = SVector{2N^2, Tuple{T, T}}(collect(Iterators.product(LinRange(-π/2, π/2, N), LinRange(-π, π, 2N))))
		quad_points, quad_weights = gauss(Nr, -r, r)
		quad_points = SVector{Nr, T}(quad_points)
		quad_weights = SVector{Nr, T}(quad_weights)

		p = Progress(length(LFT_intensity))
		@threads for ind in CartesianIndices(LFT_intensity)
			OFT[ind] = @fastmath OFT_point_faster(ind.I..., angles, ρ, θ, ϕ, quad_points, quad_weights)
			next!(p)
		end

		return OFT
	end
end


text:
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# Description
# ==============================================================================
#
#   Types and structures for the LaTeX backend.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

export LatexTableFormat, LatexHighlighter

"""
    LatexTableFormat

This structure defines the format of the LaTeX table.

# Fields

- `top_line::String`: Top line of the table.
- `header_line::String`: Line that separate the header from the table body.
- `mid_line::String`: Line printed in the middle of the table.
- `bottom_line::String`: Bottom line of the table.
- `left_vline::String`: Left vertical line of the table.
- `mid_vline::String`: Vertical line in the middle of the table.
- `right_vline::String`: Right vertical line of the table.
- `header_envs::Vector{String}`: LaTeX environments that will be used in each
    header cell.
- `subheader_envs::Vector{String}`: LaTeX environments that will be used in each
    sub-header cell.
- `hlines::Vector{Symbol}`: Horizontal lines that must be drawn by default.
- `vlines::Union{Symbol, Vector{Symbol}}`: Vertical lines that must be drawn by
    default.
- `table_type::Symbol`: Select the type of table that should be used for this
    format.
- `wrap_table::Bool`: Select if the table must be wrapped inside the environment
    defined by `wrap_table_environment`.
- `wrap_table_environment::String`: Environment in which the table will be
    wrapped if `wrap_table` is true.
"""
@kwdef struct LatexTableFormat
    top_line::String                      = "\\hline\\hline"
    header_line::String                   = "\\hline"
    mid_line::String                      = "\\hline"
    bottom_line::String                   = "\\hline\\hline"
    left_vline::String                    = "|"
    mid_vline::String                     = "|"
    right_vline::String                   = "|"
    header_envs::Vector{String}           = ["textbf"]
    subheader_envs::Vector{String}        = ["texttt"]
    hlines::Vector{Symbol}                = [:begin, :header, :end]
    vlines::Union{Symbol, Vector{Symbol}} = :none
    table_type::Symbol                    = :tabular
    wrap_table::Bool                      = true
    wrap_table_environment::String        = "table"
end

"""
    LatexHighlighter

Defines the default highlighter of a table when using the LaTeX backend.

# Fields

- `f::Function`: Function with the signature `f(data, i, j)` in which should
    return `true` if the element `(i, j)` in `data` must be highlighted, or
    `false` otherwise.
- `fd`: A function with the signature `f(data, i, j, str)::String` in which
    `data` is the matrix, `(i, j)` is the element position in the table, and
    `str` is the data converted to string. This function must return a string
    that will be placed in the cell.

# Remarks

This structure can be constructed using two helpers:

    LatexHighlighter(f::Function, envs::Union{String, Vector{String}})

    LatexHighlighter(f::Function, fd::Function)

The first will apply recursively all the LaTeX environments in `envs` to the
highlighted text whereas the second let the user select the desired decoration
by specifying the function `fd`.

Thus, for example:

    LatexHighlighter((data, i, j)->true, ["textbf", "small"])

will wrap all the cells in the table in the following environment:

    \\textbf{\\small{<Cell text>}}
"""
@kwdef struct LatexHighlighter
    f::Function
    fd::Function
end

LatexHighlighter(f::Function, env::String) = LatexHighlighter(f, [env])

function LatexHighlighter(f::Function, envs::Vector{String})
    return LatexHighlighter(f, (data, i, j, str)->_latex_envs(str, envs))
end