libcint 0.3.2

FFI binding and GTO wrapper for libcint (C library)
Documentation
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
#![cfg(feature = "bse")]

use libcint::prelude::*;

fn check_cint_mol(toml_input: &str, refs: (usize, usize, f64, f64)) {
    let mol = CIntMol::from_toml(toml_input);
    let (ref_nao, ref_nbas, ref_kin_fp, ref_nuc_fp) = refs;

    let nao = mol.cint.nao();
    let nbas = mol.cint.nbas();
    let kin_fp = cint_fingerprint(mol.cint.integrate("int1e_kin", None, None).out.as_ref().unwrap());
    let nuc_fp = cint_fingerprint(mol.cint.integrate("int1e_nuc", None, None).out.as_ref().unwrap());

    assert_eq!(nao, ref_nao);
    assert_eq!(nbas, ref_nbas);
    assert!(
        (kin_fp - ref_kin_fp).abs() < 1e-6 || (kin_fp / ref_kin_fp - 1.0).abs() < 1e-4,
        "kinetic fingerprint mismatch: got {kin_fp}, expected {ref_kin_fp}"
    );
    assert!(
        (nuc_fp - ref_nuc_fp).abs() < 1e-6 || (nuc_fp / ref_nuc_fp - 1.0).abs() < 1e-4,
        "nuclear fingerprint mismatch: got {nuc_fp}, expected {ref_nuc_fp}"
    );
}

fn check_cint_mol_ecp(toml_input: &str, refs: (usize, usize, f64, f64, f64)) {
    let mol = CIntMol::from_toml(toml_input);
    let (ref_nao, ref_nbas, ref_kin_fp, ref_nuc_fp, ref_ecp_fp) = refs;

    let nao = mol.cint.nao();
    let nbas = mol.cint.nbas();
    let kin_fp = cint_fingerprint(mol.cint.integrate("int1e_kin", None, None).out.as_ref().unwrap());
    let nuc_fp = cint_fingerprint(mol.cint.integrate("int1e_nuc", None, None).out.as_ref().unwrap());
    let ecp_fp = cint_fingerprint(mol.cint.integrate_row_major("ECPscalar_iprinv", None, None).out.as_ref().unwrap());

    assert_eq!(nao, ref_nao);
    assert_eq!(nbas, ref_nbas);
    assert!(
        (kin_fp - ref_kin_fp).abs() < 1e-6 || (kin_fp / ref_kin_fp - 1.0).abs() < 1e-4,
        "kinetic fingerprint mismatch: got {kin_fp}, expected {ref_kin_fp}"
    );
    assert!(
        (nuc_fp - ref_nuc_fp).abs() < 1e-6 || (nuc_fp / ref_nuc_fp - 1.0).abs() < 1e-4,
        "nuclear fingerprint mismatch: got {nuc_fp}, expected {ref_nuc_fp}"
    );
    assert!(
        (ecp_fp - ref_ecp_fp).abs() < 1e-6 || (ecp_fp / ref_ecp_fp - 1.0).abs() < 1e-4,
        "ECP fingerprint mismatch: got {ecp_fp}, expected {ref_ecp_fp}"
    );
}

// simple case with sp shell
#[test]
fn simple_h2o_xyz_631g() {
    let toml_input = r#"
atom = """
O  0.0  0.0  1.0
H  1.2  0.5  1.3
H -0.7  1.2  0.1
"""

basis = "6-31G"
"#;
    let reference = (13, 9, 29.963738021815416, -74.71909470205469);
    check_cint_mol(toml_input, reference);
}

// zmat for three atoms
#[test]
fn simple_h2o_zmat_def2tzvp() {
    let toml_input = r#"
atom = "O; H 1 0.94; H 1 0.94 2 104.5"
basis = "def2-TZVP"
"#;
    let reference = (43, 19, 240.82414038242027, -455.36011189734484);
    check_cint_mol(toml_input, reference);
}

// large contraction in s orbital, cartesian
#[test]
fn simple_h2o_xyzcart_avqz() {
    let toml_input = r#"
atom = """
O  0.0  0.0  1.0
H  1.2  0.5  1.3
H -0.7  1.2  0.1
"""

basis = "aug-cc-pVQZ"
cart = true
"#;
    let reference = (215, 26, 117.86354585363418, -82.98711934741058);
    check_cint_mol(toml_input, reference);
}

// hybrid basis, zmat with dihedral
#[test]
fn difbas_ch4_zmat() {
    let toml_input = r#"
atom = """
C
H1 1 1.1
H  1 1.1 2 109.47
H2 1 1.1 2 109.47 3 120
H1 1 1.1 2 109.47 4 120
"""

basis = "custom"
cart = true

[basis-custom]
H1 = "aug-cc-pVQZ"
H2 = "def2-TZVP"
default = "6-31G"
"#;
    let reference = (127, 27, 26.883841020740512, -100.6569835983665);
    check_cint_mol(toml_input, reference);
}

// hybrid basis, zmat with dihedral, inline toml dict
#[test]
fn difbas_ch4_zmat_inline_dict() {
    let toml_input = r#"
atom = """
C
H1 1 1.1
H  1 1.1 2 109.47
H2 1 1.1 2 109.47 3 120
H1 1 1.1 2 109.47 4 120
"""

basis = { H1 = "aug-cc-pVQZ", H2 = "def2-TZVP", default = "6-31G" }
cart = true
"#;
    let reference = (127, 27, 26.883841020740512, -100.6569835983665);
    check_cint_mol(toml_input, reference);
}

#[test]
fn difbas_ch4_fmthybrid() {
    let toml_input = r#"
atom = """
C
H1 1 1.1
H  1 1.1 2 109.47
H2 1 1.1 2 109.47 3 120
H1 1 1.1 2 109.47 4 120
"""

basis = "custom"
cart = true

[basis-custom]
H1 = """BASIS_H1"""
H2 = """BASIS_H2"""
default = """BASIS_DEFAULT"""
"#;
    let toml_input = &toml_input
        .replace("BASIS_H1", &bse::get_formatted_basis("aug-cc-pVQZ", "nwchem", ""))
        .replace("BASIS_H2", &bse::get_formatted_basis("def2-TZVP", "cp2k", ""))
        .replace("BASIS_DEFAULT", &bse::get_formatted_basis("6-31G", "g94", ""));
    let reference = (127, 27, 26.883841020740512, -100.6569835983665);
    check_cint_mol(toml_input, reference);
}

// ghost atoms with hybrid basis, hybrid formats
#[test]
fn ghost_ch4_fmthybrid() {
    let toml_input = r#"
atom = """
C
H1 1 1.1
H  1 1.1 2 109.47
H2 1 1.1 2 109.47 3 120
H1 1 1.1 2 109.47 4 120
GHOST-H2 1 1.1 2 50 4 60
"""

basis = "custom"

[basis-custom]
H1 = """BASIS_H1"""
H2 = """BASIS_H2"""
default = """BASIS_DEFAULT"""
"#;
    let toml_input = &toml_input
        .replace("BASIS_H1", &bse::get_formatted_basis("aug-cc-pVQZ", "cp2k", ""))
        .replace("BASIS_H2", &bse::get_formatted_basis("def2-TZVP", "gamess_us", ""))
        .replace("BASIS_DEFAULT", &bse::get_formatted_basis("6-31G", "crystal", ""));
    let reference = (115, 31, 22.917103194160873, -59.51548379533634);
    check_cint_mol(toml_input, reference);
}

// ghost atoms with uncontract general basis, hybrid formats
#[test]
fn ghost_ch4_uncontract_general() {
    let toml_input = r#"
atom = """
C
H1 1 1.1
H  1 1.1 2 109.47
H2 1 1.1 2 109.47 3 120
H1 1 1.1 2 109.47 4 120
GHOST-H2 1 1.1 2 50 4 60
"""

basis = "custom"

[basis-custom]
H1 = """BASIS_H1"""
H2 = """BASIS_H2"""
default = """BASIS_DEFAULT"""
"#;
    let toml_input = &toml_input
        .replace("BASIS_H1", &bse::get_formatted_basis("aug-cc-pVQZ", "g94", ""))
        .replace("BASIS_H2", &bse::get_formatted_basis("def2-TZVP", "turbomole", ""))
        .replace("BASIS_DEFAULT", &bse::get_formatted_basis("6-31G", "cp2k", ""));
    let reference = (115, 43, 22.917103194160873, -59.51548379533635);
    check_cint_mol(toml_input, reference);
}

// X ghost atoms with hybrid basis, hybrid formats
#[test]
fn x_ch4_fmthybrid() {
    let toml_input = r#"
atom = """
C
H1 1 1.1
H  1 1.1 2 109.47
H2 1 1.1 2 109.47 3 120
H1 1 1.1 2 109.47 4 120
X-H2 1 1.1 2 50 4 60
"""

basis = "custom"
cart = true

[basis-custom]
H1 = """BASIS_H1"""
H2 = """BASIS_H2"""
default = """BASIS_DEFAULT"""
"#;
    let toml_input = &toml_input
        .replace("BASIS_H1", &bse::get_formatted_basis("aug-cc-pVQZ", "nwchem", ""))
        .replace("BASIS_H2", &bse::get_formatted_basis("def2-TZVP", "nwchem", ""))
        .replace("BASIS_DEFAULT", &bse::get_formatted_basis("6-31G", "nwchem", ""));
    let reference = (133, 31, 6.762701948984031, 6.691179124574312);
    check_cint_mol(toml_input, reference);
}

// empty basis for some atoms
#[test]
fn empty_basis() {
    let toml_input = r#"
atom = """
C
H1 1 1.1
H  1 1.1 2 109.47
H2 1 1.1 2 109.47 3 120
H1 1 1.1 2 109.47 4 120
X-H2 1 1.1 2 50 4 60
"""

basis = "custom"
allow_empty_basis = true

[basis-custom]
H1 = "aug-cc-pVQZ"
H2 = "def2-TZVP"
C = "6-31G"
H = ""
"#;
    let reference = (113, 29, 25.5437545117713, -218.53479925755568);
    check_cint_mol(toml_input, reference);
}

// ECP tests

#[test]
fn simple_ecp() {
    let toml_input = r#"
atom = """
Sb        -1.33937843      0.44597852     -1.27279684
Sb1        1.33937843     -0.44597852     -1.27279684
C1        -1.40429524      1.10441871      0.83468205
C         -2.16210130     -1.56132398     -0.84717555
C2         2.16210130      1.56132398     -0.84717555
C          1.40429524     -1.10441871      0.83468205
H1        -0.69918639      1.91987631      1.00872018
H1        -1.16111477      0.29030616      1.51873028
H1        -2.40124532      1.47235562      1.08516843
H1        -2.02002046     -2.22909286     -1.69887295
H         -1.69052287     -2.01612927      0.02577778
H-1       -3.23450854     -1.49489801     -0.65423339
H-1        2.02002046      2.22909286     -1.69887295
H-1        3.23450854      1.49489801     -0.65423339
H          1.69052287      2.01612927      0.02577778
H          0.69918639     -1.91987631      1.00872018
H@2        2.40124532     -1.47235562      1.08516843
H@2        1.16111477     -0.29030616      1.51873028
"""

basis = "def2-TZVP"
ecp = "def2-TZVP"
"#;
    let reference = (296, 124, 46.36693654819834, -85.3713246949453, -382.5298577424865);
    check_cint_mol_ecp(toml_input, reference);
}

#[test]
fn hybrid_ecp() {
    let toml_input = r#"
atom = """
Sb        -1.33937843      0.44597852     -1.27279684
Sb1        1.33937843     -0.44597852     -1.27279684
C1        -1.40429524      1.10441871      0.83468205
C         -2.16210130     -1.56132398     -0.84717555
C2         2.16210130      1.56132398     -0.84717555
C          1.40429524     -1.10441871      0.83468205
H1        -0.69918639      1.91987631      1.00872018
H1        -1.16111477      0.29030616      1.51873028
H1        -2.40124532      1.47235562      1.08516843
H1        -2.02002046     -2.22909286     -1.69887295
H         -1.69052287     -2.01612927      0.02577778
H-1       -3.23450854     -1.49489801     -0.65423339
H-1        2.02002046      2.22909286     -1.69887295
H-1        3.23450854      1.49489801     -0.65423339
H          1.69052287      2.01612927      0.02577778
H          0.69918639     -1.91987631      1.00872018
H@2        2.40124532     -1.47235562      1.08516843
H@2        1.16111477     -0.29030616      1.51873028
"""

basis = "def2-TZVP"
ecp = "lanl2dz"
"#;
    let reference = (296, 124, 46.36693654819834, -101.63816733519229, -356.64926629582527);
    check_cint_mol_ecp(toml_input, reference);
}

#[test]
fn complicated_ecp() {
    let toml_input = r#"
atom = """
Sb        -1.33937843      0.44597852     -1.27279684
Sb1        1.33937843     -0.44597852     -1.27279684
C1        -1.40429524      1.10441871      0.83468205
C         -2.16210130     -1.56132398     -0.84717555
C2         2.16210130      1.56132398     -0.84717555
C          1.40429524     -1.10441871      0.83468205
H1        -0.69918639      1.91987631      1.00872018
H1        -1.16111477      0.29030616      1.51873028
H1        -2.40124532      1.47235562      1.08516843
H1        -2.02002046     -2.22909286     -1.69887295
H         -1.69052287     -2.01612927      0.02577778
H-1       -3.23450854     -1.49489801     -0.65423339
H-1        2.02002046      2.22909286     -1.69887295
H-1        3.23450854      1.49489801     -0.65423339
H          1.69052287      2.01612927      0.02577778
H          0.69918639     -1.91987631      1.00872018
H@2        2.40124532     -1.47235562      1.08516843
H@2        1.16111477     -0.29030616      1.51873028
"""

basis = "custom"
ecp = "custom"

[basis-custom]
H1 = "2ZaPa-NR"
"H@2" = "AHGBSP1-5"
C1 = "Ahlrichs VDZ"
C = "pcS-3"
Sb1 = "dyall-v2z"
default = "def2-SVP"

[ecp-custom]
C2 = "pSBKJC"
Sb1 = "lanl2dz"
"#;
    let reference = (499, 149, 56669463.51097445, -33390.20950360246, 241.4214981674055);
    check_cint_mol_ecp(toml_input, reference);
}

#[test]
fn ghost_heavy() {
    let toml_input = r#"
atom = """
Sb        -1.33937843      0.44597852     -1.27279684
Sb1        1.33937843     -0.44597852     -1.27279684
C1        -1.40429524      1.10441871      0.83468205
C         -2.16210130     -1.56132398     -0.84717555
C2         2.16210130      1.56132398     -0.84717555
C          1.40429524     -1.10441871      0.83468205
H1        -0.69918639      1.91987631      1.00872018
H1        -1.16111477      0.29030616      1.51873028
H1        -2.40124532      1.47235562      1.08516843
H1        -2.02002046     -2.22909286     -1.69887295
H         -1.69052287     -2.01612927      0.02577778
H-1       -3.23450854     -1.49489801     -0.65423339
H-1        2.02002046      2.22909286     -1.69887295
H-1        3.23450854      1.49489801     -0.65423339
H          1.69052287      2.01612927      0.02577778
H          0.69918639     -1.91987631      1.00872018
H@2        2.40124532     -1.47235562      1.08516843
H@2        1.16111477     -0.29030616      1.51873028
GHOST-Sb  -2.33937843      1.44597852     -1.27279684
GHOST-Sb1  2.33937843     -1.44597852     -1.27279684
"""

basis = "custom"
ecp = "custom"

[basis-custom]
H1 = "2ZaPa-NR"
"H@2" = "AHGBSP1-5"
C1 = "Ahlrichs VDZ"
C = "pcS-3"
Sb1 = "dyall-v2z"
default = "def2-SVP"

[ecp-custom]
C2 = "pSBKJC"
Sb1 = "lanl2dz"
"#;
    let reference = (646, 206, 64220631.18409411, 26146.394518924033, -41.935106631928406);
    check_cint_mol_ecp(toml_input, reference);
}

// simple case with sp shell
#[test]
fn expand_nwchem_basis_h2o_sto3g() {
    let toml_input = r#"
atom = """
O  0.0  0.0  1.0
H  1.2  0.5  1.3
H -0.7  1.2  0.1
"""

basis = """
BASIS "ao basis" SPHERICAL PRINT
#BASIS SET: (3s) -> [1s]
H    S
      0.3425250914E+01       0.1543289673E+00
      0.6239137298E+00       0.5353281423E+00
      0.1688554040E+00       0.4446345422E+00
#BASIS SET: (6s,3p) -> [2s,1p]
O    S
      0.1307093214E+03       0.1543289673E+00
      0.2380886605E+02       0.5353281423E+00
      0.6443608313E+01       0.4446345422E+00
O    SP
      0.5033151319E+01      -0.9996722919E-01       0.1559162750E+00
      0.1169596125E+01       0.3995128261E+00       0.6076837186E+00
      0.3803889600E+00       0.7001154689E+00       0.3919573931E+00
END
"""
"#;
    let reference = (7, 5, 28.6285686659059, -72.0915097275113);
    check_cint_mol(toml_input, reference);
}

#[test]
fn expand_g94_basis_h2o_sto3g() {
    let toml_input = r#"
atom = """
O  0.0  0.0  1.0
H  1.2  0.5  1.3
H -0.7  1.2  0.1
"""

basis = """
H     0
S    3   1.00
      0.3425250914D+01       0.1543289673D+00
      0.6239137298D+00       0.5353281423D+00
      0.1688554040D+00       0.4446345422D+00
****
O     0
S    3   1.00
      0.1307093214D+03       0.1543289673D+00
      0.2380886605D+02       0.5353281423D+00
      0.6443608313D+01       0.4446345422D+00
SP   3   1.00
      0.5033151319D+01      -0.9996722919D-01       0.1559162750D+00
      0.1169596125D+01       0.3995128261D+00       0.6076837186D+00
      0.3803889600D+00       0.7001154689D+00       0.3919573931D+00
****
"""
"#;
    let reference = (7, 5, 28.6285686659059, -72.0915097275113);
    check_cint_mol(toml_input, reference);
}