Icon representing a recipe

Recipe: Beginner Rebuild SCRIPT 4.01

created by LociOiling

Profile


Name
Beginner Rebuild SCRIPT 4.01
ID
102319
Shared with
Public
Parent
None
Children
None
Created on
March 29, 2017 at 23:51 PM UTC
Updated on
March 29, 2017 at 23:51 PM UTC
Description

New recipe based on work by the marquis from October, 2009. This recipe includes a for loop, and the structure.GetCount() function.

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 -- -- -- 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 for ii = 1, segCnt - buildLen + 1, buildLen do loopScore = current.GetEnergyScore () print ( "rebuilding segments " .. ii .. " - " .. ii + buildLen - 1 ) selection.DeselectAll () -- deselect everything selection.SelectRange ( ii, ii + buildLen - 1 ) -- 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

Comments