mirror of
https://github.com/dnlbauer/WHAM.git
synced 2026-09-10 22:25:31 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
99f2c9069d | ||
|
|
7109d27543 | ||
|
|
c03be1723e |
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -293,7 +293,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wham"
|
name = "wham"
|
||||||
version = "0.9.1"
|
version = "0.9.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"GSL 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"GSL 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "wham"
|
name = "wham"
|
||||||
version = "0.9.1"
|
version = "0.9.2"
|
||||||
authors = ["D. Bauer <bauer@bio.tu-darmstadt.de>"]
|
authors = ["D. Bauer <bauer@bio.tu-darmstadt.de>"]
|
||||||
description = "An implementation of the weighted histogram analysis method"
|
description = "An implementation of the weighted histogram analysis method"
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
@@ -17,4 +17,4 @@ rayon = "1.0.3"
|
|||||||
opt-level = 2
|
opt-level = 2
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["GSL/v2"]
|
default = ["GSL/v2"]
|
||||||
|
|||||||
20
src/io.rs
20
src/io.rs
@@ -7,6 +7,7 @@ use std::io::{BufReader,BufWriter};
|
|||||||
use k_B;
|
use k_B;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use super::errors::*;
|
use super::errors::*;
|
||||||
|
use f64;
|
||||||
|
|
||||||
// Returns the path to path2 relative to path1
|
// Returns the path to path2 relative to path1
|
||||||
// path1: "path/to/file.dat"
|
// path1: "path/to/file.dat"
|
||||||
@@ -112,7 +113,7 @@ fn is_in_hist_boundaries(values: &Vec<f64>, cfg: &Config) -> bool {
|
|||||||
// parse a timeseries file into a histogram
|
// parse a timeseries file into a histogram
|
||||||
fn read_window_file(window_file: &str, cfg: &Config) -> Result<Histogram> {
|
fn read_window_file(window_file: &str, cfg: &Config) -> Result<Histogram> {
|
||||||
let f = File::open(window_file)
|
let f = File::open(window_file)
|
||||||
.chain_err(|| format!("Failed to open sample data file {}", window_file))?;
|
.chain_err(|| format!("Failed to open sample data file {}.", window_file))?;
|
||||||
let mut buf = BufReader::new(&f);
|
let mut buf = BufReader::new(&f);
|
||||||
|
|
||||||
// total number of bins is the product of all dimensions length
|
// total number of bins is the product of all dimensions length
|
||||||
@@ -126,7 +127,9 @@ fn read_window_file(window_file: &str, cfg: &Config) -> Result<Histogram> {
|
|||||||
|
|
||||||
// read and parse each timeseries line
|
// read and parse each timeseries line
|
||||||
let mut line = String::new();
|
let mut line = String::new();
|
||||||
|
let mut linecount = 0;
|
||||||
while buf.read_line(&mut line).chain_err(|| "Failed to read line")? > 0 {
|
while buf.read_line(&mut line).chain_err(|| "Failed to read line")? > 0 {
|
||||||
|
linecount += 1;
|
||||||
// skip comments and empty lines
|
// skip comments and empty lines
|
||||||
if line.starts_with("#") || line.starts_with("@") || line.len() == 0 {
|
if line.starts_with("#") || line.starts_with("@") || line.len() == 0 {
|
||||||
line.clear();
|
line.clear();
|
||||||
@@ -134,12 +137,17 @@ fn read_window_file(window_file: &str, cfg: &Config) -> Result<Histogram> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut split = line.split_whitespace();
|
|
||||||
|
|
||||||
split.next(); // skip time/step column
|
let split: Vec<&str> = line.split_whitespace().collect();
|
||||||
let values: Vec<f64> = (0..cfg.dimens).collect::<Vec<usize>>().iter().map(|_| {
|
if split.len() < cfg.dimens+1 {
|
||||||
split.next().unwrap().parse::<f64>().unwrap()
|
bail!(format!("Wrong number of columns in line {} of window file {}. Empty Line?.", linecount, window_file));
|
||||||
}).collect();
|
}
|
||||||
|
|
||||||
|
let mut values: Vec<f64> = vec![f64::NAN; cfg.dimens];
|
||||||
|
for i in 0..values.len() {
|
||||||
|
values[i] = split[i+1].parse::<f64>()
|
||||||
|
.chain_err(|| format!("Failed to parse line {} of window file {}.", linecount, window_file))?;
|
||||||
|
}
|
||||||
|
|
||||||
if is_in_hist_boundaries(&values, cfg) {
|
if is_in_hist_boundaries(&values, cfg) {
|
||||||
let bin_indeces = (0..cfg.dimens).map(|dimen: usize| {
|
let bin_indeces = (0..cfg.dimens).map(|dimen: usize| {
|
||||||
|
|||||||
11
tests/COLVAR_unparseable_1.xvg
Normal file
11
tests/COLVAR_unparseable_1.xvg
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
84.840004 -2.878293
|
||||||
|
84.860004 -2.827750
|
||||||
|
84.880004 -2.962375
|
||||||
|
84.900004
|
||||||
|
84.920004 -2.748589
|
||||||
|
84.940004 -2.726197
|
||||||
|
84.960004 -2.802982
|
||||||
|
84.980004 -2.771980
|
||||||
|
85.000004 -2.706482
|
||||||
|
85.020004 -2.776983
|
||||||
|
85.040004 -2.883180
|
||||||
11
tests/COLVAR_unparseable_2.xvg
Normal file
11
tests/COLVAR_unparseable_2.xvg
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
84.840004 -2.878293
|
||||||
|
84.860004 -2.827750
|
||||||
|
84.880004 -2.962375
|
||||||
|
84.900004 qwee
|
||||||
|
84.920004 -2.748589
|
||||||
|
84.940004 -2.726197
|
||||||
|
84.960004 -2.802982
|
||||||
|
84.980004 -2.771980
|
||||||
|
85.000004 -2.706482
|
||||||
|
85.020004 -2.776983
|
||||||
|
85.040004 -2.883180
|
||||||
@@ -77,6 +77,36 @@ mod integration {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unparseable_timeseries() {
|
||||||
|
let output = Command::new("./target/debug/wham")
|
||||||
|
.args(&["--bins", "100", "--min", "-3.0", "--max", "3.0", "-T", "300"])
|
||||||
|
.args(&["-f", "tests/metadata_unparseable3.dat"])
|
||||||
|
.args(&["-o", "/dev/null"])
|
||||||
|
.output()
|
||||||
|
.expect("failed to execute process");
|
||||||
|
let output = String::from_utf8_lossy(&output.stderr);
|
||||||
|
println!("{}", output);
|
||||||
|
assert!(output.to_string().contains(
|
||||||
|
"Failed to parse line"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unparseable_timeseries_empty() {
|
||||||
|
let output = Command::new("./target/debug/wham")
|
||||||
|
.args(&["--bins", "100", "--min", "-3.0", "--max", "3.0", "-T", "300"])
|
||||||
|
.args(&["-f", "tests/metadata_unparseable4.dat"])
|
||||||
|
.args(&["-o", "/dev/null"])
|
||||||
|
.output()
|
||||||
|
.expect("failed to execute process");
|
||||||
|
let output = String::from_utf8_lossy(&output.stderr);
|
||||||
|
println!("{}", output);
|
||||||
|
assert!(output.to_string().contains(
|
||||||
|
"Wrong number of columns in line"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn wham_1d() {;
|
fn wham_1d() {;
|
||||||
Command::new("./target/debug/wham")
|
Command::new("./target/debug/wham")
|
||||||
|
|||||||
1
tests/metadata_unparseable3.dat
Normal file
1
tests/metadata_unparseable3.dat
Normal file
@@ -0,0 +1 @@
|
|||||||
|
COLVAR_unparseable_2.xvg -3.0 100
|
||||||
1
tests/metadata_unparseable4.dat
Normal file
1
tests/metadata_unparseable4.dat
Normal file
@@ -0,0 +1 @@
|
|||||||
|
COLVAR_unparseable_1.xvg -3.0 100
|
||||||
Reference in New Issue
Block a user