@@ -129,6 +129,14 @@ fn run() {
129
129
}
130
130
}
131
131
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
+
132
140
fn simulate ( simulation_path : & str , setup : & SetupFile , swarm_filename : & str , steps : u32 , method : Method ) {
133
141
134
142
let seed: u64 = match setup. seed {
@@ -141,6 +149,16 @@ fn simulate(simulation_path: &str, setup: &SetupFile, swarm_filename: &str, step
141
149
} ;
142
150
143
151
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) ;
144
162
let positions = parse_input_coordinates ( swarm_filename) ;
145
163
146
164
// Parse receptor input PDB structure
@@ -206,7 +224,15 @@ fn simulate(simulation_path: &str, setup: &SetupFile, swarm_filename: &str, step
206
224
207
225
// Glowworm Swarm Optimization algorithm
208
226
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
+ ) ;
210
236
211
237
// Simulate for the given steps
212
238
println ! ( "Starting optimization ({} steps)" , steps) ;
0 commit comments