Profile
- Name
- Ligand docker v2.0
- ID
- 103649
- Shared with
- Public
- Parent
- None
- Children
- None
- Created on
- June 26, 2020 at 18:46 PM UTC
- Updated on
- June 26, 2020 at 18:46 PM UTC
- Description
pseudo random walk
Best for
Code
-- Ligand docker v2.0
-- Credits: Raven_pl,Susume,LociOiling,Lynnai
--dev version : Ligand docker BiS RW v1.5
--It makes BiS bands to move the Ligand thru space, hopefully finding a better position,
-- every so often it moves the Ligand extra far to try and optimize its search strategy for finding a better position.
-- This type of search is based on a Levy flight (e should be accented on Levy), Sharks and Albatrosses use it.
-- It is not a proper random walk/Levy flight because frankly i dont know how to do that with spacebands.
--To Do:
-- More stuff in Prelim
-- More stuff in dialog, distances, Max Levy distance
-- Band X,Y atoms ????
-- toggle for wiggle(backbone),wiggle(all)
-- ------------------------------------
-- ---------- GLOBAL VARS -------------
-- ------------------------------------
Recipe = "Ligand docker"
Version = " v2.0"
ReVersion = Recipe .. " " .. Version
-- -
-- ------------- OPTIONS --------------
-- -
Cycles = 30
Wiggles = 3 --amount restorative wiggles
minDist = 10
maxDist = 50
Levy = 0
CapCI = false
userSetMaxCI = behavior.GetClashImportance()
-- END OPTIONS
segCnt = structure.GetCount( )
numSegs =structure.GetCount()
highscore = 0
BASESCORE = current.GetEnergyScore()
-- -------------------------------------------
function HasLigandCheck( )
alwaysLigand = false
segCnt2 = segCnt
while structure.GetSecondaryStructure(segCnt2)=="M" do segCnt2 = segCnt2-1 end
HASLIGAND = segCnt2 < segCnt
if HASLIGAND then
LIGAND = segCnt
alwaysLigand = true
end
end
function round ( x )--to 3 places
return x - x % 0.001
end
-- -----------------------------------------------------
function CI( RecipeCI )-- Cap CI else relative CI
local Using_CI = RecipeCI
if CapCI == true then
if RecipeCI > userSetMaxCI then
Using_CI = userSetMaxCI
end
else
Using_CI = RecipeCI * userSetMaxCI -- relative CI
end
if Using_CI < 0 or Using_CI > 1 then--sanity check
print( 'CI ERROR, CI now set to 1' )
Using_CI = 1
end
--print('Recipe set CI', RecipeCI, ' Using_CI ', Using_CI )
behavior.SetClashImportance( Using_CI )
end-- Thnx to TvdL
function SeedRandom( )
local seed = os.time ( ) / math.abs ( current.GetEnergyScore ( ) )
seed = seed % 0.001
seed = 1 / seed
while seed < 10000000 do
seed = seed * 1000
end
while seed > 2 ^ 32 do
seed = seed / 10
end--LO
seed = seed - seed % 1
math.randomseed( seed )
math.random( ); math.random( ); math.random( ) --See stackoverflow
end-- Rav3n_pl, LociOiling
-- ------------------------------------------------------
function Cleanup(err) -- cancel recipe function
if CLEANUPENTRY ~= nil then
return
end
CLEANUPENTRY = true --LO
print( '========================' )
print( ReVersion..' Cleaning up' )
save.Quickload( 2 )
selection.DeselectAll()
band.DeleteAll()
behavior.SetClashImportance( userSetMaxCI )
print( "Final score: ",round( highscore ) )
print( "Total gain: ", round( highscore - BASESCORE ) )
print( "Error", err)
end
-- -----------------------------------------
function random_bands(sg, str, Levy)
local hscore = current.GetScore()
print("Cycle start score", round( hscore ) )
minDist = 10 + Levy
maxDist = 50 + Levy
local dst = math.random( minDist, maxDist )
local RHO=(dst / 1000) --rho is a distance
print('Distance', RHO)
local OG = LIGAND
local StrengthofBands = str -- Band strength, works best around 0.03-0.08.
for numofbands = 1, 2 do
local theta = math.acos(math.random())
local phi = 2 * math.pi * math.random()
repeat
Xaxis=math.random(1, numSegs-1)
Yaxis=math.random(1, numSegs-1)
until OG~=Xaxis and Yaxis~=Xaxis and OG ~=Yaxis
--print(OG,Xaxis,Yaxis) all 3 must be different
-- {segmentOrigin, segmentXAxis, segmentYAxis, rho, theta, phi, Oatom, Xatom, Yatom}
--ok zero is th default we'll use that for x and Y
--soo we need getcount every time we make a n=band for Ligand
local Xatom = 0
local Yatom = 0
local zap = structure.GetAtomCount( LIGAND )
zap=zap-1
--print('LIGAND atomcount is:', zap)
local rzap = math.random( 1, zap-1 )
--print('Rndom LIGAND atomcount number is:', rzap)
local OriginAtom = rzap
local qed = band.Add(OG, Xaxis, Yaxis, RHO, theta, phi, OriginAtom, Xatom, Yatom )
if qed >= 1 then
band.SetStrength( qed, StrengthofBands )
end
end
selection.DeselectAll ()
selection.Select ( OG )
CI(0.88)
local witers = 1
--structure.ShakeSidechainsSelected(iters)
--structure.WiggleSelected(iters, false, true) -- moves ligand through space and bends it.
structure.WiggleSelected( witers, true, false ) -- moves ligand through space but does not bend it.
--structure.WiggleSelected(iters, true, true) -- moves ligand through space and bends it.
-- -----------------------------------------------------------------------------------------------------
band.DeleteAll()
--print('After banded wiggle:', current.GetEnergyScore())
CI(1.0)
--structure.ShakeSidechainsSelected( 2 )
structure.WiggleAll( Wiggles , true, true )
newscore = current.GetEnergyScore()
print('After main wiggle/shake', newscore)
if newscore > highscore then
save.Quicksave( 2 )
recentbest.Save( )
local gain = newscore - highscore
print('gain:', newscore - highscore)
highscore = newscore
print("+++ High score = "..highscore)
end
selection.DeselectAll()
end -- random_bands
function LigandDock()
local str = 1.50 --Band strength (5.01)
highscore = current.GetScore( )
local revertscore = current.GetScore( )
for i = 1, Cycles do
LevyFlight = false
Levy = 0
revertscore = current.GetScore( )
if i % 5 == 0 and revertscore <= highscore then
print(' -- reverting to best position --')
save.Quickload( 2 )
end
if i % 8 == 0 and revertscore <= highscore then
print(' -- Implementing Levy flight --')
LevyFlight = true
end
print('Cycle number:', i)
if LevyFlight then
Levy = math.random( 500, 800 )
LevyFlight = false
end
random_bands( LIGAND, str, Levy )
end
end
--
--- ----------------------------------------------------------
--
function Prelim()
print( ReVersion )
save.Quicksave( 1 ) --OG pose for backup
save.Quicksave( 2 ) --for high score
print('Start pose in Quicksave 1')
print('Best pose in Quicksave 2')
print("Levy flight version, with rnd distance")
print("Protein length:",structure.GetCount() )
print("Recipe start score:", current.GetEnergyScore() )
end
function DialogOptions( )
local dlog = dialog.CreateDialog ( ReVersion )
dlog.iters = dialog.AddSlider( "Cycles", Cycles, 1, 100, 0 )
dlog.wigls = dialog.AddSlider( "Wiggles", Wiggles, 1, 20, 0 )
dlog.usermaxci = dialog.AddSlider( "Maximum CI", userSetMaxCI, 0.05, 1, 2 )
dlog.ok = dialog.AddButton ( "OK" , 1 )
dlog.cancel = dialog.AddButton ( "Cancel" , 0 )
dialogresult = dialog.Show( dlog )
if dialogresult > 0 then
Cycles =dlog.iters.value
userSetMaxCI = dlog.usermaxci.value
Wiggles = dlog.wigls.value
end
return dialogresult
end
function Main()
SeedRandom()
HasLigandCheck( )
if HASLIGAND == false then print('This is NOT a LIGAND puzzle..exiting') return end
local go = DialogOptions( )
if go == 1 then
Prelim( ) --print the settings
LigandDock( )
else
print( 'Cancelled' )
return
end
print('Restoring best score')
save.Quickload( 2 )
undo.SetUndo( true )
behavior.SetClashImportance( userSetMaxCI )-- return to user setting
end
xpcall( Main, Cleanup )
--Ligand docker v2.0