Code
--------------------
-- Main functions --
--------------------
--------------------
function BF(seg, radius, precise, mutate)
local phrase = "Blue Fuse"
if (mutate == nil) then
mutate = false
else if (mutate == true) then
phrase = "Mutating"
end
end
if (Init(phrase, seg, precise) == false) then
return false
end
Sphere(seg, radius, true)
CI(0.05)
DS(1, mutate)
CI(1.00)
WA(2)
CI(0.07)
DS(1, mutate)
CI(1.00)
W(2)
recentbest.Restore()
CI(0.30)
WA(2)
CI(1.00)
W(2)
recentbest.Restore()
GetBestLocalScore()
return true
end
--40
--------------------
function AT(seg, radius, precise)
if (Init("Acid Tweeker", seg, precise) == false) then
return false
end
print("Phase 1")
selection.DeselectAll()
selection.Select(seg)
CI(0.00)
DS(2)
CI(1.00)
Sphere(seg, radius, false)
ATW()
GetBestLocalScore()
print("Phase 2")
StartLocalScore()
selection.DeselectAll()
selection.Select(seg)
CI(0.00)
DS(2)
CI(1.00)
Sphere(seg,radius, false)
selection.Deselect(seg)
ATW()
GetBestLocalScore()
print("Phase 3")
StartLocalScore()
selection.DeselectAll()
local rotamers = rotamer.GetCount(seg)
if (rotamers > 1) then
QS(7)
for x=1, rotamers do
StartLocalScore()
QL(7)
print(x, " of ", rotamers, " rotamers")
rotamer.SetRotamer(seg, x)
Sphere(seg,radius,false)
selection.Deselect(seg)
ATW()
Sphere(seg,radius,false)
ATW()
GetBestLocalScore()
end
end
return true
end
--90
function ATW(seg)
recentbest.Save()
CI(0.60)
W(1)
CI(1.00)
W(2)
DS(1)
CI(0.60)
W(1)
CI(1.00)
W(2)
recentbest.Restore()
end
--------------------
function Mutate(seg, radius, precise)
BF(seg, radius, precise, true)
return true
end
--110
--------------------
function CutPoint(seg, radius, precise)
if (Init("Solving cutpoint", seg, precise) == false) then
return false
end
print("Fixing")
band.DeleteAll()
local nb=1
local dist=0
for i=1, seg_count do
for j=i, seg_count do
dist = structure.GetDistance(i, j)
if (((19<dist and dist<20) or (7<dist and dist<8)) and
((i~=seg) and (j~=seg))) then
local cband = band.GetCount()
band.AddBetweenSegments(i, j)
if (cband < band.GetCount()) then
band.SetGoalLength(nb, dist)
nb = nb+1
end
end
end
end
print("Rebuilding")
recentbest.Save()
for i=1, 5 do
selection.DeselectAll()
selection.Select(seg)
if (seg>1) then
selection.Select(seg-1)
end
if (seg<seg_count) then
selection.Select(seg+1)
end
structure.RebuildSelected(5)
Sphere(seg, radius, true)
CI(1.00)
WA(2)
CI(0.05)
DS(1)
CI(1.00)
WA(2)
DS(1)
WA(2)
CI(0.15)
WA(2)
CI(1.00)
WA(2)
end
recentbest.Restore()
GetBestLocalScore()
band.DeleteAll()
return true
end
--165
--------------------
function Compress(radius, precise, hydro)
if (Init("Compress void", 1, precise) == false) then
return false
end
local nb = band.GetCount()
if (nb ~= 1) then
print("I need ONE band. I'll use its end as center")
return false
end
selection.DeselectAll()
for i=1, seg_count do
local condition = true
if (hydro==true) and (structure.IsHydrophobic(i)==false) then
condition = false
end
local newband = band.AddToBandEndpoint(i,1)
if (newband > 0) then
local len = band.GetLength(newband)
if len < radius+1 then
if (condition==true) then
band.SetGoalLength(newband, len*0.9)
end
selection.Select(i)
else
band.Delete(newband)
end
end
end
for loops=1,3 do
band.EnableAll()
band.Disable(1)
recentbest.Save()
CI(1.00)
W(2)
band.DisableAll()
CI(0.07)
DS(1)
CI(1.00)
W(2)
DS(1)
W(2)
recentbest.Restore()
print("Score: ", current.GetScore())
end
while (band.GetCount()>1) do
band.Delete(2)
end
GetBestLocalScore()
return true
end
--216
--------------------
function FreezeBest(worst_value, side_freeze)
freeze.UnfreezeAll()
for i=1,seg_count do
if (current.GetSegmentEnergyScore(i) > worst_value) then
freeze.Freeze(i, true, side_freeze)
end
end
return true
end
--------------------
function LocalWiggle()
if (ValidSeg(seg) == false) then
return false
end
return true
end
---------------------------------
-- global variables and macros --
---------------------------------
--239
seg_count = structure.GetCount()
segcount = seg_count
global_ci = behavior.GetClashImportance()
CI = behavior.SetClashImportance
QL = save.Quickload
QS = save.Quicksave
-----------------------
-- general functions --
-----------------------
function DS(val, mutate)
if (mutate == nil) then
mutate = false
end
if (mutate == true) then
structure.MutateSidechainsSelected(val)
else
structure.ShakeSidechainsSelected(val)
end
end
function Init(phrase, seg, precise)
print(phrase)
if (precise == true) then
W = WAP
else
W = WA
end
StartLocalScore()
recentbest.Save()
print("Score: ", current.GetScore())
return ValidSeg(seg)
end
function ValidSeg(seg)
if ((seg>0) and (seg<seg_count+1)) then
return true
end
print("segment ", seg, " out of bounds")
return false
end
--283
function StartLocalScore()
-- print("Start local score: ", current.GetScore())
QS(4)
end
function GetBestLocalScore()
local final_sc = 0
QS(5)
local sc_last = current.GetScore()
QL(4)
local sc_local_start = current.GetScore()
if (sc_local_start >= sc_last) then
final_sc = sc_local_start
else
final_sc = sc_last
QL(5)
end
print("Score: ", final_sc)
return
end
--305
function Sphere(seg,radius, onlysphere)
if (onlysphere == true) then
selection.DeselectAll()
end
for i = 1, seg_count do
if (structure.GetDistance(seg, i) <= radius) then
selection.Select(i)
end
end
end
-- Wiggle All Selected
function WA(iter)
local lci = behavior.GetClashImportance()
if (lci > global_ci) then
CI(global_ci)
end
structure.WiggleSelected(iter)
CI(lci)
end
-- WiggleAll precise
function WAP(iter)
local sc_ini = 0.00
local delta = 1.00
local loops = 5
while ((delta > 0.001) and (loops > 0)) do
sc_ini = current.GetScore()
QS(6)
WA(iter)
delta = current.GetScore() - sc_ini
iter = iter+1
loops = loops-1
end
if (delta < 0) then
QL(6)
end
end
-----------------------
-- Main
-----------------------
--400
function GetParam()
local dlg = dialog.CreateDialog("Hand work tools v0.1 beta")
dlg.bf = dialog.AddCheckbox("Blue Fuse on sphere *", false)
dlg.at = dialog.AddCheckbox("Acid Tweeker on sphere *", false)
dlg.mut = dialog.AddCheckbox("Mutate on sphere *", false)
dlg.cut = dialog.AddCheckbox("Rebuild and stabilize, for cutpoints *", false)
dlg.comp = dialog.AddCheckbox("Compress with center in space **", false)
dlg.freez = dialog.AddCheckbox("Freeze the best segments", false)
dlg.ins = dialog.AddLabel("* A segment selected is required")
dlg.ins2 = dialog.AddLabel("** One band to space required to point to the center")
dlg.cancel = dialog.AddButton("Cancel", 0)
dlg.ok = dialog.AddButton("Ok", 1)
local result = dialog.Show(dlg)
if (result > 0) then
local bf = dlg.bf.value
local at = dlg.at.value
local mut = dlg.mut.value
local cut = dlg.cut.value
local comp = dlg.comp.value
local freez = dlg.freez.value
if (bf==true or at==true or mut==true or cut==true or comp==true or freez==true) then
local nsel = 0
local seg = 0
-- print("seleccionada funcion")
if (bf==true or at==true or mut==true or cut==true) then
if (freeze.GetCount()==1) then
for i=1, seg_count do
if freeze.IsFrozen(i) then
seg=i
end
end
nsel=1
else
for i=1, seg_count do
if selection.IsSelected(i) then
nsel = nsel + 1
seg = i
end
end
end
if (nsel ~= 1) then
local dlg_error = dialog.CreateDialog("Error")
dlg_error.lbl = dialog.AddLabel("ONE segment selected is necessary for that function")
dlg_error.lbl2 = dialog.AddLabel("Please select one segment with Selection Interface")
dlg_error.lbl3 = dialog.AddLabel("or freeze a segment with Original Interface")
dlg_error.ok = dialog.AddButton("Exit", 0)
dialog.Show(dlg_error)
return
end
freeze.UnfreezeAll()
end
local dlg_options = dialog.CreateDialog("Otions")
if (bf==true or at==true or mut==true or cut==true or comp==true) then
dlg_options.radius = dialog.AddSlider("Radius: ", 10, 6, 20, 1)
dlg_options.precise = dialog.AddCheckbox("Precise (slow, for decimals of point)", false)
end
if (comp==true) then
dlg_options.hydro = dialog.AddCheckbox("Only hydrophobe", false)
end
if (freez==true) then
dlg_options.freez = dialog.AddSlider("Worst segment value: ", 5, -10, 40, 1)
dlg_options.side = dialog.AddCheckbox("Also freeze sidechains ", false)
end
dlg_options.ci = dialog.AddSlider("Clash Importance: ", global_ci, 0.00, 1.00, 2)
dlg_options.cancel = dialog.AddButton("Cancel", 0)
dlg_options.ok = dialog.AddButton("Ok", 1)
local res_options = dialog.Show(dlg_options)
if (res_options > 0) then
local radius = 10
local precise = false
global_ci = dlg_options.ci.value
if (bf==true or at==true or mut==true or cut==true or comp==true) then
radius = dlg_options.radius.value
precise = dlg_options.precise.value
end
if (bf == true) then
print("Blue Fuse, segment:", seg, " radius:", radius, "precise:", precise)
BF(seg,radius,precise)
return
end
if (at == true) then
print("AT, segment", seg, " radius:", radius, "precise:",precise)
AT(seg, radius, precise)
return
end
if (mut == true) then
print("Mutate, segment:", seg, " radius:", radius, "precise:", precise)
Mutate(seg, radius, precise)
return
end
if (cut == true) then
print("Rebuild, segment:", seg, " radius:", radius, "precise:", precise)
CutPoint(seg, radius, precise)
return
end
if (comp == true) then
print("Compress, radius:", radius, " precise: ", precise, " hydro: ", dlg_options.hydro.value)
Compress(radius, precise, dlg_options.hydro.value)
return
end
if (freez == true) then
print("Freeze, value:", dlg_options.freez.value, " precise: ", precise)
FreezeBest(dlg_options.freez.value, precise)
return
end
end
end
end
end
function Run()
GetParam()
local seg = 9
-- BF(seg, 8, true)
-- AT(seg, 8, false)
-- Mutate(seg, 8, false)
-- CutPoint(seg, 8)
-- Compress(10, false, true) -- radius, precise, hydro
-- FreezeBest(5, true)
end
GetParam()