def test_mm_twist():
    # Set CG1-CG1-CG1-CG1 torsion
    cg_pyrosetta.change_parameters.changeTorsionParameters(
        {'CG2 CG1 CG1 CG2': [10, 6, 35]})
    # Build 1-1 CG model
    pose = pyrosetta.pose_from_sequence(
        'X[CG31:CGLower]X[CG31]X[CG31]X[CG31]X[CG31]X[CG31]X[CG31]X[CG31:CGUpper]'
    )

    # Randomize torsion in backbone
    randomize = cg_pyrosetta.CG_movers.randomizeBackBone(pose)
    randomize.apply(pose)

    # Scorefunction w/o mm_twist
    scorefunction = pyrosetta.ScoreFunction()
    scorefunction.set_weight(pyrosetta.rosetta.core.scoring.fa_atr, 1)
    scorefunction.set_weight(pyrosetta.rosetta.core.scoring.fa_rep, 1)

    # Scorefunction w/ mm_twist
    scorefunction_mm = pyrosetta.ScoreFunction()
    scorefunction_mm.set_weight(pyrosetta.rosetta.core.scoring.fa_atr, 1)
    scorefunction_mm.set_weight(pyrosetta.rosetta.core.scoring.fa_rep, 1)
    scorefunction_mm.set_weight(pyrosetta.rosetta.core.scoring.mm_twist, 1)
    print(scorefunction(pose))
    print(scorefunction_mm(pose))
    assert not math.isclose(scorefunction(pose), scorefunction_mm(pose))
Esempio n. 2
0
def main():
    for s in range(10):
        kt_i = 100
        kt_anneal = [kt_i * (0.9)**i for i in range(50)]
        obj = CGFoldingAlgorithm(
            'X[CG11]X[CG11]X[CG11]X[CG11]X[CG11]X[CG11]X[CG11]X[CG11]X[CG11]X[CG11]X[CG11]X[CG11]X[CG11]X[CG11]X[CG11]',
            file_name='outputs/traj_anneal.pdb')
        obj.add_folding_move('default', obj.pymol)
        obj.PDB_writer.stride(2000)
        obj.small.angle = 180
        obj.shear.angle = 180
        obj.add_folding_move('default', obj.PDB_writer)
        obj.run_anneal_fold('default', 150, kt_anneal)
        obj.mc.lowest_score_pose().dump_pdb('outputs/11_lowest_energy_' +
                                            str(s) + '.pdb')

        lj_scorefxn = pyrosetta.ScoreFunction()

        lj_scorefxn.set_weight(pyrosetta.rosetta.core.scoring.mm_twist, 0.1)
        lj_scorefxn.set_weight(pyrosetta.rosetta.core.scoring.mm_lj_inter_rep,
                               1)
        lj_scorefxn.set_weight(pyrosetta.rosetta.core.scoring.mm_lj_inter_atr,
                               1)
        lj_scorefxn.set_weight(pyrosetta.rosetta.core.scoring.mm_lj_intra_rep,
                               1)
        lj_scorefxn.set_weight(pyrosetta.rosetta.core.scoring.mm_lj_intra_atr,
                               1)

        with open('outputs/11_lowest_energy_' + str(s) + '.pdb', 'a') as f:
            f.write('# LJ Energy : ' +
                    str(lj_scorefxn(obj.mc.lowest_score_pose())))
Esempio n. 3
0
    def build_energy_function(self, score_term_weight_map):
        score = pyrosetta.ScoreFunction()

        for term in score_term_weight_map.keys():
            if term in self.methods.keys():
                score.set_weight(
                    eval('pyrosetta.rosetta.core.scoring.' + term),
                    score_term_weight_map[term])
            else:
                warnings.warn(
                    "Energy Term not implemented :" + term +
                    "\n Skipping term", UserWarning)

        return (score)
Esempio n. 4
0
def build_scorefxn(cgmodel, mm=False):
    """
        Given a cgmodel class object, this function uses its definitions to build a PyRosetta scoring function.
        (Used to confirm energetic agreement between PyRosetta and OpenMM for identical model parameters and an identical structural ensemble.)

        Parameters
        ----------

        cgmodel: CGModel() class object

        Returns
        -------

        scorefxn: A PyRosetta ScoreFunction() class object, containing all scoring function components that are defined/requested within the cgmodel() class object.

        """
    scorefxn = pyrosetta.ScoreFunction()

    if mm:
        scorefxn.set_weight(pyrosetta.rosetta.core.scoring.mm_lj_intra_rep, 1)
        scorefxn.set_weight(pyrosetta.rosetta.core.scoring.mm_lj_intra_atr, 1)
        scorefxn.set_weight(pyrosetta.rosetta.core.scoring.mm_lj_inter_atr, 1)
        scorefxn.set_weight(pyrosetta.rosetta.core.scoring.mm_lj_inter_rep, 1)

    else:
        scorefxn.set_weight(pyrosetta.rosetta.core.scoring.fa_elec, 1)
        scorefxn.set_weight(pyrosetta.rosetta.core.scoring.fa_rep, 1)
        scorefxn.set_weight(pyrosetta.rosetta.core.scoring.fa_atr, 1)
        scorefxn.set_weight(pyrosetta.rosetta.core.scoring.fa_intra_atr, 1)
        scorefxn.set_weight(pyrosetta.rosetta.core.scoring.fa_intra_rep, 1)
    cg_pyrosetta.change_parameters.changeTorsionParameters({
        'CG1 CG1 CG1 CG1': [0, 0, 0],
        'CG2 CG1 CG1 CG2': [0, 0, 0],
        'CG2 CG1 CG1 CG1': [0, 0, 0],
        'X CG2 CG1 CG1': [0, 0, 0]
    })

    cg_pyrosetta.change_parameters.changeAngleParameters({
        'CG1 CG1 CG1': [0, 0],
        'CG2 CG1 CG1': [0, 0],
        'CG1 CG1 CG2': [0, 0],
        'X CG2 CG1': [0, 0]
    })
    #        scorefxn.set_weight(pyrosetta.rosetta.core.scoring.mm_twist, 0.1)
    return (scorefxn)
Esempio n. 5
0
def build_scorefxn(cgmodel):
    """
    Given a cgmodel class object, this function uses its definitions to build a PyRosetta scoring function.
    (Used to confirm energetic agreement between PyRosetta and OpenMM for identical model parameters and an identical structural ensemble.)

    Parameters
    ----------

    cgmodel: CGModel() class object

    Returns
    -------

    scorefxn: A PyRosetta ScoreFunction() class object, containing all scoring function components that are defined/requested within the cgmodel() class object.

    """
    scorefxn = pyrosetta.ScoreFunction()
    scorefxn.set_weight(pyrosetta.rosetta.core.scoring.fa_atr, 1)
    scorefxn.set_weight(pyrosetta.rosetta.core.scoring.fa_rep, 1)
    scorefxn.set_weight(pyrosetta.rosetta.core.scoring.fa_intra_atr, 1)
    scorefxn.set_weight(pyrosetta.rosetta.core.scoring.fa_intra_rep, 1)
#        scorefxn.set_weight(pyrosetta.rosetta.core.scoring.mm_twist, 0.1)
    return(scorefxn)
Esempio n. 6
0
def setup_scorefxn():
    py.init()
    scorefxn = py.ScoreFunction()
    fa_rep = py.rosetta.core.scoring.ScoreType.fa_rep
    scorefxn.set_weight(fa_rep, 1.0)
    return scorefxn
Esempio n. 7
0
        small_sc_mover.angle = 180

        # repeat_sc_mover = pyrosetta.RepeatMover(small_sc_mover, 5)
        # folding_object.add_folding_move('AngleMC', repeat_sc_mover)

        small_bb_angle_mover = cg_pyrosetta.CG_movers.CGSmallAngleMover(
            folding_object.pose)
        small_bb_angle_mover.angle = 10
        # repeat_bb_angle_mover = pyrosetta.RepeatMover(small_bb_angle_mover, 2)
        # folding_object.add_folding_move('AngleMC', repeat_bb_angle_mover)

        # Adding a PyMOL object to the folding sequence so we can see output

        folding_object.add_folding_move(
            'AngleMC', pyrosetta.RepeatMover(folding_object.mini, 10))

        pymol = pyrosetta.PyMOLMover()
        folding_object.add_folding_move('AngleMC', pymol)

        # Runs a folding MC simulation with 200 repeats of the 'default' folder at each kt
        folding_object.run_anneal_fold('AngleMC', 10, kt_anneal)

        # Dump the lowest energy structure from the MC simulation
        folding_object.mc.lowest_score_pose().dump_pdb(
            'fold_from_sequence_output/' + names[i] + '_example_angles_' +
            str(rep) + '.pdb')

        twist_score = pyrosetta.ScoreFunction()
        twist_score.set_weight(pyrosetta.rosetta.core.scoring.mm_twist, 1)
        # print(twist_score(folding_object.pose))
Esempio n. 8
0
    def __init__(self,
                 sequence,
                 BBB_angle=120,
                 BBBB_dihe=180,
                 file_name='outputs/traj.pdb',
                 energy_graph_output=False):
        """
        folding object used for easily implementing different
        movers into a single folding algorithm.

        Arguments
        ---------

        sequence : str
            Sequence of CG residues
        BBB_angle : float
            Desired angle of all B-B-B angles. Generalizes to all backbone models (not working)
        BBBB_angle : float
            Desired dihedral of all B-B-B-B torsion angles. Generalizes to all backbone models (not working)


        """
        # Build CG model and set desired initial angles
        self.pose = pyrosetta.pose_from_sequence(sequence, auto_termini=False)
        self.energy_graph_output = energy_graph_output
        # self.pose = self.set_BBB_angles(self.pose, BBB_angle)
        # self.pose = self.set_BBBB_dihe(self.pose, BBBB_dihe)
        # PyMOL mover, if wanting to visualize
        self.pymol = pyrosetta.PyMOLMover()
        self.pymol.apply(self.pose)

        # randomizer = CG_movers.randomizeBackBone(self.pose)
        # randomizer.apply(self.pose)

        self.pymol.apply(self.pose)
        # Building PDBTrajWriter object, used for writing multiple structures
        # to a single file
        self.PDB_writer = pyrosetta.rosetta.protocols.canonical_sampling.PDBTrajectoryRecorder(
        )
        # self.PDB_writer.apply(self.pose) # write initial structure
        self.PDB_writer.file_name('outputs/traj.pdb')
        self.PDB_writer.stride(100)

        # Define scorefunction terms
        self.scorefxn = pyrosetta.ScoreFunction()
        self.scorefxn.set_weight(pyrosetta.rosetta.core.scoring.fa_rep, 1)
        self.scorefxn.set_weight(pyrosetta.rosetta.core.scoring.fa_atr, 1)
        self.scorefxn.set_weight(pyrosetta.rosetta.core.scoring.fa_intra_atr,
                                 1)
        self.scorefxn.set_weight(pyrosetta.rosetta.core.scoring.fa_intra_rep,
                                 1)
        self.scorefxn.set_weight(pyrosetta.rosetta.core.scoring.mm_twist, 1)
        self.scorefxn.set_weight(pyrosetta.rosetta.core.scoring.mm_bend, 1)
        # self.scorefxn.set_weight(pyrosetta.rosetta.core.scoring.mm_lj_inter_rep, 1) # segfaults beware!
        # self.scorefxn.set_weight(pyrosetta.rosetta.core.scoring.mm_lj_inter_atr, 1)
        # self.scorefxn.set_weight(pyrosetta.rosetta.core.scoring.mm_lj_intra_rep, 1)
        # self.scorefxn.set_weight(pyrosetta.rosetta.core.scoring.mm_lj_intra_atr, 1)

        # Build standard CG 1-1 movers
        self.small = CG_movers.CGSmallMover(self.pose)
        # self.shear = CG_movers.CGShearMover(self.pose)
        self.small_angle = CG_movers.CGSmallAngleMover(self.pose)

        # Build minimization movers
        self.mini = pyrosetta.rosetta.protocols.minimization_packing.MinMover()
        self.mini.min_type('lbfgs_armijo_nonmonotone')
        self.movemap = pyrosetta.MoveMap()
        self.mini.score_function(self.scorefxn)
        # for atom in self.small_angle.bb_atoms:
        #      self.movemap.set(pyrosetta.rosetta.core.id.DOF_ID(atom , pyrosetta.rosetta.core.id.THETA), True)
        self.movemap.set_bb_true_range(1, self.pose.size())
        self.mini.movemap(self.movemap)

        # Build MC object + Trial Mover (empty for now)
        self.mc = pyrosetta.MonteCarlo(self.pose, self.scorefxn, 1)
        self.trial_mc = pyrosetta.TrialMover()

        # Building variable to store various folding algorithms
        self.folding_protocols = {}

        # Adding a default mover
        self.build_fold_alg('default')
        self.add_folding_move('default', pyrosetta.RepeatMover(self.small, 10))
        # self.add_folding_move('default', pyrosetta.RepeatMover(self.shear, 10))
        self.add_folding_move('default', pyrosetta.RepeatMover(self.mini, 10))
def score_function():
    score = pyrosetta.ScoreFunction()
    score.set_weight(pyrosetta.rosetta.core.scoring.fa_atr, 1)
    score.set_weight(pyrosetta.rosetta.core.scoring.fa_rep, 1)
    return (score)
def load_score_fxn_with_weights(filename):
    filename = str(filename)
    sf = pyrosetta.ScoreFunction()
    sf.add_weights_from_file(filename)
    return sf
Esempio n. 11
0
import pyrosetta

cg_pyrosetta.pyrosetta.init("-extra_mm_params_dir mm_atom_type_sets")

# Build models
polyA = pyrosetta.pose_from_sequence('AAAAAAAA')
polyCG = pyrosetta.pose_from_sequence(
    'X[CG31:CGLower]X[CG31]X[CG31]X[CG31]X[CG31:CGUpper]')

# Build PyMol visualizer
pymol = pyrosetta.PyMOLMover()
# pymol.apply(polyA)
pymol.apply(polyCG)

# Build Score Function
sf = pyrosetta.ScoreFunction()
sf.set_weight(pyrosetta.rosetta.core.scoring.mm_bend, 1)
sf.set_weight(pyrosetta.rosetta.core.scoring.mm_twist, 1)
sf.set_weight(pyrosetta.rosetta.core.scoring.fa_atr, 1)
sf.set_weight(pyrosetta.rosetta.core.scoring.fa_rep, 1)

# Build MoveMap
mm = pyrosetta.MoveMap()
mm.set(
    pyrosetta.rosetta.core.id.DOF_ID(pyrosetta.AtomID(3, 2),
                                     pyrosetta.rosetta.core.id.THETA), True)

# Build Minimizer
mini = pyrosetta.rosetta.protocols.minimization_packing.MinMover()
mini.score_function(sf)
mini.movemap(mm)