Skip to main content

Module parsing

Module parsing 

Source
Expand description

Flexible parsing of DFT-D3 damping parameters from TOML or JSON input.

This module provides functions to parse parameter specifications that can combine method lookups from the database with direct parameter values, overrides, and the atm flag for three-body dispersion control.

§Supported input formats

  • Usual case with method: {version = "d3bj", method = "b3lyp"} Lookup B3LYP-D3(BJ) parameters from the database.
  • Version without d3 prefix: {version = "bj", method = "b3lyp"} The d3 prefix is optional. The version field is case-insensitive, so BJ works too.
  • Direct parameters: {version = "d3bj", a1 = 0.3981, s8 = 1.9889, a2 = 4.4211} Specify parameters directly without using the database.
  • ATM flag (no three-body): {version = "bj", method = "b3lyp", atm = false} Sets s9 = 0.0. Default is atm = true (s9 = 1.0).
  • Parameter override: {version = "d3bj", method = "b3lyp", a1 = 0.5} Use database values but override a1 to 0.5.
  • Direct params + ATM: {version = "d3bj", a1 = 0.3981, s8 = 1.9889, a2 = 4.4211, atm = false} Direct parameters with s9 = 0.0. If both s9 and atm are provided, s9 takes precedence.
  • Method name normalization: {version = "zero", method = "m06-2x"} Separators like -, _ are removed automatically (normalized to m062x for lookup).
  • Invalid field error: {version = "d3bj", method = "b3lyp", rs6 = 0.5} Returns an error because rs6 is not a valid parameter for the bj variant.

§Example

use dftd3::prelude::*;

// B3LYP with Becke-Johnson damping, no overrides, atm = true (default)
let input = r#"{version = "d3bj", method = "b3lyp"}"#;
// toml parameter type
let damping_param = dftd3_parse_damping_param_from_toml(input);
// FFI parameter type
let dftd3_param = damping_param.new_param();

let atom_charges = vec![8, 1, 1];
// coordinates in bohr
#[rustfmt::skip]
let coordinates = vec![
    0.000000, 0.000000, 0.000000,
    0.000000, 0.000000, 1.807355,
    1.807355, 0.000000, -0.452500,
];
let model = DFTD3Model::new(&atom_charges, &coordinates, None, None);
let res = model.get_dispersion(&dftd3_param, false);
let eng = res.energy;
println!("Dispersion energy: {eng}");

Functions§

dftd3_parse_damping_param
Parse damping parameters from a TOML table.
dftd3_parse_damping_param_f
dftd3_parse_damping_param_from_json
Parse damping parameters from a JSON string (panics on error).
dftd3_parse_damping_param_from_json_f
Parse damping parameters from a JSON string (fallible version).
dftd3_parse_damping_param_from_toml
Parse damping parameters from a TOML string (panics on error).
dftd3_parse_damping_param_from_toml_f
Parse damping parameters from a TOML string (fallible version).