Profile
- Name
- Mutate Frozen 1.0 -- Brow42
- ID
- 47609
- Shared with
- Public
- Parent
- None
- Children
- None
- Created on
- December 27, 2013 at 00:12 AM UTC
- Updated on
- December 27, 2013 at 00:12 AM UTC
- Description
For ORIGINAL interface users. Mutates any frozen segments until cancelled. Intial state can be found at the end of the undo table.
Best for
Code
--[[ Mutate Frozen
* Freeze one section, it will mutate it
* For orginal interface
* Original unmutated conformation will be placed
* at the end of the undo table
* Version 1.0 12/26/2013 Brow42
--]]
-- Find contiguous blocks of frozen or selected segments
-- Idea is that original interface users will freeze segments
-- Args are whether to look for frozen or selected or both (default)
ERROR_BOTH = -1
function FindSelected(select_frozen, select_selection)
select_frozen = select_frozen == nil and false or select_frozen
select_selection = select_selection == nil and false or select_selection
local appending = false
local f,s,e
local range
local list = {}
local seen_f, seen_s = false,false
for i = 1, structure.GetCount() do
f,s = select_frozen and freeze.IsFrozen(i), select_selection and selection.IsSelected(i)
seen_f, seen_s = f or seen_f, s or seen_s
if seen_s and seen_f then return ERROR_BOTH end
if (f or s) then
if appending then range[2] = i
else
range = {i,i}
list[#list+1] = range
appending = true
end
else
if appending then appending = false end
end
end
return list
end
-- Add a wall of text from a table
function dialog.AddLabels(d,msg,nlabels) -- pass in # of existing autolabels
local nlabels = nlabels or #(d._Order or {}) -- default, valid if never delete dialog elements
if type(msg) == 'string' then
msg = { msg }
end
for i = 1,#msg do
d['autolabel'..tostring(i+nlabels)] = dialog.AddLabel(msg[i])
end
end
-- Create but don't display a wall of text and 1 or 2 buttons
function dialog.CreateMessageBox(msg,title,buttontext1,buttontext0)
title = title or ''
local d = dialog.CreateDialog(title)
dialog.AddLabels(d,msg)
buttontext1 = buttontext1 or 'Ok'
d.button = dialog.AddButton(buttontext1,1)
if buttontext0 ~= nil then d.button0 = dialog.AddButton(buttontext0,0) end
return d
end
-- Display a dialog box
function dialog.ShowMessageBox(msg,title,buttontext1,buttontext0)
return dialog.Show(dialog.CreateMessageBox(msg,title,buttontext1,buttontext0))
end
-- ================ Begin Main =====================
-- Find groups of frozen segments (ignore selections)
list = FindSelected(true,false)
-- This won't happen because we are ignoring selections
if list == ERROR_BOTH then
print("Used both selection and freezing")
rc = dialog.ShowMessageBox("Used both selection and freezing. Clear both?","Oops","Yes","No")
if rc == 1 then
freeze.UnfreezeAll()
selection.DeselectAll()
end
return
end
if #list == 0 then
print("Nothing selected")
dialog.ShowMessageBox("Nothing selected.","Oops","Okay")
return
end
-- No need to be limited to a single contigous group for mutation
--[[
if #list ~= 1 then
print("Need exactly one selection.")
dialog.ShowMessageBox("Need exactly one selection.","Oops","Okay")
return
end
--]]
save.Quicksave(100)
freeze.UnfreezeAll()
selection.DeselectAll()
for i = 1,#list do
selection.SelectRange(list[i][1],list[i][2])
end
-- Routine called on cancel or error
function OnError(err)
if err:find('Cancel') then
print('Cancelled')
selection.DeselectAll()
else print('Error: ',err)
end
print("Inserting initial fold into undo table")
save.Quicksave(99)
save.Quickload(100)
save.Quickload(99)
return err
end
xpcall( function() structure.MutateSidechainsSelected(1000) end, OnError )