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, mdb: bool) -> Self
pub fn load_rational_damping(name: &str, mdb: bool) -> Self
Load damping parameters from internal storage.
name
- name of the xc-functionalmdb
- use three-body specific parametrization
Examples found in repository?
examples/test_interface.rs (line 118)
91fn test_blypd4() {
92 // Use BLYP-D4 for a mindless molecule
93 let thr = 1.0e-7;
94
95 let numbers = vec![1, 1, 6, 5, 1, 15, 8, 17, 13, 15, 5, 1, 9, 15, 1, 15];
96 #[rustfmt::skip]
97 let positions = vec![
98 2.79274810283778, 3.82998228828316, -2.79287054959216,
99 -1.43447454186833, 0.43418729987882, 5.53854345129809,
100 -3.26268343665218, -2.50644032426151, -1.56631149351046,
101 2.14548759959147, -0.88798018953965, -2.24592534506187,
102 -4.30233097423181, -3.93631518670031, -0.48930754109119,
103 0.06107643564880, -3.82467931731366, -2.22333344469482,
104 0.41168550401858, 0.58105573172764, 5.56854609916143,
105 4.41363836635653, 3.92515871809283, 2.57961724984000,
106 1.33707758998700, 1.40194471661647, 1.97530004949523,
107 3.08342709834868, 1.72520024666801, -4.42666116106828,
108 -3.02346932078505, 0.04438199934191, -0.27636197425010,
109 1.11508390868455, -0.97617412809198, 6.25462847718180,
110 0.61938955433011, 2.17903547389232, -6.21279842416963,
111 -2.67491681346835, 3.00175899761859, 1.05038813614845,
112 -4.13181080289514, -2.34226739863660, -3.44356159392859,
113 2.85007173009739, -2.64884892757600, 0.71010806424206,
114 ];
115
116 let model = DFTD4Model::new(&numbers, &positions, None, None, None);
117
118 let param = DFTD4Param::load_rational_damping("blyp", false);
119 let res = model.get_dispersion(¶m, false);
120
121 assert_abs_diff_eq!(res.energy, -0.06991716314879085, epsilon = thr);
122
123 let res = model.get_dispersion(¶m, true);
124
125 assert_abs_diff_eq!(res.energy, -0.06991716314879085, epsilon = thr);
126}
127
128#[cfg(feature = "d4s")]
129fn test_tpssd4s() {
130 // Use TPSS-D4S for a mindless molecule
131 let thr = 1.0e-7;
132
133 let numbers = vec![1, 1, 6, 5, 1, 15, 8, 17, 13, 15, 5, 1, 9, 15, 1, 15];
134 #[rustfmt::skip]
135 let positions = vec![
136 2.79274810283778, 3.82998228828316, -2.79287054959216,
137 -1.43447454186833, 0.43418729987882, 5.53854345129809,
138 -3.26268343665218, -2.50644032426151, -1.56631149351046,
139 2.14548759959147, -0.88798018953965, -2.24592534506187,
140 -4.30233097423181, -3.93631518670031, -0.48930754109119,
141 0.06107643564880, -3.82467931731366, -2.22333344469482,
142 0.41168550401858, 0.58105573172764, 5.56854609916143,
143 4.41363836635653, 3.92515871809283, 2.57961724984000,
144 1.33707758998700, 1.40194471661647, 1.97530004949523,
145 3.08342709834868, 1.72520024666801, -4.42666116106828,
146 -3.02346932078505, 0.04438199934191, -0.27636197425010,
147 1.11508390868455, -0.97617412809198, 6.25462847718180,
148 0.61938955433011, 2.17903547389232, -6.21279842416963,
149 -2.67491681346835, 3.00175899761859, 1.05038813614845,
150 -4.13181080289514, -2.34226739863660, -3.44356159392859,
151 2.85007173009739, -2.64884892757600, 0.71010806424206,
152 ];
153
154 let model = DFTD4Model::new_d4s(&numbers, &positions, None, None, None);
155
156 let param = DFTD4Param::load_rational_damping("tpss", false);
157 let res = model.get_dispersion(¶m, false);
158
159 assert_abs_diff_eq!(res.energy, -0.046233140236052253, epsilon = thr);
160
161 let res = model.get_dispersion(¶m, true);
162
163 assert_abs_diff_eq!(res.energy, -0.046233140236052253, epsilon = thr);
164}
165
166fn test_pbed4() {
167 // Use PBE-D4 for a mindless molecule
168 let thr = 1.0e-7;
169
170 let numbers = vec![1, 9, 15, 13, 1, 1, 13, 5, 3, 15, 8, 1, 1, 5, 16, 1];
171 #[rustfmt::skip]
172 let positions = vec![
173 -2.14132037405479, -1.34402701877044, -2.32492500904728,
174 4.46671289205392, -2.04800110524830, 0.44422406067087,
175 -4.92212517643478, -1.73734240529793, 0.96890323821450,
176 -1.30966093045696, -0.52977363497805, 3.44453452239668,
177 -4.34208759006189, -4.30470270977329, 0.39887431726215,
178 0.61788392767516, 2.62484136683297, -3.28228926932647,
179 4.23562873444840, -1.68839322682951, -3.53824299552792,
180 2.23130060612446, 1.93579813100155, -1.80384647554323,
181 -2.32285463652832, 2.90603947535842, -1.39684847191937,
182 2.34557941578250, 2.86074312333371, 1.82827238641666,
183 -3.66431367659153, -0.42910188232667, -1.81957402856634,
184 -0.34927881505446, -1.75988134003940, 5.98017466326572,
185 0.29500802281217, -2.00226104143537, 0.53023447931897,
186 2.10449364205058, -0.56741404446633, 0.30975625014335,
187 -1.59355304432499, 3.69176153150419, 2.87878226787916,
188 4.34858700256050, 2.39171478113440, -2.61802993563738,
189 ];
190
191 let model = DFTD4Model::new(&numbers, &positions, None, None, None);
192
193 let param = DFTD4Param::load_rational_damping("pbe", false);
194 let res = model.get_dispersion(¶m, false);
195
196 assert_abs_diff_eq!(res.energy, -0.028415184156428127, epsilon = thr);
197
198 let res = model.get_dispersion(¶m, true);
199
200 assert_abs_diff_eq!(res.energy, -0.028415184156428127, epsilon = thr);
201}
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,
mdb: bool,
) -> Result<Self, DFTD4Error>
pub fn load_rational_damping_f( name: &str, mdb: 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 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