def finish_initialization(experiment): """Finish an initialization""" # Sharing is already started and the structures and energies have already # been loaded into the Experiment # Make the initial experiment summary experiment["Summary"] = "Initial Calculations\n" # Determine when they started f = open(experiment["Folder"]+"initialize/Group1/Group1_Summary.txt","r") for line in f: if line.startswith("Started"): experiment["Summary"] += line break f.close() # Include the energies of each Design Group for group in experiment: experiment["Summary"] += SHARING.format_energies(\ experiment["Energies"][group.number], group.number, False) # Create the initial folder in results SHARING.output_best(experiment, 0, None) # Figure out the name of the output file if experiment["Type"] == "Mutator": folder = experiment["Folder"] + "results/wildtype/" else: folder = experiment["Folder"] + "results/initial/" # List the energies of each Target Molecule, too if experiment["Energy Calculation"] == "Binding": for molecule in experiment[0]: if not molecule.design: name = experiment["Folder"] + "initialize/Current/Molecule" name += molecule.name + "_Energy.txt" f = open(name, "r") energy = f.readline().split()[2] f.close() experiment["Summary"] += "The energy of Target Molecule " experiment["Summary"] += molecule.name + " is " + energy experiment["Summary"] += " kcal / mol\n" # Copy the file to the output folder os.system("cp " + name + " " + folder) # Move to the Experiment's folder os.chdir(experiment["Folder"]) # Try to make the current folder try: os.mkdir("Current") except OSError: pass # Write the Structures to the Current folder SHARING.output_Current(experiment, "./Current/", None, 0) experiment["Last Update"] = 0 # Start a refinment REFINEMENT.Start(experiment, 0, None) # Create the initial summary file experiment["Summary"] += "Ended" + SHARING.time_stamp() name = SHARING.summary_name(experiment["Folder"]) f = open(name, "w") f.write(experiment["Summary"]) f.close() # Remove the initialization folder os.system("rm -rf initialize") # End the sharing that was started elsewhere 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 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 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 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 Summarize(experiment, choice, IEs, BEs, CEs, mn=None): """Summarize the results of a structure refinement""" # Come up with an appropriate header if experiment["Type"] == "Mutator": if mn == 0: experiment["Summary"] = "\nWildtype Refinement Results\n" else: experiment["Summary"] = "\nMutant " + str( mn) + " Refinement Results\n" else: f = open("./Current/iteration.txt", "r") n = int(f.readline()) f.close() if n == 0: experiment["Summary"] = "\nInitial Structures Refinement\n" else: experiment["Summary"] = "\nRefinement of Iteration " + str( n) + "\n" # Find out when the refinement started f = open("./Group1/Ensemble1/Ensemble1_Summary.txt", "r") for line in f: if line.startswith("Started"): experiment["Summary"] += line break f.close() # Store the information about the calculated energies for group in experiment: if experiment["Energy Calculation"] == "Binding" and group.number == \ len(experiment): continue # Summarize Complex energy experiment["Summary"] += "Design Group " + str(group.number) + "\n" experiment["Summary"] += "Average Complex Energy: " + \ format(CEs[group.number]["Average"][0], '.3f') + " +/- " + \ format(CEs[group.number]["Average"][1], '.3f') + " kcal/mol\n" # IE experiment["Summary"] += "Average Interaction Energy: " + \ format(IEs[group.number]["Average"][0], '.3f') + " +/- " + \ format(IEs[group.number]["Average"][1], '.3f') + " kcal/mol\n" # BE if experiment["Energy Calculation"] == "Binding": experiment["Summary"] += "Average Binding Energy: " + \ format(BEs[group.number]["Average"][0], '.3f') + " +/- " + \ format(BEs[group.number]["Average"][1], '.3f') + " kcal/mol\n" if experiment["Type"] != "Mutator" and n != 0: if choice: experiment["Summary"] += "These were the BEST results so far\n" else: experiment["Summary"] += "These results were DISCARDED\n" # Say when the calculations finished experiment["Summary"] += "Ended" + SHARING.time_stamp()
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 Summarize(experiment, choice, IEs, BEs, CEs, mn = None): """Summarize the results of a structure refinement""" # Come up with an appropriate header if experiment["Type"] == "Mutator": if mn == 0: experiment["Summary"] = "\nWildtype Refinement Results\n" else: experiment["Summary"] = "\nMutant " + str(mn)+" Refinement Results\n" else: f = open("./Current/iteration.txt", "r") n = int(f.readline()) f.close() if n == 0: experiment["Summary"] = "\nInitial Structures Refinement\n" else: experiment["Summary"] = "\nRefinement of Iteration " + str(n) + "\n" # Find out when the refinement started f = open("./Group1/Ensemble1/Ensemble1_Summary.txt", "r") for line in f: if line.startswith("Started"): experiment["Summary"] += line break f.close() # Store the information about the calculated energies for group in experiment: if experiment["Energy Calculation"] == "Binding" and group.number == \ len(experiment): continue # Summarize Complex energy experiment["Summary"] += "Design Group " + str(group.number) + "\n" experiment["Summary"] += "Average Complex Energy: " + \ format(CEs[group.number]["Average"][0], '.3f') + " +/- " + \ format(CEs[group.number]["Average"][1], '.3f') + " kcal/mol\n" # IE experiment["Summary"] += "Average Interaction Energy: " + \ format(IEs[group.number]["Average"][0], '.3f') + " +/- " + \ format(IEs[group.number]["Average"][1], '.3f') + " kcal/mol\n" # BE if experiment["Energy Calculation"] == "Binding": experiment["Summary"] += "Average Binding Energy: " + \ format(BEs[group.number]["Average"][0], '.3f') + " +/- " + \ format(BEs[group.number]["Average"][1], '.3f') + " kcal/mol\n" if experiment["Type"] != "Mutator" and n != 0: if choice: experiment["Summary"] += "These were the BEST results so far\n" else: experiment["Summary"] += "These results were DISCARDED\n" # Say when the calculations finished experiment["Summary"] += "Ended" + SHARING.time_stamp()