PyRosetta (9) FastRelax

PyRosetta (9): FastRelax

Initialization(Same as the “Packing” chapter)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#Python
from pyrosetta import *
from pyrosetta.rosetta import *
from pyrosetta.teaching import *

#Core Includes
from pyrosetta.rosetta.core.kinematics import MoveMap
from pyrosetta.rosetta.core.kinematics import FoldTree
from pyrosetta.rosetta.core.pack.task import TaskFactory
from pyrosetta.rosetta.core.pack.task import operation
from pyrosetta.rosetta.core.simple_metrics import metrics
from pyrosetta.rosetta.core.select import residue_selector as selections
from pyrosetta.rosetta.core import select
from pyrosetta.rosetta.core.select.movemap import *

#Protocol Includes
from pyrosetta.rosetta.protocols import minimization_packing as pack_min
from pyrosetta.rosetta.protocols import relax as rel
from pyrosetta.rosetta.protocols.antibody.residue_selector import CDRResidueSelector
from pyrosetta.rosetta.protocols.antibody import *
from pyrosetta.rosetta.protocols.loops import *
from pyrosetta.rosetta.protocols.relax import FastRelax
1
2
init('-use_input_sc -input_ab_scheme AHo_Scheme -ignore_unrecognized_res \
-ignore_zero_occupancy false -load_PDB_components false -relax:default_repeats 2 -no_fconfig')

FastRelax class

Overview

As is descibe above,

Default FastRelax is:

5 cycles of {[packing + minimization] * n_ramping_of_fa_rep}.

TaskFactory

We can specify a TaskFactoryto instruct packing (Refer to Side Chain Packing and Design for “packing”, “TaskFactory” and “PackerTask”).

MoveMapFactory

We can pass in a MoveMapFactory object to instrucrt minimization (Refer to Backbone Folding for “minimization” and “movemap”).

FastRelax is Stochastic, which means that it contains ramdom processes and is not deterministic.

Score function

FastRelax needs a score function for both packing and minimization. The default is “ref_2015”.

Default Instantiation & Configurations

WARNING: If you apply a FastRelaxobject to a pose without specifying a score function, the kernel would crash.

1
2
3
4
5
6
7
8
9
10
my_fr = FastRelax() # Instantiation a `FastRelax` object named `my_fr`

my_scorefxn = get_score_function() # A default ref2015 full atom score function

my_fr.set_scorefxn(my_scorefxn)

#FastRelax takes a very long time,
#but we can decrease the amount of minimization cycles by using:
# fr.max_iter(100)
#(Only recommended for cartesian)

Customized Setup of Regional FastRelax

1
2
3
4
5
6
7
8
9
10
11
12
13
# Assume that we have a `FastRelax` object called `my_fr`
# Assume that we have a `MoveMapFactory` object called `my_mmf`
my_fr.set_movemap_factory(my_mmf)

# Assume that we have a `TaskFactory` object called `pack_cdrs_and_neighbors_tf`
my_fr.set_task_factory(pack_cdrs_and_neighbors_tf)

# Assume that we have a default ref2015 full atom score function
my_fr.set_scorefxn(my_scorefxn)

# Assume that we have a `Pose` object called `my_pose`
# Finally, we can apply the `my_fr` to `my_pose`:
my_fr.apply(my_pose)

Apply FastRelaxto a Poseobject

1
2
# Assume that we have a `Pose` object named `my_pose`
my_fr.apply(my_pose)

TaskFactory class

Introduction

Note | PyRosetta Basics (7): Side Chain Packing and Design

Set selectors in packing and design through TaskFactory.

Instances ofPackerTaskclass are used to determine the specific tasks in packing.

TaskFactoryis the prototype of PackerTask class.

Every time the protein is packed for a single round, the TaskFactory will generate what is called the PackerTask.

We do NOT use PackerTask directly.

We can set TaskOperationsto the TaskFactory, and all PackerTaskgenerated by thisTaskFactory will be controlled by these TaskOpterations.

So bascically a TaskFactoryobject can be seen as “a list of task operations”.

Some TaskOperationscan respond to changes in the pose, so we do not set TaskOperations directly to PackerTaskin each packing step.

Instead, we use TaskFactoryto dynamically generate PackerTaskobjects in each round, behind the scene.

Instantiation & Configuration(push_back)

1
2
3
4
5
6
7
my_tf = TaskFactory() # Create an empty task factory

# And set task operations to the task factory:
my_tf.push_back(operation.InitializeFromCommandline())
# IMPORTANT! Use configurations declared in `init()`
my_tf.push_back(operation.RestrictToRepacking())
# Disable "designing of side chains" so that the sequence will be untouched

Regional Packing: selections & PreventRepackingRLT

We can also use selectionsfor regional packing

E.g. Selecting CDR H1 region of an antibody

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Selecting CDR H1 region of an antibody
cdr_selector = CDRResidueSelector() # Instantiation
cdr_selector.set_cdr(h1) # Select the H1 loop only
# the namespace of `h1` was imported by commandlines that were passed to init()

# Selecting the Neiborhood (in 3D space) residue of CDR H1
nbr_selector = selections.NeighborhoodResidueSelector() # Instantiation
nbr_selector.set_focus_selector(cdr_selector) # Find neighbors of cdr_selector (which is the H1 loop)
nbr_selector.set_include_focus_in_subset(True) # Include the H1 loop in `nbr_selector` as well

#"RLT": Residue Level Task Operation
prevent_repacking_rlt = operation.PreventRepackingRLT() # Instantication

prevent_subset_repacking = operation.OperateOnResidueSubset(prevent_repacking_rlt, nbr_selector, True)
#`True` indicates here that we are flipping the selection.
# So that we are turning off everything but the CDR and its neighbors.

# Assume that we have a `TaskFactory` named `my_tf`
my_tf.push_back(prevent_subset_repacking)

TaskFacrtory Methods

Add operations: TaskFacrtory.push_back

1
2
3
my_tf.push_back(my_operation) 
# E.g.
my_tf.push_back(operation.InitializeFromCommandline())
1
2
3
4
5
6
7
8
# A standard setting:

## Take command line settings from init()
tf.push_back(operation.InitializeFromCommandline())
## Include the current rotamer of the pose
tf.push_back(operation.IncludeCurrent())
## Disallow repacking Disulfides
tf.push_back(operation.NoRepackDisulfides())

pyrosetta.rosetta.core.pack.task.operation

Clear all operations: TaskFacrtory.clear

1
my_tf.clear()

Preview of task applied to a Poseobject

1
2
3
4
5
6
7
8
9
10
11
12
# Preview a task generated by a `TaskFactory` object
task_design = my_tf.create_task_and_apply_taskoperations( my_pose )

# Print numbers of packable residues
print("Num packable residues: ", task_design.num_to_be_packed())

# Print numbers of designable residues
num_designable = 0
for i in range( 1, my_pose.size() + 1 ):
if( task_design.design_residue( i ) ):
num_designable += 1;
print( "Num designable residues: ", num_designable )

Set Residue file (Resfile) for a TaskFactoryobject

Resfile Syntax: Resfile syntax and conventions

1
tf.push_back(pyrosetta.rosetta.core.pack.task.operation.ReadResfile("./path/to/my_resfile"))

Resources

https://graylab.jhu.edu/PyRosetta.documentation/pyrosetta.rosetta.core.pack.task.operation.html

MoveMapFactory class

Introduction to MoveMapFactory class

Set restrictions to degree of freedom in Minimization through a MoveMapFactory object.

MoveMapFactoryis the prototype of MoveMap.

MoveMap instructs a mover; in FastRelax, it instructs minimization mover.

The default is to have everything OFF first, and turn specific things on.

Degree of freedom settings (to a specific region of the pose) requires:

  1. pre-defined residue selectors
  2. the pose

So residue selectors are designed to be passed to the MoveMapFactory.

pyrosetta.rosetta.core.select.movemap.MoveMapFactory()

Note | PyRosetta Basics (6): Movers for Backbone Folding

MoveMapFactories (RosettaScripts)

Instantiation

1
2
3
4
5
6
7
8
9
10
11
12
# Establish Residue Selector
cdr_selector = CDRResidueSelector()
cdr_selector.set_cdr(h1)
# h1 is a Enum imported when we imported the antibody namespace

# Instantiate a `MoveMapFactory` object named "my_mmf"
my_mmf = MoveMapFactory()

# Then setup `my_mmf`
# E.g.
mmf.all_bb(setting=True)
mmf.all_chi(setting=True)

MoveMapFactory methods

Setup the MoveMapFactoryobject

Pass a Boolean to setting prop

1
2
3
4
5
6
7
8
mmf.all_bb(setting=True)
mmf.all_bondangles(setting=True)
mmf.all_bondlengths(setting=True)
mmf.all_chi(setting=True)
# Allow `jumps` to move (For the definition of `jump`, see FoldTree terms)
mmf.all_jumps(setting=True)
# Use xyz (Cartesian space)
mmf.set_cartesian(setting=True)

Pass Enums and selectors

1
2
3
4
5
'''
mm_enable and mm_disable are Enums (numbered variables)
that come when we import the MMF
'''
mmf.add_bb_action(mm_enable, cdr_selector)

Settings for individual residue

1
2
3
4
5
6
7
8
9
10
'''
If needed, you could turn off bb and chi torsions
for individual residues like this:
'''
# subset_to_minimize is a list (vector) of residue locations

for i in range(1, pose.size() + 1):
if (not subset_to_minimize[i]):
mm.set_bb(i, False)
mm.set_chi(i, False)

Check the MoveMapFactory settings

Based on the MoveMapFactory, we can create a MoveMapobject from a Poseobject, and thus we can check the settings.

1
2
3
4
5
6
# Instantiate a `MoveMap` object from `my_mmf`
# We need to pass in a `Pose` object (`my_pose`)
my_mm = my_mmf.create_movemap_from_pose(my_pose)

# Inspect my_mm
print(my_mm)

Optimization through MoveMapFactory

Basic Setup may cause large conformation shifts that we don’t want.

We can tackle this problem either by using a different score function, or by customizing the FoldTree.

Cartesian-space refinement ref2015_cart

Cartesian-space: the space descibed in X Y Z coordinates.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Create score function specified for Cartesian
cart_sf = create_score_function("ref2015_cart")

# Assume that we have a `MoveMapFactory` object called `my_mmf`
my_mmf.set_cartesian(True) # Turn "Cartesian mode" on.

# Assume that we have a `FastRelax` object called `my_fr`
my_fr.set_movemap_factory(my_mmf)

# Use `cart_sf` as the score function for FastRelax
my_fr.set_scorefxn(cart_sf)
my_fr.cartesian(True)
# my_fr.min_type("lbfgs_armijo_nonmonotone")
#This is a general recommendation for cartesian minimization - it lowers the number of maximum cycles.
# More than this only increases time of protocol, but has little effect on energies/structure
my_fr.max_iter(200)

These settings are Cartesian-specifc. They are turned off by default. Turn them off under other circumstances.

1
2
3
4
my_mmf.set_cartesian(False)
my_fr.cartesian(False)
my_fr.max_iter(0) #Reset to default
# my_fr.min_type("dfpmin_armijo_nonmonotone") # This seems to be a legacy thing

Customizing FoldTree (A Classic way)

WARNING: If Cartesian has been turned on, we should turn Cartesian off before using this solution.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Assume that we have a `Pose` object named `my_pose`, and it is an antibody
ab_info = AntibodyInfo(my_pose) # Get antibody-specific information
my_ft = FoldTree() # Instantiate an empty FolTree

# Get CDR H1 loop parameters
# >>> #
start = ab_info.get_CDR_start(h1, my_pose)
stop = ab_info.get_CDR_end(h1, my_pose)
cutpoint = int((stop-start)/2) + start
# <<< #

# Define the loop
cdr_loop = Loop(start, stop, cutpoint)
cdr_loops = Loops()
cdr_loops.add_loop(cdr_loop)

# Setup of `my_ft`
fold_tree_from_loops(my_pose, cdr_loops, my_ft)

my_pose.fold_tree(my_ft)
original_ft = my_pose.fold_tree() # Backup the original fold tree
add_cutpoint_variants(my_pose)

# Create a default full atom score function
scorefxn = get_score_function()

# Add chainbreak term to `scorefxn` so we don't get wacky stuff.
# This term helps keep the peptide closed during bb movement.
scorefxn_ch = scorefxn # Copy the default score function
scorefxn_ch.set_weight(rosetta.core.scoring.chainbreak, 100) # Add chainbreak term

# Assume that we have a `FastRelax` object called `my_fr`
my_fr.set_scorefxn(scorefxn_ch)

# Assume that we have a `MoveMap` object (with basic configurations) called `my_mmf`
my_fr.set_movemap_factory(my_mmf)

my_fr.max_iter(0) #Reset to default
# if it's 0, then we don't set it in the MinMover that FastRelax runs

# Start FastRelax
my_fr.apply(my_pose)

#Reapply the original fold tree
my_pose.fold_tree(original_ft)
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2024-2025 Michael Lau
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信