-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathexternal_potential.rs
More file actions
250 lines (241 loc) · 8.6 KB
/
external_potential.rs
File metadata and controls
250 lines (241 loc) · 8.6 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
240
241
242
243
244
245
246
247
248
249
250
use crate::adsorption::ExternalPotential;
use numpy::PyArray1;
use pyo3::prelude::*;
use quantity::python::{PySIArray2, PySINumber};
/// A collection of external potentials.
#[pyclass(name = "ExternalPotential")]
#[derive(Clone)]
pub struct PyExternalPotential(pub ExternalPotential);
#[pymethods]
#[allow(non_snake_case)]
impl PyExternalPotential {
/// Hard wall potential
///
/// .. math:: V_i^\mathrm{ext}(z)=\begin{cases}\infty&z\leq\sigma_{si}\\\\0&z>\sigma_{si}\end{cases},~~~~\sigma_{si}=\frac{1}{2}\left(\sigma_{ss}+\sigma_{ii}\right)
///
/// Parameters
/// ----------
/// sigma_ss : float
/// Segment diameter of the solid.
///
/// Returns
/// -------
/// ExternalPotential
///
#[staticmethod]
#[allow(non_snake_case)]
pub fn HardWall(sigma_ss: f64) -> Self {
Self(ExternalPotential::HardWall { sigma_ss })
}
/// 9-3 Lennard-Jones potential
///
/// .. math:: V_i^\mathrm{ext}(z)=\frac{2\pi}{45} m_i\varepsilon_{si}\sigma_{si}^3\rho_s\left(2\left(\frac{\sigma_{si}}{z}\right)^9-15\left(\frac{\sigma_{si}}{z}\right)^3\right),~~~~\varepsilon_{si}=\sqrt{\varepsilon_{ss}\varepsilon_{ii}},~~~~\sigma_{si}=\frac{1}{2}\left(\sigma_{ss}+\sigma_{ii}\right)
///
/// Parameters
/// ----------
/// sigma_ss : float
/// Segment diameter of the solid.
/// epsilon_k_ss : float
/// Energy parameter of the solid.
/// rho_s : float
/// Density of the solid.
///
/// Returns
/// -------
/// ExternalPotential
///
#[staticmethod]
pub fn LJ93(sigma_ss: f64, epsilon_k_ss: f64, rho_s: f64) -> Self {
Self(ExternalPotential::LJ93 {
sigma_ss,
epsilon_k_ss,
rho_s,
})
}
/// Simple 9-3 Lennard-Jones potential
///
/// .. math:: V_i^\mathrm{ext}(z)=\varepsilon_{si}\left(\left(\frac{\sigma_{si}}{z}\right)^9-\left(\frac{\sigma_{si}}{z}\right)^3\right),~~~~\varepsilon_{si}=\sqrt{\varepsilon_{ss}\varepsilon_{ii}},~~~~\sigma_{si}=\frac{1}{2}\left(\sigma_{ss}+\sigma_{ii}\right)
///
/// Parameters
/// ----------
/// sigma_ss : float
/// Segment diameter of the solid.
/// epsilon_k_ss : float
/// Energy parameter of the solid.
///
/// Returns
/// -------
/// ExternalPotential
///
#[staticmethod]
pub fn SimpleLJ93(sigma_ss: f64, epsilon_k_ss: f64) -> Self {
Self(ExternalPotential::SimpleLJ93 {
sigma_ss,
epsilon_k_ss,
})
}
/// Custom 9-3 Lennard-Jones potential
///
/// .. math:: V_i^\mathrm{ext}(z)=\varepsilon_{si}\left(\left(\frac{\sigma_{si}}{z}\right)^9-\left(\frac{\sigma_{si}}{z}\right)^3\right)
///
/// Parameters
/// ----------
/// sigma_sf : numpy.ndarray[float]
/// Solid-fluid interaction diameters.
/// epsilon_k_sf : numpy.ndarray[float]
/// Solid-fluid interaction energies.
///
/// Returns
/// -------
/// ExternalPotential
///
#[staticmethod]
pub fn CustomLJ93(sigma_sf: &PyArray1<f64>, epsilon_k_sf: &PyArray1<f64>) -> Self {
Self(ExternalPotential::CustomLJ93 {
sigma_sf: sigma_sf.to_owned_array(),
epsilon_k_sf: epsilon_k_sf.to_owned_array(),
})
}
/// Steele potential
///
/// .. math:: V_i^\mathrm{ext}(z)=2\pi m_i\xi\varepsilon_{si}\sigma_{si}^2\Delta\rho_s\left(0.4\left(\frac{\sigma_{si}}{z}\right)^{10}-\left(\frac{\sigma_{si}}{z}\right)^4-\frac{\sigma_{si}^4}{3\Delta\left(z+0.61\Delta\right)^3}\right),~~~~\varepsilon_{si}=\sqrt{\varepsilon_{ss}\varepsilon_{ii}},~~~~\sigma_{si}=\frac{1}{2}\left(\sigma_{ss}+\sigma_{ii}\right),~~~~\Delta=3.35
///
/// Parameters
/// ----------
/// sigma_ss : float
/// Segment diameter of the solid.
/// epsilon_k_ss : float
/// Energy parameter of the solid.
/// rho_s : float
/// Density of the solid.
/// xi : float, optional
/// Binary wall-fluid interaction parameter.
///
/// Returns
/// -------
/// ExternalPotential
///
#[staticmethod]
#[pyo3(text_signature = "(sigma_ss, epsilon_k_ss, rho_s, xi=None)")]
pub fn Steele(sigma_ss: f64, epsilon_k_ss: f64, rho_s: f64, xi: Option<f64>) -> Self {
Self(ExternalPotential::Steele {
sigma_ss,
epsilon_k_ss,
rho_s,
xi,
})
}
/// Steele potential with custom combining rules
///
/// .. math:: V_i^\mathrm{ext}(z)=2\pi m_i\xi\varepsilon_{si}\sigma_{si}^2\Delta\rho_s\left(0.4\left(\frac{\sigma_{si}}{z}\right)^{10}-\left(\frac{\sigma_{si}}{z}\right)^4-\frac{\sigma_{si}^4}{3\Delta\left(z+0.61\Delta\right)^3}\right),~~~~\Delta=3.35
///
/// Parameters
/// ----------
/// sigma_sf : numpy.ndarray[float]
/// Solid-fluid interaction diameters.
/// epsilon_k_sf : numpy.ndarray[float]
/// Solid-fluid interaction energies.
/// rho_s : float
/// Density of the solid.
/// xi : float, optional
/// Binary wall-fluid interaction parameter.
///
/// Returns
/// -------
/// ExternalPotential
///
#[staticmethod]
#[pyo3(text_signature = "(sigma_sf, epsilon_k_sf, rho_s, xi=None)")]
pub fn CustomSteele(
sigma_sf: &PyArray1<f64>,
epsilon_k_sf: &PyArray1<f64>,
rho_s: f64,
xi: Option<f64>,
) -> Self {
Self(ExternalPotential::CustomSteele {
sigma_sf: sigma_sf.to_owned_array(),
epsilon_k_sf: epsilon_k_sf.to_owned_array(),
rho_s,
xi,
})
}
/// Double well potential
///
/// .. math:: V_i^\mathrm{ext}(z)=\mathrm{min}\left(\frac{2\pi}{45} m_i\varepsilon_{2si}\sigma_{si}^3\rho_s\left(2\left(\frac{2\sigma_{si}}{z}\right)^9-15\left(\frac{2\sigma_{si}}{z}\right)^3\right),0\right)+\frac{2\pi}{45} m_i\varepsilon_{1si}\sigma_{si}^3\rho_s\left(2\left(\frac{\sigma_{si}}{z}\right)^9-15\left(\frac{\sigma_{si}}{z}\right)^3\right),~~~~\varepsilon_{1si}=\sqrt{\varepsilon_{1ss}\varepsilon_{ii}},~~~~\varepsilon_{2si}=\sqrt{\varepsilon_{2ss}\varepsilon_{ii}},~~~~\sigma_{si}=\frac{1}{2}\left(\sigma_{ss}+\sigma_{ii}\right)
///
/// Parameters
/// ----------
/// sigma_ss : float
/// Segment diameter of the solid.
/// epsilon1_k_ss : float
/// Energy parameter of the first well.
/// epsilon2_k_ss : float
/// Energy parameter of the second well.
/// rho_s : float
/// Density of the solid.
///
/// Returns
/// -------
/// ExternalPotential
///
#[staticmethod]
pub fn DoubleWell(sigma_ss: f64, epsilon1_k_ss: f64, epsilon2_k_ss: f64, rho_s: f64) -> Self {
Self(ExternalPotential::DoubleWell {
sigma_ss,
epsilon1_k_ss,
epsilon2_k_ss,
rho_s,
})
}
/// Free-energy averaged potential
///
/// for details see: `J. Eller, J. Gross (2021) <https://pubs.acs.org/doi/abs/10.1021/acs.langmuir.0c03287>`_
///
/// Parameters
/// ----------
/// coordinates: SIArray2
/// The positions of all interaction sites in the solid.
/// sigma_ss : numpy.ndarray[float]
/// The size parameters of all interaction sites.
/// epsilon_k_ss : numpy.ndarray[float]
/// The energy parameter of all interaction sites.
/// pore_center : [SINumber; 3]
/// The cartesian coordinates of the center of the pore
/// system_size : [SINumber; 3]
/// The size of the unit cell.
/// n_grid : [int; 2]
/// The number of grid points in each direction.
/// cutoff_radius : float, optional
/// The cutoff used in the calculation of fluid/wall interactions.
/// Returns
/// -------
/// ExternalPotential
///
#[staticmethod]
#[pyo3(
text_signature = "(coordinates, sigma_ss, epsilon_k_ss, pore_center, system_size, n_grid, cutoff_radius=None)"
)]
pub fn FreeEnergyAveraged(
coordinates: PySIArray2,
sigma_ss: &PyArray1<f64>,
epsilon_k_ss: &PyArray1<f64>,
pore_center: [f64; 3],
system_size: [PySINumber; 3],
n_grid: [usize; 2],
cutoff_radius: Option<f64>,
) -> PyResult<Self> {
Ok(Self(ExternalPotential::FreeEnergyAveraged {
coordinates: coordinates.try_into()?,
sigma_ss: sigma_ss.to_owned_array(),
epsilon_k_ss: epsilon_k_ss.to_owned_array(),
pore_center,
system_size: [
system_size[0].try_into()?,
system_size[1].try_into()?,
system_size[2].try_into()?,
],
n_grid,
cutoff_radius,
}))
}
}