Profile
- Name
- Rav3n_pl Snap n wiggle V2
- ID
- 31266
- Shared with
- Public
- Parent
- None
- Children
-
- v2_X_Rav3n_pl Snap n wiggle
- v2_X_Rav3n_pl Snap n wiggle
- v2_X_Rav3n_pl Snap n wiggle
- My Rav3n_pl Snap n wiggle + shake V2
- 2Rav3n_pl Snap n wiggle V2
- My_551_Rav3n_pl Snap n wiggle V2
- My_Start_Rav3n_pl Snap n wiggle V2
- My_Hydro_Rav3n_pl Snap n wiggle V2
- Snap n wiggle V2.1
- Rav3n_pl Snap n wiggle V2 NC
- Rav3n_pl Snap A
- Rav3n_pl Sidechain Snap n wiggle V2
- Rav3n_pl Snap n wiggle V2 ci35
- Created on
- August 21, 2011 at 10:16 AM UTC
- Updated on
- August 21, 2011 at 10:16 AM UTC
- Description
snapping and wiggling in lua v2
Best for
Code
--[[
Rav3n_pl Snap`n`wiggle v2 LUA
snapping all sidechain roamers then wiggle
best score saved to slot 3
]]--
---- OPTIONS START
sStart=1
sEnd=nil
normal=true --set false for exploration scoring
breakOnGain=true --stop snapping ss if gain >1pt
worst=true --start snapping from worstscoring, if false in random order
---- END OF OPTIONS
-- "lua v1 in v2" library by rav3n_pl
--just add it in front of your v1 code and use v2 and v1 code in v2 scripts :)
-- print(arg1[,...,argN]) no change :)
function are_conditions_met()
return current.AreConditionsMet()
end
function band_add_segment_segment(sgi1, sgi2)
band.AddBetweenSegments(sgi1, sgi2)
end
function band_delete(bndIdx)
if bndIdx~= nil then
band.Delete(bndIdx)
else
band.DeleteAll()
end
end
function band_disable(bndIdx)
if bndIdx~=nil then
band.Disable(bndIdx)
else
band.DisableAll()
end
end
function band_enable(bndIdx)
if bndIdx~=nil then
band.Enable(bndIdx)
else
band.EnableAll()
end
end
function band_set_length(bndIdx, len)
band.SetGoalLength(bndIdx, len)
end
function band_set_strength(bndIdx, str)
band.SetStrength(bndIdx, str)
end
function get_band_count()
return band.GetCount()
end
function deselect_all()
selection.DeselectAll()
end
function deselect_index(sgn)
selection.Deselect(sgn)
end
function select_all()
selection.SelectAll()
end
function select_index(sgn)
selection.Select(sgn)
end
function select_index_range(sg1,sg2)
selection.SelectRange(sg1,sg2)
end
function do_freeze(bbone,schain)
freeze.FreezeSelected(bbone,schain)
end
function do_unfreeze_all()
freeze.UnfreezeAll()
end
function do_global_wiggle_all(iters)
structure.WiggleAll(iters)
end
function do_global_wiggle_backbone(iters)
structure.WiggleAll(iters, true,false)
end
function do_global_wiggle_sidechains(iters)
structure.WiggleAll(iters,false,true)
end
function do_local_rebuild(iters)
structure.RebuildSelected(iters)
end
function do_local_wiggle(iters)
structure.LocalWiggleSelected(iters,true,true)
end
function do_mutate(iters)
structure.MutateSidechainsSelected(iters)
end
function do_shake(iters)
structure.ShakeSidechainsSelected(iters)
end
function do_sidechain_snap(sgn, snap)
rotamer.SetRotamer(sgn, snap)
end
function get_sidechain_snap_count(sgn)
return rotamer.GetCount(sgn)
end
function load_structure()
save.LoadSecondaryStructure()
end
function save_structure()
save.SaveSecondaryStructure()
end
function quickload(slot)
save.Quickload(slot)
end
function quicksave(slot)
save.Quicksave(slot)
end
function get_exploration_score()
return current.GetExplorationMultiplier()
end
function get_ranked_score()
return current.GetScore()
end
function get_score()
return current.GetEnergyScore()
end
function get_segment_distance(sg1,sg2)
return structure.GetDistance(sg1,sg2)
end
function get_aa(sn)
return structure.GetAminoAcid(sn)
end
function get_segment_count()
return structure.GetCount()
end
function get_ss(sn)
return structure.GetSecondaryStructure(sn)
end
function is_hydrophobic(sn)
return structure.IsHydrophobic(sn)
end
function replace_aa(aa)
for i=1,structure.GetCount() do
if selection.IsSelected(i) then
structure.SetAminoAcid(i, aa)
end
end
end
function replace_ss(ss)
for i=1,structure.GetCount() do
if selection.IsSelected(i) then
structure.SetSecondaryStructure(i,ss)
end
end
end
function get_segment_score(sg)
return current.GetSegmentEnergyScore(sg)
end
function get_segment_score_part(score_part,sg)
return current.GetSegmentEnergySubscore(sg,score_part)
end
function reset_puzzle()
puzzle.StartOver()
end
function restore_abs_best()
absolutebest.Restore()
end
function restore_credit_best()
creditbest.Restore()
end
function reset_recent_best()
recentbest.Save()
end
function restore_recent_best()
recentbest.Restore()
end
function set_behavior_clash_importance(ci)
behavior.SetClashImportance(ci)
end
-- end of library
p=print
segCnt=get_segment_count()
if get_ss(segCnt)=="M" then segCnt=segCnt-1 end --skip ligand
CI=set_behavior_clash_importance
function Score()
local s=0
if normal==true then
s=get_score(true)
else
s=get_ranked_score(true)
end
return s
end
function round(x)--cut all afer 3-rd place
return x-x%0.001
end
bestScore=Score()
function SaveBest()
local g=Score()-bestScore
if g>0 then
if g>0.01 then p("Gained another "..round(g).." pts.") end
bestScore=Score()
quicksave(3)
end
end
function Wiggle(how, iters, minppi) --score conditioned recursive wiggle/shake
if how==nil then how="wa" end
if iters==nil then iters=6 end
if minppi==nil then minppi=0.1 end
if iters>0 then
iters=iters-1
local sp=Score()
if how == "s" then do_shake(1)
elseif how == "wb" then do_global_wiggle_backbone(2)
elseif how == "ws" then do_global_wiggle_sidechains(2)
elseif how == "wa" then do_global_wiggle_all(2)
end
local ig=Score()-sp
if ig > minppi then return Wiggle(how, iters, minppi) end
end
end
--[[
Tlaloc`s math library
------------------------------------------------------------------------
The original random script this was ported from has the following notices:
Copyright (c) 2007 Richard L. Mueller
Hilltop Lab web site - http://www.rlmueller.net
Version 1.0 - January 2, 2007
You have a royalty-free right to use, modify, reproduce, and
distribute this script file in any way you find useful, provided that
you agree that the copyright owner above has no warranty, obligations,
or liability for such use.
------------------------------------------------------------------------
]]--
local lngX = 1000
local lngC = 48313
local function _random(m,n)
local A_Hi = 63551
local A_Lo = 25354
local M = 4294967296
local H = 65536
function _MWC()
local S_Hi = math.floor(lngX / H)
local S_Lo = lngX - (S_Hi * H)
local C_Hi = math.floor(lngC / H)
local F1 = A_Hi * S_Hi
local F2 = (A_Hi * S_Lo) + (A_Lo * S_Hi) + C_Hi
lngX = ((F2 - (math.floor(F2 / H) * H)) * H) + (A_Lo * S_Lo) + lngC - (C_Hi * H)
lngX = lngX - (math.floor(lngX / M) * M)
lngC = math.floor((F2 / H) + F1)
return lngX
end
if n == nil and m ~= nil then
n = m
m = 1
end
if (m == nil) and (n == nil) then
return _MWC() / M
else
if n < m then
return nil
end
return math.floor((_MWC() / M) * (n - m + 1)) + m
end
end
local function _abs(value)
if value < 0 then
return -value
else
return value
end
end
local function _floor(value)
return value - (value % 1)
end
local function _randomseed(s)
if s==nil then
s=math.abs(Score())
s=s%0.001
s=1/s
while s<10000000 do s=s*10 end
s=s-s%1
end
lngX = s
end
math=
{
abs = _abs,
floor = _floor,
random = _random,
randomseed = _randomseed,
}
math.randomseed()
--[[ End math library ]]--
function getAas()
aas={}
if worst==true then
local t={}
for i=sStart,sEnd do
t[#t+1]={get_segment_score(i),i}
end
for i=1,#t-1 do
for j=i+1,#t do
if t[i][1]>t[j][1] then
t[i],t[j]=t[j],t[i]
end
end
end
for i=1,#t do
aas[#aas+1]=t[i][2]
end
else
for i=sStart,sEnd do --prepeare list
aas[#aas+1]=i
end
for i=1,#aas do --shuffle list
local x=math.random(#aas)
aas[i],aas[x]=aas[x],aas[i]
end
end
return aas
end
function Snap()
if sEnd==nil then sEnd=segCnt end
print("Start snapping! Score: "..round(Score()))
CI(1)
select_all()
reset_recent_best()
quicksave(3)
startScore=Score()
aas=getAas()
for x=1,#aas do --main loop
aa=aas[x]
snaps=get_sidechain_snap_count(aa)
if snaps>2 then --skipping when less than 2 roamers
quicksave(4)
p("Snapping no "..aa.." x ".. snaps.." times; "..x.."/"..#aas.."; score: "..round(Score()).."; gain: "..round(Score()-startScore))
for i=1, snaps do
local s=Score()
CI(0)
do_sidechain_snap(aa, i)
CI(1)
Wiggle("wa",1)
local g=Score()-s
if g>0 then
SaveBest()
if breakOnGain==true and g>1 then break end
else
quickload(4)
end
end
quickload(3)
end
end
end
--main call
Snap()
--end of script