Profile
- Name
- Secondary Structure
- ID
- 104686
- Shared with
- Public
- Parent
- None
- Children
- None
- Created on
- March 25, 2021 at 16:14 PM UTC
- Updated on
- March 25, 2021 at 16:14 PM UTC
- Description
Secondary Structure
Best for
Code
function Cleanup ( errmsg )
p("Cleanup")
if CLEANUPENTRY ~= nil then
return
end
CLEANUPENTRY = true
print ( "---*****" )
local reason
local start, stop, line, msg
if errmsg == nil then
reason = "complete"
else
--
-- civilized error reporting,
-- thanks to Bruno K. and Jean-Bob
--
start, stop, line, msg = errmsg:find ( ":(%d+):%s()" )
if msg ~= nil then
errmsg = errmsg:sub ( msg, #errmsg )
end
if errmsg:find ( "Cancelled" ) ~= nil then
reason = "cancelled"
else
reason = "error"
end
p(errmsg)
p(reason)
p( "Puzzle: " .. puzzle.GetName () )
p( "Track: " .. ui.GetTrackName () )
p( "Error line: " .. line )
end
print ( ReVersion .. " " .. reason )
print ( "Puzzle: " .. puzzle.GetName () )
print ( "Track: " .. ui.GetTrackName () )
if reason == "error" then
print ( "Unexpected error detected" )
print ( "Error line: " .. line )
print ( "Error: \"" .. errmsg .. "\"" )
end
save.Quickload ( QS_Best )
PrintState ()
SetCI ( 1.0 )
selection.DeselectAll ()
ManageBands ()
end
function Initial()
-- p("Initial")
Iterations=6
Start=115
Stop=197
InitialFlag="Y"
behavior.SetClashImportance(0)
behavior.SetSidechainHBondImportance(1)
behavior.SetBackboneHBondImportance(1)
MainDialog = dialog.CreateDialog("Main")
end
function Initialise()
p("Initialise")
puzzle.StartOver()
band.DeleteAll()
selection.DeselectAll()
Main()
end
function Forward()
p("Forward")
SecondaryStructureFunction()
end
function Main()
p("Main")
if InitialFlag ~= "Y" then
Initial()
InitialFlag = "Y"
end
PopulateMain()
local choice = dialog.Show(MainDialog)
Start = MainDialog.SeqStartSlider.value
Stop = MainDialog.SeqStopSlider.value
Iterations = MainDialog.IterationsSlider.value
if (choice == 0) then
print("Cancelled")
elseif choice==1 then
Initialise()
elseif choice==2 then
Forward()
end
if choice ~=0 then
Main()
end
end
function SecondaryStructureFunction()
p("SecondaryStructure")
SegmentCount = Stop - Start + 1
Score = math.floor(current.GetEnergyScore())
p("Initial Score: "..Score)
for i = 1,Iterations,1 do
SegmentRandom = Start + math.random(SegmentCount) - 1
selection.Select(SegmentRandom)
SecondaryStructureRandom = math.random(3)
SecondaryStructureOld = structure.GetSecondaryStructure(SegmentRandom)
if SecondaryStructureRandom == 1 then SecondaryStructure = "H" end
if SecondaryStructureRandom == 2 then SecondaryStructure = "E" end
if SecondaryStructureRandom == 3 then SecondaryStructure = "L" end
structure.SetSecondaryStructure(SegmentRandom,SecondaryStructure)
structure.WiggleSelected(1)
newscore = math.floor(current.GetEnergyScore())
if (newscore > Score) then
p(i..") Seg: "..SegmentRandom.." from "..SecondaryStructureOld.." to "..SecondaryStructure.." Score: "..math.floor(newscore))
save.Quicksave(3)
end
save.Quickload(3)
selection.DeselectAll()
end
p("Secondary Structure")
p("Finished")
end
function PopulateMain()
--p("PopulateMain")
MainDialog.IterationsSlider = dialog.AddSlider("Iterations",Iterations,0,100,0)
MainDialog.SeqStartSlider = dialog.AddSlider("Start Segment",Start,0,200,0.1)
MainDialog.SeqStopSlider = dialog.AddSlider("Stop segment",Stop,0,200,0.1)
MainDialog.InitialiseButton = dialog.AddButton("Initialise", 1)
MainDialog.ForwardButton = dialog.AddButton("Forward", 2)
MainDialog.BackButton = dialog.AddButton("Back", 3)
MainDialog.CancelButton = dialog.AddButton("Display Macro", 0)
end
function p(str)
print(str)
end
xpcall(Main, Cleanup)