Icon representing a recipe

Recipe: Restore State

created by latin krepin

Profile


Name
Restore State
ID
108607
Shared with
Public
Parent
Restore State
Children
None
Created on
March 21, 2024 at 07:48 AM UTC
Updated on
March 23, 2024 at 11:03 AM UTC
Description

Restores frozens, secondary structure and bands from chosen save slot.

Best for


Code


saveSlot=2 restoreStructs=true restoreFrozens=true restoreBands=true TOTAL_SEGMENTS=structure.GetCount() bands={} frozens={} secondary_structure={} function GetBands() for i=1, band.GetCount() do bands[i] = {band.GetResidueBase(i), band.GetResidueEnd(i)} end end function RestoreSecondaryStructure() for i=1, TOTAL_SEGMENTS do structure.SetSecondaryStructure(i, secondary_structure[i]) end end function GetStruct() for i=1, TOTAL_SEGMENTS do secondary_structure[i]=structure.GetSecondaryStructure(i) end end function GetFrozens() for i=1, TOTAL_SEGMENTS do b, s=freeze.IsFrozen(i) if b or s then table.insert(frozens, {i, b, s}) end end end function RestoreFrozens() for i=1, #frozens do freeze.Freeze(frozens[i][1], frozens[i][2], frozens[i][3]) end end function RestoreBands() for i=1, #bands do band.AddBetweenSegments(bands[i][1], bands[i][2]) end end function main() AskOptions() save.Quicksave(1) save.Quickload(saveSlot) if restoreBands then GetBands() end if restoreStructs then GetStruct() end if restoreFrozens then GetFrozens() end save.Quickload(1) if restoreBands and #bands>0 then RestoreBands() end if restoreStructs then RestoreSecondaryStructure() end if restoreFrozens and #frozens>0 then RestoreFrozens() end end function AskOptions() local ask=dialog.CreateDialog('Restore State') ask.l2=dialog.AddLabel('Choose a save slot from 1-99') ask.saveSlot=dialog.AddSlider('Save slot', saveSlot, 2, 99, 0) ask.restoreStructs=dialog.AddCheckbox('Restore structs', restoreStructs) ask.restoreFrozens=dialog.AddCheckbox('Restore frozens', restoreFrozens) ask.restoreBands=dialog.AddCheckbox('Restore bands', restoreBands) ask.OK = dialog.AddButton("OK",1) ask.Cancel = dialog.AddButton("Cancel",0) if dialog.Show(ask)>0 then saveSlot=ask.saveSlot.value restoreStructs=ask.restoreStructs.value restoreFrozens=ask.restoreFrozens.value restoreBands=ask.restoreBands.value end end main()

Comments