Back to Recipes Homepage
recipe picture
Recipe: Loop rebuild 2.0
Created by spvincent 33 32
4.833335
Your rating: None Average: 4.8 (42 votes)
Used 9214 times with an average impact of 36920 points.

Profile

Name: Loop rebuild 2.0
ID: 6985
Created on: Fri, 08/06/2010 - 11:43
Updated on: Fri, 08/06/2010 - 18:43
Description:

New! Improved! Washes whiter! See first comment for details.



Best For


Comments

spvincent's picture
User offline. Last seen 11 hours 12 min ago. Offline
Joined: 12/07/2007
Groups: Contenders
Changes from 1.1

1) By default, runs forever (useful for running overnight). If you don't like this, change the value of loop_forever to false.

2) Allows you to work on a specific area of the protein rather than the whole thing. Change the values of min_residue and max_residue to limit the area, perhaps the start and end of a big loop, upon which loop rebuild will act. Don't forget to set these values back as directed in the script.

3) If a rebuild plus subsequent recovery comes close to or exceeds the best score, it'll try an alternative recovery technique and pick the best of the two.

4) Stores, in Quicksave slot 10, the post-rebuild structure that lead to the highest score that did not create a new best score. The rebuild area in question will be bracketed by frozen residues for easy identification. The idea is that, whether or not this script produces a gain, the user can load the structure in Quicksave 10 (Open/Share solutions: ensure the Show auto and quick saves box is checked) and try alternative post-rebuild techniques such as local wiggling the rebuild section or stopping the wiggle before completion.

5) Respects frozen areas and does a better job maintaining the secondary structure.

6) You can alter the value of a variable called refinement_hack (use as directed in the script) on those puzzles which require a refinement condition.

Joined: 09/18/2009
Groups: SETI.Germany
Server

As long as we can't load recipes, could you paste it as text, please?

regards,
Alex

spvincent's picture
User offline. Last seen 11 hours 12 min ago. Offline
Joined: 12/07/2007
Groups: Contenders
Hopefully this works

max_rebuild_length = 5 -- Maximum rebuild length.
min_rebuild_length = 4 -- Suggest leaving this at 4. Haven't had much luck with smaller rebuilds but
-- others have. Your mileage may vary.
number_of_rebuilds = 10 -- It'll look for the best score from this number of rebuilds. Change to taste.
-- Irrelevant for rebuild lengths of 2 where this value is coerced to 1
stop_if_close = false -- Set to true to make it interactive and manually explore rebuilds that get close
-- to the highest score
start_idx = 6 -- start residue. Anything between 1 and the number of residues will do
-- Change for a bit of randomness.
loops_only = false -- if false, rebuild helices and sheets also
-- they'll be temporarily converted to loops
loop_forever = true -- just keep going. Good for overnight running.
start_from_best = false -- set to false if you want it to start from the current configuration, not the best
min_residue = 1 -- Change these if you want to rebuild part of a protein only. For example, to
-- rebuild 53-64, set min_residue to 53 and max_residue to 64. To restore, set to
-- 1 and 9999 (or any large number) respectively
max_residue = 9999

refinement_hack = false -- For refinement puzzles with conditions only.
-- if set to true , it'll reset the puzzle to the recent credit best before each rebuild
-- you will always effectively be starting from the best credit solution, so will be -- unable to use this script to explore from lower-scoring solutions. The output -- may be misleading also. As the name implies, its a hack until a cleaner interface
-- comes from the devs.

sidechain_scramble = true -- if true, will do one after a point gain. Trade off: more points from the script but
-- more time-consuming also and possibly fewer subsequent points from walks.
monit = false -- prints debug and performance info.

-- Other changes

-- Tries an alternative post-rebuild strategy if the first one is close

-- Stores the best non-improved structure in Quicksave slot 10. The structure that's saved is the
-- the best before WS etc, so if this script fails to produce (or even if it does) you can load the structure in
-- slot 10 and try WS in different ways.

original_secondary_structure = {}

function Coprime ( n )

-- returns a number that has no common factors with n
-- an ugly hack

if ( n < 31 ) then
return 1
elseif ( n >= 31*37 ) then
return 1
elseif ( n%31 ~= 0 ) then
return 31
else
return 37
end

end

function IsSegmentALoop ( first , last )

non_loop_found = false
for i = first , last do
if ( get_ss ( i ) ~= "L" ) then
non_loop_found= true
end
end

return not non_loop_found
end

function ConvertToLoop ( first , last )

for k = first , last do
if ( original_secondary_structure [ k ] ~= "L" ) then
deselect_all ( )
select_index ( k )
replace_ss ( "L" )
end
end
end

function RestoreStructure ( first , last )

for k = first, last do
deselect_all ()
select_index ( k )
replace_ss ( original_secondary_structure [ k ] )
end
end

function nudge ()

if ( monit ) then
c = get_score ()
end

select_all ()
set_behavior_clash_importance ( 0.3 )
do_global_wiggle_all ( 1 )
set_behavior_clash_importance ( 1 )
do_global_wiggle_all ( 10 )

if ( monit ) then
print ( "Gain from nudge " , get_score() - c )
end

end

function BlueFuse_part_1 ( )

if ( monit ) then
c = get_score ()
end

reset_recent_best ()
select_all ()
set_behavior_clash_importance ( 0.05 )
do_shake ( 1 )
set_behavior_clash_importance ( 1 )
do_global_wiggle_all ( 8 )

restore_recent_best () -- In case the above machinations made things worse

if ( monit ) then
d = get_score ()
print ( "Gain from BF1 " , d - c )
end

end

function disable_all_bands ()

band_count = get_band_count ()

for i = band_count , 1 , -1 do
band_disable ( i )
end

end

function enable_all_bands ()

band_count = get_band_count ()

for i = band_count , 1 , -1 do
band_enable ( i)
end

end

function BlueFuse_part_2 ()

c = get_score ()
reset_recent_best()

select_all ()
set_behavior_clash_importance ( 0.05 )
do_shake ( 1 )
set_behavior_clash_importance ( 1 )
do_global_wiggle_all ( 8 )
restore_recent_best ()

set_behavior_clash_importance ( 0.07 )
do_shake ( 1 )
set_behavior_clash_importance ( 1 )
do_global_wiggle_all ( 8 )
restore_recent_best ()
set_behavior_clash_importance ( 0.3 )
do_global_wiggle_all ( 1 )
set_behavior_clash_importance ( 1 )
do_global_wiggle_all ( 8 )
restore_recent_best ()

if ( monit ) then
d = get_score ()
print ( "Gain from BF2 " , d - c )
end

end

function WiggleShakeWiggle ( start_idx , end_idx )

-- returns the score after doing a WSW: shortcircuiting if things don't look promising

score_a = get_score ()

do_global_wiggle_all ( 15 )
score_after_wiggle = get_score ()

if ( score_after_wiggle - score_a < 10 and best_score - score_after_wiggle > 30 ) then
-- The wiggle got stuck and didn't achieve anything
nudge ()
score_after_wiggle = get_score ()
end

if ( monit ) then
--print ( "After first wiggle (bb) : ", best_score - score_after_wiggle )
end

if ( best_score - score_after_wiggle > 100 ) then
-- Not worth continuing
return score_after_wiggle
end

do_shake ( 1 )

score_after_second_shake = get_score ()

if ( score_after_second_shake - score_after_wiggle > 0.5 ) then
do_global_wiggle_all ( 10 )
score_after_second_wiggle = get_score ()

if ( score_after_second_wiggle - score_after_second_shake < 1 and best_score - score_after_second_wiggle < 50 ) then

-- The second shake did something but the subsequent wiggle didn't

reset_recent_best ()
nudge ( )
restore_recent_best ()

score = get_score ()

return score
else
return score_after_second_wiggle
end
else
return score_after_second_shake
end

end

function post_rebuild ( score_after_rebuild , threshold_a , threshold_b , start_idx , end_idx )

-- Tries to recover after a rebuild.

-- If the first recovery attempt results in a score that is less than the best score by a value
-- of threshold_a or less, then try alternative strategies

if ( best_score - score_after_rebuild > 3000 ) then
do_shake ( 2 )
initial_shake = true
elseif ( best_score - score_after_rebuild > 1500 ) then
do_shake ( 1 )
initial_shake = true
else
initial_shake = false
end

-- First try WSW

curr_score = WiggleShakeWiggle ( start_idx , end_idx )

if ( monit ) then
print ( "after wsw bb ", best_score - curr_score )
end

best_recovery_score = curr_score
quicksave ( 3 )

if ( best_score - curr_score < threshold_a ) then

best_recovery_score = curr_score
quicksave ( 3 )

-- Now try shaking at start if we didn't already do so

quickload ( 2 )

if ( initial_shake == false ) then

score_before_shake = get_score ()
do_shake ( 1 )
score_after_shake = get_score ()

if ( score_after_shake - score_before_shake > 0.1 ) then

-- If shaking did nothing then no point duplicating previous WSW

curr_score = WiggleShakeWiggle ( start_idx , end_idx )

if ( monit ) then
print ( "after swsw bb " , best_score - curr_score )
end

if ( curr_score > best_recovery_score ) then
if ( monit ) then
print ( "Second better" )
end

best_recovery_score = curr_score
quicksave ( 3 )
else
if ( monit ) then
print ( "First better" )
end
end

end

end

-- Additional post-rebuild strategies will go here as the API matures

end

if ( best_score - best_recovery_score < threshold_b ) then
quickload ( 3 )
return true
else
return false
end

end

function rebuild ( n , rebuild_length )

n_possible_segs = n - rebuild_length + 1

inc = Coprime ( n_possible_segs )

-- The point of this Coprime, start_idx business is so we go through the protein in a
-- nonuniform way. Rather than rebuilding 1-4, 2-5 , 3-6 for example, we might do 21 4, 53-57, 3-6
-- or something like that

for i = 1 , n_possible_segs do

improvement_made = false

end_idx = start_idx + rebuild_length - 1

if ( start_idx >= min_residue and end_idx <= max_residue and
( loops_only == false or IsSegmentALoop ( start_idx , end_idx ) == true ) ) then

rb = rb + 1

print ( "rb ", rb , " " , start_idx ,"-" , end_idx , " (" ,i , "/" , n_possible_segs , ")" )

if ( refinement_hack == true ) then
restore_credit_best ()
else
quickload ( 1 )
end

best_score = get_score ()

if ( loops_only == false ) then
ConvertToLoop ( start_idx , end_idx )
end

deselect_all ()
select_index_range ( start_idx , end_idx )

-- for some reason, do_local_rebuild ( 1) often leaves the protein unchanged

k = 0
repeat
k = k + 1
do_local_rebuild ( k )
score_after_rebuild = get_score ()
until score_after_rebuild ~= best_score or k > 2

if ( score_after_rebuild ~= best_score ) then

-- If the scores are still equal we probably have a locked segment

reset_recent_best ()
if ( number_of_rebuilds > 1 ) then
do_local_rebuild ( number_of_rebuilds - 1 )
restore_recent_best ()
end

score_after_rebuild = get_score ()

select_all ()

-- Compute a value delta which will be used later to determine if we are
-- "sufficiently" close to our original best score. If it turns out later that
-- we are, then either stop if stop _if_close is true or nudge it around

if ( best_score - score_after_rebuild < 20 ) then
delta = 0.01
elseif ( rebuild_length >= 6 ) then
delta = 10
elseif ( rebuild_length == 5 ) then
delta = 7
elseif ( rebuild_length == 4 ) then
delta = 5
else
delta = 2
end

investigate_alternates_threshold = 2*delta

if ( investigate_alternates_threshold < 10 ) then
investigate_alternates_threshold = 10
end

quicksave ( 2 )

if ( post_rebuild ( score_after_rebuild , investigate_alternates_threshold , delta , start_idx , end_idx ) == true ) then

if ( loops_only == false ) then
load_structure ()
end

if ( stop_if_close == true ) then
return true
end

BlueFuse_part_1 ()
curr_score = get_score ()

if ( curr_score > best_score ) then

if ( sidechain_scramble == true ) then
BlueFuse_part_2 ( )
end

curr_score = get_score ()

best_score = curr_score

improvement_made = true

quicksave ( 1 )
print ( "Improvement to ", best_score )
end

end

curr_score = get_score ()

if ( curr_score > qs10_best_score and improvement_made == false ) then
qs10_best_score = curr_score
quickload ( 2 )

-- Bracket the area with frozen segments for easy recognition
deselect_all ()

if ( start_idx > 1 ) then
select_index ( start_idx - 1 )
end

if ( end_idx < n ) then
select_index ( end_idx + 1 )
end

do_freeze ( true , false )

quicksave ( 10 )
end

end -- if first rebuild worked

if ( loops_only == false ) then
-- RestoreStructure ( start_idx , end_idx )
load_structure ()
end

end

start_idx = start_idx + inc
if ( start_idx > n_possible_segs ) then
start_idx = start_idx - n_possible_segs
end

end -- for i
return false
end

if ( start_from_best == true ) then
restore_abs_best ()
end

-- Tidy up if necessary

disable_all_bands ()

n_residues = get_segment_count()

if ( loops_only == false ) then
for i = 1, n_residues do
original_secondary_structure [ i ] = get_ss ( i )
end
end

save_structure ()

rb = 0
quicksave ( 1 )

set_behavior_clash_importance ( 1 )

best_score = get_score ()
print ( "Start score : " , best_score )

if ( start_score == 0 ) then
print ( "Suggest quitting as starting score < = 0" )
end

if ( loops_only == true ) then
print ( "Loops only" )
else
print ( "Loops, sheets, and helices" )
end

if ( max_residue > n_residues ) then
max_residue = n_residues
end

if ( min_residue < 1 ) then
min_residue = 1
end

if ( max_residue <= min_residue ) then
print ( "Rebuild range error" )
loop_forever = false
end

if ( true ) then -- min_residue > 1 or max_residue < n_residues ) then
print ( "Rebuild range " , min_residue , " to " , max_residue )
else
print ( "Rebuild all" )
end

qs10_best_score = 0

if ( refinement_hack == true ) then
print ( "Refinement hack on" )
end

repeat
for rebuild_length = max_rebuild_length , min_rebuild_length , -1 do

if ( rebuild_length <= 2 ) then
number_of_rebuilds = 1
end

if ( rebuild ( n_residues , rebuild_length ) == true ) then
loop_forever = false
break
end
end
until loop_forever == false

if ( refinement_hack == true ) then
restore_credit_best ()
else
quickload ( 1 )
end

enable_all_bands ()

spvincent's picture
User offline. Last seen 11 hours 12 min ago. Offline
Joined: 12/07/2007
Groups: Contenders
it certainly made a mess of

it certainly made a mess of the formatting

Joined: 08/06/2010
Groups: Contenders
Tlaloc's Random Tug, Push, and Your Loop Rebuild make short work

Great script. Combinded with The other two and
repeated application between them raised my score from 9093 to 9350.

auxilio's picture
User offline. Last seen 8 years 1 week ago. Offline
Joined: 09/23/2011
Groups: None
Some Help

Hey, I greatly appreciate your work on this recipe. It's raised MANY of my scores by a lot.
I'm not sure if I'm now doing something wrong, but when it gets to the step, "load_structure" it just stops. Is it possible for me to get a bit of an explanation for what this step does? For example, right now I'm behind an internet blocking service. Does that step require the internet?
Thank you for your help and your work in this program,
Matt.

Joined: 02/11/2012
Groups: Geekdo
cannot add

Can we still not add recipes (I can't, tells me torun foldit, though it it running)?
Merci.

Want to try?
Add to Cookbook!
To download recipes to your cookbook, you need to have the game client running.
Parent
Children
Authors
Sitemap

Developed by: UW Center for Game Science, UW Institute for Protein Design, Northeastern University, Vanderbilt University Meiler Lab, UC Davis
Supported by: DARPA, NSF, NIH, HHMI, Amazon, Microsoft, Adobe, RosettaCommons