Skip to content

Commit

Permalink
experimenting with HDF5
Browse files Browse the repository at this point in the history
  • Loading branch information
2AUK committed Oct 17, 2023
1 parent f01c0eb commit cc5254b
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 5 deletions.
165 changes: 163 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ lexopt = "0.3.0"
simple_logger = "4.2.0"
flate2 = "1.0.28"
time = "0.3.30"
hdf5 = "0.8.1"

[dependencies.fftw]
version = "0.8.0"
Expand Down
10 changes: 9 additions & 1 deletion src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,18 @@ impl RISMDriver {
}
};

let config = Configuration {
data_config: self.data.clone(),
operator_config: self.operator.clone(),
potential_config: self.potential.clone(),
solver_config: self.solver.clone(),
};

// let gr_uv = &uv_solution.clone().unwrap().correlations.cr
// + &uv_solution.clone().unwrap().correlations.tr
// + 1.0;
Solutions {
config,
vv: vv_solution,
uv: uv_solution,
}
Expand All @@ -309,7 +317,7 @@ impl RISMDriver {
}
}

pub fn from_toml(fname: PathBuf) -> Self {
pub fn from_toml(fname: &PathBuf) -> Self {
let config: Configuration = InputTOMLHandler::construct_configuration(&fname);
let name = fname
.file_stem()
Expand Down
18 changes: 16 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use librism::driver::{RISMDriver, Verbosity};
use librism::{
driver::{RISMDriver, Verbosity},
writer::RISMWriter,
};
use std::path::PathBuf;

struct Args {
Expand Down Expand Up @@ -34,7 +37,18 @@ fn parse_args() -> Result<Args, lexopt::Error> {

fn main() -> Result<(), lexopt::Error> {
let args = parse_args()?;
let mut driver = RISMDriver::from_toml(args.input_file);
let mut driver = RISMDriver::from_toml(&args.input_file);
let solutions = driver.execute(args.verbosity, args.compress);
let writer = RISMWriter::new(
&args
.input_file
.file_stem()
.unwrap()
.to_str()
.unwrap()
.to_string(),
solutions,
);
writer.write();
Ok(())
}
2 changes: 2 additions & 0 deletions src/solution.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::data::{Correlations, DataConfig, Interactions};
use crate::input::Configuration;
use crate::operator::OperatorConfig;
use crate::potential::PotentialConfig;
use crate::solver::SolverConfig;
Expand All @@ -8,6 +9,7 @@ use pyo3::prelude::*;
use serde::{Deserialize, Serialize};

pub struct Solutions {
pub config: Configuration,
pub vv: SolvedData,
pub uv: Option<SolvedData>,
}
Expand Down
30 changes: 30 additions & 0 deletions src/writer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use crate::solution::Solutions;
use hdf5::{File, Result};
use std::path::PathBuf;

pub struct RISMWriter {
pub name: String,
pub data: Solutions,
}

impl RISMWriter {
pub fn new(name: &String, data: Solutions) -> Self {
RISMWriter {
name: name.clone(),
data,
}
}

pub fn write(&self) -> Result<()> {
let file = File::create(&self.name)?;
let correlations_group = file.create_group("correlations")?;
let direct_group = correlations_group.create_group("direct")?;

let cr_builder = direct_group.new_dataset_builder();
let cr = cr_builder
.with_data(&self.data.vv.correlations.cr)
.create("direct correlation function")?;
println!("{:?}", file);
Ok(())
}
}

0 comments on commit cc5254b

Please sign in to comment.