Icon representing a recipe

Recipe: QuakeR & BWF v1.0 with mutate

created by ZeroLeak7

Profile


Name
QuakeR & BWF v1.0 with mutate
ID
109059
Shared with
Public
Parent
QuakeR v5.0 with mutate
Children
Created on
May 22, 2025 at 12:58 PM UTC
Updated on
May 22, 2025 at 17:17 PM UTC
Description

QuakeR & BWF v1.0 with mutate + better shake and wiggle ci in Fuze + GUI

Best for


Code


--QuakeR - a randomized Quake recipeTitle='QuakeR & BWF v1.0 ' --v1.0 combined two recpies QuakeR v5.0 with mutate -- updated and changed some functions! -- future plans more settings in the gui -- created 2025-05-22 ZeroLeak7 --[[ 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 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 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 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 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 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 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 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 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 brute_force() while (global_clashing_importance > 0)do print("global CI: " .. global_clashing_importance) iteration_variable= 25 while (iteration_variable > 0) do for importance = 3, 0, -0.5 do print("Testing Importance: "..importance.. " iteration: ".. iteration_variable .. " CI: " ..global_clashing_importance) Importance = importance SidechainsHbondFuze() BackboneHbondFuze() PairWiseFuze() PackingFuze() HidingFuze() DensityFuze() ClashingFuze() save.Quickload(Best_Score_slot_num) --best score saved in quick save 3 end for importance = 1.1, .9, -0.01 do print("Testing Importance: "..importance.. " iteration: ".. iteration_variable .. " CI: " ..global_clashing_importance) Importance = importance SidechainsHbondFuze() BackboneHbondFuze() PairWiseFuze() PackingFuze() HidingFuze() DensityFuze() ClashingFuze() save.Quickload(Best_Score_slot_num) --best score saved in quick save 3 end if (iteration_variable > 5) then iteration_variable = iteration_variable-5 else iteration_variable = iteration_variable-1 end if (global_clashing_importance > .16) then global_clashing_importance = global_clashing_importance-.15 else global_clashing_importance = global_clashing_importance-.01 end end end print("Best Score: ".. BestScore) print("Total Gain: ".. (BestScore-StartScore)) 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 function floor3(x)--cut at 3rd decimal place return tostring(x-x%0.001) end function Score() local s=0 if normal==true then s=current.GetEnergyScore() else for i=1,segCnt do s=s+current.GetSegmentEnergyScore(i) end end return s end function ScoreRB() local s=0 if normal==true then s=recentbest.GetEnergyScore() else for i=1,segCnt do s=s+recentbest.GetSegmentEnergyScore(i) end end return s end function SaveBest() local g=Score()-bestScore if g>0 then print("Gained another "..floor3(g).." points.") bestScore=Score() save.Quicksave(4) -- under normal conditions retain pose even as recording improvement recentbest.Restore() save.Quicksave(3) save.Quickload(4) end return Score()-bestScore end function Wiggle(how, iters, minppi) --score conditioned recursive wiggle/shake if how==nil then how="wa" end if iters==nil then iters=6 end if minppi==nil then minppi=0.1 end if iters>0 then iters=iters-1 local sp=Score() if how == "s" then structure.ShakeSidechainsAll(1) elseif how == "wb" then structure.WiggleAll(2,true,false) elseif how == "ws" then structure.WiggleAll(2,false,true) elseif how == "wa" then structure.WiggleAll(2,true,true) end if Score()-sp > minppi then return Wiggle(how, iters, minppi) end end end function qStab() behavior.SetClashImportance(0.21) structure.MutateSidechainsSelected(1) Wiggle("s",1) if fastQstab==false then behavior.SetClashImportance(0.4) Wiggle("wa",1) behavior.SetClashImportance(1) Wiggle("s",1) end behavior.SetClashImportance(1) Wiggle() return SaveBest() end function Fuze1(ci1,ci2) behavior.SetClashImportance(ci1) Wiggle("s",1) behavior.SetClashImportance(ci2) Wiggle("wa",1) end function Fuze2(ci1,ci2) behavior.SetClashImportance(ci1) Wiggle("wa",1) behavior.SetClashImportance(1) Wiggle("wa",1) behavior.SetClashImportance(ci2) Wiggle("wa",1) end function FuzeEnd() behavior.SetClashImportance(1) Wiggle("wa",1) Wiggle("s",1) behavior.SetClashImportance(0.9) Wiggle() behavior.SetClashImportance(1) Wiggle("wa",1) SaveBest() end function reFuze(scr) local s=ScoreRB() if s<scr then recentbest.Restore() else scr=s end return scr end function Fuze() local scr=Score() Fuze1(1,0.6) FuzeEnd() scr=reFuze(scr) Fuze2(1,1) SaveBest() scr=reFuze(scr) Fuze1(1,0.9) SaveBest() scr=reFuze(scr) Fuze2(1,1) FuzeEnd() scr=reFuze(scr) Fuze1(1,1) SaveBest() 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 QuakeR() math.randomseed(os.time()) math.random() math.random() math.random() calcBandAtom() --freeze.UnfreezeAll() selection.SelectAll() StartingScore=Score() bestScore=StartingScore recentbest.Save() save.Quicksave(3) print("Starting "..recipeTitle..tostring(qLoops).." passes. Start score: "..floor3(StartingScore)) for x=1, qLoops do print("Pass "..tostring(x).." of "..tostring(qLoops)) local start=math.floor(math.random(segCnt/10)) --first band somewhere in first 10% of protein local len=math.floor(math.random(segCnt/2-5))+10 local step=math.floor(math.random(segCnt/2-5))+10 local loss=math.abs(math.floor(Score()*maxLoss/100)) band.DeleteAll() print("Bands from segment "..tostring(start).." of length "..tostring(len) .." every "..tostring(step).." segments.") print("Pulling until loss of "..tostring(loss).." points.") for x=start,segCnt, step do for y=start+len, segCnt, step do band.AddBetweenSegments(x,y,bandAtom[x],bandAtom[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) gain=SaveBest() if gain > 0 then recentbest.Restore() end until gain<=0 if gain<-loss then break end end band.DeleteAll() behavior.SetClashImportance(1) recentbest.Save() --after pulling print("Stabilizing...") loop_starting_score = current.GetScore() loop_gain = 1.1 loop_count = 0 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: ".. loop_starting_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 ("Density: Fuze...") print (" ") Bravo_BWF("Density:",3,25,0.07) print ("BackboneHbond: Fuze...") print (" ") Bravo_BWF("BackboneHbond:",3,25,1) print ("PairWise: Fuze...") print (" ") Bravo_BWF("PairWise:",3,25,1) print ("Hiding: Fuze...") print (" ") Bravo_BWF("Hiding:",3,25,1) print ("Packing: Fuze...") print (" ") Bravo_BWF("Packing:",3,3,0.1) print ("Clashing: Fuze...") print (" ") Bravo_BWF("Clash:",0.5,25,0.07) loop_gain = current.GetScore() - loop_starting_score print("Loop " .. loop_count .. " Gain: " .. loop_gain) end if qStab() > doFuze then print("Starting End Round: Fuzing....") Fuze() end end SaveBest() save.Quickload(3) --load best state print("Current score: "..floor3(Score()).." Total gain: "..floor3(Score()-StartingScore)) print("Total QuakeR gain: "..floor3(Score()-StartingScore)) return true end function GetParameters () local dlog = dialog.CreateDialog ( "QuakeR & BWF v1.0 with mutate" ) dlog.iterations = dialog.AddSlider ( "iterations: " , qLoops , 1 , 1000 , 0 ) dlog.ok = dialog.AddButton ( "OK" , 1 ) dlog.cancel = dialog.AddButton ( "Cancel" , 0 ) if ( dialog.Show ( dlog ) > 0 ) then qLoops = dlog.iterations.value return true else return false end end function main () if ( GetParameters () == false ) then return -- graceful exit end QuakeR() cleanUp() end function CleanUp(err) if err:find('Cancelled')~=nil then print "QuakeR & BWF Cancelled" else print(err) end behavior.SetClashImportance(1) -- band.DeleteAll() SaveBest() save.Quickload(3) print("Total QuakeR & BWF gain: "..floor3(bestScore-StartingScore)) end segCnt=structure.GetCount() while structure.GetSecondaryStructure(segCnt)=="M" do segCnt=segCnt-1 end --- VVVVVVVVVV OPTIONS normal=(current.GetExplorationMultiplier()==0) qLoops=50 -- <<<OVER THERE! do more! much more! minBS=0.3 --starting minimum bands strength maxBS=1.0 --maximum band strength maxLoss=1 --minimum percentage loss when pulling. ie 5% of 10000 is 500pts pullingCI=1.0 --clash importance while pulling fastQstab=false --true for 1s1w as stabilize (faster) doFuze=-10 --run fuze when score after qstabilize is close to best. xpcall(main,CleanUp)

Comments


bravosk8erboy Lv 1

fun fact: that the Bravo_BWF recipe used here is actually V1.1 with different Behavior Importance values. also, it was built off of a private recipe based on Bruno Kestemont's Group Recipe (Go Science) called Behaviour wiggle fuze v1 (public recipe: Behaviour wiggle fuze at https://fold.it/recipes/108109)

you ended up with some sloppy code from my self that never calls the function brute_force() lol. this brute force recipe is how i determined the original values for Bravo_BWF() function.

Curious how you end up with the values listed below? the original values were brute force determine on a puzzle that didn't have Electron density clouds, plus a couple extra that were added because they seemed to help. (discovered from the glitch in the orginal Bravo_BWF V1 recipe.)

Bravo_BWF("Density:",3,25,0.07)
Bravo_BWF("BackboneHbond:",3,25,1)
Bravo_BWF("PairWise:",3,25,1)
Bravo_BWF("Hiding:",3,25,1)
Bravo_BWF("Packing:",3,3,0.1)
Bravo_BWF("Clash:",0.5,25,0.07)

ZeroLeak7 Lv 1

I can add the brute_force() function in the next version v1.1 and some GUI options, optimizations coming in Future Versions! greetings from ZeroLeak7

ZeroLeak7 Lv 1

Curious how you end up with the values listed below? I tested it and it gave me points the special values, in the next version I will put everything in the gui as options! @bravosk8erboy

bravosk8erboy Lv 1

no need to add the brute_force, it took days to run and only added minimal gains. i was saying it can be deleted lol.