Skip to content

Commit 319a80e

Browse files
committed
Krack-Koster radial grid
1 parent 63cf3eb commit 319a80e

5 files changed

Lines changed: 78 additions & 0 deletions

File tree

README.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,19 @@ As an example let us generate a grid for the water molecule:
243243
coordinates, weights = numgrid.angular_grid(14)
244244
245245
246+
Unreleased functionality
247+
------------------------
248+
249+
These will be released soon but I need to think carefully about the API.
250+
251+
.. code:: python
252+
253+
import numgrid
254+
255+
# radial grid with 100 points using Krack-Koster approach
256+
radii, weights = numgrid.radial_grid_kk(100)
257+
258+
246259
Notes and recommendations
247260
-------------------------
248261

example.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,8 @@
5757
proton_charges[center_index],
5858
)
5959

60+
# radial grid with 100 points using Krack-Koster approach
61+
radii, weights = numgrid.radial_grid_kk(100)
62+
6063
# angular grid with 14 points
6164
coordinates, weights = numgrid.angular_grid(14)

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ pub use crate::atom::atom_grid;
1515
pub use crate::atom::atom_grid_bse;
1616
pub use crate::lebedev::angular_grid;
1717
pub use crate::radial::radial_grid;
18+
pub use crate::radial::radial_grid_kk;

src/python.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::atom::__pyo3_get_function_atom_grid;
55
use crate::atom::__pyo3_get_function_atom_grid_bse;
66
use crate::lebedev::__pyo3_get_function_angular_grid;
77
use crate::radial::__pyo3_get_function_radial_grid;
8+
use crate::radial::__pyo3_get_function_radial_grid_kk;
89

910
#[pymodule]
1011
fn numgrid(_py: Python, m: &PyModule) -> PyResult<()> {
@@ -14,6 +15,7 @@ fn numgrid(_py: Python, m: &PyModule) -> PyResult<()> {
1415
m.add_function(wrap_pyfunction!(atom_grid_bse, m)?)?;
1516
m.add_function(wrap_pyfunction!(angular_grid, m)?)?;
1617
m.add_function(wrap_pyfunction!(radial_grid, m)?)?;
18+
m.add_function(wrap_pyfunction!(radial_grid_kk, m)?)?;
1719

1820
Ok(())
1921
}

src/radial.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,65 @@ use statrs::function::gamma;
1111
#[cfg(test)]
1212
use crate::comparison;
1313

14+
#[pyfunction]
15+
pub fn radial_grid_kk(num_points: usize) -> (Vec<f64>, Vec<f64>) {
16+
let n = num_points as i32;
17+
let rws: Vec<_> = (1..=n).map(|i| kk_r_w(i, n)).collect();
18+
rws.iter().cloned().unzip()
19+
}
20+
21+
// https://doi.org/10.1063/1.475719, eqs. 9-13
22+
fn kk_r_w(i: i32, n: i32) -> (f64, f64) {
23+
let pi = std::f64::consts::PI;
24+
25+
let angle = ((i as f64) * pi) / ((n + 1) as f64);
26+
let s = angle.sin();
27+
let c = angle.cos();
28+
let t1 = ((n + 1 - 2 * i) as f64) / ((n + 1) as f64);
29+
let t2 = 2.0 / pi;
30+
let x = t1 + t2 * c * s * (1.0 + (2.0 / 3.0) * s * s);
31+
let f = 1.0 / 2.0_f64.ln();
32+
let r = f * (2.0 / (1.0 - x)).ln();
33+
let w = r * r * (f / (1.0 - x)) * (16.0 * s * s * s * s) / (3.0 * (n as f64) + 3.0);
34+
35+
(r, w)
36+
}
37+
38+
#[test]
39+
fn test_radial_grid_kk() {
40+
let (rs, ws) = radial_grid_kk(99);
41+
assert!(comparison::floats_are_same(
42+
rs[0],
43+
27.520865062836048,
44+
1.0e-15
45+
));
46+
assert!(comparison::floats_are_same(
47+
rs[1],
48+
22.522899235303480,
49+
1.0e-15
50+
));
51+
assert!(comparison::floats_are_same(
52+
rs[98],
53+
7.4914976443367854e-9,
54+
1.0e-15
55+
));
56+
assert!(comparison::floats_are_same(
57+
ws[0],
58+
5462.4446669497620,
59+
1.0e-15
60+
));
61+
assert!(comparison::floats_are_same(
62+
ws[1],
63+
1828.2535433191961,
64+
1.0e-15
65+
));
66+
assert!(comparison::floats_are_same(
67+
ws[98],
68+
2.1018140707490095e-24,
69+
1.0e-15
70+
));
71+
}
72+
1473
#[pyfunction]
1574
pub fn radial_grid(
1675
alpha_min: HashMap<usize, f64>,

0 commit comments

Comments
 (0)