Skip to content

Commit dde2b99

Browse files
authored
Github action for testing (#1)
* dftd3-src action * dftd3 action * dftd3 action (change name) * update docs of crate dftd3 * update readme for dftd3-src * fix cargo test
1 parent 0150d28 commit dde2b99

File tree

9 files changed

+350
-33
lines changed

9 files changed

+350
-33
lines changed

.github/workflows/test-dftd3-src.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: test-dftd3-src
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build-static:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: run tests directly
15+
run: |
16+
cd dftd3-src
17+
export DFTD3_SRC_DEV=1
18+
cargo test --test "*" -vv --features="build_from_source static" -- --nocapture
19+
20+
build-dynamic:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
- name: run tests directly
25+
run: |
26+
cd dftd3-src
27+
cargo test --test "*" -vv --features="build_from_source" -- --nocapture
28+
29+
external-static:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
- uses: conda-incubator/setup-miniconda@v3
34+
- name: run tests directly
35+
run: |
36+
cd dftd3-src
37+
conda install dftd3-python -c conda-forge
38+
ls /usr/share/miniconda/lib
39+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/share/miniconda/lib
40+
export DFTD3_SRC_DEV=1
41+
cargo test --test "*" -vv --features="static" -- --nocapture
42+
43+
external-dynamic:
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v4
47+
- uses: conda-incubator/setup-miniconda@v3
48+
- name: run tests directly
49+
run: |
50+
cd dftd3-src
51+
conda install dftd3-python -c conda-forge
52+
ls /usr/share/miniconda/lib
53+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/share/miniconda/lib
54+
cargo test --test "*" -vv -- --nocapture

.github/workflows/test-dftd3.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: test-dftd3
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test-from-miniconda:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: conda-incubator/setup-miniconda@v3
15+
- name: run tests directly
16+
run: |
17+
cd dftd3
18+
conda install dftd3-python -c conda-forge
19+
ls /usr/share/miniconda/lib
20+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/share/miniconda/lib
21+
export DFTD3_DEV=1
22+
cargo test
23+
cargo test --examples

dftd3-src/build.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ fn main() {
8383
if cfg!(feature = "static") {
8484
println!("cargo:rustc-link-lib=static=s-dftd3");
8585
println!("cargo:rustc-link-lib=static=mctc-lib");
86-
println!("cargo:rerun-if-env-changed=DFTD3_DEV_LINUX");
87-
if std::env::var("DFTD3_DEV_LINUX").is_ok() {
86+
// static linking may requires gomp and gfortran to be dynamically linked
87+
// but that depends on the compiler and the system, so user should take care
88+
// of that. We just provide a hint here.
89+
println!("cargo:rerun-if-env-changed=DFTD3_SRC_DEV");
90+
if std::env::var("DFTD3_SRC_DEV").is_ok() {
8891
println!("cargo:rustc-link-lib=gomp");
8992
println!("cargo:rustc-link-lib=gfortran");
9093
}

dftd3-src/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1+
//! simple-dftd3 build-from-source or library selection
2+
//!
3+
//! This module is only used for rust-side configuration of library linking.
4+
//! Please see the following document for more details.
5+
#![doc = include_str!("../readme.md")]
16
#![no_std]

dftd3/examples/energy_r2scan_d3zero.rs

+33-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ fn main_test() {
3131
let model = DFTD3Model::new(&numbers, &positions, None, None);
3232
// explicitly set DFTD3 parameters
3333
for atm in [true, false] {
34+
let energy_ref = if atm { -0.01410721853585842 } else { -0.014100267345314462 };
35+
3436
let param = DFTD3ZeroDampingParamBuilder::default()
3537
.s8(1.683)
3638
.rs6(1.139)
@@ -40,7 +42,37 @@ fn main_test() {
4042
let (energy, _, _) = model.get_dispersion(&param, false).into();
4143

4244
println!("Dispersion energy: {}", energy);
43-
let energy_ref = if atm { -0.01410721853585842 } else { -0.014100267345314462 };
45+
assert!((energy - energy_ref).abs() < 1e-9);
46+
47+
// this way to provide custom damping parameter is also valid
48+
let param = DFTD3ZeroDampingParam {
49+
s6: 1.0,
50+
s8: 1.683,
51+
rs6: 1.139,
52+
rs8: 1.0,
53+
alp: 14.0,
54+
s9: if atm { 1.0 } else { 0.0 },
55+
};
56+
let param = param.new_param();
57+
// obtain the dispersion energy without gradient and sigma
58+
let (energy, _, _) = model.get_dispersion(&param, false).into();
59+
60+
println!("Dispersion energy: {}", energy);
61+
assert!((energy - energy_ref).abs() < 1e-9);
62+
63+
// this way to provide custom damping parameter is also valid
64+
let param = DFTD3Param::new_zero_damping(
65+
1.0, // s6
66+
1.683, // s8
67+
if atm { 1.0 } else { 0.0 }, // s9
68+
1.139, // rs6
69+
1.0, // rs8
70+
14.0, // alp
71+
);
72+
// obtain the dispersion energy without gradient and sigma
73+
let (energy, _, _) = model.get_dispersion(&param, false).into();
74+
75+
println!("Dispersion energy: {}", energy);
4476
assert!((energy - energy_ref).abs() < 1e-9);
4577
}
4678
}

dftd3/src/damping_param_usage.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Common API documentation for custom damping parameter specification
2+
3+
If your task is to retrive damping parameters of some specific xc-functionals, you may wish to try [`dftd3_load_param`] function.
4+
5+
In this crate, you may have three ways to define customized parameters:
6+
7+
- By `DFTD3***DampingParam` struct. In this way, all parameters (include optional parameters with default value) must be provided. For example of B3-Zero:
8+
9+
```rust
10+
# use dftd3::prelude::*;
11+
# let atm = true;
12+
let param = DFTD3ZeroDampingParam {
13+
s6: 1.0,
14+
s8: 1.683,
15+
rs6: 1.139,
16+
rs8: 1.0,
17+
alp: 14.0,
18+
s9: if atm { 1.0 } else { 0.0 },
19+
};
20+
let param = param.new_param();
21+
// this will give param: DFTD3Param
22+
```
23+
24+
- By `DFTD3***DampingParamBuilder` struct. In this way, optional parameters can be omitted. For example of B3-Zero:
25+
26+
```rust
27+
# use dftd3::prelude::*;
28+
# let atm = true;
29+
let param = DFTD3ZeroDampingParamBuilder::default()
30+
.s8(1.683)
31+
.rs6(1.139)
32+
.s9(if atm { 1.0 } else { 0.0 })
33+
.init();
34+
// this will give param: DFTD3Param
35+
```
36+
37+
- By `DFTD3Param` utility. In this way, all parameters must be provided. For example of B3-Zero:
38+
39+
```rust
40+
# use dftd3::prelude::*;
41+
# let atm = true;
42+
let param = DFTD3Param::new_zero_damping(
43+
1.0, // s6
44+
1.683, // s8
45+
if atm { 1.0 } else { 0.0 }, // s9
46+
1.139, // rs6
47+
1.0, // rs8
48+
14.0, // alp
49+
);
50+
```
51+
52+
Please note that different DFT-D3 versions may have different parameters, for example modified zero damping have another parameter `bet` for beta, and rational damping (D3-BJ) have parameter name `a1`, `a2` instead of `rs6`, `rs8`.

0 commit comments

Comments
 (0)