diff --git a/src/cli.yml b/src/cli.yml index ca76a2f..9139666 100644 --- a/src/cli.yml +++ b/src/cli.yml @@ -112,3 +112,8 @@ args: help: "Performs WHAM for slices with the given delta in time and returns an output file for each slice. THis is useful to check the result for convergence. Example: with --convdt 100 and a timeseries ranging from 0-300, free energy surfaces for slices 0-100, 0-200 and 0-300 will be given returned." takes_value: true required: false + - ignore_empty: + long: ignore_empty + help: If this is set, do not fail if a histogram is empty. + takes_value: false + required: false diff --git a/src/io.rs b/src/io.rs index e39265d..eb667eb 100644 --- a/src/io.rs +++ b/src/io.rs @@ -103,19 +103,24 @@ pub fn read_data(cfg: &Config) -> Result> { } } - // Histograms are stored as timeseries x convdt right now, - // but we need convdt x timeseries to create Datasets - // this transposes the data + // Datasets are created from histograms. + // Empty histograms result in an error when its the final dataset, + // and a warning otherwise. let num_datasets: usize = histograms.iter().map(|h| h.len()).max().unwrap(); + let dataset_boundaries: Vec<(f64, f64)> = (0..num_datasets).map(|idx| { + (cfg.start, cfg.start+(idx as f64 + 1.0)*cfg.convdt) } + ).collect(); + vprintln(format!("Generating {} datasets from histograms.", num_datasets), cfg.verbose); let datasets: Vec = (0..num_datasets).map(|idx| { let mut dataset_histograms: Vec = Vec::with_capacity(histograms.len()); for (hs, path) in histograms.iter().zip(&paths) { if hs.len() > idx { dataset_histograms.push(hs[idx].clone()) } else { - let warning = format!("No data points in histogram boundaries: {}", &path); - if idx+1 == num_datasets { - bail!(warning); + let warning = format!("No data points for interval {}-{} in histogram boundaries: {}.", + dataset_boundaries[idx].0, dataset_boundaries[idx].1 ,&path); + if !cfg.ignore_empty && idx+1 == num_datasets { + bail!(warning + " This is the final dataset."); } else { eprintln!("{}", warning); } diff --git a/src/lib.rs b/src/lib.rs index 14d0129..31b6881 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,6 +48,7 @@ pub struct Config { pub end: f64, pub uncorr: bool, pub convdt: f64, + pub ignore_empty: bool } impl fmt::Display for Config { @@ -55,11 +56,11 @@ impl fmt::Display for Config { write!(f, "Metadata={}, hist_min={:?}, hist_max={:?}, bins={:?}, verbose={}, tolerance={}, iterations={}, temperature={}, cyclic={:?}, uncorr={:?}, bootstrap={:?}, seed={:?}, - uncorr={:?}, start={:?}, end={:?}, convdt={:?}", + uncorr={:?}, start={:?}, end={:?}, convdt={:?}, ignore_empty={:?}", self.metadata_file, self.hist_min, self.hist_max, self.num_bins, self.verbose, self.tolerance, self.max_iterations, self.temperature, self.cyclic, self.uncorr, self.bootstrap, self.bootstrap_seed, - self.uncorr, self.start, self.end, self.convdt) + self.uncorr, self.start, self.end, self.convdt, self.ignore_empty) } } diff --git a/src/main.rs b/src/main.rs index 94e7a56..aa8cff4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,9 +71,11 @@ fn cli() -> Result { let convdt: f64 = matches.value_of("convdt").unwrap_or("0").parse() .chain_err(|| "Cannot parse convdt.")?; + let ignore_empty: bool = matches.is_present("ignore_empty"); + Ok(wham::Config{metadata_file, hist_min, hist_max, num_bins, dimens, verbose, tolerance, max_iterations, temperature, cyclic, output, - bootstrap, bootstrap_seed, start, end, uncorr, convdt}) + bootstrap, bootstrap_seed, start, end, uncorr, convdt, ignore_empty}) } fn main() {