Exemple #1
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
def Finish(experiment, mn=None):
    """Finish a Refinement"""
    # Sharing will have been started elsewhere (in finish_check)
    # Collect the calculated energies
    energies = gather_energies(experiment)
    # Get interaction, complex, and binding energies
    IEs = calculate_IEs(energies)
    CEs = calculate_CEs(energies)
    BEs = calculate_BEs(experiment, energies)
    # Evaluate the results
    choice = make_refinement_choice(experiment, IEs, BEs)
    # If the choice is to keep the results, make a permanent copy
    if choice:
        store_results(experiment, IEs, BEs, CEs, mn)
    # Summarize the results
    Summarize(experiment, choice, IEs, BEs, CEs, mn)
    # Move out of the refinement's folder
    os.chdir(experiment["Folder"])
    # Store the refinement summary
    name = SHARING.summary_name(experiment["Folder"])
    f = open(name, "a")
    f.write(experiment["Summary"])
    f.close()
    # Delete the folder the refinement happened in
    if experiment["Type"] == "Mutator":
        if mn in [None, 0]:
            name = "wildtype"
        else:
            name = "mutant" + str(mn)
    else:
        name = "refinement"
    os.system("rm -rf " + name)
    # End sharing
    SHARING.End(experiment)
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
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)
Exemple #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)
Exemple #6
0
def DO(experiment, mn):
    """Make a particular Mutant"""
    # Determine if the mutant should be made
    do = initial_check(experiment, mn)
    # If it should be, do so
    if do:
        # Mutate the Design Groups
        mutate_DesignGroups(experiment, mn)
        # Check to see if everything is finished
        finished = check_finish(experiment)
        # If everything is done, start the refinement calculations for the
        # mutant
        if finished:
            Finish(experiment, mn)
        else:
            # Otherwise, go back to the Experiment's folder, end sharing, and
            # wait for the initial folder to be deleted
            os.chdir(experiment["Folder"])
            SHARING.End(experiment)
            SHARING.Wait("initial_mutant" + str(mn))
Exemple #7
0
def DO(experiment, mn=None):
    """Do a Refinement"""
    # Only do a refinement when there is a refinement folder to do the
    # refinement IN
    if experiment["Type"] == "Mutator":
        if mn in [None, 0]:
            name = "wildtype"
        else:
            name = "mutant" + str(mn)
    else:
        name = "refinement"
    # If the folder doesn't exist, don't do anything
    if name in os.listdir("./"):
        # Initialize the experiment for the refinement
        modify = initialize(experiment, mn)
        # do the first set of refinement calculations - which exist to try and
        # keep the processors working on separate jobs as much as possible
        first_group_refinement(experiment)
        # And the second, which exists to get everything finished ASAP
        second_group_refinement(experiment)
        # Determine if the calculations are finished yet
        finished = finish_check(experiment, mn)
        # If the refinement is not finished, move out of the refinement's folder
        # and wait for it to be deleted
        if not finished:
            os.chdir(experiment["Folder"])
            SHARING.End(experiment)
            # There's no need to wait during mutator experiments, except for the
            # Wildtype values to finish
            if experiment["Type"] != "Mutator" or mn in [None, 0]:
                SHARING.Wait(name)
        # If the refinement is finished, store the information
        else:
            Finish(experiment, mn)
        # The refinement folder is gone, the structures and energies are stored,
        # so we can be done with the refinement after a few more things
        delete_extra_group(experiment)
        if modify:
            experiment["Refinement Iterations"] = int(
                experiment["Refinement Iterations"] / 2)
        experiment["Activity"] = "Standard"
Exemple #8
0
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 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)