You are here

Relax with constraints

3 posts / 0 new
Last post
Relax with constraints

Hi everyone,

I am a newbee in Pyrosetta, and I am trying to learn how to relax with constraints. I wanted to do distance constraints, but I am not sure if I am doing it right or wrong at all.  The score came out to be almost the same for with and without the constraint. Can anyone give me any advise? 

#------------------------Set up Score Function-----------------------

scorefxn = get_fa_scorefxn() 
score_before = scorefxn(pose)

#-------------------------Set up constraints----------------------------

score_manager = pyrosetta.rosetta.core.scoring.ScoreTypeManager()
constraint = score_manager.score_type_from_name('atom_pair_constraint')
scorefxn.set_weight(constraint, 5)

#-------------------------Set up Fast-relax-----------------------------

relax = pyrosetta.rosetta.protocols.relax.FastRelax()


score_after = scorefxn(pose)
print ('The initial score of this structure is:', '\n', score_before)
print ('The score after relaxing is:', '\n', score_after)
print ('The distribution of scores', '\n')
print (



I also have another question. I wanted to see the break down of the contribution of each score term, so I used the scorefxn and I found that the atom_pair_constraint  I set did not contribute to the score at all. Is this normal? Or I have been doing something wrong?

 Scores                          Weight   Raw Score Wghtd.Score
 fa_atr                              1.000   -2424.358   -2424.358
 fa_rep                             0.550     574.759     316.118
 fa_sol                              1.000    1347.288    1347.288
 fa_intra_rep                  0.005     878.587       4.393
 fa_intra_sol_xover4     1.000      65.973      65.973
 lk_ball_wtd                    1.000     -48.242     -48.242
 fa_elec                            1.000    -746.968    -746.968
 pro_close                        1.250       2.518       3.147
 hbond_sr_bb                  1.000     -52.160     -52.160
 hbond_lr_bb                  1.000    -213.687    -213.687
 hbond_bb_sc                  1.000     -91.416     -91.416
 hbond_sc                     1.000     -73.974     -73.974
 dslf_fa13                    1.250      -2.186      -2.732
 atom_pair_constraint         5.000       0.000       0.000
 omega                        0.400      85.757      34.303
 fa_dun                       0.700     648.952     454.266
 p_aa_pp                      0.600    -191.109    -114.665
 yhh_planarity                0.625       1.530       0.956
 ref                          1.000     144.570     144.570
 rama_prepro                  0.450       4.929       2.218
 Total weighted score:                    -1394.971


I guess what I want to know for my second question is that if the atom_pair_constraint is being applied to the relax at all?

Post Situation: 
Tue, 2019-05-07 11:16

There's two parts to Rosetta constraints. The part in the pose and the part in the scorefunction.

You've found the part in the scorefunction. This needs to be turned on to a non-zero value in order to tell Rosetta to evaluate the constraints in the protocol (here relax).

The other portion of the constraint is the part that's set in the Pose. This tells Rosetta what actually to constrain. (Take another look at your code - you say you want atom-atom distance constraints, but you never specify which pairs of atoms you want to constrain or what distance separation you want to restrain them to.)

There's a number of ways to setup constraints in the pose. From PyRosetta the most direct way is probably to use the pose.add_constraint() functions. But there are also various movers which will add constraints according to a pre-defined specifications, and there's also the Rosetta constraint file format ( which (I think) can be loaded with the core.scoring.constraints.ConstraintIO.get_instance().read_constraints() function (or various movers).

Thu, 2019-05-09 14:22

Thank you so much for your reply, I figured it out how to do it. 

Wed, 2019-05-22 09:54