Profile
- Name
- Electron Density kick-off v0.2
- ID
- 108257
- Shared with
- Public
- Parent
- Electron Density kick-off
- Children
- Created on
- April 23, 2023 at 02:50 AM UTC
- Updated on
- April 29, 2023 at 01:46 AM UTC
- Description
This recipe:
1. Reduces importance of H-Bonds, alters wiggle strength and cycles W/S to get better fit to the cloud, then
2. Normalises H-Bond importance and cycles W/S to improve score.Use your normal polishing tricks after that.
*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.
v1.1
* Altered the default dialogue values for improvement-check to account for differently sized puzzles. Puzzle https://fold.it/puzzles/2013609 (~200 segments) ran in about 45 minutes on my ancient i5 and left me about mid-field 29,589 points before other work.
* Better commenting in code.
* Cosmetic fixes.
Best for
Code
-- Automating tedious start to electron density puzzles
recipename= "Electron Density kick-off v0.2"
-- Adjust default values based on puzzle segment count
segmentCount = structure.GetCount()
defWiggle = segmentCount / 100
defShake = segmentCount / 1000
defCycle = segmentCount / 200
local ask = dialog.CreateDialog("Electron Density - start of puzzle")
ask.revertWiggleStrength = dialog.AddCheckbox("Wiggle strenth Auto when finished?", false)
ask.instructionsIterations = dialog.AddLabel("Iters before checking for improvement")
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 before break out")
ask.wiggleImprovement = dialog.AddSlider("Wiggle Min", defWiggle, 0.1, 100, 2)
ask.shakeImprovement = dialog.AddSlider("Shake Min", defShake, 0.01, 10, 2)
ask.cycleImprovement = dialog.AddSlider("Cycle Min", defCycle, 0.1, 100, 2)
ask.OK = dialog.AddButton("OK", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
if (dialog.Show(ask) > 0) then
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 ("Puzzle size = "..segmentCount)
print ("wiggleIterations = "..wiggleIterations)
print ("shakeIterations = "..shakeIterations)
print ("wiggleImprovement breakout = "..wiggleImprovement)
print ("shakeImprovement breakout = "..shakeImprovement)
print ("cycleImprovement breakout = "..cycleImprovement)
-- Set behavior to 'best fit' the cloud
behavior.SetClashImportance(1)
behavior.SetBackboneHBondImportance(0)
behavior.SetSidechainHBondImportance(0)
behavior.SetWigglePower("h")
function DoWiggle()
-- Keeps looping while improvement better than dialogue spec
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 set
local loopStartScore = current.GetEnergyScore()
structure.WiggleAll(wiggleIterations)
local loopEndScore = current.GetEnergyScore()
-- Break if improvement less than dialogue spec for wiggles
if (loopEndScore - loopStartScore < wiggleImprovement) then
break
end
-- Let everyone know what's happening
print ("DoWiggle "..i.." done, now:"..loopEndScore)
end
return current.GetEnergyScore() > recentBest
end
function DoShake()
-- Keeps looping while improvement better than dialogue spec
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 set
local loopStartScore = current.GetEnergyScore()
structure.ShakeSidechainsAll(shakeIterations)
local loopEndScore = current.GetEnergyScore()
-- Break if improvement less than dialogue spec for shakes
if (loopEndScore - loopStartScore < shakeImprovement) then
break
end
-- Let everyone know what's happening
print ("DoShake "..i.." done, now: "..loopEndScore)
end
return current.GetEnergyScore() > recentBest
end
function DoCycle()
-- Switches back and forth between wiggle and shake while improvement better than dialogue spec
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()
DoWiggle()
DoShake()
local loopEndScore = current.GetEnergyScore()
-- Break if improvement less than dialogue spec for cycles
if (loopEndScore - loopStartScore < cycleImprovement) then
break
end
-- Let everyone know what's happening
print ("DoCycle "..i.." end: "..loopEndScore)
end
return current.GetEnergyScore() > recentBest
end
-- Loose munge to the cloud shape
print ("Starting the cloud-fit bit, not worrying about score")
DoCycle()
-- Restore normal behavior
behavior.SetBackboneHBondImportance(1)
behavior.SetSidechainHBondImportance(1)
-- Get some points
print ("Time to get some points!")
DoCycle()
if revertWiggleStrength then
behavior.SetWigglePower("a")
print ("Wiggle strength reset to Auto")
else
print ("Wiggle strength left on High")
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.")