Icon representing a recipe

Recipe: QuakeR & BWF v2.5

created by ZeroLeak7

Profile


Name
QuakeR & BWF v2.5
ID
109070
Shared with
Public
Parent
QuakeR & BWF v2.0
Children
Created on
June 05, 2025 at 00:43 AM UTC
Updated on
June 09, 2025 at 18:54 PM UTC
Description

QuakeR & BWF v2.5 + 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 ' --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 --[[ 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 = 3 save.Quicksave(Best_Score_slot_num) --save starting score as best score saved in quick save 3 BestScore = current.GetScore() StartScore = BestScore BestBonus = filter.GetBonusTotal() StartBonus = BestBonus Importance = 3 global_clashing_importance = 1 behavior_string = "starting" Behavior_value = 1 print("Make sure RECIPE SCORE MODDING is checked before running") 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 " .. g.. " Score: "..ss.. " Bonus: "..tb) print("Total Gain: ".. (ss-StartScore)) --end BestScore= ss BestBonus = tb save.Quicksave(Best_Score_slot_num) --best score saved in quick save 3 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() save.Quicksave(93) recentbest.Save() sci=(math.random(cival*100)/100) setCI(sci) if (local_shake == true) then p(" Shake CI:", sci) wig('s') Check() end print ("Density: Fuze...") print (" ") Bravo_BWF("Density:",3,2,0.07) print (" ") setCI(cival) wig() Check() setCI(cival/2) wig("wa",5) Check() setCI(cival) wig() Check() qStab(2,1) save.Quickload(93) setCI(cival) wig() Check() setCI(cival/2) wig("wa",5) Check() setCI(cival) wig() Check() recentbest.Restore() Check() if fuzt>=0 then if score()>(bestscore-fuzt) then Fuzit() end else if score()>=(bestscore+FF) then Fuzit() 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 floor3(x)--cut at 3rd decimal place return x-x%0.001 end function rounding2(x)--cut at 2nd decimal place return x-x%0.01 end function internalGetScore( wantRB ) if wantRB == nil then wantRB = false end local s=0.0 if not USENORMALSCORE then if wantRB then s = recentbest.GetEnergyScore( ) else s=current.GetEnergyScore( ) end else if wantRB then s = recentbest.GetScore( ) else s=current.GetScore( ) end end return s end function getScore( ) behavior.SetFiltersDisabled(false) behavior.SetFiltersDisabled(true) return internalGetScore( false ) end function getRBScore( ) behavior.SetFiltersDisabled(false) behavior.SetFiltersDisabled(true) return internalGetScore( true ) end function score() return current.GetScore() end function SaveBest2() local score = getScore() if score > current.GetScore() then print("Gained another "..floor3(score-current.GetScore()).." points. new Score: "..floor3(score)) score=current.GetScore() save.Quicksave(4) recentbest.Restore() save.Quicksave(3) save.Quickload(4) end return getScore()-current.GetScore() end function InitializePuzzleState() --function by ZeroLeak7 InitialScore = getRBScore() 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).." hours "..math.floor(timeshift).." minutes") end function Wiggle(how, iters, minppi, shakeiters) --score conditioned recursive wiggle/shake 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=getScore() if how == "s" then structure.ShakeSidechainsAll(shakeiters) return 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 getScore()-sp > minppi then return Wiggle(how, iters, minppi, shakeiters) end end end function wig(how, it, iters, minppi) 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 if AllAla==false then structure.ShakeSidechainsAll(1) end 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) Wiggle("wa",iters) if fastQstab==false then behavior.SetClashImportance(0.02) Wiggle("wa",iters) behavior.SetClashImportance(1) Wiggle("wa",iters*12) end behavior.SetClashImportance(1) Wiggle("wa",iters) if (local_shake == true) then print("Shake!") Wiggle("s",shakeiters) end closetobest = bestScore-current.GetScore() return SaveBest() end function reFuze(scr) local s=getRBScore() 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.SetSidechainHBondImportance(3) behavior.SetBackboneHBondImportance(3) behavior.SetDensityImportance(3) behavior.SetClashImportance(ci1) Wiggle("wa",iters+22) Behavior_reset() Wiggle("wa",iters+22) behavior.SetClashImportance(ci2) Wiggle("wa",iters+22) if (local_shake == true) then print("Shake!") Wiggle("s",shakeiters) end end function Fuze2(ci1, ci2, iters) iteration_variable = iters*2 behavior.SetClashImportance(ci1) Wiggle("wa",iters) behavior.SetClashImportance(0.07) Wiggle("wa",iters) behavior.SetClashImportance(ci2) Wiggle("wa",iters) end function FuzeEnd(iters, shakeiters) iteration_variable = iters*2 print("FuzeEnd") behavior.SetClashImportance(1) Wiggle("wa",iters) behavior.SetClashImportance(0.07) Wiggle("wa",iters) behavior.SetClashImportance(1) Wiggle("wa",iters) if (local_shake == true) then print("Shake!") Wiggle("s",shakeiters) end SaveBest() 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) p(" ",cut(gain),"pts.") else gain = 0 end end function Fuze() local scr=getScore() print("Fuze1") Fuze1(0.01, 0.88, 3, 1) SaveBest() FuzeEnd(2, 1) print("reFuze") qStab(2,1) scr=reFuze(scr) print("Fuze2") Fuze2(0.3,1,2) SaveBest() print("reFuze") scr=reFuze(scr) print("Fuze1") Fuze1(0.05, 1, 2, 1) SaveBest() 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) SaveBest() 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 calcBandAtom() bandAtom={} for x = 1,segCnt do if (structure.GetAminoAcid(x) == 'g') or not structure.IsHydrophobic(x) then bandAtom[x] = 2 -- center for Glycine and Hydophiles elseif x == segCnt then bandAtom[x] = 6 -- beta carbon for terminal segment else bandAtom[x] = 5 -- beta carbon end end end function End(errmsg) if done then return end done=true if string.find(errmsg,"Cancelled") then p("") p(" User cancel.") Result() p("") else Result() p("") p(errmsg) end return errmsg 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 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',5,1,500) 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 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)) band.DeleteAll() if(rev==true) then print("----------------------------------------------------------------------------") print("Bands from segment "..tostring(ix+step2)) print(" of length "..tostring(step2*(-1)).." every "..tostring(step2).." segments.") print("----------------------------------------------------------------------------") print("Pulling..") for x=ix,iy, step2 do for y=ix, iy, step2 do band.AddBetweenSegments(x,y) end end behavior.SetClashImportance(pullingCI) recentbest.Save() local gain for str=minBS,maxBS,0.07 do--search enough band strength to move bandstr(str) repeat structure.WiggleAll(1,true,false) maxLoss = current.GetScore() local loss=math.abs(math.floor(bestScore - maxLoss)) print("Pulling until loss of "..tostring(loss).." points.") gain=SaveBest( ) if gain > 0 then recentbest.Restore() end until gain<=0 break end else print("----------------------------------------------------------------------------") print("Bands from segment "..tostring(start)) print(" of length "..tostring(step).." every "..tostring(step).." segments.") print("----------------------------------------------------------------------------") print("Pulling..") for x=start,iy, step do for y=start+len, iy, step do band.AddBetweenSegments(x,y) end end behavior.SetClashImportance(pullingCI) recentbest.Save() local gain for str=minBS,maxBS,0.07 do--search enough band strength to move bandstr(str) repeat structure.WiggleAll(1,true,false) maxLoss = current.GetScore() local loss=math.abs(math.floor(bestScore - maxLoss)) print("Pulling until loss of "..tostring(loss).." points.") gain=SaveBest() if gain > 0 then recentbest.Restore() end until gain<=0 break end end return current.GetScore() end function QuakeR(ix,iy,ql,rev) math.randomseed(os.time()) math.random() math.random() math.random() calcBandAtom() -- Disable filters behavior.SetFiltersDisabled(true) selection.SelectAll() StartingScore=getScore() bestScore=StartingScore recentbest.Save() save.Quicksave(5) print("----------------------------------------------------------------------------") print("Starting "..recipeTitle..tostring(ql).." passes.") print("----------------------------------------------------------------------------") print("Start score: "..floor3(StartingScore)) for x=1, ql do PullingQuakeR(x,ix,iy,ql,rev) band.DeleteAll() behavior.SetClashImportance(1) recentbest.Save() --after pulling print("Stabilizing...") qStab(2,1) if fuzt>=0 then if score()>(bestScore-fuzt) then print("Fuzing...") Fuzit() print("end of Fuzing!...") end else if score()>=(bestScore+FF) then print("Fuzing...") Fuzit() print("end of Fuzing!...") end end is_recent_best_better() SaveBest() save.Quicksave(3) gain=SaveBest() if gain > 0 then recentbest.Restore() end loop_starting_score = current.GetScore() loop_gain = 1.1 loop_count = 0 current_Score = current.GetScore() while (loop_gain > 0.1) 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 current_Score = current_Score + loop_gain print("Loop " .. loop_count .. " Gain: " .. loop_gain) end is_recent_best_better() SaveBest() save.Quicksave(3) qStab(2,1) if fuzt>=0 then if score()>(bestScore-fuzt) then print("Starting End Round: Fuzing...") Fuzit() end else if score()>=(bestScore+FF) then print("Starting End Round: Fuzing...") Fuzit() end end is_recent_best_better() SaveBest() if current_Score < bestScore then save.Quickload(5) --load best state end print("Current score: "..floor3(getScore()).." Total gain: "..floor3(getScore()-StartingScore)) print("Total QuakeR & BWF gain: "..floor3(getScore()-StartingScore)) end end cival=behavior.GetClashImportance() if cival<0.1 then cival = 1 end function Seed() -- Rav3n_pl seed=os.time()/math.abs(current.GetEnergyScore()) seed=seed%0.001 seed=1/seed while seed<10000000 do seed=seed*10 end seed=seed-seed%1 --p("Seed is: "..seed) math.randomseed(seed) end Seed() function cut(x) return x-x%0.000000001 end function setCI(ci) return behavior.SetClashImportance(ci) 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, 19) 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, 19) 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" ) dlog.iterations = dialog.AddSlider ( "normal iter: " , qLoops , 0 , 1000 , 0 ) dlog.iterationsr = dialog.AddSlider ( "reverse iter: " , qLoops2 , 0 , 1000 , 0 ) dlog.iterationsBF = dialog.AddSlider ( "BandFuze. iter: " , qLoops3 , 0 , 250 , 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.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 qLoops = dlog.iterations.value qLoops2 = dlog.iterationsr.value qLoops3 = dlog.iterationsBF.value QQ=dlog.Qq.value BiS=dlog.Bs.value Shock=dlog.Sk.value TG=dlog.Tg.value Combo=dlog.Cmb.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 qLoops = dlog.iterations.value qLoops2 = dlog.iterationsr.value qLoops3 = dlog.iterationsBF.value QQ=dlog.Qq.value BiS=dlog.Bs.value Shock=dlog.Sk.value TG=dlog.Tg.value Combo=dlog.Cmb.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") end return choice, qLoops, qLoops2, qLoops3, QQ, BiS, Shock, TG, Combo, FF, cival, local_shake, KB, KBE, KBSTR end function main () if ( GetParameters () == false ) then return -- graceful exit end 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 ] StartingScore=getScore() bestScore=StartingScore save.Quicksave(1) save.Quicksave(2) startscore = score() bestscore = startscore for x=1, qLoops3 do p("BandFuze. starts: ") 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) end QuakeR(idx_starts, idx_ends, qLoops,false) print("reverse QuakeR & BWF starts:") QuakeR(idx_ends, idx_starts, qLoops2,true) CleanUp() end function CleanUp(err) undo.SetUndo(true) if EndCalled then return end -- no infinite recursion please EndCalled = true if err:find("Cancelled") ~= nil then print "QuakeR & BWF Cancelled" behavior.SetClashImportance(1) Behavior_reset() band.DeleteAll() else print(err) end behavior.SetClashImportance(1) Behavior_reset() Delbands() SaveBest() recentbest.Restore() -- Re-enable filters behavior.SetFiltersDisabled(false) print("Total QuakeR & BWF gain: " .. floor3(current.BestScore() - StartingScore)) end segCnt=structure.GetCount() while structure.GetSecondaryStructure(segCnt)=="M" do segCnt=segCnt-1 end --- VVVVVVVVVV OPTIONS normal=(current.GetExplorationMultiplier()==0) qLoops=5 --number of passes qLoops2=5 -- <<<OVER THERE! do more! much more! qLoops3=5 -- 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)

Comments