Skip to content

Commit

Permalink
toml preserves order, consistent calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
2AUK committed Oct 15, 2023
1 parent dfd691c commit 7dcf5d7
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 39 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ edition = "2021"


[[bin]]
name = "pyrism"
src = "src/main.rs"
name = "rism"
path = "src/main.rs"

[lib]
# The name of the native library. This is the name which will be used in Python to import the
Expand Down Expand Up @@ -37,7 +37,7 @@ simple_logger = "4.2.0"
gnuplot = "0.0.39"
serde = { version = "1.0.189", features = ["derive"] }
bincode = "1.3.3"
toml = { version = "0.8.2", features = ["parse"] }
toml = { version = "0.8.2", features = ["parse", "preserve_order"] }
bzip2 = "0.4.4"
lexopt = "0.3.0"

Expand Down
8 changes: 4 additions & 4 deletions cSPCE_XRISM_methane.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ potential = "LJ"
closure = "HNC"
IE = "XRISM"
solver = "MDIIS"
depth = 12
depth = 8
picard_damping = 0.5
mdiis_damping = 0.5
itermax = 10000
Expand All @@ -31,17 +31,17 @@ nspu = 1
[solvent.water]
dens = 0.03334
ns = 3
"O" = [
O = [
[78.15, 3.1657, -0.8476000010975563],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00]
]

"H1" = [
H1 = [
[7.815, 1.1657, 0.4238],
[1.00000000e+00, 0.00000000e+00, 0.00000000e+00]
]

"H2" = [
H2 = [
[7.815, 1.1657, 0.4238],
[-3.33314000e-01, 9.42816000e-01, 0.00000000e+00]
]
Expand Down
2 changes: 1 addition & 1 deletion pyrism/rism_ctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def read_input(self):
rism_job = RISMDriver(
data_config, operator_config, potential_config, solver_config
)
vv = rism_job.execute()
vv = rism_job.do_rism()

print(vv)

Expand Down
112 changes: 84 additions & 28 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::data::{
SystemState,
};
use crate::dipole::*;
use crate::input::{Configuration, InputTOMLHandler};
use crate::integralequation::IntegralEquationKind;
use crate::operator::{Operator, OperatorConfig};
use crate::potential::{Potential, PotentialConfig};
Expand All @@ -17,6 +18,7 @@ use pyo3::prelude::*;
use std::f64::consts::PI;
use std::fs;
use std::io::prelude::*;
use std::path::PathBuf;

pub enum Verbosity {
Quiet,
Expand Down Expand Up @@ -98,7 +100,39 @@ impl RISMDriver {
})
}

pub fn execute<'py>(&'py mut self, py: Python<'py>) -> PyResult<Py<PyAny>> {
pub fn do_rism<'py>(&'py mut self, py: Python<'py>) {
// -> PyResult<Py<PyAny>> {
self.execute();
// Ok(PyCorrelations::new(
// uv.clone().unwrap().correlations.cr,
// uv.clone().unwrap().correlations.tr,
// uv.clone().unwrap().correlations.hr,
// gr_uv,
// py,
// )
// .into_py(py))
}

// pub fn extract<'py>(
// &'py self,
// py: Python<'py>,
// ) -> PyResult<(
// &PyArray3<f64>,
// &PyArray3<f64>,
// &PyArray3<f64>,
// &PyArray3<f64>,
// )> {
// Ok((
// self.data.cr.clone().into_pyarray(py),
// self.data.tr.clone().into_pyarray(py),
// self.data.hr.clone().into_pyarray(py),
// self.data.hk.clone().into_pyarray(py),
// ))
// }
}

impl RISMDriver {
pub fn execute(&mut self) {
self.print_header();
simple_logger::init_with_env().unwrap();
// set up operator(RISM equation and Closure)
Expand All @@ -109,6 +143,11 @@ impl RISMDriver {
..self.operator.clone()
});

println!(
"{:#?}\n\n{:#?}\n\n{:#?}\n\n{:#?}",
self.data, self.operator, self.solver, self.potential
);

let (mut vv, mut uv) = self.problem_setup();

let mut solver = self.solver.solver.set(&self.solver.settings);
Expand Down Expand Up @@ -155,36 +194,53 @@ impl RISMDriver {
let encoded_vv: Vec<u8> =
bincode::serialize(&vv_solution).expect("encode solvent-solvent results to binary");
let compressor = BzEncoder::new(encoded_vv.as_slice(), Compression::best());

Ok(PyCorrelations::new(
uv.clone().unwrap().correlations.cr,
uv.clone().unwrap().correlations.tr,
uv.clone().unwrap().correlations.hr,
gr_uv,
py,
)
.into_py(py))
}

// pub fn extract<'py>(
// &'py self,
// py: Python<'py>,
// ) -> PyResult<(
// &PyArray3<f64>,
// &PyArray3<f64>,
// &PyArray3<f64>,
// &PyArray3<f64>,
// )> {
// Ok((
// self.data.cr.clone().into_pyarray(py),
// self.data.tr.clone().into_pyarray(py),
// self.data.hr.clone().into_pyarray(py),
// self.data.hk.clone().into_pyarray(py),
// ))
// }
}
pub fn from_toml(fname: PathBuf) -> Self {
let config: Configuration = InputTOMLHandler::construct_configuration(&fname);
let data = config.data_config;
let (solvent, solute);
let shape = (data.npts, data.nsv, data.nsv);

impl RISMDriver {
// Construct the solvent-solvent problem
solvent = SingleData::new(
data.solvent_atoms.clone(),
data.solvent_species.clone(),
shape,
);

// Check if a solute-solvent problem exists
match data.nsu {
None => solute = None,
_ => {
let shape = (data.npts, data.nsu.unwrap(), data.nsu.unwrap());
// Construct the solute-solvent problem
solute = Some(SingleData::new(
data.solute_atoms.as_ref().unwrap().clone(),
data.solute_species.as_ref().unwrap().clone(),
shape,
));
}
}

// Extract operator information
let operator: OperatorConfig = config.operator_config;

// Extract potential information
let potential: PotentialConfig = config.potential_config;

// Extract solver information
let solver: SolverConfig = config.solver_config;

RISMDriver {
solvent,
solute,
data,
operator,
potential,
solver,
}
}
fn problem_setup(&mut self) -> (DataRs, Option<DataRs>) {
let (mut vv_problem, uv_problem);
info!("Defining solvent-solvent problem");
Expand Down
4 changes: 2 additions & 2 deletions src/input.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use log::info;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::collections::{BTreeMap, HashMap};
use std::fs;
use std::path::PathBuf;

Expand Down Expand Up @@ -261,7 +261,7 @@ pub struct Params {
pub enum ProblemInfo {
Preconverged(String),
Length(usize),
Data(HashMap<String, SpeciesInfo>),
Data(BTreeMap<String, SpeciesInfo>),
}

impl ProblemInfo {}
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fn main() -> Result<(), lexopt::Error> {
let args = parse_args()?;
println!("{}", args.verbosity);
println!("{}", args.input_file.display());

let mut driver = RISMDriver::from_toml(args.input_file);
driver.execute();
Ok(())
}

0 comments on commit 7dcf5d7

Please sign in to comment.