Icon representing a recipe

Recipe: TEST JF Rav3n_pl WalkeR MarathoN

created by Vincera

Profile


Name
TEST JF Rav3n_pl WalkeR MarathoN
ID
104984
Shared with
Public
Parent
Rav3n_pl WalkeR MarathoN
Children
Created on
July 06, 2021 at 23:56 PM UTC
Updated on
December 30, 2024 at 19:55 PM UTC
Description

A randomatic LWS sequence walker.

Best for


Code


--[[ WalkeR v1.0 a randomatic LWS script set from-to set min-max len of lws ser minimum points per iter optiona at end ]]-- --[[ Tlaloc`s math library ------------------------------------------------------------------------ The original random script this was ported from has the following notices: Copyright (c) 2007 Richard L. Mueller Hilltop Lab web site - http://www.rlmueller.net Version 1.0 - January 2, 2007 You have a royalty-free right to use, modify, reproduce, and distribute this script file in any way you find useful, provided that you agree that the copyright owner above has no warranty, obligations, or liability for such use. ------------------------------------------------------------------------ ]]-- -- Updated to Script V2 and given some repeat options (StackOverflow) local lngX = 1000 local lngC = 48313 local function _MWC() local S_Hi local S_Lo local C_Hi local C_Lo local F1 local F2 local F3 local T1 local T2 local T3 local A_Hi = 63551 local A_Lo = 25354 local M = 4294967296 local H = 65536 local S_Hi = math.floor(lngX / H) local S_Lo = lngX - (S_Hi * H) local C_Hi = math.floor(lngC / H) local C_Lo = lngC - (C_Hi * H) local F1 = A_Hi * S_Hi local F2 = (A_Hi * S_Lo) + (A_Lo * S_Hi) + C_Hi local F3 = (A_Lo * S_Lo) + C_Lo local T1 = math.floor(F2 / H) local T2 = F2 - (T1 * H) lngX = (T2 * H) + F3 local T3 = math.floor(lngX / M) lngX = lngX - (T3 * M) lngC = math.floor((F2 / H) + F1) return lngX end local function _abs(value) if value < 0 then value = -value end return value end local function _floor(value) return value - (value % 1) end local function _randomseed(x) lngX = x end local function _random(m,n) if n == nil and m ~= nil then n = m m = 1 end if (m == nil) and (n == nil) then return _MWC() / 4294967296 else if n < m then return nil end return math.floor((_MWC() / 4294967296) * (n - m + 1)) + m end end math= { abs = _abs, floor = _floor, random = _random, randomseed = _randomseed, } --[[ End math library ]]-- function Score() return current.GetScore () end function seed() local s=math.abs(Score()) s=s%0.001 s=1/s while s<10000000 do s=s*10 end s=s-s%1 math.randomseed(s) end seed() segCnt=structure.GetCount () p=print function round(x)--cut all afer 3-rd place return x-x%0.001 end function down(x) return x-x%1 end function ShuffeleTable() p("Mixing LWS table...") local tl=#lwsTable for i=1,tl do local n=math.random(tl) lwsTable[i],lwsTable[n]=lwsTable[n],lwsTable[i] end --p("Mixing done.") --save some screen space, redundant message (Stack) end lwsTable={} function CreateTable() p("Preparing LWS table...") lwsTable={} if segEnd==nil then segEnd=segCnt end for sn=segStart,segEnd do for l=minLen, maxLen do if (sn+l-1)<=segEnd then lwsTable[#lwsTable+1]={sn,l} end end end p("We have LWS ",#lwsTable," starts to do.") end function lws() repeat local s=Score() structure.LocalWiggleSelected(2) local g=Score()-s if g<0 then recentbest.Restore() end until g<minPpi end function WalkeR() recentbest.Save () save.Quicksave(3) local ss=Score() p("Starting WalkeR, Score=",round(ss)) local tl=#lwsTable for i=1, tl do local sc=Score() local s=lwsTable[i][1] local l=lwsTable[i][2] selection.DeselectAll () selection.SelectRange(s,s+l-1) lws() save.Quicksave(3) print("Iter " ..i .. "/" .. tl .. " (" .. s .. ":" .. l .. ") g: " .. round(Score()-sc) .. " score: " .. round(Score()) .. plus() ) end p("Total gain: ",round(Score()-ss)) end segStart=1 --start from segEnd=nil --end seg: nil=end of protein minLen=1 --minimum lws len maxLen=7 --maximum lws len minPpi=0.01 --minimum points gain per 2 wiggles, set 0.0001 in endgame :) function go () CreateTable() ShuffeleTable() WalkeR() end function main () -- main added by StackOverflow startScore = current.GetScore () local mf = dialog.CreateDialog ( "Rav3n Marathon WalkeR" ) mf.chk1 = dialog.AddCheckbox ( "Run specified number of times" , true ) mf.sldr = dialog.AddSlider ( "Times" , 3 , 1 , 10 , 0 ) mf.chk2 = dialog.AddCheckbox ( "Run until no more gains are achieved" , false ) mf.chk3 = dialog.AddCheckbox ( "Run forever" , false ) mf.btnGo = dialog.AddButton ( "Start" , 1 ) mf.btnExit = dialog.AddButton ( "Exit" , 0 ) local cmd = dialog.Show ( mf ) if ( cmd == 1 ) then if ( mf.chk3.value == true ) then local iter1 = 1 while ( true ) do print ( "Run " .. iter1 .. " (will run forever!)" ) go () iter1 = iter1 + 1 print ( newscore () ) end elseif ( mf.chk2.value == true ) then local ssc = current.GetScore () - 1 local iter2 = 1 while ( flr ( current.GetScore () , 3 ) > flr ( ssc , 3 ) ) do print ( "Run " .. iter2 .. " (will run until no gains are achieved)" ) ssc = current.GetScore () go () iter2 = iter2 + 1 print ( newscore () ) end elseif ( mf.chk1.value == true ) then for r = 1 , mf.sldr.value do print ( "Run " .. r .. " of " .. mf.sldr.value ) go () print ( newscore () ) end else print ( "no valid repeat options specified, running once only" ) go () end else print ( "user cancelled" ) end end function newscore () return "New Score: " .. flr ( current.GetScore() , 3 ) .. plus () end function plus () return " (+" .. flr((current.GetScore() - startScore),3) .. ")" end function flr(num, idp) local mult = 10^(idp or 0) return math.floor(num * mult) / mult end main () -- -- Josh's Fuse - 6 Nov 2020 - see notes at end -- print ( "Josh's Fuse" ) startScore = current.GetEnergyScore () -- Get the current energy score. print ( "starting score = " .. startScore ) -- print the starting score recentbest.Save () -- Save the current pose as the recent best pose. behavior.SetPackingImportance(0.17) seventeen = behavior.GetPackingImportance() behavior.SetPackingImportance(0.18) eighteen = behavior.GetPackingImportance() modding = true if (seventeen == eighteen) then modding = false end local ask = dialog.CreateDialog("Josh's Fuse") ask.Clashing = dialog.AddCheckbox("Clashing", true) ask.SidechainHBonds = dialog.AddCheckbox("Sidechain HBonds", true) ask.BackboneHBonds = dialog.AddCheckbox("Backbone HBonds", true) ask.Packing = dialog.AddCheckbox("Packing", true) ask.Hiding = dialog.AddCheckbox("Hiding", true) ask.Pairwise = dialog.AddCheckbox("Pairwise", true) if (modding == false) then ask.Warning = dialog.AddLabel("WARNING: Recipe Modding is currently OFF\nPlease turn it on before running this recipe.") end ask.OK = dialog.AddButton("OK", 1) ask.Cancel = dialog.AddButton("Cancel", 0) function resetBehavior() behavior.SetClashImportance ( 1.0 ) behavior.SetSidechainHBondImportance ( 1.0 ) behavior.SetBackboneHBondImportance ( 1.0 ) behavior.SetPackingImportance ( 1.0 ) behavior.SetHidingImportance ( 1.0 ) behavior.SetPairwiseImportance ( 1.0 ) end resetBehavior() if (dialog.Show(ask) > 0) then if (ask.Clashing.value) then behavior.SetClashImportance ( 0.05 ) -- Set the clashing importance. end if (ask.SidechainHBonds.value) then behavior.SetSidechainHBondImportance ( 3.0 ) -- Set the schbonds importance. end if (ask.BackboneHBonds.value) then behavior.SetBackboneHBondImportance ( 3.0 ) -- Set the bbhbonds importance. end if (ask.Packing.value) then behavior.SetPackingImportance ( 3.0 ) -- Set the packing importance. end if (ask.Hiding.value) then behavior.SetHidingImportance ( 3.0 ) -- Set the hiding importance. end if (ask.Pairwise.value) then behavior.SetPairwiseImportance ( 3.0 ) -- Set the pairwise importance. end structure.ShakeSidechainsAll ( 1 ) -- Shake all sidechains. resetBehavior() structure.WiggleAll ( 8 ) -- Global wiggle all segments. print ( "after first shake/wiggle, score = " .. current.GetEnergyScore () ) if (ask.Clashing.value) then behavior.SetClashImportance ( 0.07 ) -- Set the clashing importance. end if (ask.SidechainHBonds.value) then behavior.SetSidechainHBondImportance ( 2.0 ) -- Set the schbonds importance. end if (ask.BackboneHBonds.value) then behavior.SetBackboneHBondImportance ( 2.0 ) -- Set the bbhbonds importance. end if (ask.Packing.value) then behavior.SetPackingImportance ( 2.0 ) -- Set the packing importance. end if (ask.Hiding.value) then behavior.SetHidingImportance ( 2.0 ) -- Set the hiding importance. end if (ask.Pairwise.value) then behavior.SetPairwiseImportance ( 2.0 ) -- Set the pairwise importance. end structure.ShakeSidechainsAll ( 1 ) -- Shake all sidechains. resetBehavior() structure.WiggleAll ( 8 ) -- Global wiggle all segments. print ( "after second shake/wiggle, score = " .. current.GetEnergyScore () ) recentbest.Restore () -- Load the recent best pose. print ( "after restoring recent best, score = " .. current.GetEnergyScore () ) if (ask.Clashing.value) then behavior.SetClashImportance ( 0.3 ) -- Set the clashing importance. end if (ask.SidechainHBonds.value) then behavior.SetSidechainHBondImportance ( 1.5 ) -- Set the schbonds importance. end if (ask.BackboneHBonds.value) then behavior.SetBackboneHBondImportance ( 1.5 ) -- Set the bbhbonds importance. end if (ask.Packing.value) then behavior.SetPackingImportance ( 1.5 ) -- Set the packing importance. end if (ask.Hiding.value) then behavior.SetHidingImportance ( 1.5 ) -- Set the hiding importance. end if (ask.Pairwise.value) then behavior.SetPairwiseImportance ( 1.5 ) -- Set the pairwise importance. end structure.WiggleAll ( 1 ) -- Global wiggle all segments. resetBehavior() if (ask.Clashing.value) then behavior.SetClashImportance ( 0.5 ) -- Set the clashing importance. end if (ask.SidechainHBonds.value) then behavior.SetSidechainHBondImportance ( 0.3 ) -- Set the schbonds importance. end if (ask.BackboneHBonds.value) then behavior.SetBackboneHBondImportance ( 0.3 ) -- Set the bbhbonds importance. end if (ask.Packing.value) then behavior.SetPackingImportance ( 0.3 ) -- Set the packing importance. end if (ask.Hiding.value) then behavior.SetHidingImportance ( 0.3 ) -- Set the hiding importance. end if (ask.Pairwise.value) then behavior.SetPairwiseImportance ( 0.3 ) -- Set the pairwise importance. end structure.WiggleAll ( 3 ) -- Global wiggle all segments. resetBehavior() print ( "after third wiggle, score = " .. current.GetEnergyScore () ) recentbest.Restore () -- Load the recent best pose. structure.WiggleAll ( 8 ) -- Global wiggle all segments. print ( "after final wiggle, score = " .. current.GetEnergyScore () ) recentbest.Restore () -- Load the recent best pose. finalScore = current.GetEnergyScore () -- Get the current energy score. print ( "final score = " .. finalScore ) -- print the final score gain = finalScore - startScore -- calculate the gain print ( "gain = " .. gain ) -- print the gain end print ( "Josh's Fuse complete" ) -- -- original: Blue Fuse v1.1 by Vertex 3 January 2010 - https://fold.it/portal/recipe/2052 -- -- BlueFuse 2020a - LociOiling - 21 March 2020 -- + converted to Foldit Lua interface V1 to V2 -- + added printing scores and gain -- + dropped "select_all", not needed with ShakeSidechainsAll and WiggleAll -- -- Some potential improvements: -- -- TODO: round the score to three decimals -- TODO: repeat the process if there's a gain -- TODO: try different values for clashing importance -- TODO: try a different number of iterations for wiggle -- TODO: turn off filters during shake and wiggle for better performance -- TODO: add a dialog to control settings -- -- -- original: Blue Fuse v1.1 by Vertex 3 January 2010 - https://fold.it/portal/recipe/2052 -- -- BlueFuse 2020a - LociOiling - 21 March 2020 -- + converted to Foldit Lua interface V1 to V2 -- + added printing scores and gain -- + dropped "select_all", not needed with ShakeSidechainsAll and WiggleAll -- --

Comments