pub struct DFTD4Param { /* private fields */ }Expand description
Basic struct for damping parameters, representing a parametrization of a DFT-D4 method.
The damping parameters contained in the object are immutable. To change the parametrization, a new object must be created. Furthermore, the object is opaque to the user and the contained data cannot be accessed directly.
Implementations§
Source§impl DFTD4Param
impl DFTD4Param
Sourcepub fn new_rational_damping(
s6: f64,
s8: f64,
s9: f64,
a1: f64,
a2: f64,
alp: f64,
) -> Self
pub fn new_rational_damping( s6: f64, s8: f64, s9: f64, a1: f64, a2: f64, alp: f64, ) -> Self
Create new damping parameters.
The parameters are:
s6- Scaling factor for C6 contributions8- Scaling factor for C8 contributions9- Scaling factor for C9 contributiona1- Scaling factor for critical radiia2- Offset distance in Bohr for critical radii
Sourcepub fn new_rational_damping_f(
s6: f64,
s8: f64,
s9: f64,
a1: f64,
a2: f64,
alp: f64,
) -> Result<Self, DFTD4Error>
pub fn new_rational_damping_f( s6: f64, s8: f64, s9: f64, a1: f64, a2: f64, alp: f64, ) -> Result<Self, DFTD4Error>
Crate new damping parameters (failable).
Sourcepub fn load_rational_damping(name: &str, atm: bool) -> Self
pub fn load_rational_damping(name: &str, atm: bool) -> Self
Load damping parameters from internal storage.
name- name of the xc-functionalatm- use three-body specific parametrization
Examples found in repository?
examples/test_interface.rs (line 122)
95fn test_blypd4() {
96 // Use BLYP-D4 for a mindless molecule
97 let thr = 1.0e-7;
98
99 let numbers = vec![1, 1, 6, 5, 1, 15, 8, 17, 13, 15, 5, 1, 9, 15, 1, 15];
100 #[rustfmt::skip]
101 let positions = vec![
102 2.79274810283778, 3.82998228828316, -2.79287054959216,
103 -1.43447454186833, 0.43418729987882, 5.53854345129809,
104 -3.26268343665218, -2.50644032426151, -1.56631149351046,
105 2.14548759959147, -0.88798018953965, -2.24592534506187,
106 -4.30233097423181, -3.93631518670031, -0.48930754109119,
107 0.06107643564880, -3.82467931731366, -2.22333344469482,
108 0.41168550401858, 0.58105573172764, 5.56854609916143,
109 4.41363836635653, 3.92515871809283, 2.57961724984000,
110 1.33707758998700, 1.40194471661647, 1.97530004949523,
111 3.08342709834868, 1.72520024666801, -4.42666116106828,
112 -3.02346932078505, 0.04438199934191, -0.27636197425010,
113 1.11508390868455, -0.97617412809198, 6.25462847718180,
114 0.61938955433011, 2.17903547389232, -6.21279842416963,
115 -2.67491681346835, 3.00175899761859, 1.05038813614845,
116 -4.13181080289514, -2.34226739863660, -3.44356159392859,
117 2.85007173009739, -2.64884892757600, 0.71010806424206,
118 ];
119
120 let model = DFTD4Model::new(&numbers, &positions, None, None, None);
121
122 let param = DFTD4Param::load_rational_damping("blyp", true);
123 let res = model.get_dispersion(¶m, false);
124
125 assert_abs_diff_eq!(res.energy, -0.06991716314879085, epsilon = thr);
126
127 let res = model.get_dispersion(¶m, true);
128
129 assert_abs_diff_eq!(res.energy, -0.06991716314879085, epsilon = thr);
130}
131
132#[cfg(feature = "api-v4_0")]
133fn test_tpssd4s() {
134 // Use TPSS-D4S for a mindless molecule
135 let thr = 1.0e-7;
136
137 let numbers = vec![1, 1, 6, 5, 1, 15, 8, 17, 13, 15, 5, 1, 9, 15, 1, 15];
138 #[rustfmt::skip]
139 let positions = vec![
140 2.79274810283778, 3.82998228828316, -2.79287054959216,
141 -1.43447454186833, 0.43418729987882, 5.53854345129809,
142 -3.26268343665218, -2.50644032426151, -1.56631149351046,
143 2.14548759959147, -0.88798018953965, -2.24592534506187,
144 -4.30233097423181, -3.93631518670031, -0.48930754109119,
145 0.06107643564880, -3.82467931731366, -2.22333344469482,
146 0.41168550401858, 0.58105573172764, 5.56854609916143,
147 4.41363836635653, 3.92515871809283, 2.57961724984000,
148 1.33707758998700, 1.40194471661647, 1.97530004949523,
149 3.08342709834868, 1.72520024666801, -4.42666116106828,
150 -3.02346932078505, 0.04438199934191, -0.27636197425010,
151 1.11508390868455, -0.97617412809198, 6.25462847718180,
152 0.61938955433011, 2.17903547389232, -6.21279842416963,
153 -2.67491681346835, 3.00175899761859, 1.05038813614845,
154 -4.13181080289514, -2.34226739863660, -3.44356159392859,
155 2.85007173009739, -2.64884892757600, 0.71010806424206,
156 ];
157
158 let model = DFTD4Model::new_d4s(&numbers, &positions, None, None, None);
159
160 let param = DFTD4Param::load_rational_damping("tpss", true);
161 let res = model.get_dispersion(¶m, false);
162
163 assert_abs_diff_eq!(res.energy, -0.046233140236052253, epsilon = thr);
164
165 let res = model.get_dispersion(¶m, true);
166
167 assert_abs_diff_eq!(res.energy, -0.046233140236052253, epsilon = thr);
168}
169
170fn test_pbed4() {
171 // Use PBE-D4 for a mindless molecule
172 let thr = 1.0e-7;
173
174 let numbers = vec![1, 9, 15, 13, 1, 1, 13, 5, 3, 15, 8, 1, 1, 5, 16, 1];
175 #[rustfmt::skip]
176 let positions = vec![
177 -2.14132037405479, -1.34402701877044, -2.32492500904728,
178 4.46671289205392, -2.04800110524830, 0.44422406067087,
179 -4.92212517643478, -1.73734240529793, 0.96890323821450,
180 -1.30966093045696, -0.52977363497805, 3.44453452239668,
181 -4.34208759006189, -4.30470270977329, 0.39887431726215,
182 0.61788392767516, 2.62484136683297, -3.28228926932647,
183 4.23562873444840, -1.68839322682951, -3.53824299552792,
184 2.23130060612446, 1.93579813100155, -1.80384647554323,
185 -2.32285463652832, 2.90603947535842, -1.39684847191937,
186 2.34557941578250, 2.86074312333371, 1.82827238641666,
187 -3.66431367659153, -0.42910188232667, -1.81957402856634,
188 -0.34927881505446, -1.75988134003940, 5.98017466326572,
189 0.29500802281217, -2.00226104143537, 0.53023447931897,
190 2.10449364205058, -0.56741404446633, 0.30975625014335,
191 -1.59355304432499, 3.69176153150419, 2.87878226787916,
192 4.34858700256050, 2.39171478113440, -2.61802993563738,
193 ];
194
195 let model = DFTD4Model::new(&numbers, &positions, None, None, None);
196
197 let param = DFTD4Param::load_rational_damping("pbe", true);
198 let res = model.get_dispersion(¶m, false);
199
200 assert_abs_diff_eq!(res.energy, -0.028415184156428127, epsilon = thr);
201
202 let res = model.get_dispersion(¶m, true);
203
204 assert_abs_diff_eq!(res.energy, -0.028415184156428127, epsilon = thr);
205}More examples
examples/energy_r2scan.rs (line 33)
3fn main_test() {
4 // atom indices
5 let numbers = vec![6, 6, 6, 6, 6, 6, 53, 1, 1, 1, 1, 1, 16, 1, 6, 1, 1, 1];
6 // geometry in angstrom
7 #[rustfmt::skip]
8 let positions = vec![
9 -0.755422531, -0.796459123, -1.023590391,
10 0.634274834, -0.880017014, -1.075233285,
11 1.406955202, 0.199695367, -0.653144334,
12 0.798863737, 1.361204515, -0.180597909,
13 -0.593166787, 1.434312023, -0.133597923,
14 -1.376239198, 0.359205222, -0.553258516,
15 -1.514344238, 3.173268101, 0.573601106,
16 1.110906949, -1.778801728, -1.440619836,
17 1.399172302, 2.197767355, 0.147412751,
18 2.486417780, 0.142466525, -0.689380574,
19 -2.454252250, 0.422581120, -0.512807958,
20 -1.362353593, -1.630564523, -1.348743149,
21 -3.112683203, 6.289227834, 1.226984439,
22 -4.328789697, 5.797771251, 0.973373089,
23 -2.689135032, 6.703163830, -0.489062886,
24 -1.684433029, 7.115457372, -0.460265708,
25 -2.683867206, 5.816530502, -1.115183775,
26 -3.365330613, 7.451201412, -0.890098894,
27 ];
28 // convert angstrom to bohr
29 let positions = positions.iter().map(|&x| x / 0.52917721067).collect::<Vec<f64>>();
30 // generate DFTD4 model
31 let model = DFTD4Model::new(&numbers, &positions, None, None, None);
32 // retrive the DFTD4 parameters
33 let param = DFTD4Param::load_rational_damping("r2SCAN", true);
34 // obtain the dispersion energy without gradient and sigma
35 let (energy, _, _) = model.get_dispersion(¶m, false).into();
36
37 println!("Dispersion energy: {}", energy);
38 let energy_ref = -0.005001101058518388;
39 assert!((energy - energy_ref).abs() < 1e-9);
40}examples/gradient_b97m.rs (line 32)
3fn main_test() {
4 // atom indices
5 let numbers = vec![1, 6, 6, 6, 6, 6, 6, 1, 1, 1, 1, 1, 35, 6, 9, 9, 9];
6 // geometry in angstrom
7 #[rustfmt::skip]
8 let positions = vec![
9 0.002144194, 0.361043475, 0.029799709,
10 0.015020592, 0.274789738, 1.107648016,
11 1.227632658, 0.296655040, 1.794629427,
12 1.243958826, 0.183702791, 3.183703934,
13 0.047958213, 0.048915002, 3.886484583,
14 -1.165135654, 0.026954348, 3.200213281,
15 -1.181832083, 0.139828643, 1.810376587,
16 2.155807907, 0.399177037, 1.249441585,
17 2.184979344, 0.198598553, 3.716170761,
18 0.060934662, -0.040672756, 4.964014252,
19 -2.093220602, -0.078628959, 3.745125056,
20 -2.122845437, 0.123257119, 1.277645797,
21 -0.268325907, -3.194209024, 1.994458950,
22 0.049999933, -5.089197474, 1.929391171,
23 0.078949601, -5.512441335, 0.671851563,
24 1.211983937, -5.383996300, 2.498664481,
25 -0.909987405, -5.743747328, 2.570721738,
26 ];
27 // convert angstrom to bohr
28 let positions = positions.iter().map(|&x| x / 0.52917721067).collect::<Vec<f64>>();
29 // generate DFTD4 model
30 let model = DFTD4Model::new(&numbers, &positions, None, None, None);
31 // retrive the DFTD4 parameters
32 let param = DFTD4Param::load_rational_damping("b97m", true);
33 // obtain the dispersion energy and gradient, without sigma
34 let (energy, gradient, _) = model.get_dispersion(¶m, true).into();
35 let gradient = gradient.unwrap();
36 println!("Dispersion energy: {}", energy);
37 println!("Dispersion gradient:");
38 gradient.chunks(3).for_each(|chunk| println!("{:16.9?}", chunk));
39
40 #[rustfmt::skip]
41 let gradient_ref = vec![
42 2.98598566e-06, 5.58662750e-05, -2.26040542e-04,
43 1.75816159e-05, 3.76346114e-04, -5.59737686e-04,
44 5.30037419e-04, 3.39528029e-04, -2.58687563e-04,
45 5.28657666e-04, 2.71291979e-04, 3.25797992e-04,
46 2.86698935e-05, 2.42198161e-04, 6.35784343e-04,
47 -4.99037369e-04, 2.74343468e-04, 3.55926359e-04,
48 -5.08919994e-04, 3.36480299e-04, -2.53165937e-04,
49 1.90422032e-04, 3.91738111e-05, -1.05867702e-04,
50 1.88137796e-04, 1.62741316e-05, 1.07526135e-04,
51 6.73432246e-06, 2.93353505e-06, 2.23028509e-04,
52 -1.97182105e-04, 1.82664904e-05, 1.26683921e-04,
53 -2.07136902e-04, 4.89015922e-05, -1.12337721e-04,
54 -2.01762905e-04, -1.23133705e-03, -2.26387771e-04,
55 7.59912392e-06, -1.01235495e-04, -7.86554908e-06,
56 3.02563455e-05, -2.19783887e-04, -2.31677736e-04,
57 2.31670341e-04, -2.08064229e-04, 9.53780006e-05,
58 -1.48713265e-04, -2.61183219e-04, 1.11642946e-04,
59 ];
60
61 let l2_diff =
62 gradient.iter().zip(gradient_ref.iter()).map(|(x, y)| (x - y).powi(2)).sum::<f64>().sqrt();
63 println!("L2 difference: {:16.8e}", l2_diff);
64 assert!(l2_diff < 1e-9);
65}Sourcepub fn load_rational_damping_f(
name: &str,
atm: bool,
) -> Result<Self, DFTD4Error>
pub fn load_rational_damping_f( name: &str, atm: bool, ) -> Result<Self, DFTD4Error>
Load damping parameters from internal storage (failable).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DFTD4Param
impl RefUnwindSafe for DFTD4Param
impl !Send for DFTD4Param
impl !Sync for DFTD4Param
impl Unpin for DFTD4Param
impl UnsafeUnpin for DFTD4Param
impl UnwindSafe for DFTD4Param
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more