Code
-- converted to LUA V2
-- Aotearoa's Romance by Aotearoa aka Renton
-- Lua translation, x-functions and other extras by Crashguard303
-- adapted from Aot-Rom-Lua_V2.0.txt 11/2/12 by jeff101 by 247pm
-- to keep the best scores not just the last scores in each section
-- and to run repeatedly until it is forced to quit
--
-- last updated 1241pm noon 11/5/12 by jeff101
function xshake(iter,threshold,NumSegs,BestScore)
curr_iter=0
exit_condition=false
repeat
curr_iter=curr_iter+1
print(" Iteration# "..curr_iter.."/max "..iter.." in xshake.")
structure.ShakeSidechainsSelected(1)
BestScore,delta=ScoreCheck(BestScore)
if (iter>0) and (curr_iter>=iter) then exit_condition=true end
if delta<threshold then exit_condition=true end
until exit_condition==true
return BestScore
end -- function
function xwiggleall(iterAll,threshold,NumSegs,BestScore)
curr_iter=0
exit_condition=false
repeat
curr_iter=curr_iter+1
print(" Iteration# "..curr_iter.."/max "..iterAll.." in xwiggleall.")
structure.WiggleSelected(2,true,true)
BestScore,delta=ScoreCheck(BestScore)
if (iterAll>0) and (curr_iter>=iterAll) then exit_condition=true end
if delta<threshold then exit_condition=true end
until exit_condition==true
return BestScore
end -- function
function xwigglelocal(iterlocal,threshold,NumSegs,BestScore)
curr_iter=0
exit_condition=false
repeat
curr_iter=curr_iter+1
print(" Iteration# "..curr_iter.."/max "..iterlocal.." in xwigglelocal.")
structure.LocalWiggleSelected(1,true,true)
BestScore,delta=ScoreCheck(BestScore)
if (iterlocal>0) and (curr_iter>=iterlocal) then exit_condition=true end
if delta<threshold then exit_condition=true end
until exit_condition==true
return BestScore
end -- function
function xwigglelocal2(Start,NumSegs,Step,iterlocal,threshold,BestScore,frozenlist)
print("Local Wiggle in xwigglelocal2.")
for k=Start,NumSegs,Step do
if (k-Start)%Step==0 and frozenlist[k]==false then
print(" Segment: "..k.."/"..NumSegs.." in xwigglelocal2.")
selection.DeselectAll()
selection.Select(k)
BestScore=xwigglelocal(iterlocal,threshold,NumSegs,BestScore)
end -- if
end -- for k
return BestScore
end -- function
function ScoreCheck(BestScore)
-- changed 11/2/12 by jeff101 to keep the best score in each stage
-- stages don't necessarily end with the best score
-- recentbest.Restore() is needed to find the best score in each stage
oldscore=BestScore
newscore=current.GetScore() -- get current score
recentbest.Restore() -- restore best since last recentbest.Save()
topscore=current.GetScore() -- get current score
recentbest.Save() -- save best again
delta=topscore-oldscore
print(" Score just went from "..trunc3(oldscore).." to "..trunc3(topscore).." to "..trunc3(newscore)..",")
print(" so keeping "..trunc3(topscore).." with delta="..round3(delta)..".")
return topscore,delta
end -- function
-- below rounds val down to the nearest thousandth and returns the result
function trunc3(val)
return val-(val % 0.001)
end -- trunc3()
-- below rounds val to the nearest thousandth to get res
function round3(val)
local res=round(val*1000)/1000
return res
end -- round3()
-- below rounds val to the nearest integer to get res
function round(val)
local res=math.floor(val)
if val-res>=0.5 then
res=res+1
end
return res
end -- round()
function FlushList(list,NumSegs)
print("Unfreezing in FlushList.")
freeze.UnfreezeAll()
for k=1,NumSegs do
list[k]=false
end -- for k
return list
end -- function
function xfreeze(Start,NumSegs,Step,list)
print("Freezing in xfreeze.")
selection.DeselectAll()
for k=Start,NumSegs,Step do
if (k-Start)%Step==0 then
selection.Select(k)
list[k]=true
end -- if
end -- for k
freeze.FreezeSelected(true,true)
recentbest.Save()
return list
end -- function
function Romance(threshold,CI)
behavior.SetClashImportance(CI)
NumSegs=structure.GetCount()
frozenlist={}
frozenlist=FlushList(frozenlist,NumSegs)
recentbest.Save()
BestScore=current.GetScore()
print("Starting with "..NumSegs.." residues and score "..trunc3(BestScore)..".")
selection.SelectAll()
print("First Global Shake (1).")
structure.ShakeSidechainsSelected(1)
BestScore=ScoreCheck(BestScore)
print("First Global Wiggle.")
BestScore=xwiggleall(25,threshold,NumSegs,BestScore)
frozenlist=xfreeze(2,NumSegs,3,frozenlist)
BestScore=xwigglelocal2(2,NumSegs,2,17,threshold,BestScore,frozenlist)
frozenlist=FlushList(frozenlist,NumSegs)
save.SaveSecondaryStructure()
print("Just stored original secondary structure,\n now resetting secondary structure to all loops.")
selection.SelectAll()
structure.SetSecondaryStructureSelected("L")
recentbest.Save()
print("Second Global Shake (1).")
structure.ShakeSidechainsSelected(1)
BestScore=ScoreCheck(BestScore)
print("Second Global Wiggle.")
BestScore=xwiggleall(4,threshold,NumSegs,BestScore)
frozenlist=FlushList(frozenlist,NumSegs)
frozenlist=xfreeze(3,NumSegs,4,frozenlist)
recentbest.Save()
BestScore=xwigglelocal2(3,NumSegs,2,15,threshold,BestScore,frozenlist)
frozenlist=xfreeze(4,NumSegs,5,frozenlist)
recentbest.Save()
BestScore=xwigglelocal2(2,NumSegs,3,7,threshold,BestScore,frozenlist)
frozenlist=FlushList(frozenlist,NumSegs)
recentbest.Save()
selection.SelectAll()
print("Third Global Shake (1).")
structure.ShakeSidechainsSelected(1)
BestScore=ScoreCheck(BestScore)
print("Third Global Wiggle.")
BestScore=xwiggleall(25,threshold,NumSegs,BestScore)
print("Ending with score "..trunc3(BestScore)..".")
print("Restoring original secondary structure.")
save.LoadSecondaryStructure()
freeze.UnfreezeAll()
end -- function
function Main()
tryno=0
qflag=0
print(" \nWARNING: This script will run until you force it to quit.")
while qflag==0 do
tryno=tryno+1
print(string.format(" \nStarting Aot-Rom-Lua V2.3 loop %i at %s",tryno,os.date()))
Romance(0.0001,1)
end -- while qflag
end -- Main()
Main()