示例#1
0
    if deltaE > 0:
        P = math.exp(-deltaE / kT)  # probability of accepting move diminishes
        # exponetially with increasing energy
        roll = random.uniform(0.0, 1.0)
        if roll >= P:
            p.assign(last_pose)  # reject pose and reassign previous
            continue

    # if new pose is accepted, store lowest score and associated pose
    if new_score < low_score:
        low_score = new_score
        low_pose.assign(p)

# output files
p.dump_pdb("poly-A_final.pdb")
low_pose.dump_pdb("poly-A_low.pdb")

# Low-Resolution (Centroid) Scoring
ras = pose_from_file("../test/data/workshops/6Q21.clean.pdb")
score2 = get_score_function()
print(score2(ras))
print(ras.residue(5))

switch = SwitchResidueTypeSetMover("centroid")
switch.apply(ras)
print(ras.residue(5))

score3 = create_score_function("score3")
print(score3(ras))

switch2 = SwitchResidueTypeSetMover("fa_standard")
示例#2
0
def movemap(pose, PDB_out=False):
    """
    Demonstrates the syntax necessary for basic usage of the MoveMap object
        performs these changes with a demonstrative backbone minimization
        using  <pose>  and writes structures to PDB files if  <PDB_out>  is True

    """

    #########
    # MoveMap
    # a MoveMap encodes what data is allowed to change in a Pose, referred to as
    #    its degrees of freedom
    # a MoveMap is separate from a Pose and is usually required by a Mover so
    #    that the correct degrees of freedom are manipulated, in this way,
    #    MoveMap and Pose objects often work in parallel
    # several MoveMap's can correspond to the same Pose
    # a MoveMap stores information on a per-residue basis about the
    #    backbone ({phi, psi, omega}) and chi ({chi_i}) torsion angle sets
    #    the MoveMap can only set these sets of torsions to True or False, it
    #    cannot set freedom for the individual angles (such as phi free and psi
    #    fixed)
    # the MoveMap has no upper-limit on its residue information, it defaults to
    #    all residues (up to residue 99999999) backbone and chi False
    # you can view the MoveMap per-residue torsion settings by using the
    #    MoveMap.show( Pose.total_residue() ) method (the input argument is the
    #    highest residue to output, it does not support viewing a range)
    pose_move_map = MoveMap()
    # change all backbone torsion angles
    pose_move_map.set_bb(True)
    # change all chi angle torsion angles (False by default)
    pose_move_map.set_chi(False)
    # change a single backbone torsion angles
    #pose_move_map.set_bb(1, True)    # example syntax
    # change a single residue's chi torsion angles
    #pose_move_map.set_chi(1, True)    # example syntax
    pose_move_map.show(pose.total_residue())

    # perform gradient based minimization on the "median" residues, this
    #    method (MinMover) determines the gradient of an input pose using a
    #    ScoreFunction for evaluation and a MoveMap to define the degrees of
    #    freedom
    # create a standard ScoreFunction
    scorefxn = get_fa_scorefxn(
    )  #  create_score_function_ws_patch('standard', 'score12')
    # redefine the MoveMap to include the median half of the residues
    # turn "off" all backbone torsion angles
    pose_move_map.set_bb(False)  # reset to backbone False
    # turn "on" a range of residue backbone torsion angles
    pose_move_map.set_bb_true_range(int(pose.total_residue() / 4),
                                    int(pose.total_residue() * 3 / 4))
    # create the MinMover
    minmover = protocols.minimization_packing.MinMover()
    minmover.score_function(scorefxn)
    minmover.movemap(pose_move_map)

    # create a copy of the pose
    test_pose = Pose()
    test_pose.assign(pose)
    # apply minimization
    scorefxn(test_pose)  # to prevent verbose output on the next line

    pymover = PyMOLMover()
    #### uncomment the line below and "comment-out" the two lines below to
    ####    export the structures into different PyMOL states of the same object
    #pymover.keep_history = True    # enables viewing across states

    #### comment-out the line below, changing PDBInfo names tells the
    ####    PyMOLMover to produce new objects
    test_pose.pdb_info().name('original')
    pymover.apply(test_pose)
    print('\nPre minimization score:', scorefxn(test_pose))

    minmover.apply(test_pose)
    if PDB_out:
        test_pose.dump_pdb('minimized.pdb')

    print('Post minimization score:', scorefxn(test_pose))
    #### comment-out the line below
    test_pose.pdb_info().name('minimized')
    pymover.apply(test_pose)
def packer_task(pose, PDB_out=False):
    """
    Demonstrates the syntax necessary for basic usage of the PackerTask object
		performs demonstrative sidechain packing and selected design
		using  <pose>  and writes structures to PDB files if  <PDB_out>
		is True

    """
    # create a copy of the pose
    test_pose = Pose()
    test_pose.assign(pose)

    # this object is contained in PyRosetta v2.0 and above
    pymover = PyMOLMover()

    # create a standard ScoreFunction
    scorefxn = get_fa_scorefxn(
    )  #  create_score_function_ws_patch('standard', 'score12')

    ############
    # PackerTask
    # a PackerTask encodes preferences and options for sidechain packing, an
    #    effective Rosetta methodology for changing sidechain conformations, and
    #    design (mutation)
    # a PackerTask stores information on a per-residue basis
    # each residue may be packed or designed
    # PackerTasks are handled slightly differently in PyRosetta
    ####pose_packer = PackerTask()    # this line will not work properly
    pose_packer = standard_packer_task(test_pose)
    # the pose argument tells the PackerTask how large it should be

    # sidechain packing "optimizes" a pose's sidechain conformations by cycling
    #    through (Dunbrack) rotamers (sets of chi angles) at a specific residue
    #    and selecting the rotamer which achieves the lowest score,
    #    enumerating all possibilities for all sidechains simultaneously is
    #    impractically expensive so the residues to be packed are individually
    #    optimized in a "random" order
    # packing options include:
    #    -"freezing" the residue, preventing it from changing conformation
    #    -including the original sidechain conformation when determining the
    #        lowest scoring conformation
    pose_packer.restrict_to_repacking()  # turns off design
    pose_packer.or_include_current(True)  # considers original conformation
    print(pose_packer)

    # packing and design can be performed by a PackRotamersMover, it requires
    #    a ScoreFunction, for optimizing the sidechains and a PackerTask,
    #    setting the packing and design options
    packmover = protocols.minimization_packing.PackRotamersMover(
        scorefxn, pose_packer)

    scorefxn(pose)  # to prevent verbose output on the next line
    print('\nPre packing score:', scorefxn(test_pose))
    test_pose.pdb_info().name('original')  # for PyMOLMover
    pymover.apply(test_pose)

    packmover.apply(test_pose)
    print('Post packing score:', scorefxn(test_pose))
    test_pose.pdb_info().name('packed')  # for PyMOLMover
    pymover.apply(test_pose)
    if PDB_out:
        test_pose.dump_pdb('packed.pdb')

    # since the PackerTask specifies how the sidechains change, it has been
    #    extended to include sidechain constitutional changes allowing
    #    protein design, this method of design is very similar to sidechain
    #    packing; all rotamers of the possible mutants at a single residue
    #    are considered and the lowest scoring conformation is selected
    # design options include:
    #    -allow all amino acids
    #    -allow all amino acids except cysteine
    #    -allow specific amino acids
    #    -prevent specific amino acids
    #    -allow polar amino acids only
    #    -prevent polar amino acids
    #    -allow only the native amino acid
    # the myriad of packing and design options can be set manually or, more
    #    commonly, using a specific file format known as a resfile
    #    resfile syntax is explained at:
    #    http://www.rosettacommons.org/manuals/archive/rosetta3.1_user_guide/file_resfiles.html
    # manually setting deign options is tedious, the methods below are handy
    #    for creating resfiles
    # mutate the "middle" residues
    center = test_pose.total_residue() // 2
    specific_design = {}
    for i in range(center - 2, center + 3):
        specific_design[i] = 'ALLAA'
    # write a resfile to perform these mutations
    generate_resfile_from_pose(test_pose,
                               'sample_resfile',
                               False,
                               specific=specific_design)

    # setup the design PackerTask, use the generated resfile
    pose_design = standard_packer_task(test_pose)
    rosetta.core.pack.task.parse_resfile(test_pose, pose_design,
                                         'sample_resfile')
    print(pose_design)

    # prepare a new structure
    test_pose.assign(pose)

    # perform design
    designmover = protocols.minimization_packing.PackRotamersMover(
        scorefxn, pose_design)
    print(
        '\nDesign with all proteogenic amino acids at (pose numbered)\
        residues', center - 2, 'to', center + 2)
    print('Pre-design score:', scorefxn(test_pose))
    print( 'Pre-design sequence: ...' + \
        test_pose.sequence()[center - 5:center + 4] + '...' )

    designmover.apply(test_pose)  # perform design
    print('\nPost-design score:', scorefxn(test_pose))
    print( 'Post-design sequence: ...' + \
        test_pose.sequence()[center - 5:center + 4] + '...' )
    test_pose.pdb_info().name('designed')  # for PyMOLMover
    pymover.apply(test_pose)
    if PDB_out:
        test_pose.dump_pdb('designed.pdb')
示例#4
0
            chi=designable.extend(repackable))

    if test_run:
        fd.rounds = 1

    print(fd.movemap)
    print(fd.task_factory)
    fd.apply()

    # Create new pose from input file for comparison
    input_pose = pose_from_file(pdbpath)
    #input_pose = pose_from_file(workspace.input_pdb_path)
    # Calculate several different types of RMSD
    ca_rmsd = CA_rmsd(fd.pose, input_pose)
    all_atom_rmsd = all_atom_rmsd(fd.pose, input_pose)

    filters = workspace.get_filters(fd.pose,
            task_id=job_info['task_id'], score_fragments=False,
            test_run=test_run)
    filters.run_filters()

    # Add RMSDs as extra metrics, which will be printed at the end of
    # the PDB file.
    setPoseExtraScore(fd.pose, 'EXTRA_METRIC_CA_RMSD', ca_rmsd)
    setPoseExtraScore(fd.pose, 'EXTRA_METRIC_AllAtom_RMSD', all_atom_rmsd)

    # Save final pose as a pdb file.
    input_name = os.path.basename(pdbpath).split(".")[0]
    out = workspace.output_prefix(job_info) + input_name + workspace.output_suffix(job_info) + '.pdb.gz'
    pose.dump_pdb(out)
示例#5
0
def interface_ddG(pose,
                  mutant_position,
                  mutant_aa,
                  movable_jumps,
                  scorefxn='',
                  cutoff=8.0,
                  out_filename=''):
    # 1. create a reference copy of the pose
    wt = Pose()  # the "wild-type"
    wt.assign(pose)

    # 2. setup a specific default ScoreFunction
    if not scorefxn:
        # this is a modified version of the scoring function discussed in
        #    PNAS 2002 (22)14116-21, without environment dependent hbonding
        scorefxn = ScoreFunction()
        scorefxn.set_weight(fa_atr, 0.44)
        scorefxn.set_weight(fa_rep, 0.07)
        scorefxn.set_weight(fa_sol, 1.0)
        scorefxn.set_weight(hbond_bb_sc, 0.5)
        scorefxn.set_weight(hbond_sc, 1.0)

    # 3. create a copy of the pose for mutation
    mutant = Pose()
    mutant.assign(pose)

    # 4. mutate the desired residue
    # the pack_radius argument of mutate_residue (see below) is redundant
    #    for this application since the area around the mutation is already
    #    repacked
    mutant = mutate_residue(mutant, mutant_position, mutant_aa, 0.0, scorefxn)

    # 5. calculate the "interaction energy"
    # the method calc_interaction_energy is exposed in PyRosetta however it
    #    does not alter the protein conformation after translation and may miss
    #    significant interactions
    # an alternate method for manually separating and scoring is provided called
    #    calc_binding_energy (see Interaction Energy vs. Binding Energy below)
    wt_score = calc_binding_energy(wt, scorefxn, mutant_position, cutoff)
    mut_score = calc_binding_energy(mutant, scorefxn, mutant_position, cutoff)
    #### the method calc_interaction_energy separates an input pose by
    ####    500 Angstroms along the jump defined in a Vector1 of jump numbers
    ####    for movable jumps, a ScoreFunction must also be provided
    #### if setup_foldtree has not been applied, calc_interaction_energy may be
    ####    wrong (since the jumps may be wrong)
    #wt_score = calc_interaction_energy(wt, scorefxn, movable_jumps)
    #mut_score = calc_interaction_energy(mutant, scorefxn, movable_jumps)
    ddg = mut_score - wt_score

    # 6. output data (optional)
    # -export the mutant structure to PyMOL (optional)
    mutant.pdb_info().name(pose.sequence()[mutant_position - 1] +
                           str(pose.pdb_info().number(mutant_position)) +
                           mutant.sequence()[mutant_position - 1])
    pymover = PyMOLMover()
    scorefxn(mutant)
    pymover.apply(mutant)
    pymover.send_energy(mutant)

    # -write the mutant structure to a PDB file
    if out_filename:
        mutant.dump_pdb(out_filename)

    return ddg