Profile
- Name
- Electron Density kick-off User WP
- ID
- 108261
- Shared with
- Public
- Parent
- Electron Density kick-off
- Children
- None
- Created on
- April 27, 2023 at 19:25 PM UTC
- Updated on
- April 27, 2023 at 19:38 PM UTC
- Description
1. Reduced importance of H-Bonds to get better fit to the cloud.
2. Normalise H-Bond importance and cycle W/S to improve score.
3. Use your normal polishing tricks after that.
4. *Do not* re-run the script once you have made further improvements, like indealise or rebuild. It will only make it worse. This is just to give a good starting position while you get a coffee.1st attempt at a script, automating tedious start to electron density puzzles.
Be gentle.
Best for
Code
-- 1st attempt at a script, automating tedious start to electron density puzzles
-- User's wiggel power at start. Default option start with shake tehn wiggle.
recipename= "Electron Density kick-off User WP v0.1"
local ask = dialog.CreateDialog("Electron Density - start of puzzle")
ask.revertWiggleStrength = dialog.AddCheckbox("Wiggle strenth Auto when finished?", false)
ask.StartWithShake = dialog.AddCheckbox("Start with shake", true)
ask.instructionsIterations = dialog.AddLabel("Iters before checking for improvement per cycle")
ask.wiggleIterations = dialog.AddSlider("Wiggle Iters", 7, 1, 20, 0)
ask.shakeIterations = dialog.AddSlider("Shake Iters", 3, 1, 10, 0)
ask.instructionsMinimums = dialog.AddLabel("Minimum improvements to break out of each cycle")
ask.wiggleImprovement = dialog.AddSlider("Wiggle Min", 0.1, 0.01, 20, 3)
ask.shakeImprovement = dialog.AddSlider("Shake Min", 0.01, 0.001, 5, 3)
ask.cycleImprovement = dialog.AddSlider("Cycle Min", 0.1, 0.01, 20, 3)
ask.OK = dialog.AddButton("OK", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
if (dialog.Show(ask) > 0) then
StartWithShake=ask.StartWithShake.value
wiggleIterations = ask.wiggleIterations.value
shakeIterations = ask.shakeIterations.value
revertWiggleStrength = ask.revertWiggleStrength.value
wiggleImprovement = ask.wiggleImprovement.value
shakeImprovement = ask.shakeImprovement.value
cycleImprovement = ask.cycleImprovement.value
end
print ("wiggleIterations ="..wiggleIterations)
print ("shakeIterations ="..shakeIterations)
print ("wiggleImprovement ="..wiggleImprovement)
print ("shakeImprovement ="..shakeImprovement)
print ("cycleImprovement ="..cycleImprovement)
-- Set behavior to 'best fit' the cloud
behavior.SetClashImportance(1)
behavior.SetBackboneHBondImportance(0)
behavior.SetSidechainHBondImportance(0)
-- behavior.SetWigglePower("h")
function DoWiggle()
-- Keeps going while improvement up to dialogue spec wiggles
local recentBest = recentbest.GetEnergyScore()
local startingScore = current.GetEnergyScore()
for i=1, 200 do -- 200 to stop infinite loop to an asymptote
-- Measure the improvement from one wiggle
local loopStartScore = current.GetEnergyScore()
structure.WiggleAll(wiggleIterations)
local loopEndScore = current.GetEnergyScore()
-- Break if we stop making progress
if (loopEndScore - loopStartScore < wiggleImprovement) then
break
end
-- Let everyone know what's happening
print ("DoWiggle improvement:"..loopEndScore)
end
return current.GetEnergyScore() > recentBest
end
function DoShake()
-- Keeps going while improvement up to 20 shakes
local recentBest = recentbest.GetEnergyScore()
local startingScore = current.GetEnergyScore()
for i=1, 200 do -- 200 to stop infinite loop to an asymptote
-- Measure the improvement from one shake
local loopStartScore = current.GetEnergyScore()
structure.ShakeSidechainsAll(shakeIterations)
local loopEndScore = current.GetEnergyScore()
-- Break if we stop making progress
if (loopEndScore - loopStartScore < shakeImprovement) then
break
end
-- Let everyone know what's happening
print ("DoShake improvement: "..loopEndScore)
end
return current.GetEnergyScore() > recentBest
end
function DoCycle()
-- Switches back and forth between wiggle and shake while improvement
local recentBest = recentbest.GetScore()
local startingScore = current.GetEnergyScore()
for i=1, 200 do -- 200 to stop infinite loop to an asymptote
-- Measure improvement from one cycle
local loopStartScore = current.GetEnergyScore()
if StartWithShake then
DoShake()
end
DoWiggle()
if not StartWithShake then
DoShake()
end
local loopEndScore = current.GetEnergyScore()
-- Break if we stop making progress
if (loopEndScore - loopStartScore < cycleImprovement) then
break
end
-- Let everyone know what's happening
print ("DoCycle improvement: "..i.." "..loopEndScore)
end
return current.GetEnergyScore() > recentBest
end
-- Loose munge to the cloud shape
print ("Do the cloud-fit bit, not worrying about score")
DoCycle()
-- Restore normal behavior
behavior.SetBackboneHBondImportance(1)
behavior.SetSidechainHBondImportance(1)
-- Get some points
print ("Do the get points bit")
DoCycle()
if revertWiggleStrength then
behavior.SetWigglePower("a")
print ("Wiggle strength set to Auto")
else
print ("Wiggle strength left as user's")
end
print ("Electron density kick-off wiggles and shakes complete.")
print ("Do not re-run once you've improved from here - it will make it worse.")
print ("Over to you.")