Code
--[[------------------------------------------------------------------------------------------------
-- This recipe is based on GAB loss, however attempts to band to space
REFERENCES
1. Rav3n_pl GAB v0.6 loss - http://fold.it/portal/recipe/34931
Copyright (C) 2014 Seagat2011 <http://fold.it/port/user/1992490>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
$Id$
------------------------------------------------------------------------------------------------]]--
--[[
v1
- inception
- New operator
v1.0
- rho/theta/phi band-angles functionality
- fixed band.Add parameter-list bug
v1.1
- centered viewport before wiggle
v1.2
- added ws after wb
- disabled recentbest.Restore ()
v1.3
- Nudge local area only (with local wiggle)
v1.4
- No Nudge
- wout 30 => 3 iters (performance)
v1.5
- Added ci awareness
- Added band.AddXBand
- Added sh after wb
- wout 3 => 10 iters (coverage)
v1.6
- fixed band.Add (x-segment-collision) bug
- re-enabled recentbest.Restore () (thresholded)
- Added SmartShake
- wout 10 => 3 (performance) + wout2 + wout (threshold)
v1.7
- GUI Added :)
]]--
local idx = 1
local idx2 = structure.GetCount ()
local cs = current.GetScore ()
local wout = 3
local wout2 = 2
local wout3 = 7
local thresh = 1 -- minppi (gain/threshold) to employ wout3 --
local PI_degrees = 180
local PI_degreeN = -180
local ZERO = 0
local percent = 30 -- percent ( 0 - 100 )
local neighbors = 12 -- structure.GetCount ()*percent*1e-2 -- Distance to nearest neighbors, measured in foldit units (fu) --
local rthresh = 500 -- reset threshold to recent/abs best pose --
local str = 'Anthropic Dreams Solution - ref#:'..puzzle.GetExpirationTime ()..user.GetPlayerID ()
local return_value = {
OK = 1,
HELP = 2,
CANCEL = 0
}
local status = 0
local ask = dialog.CreateDialog ( "Anthropic Dreams - XBander v1.7 " )
ask.l1 = dialog.AddLabel ( "Enter necessary values. ( if any )" )
ask.spacer03 = dialog.AddLabel ( '' )
ask.spacer04 = dialog.AddLabel ( '' )
ask.spacer05 = dialog.AddLabel ( '' )
ask.spacer06 = dialog.AddLabel ( '' )
ask.spacer07 = dialog.AddLabel ( '' )
ask.spacer08 = dialog.AddLabel ( '' )
ask.spacer09 = dialog.AddLabel ( '' )
ask.spacer10 = dialog.AddLabel ( '' )
ask.l4 = dialog.AddLabel ( [[ KEYWORDS: XBanderExecute()*,
BF_DuringStabilize(,)*,MutateDuringBF(,),
ShakeDuringBF()*,MutateInsteadOFShake(),
LWS_DuringStabilize(),BF_first*,
LWS_First,RestoreIfStopped()*,
MutateInsteadOFShakeDuringBF(),
EnableCrashRecovery(),IgnoreBands(,..)*,
DisableBands(,..),UseBands(,..),
DeleteBands(,..)*,EnableBandsAfterBF(,..),
EnableBandsDuringBF(,..),
EnableBandsBeforeBF(,..),
EnableBandsAfterStabilize(,..),
EnableBandsDuringStabilize(,..),
EnableBandsBeforeStabilize(,..),
IncludeFrozenSegments(,..)*,
IgnoreFrozenSegments(,..)
IncludeMutableSegments(,..)*,
IgnoreMutableSegments(,..),
IncludeAllStructures*,
IgnoreMotifs(),IgnoreHelices(,..),
IgnoreLoops(,..),PreserveStructures*,
ConvertStructuresToLOOP(,..),
ConvertStructuresToHELICES(,..),
ConvertStructuresToSHEET(,..)
SaveConfigurationOnExit()
* - Indicates default Settings ]] )
ask.spacer13 = dialog.AddLabel ( '' )
ask.spacer14 = dialog.AddLabel ( '' )
ask.spacer15 = dialog.AddLabel ( '' )
ask.spacer16 = dialog.AddLabel ( '' )
ask.spacer17 = dialog.AddLabel ( '' )
ask.spacer18 = dialog.AddLabel ( '' )
ask.spacer19 = dialog.AddLabel ( '' )
ask.spacer20 = dialog.AddLabel ( '' )
ask.commands = dialog.AddTextbox( "Configuration:",'' )
ask.spacer7 = dialog.AddLabel ( '' )
ask.OK = dialog.AddButton("OK",1)
ask.HELP = dialog.AddButton("HELP",2)
local askhelp = dialog.CreateDialog ( 'Anthropic Dreams - Help Window ' )
askhelp.spacer02 = dialog.AddLabel ( '' )
askhelp.spacer03 = dialog.AddLabel ( '' )
askhelp.spacer04 = dialog.AddLabel ( '' )
askhelp.spacer05 = dialog.AddLabel ( '' )
askhelp.spacer01 = dialog.AddLabel ( [[ Wildcards:
- () None - Enable/Use defaults
- (*) All or forever (Most Points)*
- (n) n number of times (Very stable)
- (?) RANDOM number of times
- (s) Summon Selection Interface
- (-r) recent best pose
- (-a) absolute best pose
- (-c) current best pose
- (?>n) RANDOM ATLEAST n number of times
- (?<n) RANDOM ATMOST n number of times ]] )
askhelp.spacer06 = dialog.AddLabel ( '' )
askhelp.spacer07 = dialog.AddLabel ( '' )
askhelp.spacer08 = dialog.AddLabel ( '' )
askhelp.spacer09 = dialog.AddLabel ( '' )
askhelp.OK = dialog.AddButton ( "OK",1 )
status = dialog.Show ( ask )
while ( status == return_value.HELP ) do
dialog.Show ( askhelp )
status = dialog.Show ( ask )
end
print ( 'XBander v1.7 SG2011 - Current Score: '..cs )
print ( 'Working..' )
function SelectSphere ( n )
local x = n.idx
local x2 = n.idx2
local offset = ( n.idx2 - n.idx ) / 2
local k = structure.GetCount ()
local i = x + offset
repeat
if structure.GetDistance ( k,i ) < neighbors then
selection.Select ( k )
end
k = k - 1
until k < 1
end
selection.SelectSphere = SelectSphere
local function cleanup ()
behavior.SetClashImportance ( 1 )
recentbest.Restore ()
print ( 'Done.' )
end
local function ToRadians ( deg )
if deg > PI_degrees or deg < PI_degreeN then
print ( '** Warning ** - Angle too big! ('..deg..')' )
deg = deg%PI_degrees
print ( 'Trim to new value:'..deg )
end
return (deg * 0.01745329251994329577)
end
local Math = { ToRadians = ToRadians }
local ss = { HELIX = HELIX, SHEET = SHEET, LOOP = LOOP }
local function New ( obj )
return obj -- pass-new-obj-by-value
end
structure.New = function ( proto ) -- new metatable entry
return structure [ proto ]
end
structure.WiggleBackbone = structure.New ('WiggleAll')
structure.WiggleSidechains = structure.New ('WiggleAll')
structure.LocalWiggleBackbone = structure.New ('LocalWiggleSelected')
structure.WiggleBackbone_ = function ( iters )
structure.WiggleBackbone ( iters,true,false ) -- update screen
end
structure.WiggleSidechains_ = function ( iters )
structure.WiggleSidechains ( iters,false,true ) -- update screen
end
structure.LocalWiggleBackbone_ = function ( iters )
structure.LocalWiggleBackbone ( iters,true,false )
end
local function func ()
local nStep2 = -1
while ( nStep2 < ( idx )) or ( nStep2 > ( idx2 )) do
nStep2 = (recipe.GetRandomSeed ()%(idx2)) + (recipe.GetRandomSeed ()%(idx))
end
return nStep2
end
local function func2 ()
local nStep2 = -1e-99
while ( nStep2 < ( ZERO )) or ( nStep2 > ( PI_degrees )) do
nStep2 = (recipe.GetRandomSeed ()%(PI_degrees))
end
return Math.ToRadians ( nStep2 )
end
local function check_score ( bs )
local cs = current.GetScore ()
local c = current.GetScore ()-bs
if c > 0 then
print ( 'Gain found: '..cs..'\t+'..c )
bs = cs
elseif c < -rthresh then -- are we stuck ?
recentbest.Restore ()
end -- test c
return bs
end
local function GetSeed ()
local n = {}
n.idx = func ()
n.Rho = 3
n.Theta = func2()
n.Phi = func2()
return n
end
recipe.GetSeed = GetSeed
local function AddXBand ( n )
local bseg = band.Add ( n.idx,1 or 2,2 or 3,n.Rho,n.Theta,n.Phi )
band.SetGoalLength ( bseg,0.0 )
band.SetStrength ( bseg,10.0 )
return bseg
end
local _gses = New ( current.GetSegmentEnergySubscore )
local function SmartShake ( iters )
for i=idx,idx2 do
local ci = _gses ( i,'clashing' )
if ci > _gses ( i,'hiding' ) and
ci > _gses ( i,'packing' ) and
ci > _gses ( i,'ideality' ) and
ci > _gses ( i,'sidechain') and
ci > _gses ( i,'bonding' ) and
ci > _gses ( i,'other' ) and
ci > _gses ( i,'reference') then
selection.Select ( i )
end -- test ci
end -- loop
if selection.GetCount () then
structure.ShakeSidechainsSelected ( iters )
selection.DeselectAll ()
end
end
band.AddXBand = AddXBand
structure.SmartShake = SmartShake
structure.SmartWiggle = function ( iters )
structure.WiggleAll ( iters )
local css = current.GetScore ()
structure.WiggleAll ( wout2 )
if current.GetScore ()-css > thresh then
structure.WiggleAll ( wout3 )
end
end
local function XBander ()
structure.SetNote ( 1,str )
while ( 1 ) do
cs = check_score ( cs )
local n = recipe.GetSeed ()
local bseg = band.AddXBand ( n )
structure.WiggleBackbone_ ( 1 )
ui.CenterViewport ()
band.Delete ( bseg )
structure.SmartShake ( 1 )
structure.WiggleSidechains_ ( 1 )
structure.WiggleAll ( wout )
cs = check_score ( cs )
end
end -- XBander ()
--while ( 1 ) do
if ( status == return_value.OK ) then
xpcall (XBander,cleanup)
end
--end