import std.stdio; import std.file; import std.conv; import std.format; import std.array; import std.regex; void main(string[] args){ if(args.length < 2){ writefln("Usage: prepNextCycle 3 should be run when cycle02 is finished, this will set up cycle03."); return; } int nextCycle = to!int(args[1]); string nextDir = format("cycle%02d", nextCycle); string prevDir = format("cycle%02d", nextCycle-1); if (exists(format("cycle%02d", nextCycle))){ writeln("ERROR: Directory exists."); return; } mkdir(format("cycle%02d", nextCycle)); copy(prevDir ~ "/out_production_" ~ prevDir ~ ".restart.coor" , nextDir ~ "/out_production_" ~ prevDir ~ ".restart.coor" ); copy(prevDir ~ "/out_production_" ~ prevDir ~ ".restart.vel" , nextDir ~ "/out_production_" ~ prevDir ~ ".restart.vel" ); copy(prevDir ~ "/out_production_" ~ prevDir ~ ".restart.xsc" , nextDir ~ "/out_production_" ~ prevDir ~ ".restart.xsc" ); //Get the last step number from the restart file: auto xscFile = File(prevDir ~ "/out_production_" ~ prevDir ~ ".restart.xsc", "r"); xscFile.readln(); xscFile.readln(); auto xscLine = split(xscFile.readln()); auto lastTimeStep = to!ulong(xscLine[0]); //Copy over the sge script: auto sgeInFile = File(prevDir ~ "/production_" ~ prevDir ~ ".sge", "r"); auto sgeOutFile = File(nextDir ~ "/production_" ~ nextDir ~ ".sge", "w"); //We just need to fix the cycle numbers. auto oldCycle = regex(prevDir); foreach(line; sgeInFile.byLine()){ sgeOutFile.writeln(replaceAll(line, oldCycle, nextDir)); } sgeInFile.close(); sgeOutFile.close(); //Copy over the namd config. auto namdInFile = File(prevDir ~ "/production_" ~ prevDir ~ ".namd", "r"); auto namdOutFile = File(nextDir ~ "/production_" ~ nextDir ~ ".namd", "w"); auto fts = ctRegex!("firsttimestep"); auto spn = ctRegex!("set inputname"); foreach (line; namdInFile.byLine()){ if(matchFirst(line, fts).length){ namdOutFile.writefln("firsttimestep %s", lastTimeStep); }else if(matchFirst(line, spn).length){ namdOutFile.writefln("set inputname out_production_%s.restart", prevDir); }else{ namdOutFile.writeln(replaceAll(line, oldCycle, nextDir)); } } namdInFile.close(); namdOutFile.close(); //Copy over the last remaining needed files. if(exists(prevDir ~ "/ionized.psf")){ copy(prevDir ~ "/ionized.psf" , nextDir ~ "/ionized.psf"); copy(prevDir ~ "/ionized.pdb" , nextDir ~ "/ionized.pdb"); }else{ copy(prevDir ~ "/comb.prmtop" , nextDir ~ "/comb.prmtop"); if(exists(prevDir ~ "/comb.inpcrd")){ copy(prevDir ~ "/comb.inpcrd" , nextDir ~ "/comb.inpcrd"); } copy(prevDir ~ "/comb.pdb" , nextDir ~ "/comb.pdb"); } copy(prevDir ~ "/ends.col" , nextDir ~ "/ends.col"); }