Beispiel #1
0
def run_mc_simulation(job):
    start = time.time()
    os.chdir(job.ws)
    cg_pyrosetta.init()
    # Build Annealer Parameters
    # Annealing simulation with 500000
    annealer_params = cg_pyrosetta.CG_monte_carlo.\
        CGMonteCarloAnnealerParameters(n_inner = 1000,
                                       t_init = 10,
                                       anneal_rate = 0.9,
                                       n_anneals = 50,
                                       annealer_criteron = cg_pyrosetta.CG_monte_carlo.Repeat10Convergence,
                                       mc_output = True,
                                       out_freq = 500,
    )

    # Build Energy Function
    energy_function = cg_pyrosetta.CG_monte_carlo.EnergyFunctionFactory(
    ).build_energy_function({
        "mm_twist": 1,
        "mm_bend": 1,
        "fa_atr": 1,
        "fa_rep": 1,
        "fa_intra_rep": 1,
        "fa_intra_atr": 1,
    })

    # Pose to be folded
    pose = cg_pyrosetta.pyrosetta.pose_from_sequence("X[CG13x3:CGLower]" +
                                                     "X[CG13x3]" *
                                                     (job.sp.nmer - 2) +
                                                     "X[CG13x3:CGUpper]")

    # Build Minimizer
    mini = cg_pyrosetta.pyrosetta.rosetta.protocols.minimization_packing.MinMover(
    )
    mini.min_type('lbfgs_armijo_nonmonotone')
    mini.score_function(energy_function)

    movemap = cg_pyrosetta.pyrosetta.MoveMap()
    movemap.set_bb_true_range(1, pose.size())
    movemap.set_branches(True)
    movemap.set(cg_pyrosetta.pyrosetta.rosetta.core.id.THETA, True)
    movemap.set(cg_pyrosetta.pyrosetta.rosetta.core.id.PHI, True)

    # print("Using the following MoveMap:")
    # print(movemap)

    mini.movemap(movemap)

    # Build Sequence Mover for MC object
    sequence_mover_factory = cg_pyrosetta.CG_monte_carlo.SequenceMoverFactory(
        pose, {"mini": mini})
    sequence_mover = sequence_mover_factory.build_seq_mover({
        "small_dihe": 1,
        "small_angle": 1,
        "mini": 1,
    })

    cg_annealer = cg_pyrosetta.CG_monte_carlo.CGMonteCarloAnnealer(
        seq_mover=sequence_mover,
        score_function=energy_function,
        pose=pose,
        param_file_object=annealer_params)

    # Setup Configuration/Energy observer for saving minimum energy structures
    struct_obs = cg_pyrosetta.CG_monte_carlo.StructureObserver(
        cg_annealer.get_mc_sim())
    energy_obs = cg_pyrosetta.CG_monte_carlo.EnergyObserver(
        cg_annealer.get_mc_sim())
    cg_annealer.registerObserver(struct_obs)
    cg_annealer.registerObserver(energy_obs)

    # Run Annealer
    cg_annealer.run_schedule()
    min_pose = cg_annealer._cg_mc_sim.get_minimum_energy_pose()
    print("Writing structure to:")
    print(job.fn("minimum.pdb"))
    min_pose.dump_pdb(job.fn("minimum.pdb"))

    end = time.time()

    t_rep = end - start
    print(t_rep, "seconds")
    job.data['timing'] = t_rep
def main():

    cgpy.change_parameters.changeAtomParameters(
        {"CG1": ['X', 1.5, 0.2]},
        atom_types_path="parameters/atom_properties.txt",
        mm_atom_types_path="parameters/mm_atom_type_sets/mm_atom_properties.txt"
    )

    # Initialize CG_PyRosetta with extra mm_types
    cgpy.init()
    # cgpy.pyrosetta.init()
    # CG MC Annealer Parameters
    params = cgpy.CG_monte_carlo.\
        CGMonteCarloAnnealerParameters(n_inner=100,
                                    t_init=5,
                                    anneal_rate=0.9,
                                    n_anneals=3,
                                    annealer_criteron=cgpy.CG_monte_carlo.Repeat10Convergence,
                                    traj_out = "testing.pdb",
                                    mc_output = True,
                                    mc_traj = False,
                                    out_freq = 10,
                                    )
    # Energy Function
    energy_function = cgpy.CG_monte_carlo.\
        EnergyFunctionFactory().build_energy_function(
            {
                "mm_twist": 1,
                "mm_bend": 1,
                "fa_atr": 1,
                "fa_rep": 1,
                "fa_intra_rep": 1,
                "fa_intra_atr": 1
            }
        )

    # Pose to be folded
    pose = cgpy.pyrosetta.pose_from_sequence(
        "X[CG11x3:CGLower]X[CG11x3]X[CG11x3]X[CG11x3]X[CG11x3:CGUpper]")
    change_lengths = cgpy.CG_movers.setBondLengths(pose, {
        "BB1 BB2": 1,
        "BB2 BB3": 1,
        "BB3 BB1": 1
    })
    change_lengths.apply(pose)
    print(energy_function(pose))
    # exit()

    # Build Minimizer
    mini = cgpy.pyrosetta.rosetta.protocols.minimization_packing.MinMover()
    mini.min_type('lbfgs_armijo_nonmonotone')
    mini.score_function(energy_function)

    # MoveMap for Minimizer
    movemap = cgpy.pyrosetta.MoveMap()
    movemap.set_bb_true_range(1, pose.size())
    movemap.set_branches(True)
    movemap.set(cgpy.pyrosetta.rosetta.core.id.THETA, True)
    movemap.set(cgpy.pyrosetta.rosetta.core.id.PHI, True)

    # Insert MoveMap into Minimizer
    mini.movemap(movemap)

    # import pdb
    # pdb.set_trace()

    mini.apply(pose)

    # Build Sequence Mover for MC object
    sequence_mover_fct = cgpy.CG_monte_carlo.SequenceMoverFactory(
        pose, {"mini": mini})
    sequence_mover = sequence_mover_fct.build_seq_mover({
        "small_dihe": 1,
        "small_angle": 1,
        "mini": 20
    })

    # Initialize Annealer
    cg_annealer = cgpy.CG_monte_carlo.CGMonteCarloAnnealer(
        seq_mover=sequence_mover,
        score_function=energy_function,
        pose=pose,
        param_file_object=params)

    min_energy_confs = cgpy.CG_monte_carlo.MinEnergyConfigObserver(
        cg_annealer.get_mc_sim())

    cg_annealer.registerObserver(min_energy_confs)

    # Run Annealer
    cg_annealer.run_schedule()
    min_pose = cg_annealer._cg_mc_sim.get_minimum_energy_pose()
    cg_annealer._cg_mc_sim.pymol.apply(min_pose)

    # Extract all structures
    print("There are a total of", len(min_energy_confs.structures),
          "structures")
    print("Energies:")

    if not os.path.exists("structures"):
        os.mkdir("structures")

    for i in range(len(min_energy_confs.energies)):
        print("Structure:", i, "Energy:", min_energy_confs.energies[i])
        min_energy_confs.structures[i].dump_pdb("structures/structure_" +
                                                str(i) + ".pdb")

    # Extract bottom 20 structures
    sorted_structures = [
        pose for _, pose in sorted(
            zip(min_energy_confs.energies, min_energy_confs.structures))
    ]
    if not os.path.exists("50_min_structures"):
        os.mkdir("50_min_structures")
    for i, p in enumerate(sorted_structures[:50]):
        p.dump_pdb("50_min_structures/structure_" + str(i) + ".pdb")

    # Save output config object
    with open("min_energy_configs.pkl", "wb") as f:
        pickle.dump(min_energy_confs, f, pickle.HIGHEST_PROTOCOL)
Beispiel #3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--model",
        required=False,
        help="Type of model that you would like to generate \
                             random distribution of structures and energy for",
        type=str,
        default="CG11x3",
    )
    parser.add_argument(
        "--mer",
        required=False,
        help="Number of monomers for this model",
        type=int,
        default=5,
    )
    parser.add_argument(
        "--kt",
        required=True,
        default=100,
        help="kT value used to generate a random ensemble",
        type=int,
    )
    parser.add_argument("--params",
                        required=False,
                        type=str,
                        help="YAML file where specific torsions are defined",
                        default="params.yml")

    parser.add_argument(
        "--e_output",
        required=False,
        type=str,
        default="outputs/random_distribution.npy",
        help="output filename of the energies",
    )
    parser.add_argument(
        "--s_output",
        required=False,
        type=str,
        default="outputs/random_distribution.pdb",
        help="output filename of the energies",
    )

    parser.add_argument(
        "--steps",
        required=False,
        default=1000000,
        type=int,
        help="Number of steps to run the high T simulation",
    )

    parser.add_argument(
        "--stride",
        required=False,
        default=1000,
        type=int,
        help="Number of steps to run the high T simulation",
    )

    # Parse Arguments
    args = parser.parse_args()

    # Get parameters from .yml file
    param_file = open(args.params, 'r')
    params = yaml.load(param_file)
    print(params)

    # for param_type in params:
    #     if param_type == "atoms":
    #         cg_pyrosetta.change_parameters.changeAtomParameters(params["atoms"])
    #     if param_type == "dihedrals":
    #         cg_pyrosetta.change_parameters.changeTorsionParameters(params["dihedrals"])
    #     if param_type == "angles":
    #         cg_pyrosetta.change_parameters.changeAngleParameters(params["angles"])
    #     else:
    #         print("Input YAML file had a key for", param_type+".", "This key is not a valid parameter type for this model.", file=sys.stderr)
    #         print("Ignoring", param_type, "and continuing!", file=sys.stderr)

    cg_pyrosetta.init()

    # Build sequence for folder object
    monomer = "X[" + args.model + "]"
    sequence = monomer * args.mer

    # Build Folder Object
    folder = cg_pyrosetta.CG_folding.CGFoldingAlgorithm(sequence)

    # Change PDBWriter to specific outputs
    folder.PDB_writer.stride(args.stride)
    folder.PDB_writer.file_name(args.s_output)

    # Build MC algorithm to get unfolded ensemble
    folder.build_fold_alg('no_min')
    folder.add_folding_move('no_min', pyrosetta.RepeatMover(folder.small, 10))
    folder.add_folding_move('no_min', folder.PDB_writer)

    # Set kT
    folder.kT = args.kt

    # Run algorithm
    folder.run_folding_alg('no_min', args.steps)

    energy_list = []
    for line in open(args.s_output):
        if "pose" in line:
            # print(line)
            termwise_energy = line.rstrip().split(' ')
            energy_list.append(float(termwise_energy[1]))

        else:
            continue

    np.save(args.e_output, np.array(energy_list))
Beispiel #4
0
def run_mc_simulation(job):
    os.chdir(job.ws)
    cg_pyrosetta.init()
    # Build Annealer Parameters
    annealer_params = cg_pyrosetta.CG_monte_carlo.\
        CGMonteCarloAnnealerParameters(n_inner = 100,
                                       t_init = 5,
                                       anneal_rate = 0.9,
                                       n_anneals = 3,
                                       annealer_criteron = cg_pyrosetta.CG_monte_carlo.Repeat10Convergence,
                                       mc_output = True,
                                       out_freq = 50,
    )

    # Build Energy Function
    energy_function = cg_pyrosetta.CG_monte_carlo.EnergyFunctionFactory(
    ).build_energy_function({
        "mm_twist": 1,
        "mm_bend": 1,
        "fa_atr": 1,
        "fa_rep": 1,
        "fa_intra_rep": 1,
        "fa_intra_atr": 1,
    })

    # Pose to be folded
    pose = cg_pyrosetta.pyrosetta.pose_from_sequence(
        "X[CG31:CGLower]X[CG31]X[CG31]X[CG31]X[CG31:CGUpper]")
    change_lengths = cg_pyrosetta.CG_movers.setBondLengths(
        pose, {
            "BB1 BB2": job.sp.bb_length,
            "BB2 BB3": job.sp.bb_length,
            "BB3 BB1": job.sp.bb_length
        })
    change_lengths.apply(pose)

    # Build Minimizer
    mini = cg_pyrosetta.pyrosetta.rosetta.protocols.minimization_packing.MinMover(
    )
    mini.min_type('lbfgs_armijo_nonmonotone')
    mini.score_function(energy_function)

    movemap = cg_pyrosetta.pyrosetta.MoveMap()
    movemap.set_bb_true_range(1, pose.size())
    movemap.set_branches(True)
    movemap.set(cg_pyrosetta.pyrosetta.rosetta.core.id.THETA, True)
    movemap.set(cg_pyrosetta.pyrosetta.rosetta.core.id.PHI, True)

    # print("Using the following MoveMap:")
    # print(movemap)

    mini.movemap(movemap)

    # Build Sequence Mover for MC object
    sequence_mover_factory = cg_pyrosetta.CG_monte_carlo.SequenceMoverFactory(
        pose, {"mini": mini})
    sequence_mover = sequence_mover_factory.build_seq_mover({
        "small_dihe": 1,
        "small_angle": 1,
        "mini": 1,
    })

    cg_annealer = cg_pyrosetta.CG_monte_carlo.CGMonteCarloAnnealer(
        seq_mover=sequence_mover,
        score_function=energy_function,
        pose=pose,
        param_file_object=annealer_params)

    # Setup Configuration/Energy observer for saving minimum energy structures
    min_energy_confs = cg_pyrosetta.CG_monte_carlo.MinEnergyConfigObserver(
        cg_annealer.get_mc_sim())
    cg_annealer.registerObserver(min_energy_confs)

    # Run Annealer
    cg_annealer.run_schedule()
    min_pose = cg_annealer._cg_mc_sim.get_minimum_energy_pose()
    print("Writing structure to:")
    print(job.fn("minimum.pdb"))
    min_pose.dump_pdb(job.fn("minimum.pdb"))