def Start_Iteration(experiment, gn = None): """Start an iteration of IPRO""" # Do the standard initial checks if not isinstance(experiment, EXPERIMENT.Experiment): text = "The Start Iteration function requires an Experiment class " text += "object as its input." raise IPRO_Error(text) refinement = refinement_check(experiment, gn) if refinement: return 0, refinement # Start sharing so this processor has exclusive access to the shared files SHARING.Start(experiment) # Determine what iteration this will be iteration = SHARING.iteration_counter(SHARING.get_current(), True) + 1 # Determine what the expected maximum number of iterations is ITERATIONS = max_iterations(experiment) # Create a folder while iteration <= ITERATIONS: folder = "iteration" + str(iteration) do = SHARING.claim_calculations(folder) if do: break else: iteration += 1 # If a folder was made if iteration <= ITERATIONS: # Start a summary experiment["Summary"] = "Started" + SHARING.time_stamp() # Get the last time structures were updated N = SHARING.identify_last_update("./Current/") # If necessary, update the structures if N > experiment["Last Update"]: SHARING.update_Current(experiment, "./Current/", gn) experiment["Last Update"] = N # Say what structures are being used if experiment["Last Update"] == 0: experiment["Summary"] += "Using the initial structures\n" else: experiment["Summary"] += "Using the structures from iteration " experiment["Summary"] += str(experiment["Last Update"]) + "\n" # Move into the appropriate folder os.chdir(folder) # Copy in the C++ and force field files SHARING.copy_standard_files(experiment) # Update the Experiment's structures for group in experiment: if gn not in [None, group.number]: continue for molecule in group: text =format(experiment["Current"][group.number][molecule.name]) molecule.load(text) # End sharing SHARING.End(experiment) return iteration, refinement
def End_Iteration(experiment, energies, iteration, gn): """End an iteration of IPRO.""" # The standard initial checks if not isinstance(experiment, EXPERIMENT.Experiment): text = "The End Iteration function requires an Experiment class object " text += "as its input." raise IPRO_Error(text) refinement = refinement_check(experiment, gn) if refinement: return refinement # Move out of the iteration's folder os.chdir("../") # Start sharing SHARING.Start(experiment) # Load the appropriate reference energies if experiment["Activity"] == "Standard": SHARING.load_reference_Energies(experiment) else: SHARING.update_Energies(experiment, "./Best/", gn) # Determine the last completed iteration this = SHARING.iteration_counter(SHARING.get_current(), False) + 1 # Determine whether or not keep the iteration results best, keep = iteration_decision(experiment, energies, this, gn) # If results should be kept, do so if best or keep: store_structures(experiment, gn) # If these are the best results so far, store the energies if best: store_energies(experiment, energies, gn) # If appropriate, share the results with other processors SHARING.Results(experiment, this, best, keep, gn) # Say what happened in the summary experiment["Summary"] = "\nIteration " + str(this) + "\n" + \ experiment["Summary"] + "The results were " if best: experiment["Summary"] += "the BEST so far\n" elif keep: experiment["Summary"] += "KEPT by simulated annealing\n" else: experiment["Summary"] += "DISCARDED\n" # Put a time stamp on the summary experiment["Summary"] += "Ended" + SHARING.time_stamp() # Get the name of the Summary file name = SHARING.summary_name(SHARING.get_current()) f = open(name, "a") f.write(experiment["Summary"]) f.close() # Delete the iteration os.system("rm -rf iteration" + str(iteration)) # End sharing SHARING.End(experiment) return refinement
def change_iterations(experiment, mn=None): """Do 2x the calculations for initial / wildtype calcs""" # If there is a mutant number that's not 0, don't do this if mn not in [None, 0]: return False # If it is None, check the number of completed iterations if mn == None: n = SHARING.iteration_counter(SHARING.get_current(), False) if n > 0: return False # multiply the number by 2 experiment["Refinement Iterations"] *= 2 return True
def change_iterations(experiment, mn = None): """Do 2x the calculations for initial / wildtype calcs""" # If there is a mutant number that's not 0, don't do this if mn not in [None, 0]: return False # If it is None, check the number of completed iterations if mn == None: n = SHARING.iteration_counter(SHARING.get_current(), False) if n > 0: return False # multiply the number by 2 experiment["Refinement Iterations"] *= 2 return True
def Wait(experiment): """Wait for an IPRO Experiment to be entirely completed""" # Keep track using this variable finished = False while not finished: # Periodically check the last completed iteration SHARING.Start(experiment) n = SHARING.iteration_counter(SHARING.get_current(), False) SHARING.End(experiment) # If all iterations are complete, the program doesn't need to wait any # more if n == experiment["IPRO Iterations"]: finished = True # If another processor has called for a refinement, do it REFINEMENT.DO(experiment) # If the experiment isn't done yet, take a 15 second break before # continuing the while loop if not finished: time.sleep(15)
def finish_check(experiment, mn): """Check that all ensembles are entirely finished""" # NOTE THAT THIS DOES NOT END SHARING SHARING.Start(experiment) # Figure out what folder we should be looking for if experiment["Type"] == "Mutator": if mn in [None, 0]: folder = "wildtype" else: folder = "mutant" + str(mn) else: folder = "refinement" # Move to the Experiment's folder os.chdir(experiment["Folder"]) # If the appropriate folder no longer exists, be done but return False so # the Finish function isn't called if folder not in os.listdir("./"): return False os.chdir(folder) finished = True # Loop through the groups for group in experiment: os.chdir("Group" + str(group.number)) # and the ensembles for en in range(1, experiment["Ensemble Number"] + 1): os.chdir("Ensemble" + str(en)) # Get the number of the last completed iteration I = SHARING.iteration_counter(SHARING.get_current(), False) # If they aren't all done yet if I < experiment["Refinement Iterations"]: finished = False os.chdir("../../") break os.chdir("../") if not finished: break os.chdir("../") return finished