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 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 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 Finish(experiment, mn): """Finish the initial creation of a mutant""" # Sharing was started in check finish # Load the structures and energies SHARING.update_Current(experiment, "./Current/") SHARING.update_Energies(experiment, "./Current/") # Create a brief summary of the information experiment["Summary"] = '\nMutant ' + str(mn) + " Creation\n" f = open("Group1/Group1_Summary.txt", "r") for line in f: if line.startswith("Started"): experiment["Summary"] += line break f.close() # Include information about the energies for group in experiment: experiment["Summary"] += \ SHARING.format_energies(experiment["Energies"][group.number], \ group.number, False) # Put this in the overall summary os.chdir(experiment["Folder"]) name = SHARING.summary_name(SHARING.get_current()) f = open(name, "a") f.write(experiment["Summary"]) f.close() # Make a folder to do the structure refinements in folder = "mutant" + str(mn) os.mkdir(folder) folder += "/Current/" os.mkdir(folder) SHARING.output_Current(experiment, folder) SHARING.output_Energies(experiment, folder) f = open(folder + "iteration.txt", "w") f.write(str(mn)) f.close() # Delete the current folder name = "initial_mutant" + str(mn) os.system("rm -rf " + name) # 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 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)
def store_results(experiment, IEs, BEs, CEs, mn=None): """Store the results of the refinement and share them""" # If this isn't a mutator, get the current iteration if experiment["Type"] != "Mutator": f = open("./Current/iteration.txt", "r") mn = int(f.readline()) f.close() # Go through the Design Groups, identify the chosen ensemble, and store the # structures and relevant energies for group in experiment: if group.number == len(experiment) and BEs != {}: continue # Store the energies experiment["Energies"][group.number] = {} experiment["Energies"][group.number]["Complex"] = \ CEs[group.number]["Average"][0] experiment["Energies"][group.number]["Interaction"] = \ IEs[group.number]["Average"][0] if BEs != {}: experiment["Energies"][group.number]["Binding"] = \ BEs[group.number]["Average"][0] # Identify the best ensemble structure en = BEs[group.number]["Choice"][0] # Otherwise get the best ensemble structure from the IEs else: en = IEs[group.number]["Choice"][0] # Load the structures from that ensemble folder = "Group" + str(group.number) + "/Ensemble" + str(en) + "/Best/" SHARING.update_Current(experiment, folder, group.number) # If this isn't a mutator, share them in the Experiment's folder if experiment["Type"] != "Mutator": # Share the structures in the Experiment's Current folder SHARING.output_Current(experiment, experiment["Folder"]+"Current/",\ group.number, mn) # Share the results SHARING.output_best(experiment, mn, group.number)
def Start(experiment, iteration, gn=None): """Create a folder to run a refinement in.""" # Only do this when appropriate if not experiment["Do Refinement"] or gn != None or experiment["Activity"] \ != "Standard": return False # Try to make the directory if experiment["Type"] == "Mutator": folder = "wildtype" else: folder = "refinement" try: os.mkdir(folder) except OSError: return False # Assuming that was successful, prep that folder folder += "/Current/" os.mkdir(folder) SHARING.output_Current(experiment, folder) SHARING.output_Energies(experiment, folder) f = open(folder + "iteration.txt", "w") f.write(str(iteration)) f.close() return True
def store_results(experiment, IEs, BEs, CEs, mn = None): """Store the results of the refinement and share them""" # If this isn't a mutator, get the current iteration if experiment["Type"] != "Mutator": f = open("./Current/iteration.txt", "r") mn = int(f.readline()) f.close() # Go through the Design Groups, identify the chosen ensemble, and store the # structures and relevant energies for group in experiment: if group.number == len(experiment) and BEs != {}: continue # Store the energies experiment["Energies"][group.number] = {} experiment["Energies"][group.number]["Complex"] = \ CEs[group.number]["Average"][0] experiment["Energies"][group.number]["Interaction"] = \ IEs[group.number]["Average"][0] if BEs != {}: experiment["Energies"][group.number]["Binding"] = \ BEs[group.number]["Average"][0] # Identify the best ensemble structure en = BEs[group.number]["Choice"][0] # Otherwise get the best ensemble structure from the IEs else: en = IEs[group.number]["Choice"][0] # Load the structures from that ensemble folder = "Group" + str(group.number) + "/Ensemble" + str(en) + "/Best/" SHARING.update_Current(experiment, folder, group.number) # If this isn't a mutator, share them in the Experiment's folder if experiment["Type"] != "Mutator": # Share the structures in the Experiment's Current folder SHARING.output_Current(experiment, experiment["Folder"]+"Current/",\ group.number, mn) # Share the results SHARING.output_best(experiment, mn, group.number)
def Start(experiment, iteration, gn = None): """Create a folder to run a refinement in.""" # Only do this when appropriate if not experiment["Do Refinement"] or gn != None or experiment["Activity"] \ != "Standard": return False # Try to make the directory if experiment["Type"] == "Mutator": folder = "wildtype" else: folder = "refinement" try: os.mkdir(folder) except OSError: return False # Assuming that was successful, prep that folder folder += "/Current/" os.mkdir(folder) SHARING.output_Current(experiment, folder) SHARING.output_Energies(experiment, folder) f = open(folder + "iteration.txt", "w") f.write(str(iteration)) f.close() return True
def make_extra_group(experiment): """Create an extra Design Group with no Target Molecules""" # Only do this if Binding energy calculations are being done if experiment["Energy Calculation"] == "Binding": # Get all of the Design Molecules from Design Group 1 molecules = [] for molecule in experiment[1]: if molecule.design: molecules.append(molecule) # Make and store a new Design Group (which duplicates these Molecules # for run independence reasons) N = len(experiment) + 1 group = MOLECULES.DesignGroup(N, molecules, experiment["Force Field"], \ experiment["File Format"]) experiment._groupOrder.append(N) experiment._groups[N] = group n = len(experiment) # Update the Current dictionary, too experiment["Current"][n] = {} for molecule in experiment[n]: new = molecule.duplicate() experiment["Current"][n][new.name] = new # Those structures are essentially place holders at this point. However, # we do need to run an energy minimization and calculate an initial # energy for that group name = "Group" + str(n) + "_Energies.txt" SHARING.Start(experiment) # If another processor already did the calculation, we're fine if name not in os.listdir("./Current/"): # Try to make a temp directory to do the calculations in if "temp" not in os.listdir("./"): # Make the directory and move into it os.mkdir("temp") os.chdir("temp") # Stop sharing SHARING.End(experiment) # Copy in the relevant files SHARING.copy_standard_files(experiment, False) # Relax the Design Group refinement = IPRO_FUNCTIONS.Relaxation(experiment, n, True) # And calculate the energies energies, refinement = \ IPRO_FUNCTIONS.Calculate_Energy(experiment, n) # Move back up a folder os.chdir("../") # Start sharing SHARING.Start(experiment) # Store the energy text = SHARING.format_energies(energies[n]) f = open("./Current/" + name, "w") f.write(text) f.close() SHARING.output_Current(experiment, "./Current/", n) # Delete the temp folder os.system("rm -rf temp") # Otherwise, just wait else: SHARING.End(experiment) SHARING.Wait("temp", "./") SHARING.Start(experiment) # Store that complex energy f = open("./Current/" + name, "r") experiment["Energies"][n] = {"Complex": float(f.readline().split()[2])} f.close() SHARING.End(experiment)
def make_extra_group(experiment): """Create an extra Design Group with no Target Molecules""" # Only do this if Binding energy calculations are being done if experiment["Energy Calculation"] == "Binding": # Get all of the Design Molecules from Design Group 1 molecules = [] for molecule in experiment[1]: if molecule.design: molecules.append(molecule) # Make and store a new Design Group (which duplicates these Molecules # for run independence reasons) N = len(experiment) + 1 group = MOLECULES.DesignGroup(N, molecules, experiment["Force Field"], \ experiment["File Format"]) experiment._groupOrder.append(N) experiment._groups[N] = group n = len(experiment) # Update the Current dictionary, too experiment["Current"][n] = {} for molecule in experiment[n]: new = molecule.duplicate() experiment["Current"][n][new.name] = new # Those structures are essentially place holders at this point. However, # we do need to run an energy minimization and calculate an initial # energy for that group name = "Group" + str(n) + "_Energies.txt" SHARING.Start(experiment) # If another processor already did the calculation, we're fine if name not in os.listdir("./Current/"): # Try to make a temp directory to do the calculations in if "temp" not in os.listdir("./"): # Make the directory and move into it os.mkdir("temp") os.chdir("temp") # Stop sharing SHARING.End(experiment) # Copy in the relevant files SHARING.copy_standard_files(experiment, False) # Relax the Design Group refinement = IPRO_FUNCTIONS.Relaxation(experiment, n, True) # And calculate the energies energies, refinement = \ IPRO_FUNCTIONS.Calculate_Energy(experiment, n) # Move back up a folder os.chdir("../") # Start sharing SHARING.Start(experiment) # Store the energy text = SHARING.format_energies(energies[n]) f = open("./Current/" + name, "w") f.write(text) f.close() SHARING.output_Current(experiment, "./Current/", n) # Delete the temp folder os.system("rm -rf temp") # Otherwise, just wait else: SHARING.End(experiment) SHARING.Wait("temp", "./") SHARING.Start(experiment) # Store that complex energy f = open("./Current/" + name, "r") experiment["Energies"][n] = {"Complex":float(f.readline().split()[2])} f.close() SHARING.End(experiment)