Profile
- Name
- Push and Pull Filter Toggle
- ID
- 108748
- Shared with
- Public
- Parent
- Gary Rebuild Worst NC v1&v2 Filter Toggle
- Children
- None
- Created on
- June 19, 2024 at 18:45 PM UTC
- Updated on
- June 20, 2024 at 05:47 AM UTC
- Description
based upon Gary Rebuild Worst NC v1&v2 Filter Toggle
Added Ravs v1 in v2 and bits's overload filters
Best for
Code
--Gary Rebuild worst delta
--A modified version of Walkin Rebuild V4
rav={}
CG303={}
game={}
--[[
Push v2
randomly pushes then pulls one segment
options at end
]]--
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 --a short
segmentCount = get_segment_count()
segCnt=segmentCount
function Score()--return score, negative too
return get_score(true)
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 "how"=="s" then iters=1 end
if iters>0 then
iters=iters-1
local sp=Score()
if how == "s" then do_shake(1)
elseif how == "wb" then do_global_wiggle_backbone(25)
elseif how == "ws" then do_global_wiggle_sidechains(25)
elseif how == "wa" then do_global_wiggle_all(25)
end
local ig=Score()-sp
if ig > minppi then return Wiggle(how, iters, minppi) end --to learn recursion you have to learn recursion ;]
end
end
function FuseEnd()
set_behavior_clash_importance(1)
Wiggle()
Wiggle("s",1)
Wiggle()
end
function Fuze1(ci1,ci2)
set_behavior_clash_importance(ci1)
Wiggle("s",1)
set_behavior_clash_importance(ci2)
Wiggle("wa",1)
FuseEnd()
end
function Fuze2(ci1,ci2)
set_behavior_clash_importance(ci1)
Wiggle("wa",1)
set_behavior_clash_importance(1)
Wiggle()
set_behavior_clash_importance(ci2)
Wiggle("wa",1)
FuseEnd()
end
function PinkFuse()
reset_recent_best()
quicksave(4) -- store state before fuse
Fuze1(0.1,0.7)
quickload(4) -- load state before fuse
Fuze1(0.3,0.6)
quickload(4) -- load state before fuse
Fuze2(0.5,0.7)
quickload(4) -- load state before fuse
Fuze2(0.7,0.5)
restore_recent_best()
end
function qStab()
--select_all()
set_behavior_clash_importance(0.1)
Wiggle("s",1)
if fastQstab==false then
set_behavior_clash_importance(0.6)
Wiggle()
set_behavior_clash_importance(1)
Wiggle("s",1)
end
set_behavior_clash_importance(1)
Wiggle()
end
bestScore=Score()
function SaveBest()
local g=Score()-bestScore
if g>0 then
p("Gained another ",round(g)," pts.")
bestScore=Score()
quicksave(3)
end
end
--[[
Tlaloc`s math library
------------------------------------------------------------------------
The original random script this was ported from has the following notices:
Copyright (c) 2007 Richard L. Mueller
Hilltop Lab web site - http://www.rlmueller.net
Version 1.0 - January 2, 2007
You have a royalty-free right to use, modify, reproduce, and
distribute this script file in any way you find useful, provided that
you agree that the copyright owner above has no warranty, obligations,
or liability for such use.
------------------------------------------------------------------------
]]--
local lngX = 1000
local lngC = 48313
local function _random(m,n)
local A_Hi = 63551
local A_Lo = 25354
local M = 4294967296
local H = 65536
function _MWC()
local S_Hi = math.floor(lngX / H)
local S_Lo = lngX - (S_Hi * H)
local C_Hi = math.floor(lngC / H)
local F1 = A_Hi * S_Hi
local F2 = (A_Hi * S_Lo) + (A_Lo * S_Hi) + C_Hi
lngX = ((F2 - (math.floor(F2 / H) * H)) * H) + (A_Lo * S_Lo) + lngC - (C_Hi * H)
lngX = lngX - (math.floor(lngX / M) * M)
lngC = math.floor((F2 / H) + F1)
return lngX
end
if n == nil and m ~= nil then
n = m
m = 1
end
if (m == nil) and (n == nil) then
return _MWC() / M
else
if n < m then
return nil
end
return math.floor((_MWC() / M) * (n - m + 1)) + m
end
end
local function _abs(value)
if value < 0 then
return -value
else
return value
end
end
local function _floor(value)
return value - (value % 1)
end
local function _randomseed(s)
if s==nil then
s=math.abs(get_score(true))
s=s%0.001
s=1/s
while s<10000000 do s=s*10 end
s=s-s%1
end
lngX = s
end
math=
{
abs = _abs,
floor = _floor,
random = _random,
randomseed = _randomseed,
}
math.randomseed()
--[[ End math library ]]--
function down(x)--cut all after comma
return x-x%1
end
function round(x)--cut all afer 3-rd place
return x-x%0.001
end
function SaveRB(slot)
quicksave(slot)
restore_recent_best()
SaveBest()
quickload(slot)
end
bigBRK=0
function MakeBands(sgn,bands,center)
local SC = get_segment_distance(sgn,center)
local search=true
local sg2, SR, RC
local brk=0
repeat --try determine that band can push in good direction
brk=brk+1
sg2=math.random(segmentCount)
RC=get_segment_distance(sg2,center)
SR=get_segment_distance(sg2,sgn)
if SR<15
and RC<SC-3
and math.abs(sg2-sgn)>5
and math.abs(sg2-center)>3
then search=false end
if brk>segmentCount then break end
until search==false
if brk<segmentCount then
band_add_segment_segment(sgn, sg2)
if push then
SR=SR+pushDst --push x units
else
SR=SR-pushDst --pulls x units
end
if SR>20 then SR=20 end
if SR<3 then SR=3 end
band_set_length(get_band_count(), SR)
bands=bands-1
ppoints[#ppoints+1]=sg2
else
bigBRK=bigBRK+1
end
if bands >0 and bigBRK<10 then return MakeBands(sgn,bands,center) end --make next band
end
ppoints={}
function Push(sgn)
local ssc=Score()
if push then
p("Pushing segment ",sgn, " score: ",round(ssc))
else
p("Pulling segment ",sgn, " score: ",round(ssc))
end
band_delete()
quicksave(3)
reset_recent_best()
ppoints={}
bigBRK=0
MakeBands(sgn,numBands,cntSeg)
if get_band_count()>0 then
if doPlatform then --stabilize pushing point
for i=1,#ppoints do
local sn=ppoints[i]
for x=i,#ppoints do
local sn2=ppoints[x]
band_add_segment_segment(cntSeg, sn)
band_set_length(get_band_count(), get_segment_distance(sn,cntSeg))
band_add_segment_segment(sn2, sn)
band_set_length(get_band_count(), get_segment_distance(sn,sn2))
end
end
end
if doFreeze>0 then
local ss=sgn-doFreeze
local se=sgn+doFreeze
if ss<1 then ss=1 end
if se>segmentCount then se=segmentCount end
deselect_all()
select_index_range(1,ss)
select_index_range(se,segmentCount)
do_freeze(true,false)
end
select_all()
--deselect_all()
--SelectAround(326,338,15)
set_behavior_clash_importance(wiggleCI)
Wiggle("wb",1)
SaveRB(4) --maybe it found some already?
set_behavior_clash_importance(1)
band_delete()
do_unfreeze_all()
--deselect_all()
--SelectAround(326,338,15)
qStab()
if doPF and Score()>bestScore-PFthreshold then
PinkFuse()
end
SaveBest()
quickload(3)
local g=round(Score()-ssc)
if g>0 then p("Push gain: ",g) end
else
p("Can`t make proper bands")
end
end
function CanBeUsed(sn)
local can=false
if #alwaysUse>0 then
for i=1,#alwaysUse do
local ss=alwaysUse[i][1]
local se=alwaysUse[i][2]
if sn>=ss and sn<=se then
can=true
break
end
end
else
can=true
end
return can
end
function SelectAround(ss,se,radius)
for i=1, segCnt do
for x=ss,se do
if get_segment_distance(x,i)<radius then select_index(i) break end
end
end
end
function RandomPush(pushes)
if push==true then p("Pushing away from ",cntSeg)
else p("Pulling to ",cntSeg) end
for i=1,pushes do
local search=true
local sn
local t=0
repeat
t=t+1
sn=math.random(segmentCount)
local dst=get_segment_distance(sn, cntSeg)
if dst>minDist and CanBeUsed(sn) then search=false end
if t>10 then break end
until search==false
if t<10 then Push(sn) end
end
end
alwaysUse={ --always push that area/areas
--{326,338}, --391
--{1,100},
--{150,170},
}
cntSeg=0 --"center" segment global variable, segment to push from. now randomized
numBands=5 --how many bands should push (max, sometimes less)
wiggleCI=0.9 --pusching Clash Importance
doPF=true --false --use pink fuze
PFthreshold=-1 --PinkFuze if we so close to best score after qSatb
fastQstab=false --true --only 1s 1w if true
minDist=8 --minimum distance from "center" to push segment
pushDst=4 --push/pull how far away
doPlatform=false --true --makes additional bands to center to stabilize push points
doFreeze=0 --10 --if positve freezes entire protein except for area around pushed segment
-- set to 0 to disable freeze
--Push(78) --run that way to push desired segment
while true do
cntSeg=math.random(segmentCount)
push=true
RandomPush(3) --10 pushes from that segment
push=false
RandomPush(3) --10 pulls to that segment
end