fix multidimensional io

This commit is contained in:
Daniel Bauer
2018-10-21 14:42:03 +02:00
parent 429224ff3f
commit c440f46a82
3 changed files with 10108 additions and 10106 deletions

View File

@@ -1,4 +1,4 @@
#x Free Energy Probability
#coord1 Free Energy Probability
-3.108600 7.118166 0.003561
-3.045800 5.331290 0.007290
-2.983000 3.879241 0.013048

View File

@@ -1,4 +1,4 @@
#x Free Energy Probability
#coord1 coord2 Free Energy Probability
-3.109590 -3.109590 10.330312 0.000095
-3.046770 -3.109590 8.907360 0.000168
-2.983950 -3.109590 7.431969 0.000303

View File

@@ -176,16 +176,18 @@ fn read_window_file(window_file: &str, cfg: &Config) -> Option<Histogram> {
Some(Histogram::new(num_points as u32, hist))
}
// TODO multidimensional output
pub fn write_results(out_file: &str, ds: &Dataset, free: &Vec<f64>, prob: &Vec<f64>) -> Result<(), Box<Error>> {
let output = File::create(out_file)?;
let mut buf = BufWriter::new(output);
writeln!(buf, "#{}\t{}\t{}", "x", "Free Energy", "Probability"); // TODO better format (coord1, coord2..)
let header: String = (0..ds.dimens_lengths.len()).map(|d| {format!("coord{}", d+1)}).collect::<Vec<String>>().join(" ");
writeln!(buf, "#{} {} {}", header, "Free Energy", "Probability");
for bin in 0..free.len() {
let coords = ds.get_coords_for_bin(bin);
let coords_str: String = coords.iter().map(|c| {format!("{:8.6}", c)})
let coords_str: String = coords.iter().map(|c| {format!("{:8.6} ", c)})
.collect::<Vec<String>>().join("\t");
writeln!(buf, "{}\t{:8.6}\t{:8.6}", coords_str, free[bin], prob[bin])?;
writeln!(buf, "{}{:8.6} {:8.6}", coords_str, free[bin], prob[bin])?;
}
Ok(())
}