Skip to content

Add toml parsing for parameters#4

Merged
ajz34 merged 13 commits intomainfrom
param-and-serde
Apr 27, 2026
Merged

Add toml parsing for parameters#4
ajz34 merged 13 commits intomainfrom
param-and-serde

Conversation

@ajz34
Copy link
Copy Markdown
Member

@ajz34 ajz34 commented Apr 27, 2026

This PR will introduce parsing toml dictionary to define DFTD3 parameters, and also allow the API caller to retrive DFTD3 parameters in struct DFTD3DampingParam.

The minimal full example can be

use dftd3::prelude::*;
// Use custom parameters by toml string
let input = r#"{version = "d3bj", a1 = 0.3981, s8 = 1.9889, a2 = 4.4211, atm = false}"#;
// You can also use the following input to specify B3LYP-D3(BJ) parameters
// 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}");

ajz34 and others added 13 commits April 25, 2026 23:41
- Add new parameters module for accessing DFT-D3 damping parameters
  from embedded TOML database (172 methods from simple-dftd3)
- Make interface damping structs serde-serializable with
  serde_inline_default for inline default values
- Extend DFTD3Error with ParametersError variant for TOML/parameter errors
- Parse TOML entries directly via toml::Table and deserialize into
  interface structs using IntoDeserializer (eliminates intermediate
  DampingEntryRaw struct)
- Add test_parameters example demonstrating module usage

Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: glm-5 <service@zhipuai.cn>
Move public API tests from parameters.rs inline #[cfg(test)] module
to examples/test_parameters.rs as #[test] functions, matching the
style of test_interface.rs. Tests are translated from s-dftd3's
python/dftd3/test_parameters.py. Only private-function tests
(load_data_base, normalize_version) remain in the module.

Also fix clippy needless-borrow warning in get_variant_entry call.

Co-authored-by: Claude Code <noreply@anthropic.com>
Co-authored-by: glm-5.1 <service@zhipuai.cn>
- Create parsing.rs with parse_damping_param, parse_damping_param_from_toml, and JSON support (behind json feature)
- Enhance parameters.rs with get_merged_param_table, get_default_param_table, and normalize_method
- Add test_parsing.rs example with comprehensive tests for all use cases
- Update Cargo.toml with serde_json optional dependency and json feature
- Add parsing module to lib.rs

Co-authored-by: Claude Code <noreply@anthropic.com>
Co-authored-by: glm-5.1 <service@zhipuai.cn>
Co-authored-by: doubao-seed-2.0-code <service@volcengine.com>
- Create parsing.rs with dftd3_parse_damping_param, dftd3_parse_damping_param_from_toml, and json support (dftd3_parse_damping_param_from_json)
- Update parameters.rs: rename functions to dftd3_* prefix, make helper functions pub(crate)
- Update lib.rs prelude to include parsing module
- Update test examples to use new function names
- Add comprehensive tests for parsing module

Co-authored-by: Claude Code <noreply@anthropic.com>
Co-authored-by: doubao-seed-2.0-code <doubao@bytedance.com>
- Update module-level docstring with all supported input formats and a runnable example
- Enhance function docstrings for all parsing functions
- Update lib.rs top-level doc to mention parsing functions
- Fix bug in dftd3_parse_damping_param_from_json_f where it was calling non-fallible version

Co-authored-by: Claude Code <noreply@anthropic.com>
Co-authored-by: doubao-seed-2.0-code <doubao@bytedance.com>
@ajz34 ajz34 merged commit 971a2a6 into main Apr 27, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant