Profile
- Name
- QuakeR & BWF v2.5.9
- ID
- 109077
- Shared with
- Public
- Parent
- QuakeR & BWF v2.5.8
- Children
- Created on
- June 16, 2025 at 16:47 PM UTC
- Updated on
- June 17, 2025 at 21:45 PM UTC
- Description
QuakeR & BWF v2.5.9 + better shake and wiggle ci in Fuze + GUI + reverse algo + Filter Disabled + BandFuze.
Best for
Code
--QuakeR - a randomized Quake
recipeTitle='QuakeR & BWF v2.5.9 '
--v1.0 combined two recpies QuakeR v5 with mutate & Bravo BWF v1.1
-- updated and changed some functions!
-- future plans more settings in the gui
-- created 2025-05-22 ZeroLeak7
-- QuakeR & BWF v1.5
-- updated 28 May 2025 ZeroLeak7
-- No Shake! or Shake! two Buttons option in the gui and some optimizations
-- QuakeR & BWF v2.0 Bugfixing and some tweaks
-- updated & released 4 June 2025
-- Quaker & BWF v2.5 combined with BandFuze.
-- updated & released 5 June 2025
-- QuakeR & BWF v2.5.1
-- updated & released 12 June 2025
-- QuakeR & BWF v2.5.7
-- updated & released 13 June 2025
-- bugfixing
-- QuakeR & BWF v2.5.8
-- updated & released 15 June 2025
-- bugfixing
-- QuakeR & BWF v2.5.9
-- updated & released 16 June 2025
-- bugfixing (fixed a bug in Bandfuze starts: x iterations with a loop_count variable)
--[[
Based on "Quake" by Grom
v2.51 -- update 2011-01-15 rav3n_pl
v3.0 -- update 2011-04-18 rav3n_pl
v4.0 -- updated 27 Dec 2014 GaryForbis
v4.5 -- updated 2019-12-30 ZeroLeak7
v5.0 -- updated 2019-12-31
-converted to script v2
-band hydrophobes to beta carbon
-clean up on early exit
-better shake and wiggle ci in Fuze and with mutate now
-updated with a gui
]]
-- original -- behavior wiggle fuze v1 by Bruno Kestemont
--Bravo BWF
--v1 i did a brute force of all single variable behaivor wiggle variations that were reasonable, this script includes all gains that were >0.1
-- it's just a potential script that might see some gains. totally experimental.
-- just a small script that uses recipe scoring mods. works well on ligand / small molecule placement
--v1.1 fixed glitch on Behavior importance
--Wiggle all
Best_Score_slot_num = 1 -- quick save slot for best score
save.Quicksave(Best_Score_slot_num) --save starting score as best score saved in quick save 1
BestScore = current.GetScore()
StartScore = BestScore
BestBonus = filter.GetBonusTotal()
StartBonus = BestBonus
Importance = 3
global_clashing_importance = 1
behavior_string = "starting"
Behavior_value = 1
segCnt=structure.GetCount()
while structure.GetSecondaryStructure(segCnt)=="M" do segCnt=segCnt-1 end
function floor3(x)--cut at 3rd decimal place
return x-x%0.001
end
start_clock=os.clock()
start_time=os.time()
function report_time(start_clock,start_time,clock_msg,time_msg)
local seconds,minutes,hours,days
if clock_msg==nil then clock_msg="CPU time" end
if time_msg==nil then time_msg="Elasped time" end
print(string.format("%s",os.date()))
days,remainder=math.modf((os.clock()-start_clock)/(24*60*60))
hours,remainder=math.modf(remainder*24)
minutes,remainder=math.modf(remainder*60)
seconds,remainder=math.modf(remainder*60)
print(string.format("%s(%02id:%02ih:%02im:%02is)",clock_msg,days,hours,minutes,seconds))
days,remainder=math.modf(os.difftime(os.time(),start_time)/(24*60*60))
hours,remainder=math.modf(remainder*24)
minutes,remainder=math.modf(remainder*60)
seconds,remainder=math.modf(remainder*60)
print(string.format("%s(%02id:%02ih:%02im:%02is)",time_msg,days,hours,minutes,seconds))
end
print("Make sure RECIPE SCORE MODDING")
print("is checked before running!")
print("----------------------------------------------------------------------------")
print("Starting "..recipeTitle)
print("----------------------------------------------------------------------------")
print("Start score: "..floor3(StartScore))
print('puzzle: '..puzzle.GetName())
print('with puzzle ID '..puzzle.GetPuzzleID()..', '..segCnt..' segments,')
save.SaveSecondaryStructure()
function SaveBest()
local ss= current.GetScore()
local g = ss - BestScore
local tb = filter.GetBonusTotal()
local bg = tb - BestBonus --dont let the bonus score decrease
if g > 0 then --and bg >= 0 then -- removed bonus requirements
--if g > 0.1 then
print(behavior_string .. Importance)
print("Iteration length: " , iteration_variable , " CI: " , global_clashing_importance)
print("Gained another " ..floor3(g).. " Score: "..floor3(ss).. " Bonus: "..tb)
print("Total Gain: "..floor3(ss-StartScore))
--end
BestScore= ss
BestBonus = tb
save.Quicksave(Best_Score_slot_num) --best score saved in quick save 1
save.Quickload(Best_Score_slot_num) --load best state
else
--print(":( no gain")
end
return ss-StartScore
end
function SidechainsHbondFuze()
--print("SidechainHbond")
behavior_string= "SidechainHbond: "
recentbest.Save()
behavior.SetClashImportance(global_clashing_importance)
behavior.SetSidechainHBondImportance(Importance)
structure.WiggleAll(iteration_variable,true,true) -- wa
iteration_variable=iteration_variable*2
Behavior_reset()
structure.WiggleAll(25,true,true)
is_recent_best_better()
SaveBest()
--behavior.SetSidechainHBondImportance(1)
end
function BackboneHbondFuze()
--print("BackboneHbond")
behavior_string= "BackboneHbond: "
recentbest.Save()
behavior.SetClashImportance(global_clashing_importance)
behavior.SetBackboneHBondImportance(Importance)
structure.WiggleAll(iteration_variable,true,true) -- wa
iteration_variable=iteration_variable*2
Behavior_reset()
structure.WiggleAll(25,true,true)
is_recent_best_better()
SaveBest()
--behavior.SetBackboneHBondImportance(1)
end
function PairWiseFuze()
--print("PairWise")
behavior_string= "PairWise: "
recentbest.Save()
behavior.SetClashImportance(global_clashing_importance)
behavior.SetPairwiseImportance(Importance)
structure.WiggleAll(iteration_variable,true,true) -- wa
iteration_variable=iteration_variable*2
Behavior_reset()
structure.WiggleAll(25,true,true)
is_recent_best_better()
SaveBest()
--behavior.SetPairwiseImportance(1)
end
function PackingFuze()
--print("Packing")
behavior_string= "Packing: "
recentbest.Save()
behavior.SetClashImportance(global_clashing_importance)
behavior.SetPackingImportance(Importance)
structure.WiggleAll(iteration_variable,true,true) -- wa
iteration_variable=iteration_variable*2
Behavior_reset()
structure.WiggleAll(25,true,true)
is_recent_best_better()
SaveBest()
--behavior.SetPackingImportance(1)
end
function HidingFuze()
--print("Hiding")
behavior_string= "Hiding: "
recentbest.Save()
behavior.SetClashImportance(global_clashing_importance)
behavior.SetHidingImportance(Importance)
structure.WiggleAll(iteration_variable,true,true) -- wa
iteration_variable=iteration_variable*2
Behavior_reset()
structure.WiggleAll(25,true,true)
is_recent_best_better()
SaveBest()
--behavior.SetHidingImportance(1)
end
function ClashingFuze()
--print("Clashing importance 0.9")
behavior_string= "Clash: "
recentbest.Save()
--behavior.SetClashImportance(0.9)
behavior.SetClashImportance(global_clashing_importance)
structure.WiggleAll(iteration_variable,true,true) -- wa
iteration_variable=iteration_variable*2
Behavior_reset()
structure.WiggleAll(25,true,true)
is_recent_best_better()
SaveBest()
--behavior.SetClashImportance(1)
end
function DensityFuze()
--print("Density")
behavior_string = "Density: "
recentbest.Save()
behavior.SetClashImportance(global_clashing_importance)
behavior.SetDensityImportance(Importance)
structure.WiggleAll(iteration_variable,true,true) -- wa
iteration_variable=iteration_variable*2
Behavior_reset()
structure.WiggleAll(25,true,true)
is_recent_best_better()
SaveBest()
--behavior.SetDensityImportance(1)
end
recent_best_count=0
function is_recent_best_better() --sometime recent best is better than settled score
local score = current.GetScore()
recentbest.Restore()
recent_best_score = current.GetScore()
if (recent_best_score>score and recent_best_score > BestScore) then
print("Recent best restored")
structure.WiggleAll(10,true,true)
if (recent_best_count<4) then --infinite recursion != infinite gain. breaks on 4 failed attemps. might get triggered many times
recent_best_count = recent_best_count + 1
print ("recent_best_count: " .. recent_best_count .. " of 5")
is_recent_best_better() --fixes a bug where the score goes down with these settings
end
score = current.GetScore()
if (score < recent_best_score ) then
recentbest.Restore()
end
end
recent_best_count=0
end
function Behavior_reset()
behavior.SetClashImportance(1)
behavior.SetHidingImportance(1)
behavior.SetPackingImportance(1)
behavior.SetPairwiseImportance(1)
behavior.SetBackboneHBondImportance(1)
behavior.SetSidechainHBondImportance(1)
behavior.SetDensityImportance(1)
end
function Bravo_BWF(BWF_string,Behavior_value,Iterationlength,CI)
Importance = Behavior_value
iteration_variable = Iterationlength
global_clashing_importance = CI
if (BWF_string== "SidechainHbond:") then
SidechainsHbondFuze()
elseif (BWF_string== "BackboneHbond:") then
BackboneHbondFuze()
elseif (BWF_string== "PairWise:") then
PairWiseFuze()
elseif (BWF_string== "Packing:") then
PackingFuze()
elseif (BWF_string== "Hiding:") then
HidingFuze()
elseif (BWF_string== "Density:") then
DensityFuze()
elseif (BWF_string== "Clash:") then
ClashingFuze()
else
print("error Bravo_BWF: BWF_string: ".. BWF_string)
end
end
-- variables users probably don't want to play with
USENORMALSCORE = true
InitialScore = 0.0 -- not important: will be reinitialized in InitializePuzzleState( )
StartTime = 0 -- not important: will be reinitialized in InitializePuzzleState( )
CurrentBestScore = 0 -- not important: will be reinitialized in InitializePuzzleState( )
-- Globals
loop_starts = {}
loop_ends = {}
n_loops = 0
n_residues = 0
IterationMultiplier = 1.2 -- 2.4
ItMu = IterationMultiplier
if ItMu<=0 then ItMu=1 end
nSegs=structure.GetCount()
p=print
p("")
function Test()
recentbest.Save()
sci=(math.random(cival*100)/100)
setCI(sci)
if (local_shake == true) then
global_clashing_importance = sci
p(" Shake CI:", sci)
p("Shake!...")
wig("s") Check()
end
print ("Density: Fuze...")
Bravo_BWF("Density:",3,2,0.07)
Check()
setCI(cival)
global_clashing_importance = cival
wig() Check()
setCI(cival/2)
global_clashing_importance = cival
wig("wa",5) Check()
setCI(cival)
global_clashing_importance = cival
wig() Check()
qStab(2,1)
setCI(cival)
global_clashing_importance = cival
wig() Check()
setCI(cival/2)
global_clashing_importance = cival
wig("wa",5) Check()
setCI(cival)
global_clashing_importance = cival
wig() Check()
recentbest.Restore()
Check()
current_Score = current.GetScore()
if (fuzing == true) then
if fuzt<=0 then
if score()>=(bestscore+fuzt) then
recentbest.Save()
SaveBest2() -- save best score
p("Fuzing...")
Fuzit()
if (current.GetScore()-startscore) <= 0.001 then
recentbest.Restore()
save.Quickload(2) --load initial state
elseif (current.GetScore()-startscore) >= 0.001 then
recentbest.Restore()
save.Quickload(1)
end
current_Score = current.GetScore()
end
else
if score()>=(bestscore+FF) then
p("Fuzing...")
recentbest.Save()
SaveBest2() -- save best score
Fuzit()
if (current.GetScore()-startscore) <= 0.001 then
recentbest.Restore()
save.Quickload(2) --load initial state
elseif (current.GetScore()-startscore) >= 0.001 then
recentbest.Restore()
save.Quickload(1)
end
current_Score = current.GetScore()
end
end
else
current_Score = current.GetScore()
is_recent_best_better() -- check if recent best is better than current score
SaveBest2() -- save best score
if current_Score < bestscore then
print("Current score is lower than best score. ")
print("Loading best state.")
recentbest.Restore() --restore best state
save.Quickload(1)
else
print("Current score is better than best score. ")
print("Saving & Loading current state.")
recentbest.Save() --save current state
save.Quicksave(1)
recentbest.Restore()
save.Quickload(1)
end
end
end
function residues_range ()
selection.SelectAll()
structure.SetSecondaryStructureSelected("L")
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
function rounding2(x)--cut at 2nd decimal place
return x-x%0.01
end
function score()
return current.GetScore()
end
function SaveBest2()
local ss= current.GetScore()
local g = ss - BestScore
local tb = filter.GetBonusTotal()
local bg = tb - BestBonus --dont let the bonus score decrease
if g > 0 then --and bg >= 0 then -- removed bonus requirements
--if g > 0.1 then
print("Iteration length: " , iteration_variable , " CI: " , global_clashing_importance)
print("Gained another " ..floor3(g).. " pts. new Score: "..floor3(ss))
print("Bonus: "..tb)
print("Total Gain: "..floor3(ss-StartScore).." pts.")
--end
BestScore= ss
BestBonus = tb
save.Quicksave(Best_Score_slot_num) --best score saved in quick save 1
save.Quickload(Best_Score_slot_num) -- load best state
else
--print(":( no gain")
end
return ss-StartScore
end
function InitializePuzzleState() --function by ZeroLeak7
InitialScore = score()
CurrentBestScore = InitialScore
Starttime = os.time()
Endtime = puzzle.GetExpirationTime()
timeLeft=os.difftime(Endtime,Starttime)/3600
tminutes=math.floor(timeLeft)
timeshift=(timeLeft-tminutes)*60
print("Remaining time: "..string.format("%.0f", timeLeft).." hour/s "..math.floor(timeshift).." minute/s")
end
function Wiggle(how, iters, minppi, shakeiters) --score conditioned recursive wiggle/shake
iteration_variable = iters
if how==nil then how="wa" end
if iters==nil then iters=3 end
if minppi==nil then minppi=0.1 end
if shakeiters==nil then shakeiters=1 end
if iters>0 then
local sp=score()
if how == "s" then
structure.ShakeSidechainsAll(shakeiters) return 0
elseif how == "wb" then structure.WiggleAll(iters,true,false)
elseif how == "ws" then structure.WiggleAll(iters,false,true)
elseif how == "wa" then structure.WiggleAll(iters,true,true)
end
if score()-sp > minppi then return Wiggle(how, iters, minppi, shakeiters) end
end
end
function wig(how, it, iters, minppi)
iteration_variable = it
behavior.SetSlowFiltersDisabled(true)
if how==nil then how="wa" end
if minppi==nil then minppi=2 end
if iters==nil then iters=2 end
if it==nil then it=10*ItMu end
it=math.ceil(it)
if iters>0 then
iters=iters-1
local sp=score()
if how == "s" then structure.ShakeSidechainsAll(1) return 0
elseif how == "wb" then structure.WiggleAll(it,true,false)
elseif how == "ws" then structure.WiggleAll(it,false,true)
elseif how == "wa" then structure.WiggleAll(it)
end
if score()-sp > minppi and how ~= "s" then return wig(how, it, iters, minppi) end
end
behavior.SetSlowFiltersDisabled(false)
end
function qStab(iters, shakeiters)
iteration_variable = iters*2
behavior.SetClashImportance(0.1)
global_clashing_importance = 0.1
Wiggle("wa",iters)
if fastQstab==false then
behavior.SetClashImportance(0.02)
global_clashing_importance = 0.02
Wiggle("wa",iters)
behavior.SetClashImportance(1)
global_clashing_importance = 1
Wiggle("wa",iters*12)
end
behavior.SetClashImportance(1)
global_clashing_importance = 1
Wiggle("wa",iters)
if (local_shake == true) then
print("Shake!...")
Wiggle("s",shakeiters)
iteration_variable = shakeiters
end
closetobest = bestscore-current.GetScore()
return SaveBest2()
end
function reFuze(scr)
local s=score()
if s<scr then
recentbest.Restore()
else
scr=s
recentbest.Save()
end
return scr
end
function Fuze1(ci1, ci2, iters, shakeiters)
iteration_variable = iters*2
behavior.SetDensityImportance(3)
behavior.SetClashImportance(ci1)
global_clashing_importance = ci1
Wiggle("wa",iters+22)
Behavior_reset()
Wiggle("wa",iters+22)
behavior.SetClashImportance(ci2)
global_clashing_importance = ci2
Wiggle("wa",iters+22)
behavior.SetClashImportance(0.88)
global_clashing_importance = 0.88
if (local_shake == true) then
print("Shake!...")
Wiggle("s",shakeiters)
end
end
function Fuze2(ci1, ci2, iters)
iteration_variable = iters*2
behavior.SetClashImportance(ci1)
global_clashing_importance = ci1
Wiggle("wa",iters)
behavior.SetClashImportance(0.07)
global_clashing_importance = 0.07
Wiggle("wa",iters)
behavior.SetClashImportance(ci2)
global_clashing_importance = ci2
Wiggle("wa",iters)
end
function FuzeEnd(iters, shakeiters)
iteration_variable = iters*2
print("FuzeEnd")
behavior.SetClashImportance(1)
global_clashing_importance = 1
Wiggle("wa",iters)
behavior.SetClashImportance(0.07)
global_clashing_importance = 0.07
Wiggle("wa",iters)
behavior.SetClashImportance(1)
global_clashing_importance = 1
Wiggle("wa",iters)
behavior.SetClashImportance(0.88)
global_clashing_importance = 0.88
if (local_shake == true) then
print("Shake!...")
Wiggle("s",shakeiters)
iteration_variable = shakeiters
end
SaveBest2()
end
function Fuzit()
Sf1=math.random(-100,100)
if Sf1>=0 then Sf=false
else Sf=true end
Fuze()
end
function Check()
if (bestscore < score()) then
gain = score() - bestscore
bestscore = score()
save.Quicksave(1)
save.Quickload(1)
p(" ",cut(gain),"pts.")
else
gain = 0
end
end
function Fuze()
local scr=score()
print("Fuze1")
Fuze1(0.01,1,3,1)
SaveBest2()
FuzeEnd(2, 1)
print("reFuze")
qStab(2,1)
scr=reFuze(scr)
print("Fuze2")
Fuze2(0.3,1,2)
SaveBest2()
print("reFuze")
scr=reFuze(scr)
print("Fuze1")
Fuze1(0.05,1,2,1)
SaveBest2()
print("reFuze")
qStab(2,1)
scr=reFuze(scr)
print("Fuze2")
Fuze2(0.7,0.5,2)
FuzeEnd(2, 1)
print("reFuze")
scr=reFuze(scr)
print("Fuze1")
Fuze1(0.07,1,2,1)
SaveBest2()
print("reFuze")
qStab(2,1)
scr=reFuze(scr)
end
function bandstr(str) --set all band strength
for i=1, band.GetCount() do
band.SetStrength(i, str)
end
end
function Result()
behavior.SetSlowFiltersDisabled(false)
recentbest.Restore() Check()
save.Quickload(1)
Delbands()
Tgain = (bestscore-startscore)
if Tgain<0.008 then
p(" No change.. :/ ")
else
p(" Startscore: "..cut(startscore))
p(" Score: "..cut(score()))
p(" Total gain: "..cut(Tgain).." pts.")
end
setCI(cival)
end
function bandpull(minBS,maxBS)
if KB then band.EnableAll() end
local ss = score()
local perc=math.random(80,200)/100
local loss=((perc*ss)/100)
--p(" Min. loss: "..perc.."%, "..cut(loss),"points.")
local lastBS=minBS
print("Pulling...")
for str=lastBS,maxBS, 0.1 do
if KBSTR then
local NNbands = band.GetCount()
for i=oldbands+1, NNbands do
band.SetStrength(i, str)
end
else
for i=1, band.GetCount() do
band.SetStrength(i, str)
end
end
wig('wb',1,1,500)
maxLoss = score()
loss2=math.abs(math.floor(bestscore - maxLoss))
if (ss-score()>=loss) or (score()>bestscore+1) then
if band.GetCount()>(nSegs/10)*2 then
lastBS=str-0.1
if lastBS<minBS then lastBS=minBS end
else
lastBS=minBS
end
break
end
end
print("Pulling until loss of "..tostring(loss2).." points.")
end
function bandage()
if bloat==true then
if KBSTR then
local NNbands = band.GetCount()
for i=oldbands+1, NNbands do
band.SetGoalLength(i,band.GetLength(i)+4)
end
else
for i=1, band.GetCount() do
band.SetGoalLength(i,band.GetLength(i)+4)
end
end
else
if KBSTR then
local NNbands = band.GetCount()
for i=oldbands+1, NNbands do
local leng=band.GetLength(i)
local perc=math.random(20,50)
local loss=((perc*leng)/100)
band.SetGoalLength(i,band.GetLength(i)-loss)
end
else
for i=1, band.GetCount() do
local leng=band.GetLength(i)
local perc=math.random(20,50)
local loss=((perc*leng)/100)
band.SetGoalLength(i,band.GetLength(i)-loss)
end
end
end
end
function spacebands(amnt)
local zeBands=math.random(amnt)+Qbands
if zeBands<1 then
zeBands = 1
end
while band.GetCount()<zeBands do
segO = math.random(nSegs)
OsegC=1
while structure.IsLocked(segO)==true do
segO=math.random(nSegs)
OsegC=OsegC+1
if OsegC>25 then
break
end
end
if ZL==true then
rho=0.2
else
rho=math.random(10)
end
theta = math.random(100,314.159)/100
phi = math.random(100,314.159)/100
if phi<1 then phi=phi+1 end
if theta<1 then theta=theta+1 end
if segO<=nSegs and segO>=1 then
if segO==nSegs then
segX = segO-1
segY = segO-2
elseif segO==1 then
segX = segO+1
segY = segO+2
else
segX = segO-1
segY = segO+1
end
if segX>nSegs then segX=nSegs-1 end
if segY>nSegs then segY=nSegs-1 end
if segY<1 then segY=1 end
if segX<1 then segX=1 end
--[[
p(segX,"X")
p(segY,"Y")
p(segO,"O")
p(theta,"theta")
p(phi,"phi")
]]
lb=band.Add(segO, segX, segY, rho, theta, phi)
--local lb=band.GetCount()
if ZL==true then
band.SetGoalLength(lb,math.random(1))
band.SetStrength(lb,math.random(10))
else
band.SetGoalLength(lb,math.random(band.GetLength(lb)*2))
end
end
end
end
function Delbands()
freshbands = band.GetCount()
for h = oldbands, freshbands-1 do
band.Delete(oldbands+1)
end
end
cival=behavior.GetClashImportance()
if cival<0.1 then cival = 1 end
oldbands = 0
oldbands = band.GetCount()
Qbands = 0
function PullingQuakeR(x,ix,iy,ql,rev)
print("Pass "..tostring(x).." of "..tostring(ql))
local start=math.floor(math.random(segCnt/10))
local len=math.floor(math.random(segCnt/2-5))+10
local step=math.floor(math.random((iy-ix)/10,((iy-ix)/10)+10))
local step2=math.floor(math.random(((iy-ix)/10)-10,(iy-ix)/10))
local ss=score()
Delbands()
if not KBE then band.DisableAll() end
if(rev==true) then
print("----------------------------------------------------------------------------")
print("Bands from segment "..tostring(ix+step2))
print(" of length "..tostring(step2*(-1)).." every "..tostring(step2).." segments.")
print("----------------------------------------------------------------------------")
for x=ix,iy, step2 do
for y=ix, iy, step2 do
band.AddBetweenSegments(x,y)
end
end
behavior.SetClashImportance(pullingCI)
recentbest.Save()
bandpull(minBS,maxBS)
else
print("----------------------------------------------------------------------------")
print("Bands from segment "..tostring(start))
print(" of length "..tostring(step).." every "..tostring(step).." segments.")
print("----------------------------------------------------------------------------")
for x=start,iy, step do
for y=start+len, iy, step do
band.AddBetweenSegments(x,y)
end
end
behavior.SetClashImportance(pullingCI)
recentbest.Save()
bandpull(minBS,maxBS)
end
return current.GetScore()
end
function QuakeR(ix,iy,ql,rev)
math.randomseed(os.time()) math.random() math.random() math.random()
-- Disable filters
behavior.SetFiltersDisabled(true)
selection.SelectAll()
save.Quicksave(1)
save.Quicksave(2)
startscore = score()
bestscore = startscore
print("----------------------------------------------------------------------------")
print("Starting "..recipeTitle..tostring(ql).." passes.")
print("----------------------------------------------------------------------------")
print("Start score: "..floor3(startscore))
for x=1, ql do
PullingQuakeR(x,ix,iy,ql,rev)
Delbands()
if not KBE then band.DisableAll() end
behavior.SetClashImportance(1)
recentbest.Save() --after pulling
print("Stabilizing...")
qStab(2,1)
Check()
if (fuzing == true) then
if fuzt<=0 then
if score()>=(bestscore+fuzt) then
recentbest.Save()
SaveBest2() -- save best score
p("Fuzing...")
Fuzit()
if (current.GetScore()-startscore) <= 0.001 then
recentbest.Restore()
save.Quickload(2) --load initial state
elseif (current.GetScore()-startscore) >= 0.001 then
recentbest.Restore()
save.Quickload(1)
end
current_Score = current.GetScore()
end
else
if score()>=(bestscore+FF) then
p("Fuzing...")
recentbest.Save()
SaveBest2() -- save best score
Fuzit()
if (current.GetScore()-startscore) <= 0.001 then
recentbest.Restore()
save.Quickload(2) --load initial state
elseif (current.GetScore()-startscore) >= 0.001 then
recentbest.Restore()
save.Quickload(1)
end
current_Score = current.GetScore()
end
end
else
current_Score = current.GetScore()
is_recent_best_better() -- check if recent best is better than current score
SaveBest2() -- save best score
if current_Score < bestscore then
print("Current score is lower than best score. ")
print("Loading best state.")
recentbest.Restore() --restore best state
save.Quickload(1)
else
print("Current score is better than best score. ")
print("Saving & Loading current state.")
recentbest.Save() --save current state
save.Quicksave(1)
recentbest.Restore()
save.Quickload(1)
end
end
loop_starting_score = current.GetScore()
loop_gain = 1.2
loop_count = 0
current_Score = current.GetScore()
while (loop_gain > 1.0) do -- recent best tends to make .01 gains forever. want to avoid that slowness.
print("Starting Score: ".. startscore)
print("Current Score: ".. current_Score)
loop_starting_score = current.GetScore()
loop_count = loop_count+1
-- these were experimentally determined to make gains. doesn't always work but it's better then brute force.
-- Bravo_BWF(Behavior type,B_v , Iteration length , Clashing Importance)
print ("Starting behavior wiggle fuze (BWF)...")
print (" ")
print ("Density: Fuze...")
print (" ")
Bravo_BWF("Density:",3,2,0.07)
print ("BackboneHbond: Fuze...")
print (" ")
Bravo_BWF("BackboneHbond:",3,2,0.02)
print ("PairWise: Fuze...")
print (" ")
Bravo_BWF("PairWise:",3,2,0.88)
print ("Hiding: Fuze...")
print (" ")
Bravo_BWF("Hiding:",3,2,0.88)
print ("Packing: Fuze...")
print (" ")
Bravo_BWF("Packing:",3,2,0.1)
print ("Clashing: Fuze...")
print (" ")
Bravo_BWF("Clash:",0.5,2,0.07)
print ("Hiding: Fuze...")
print (" ")
Bravo_BWF("Hiding:",3,2,0.07)
print ("BackboneHbond: Fuze...")
print (" ")
Bravo_BWF("BackboneHbond:",3,2,0.07)
print ("Hiding: Fuze...")
print (" ")
Bravo_BWF("Hiding:",0.5,2,0.07)
print ("Density: Fuze...")
print (" ")
Bravo_BWF("Density:",0.5,2,0.07)
print ("Hiding: Fuze...")
print (" ")
Bravo_BWF("Hiding:",1.1,2,0.05)
print ("Hiding: Fuze...")
print (" ")
Bravo_BWF("Hiding:",3,2,0.05)
loop_gain = current.GetScore() - loop_starting_score -- gain from this loop
current_Score = current_Score + loop_gain -- this is the current score after the loop
print("Loop " .. loop_count .. " Gain: " .. loop_gain)
end
is_recent_best_better() -- check if recent best is better than current score
SaveBest2() -- save best score after each loop
save.Quicksave(1) -- save current state after each loop
qStab(2,1)
Check()
if (fuzing == true) then
if fuzt<=0 then
if score()>=(bestscore+fuzt) then
recentbest.Save()
SaveBest2() -- save best score
p("Fuzing...")
Fuzit()
if (current.GetScore()-startscore) <= 0.001 then
recentbest.Restore()
save.Quickload(2) --load initial state
elseif (current.GetScore()-startscore) >= 0.001 then
recentbest.Restore()
save.Quickload(1)
end
current_Score = current.GetScore()
end
else
if score()>=(bestscore+FF) then
p("Fuzing...")
recentbest.Save()
SaveBest2() -- save best score
Fuzit()
if (current.GetScore()-startscore) <= 0.001 then
recentbest.Restore()
save.Quickload(2) --load initial state
elseif (current.GetScore()-startscore) >= 0.001 then
recentbest.Restore()
save.Quickload(1)
end
current_Score = current.GetScore()
end
end
else
current_Score = current.GetScore()
is_recent_best_better() -- check if recent best is better than current score
SaveBest2() -- save best score
if current_Score < bestscore then
print("Current score is lower than best score. ")
print("Loading best state.")
recentbest.Restore() --restore best state
save.Quickload(1)
else
print("Current score is better than best score. ")
print("Saving & Loading current state.")
recentbest.Save() --save current state
save.Quicksave(1)
recentbest.Restore()
save.Quickload(1)
end
end
print("Current score: "..floor3(current.GetScore()).." Total gain: "..floor3(SaveBest2()))
print("Total QuakeR & BWF gain: "..floor3(SaveBest2()))
end
end
cival=behavior.GetClashImportance()
if cival<0.1 then cival = 1 end
function Seed() -- Rav3n_pl
seed=os.time()/math.abs(current.GetEnergyScore()) -- use time and energy score to generate a seed
seed=seed%0.001 -- ensure seed is a small number
seed=1/seed -- invert the seed to get a larger number
while seed<10000000 do seed=seed*10 end -- ensure seed is large enough
seed=seed-seed%1 -- remove decimal part
--p("Seed is: "..seed)
math.randomseed(seed) -- set the seed for random number generation
end
Seed() -- initialize the seed
function cut(x)
return x-x%0.000000001 -- cut at 9th decimal place
end
function setCI(ci)
return behavior.SetClashImportance(ci) -- set the clash importance to the given value
end
function ZLb()
if Combo==false then
if BiS then
p(" BiS ")
for i=1, 2 do
spacebands(nSegs/2)
pci=(math.random(cival*100)/100)
setCI(pci)
p(" Wiggle CI:", pci)
bandpull(0.2,1)
Delbands()
if not KBE then band.DisableAll() end
Test()
end
end--bis
end--combo
ZL=true
if Shock then
p(" Shock ")
for u=1, 2 do
spacebands(nSegs/2)
pci=(math.random(cival*100)/100)
setCI(pci)
p(" Wiggle CI:", pci)
if KB then band.EnableAll() end
wig('wb',5,1)
Delbands()
if not KBE then band.DisableAll() end
Test()
end
end
ZL=false
end
function BandAcross()
p(" TailGrab ")
for i=1, nSegs do
if structure.IsLocked(i)==false then first=i break end end
for u=nSegs, 1, -1 do
if structure.IsLocked(u)==false then last=u break end end
band.AddBetweenSegments(first,last)
bandage()
pci=(math.random(cival*100)/100)
setCI(pci)
p(" Wiggle CI:", pci)
bandpull(0.2,1.4)
Delbands()
if not KBE then band.DisableAll() end
Test()
RM=math.random(-100,100)
if RM>=0 then bloat=false
else bloat=true end
band.AddBetweenSegments(nSegs/2,first)
band.AddBetweenSegments(nSegs/2,last)
bandage()
pci=(math.random(cival*100)/100)
setCI(pci)
p(" Wiggle CI:", pci)
bandpull(0.2,1.4)
Delbands()
if not KBE then band.DisableAll() end
Test()
end
function Quake()
if Combo then
p(" Combo ")
for i=1, 4 do
RM=math.random(-100,100)
if RM>=0 then bloat=false
else bloat=true end
nrR=math.random(1, 30)
for u=1, nrR do
seg1=math.random(1,nSegs)
seg2=math.random(1,nSegs)
while structure.IsLocked(seg1) do seg1=math.random(1,nSegs) end
while structure.IsLocked(seg2) do seg2=math.random(1,nSegs) end
while seg1==seg2 do
seg1=math.random(1,nSegs)
end
band.AddBetweenSegments(seg1,seg2)
end
bandage()
Qbands=band.GetCount()
spacebands(10)
pci=(math.random(cival*100)/100)
setCI(pci)
p(" Wiggle CI:", pci)
bandpull(0.2,2)
Delbands()
if not KBE then band.DisableAll() end
Test()
end
else
p(" Quake ")
for i=1, 2 do
RM=math.random(-100,100)
if RM>=0 then bloat=false
else bloat=true end
nrR=math.random(1, 30)
for u=1, nrR do
seg1=math.random(1,nSegs)
seg2=math.random(1,nSegs)
while structure.IsLocked(seg1) do seg1=math.random(1,nSegs) end
while structure.IsLocked(seg2) do seg2=math.random(1,nSegs) end
while seg1==seg2 do
seg1=math.random(1,nSegs)
end
band.AddBetweenSegments(seg1,seg2)
end
bandage()
pci=(math.random(cival*100)/100)
setCI(pci)
p(" Wiggle CI:", pci)
bandpull(0.2,2)
Delbands()
if not KBE then band.DisableAll() end
Test()
end --quake
end --combo
end
function GetParameters ()
if band.GetCount()~=0 then Bands=true end
local dlog = dialog.CreateDialog ( "QuakeR & BWF v2.5.9" )
dlog.iterationsBF = dialog.AddSlider ( "BandFuze. iter: " , qLoops3 , 0 , segCnt/2 , 0 )
dlog.QandBWF = dialog.AddLabel("QuakeR & BWF iterations (Loops)")
dlog.iterations = dialog.AddSlider ( "normal iter: " , qLoops , 0 , segCnt/2 , 0 )
dlog.iterationsr = dialog.AddSlider ( "reverse iter: " , qLoops2 , 0 , segCnt/2 , 0 )
dlog.maxci=dialog.AddSlider("MaxCI:",cival,0.1,1,2)
dlog.Qq=dialog.AddCheckbox(" Quake.",true)
dlog.Bs=dialog.AddCheckbox(" BiS.",true)
dlog.Cmb=dialog.AddCheckbox(" Combine Quake and BiS.",false)
dlog.Sk=dialog.AddCheckbox(" Shock.",true)
dlog.Tg=dialog.AddCheckbox(" Tailgrab.",true)
dlog.fuztf=dialog.AddCheckbox("do (long and slow) Fuzing.",false)
dlog.fu = dialog.AddLabel("Fuzing threshold (negative value is gain)")
dlog.fuz = dialog.AddSlider("", -50, -100, 100, 1)
if Bands then
dlog.KB=dialog.AddCheckbox("Keep original bands", true)
dlog.KBE=dialog.AddCheckbox("Keep enabled always",false)
dlog.KBSTR=dialog.AddCheckbox("Keep original strength and goal length", true)
end
dlog.local_shake = dialog.AddButton ( "Shake!" , 1)
dlog.local_no_shake = dialog.AddButton ( "No Shake!" , 2 )
dlog.cancel = dialog.AddButton ( "Cancel" , 0 )
local choice = dialog.Show ( dlog )
if (choice > 1) then
qLoops3 = dlog.iterationsBF.value
qLoops = dlog.iterations.value
qLoops2 = dlog.iterationsr.value
QQ=dlog.Qq.value
BiS=dlog.Bs.value
Shock=dlog.Sk.value
TG=dlog.Tg.value
Combo=dlog.Cmb.value
fuzing=dlog.fuztf.value
fuzt=dlog.fuz.value
cival=dlog.maxci.value
if Bands then
KB=dlog.KB.value
KBE=dlog.KBE.value
KBSTR=dlog.KBSTR.value
end
if fuzt<=0 then
FF = (-1*fuzt)
end
local_shake = false
elseif (choice > 0) then
qLoops3 = dlog.iterationsBF.value
qLoops = dlog.iterations.value
qLoops2 = dlog.iterationsr.value
QQ=dlog.Qq.value
BiS=dlog.Bs.value
Shock=dlog.Sk.value
TG=dlog.Tg.value
Combo=dlog.Cmb.value
fuzing=dlog.fuztf.value
fuzt=dlog.fuz.value
cival=dlog.maxci.value
if Bands then
KB=dlog.KB.value
KBE=dlog.KBE.value
KBSTR=dlog.KBSTR.value
end
if fuzt<=0 then
FF = (-1*fuzt)
end
else
print("Dialog cancelled")
return false
end
return choice, qLoops3, qLoops, qLoops2, QQ, BiS, Shock, TG, Combo, fuzing, fuzt, FF, cival, local_shake, KB, KBE, KBSTR
end
function main ()
if ( GetParameters () == false ) then
return 1 -- graceful exit
end
undo.SetUndo(false)
print("--------")
report_time(start_clock,start_time)
print("--------")
if not KB then band.DeleteAll()
oldbands=0
end
n_residues = structure.GetCount ()
behavior.SetClashImportance ( 1 )
InitializePuzzleState( )
print("wait! initializing...")
residues_range ()
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
local idx_starts = loop_starts[ 1 ]
local idx_ends = loop_ends[ 1 ]
local loop_count = qLoops3
for x=1, qLoops3 do
save.Quicksave(1)
save.Quicksave(2)
startscore = score()
bestscore = startscore
p("BandFuze. starts: " ..loop_count.." iterations")
p(" Startscore: "..cut(score()))
p(" Best score in quicksave slot 1, starting pose in slot 2 ")
p(" maxCI = "..cival)
if QQ or Combo then Quake() end
ZLb()
if TG then BandAcross() end
save.Quickload(1)
loop_count = loop_count-1
end
if qLoops3==0 then p("skipped BandFuze.")
else
Result() -- final result after BandFuze iterations
end
print("--------")
report_time(start_clock,start_time)
print("--------")
QuakeR(idx_starts, idx_ends, qLoops,false)
print("reverse QuakeR & BWF starts:")
QuakeR(idx_ends, idx_starts, qLoops2,true)
print("--------")
report_time(start_clock,start_time)
print("--------")
CleanUp()
end
function CleanUp(err) -- called on error or normal exit
if err == nil then err = "Normal exit" end
undo.SetUndo(true)
if EndCalled then return end -- no infinite recursion please
EndCalled = true
if err:find("Cancelled") ~= nil then
print ("QuakeR & BWF Cancelled")
Delbands()
behavior.SetClashImportance(1)
Behavior_reset()
if not KBE then band.DisableAll() end
if (current.GetScore()-startscore) <= 0.001 then
save.Quickload(2) --load initial state
recentbest.Restore()
elseif (current.GetScore()-startscore) >= 0.001 then
save.Quickload(1)
recentbest.Restore()
end
save.LoadSecondaryStructure()
-- Re-enable filters
behavior.SetFiltersDisabled(false)
else
print(err)
end
behavior.SetClashImportance(1)
Behavior_reset()
Delbands()
if not KBE then band.DisableAll() end
if (current.GetScore()-startscore) <= 0.001 then
save.Quickload(2) --load initial state
recentbest.Restore()
elseif (current.GetScore()-startscore) >= 0.001 then
save.Quickload(1)
recentbest.Restore()
end
-- Re-enable filters
behavior.SetFiltersDisabled(false)
save.LoadSecondaryStructure()
print("Total QuakeR & BWF gain: "..floor3(SaveBest()))
end
--- VVVVVVVVVV OPTIONS
normal=(current.GetExplorationMultiplier()==0)
qLoops=1 --number of passes
qLoops2=1 -- <<<OVER THERE! do more! much more!
qLoops3=1 -- BandFuze iterations value
minBS=0.3 --starting minimum bands strength
maxBS=1.0 --maximum band strength
--minimum percentage loss when pulling.
pullingCI=1.0 --clash importance while pulling
fastQstab=false --false for stabilize (faster)
local_shake=true --true for local shake
xpcall(main,CleanUp)