-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathdft.rs
More file actions
239 lines (222 loc) · 7.64 KB
/
dft.rs
File metadata and controls
239 lines (222 loc) · 7.64 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
231
232
233
234
235
236
237
238
239
use crate::dft::FunctionalVariant;
#[cfg(feature = "estimator")]
use crate::estimator::*;
#[cfg(feature = "gc_pcsaft")]
use crate::gc_pcsaft::python::PyGcPcSaftFunctionalParameters;
#[cfg(feature = "gc_pcsaft")]
use crate::gc_pcsaft::{GcPcSaftFunctional, GcPcSaftOptions};
use crate::hard_sphere::{FMTFunctional, FMTVersion};
#[cfg(feature = "estimator")]
use crate::impl_estimator;
#[cfg(feature = "pcsaft")]
use crate::pcsaft::python::PyPcSaftParameters;
#[cfg(feature = "pcsaft")]
use crate::pcsaft::{DQVariants, PcSaftFunctional, PcSaftOptions};
#[cfg(feature = "pets")]
use crate::pets::python::PyPetsParameters;
#[cfg(feature = "pets")]
use crate::pets::{PetsFunctional, PetsOptions};
use feos_core::*;
use feos_dft::adsorption::*;
use feos_dft::interface::*;
use feos_dft::python::*;
use feos_dft::solvation::*;
use feos_dft::*;
use numpy::convert::ToPyArray;
use numpy::{PyArray1, PyArray2, PyArray4};
use pyo3::exceptions::{PyIndexError, PyValueError};
use pyo3::prelude::*;
#[cfg(feature = "estimator")]
use pyo3::wrap_pymodule;
use quantity::python::*;
use quantity::si::*;
use std::collections::HashMap;
use std::sync::Arc;
#[pyclass(name = "HelmholtzEnergyFunctional")]
#[derive(Clone)]
pub struct PyFunctionalVariant(pub Arc<DFT<FunctionalVariant>>);
#[pymethods]
impl PyFunctionalVariant {
/// PC-SAFT Helmholtz energy functional.
///
/// Parameters
/// ----------
/// parameters: PcSaftParameters
/// The set of PC-SAFT parameters.
/// fmt_version: FMTVersion, optional
/// The specific variant of the FMT term. Defaults to FMTVersion.WhiteBear
/// max_eta : float, optional
/// Maximum packing fraction. Defaults to 0.5.
/// max_iter_cross_assoc : unsigned integer, optional
/// Maximum number of iterations for cross association. Defaults to 50.
/// tol_cross_assoc : float
/// Tolerance for convergence of cross association. Defaults to 1e-10.
/// dq_variant : DQVariants, optional
/// Combination rule used in the dipole/quadrupole term. Defaults to 'DQVariants.DQ35'
///
/// Returns
/// -------
/// Functional
#[cfg(feature = "pcsaft")]
#[args(
fmt_version = "FMTVersion::WhiteBear",
max_eta = "0.5",
max_iter_cross_assoc = "50",
tol_cross_assoc = "1e-10",
dq_variant = "DQVariants::DQ35"
)]
#[staticmethod]
#[pyo3(
text_signature = "(parameters, fmt_version, max_eta, max_iter_cross_assoc, tol_cross_assoc, dq_variant)"
)]
fn pcsaft(
parameters: PyPcSaftParameters,
fmt_version: FMTVersion,
max_eta: f64,
max_iter_cross_assoc: usize,
tol_cross_assoc: f64,
dq_variant: DQVariants,
) -> Self {
let options = PcSaftOptions {
max_eta,
max_iter_cross_assoc,
tol_cross_assoc,
dq_variant,
};
Self(Arc::new(
PcSaftFunctional::with_options(parameters.0, fmt_version, options).into(),
))
}
/// (heterosegmented) group contribution PC-SAFT Helmholtz energy functional.
///
/// Parameters
/// ----------
/// parameters: GcPcSaftFunctionalParameters
/// The set of PC-SAFT parameters.
/// fmt_version: FMTVersion, optional
/// The specific variant of the FMT term. Defaults to FMTVersion.WhiteBear
/// max_eta : float, optional
/// Maximum packing fraction. Defaults to 0.5.
/// max_iter_cross_assoc : unsigned integer, optional
/// Maximum number of iterations for cross association. Defaults to 50.
/// tol_cross_assoc : float
/// Tolerance for convergence of cross association. Defaults to 1e-10.
///
/// Returns
/// -------
/// Functional
#[cfg(feature = "gc_pcsaft")]
#[args(
fmt_version = "FMTVersion::WhiteBear",
max_eta = "0.5",
max_iter_cross_assoc = "50",
tol_cross_assoc = "1e-10"
)]
#[staticmethod]
#[pyo3(
text_signature = "(parameters, fmt_version, max_eta, max_iter_cross_assoc, tol_cross_assoc)"
)]
fn gc_pcsaft(
parameters: PyGcPcSaftFunctionalParameters,
fmt_version: FMTVersion,
max_eta: f64,
max_iter_cross_assoc: usize,
tol_cross_assoc: f64,
) -> Self {
let options = GcPcSaftOptions {
max_eta,
max_iter_cross_assoc,
tol_cross_assoc,
};
Self(Arc::new(
GcPcSaftFunctional::with_options(parameters.0, fmt_version, options).into(),
))
}
/// PeTS Helmholtz energy functional without simplifications
/// for pure components.
///
/// Parameters
/// ----------
/// parameters: PetsParameters
/// The set of PeTS parameters.
/// fmt_version: FMTVersion, optional
/// The specific variant of the FMT term. Defaults to FMTVersion.WhiteBear
/// max_eta : float, optional
/// Maximum packing fraction. Defaults to 0.5.
///
/// Returns
/// -------
/// Functional
#[cfg(feature = "pets")]
#[args(fmt_version = "FMTVersion::WhiteBear", max_eta = "0.5")]
#[staticmethod]
#[pyo3(text_signature = "(parameters, fmt_version, max_eta)")]
fn pets(parameters: PyPetsParameters, fmt_version: FMTVersion, max_eta: f64) -> Self {
let options = PetsOptions { max_eta };
Self(Arc::new(
PetsFunctional::with_options(parameters.0, fmt_version, options).into(),
))
}
/// Helmholtz energy functional for hard sphere systems.
///
/// Parameters
/// ----------
/// sigma : numpy.ndarray[float]
/// The diameters of the hard spheres in Angstrom.
/// fmt_version : FMTVersion
/// The specific variant of the FMT term.
///
/// Returns
/// -------
/// Functional
#[staticmethod]
#[pyo3(text_signature = "(sigma, version)")]
fn fmt(sigma: &PyArray1<f64>, fmt_version: FMTVersion) -> Self {
Self(Arc::new(
FMTFunctional::new(&sigma.to_owned_array(), fmt_version).into(),
))
}
}
impl_equation_of_state!(PyFunctionalVariant);
impl_state!(DFT<FunctionalVariant>, PyFunctionalVariant);
impl_state_molarweight!(DFT<FunctionalVariant>, PyFunctionalVariant);
impl_phase_equilibrium!(DFT<FunctionalVariant>, PyFunctionalVariant);
impl_planar_interface!(FunctionalVariant);
impl_surface_tension_diagram!(FunctionalVariant);
impl_pore!(FunctionalVariant, PyFunctionalVariant);
impl_adsorption!(FunctionalVariant, PyFunctionalVariant);
impl_pair_correlation!(FunctionalVariant);
impl_solvation_profile!(FunctionalVariant);
#[cfg(feature = "estimator")]
impl_estimator!(DFT<FunctionalVariant>, PyFunctionalVariant);
#[pymodule]
pub fn dft(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_class::<Contributions>()?;
m.add_class::<Verbosity>()?;
m.add_class::<PyFunctionalVariant>()?;
m.add_class::<PyState>()?;
m.add_class::<PyPhaseDiagram>()?;
m.add_class::<PyPhaseEquilibrium>()?;
m.add_class::<FMTVersion>()?;
m.add_class::<PyPlanarInterface>()?;
m.add_class::<Geometry>()?;
m.add_class::<PyPore1D>()?;
m.add_class::<PyPore3D>()?;
m.add_class::<PyPairCorrelation>()?;
m.add_class::<PyExternalPotential>()?;
m.add_class::<PyAdsorption1D>()?;
m.add_class::<PyAdsorption3D>()?;
m.add_class::<PySurfaceTensionDiagram>()?;
m.add_class::<PyDFTSolver>()?;
m.add_class::<PySolvationProfile>()?;
#[cfg(feature = "estimator")]
m.add_wrapped(wrap_pymodule!(estimator_dft))?;
Ok(())
}
#[cfg(feature = "estimator")]
#[pymodule]
pub fn estimator_dft(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_class::<PyDataSet>()?;
m.add_class::<PyEstimator>()?;
m.add_class::<PyLoss>()
}