def filter_junction(self, pose, junction_res, src_pose_N_info, src_pose_C_info, src_pose_N_jct_res, src_pose_C_jct_res): """TODO: Summary Args: pose (TYPE): Description junction_res (TYPE): Description src_pose_N_info (TYPE): Description src_pose_C_info (TYPE): Description src_pose_N_jct_res (TYPE): Description src_pose_C_jct_res (TYPE): Description Returns: TYPE: Description """ nc, nc_no_helix, n_helix_contacted, n_helix_contacted_before, n_helix_contacted_after, begin_res, end_res = count_contacts_accross_junction( pose, junction_res) jct_pose = Pose() for res_id in range(begin_res, end_res): jct_pose.append_residue_by_bond(pose.residue(res_id)) # mode=pyrosetta.rosetta.core.chemical.type_set_mode_from_string("centroid") # centroid_jct_pose=jct_pose.clone() # pyrosetta.rosetta.core.util.switch_to_residue_type_set(centroid_jct_pose,mode ) score0 = self.scorefxn(jct_pose) # AV.test_pair_alignment(,resN,resC) test, result = self.AV.test_pair_alignment( src_pose_N_info, src_pose_C_info, src_pose_N_jct_res, src_pose_C_jct_res) # Assign grades if test is None: super_grade = 'F' elif result < self.superimpose_rmsd: super_grade = 'A' else: super_grade = 'B' if nc < self.num_contact_threshold - 7: nc_grade = 'F' elif nc < self.num_contact_threshold: nc_grade = 'B' else: nc_grade = 'A' if nc_no_helix < self.num_contact_no_helix_threshold: nc_no_helix_grade = 'B' else: nc_no_helix_grade = 'A' if n_helix_contacted < self.n_helix_contacted_threshold: helix_contact_grade = 'B' else: helix_contact_grade = 'A' grade = super_grade + nc_grade + nc_no_helix_grade + helix_contact_grade return grade
def generate_canonical_rotamer_residues_phipsi(residue_name3, target_phi_psi): raise NotImlementedError canonical_residue = generate_canonical_residue(residue_name3) test_sequence = "AAX[%s]AA" % residue_name3 target_phi, target_psi = target_phi_psi sf = get_score_function() tryrot = TryRotamers(resnum=3, scorefxn=sf, explosion=0, jump_num=0, clash_check=True, solo_res=False, include_current=False) test_pose = Pose() make_pose_from_sequence(test_pose, test_sequence, "fa_standard") for i in range(1, test_pose.size() + 1): test_pose.set_psi(i, target_psi) test_pose.set_phi(i, target_phi) test_pose.set_omega(i, 180) tryrot.setup_rotamer_set(test_pose) rotamer_set = tryrot.rotamer_set() # print('rotamer_set.num_rotamers()', # residue_name3, target_phi_psi, rotamer_set.num_rotamers()) rotamers = [ rotamer_set.rotamer(i).clone() for i in range(1, rotamer_set.num_rotamers() + 1) ] for r in rotamers: r.orient_onto_residue(canonical_residue) r.seqpos(1) return rotamers
def mutate_residue(pose, mutant_position, mutant_aa, pack_radius, pack_scorefxn): if pose.is_fullatom() == False: IOError('mutate_residue only works with fullatom poses') test_pose = Pose() test_pose.assign(pose) # Create a packer task (standard) task = TaskFactory.create_packer_task(test_pose) # the Vector1 of booleans (a specific object) is needed for specifying the # mutation, this demonstrates another more direct method of setting # PackerTask options for design aa_bool = vector1_bool() # PyRosetta uses several ways of tracking amino acids (ResidueTypes) # the numbers 1-20 correspond individually to the 20 proteogenic amino acids # aa_from_oneletter returns the integer representation of an amino acid # from its one letter code # convert mutant_aa to its integer representation mutant_aa = aa_from_oneletter_code(mutant_aa) # mutation is performed by using a PackerTask with only the mutant # amino acid available during design # to do this, construct a Vector1 of booleans indicating which amino acid # (by its numerical designation, see above) to allow for i in range(1, 21): # in Python, logical expression are evaluated with priority, thus the # line below appends to aa_bool the truth (True or False) of the # statement i == mutant_aa aa_bool.append(i == mutant_aa) # modify the mutating residue's assignment in the PackerTask using the # Vector1 of booleans across the proteogenic amino acids task.nonconst_residue_task(mutant_position).restrict_absent_canonical_aas( aa_bool) # prevent residues from packing by setting the per-residue "options" of # the PackerTask center = pose.residue(mutant_position).nbr_atom_xyz() for i in range(1, pose.total_residue() + 1): dist = center.distance_squared(test_pose.residue(i).nbr_atom_xyz()) # only pack the mutating residue and any within the pack_radius print(i, pack_radius, dist, pow(float(pack_radius), 2)) print('##################################################') if i != mutant_position and dist > pow(float(pack_radius), 2): task.nonconst_residue_task(i).prevent_repacking() # apply the mutation and pack nearby residues packer = PackRotamersMover(pack_scorefxn, task) packer.apply(test_pose) return test_pose
def generate_canonical_residue(residue_name3): work_pose = Pose() make_pose_from_sequence(work_pose, "X[%s]" % residue_name3, "fa_standard", auto_termini=False) work_residue = rosetta.core.conformation.Residue(work_pose.residue(1)) ca_loc = work_residue.xyz("CA") for a in range(work_residue.natoms()): work_residue.set_xyz(a + 1, work_residue.xyz(a + 1) - ca_loc) return work_residue
def poses_from_silent(silent_filename): """Returns an Iterator object which is composed of Pose objects from a silent file. @atom-moyer """ sfd = rosetta.core.io.silent.SilentFileData( rosetta.core.io.silent.SilentFileOptions()) sfd.read_file(silent_filename) for tag in sfd.tags(): ss = sfd.get_structure(tag) pose = Pose() ss.fill_pose(pose) pose.pdb_info().name(tag) yield pose
def run_mcmc(pose): # old_score = score(pose) old_pose = Pose() old_pose.assign(pose) # sample; sample(pose) new_score = score(pose) # accept? P = math.exp(-1 * (new_score - old_score) / 1.5) print(P) if P > 1: return pose else: p = random.uniform(0, 1.0) if p < P: return pose else: return old_pose
# 举例使用FastDesign快速设计一些序列和结构: from pyrosetta import pose_from_pdb, init, create_score_function from pyrosetta.rosetta.protocols.denovo_design.movers import FastDesign from pyrosetta.rosetta.core.pack.task import TaskFactory from pyrosetta.rosetta.core.pose import Pose from pyrosetta.io import poses_to_silent # init init('') # load pose starting_pose = pose_from_pdb('./data/EHEE_rd4_0976.pdb') ref2015 = create_score_function('ref2015') design_tf = TaskFactory() # setup FastDesign fastdesign = FastDesign(ref2015, 1) fastdesign.set_default_movemap() #使用默认的Movemap() fastdesign.set_task_factory(design_tf) # design for 10 times: for i in range(10): design_pose = Pose() design_pose.assign(starting_pose) # assign pose fastdesign.apply(design_pose) ## apply design # output to silent file; poses_to_silent(design_pose, './data/design_result.silent')
import pyrosetta from pyrosetta.rosetta.core.pose import Pose from pyrosetta.rosetta.core.conformation import Residue from pyrosetta.rosetta.core.kinematics import FoldTree from pyrosetta.rosetta.core.select.residue_selector import ResidueIndexSelector pyrosetta.init( extra_options="-constant_seed -out:mute all" ) # WARNING: option '-constant_seed' is for testing only! MAKE SURE TO REMOVE IT IN PRODUCTION RUNS!!!!! import os os.chdir('.test.output') pose1 = pyrosetta.pose_from_sequence('ACDEFGHI') # Test __len__ assert (len(Pose().residues) == 0) assert (len(pose1.residues) == 8) assert (len(pose1) == 8) # Deprecated # Test __iter__ for residue in Pose().residues: pass for residue in pose1.residues: pass for residue in pose1: # Deprecated pass # Test __getitem__ # assert(pose1.residues[0] == ValueError)
def pose_from_sequence(seq, res_type="fa_standard", auto_termini=True): """ Returns a pose generated from a single-letter sequence of amino acid residues in <seq> using the <res_type> ResidueType and creates N- and C- termini if <auto_termini> is set to True. Unlike make_pose_from_sequence(), this method generates a default PDBInfo and sets all torsion angles to 180 degrees. Example: pose = pose_from_sequence("THANKSEVAN") See also: Pose make_pose_from_sequence() pose_from_file() pose_from_rcsb() """ pose = Pose() make_pose_from_sequence(pose, seq, res_type, auto_termini) #print 'Setting phi, psi, omega...' for i in range(0, pose.total_residue()): res = pose.residue(i + 1) if not res.is_protein() or res.is_peptoid() or res.is_carbohydrate(): continue pose.set_phi(i + 1, 180) pose.set_psi(i + 1, 180) pose.set_omega(i + 1, 180) #print 'Attaching PDBInfo...' # Empty PDBInfo (rosetta.core.pose.PDBInfo()) is not correct here; # we have to reserve space for atoms.... pose.pdb_info(rosetta.core.pose.PDBInfo(pose)) pose.pdb_info().name(seq[:8]) # print pose return pose