Skip to content

Refactoring #270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lumol-core/src/energy/computations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl TableComputation {
/// assert_eq!(table.energy(1.0), 0.525);
/// assert_eq!(table.energy(3.0), 0.0);
/// ```
pub fn new(potential: Box<dyn PairPotential>, size: usize, max: f64) -> TableComputation {
pub fn new(potential: Box<dyn PairPotential>, size: usize, max: f64) -> Self {
let delta = max / (size as f64);
let mut energy_table = Vec::with_capacity(size);
let mut force_table = Vec::with_capacity(size);
Expand All @@ -109,12 +109,12 @@ impl TableComputation {
force_table.push(potential.force(r));
}

TableComputation {
delta: delta,
Self {
delta,
cutoff: max,
energy_table: energy_table,
force_table: force_table,
potential: potential,
energy_table,
force_table,
potential,
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions lumol-core/src/energy/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ pub struct CosineHarmonic {
impl CosineHarmonic {
/// Create a new `CosineHarmonic` potentials, with elastic constant of `k`
/// and equilibrium value of `x0`
pub fn new(k: f64, x0: f64) -> CosineHarmonic {
CosineHarmonic {
k: k,
pub fn new(k: f64, x0: f64) -> Self {
Self {
k,
cos_x0: f64::cos(x0),
}
}
Expand Down Expand Up @@ -465,9 +465,9 @@ pub struct Gaussian {

impl Gaussian {
/// Create a new `Gaussian` potential with a depth of `a` and a width of `b`
pub fn new(a: f64, b: f64) -> Gaussian {
pub fn new(a: f64, b: f64) -> Self {
assert!(b > 0.0, "\"b\" has to be positive in Gaussian potential");
Gaussian { a: a, b: b }
Self { a, b }
}
}

Expand Down Expand Up @@ -537,14 +537,14 @@ pub struct Mie {

impl Mie {
/// Return Mie potential.
pub fn new(sigma: f64, epsilon: f64, n: f64, m: f64) -> Mie {
pub fn new(sigma: f64, epsilon: f64, n: f64, m: f64) -> Self {
assert!(m < n, "The repulsive exponent n has to be larger than the attractive exponent m");
let prefac = n / (n - m) * (n / m).powf(m / (n - m)) * epsilon;
Mie {
sigma: sigma,
n: n,
m: m,
prefac: prefac,
Self {
sigma,
n,
m,
prefac,
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions lumol-core/src/energy/global/ewald.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Ewald3DArray {
let i = (range.end + offset) as usize;
Ewald3DArray {
data: Array3::zeros((i, j, k)),
offset: offset
offset
}
}

Expand Down Expand Up @@ -250,8 +250,8 @@ pub struct Ewald {
}

impl Clone for Ewald {
fn clone(&self) -> Ewald {
Ewald {
fn clone(&self) -> Self {
Self {
parameters: self.parameters.clone(),
factors: self.factors.clone(),
restriction: self.restriction,
Expand All @@ -275,7 +275,7 @@ impl Ewald {
/// Create an Ewald summation using the given `cutoff` radius in real space,
/// and `kmax` points in k-space (Fourier space). If `alpha` is None, then
/// the default value of `π / cutoff` is used.
pub fn new<I: Into<Option<f64>>>(cutoff: f64, kmax: usize, alpha: I) -> Ewald {
pub fn new<I: Into<Option<f64>>>(cutoff: f64, kmax: usize, alpha: I) -> Self {
let alpha = alpha.into().unwrap_or(PI / cutoff);
if cutoff < 0.0 {
panic!("the cutoff can not be negative in Ewald");
Expand All @@ -286,14 +286,14 @@ impl Ewald {
}

let parameters = EwaldParameters {
alpha: alpha,
alpha,
rc: cutoff,
kmax: kmax as isize,
kmax2: 0.0,
};

Ewald {
parameters: parameters,
Self {
parameters,
restriction: PairRestriction::None,
factors: EwaldFactorVec::new(),
eikr: Ewald3DArray::zeros((0..0, 0, 0)),
Expand Down Expand Up @@ -855,8 +855,8 @@ impl SharedEwald {
/// let ewald = SharedEwald::new(Ewald::new(12.5, 10, None));
/// let boxed: Box<dyn CoulombicPotential> = Box::new(ewald);
/// ```
pub fn new(ewald: Ewald) -> SharedEwald {
SharedEwald(RwLock::new(ewald))
pub fn new(ewald: Ewald) -> Self {
Self(RwLock::new(ewald))
}

/// Get read access to the underlying Ewald solver
Expand Down
12 changes: 6 additions & 6 deletions lumol-core/src/energy/global/wolf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub struct Wolf {

impl Wolf {
/// Create a new Wolf summation, using a real-space cutoff of `cutoff`.
pub fn new(cutoff: f64) -> Wolf {
pub fn new(cutoff: f64) -> Self {
assert!(cutoff > 0.0, "Got a negative cutoff in Wolf summation");
let alpha = PI / cutoff;

Expand All @@ -74,11 +74,11 @@ impl Wolf {

let energy_constant = erfc(alpha_cutoff) / cutoff;
let force_constant = erfc(alpha_cutoff) / (cutoff * cutoff) + FRAC_2_SQRT_PI * alpha * f64::exp(-alpha_cutoff_2) / cutoff;
Wolf {
alpha: alpha,
cutoff: cutoff,
energy_constant: energy_constant,
force_constant: force_constant,
Self {
alpha,
cutoff,
energy_constant,
force_constant,
restriction: PairRestriction::None,
}
}
Expand Down
16 changes: 8 additions & 8 deletions lumol-core/src/energy/pairs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ impl PairInteraction {
/// // energy at and after the cutoff is zero
/// assert_eq!(interaction.energy(2.0), 0.0);
/// ```
pub fn new(potential: Box<dyn PairPotential>, cutoff: f64) -> PairInteraction {
PairInteraction {
potential: potential,
cutoff: cutoff,
pub fn new(potential: Box<dyn PairPotential>, cutoff: f64) -> Self {
Self {
potential,
cutoff,
restriction: PairRestriction::None,
computation: PairComputation::Cutoff,
tail: false,
Expand All @@ -83,11 +83,11 @@ impl PairInteraction {
/// // energy after the cutoff is zero
/// assert_eq!(interaction.energy(2.0), 0.0);
/// ```
pub fn shifted(potential: Box<dyn PairPotential>, cutoff: f64) -> PairInteraction {
pub fn shifted(potential: Box<dyn PairPotential>, cutoff: f64) -> Self {
let shift = potential.energy(cutoff);
PairInteraction {
potential: potential,
cutoff: cutoff,
Self {
potential,
cutoff,
restriction: PairRestriction::None,
computation: PairComputation::Shifted(shift),
tail: false,
Expand Down
22 changes: 11 additions & 11 deletions lumol-core/src/energy/restrictions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ impl PairRestriction {
pub fn information(&self, path: BondPath) -> RestrictionInfo {
let are_in_same_molecule = path != BondPath::None;
let excluded = match *self {
PairRestriction::None => false,
PairRestriction::InterMolecular => are_in_same_molecule,
PairRestriction::IntraMolecular => !are_in_same_molecule,
PairRestriction::Exclude12 => path == BondPath::OneBond,
PairRestriction::Exclude13 | PairRestriction::Scale14(..) => {
path == BondPath::OneBond || path == BondPath::TwoBonds
Self::None => false,
Self::InterMolecular => are_in_same_molecule,
Self::IntraMolecular => !are_in_same_molecule,
Self::Exclude12 => path == BondPath::OneBond,
Self::Exclude13 | Self::Scale14(..) => {
matches!(path, BondPath::OneBond | BondPath::TwoBonds)
}
PairRestriction::Exclude14 => {
path == BondPath::OneBond || path == BondPath::TwoBonds || path == BondPath::ThreeBonds
Self::Exclude14 => {
matches!(path, BondPath::OneBond | BondPath::TwoBonds | BondPath::ThreeBonds)
},
};

let scaling = if let PairRestriction::Scale14(scaling) = *self {
let scaling = if let Self::Scale14(scaling) = *self {
if path == BondPath::ThreeBonds {
scaling
} else {
Expand All @@ -108,8 +108,8 @@ impl PairRestriction {
};

RestrictionInfo {
excluded: excluded,
scaling: scaling,
excluded,
scaling,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lumol-core/src/sys/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ pub struct EnergyCache {

impl EnergyCache {
/// Create a new empty energy cache.
pub fn new() -> EnergyCache {
EnergyCache {
pub fn new() -> Self {
Self {
pairs_cache: Array2::zeros((0, 0)),
pairs: 0.0,
pairs_tail: 0.0,
Expand Down
18 changes: 9 additions & 9 deletions lumol-core/src/sys/chfl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ impl<'a> TrajectoryBuilder<'a> {
/// .open("file.xyz")
/// .unwrap();
/// ```
pub fn new() -> TrajectoryBuilder<'a> {
TrajectoryBuilder {
pub fn new() -> Self {
Self {
mode: OpenMode::Read,
format: "",
}
Expand All @@ -227,9 +227,9 @@ impl<'a> TrajectoryBuilder<'a> {
/// .open("file.mol")
/// .unwrap();
/// ```
pub fn format(self, format: &'a str) -> TrajectoryBuilder<'a> {
TrajectoryBuilder {
format: format,
pub fn format(self, format: &'a str) -> Self {
Self {
format,
mode: self.mode,
}
}
Expand All @@ -245,9 +245,9 @@ impl<'a> TrajectoryBuilder<'a> {
/// .open("file.nc")
/// .unwrap();
/// ```
pub fn mode(self, mode: OpenMode) -> TrajectoryBuilder<'a> {
TrajectoryBuilder {
mode: mode,
pub fn mode(self, mode: OpenMode) -> Self {
Self {
mode,
format: self.format,
}
}
Expand All @@ -270,7 +270,7 @@ impl<'a> TrajectoryBuilder<'a> {
OpenMode::Append => 'a',
};
let trajectory = chemfiles::Trajectory::open_with_format(path, mode, self.format)?;
return Ok(Trajectory(trajectory));
Ok(Trajectory(trajectory))
}
}

Expand Down
8 changes: 4 additions & 4 deletions lumol-core/src/sys/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ mod test {
// Direct computation
let expected = natoms * K_BOLTZMANN * temperature / volume + virial / (3.0 * volume);
let pressure = PressureAtTemperature {
temperature: temperature,
temperature,
};
let pressure = pressure.compute(system);
assert_ulps_eq!(pressure, expected);
Expand All @@ -703,7 +703,7 @@ mod test {

// Computation with an external temperature for the system
let pressure = PressureAtTemperature {
temperature: temperature,
temperature,
};
let pressure = pressure.compute(system);
system.simulated_temperature(Some(temperature));
Expand All @@ -730,11 +730,11 @@ mod test {
let system = &mut test_pairs_system();
let temperature = 550.0;
let stress = StressAtTemperature {
temperature: temperature,
temperature,
};
let stress = stress.compute(system);
let pressure = PressureAtTemperature {
temperature: temperature,
temperature,
};
let pressure = pressure.compute(system);

Expand Down
4 changes: 2 additions & 2 deletions lumol-core/src/sys/config/bonding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ pub struct Bonding {

impl Bonding {
/// Create a new `Bonding` containing only the atom i
pub fn new(i: usize) -> Bonding {
Bonding {
pub fn new(i: usize) -> Self {
Self {
bonds: HashSet::new(),
angles: HashSet::new(),
dihedrals: HashSet::new(),
Expand Down
28 changes: 14 additions & 14 deletions lumol-core/src/sys/config/cells.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,36 +40,36 @@ pub struct UnitCell {

impl UnitCell {
/// Create an infinite unit cell
pub fn infinite() -> UnitCell {
UnitCell {
pub fn infinite() -> Self {
Self {
cell: Matrix3::zero(),
inv: Matrix3::zero(),
shape: CellShape::Infinite,
}
}
/// Create an orthorhombic unit cell, with side lengths `a, b, c`.
pub fn ortho(a: f64, b: f64, c: f64) -> UnitCell {
pub fn ortho(a: f64, b: f64, c: f64) -> Self {
assert!(a > 0.0 && b > 0.0 && c > 0.0, "Cell lengths must be positive");
let cell = Matrix3::new([[a, 0.0, 0.0], [0.0, b, 0.0], [0.0, 0.0, c]]);
UnitCell {
cell: cell,
Self {
cell,
inv: cell.inverse(),
shape: CellShape::Orthorhombic,
}
}
/// Create a cubic unit cell, with side lengths `length, length, length`.
pub fn cubic(length: f64) -> UnitCell {
pub fn cubic(length: f64) -> Self {
assert!(length > 0.0, "Cell lengths must be positive");
let cell = Matrix3::new([[length, 0.0, 0.0], [0.0, length, 0.0], [0.0, 0.0, length]]);
UnitCell {
cell: cell,
Self {
cell,
inv: cell.inverse(),
shape: CellShape::Orthorhombic,
}
}
/// Create a triclinic unit cell, with side lengths `a, b, c` and angles
/// `alpha, beta, gamma`.
pub fn triclinic(a: f64, b: f64, c: f64, alpha: f64, beta: f64, gamma: f64) -> UnitCell {
pub fn triclinic(a: f64, b: f64, c: f64, alpha: f64, beta: f64, gamma: f64) -> Self {
assert!(a > 0.0 && b > 0.0 && c > 0.0, "Cell lengths must be positive");
let cos_alpha = alpha.to_radians().cos();
let cos_beta = beta.to_radians().cos();
Expand All @@ -84,8 +84,8 @@ impl UnitCell {

let cell = Matrix3::new([[a, b_x, c_x], [0.0, b_y, c_y], [0.0, 0.0, c_z]]);

UnitCell {
cell: cell,
Self {
cell,
inv: cell.inverse(),
shape: CellShape::Triclinic,
}
Expand Down Expand Up @@ -209,11 +209,11 @@ impl UnitCell {
/// Scale this unit cell by multiplying the cell matrix by `s`, and return a
/// new scaled unit cell
#[inline]
pub fn scale(&self, s: Matrix3) -> UnitCell {
pub fn scale(&self, s: Matrix3) -> Self {
assert!(self.shape() != CellShape::Infinite, "can not scale infinite cells");
let cell = s * self.cell;
UnitCell {
cell: cell,
Self {
cell,
inv: cell.inverse(),
shape: self.shape,
}
Expand Down
Loading