Code
-- Toolbox v1.3
-- MurloW
p = print
p("")
nSegs = structure.GetCount()
Magic = 220
ItMu = 1.4
if ItMu <= 0.2 then ItMu = 1 end
function wig(how, it, iters, minppi)
if how == nil then how = "wa" end
if it == nil then it = 10 * ItMu else it = it * ItMu end
if iters == nil then iters = 2 end
if minppi == nil then minppi = 1 end
it = math.ceil(it)
if iters > 0 then
iters = iters - 1
local sp = score()
if how == "s" then structure.ShakeSidechainsAll(1)
elseif how == "wb" then structure.WiggleAll(it, true, false)
elseif how == "ws" then structure.WiggleAll(it, false, true)
elseif how == "wa" then structure.WiggleAll(it, true, true) end
if score() - sp > minppi and how ~= "s" then return wig(how, it, iters, minppi) end
end end
function score()
local s = 0
if DisFil then behavior.SetSlowFiltersDisabled(false) end
s = current.GetScore()
if DisFil then behavior.SetSlowFiltersDisabled(true) end
return s end
function Seed()
seed = os.time() / math.abs(current.GetEnergyScore())
seed = seed % 0.001
seed = 1 / seed
while seed < 10000000 do seed = seed * 10 end
seed = seed - seed % 1
math.randomseed(seed) end
Seed()
function isMovable(seg1, seg2)
local FT = true
for i = seg1, seg2 do
BB, SC = freeze.IsFrozen(i)
if (BB == true) then FT = false end
sl = structure.IsLocked(i)
if (sl == true) then FT = false end
end
return FT end
function Check()
local sc = score()
local gain = 0
if (bestscore < sc) then
gain = sc - bestscore
bestscore = sc
save.Quicksave(20)
Delbands()
save.Quicksave(1)
save.Quickload(20)
if cut(gain) > 0 then p("", string.format(" %.4f pts, new score: %.4f", gain, sc), os.date("%X")) end
end end
function qStab()
setCI(cival / 2)
wig("wa", 5) Check()
setCI(cival)
wig("s") Check()
wig() Check()
setCI(cival / 3)
wig("wa", 5) Check()
setCI(cival)
wig() Check()
wig("s") Check()
wig() Check() end
function Fuze()
Check()
setCI(.05)
wig("s") Check()
setCI(cival)
wig() Check()
setCI(cival / 3)
wig("wa", 5) Check()
if Dsp == 4 then
setCI(.07)
wig("s") Check()
setCI(cival)
wig() Check()
setCI(cival / 3)
wig("wa", 5) Check() end
setCI(cival)
wig("s") Check()
wig() Check() end
function mutaFuze()
Check()
setCI(0.15)
structure.MutateSidechainsAll(1) Check()
setCI(cival / 3)
wig("wa", 4) Check()
setCI(cival)
wig() Check()
if Dsp == 4 then
setCI(0.2)
wig("s") Check()
setCI(cival / 2)
wig("wa", 5) Check()
setCI(0.87 * cival)
structure.MutateSidechainsSAll(1) Check()
selection.DeselectAll() end
setCI(cival)
wig() Check()
wig("s") Check()
wig() Check() end
function Fuzit()
if muta then mutaFuze()
else Fuze() end
end
function Test()
if (Qscore - score()) >= (Qscore / 4) then
setCI(cival / 3)
wig("wa", 5) Check()
wig("s") Check() end
setCI(cival)
wig() Check()
setCI(cival / 3)
wig("wa", 5) Check()
setCI(cival)
wig() Check()
if Dsp >= 2 then qStab()
if Dsp == 3 then
if score() >= (Qscore + (Qscore / Magic)) then
Fuzit() end
elseif Dsp == 4 then
if score() >= (Qscore - (Qscore / Magic)) then
Fuzit() end end
recentbest.Restore() Check() end
end
function sort(part)
Mseg = {}
for x = 1, nSegs do
if part ~= 'total' then Mseg[x] = {x, current.GetSegmentEnergySubscore(x, part)} else Mseg[x] = {x, current.GetSegmentEnergyScore(x)} end
end
if WorstFirst then table.sort(Mseg, function (x, y) return x[2] < y[2] end) else table.sort(Mseg, function (x, y) return x[2] > y[2] end) end
return Mseg end
function cut(x)
return x - x % 0.01 end
function setCI(ci)
return behavior.SetClashImportance(ci) end
function getSS(x)
return structure.GetSecondaryStructure(x) end
function checkLocked()
lockd = 0 -- locked seg quantity counter
locklist = {}
for k = 1, nSegs do -- k = seg identity counter
if not isMovable(k, k) then
lockd = lockd + 1
locklist[lockd] = k
end end
return lockd, locklist end
function checkSelected()
selected = 0
selList = {}
for k = 1, nSegs do
if selection.IsSelected(k) then
selected = selected + 1
selList[selected] = k
end end
if selected > 0 then sels = true
else sels = false end
return selList, sels end
function checkSelLengths(length)
local b = 0
cnt = 0
broken = true
for e = 1, nSegs do
if selection.IsSelected(e) then b = b + 1
if b > cnt then cnt = b end
else b = 0 end
if b >= length then
broken = false
break end
end
return cnt, broken end
function selectsphere(seg, radius)
for i = 1, nSegs do --p(i)
if structure.GetDistance(seg, i) <= radius then selection.Select(i) --p(selected)
end end
end
function contains(tab, value)
for _, v in pairs(tab) do
if v == value then
return true
end
end
return false end
function Rbld()
local sco = score()
local its = 0
Disbands()
setCI(math.random(5, 18)/100)
repeat
its = its + 1
if its > 4 then break end
structure.RebuildSelected(its)
until cut(score()) ~= cut(sco) end
function End(errmsg)
if done then return end
done = true
if string.find(errmsg, "Cancelled") then
p("")
p(" User cancel.")
Result()
p("")
else
p("")
p(errmsg)
Result()
end
return errmsg end
function Result()
Check()
recentbest.Restore() Check()
save.Quickload(1)
Delbands()
p("", os.date("%X"))
if DisFil then behavior.SetSlowFiltersDisabled(false) end
local Tgain = (score() - startscore)
if Tgain >= 0.0001 then
p(string.format(" Startscore: %.4f",startscore))
p(string.format(" Score: %.4f",score()))
p(" Total gain: " .. Tgain .. " pts.")
elseif (PrB == nil) and (ShSt == nil) then
p(" No change.. :/ ") end
setCI(cival)
selection.DeselectAll()
for ii = 1, #selList do selection.Select(selList[ii]) end
end
function init()
cival = behavior.GetClashImportance()
if cival < 0.1 then cival = 1 end
cutlist = {}
checkLocked()
checkSelected()
Qbands = 0
for i = 1, #selList do
if not isMovable(selList[i], selList[i]) then selection.Deselect(selList[i]) end
end
checkSelected()
Cbds = band.GetCount()
if Cbds >= 1 then bands = true end
oldbands = Cbds
WorstFirst = true
for i = 2, nSegs - 1 do -- mutable?
if structure.IsMutable(i) then MM = true break end end
ConP = false
for y = 1, nSegs - 2 do -- contact?
for j = y + 2, nSegs do
if contactmap.GetHeat(y, j) ~= 0 then ConP = true
break
end
end
if ConP then break end
end
return ConP, MM, locklist, selList, bands, oldbands
end
function dia()
opt = dialog.CreateDialog(" Toolbox. ")
if not bands then opt.pbl = dialog.AddCheckbox(" Create Zero Length Bands on: ", false)
opt.pbb = dialog.AddLabel("Helices(1), Sheets(2), Both(3), Selected(4), Non-Selected(5)")
opt.pb = dialog.AddSlider("", 3, 1, 5, 0)
opt.shS = dialog.AddCheckbox(" Sheet Stitcher", false) end
if sels then
opt.sel = dialog.AddCheckbox(" Rebuild all selected residues simultaneously", false)
opt.selS = dialog.AddSlider(" ^ x times ", 2, 1, 9, 0)
opt.selR = dialog.AddCheckbox(" Rebuild selected residues one area at a time", false)
opt.selY = dialog.AddSlider(" x times per area ", 2, 1, 9, 0)
opt.Rem = dialog.AddCheckbox(" Remix selected residues one area at a time", false)
opt.remTs = dialog.AddSlider(" x times per area ", 2, 2, 9, 0) else
opt.rr = dialog.AddCheckbox(" Rainbow Rebuild", false) end
opt.cuts = dialog.AddCheckbox(" Cut and Wiggle", false)
opt.id = dialog.AddCheckbox(" Idealize", false)
opt.ntw = dialog.AddCheckbox(" Rotamer test", false)
if MM then opt.bfo = dialog.AddCheckbox(" and bruteforce polar AAs", false) end
if sels then opt.ran = dialog.AddCheckbox(" Random rebuilds/remix among selected (loops forever)", false)
opt.ranb = dialog.AddSlider("Rebuilds(1), Remix(2), Both(3)", 3, 1, 3, 0)
opt.rani = dialog.AddSlider(" Min. length: ", 3, 2, nSegs / 3, 0)
opt.rana = dialog.AddSlider(" Max. length: ", nSegs / 5, 2, nSegs, 0) end
opt.qu = dialog.AddCheckbox(" Quick quake here and there during Actions", false)
if ConP then opt.cb = dialog.AddCheckbox(" Contact Bander (loops forever)", true) end
if bands then opt.wb = dialog.AddCheckbox(" Work Existing Bands (loops forever)", false) end
opt.bf = dialog.AddCheckbox(" BandFuze (loops forever)", false)
opt.ok = dialog.AddButton("Go go!", 1)
opt.can = dialog.AddButton("Cancel.", 2)
local res = dialog.Show(opt)
if res == 2 then return Cancel()
elseif res ~= 1 then return dia() end
if sels then
randr = opt.ran.value
RanB=opt.ranb.value
minr = opt.rani.value
maxr = opt.rana.value
if minr > maxr then
mnnrb = minr
mxxrb = maxr
minr = mxxrb
maxr = mnnrb
end
checkSelLengths(maxr)
if broken then maxr = cnt end -- p(maxr)
remTrs = opt.remTs.value
RMX = opt.Rem.value
sim = opt.sel.value
simTrs = opt.selS.value
selTrs = opt.selY.value
selR = opt.selR.value else
rr = opt.rr.value end
ide = opt.id.value
cuts = opt.cuts.value
BF = opt.bf.value
NTW = opt.ntw.value
QO = opt.qu.value
if MM then BForce = opt.bfo.value end
if bands then
wb = opt.wb.value
else PrB = opt.pbl.value
SS = opt.pb.value
ShSt= opt.shS.value end
if ConP then CB = opt.cb.value end
dia2()
return rr, wb, muta, cuts, ide, sim, KB, KBE, KBSTR, CB, tacu, tid, selR, simTrs, QO, BF, NTW, Snt, BForce, selTrs, randr, minr, maxr, PrB, SS, ShSt
end
function dia2()
opt = dialog.CreateDialog(" Options: ")
opt.mxc = dialog.AddSlider(" MaxCI:", cival, 0.1, 1, 2)
opt.dd = dialog.AddSlider("Desperation level: ", 1, 1, 4, 0)
if MM then opt.Muta = dialog.AddCheckbox(" Mutate (after perturb, during fuze, etc.)", true) end
if sels then
if cuts then opt.tac = dialog.AddCheckbox(" Target selected residues only with Cut & Wiggle", false) end
if ide then opt.tid = dialog.AddCheckbox(" Target selected residues only with Idealize", false) end
if NTW then opt.sn = dialog.AddCheckbox(" Target selected residues only with Rotamer Test", true) end
elseif rr then opt.rldr = dialog.AddLabel("Rainbow Rebuild.")
opt.mnlng = dialog.AddSlider("Min. rebuild length", (nSegs - lockd) / 4, 2, (nSegs / 2) - 1, 0)
opt.mxlng = dialog.AddSlider("Max. rebuild length", (nSegs - lockd) / 4, 2, (nSegs / 2) - 1, 0)
opt.lf = dialog.AddCheckbox("Longest first", true)
opt.LF = dialog.AddCheckbox("Loop forever (unchecked = 1 cycle through lengths)", false) end
if bands then
opt.KB = dialog.AddCheckbox(" Keep original bands", true)
opt.KBE = dialog.AddCheckbox(" Keep enabled always", false)
opt.KBE2 = dialog.AddCheckbox(" ^only for bands with strength >= 10", true)
opt.KBSTR = dialog.AddCheckbox(" Keep original strength", false)
opt.KBSTR2 = dialog.AddCheckbox(" ^only for bands with strength >= 10", true)
elseif ShSt then opt.shS = dialog.AddLabel(" Sheet Stitcher")
opt.Bstr = dialog.AddSlider("Band Strength:", 0.7, 0.1, 1, 2)
opt.dis = dialog.AddSlider("Distance:", 6, 5, 30, 0)
opt.frz = dialog.AddCheckbox("Freeze sheet backbone.",true)
end
opt.df = dialog.AddCheckbox(" Disable Filters during operations", true)
opt.ok = dialog.AddButton("Go go!", 1)
opt.can = dialog.AddButton("Cancel.", 2)
local res = dialog.Show(opt)
if res == 2 then return Cancel()
elseif res ~= 1 then return dia2() end
Dsp = opt.dd.value
if MM then muta = opt.Muta.value end
if rr then
minlng = opt.mnlng.value
maxlng = opt.mxlng.value
if minlng > maxlng then
Mlng = maxlng
maxlng = minlng
minlng = Mlng end
lFirst = opt.lf.value
LoFo = opt.LF.value end
if bands then
KB = opt.KB.value
KBE = opt.KBE.value
KBE2 = opt.KBE2.value
KBSTR = opt.KBSTR.value
KBSTR2 = opt.KBSTR2.value
elseif ShSt then
BStr = opt.Bstr.value
distance = opt.dis.value
frzz = opt.frz.value
end
DisFil = opt.df.value
cival = opt.mxc.value
if sels then
if cuts then tacu = opt.tac.value end
if ide then tid = opt.tid.value end
if NTW then Snt = opt.sn.value end end
return muta, cuts, KB, KBE, KBSTR, DisFil, tacu, tid, Snt, KBSTR2, KBE2, Dsp, cival, minlng, maxlng, lFirst, LoFo, BStr, distance, frzz
end
PoAs = {"r", "n", "d", "q", "e", "h", "k", "y", "w", "s", "t"}
for i = 1, #PoAs do -- shuffle list
local x = math.random(#PoAs)
PoAs[i], PoAs[x] = PoAs[x], PoAs[i] end
---- Actions functions
function ZLBandSS(SS)
if SS == 1 then SeSe = 'H'
elseif SS == 2 then SeSe = 'E'
elseif SS == 4 then for i = 1, #selList do ZLBand(selList[i], 10, 0) end
elseif SS == 5 then for i = 1, nSegs do
if not contains(selList, i) then ZLBand(i, 10, 0) end end
else for i = 1, nSegs do
if getSS(i) == 'H' then ZLBand(i, 10, 0) end end
SeSe = 'E'
end
for i = 1, nSegs do
if getSS(i) == SeSe then ZLBand(i, 10, 0) end
end
end
function SheetStitcher()
for i = 1, nSegs do
for y = i + 1, nSegs do
if (structure.GetDistance(i, y) <= distance and getSS(i) == 'E' and getSS(y) == 'E' ) and i ~= y - 1 then
band.AddBetweenSegments(i, y) -- p(i,y)
local lb = band.GetCount()
band.SetStrength(lb, BStr)
band.SetGoalLength(lb, ((band.GetLength(lb)/100)*80)) end
end end end
function simul()
p(" Rebuild All Selected", os.date("%X"))
save.Quicksave(80)
for i = 1, simTrs do
save.Quickload(80)
Qscore = score()
Rbld() Check()
if cut(score()) ~= cut(Qscore) then
recentbest.Save()
for x = 1, #selList do
selectsphere(selList[x], 8) end
setCI(cival * 0.8)
if muta then structure.MutateSidechainsSelected(1)
Check()
wig("s") else
structure.ShakeSidechainsSelected(1) end
Check()
selection.DeselectAll()
for k = 1, #selList do
selection.Select(selList[k]) end
Test()
if CB then
BandSelectedContacts()
BandTest()
end
if QO then QuakeOnce() end
save.Quicksave(60 + i)
end
end
for yj = 1, simTrs do
save.Quickload(60 + yj) Check() end
recentbest.Restore() Check() end
function selReb()
save.Quickload(1)
p(" Rebuild Selected", os.date("%X"))
local v = 0
local tag = 2
local tac = 1
local tec = 0
for i = 2, #selList do
if not (selList[i] == selList[i - 1] + 1) then v = v + 1 end
end
for cnt = 1, v + 1 do
for e = tag, #selList + 1 do
if not (selList[e] == selList[e - 1] + 1) then tec = e break end
end
selection.DeselectAll()
save.Quickload(1)
selStr = selList[tac]
selEnd = selList[tec - 1]
for i = selStr, selEnd do
selection.Select(i)
tac = tac + 1 end
p(" segs " .. selStr .. " to " .. selEnd, "")
tag = tec + 1
save.Quicksave(80)
for yh = 1, selTrs do
save.Quickload(80)
Qscore = score()
Rbld() Check()
if cut(score()) ~= cut(Qscore) then
recentbest.Save()
setCI(cival * 0.8)
for x = selStr, selEnd do
selectsphere(x, 8) end
if muta then structure.MutateSidechainsSelected(1)
Check()
wig("s") Check() else
structure.ShakeSidechainsSelected(1) Check() end
selection.DeselectAll()
selection.SelectRange(selStr, selEnd)
Test()
if CB then
BandSelectedContacts()
BandTest()
end
if QO then QuakeOnce() end
end
end
end
recentbest.Restore() Check()
for ii = 1, #selList do selection.Select(selList[ii]) end
end
function Remix()
save.Quickload(1)
p(" Remix Selected", os.date("%X"))
local v = 0
local tag = 2
local tac = 1
local tec = 0
local rmx = function ()
remS6 = true
recentbest.Save()
structure.RemixSelected(5, remTrs-1) Check()
setCI(cival * 0.8)
for y = 1, remTrs do
save.Quickload(3 + y)
for x = selStr, selEnd do --p(x,y)
selectsphere(x, 8) end
if muta then structure.MutateSidechainsSelected(1) Check()
structure.ShakeSidechainsSelected(1) Check()
else
structure.ShakeSidechainsSelected(1) Check()
end
wig() Check()
structure.ShakeSidechainsSelected(1) Check()
end
recentbest.Restore() Check()
selection.DeselectAll()
Test()
if CB then
BandSelectedContacts()
BandTest()
end
if QO then QuakeOnce() end
end
for i = 2, #selList do
if not (selList[i] == selList[i - 1] + 1) then v = v + 1 end
end
for cnt = 1, v + 1 do
for e = tag, #selList + 1 do
if not (selList[e] == selList[e - 1] + 1) then tec = e break end
end
selection.DeselectAll()
save.Quickload(1)
selStr = selList[tac]
selEnd = selList[tec - 1]
local selC = 0
for i = selStr, selEnd do
selection.Select(i)
selC = selC + 1
tac = tac + 1 end
local tS = selC - 1
p(" segs " .. selStr .. " to " .. selEnd, "")
tag = tec + 1
remS6 = false
Qscore = score()
structure.RemixSelected(4, 1) Check()
if cut(score()) ~= cut(Qscore) then
rmx()
else
local zer = 0
while tS > 4 do tS = tS - 1
if selEnd == nSegs then selection.Deselect(nSegs - zer) else selection.Deselect((selStr + tS) + 1) end
structure.RemixSelected(4, 1) Check()
zer = zer + 1
if cut(score()) ~= cut(Qscore) then break end
end
if cut(score()) ~= cut(Qscore) then
rmx() end
end
if remS6 ~= true then
local tS = selC - 1
selection.SelectRange(selStr,selEnd)
local zer = 0
while tS > 4 do tS = tS - 1
if selStr == 1 then selection.Deselect(1 + zer) else selection.Deselect((selEnd - tS) - 2) end
structure.RemixSelected(4, 1) Check()
zer = zer + 1
if cut(score()) ~= cut(Qscore) then break end
end
if cut(score()) ~= cut(Qscore) then
rmx() end
end
if remS6 ~= true then p(" no remix available ") end
end
recentbest.Restore() Check()
for ii = 1, #selList do selection.Select(selList[ii]) end
end
function RR()
p(" Rainbow Rebuild ", os.date("%X"))
local rrD = function ()
if isMovable(TargetS, TargetS + (rrlng - 1)) then
save.Quickload(1)
Qscore = score()
selection.DeselectAll()
selection.SelectRange(TargetS, TargetS + (rrlng - 1))
checkSelected()
Rbld() Check()
if cut(score()) ~= cut(Qscore) then
recentbest.Save()
setCI(cival * 0.8)
for x = 1, #selList do selectsphere(selList[x], 7) end
if muta then structure.MutateSidechainsSelected(1) Check() end
structure.ShakeSidechainsSelected(1) Check()
selection.DeselectAll()
for k = 1, #selList do
selection.Select(selList[k]) end
Test()
if CB then
for y = 1, nSegs - 1 do
for j = TargetS, TargetS + (rrlng - 1) do
if (structure.GetDistance(y, j) <= 10) and (structure.GetDistance(y, j) >= 4) then
if contactmap.GetHeat(y, j) ~= 0 then lb = band.AddBetweenSegments(y, j)
band.SetGoalLength(lb, band.GetLength(lb) * (1 - contactmap.GetHeat(y, j))) end end
end
end
BandTest()
end
if QO then QuakeOnce() end
end
end -- isMov
end
if lFirst then rrlng = maxlng
if minlng ~= maxlng then p(" Lengths " .. maxlng .. " to " .. minlng) else
p(" Length " .. rrlng, os.date("%X")) end
else rrlng = minlng
if minlng ~= maxlng then p(" Lengths " .. minlng .. " to " .. maxlng) else
p(" Length " .. rrlng, os.date("%X")) end
end
if LoFo then
while true do
TargetS = 1
for i = 1, nSegs, nSegs / rrlng do
if (TargetS + (rrlng - 1)) > nSegs then break end
if not isMovable(TargetS, TargetS + (rrlng - 1)) then repeat
TargetS = TargetS + 1
if (TargetS + (rrlng - 1)) > nSegs then break end
until isMovable(TargetS, TargetS + (rrlng - 1)) end
rrD() TargetS = TargetS + (rrlng - 1)
if (TargetS + (rrlng - 1)) > nSegs then break end end
if lFirst then rrlng = rrlng - 1
if rrlng < minlng then rrlng = maxlng end
elseif not lFirst then rrlng = rrlng + 1
if rrlng > maxlng then rrlng = minlng end end
end -- while
else
RRc = (maxlng - minlng) + 1
for rc = 1, RRc do
TargetS = 1
for i = 1, nSegs, nSegs / rrlng do
if (TargetS + (rrlng - 1)) > nSegs then break end
if not isMovable(TargetS, TargetS + (rrlng - 1)) then repeat
TargetS = TargetS + 1
if (TargetS + (rrlng - 1)) > nSegs then break end
until isMovable(TargetS, TargetS + (rrlng - 1)) end
rrD() TargetS = TargetS + (rrlng - 1)
if (TargetS + (rrlng - 1)) > nSegs then break end end
if lFirst then rrlng = rrlng - 1 elseif not lFirst then rrlng = rrlng + 1 end -- p("",rrlng,"rrlng,","end of rc, RRc")
end
end -- LoFo
end
function Cuts()
save.Quickload(1)
Qscore = score()
if tacu then
cuts = 0
for i = 1, #selList do
structure.InsertCut(selList[i])
cuts = cuts + 1
cutlist[cuts] = selList[i]
end
p("", cuts .. " cuts", os.date("%X"))
cutheal()
if CB then
BandSelectedContacts()
BandTest()
end
if QO then QuakeOnce() end
---------
cuts = 0
CHu = true
for i = 1, #selList do
structure.InsertCut(selList[i])
cuts = cuts + 1
cutlist[cuts] = selList[i]
cutheal()
end
CHu = false
if CB then
BandSelectedContacts()
BandTest()
end
if QO then QuakeOnce() end
else -- no tacu
sort('backbone')
cuts = 0
local ab = 0
while cuts < (nSegs - lockd) / 6 do
ab = ab + 1
local xi = Mseg[ab][1]
if isMovable(xi, xi) then structure.InsertCut(xi)
cuts = cuts + 1
cutlist[cuts] = xi
end end
p("", cuts .. " cuts", os.date("%X"))
cutheal()
if CB then
BandAllContacts()
BandTest()
end
if QO then QuakeOnce() end
---------
cuts = 0
for xy = 1, nSegs do
if (getSS(xy) == 'L') and isMovable(xy, xy) then structure.InsertCut(xy)
cuts = cuts + 1
cutlist[cuts] = xy
end
end
p("", cuts .. " cuts", os.date("%X"))
cutheal()
if CB then
BandAllContacts()
BandTest()
end
if QO then QuakeOnce() end
---------
sort('backbone')
cuts = 0
CHu = true
local ab = 0
p("", "10 cuts", os.date("%X"))
for ab = 1, 10 do
local xi = Mseg[ab][1]
if xi ~= nSegs then
if (isMovable(xi, xi) or isMovable(xi + 1, xi + 1)) then structure.InsertCut(xi)
cuts = cuts + 1
cutlist[cuts] = xi
cutheal()
end end
end
CHu = false
if CB then
BandAllContacts()
BandTest()
end
if QO then QuakeOnce() end
end -- tacu
end
function cutheal()
setCI(cival)
wig()
save.Quicksave(90)
for ch = 1, #cutlist do structure.DeleteCut(cutlist[ch]) end
Check()
local Csc = score()
recentbest.Save()
wig() Check()
if cut(score()) ~= cut(Csc) then
Test() end
if not CHu then
save.Quickload(90)
setCI(cival / 3)
wig("wa", 5)
setCI(cival)
wig()
for ch = 1, #cutlist do structure.DeleteCut(cutlist[ch]) end
Check()
recentbest.Save()
if cut(score()) ~= cut(Csc) then
Test() end
end end
function Idia()
opt = dialog.CreateDialog("Idealize.")
opt.wh = dialog.AddSlider("whole structure(1) or worst scoring only(2)", 2, 1, 2, 0)
opt.iln = dialog.AddSlider(" Length:", 3, 2, nSegs, 0)
opt.uc = dialog.AddCheckbox(" Use Cutpoints.", false)
opt.ok = dialog.AddButton("Go go!", 1)
opt.can = dialog.AddButton("Cancel.", 2)
local res = dialog.Show(opt)
if res == 2 then return Cancel()
elseif res ~= 1 then return Idia() end
wh = opt.wh.value
uc = opt.uc.value
if not tid then Ilng = opt.iln.value end
return Ilng, uc, wh
end
function Ide()
save.Quickload(1)
p(" Idealize ", os.date("%X"))
recentbest.Save()
Qscore = score()
if tid then
local Csc = score()
structure.IdealizeSelected()
if cut(score()) ~= cut(Csc) then
Test()
if CB then
BandSelectedContacts()
BandTest()
end
if QO then QuakeOnce() end
end
else -- tid
if wh == 2 then
sort('ideality')
local y=0
for x = 1, (nSegs - lockd) / (Ilng - 1) do
local segC=x
local segI=segC+y
if contains(locklist,Mseg[segI][1]) then repeat y=y+1
segI=segC+y until not contains(locklist,Mseg[segI][1]) end
if Mseg[segI][1] + (Ilng / 2) > nSegs then IdStrt, IdEnd = nSegs - (Ilng - 1), nSegs
elseif Mseg[segI][1] - (Ilng / 2) < 1 then IdStrt, IdEnd = 1, Ilng
else
if Ilng % 2 ~= 0 then
IdStrt = Mseg[segI][1] - math.floor(Ilng / 2)
IdEnd = Mseg[segI][1] + math.floor(Ilng / 2) else
IdStrt = Mseg[segI][1] - (math.floor(Ilng / 2) - 1)
IdEnd = Mseg[segI][1] + math.floor(Ilng / 2)
end end -- p(IdStrt,IdEnd)
selection.DeselectAll()
local Csc = score()
selection.SelectRange(IdStrt, IdEnd)
if uc then
cuts = 0
if IdStrt > 1 then structure.InsertCut(IdStrt - 1)
cuts = cuts + 1
cutlist[cuts] = IdStrt - 1 end
if (IdEnd) < nSegs then structure.InsertCut(IdEnd)
cuts = cuts + 1
cutlist[cuts] = IdEnd end
end
structure.IdealizeSelected()
if uc then cutheal() else
if cut(score()) ~= cut(Csc) then
Test() end
end -- uc
if cut(score()) ~= cut(Csc) then
if CB then
BandSelectedContacts()
BandTest()
end
if QO then QuakeOnce() end
end
recentbest.Restore() Check()
end -- for x
else
if Ilng > nSegs - 2 then uc = false end
p(" Length " .. Ilng)
for i = 1, nSegs, Ilng do
if (i + Ilng) > nSegs then Ilng = (nSegs - i) + 1 end
if isMovable(i, i + (Ilng - 1)) then
selection.DeselectAll()
selection.SelectRange(i, i + (Ilng - 1))
local Csc = score()
if uc then
cuts = 0
if (i - 1) >= 1 then structure.InsertCut(i - 1)
cuts = cuts + 1
cutlist[cuts] = i - 1 end
if (i + Ilng) < nSegs then structure.InsertCut(i + (Ilng - 1))
cuts = cuts + 1
cutlist[cuts] = i + (Ilng - 1) end
end
structure.IdealizeSelected()
if uc then cutheal() else
if cut(score()) ~= cut(Csc) then
Test() end
end -- uc
if CB then
BandSelectedContacts()
BandTest()
end
if QO then QuakeOnce() end
end -- isMov
end
selection.DeselectAll()
end
end -- if tid
recentbest.Restore() Check() end
function NetwTest()
p(" Rotamer Test ", os.date("%X"))
save.Quickload(1)
lscore = score()
selection.DeselectAll()
local k = 0
local targets = 0
if Snt then targets = #selList
p(" ", targets .. " segs to test") else
targets = nSegs
p(" ", " all polar segs") end
for jj = 1, targets do
k = k + 1
if Snt then st = selList[k] else st = k end
if not Snt then
if contains(PoAs, structure.GetAminoAcid(st)) then Snap(st) end
else Snap(st) end
end
if BForce then p(" ", "bruteforcing polar AAs ", os.date("%X"))
selection.DeselectAll()
local k = 0
local targets = 0
if Snt then targets = #selList else targets = nSegs end
for jj = 1, targets do
k = k + 1
if Snt then st = selList[k] else st = k end
if not Snt then
if contains(PoAs, structure.GetAminoAcid(st)) then BruF(st) end
else BruF(st) end
end
end -- BForce
end
function nTest()
setCI(0.01)
structure.WiggleSelected(5, false, true) Check()
structure.ShakeSidechainsSelected(1) Check()
setCI(cival)
structure.WiggleSelected(5, false, true) Check()
structure.ShakeSidechainsSelected(1) Check()
selection.DeselectAll()
wig("ws", 3) Check() end
function Snap(x)
Check()
selectsphere(x, 10)
nTest()
snaps = rotamer.GetCount(x)
for y = 1, snaps do
Qscore = score()
rotamer.SetRotamer(x, y) Check()
if cut(score()) ~= cut(Qscore) then
selectsphere(x, 10)
selection.Deselect(x)
nTest() end
end
end
function BruF(x)
for i = 1, #PoAs do
save.Quickload(1)
origA = structure.GetAminoAcid(x)
BB, SC = freeze.IsFrozen(x)
if structure.CanMutate(x, PoAs[i]) and SC == false then structure.SetAminoAcid(x, PoAs[i])
newA = structure.GetAminoAcid(x)
Nlscore = score()
if newA ~= origA then Snap(x) end
save.Quickload(1)
newA = structure.GetAminoAcid(x)
if newA ~= origA then p(" seg " .. x .. " changed from " .. origA .. " to " .. newA) end
end
end -- PoAs--p(os.date("%X"))
end
function ran()
local rmx = function()
recentbest.Save()
structure.RemixSelected(4, 5) Check()
setCI(cival * 0.8)
for y = 1, 5 do
save.Quickload(3 + y)
for x = selStr, selEnd do selectsphere(x, 8) end
if muta then structure.MutateSidechainsSelected(1) Check()
structure.ShakeSidechainsSelected(1) Check() else
structure.ShakeSidechainsSelected(1) Check() end
wig() Check()
structure.ShakeSidechainsSelected(1) Check()
end
recentbest.Restore() Check()
selection.DeselectAll()
end --end
if RanB==2 then p(" Random Remixes ", os.date("%X"))
elseif RanB==3 then p(" Random Rebuilds and Remixes", os.date("%X"))
elseif RanB==1 then p(" Random Rebuilds ", os.date("%X")) end
while true do
save.Quickload(1)
Qscore = score()
rsz = math.random(minr, maxr) -- rebuild length p(rsz)
broken = true
while broken ~= false do
broken = false
Oseg = selList[math.random(1, #selList)]
for yh = Oseg, (Oseg + rsz) - 1 do -- p(yh, Oseg,(Oseg+rsz)-1)
if not contains(selList, yh) then broken = true end -- p(broken)
end
end
selStr = Oseg
selEnd = (Oseg + rsz) - 1
selection.DeselectAll()
selection.SelectRange(selStr, selEnd) -- p(" segs "..selStr.." to "..selEnd,"lng",rsz)
if RanB~=2 then
Rbld() Check() elseif RanB==2 then rmx() end
if cut(score()) ~= cut(Qscore) then
recentbest.Save()
setCI(cival * 0.8)
for x = selStr, selEnd do
selectsphere(x, 7) end
if muta then structure.MutateSidechainsSelected(1) Check()
wig("s") Check() else
structure.ShakeSidechainsSelected(1) Check() end
selection.DeselectAll()
wig()
if RanB==3 then selection.SelectRange(selStr, selEnd)
rmx() end
Test()
if CB then
BandSelectedContacts()
BandTest()
end
if QO then QuakeOnce() end
end
recentbest.Restore() Check()
for ii = 1, #selList do selection.Select(selList[ii]) end
end end
function ContactBander()
p(" Band Contacts")
BandAllContacts()
CBe = true
if (band.GetCount() < 1) or BF then wb = false else
wb = true end
end
function WorkExBands()
p(" Work Bands", os.date("%X"))
Qscore = score()
while true do
save.Quickload(20)
BandTest()
end -- while
end
function BFdia()
opt = dialog.CreateDialog(" BandFuze. ")
opt.Qq = dialog.AddCheckbox(" Quake.", true)
opt.Bs = dialog.AddCheckbox(" BiS.", false)
opt.Cmb = dialog.AddCheckbox(" Combine Quake and BiS.", false)
opt.Sk = dialog.AddCheckbox(" Shock.", true)
opt.Tg = dialog.AddCheckbox(" Tailgrab.", false)
opt.ok = dialog.AddButton("Go go!", 1)
opt.can = dialog.AddButton("Cancel.", 2)
local res = dialog.Show(opt)
if res == 2 then return Cancel()
elseif res ~= 1 then return BFdia() end
QQ = opt.Qq.value
BiS = opt.Bs.value
Shock = opt.Sk.value
TG = opt.Tg.value
Combo = opt.Cmb.value
return QQ, BiS, Shock, TG, Combo
end
function BFuze()
p(" BandFuze ", os.date("%X"))
while true do
save.Quickload(20)
Qscore = score()
if QQ or Combo then Quaker() end
BiSs()
if TG then BandAcross() end
end
end
---- Band functions
function DisRdm() --p("disrdm")
band.EnableAll()
local RMr = function ()
RM = math.random(-100, 100)
if RM >= 0 then BdOff = false
else BdOff = true end
end
if band.GetCount() > 1 then
if KBE and KBE2 then
for b = 1, band.GetCount() do
if band.GetStrength(b) < 10 then
RMr()
if BdOff then band.Disable(b) end
end
end
elseif not KBE2 and KBE then
for b = oldbands+1, band.GetCount() do
RMr()
if BdOff then band.Disable(b) end
end
else
for b = 1, band.GetCount() do
RMr()
if BdOff then band.Disable(b) end
end
end
end
end
function Delbands() --p("delbands",Cbds)
local BDC = band.GetCount()
if CBe then
for cn = Cbds, BDC - 1 do band.Delete(Cbds + 1) end
elseif KB then
for h = oldbands, BDC - 1 do band.Delete(oldbands + 1) end
else
band.DeleteAll() end
end
function Disbands() --p("disbands")
if KBE and KBE2 then
for b = 1, band.GetCount() do
if band.GetStrength(b) < 10 then
band.Disable(b) end
end
elseif not KBE2 and KBE then
for b = oldbands+1, band.GetCount() do
band.Disable(b) end
else band.DisableAll() end
end
function ZLBand(seg, Str, atom)
local seg2, seg3
local phi =0
local theta = 0
local minlen = 0.1
atom = atom or 0
Str = Str or 10
if (seg == 1) then seg2, seg3 = 2, 3
elseif seg == nSegs then seg2, seg3 = nSegs-1, nSegs-2
else seg2, seg3 = seg-1, seg+1 end
local lb = band.Add(seg, seg2, seg3, 0.1, theta, phi, atom)
if lb > 0 then
band.SetGoalLength(lb, band.GetLength(lb))
band.SetStrength(lb, Str) end
return lb end
function bandpull(minBS, maxBS)
local ss = score()
local perc = math.random(80, 180) / 100
local loss = ((perc * ss) / 100) -- p("ss,perc,loss",ss,perc,loss)
local lastBS = minBS
for str = lastBS, maxBS, 0.1 do
if KBSTR and KBSTR2 then
for i = 1, band.GetCount() do
if band.GetStrength(i) < 10 then band.SetStrength(i, str) end
end
elseif not KBSTR2 and KBSTR then
local NNbands = band.GetCount()
for i = oldbands + 1, NNbands do band.SetStrength(i, str) end
else
for i = 1, band.GetCount() do band.SetStrength(i, str) end
end
wig("wb", 5) Check()
save.Quicksave(70)
recentbest.Restore() Check()
save.Quickload(70)
if (ss - score() >= loss) or (score() > bestscore + 5) then
if band.GetCount() > (nSegs / 10) * 2 then
lastBS = str - 0.1
if lastBS < minBS then lastBS = minBS end
else
lastBS = minBS end
break end
end
end
function BandTest()
if band.GetCount() > 0 then
band.EnableAll()
if CBe or (wb and (not BF)) then DisRdm() end
setCI(cival * 0.9)
if SHK then bandpull(5, 5.3) else bandpull(0.2, 3) end
Delbands()
recentbest.Save()
Check()
if muta then
save.Quicksave(93)
setCI(math.random(10, cival * 100) / 100)
structure.MutateSidechainsAll(1) Check()
setCI(cival)
wig() Check()
setCI(cival / 2)
wig("wa", 5) Check()
setCI(cival)
wig() Check()
wig("s") Check()
wig() Check()
save.Quickload(93) end
wig("s") Check()
Test()
end end
function QuakeOnce()
local dd = math.floor((nSegs - lockd) / 7)
repeat
local start = math.random(dd)
local len = math.floor(math.random((nSegs - dd) / 2) + dd)
local step = math.floor(math.random((nSegs - dd) / 2) + dd)
for x = start, nSegs, step do
for y = start + len, nSegs, step do
if (y <= nSegs) and (isMovable(y, y) or isMovable(x, x)) then band.AddBetweenSegments(x, y) end
end end
until (band.GetCount() + oldbands) > (oldbands + 3)
BandTest() end
function BandAllContacts()
for y = 1, nSegs - 2 do
for j = y + 2, nSegs do
HT = contactmap.GetHeat(y, j)
if HT >= 0.75 then lb = band.AddBetweenSegments(y, j)
band.SetGoalLength(lb, band.GetLength(lb) * (1 - HT)) end
end
end
Cbds = band.GetCount()
save.Quicksave(20)
end
function BandSelectedContacts()
for y = 1, nSegs do
for j = 1, #selList do
if (structure.GetDistance(y, selList[j]) <= 10) and (structure.GetDistance(y, selList[j]) >= 4) then
if contactmap.GetHeat(y, selList[j]) ~= 0 then lb = band.AddBetweenSegments(y, selList[j])
band.SetGoalLength(lb, band.GetLength(lb) * (1 - contactmap.GetHeat(y, selList[j]))) end end
end
end
end
function bandage()
bloat = false
if (cival >= 0.9) and not CB then
RM = math.random(-100, 100)
if RM >= 0 then bloat = false
else bloat = true end
end
if bloat then
for i = 1, band.GetCount() do
if band.GetStrength(i) < 10 then
band.SetGoalLength(i, band.GetLength(i) + 4) end
end
else
for i = 1, band.GetCount() do
local leng = band.GetLength(i)
local perc = math.random(20, 50)
local loss = ((perc * leng) / 100)
if band.GetStrength(i) < 10 then
band.SetGoalLength(i, band.GetLength(i) - loss) end
end
end
end
function spacebands(amnt)
local zeBands = math.random(amnt) + Qbands
if zeBands < 1 then zeBands = 1 end
while band.GetCount() < zeBands do
repeat segO = math.random(nSegs)
until not structure.IsLocked(segO)
if SHK then
rho = 0.2 else
rho = math.random(10) end
theta = math.random(100, 314.159) / 100
phi = math.random(100, 314.159) / 100
if phi < 1 then phi = phi + 1 end
if theta < 1 then theta = theta + 1 end
if segO <= nSegs and segO >= 1 then
if segO == nSegs then
segX = segO - 1
segY = segO - 2
elseif segO == 1 then
segX = segO + 1
segY = segO + 2
else
segX = segO - 1
segY = segO + 1
end
if segX > nSegs then segX = nSegs - 1 end
if segY > nSegs then segY = nSegs - 1 end
if segY < 1 then segY = 1 end
if segX < 1 then segX = 1 end
-- p(segX,"X",segY,"Y",segO,"O",theta,"theta",phi,"phi")
local lb = band.Add(segO, segX, segY, rho, theta, phi)
if SHK then
band.SetGoalLength(lb, math.random(1))
else
band.SetGoalLength(lb, math.random(band.GetLength(lb) * 2))
end end end end
function BiSs()
if Combo == false then
if BiS then
for i = 1, 2 do
spacebands((nSegs - lockd) / 2)
BandTest()
end
end -- bis
end -- combo
if Shock then
SHK = true
for u = 1, 2 do
spacebands((nSegs - lockd) / 2)
BandTest()
end
SHK = false
end end
function BandAcross()
for i = 1, nSegs do
if not structure.IsLocked(i) then first = i break end end
for u = nSegs, 1, -1 do
if not structure.IsLocked(u) then last = u break end end
band.AddBetweenSegments(first, last)
bandage()
BandTest()
band.AddBetweenSegments(nSegs / 2, first)
band.AddBetweenSegments(nSegs / 2, last)
bandage()
BandTest()
end
function Quaker()
if Combo then
for i = 1, 4 do
nrR = math.random(1, 19)
for u = 1, nrR do
repeat
seg1 = math.random(1, nSegs)
seg2 = math.random(1, nSegs)
until (seg1 ~= seg2) and (not structure.IsLocked(seg1) or not structure.IsLocked(seg2))
band.AddBetweenSegments(seg1, seg2)
end
bandage()
Qbands = band.GetCount()
spacebands(10)
BandTest()
end
else
for i = 1, 2 do
nrR = math.random(1, 19)
for u = 1, nrR do
repeat
seg1 = math.random(1, nSegs)
seg2 = math.random(1, nSegs)
until (seg1 ~= seg2) and (not structure.IsLocked(seg1) or not structure.IsLocked(seg2))
band.AddBetweenSegments(seg1, seg2)
end
bandage()
BandTest()
end -- quake
end -- combo
end
---- Container
function main()
init()
if lockd < nSegs - 2 then dia() else return end
if DisFil then behavior.SetSlowFiltersDisabled(true) end
Delbands()
if KBE then band.EnableAll() end
if PrB then ZLBandSS(SS)
oldbands = band.GetCount()
KB, KBE = true, true end
if ShSt then SheetStitcher()
oldbands = band.GetCount()
KB, KBE = true, true end
save.Quicksave(1)
save.Quicksave(2)
save.Quicksave(20)
recentbest.Save()
startscore = score()
bestscore = startscore
p(string.format(" Startscore: %.4f",startscore))
p(" Best score in quicksave slot 1, start in slot 2 ")
p(" maxCI = " .. cival, " Start time:", os.date("%X"))
p("")
if ide then
if not tid then Idia() end end
if BF then BFdia() end
if sim then simul() end
if selR then selReb() end
if rr then RR() end
if RMX then Remix() end
if cuts then Cuts() end
if ide then Ide() end
if NTW then NetwTest() end
if randr then ran() end
if CB then ContactBander() end
if wb then WorkExBands() end
if BF then BFuze() end
Result()
end
--[[
Toolbox includes:
-Zero Length Bands, this helps to preserve your general structure and severely limits rebuilds (remix seems unaffected though the subsequent wiggles will get things back in place);
-Rebuilders, Rainbow whole structure or Selected residues only;
-a Remix routine, selected residues only;
-a Cut and Wiggle routine, selected residues only or worst backbone scores and all loops;
-an Idealize routine, selected residues only or worst scoring ('ideality') only or whole structure variable length with the option to use cutpoints;
-a Rotamer Tester, selected residues only (recommended) or all polar residues (hydrophilics + TYR & TRYP), tries all rotamers of current sidechain and local wiggles;
-and bruteforce polar AAs, while testing their rotamers (very lengthy), if you pick the right residues this will do wonders for finding HBonds,
e.g.: a network is <75% satisfied -> select promising nearby residues (and/or those already contributing to the network) and run;
-Contact Bander, bands all contacts with a heat >=0.75 and runs WorkExBands or BandFuze;
-Work Existing Bands, randomly disables/enables bands and quakes the structure (needs user created bands, more bands = more profit);
-BandFuze, creates random bands and quakes the structure.
----
If multiple Actions are checked they will happen in consecutive order, top to bottom, as displayed in the dialog (unless loop forever negates this).
A single pull of Contact Bander and/or Quick Quake happen after the stabilization wiggles if checked.
Random rebuilds/remix, Contact Bander, Work Exist. Bands and BandFuze loop forever until cancelled.
----
If 'Disable filters during operations' is unchecked, recipe will not touch the filters and leave them as is;
this can be used to run the recipe with only 1 filter enabled, or to keep any filter bonus from locking up the structure, etc.
If it is checked, all filters will be enabled to check score, and disabled during any and all other operations.
Has no effect on puzzles without filters, just ignore the option.
]]
err = xpcall(main, End)