def setup_fastrelax(sf, pose): """ Creates FastRelax mover with appropriate score function, movemap, and packer rules. All sidechains are mobile, only substrate backbone is mobile. """ relax = FastRelax() relax.set_scorefxn(sf) # MoveMap mm = MoveMap() mm.set_chi(True) for i in range(1, pose.total_residue() + 1): if pose.residue(i).chain() == 2: mm.set_bb(i, True) relax.set_movemap(mm) # Packer tasks tf = standard_task_factory() tf.push_back(RestrictToRepacking()) tf.push_back(IncludeCurrent()) tf.push_back(ExtraRotamers(0, 1, 1)) tf.push_back(ExtraRotamers(0, 2, 1)) relax.set_task_factory(tf) return relax
def fast_relax_mutant(pose, task_factory, move_map, score_function, decoys=1): """ Runs Fast Relax on the mutant pose instead of just repack an minimize. Can modify to take varying amounts of decoys. """ fast_relax = FastRelax(1) fast_relax.set_scorefxn(score_function) fast_relax.set_task_factory(task_factory) fast_relax.set_movemap(move_map) score_function(pose) packer = task_factory.create_task_and_apply_taskoperations(pose) print_out("packer task") print_out(packer) #sys.exit() traj_idx = 0 lowest_energy = 1000.0 print_out("emd182::Running Fast Relax") while traj_idx < decoys: print_out("Round Number: " + str(traj_idx)) pose_copy = pr.Pose() pose_copy.assign(pose) print_out("emd182:: pose total residues: " + str(pose.total_residue())) fast_relax.apply(pose_copy) decoy_energy = total_energy(pose_copy, score_function) if traj_idx == '0': mutated_pose = pose_copy lowest_energy = decoy_energy elif decoy_energy < lowest_energy: mutated_pose = pose_copy lowest_energy = decoy_energy traj_idx += 1 return mutated_pose
def setup_fastrelax(sf): """ Creates FastRelax mover with appropriate score function, movemap, and packer rules. List of neighbor residues was generated using a 8A PyMOL selection expansion around the peptide chain. """ relax = FastRelax() relax.set_scorefxn(sf) # MoveMap mm = MoveMap() mm.set_bb_true_range(106, 112) neighbors = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 19, 22, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 53, 59, 62, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 83, 85, 98, 100, 101, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112 ] # Did 8A selection separately for n in neighbors: mm.set_chi(n, True) relax.set_movemap(mm) # Packer tasks tf = standard_task_factory() tf.push_back(RestrictToRepacking()) tf.push_back(IncludeCurrent()) tf.push_back(ExtraRotamers(0, 1, 1)) tf.push_back(ExtraRotamers(0, 2, 1)) relax.set_task_factory(tf) return relax
def get_relaxer_mover(pose, score_function=DEFAULT.score_function, no_constraints=DEFAULT.no_constraints, c_weight=DEFAULT.c_weight): """ TO DO """ if score_function == "auto": try: score_function = get_fa_scorefxn() except: import pyrosetta init() score_function = get_fa_scorefxn() else: from pyrosetta.rosetta.core.scoring import ScoreFunction assert type(score_function) == ScoreFunction, \ "Score function for relaxer mover must be of type ScoreFunction." if no_constraints == False: coordinates_constraint = CoordinateConstraintGenerator() constraints = AddConstraints() constraints.add_generator(coordinates_constraint) constraints.apply(pose) activate_constraints(score_function, c_weight) task_factory = standard_task_factory() task_factory.push_back(ExtraRotamers(0, 2, 1)) task_factory.push_back(RestrictToRepacking()) task_factory.push_back(IncludeCurrent()) fast_relax = FastRelax() fast_relax.set_scorefxn(score_function) fast_relax.set_task_factory(task_factory) return fast_relax
def fast_relax_mover(score_function, task_factory=None, movemap=None, repeats=5): """ Creates a FastRelax mover with a given score function. If a task factory and/or movemap are provided, they will also be incorporated into the mover. By default, FastRelax goes through five ramping cycles, but this number can be adjusted with the repeats option. """ from pyrosetta.rosetta.protocols.relax import FastRelax # Make FastRelax mover with given score function fr = FastRelax(repeats) fr.set_scorefxn(score_function) # Set task factory if task_factory: fr.set_task_factory(task_factory) # Set move map if movemap: fr.set_movemap(movemap) return fr
def setup_fastrelax(sf): """ Creates FastRelax mover with appropriate score function, movemap, and packer rules. List of neighbor residues was generated using a 10A neighborhood residue selector around the peptide chain. """ relax = FastRelax() relax.set_scorefxn(sf) # MoveMap mm = MoveMap() mm.set_bb_true_range(212,216) neighbors = [28, 29, 41, 42, 43, 44, 45, 46, 59, 60, 61, 62, 91, 125, 126, 127, 128, 129, 145, 147, 148, 149, 150, 151, 157, 164, 165, 166, 167, 168, 169, 170, 171, 183, 184, 185, 186, 187, 188, 189, 192, 193, 194, 212, 213, 214, 215, 216, 217, 218, 219, 220] # Did 10A selection separately for n in neighbors: mm.set_chi(n, True) relax.set_movemap(mm) # Packer tasks tf = standard_task_factory() tf.push_back(RestrictToRepacking()) tf.push_back(IncludeCurrent()) tf.push_back(ExtraRotamers(0, 1, 1)) tf.push_back(ExtraRotamers(0, 2, 1)) relax.set_task_factory(tf) return relax
def create_fast_relax_mover(score_function, task_factory, move_map=None): # Make FastRelax mover fast_relax = FastRelax() fast_relax.set_scorefxn(score_function) fast_relax.set_task_factory(task_factory) if move_map: fast_relax.set_movemap(move_map) return fast_relax
def fastrelax(pose, score_function, movemap): """ Runs the FastRelax protocol on a pose, using given score function and movemap """ relax = FastRelax() relax.set_scorefxn(score_function) relax.set_movemap(movemap) relax.apply(pose) return pose
def main(args): # Destination folder for PDB files od = out_directory(args.out_dir) # Determining file name if args.name: file_name = args.name else: file_name = basename(args.pdb_file).replace('.pdb', '').replace('.gz', '') file_name += '_relaxed' out_name = join(od, file_name) # Loading pose and applying constraints, symmetry, pose = load_pose(args.pdb_file, enzdes_cst=args.constraints, coord_cst=True, symmetry=args.symmetry, membrane=None) # Setting up the scorefunction with the desired constraint weights sf = get_sf(rep_type='hard', symmetry=args.symmetry, membrane=0, constrain=args.constraint_weight) # Creating FastRelax protocol with the given score function fr = FastRelax() fr.set_scorefxn(sf) # Packer tasks tf = standard_task_factory() tf.push_back(RestrictToRepacking()) tf.push_back(IncludeCurrent()) tf.push_back(ExtraRotamers(0, 1, 1)) tf.push_back(ExtraRotamers(0, 2, 1)) fr.set_task_factory(tf) # RMSD metric rmsdm = RMSDMetric() rmsdm.set_comparison_pose(pose) # Running relax set jd = PyJobDistributor(out_name, args.n_decoys, sf) while not jd.job_complete: pp = Pose(pose) fr.apply(pp) rmsdm.apply(pp) jd.output_decoy(pp) print("Starting relax {}".format(pdb_name)) pose = fastrelax(pose, sf, mm, taskfactory=tf)
def fastrelax(pose, score_function, movemap, taskfactory=None): """ Runs the FastRelax protocol on a pose, using given score function and movemap, and optionally a task factory. By default, FastRelax will not do design. However, given a task factory that enables design, it functions like FastDesign. """ relax = FastRelax() relax.set_scorefxn(score_function) relax.set_movemap(movemap) if taskfactory: relax.set_task_factory(taskfactory) pp = Pose(pose) relax.apply(pp) return pp
def __init__(self, net, pose, fix=None, glycinate=False, max_iter=100, n_moves=1, scorefxn=None, kT=0.1, k=15, dropout=0.5, relax=True): super(NetPackMover, self).__init__(net, pose, k=k, dropout=dropout) self.relax = relax self.n_moves = n_moves self.max_iter = max_iter self.kT = kT self.scorefxn = scorefxn self.fix = fix if fix is not None else [] self.step = 0 self.fastrelax = ... if relax or glycinate: fastrelax = FastRelax() fastrelax.set_scorefxn(self.scorefxn) mm = MoveMap() mm.set_bb(False) mm.set_chi(True) #for fixed in self.fix: # mm.set_chi(fixed, False) fastrelax.set_movemap(mm) self.fastrelax = fastrelax if glycinate: self.dropout = 1.0 mask = torch.tensor([ 1 - int(self.fixed_position(idx)) for idx in range(len(pose.sequence())) ], dtype=torch.bool) for idx, residue in enumerate(pose.residues): residue_name = self.sample_residue(pose, idx, mask=mask, argmax=True) if not self.fixed_position(idx): mutate_residue(pose, idx + 1, residue_name, pack_radius=10.0, pack_scorefxn=scorefxn) mask[idx] = 0 self.dropout = dropout self.fastrelax.apply(pose) self.monte_carlo = MonteCarlo(pose, scorefxn, kT) self.glycinate = glycinate
def relax(pdb, native, scorefxn=scorefxn_fa): """ Performs energy minimization using Rosetta FastRelax protocol, superimpose onto native structure, and calculate RMSD -------- Params - pdb (str): path to input structure in PDB format - native (str): path to native structure in PDB format - scorefxn (ScoreFunction): energy function to use in scoring. Either centroid ('score3') or full-atom ('fa_standard'), default full-atom Returns - Protein object representing relaxed structure - RMSD between input and native (float) - Score after minimization (float) """ pose = pose_from_pdb(pdb) score = score_pose(pose, scorefxn) print('initial score', score) to_fullatom = SwitchResidueTypeSetMover('fa_standard') to_fullatom.apply(pose) relax = FastRelax() #ClassicRelax() relax.set_scorefxn(scorefxn) relax.apply(pose) score = score_pose(pose, scorefxn) print('final score', score) pose.dump_pdb("%s_fast_relax.pdb" % (pdb[:-4])) native_pose = pose_from_pdb(native) relax.apply(native_pose) native_pose.dump_pdb("%s_fast_relax.pdb" % (native[:-4])) rmsd = superimpose_rmsd("%s_fast_relax.pdb" % (pdb[:-4]), "%s.pdb" % (native[:-4])) print('RMSD to native', rmsd) return Protein(pose=pose), rmsd, score
def main(args): init() sf = create_score_function('ref2015_cst') sf.set_weight(ScoreType(1).atom_pair_constraint, 2) # Increasing repulsion weight sf.set_weight(ScoreType(1).dihedral_constraint, 0.5) # Reducing dihedral weight def_score = get_fa_scorefxn() if not isdir(args.outdir): makedirs(args.outdir) # Reading in PDB, determining middle chain pose = pose_from_pdb(args.start_struct) chain_count = pose.num_chains() chain_no = chain_count / 2 # Determining which sites to tug if args.test_single: tug_sites = [args.test_single] else: chain_residues = selector_to_list(pose, get_mobile_range(chain_no)) tug_sites = chain_residues[1::args.frame] # First res will error # Error because dihedrals are calculated using the upstream residue # Making decoy set for each sliding frame on the tau middle monomer for site in tug_sites: in_res = int(pose.pdb_info().pose2pdb(site).split()[0]) site_name = join(args.outdir, 'tau_fibril_distort_' + str(in_res)) # Determining backbone-mobile section of pose if args.mobile_range: mobile_selection = get_mobile_range(chain_no, \ central_res=in_res, range_from_tug=args.mobile_range) else: mobile_selection = get_mobile_range(chain_no) # Selecting repackable shell within 18A of the target (includes target) ris = ResidueIndexSelector(str(site)) nrs = NeighborhoodResidueSelector(ris, 18) # Combining selections combined_selection = OrResidueSelector() combined_selection.add_residue_selector(mobile_selection) combined_selection.add_residue_selector(nrs) # Making move map and task factory for FastRelax mm = make_move_map(pose, mobile_selection, combined_selection) tf = make_task_factory(combined_selection) # Making FastRelax fr = FastRelax() fr.set_scorefxn(sf) fr.set_movemap(mm) fr.set_task_factory(tf) # Making constraints csts = make_constraints(pose, chain_no, site, args.tug_distance) # Making ten decoys jd = PyJobDistributor(site_name, args.num_decoys, sf) while not jd.job_complete: p = Pose() p.assign(pose) # Add constraints for c in csts: p.add_constraint(c) fr.apply(p) print("\n" * 5, jd.current_name) print(sf.show(p), "\n" * 5) jd.output_decoy(p)
#!/usr/bin/python from glob import glob from os.path import basename, join from pyrosetta import * from pyrosetta.rosetta.protocols.relax import FastRelax init() sf = create_score_function('ref2015_cst') fr = FastRelax() fr.set_scorefxn(sf) fr.constrain_coords(True) fr.constrain_relax_to_start_coords(True) fr.coord_constrain_sidechains(True) structs = glob('pdz_nmr/*.pdb') structs.sort() for s in structs: pose = pose_from_pdb(s) jdname = join('pdz_relax/', basename(s).rstrip('.pdb')) jd = PyJobDistributor(jdname, 20, sf) while not jd.job_complete: pp = Pose() pp.assign(pose) fr.apply(pp) jd.output_decoy(pp)
# Ex. task_factory.push_back(ExtraRotamers(0, 1, 1)) # ex1 task_factory.push_back(ExtraRotamers(0, 2, 1)) # ex2 # FastRelax, by default, blocks 'design' on the regular rotamers. However, # when adding the ExtraRotamers, new 'designable' rotamers are included # and considered during the sampling. Therefore, the TaskFactory must # re-restrict the rotamers to repackaging. task_factory.push_back(RestrictToRepacking()) # Altough the PyRosetta manual states that the current rotamer is included # by default, this does not seem to be true and therefore needs to be # activated. task_factory.push_back(IncludeCurrent()) # Define the FastRelax object with the correct score function and extra # rotamers enabled fast_relax = FastRelax() fast_relax.set_scorefxn(score_function) fast_relax.set_task_factory(task_factory) fast_relax.apply(pose) pose.dump_pdb(args.output + ".pdb") # A U X I L I A R Y F U N C T I O N S # ______________________________________________________________________________ # # Minimalistic version of the above script. # Aimed to be called from other scripts. def relax(pose, no_constraints=DEFAULT.no_constraints, c_weight=DEFAULT.c_weight):
def main(args): # Destination folder for PDB files if args.out_dir: dir_name = args.out_dir if not isdir(dir_name): makedirs(dir_name) else: dir_name = "" # Creating coordinate constraints for the entire molecule cg = CoordinateConstraintGenerator() ac = AddConstraints() ac.add_generator(cg) # Create enzdes constraints if args.constraints: enz_cst = AddOrRemoveMatchCsts() enz_cst.set_cst_action(ADD_NEW) # Creating symmetry setup if args.symmetry: sfsm = SetupForSymmetryMover(args.symmetry) # Setting up the scorefunction with the desired constraint weights if args.symmetry: sf = SymmetricScoreFunction() sf.add_weights_from_file(args.score_function) else: sf = create_score_function(args.score_function) if args.coord_wt: sf.set_weight(st.coordinate_constraint, args.coord_wt) if args.enzdes_wt: sf.set_weight(st.atom_pair_constraint, args.enzdes_wt) sf.set_weight(st.angle_constraint, args.enzdes_wt) sf.set_weight(st.dihedral_constraint, args.enzdes_wt) # Creating FastRelax protocol with the given score function fr = FastRelax() fr.set_scorefxn(sf) # Packer tasks tf = standard_task_factory() tf.push_back(RestrictToRepacking()) tf.push_back(IncludeCurrent()) tf.push_back(ExtraRotamers(0, 1, 1)) tf.push_back(ExtraRotamers(0, 2, 1)) fr.set_task_factory(tf) # Determining file name if args.name: file_name = args.name else: file_name = basename(args.pdb_file).replace('.pdb', '').replace('.gz', '') file_name += '_relaxed' out_name = join(dir_name, file_name) # Loading PDB file, applying constraints pose = pose_from_pdb(args.pdb_file) ac.apply(pose) if args.constraints: enz_cst.apply(pose) if args.symmetry: sfsm.apply(pose) # RMSD metric rmsdm = RMSDMetric() rmsdm.set_comparison_pose(pose) # Running relax set jd = PyJobDistributor(out_name, args.n_decoys, sf) while not jd.job_complete: pp = Pose() pp.assign(pose) fr.apply(pp) rmsdm.apply(pp) jd.output_decoy(pp)
def main(args): # Destination folder for PDB files if args.out_dir: dir_name = args.out_dir if not isdir(dir_name): makedirs(dir_name) else: dir_name = "" # Creating coordinate constraints for the entire molecule cg = CoordinateConstraintGenerator() ac = AddConstraints() ac.add_generator(cg) # Create enzdes constraints if args.constraints: enz_cst = AddOrRemoveMatchCsts() enz_cst.set_cst_action(ADD_NEW) ''' Declare the score function. ''' if args.symmetry: # Declare symmetric score functions score_function = SymmetricScoreFunction() if args.repulsive_type == 'hard': if args.membrane: score_function.add_weights_from_file('franklin2019') else: score_function.add_weights_from_file('ref2015') elif args.repulsive_type == 'soft': if args.membrane: # Set up a soft-rep version of franklin2019 manually score_function.add_weights_from_file('ref2015_soft') score_function.set_weight(ScoreType.fa_water_to_bilayer, 1.0) else: score_function.add_weights_from_file('ref2015_soft') else: # Declare ordinary score functions if args.repulsive_type == 'hard': if args.membrane: score_function = create_score_function('franklin2019') else: score_function = create_score_function('ref2015') elif args.repulsive_type == 'soft': if args.membrane: # Set up a soft-rep version of franklin2019 manually score_function = create_score_function('ref2015_soft') score_function.set_weight(ScoreType.fa_water_to_bilayer, 1.0) else: score_function = create_score_function('ref2015_soft') if args.coord_wt: score_function.set_weight(ScoreType.coordinate_constraint, args.coord_wt) if args.enzdes_wt: score_function.set_weight(ScoreType.atom_pair_constraint, args.enzdes_wt) score_function.set_weight(ScoreType.angle_constraint, args.enzdes_wt) score_function.set_weight(ScoreType.dihedral_constraint, args.enzdes_wt) # Loading PDB file pose = pose_from_pdb(args.pdb_file) if args.symmetry: # Applying symmetry if specified sfsm = SetupForSymmetryMover(args.symmetry) sfsm.apply(pose) if args.membrane: # Set up membrane for membrane protein add_memb = SymmetricAddMembraneMover(args.span_file) add_memb.apply(pose) else: if args.membrane: # Set up membrane for membrane protein add_memb = AddMembraneMover(args.span_file) add_memb.apply(pose) # Creating FastRelax protocol with the given score function fr = FastRelax() fr.set_scorefxn(score_function) # Packer tasks tf = standard_task_factory() tf.push_back(IncludeCurrent()) tf.push_back(ExtraRotamers(0, 1, 1)) tf.push_back(ExtraRotamers(0, 2, 1)) protein_selector = ResiduePropertySelector(ResidueProperty.PROTEIN) repack = RestrictToRepackingRLT() tf.push_back(OperateOnResidueSubset(repack, protein_selector)) prevent = PreventRepackingRLT() tf.push_back(OperateOnResidueSubset(prevent, protein_selector, True)) fr.set_task_factory(tf) move_map = MoveMap() if args.repulsive_type == 'hard': move_map.set_bb(True) elif args.repulsive_type == 'soft': ''' When using the soft-rep score function, backbone should be fixed. ''' move_map.set_bb(False) protein_res_true_vector = protein_selector.apply(pose) move_map.set_chi(protein_res_true_vector) fr.set_movemap(move_map) # Determining file name if args.name: file_name = args.name else: file_name = basename(args.pdb_file).replace('.pdb', '_relaxed') out_name = join(dir_name, file_name) # Applying constraints ac.apply(pose) if args.constraints: enz_cst.apply(pose) # RMSD metric rmsdm = RMSDMetric() rmsdm.set_comparison_pose(pose) print(tf.create_task_and_apply_taskoperations(pose)) # Running relax set jd = PyJobDistributor(out_name, args.n_decoys, score_function) while not jd.job_complete: pp = Pose() pp.assign(pose) fr.apply(pp) rmsdm.apply(pp) jd.output_decoy(pp)