Profile
- Name
- Beginner Rebuild SCRIPT 5.01
- ID
- 102322
- Shared with
- Public
- Parent
- None
- Children
- Created on
- April 04, 2017 at 04:25 AM UTC
- Updated on
- April 04, 2017 at 04:25 AM UTC
- Description
New recipe based on work by the marquis from October, 2009. This recipe introduces Lua tables, and includes the function current.GetSegmentEnergyScore.
Best for
Code
--
-- Automatic Rebuild script by your name here
--
-- step 1 - rebuild the first 10 segments
-- step 2 - add a function, use variables, use if .. then .. else,
-- restore recentbest if there's a loss
-- step 3 - rebuild the whole protein
-- step 4 - rebuild worst areas first,
-- rebuild in overlapping sections
--
--
-- round numbers to three decimal places
--
function round ( x )
return x - x % 0.001
end
recentbest.Save () -- save the current pose as recentbest
preScore = current.GetEnergyScore ()
segCnt = structure.GetCount ()
print ( "The protein has " .. segCnt .. " segments" )
print ( "Score before rebuilding is " .. round ( preScore ) )
buildLen = 3
buildWorst = 5
--
-- get the score of each segment, store it in a table
--
scoreTab = {} -- a new, empty table
for ii = 1, segCnt do
scoreTab [ #scoreTab + 1 ] = current.GetSegmentEnergyScore ( ii )
end
--
-- now get the worst sections of the specified length
--
worstTab = {} -- another new empty table
for ii = 1, segCnt - buildLen + 1 do
local partScore = 0
for jj = ii, ii + buildLen - 1 do
partScore = partScore + scoreTab [ jj ]
end
worstTab [ #worstTab + 1 ] = { partScore, ii, ii + buildLen - 1 }
end
--
-- the function Sort is taken from http://fold.it/portal/recipe/49233
-- "Tvdl enhanced DRW 3.0.1" by Timo van der Laan
--
function Sort ( tab, items ) --BACKWARD bubble sorting - lowest on top, only needed items
for xx = 1, items do --items do
for yy = xx + 1, #tab do
if tab [ xx ] [ 1 ] > tab [ yy ] [ 1 ] then
tab [ xx ], tab [ yy ] = tab [ yy ], tab [ xx ]
end
end
end
return tab
end
worstTab = Sort ( worstTab, buildWorst )
for ii = 1, buildWorst do
loopScore = current.GetEnergyScore ()
print ( "rebuild "
.. ii ..
"/"
.. buildWorst ..
", segments "
.. worstTab [ ii ] [ 2 ] ..
" - "
.. worstTab [ ii ] [ 3 ] ..
", score = "
.. round ( worstTab [ ii ] [ 1 ] )
)
selection.DeselectAll () -- deselect everything
selection.SelectRange ( worstTab [ ii ] [ 2 ], worstTab [ ii ] [ 3 ] ) -- select segments
structure.RebuildSelected ( 1 ) -- rebuild selected segments for 1 round
structure.ShakeSidechainsAll ( 2 ) -- shake for 2 rounds
structure.WiggleAll ( 10 ) -- wiggle for 10 rounds
postScore = current.GetEnergyScore ()
print ( "Score after rebuilding is " .. round ( postScore ) )
--
-- use if-then-else to report gain or loss, reset recentbest
--
if postScore > loopScore then
print ( "gain is " .. round ( postScore - loopScore ) )
recentbest.Save () -- save the current pose as recentbest
else
print ( "loss is " .. round ( loopScore - postScore ) .. ", resetting to recentbest pose" )
recentbest.Restore () -- reset to previous pose
end
end
postScore = current.GetEnergyScore () -- postScore is another variable
if postScore > preScore then
print ( "after all rebuilds, gain is " .. round ( postScore - preScore ) )
elseif round ( postScore ) == round ( preScore ) then
print ( "after all rebuilds, no gain, score = " .. round ( preScore ) )
else
print ( "after all rebuilds, loss is " .. round ( preScore - postScore ) .. ", resetting to recentbest pose" )
recentbest.Restore () -- reset to previous pose
end