1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use reqwest::header::{HeaderMap, HeaderValue, USER_AGENT};
use serde::Deserialize;
use std::{collections::HashMap, f64::MAX};

#[derive(Deserialize, Debug)]
struct Basis {
    elements: HashMap<String, ElementInfo>,
}

#[derive(Deserialize, Debug)]
struct ElementInfo {
    electron_shells: Vec<Shell>,
}

#[derive(Deserialize, Debug)]
struct Shell {
    angular_momentum: Vec<usize>,
    exponents: Vec<String>,
}

pub fn ang_min_and_max(basis_set: &str, element: usize) -> (HashMap<usize, f64>, f64) {
    let mut headers = HeaderMap::new();
    headers.insert(USER_AGENT, HeaderValue::from_static("reqwest"));

    let url = format!(
        "http://basissetexchange.org/api/basis/{}/format/json?elements={}",
        basis_set, element,
    );

    let resp = reqwest::blocking::Client::new()
        .get(&url)
        .headers(headers)
        .send()
        .unwrap()
        .json::<Basis>()
        .unwrap();

    let element = resp.elements.get(&element.to_string()).unwrap();

    let mut alpha_max = -std::f64::MAX;
    let mut alpha_min = HashMap::new();

    for shell in &element.electron_shells {
        let angular_momentum = shell.angular_momentum[0];
        for exponent_string in &shell.exponents {
            let exponent: f64 = exponent_string.parse().unwrap();
            alpha_max = alpha_max.max(exponent);
            let s = alpha_min.entry(angular_momentum).or_insert(std::f64::MAX);
            if &exponent < s {
                *s = exponent;
            }
        }
    }

    (alpha_min, alpha_max)
}

// alpha max is the maximum of exponent, min is the minimum expo