Icon representing a recipe

Recipe: Precise Wiggle For Slow Filters V1inV2

created by Vredeman

Profile


Name
Precise Wiggle For Slow Filters V1inV2
ID
100709
Shared with
Public
Parent
None
Children
None
Created on
February 21, 2015 at 15:45 PM UTC
Updated on
February 21, 2015 at 15:45 PM UTC
Description

Added Bitspawns and Rav's

Best for


Code


--Precise LWS by rav3n_pl --searches and wiggles worst segments --options at end of script -- "lua v1 in v2" library by rav3n_pl --just add it in front of your v1 code and use v2 and v1 code in v2 scripts :) -- print(arg1[,...,argN]) no change :) function are_conditions_met() return current.AreConditionsMet() end function band_add_segment_segment(sgi1, sgi2) band.AddBetweenSegments(sgi1, sgi2) end function band_delete(bndIdx) if bndIdx~= nil then band.Delete(bndIdx) else band.DeleteAll() end end function band_disable(bndIdx) if bndIdx~=nil then band.Disable(bndIdx) else band.DisableAll() end end function band_enable(bndIdx) if bndIdx~=nil then band.Enable(bndIdx) else band.EnableAll() end end function band_set_length(bndIdx, len) band.SetGoalLength(bndIdx, len) end function band_set_strength(bndIdx, str) band.SetStrength(bndIdx, str) end function get_band_count() return band.GetCount() end function deselect_all() selection.DeselectAll() end function deselect_index(sgn) selection.Deselect(sgn) end function select_all() selection.SelectAll() end function select_index(sgn) selection.Select(sgn) end function select_index_range(sg1,sg2) selection.SelectRange(sg1,sg2) end function do_freeze(bbone,schain) freeze.FreezeSelected(bbone,schain) end function do_unfreeze_all() freeze.UnfreezeAll() end function do_global_wiggle_all(iters) structure.WiggleAll(iters,true,true) end function do_global_wiggle_backbone(iters) structure.WiggleAll(iters, true,false) end function do_global_wiggle_sidechains(iters) structure.WiggleAll(iters,false,true) end function do_local_rebuild(iters) structure.RebuildSelected(iters) end function do_local_wiggle(iters) structure.LocalWiggleSelected(iters,true,true) end function do_mutate(iters) structure.MutateSidechainsSelected(iters) end function do_shake(iters) structure.ShakeSidechainsSelected(iters) end function do_sidechain_snap(sgn, snap) rotamer.SetRotamer(sgn, snap) end function get_sidechain_snap_count(sgn) return rotamer.GetCount(sgn) end function load_structure() save.LoadSecondaryStructure() end function save_structure() save.SaveSecondaryStructure() end function quickload(slot) save.Quickload(slot) end function quicksave(slot) save.Quicksave(slot) end function get_exploration_score() return current.GetExplorationMultiplier() end function get_ranked_score() return current.GetScore() end function get_score() return current.GetEnergyScore() end function get_segment_distance(sg1,sg2) return structure.GetDistance(sg1,sg2) end function get_aa(sn) return structure.GetAminoAcid(sn) end function get_segment_count() return structure.GetCount() end function get_ss(sn) return structure.GetSecondaryStructure(sn) end function is_hydrophobic(sn) return structure.IsHydrophobic(sn) end function replace_aa(aa) for i=1,structure.GetCount() do if selection.IsSelected(i) then structure.SetAminoAcid(i, aa) end end end function replace_ss(ss) for i=1,structure.GetCount() do if selection.IsSelected(i) then structure.SetSecondaryStructure(i,ss) end end end function get_segment_score(sg) return current.GetSegmentEnergyScore(sg) end function get_segment_score_part(score_part,sg) return current.GetSegmentEnergySubscore(sg,score_part) end function reset_puzzle() puzzle.StartOver() end function restore_abs_best() absolutebest.Restore() end function restore_credit_best() creditbest.Restore() end function reset_recent_best() recentbest.Save() end function restore_recent_best() recentbest.Restore() end function set_behavior_clash_importance(ci) behavior.SetClashImportance(ci) end -- end of library -- function to copy class/table function CopyTable(orig) local copy = {} for orig_key, orig_value in pairs(orig) do copy[orig_key] = orig_value end return copy end -- functions for filters function FiltersOn() if behavior.GetSlowFiltersDisabled() then behavior.SetSlowFiltersDisabled(false) end end function FiltersOff() if behavior.GetSlowFiltersDisabled()==false then behavior.SetSlowFiltersDisabled(true) end end -- function to overload a funtion function mutFunction(func) local currentfunc = func local function mutate(func, newfunc) local lastfunc = currentfunc currentfunc = function(...) return newfunc(lastfunc, ...) end end local wrapper = function(...) return currentfunc(...) end return wrapper, mutate end -- function to overload a class -- to do: set the name of function classes_copied = 0 myclcp = {} function MutClass(cl, filters) classes_copied = classes_copied+1 myclcp[classes_copied] = CopyTable(cl) local mycl =myclcp[classes_copied] for orig_key, orig_value in pairs(cl) do myfunc, mutate = mutFunction(mycl[orig_key]) if filters==true then mutate(myfunc, function(...) FiltersOn() if table.getn(arg)>1 then -- first arg is self (function pointer), we pack from second argument local arguments = {} for i=2,table.getn(arg) do arguments[i-1]=arg[i] end return mycl[orig_key](unpack(arguments)) else --print("No arguments") return mycl[orig_key]() end end) cl[orig_key] = myfunc else mutate(myfunc, function(...) FiltersOff() if table.getn(arg)>1 then local arguments = {} for i=2, table.getn(arg) do arguments[i-1]=arg[i] end return mycl[orig_key](unpack(arguments)) else return mycl[orig_key]() end end) cl[orig_key] = myfunc end end end -- how to use: MutClass(structure, false) MutClass(band, false) MutClass(current, true) local function p(s1,s2,s3,s4,s5) --"quicker" print ;] print(s1,s2,s3,s4,s5) end local function score() --score of puzzle s=get_score() if s==0 then for i=1, get_segment_count() do s=s+get_segment_score(i) end s=s+8000 end return s end local function getworst() --fill score table worst={} for i=1, get_segment_count() do sc=get_segment_score(i) worst[i]=sc end return worst end local function wig(mingain) --score conditioned wiggle, repeat --wiggles selected segments ss=score() do_local_wiggle(1) se=score() wg=se-ss p("Wiggle gain: ",wg) if wg<0 then p("Restored...") restore_recent_best() end until wg<mingain deselect_all() do_unfreeze_all() end local function wiggle(s, mingain, buddies) p("Wigglin segment ",s) deselect_all() do_unfreeze_all() sgs=score() maxi=get_segment_count() if s+1<=maxi then select_index(s+1)end if s-1>=1 then select_index(s-1)end do_freeze(true, true) deselect_all() select_index(s) wig(mingain) if buddies > 0 then --select buddies for b=1, buddies do if s+b+1<=maxi then select_index(s+b+1)end if s-1>=1 then select_index(s-1)end do_freeze(true, true) deselect_all() if s+b>maxi then select_index_range(s,maxi) else select_index_range(s,s+b)end wig(mingain) if s+1<=maxi then select_index(s+1)end if s-b-1>=1 then select_index(s-b-1)end do_freeze(true, true) deselect_all() if s-b<1 then select_index_range(1,s) else select_index_range(s-b,s)end wig(mingain) if s+b+1<=maxi then select_index(s+b+1)end if s-b-1>=1 then select_index(s-b-1)end do_freeze(true, true) deselect_all() if s+b>maxi then select_index_range(s,maxi) else select_index_range(s,s+b)end if s-b<1 then select_index_range(1,s) else select_index_range(s-b,s)end wig(mingain) end end sge=score() p("Segment gain: ",sge-sgs) end function wiggleworst(howmany, mingain, buddies) set_behavior_clash_importance(1) do_unfreeze_all() deselect_all() reset_recent_best() sscore=score() worst=getworst() for i=1, howmany do p(howmany+1-i, " segments left to do.") min=worst[1] seg=1 for f=2,get_segment_count() do if min>worst[f] then min=worst[f] seg=f end end wiggle(seg, mingain, buddies) worst[seg]=9999--never again same one end escore=score() p("Total gain: ", escore-sscore, " pts") end howmany = 20 --how many worst segments to process mingain = 0.1 --minimum gain per wiggle iterations (if more per 1 wiggle wiggles again) buddies = 4 --how many segments aside should be wibbled 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 wiggleworst(howmany, mingain, buddies)

Comments