Icon representing a recipe

Recipe: Ligand docker v2.1

created by robgee

Profile


Name
Ligand docker v2.1
ID
103668
Shared with
Public
Parent
None
Children
Created on
June 30, 2020 at 23:26 PM UTC
Updated on
June 30, 2020 at 23:26 PM UTC
Description

pseudo random walk

Best for


Code


-- Ligand docker v2.1 -- 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: -- Band X,Y atoms ???? -- toggle for wiggle(backbone),wiggle(all) -- ------------------------------------ -- ---------- GLOBAL VARS ------------- -- ------------------------------------ Recipe = "Ligand docker" Version = " v2.1" ReVersion = Recipe .. " " .. Version -- - -- ------------- OPTIONS -------------- -- - Cycles = 30 Wiggles = 3 --amount restorative wiggles minDist = 10 maxDist = 50 Levy = 0 BandStrength = 1.50 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, Levy ) local hscore = current.GetScore() print("Cycle start score", round( hscore ) ) minDist = minDist + Levy maxDist = maxDist + Levy local dst = math.random( minDist, maxDist ) local RHO=(dst / 1000) --rho is a distance --print('Distance', RHO) local OG = LIGAND if BandStrength >10.0 then BandStrength = 9.99 end 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, BandStrength ) 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() 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, 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('Maximum CI recipe will use:', userSetMaxCI ) print('Wiggles',Wiggles ) print('Minimum band length', minDist ) print('Maximum band length', maxDist ) print('Band strength:', BandStrength ) print("Recipe start score:", current.GetEnergyScore() ) print('') end function DialogOptions( ) local dlog = dialog.CreateDialog ( ReVersion ) --dlog.spacer = dialog.AddLabel('Options') dlog.iters = dialog.AddSlider( "Cycles", Cycles, 1, 100, 0 ) dlog.wigls = dialog.AddSlider( "Wiggles", Wiggles, 1, 30, 0 ) dlog.spacer1 = dialog.AddLabel('') dlog.minidist = dialog.AddSlider('Min band length' ,minDist, 5,100,0 ) dlog.maxidist = dialog.AddSlider('Max band length', maxDist ,20, 200, 0 ) dlog.bandstren = dialog.AddSlider('Band Strength', BandStrength ,0.1, 5, 1 ) dlog.spacer2 = dialog.AddLabel('') dlog.usermaxci = dialog.AddSlider( "Maximum CI", userSetMaxCI, 0.00, 1, 2 ) dlog.spacer3 = dialog.AddLabel('') 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 minDist = dlog.minidist.value maxDist = dlog.maxidist.value BandStrength = dlog.bandstren.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.1

Comments