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
//! Built-in parameter descriptions shared by every surface (Task 3.8.2).
//!
//! The sets below are the single definition used by the CLI, the Python
//! bindings, the WASM bindings and the JSON schema the agent layer reads. A
//! front end renders them; it never duplicates the bounds or help text.
use serde_json::json;
use crate::params::{ParamSet, ParamSpec, ParamType};
/// Names of the built-in parameter sets.
pub const PRESET_NAMES: [&str; 3] = ["symmetry", "pxrd", "uff"];
fn spec(
name: &str,
kind: ParamType,
default: serde_json::Value,
help: &str,
group: &str,
) -> ParamSpec {
ParamSpec {
name: name.to_owned(),
kind,
default,
help: help.to_owned(),
required: false,
group: Some(group.to_owned()),
}
}
/// Returns the named built-in parameter set.
///
/// # Errors
///
/// Returns [`crate::Error::InvalidInput`] for an unknown name or an invalid
/// built-in default.
pub fn preset(name: &str) -> Result<ParamSet, crate::Error> {
let set = ParamSet::new();
let set = match name {
"symmetry" => set
.with_param(spec(
"symprec",
ParamType::Float {
min: Some(1e-6),
max: Some(1.0),
unit: Some("Angstrom".to_owned()),
},
json!(1e-3),
"Position tolerance for the space-group search",
"Symmetry",
))?
.with_param(spec(
"angle_tolerance",
ParamType::Float {
min: Some(0.1),
max: Some(10.0),
unit: Some("degree".to_owned()),
},
json!(5.0),
"Angle tolerance for the space-group search",
"Symmetry",
))?
.with_param(spec(
"hall_number",
ParamType::Integer {
min: Some(1),
max: Some(530),
},
json!(1),
"Preferred Hall setting; 1 means the spglib default",
"Symmetry",
))?,
"pxrd" => set
.with_param(spec(
"radiation",
ParamType::Choice {
choices: [
"cu-ka", "cu-ka1", "mo-ka", "co-ka", "fe-ka", "cr-ka", "ag-ka",
]
.map(str::to_owned)
.to_vec(),
},
json!("cu-ka"),
"X-ray source",
"Pattern",
))?
.with_param(spec(
"max_two_theta",
ParamType::Float {
min: Some(5.0),
max: Some(180.0),
unit: Some("degree".to_owned()),
},
json!(80.0),
"Highest two-theta in the pattern",
"Pattern",
))?
.with_param(spec(
"step",
ParamType::Float {
min: Some(0.001),
max: Some(1.0),
unit: Some("degree".to_owned()),
},
json!(0.02),
"Pattern sampling step",
"Pattern",
))?
.with_param(spec(
"fwhm",
ParamType::Float {
min: Some(0.01),
max: Some(5.0),
unit: Some("degree".to_owned()),
},
json!(0.1),
"Peak full width at half maximum",
"Profile",
))?,
"uff" => set
.with_param(spec(
"parameter_set",
ParamType::Choice {
choices: ["uff", "uff4mof", "uff4mof-ii"].map(str::to_owned).to_vec(),
},
json!("uff4mof"),
"Parameter table",
"Force field",
))?
.with_param(spec(
"vdw",
ParamType::Boolean,
json!(true),
"Whether the Lennard-Jones term is evaluated",
"Force field",
))?
.with_param(spec(
"vdw_cutoff",
ParamType::Float {
min: Some(1.0),
max: Some(50.0),
unit: Some("Angstrom".to_owned()),
},
json!(12.0),
"van der Waals cutoff",
"Force field",
))?
.with_param(spec(
"total_charge",
ParamType::Float {
min: Some(-20.0),
max: Some(20.0),
unit: Some("e".to_owned()),
},
json!(0.0),
"Total charge for the charge equilibration",
"Charges",
))?,
other => {
return Err(crate::Error::InvalidInput(format!(
"unknown parameter preset {other:?}; expected one of {PRESET_NAMES:?}"
)));
}
};
Ok(set)
}
/// Every built-in set with its name, in [`PRESET_NAMES`] order.
///
/// # Errors
///
/// Returns the errors of [`preset`].
pub fn presets() -> Result<Vec<(&'static str, ParamSet)>, crate::Error> {
PRESET_NAMES
.iter()
.map(|name| preset(name).map(|set| (*name, set)))
.collect()
}