def defineLigandStructure(self, ligandFile, nameLigand, pathfile=""): self.__ligandName = nameLigand 'Validates path parameters' if (pathfile == ""): pathfile = self.__resDir 'Delete Files' self.deleteRosettaFiles() 'Creates mdl file' os.system(BABEL_COM + ' -ipdb ' + os.path.join(pathfile, ligandFile) + ' -omdl ' + os.path.join(self.__tmpDir, 'Struct.mdl')) 'Generates param file' os.system(PYTHON_COM + os.path.join(self.__molDir, 'molfile_to_params.py') + ' ' + os.path.join(self.__tmpDir, 'Struct.mdl') + ' -d ' + self.__tmpDir + ' -n ' + self.__ligandName) self.__residueSet = rosetta.generate_nonstandard_residue_set( [os.path.join(self.__tmpDir, self.__ligandName + '.params')]) 'Generates Ligand' self.__ligandFile = IO.readPDB(self.__ligandName + '_0001.pdb', 'HETATM', self.__tmpDir) IO.writePDB("ligand.pdb", self.__ligandFile, self.__tmpDir) 'Init Function' self.__scorefxn = rosetta.create_score_function("ligand")
def fa_rep(self, norm=True): import_rosetta() sfxn = rosetta.create_score_function('talaris2014') # sfxn = rosetta.create_score_function_ws_patch("standard", "score12") p = self.pose() sfxn(p) fa_rep = p.energies().total_energies()[rosetta.fa_rep] if norm: return fa_rep / p.n_residue() return fa_rep
def score(self, norm=True): """ Use Rosetta::Score to evaluate a structure """ import_rosetta() sfxn = rosetta.create_score_function('talaris2014') # sfxn = rosetta.create_score_function_ws_patch("standard", "score12") p = self.pose() sc = sfxn(p) if norm: return sc / p.n_residue() return sc
def relax(self): """ Apply Rosetta:FastRelax """ import_rosetta() pose = self.pose() relax = rosetta.FastRelax() relax.constrain_relax_to_start_coords(True) relax.set_scorefxn(rosetta.create_score_function('talaris2014')) # relax.set_scorefxn(rosetta.create_score_function_ws_patch("standard", "score12")) relax.apply(pose) return self.from_pose(pose)
def main(argv): ## Step 1: Initialize Rosetta, including spanfile for the membrane framework rosetta.init( extra_options= "-mp:setup:spanfiles inputs/1qd6_tr_C.span -run:constant_seed") ## Step 2: Load in pose as a membrane pose (using AddMembraneMover) pose = pose_from_pdb("inputs/1qd6_tr_C.pdb") add_memb = rosetta.protocols.membrane.AddMembraneMover() add_memb.apply(pose) ## Step 3: Orient Pose in the membrane based on transmembrane spans init_mem_pos = rosetta.protocols.membrane.MembranePositionFromTopologyMover( ) init_mem_pos.apply(pose) ## Step 4: Create a membrane energy function ## @note: Two possible energy functions: (1) standard membrane full atom energy function ## or (2) energy function accommodating for pH (requires extra flags - see README) sfxn = create_score_function("mpframework_smooth_fa_2012") ## Step 5: Repack neighbors within 8.0 angstroms of the mutant position repacked_native = mutate_residue(pose, 181, 'A', 8.0, sfxn) ## Step 6: Compute the ddG of mutation from alanine to each of the 20 canonical ## amino acids. Then print the ddG file to an output file (ompLA_ddG.out) AAs = [ 'A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'Y' ] with file('ompLA_ddG.out', 'a') as f: f.write("Res AA ddG\n") for aa in AAs: ddG = compute_ddG(repacked_native, sfxn, 181, aa, 8.0) f.write(str(181) + " " + aa + " " + str(round(ddG, 3)) + "\n") f.close
default_color=rosetta.protocols.moves.XC_blue) #pymol.send_energy( pose_s ) time.sleep(.1) rosetta.init() pose = rosetta.Pose() pose.name = 'CustomNamedPose' pose_s = rosetta.Pose() rosetta.pose_from_pdb(pose, "test/data/test_in.pdb") rosetta.pose_from_pdb(pose_s, "test/data/test_in_short.pdb") scorefxn = rosetta.create_score_function('standard') scorefxn(pose) pymol = rosetta.PyMOL_Mover() pymol.apply(pose_s) coloring_demo(pose_s) seq = rosetta.protocols.moves.SequenceMover() seq.add_mover(pymol) seq.apply(pose) seq.apply(pose_s) #pm.sendEnergies(pose, 'some_thing', [1,2,3]) #pm.sendEnergies(pose, 'some_thing_other', [1,2,3./7., 1/3.])
def main( args ): parser = OptionParser(usage="usage: %prog [OPTIONS] [TESTS]") parser.set_description(main.__doc__) #input options parser.add_option('--in_pdb', '-p', action="store", help="Input PDB file.", ) parser.add_option('--in_span', '-s', action="store", help="Input spanfile.", ) parser.add_option('--out', '-o', action="store", default='ddG.out', help="Output filename with pose residue numbering. Default: 'ddG.out'", ) parser.add_option('--res', '-r', action="store", help="Pose residue number to mutate.", ) parser.add_option('--mut', '-m', action="store", help="One-letter code of residue identity of the mutant. Example: A181F would be 'F'", ) parser.add_option('--repack_radius', '-a', action="store", default=0, help="Repack the residues within this radius",) parser.add_option('--output_breakdown', '-b', action="store", default="scores.sc", help="Output mutant and native score breakdown by weighted energy term into a scorefile", ) #parse options (options, args) = parser.parse_args(args=args[1:]) global Options Options = options # Check the required inputs (PDB file, spanfile) are present if ( not Options.in_pdb or not Options.in_span or not Options.res ): sys.exit( "Must provide flags '-in_pdb', '-in_span', and '-res'! Exiting..." ) # Initialize Rosetta options from user options. rosetta_options = "-mp:setup:spanfiles " + Options.in_span + " -run:constant_seed -in:ignore_unrecognized_res" rosetta.init( extra_options=rosetta_options ) # Load Pose, & turn on the membrane pose = pose_from_file( Options.in_pdb ) # Add Membrane to Pose add_memb = rosetta.protocols.membrane.AddMembraneMover() add_memb.apply( pose ) # Setup in a topology based membrane init_mem_pos = rosetta.protocols.membrane.MembranePositionFromTopologyMover() init_mem_pos.apply( pose ) # check the user has specified a reasonable value for the pH sfxn = rosetta.core.scoring.ScoreFunction() # Create a smoothed membrane full atom energy function (pH 7 calculations) sfxn = create_score_function( "mpframework_smooth_fa_2012") # Repack the native rotamer and residues within the repack radius native_res = pose.residue( int( Options.res ) ).name1() repacked_native = mutate_residue( pose, int( Options.res), native_res, Options.repack_radius, sfxn ) # to output score breakdown, start by printing the score labels in # the top of the file print_score_labels_to_file( repacked_native, sfxn, Options.output_breakdown ) # Compute mutations if ( Options.mut ): with file( Options.out, 'a' ) as f: ddGs = compute_ddG( repacked_native, sfxn, int( Options.res ), Options.mut, Options.repack_radius, Options.output_breakdown ) f.write( Options.in_pdb + " " + Options.res + " " + str(ddGs[0]) + " " + str(ddGs[1]) + " " + str(ddGs[2]) + " " + str(ddGs[3]) + "\n" ) f.close else: AAs = ['A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'Y'] for aa in AAs: with file( Options.out, 'a' ) as f: ddGs = compute_ddG( repacked_native, sfxn, int( Options.res ), aa, Options.repack_radius, Options.output_breakdown ) f.write( str(ddGs[0]) + " " + str(ddGs[1]) + " " + str(ddGs[2]) + " " + str(ddGs[3]) + "\n" ) f.close
def __init__(self, pdb, centroid=False, pdb_file='', frag=False, nine_mer=False, local=False, local_size=3, full=False, rosetta_refinement=False): """ :param pdb: :type string: pdb ID of the protein to be folded :param centroid: :type boolean: Option for use of centroid model """ self.loops = 0 # Stores generation for which energy score was last calculated self.scores = {} # Dictionary container for current gen genomes/scores self.scores_list = [] # List container of current gen scores for search self.gen_added = 0 # Last gen in which a point was added to novelty archive self.threshold = 10 # Novelty threshold for which point is added to archive self.acceptance_threshold = 100 # Novelty threshold for which move is accepted automatically self.num_added = 0 # Number of points added to novelty archive self.switch = False # All atom switch self.temperature = 5 # Monte Carlo temperature self.mover_range = 10 # +-range of the angle in degrees in which mover moves residue self.local_size = local_size # For local mover, size of fragment to move self.local = local # Whether to use local mover self.novelty_archive = deque() # Initialize novelty archive self.centroid = centroid # If true use centroid scoring self.last_lowest = 0 # For use in novelty loop self.last_lowest_10 = 0 # For use in clear main loop self.frag = frag # If true use frag mover self.rosetta_refinement = rosetta_refinement # If true refine rosetta fold # Rosetta inits rosetta.init() # Initialize rosetta libraries pose_native = pose_from_rcsb(pdb) # Create rosetta pose of natively folded protein from pdb file sequence = pose_native.sequence() # Get sequence of protein self.scorefxn = rosetta.get_fa_scorefxn() # Create the rosetta energy score function for all atom if pdb_file != '': self.pose = rosetta.pose_from_pdb(pdb_file) # If a starting pdb is given search from this pose elif rosetta_refinement: # If rosetta refinement, start from fastrelax structure self.pose = rosetta.pose_from_sequence(sequence) relax = rosetta.FastRelax() relax.set_scorefxn(self.scorefxn) relax.apply(self.pose) else: self.pose = rosetta.pose_from_sequence(sequence) # Create the rosetta pose that will be manipulated if centroid: # Switch pose to centroid if centroid option is true switch = rosetta.SwitchResidueTypeSetMover("centroid") switch.apply(self.pose) self.c_size = len(sequence)*2 # Number of residues * 2 (phi and psi for each residue) self.native_energy = self.scorefxn(pose_native) # Energy of the natively folded protein if centroid: # Switch rosetta score function if centroid self.scorefxn = rosetta.create_score_function('score3') self.conformation = [] i = 1 while i <= len(sequence): self.conformation.append(self.pose.phi(i)) self.conformation.append(self.pose.psi(i)) i += 1 self.mc_energy = self.scorefxn(self.pose) + 500 # Energy to be used as minimal criteria self.lowest = self.scorefxn(self.pose) # Lowest energy in archive if frag: if nine_mer: fragset = rosetta.ConstantLengthFragSet(9) fragset.read_fragment_file("aat000_09_05-1.200_v1_3") else: fragset = rosetta.ConstantLengthFragSet(3) fragset.read_fragment_file("aat000_03_05-1.200_v1_3") movemap = rosetta.MoveMap() movemap.set_bb(True) self.mover_3mer = rosetta.ClassicFragmentMover(fragset, movemap) if local: # For local, initialize na with appropriate number of deques self.novelty_archive = [deque() for i in range(self.c_size/2/self.local_size)] self.full = full # If true use full mover
def main(): parent_path = "/Users/yanxia/Documents/Workspace/PyRosetta_Practice/" resource_path = parent_path + "resources" os.chdir(resource_path) rosetta.init() # initiate pose and two score functions pose = rosetta.Pose() rosetta.make_pose_from_sequence(pose, "GSSGSSGTGVKPYGCSQCAKTFSLKSQLIVHQRSHTGVKPSGPSSG", "centroid") fa_scorefxn = rosetta.create_score_function("standard") ct_scorefxn = rosetta.create_score_function("score3") kt_value = 1 # initiate fragment set fragmentSet9 = rosetta.ConstantLengthFragSet(9) fragmentSet3 = rosetta.ConstantLengthFragSet(3) fragmentSet9.read_fragment_file("zf_9mer.txt") fragmentSet3.read_fragment_file("zf_3mer.txt") # set up movemap and Fragment Mover movemap = rosetta.MoveMap() movemap.set_bb(True) move_9mer = rosetta.ClassicFragmentMover(fragmentSet9, movemap) move_3mer = rosetta.ClassicFragmentMover(fragmentSet3, movemap) # Monte Carlo mc_low = rosetta.MonteCarlo(pose, ct_scorefxn, kt_value) #set up small and shear movers n_moves = 5 small_mover = rosetta.SmallMover(movemap, kt_value, n_moves) shear_mover = rosetta.ShearMover(movemap, kt_value, n_moves) #set up minimize mover min_mover = rosetta.MinMover() min_mover.movemap(movemap) min_mover.score_function(fa_scorefxn) min_mover.min_type("linmin") min_mover.tolerance(0.5) #set up sequence mover and repeat mover seq_mover = rosetta.SequenceMover() seq_mover.add_mover(small_mover) seq_mover.add_mover(min_mover) seq_mover.add_mover(shear_mover) seq_mover.add_mover(min_mover) # folding # first low resolution #ct_switch = rosetta.SwitchResidueTypeSetMover("centroid") #ct_switch.apply(pose) low_res_folding(pose, move_9mer, move_3mer, mc_low) # high resolution fa_switch = rosetta.SwitchResidueTypeSetMover("fa_standard") fa_switch.apply(pose) mc_high = rosetta.MonteCarlo(pose, fa_scorefxn, kt_value) for i in range(5): print "before: ", fa_scorefxn(pose) max_angle = 25 - 5 * i small_mover.angle_max("H", max_angle) small_mover.angle_max("E", max_angle) small_mover.angle_max("S", max_angle) shear_mover.angle_max("H", max_angle) shear_mover.angle_max("E", max_angle) shear_mover.angle_max("S", max_angle) for _ in range(simulation_iter): seq_mover.apply(pose) mc_high.boltzmann(pose) print "after: ", fa_scorefxn(pose) result_path = parent_path + "results/" os.chdir(result_path) pose.dump_pdb("ara.pdb") print "Done!"
def mutate_residue(pose, mutant_position, mutant_aa, pack_radius=0.0, pack_scorefxn=''): """ Replaces the residue at <mutant_position> in <pose> with <mutant_aa> and repack any residues within <pack_radius> Angstroms of the mutating residue's center (nbr_atom) using <pack_scorefxn> note: <mutant_aa> is the single letter name for the desired ResidueType example: mutate_residue(pose,30,A) See also: Pose PackRotamersMover MutateResidue pose_from_sequence """ #### a MutateResidue Mover exists similar to this except it does not pack #### the area around the mutant residue (no pack_radius feature) #mutator = MutateResidue( mutant_position , mutant_aa ) #mutator.apply( test_pose ) if pose.is_fullatom() == False: IOError('mutate_residue only works with fullatom poses') test_pose = Pose() test_pose.assign(pose) # create a standard scorefxn by default if not pack_scorefxn: pack_scorefxn = create_score_function('standard') task = standard_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 = rosetta.utility.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): # only pack the mutating residue and any within the pack_radius if not i == mutant_position or center.distance_squared( test_pose.residue(i).nbr_atom_xyz()) > 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 main(): parent_path = "/Users/yanxia/Documents/Workspace/PyRosetta_Practice/" resource_path = parent_path + "resources" os.chdir(resource_path) rosetta.init() # initiate pose and two score functions pose = rosetta.Pose() rosetta.make_pose_from_sequence( pose, "GSSGSSGTGVKPYGCSQCAKTFSLKSQLIVHQRSHTGVKPSGPSSG", "centroid") fa_scorefxn = rosetta.create_score_function("standard") ct_scorefxn = rosetta.create_score_function("score3") kt_value = 1 # initiate fragment set fragmentSet9 = rosetta.ConstantLengthFragSet(9) fragmentSet3 = rosetta.ConstantLengthFragSet(3) fragmentSet9.read_fragment_file("zf_9mer.txt") fragmentSet3.read_fragment_file("zf_3mer.txt") # set up movemap and Fragment Mover movemap = rosetta.MoveMap() movemap.set_bb(True) move_9mer = rosetta.ClassicFragmentMover(fragmentSet9, movemap) move_3mer = rosetta.ClassicFragmentMover(fragmentSet3, movemap) # Monte Carlo mc_low = rosetta.MonteCarlo(pose, ct_scorefxn, kt_value) #set up small and shear movers n_moves = 5 small_mover = rosetta.SmallMover(movemap, kt_value, n_moves) shear_mover = rosetta.ShearMover(movemap, kt_value, n_moves) #set up minimize mover min_mover = rosetta.MinMover() min_mover.movemap(movemap) min_mover.score_function(fa_scorefxn) min_mover.min_type("linmin") min_mover.tolerance(0.5) #set up sequence mover and repeat mover seq_mover = rosetta.SequenceMover() seq_mover.add_mover(small_mover) seq_mover.add_mover(min_mover) seq_mover.add_mover(shear_mover) seq_mover.add_mover(min_mover) # folding # first low resolution #ct_switch = rosetta.SwitchResidueTypeSetMover("centroid") #ct_switch.apply(pose) low_res_folding(pose, move_9mer, move_3mer, mc_low) # high resolution fa_switch = rosetta.SwitchResidueTypeSetMover("fa_standard") fa_switch.apply(pose) mc_high = rosetta.MonteCarlo(pose, fa_scorefxn, kt_value) for i in range(5): print "before: ", fa_scorefxn(pose) max_angle = 25 - 5 * i small_mover.angle_max("H", max_angle) small_mover.angle_max("E", max_angle) small_mover.angle_max("S", max_angle) shear_mover.angle_max("H", max_angle) shear_mover.angle_max("E", max_angle) shear_mover.angle_max("S", max_angle) for _ in range(simulation_iter): seq_mover.apply(pose) mc_high.boltzmann(pose) print "after: ", fa_scorefxn(pose) result_path = parent_path + "results/" os.chdir(result_path) pose.dump_pdb("ara.pdb") print "Done!"
# Prepare the foldtree. upstream_chains, downstream_chains = \ determine_docking_partners(starting_pose) partners = upstream_chains + "_" + downstream_chains # TODO: Modify C++ so that chemical edges are not removed. setup_foldtree(starting_pose, partners, Vector1([JUMP_NUM])) # Print some information about the starting pose. print "", starting_pose.fold_tree(), print ' Ligand [chain(s) ' + downstream_chains + '] center is', print starting_pose.jump(JUMP_NUM).get_translation().length, print 'angstroms from protein center [chain(s) ' + upstream_chains + '].' # Prepare scoring function. if args.mm: sf = create_score_function('mm_std') else: #sf = get_fa_scorefxn() sf = create_score_function_ws_patch('talaris2013', 'docking') sf.set_weight(hbond_sr_bb, sf.get_weight(hbond_sr_bb) * args.Hbond_mult) sf.set_weight(hbond_lr_bb, sf.get_weight(hbond_lr_bb) * args.Hbond_mult) sf.set_weight(hbond_bb_sc, sf.get_weight(hbond_bb_sc) * args.Hbond_mult) sf.set_weight(hbond_sc, sf.get_weight(hbond_sc) * args.Hbond_mult) if not args.mm: sf.set_weight(fa_elec, sf.get_weight(fa_elec) * args.elec_mult) sf.set_weight(fa_sol, sf.get_weight(fa_sol) * args.sol_mult) target_atr = sf.get_weight(fa_atr) * args.atr_mult target_rep = sf.get_weight(fa_rep) * args.rep_mult sf.set_weight(fa_atr, target_atr) sf.set_weight(fa_rep, target_rep) print ' Starting Score:'