@@ -129,6 +129,14 @@ fn run() {
129129    } 
130130} 
131131
132+ fn  parse_swarm_id ( path :  & Path )  -> Option < i32 >  { 
133+     path. file_name ( ) 
134+         . and_then ( |s| s. to_str ( ) ) 
135+         . and_then ( |s| s. strip_prefix ( "initial_positions_" ) ) 
136+         . and_then ( |s| s. strip_suffix ( ".dat" ) ) 
137+         . and_then ( |s| s. parse :: < i32 > ( ) . ok ( ) ) 
138+ } 
139+ 
132140fn  simulate ( simulation_path :  & str ,  setup :  & SetupFile ,  swarm_filename :  & str ,  steps :  u32 ,  method :  Method )  { 
133141
134142    let  seed: u64  = match  setup. seed  { 
@@ -141,6 +149,16 @@ fn simulate(simulation_path: &str, setup: &SetupFile, swarm_filename: &str, step
141149    } ; 
142150
143151    println ! ( "Reading starting positions from {:?}" ,  swarm_filename) ; 
152+     let  file_path = Path :: new ( swarm_filename) ; 
153+     let  swarm_id = parse_swarm_id ( file_path) . expect ( "Could not parse swarm from swarm filename" ) ; 
154+     println ! ( "Swarm ID {:?}" ,  swarm_id) ; 
155+     let  swarm_directory = format ! ( "swarm_{}" ,  swarm_id) ; 
156+ 
157+     if  !fs:: metadata ( & swarm_directory) . map ( |m| m. is_dir ( ) ) . unwrap_or ( false )  { 
158+         panic ! ( "Output directory does not exist for swarm {:?}" ,  swarm_id) ; 
159+     } 
160+ 
161+     println ! ( "Writing to swarm dir {:?}" ,  swarm_directory) ; 
144162    let  positions = parse_input_coordinates ( swarm_filename) ; 
145163
146164    // Parse receptor input PDB structure 
@@ -206,7 +224,15 @@ fn simulate(simulation_path: &str, setup: &SetupFile, swarm_filename: &str, step
206224
207225    // Glowworm Swarm Optimization algorithm 
208226    println ! ( "Creating GSO with {} glowworms" ,  positions. len( ) ) ; 
209-     let  mut  gso = GSO :: new ( & positions,  seed,  & scoring,  setup. use_anm ,  setup. anm_rec ,  setup. anm_lig ) ; 
227+     let  mut  gso = GSO :: new ( 
228+         & positions, 
229+         seed, 
230+         & scoring, 
231+         setup. use_anm , 
232+         setup. anm_rec , 
233+         setup. anm_lig , 
234+         swarm_directory
235+     ) ; 
210236
211237    // Simulate for the given steps 
212238    println ! ( "Starting optimization ({} steps)" ,  steps) ; 
0 commit comments