-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathpython.rs
More file actions
230 lines (208 loc) · 5.88 KB
/
Copy pathpython.rs
File metadata and controls
230 lines (208 loc) · 5.88 KB
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
use super::parameters::{QuantumCorrection, UVCSBinaryRecord, UVCSParameters, UVCSRecord};
use feos_core::parameter::{
BinaryRecord, Identifier, IdentifierOption, Parameter, ParameterError, PureRecord,
};
use feos_core::python::parameter::*;
use feos_core::*;
use numpy::{PyArray2, PyReadonlyArray2, ToPyArray};
use pyo3::exceptions::PyTypeError;
use pyo3::prelude::*;
use std::convert::{TryFrom, TryInto};
use std::sync::Arc;
#[pyclass(name = "QuantumCorrection")]
#[derive(Clone)]
pub struct PyQuantumCorrection(QuantumCorrection);
#[pymethods]
impl PyQuantumCorrection {
#[staticmethod]
#[pyo3(signature = (c_sigma=None, c_epsilon_k=None, c_rep=None))]
fn feynman_hibbs1(
c_sigma: Option<[f64; 3]>,
c_epsilon_k: Option<[f64; 3]>,
c_rep: Option<[f64; 5]>,
) -> Self {
Self(QuantumCorrection::FeynmanHibbs1 {
c_sigma,
c_epsilon_k,
c_rep,
})
}
}
/// Create a set of UV Theory parameters from records.
#[pyclass(name = "UVCSRecord")]
#[derive(Clone)]
pub struct PyUVCSRecord(UVCSRecord);
#[pymethods]
impl PyUVCSRecord {
#[new]
#[pyo3(signature = (rep, att, sigma, epsilon_k, quantum_correction=None))]
fn new(
rep: f64,
att: f64,
sigma: f64,
epsilon_k: f64,
quantum_correction: Option<PyQuantumCorrection>,
) -> Self {
Self(UVCSRecord::new(
rep,
att,
sigma,
epsilon_k,
quantum_correction.map(|qc| qc.0),
))
}
fn __repr__(&self) -> PyResult<String> {
Ok(self.0.to_string())
}
#[getter]
fn get_quantum_correction(&self) -> Option<PyQuantumCorrection> {
if let Some(qc) = self.0.quantum_correction.as_ref() {
Some(PyQuantumCorrection(qc.clone()))
} else {
None
}
}
}
/// Create a binary record from k_ij and l_ij values.
#[pyclass(name = "UVCSBinaryRecord")]
#[derive(Clone)]
pub struct PyUVCSBinaryRecord(UVCSBinaryRecord);
#[pymethods]
impl PyUVCSBinaryRecord {
#[new]
#[pyo3(text_signature = "(k_ij, l_ij)")]
fn new(k_ij: f64, l_ij: f64) -> Self {
Self(UVCSBinaryRecord { k_ij, l_ij })
}
#[getter]
fn get_k_ij(&self) -> f64 {
self.0.k_ij
}
#[getter]
fn get_l_ij(&self) -> f64 {
self.0.l_ij
}
#[setter]
fn set_k_ij(&mut self, k_ij: f64) {
self.0.k_ij = k_ij
}
#[setter]
fn set_l_ij(&mut self, l_ij: f64) {
self.0.l_ij = l_ij
}
}
impl_json_handling!(PyUVCSRecord);
impl_binary_record!(UVCSBinaryRecord, PyUVCSBinaryRecord);
#[pyclass(name = "UVCSParameters")]
#[derive(Clone)]
pub struct PyUVCSParameters(pub Arc<UVCSParameters>);
#[pymethods]
impl PyUVCSParameters {
/// Create a set of UV Theory parameters from lists.
///
/// Parameters
/// ----------
/// rep : List[float]
/// repulsive exponents
/// att : List[float]
/// attractive exponents
/// sigma : List[float]
/// Mie diameter in units of Angstrom
/// epsilon_k : List[float]
/// Mie energy parameter in units of Kelvin
///
/// Returns
/// -------
/// UVCSParameters
#[pyo3(text_signature = "(rep, att, sigma, epsilon_k)")]
#[staticmethod]
fn from_lists(
rep: Vec<f64>,
att: Vec<f64>,
sigma: Vec<f64>,
epsilon_k: Vec<f64>,
quantum_correction: Vec<Option<PyQuantumCorrection>>,
) -> PyResult<Self> {
let n = rep.len();
let pure_records = (0..n)
.map(|i| {
let identifier = Identifier::new(
Some(format!("{}", i).as_str()),
None,
None,
None,
None,
None,
);
let model_record = UVCSRecord::new(
rep[i],
att[i],
sigma[i],
epsilon_k[i],
quantum_correction[i].as_ref().map(|qc| qc.0.clone()),
);
PureRecord::new(identifier, 1.0, model_record)
})
.collect();
Ok(Self(Arc::new(UVCSParameters::from_records(
pure_records,
None,
)?)))
}
/// Create UV Theory parameters for pure substance.
///
/// Parameters
/// ----------
/// rep : float
/// repulsive exponents
/// att : float
/// attractive exponents
/// sigma : float
/// Mie diameter in units of Angstrom
/// epsilon_k : float
/// Mie energy parameter in units of Kelvin
///
/// Returns
/// -------
/// UVCSParameters
///
/// # Info
///
/// Molar weight is one. No ideal gas contribution is considered.
#[pyo3(text_signature = "(rep, att, sigma, epsilon_k)")]
#[staticmethod]
fn new_simple(rep: f64, att: f64, sigma: f64, epsilon_k: f64) -> PyResult<Self> {
Ok(Self(Arc::new(UVCSParameters::new_simple(
rep, att, sigma, epsilon_k,
)?)))
}
/// Print effective parameters
fn print_effective_parameters(&self, temperature: f64) -> String {
self.0.print_effective_parameters(temperature)
}
fn _repr_markdown_(&self) -> String {
self.0.to_markdown()
}
fn __repr__(&self) -> PyResult<String> {
Ok(self.0.to_string())
}
}
impl_pure_record!(UVCSRecord, PyUVCSRecord);
impl_parameter!(
UVCSParameters,
PyUVCSParameters,
PyUVCSRecord,
PyUVCSBinaryRecord
);
#[pymodule]
pub fn uvcstheory(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<PyIdentifier>()?;
m.add_class::<IdentifierOption>()?;
m.add_class::<PyQuantumCorrection>()?;
m.add_class::<PyUVCSRecord>()?;
m.add_class::<PyUVCSBinaryRecord>()?;
m.add_class::<PyPureRecord>()?;
m.add_class::<PyBinaryRecord>()?;
m.add_class::<PyUVCSParameters>()?;
Ok(())
}