def __init__(self, pose_init, niter, ntraj, use_criterion, annealing=False, max_add=25, kT0=100): self.trajectories = [] self.final_energies = np.zeros(ntraj) self.ntraj = ntraj self.niter = niter pose = pose_init() # movers needed to convert to centroid and full atom movers = { "pmover": PyMOLMover(), "centroid": SwitchResidueTypeSetMover("centroid"), "fa_mover": SwitchResidueTypeSetMover("fa_standard") } # initialise trajectories with clone of initial pose for i in range(ntraj): tr = Trajectory(i, pose.clone(), movers, niter, use_criterion, annealing, max_add, kT0) tr.set_score_fn(tr.centroid_score) self.trajectories.append(tr)
def pep_run(decoy_name, n_decoys, pose, sf='docking', pymol_ip_addr=None): """ Tested score function is 'docking' not sure if this is the best. Is there a way to run this in a distributed fashion? Each decoy takes ~3 minutes on my machine. """ if pymol_ip_addr: pmm = PyMOLMover(pymol_ip_addr, 65000) #enter the IP that pymol displays on startup pmm.keep_history(True) # Score function and starting PDB sf = create_score_function(sf) # no idea what this sf is... #pose = pose_from_pdb(pdb) # Creating FlexPepDock protocol using init options fpdock = FlexPepDockingProtocol() jd = PyJobDistributor(decoy_name, n_decoys, sf) while not jd.job_complete: pp = Pose() pp.assign(pose) fpdock.apply(pp) if pymol_ip_addr: pmm.apply(pp) jd.output_decoy( pp) # this will output a PDB file, which is not really necessary.
################################################################## ################### MUTATE PROTEIN ############################### ################################################################## # make score function scorefxn = get_fa_scorefxn() # mutate protein print(fa_working.pdb_info().pdb2pose('H', 12)) mutater = pyrosetta.rosetta.protocols.simple_moves.MutateResidue() mutater.set_target(386) mutater.set_res_name('PRO') mutater.apply(fa_working) # see in PyMOL pymol = PyMOLMover() pymol.pymol_name('mutated_superantigen') pymol.apply(fa_working) ################################################################## ################### RELAX LOCALLY ################################ ################################################################## # relax pose, store lowest energy # (i.e. import fast relax method from lecture7) # task factory, what to design, where and how... # (dock mcm protocol, get interface residues) # interface energy optimization from fast_relax_function import * fast_relax(fa_working, fast_relax_rounds=1)
def pose_scoring(pose, display_residues = []): """ Extracts and displays various score evaluations on the input <pose> and its <display_residues> including: total score score term evaluations per-residue score radius of gyration (approximate) """ # this object is contained in PyRosetta v2.0 and above # create a PyMOLMover for exporting structures directly to PyMOL pymover = PyMOLMover() # 1. score the pose using the default full-atom (fa) ScoreFunction # a ScoreFunction is essentially a list of weights indicating which # ScoreTypes are "on" and how they are scaled when summed together # ScoreTypes define what scoring methods are performed on the pose # some ScoreTypes are centroid or fullatom specific, others are not # there are (at least) 5 ways to obtain the general fullatom ScoreFunction # the 1st (a) and 2nd (b) methods are only present since PyRosetta v2.0 # # a. this method returns the hard-coded set of weights for the standard # fullatom ScoreFunction, which is currently called "ref2015" fa_scorefxn = get_fa_scorefxn() # b. this method returns a ScoreFunction with its weights set based on # files stored in the database/scoring/weights (.wts files) full_scorefxn = create_score_function('ref2015') # c. this method sets the weights based on 'ref2015.wts' and then # corrects them based on 'docking.wts_patch' ws_patch_scorefxn = create_score_function('ref2015', 'docking') # create_score_function_ws_patch('ref2015', 'docking') # d. this method returns a ScoreFunction with its weights set by loading # weights from 'ref2015' followed by an adjustment by setting # weights from 'docking.wts_patch' patch_scorefxn = create_score_function('ref2015') patch_scorefxn.apply_patch_from_file('docking') # e. here an empty ScoreFunction is created and the weights are set manually scorefxn = ScoreFunction() scorefxn.set_weight(core.scoring.fa_atr, 0.800) # full-atom attractive score scorefxn.set_weight(core.scoring.fa_rep, 0.440) # full-atom repulsive score scorefxn.set_weight(core.scoring.fa_sol, 0.750) # full-atom solvation score scorefxn.set_weight(core.scoring.fa_intra_rep, 0.004) # f.a. intraresidue rep. score scorefxn.set_weight(core.scoring.fa_elec, 0.700) # full-atom electronic score scorefxn.set_weight(core.scoring.pro_close, 1.000) # proline closure scorefxn.set_weight(core.scoring.hbond_sr_bb, 1.170) # short-range hbonding scorefxn.set_weight(core.scoring.hbond_lr_bb, 1.170) # long-range hbonding scorefxn.set_weight(core.scoring.hbond_bb_sc, 1.170) # backbone-sidechain hbonding scorefxn.set_weight(core.scoring.hbond_sc, 1.100) # sidechain-sidechain hbonding scorefxn.set_weight(core.scoring.dslf_fa13, 1.000) # disulfide full-atom score scorefxn.set_weight(core.scoring.rama, 0.200) # ramachandran score scorefxn.set_weight(core.scoring.omega, 0.500) # omega torsion score scorefxn.set_weight(core.scoring.fa_dun, 0.560) # fullatom Dunbrack rotamer score scorefxn.set_weight(core.scoring.p_aa_pp, 0.320) scorefxn.set_weight(core.scoring.ref, 1.000) # reference identity score # ScoreFunction a, b, and e above have the same weights and thus return # the same score for an input pose. Likewise, c and d should return the # same scores. # 2. output the ScoreFunction evaluations #ws_patch_scorefxn(pose) # to prevent verbose output on the next line print( '='*80 ) print( 'ScoreFunction a:', fa_scorefxn(pose) ) print( 'ScoreFunction b:', full_scorefxn(pose) ) print( 'ScoreFunction c:', ws_patch_scorefxn(pose) ) print( 'ScoreFunction d:', patch_scorefxn(pose) ) print( 'ScoreFunction e:', scorefxn(pose) ) pose_score = scorefxn(pose) # 3. obtain the pose Energies object and all the residue total scores energies = pose.energies() residue_energies = [energies.residue_total_energy(i) for i in range(1, pose.total_residue() + 1)] # 4. obtain the non-zero weights of the ScoreFunction, active ScoreTypes weights = [core.scoring.ScoreType(s) for s in range(1, int(core.scoring.end_of_score_type_enumeration) + 1) if scorefxn.weights()[core.scoring.ScoreType(s)]] # 5. obtain all the pose energies using the weights list # Energies.residue_total_energies returns an EMapVector of the unweighted # score values, here they are multiplied by their weights # remember when performing individual investigation, these are the raw # unweighted score! residue_weighted_energies_matrix = [ [energies.residue_total_energies(i)[w] * scorefxn.weights()[w] for i in range(1, pose.total_residue() + 1)] for w in weights] # Unfortunately, hydrogen bonding scores are NOT stored in the structure # returned by Energies.residue_total_energies # 6. hydrogen bonding information must be extracted separately pose_hbonds = core.scoring.hbonds.HBondSet() core.scoring.hbonds.fill_hbond_set( pose , False , pose_hbonds ) # 7. create a dictionary with the pose residue numbers as keys and the # residue hydrogen bonding information as values # hydrogen bonding information is stored as test in the form: # (donor residue) (donor atom) => (acceptor residue) (accecptor atom) |score hbond_dictionary = {} for residue in range(1, pose.total_residue() + 1): hbond_text = '' for hbond in range(1, pose_hbonds.nhbonds() + 1): hbond = pose_hbonds.hbond(hbond) acceptor_residue = hbond.acc_res() donor_residue = hbond.don_res() if residue == acceptor_residue or residue == donor_residue: hbond_text += str(donor_residue).ljust(4) + ' ' + \ str(pose.residue(donor_residue).atom_name(\ hbond.don_hatm() )).strip().ljust(4) + \ ' => ' + str(acceptor_residue).ljust(4) + ' ' + \ str(pose.residue(acceptor_residue).atom_name(\ hbond.acc_atm() )).strip().ljust(4) + \ ' |score: ' + str(hbond.energy()) + '\n' hbond_dictionary[residue] = hbond_text # 8. approximate the radius of gyration # there is an rg ScoreType in PyRosetta for performing this computation so # a ScoreFunction can be made as an Rg calculator, likewise you can # bias a structure towards more or less compact structures using this # NOTE: this is NOT the true radius of gyration for a protein, it uses # the Residue.nbr_atom coordinates to save time, this nbr_atom is the # Residue atom closest to the Residue's center of geometry RadG = ScoreFunction() RadG.set_weight(core.scoring.rg , 1) pose_radg = RadG(pose) # 9. output the pose information # the information is not expressed sequentially as it is produced because # several PyRosetta objects and methods output intermediate information # to screen, this would produce and unattractive output print( '='*80 ) print( 'Loaded from' , pose.pdb_info().name() ) print( pose.total_residue() , 'residues' ) print( 'Radius of Gyration ~' , pose_radg ) print( 'Total Rosetta Score:' , pose_score ) scorefxn.show(pose) # this object is contained in PyRosetta v2.0 and above pymover.apply(pose) pymover.send_energy(pose) # 10. output information on the requested residues for i in display_residues: print( '='*80 ) print( 'Pose numbered Residue' , i ) print( 'Total Residue Score:' , residue_energies[i-1] ) print( 'Score Breakdown:\n' + '-'*45 ) # loop over the weights, extract the scores from the matrix for w in range(len(weights)): print( '\t' + core.scoring.name_from_score_type(weights[w]).ljust(20) + ':\t' ,\ residue_weighted_energies_matrix[w][i-1] ) print( '-'*45 ) # print the hydrogen bond information print( 'Hydrogen bonds involving Residue ' + str(i) + ':' ) print( hbond_dictionary[i][:-1] ) print( '='*80 )
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')
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)
################################################################### ## Loop through and store lowest energy docking pose lowest_energy_pose = Pose() lowest_energy = float('inf') for i in range(3): # rotate and translate superantigen (8 degrees rot, 3 ang trans) pert_mover = rigid_moves.RigidBodyPerturbMover(jump_num, 8, 3) pert_mover.apply(fa_working) # minimize the energy min_mover.apply(fa_working) # score pose print('working pose energy: ') curr_score = scorefxn(fa_working) print(curr_score) # store values if curr_score < lowest_energy: lowest_energy = curr_score ################################################################### # see in PyMOL pymol = PyMOLMover() pymol.keep_history(True) pymol.apply(fa_starting) pymol.apply(fa_working)
def scanning(pdb_filename, partners, mutant_aa='A', interface_cutoff=8.0, output=False, trials=1, trial_output=''): """ Performs "scanning" at an interface within <pdb_filename> between <partners> by mutating relevant residues to <mutant_aa> and repacking residues within <pack_radius> Angstroms, further repacking all residues within <interface_cutoff> of the interface residue, scoring the complex and subtracting the score of a pose with the partners separated by 500 Angstroms. <trials> scans are performed (to average results) with summaries written to <trial_output>_(trial#).txt. Structures are exported to a PyMOL instance. """ # 1. create a pose from the desired PDB file pose = Pose() pose_from_file(pose, pdb_filename) # 2. setup the docking FoldTree and other related parameters dock_jump = 1 movable_jumps = Vector1([dock_jump]) protocols.docking.setup_foldtree(pose, partners, movable_jumps) # 3. create ScoreFuncions for the Interface and "ddG" calculations # the pose's Energies objects MUST be updated for the Interface object to # work normally scorefxn = get_fa_scorefxn() # create_score_function('standard') scorefxn(pose) # needed for proper Interface calculation # setup a "ddG" ScoreFunction, custom weights ddG_scorefxn = ScoreFunction() ddG_scorefxn.set_weight(core.scoring.fa_atr, 0.44) ddG_scorefxn.set_weight(core.scoring.fa_rep, 0.07) ddG_scorefxn.set_weight(core.scoring.fa_sol, 1.0) ddG_scorefxn.set_weight(core.scoring.hbond_bb_sc, 0.5) ddG_scorefxn.set_weight(core.scoring.hbond_sc, 1.0) # 4. create an Interface object for the pose interface = Interface(dock_jump) interface.distance(interface_cutoff) interface.calculate(pose) # 5. create a PyMOLMover for sending output to PyMOL (optional) pymover = PyMOLMover() pymover.keep_history(True) # for multiple trajectories pymover.apply(pose) pymover.send_energy(pose) # 6. perform scanning trials # the large number of packing operations introduces a lot of variability, # for best results, perform several trials and average the results, # these score changes are useful to QUALITATIVELY defining "hotspot" # residues # this script does not use a PyJobDistributor since no PDB files are output for trial in range(trials): # store the ddG values in a dictionary ddG_mutants = {} for i in range(1, pose.total_residue() + 1): # for residues at the interface if interface.is_interface(i) == True: # this way you can TURN OFF output by providing False arguments # (such as '', the default) filename = '' if output: filename = pose.pdb_info().name()[:-4] + '_' +\ pose.sequence()[i-1] +\ str(pose.pdb_info().number(i)) + '->' + mutant_aa # determine the interace score change upon mutation ddG_mutants[i] = interface_ddG(pose, i, mutant_aa, movable_jumps, ddG_scorefxn, interface_cutoff, filename) # output results print('=' * 80) print('Trial', str(trial + 1)) print( 'Mutants (PDB numbered)\t\"ddG\" (interaction dependent score change)' ) residues = list(ddG_mutants.keys() ) # list(...) conversion is for python3 compatbility residues.sort() # easier to read display = [ pose.sequence()[i - 1] + str(pose.pdb_info().number(i)) + mutant_aa + '\t' + str(ddG_mutants[i]) + '\n' for i in residues ] print(''.join(display)[:-1]) print('=' * 80) # write to file f = open(trial_output + '_' + str(trial + 1) + '.txt', 'w') f.writelines(display) f.close() #### alternate output using scanning_analysis (see below), only display #### mutations with "deviant" score changes print('Likely Hotspot Residues') for hotspot in scanning_analysis(trial_output): print(hotspot) print('=' * 80)
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
#! /usr/bin/python # This file simply contains a list of commands copied from a carbohydrates # tutorial/demo that I am writing. ~Labonte from __future__ import print_function import pyrosetta import pyrosetta.rosetta as rosetta from pyrosetta import init, PyMOLMover, pose_from_file, pose_from_sequence from pyrosetta.rosetta import core, protocols init('-constant_seed -include_sugars') import os; os.chdir('.test.output') pm = PyMOLMover() # Linear Oligosaccharides & IUPAC Sequences from rosetta.core.pose import pose_from_saccharide_sequence glucose = pose_from_saccharide_sequence('alpha-D-Glcp') galactose = pose_from_saccharide_sequence('Galp') mannose = pose_from_saccharide_sequence('->3)-a-D-Manp') maltotriose = pose_from_saccharide_sequence('a-D-Glcp-' * 3) isomaltose = pose_from_saccharide_sequence('->6)-Glcp-' * 2) lactose = pose_from_saccharide_sequence('b-D-Galp-(1->4)-a-D-Glcp') pm.apply(isomaltose) pm.apply(glucose)
################################################################## ################### IMPORT MODULES ############################### ################################################################## # import pyrosetta from pyrosetta import * init( "-mh:path:scores_BB_BB motif_dock/xh_16_ -mh:score:use_ss1 false -mh:score:use_ss2 false -mh:score:use_aa1 true -mh:score:use_aa2 true" ) # for docking # setup pymol from pyrosetta import PyMOLMover pymol = PyMOLMover() # import additional modules from pyrosetta.teaching import * import rosetta.protocols.rigid as rigid_moves from rosetta.protocols.minimization_packing import * from pyrosetta import PyMOLMover import numpy as np from rosetta.protocols import minimization_packing as pack_min from rosetta.protocols.relax import FastRelax import matplotlib.pyplot as plt # import and clean pdb (superantigen + TCR + MHC) from pyrosetta.toolbox import cleanATOM cleanATOM("2ICW_MHC.pdb")
def fold_tree(PDB_out=False): """ Demonstrates the syntax necessary for basic usage of the FoldTree object performs these changes with a demonstrative pose example and writes structures to PDB files if <PDB_out> is True """ ########## # FoldTree # a FoldTree encodes the internal coordinate dependencies of a Pose # a Pose object MUST have a FoldTree # the FoldTree allows regions of a pose to become independent, # it is used in many important applications, particularly: # loop modeling: where changes to the conformation of a loop region # should NOT alter the conformation of the entire protein # rigid-body docking: where changes in the position of one docking # partner should not alter the position of the other docking partner # a FoldTree is effectively a list of Edge objects, you can view the Edges # by printing the FoldTree ("print FoldTree") # the length of a FoldTree (FoldTree.size) MUST match the length of its # corresponding Pose (Pose.total_residue) # it is possible to create an improper FoldTree, the method # FoldTree.check_fold_tree returns True if the FoldTree is complete and # usable and False otherwise # some Edge objects are Jumps, indicating a "jump" in the internal # coordinate dependency # when a FoldTree is created, it can accept an optional integer argument # setting the FoldTree to contain a single Edge with a length equal to # the input integer value, the same result is attained by creating an # empty FoldTree (no input arguments) and using the method # FoldTree.simple_tree with an input integer equal to the size of the # FoldTree # 1. create the example pose test_pose = pose_from_sequence('ACDEFGHIKLMNPQRSTVWY' * 3) # 2. setup the jump points, where a jump is anchored, and the cutpoint cutpoint = int(test_pose.total_residue() / 2) # integer division, no decimal low_jump_point = cutpoint - 10 high_jump_point = cutpoint + 10 # the easiest way to create a new complete FoldTree is to use the method # FoldTree.simple_tree to create and empty FoldTree and assign jumps to # it using the method FoldTree.new_jump # the FoldTree constructor is overloaded to accept an input integer # indicating how large to make the FoldTree # 3. create a simple, one jump FoldTree for the pose # a. using FoldTree.new_jump #pose_fold_tree = FoldTree(test_pose.total_residue()) #### these two lines produce the same FoldTree as the one above pose_fold_tree = FoldTree() pose_fold_tree.simple_tree(test_pose.total_residue()) pose_fold_tree.new_jump(low_jump_point, high_jump_point, cutpoint) print('\nThe first FoldTree is proper:', pose_fold_tree.check_fold_tree()) # b. using FoldTree.add_edge # a more difficult method for creating a FoldTree is simply to create it # empty and use the method FoldTree.add_edge to fill the FoldTree with # new Edge data pose_fold_tree = FoldTree() pose_fold_tree.add_edge(1, low_jump_point, -1) pose_fold_tree.add_edge(low_jump_point, cutpoint, -1) pose_fold_tree.add_edge(low_jump_point, high_jump_point, 1) pose_fold_tree.add_edge(high_jump_point, test_pose.total_residue(), -1) pose_fold_tree.add_edge(high_jump_point, cutpoint + 1, -1) print('The second FoldTree is proper:', pose_fold_tree.check_fold_tree()) # demonstrate FoldTree's effect on structure # 4. linearize it for i in range(1, test_pose.total_residue() + 1): test_pose.set_phi(i, -180) test_pose.set_psi(i, 180) test_pose.set_omega(i, 180) # the Pose.fold_tree method is an overloaded getter/setter, # providing it with no input returns the Pose's FoldTree object # providing a FoldTree object as input overwrites the Pose's current # FoldTree with the new one # the FoldTree is set here to prevent problems when "linearizing" test_pose.fold_tree(pose_fold_tree) # this object is contained in PyRosetta v2.0 and above (optional) pymover = PyMOLMover() # 5. change and display the new structures # a. export "linearized" structure test_pose.pdb_info().name('linearized') # for PyMOLMover pymover.apply(test_pose) if PDB_out: test_pose.dump_pdb('linearized.pdb') print('\nlinearized structure output') # b. make an early change test_pose.set_phi(low_jump_point - 10, 50) test_pose.pdb_info().name('pre_jump') # for PyMOLMover pymover.apply(test_pose) # all downstream residues move if PDB_out: test_pose.dump_pdb('pre_jump.pdb') print('pre jump perturbed structure output') # c. make a change in the first edge created by the jump test_pose.set_phi(low_jump_point + 5, 50) test_pose.pdb_info().name('early_in_jump') # for PyMOLMover pymover.apply(test_pose) # residues up to the cutpoint change if PDB_out: test_pose.dump_pdb('early_in_jump.pdb') print('first internal jump edge perturbed structure output') # d. make a change in the second edge created by the jump test_pose.set_phi(high_jump_point - 5, 50) test_pose.pdb_info().name('late_in_jump') # for PyMOLMover pymover.apply(test_pose) # residues down to the cutpoint change if PDB_out: test_pose.dump_pdb('late_in_jump.pdb') print('second internal jump edge perturbed structure output') # e. make a late change test_pose.set_phi(high_jump_point + 10, 50) test_pose.pdb_info().name('post_jump') # for PyMOLMover pymover.apply(test_pose) # all residues downstream move if PDB_out: test_pose.dump_pdb('post_jump.pdb') print('post jump perturbed structure output')
print(pose) print(pose.sequence()) print("Protein has", pose.total_residue(), "residues.") print(pose.residue(500).name()) print(pose.pdb_info().chain(500)) print(pose.pdb_info().number(500)) print(pose.phi(5)) print(pose.psi(5)) print(pose.chi(1, 5)) R5N = AtomID(1, 5) R5CA = AtomID(2, 5) R5C = AtomID(3, 5) print(pose.conformation().bond_length(R5N, R5CA)) print(pose.conformation().bond_length(R5CA, R5C)) from pyrosetta import PyMOLMover pymol = PyMOLMover() pymol.apply(pose) # Calculating energy score print("Calculating energy score of 6Q21 protein") ras = pose_from_pdb("6q21.pdb") print(ras) print(ras.sequence()) from pyrosetta.teaching import * scorefxn = get_fa_scorefxn() print("Score function of 6Q21 protein is :") print(scorefxn) scorefxn2 = ScoreFunction() scorefxn2.set_weight(fa_atr, 1.0) scorefxn2.set_weight(fa_rep, 1.0) print(scorefxn(ras)) scorefxn.show(ras)
from pyrosetta import init, pose_from_file, create_score_function, Pose, MoveMap, PyMOLMover from pyrosetta.rosetta import core, protocols from pyrosetta.teaching import MinMover, SmallMover, ShearMover, TrialMover, MonteCarlo, RepeatMover init(extra_options = "-constant_seed") # WARNING: option '-constant_seed' is for testing only! MAKE SURE TO REMOVE IT IN PRODUCTION RUNS!!!!! import os; os.chdir('.test.output') start = pose_from_file("../test/data/workshops/1YY8.clean.pdb") test = Pose() test.assign(start) start.pdb_info().name("start") test.pdb_info().name("test") pmm = PyMOLMover() pmm.apply(start) pmm.apply(test) pmm.keep_history(True) print( pmm ) # Small and Shear Moves kT = 1.0 n_moves = 1 movemap = MoveMap() movemap.set_bb(True) small_mover = SmallMover(movemap, kT, n_moves) shear_mover = ShearMover(movemap, kT, n_moves) small_mover.angle_max("H", 5) small_mover.angle_max("E", 5)
res_path = sys.argv[2] OUT = sys.argv[3] weight_file = sys.argv[4] from pyrosetta import * from rosetta import * from rosetta.protocols.rigid import * from rosetta.core.scoring import * from pyrosetta import PyMOLMover from rosetta.protocols.rigid import * import pyrosetta.rosetta.protocols.rigid as rigid_moves from pyrosetta.rosetta.protocols.minimization_packing import MinMover init() pmm = PyMOLMover() pmm.keep_history(True) #os.system('mkdir working_dir') working_dir = os.getcwd() #os.system('cd working_dir') def add_cst(pose, resi, resj, lb, up): res_i = pose.pdb_info().pdb2pose('A', res=resi) res_j = pose.pdb_info().pdb2pose('B', res=resj) if res_i != 0 and res_j != 0: atm_i = 'CA' if pose.residue(res_i).name()[0:3] == 'GLY' else 'CB'
ft.add_edge(1, 13, -1) ft.add_edge(13, 19, -1) ft.add_edge(13, 26, 1) ft.add_edge(26, 20, -1) ft.add_edge(26, 116, -1) print(ft) ft.check_fold_tree() pose.fold_tree(ft) for res in (10, 13, 16, 23, 26, 30): pose.set_phi(res, 180) pose.dump_pdb("loop" + str(res) + ".pdb") pmm = PyMOLMover() pmm.apply(pose) # no longer supported: pmm.send_foldtree(pose) # no longer supported: pmm.view_foldtree_diagram(pose, ft) ft.clear() ft.simple_tree(116) ft.new_jump(76, 85, 80) # Cyclic Coordination Descent (CCD) Loop Closure movemap = MoveMap() movemap.set_bb(True) movemap.set_chi(True) loop1 = protocols.loops.Loop(15, 24, 19) add_single_cutpoint_variant(pose, loop1)
def pose_structure(pose, display_residues=[]): """ Extracts and displays various structural properties of the input <pose> and its <display_residues> including: -PDB numbering -chain identification -sequence -secondary structure """ # store the pose's number of residues, example Python syntax nres = pose.total_residue() # 1. obtain the pose's sequence sequence = pose.sequence() # 2. obtain a list of PDB numbering and icode as a single string pdb_info = pose.pdb_info() PDB_nums = [(str(pdb_info.number(i)) + pdb_info.icode(i)).strip() for i in range(1, nres + 1)] # 3. obtains a list of the chains organized by residue chains = [pdb_info.chain(i) for i in range(1, nres + 1)] # 4. extracts a list of the unique chain IDs unique_chains = [] for c in chains: if c not in unique_chains: unique_chains.append(c) # start outputting information to screen print('\n' + '=' * 80) print('Loaded from', pdb_info.name()) print(nres, 'residues') print(len(unique_chains), 'chain(s) (' + str(unique_chains)[1:-1] + ')') print('Sequence:\n' + sequence) # this object is contained in PyRosetta v2.0 and above # 5. obtain the pose's secondary structure as predicted by PyRosetta's # built-in DSSP algorithm DSSP = protocols.moves.DsspMover() DSSP.apply(pose) # populates the pose's Pose.secstruct ss = pose.secstruct() print('Secondary Structure:\n' + ss) print('\t' + str(100. * ss.count('H') / len(ss))[:4] + '% Helical') print('\t' + str(100. * ss.count('E') / len(ss))[:4] + '% Sheet') print('\t' + str(100. * ss.count('L') / len(ss))[:4] + '% Loop') # 6. obtain the phi, psi, and omega torsion angles phis = [pose.phi(i) for i in range(1, nres + 1)] psis = [pose.psi(i) for i in range(1, nres + 1)] omegas = [pose.omega(i) for i in range(1, nres + 1)] # this object is contained in PyRosetta v2.0 and above # create a PyMOLMover for exporting structures directly to PyMOL pymover = PyMOLMover() pymover.apply(pose) # export the structure to PyMOL (optional) # 7. output information on the requested residues # use a simple dictionary to make output nicer ss_dict = {'L': 'Loop', 'H': 'Helix', 'E': 'Strand'} for i in display_residues: print('=' * 80) print('Pose numbered Residue', i) print('PDB numbered Residue', PDB_nums[i - 1]) print('Single Letter:', sequence[i - 1]) print('Chain:', chains[i - 1]) print('Secondary Structure:', ss_dict[ss[i - 1]]) print('Phi:', phis[i - 1]) print('Psi:', psis[i - 1]) print('Omega:', omegas[i - 1]) # extract the chis chis = [pose.chi(j + 1, i) for j in range(pose.residue(i).nchi())] for chi_no in range(len(chis)): print('Chi ' + str(chi_no + 1) + ':', chis[chi_no]) print('=' * 80)
def sample_single_loop_modeling(pdb_filename, loop_begin, loop_end, loop_cutpoint, frag_filename, frag_length, outer_cycles_low=2, inner_cycles_low=5, init_temp_low=2.0, final_temp_low=0.8, outer_cycles_high=5, inner_cycles_high=10, init_temp_high=2.2, final_temp_high=0.6, jobs=1, job_output='loop_output'): """ Performs simple single loop construction on the input <pdb_filename> with loop from <loop_begin> to <loop_end> with a cutpoint at <loop_cutpoint> using fragments of length <frag_length> in the file <frag_filename>. <jobs> trajectories are performed, each using a low resolution (centroid) simulated annealing with <outer_cycles> rounds and <inner_cycles> steps per round decrementing "temperature" from <init_temp> to <final_temp> geometrically. Output structures are named <job_output>_(job#).pdb. """ # 1. create a pose from the desired PDB file p = Pose() pose_from_file(p, pdb_filename) # 2. create a reference copy of the pose in fullatom starting_p = Pose() starting_p.assign(p) #### if you are constructing multiple loops simultaneously, changes will #### occur in most of the steps below # 3. create the Loop object # (note: Loop objects merely specify residues, they contain no # conformation data) my_loop = protocols.loops.Loop(loop_begin, loop_end, loop_cutpoint) #### if using multiple loops, add additional Loop objects # 4. use the Loop to set the pose FoldTree protocols.loops.set_single_loop_fold_tree(p, my_loop) #### alternate FoldTree setup, if you uncomment the lines below, #### comment-out the set_single_loop_foldtree line above (line 189) #### -create an empty FoldTree #ft = FoldTree() #### -make it a single edge the length of pose #ft.simple_tree(p.total_residue()) #### -insert a jump corresponding to the single loop region #ft.add_jump(loop_begin - 2, loop_end + 2, loop_cutpoint) #### -give the pose this FoldTree (set it to this object), this will #### erase any previous FoldTree held by the pose #p.fold_tree(ft) #### there is also a fold_tree_from_loops method in exposed which sets up #### a FoldTree but it is different from set_single_loop_foldtree in #### that is creates jumps +/- 1 residue from their corresponding loop #### endpoints and requires a third argument, the FoldTree to setup # 5. sets the cut-point residues as cut-point variants protocols.loops.add_single_cutpoint_variant(p, my_loop) # 6. create the MoveMap, allow the loop region backbone and # all chi torsions to be free movemap = MoveMap() movemap.set_bb_true_range(loop_begin, loop_end) movemap.set_chi(True) # sets all chi torsions free # 7. setup the fragment Mover # this "try--except" is used to catch improper fragment files try: fragset = core.fragment.ConstantLengthFragSet(frag_length, frag_filename) #### the ConstantLengthFragSet is overloaded, this same #### ConstantLengthFragSet can be obtained with different syntax # to obtain custom fragments, see Generating Fragment Files below except: raise IOError('Make sure frag_length matches the fragments in\n\ frag_file and that frag_file is valid') fragment_mover = protocols.simple_moves.ClassicFragmentMover( fragset, movemap) # 8. create a Mover for loop modeling using CCD (low resolution) ccd_closure = protocols.loops.loop_closure.ccd.CCDLoopClosureMover( my_loop, movemap) # 9. create ScoreFunctions # for centroid, use the default centroid ScoreFunction with chainbreak on scorefxn_low = create_score_function('cen_std') # the chainbreak ScoreType exists to penalize broken bonds # try creating a broken pose in the interpreter and use a ScoreFunction # with a chainbreak score to investigate its impact, the score is 0.0 # except when a bond is broken # this penalizes failures caused by CCD failing to close the loop scorefxn_low.set_weight(core.scoring.chainbreak, 1) # for fullatom, used for packing and scoring final output scorefxn_high = get_fa_scorefxn( ) # create_score_function_ws_patch('standard', 'score12') # 10. setup sidechain packing Mover task_pack = core.pack.task.TaskFactory.create_packer_task(starting_p) task_pack.restrict_to_repacking() # prevents design, packing only task_pack.or_include_current(True) # considers original sidechains pack = protocols.minimization_packing.PackRotamersMover( scorefxn_high, task_pack) # 11. setup the high resolution refinement # by creating a Loops object, # (note: Loops is basically a list of Loop objects), sample_loops = protocols.loops.Loops() # giving it the loop to remodel, sample_loops.add_loop(my_loop) # and creating a fullatom CCD Mover (high resolution) # this Mover is somewhat abnormal since it handles everything itself, it: # -creates its own MoveMap for the loop regions # -creates its own ScoreFunction (default to get_fa_scorefxn()) # -creates its own FoldTree for the pose based on the loops # -creates its own MonteCarlo object for monitoring the pose # -performs "simulated annealing" with 3 outer cycles and 90 inner # cycles, very similar to the protocol outlined ere # -creates its own backbone Movers (SmallMover, ShearMover) # -creates its own PackRotamersMover, it does NOT restrict repacking # to the loop regions and can alter all sidechain conformations loop_refine = LoopMover_Refine_CCD(sample_loops) # some of these parameters or objects can be set but the protocol # executed by this Mover is effectively untouchable #loop_refine.set_score_function(scorefxn_high) # in beta v2 and above loop_refine.temp_initial(init_temp_high) loop_refine.temp_final(init_temp_high) loop_refine.outer_cycles(outer_cycles_high) loop_refine.max_inner_cycles(inner_cycles_high) # 12. create centroid <--> fullatom conversion Movers to_centroid = SwitchResidueTypeSetMover('centroid') to_fullatom = SwitchResidueTypeSetMover('fa_standard') # and a Mover to recover sidechain conformations # when a protocol samples backbone torsion space in centroid, # the sidechain conformations are neglected, when it is transferred # to fullatom, we typically set the sidechain conformations to their # "original" values and perform sidechain packing, # a ReturnSidechainMover saves a pose's sidechains (in this case # staring_pose) and when applied, inserts these conformations # into the input pose recover_sidechains = protocols.simple_moves.ReturnSidechainMover( starting_p) # 13. create a reference copy of the pose in centroid # the first stage of each trajectory is in centroid # so a centroid reference is needed and the pose must start in centroid to_centroid.apply(p) starting_p_centroid = Pose() starting_p_centroid.assign(p) # 14. create the geometric "temperature" increment for simulated annealing gamma = pow((final_temp_low / init_temp_low), (1.0 / (outer_cycles_low * inner_cycles_low))) # 15. create a PyMOLMover for exporting structures to PyMOL pymov = PyMOLMover() # uncomment the line below to load structures into successive states #pymov.keep_history(True) scorefxn_high(starting_p) # for exporting the scores pymov.apply(starting_p) pymov.send_energy(starting_p) # 16. create a (Py)JobDistributor # a PyJobDistributor uses the job_output argument to name all output files # and performs the specified number (int) of jobs # a ScoreFunction is required since the PyJobDistributor output .fasc file # contains scoring information about each output PDB jd = PyJobDistributor(job_output, jobs, scorefxn_high) jd.native_pose = starting_p # 17. perform the loop modeling protocol counter = 0 # for exporting to PyMOL while not jd.job_complete: # a. set necessary variables for the new trajectory # -reload the starting pose (centroid) p.assign(starting_p_centroid) # -change the pose's PDBInfo.name, for exporting to PyMOL counter += 1 p.pdb_info().name(job_output + '_' + str(counter) + '_cen') # -reset the starting "temperature" (to init_temp) kT = init_temp_low # -create a MonteCarlo object for this trajectory # a MonteCarlo object assesses pass/fail by the Metropolis Criteria # and also records information on the lowest scoring pose mc = MonteCarlo(p, scorefxn_low, kT) # b. "randomize" the loop #### this section may change if you intend to use multiple loops or #### alter the sampling method to "randomize" the loop # -by breaking it open, for i in range(loop_begin, loop_end + 1): p.set_phi(i, -180) p.set_psi(i, 180) pymov.apply(p) # -and then inserting fragments # the number of insertions performed is somewhat arbitrary for i in range(loop_begin, loop_end + 1): fragment_mover.apply(p) pymov.apply(p) #### # low resolution loop modeling: # c. simulated annealing incrementing kT geometrically # from init_temp to final_temp #### this section may change if you intend to use multiple loops or #### alter the sampling method for low resolution modeling for i in range(1, outer_cycles_low + 1): # -start with the lowest scoring pose mc.recover_low(p) # loads mc's lowest scoring pose into p # -take several steps of in the simulated annealing by for j in range(1, inner_cycles_low + 1): # >increasing the "temperature" kT = kT * gamma mc.set_temperature(kT) # >inserting a fragment, fragment_mover.apply(p) pymov.apply(p) # >performing CCD, ccd_closure.apply(p) pymov.apply(p) # >and assessing the Metropolis Criteria mc.boltzmann(p) #### # the LoopMover_Refine_CCD makes A LOT of moves, DO NOT expect to # see useful results if you use the PyMOLMover keep_history option, the large # number of intermediates will slow processing to a halt # d. convert the best structure (lowest scoring) into fullatom by: # -recovering the best (centroid) structure (lowest scoring), mc.recover_low(p) # loads mc's lowest scoring pose into p # -switching the ResidueTypeSet to fullatom (from centroid), to_fullatom.apply(p) # -recovering the original sidechain conformations, recover_sidechains.apply(p) # -and packing the result (since the backbone conformation has changed) pack.apply(p) pymov.apply(p) p.pdb_info().name(job_output + '_' + str(counter) + '_fa') # high-resolution refinement: #### this section may change if you intend to use multiple loops or #### alter the sampling method for high resolution refinement # e. apply the LoopMover_Refine_CCD loop_refine.apply(p) # f. output the decoy (pose result from this trajectory) # include the loop RMSD (Lrsmd) # -output a PDB file using the PyJobDistributor lrms = protocols.loops.loop_rmsd(p, starting_p, sample_loops, True) jd.additional_decoy_info = ' Lrmsd: ' + str(lrms) jd.output_decoy(p) # -export the structure to PyMOL pymov.apply(p) pymov.send_energy(p)
def sample_refinement(pdb_filename, kT=1.0, smallmoves=3, shearmoves=5, backbone_angle_max=7, cycles=9, jobs=1, job_output='refine_output'): """ Performs fullatom structural refinement on the input <pdb_filename> by perturbing backbone torsion angles with a maximum perturbation of <backbone_angle_max> for <cycles> trials of <smallmoves> perturbations of a random residue's phi or psi and <shearmoves> perturbations of a random residue's phi and the preceding residue's psi followed by gradient based backbone torsion angle minimization and sidechain packing with an acceptance criteria scaled by <kT>. <jobs> trajectories are performed, continually exporting structures to a PyMOL instance. Output structures are named <job_output>_(job#).pdb. """ # 1. create a pose from the desired PDB file pose = Pose() pose_from_file(pose, pdb_filename) # 2. create a reference copy of the pose in fullatom starting_pose = Pose() starting_pose.assign(pose) # 3. create a standard ScoreFunction #### implement the desired ScoreFunction here scorefxn = get_fa_scorefxn() # create_score_function('standard') #### If you wish to use the ClassRelax protocol, uncomment the following #### line and comment-out the protocol setup below #refinement = protocols.relax.ClassicRelax( scorefxn ) #### Setup custom high-resolution refinement protocol #### backbone refinement protocol # 4. create a MoveMap, all backbone torsions free movemap = MoveMap() movemap.set_bb(True) # 5. create a SmallMover # a SmallMover perturbs a random (free in the MoveMap) residue's phi or psi # torsion angle for an input number of times and accepts of rejects this # change based on the Metropolis Criteria using the "rama" ScoreType and # the parameter kT # set the maximum angle to backbone_angle_max, apply it smallmoves times smallmover = protocols.simple_moves.SmallMover(movemap, kT, smallmoves) # angle_max is secondary structure dependent, however secondary structure # has not been evaulated in this protocol, thus they are all set # to the same value0 smallmover.angle_max(backbone_angle_max) # sets all at once #### use the overloaded version of the SmallMover.angle_max method if you #### want to use secondary structure biased moves #smallmover.angle_max('H', backbone_angle_max) #smallmover.angle_max('E', backbone_angle_max) #smallmover.angle_max('L', backbone_angle_max) # 6. create a ShearMover # a ShearMover is identical to a SmallMover except that the angles perturbed # are instead a random (free in the MoveMap) residue's phi and the # preceding residue's psi, this reduces the downstream structural change # set the maximum angle to backbone_angle_max, apply it shearmoves times shearmover = protocols.simple_moves.ShearMover(movemap, kT, shearmoves) # same angle_max restictions as SmallMover shearmover.angle_max(backbone_angle_max) #### use the overloaded version of the SmallMover.angle_max method if you #### want to use secondary structure biased moves #shearmover.angle_max('H', backbone_angle_max) #shearmover.angle_max('E', backbone_angle_max) #shearmover.angle_max('L', backbone_angle_max) # 7. create a MinMover, for backbone torsion minimization minmover = protocols.minimization_packing.MinMover() minmover.movemap(movemap) minmover.score_function(scorefxn) #### sidechain refinement protocol, simple packing # 8. setup a PackRotamersMover to_pack = standard_packer_task(starting_pose) to_pack.restrict_to_repacking() # prevents design, packing only to_pack.or_include_current(True) # considers the original sidechains packmover = protocols.minimization_packing.PackRotamersMover( scorefxn, to_pack) #### assess the new structure # 9. create a PyMOLMover pymover = PyMOLMover() # uncomment the line below to load structures into successive states #pymover.keep_history(True) #### the PyMOLMover slows down the protocol SIGNIFICANTLY but provides #### very informative displays #### the keep_history flag (when True) tells the PyMOLMover to store new #### structures into successive states, for a single trajectory, this #### allows you to see intermediate changes (depending on where the #### PyMOLMover is applied), when using a JobDistributor or otherwise #### displaying multiple trajectories with a single protocol, the output #### can get confusing to interpret, by changing the pose's PDBInfo.name #### the structure will load into a new PyMOL state #### try uncommenting the lines below to see different output #pymover.update_energy(True) # see the total score in color # 10. export the original structure, and scores, to PyMOL pymover.apply(pose) scorefxn(pose) pymover.send_energy(pose) # 11. setup a RepeatMover on a TrialMover of a SequenceMover (wow!) # -setup a TrialMover # a. create a SequenceMover of the previous moves #### add any other moves you desire combined_mover = SequenceMover() combined_mover.add_mover(smallmover) combined_mover.add_mover(shearmover) combined_mover.add_mover(minmover) combined_mover.add_mover(packmover) #### explore the protocol using the PyMOLMover, try viewing structures #### before they are accepted or rejected combined_mover.add_mover(pymover) # b. create a MonteCarlo object to define success/failure mc = MonteCarlo(pose, scorefxn, kT) # must reset for each trajectory! # c. create the TrialMover trial = TrialMover(combined_mover, mc) #### explore the protocol using the PyMOLMover, try viewing structures #### after acceptance/rejection, comment-out the lines below #original_trial = TrialMover(combined_mover, mc) #trial = SequenceMover() #trial.add_mover(original_trial) #trial.add_mover(pymover) #### for each trajectory, try cycles number of applications # -create the RepeatMover refinement = RepeatMover(trial, cycles) #### # 12. create a (Py)JobDistributor jd = PyJobDistributor(job_output, jobs, scorefxn) jd.native_pose = starting_pose # 13. store the score evaluations for output # printing the scores as they are produced would be difficult to read, # Rosetta produces a lot of verbose output when running scores = [0] * (jobs + 1) scores[0] = scorefxn(starting_pose) # 14. perform the refinement protocol counter = 0 # for exporting to PyMOL while not jd.job_complete: # a. set necessary variables for the new trajectory # -reload the starting pose pose.assign(starting_pose) # -change the pose's PDBInfo.name, for the PyMOLMover counter += 1 pose.pdb_info().name(job_output + '_' + str(counter)) # -reset the MonteCarlo object (sets lowest_score to that of p) mc.reset(pose) #### if you create a custom protocol, you may have additional #### variables to reset, such as kT #### if you create a custom protocol, this section will most likely #### change, many protocols exist as single Movers or can be #### chained together in a sequence (see above) so you need #### only apply the final Mover # b. apply the refinement protocol refinement.apply(pose) #### # c. output the lowest scoring decoy structure for this trajectory # -recover and output the decoy structure to a PDB file mc.recover_low(pose) jd.output_decoy(pose) # -export the final structure to PyMOL for each trajectory pose.pdb_info().name(job_output + '_' + str(counter) + '_final') pymover.apply(pose) pymover.send_energy(pose) # see the total score in color # -store the final score for this trajectory scores[counter] = scorefxn(pose) # 15. output the score evaluations print('Original Score\t:\t', scores[0]) for i in range(1, len(scores)): # print out the job scores print(job_output + '_' + str(i) + '\t:\t', scores[i]) return scores # for other protocols
) # -loops:test_cycles is only needed for self-test, please make sure to remove it on production run # WARNING: option '-constant_seed' is for testing only! MAKE SURE TO REMOVE IT IN PRODUCTION RUNS!!!!! import os os.chdir('.test.output') p = core.import_pose.pose_from_file("../test/data/2cpl_min.pdb") starting_p = Pose() starting_p.assign(p) scorefxn_low = protocols.loops.get_cen_scorefxn( ) # create_score_function( 'cen_std' ) scorefxn_high = protocols.loops.get_fa_scorefxn( ) # create_score_function_ws_patch( 'standard', 'score12' ) pymol = PyMOLMover() # If Pymol server is running, centroid stage will display loop_begin = 145 loop_end = 155 loop_cut = 150 my_loop = protocols.loops.Loop(loop_begin, loop_end, loop_cut) my_loops = protocols.loops.Loops() my_loops.add_loop(my_loop) print(my_loop) protocols.loops.set_single_loop_fold_tree(p, my_loop) movemap = MoveMap() movemap.set_bb_true_range(loop_begin, loop_end) movemap.set_chi(True)
torsion = pose.psi(res) a = random.gauss(torsion, 25) pose.set_psi(res, a) # initialize pose objects last_pose = Pose() low_pose = Pose() # create poly-A chain and set all peptide bonds to trans p = pose_from_sequence("AAAAAAAAAA", "fa_standard") for res in range(1, p.total_residue() + 1): p.set_omega(res, 180) # use the PyMOLMover to echo this structure to PyMOL pmm = PyMOLMover() pmm.apply(p) # set score function to include Van der Wals and H-bonds only score = ScoreFunction() score.set_weight(fa_atr, 0.8) score.set_weight(fa_rep, 0.44) score.set_weight(hbond_sr_bb, 1.17) # initialize low score objects low_pose.assign(p) low_score = score(p) for i in range(100): last_score = score(p) last_pose.assign(p)
hset = ras.get_hbonds() hset.show(ras) hset.show(ras, 24) pose = pose_from_file("../test/data/workshops/1YY9.clean.pdb") rsd1_num = pose.pdb_info().pdb2pose('D', 102) rsd2_num = pose.pdb_info().pdb2pose('A', 408) print(rsd1_num) print(rsd2_num) rsd1 = pose.residue(rsd1_num) rsd2 = pose.residue(rsd2_num) emap = EMapVector() scorefxn.eval_ci_2b(rsd1, rsd2, pose, emap) print(emap[fa_atr]) print(emap[fa_rep]) print(emap[fa_sol]) pymol = PyMOLMover() ras.pdb_info().name("ras") pymol.send_energy(ras) pymol.send_energy(ras, "fa_atr") pymol.send_energy(ras, "fa_sol") pymol.update_energy(True) pymol.energy_type(fa_atr) pymol.apply(ras) # no longer supported: pymol.label_energy(ras, "fa_rep") # no longer supported: pymol.send_hbonds(ras)