Icon representing a recipe

Recipe: Bravo BWF v1.1

created by bravosk8erboy

Profile


Name
Bravo BWF v1.1
ID
108986
Shared with
Public
Parent
Bravo BWF v1
Children
Created on
March 07, 2025 at 04:15 AM UTC
Updated on
March 07, 2025 at 05:06 AM UTC
Description

Behavior Wiggle Fuse - check recipe score modding

Best for


Code


-- 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: " save.Quickload(Best_Score_slot_num) --best score saved in quick save 3 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: " save.Quickload(Best_Score_slot_num) --best score saved in quick save 3 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: " save.Quickload(Best_Score_slot_num) --best score saved in quick save 3 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: " save.Quickload(Best_Score_slot_num) --best score saved in quick save 3 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: " save.Quickload(Best_Score_slot_num) --best score saved in quick save 3 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: " save.Quickload(Best_Score_slot_num) --best score saved in quick save 3 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: " save.Quickload(Best_Score_slot_num) --best score saved in quick save 3 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 loop_starting_score = current.GetScore() loop_gain = 1.1 loop_count = 0 function main() print("Starting Score: ".. StartScore) while (loop_gain>0.1) do -- recent best tends to make .01 gains forever. want to avoid that slowness. 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) Bravo_BWF("BackboneHbond:",3,25,1) Bravo_BWF("PairWise:",3,25,1) Bravo_BWF("Hiding:",3,25,1) Bravo_BWF("BackboneHbond:",2.5,25,1) Bravo_BWF("PairWise:",2,25,1) Bravo_BWF("Hiding:",0.5,25,1) Bravo_BWF("Packing:",3,3,0.1) Bravo_BWF("Packing:",2,3,0.1) Bravo_BWF("Packing:",1.5,3,0.1) Bravo_BWF("Hiding:",3,25,0.07) Bravo_BWF("Density:",3,25,0.07) Bravo_BWF("Hiding:",0.5,25,0.07) Bravo_BWF("Density:",0.5,25,0.07) Bravo_BWF("Hiding:",1.1,15,0.05) Bravo_BWF("Hiding:",3,15,0.05) loop_gain = current.GetScore() - loop_starting_score print("Loop " .. loop_count .. " Gain: " .. loop_gain) end cleanup() end function cleanup(error_string) print( "" ) if error_string ~= nil then if string.find( error_string, "Cancelled" ) then print( "User cancel" ) else print( error_string ) end end Behavior_reset() save.Quickload(Best_Score_slot_num) print("Best Score: ".. BestScore) print("Total Gain: ".. (BestScore-StartScore)) return end xpcall(main,cleanup)

Comments


bravosk8erboy Lv 1

works best on high wiggle power.
make sure to check/ enable "recipe score modding"
it will repeat the loop if any gain is made otherwise it stops.
often the later loops can have a bigger gain then previous ones so i recommend always letting the recipe come to a finish.