Profile
- Name
- AA Investigator.lua
- ID
- 48507
- Shared with
- Public
- Parent
- None
- Children
- None
- Created on
- March 12, 2014 at 03:07 AM UTC
- Updated on
- March 12, 2014 at 03:07 AM UTC
- Description
Investigage AA atoms and residues with zero length bands.
Results saved to slot 3, Starting conditions in slot 2.
Best for
Code
--[[
Viosca's AA Investigator v2 LUA
Investigage AA atoms and residues with zero length bands.
Results saved to slot 3, Starting conditions in slot 2.
]]--
--[[
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
-- limit value to between low and high
local function _limit(value, low, high)
return math.min(high, math.max(low, value))
end
-- Iterate an integer cyclically between min and max
local function _cycle(iter, maximum, minimum)
minimum = minimum or 1
iter = math.limit(iter, minimum, maximum)
local base = iter - minimum
return math.floor((base + 1) % (maximum - minimum + 1)) + 1
end
math.abs = _abs
math.floor = _floor
math.random = _random
math.randomseed = _randomseed
math.limit = _limit
math.cycle = _cycle
function printf(...) print(string.format(...)) end
function sprintf(...) return string.format(...) end
function errorf(...) error(string.format(...)) end
--[[ End math library ]]--
function selection.GetSelectedList()
local selected_list = {}
for i = 1,structure.GetCount() do
if selection.IsSelected(i) then table.insert(selected_list,i) end
end
return selected_list
end
function selection.SetSelectedList(select_list)
local saved_selection = selection.GetSelectedList()
selection.DeselectAll()
for i = 1, #select_list do
selection.Select(select_list[i])
end
return saved_selection
end
function band.AddSpace(
segmentOrigin,
segmentXAxis,
segmentYAxis,
rho,
theta,
phi,
atomIndexOrigin,
atomIndexXAxis,
atomIndexYAxis,
deprecated
)
local function SetDefaultAtomIndex(seg, atom)
if not atom then atom = 0 end
if atom < 0 then atom = structure.GetAtomCount(seg) end
return atom
end
deprecated = deprecated or false
if not deprecated then
--Defaults are for random zero band of length .001
local minlen = 0.001
rho = rho or minlen
phi = phi or 2 * math.pi * math.random()
theta = theta or math.acos(2*math.random()-1)
local nSeg = structure.GetCount()
if segmentOrigin == 1 then
-- point X up the chain.
segmentXAxis = segmentXAxis or 2
segmentYAxis = segmentYAxis or 3
elseif segmentOrigin == nSeg then
-- point X down the chain.
segmentXAxis = segmentXAxis or nSeg-1
segmentYAxis = segmentYAxis or nSeg-2
-- since X points backwards, and Z down,
-- rotate theta and phi back to where they should be.
new_theta = math.acos(-math.cos(theta))
new_phi =
math.acos( -math.sin(theta) * math.cos(phi)/
math.sin(new_theta) )
theta, phi = new_theta, new_phi
else
-- point X up the chain.
segmentXAxis = segmentXAxis or segmentOrigin+1
segmentYAxis = segmentYAxis or segmentOrigin-1
end
end
atomIndexOrigin = SetDefaultAtomIndex(segmentOrigin, atomIndexOrigin)
atomIndexXAxis = SetDefaultAtomIndex(segmentXAxis, atomIndexXAxis)
atomIndexYAxis = SetDefaultAtomIndex(segmentYAxis, atomIndexYAxis)
return band.Add(
segmentOrigin,
segmentXAxis,
segmentYAxis,
rho,
theta,
phi,
atomIndexOrigin,
atomIndexXAxis,
atomIndexYAxis
)
end
local AA_Atoms = {
C = {
name = "Carbon",
},
H = {
name = "Hydrogen",
},
N = {
name = "Nitrogen",
},
O = {
name = "Oxygen",
},
S = {
name = "Sulfur",
},
Se = {
name = "Selenium",
},
}
local AA_Props = {
a = {
name = "Alanine",
abbrev = "Ala",
},
c = {
name = "Cysteineine",
abbrev = "Cys",
},
d = {
name = "Aspartic Acid",
abbrev = "Asp",
},
e = {
name = "Glutamic Acid",
abbrev = "Glu",
},
f = {
name = "Phenylalanine",
abbrev = "Phe",
},
g = {
name = "Glycine",
abbrev = "Gly",
residue_atoms = 0,
hydrogen_atoms = 1,
},
h = {
name = "Histidine",
abbrev = "His",
},
i = {
name = "Isoleucine",
abbrev = "Ile",
},
k = {
name = "Lysine",
abbrev = "Lys",
},
l = {
name = "Leucine",
abbrev = "Leu",
},
m = {
name = "Methionine",
abbrev = "Met",
},
n = {
name = "Asparagine",
abbrev = "Asn",
},
p = {
-- proline is odd in that atom 8 is the same as atom 1.
name = "Proline",
abbrev = "Pro",
},
q = {
name = "Glutamineine",
abbrev = "Gln",
},
r = {
name = "Arginine",
abbrev = "Arg",
residue_atoms = 7,
hydrogen_atoms,
},
s = {
name = "Serine",
abbrev = "Ser",
},
t = {
name = "Threonine",
abbrev = "Thr",
},
u = {
name = "Selenocysteine",
abbrev = "Sec",
},
v = {
name = "Valine",
abbrev = "Val",
},
w = {
name = "Tryptophan",
abbrev = "Trp",
},
y = {
name = "Tyrosine",
abbrev = "Tyr",
},
}
function Investigate_AA(aa_seg)
local atom_count = structure.GetAtomCount(aa_seg)
local aa = structure.GetAminoAcid(aa_seg)
local seg_count = structure.GetCount()
local terminus_info = seg_count == aa_seg and "C" or (aa_seg == 1 and "N") or ""
local terminus_str = "" .. terminus_info .. ""
local info_str = string.format("Seg %d%s is '%s' %s (%s), atoms: %d.",
aa_seg, terminus_str, aa, AA_Props[aa].name, AA_Props[aa].abbrev, atom_count)
print(info_str)
local curr_atom = 1
local atom_inc = true
local disable_past = true
local delete_past = false
local atom_bids = {}
local ACTION_QUIT = 0
local ACTION_BAND = 1
local ACTION_CUT = 2
local ACTION_JOIN = 3
local ACTION_IDEAL = 4
local ACTION_REMIX = 5
local ACTION_SHAKE = 6
local ACTION_WIGGLE = 7
local action = nil
repeat
local ask = dialog.CreateDialog("Investigate AA.")
ask.l1=dialog.AddLabel(info_str)
ask.l2=dialog.AddLabel("Notes:")
ask.l3=dialog.AddLabel(" Set 'View Options' to 'Stick+H' to see all")
ask.l4=dialog.AddLabel(" Bands can be toggled enable/disable with 'd'")
ask.l5=dialog.AddLabel(" Bands can be deleted/modified in the GUI")
ask.l6=dialog.AddLabel(" rotamers can be snapped with Shift <- and ->")
ask.curr_atom=dialog.AddSlider("Next Atom:", curr_atom, 1, atom_count, 0)
ask.disable_past = dialog.AddCheckbox("Disable old bands.", disable_past)
ask.delete_past = dialog.AddCheckbox("Delete old bands.", delete_past)
ask.atom_inc = dialog.AddCheckbox("Increment Atom number.", atom_inc)
-- Actions:
ask.band=dialog.AddButton("Band", ACTION_BAND)
ask.cut=dialog.AddButton("Cut", ACTION_CUT)
ask.join=dialog.AddButton("Join", ACTION_JOIN)
ask.idealize=dialog.AddButton("Ideal", ACTION_IDEAL)
ask.remix=dialog.AddButton("Remix", ACTION_REMIX)
ask.shake=dialog.AddButton("Shake", ACTION_SHAKE)
ask.wiggle=dialog.AddButton("Wiggle", ACTION_WIGGLE)
ask.quit=dialog.AddButton("Quit", ACTION_QUIT)
action = dialog.Show(ask)
curr_atom = ask.curr_atom.value
atom_inc = ask.atom_inc.value
disable_past = ask.disable_past.value
delete_past = ask.delete_past.value
if action == ACTION_BAND then
if disable_past then band.DisableAll() end
if delete_past then
band.DeleteAll()
atom_bids = {}
end
local iBand = band.AddSpace(
aa_seg, --segmentOrigin,
nil, --segmentXAxis,
nil, --segmentYAxis,
nil, --rho,
nil, -- theta
nil, -- phi
curr_atom, --atomIndexOrigin,
1, --atomIndexXAxis,
1 --atomIndexYAxis
)
band.SetGoalLength(iBand, 0)
if atom_inc then
curr_atom = math.cycle(curr_atom, atom_count)
end
elseif action == ACTION_CUT then
structure.InsertCut(aa_seg)
elseif action == ACTION_JOIN then
structure.DeleteCut(aa_seg)
elseif action == ACTION_IDEAL then
structure.IdealizeSelected()
elseif action == ACTION_REMIX then
structure.RemixSelected()
elseif action == ACTION_SHAKE then
structure.ShakeSidechainsSelected(2)
elseif action == ACTION_WIGGLE then
structure.WiggleSelected(25)
end
until action == 0
return action
end
function Investigate_AAs(aa_list)
for k,seg in pairs(aa_list) do
Investigate_AA(seg)
end
end
result_slot = 3
save_slot = 2
function main()
seed = (os.time() * 5779) % 10000
math.randomseed(seed)
save.Quicksave(save_slot)
band.DeleteAll()
freeze.UnfreezeAll()
Investigate_AAs(selection.GetSelectedList())
end
--main call
function CleanUp()
save.Quicksave(result_slot)
save.Quickload(save_slot)
print("Result in slot: " .. result_slot)
end
-- Routine called on cancel or error
function OnError(err)
if err:find('Cancel') then print('Cancelled') CleanUp()
else print('Error: ',err)
end
return err
end
rc,err = xpcall(main, OnError)
if rc == true then CleanUp() end
--end of script