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
Example #2
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)
Example #3
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)
Example #4
0
def input_validation(experiment):
    """Make sure that the force field and rotamer calculations will work"""
    # Clear the screen
    os.system("clear")
    # Tell the user what is happening
    message = """
The inputs you have provided are now being validated. This should only take a
moment, so please be patient."""
    print screen_formatting(message[1:])
    # Make the Experiment's folder
    os.mkdir(experiment["Folder"])
    # Get the current folder, so we can move back to it when finished
    current = os.getcwd()
    # Move to the Experiment's folder
    os.chdir(experiment["Folder"])
    # copy in the force field and solvation files
    SHARING.copy_standard_files(experiment, current + "/input_files/", False, \
                                True, True)
    # Check the appropriateness of the Molecules, force field, and non-bonded
    # energy parameters
    molecules = appropriateness(experiment, True)
    # If everything worked correctly, the folder can be prepped for the
    # experiment
    # Delete all files, as they're not needed anymore
    names = os.listdir("./")
    for name in names:
        i = os.remove(name)
    # Make an input files folder
    os.mkdir("input_files")
    # Move into that folder
    os.chdir("input_files")
    # Copy in the force field and solvation files
    SHARING.copy_standard_files(experiment, current + "/input_files/", False, \
                                True, True)
    # Move back to the Experiment's folder
    os.chdir(experiment["Folder"])
    # Create a results folder
    os.mkdir("results")
    # Create a structures folder
    os.mkdir("structures")
    # Move into that folder
    os.chdir("structures")
    # Output each Molecule in the structures folder
    for molecule in molecules:
        molecule.output(None, experiment["File Format"], experiment["User"])
    # Move back to the starting folder
    os.chdir(current)
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)
Example #6
0
def input_validation(experiment):
    """Make sure that the force field and rotamer calculations will work"""
    # Clear the screen
    os.system("clear")
    # Tell the user what is happening
    message = """
The inputs you have provided are now being validated. This should only take a
moment, so please be patient."""
    print screen_formatting(message[1:])
    # Make the Experiment's folder
    os.mkdir(experiment["Folder"])
    # Get the current folder, so we can move back to it when finished
    current = os.getcwd()
    # Move to the Experiment's folder
    os.chdir(experiment["Folder"])
    # copy in the force field and solvation files
    SHARING.copy_standard_files(experiment, current + "/input_files/", False, \
                                True, True)
    # Check the appropriateness of the Molecules, force field, and non-bonded
    # energy parameters
    molecules = appropriateness(experiment, True)
    # If everything worked correctly, the folder can be prepped for the
    # experiment
    # Delete all files, as they're not needed anymore
    names = os.listdir("./")
    for name in names:
        i = os.remove(name)
    # Make an input files folder
    os.mkdir("input_files")
    # Move into that folder
    os.chdir("input_files")
    # Copy in the force field and solvation files
    SHARING.copy_standard_files(experiment, current + "/input_files/", False, \
                                True, True)
    # Move back to the Experiment's folder
    os.chdir(experiment["Folder"])
    # Create a results folder
    os.mkdir("results")
    # Create a structures folder
    os.mkdir("structures")
    # Move into that folder
    os.chdir("structures")
    # Output each Molecule in the structures folder
    for molecule in molecules:
        molecule.output(None, experiment["File Format"], experiment["User"])
    # Move back to the starting folder
    os.chdir(current)
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
Example #8
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)
Example #9
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)