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 mutate_DesignGroups(experiment, mn): """Make the initial mutants of the Design Groups""" # Move into the folder to do the initial calculations in folder = "initial_mutant" + str(mn) os.chdir(folder) # Loop through the Design Groups for group in experiment: # The calculations will be stored in this folder folder = "Group" + str(group.number) # Try to claim the calculations do = SHARING.claim_calculations(folder) # If this processor is doing those calculations if do: # Time stamp when this started experiment["Summary"] = "Started" + SHARING.time_stamp() # Move into the folder os.chdir(folder) # Copy in the C++ and force field files SHARING.copy_standard_files(experiment) # Use the Current structures for molecule in experiment[group.number]: text =format(experiment["Current"][group.number][molecule.name]) molecule.load(text) # Set the permissions for the Molecules permission_setter(experiment, group.number, mn) # Mutate the Residues refinement = IPRO_FUNCTIONS.Optimal_Rotamers(experiment, \ group.number) refinement = IPRO_FUNCTIONS.Relaxation(experiment, group.number, \ True) energies, refinement = IPRO_FUNCTIONS.Calculate_Energy(experiment, \ group.number) # Start sharing SHARING.Start(experiment) # Write a brief summary file name = SHARING.summary_name(SHARING.get_current()) f = open(name, "w") f.write(experiment["Summary"]) f.close() # Move up a folder os.chdir("../") # Store the structures in the Current dictionary IPRO_FUNCTIONS.store_structures(experiment, group.number) IPRO_FUNCTIONS.store_energies(experiment, energies, group.number) # Write the structures to the Current folder SHARING.output_Current(experiment, "./Current/", group.number) SHARING.output_Energies(experiment, "./Current/", group.number) # End sharing SHARING.End(experiment)
def initialize_molecule(experiment, mn): """Initialize a Molecule""" # Create the folder's name folder = "Molecule" + mn do = SHARING.claim_calculations(folder) # If this processor is doing the calculations if do: # Make a summary experiment["Summary"] = "Started" + SHARING.time_stamp() # Move into the folder os.chdir(folder) SHARING.copy_standard_files(experiment) # Get a unique copy of the Molecule molecule = experiment[0][mn].duplicate() for residue in molecule: residue.freedom = "FREE" # Store the calculated energies here energies = {} # Do a relaxation and energy calculation if experiment["Force Field"] == "CHARMM": CHARMM.Relaxation(molecule, experiment) energies["Complex"] = CHARMM.Energy(molecule, experiment) else: text = "The initialize molecule function does not support the " text += str(experiment["Force Field"]) + " force field." raise IPRO_Error(text) # Format the energy text = SHARING.format_energies(energies) experiment["Summary"] += text # Create the summary file for the Molecule experiment["Summary"] += "Ended" + SHARING.time_stamp() name = SHARING.summary_name(SHARING.get_current()) f = open(name, "w") f.write(experiment["Summary"]) f.close() # Leave this folder, then start sharing os.chdir('../') SHARING.Start(experiment) # Output the Molecule's structure name = "./Current/" + molecule.generate_name() molecule.output(name, molecule.fileFormat, experiment["User"]) # Output the Complex energy f = open("./Current/Molecule" + mn + "_Energy.txt", "w") f.write(text) f.close() # End sharing SHARING.End(experiment)
def first_group_refinement(experiment): """Start all ensembles for the Design Groups""" # Start sharing (for file creation reasons) SHARING.Start(experiment) # Loop through the design groups print "Check1" for group in experiment: gn = group.number # Generate the name for the Design Group's calculations folder = "Group" + str(gn) try: os.mkdir(folder) except OSError: pass os.chdir(folder) # Start each ensemble for en in range(1, experiment["Ensemble Number"] + 1): eFolder = "Ensemble" + str(en) do = SHARING.claim_calculations(eFolder) # If this processor has started the calculations for this ensemble print en, do if do: # Make sure the experiment has the right structures and energies SHARING.update_Current(experiment, "../Current/", gn) SHARING.update_Energies(experiment, "../Current/", gn) # Move into the folder os.chdir(eFolder) # Make a copy of the best structures and energies for the group os.mkdir("Current") SHARING.output_Current(experiment, "./Current/", gn, 0) os.mkdir("Best") SHARING.output_Current(experiment, "./Best/", gn) SHARING.output_Energies(experiment, "./Best/", gn) # Move out of the e Folder os.chdir("../") SHARING.End(experiment) # Do the ensemble refinement ensemble_refinement(experiment, gn, en) SHARING.Start(experiment) # Move out of the folder os.chdir("../") SHARING.End(experiment)
def initialize_group(experiment, gn): """Initialize a Design Group""" # Create the folder's name folder = "Group" + str(gn) # Try to claim it for calculations do = SHARING.claim_calculations(folder) # If this processor is doing the calculations if do: # Make a summary experiment["Summary"] = "Started" + SHARING.time_stamp() # Move into the folder and copy in files os.chdir(folder) SHARING.copy_standard_files(experiment) # Relax everything refinement = Relaxation(experiment, gn, True) # Assign closest rotamers Closest_Rotamers(experiment, gn) # Do another relaxation refinement = Relaxation(experiment, gn, True) # Calculate the initial energies energies, refinement = Calculate_Energy(experiment, gn) # Store the structures and energies store_structures(experiment, gn) store_energies(experiment, energies, gn) # Create a summary file experiment["Summary"] += "Ended" + SHARING.time_stamp() name = SHARING.summary_name(SHARING.get_current()) f = open(name, "w") f.write(experiment["Summary"]) f.close() # Move up a folder os.chdir("../") # Start sharing SHARING.Start(experiment) # output the structures and energies to the Current folder SHARING.output_Current(experiment, "./Current/", gn) SHARING.output_Energies(experiment, "./Current/", gn) # End sharing SHARING.End(experiment) return do
def first_group_refinement(experiment): """Start all ensembles for the Design Groups""" # Start sharing (for file creation reasons) SHARING.Start(experiment) # Loop through the design groups for group in experiment: gn = group.number # Generate the name for the Design Group's calculations folder = "Group" + str(gn) try: os.mkdir(folder) except OSError: pass os.chdir(folder) # Start each ensemble for en in range(1, experiment["Ensemble Number"] + 1): eFolder = "Ensemble" + str(en) do = SHARING.claim_calculations(eFolder) # If this processor has started the calculations for this ensemble if do: # Make sure the experiment has the right structures and energies SHARING.update_Current(experiment, "../Current/", gn) SHARING.update_Energies(experiment, "../Current/", gn) # Move into the folder os.chdir(eFolder) # Make a copy of the best structures and energies for the group os.mkdir("Current") SHARING.output_Current(experiment, "./Current/", gn, 0) os.mkdir("Best") SHARING.output_Current(experiment, "./Best/", gn) SHARING.output_Energies(experiment, "./Best/", gn) # Move out of the e Folder os.chdir("../") SHARING.End(experiment) # Do the ensemble refinement ensemble_refinement(experiment, gn, en) SHARING.Start(experiment) # Move out of the folder os.chdir("../") SHARING.End(experiment)