Profile
- Name
- IdealizeWalker
- ID
- 103643
- Shared with
- Public
- Parent
- None
- Children
- Created on
- June 26, 2020 at 03:23 AM UTC
- Updated on
- June 26, 2020 at 03:23 AM UTC
- Description
Selects each group of secondary structures (helix or sheet) and the surrounding loops one at a time. For each selected, idealizes the peptide bonds and then runs wiggle.
Best for
Code
segCount = structure.GetCount()
disableFilters = true
shakeOut = false
previouslySelected = {}
startScore = 0
function previouslySelected.Set()
previouslySelected.Data = {}
for segment = 1, segCount do
if selection.IsSelected(segment) then
previouslySelected.Data[#previouslySelected.Data + 1] = segment
end
end
end
function previouslySelected.Restore()
selection.DeselectAll()
for segment = 1, #previouslySelected.Data do
selection.Select(previouslySelected.Data[segment])
end
end
function setFiltersDisabled(state) -- Set filters state, but only if user has asked the script to control filters
if disableFilters then
behavior.SetFiltersDisabled(state)
end
end
function getScore() -- Calculate the score, enable/disable filters if asked to
local score = 0
setFiltersDisabled(false)
score = current.GetEnergyScore()
setFiltersDisabled(true)
return score
end
function settingsMenu() -- Show settings
local settings = dialog.CreateDialog("Settings")
local userChoice = 0
settings.shake = dialog.AddCheckbox("Shake out after First Wiggle?", shakeOut)
settings.filters = dialog.AddCheckbox("Disable Filters?", disableFilters)
settings.ok = dialog.AddButton("OK", 1)
settings.cancel = dialog.AddButton("Cancel", 0)
userChoice = dialog.Show(settings)
-- Update settings from dialog
shakeOut = settings.shake.value
disableFilters = settings.filters.value
return userChoice
end
function findFirstNonLoop() -- Find the firt segment in the protein that is not a loop
for segment = 1, segCount do
local ss = structure.GetSecondaryStructure(segment)
if ss == "E" or ss == "H" then
return segment
end
end
return nil
end
function findSSRange(startSegment, searchBackwards)
-- Determine the range of segements where the protein SS stays the same as the provided starting segment
-- Optionally allows the user search backwards instead of forwards.
searchBackwards = searchBackwards or false
-- Find starting segemnt SS
local startSS = structure.GetSecondaryStructure(startSegment)
if searchBackwards then
-- Look through the protein (moving backwards), untill the SS type changes, then return the range where it did not
for segment = startSegment, 1, -1 do
if structure.GetSecondaryStructure(segment) ~= startSS then
return {startSegment, segment + 1}
end
end
return {1, startSegment}
else
-- Look through the protein (moving forwards), untill the SS type changes, then return the range where it did not
for segment = startSegment, segCount do
if structure.GetSecondaryStructure(segment) ~= startSS then
return {startSegment, segment - 1}
end
end
return {startSegment, segCount}
end
end
function findSSLoopRange(ssRange)
local totalRange = {}
-- Look for end of loop before SS. But if SS range starts at protein start, set start of range to 1
if ssRange[1] == 1 then
totalRange[1] = 1
else
for segment = ssRange[1] - 1, 1, -1 do
if structure.GetSecondaryStructure(segment) ~= "L" then
totalRange[1] = segment + 1
break
elseif segment == 1 then
totalRange[1] = 1
end
end
end
-- Look for end of loop after SS, but if SS range ends at protein stop, set end of range to protein length
if ssRange[2] == segCount then
totalRange[2] = segCount
else
for segment = ssRange[2] + 1, segCount do
if structure.GetSecondaryStructure(segment) ~= "L" then
totalRange[2] = segment - 1
break
elseif segment == segCount then
totalRange[2] = segCount
end
end
end
return totalRange
end
function findAllRanges()
local startSS = findFirstNonLoop()
local regions = {startSS}
local i = 1
while true do
regions[i] = findSSLoopRange(findSSRange(regions[i]))
if regions[i][2] ~= segCount then
regions[i + 1] = regions[i][2] + 1
else
break
end
i = i + 1
end
return regions
end
function main()
-- Set the list of segments the user has already selected
previouslySelected.Set()
-- Save new recent best
recentbest.Save()
-- Get the starting score
startScore = getScore()
-- Show the settings dialog
userChoice = settingsMenu()
if userChoice > 0 then
-- Find all of the regions that we will idealize
regions = findAllRanges()
-- Iterate through all of the found regions.
for i = 1, #regions do
-- Select the region
selection.DeselectAll()
selection.SelectRange(regions[i][1], regions[i][2])
-- Idealize the region
structure.IdealizeSelected()
-- Wiggle and Shake the region
structure.WiggleAll(25, true, true)
if shakeOut then
structure.ShakeSidechainsAll(2)
structure.WiggleAll(25, true, true)
end
print("Finished Region "..i.." of "..#regions..".")
-- Update the score, possibly including filters, so recentbest is correct
getScore()
recentbest.Restore()
end
end
cleanup("Recipe Done")
end
function pause()
x = dialog.CreateDialog('x')
x.button = dialog.AddButton('OK', 1)
dialog.Show(x)
end
function cleanup(errorMsg)
errorMsg = errorMsg or "" -- Make the argument optional, default is an empty string
if string.find(errorMsg, "Cancelled") then
print("User Cancelled")
else
print(errorMsg)
end
recentbest.Restore()
previouslySelected.Restore()
print("Total Gain: " .. getScore() - startScore)
setFiltersDisabled(false)
end
xpcall(main, cleanup)