Beispiel #1
0
def initialize(experiment, mn):
    """Set up an Experiment to work in a refinement"""
    # Start sharing
    SHARING.Start(experiment)
    # Modify the number of iterations
    modify = change_iterations(experiment, mn)
    # Identify the proper folder for the refinement
    if experiment["Type"] == "Mutator":
        if mn in [None, 0]:
            folder = "./wildtype/"
        else:
            folder = "./mutant" + str(mn) + "/"
    else:
        folder = "./refinement/"
    # Move into the refinement folder
    os.chdir(folder)
    # Load the current structures and energies
    SHARING.update_Current(experiment, "./Current/")
    SHARING.update_Energies(experiment, "./Current/")
    # Stop sharing
    SHARING.End(experiment)
    # Make the extra Design Group
    make_extra_group(experiment)
    # Modify the 'Activity' of the Experiment
    experiment['Activity'] = "Refinement"
    return modify
Beispiel #2
0
def initial_check(experiment, mn):
    """Do an initial check about doing calculations for a mutant"""
    # Start sharing
    SHARING.Start(experiment)
    # This is the name of the folder we're looking for
    folder = "mutant" + str(mn)
    # If the results are already completed
    if folder in os.listdir(experiment["Folder"] + "results/"):
        SHARING.End(experiment)
        return False
    # Or if the refinement is ongoing
    elif folder in os.listdir(experiment["Folder"]):
        SHARING.End(experiment)
        return False
    # If the initial folder for that mutant does not yet exist, make it
    folder = "initial_" + folder
    if folder not in os.listdir(experiment["Folder"]):
        os.mkdir(folder)
        os.mkdir(folder + "/Current")
    # Load the wildtype structures
    SHARING.update_Current(experiment, experiment["Folder"] + \
                           "results/wildtype/")
    SHARING.update_Energies(experiment, experiment["Folder"] + \
                            "results/wildtype/")
    # End sharing
    SHARING.End(experiment)
    return True
Beispiel #3
0
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)
Beispiel #4
0
def check_finish(experiment):
    """Check to see if the initial structures for a mutant have been made yet"""
    # Start sharing
    SHARING.Start(experiment)
    # Keep track of whether everything is finished
    finished = True
    # Check every Design Group for a summary file
    for group in experiment:
        label = "Group" + str(group.number)
        if label + "_Summary.txt" not in os.listdir(label):
            finished = False
            break
    return finished
Beispiel #5
0
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)
Beispiel #6
0
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
Beispiel #7
0
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)