This repository was archived by the owner on Sep 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpython.rs
More file actions
187 lines (163 loc) · 4.58 KB
/
python.rs
File metadata and controls
187 lines (163 loc) · 4.58 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
use crate::eos::polar::DQVariants;
use crate::parameters::{PcSaftParameters, PcSaftRecord};
use feos_core::joback::JobackRecord;
use feos_core::parameter::{
BinaryRecord, IdentifierOption, Parameter, ParameterError, PureRecord, SegmentRecord,
};
use feos_core::python::joback::PyJobackRecord;
use feos_core::python::parameter::{PyBinarySegmentRecord, PyChemicalRecord, PyIdentifier};
use feos_core::*;
use numpy::{PyArray2, ToPyArray};
use pyo3::prelude::*;
use std::convert::TryFrom;
use std::rc::Rc;
impl From<&str> for DQVariants {
fn from(str: &str) -> Self {
match str {
"dq35" => Self::DQ35,
"dq44" => Self::DQ44,
_ => panic!("dq_variant must be either \"dq35\" or \"dq44\""),
}
}
}
/// Create a set of PC-Saft parameters from records.
#[pyclass(name = "PcSaftRecord", unsendable)]
#[pyo3(
text_signature = "(m, sigma, epsilon_k, mu=None, q=None, kappa_ab=None, epsilon_k_ab=None, na=None, nb=None, viscosity=None, diffusion=None, thermal_conductivity=None)"
)]
#[derive(Clone)]
pub struct PyPcSaftRecord(PcSaftRecord);
#[pymethods]
impl PyPcSaftRecord {
#[new]
fn new(
m: f64,
sigma: f64,
epsilon_k: f64,
mu: Option<f64>,
q: Option<f64>,
kappa_ab: Option<f64>,
epsilon_k_ab: Option<f64>,
na: Option<f64>,
nb: Option<f64>,
viscosity: Option<[f64; 4]>,
diffusion: Option<[f64; 5]>,
thermal_conductivity: Option<[f64; 4]>,
) -> Self {
Self(PcSaftRecord::new(
m,
sigma,
epsilon_k,
mu,
q,
kappa_ab,
epsilon_k_ab,
na,
nb,
viscosity,
diffusion,
thermal_conductivity,
))
}
#[getter]
fn get_m(&self) -> f64 {
self.0.m
}
#[getter]
fn get_sigma(&self) -> f64 {
self.0.sigma
}
#[getter]
fn get_epsilon_k(&self) -> f64 {
self.0.epsilon_k
}
#[getter]
fn get_mu(&self) -> Option<f64> {
self.0.mu
}
#[getter]
fn get_q(&self) -> Option<f64> {
self.0.q
}
#[getter]
fn get_kappa_ab(&self) -> Option<f64> {
self.0.kappa_ab
}
#[getter]
fn get_epsilon_k_ab(&self) -> Option<f64> {
self.0.epsilon_k_ab
}
#[getter]
fn get_na(&self) -> Option<f64> {
self.0.na
}
#[getter]
fn get_nb(&self) -> Option<f64> {
self.0.nb
}
#[getter]
fn get_viscosity(&self) -> Option<[f64; 4]> {
self.0.viscosity
}
#[getter]
fn get_diffusion(&self) -> Option<[f64; 5]> {
self.0.diffusion
}
#[getter]
fn get_thermal_conductivity(&self) -> Option<[f64; 4]> {
self.0.thermal_conductivity
}
fn __repr__(&self) -> PyResult<String> {
Ok(self.0.to_string())
}
}
impl_json_handling!(PyPcSaftRecord);
impl_pure_record!(PcSaftRecord, PyPcSaftRecord, JobackRecord, PyJobackRecord);
impl_segment_record!(PcSaftRecord, PyPcSaftRecord, JobackRecord, PyJobackRecord);
/// Create a set of PC-SAFT parameters from records.
///
/// Parameters
/// ----------
/// pure_records : List[PureRecord]
/// pure substance records.
/// binary_records : List[BinaryRecord], optional
/// binary saft 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 : {'Name', 'Cas', 'Inchi', 'IupacName', 'Formula', 'Smiles'}, optional, defaults to 'Name'.
/// Identifier that is used to search substance.
///
/// Returns
/// -------
/// PcSaftParameters
#[pyclass(name = "PcSaftParameters", unsendable)]
#[pyo3(
text_signature = "(pure_records, binary_records=None, substances=None, search_option='Name')"
)]
#[derive(Clone)]
pub struct PyPcSaftParameters(pub Rc<PcSaftParameters>);
impl_parameter!(PcSaftParameters, PyPcSaftParameters);
impl_parameter_from_segments!(PcSaftParameters, PyPcSaftParameters);
#[pymethods]
impl PyPcSaftParameters {
#[getter]
fn get_pure_records(&self) -> Vec<PyPureRecord> {
self.0
.pure_records
.iter()
.map(|r| PyPureRecord(r.clone()))
.collect()
}
#[getter]
fn get_k_ij<'py>(&self, py: Python<'py>) -> &'py PyArray2<f64> {
self.0.k_ij.view().to_pyarray(py)
}
fn _repr_markdown_(&self) -> String {
self.0.to_markdown()
}
fn __repr__(&self) -> PyResult<String> {
Ok(self.0.to_string())
}
}