# Clear the scratch path os.chdir(cwd) if not keep_outputs: shutil.rmtree(scratching_path) if 0 == return_code: return num_matches, matched_positions else: return -1, matched_positions if __name__ == '__main__': pyrosetta.init() binding_site_pdb = './test_inputs/test_site.pdb' site_pose = pyrosetta.pose_from_file(binding_site_pdb) generate_cst_file(site_pose, './test_inputs/test.cst') ##write_params_file_for_ligand(binding_site_pdb, 'test.params') num_matches, matched_positions = standard_rosetta_match('test_rosetta_match', './test_inputs/2src_scaffold.pdb', './test_inputs/test_short.cst', 'ANP', './test_inputs/debug_params/params_file_from_mol2/ANP.params', #keep_outputs=False) keep_outputs=True) print('Found {0} matches. The matched positions are {1}'.format(num_matches, matched_positions))
def main(): init() args = docopt.docopt(__doc__) root_workspace = ws.workspace_from_dir(args['<workspace>']) # posefile = os.path.abspath(args['<target_pdb>']) if args['--target']: targets = args['--target'] else: targets = root_workspace.targets chainmap = None if args['--chainmap']: with open(args['--chainmap']) as file: chainmap = yaml.load(file) for target in targets: workspace = ws.RIFWorkspace(args['<workspace>'], target) workspace.make_dirs() pose = pose_from_file(workspace.initial_target_path) chain = None if chainmap: chain = chainmap[workspace.focus_name] elif args['--chain']: chain = args['--chain'] if chain: print('MAKING PATCHES FOR CHAIN {}'.format(args['--chain'])) poses = [] for i in range(1, pose.num_chains() + 1): chainpose = pose.split_by_chain(i) info = chainpose.pdb_info().pose2pdb(1) if info.split(' ')[1] in chain and chainpose.residue(1).is_protein(): if chainpose.size() < 5: raise('Error: chain {} too small.'.format(chain)) else: poses.append(chainpose) pose = poses[0] if len(poses) > 1: for chainpose in poses[1:]: append_pose_to_pose(pose, chainpose) else: pose = pose.split_by_chain(1) reslist = [] for res in range(1, pose.size() + 1): if pose.residue(res).is_protein(): reslist.append(res) print('POSE SIZE') print(pose.size()) patches = Patches(pose) patches.set_reslist(reslist) patches.determine_surface_residues() print(patches.reslist) patches.map_residues() print(patches.resmap) # parent_folder = os.path.abspath(os.path.join(args['<output_folder>'])) target_pdb = workspace.target_path i = 1 for res in patches.reslist: patch_folder = os.path.join(workspace.focus_dir, 'patch_{}'.format(i)) i += 1 if not os.path.exists(patch_folder): os.makedirs(patch_folder, exist_ok=True) # print(patches.nearest_n_residues(res, 100, # cutoff=float(args['--patchsize']), # pymol=True)) write_to_file(patches.nearest_n_residues(res, 100, cutoff=float(args['--patchsize'])), patch_folder) write_flags(patch_folder, target_pdb) pose.dump_pdb(target_pdb)
def test_get_chain_info(rosetta): pose = pose_from_file('kysi.pdb') seq, resis = get_chain_info(pose, 'B') assert seq == 'KYSI' assert resis == [3, 4, 5, 6]
distance = math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2 + (a[2]-b[2])**2) return distance resi_within = [] center = resi_atom_coords(pose.residue(the_sun)) for resi in range(1, pose.total_residue()+1): # loop over protein planets = resi_atom_coords(pose.residue(resi)) for coords in center: for other_coords in planets: distance = distance_between_two_xyz_coords(coords,other_coords) if distance <= angstrom: resi_within.append(resi) return sorted(list(set(resi_within)))[0:-1] pose = pyrosetta.pose_from_file(<PDB>) sfxn = pyrosetta.get_fa_scorefxn() dssp = pyrosetta.rosetta.core.scoring.dssp.Dssp(pose) ss = dssp.get_dssp_secstruct() #Active site loops loops_at_interface = [] all_loops = [] for j,k in zip(ss, range(1,len(pose.sequence()))): if j == 'L': all_loops.append(k) active_site_resi = resi_within(pose, 10, len(pose.sequence()))
from __future__ import print_function import sys import pyrosetta import pyrosetta.rosetta as rosetta import os os.chdir('.test.output') pyrosetta.init( extra_options="-constant_seed" ) # WARNING: option '-constant_seed' is for testing only! MAKE SURE TO REMOVE IT IN PRODUCTION RUNS!!!!! pose = pyrosetta.pose_from_file("../test/data/test_in.pdb") some_storage = [] # rosetta.core.scoring.methods.ContextIndependentOneBodyEnergy sub-classing ----------------------------------- @pyrosetta.EnergyMethod(version=2) # version is optional here class MyCI1B_Method( rosetta.core.scoring.methods.ContextIndependentOneBodyEnergy): def __init__(self): rosetta.core.scoring.methods.ContextIndependentOneBodyEnergy.__init__( self, self.creator()) def residue_energy(self, rsd, pose, emap): emap.set(self.scoreType, 2.0)
def get_pose(pdbdir, fname): if not HAVE_PYROSETTA: return None return pyrosetta.pose_from_file(join(pdbdir, fname))
from roseasy import big_jobs import os, sys, subprocess, gzip from roseasy.movers import relax as r #from roseasy.standard_params.filters import FilterContainer def get_workspace(root_dir, step): return pipeline.DesignWorkspace(root_dir, step) if __name__ == '__main__': workspace, job_info = big_jobs.initiate() test_run = job_info.get('test_run', False) init('-relax:constrain_relax_to_start_coords -total_threads 1') pdbpath = workspace.input_path(job_info) pose = pose_from_file(workspace.input_pdb_path) relax = r.Relax() dalphaball_path = os.path.join(workspace.rosetta_dir, 'source', 'external', 'DAlpahBall', 'DAlphaBall.gcc') relax.add_init_arg('-holes:dalphaball {} -in:file:s {}'.format( dalphaball_path, pdbpath)) relax.add_init_arg('-total_threads 1') if test_run: relax.rounds = 1 relax.pose = pose # Warning: This is an all-atom movemap. Constrain to input coords if # you don't want things to move around a lot, or set a different # movemap. relax.setup_default_movemap() # Constrain relax to start coords.
import os import pyrosetta import rosetta import pyrosetta.toolbox as toolbox import pprint pyrosetta.init() toolbox.cleanATOM('../PDB_REDO/1DAN_HLTU.pdb') pose = pyrosetta.pose_from_file("../PDB_REDO_Stripped/1DAN_HLTU.pdb") pprint.pprint(dir(pyrosetta)) pprint.pprint(dir(pose))
'ALA', 'ASN', 'ASP', 'ARG', 'CYS', 'GLN', 'GLU', 'GLY', 'HIS', 'ILE', 'LEU', 'LYS', 'MET', 'PRO', 'PHE', 'SER', 'THR', 'TRP', 'TYR', 'VAL' ])) # flags from command line with open('input_files/flags') as fn: flags = fn.read().replace('\n', ' ') pyrosetta.init(''.join(flags)) # extra residue (pNPG) params ligand_params = pyrosetta.Vector1(['input_files/pNPG.params']) new_res_set = pyrosetta.generate_nonstandard_residue_set(ligand_params) # construct pose p = pyrosetta.Pose() pyrosetta.pose_from_file(p, new_res_set, 'input_files/bglb.pdb') # construct score function scorefxn = pyrosetta.create_score_function('beta_cst') # add in enzyme design constraints 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) # mutate the residue target = int(mutant_name[1:-1]) new_res = fmt[mutant_name[-1]] mut = rosetta.protocols.simple_moves.MutateResidue(target, new_res) mut.apply(p)
os.path.join(output_path, 'match_info_{0}.json'.format(num_matches)), 'w') as f: json.dump(match_info, f) matched_positions.append(best_matched_residues) num_matches += 1 return num_matches, matched_positions if __name__ == '__main__': pyrosetta.init() site_pose = pyrosetta.pose_from_file('./test_inputs/test_site.pdb') scaffold_pose = pyrosetta.pose_from_file('./test_inputs/2src_scaffold.pdb') site_protein_residues = [ i for i in range(1, site_pose.size() + 1) if site_pose.residue(i).is_protein() ] scaffold_protein_residues = [ i for i in range(1, scaffold_pose.size() + 1) if scaffold_pose.residue(i).is_protein() ] print( fast_match(site_pose, site_protein_residues, scaffold_pose,
from pyrosetta.rosetta import core, protocols from pyrosetta.teaching import SwitchResidueTypeSetMover, CA_rmsd, calc_Lrmsd import pyrosetta.rosetta.protocols.rigid as rigid_moves 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') ''' for _i in range(10): try: ''' # Docking Moves in Rosetta pose = pose_from_file("../test/data/workshops/complex.start.pdb") print( pose.fold_tree() ) protocols.docking.setup_foldtree(pose, "A_B", Vector1([1])) print( pose.fold_tree() ) jump_num = 1 print( pose.jump(jump_num).get_rotation() ) print( pose.jump(jump_num).get_translation() ) print( "_____ Check point 1" ) pert_mover = rigid_moves.RigidBodyPerturbMover(jump_num, 8, 3) #pert_mover.apply(pose) randomize1 = rigid_moves.RigidBodyRandomizeMover(pose, jump_num, rigid_moves.partner_upstream)
from roseasy.standard_params import filters import os, sys from pyrosetta import pose_from_file from pyrosetta import init from roseasy.pipeline import workspace_from_dir #rosetta_dir = '~/software/rosetta' ws = workspace_from_dir(os.path.expanduser('~/cas/test/')) print(ws.largest_loop) print(ws.loops_path) #sys.exit() dalphaball_path = os.path.join(ws.rosetta_dir, 'source', 'external', 'DAlphaBall', 'DAlphaBall.gcc') init('-holes:dalphaball {} -in:file:s {}'.format(dalphaball_path, ws.input_pdb_path)) pose = pose_from_file(ws.input_pdb_path) filters = filters.get_filters(ws, score_fragments=True, test_run=True) #for f in filters: filters[-1].apply(pose) pose.dump_pdb('test_out.pdb')
def standard_rosetta_match(scratching_path, scaffold_pdb, constraint_file, ligand_name, params_file=None, keep_outputs=False): '''Run standard Rosetta matching. Return the number of matches and the matched positions in rosetta numbering. Return -1 if matching failed. ''' abs_scaffold_pdb = os.path.abspath(scaffold_pdb) abs_constraint_file = os.path.abspath(constraint_file) if not (params_file is None): abs_params_file = os.path.abspath(params_file) with open('../site_settings.json', 'r') as f: site_settings = json.load(f) matcher_app = site_settings['matcher_app'] # Go to the output path cwd = os.getcwd() os.makedirs(scratching_path, exist_ok=True) os.chdir(scratching_path) # Generate pos file scaffold_pose = pyrosetta.pose_from_file(abs_scaffold_pdb) scaffold_protein_residues = [] for i in range(1, scaffold_pose.size() + 1): if scaffold_pose.residue(i).is_protein(): scaffold_protein_residues.append(str(i)) pos_file = 'scaffold.pos' with open(pos_file, 'w') as f: f.write(' '.join(scaffold_protein_residues)) # Run matcher matcher_cmd = [matcher_app, '-match:output_format', 'PDB', '-match:match_grouper', 'SameSequenceGrouper', '-match:consolidate_matches', '-match:output_matches_per_group', '1', '-use_input_sc', '-in:ignore_unrecognized_res', '-ex1', '-ex2', '-enumerate_ligand_rotamers', 'false', '-match::lig_name', ligand_name, '-match:geometric_constraint_file', abs_constraint_file, '-s', abs_scaffold_pdb, '-match::scaffold_active_site_residues', pos_file ] if not (params_file is None): matcher_cmd += ['-extra_res_fa', abs_params_file] return_code = subprocess.call(matcher_cmd) # Count the number of matches and get the matched positions num_matches = 0 matched_positions = [] scaffold_pose = pyrosetta.pose_from_file(abs_scaffold_pdb) scaffold_pose.pdb_info().set_chains('A') for f in os.listdir('.'): if f.startswith('UM') and f.endswith('.pdb'): num_matches += 1 # Extract the matched positions from the name of the output file matched_positions.append([]) pos_string = f.split('_')[2] # Get the positions of the amino acid characters c_positions = [] for i in range(len(pos_string)): if not pos_string[i].isnumeric(): c_positions.append(i) for i in range(len(c_positions)): if i < len(c_positions) - 1: pdb_id = int(pos_string[c_positions[i] + 1 : c_positions[i + 1]]) else: pdb_id = int(pos_string[c_positions[i] + 1 : len(pos_string)]) matched_positions[-1].append(scaffold_pose.pdb_info().pdb2pose('A', pdb_id)) # Clear the scratch path os.chdir(cwd) if not keep_outputs: shutil.rmtree(scratching_path) if 0 == return_code: return num_matches, matched_positions else: return -1, matched_positions
galactose.chi(2, 1) galactose.chi(3, 1) galactose.chi(4, 1) galactose.chi(5, 1) galactose.chi(6, 1) #observer = PyMOL_Observer(galactose, True) galactose.set_chi(1, 1, 180) galactose.set_chi(2, 1, 60) galactose.set_chi(3, 1, 60) galactose.set_chi(4, 1, 0) galactose.set_chi(5, 1, 60) galactose.set_chi(6, 1, -60) maltotriose = pose_from_file('../test/data/carbohydrates/maltotriose.pdb') isomaltose = pose_from_file('../test/data/carbohydrates/isomaltose.pdb') pm.apply(maltotriose) maltotriose.phi(1) maltotriose.psi(1) maltotriose.phi(1) maltotriose.phi(2) maltotriose.psi(2) maltotriose.omega(2) maltotriose.phi(3) maltotriose.psi(3) #observer = PyMOL_Observer(maltotriose, True)
from roseasy import big_jobs #from roseasy.standard_params.filters import FilterContainer import os, sys, subprocess def get_workspace(root_dir, step): return pipeline.ValidationWorkspace(root_dir, step) if __name__ == "__main__": from roseasy.movers.loopmodeler import LoopModeler workspace, job_info = big_jobs.initiate() test_run = job_info.get('test_run', False) init() pdbpath = workspace.input_path(job_info) pose = pose_from_file(pdbpath) lm = LoopModeler() lm.config = 'ngk' lm.fragments_flags = workspace.fragments_flags(pdbpath) lm.loops_from_file(workspace.loops_path) dalphaball_path = os.path.join(workspace.rosetta_dir, 'source', 'external', 'DAlphaBall', 'DAlphaBall.gcc') #lm.add_init_arg('-holes:dalphaball {}'.format(dalphaball_path)) # Init arguments needed to run FragmentScoreFilter & BUNS dalphaball_path = os.path.join(workspace.rosetta_dir, 'source', 'external', 'DAlpahBall', 'DAlphaBall.gcc') lm.add_init_arg('-holes:dalphaball {} -in:file:s {}'.format( dalphaball_path, pdbpath)) lm.add_init_arg('-in:file:s {}'.format(pdbpath)) if test_run: lm.mover.centroid_stage().mark_as_test_run()
def modeling(template_hits, template_pdb_path, alignment_file_path, target_seq_path): top_hit_template_file_path = [] with open(template_hits, newline='') as csvFile: reader = csv.DictReader(csvFile) for row in reader: target_seq = os.path.basename(target_seq_path).split('.')[0] alignment_file_name = '{}_{}.needle'.format(target_seq, row['template']) alignment_file_path_with_name = os.path.join(alignment_file_path, alignment_file_name) top_hit_template_file_path.append(alignment_file_path_with_name) aligned_seq = defaultdict(list) for path in top_hit_template_file_path: target_template_file_name = os.path.splitext(os.path.basename(path))[0] target_name_fasta_format = '>{} ..'.format('_'.join(target_template_file_name.split('_')[0:2])) template_name_fasta_format = '>{} ..'.format('_'.join(target_template_file_name.split('_')[2:])) target_aligned_seq = '' template_aligned_seq = '' with open (path, 'r') as readFile: parse = False parse2 = False for line in readFile: line = line.strip() if not parse: if line.startswith(target_name_fasta_format): parse = True elif line.startswith(template_name_fasta_format): parse = False else: target_aligned_seq+=line if not parse2: if line.startswith(template_name_fasta_format): parse2 = True elif line.startswith('#'): parse2 = False else: template_aligned_seq += line aligned_seq[target_template_file_name].append(target_aligned_seq) aligned_seq[target_template_file_name].append(template_aligned_seq) target_seq_for_modeling = {} for name, alignment_file in aligned_seq.items(): top_hits_alignment = '{}\n{}\n{}\n\n'.format(name, alignment_file[0], alignment_file[1]) with open('top_hits_alignment.txt', 'a') as writeFile: writeFile.write(top_hits_alignment) target_seq_based_on_temp_pdb = '' for i in range(len(alignment_file[0])): if not alignment_file[1][i] == '-': target_seq_based_on_temp_pdb += alignment_file[0][i] target_seq_for_modeling[name]=target_seq_based_on_temp_pdb final_target_template_for_modeling = {} for target_template, target_final_seq in target_seq_for_modeling.items(): template_name = '_'.join(target_template.split('_')[2:]) temp_list_dir = os.listdir(template_pdb_path) for template_hit in temp_list_dir: if template_name in template_hit: final_target_template_for_modeling[template_hit] = target_final_seq for template_pdb, target_seq in final_target_template_for_modeling.items(): output_model_name = '{}_{}.pdb'.format(target_seq_path.split('.')[0], '_'.join(template_pdb.split('_')[0:2])) join_apo_dir_path = os.path.join(template_pdb_path, template_pdb) pose = pyrosetta.pose_from_file(join_apo_dir_path) assert(pose.size() == len(target_seq)) scorefxn = pyrosetta.get_fa_scorefxn() for i in range(len(target_seq)): seqpos = i + 1 name1 = target_seq[i] if (name1 == "-"): continue pyrosetta.rosetta.protocols.toolbox.pose_manipulation.repack_this_residue(seqpos, pose, scorefxn, True, name1) pose.dump_pdb(output_model_name)
def main(): args = docopt.docopt(__doc__) print(args) cluster.require_qsub() start_time = time.time() workspace, job_info = big_jobs.initiate() pdbpath = workspace.input_path(job_info) if not os.path.exists(workspace.output_prefix(job_info)): os.mkdir(workspace.output_prefix(job_info)) outpath = workspace.output_path(job_info) test_run = job_info.get('test_run', False) # append location of Rosetta binaries to path sys.path.append('/wynton/home/kortemme/krivacic/source/bin') # find necessary files tmers = glob.glob( os.path.join(workspace.fragments_dir, workspace.fragments_tag(pdbpath) + '?', '*3mers.gz')) nmers = glob.glob( os.path.join(workspace.fragments_dir, workspace.fragments_tag(pdbpath) + '?', '*9mers.gz')) ss2 = glob.glob( os.path.join(workspace.fragments_dir, workspace.fragments_tag(pdbpath) + '?', '*psipred_ss2')) # Run the ab initio relaxation script. relax_abinitio = [ 'AbinitioRelax.linuxgccrelease', '-abinitio:relax', '-use_filters', 'true', '-abinitio::increase_cycles', '10', '-abinitio::rg_reweight', '0.5', '-abinitio::rsd_wt_helix', '0.5', '-abinitio::rsd_wt_loop', '0.5', '-relax::fast', '-in:file:fasta', workspace.fasta_path, '-in:file:frag3', tmers, '-in:file:frag9', nmers, '-in:file:psipred_ss2', ss2, '-nstruct', args.nstruct, '-out:pdb_gz', '-out:prefix', workspace.output_prefix(job_info), '-out:suffix', workspace.output_suffix(job_info), # '--outdir', workspace.fragments_dir, # '--memfree', args['--mem-free'] ] if args['--dry-run']: print(' '.join(relax_abinitio)) else: subprocess.call(relax_abinitio) init() pose = pose_from_file(outpath) input_pose = pose_from_file(pdbpath) ca_rmsd = CA_rmsd(pose, input_pose) all_atom_rmsd = all_atom_rmsd(pose, input_pose) setPoseExtraScore(pose, 'EXTRA_METRIC_CA_RMSD [[-]]', ca_rmsd) setPoseExtraScore(pose, 'EXTRA_METRIC_AllAtom_RMSD [[-]]', all_atom_rmsd) filters = workspace.get_filters(pose, task_id=job_info['task_id'], score_fragments=not test_run, test_run=test_run) filters.run_filters() total_time = time.time() - start_time setPoseExtraScore(pose, 'EXTRA_METRIC_Run time', total_time) outname = os.path.basename(outpath) outfolder = os.path.join(workspace.output_prefix(job_info), 'filtered') pose.dump_pdb(os.path.join(outfolder, outpath))
def clash_based_taskfactory(pdbpath, pose, workspace): insertion = lucs.get_insertion(pdbpath, workspace) # How much to add to insertion['stop'] to get the residue number to # design input_pose = pose_from_file(workspace.input_pdb_path) designable, repackable = lucs.relative_resfile_from_reference( workspace, insertion, pose, input_pose) # Ignoring repackable residues in resfile. # This should give us all designed positions design_mask = size_list_to_res_selector(designable, pose) design_selector = select.residue_selector.ResidueIndexSelector( numeric.intlist_to_vector1_size(designable)) # Takes a resfile and returns a task factory with a clash-based # repack shell. tf = TaskFactory() cl = operation.InitializeFromCommandline() notaa = operation.ProhibitSpecifiedBaseResidueTypes( strlist_to_vector1_str(['C', 'H']), design_selector) # read = operation.ReadResfile(resfile) tf.push_back(cl) tf.push_back(notaa) # tf.push_back(read) # Select repackable residues from designed residues repack_only = operation.RestrictToRepackingRLT() repack = operation.OperateOnResidueSubset(repack_only, design_selector, False) repack.flip_subset(True) tf.push_back(repack) all_selector = residue_selector.ClashBasedShellSelector(design_mask) all_selector.set_num_shells(2) all_selector.set_include_focus(True) all_selector.invert(True) no_packing = operation.PreventRepackingRLT() static = operation.OperateOnResidueSubset(no_packing, all_selector, False) packertask = tf.create_task_and_apply_taskoperations(pose) ld = rosetta_scripts.XmlObjects.static_get_task_operation( '''<LayerDesign name="layer_all" layer="core_boundary_surface_Nterm_Cterm" use_sidechain_neighbors="True"> <core> <all exclude="CW" /> </core> <boundary> <all exclude="CW" /> </boundary> <Nterm> <all append="DEGHKNQRST" /> <all exclude="CAFILMPVWY" /> </Nterm> <Cterm> <all append="DEGHKNQRST" /> <all exclude="CAFILMPVWY" /> </Cterm> </LayerDesign>''') tf.push_back(static) tf.push_back(ld) packertask = tf.create_task_and_apply_taskoperations(pose) print('PRINTING PACKERTASK') print(packertask) repack_mask = packertask.repacking_residues() design_mask = packertask.designing_residues() movemap = setup_movemap_from_resselectors(design_mask, repack_mask) return tf, movemap
import pyrosetta import pyrosetta.rosetta as rosetta from pyrosetta import init, pose_from_file, create_score_function, ScoreFunction, etable_atom_pair_energies, PyMOLMover from pyrosetta.rosetta import core, protocols from pyrosetta.teaching import fa_atr, fa_rep, fa_sol, hbonds, EMapVector 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') # Scoring Poses ras = pose_from_file("../test/data/workshops/6Q21.clean.pdb") scorefxn = create_score_function("ref2015") print(scorefxn) scorefxn2 = ScoreFunction() scorefxn2.set_weight(fa_atr, 1.0) scorefxn2.set_weight(fa_rep, 1.0) print(scorefxn(ras)) scorefxn.show(ras) print(ras.energies().show(24))
all_match_info = [] for f in os.listdir(scaffold_path): if f.endswith('.pdb') or f.endswith('.pdb.gz'): match_start_time = time.time() match_info = {} match_info['job_id'] = job_id match_info['scaffold'] = f match_info['scaffold'] = f d4 = 'match_scaffold_{0}'.format(f.split('.')[0]) match_output_path = os.path.join(output_path, d1, d2, d3, d4) scaffold_pose = pyrosetta.pose_from_file( os.path.join(scaffold_path, f)) # Run fast match scaffold_protein_residues = [ i for i in range(1, scaffold_pose.size() + 1) if scaffold_pose.residue(i).is_protein() ] num_fast_matches, fast_matched_positions = fast_match.fast_match( site_pose, site_protein_residues, scaffold_pose, scaffold_protein_residues, match_output_path,
parser = optparse.OptionParser() parser.add_option('--pdb_filename', dest = 'pdb_filename', default = '../test/data/test_in.pdb', # default example PDB help = 'the PDB file containing the loop to remodel') parser.add_option('--residues', dest = 'residues', default = '', # default to the median residue number help = 'the (pose numbered) residues to inspect carefully') (options,args) = parser.parse_args() # PDB file option pdb_filename = options.pdb_filename # create a pose from the desired PDB file # -create an empty Pose object pose = Pose() # -load the data from pdb_file into the pose pose_from_file(pose, pdb_filename) # default to the median residue number residues = options.residues if not options.residues: residues = [int(pose.total_residue()/2)] elif options.residues == 'all': # accept the word 'all' in place of a residue list residues = range(1, pose.total_residue() + 1) else: # please provide the residues of interest as , delimited residues = [int(r) for r in options.residues.split(',')] pose_scoring(pose, residues) ################################################################################ # ALTERNATE SCENARIOS
import time def get_workspace(root_dir, step): return pipeline.DesignWorkspace(root_dir, step) if __name__ == '__main__': start_time = time.time() workspace, job_info = big_jobs.initiate() test_run = job_info.get('test_run', False) init() # Figure out input pdb and create a pose pdbpath = workspace.input_path(job_info) pose = pose_from_file(pdbpath) # Create FastDesign object fd = fastdesign.FastDesign() fd.pose = pose fd.add_init_arg('-ex1 -ex2 -use_input_sc -ex1aro') fd.add_init_arg('-total_threads 1') # Create task factory and read the resfile taskfactory = TaskFactory() readresfile = ReadResfile(workspace.resfile_path) taskfactory.push_back(readresfile) fd.task_factory = taskfactory movemap = MoveMap() # Set the movemap to turn off backbone DOF
#! /usr/bin/python # List of commands used in PyRosetts Workshop #5 from __future__ import print_function import pyrosetta import pyrosetta.rosetta as rosetta 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
import pyrosetta import rosetta # input with open( 'input_files/features.flags' ) as fn: flags = fn.read().replace( '\n', ' ' ) 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, 'output_files/H178K.pdb' ) scorefxn = pyrosetta.create_score_function( 'beta_cst' ) report = rosetta.protocols.features.ReportToDB() report.add_features_reporter( rosetta.protocols.features.JobDataFeatures() ) #report.add_features_reporter( rosetta.protocols.features.StructureScoresFeatures( scorefxn ) ) report.apply( p )
import time def get_workspace(root_dir, step): return pipeline.DesignWorkspace(root_dir, step) if __name__ == '__main__': start_time = time.time() workspace, job_info = big_jobs.initiate() test_run = job_info.get('test_run', False) init() # Figure out input pdb and create a pose pdbpath = workspace.input_path(job_info) pose = pose_from_file(pdbpath) temp_outdir = os.path.join(workspace.focus_dir, 'cm_outputs') os.makedirs(temp_outdir, exist_ok=True) os.chdir(temp_outdir) # Set up init args init_args = [] init_args.append('-ex1 -ex2 -use_input_sc -ex1aro -extrachi_cutoff 0') init_args.append('-s {}'.format(pdbpath)) for path in workspace.ligand_params_paths: init_args.append('-extra_res_fa {}'.format(path)) if len(workspace.ligand_params_paths) > 0: init_args.append('-coupled_moves:ligand_mode true') init_args.append('-coupled_moves:output_prefix {}'.format(
fmt = dict( zip( 'ANDRCQEGHILKMPFSTWYV', [ '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()
#!usr/bin/env python import pyrosetta from collections import defaultdict pyrosetta.init() pose = pyrosetta.pose_from_file("test_pose.pdb") scorefxn = pyrosetta.get_fa_scorefxn() scorefxn(pose) sela = pyrosetta.rosetta.core.select.residue_selector.ChainSelector("A") selb = pyrosetta.rosetta.core.select.residue_selector.ChainSelector("B") neigha = pyrosetta.rosetta.core.select.residue_selector.NeighborhoodResidueSelector( sela, 10, False) neighb = pyrosetta.rosetta.core.select.residue_selector.NeighborhoodResidueSelector( selb, 10, False) suba = neigha.apply(pose) subb = neighb.apply(pose) # this will return all currently active TwoBodyEnergies # this thing returns two AnalyticEtableEnergy which is correct. # they get initialized with different flags for intra and inter def find_all_2body_methods(scorefxn): nonzero = scorefxn.get_nonzero_weighted_scoretypes()