Profile
- Name
- Worm LWS Forever NC For Filters V1 in V2
- ID
- 100710
- Shared with
- Public
- Parent
- None
- Children
- None
- Created on
- February 21, 2015 at 16:15 PM UTC
- Updated on
- February 21, 2015 at 16:15 PM UTC
- Description
Added Ravs and Bitspawns
Best for
Code
--[[
Worm LWS v2
Performin "worm" LWS by given patterns, no freezing
]]--
-- "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)
p=print --"quicker" print ;]
segCount=get_segment_count()
local function Score() --Score of puzzle
return get_score(true)
end
function round(x)
return x-x%0.001
end
function AllLoop()
local ok=false
for i=1, segCount do
local ss=get_ss(i)
if ss~="L" then
save_structure()
ok=true
break
end
end
if ok then
select_all()
replace_ss("L")
end
end
function lw()
local s=Score()
do_local_wiggle(25)
if Score()-s>0 then
do_local_wiggle(bigLw)
end
restore_recent_best() --sometimes wiggle(20) makes worse!!! lets see if nc is ok
end
function Worm()
if sEnd==nil then sEnd=segCount end
AllLoop()
reset_recent_best()
set_behavior_clash_importance(1)
quicksave(3)
local ss=Score()
while 1 do
for w=1,#pattern do
len=pattern[w]
local sw=Score()
p("Starting Worm of len ",len,", score: ",round(Score()))
for s=sStart,sEnd-len+1 do
deselect_all()
select_index_range(s,s+len-1)
lw()
end
p("Pattern gain: ",round(Score()-sw))
quicksave(3)
end
end
deselect_all()
load_structure()
p("Total Worm gain: ",round(Score()-ss))
end
pattern={2,5,11,3,13,4,7,1,6} --how many segments at once to LWS
sStart=1 --from segment
sEnd=nil --to segment, nil=end of it
bigLw=20 --do local_wiggle() that many times if positive lw 1 test
Worm()