-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathpython.rs
More file actions
155 lines (143 loc) · 4.59 KB
/
python.rs
File metadata and controls
155 lines (143 loc) · 4.59 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
use super::parameters::{NoRecord, UVBinaryRecord, UVParameters, UVRecord};
use super::{Perturbation, VirialOrder};
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;
/// Create a set of UV Theory parameters from records.
#[pyclass(name = "NoRecord")]
#[derive(Clone)]
struct PyNoRecord(NoRecord);
/// Create a set of UV Theory parameters from records.
#[pyclass(name = "UVRecord")]
#[pyo3(text_signature = "(rep, att, sigma, epsilon_k)")]
#[derive(Clone)]
pub struct PyUVRecord(UVRecord);
#[pymethods]
impl PyUVRecord {
#[new]
fn new(rep: f64, att: f64, sigma: f64, epsilon_k: f64) -> Self {
Self(UVRecord::new(rep, att, sigma, epsilon_k))
}
fn __repr__(&self) -> PyResult<String> {
Ok(self.0.to_string())
}
}
impl_json_handling!(PyUVRecord);
#[pyclass(name = "UVBinaryRecord")]
#[derive(Clone)]
pub struct PyUVBinaryRecord(UVBinaryRecord);
impl_binary_record!(UVBinaryRecord, PyUVBinaryRecord);
/// Create a set of UV Theory parameters from records.
///
/// Parameters
/// ----------
/// pure_records : List[PureRecord]
/// pure substance records.
/// binary_records : List[BinarySubstanceRecord], optional
/// binary parameter records
/// substances : List[str], optional
/// The substances to use. Filters substances from `pure_records` according to
/// `search_option`.
/// When not provided, all entries of `pure_records` are used.
/// search_option : IdentifierOption, optional, defaults to IdentifierOption.Name
/// Identifier that is used to search binary records.
#[pyclass(name = "UVParameters")]
#[pyo3(text_signature = "(pure_records, binary_records, substances, search_option)")]
#[derive(Clone)]
pub struct PyUVParameters(pub Arc<UVParameters>);
#[pymethods]
impl PyUVParameters {
/// 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
/// -------
/// UVParameters
#[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>,
) -> 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 = UVRecord::new(rep[i], att[i], sigma[i], epsilon_k[i]);
PureRecord::new(identifier, 1.0, model_record)
})
.collect();
Ok(Self(Arc::new(UVParameters::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
/// -------
/// UVParameters
///
/// # 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(UVParameters::new_simple(
rep, att, sigma, epsilon_k,
)?)))
}
}
impl_pure_record!(UVRecord, PyUVRecord);
impl_parameter!(UVParameters, PyUVParameters, PyUVRecord, PyUVBinaryRecord);
#[pymodule]
pub fn uvtheory(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_class::<PyIdentifier>()?;
m.add_class::<IdentifierOption>()?;
m.add_class::<PyChemicalRecord>()?;
m.add_class::<Perturbation>()?;
m.add_class::<VirialOrder>()?;
m.add_class::<PyUVRecord>()?;
m.add_class::<PyPureRecord>()?;
m.add_class::<PyBinaryRecord>()?;
m.add_class::<PyUVParameters>()?;
Ok(())
}