def __init__(self, PDB, EPITOPES=[], ANTIBODY='HK', ANTIGEN='A', pymol=True): pose = Pose() self.pose = pose_from_file(PDB) self.native_pose = self.pose.clone() self.scorefxn = create_score_function('ref2015') self.partners = '{0}_{1}'.format(ANTIGEN, ANTIBODY) self.antibody = ANTIBODY self.antigen = ANTIGEN self.epitopes_pdb = EPITOPES # store corresponding pose residue numbers self.epitopes_pose = [] info = self.pose.pdb_info() for ep in EPITOPES: chain, res = ep self.epitopes_pose.append(info.pdb2pose(chain, res)) if pymol: pymover = PyMOLMover() self.pymol_mover = pymover pymover.update_interval(1) pymover.keep_history(True) self.send_to_pymol()
def __init__(self, loop_residues): """VK Mulligans insanely customizable GenKic algorithm adapted to PyRosetta Arguments: loop_residues {list} -- list of pose residues that will be rebuilt in the GenKic Protocol it is imperative that you read V. Mulligan tutorials to have any idea what the hell is going on. Currently this is behind the RosettaCommons Firwall https://github.com/RosettaCommons/demos/blob/master/tutorials/GeneralizedKIC/generalized_kinematic_closure_1.md """ # Make an Instance self.gk_instance = GeneralizedKIC() # Pose Numbering of residues to consider in the GK. Can be a loop or the entire structure self.loop_residues = loop_residues for res_num in self.loop_residues: self.gk_instance.add_loop_residue(res_num) # The residues to pivot around GK. These of scourse can be reset, but you should use the defaults self.pivot_residues = [ self.loop_residues[0], self.loop_residues[int(len(self.loop_residues) / 2)], self.loop_residues[-1], ] # Here are some basics we can set in the constructor but also have the option to set somewhere else self.closure_attempts = 100000 self.min_solutions = 1 self.scorefxn = create_score_function("ref2015") self.selector = ""
def redock(self, hires=True, perturb=False, TRANS_PERT=0.05, ROT_PERT=1): # setup the docking FoldTree # using this method, the jump number 1 is automatically set to be the # inter-body jump dock_jump = 1 protocols.docking.setup_foldtree(self.pose, self.partners, Vector1([dock_jump])) # create ScoreFunctions for centroid and fullatom docking self.scorefxn = create_score_function('ref2015') # setup the high resolution (fullatom) docking protocol (DockMCMProtocol) hiresdocker = protocols.docking.DockMCMProtocol() hiresdocker.set_scorefxn(self.scorefxn) hiresdocker.set_first_cycle(4) hiresdocker.set_second_cycle(20) self.hiresdocker = hiresdocker # Setup perturber dockperturb = RigidBodyPerturbMover(dock_jump, TRANS_PERT, ROT_PERT) self.perturber = dockperturb if hires: self.hiresdocker.apply(self.pose) elif perturb: self.perturber.apply(self.pose)
def correct_and_relax(self, pose: pyrosetta.Pose): altered = self.correct(pose) movemap = pyrosetta.MoveMap() NeighborhoodResidueSelector = pyrosetta.rosetta.core.select.residue_selector.NeighborhoodResidueSelector neigh_sele = NeighborhoodResidueSelector(altered, distance=15, include_focus_in_subset=True) n = neigh_sele.apply(pose) movemap.set_bb(allow_bb=n) movemap.set_chi(allow_chi=n) scorefxn = pyrosetta.get_fa_scorefxn() # cartesian scorefxn_cart = pyrosetta.create_score_function('ref2015_cart') relax = pyrosetta.rosetta.protocols.relax.FastRelax(scorefxn_cart, 5) relax.cartesian(True) relax.minimize_bond_angles(True) relax.minimize_bond_lengths(True) relax.set_movemap_disables_packing_of_fixed_chi_positions(True) relax.set_movemap(movemap) relax.apply(pose) # dual relax = pyrosetta.rosetta.protocols.relax.FastRelax(scorefxn, 5) relax.set_movemap_disables_packing_of_fixed_chi_positions(True) relax.set_movemap(movemap) relax.apply(pose)
def __init__(self, pose: pyrosetta.Pose, constraint_file: str, ligand_residue: Union[str, int, Tuple[int, str], pyrosetta.Vector1] = 'LIG', key_residues: Union[None, Sequence[Union[int, str, Tuple[int, str]]], pyrosetta.Vector1] = None): """ Given a pose with a blended ligand at ligand residue. Load it (ready for minimisation). :param pose: pose. :param constraint_file: filename :param ligand_residue: ligand -see class docstring :param key_residues: multiple entries -see class docstring """ self.pose = pose pyrosetta.create_score_function('ref2015')(pose) self.constraint_file = constraint_file self.ligand_residue = self._parse_residue(ligand_residue) self.key_residues = self._parse_key_residues(key_residues)
def dock(self): """Docks the pose the normal way and without constraints""" docked = self.pose.clone() docked.remove_constraints() pyrosetta.rosetta.protocols.docking.setup_foldtree( docked, 'A_B', pyrosetta.Vector1([1])) scorefxn = pyrosetta.create_score_function('ligand') docking = pyrosetta.rosetta.protocols.docking.DockMCMProtocol() docking.set_scorefxn(scorefxn) docking.apply(docked) return docked
def dock(self) -> pyrosetta.Pose: """ Docks the pose the normal way and without constraints. :return: """ docked = self.pose.clone() docked.pdb_info().set_resinfo(res=self.ligand_residue[0], chain_id='B', pdb_res=1) docked.remove_constraints() pyrosetta.rosetta.protocols.docking.setup_foldtree( docked, 'A_B', pyrosetta.Vector1([1])) scorefxn = pyrosetta.create_score_function('ligand') docking = pyrosetta.rosetta.protocols.docking.DockMCMProtocol() docking.set_scorefxn(scorefxn) docking.apply(docked) return docked
def dock(self, pose: pyrosetta.Pose, cst: bool = False) -> None: """ Assumes the chain B is last. Uses ``docking.setup_foldtree`` mysterious method. :param pose: replaced structure with ligand :return: Changes in place """ dock_jump = 1 pyrosetta.rosetta.protocols.docking.setup_foldtree( pose, 'A_X', pyrosetta.Vector1([dock_jump])) scorefxn = pyrosetta.create_score_function('ligand') if cst: stm = pyrosetta.rosetta.core.scoring.ScoreTypeManager() st = stm.score_type_from_name("atom_pair_constraint") scorefxn.set_weight(st, 20) docking = pyrosetta.rosetta.protocols.docking.DockMCMProtocol() docking.set_scorefxn(scorefxn) docking.apply(pose)
def _get_scorefxn(self, name: str = "ref2015"): scorefxn = pyrosetta.create_score_function(name) # ref2015_cart_cst.wts # constrain setup = pyrosetta.rosetta.protocols.constraint_movers.ConstraintSetMover( ) setup.constraint_file(self.constraint_file) setup.apply(self.pose) coord = pyrosetta.rosetta.protocols.relax.AtomCoordinateCstMover() coord.set_native_pose(self.pose.clone()) coord.apply(self.pose) stm = pyrosetta.rosetta.core.scoring.ScoreTypeManager() scorefxn.set_weight(stm.score_type_from_name("atom_pair_constraint"), self.atom_pair_constraint) scorefxn.set_weight(stm.score_type_from_name("angle_constraint"), self.angle_constraint) scorefxn.set_weight(stm.score_type_from_name("coordinate_constraint"), self.coordinate_constraint) return scorefxn
def get_local_scorefxn() -> pyrosetta.ScoreFunction: ## local scorefxn w/ ED # ---------- Local weights ------------------ # these are mostly the same except for the line: # <Set scale_sc_dens_byres="E:0.56,D:0.56,R:0.76,K:0.76,M:0.76,C:0.81,Q:0.81,H:0.81,N:0.81,T:0.81,S:0.81, # Y:0.88,W:0.88,A:0.88,F:0.88,P:0.88,I:0.88,L:0.88,V:0.88"/> # which is an utter mystery. weights = {"cart_bonded_length": 0.5, "cart_bonded_torsion": 0.5, "cart_bonded_angle": 1.0, "pro_close": 0.0, "fa_sol": 0.0, "elec_dens_fast": 30, # <-- ED "rama": 0.0, "rama_prepro": 1.0} scorefxn_local = pyrosetta.create_score_function('ref2015_cart') stm = pyrosetta.rosetta.core.scoring.ScoreTypeManager() for name, value in weights.items(): scorefxn_local.set_weight(stm.score_type_from_name(name), value) return scorefxn_local
def relax(pose): sf = create_score_function("ref2015") sf.set_weight(rosetta.core.scoring.atom_pair_constraint, 5) sf.set_weight(rosetta.core.scoring.dihedral_constraint, 1) sf.set_weight(rosetta.core.scoring.angle_constraint, 1) mmap = MoveMap() mmap.set_bb(True) mmap.set_chi(True) mmap.set_jump(True) relax = rosetta.protocols.relax.FastRelax() relax.set_scorefxn(sf) relax.max_iter(200) relax.dualspace(True) relax.set_movemap(mmap) switch = SwitchResidueTypeSetMover("fa_standard") switch.apply(pose) relax.apply(pose)
def __init__(self, pdb_file: str, sigmoid_center: float, sigmoid_norm_value: float): """ Create a RosettaFolding landscape from a .pdb file with structure. Args: pdb_file: Path to .pdb file with structure information. sigmoid_center: Center of sigmoid function. sigmoid_norm_value: 1 / scale of sigmoid function. """ super().__init__(name="RosettaFolding") # Inform the user if pyrosetta is not available. try: prs except NameError as e: raise ImportError( "Error: Pyrosetta not installed. " "Source, binary, and conda installations available " "at http://www.pyrosetta.org/dow") from e # Initialize pyrosetta and suppress output messages prs.init("-mute all") # We will reuse this pose over and over, mutating it to match # whatever sequence we are given to measure. # This is necessary since sequence identity can only be mutated # one residue at a time in Rosetta, because the atom coords of the # backbone of the previous residue are copied into the new one. self.pose = prs.pose_from_pdb(pdb_file) self.wt_pose = self.pose.clone() # Change self.pose from full-atom to centroid representation to_centroid_mover = prs.SwitchResidueTypeSetMover("centroid") to_centroid_mover.apply(self.pose) # Use 1 - sigmoid(centroid energy / norm_value) as the fitness score self.score_function = prs.create_score_function("cen_std") self.sigmoid_center = sigmoid_center self.sigmoid_norm_value = sigmoid_norm_value
import pyrosetta import pyrosetta.rosetta as rosetta from pyrosetta import init, create_score_function, etable_atom_pair_energies from pyrosetta.rosetta import core, protocols 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') test_pose = rosetta.core.import_pose.pose_from_file('../test/data/test_dock.pdb') residue_1 = test_pose.residue(275) residue_2 = test_pose.residue(55) #sfxn =create_score_function('score12') sfxn = create_score_function('ref2015') #calculating atom-atom pairwise interactions and summing #to get total energy (which should match, residue-residue energy!!!) atr_total, rep_total, solv_total, fa_elec_total = 0.0, 0.0, 0.0, 0.0 for i in range(residue_1.natoms()): for j in range(residue_2.natoms()): atom_index_1 = i+1 atom_index_2 = j+1 atr, rep ,solv, fa_elec = etable_atom_pair_energies(residue_1, atom_index_1, residue_2, atom_index_2, sfxn) atr_total += atr rep_total += rep
#!/usr/bin/env python from pyrosetta import pose_from_pdb,init,create_score_function init() pdb_pose = pose_from_pdb('./data/pose_demo.pdb') # 发送pose到pymol中 from pyrosetta.rosetta.protocols.moves import PyMOLMover pymover = PyMOLMover() pymover.update_energy(True) pymover.apply(pdb_pose) scoring = create_score_function('ref2015') scoring(pose)
def build_scorefxn(cgmodel, mm=False): """ Given a cgmodel class object, this function uses its definitions to build a PyRosetta scoring function. (Used to confirm energetic agreement between PyRosetta and OpenMM for identical model parameters and an identical structural ensemble.) Parameters ---------- cgmodel: CGModel() class object Returns ------- scorefxn: A PyRosetta ScoreFunction() class object, containing all scoring function components that are defined/requested within the cgmodel() class object. """ if mm: # Create new MM atom types file = open("mm_atom_properties.txt", "w") file.write( "NAME LJ_WDEPTH LJ_RADIUS LJ_3B_WDEPTH LJ_3B_RADIUS\n" ) file.write( "BB1 -0.20000 1.00 -0.20000 1.000\n") file.write( "SC1 -0.20000 1.00 -0.20000 1.000\n") file.close() mm_atom_type_set = pyrosetta.rosetta.core.chemical.MMAtomTypeSet("CG") mm_atom_type_set.read_file("mm_atom_properties.txt") pyrosetta.rosetta.core.scoring.mm.MMLJLibrary(mm_atom_type_set) #exit() #pyrosetta.rosetta.core.scoring.mm.MMLJLibrary() # Create a new MM score function file = open("mm.wts", "w") file.write("UNFOLDED_ENERGIES_TYPE UNFOLDED_MM_STD\n") file.write("mm_lj_intra_rep 1.0\n") file.write("mm_lj_intra_atr 1.0\n") file.write("mm_lj_inter_rep 1.0\n") file.write("mm_lj_inter_atr 1.0\n") file.write("mm_twist 0.0") file.close() scorefxn = pyrosetta.create_score_function("mm.wts") #print(pyrosetta.rosetta.core.scoring.mm.MMLJLibrary.lookup(1)) #exit() else: scorefxn.set_weight(pyrosetta.rosetta.core.scoring.fa_elec, 1) scorefxn.set_weight(pyrosetta.rosetta.core.scoring.fa_rep, 1) scorefxn.set_weight(pyrosetta.rosetta.core.scoring.fa_atr, 1) scorefxn.set_weight(pyrosetta.rosetta.core.scoring.fa_intra_atr, 1) scorefxn.set_weight(pyrosetta.rosetta.core.scoring.fa_intra_rep, 1) cg_pyrosetta.change_parameters.changeTorsionParameters({ 'CG1 CG1 CG1 CG1': [0, 0, 0], 'CG2 CG1 CG1 CG2': [0, 0, 0], 'CG2 CG1 CG1 CG1': [0, 0, 0], 'X CG2 CG1 CG1': [0, 0, 0] }) cg_pyrosetta.change_parameters.changeAngleParameters({ 'CG1 CG1 CG1': [0, 0], 'CG2 CG1 CG1': [0, 0], 'CG1 CG1 CG2': [0, 0], 'X CG2 CG1': [0, 0] }) return (scorefxn)
def sample_dna_interface(pdb_filename, partners, jobs=1, job_output='dna_output'): """ Performs DNA-protein docking using Rosetta fullatom docking (DockingHighRes) on the DNA-protein complex in <pdb_filename> using the relative chain <partners> . <jobs> trajectories are performed with output structures named <job_output>_(job#).pdb. """ # 1. creates a pose from the desired PDB file pose = Pose() pose_from_file(pose, pdb_filename) # 2. setup the docking FoldTree # using this method, the jump number 1 is automatically set to be the # inter-body jump dock_jump = 1 # the exposed method setup_foldtree takes an input pose and sets its # FoldTree to have jump 1 represent the relation between the two docking # partners, the jump points are the residues closest to the centers of # geometry for each partner with a cutpoint at the end of the chain, # the second argument is a string specifying the relative chain orientation # such as "A_B" of "LH_A", ONLY TWO BODY DOCKING is supported and the # partners MUST have different chain IDs and be in the same pose (the # same PDB), additional chains can be grouped with one of the partners, # the "_" character specifies which bodies are separated # the third argument...is currently unsupported but must be set (it is # supposed to specify which jumps are movable, to support multibody # docking...but Rosetta doesn't currently) # the FoldTrees setup by this method are for TWO BODY docking ONLY! protocols.docking.setup_foldtree(pose, partners, Vector1([dock_jump])) # 3. create a copy of the pose for testing test_pose = Pose() test_pose.assign(pose) # 4. create ScoreFunctions for centroid and fullatom docking scorefxn = create_score_function('dna') scorefxn.set_weight(core.scoring.fa_elec, 1) # an "electrostatic" term #### global docking, a problem solved by the Rosetta DockingProtocol, #### requires interface detection and refinement #### as with other protocols, these tasks are split into centroid (interface #### detection) and high-resolution (interface refinement) methods #### without a centroid representation, low-resolution DNA-protein #### prediction is not possible and as such, only the high-resolution #### DNA-protein interface refinement is available #### WARNING: if you add a perturbation or randomization step, the #### high-resolution stages may fail (see Changing DNA Docking #### Sampling below) #### a perturbation step CAN make this a global docking algorithm however #### the rigid-body sampling preceding refinement will require EXTENSIVE #### sampling to produce accurate results and this algorithm spends most #### of its effort in refinement (which may be useless for the predicted #### interface) # 5. setup the high resolution (fullatom) docking protocol (DockMCMProtocol) # ...as should be obvious by now, Rosetta applications have no central # standardization, the DockingProtocol object can be created and # applied to perform Rosetta docking, many of its options and settings # can be set using the DockingProtocol setter methods # as there is currently no centroid representation of DNA in the chemical # database, the low-resolution docking stages are not useful for # DNA docking # instead, create an instance of just the high-resolution docking stages docking = protocols.docking.DockMCMProtocol() docking.set_scorefxn(scorefxn) # 6. setup the PyJobDistributor jd = PyJobDistributor(job_output, jobs, scorefxn) # 7. setup a PyMOL_Observer (optional) # the PyMOL_Observer object owns a PyMOLMover and monitors pose objects for # structural changes, when changes are detected the new structure is # sent to PyMOL # fortunately, this allows investigation of full protocols since # intermediate changes are displayed, it also eliminates the need to # manually apply the PyMOLMover during a custom protocol # unfortunately, this can make the output difficult to interpret (since you # aren't explicitly telling it when to export) and can significantly slow # down protocols since many structures are output (PyMOL can also slow # down if too many structures are provided and a fast machine may # generate structures too quickly for PyMOL to read, the # "Buffer clean up" message # uncomment the line below to use the PyMOL_Observer ## AddPyMOLObserver(test_pose, True) # 8. perform protein-protein docking counter = 0 # for pretty output to PyMOL while not jd.job_complete: # a. set necessary variables for this trajectory # -reset the test pose to original (centroid) structure test_pose.assign(pose) # -change the pose name, for pretty output to PyMOL counter += 1 test_pose.pdb_info().name(job_output + '_' + str(counter)) # b. perform docking docking.apply(test_pose) # c. output the decoy structure: # to PyMOL test_pose.pdb_info().name(job_output + '_' + str(counter) + '_fa') # to a PDB file jd.output_decoy(test_pose)
def main(target=None, new_res=None): """Example function to run my custom PyRosetta script.""" # Initialize PyRosetta with custom flags pyrosetta.init("-ignore_unrecognized_res 1 -renumber_pdb 1 -mute all") # Setup pose pose = pyrosetta.pose_from_file("inputs/5JG9.clean.pdb") # Setup directory structure main_dir = os.getcwd() unique_dir = os.path.join("outputs", "testing_" + uuid.uuid4().hex) if not os.path.isdir(unique_dir): os.mkdir(unique_dir) os.chdir(unique_dir) # Create scorefunction scorefxn = pyrosetta.create_score_function("ref2015_cart") # PyRosetta design protocol keep_chA = pyrosetta.rosetta.protocols.grafting.simple_movers.KeepRegionMover( res_start=str(pose.chain_begin(1)), res_end=str(pose.chain_end(1))) keep_chA.apply(pose) mutate = pyrosetta.rosetta.protocols.simple_moves.MutateResidue( target=target, new_res=new_res) mutate.apply(pose) mm = pyrosetta.rosetta.core.kinematics.MoveMap() mm.set_bb(True) mm.set_chi(True) min_mover = pyrosetta.rosetta.protocols.minimization_packing.MinMover() min_mover.set_movemap(mm) min_mover.score_function(scorefxn) min_mover.min_type("lbfgs_armijo_nonmonotone") min_mover.cartesian(True) min_mover.tolerance(0.01) min_mover.max_iter(200) min_mover.apply(pose) total_score = scorefxn(pose) # Setup outputs pdb_output_filename = "_".join( ["5JG9.clean", str(target), str(new_res), ".pdb"]) pyrosetta.dump_pdb(pose, pdb_output_filename) # Append scores to scorefile pyrosetta.toolbox.py_jobdistributor.output_scorefile( pose=pose, pdb_name="5JG9.clean", current_name=pdb_output_filename, scorefilepath="score.fasc", scorefxn=scorefxn, nstruct=1, native_pose=None, additional_decoy_info=None, json_format=True) os.chdir(main_dir)
conf.read("configs/generation.ini") # Read fasta file and generate a pose from the sequence pose = pr.pose_from_sequence( io.get_sequence_from_fasta(conf['init']['fastaPath'])) # Native pose native_pose = pr.pose_from_pdb(conf['init']['pdbPath']) # Convert the pose to coarse-grained representation switch = pr.SwitchResidueTypeSetMover("centroid") switch.apply(pose) switch.apply(native_pose) # Create score function for evaluation score4_function = pr.create_score_function("score3", "score4L") score4_function.set_weight(pr.rosetta.core.scoring.rama, 1) population_size = int(conf['init']['population']) eval_budget = int(conf['init']['evalbudget']) no_of_decoys = int(conf['init']['noOfDecoys']) min_ca_rmsd = math.inf lowest_energy = math.inf min_ca_rmsd_pose = pr.Pose() lowest_energy_pose = pr.Pose() # ***************************** # Generate initial population *
'ALA','ASN','ASP','ARG','CYS','GLN','GLU', 'GLY','HIS','ILE','LEU','LYS','MET','PRO','PHE','SER', 'THR','TRP','TYR','VAL' ] ) ) with open( 'input_files/flags' ) as fn: flags = fn.read().replace( '\n', ' ' ) # init PyRosetta pyrosetta.init( ''.join( flags ) ) ligand_params = pyrosetta.Vector1( [ 'input_files/pNPG.params' ] ) new_res_set = pyrosetta.generate_nonstandard_residue_set( ligand_params ) p = pyrosetta.Pose() pyrosetta.pose_from_file( p, new_res_set, 'input_files/bglb.pdb' ) scorefxn = pyrosetta.create_score_function( 'beta_cst' ) add_cst = rosetta.protocols.enzdes.AddOrRemoveMatchCsts() add_cst.cstfile( 'input_files/pNPG.enzdes.cst' ) add_cst.set_cst_action( rosetta.protocols.enzdes.CstAction.ADD_NEW ) add_cst.apply( p ) target = int( mutant_name[ 1:-1 ] ) new_res = fmt[ mutant_name[ -1 ] ] mut = rosetta.protocols.simple_moves.MutateResidue( target, new_res ) mut.apply( p ) # set up packing task tf = rosetta.core.pack.task.TaskFactory() around = rosetta.protocols.toolbox.task_operations.DesignAroundOperation() around.include_residue( 446 ) #ligand
def improvement(eaObj, impcfg): eaObj.relaxtype = impcfg['relaxtype'] # For now, should be 'local' for HEA eaObj.impScoreFxn = create_score_function( impcfg['scorefxn']) # Identify the scoring protocol
# 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") switch2.apply(ras) print(ras.residue(5)) # Protein Fragments fragset = core.fragment.ConstantLengthFragSet(3) fragset.read_fragment_file("../test/data/workshops/aat000_03_05.200_v1_3") movemap = MoveMap() movemap.set_bb(True) mover_3mer = protocols.simple_moves.ClassicFragmentMover(fragset, movemap) pose = pose_from_sequence("RFPMMSTFKVLLCGAVLSRIDAG", "centroid")
def sample_docking(pdb_filename, partners, translation = 3.0, rotation = 8.0, jobs = 1, job_output = 'dock_output'): """ Performs protein-protein docking using the Rosetta standard DockingProtocol on the proteins in <pdb_filename> using the relative chain <partners> with an initial perturbation using <translation> Angstroms and <rotation> degrees. <jobs> trajectories are performed with output structures named <job_output>_(job#).pdb. structures are exported to a PyMOL instance. """ # 1. creates a pose from the desired PDB file pose = Pose() pose_from_file(pose, pdb_filename) # 2. setup the docking FoldTree # using this method, the jump number 1 is automatically set to be the # inter-body jump dock_jump = 1 # the exposed method setup_foldtree takes an input pose and sets its # FoldTree to have jump 1 represent the relation between the two docking # partners, the jump points are the residues closest to the centers of # geometry for each partner with a cutpoint at the end of the chain, # the second argument is a string specifying the relative chain partners # such as "A_B" of "LH_A", ONLY TWO BODY DOCKING is supported and the # partners MUST have different chain IDs and be in the same pose (the # same PDB), additional chains can be grouped with one of the partners, # the "_" character specifies which bodies are separated # the third argument...is currently unsupported but must be set (it is # supposed to specify which jumps are movable, to support multibody # docking...but Rosetta doesn't currently) # the FoldTrees setup by this method are for TWO BODY docking ONLY! protocols.docking.setup_foldtree(pose, partners, Vector1([dock_jump])) # 3. 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(pose) # 4. convert to centroid to_centroid.apply(pose) # 5. create a (centroid) test pose test_pose = Pose() test_pose.assign(pose) # 6. create ScoreFunctions for centroid and fullatom docking scorefxn_low = create_score_function('interchain_cen') scorefxn_high = create_score_function('docking') # PyRosetta3: scorefxn_high_min = create_score_function_ws_patch('docking', 'docking_min') scorefxn_high_min = create_score_function('docking', 'docking_min') # 7. create Movers for producing an initial perturbation of the structure # the DockingProtocol (see below) can do this but several Movers are # used to demonstrate their syntax # these Movers randomize the orientation (rotation) of each docking partner randomize_upstream = RigidBodyRandomizeMover(pose, dock_jump, partner_upstream) randomize_downstream = RigidBodyRandomizeMover(pose, dock_jump, partner_downstream) # this Mover translates one docking partner away from the other in a random # direction a distance specified by the second argument (in Angstroms) # and rotates this partner randomly by the third argument (in degrees) dock_pert = RigidBodyPerturbMover(dock_jump, translation, rotation) # this Mover randomizes a pose's partners (rotation) spin = RigidBodySpinMover(dock_jump) # this Mover uses the axis defined by the inter-body jump (jump 1) to move # the docking partners close together slide_into_contact = protocols.docking.DockingSlideIntoContact(dock_jump) # 8. setup the MinMover # the MoveMap can set jumps (by jump number) as degrees of freedom movemap = MoveMap() movemap.set_jump(dock_jump, True) # the MinMover can minimize score based on a jump degree of freedom, this # will find the distance between the docking partners which minimizes # the score minmover = protocols.minimization_packing.MinMover() minmover.movemap(movemap) minmover.score_function(scorefxn_high_min) # 9. create a SequenceMover for the perturbation step perturb = protocols.moves.SequenceMover() perturb.add_mover(randomize_upstream) perturb.add_mover(randomize_downstream) perturb.add_mover(dock_pert) perturb.add_mover(spin) perturb.add_mover(slide_into_contact) perturb.add_mover(to_fullatom) perturb.add_mover(recover_sidechains) perturb.add_mover(minmover) # 10. setup the DockingProtocol # ...as should be obvious by now, Rosetta applications have no central # standardization, the DockingProtocol object can be created and # applied to perform Rosetta docking, many of its options and settings # can be set using the DockingProtocol setter methods # here, on instance is created with all default values and the movable jump # is manually set to jump 1 (just to be certain), the centroid docking # ScoreFunction is set and the fullatom docking ScoreFunction is set dock_prot = protocols.docking.DockingProtocol() # contains many docking functions dock_prot.set_movable_jumps(Vector1([1])) # set the jump to jump 1 dock_prot.set_lowres_scorefxn(scorefxn_low) dock_prot.set_highres_scorefxn(scorefxn_high_min) #### you can alternatively access the low and high resolution sections of #### the DockingProtocol, both are applied by the DockingProtocol but #### a novel protocol may only require centroid (DockingLowRes) or #### fullatom (DockingHighRes), uncomment the lines below and their #### application below #docking_low = DockingLowRes() #docking_low.set_movable_jumps(Vector1([1])) #docking_low.set_scorefxn(scorefxn_low) #docking_high = DockingHighRes() #docking_high.set_movable_jumps(Vector1([1])) #docking_high.set_scorefxn(scorefxn_high) # 11. setup the PyJobDistributor jd = PyJobDistributor(job_output, jobs, scorefxn_high) temp_pose = Pose() # a temporary pose to export to PyMOL temp_pose.assign(pose) to_fullatom.apply(temp_pose) # the original pose was fullatom recover_sidechains.apply(temp_pose) # with these sidechains jd.native_pose = temp_pose # for RMSD comparison # 12. setup a PyMOL_Observer (optional) # the PyMOL_Observer object owns a PyMOLMover and monitors pose objects for # structural changes, when changes are detected the new structure is # sent to PyMOL # fortunately, this allows investigation of full protocols since # intermediate changes are displayed, it also eliminates the need to # manually apply the PyMOLMover during a custom protocol # unfortunately, this can make the output difficult to interpret (since you # aren't explicitly telling it when to export) and can significantly slow # down protocols since many structures are output (PyMOL can also slow # down if too many structures are provided and a fast machine may # generate structures too quickly for PyMOL to read, the # "Buffer clean up" message # uncomment the line below to use the PyMOL_Observer ## AddPyMOLObserver(test_pose, True) # 13. perform protein-protein docking counter = 0 # for pretty output to PyMOL while not jd.job_complete: # a. set necessary variables for this trajectory # -reset the test pose to original (centroid) structure test_pose.assign(pose) # -change the pose name, for pretty output to PyMOL counter += 1 test_pose.pdb_info().name(job_output + '_' + str(counter)) # b. perturb the structure for this trajectory perturb.apply(test_pose) # c. perform docking dock_prot.apply(test_pose) #### alternate application of the DockingProtocol pieces #docking_low.apply(test_pose) #docking_high.apply(test_pose) # d. output the decoy structure to_fullatom.apply(test_pose) # ensure the output is fullatom # to PyMOL test_pose.pdb_info().name(job_output + '_' + str( counter ) + '_fa') # to a PDB file jd.output_decoy(test_pose)
def dock_pose(self): ## constraints def add_weights(scorefxn): stm = pyrosetta.rosetta.core.scoring.ScoreTypeManager() scorefxn.set_weight( stm.score_type_from_name("atom_pair_constraint"), 20) scorefxn.set_weight(stm.score_type_from_name("angle_constraint"), 20) setup = pyrosetta.rosetta.protocols.constraint_movers.ConstraintSetMover( ) setup.constraint_file(self.constraint_filename) setup.apply(self.pose) scorefxn = pyrosetta.get_fa_scorefxn() add_weights(scorefxn) ### First relax movemap = pyrosetta.MoveMap() v = self.get_ligand_selector().apply(self.pose) n = self.get_neighbour_selector().apply(self.pose) movemap.set_bb(allow_bb=n) movemap.set_chi(allow_chi=n) relax = pyrosetta.rosetta.protocols.relax.FastRelax(scorefxn, 10) relax.set_movemap_disables_packing_of_fixed_chi_positions(True) relax.set_movemap(movemap) print(f'FastRelax 2: {self.name}') #this one is non cartesian. self.pose.dump_pdb( f'{self.work_path}/{self.name}/min2_{self.name}.pdb') self.notebook['post-min2'] = self.calculate_score() ## repack # operation = pyrosetta.rosetta.core.pack.task.operation # allow = operation.RestrictToRepackingRLT() # restrict_to_focus = operation.OperateOnResidueSubset(allow,self.get_ligand_selector(), True) # tf = pyrosetta.rosetta.core.pack.task.TaskFactory() # tf.push_back(operation.PreventRepacking()) # tf.push_back(restrict_to_focus) # packer = pyrosetta.rosetta.protocols.minimization_packing.PackRotamersMover(scorefxn) # packer.task_factory(tf) # packer.apply(self.pose) # self.pose.dump_pdb(f'{self.work_path}/{self.name}/repacked_{self.name}.pdb') ### Docking pyrosetta.rosetta.protocols.docking.setup_foldtree( self.pose, 'A_B', pyrosetta.Vector1([1])) scorefxn = pyrosetta.create_score_function('ligand') add_weights(scorefxn) restrict_to_focus = pyrosetta.rosetta.core.pack.task.operation.OperateOnResidueSubset( pyrosetta.rosetta.core.pack.task.operation.RestrictToRepackingRLT( ), self.get_neighbour_selector(), True) tf = pyrosetta.rosetta.core.pack.task.TaskFactory() tf.push_back( pyrosetta.rosetta.core.pack.task.operation.RestrictToRepacking()) tf.push_back(restrict_to_focus) docking = pyrosetta.rosetta.protocols.docking.DockMCMProtocol() docking.set_task_factory(tf) docking.set_ignore_default_task(True) #docking.set_move_map() docking.set_scorefxn(scorefxn) docking.apply(self.pose) print(f'Dock: {self.name}') self.notebook['docked'] = self.calculate_score() self.pose.dump_pdb( f'{self.work_path}/{self.name}/docked_{self.name}.pdb')
movemap.set_bb(50, True) movemap.set_bb(51, True) print( movemap ) small_mover.apply(test) shear_mover.apply(test2) pmm.apply(test) pmm.apply(test2) # Minimization Moves min_mover = MinMover() mm4060 = MoveMap() mm4060.set_bb_true_range(40, 60) scorefxn = create_score_function("ref2015") min_mover.movemap(mm4060) min_mover.score_function(scorefxn) # Commenting out for now because this lead to seg-fault in debug builds # AddPyMOLObserver(test2, True) min_mover.apply(test2) print( min_mover ) # Monte Carlo Object mc = MonteCarlo(test, scorefxn, kT) mc.boltzmann(test)
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)
import pyrosetta import pyrosetta.rosetta as rosetta from pyrosetta import init, Pose, Vector1, create_score_function from pyrosetta.rosetta import core, protocols 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') print('testing ligand modeling') ligand_p = Pose() params_list = ['../test/data/ligand.params'] rts = ligand_p.conformation().modifiable_residue_type_set_for_conf( core.chemical.FULL_ATOM_t ) rts.read_files_for_base_residue_types( Vector1(params_list) ) ligand_p.conformation().reset_residue_type_set_for_conf( rts ) core.import_pose.pose_from_file(ligand_p, "../test/data/ligand_test.pdb") scorefxn = create_score_function("ligand") scorefxn(ligand_p) print('testing DNA modeling') dna_p = Pose() core.import_pose.pose_from_file(dna_p, "../test/data/dna_test.pdb") scorefxn = create_score_function("dna") scorefxn(dna_p) print('Done!')
## @author Sergey Lyskov from __future__ import print_function import glob import pyrosetta pyrosetta.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') sf = pyrosetta.create_score_function('ref2015') jd = pyrosetta.PyJobDistributor("_jd_test", 10, sf) while not jd.job_complete: pp = pyrosetta.pose_from_sequence("DSEEKFLRRIGRFGYGYGPYE") jd.output_decoy(pp) assert len(glob.glob('_jd_test*')) == 10 + 1 # 10 decoys + score file sf = pyrosetta.create_score_function('ref2015') jd = pyrosetta.PyJobDistributor("_jd_at_test", 10, sf, compress=True) while not jd.job_complete: pp = pyrosetta.pose_from_sequence("DSEEKFLRRIGRFGYGYGPYE") jd.output_decoy(pp)
'ALA', 'ASN', 'ASP', 'ARG', 'CYS', 'GLN', 'GLU', 'GLY', 'HIS', 'ILE', 'LEU', 'LYS', 'MET', 'PRO', 'PHE', 'SER', 'THR', 'TRP', 'TYR', 'VAL' ])) with open('input_files/flags') as fn: flags = fn.read().replace('\n', ' ') # init PyRosetta pyrosetta.init(''.join(flags)) ligand_params = pyrosetta.Vector1(['input_files/pNPG.params']) new_res_set = pyrosetta.generate_nonstandard_residue_set(ligand_params) p = pyrosetta.Pose() pyrosetta.pose_from_file(p, new_res_set, 'input_files/bglb.pdb') scorefxn = pyrosetta.create_score_function('beta_cst') add_cst = rosetta.protocols.enzdes.AddOrRemoveMatchCsts() add_cst.cstfile('input_files/pNPG.enzdes.cst') add_cst.set_cst_action(rosetta.protocols.enzdes.CstAction.ADD_NEW) add_cst.apply(p) target = int(mutant_name[1:-1]) new_res = fmt[mutant_name[-1]] mut = rosetta.protocols.simple_moves.MutateResidue(target, new_res) mut.apply(p) # set up packing task tf = rosetta.core.pack.task.TaskFactory() around = rosetta.protocols.toolbox.task_operations.DesignAroundOperation() around.include_residue(446) #ligand
import numpy as np import pyrosetta import matplotlib.pyplot as plt from pyrosetta import PyMOLMover from pyrosetta import SwitchResidueTypeSetMover # init pyrosetta and load score3 function pyrosetta.init() SCORE3 = pyrosetta.create_score_function("score3") # function to initialise a pose def create_pose(seq='DAYAQWLKDGGPSSGRPPPS'): pose = pyrosetta.pose_from_sequence(seq) # set given initial conditions for res in range(1, pose.total_residue() + 1): pose.set_phi(res, -150) pose.set_psi(res, 150) pose.set_omega(res, 180) return pose # functions to create an angle in range [a-da, a+da) new_angle = lambda a, da: modular_angle(np.random.randint(a - da, a + da)) def modular_angle(n): """Keep angle in [-180,180] range""" if np.abs(n) > 180: n = -np.sign(n) * 360 + n return n
def main(): notebook_flags = """ -out:level 300 -ignore_unrecognized_res 1 -ex2 1 -ex1aro 1 -extra_res_fa HBI.fa.params -extra_res_cen HBI.cen.params """ pyrosetta.distributed.dask.init_notebook(notebook_flags) new_Nterm_pdb_res = [35, 63, 89, 106] for pdb in ["mFAP2a", "mFAP2b"]: pose = pyrosetta.io.pose_from_file(os.path.join("pdbs/mFAP_pdbs", f"{pdb}.pdb")) for new_Nterm in new_Nterm_pdb_res: tmp_pose = pose.clone() out_pose = circularly_permute(tmp_pose, new_Nterm) scorefxn = pyrosetta.create_score_function("ref2015") Nterminus_selector = pyrosetta.rosetta.core.select.residue_selector.ResidueIndexSelector("1A-2A") Cterminus_selector = pyrosetta.rosetta.core.select.residue_selector.ResidueIndexSelector("114A-115A") termini_selector = pyrosetta.rosetta.core.select.residue_selector.OrResidueSelector(Nterminus_selector, Cterminus_selector) not_termini_selector = pyrosetta.rosetta.core.select.residue_selector.NotResidueSelector(termini_selector) tf = pyrosetta.rosetta.core.pack.task.TaskFactory() tf.push_back(pyrosetta.rosetta.core.pack.task.operation.InitializeFromCommandline()) tf.push_back(pyrosetta.rosetta.core.pack.task.operation.IncludeCurrent()) tf.push_back(pyrosetta.rosetta.core.pack.task.operation.NoRepackDisulfides()) tf.push_back(pyrosetta.rosetta.core.pack.task.operation.OperateOnResidueSubset( pyrosetta.rosetta.core.pack.task.operation.PreventRepackingRLT(), not_termini_selector)) mmf = pyrosetta.rosetta.core.select.movemap.MoveMapFactory() mmf.all_bb(setting=False) mmf.all_bondangles(setting=False) mmf.all_bondlengths(setting=False) mmf.all_chi(setting=False) mmf.all_jumps(setting=False) mmf.set_cartesian(setting=False) enable = pyrosetta.rosetta.core.select.movemap.move_map_action.mm_enable mmf.add_chi_action(action=enable, selector=termini_selector) mmf.add_bb_action(action=enable, selector=termini_selector) fast_relax = pyrosetta.rosetta.protocols.relax.FastRelax(scorefxn_in=scorefxn, standard_repeats=1) fast_relax.cartesian(False) fast_relax.set_task_factory(tf) fast_relax.set_movemap_factory(mmf) fast_relax.minimize_bond_angles(False) fast_relax.minimize_bond_lengths(False) fast_relax.min_type("dfpmin_armijo_nonmonotone") fast_relax.apply(out_pose) outdir = "circularly_permuted_relaxed_pdbs" if not os.path.isdir(outdir): os.mkdir(outdir) new_name = "cp" + str(new_Nterm) + "-" + str(new_Nterm - 1) + f"_{pdb}.pdb" # Output pose with a TER line at cutpoint cutpoint = int(re.search("SRAAQLLPGTWQ", out_pose.sequence()).start() + 1) lines_list = io.to_pdbstring(out_pose).split("\n") cont = True new_lines_list = [] for line in lines_list: if line.startswith("ATOM") or line.startswith("HETATM"): pdb_res = int(line[22:26].split()[-1]) if (pdb_res == cutpoint) and cont: new_lines_list.append("TER") cont = False new_lines_list.append(line) elif line.startswith("TER"): new_lines_list.append(line) with open(os.path.join(outdir, new_name), "w") as f: f.write("\n".join(new_lines_list))
def sample_folding(sequence, long_frag_filename, long_frag_length, short_frag_filename, short_frag_length, kT=3.0, long_inserts=1, short_inserts=3, cycles=40, jobs=1, job_output='fold_output'): """ Performs exporting structures to a PyMOL instance Output structures are named <job_output>_(job#).pdb """ # 1. create a pose from the desired sequence (fullatom) # the method pose_from_sequence produces a complete IDEALIZED # protein conformation of the input sequence, the ResidueTypeSet (second # argument below) may be varied, and this method supports non-proteogenic # chemistry (though it is still a Rosetta Residue). however this syntax # is more involved and not robust to user errors, and not presented here # small differences in bond lengths and bond angles WILL change the results, #### if you desire an alternate starting conformation, alter steps #### 1. and 2. as you please pose = pose_from_sequence(sequence, 'fa_standard') # 2. linearize the pose by setting backbone torsions to large values # the method make_pose_from_sequence does not create the new pose's # PDBInfo object, so its done here, without it an error occurs later pose.pdb_info(rosetta.core.pose.PDBInfo(pose.total_residue())) for i in range(1, pose.total_residue() + 1): pose.set_omega(i, 180) pose.set_phi(i, -150) # reasonably straight pose.set_psi(i, 150) #### if you want to see the decoy scores, the PDBInfo needs these lines #pose.pdb_info().chain(i, 'A') # necessary to color by score #pose.pdb_info().number(i, i) # for PDB numbering #### # 3. create a (fullatom) reference copy of the pose test_pose = Pose() test_pose.assign(pose) test_pose.pdb_info().name('linearized pose') # 4. create centroid <--> fullatom conversion Movers to_centroid = SwitchResidueTypeSetMover('centroid') # centroid Residue objects, of amino acids, have all their sidechain atoms # replaced by a single representative "atom" to speed up calculations to_fullatom = SwitchResidueTypeSetMover('fa_standard') # 5. convert the poses to centroid to_centroid.apply(pose) to_centroid.apply(test_pose) # 6. create the MoveMap, all backbone torsions free movemap = MoveMap() movemap.set_bb(True) # minimizing the centroid chi angles (the sidechain centroid atoms) is # almost always USELESS since this compression is performed for speed, # not accuracy and clashes usually occur when converting to fullatom # 7. setup the ClassicFragmentMovers # for the long fragments file # this "try--except" is used to catch improper fragment files try: fragset_long = core.fragment.ConstantLengthFragSet( long_frag_length, long_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 long_frag_length matches the fragments in\n\ long_frag_file and that long_frag_file is valid') long_frag_mover = protocols.simple_moves.ClassicFragmentMover( fragset_long, movemap) # and for the short fragments file # this "try--except" is used to catch improper fragment files try: fragset_short = core.fragment.ConstantLengthFragSet( short_frag_length, short_frag_filename) except: raise IOError('Make sure short_frag_length matches the fragments in\n\ short_frag_file and that short_frag_file is valid') short_frag_mover = protocols.simple_moves.ClassicFragmentMover( fragset_short, movemap) # 8. setup RepeatMovers for the ClassicFragmentMovers insert_long_frag = protocols.moves.RepeatMover(long_frag_mover, long_inserts) insert_short_frag = protocols.moves.RepeatMover(short_frag_mover, short_inserts) # 9. create a PyMOL_Observer for exporting structures to PyMOL (optional) # the PyMOL_Observer object owns a PyMOLMover and monitors pose objects for # structural changes, when changes are detected the new structure is # sent to PyMOL # fortunately, this allows investigation of full protocols since # intermediate changes are displayed, it also eliminates the need to # manually apply the PyMOLMover during a custom protocol # unfortunately, this can make the output difficult to interpret (since you # aren't explicitly telling it when to export) and can significantly slow # down protocols since many structures are output (PyMOL can also slow # down if too many structures are provided and a fast machine may # generate structures too quickly for PyMOL to read, the # "Buffer clean up" message # uncomment the line below to use PyMOL_Observer ## AddPyMOLObserver(test_pose, True) # 10. create ScoreFunctions # for low-resolution, centroid, poses necessary for the TrialMover's # MonteCarlo object (see below) scorefxn_low = create_score_function('score3') # for high-resolution, fullatom, poses necessary for scoring final output # from the PyJobDistributor (see below) scorefxn_high = get_fa_scorefxn( ) # create_score_function('standard', 'score12') # 11. setup a RepeatMover on a TrialMover of a SequenceMover # -setup a TrialMover # a. create a SequenceMover of the fragment insertions #### add any other moves you desire folding_mover = protocols.moves.SequenceMover() folding_mover.add_mover(insert_long_frag) folding_mover.add_mover(insert_short_frag) # b. create a MonteCarlo object to define success/failure # must reset the MonteCarlo object for each trajectory! mc = MonteCarlo(test_pose, scorefxn_low, kT) # c. create the TrialMover trial = TrialMover(folding_mover, mc) #### for each trajectory, try cycles number of applications # -create the RepeatMover folding = protocols.moves.RepeatMover(trial, cycles) # 12. create a (Py)JobDistributor jd = PyJobDistributor(job_output, jobs, scorefxn_high) # 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_low(pose) # 14. perform folding by counter = 0 # for exporting to PyMOL while not jd.job_complete: # a. set necessary variables for the new trajectory # -reload the starting pose test_pose.assign(pose) # -change the pose's PDBInfo.name, for the PyMOL_Observer counter += 1 test_pose.pdb_info().name(job_output + '_' + str(counter)) # -reset the MonteCarlo object (sets lowest_score to that of test_pose) mc.reset(test_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 folding.apply(test_pose) #### # c. export the lowest scoring decoy structure for this trajectory # -recover the lowest scoring decoy structure mc.recover_low(test_pose) # -store the final score for this trajectory scores[counter] = scorefxn_low(test_pose) # -convert the decoy to fullatom # the sidechain conformations will all be default, # normally, the decoys would NOT be converted to fullatom before # writing them to PDB (since a large number of trajectories would # be considered and their fullatom score are unnecessary) # here the fullatom mode is reproduced to make the output easier to # understand and manipulate, PyRosetta can load in PDB files of # centroid structures, however you must convert to fullatom for # nearly any other application to_fullatom.apply(test_pose) # -guess what cysteines are involved in disulfide bridges guess_disulfides(test_pose) # -output the fullatom decoy structure into a PDB file jd.output_decoy(test_pose) # -export the final structure to PyMOL test_pose.pdb_info().name(job_output + '_' + str(counter) + '_fa') #### if you want to see the decoy scores, uncomment the line below #scorefxn_high( test_pose ) # 15. output the score evaluations print('===== Centroid Scores =====') print('Original Score\t:\t', scores[0]) for i in range(1, len(scores)): # print out the job scores # the "[:14].ljust(14)" is to force the text alignment print( (job_output + '_' + str( i ))[:14].ljust(14) +\ '\t:\t', scores[i] ) return scores # for other protocols