Profile
- Name
- iwdn_wrs_1.0
- ID
- 108488
- Shared with
- Public
- Parent
- wrs_MS_01f
- Children
- Created on
- November 15, 2023 at 20:42 PM UTC
- Updated on
- November 15, 2023 at 20:42 PM UTC
- Description
Selects whole protein and rebuilds it in repeatable loops. Now with selection.
Saves best share to slot 1
12 rebuilds, with 6 repeats.
Enjoy all!
Best for
Code
-- wisky's Repeating Rebuild All!
-- Rebuilds whole protein of selected part in repeating loops.
-- Best scoring pose saved in quicksave slot 1
-- Temporary pose saved in quicksave slot 89
--1f:
--stabilization CIs can now be set via gui
--Variables:
NumberOfRebuilds=3 -- Number of Rebuilds per Retry
NumberOfRebuilds_max=30
NumberOfRetries=60 -- Number of Retries
NumberOfRetries_max=300
NumberOfRetries_min=10
NumberOfRetries2=3 --Outer Retry-loop (refinement-iteratiion)
NumberOfRetries2_max=10
Factor=0.5 --Decrement number of retries in each iter
CIw = {1, 1} --CIs for stabilization-wiggles; Best compromise: {1, 1}!
deltaThr = 0 --criterion for stopping the input wiggle-loop. 0: breaker off!
selStart = -1
selEnd = -1
wjbb = true --Wiggle just backbone
astr = true --Set everything to auto-structure before each retry
--Functions:
function mysplit(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
function Score() --return score
return current.GetEnergyScore()
end
function round3(inNum)
return inNum-inNum%0.001
end
function round(inNum)
return (math.floor(inNum+0.5))
end
function BlueFuse()
behavior.SetClashImportance(.05)
structure.ShakeSidechainsAll(1)
behavior.SetClashImportance(1)
if (wjbb == false) then
structure.WiggleAll(5)
else
structure.WiggleAll(5, true, false)
end
behavior.SetClashImportance(.07)
structure.ShakeSidechainsAll(1)
behavior.SetClashImportance(1)
if (wjbb == false) then
structure.WiggleAll(5)
else
structure.WiggleAll(5, true, false)
end
behavior.SetClashImportance(.3)
if (wjbb == false) then
structure.WiggleAll(8)
else
structure.WiggleAll(8, true, false)
end
behavior.SetClashImportance(1)
if (wjbb == false) then
structure.WiggleAll(15)
else
structure.WiggleAll(15, true, false)
end
end
function RebuildAll() -- Rebuild all loop, adapted from drjr's Randomizer
for j=1,NumberOfRebuilds do
print("Rebuild " .. j .. "/" .. NumberOfRebuilds .. " - Initial Score: " .. round3(Score()))
behavior.SetClashImportance(1) --Just to be safe
--Set all to autostructure if desired
if (astr == true) then
selection.SelectAll()
structure.SetSecondaryStructureSelected("A") --Set all to auto
end
selection.DeselectAll()
recentbest.Save() --Used for restore of very highest pointage at the end of each Rebuild.
selection.SelectRange(selStart, selEnd)
structure.RebuildSelected(1)
--It seems like doing multiple shake and wiggle before BF seems to work best.
--Made this input-fuze now completely programmable. Depending on what is done here, the quality of the solutions can be quite a bit improved.
--If the coefficients rise gradually, you can get the least "flying apart" of the backbone. But this may not be what scores best.
for a=1,#CIw do
local tmpScore = Score()
behavior.SetClashImportance(1)
structure.ShakeSidechainsAll(1)
behavior.SetClashImportance(CIw[a])
if (wjbb == false) then
structure.WiggleAll(10)
else
structure.WiggleAll(10, true, false)
end
local tmpScore2 = Score()
if ((tmpScore2 - tmpScore) < deltaThr) then
break
end
end
BlueFuse()
print("Rebuild " .. j .. "/" .. NumberOfRebuilds .. " - Final Score: " .. round3(Score()))
recentbest.Restore() --This MUST stand here and not before print(). Also, this ensures that in the NEXT rebuild, the very best previously found pose is used.
end
end
function Retry()
for a=1,NumberOfRetries2 do
--Increment of Retries
if a>1 and Factor ~= 1 then
NumberOfRetries = round(NumberOfRetries * Factor)
if NumberOfRetries < NumberOfRetries_min then
NumberOfRetries = NumberOfRetries_min
end
end
--MSadded: Second Retry-loop
--Idea: After a full loop of Retries is done, start another one with the previously found best solution as starting-pose (refinement).
--Execute this up to the given number of iterations. Like this, the best pose should automatically be found and refined.
save.Quickload(1) --MSadded: this should load the previously found best solution
save.Quicksave(89) --This is the starting-pose for the subsequent retry-loop. This will be used in EACH for each subsequent rebuild in this retry!
BestScore=Score()
print("-----------------------------------------------------------------------")
print("Starting new Retry-loop Iter: " .. a .. "/" .. NumberOfRetries2 .. " with Score: " .. round3(BestScore))
print("-----------------------------------------------------------------------")
for k=1,NumberOfRetries do
print("Started Retry: " .. k .. "/" .. NumberOfRetries .. ", Iter: " .. a .. "/" .. NumberOfRetries2)
save.Quickload(89)
RebuildAll()
if Score() > BestScore then
save.Quicksave(1)
BestScore=Score()
end
print("Finished Retry: " .. k .. "/" .. NumberOfRetries .. ", Iter: " .. a .. "/" .. NumberOfRetries2 .. ", Bestscore: " .. round3(BestScore))
--print("ScoreMS: " .. BestScore)
print("- - - - - - - - - -")
end
end
end
function main()
--MSadded: Dialog
dlg = dialog.CreateDialog("Wisky's Repeating Rebuild All")
dlg.wjbb = dialog.AddCheckbox("Wiggle just BB", wjbb)
dlg.nrb = dialog.AddSlider("Nr. of Rebuilds", NumberOfRebuilds, 1, NumberOfRebuilds_max, 0)
dlg.nrt = dialog.AddSlider("Nr. of Retries", NumberOfRetries, 1, NumberOfRetries_max, 0)
dlg.nrt2 = dialog.AddSlider("Nr. of Retries2", NumberOfRetries2, 1, NumberOfRetries2_max, 0)
dlg.fact = dialog.AddSlider("Retries Factor", Factor, 0, 1, 2) --2: 2 Nachkommastellen
dlg.nrt_min = dialog.AddSlider("Min Nr. of Retries", NumberOfRetries_min, 1, 50, 0)
dlg.astr = dialog.AddCheckbox("Use Autostructure", astr)
dlg.ciw = dialog.AddTextbox("CIs Wiggle", "1 1")
dlg.deltaThr = dialog.AddSlider("Breaker Delta", deltaThr, 0, 50, 0)
dlg.OK = dialog.AddButton("OK",1)
dlg.Cancel = dialog.AddButton("Cancel",0)
if(dialog.Show(dlg) > 0) then
wjbb = dlg.wjbb.value
NumberOfRebuilds = dlg.nrb.value
NumberOfRetries = dlg.nrt.value
NumberOfRetries2 = dlg.nrt2.value
Factor = dlg.fact.value
NumberOfRetries_min = dlg.nrt_min.value
astr = dlg.astr.value
CIw = mysplit(dlg.ciw.value, " ")
for m=1,#CIw do
CIw[m] = tonumber(CIw[m])
end
deltaThr = dlg.deltaThr.value
print("Wiggle just BB: " .. tostring(wjbb))
print("Number of Rebuilds: " .. NumberOfRebuilds)
print("Number of Retries: " .. NumberOfRetries)
print("Number of Retries2: " .. NumberOfRetries2)
print("Retries Factor: " .. Factor)
print("Min. Number of Retries: " .. NumberOfRetries_min)
print("Use Autostrucutre: " .. tostring(astr))
CIw_str = ""
for m=1,#CIw do
if m < #CIw then
CIw_str = CIw_str .. tostring(CIw[m]) .. " "
else
CIw_str = CIw_str .. tostring(CIw[m]) .. " "
end
end
print("CIs Wiggle: " .. CIw_str)
print("Breaker Delta: " .. deltaThr)
--print("ScoreMS: " .. Score())
else
print ("Cancelled!")
return
end
--If something is selected then use only this for rebuild. If nothing is selected then use all segments.
if (selection.GetCount() == 0) then
selection.SelectAll()
end
--Determine the start- and end-inndex of selcted range
segs = structure.GetCount() --total number of segments
for m=1,segs do
if selStart == -1 then
if (selection.IsSelected(m)) then
selStart = m
end
else
if selEnd == -1 then
if (selection.IsSelected(m) == false) then
selEnd = m-1
break
end
end
end
if m == segs then
selEnd = segs
end
end
--Now the range of the selection is determined. Use this in rebuild!
save.Quicksave(1) --MSadded for reload of initial pose after direct stop
Retry()
cleanup()
end
function cleanup()
behavior.SetClashImportance(1)
save.Quickload(1)
print("Recipe wrs has finished!")
end
xpcall(main, cleanup)
--main()