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 0
Expand file tree
/
Copy pathpython.rs
More file actions
93 lines (85 loc) · 3.11 KB
/
Copy pathpython.rs
File metadata and controls
93 lines (85 loc) · 3.11 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
use crate::parameters::{NoRecord, UVBinaryRecord, UVParameters, UVRecord};
use feos_core::parameter::{Identifier, IdentifierOption, Parameter, ParameterError, PureRecord};
use feos_core::python::parameter::PyIdentifier;
use feos_core::*;
use ndarray::Array2;
use numpy::PyArray2;
use pyo3::prelude::*;
use std::convert::TryFrom;
use std::rc::Rc;
/// Create a set of UV Theory parameters from records.
#[pyclass(name = "NoRecord", unsendable)]
#[derive(Clone)]
struct PyNoRecord(NoRecord);
/// Create a set of UV Theory parameters from records.
#[pyclass(name = "UVRecord", unsendable)]
#[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);
/// Create a set of UV Theory parameters from records.
///
/// Parameters
/// ----------
/// pure_records : List[PureRecord]
/// pure substance records.
/// binary_records : List[BinarySubstanceRecord], 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.
#[pyclass(name = "UVParameters", unsendable)]
#[pyo3(
text_signature = "(pure_records, binary_records=None, substances=None, search_option='Name')"
)]
#[derive(Clone)]
pub struct PyUVParameters(pub Rc<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>) -> Self {
let n = rep.len();
let pure_records = (0..n)
.map(|i| {
let identifier =
Identifier::new(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, None)
})
.collect();
let binary = Array2::from_shape_fn((n, n), |(_, _)| UVBinaryRecord { k_ij: 0.0 });
Self(Rc::new(UVParameters::from_records(pure_records, binary)))
}
}
impl_pure_record!(UVRecord, PyUVRecord, NoRecord, PyNoRecord);
impl_parameter!(UVParameters, PyUVParameters);