Skip to content

Commit 75afe5a

Browse files
committed
Fixed issue with nested paths
1 parent 6975ae9 commit 75afe5a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/bin/lightdock-rust.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ extern crate serde;
22
extern crate serde_json;
33
extern crate npy;
44

5-
use lightdock::GSO;
5+
use lightdock::{swarm, GSO};
66
use lightdock::constants::{DEFAULT_LIGHTDOCK_PREFIX, DEFAULT_SEED, DEFAULT_REC_NM_FILE, DEFAULT_LIG_NM_FILE};
77
use lightdock::scoring::{Score, Method};
88
use lightdock::dfire::DFIRE;
@@ -124,9 +124,10 @@ fn run() {
124124
}
125125
}
126126

127-
fn parse_swarm_id(filename: &str) -> Option<i32> {
128-
filename
129-
.strip_prefix("initial_positions_")
127+
fn parse_swarm_id(path: &Path) -> Option<i32> {
128+
path.file_name()
129+
.and_then(|s| s.to_str())
130+
.and_then(|s| s.strip_prefix("initial_positions_"))
130131
.and_then(|s| s.strip_suffix(".dat"))
131132
.and_then(|s| s.parse::<i32>().ok())
132133
}
@@ -143,7 +144,8 @@ fn simulate(setup: &SetupFile, swarm_filename: &str, steps: u32, method: Method)
143144
};
144145

145146
println!("Reading starting positions from {:?}", swarm_filename);
146-
let swarm_id = parse_swarm_id(swarm_filename).expect("Could not parse swarm from swarm filename");
147+
let file_path = Path::new(swarm_filename);
148+
let swarm_id = parse_swarm_id(file_path).expect("Could not parse swarm from swarm filename");
147149
println!("Swarm ID {:?}", swarm_id);
148150
let swarm_directory = format!("swarm_{}", swarm_id);
149151

0 commit comments

Comments
 (0)