예제 #1
0
def mutate_pose(pose, mutations):
    """Applies list of mutations to the given template pose and returns a mutated version
    Args:
        pose: PyRosetta Pose() object representing a loaded pdb structure
        mutations: list of amino acid swaps to apply, format is: [(int, char), ..., (int, char)]
                   where char is a string of length 1 in "ACDEFGHIKLMNPQRSTVWY"
    Returns:
        mutant_pose containing the specified amino acid swaps
    Notes:
        - this procedure doesn't modify the input pose
    """
    mutant_pose = Pose()
    mutant_pose.assign(pose)
    for aa_num, aa_replacement in mutations:
        # ensure mutation is valid and apply it
        assert isinstance(aa_num, int)
        assert isinstance(aa_replacement, str) and len(aa_replacement) == 1
        mutant_pose = mutate_residue(mutant_pose, aa_num, aa_replacement)
    # specify a pose packer to repack the mutation region
    pose_packer = standard_packer_task(mutant_pose)
    pose_packer.restrict_to_repacking()
    # =================================
    # mark's hack segment
    # =================================
    # This is a hack, but I want to test. Can't set a movemap, resfiles
    # might be the way to go. Freeze all residues.
    pose_packer.temporarily_fix_everything()
    # Let's release the PI domain
    for i in range(1110, 1388):
        pose_packer.temporarily_set_pack_residue(i, True)
    # =================================
    # specify the rotamer mover and apply repacking
    packmover = PackRotamersMover(get_fa_scorefxn(), pose_packer)
    packmover.apply(mutant_pose)
    return mutant_pose
예제 #2
0
 def mutateRes(self, res, chain, new_res):
     new_res = new_res.split(":")
     new_res = new_res[2]
     res = self.pose.pdb_info().pdb2pose(chain, int(res))
     pack_radius = tkSimpleDialog.askfloat(
         title="Pack radius",
         prompt="Please enter the desired neighbor packing radius (A)",
         initialvalue=5.0)
     if pack_radius == None: return
     #print radius
     print self.score_class.score(self.pose)
     print "Mutating to " + new_res
     mutate_residue(self.pose, res, new_res, pack_radius,
                    self.score_class.score)
     print self.score_class.score(self.pose)
     print "Mutagenesis Complete."
     return self.pose
예제 #3
0
def mutate_pose(pose, mutations):
    """Applies list of mutations to the given template pose and returns a mutated version
    Args:
        pose: PyRosetta Pose() object representing a loaded pdb structure
        mutations: list of amino acid swaps to apply, format is: [(int, char), ..., (int, char)]
                   where char is a string of length 1 in "ACDEFGHIKLMNPQRSTVWY"
    Returns:
        mutant_pose containing the specified amino acid swaps
    Notes:
        - this procedure doesn't modify the input pose
    """
    mutant_pose = Pose()
    mutant_pose.assign(pose)
    for aa_num, aa_replacement in mutations:
        assert isinstance(aa_num, int)
        assert isinstance(aa_replacement, str) and len(aa_replacement) == 1
        scorefxn = get_fa_scorefxn()
        pose_num = find_py_rosetta_res_num(
            mutant_pose,
            'B',
            aa_num,
        )
        # Use this mutate_residue for automatic repacking based on distance (angstroms)
        # distance can be set with using an int in the fourth arguement position. Please run 0,2,5
        mutant_pose = mutate_residue(mutant_pose, pose_num, aa_replacement, 0,
                                     scorefxn)
        # use the mutate_residue below for manually specifying packing residues with the pose_packer
        # code below. Try the entire pdb_range, as well as setting to the aa_num list passed to
        # the function
        # mutant_pose = mutate_residue(mutate_residue, pose_num, aa_replacement)
    # kims lines from D050 example
    # =================================
    # pose_packer = standard_packer_task(mutant_pose)
    # pose_packer.restrict_to_repacking()
    # This is a hack, but I want to test. Can't set a movemap, resfiles
    # might be the way to go. Freeze all residues.
    # pose_packer.temporarily_fix_everything()
    # Let's release the PI domain
    # for i in range(1097, 1364):
    #     pose_num = find_py_rosetta_res_num(mutant_pose, 'B', i)
    #     pose_packer.temporarily_set_pack_residue(pose_num,True)
    # packmover = PackRotamersMover(scorefxn, pose_packer)
    # packmover.apply(mutant_pose)
    # =================================
    return mutant_pose
예제 #4
0
def compute_ddG(pose, sfxn, resnum, aa, repack_radius, sc_file):

    # Score Native Pose
    native_score = sfxn(pose)

    # Perform Mutation at residue <resnum> to amino acid <aa>
    mutated_pose = mutate_residue(pose, resnum, aa, repack_radius, sfxn)

    # Score Mutated Pose
    mutant_score = sfxn(mutated_pose)

    # If specified the user, print the breakdown of ddG values into a file
    print_ddG_breakdown(pose, mutated_pose, sfxn, resnum, aa, sc_file)

    # return scores
    return aa, round(mutant_score,
                     3), round(native_score,
                               3), round(mutant_score - native_score, 3)
def mutate_pose(pose, mutations):
    """Applies list of mutations to the given template pose and returns a mutated version
    Args:
        pose: PyRosetta Pose() object representing a loaded pdb structure
        mutations: list of amino acid swaps to apply, format is: [(int, char), ..., (int, char)]
                   where char is a string of length 1 in "ACDEFGHIKLMNPQRSTVWY"
    Returns:
        mutant_pose containing the specified amino acid swaps
    Notes:
        - this procedure doesn't modify the input pose
    """
    mutant_pose = Pose()
    mutant_pose.assign(pose)
    for aa_num, aa_replacement in mutations:
        assert isinstance(aa_num, int)
        assert isinstance(aa_replacement, str) and len(aa_replacement) == 1
        scorefxn = get_fa_scorefxn()
        pose_num = find_py_rosetta_res_num(mutant_pose, 'B',aa_num,)
        # Use this mutate_residue for automatic repacking based on distance (angstroms)
        # distance can be set with using an int in the fourth arguement position. Please run 0,2,5
        mutant_pose = mutate_residue(mutant_pose, pose_num, aa_replacement, 0, scorefxn)
        # use the mutate_residue below for manually specifying packing residues with the pose_packer
        # code below. Try the entire pdb_range, as well as setting to the aa_num list passed to
        # the function
        # mutant_pose = mutate_residue(mutate_residue, pose_num, aa_replacement)
    # kims lines from D050 example
    # =================================
    # pose_packer = standard_packer_task(mutant_pose)
    # pose_packer.restrict_to_repacking()
    # This is a hack, but I want to test. Can't set a movemap, resfiles
    # might be the way to go. Freeze all residues. 
    # pose_packer.temporarily_fix_everything()
    # Let's release the PI domain
    # for i in range(1097, 1364):
    #     pose_num = find_py_rosetta_res_num(mutant_pose, 'B', i)
    #     pose_packer.temporarily_set_pack_residue(pose_num,True)
    # packmover = PackRotamersMover(scorefxn, pose_packer)
    # packmover.apply(mutant_pose)
    # =================================
    return mutant_pose
예제 #6
0
def mutate_pose(pose, mutations):
    """Applies list of mutations to the given template pose and returns a mutated version
    Args:
        pose: PyRosetta Pose() object representing a loaded pdb structure
        mutations: list of amino acid swaps to apply, format is: [(int, char), ..., (int, char)]
                   where char is a string of length 1 in "ACDEFGHIKLMNPQRSTVWY"
    Returns:
        mutant_pose containing the specified amino acid swaps
    Notes:
        - this procedure doesn't modify the input pose
    """
    mutant_pose = Pose()
    mutant_pose.assign(pose)
    for aa_num, aa_replacement in mutations:
        # ensure mutation is valid and apply it
        assert isinstance(aa_num, int)
        assert isinstance(aa_replacement, str) and len(aa_replacement) == 1
        #Use the find_pyrosetta_res_num() to automatically convert from pdb to Rosetta numbering
        pose_num = find_pyrosetta_res_num(mutate_pose, 'B', aa_num)
        mutant_pose = mutate_residue(mutant_pose, pose_num, aa_replacement)
    # specify a pose packer to repack the mutation region
    pose_packer = standard_packer_task(mutant_pose)
    pose_packer.restrict_to_repacking()
    # =================================
    # mark's hack segment
    # =================================
    # This is a hack, but I want to test. Can't set a movemap, resfiles
    # might be the way to go. Freeze all residues.
    pose_packer.temporarily_fix_everything()
    # Let's release the PI domain
    for i in range(1110, 1388):
        pose_num = find_pyrosetta_res_num(mutate_pose, 'B', i)
        pose_packer.temporarily_set_pack_residue(pose_num, True)
    # =================================
    # specify the rotamer mover and apply repacking
    packmover = PackRotamersMover(get_fa_scorefxn(), pose_packer)
    packmover.apply(mutant_pose)
    return mutant_pose
def runFoldxSimpleMutator(mutant, pdbs):
  output = open('list.txt', 'w')
  fns = ''
  for pdb in pdbs:
    fns += pdb + '\n'
  output.write(fns)
  output.close()

  m=mutant[2:-1]
  here=mutant[-1]

  name=rev_resdict[mutant[-1]]+mutant[2:-1]+'_'+pdbs
  print("name of file",str(name))
  
  initial_pose=pose_from_pdb(pdbs)
  res = initial_pose.residue(int(mutant[2:-1]))
  #Set up ScoreFunction.
  sf = get_fa_scorefxn()

  pose2=mutate_residue( initial_pose, int(mutant[2:-1]),mutant[-1],10,sf )
  print("mutant", mutant)
  print("pdbs", pdbs)

  pose2.dump_pdb(str(name))
예제 #8
0
def main():
    # Initialize Rosetta.
    init(extra_options='-mute basic -mute core')

    # Constants
    PACK_RADIUS = 10.0
    #Population size
    N = 37
    #Beta (temp term)
    beta = 1
    #look up what the first stored value was in the files to get the threshold
    threshold = float(-534.687360627 / 2)

    #Set up ScoreFunction
    sf = get_fa_scorefxn()

    #Set up MoveMap.
    mm = MoveMap()
    mm.set_bb(True)
    mm.set_chi(True)

    #Prepare data headers
    data = ['Generation,RevertTo,OrgScore,RevScore,Change,Prob\n']

    # Get the reversions file, the output file the score_mutant_pdb has made
    variant_scores = open('mh_rep_3_37.csv')

    #get just the mutation we want to revert to
    lines = variant_scores.readlines()
    var_line = lines[
        2]  #gets the Nth line how ever long you want the burn to be
    var_line = var_line.split(',')[0]

    var_loc = int(filter(str.isdigit, var_line))
    var_rev = var_line[:1]

    gen = 1
    #get all the pdb files
    sort_list = sorted(glob.glob('*.pdb'), key=numericalSort)

    for i in range(1, len(sort_list) - 15):

        #calc reversion for next 15 moves
        for infile in sorted(glob.glob('*.pdb'), key=numericalSort)[i:i + 15]:

            #for each mutation
            var_line = lines[
                gen +
                1]  #gets the Nth line how ever long you want the burn to be
            var_line = var_line.split(',')[0]
            var_loc = int(filter(str.isdigit, var_line))
            var_rev = var_line[:1]

            print "Current File Being Processed is: " + infile
            initial_pose = pose_from_pdb(infile)
            initial_score = sf(initial_pose)
            print("init scored")
            mutant_pose = mutate_residue(initial_pose, var_loc, var_rev,
                                         PACK_RADIUS, sf)
            variant_score = sf(mutant_pose)
            probability = calc_prob_mh(variant_score, initial_score, N, beta,
                                       threshold)
            print(
                str(gen) + "," + var_line + "," + str(initial_score) + "," +
                str(variant_score) + "," + str(variant_score - initial_score) +
                "," + str(probability) + "\n")
            data.append(
                str(gen) + "," + var_line + "," + str(initial_score) + "," +
                str(variant_score) + "," + str(variant_score - initial_score) +
                "," + str(probability) + "\n")
        gen += 1

    print '\nDONE'

    data_filename = 'rep_3_mh_37_rev_15_score.csv'
    with open(data_filename, "w") as f:
        f.writelines(data)
예제 #9
0
def main():
    #read in the file made by the forward sim
    args = sys.argv
    inputfile = args[1]
    data = open(inputfile)
    first_line = data.readlines()[1]
    var_line=first_line.split(',')
    start_stab=var_line[1]

    #the first entry in the file is the wild type structure, calc the threshold using this
    threshold=float(start_stab)+10
    print(threshold)
    
    # Initialize Rosetta.
    init(extra_options='-mute basic -mute core')

    # Constants
    PACK_RADIUS = 0
    #Population size
    N = 100
    #Beta (temp term)
    beta = .6
  
    #Set up ScoreFunction
    sf = get_fa_scorefxn()

    #Set up MoveMap.
    mm = MoveMap()
    mm.set_bb(True)
    mm.set_chi(True)

    min_mover = MinMover()
    min_mover.movemap(mm)
    min_mover.score_function(sf)
    min_mover.min_type('dfpmin_armijo_nonmonotone')

    #Prepare data headers
    data = ['pdbfile_target,pdbfile_used,step,RevertTo,Change,Pos,From,OrgScore,RevScore,Change,Prob\n']

    # Get the reversions file, the output file the score_mutant_pdb has made
    variant_scores=open(inputfile)

    #get just the mutation we want to revert to
    lines= variant_scores.readlines()
    var_line=lines[500] #gets the Nth line how ever long you want the burn to be
    print "staring here", var_line  
    var_line=var_line.split(',')[0]
  
    var_loc=int(filter(str.isdigit, var_line))
    var_rev=var_line[:1]

    gen=1
    #get all the pdb files
    sort_list=sorted(glob.glob('*[0-9].pdb'), key=numericalSort)
    sort_list=sort_list[-1016:] #include the last 1000 and some pdbs, the 16 is because we want the ones that happened before the 500th mutation too. 

  
    for i in range(1,len(sort_list)-30):
      step=-15
      #calc reversion for next 15 moves
      for infile in sort_list[i:i+31]:

	#for each mutation	
        var_line=lines[gen+500] #gets the Nth line how ever long you want the burn to be
        var_line=var_line.split(',')[0]
	print(var_line)
        var_loc=int(filter(str.isdigit, var_line))
	var_rev=""
	old=""
	if(step<0):
        	var_rev=var_line[len(var_line)-1:len(var_line)]
		old=var_line[:1]
	
	else:
		var_rev=var_line[:1]
		old=var_line[len(var_line)-1:len(var_line)]

      	print "Current File Being Processed is: " + infile
        print "revering to:", var_rev
        print "at:", var_loc

	#get the pdb you want to revert and make the reversion
        initial_pose = pose_from_pdb(infile)
        mutant_pose = mutate_residue(initial_pose, var_loc , var_rev, PACK_RADIUS, sf)

	#repack mut
        task1 = standard_packer_task(mutant_pose)
	task1.restrict_to_repacking()
        task1.or_include_current(True)
        packer_rotamers_mover1 = RotamerTrialsMover(sf,task1)
	packer_rotamers_mover1.apply(mutant_pose)

	#repack init
        task2 = standard_packer_task(initial_pose)
	task2.restrict_to_repacking()
	task2.or_include_current(True)
	pack_rotamers_mover2 = RotamerTrialsMover(sf, task2)
	pack_rotamers_mover2.apply(initial_pose)

	#apply min mover
	min_mover.apply(mutant_pose)
	min_mover.apply(initial_pose)
	
	#get scores    
	variant_score = sf(mutant_pose)
        initial_score = sf(initial_pose)

	#get prob
        probability = calc_prob_mh(variant_score, initial_score, N, beta, threshold)

	print(str(gen+499)+".pdb"+","+str(infile)+","+str(step)+","+ str(var_line) + ","+str(var_rev)+","+str(var_loc)+","+str(old)+"," +str(initial_score) + "," + str(variant
_score) + "," + str(variant_score - initial_score)+ ","+ str(probability)+ "\n")
      	data.append(str(gen+499)+".pdb"+","+str(infile)+","+str(step)+","+ str(var_line) + ","+str(var_rev)+","+str(var_loc)+","+str(old)+"," +str(initial_score) + "," + str(v
ariant_score) + "," + str(variant_score - initial_score)+ ","+ str(probability)+ "\n")
	step=step+1
      gen+=1

    print '\nDONE'

    data_filename = 'premutate_rep1_bb_T_ch_T.csv'
    with open(data_filename, "w") as f:
        f.writelines(data)
예제 #10
0
def main():
    #takes name of pdb file without the extention
    args = sys.argv
    pdb_file = args[1]
    #set up timer to figure out how long the code took to run
    t0 = time()

    # Initialize Rosetta.
    init(extra_options='-mute basic -mute core')

    # Constants
    PACK_RADIUS = 10.0
    #Amino acids, notice there is no C
    AAs = ("A", "D", "E", "F", "G", "H", "I", "K", "L", "M", "N", "P", "Q",
           "R", "S", "T", "V", "W", "Y")
    #Number of mutations to accept
    max_accept_mut = 1500
    #Population size
    N = 100
    #Beta (temp term)
    beta = 1

    #Prepare data headers
    data = ['Variant,Rosetta Score,"delta-delta-G",Probability,Generation\n']

    #Load and clean up pdb file
    name = pdb_file + ".pdb"
    cleanATOM(name)
    clean_name = pdb_file + ".clean.pdb"
    initial_pose = pose_from_pdb(clean_name)

    #Set up ScoreFunction
    sf = get_fa_scorefxn()

    #Set up MoveMap.
    mm = MoveMap()
    #change these for more or less flexability
    mm.set_bb(True)
    mm.set_chi(True)

    #Pack and minimize initial pose to remove clashes.
    pre_pre_packing_score = sf(initial_pose)

    task = standard_packer_task(initial_pose)
    task.restrict_to_repacking()
    task.or_include_current(True)
    pack_rotamers_mover = RotamerTrialsMover(sf, task)
    pack_rotamers_mover.apply(initial_pose)

    min_mover = MinMover()
    min_mover.movemap(mm)
    min_mover.score_function(sf)
    min_mover.min_type('dfpmin_armijo_nonmonotone')
    min_mover.apply(initial_pose)

    post_pre_packing_score = sf(initial_pose)

    #Set threshold for selection
    threshold = pre_pre_packing_score / 2

    data.append('WT,' + str(post_pre_packing_score) + ',0.0 ,0.0,0\n')

    #number of residues to select from
    n_res = initial_pose.total_residue()

    #start sim
    i = 0
    gen = 0
    while i < max_accept_mut:
        #update the number of generations that have pased
        gen += 1

        print 'accepts:', i

        #pick a place to mutate
        mut_location = random.randint(1, n_res)

        #get the amino acid at that position
        res = initial_pose.residue(mut_location)

        #don't mess with C, just choose again
        while (res.name1() == 'C'):
            mut_location = random.randint(1, n_res)
            #get the amino acid at that position
            res = initial_pose.residue(mut_location)

#choose the amino acid to mutate to
        new_mut_key = random.randint(0, len(AAs) - 1)

        proposed_res = AAs[new_mut_key]

        #don't bother mutating to the same amino acid it just takes more time
        while (proposed_res == res.name1()):
            new_mut_key = random.randint(0, len(AAs) - 1)
            proposed_res = AAs[new_mut_key]

#make the mutation
#this is actually a really bad model, and probably shouldnt be used. In new version is repack the whole thing, then reminimize, I should also backrub it.
        mutant_pose = mutate_residue(initial_pose, mut_location, proposed_res,
                                     PACK_RADIUS, sf)

        #score mutant
        variant_score = sf(mutant_pose)

        #get the probability that the mutation will be accepted
        probability = calc_prob_mh(variant_score, post_pre_packing_score, N,
                                   beta, threshold)

        #test to see if mutation is accepted
        if random.random() < probability:

            #create a name for the mutant if its going to be kept
            variant_name = res.name1() + str(initial_pose.pdb_info().number(
                mut_location)) + str(proposed_res)

            # Assuming 1000 burn in phase, take this if out if you want to store everything
            if i > 1000:
                #save name and energy change
                data.append(variant_name + "," + str(variant_score) + "," +
                            str(variant_score - post_pre_packing_score) + "," +
                            str(probability) + "," + str(gen) + "\n")

                pdb_name = str(i) + ".pdb"
                mutant_pose.dump_pdb(pdb_name)

            #update the wildtype
            initial_pose = mutant_pose
            post_pre_packing_score = variant_score

            #update number of accepts
            i += 1

    print '\nMutations and scoring complete.'
    t1 = time()
    # Output results.
    data_filename = pdb_file[:-5] + 'mh_1500_rep3.csv'
    with open(data_filename, "w") as f:
        f.writelines(data)

    print 'Data written to:', data_filename
    print 'program takes %f' % (t1 - t0)
예제 #11
0
         )  ##where the WT cas9 should be located???
## not sure if completely correct???? add changes if not.

## initializing rosetta:
rosetta.init()

# import cleaning module for PDB to be usable
from toolbox import cleanATOM

cleanATOM("\4UN3.pdb")  # cleaned PDB file to use for analysis
var_pose = pose_from_pdb("\4UN3.pdb")  # initial pose created from clean pdb

#inputted residue number of interest
Num = raw_input("enter residue number:\n")

for i in range(0, 20):
    # list of Amino Acids to substitute
    AA_lst = "ACDEFGHIKLMNPQRSTVWY"
    AA_var = AA_lst[i]

    var_pose = pose_from_pdb("4UN3." + AA_var + ".clean.pdb")
    mutate_residue(var_pose, Num,
                   AA_var)  # where Num = residue number to substitute AA

    # for sanity checking purposes: prints out changed 4UN3 pdb pose protein profile
    #  (sequence, # of res, what is located at Num residue - if the substitution occured)
    print var_pose
    print var_pose.sequence()
    print "Protein has", var_pose.total_residue(), "residues."
    print var_pose.residue(Num).name()  # where Num is a residue number
## not sure if completely correct???? add changes if not.

## initializing rosetta:
rosetta.init()

# import cleaning module for PDB to be usable
from toolbox import cleanATOM

cleanATOM("\4UN3.pdb") # cleaned PDB file to use for analysis
var_pose = pose_from_pdb("\4UN3.pdb") # initial pose created from clean pdb

#inputted residue number of interest
Num = raw_input("enter residue number:\n")

for i in range(0, 20):
	# list of Amino Acids to substitute
	AA_lst = "ACDEFGHIKLMNPQRSTVWY"
	AA_var = AA_lst[i]

	var_pose = pose_from_pdb("4UN3." + AA_var + ".clean.pdb")
	mutate_residue(var_pose, Num , AA_var) # where Num = residue number to substitute AA

	# for sanity checking purposes: prints out changed 4UN3 pdb pose protein profile 
	#  (sequence, # of res, what is located at Num residue - if the substitution occured)
	print var_pose
	print var_pose.sequence()
	print "Protein has", var_pose.total_residue(), "residues."
	print var_pose.residue(Num).name() # where Num is a residue number


예제 #13
0
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",
    )

    parser.add_option(
        '--include_pH',
        '-t',
        action="store",
        default=0,
        help="Include pH energy terms: pH_energy and fa_elec. Default false.",
    )

    parser.add_option(
        '--pH_value',
        '-q',
        action="store",
        default=7,
        help=
        "Predict ddG and specified pH value. Default 7. Will not work if include pH is not passed",
    )

    #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. Enable pH mode if applicable
    rosetta_options = ""
    standard_options = "-membrane_new:setup:spanfiles " + Options.in_span + " -run:constant_seed -in:ignore_unrecognized_res"
    if (Options.include_pH):
        print Options.pH_value
        if (float(Options.pH_value) < 0 or float(Options.pH_value) > 14):
            sys.exit("Specified pH value must be between 0-14: Exiting...")
        else:
            pH_options = " -pH_mode -value_pH " + str(Options.pH_value)
            rosetta_options = standard_options + pH_options
    else:
        rosetta_options = standard_options

    # Initialize Rosetta based on user inputs
    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()
    if (Options.include_pH):

        # Create a membrane energy function enabled by pH mode
        # Includes two terms not standard in the smoothed energy function: pH energy
        # and fa_elec
        sfxn = create_score_function("mpframework_pHmode_fa_2015")

    else:

        # 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
예제 #14
0
                    AA

            # Check for disulfide special case.
            if res.name() == 'CYD':
                disulfide_partner = res.residue_connection_partner(
                                               res.n_residue_connections())
                temp_pose = Pose()
                temp_pose.assign(initial_pose)
                # (Packing causes seg fault if current CYS residue is not
                # also converted before mutating.)
                change_cys_state(seq_pos, 'CYS',
                                 temp_pose.conformation())
                change_cys_state(disulfide_partner, 'CYS',
                                 temp_pose.conformation())
                # Mutate protein.
                mutant_pose = mutate_residue(temp_pose, seq_pos, AA,
                                             PACK_RADIUS, sf)
            else:
                # Mutate protein.
                mutant_pose = mutate_residue(initial_pose, seq_pos, AA,
                                             PACK_RADIUS, sf)

            # Minimize.
            if args.minimize:
                min_mover.apply(mutant_pose)

            # Score.
            variant_score = sf(mutant_pose)

            data.append(variant_name + "," + \
                        str(variant_score) + "," + \
                        str(variant_score - post_pre_packing_score) + "\n")
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('pdb_filename', action="store", type=str)
    parser.add_argument('replicate_number', action="store", type=int)

    inputs = parser.parse_args()
    #takes name of pdb file without the extention
    pdb_file = inputs.pdb_filename
    prot_name = pdb_file.split('/')[-1].split('.')[0]
    #set up timer to figure out how long the code took to run
    t0 = time()
    fasta_file = pdb_file.replace('/structures/',
                                  '/fastas/').replace('.pdb', '.fasta')
    records = list(SeqIO.parse(fasta_file, 'fasta'))
    assert len(records) == 1
    wt_seq = str(records[0].seq)

    # Initialize Rosetta.
    #init(extra_options='-mute basic -mute core')
    init(extra_options=
         '-mute basic -mute core -rebuild_disulf false -detect_disulf false')

    ########################
    # Constants
    ########################
    PACK_RADIUS = 12.0
    #Amino acids
    AAs = ("A", "C", "D", "E", "F", "G", "H", "I", "K", "L", "M", "N", "P",
           "Q", "R", "S", "T", "V", "W", "Y")
    AAs_choice_dict = {}
    for aa in AAs:
        AAs_choice_dict[aa] = [other_aa for other_aa in AAs if other_aa != aa]
    #Number of mutations to accept
    max_accept_mut = 10 * len(wt_seq)
    #max_accept_mut = 2048

    #Population size
    N = 1000
    #Beta (temp term)
    beta = 1
    #Fraction of the WT stability value to shoot for
    threshold_fraction = 0.5
    ########################
    ########################

    #Prepare data headers
    data = ['Variant,Rosetta Score,"delta-delta-G",Probability,Generation\n']

    #Load a clean pdb file
    initial_pose = pose_from_pdb(pdb_file)
    if '.clean' in pdb_file:
        pdb_file = ''.join(pdb_file.split('.clean'))

    #Set up ScoreFunction
    sf = get_fa_scorefxn()

    #Set up MoveMap.
    mm = MoveMap()
    mm.set_bb(True)
    mm.set_chi(True)

    #Pack and minimize initial pose to remove clashes.
    pre_pre_packing_score = sf(initial_pose)

    task = standard_packer_task(initial_pose)
    task.restrict_to_repacking()
    task.or_include_current(True)
    pack_rotamers_mover = RotamerTrialsMover(sf, task)
    pack_rotamers_mover.apply(initial_pose)

    min_mover = MinMover()
    min_mover.movemap(mm)
    min_mover.score_function(sf)
    min_mover.min_type('dfpmin_armijo_nonmonotone')
    min_mover.apply(initial_pose)

    post_pre_packing_score = sf(initial_pose)

    #Threshold for selection
    threshold = post_pre_packing_score * threshold_fraction
    print 'threshold:', threshold

    data.append('WT,' + str(post_pre_packing_score) + ',0.0,0.0,0\n')

    #number of residues to select from
    n_res = initial_pose.total_residue()

    #start evolution
    i = 0
    gen = 0
    while i < max_accept_mut:

        #update the number of generations that have pased
        gen += 1

        #print 'accepts:', i

        #pick a place to mutate
        mut_location = random.randint(1, n_res)

        #get the amino acid at that position
        res = initial_pose.residue(mut_location)

        #choose the amino acid to mutate to
        #new_mut_key = random.randint(0,len(AAs)-1)
        #proposed_res = AAs[new_mut_key]
        proposed_res = random.choice(AAs_choice_dict[res.name1()])

        #make the mutation
        mutant_pose = mutate_residue(initial_pose, mut_location, proposed_res,
                                     PACK_RADIUS, sf)

        #score mutant
        variant_score = sf(mutant_pose)

        #get the probability that the mutation will be accepted
        probability = calc_prob_mh(variant_score, post_pre_packing_score, N,
                                   beta, threshold)

        #test to see if mutation is accepted
        if random.random() < probability:

            #create a name for the mutant if its going to be kept
            variant_name = res.name1() + str(initial_pose.pdb_info().number(
                mut_location)) + str(proposed_res)

            #save name and energy change
            data.append(variant_name + "," + str(variant_score) + "," +
                        str(variant_score - post_pre_packing_score) + "," +
                        str(probability) + "," + str(gen) + "\n")

            #            if i == (max_accept_mut - 1):
            #                final_pdb_name=pdb_file.replace('.pdb', '_thresh={}_Neff={}_beta={}_i={}_nmut={}.pdb'.format(threshold_fraction, N, beta, inputs.replicate_number, i))
            #                mutant_pose.dump_pdb(final_pdb_name)

            #update the wildtype
            initial_pose = mutant_pose
            post_pre_packing_score = variant_score

            #update number of accepts
            i += 1

    print '\nMutations and scoring complete.'
    t1 = time()
    # Output results.
    output_filename = '../Results/{}/{}_thresh={}_Neff={}_beta={}_i={}.csv'.format(
        prot_name, prot_name, threshold_fraction, N, beta,
        inputs.replicate_number)
    with open(output_filename, "w") as outfile:
        outfile.writelines(data)

    print 'Data written to:', output_filename
    print 'program takes %f' % (t1 - t0)
예제 #16
0
# PyRosetta imports
from toolbox import mutate_residue
from rosetta import init, pose_from_sequence

# Initialize PyRosetta
init()

# Create Ala12
print('Creating Ala12...')
seq = 12*'A'
pose = pose_from_sequence(seq)

# Mutate residue 5 to K
print('Mutating Fifth Ala to Lys...')
mutant = mutate_residue(pose, 5, 'K')

# Load mutant into ParmEd
print('Loading into ParmEd...')
struct = load_rosetta(mutant)

# Load AMBER-99SBildn and TIP3P parameters
print('Loading AMBER parameters...')
ff = ForceField('amber99sbildn.xml', 'tip3p.xml')

# Solvate Structure
print('Solvating...')
mod = Modeller(struct.topology, struct.positions)
mod.addSolvent(ff, model='tip3p', boxSize=Vec3(4, 4, 4)*nanometers,
               positiveIon='Na+', negativeIon='Cl-',
               ionicStrength=0.1*molar)
def runFoldxSimpleMutator(mutant, pdbs):
  output = open('list.txt', 'w')
  fns = ''
  for pdb in pdbs:
    fns += pdb + '\n'
  output.write(fns)
  output.close()

  print("muatint")
  print(mutant)
  #print(pdbs)
  m=mutant[2:-1]
  here=mutant[-1]
  #print(m)
  #print(mutant)
  #print(here)
  
  name=rev_resdict[mutant[-1]]+mutant[2:-1]+'_'+pdbs
  print("name of file",str(name))
  
  initial_pose=pose_from_pdb(pdbs)
  res = initial_pose.residue(int(mutant[2:-1]))
  #Set up ScoreFunction.
  sf = get_fa_scorefxn()

  # Set up MoveMap.
  #mm = MoveMap()
  #mm.set_bb(True)
  #mm.set_chi(True)

  # Pack and minimize initial pose to remove clashes.
  #pre_pre_packing_score = sf( initial_pose)

  #task = standard_packer_task( initial_pose)
  #task.restrict_to_repacking()
  #task.or_include_current(True)
  #pack_rotamers_mover = RotamerTrialsMover(sf, task)
  #pack_rotamers_mover.apply(initial_pose)

  #min_mover = MinMover()
  #min_mover.movemap(mm)
  #min_mover.score_function(sf)
  #min_mover.min_type('linmin')



  print("loaded file")
  #pose2=mutate_residue(pose, m, here)
  pose2=mutate_residue( initial_pose, int(mutant[2:-1]),mutant[-1],10,sf )
  print("mutant", mutant)
  print("pdbs", pdbs)


  # Set up ScoreFunction.
  #sf = get_fa_scorefxn()

  # Set up MoveMap.
  #mm = MoveMap()
  #mm.set_bb(True)
  #mm.set_chi(True)

  # Pack and minimize initial pose to remove clashes.
  #pre_pre_packing_score = sf(pose2)

  #task = standard_packer_task(pose2)
  #task.restrict_to_repacking()
  #task.or_include_current(True)
  #pack_rotamers_mover = RotamerTrialsMover(sf, task)
  #pack_rotamers_mover.apply(pose2)

  #min_mover = MinMover()
  #min_mover.movemap(mm)
  #min_mover.score_function(sf)
  #min_mover.min_type('linmin')
  #min_mover.apply(pose2)

  #post_pre_packing_score = sf(pose2)

  #sf.show(pose2)

  pose2.dump_pdb(str(name))