Profile
- Name
- TEST JF + Walk MarathoN + MULTILOCKONES
- ID
- 104985
- Shared with
- Public
- Parent
- TEST JF Rav3n_pl WalkeR MarathoN
- Children
- None
- Created on
- July 07, 2021 at 00:08 AM UTC
- Updated on
- December 30, 2024 at 19:54 PM UTC
- Description
JOSH'S FUZE + WALKER MARATHON + MULTI WALK LOCKED ONES
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
--
-- -- ZeroLeak7 Multiwalker for locked ones v0.9
-- converted scripts to Lua "V2"
-- Precise LWS 2.0.1, Total LWS 1.0.4, Blue Fuze v1.1
-- Globals
loop_starts = {}
loop_ends = {}
n_loops = 0
n_residues = 0
function Lockedresidues ()
selection.SelectAll()
structure.SetSecondaryStructureSelected("H")
for i=1, structure.GetCount() do
if structure.GetAminoAcid(i) == "unk" then
structure.SetSecondaryStructure(i, "H")
end
if structure.IsLocked(i) == false then
structure.SetSecondaryStructure(i, "L")
end
end
end
function GetLoops ()
within_loop = false
for i = 1, n_residues do
if ( structure.GetSecondaryStructure ( i ) == "L" and structure.IsLocked(i) == false ) then
if ( within_loop == false ) then
-- start of a new loop
within_loop = true
n_loops = n_loops + 1
loop_starts [ n_loops ] = i
end
elseif ( within_loop == true ) then
-- end of a loop
within_loop = false
loop_ends [ n_loops ] = i -1
end
end -- for i
if ( within_loop == true ) then
loop_ends [ n_loops ] = n_residues
end
end
-- ================ Precise LWS v2.0.1 ================
--Precise LWS by rav3n_pl
--searches and wiggles worst segments
--options at end of script
function score() --score of puzzle
return current.GetScore()
end
function getPartScore(segments)--using partial scoring
local attr = {'packing','backbone','other','bonding','sidechain','clashing'}--,'hiding','reference','disulfides'}
local score = 0
for i=1,#attr do
score = score + current.GetSegmentEnergySubscore(segments, attr[i])
end
return score
end
function getworst() --fill score table
worst={}
for f=1, #loop_starts do
for i=loop_starts [ f ], loop_ends [ f ] do
sc=getPartScore(i)
worst[i]=sc
end
end
return worst
end
function wig(mingain) --score conditioned wiggle,
repeat --wiggles selected segments
ss=score()
structure.LocalWiggleSelected(2)
se=score()
wg=se-ss
if wg<0 then
recentbest.Restore()
end
until wg<mingain
selection.DeselectAll()
freeze.UnfreezeAll()
end
function wiggle2(s, mingain, buddies)
print("Wigglin segment "..s)
selection.DeselectAll()
freeze.UnfreezeAll()
sgs=score()
maxi=structure.GetCount()
if s+1<=maxi then selection.Select(s+1)end
if s-1>=1 then selection.Select(s-1)end
freeze.FreezeSelected(true, true)
selection.DeselectAll()
selection.Select(s)
wig(mingain)
if buddies > 0 then --select buddies
for b=1, buddies do
if s+b+1<=maxi then selection.Select(s+b+1)end
if s-1>=1 then selection.Select(s-1)end
freeze.FreezeSelected(true, true)
selection.DeselectAll()
if s+b>maxi then selection.SelectRange(s,maxi)
else selection.SelectRange(s,s+b)end
wig(mingain)
if s+1<=maxi then selection.Select(s+1)end
if s-b-1>=1 then selection.Select(s-b-1)end
freeze.FreezeSelected(true, true)
selection.DeselectAll()
if s-b<1 then selection.SelectRange(1,s)
else selection.SelectRange(s-b,s)end
wig(mingain)
if s+b+1<=maxi then selection.Select(s+b+1)end
if s-b-1>=1 then selection.Select(s-b-1)end
freeze.FreezeSelected(true, true)
selection.DeselectAll()
if s+b>maxi then selection.SelectRange(s,maxi)
else selection.SelectRange(s,s+b)end
if s-b<1 then selection.SelectRange(1,s)
else selection.SelectRange(s-b,s)end
wig(mingain)
end
end
sge=score()
print("Segment gain: "..sge-sgs)
end
function wiggleworst(howmany, mingain, buddies)
behavior.SetClashImportance(1)
freeze.UnfreezeAll()
selection.DeselectAll()
recentbest.Save()
sscore=score()
worst=getworst()
for f=1, #loop_starts do
for i=loop_starts [ f ],loop_ends [ f ] do
print(i.." "..worst[ i ])
end
end
for i=1, howmany do
print(((howmany*#loop_starts)+#loop_starts)-i*#loop_starts.." segments left to do.")
for a=1, #loop_starts do
min=loop_starts [ a ]
seg=1
for f=loop_starts [ a ],loop_ends [ a ] do
if min>worst[f] then
min=worst[f]
seg=f
end
end
wiggle2(seg, mingain, buddies)
worst[seg]=9999--never again same one
end
end
escore=score()
print("Total gain: "..escore-sscore.." pts")
end
-- ================ Total LWS 1.0.4 ================
local function score1() --score of puzzle
return current.GetScore()
end
function AllLoop()
selection.SelectAll()
structure.SetSecondaryStructureSelected("L")
end
function freeze1(start, len)
freeze.UnfreezeAll()
selection.DeselectAll()
for i = 1, n_loops do
for f=loop_starts [ i ] -1 + start, loop_ends [ i ], len+1 do
if f<= loop_ends [ i ] then selection.Select(f) end
end
freeze.FreezeSelected(true, false)
end
end
function lw(minppi)
local gain=true
while gain do
local ss=score1()
structure.LocalWiggleSelected(2)
local g=score()-ss
if g<minppi then gain=false end
if g<0 then recentbest.Restore() end
end
end
function wiggle3(start, len,minppi)
for i = 1, n_loops do
if loop_starts [ i ] -1 + start > loop_starts [ i ] then
selection.DeselectAll()
selection.SelectRange(loop_starts [ i ],loop_starts [ i ] - 1 + start - 1)
lw(minppi)
end
for f=loop_starts [ i ] -1 + start, loop_ends [ i ], len+1 do
selection.DeselectAll()
local ss = f+1
local es=f+len
if ss >= loop_ends [ i ] then ss=loop_ends [ i ] end
if es >= loop_ends [ i ] then es=loop_ends [ i ] end
selection.SelectRange(ss,es)
lw(minppi)
end
end
end
function totalLws(minlen,maxlen, minppi)
freeze.UnfreezeAll()
selection.DeselectAll()
behavior.SetClashImportance(1)
local ssc=score1()
print("Starting Total LWS: "..ssc)
print("Lenght: "..minlen.." to "..maxlen.." ;minimum ppi: "..minppi)
for l=minlen, maxlen do
for s=1, l+1 do
print("Len: "..l.." start point: "..s)
local sp=score1()
freeze1(s,l)
recentbest.Save()
wiggle3(s,l,minppi)
print("Gained: "..score1()-sp)
save.Quicksave(3)
end
end
print("Finished! Total gain: "..score1()-ssc)
freeze.UnfreezeAll()
end
-- ================ Blue Fuze v1.1 ================
function BlueFuze ()
print("=============== Blue Fuze v1.1 ===============")
freeze.UnfreezeAll()
selection.DeselectAll()
behavior.SetClashImportance(1)
recentbest.Save()
for i= 1 , #loop_starts do
selection.SelectRange(loop_starts[ i ],loop_ends[ i ])
end
behavior.SetClashImportance(.05)
structure.ShakeSidechainsSelected(1)
behavior.SetClashImportance(1)
structure.WiggleSelected(8)
behavior.SetClashImportance(.07)
structure.ShakeSidechainsSelected(1)
behavior.SetClashImportance(1)
structure.WiggleSelected(8)
recentbest.Restore()
behavior.SetClashImportance(.3)
structure.WiggleSelected(1)
behavior.SetClashImportance(1)
structure.WiggleSelected(8)
recentbest.Restore()
score2=current.GetScore()
print("Blue Fuze score: "..score2-score2%0.001)
end
function main ()
print ( "ZeroLeak7 Multiwalker for locked ones v0.9" )
band.DisableAll ()
save.SaveSecondaryStructure()
n_residues = structure.GetCount ()
behavior.SetClashImportance ( 1 )
Lockedresidues ()
GetLoops ()
n_loops = #loop_starts
print ( n_loops .. " loops" )
n_loops = #loop_starts
for i = 1 , n_loops do
print ( "Loop " .. i .. " : (" .. loop_starts [ i ] .. "-" .. loop_ends [ i ] .. ")" )
end
AllLoop()
while (true) do
--wiggleworst(howmany, mingain, buddies)
--howmany = 3 -how many worst segments to process mutiplied by loop count example(if you have 2 loops (howmany = 3) * 2 loops = 6
--mingain = 0.3 -minimum gain per wiggle iterations (if more per 2 wiggle wiggles again)
--buddies = 3 -how many segments aside should be wiggled too
--ie worst segment is no 44 and buddies set to 1 then
-- willging seg 44 then 43+44; later seg 44+45 and finally 43+44+45
print("=============== Precise LWS v2.0.1 ===============")
wiggleworst(3,0.3,3)
--totalLws(minlen, maxlen, minppi)
--minlen - minimum lenggh of sgmnts - if you have done lws by 1 and 2 you may want set it to 3
--maxlen - maximum lenght of sgments - more than 7 looks useless
--minppi - minimum gain per local wiggle iter
print("=============== Total LWS 1.0.4 ===============")
totalLws(1,7,0.001)
BlueFuze ()
end
end
function cleanup ()
print ( "Cleaning up" )
behavior.SetClashImportance ( 1.0 )
band.EnableAll ()
freeze.UnfreezeAll()
save.LoadSecondaryStructure()
end
xpcall(main , cleanup)