Profile
- Name
- Oyster Metaphor 1.15
- ID
- 49846
- Shared with
- Public
- Parent
- None
- Children
- None
- Created on
- August 15, 2014 at 23:52 PM UTC
- Updated on
- August 15, 2014 at 23:52 PM UTC
- Description
wwww
Best for
Code
PullClusters = true
function Susband()
GOOD_MULT = 0.9
BAD_MULT = 0.75
HIGH_STRENGTH = 2.5
LOW_STRENGTH = 0.9
bcount = 0
count = structure.GetCount()
for i = 2, count-2 do
for j = i+2, count-1 do
if contactmap.GetHeat(i, j) > 0 then
b = band.AddBetweenSegments(i,j,5,5)
bcount = bcount + 1
if contactmap.IsContact(i,j) then do
band.SetGoalLength(b, GOOD_MULT * band.GetLength(b))
band.SetStrength(b, LOW_STRENGTH)
end
else
band.SetGoalLength(b, BAD_MULT * band.GetLength(b))
band.SetStrength(b, HIGH_STRENGTH)
end
if PullClusters == true then
b = band.AddBetweenSegments(i-1,j-1,5,5)
band.SetGoalLength(b, 0.7 * band.GetLength(b))
band.SetStrength(b, 0.5)
bcount = bcount + 1
b = band.AddBetweenSegments(i,j-1,5,5)
band.SetGoalLength(b, 0.7 * band.GetLength(b))
band.SetStrength(b, 0.5)
bcount = bcount + 1
b = band.AddBetweenSegments(i-1,j,5,5)
band.SetGoalLength(b, 0.7 * band.GetLength(b))
band.SetStrength(b, 0.5)
bcount = bcount + 1
b = band.AddBetweenSegments(i+1,j+1,5,5)
band.SetGoalLength(b, 0.7 * band.GetLength(b))
band.SetStrength(b, 0.5)
bcount = bcount + 1
b = band.AddBetweenSegments(i,j+1,5,5)
band.SetGoalLength(b, 0.7 * band.GetLength(b))
band.SetStrength(b, 0.5)
bcount = bcount + 1
b = band.AddBetweenSegments(i+1,j,5,5)
band.SetGoalLength(b, 0.7 * band.GetLength(b))
band.SetStrength(b, 0.5)
bcount = bcount + 1
end
end
end
end
--print(bcount.." contact bands placed")
--print(b.." total bands")
end
function Megalattice()
function SewTheSheets()
-- try to maintain the global form of the protein after alignment
-- and have score positif
-- only for protein with sheets
recentbest.Save()
save.Quicksave(1)
print ('sewing the sheets')
-- sew sheets if near
nbsegtot=structure.GetCount()
BandNo=band.GetCount()
for noseg =2,nbsegtot do
for deuxseg =noseg+1,nbsegtot do
if (structure.GetDistance(noseg, deuxseg)< 8 and structure.GetSecondaryStructure(noseg)=='E' and structure.GetSecondaryStructure(deuxseg)=='E' )then do
if deuxseg-noseg>4 then do
band.AddBetweenSegments(noseg,deuxseg)
BandNo=BandNo+1
if structure.GetDistance(noseg,deuxseg)<5.5 then do
band.SetGoalLength(band.GetCount(),ShortBandLength)
band.SetStrength(band.GetCount(),SBLBSF)
band.AddBetweenSegments(noseg,deuxseg,5,5)
band.SetGoalLength(band.GetCount(),CrossLatticeLength)
band.SetStrength(band.GetCount(),CrossLatticeStrength)
end
else
if structure.GetDistance(noseg,deuxseg)>7 then do
band.SetGoalLength(band.GetCount(),LongSheetLattitude)
band.SetStrength(band.GetCount(),LSLBSF)
end
else
band.SetGoalLength(band.GetCount(),ShortSheetLattitude)
band.SetStrength(band.GetCount(),SSLBSF)
end
end
end
else end
end
else end
end
end
end
function StringTheSheets()
BandNo=band.GetCount()
for s=1,structure.GetCount()-2 do
if structure.GetSecondaryStructure(s)=="E" then do
if s+2<structure.GetCount() then do
if structure.GetSecondaryStructure(s+2)=="E" then do
band.AddBetweenSegments(s,s+2)
end
else end
end
else end
end
else end
end
NewBandNo=band.GetCount()
for m=BandNo+1,NewBandNo do
band.SetGoalLength(m,StringSheetLength)
band.SetStrength(m,SLBSF)
end
end
function LoopDLoop()
BandNo=band.GetCount()
for s=1,structure.GetCount()-4 do
if structure.GetSecondaryStructure(s)=="H" then do
if s+4<structure.GetCount() then do
if structure.GetSecondaryStructure(s+4)=="H" and structure.GetSecondaryStructure(s+3)=="H" and structure.GetSecondaryStructure(s+2)=="H" and structure.GetSecondaryStructure(s+1)=="H"then do
band.AddBetweenSegments(s,s+4)
end
else end
end
else end
end
else end
end
NewBandNo=band.GetCount()
for m=BandNo+1,NewBandNo do
band.SetGoalLength(m,OneFourHelixLength)
band.SetStrength(m,OneFourHBSF)
end
end
function LoopeR2()
BandNo=band.GetCount()
for s=1,structure.GetCount()-3 do
if structure.GetSecondaryStructure(s)=="H" then do
if s+4<structure.GetCount() then do
if structure.GetSecondaryStructure(s+3)=="H" and structure.GetSecondaryStructure(s+2)=="H" and structure.GetSecondaryStructure(s+1)=="H" then do
band.AddBetweenSegments(s,s+3)
end
else end
end
else end
end
else end
end
NewBandNo=band.GetCount()
for m=BandNo+1,NewBandNo do
band.SetGoalLength(m,OneThreeHelixLength)
band.SetStrength(m,OneThreeHBSF)
end
end
function LoopeR3()
BandNo=band.GetCount()
for s=1,structure.GetCount()-5 do
if structure.GetSecondaryStructure(s)=="H" then do
if s+4<structure.GetCount() then do
if structure.GetSecondaryStructure(s+5)=="H" and structure.GetSecondaryStructure(s+4)=="H" and structure.GetSecondaryStructure(s+3)=="H" and structure.GetSecondaryStructure(s+2)=="H" and structure.GetSecondaryStructure(s+1)=="H" then do
band.AddBetweenSegments(s,s+5)
end
else end
end
else end
end
else end
end
NewBandNo=band.GetCount()
for m=BandNo+1,NewBandNo do
band.SetGoalLength(m,OneFiveHelixLength)
band.SetStrength(m,OneFiveHBSF)
end
end
function LatticeEmUp()
BandNo=band.GetCount()
for j=1,structure.GetCount()-2 do
selection.DeselectAll()
if structure.GetSecondaryStructure(j) == "E" then
if structure.GetSecondaryStructure(j+2) == "E" then
if structure.GetSecondaryStructure(j+1) == "E" then
selection.Select(j)
selection.Select(j+1)
band.AddBetweenSegments(j,j+2,5,5)
BandNo=BandNo+1
BandLength=band.GetLength(BandNo)
band.SetGoalLength(BandNo,LatticeLength)
band.SetStrength(BandNo, LatticeStrength)
end
end
end
end
end
SewTheSheets()
StringTheSheets()
LoopDLoop()
LoopeR2()
LoopeR3()
LatticeEmUp()
end
function MotherOfPearl()
TimesIn = 0
SlotNo = 1
QuitAlready = false
SlotNo = 1
function PrepareForContacts()
for t=1,structure.GetCount() do
if structure.GetSecondaryStructure(t) == "H" or structure.GetSecondaryStructure(t) == "E" then
freeze.Freeze(t, true, false)
end
end
for t = 1, structure.GetCount()-1 do
if structure.GetSecondaryStructure(t) == "L" and structure.GetSecondaryStructure(t+1) == "H" then
structure.InsertCut(t)
end
if structure.GetSecondaryStructure(t) == "L" and structure.GetSecondaryStructure(t+1) == "E" then
structure.InsertCut(t)
end
if structure.GetSecondaryStructure(t) == "E" and structure.GetSecondaryStructure(t+1) == "L" then
structure.InsertCut(t)
end
if structure.GetSecondaryStructure(t) == "H" and structure.GetSecondaryStructure(t+1) == "L" then
structure.InsertCut(t)
end
if structure.GetSecondaryStructure(t) == "H" and structure.GetSecondaryStructure(t+1) == "E" then
structure.InsertCut(t)
end
if structure.GetSecondaryStructure(t) == "E" and structure.GetSecondaryStructure(t+1) == "H" then
structure.InsertCut(t)
end
end
end
function RepairCutpoints()
for k = 1, structure.GetCount()-1 do
structure.DeleteCut(k)
end
end
function CountContacts()
--instead, this returns number of contacts made
bcount = 0
count = structure.GetCount()
for i = 1, count-2 do
for j = i+2, count do
if contactmap.GetHeat(i, j) > 0 then
if contactmap.IsContact(i,j) == true then
bcount = bcount + 1
end
end
end
end
return bcount
end
--[[function GetSlot()
TimesIn = TimesIn + 1
if TimesIn == 1 then
--print("Anything after slot", TimesIn-1, "is junk!")
end
local dlg = dialog.CreateDialog("Quicksave Slot Retrieval")
dlg.RS = dialog.AddSlider("Retrieve Slot#", SlotNo, 1, 99, 0)
dlg.QA = dialog.AddCheckbox("Quit Already", false)
dlg.OK = dialog.AddButton("Do It",1)
dialog.Show(dlg)
DoRetrieveSlot=dlg.RS.value
save.Quickload(DoRetrieveSlot)
print("Slot", DoRetrieveSlot, "restored", CountContacts(), "contacts", current.GetScore())
if dlg.QA.value == false then
SlotNo = dlg.RS.value + 1
GetSlot()
end]]--
function CountContacts()
--instead, this returns number of contacts made
bcount = 0
count = structure.GetCount()
for i = 1, count-2 do
for j = i+2, count do
if contactmap.GetHeat(i, j) > 0 then
if contactmap.IsContact(i,j) == true then
bcount = bcount + 1
end
end
end
end
return bcount
end
function GetBestContacts()
recentbest.Save()
BestContactsAt = 1
Contacts = CountContacts()
for y = 1, 100 do
save.Quickload(y)
NewContacts = CountContacts()
if Contacts < NewContacts then
Contacts = NewContacts
BestContactsAt = y
end
save.Quickload(BestContactsAt)
end
print("slot", BestContactsAt, CountContacts(), "contacts")
end
function GetBestSlot()
BestScoreAt = 1
Score = current.GetScore()
for y = 1, 100 do
save.Quickload(y)
if Score < current.GetScore() then
Score = current.GetScore()
BestScoreAt = y
end
end
print("Best score =", Score, "Slot", BestScoreAt, CountContacts() , "contacts" )
end
function GetSlot()
local dlg = dialog.CreateDialog("Quicksave Slot Retrieval")
dlg.RS = dialog.AddSlider("Retrieve Slot#", SlotNo, 1, 100, 0)
dlg.GBS = dialog.AddCheckbox("Get Best Score Slot", false)
dlg.GBCS = dialog.AddCheckbox("Get Best Contacts Slot", false)
dlg.QA = dialog.AddCheckbox("Quit Already", QuitAlready)
dlg.OK = dialog.AddButton("Do It",1)
dialog.Show(dlg)
DoRetrieveSlot=dlg.RS.value
DoGetBestSlot = dlg.GBS.value
DoGetBestContactsSlot = dlg.GBCS.value
QuitAlready = dlg.QA.value
if DoGetBestContactsSlot == true then
GetBestContacts()
end
if DoGetBestSlot == true then
GetBestSlot()
end
if QuitAlready == false then
save.Quickload(DoRetrieveSlot)
print("Slot", DoRetrieveSlot, "restored", current.GetScore())
SlotNo = dlg.RS.value + 1
GetSlot()
end
end
function RandomBands()
for h = 3, structure.GetCount() do
if math.random(10) < 3 then
theta = math.rad(math.random(172))
phi = math.rad(math.random(259))
DD = band.Add(h, 1, 2, 5, theta, phi )
band.SetStrength(DD, math.random(3))
band.SetGoalLength(DD, math.random(5))
end
end
end
function IdealizeBits()
for s = 1, structure.GetCount() do
selection.DeselectAll()
for t = s, structure.GetCount() do
if structure.GetSecondaryStructure(t) == "L" then do
selection.Select(t)
end
else
break
end
end
structure.IdealizeSelected()
selection.DeselectAll()
end
end
function IdealizeAllInBits()
for s = 1, structure.GetCount()-1 do
selection.DeselectAll()
for t = s, s+1 do
selection.Select(t)
end
structure.IdealizeSelected()
selection.DeselectAll()
end
end
function Cleanup(err)
behavior.SetClashImportance(1)
print(err)
-- StopItAlready = NowIMeanIT
end
function CalulateFloppyScore()
FloppyScore=0
for a=1,structure.GetCount() do
for b= a, structure.GetCount() do
FloppyScore=FloppyScore+(structure.GetDistance(a,b)/structure.GetCount())/100
end
end
return FloppyScore
end
function round ( i )
return i - i % 0.001
end
function PushOut()
bcount = 0
count = structure.GetCount()
for i = 1, count-2 do
for j = i+4, count do
if contactmap.GetHeat(i, j) == 0 then
if contactmap.IsContact(i,j) then
b = band.AddBetweenSegments(i,j,5,5)
bcount = bcount + 1
band.SetGoalLength(b, 1.1 * band.GetLength(b))
band.SetStrength(b, 2)
end
end
end
end
end
function Interlude()
SortItWell("backbone")
for w = 1,3 do
selection.DeselectAll()
selection.Select(grid[w][2])
if grid[w][2] - 1 > 0 then
selection.Select(grid[w][2] - 1)
end
if grid[w][2] + 1 < structure.GetCount() then
selection.Select(grid[w][2] + 1)
end
structure.RebuildSelected(1,1000)
behavior.SetClashImportance(1)
structure.ShakeSidechainsAll(1)
behavior.SetClashImportance(0.2)
structure.WiggleAll(25)
end
end
function SortItWell(SubscorePart)
grid = {}
for i = 1, structure.GetCount() do
grid[i] = {}
grid[i][1] = current.GetSegmentEnergySubscore(i, SubscorePart)
grid[i][2]=i
end
switch = 1
while switch ~= 0 do
switch=0
for i=1, structure.GetCount()-1 do
if grid[i][1] > grid[i+1][1] then
grid[i][1],grid[i+1][1]=grid[i+1][1],grid[i][1]
grid[i][2],grid[i+1][2]=grid[i+1][2],grid[i][2]
switch = switch +1
--print(switch)
end
end
end
for i = 1, structure.GetCount() do
for j = 1, 2 do
--print(i)
--print(grid[i][j])
end
end
return grid
end
function DoTheThing()
for t = 1,2 do
selection.SelectAll()
structure.IdealizeSelected()
selection.DeselectAll()
behavior.SetClashImportance(0.2)
structure.WiggleAll(25)
Interlude()
end
end
function Crapshoot()
band.DeleteAll()
print("For Contact Puzzles.")
print("Needs secondary structure.")
--print("This runs for 99 iterations.")
--print("You may cancel at any time.")
for lll = 1, MOPIterations do
--IdealizeAllInBits()
FloppyScore = CalulateFloppyScore()
--DoTheThing()
if DoMOPMegalattice == true then
Megalattice()
end
Susband()
--PushOut()
BandNo = band.GetCount()
PrepareForContacts()
behavior.SetClashImportance(0)
structure.WiggleAll(5)
band.DisableAll()
structure.WiggleAll(5)
band.EnableAll()
--behavior.SetClashImportance(0.2)
RandomBands()
structure.WiggleAll(5)
for m = BandNo + 1, band.GetCount() do
band.Delete(band.GetCount())
end
behavior.SetClashImportance(1)
structure.ShakeSidechainsAll(1)
behavior.SetClashImportance(0.2)
structure.WiggleAll(5)
band.DeleteAll()
if DoMOPMegalattice == true then
Megalattice()
end
Susband()
structure.WiggleAll(5)
band.DeleteAll()
freeze.UnfreezeAll()
IdealizeBits()
structure.WiggleAll(5)
RepairCutpoints()
--DoTheThing()
selection.DeselectAll()
behavior.SetClashImportance(1)
structure.ShakeSidechainsAll(1)
behavior.SetClashImportance(0.2)
structure.WiggleAll(25)
--DoTheThing()
if DoMOPMegalattice == true then
Megalattice()
end
Susband()
PrepareForContacts()
behavior.SetClashImportance(1)
structure.ShakeSidechainsAll(1)
behavior.SetClashImportance(0.2)
structure.WiggleAll(5)
band.DeleteAll()
RepairCutpoints()
freeze.UnfreezeAll()
behavior.SetClashImportance(1)
structure.ShakeSidechainsAll(1)
behavior.SetClashImportance(0.2)
structure.WiggleAll(25)
--DoTheThing()
behavior.SetClashImportance(1)
structure.ShakeSidechainsAll(1)
behavior.SetClashImportance(0.2)
structure.WiggleAll(25)
save.Quicksave(lll)
print(CountContacts(), "contacts, slot", lll, round(current.GetScore()))
print('FloppyScore=',round(CalulateFloppyScore()))
--[[if FloppyScore < CalulateFloppyScore() * 1.1 and lll == 1 then
FloppyScore = CalulateFloppyScore()
print("Resetting to", 100)
save.Quickload(100)
end
if FloppyScore < CalulateFloppyScore() * 1.1 and lll > 1 then
save.Quickload(lll-1)
FloppyScore = CalulateFloppyScore()
print("Resetting to", lll-1)
end]]--
band.DeleteAll()
end
end
math.randomseed(recipe.GetRandomSeed())
print(CountContacts(), "contacts", round(current.GetScore()))
print("Saved in Slot 100")
print('FloppyScore=',round(CalulateFloppyScore()))
recentbest.Save()
save.Quicksave(100)
--
--IdealizeBits()
Crapshoot()
--xpcall(Crapshoot,GetSlot)
end
function Pearl()
-- "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,true,true)
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
function Annealer()
--drjr-Alien Downloaded
--[[possibly not properly acredited.]]--
ss=no --Sheet Straightener
SSBandLength=9.5
SSBandStrength=1.5
MinimumDistance=8
BandStrength=1.5
StartBandLength=7
EndBandLength=5
PushBands=get_segment_count()/3
--compressor loss rav3n_pl
minDist=10 --minimum spatial distance between banding segments
maxDist=20 --maximum spatial distance between banding segments
compressFrac=4 --make bands shorter by that much points
--was at 4
minSkip=10 --minimum segment distance between banded segments
numBands=get_segment_count()/7 --how many bands use at once
bandStr=1 --band strenght
pullingCI=0.3 --clash impotrance during pull
maxLoss=50 --maximum acceptable LOSS after BF/PF. also lowering fuzeScore
reloadBest=4 --reload best solution after that many worst ones
fuzeScore=10 --how close we have to be to run BF/PF
usePF=false --true --use PinkFuse after qStab
useBF=false --true --use BlueFuse after qStab.
--fuzes are started form SAME state, NOT one after one!
allLoop=false --work in all-loop mode. sometimes work better than structure mode :)
numTries=10000 --how many copmpress loops
function BBANG()
print('Starting BBANG (Better(Better(After New Geometry)))')
recentbest.Save()
selection.SelectAll()
save.Quicksave(1) --stores original
structure.WiggleSelected(25)
save.Quickload(1)
structure.ShakeSidechainsSelected(1)
structure.WiggleSelected(25)
recentbest.Restore()
save.Quicksave(1)
behavior.SetClashImportance(0.1)
structure.ShakeSidechainsSelected(1)
behavior.SetClashImportance(MaxCI)
structure.WiggleSelected(15)
save.Quickload(1)
behavior.SetClashImportance(0.1)
structure.ShakeSidechainsSelected(1)
structure.WiggleSelected(15)
behavior.SetClashImportance(MaxCI)
structure.WiggleSelected(15)
save.Quickload(1)
behavior.SetClashImportance(0.1)
structure.ShakeSidechainsSelected(1)
structure.WiggleSelected(15)
behavior.SetClashImportance(MaxCI)
structure.ShakeSidechainsSelected(1)
structure.WiggleSelected(15)
recentbest.Restore()
print('Halfway done...')
save.Quicksave(2)
behavior.SetClashImportance(0.1)
structure.ShakeSidechainsSelected(1)
structure.WiggleSelected(15)
behavior.SetClashImportance(MaxCI)
structure.WiggleSelected(15)
save.Quickload(2)
behavior.SetClashImportance(0.1)
structure.ShakeSidechainsSelected(1)
structure.WiggleSelected(15)
behavior.SetClashImportance(MaxCI)
structure.ShakeSidechainsSelected(1)
structure.WiggleSelected(15)
recentbest.Restore()
blueRfuse()
end
function SheetStraightener()
for s=1,get_segment_count()-2 do
if get_ss(s)=="E" then do
if get_ss(s+2)=="E" then do
band_add_segment_segment(s,s+2)
end
else end
end
else end
end
NewNewBandNo=get_band_count()
for m=NewBandNo+1,NewNewBandNo do
band_set_length(m,SSBandLength)
band_set_strength(m,SSBandStrength)
end
end
function SewTheSheets() --M. Suchard
print ('sewing the sheets')
-- sew sheets if near
nbsegtot=get_segment_count()
for noseg =2,nbsegtot do
for deuxseg =noseg+1,nbsegtot do
if (get_segment_distance(noseg, deuxseg)< 8 and get_ss(noseg)=='E' and get_ss(deuxseg)=='E' )then
band_add_segment_segment(noseg,deuxseg)
end
end
end
end
-- "dirty_dozen"
-- reports 12 worst-scoring segments for manual attention
-- code by smith92clone 6/21/10
-- contribution & integration of quicksort, minor cosmetic adjustments to report format - dimension9 6/21/10
-- quicksort from rosettacode.org
-- http://rosettacode.org/wiki/Sorting_algorithms/Quicksort
-- get all the segment scores and sort them
function get_all_seg_scores(start,finish)
local i
local seg_list = {}
for i= 1,get_segment_count() do
worstScore=get_segment_score_part('clashing',i)
score_set = {}
score_set.index = i
score_set.score = worstScore
seg_list[#seg_list+1] = score_set
end
return seg_list
end
--[[function sort_rebuild_list(seg_list) -- d9; substituted quicksort
if seg_list == nil then
print("sort_rebuild_list: seg_list is nil")
abort = abort + 1 -- this will stop program
end
-- binary sort
local outer
local inner
local seg_list_count = # seg_list
for outer = 1, seg_list_count-1 do
for inner = 1, seg_list_count-outer-1 do
local a = seg_list[inner+1]
local b = seg_list[inner]
if a.score < b.score then
seg_list[inner+1] = b
seg_list[inner] = a
end
end -- end of inner loopok, two tables in
end -- end of outer loop
return seg_list
end]]
--in-place quicksort
function quicksort(t, start, endi)
start, endi = start or 1, endi or #t
if(endi - start < 2) then return t end
local pivot = start
for i = start + 1, endi do
if t[i].score <= t[pivot].score then --d9; only adaptation needed ( add ".score")
local temp = t[pivot + 1]
t[pivot + 1] = t[pivot]
if(i == pivot + 1) then
t[pivot] = temp
else
t[pivot] = t[i]
t[i] = temp
end
pivot = pivot + 1
end
end
t = quicksort(t, start, pivot - 1)
return quicksort(t, pivot + 1, endi)
end
function the_list()
segment_list = get_all_seg_scores(1,get_segment_count())
--new_segment_list = sort_rebuild_list(segment_list) --d9; substitute quicksort
new_segment_list = quicksort(segment_list, 1, #segment_list)
--for jj=1,24 do --#new_segment_list --d9; only report 12 worst at a time (fits in window + it's all that's needed)
--print(jj," - segment # ",new_segment_list[jj].index," = ",new_segment_list[jj].score) --d9; added whitespace, removed brackets
--end
end
function blueRfuse()
set_behavior_clash_importance(0.2)
do_shake(1)
do_global_wiggle_all(25)
set_behavior_clash_importance(1)
do_shake(1)
do_global_wiggle_all(25)
set_behavior_clash_importance(0.05)
do_shake(1)
set_behavior_clash_importance(1)
do_global_wiggle_all(25)
set_behavior_clash_importance(0.07)
do_shake(1)
set_behavior_clash_importance(1)
do_global_wiggle_all(25)
set_behavior_clash_importance(0.3)
do_global_wiggle_all(15)
set_behavior_clash_importance(1)
do_global_wiggle_all(25)
end
function ShortFuse()
set_behavior_clash_importance(0.2)
do_shake(1)
do_global_wiggle_all(25)
set_behavior_clash_importance(1)
do_shake(1)
do_global_wiggle_all(25)
set_behavior_clash_importance(0.05)
do_shake(1)
set_behavior_clash_importance(1)
do_global_wiggle_all(25)
end
function ShorteRFuse()
set_behavior_clash_importance(0.2)
do_shake(1)
do_global_wiggle_all(25)
set_behavior_clash_importance(1)
do_shake(1)
do_global_wiggle_all(25)
end
function FreezeHelices()
for y=1,get_segment_count() do
deselect_all()
if get_ss(y)=="H" then do
select_index(y)
do_freeze(true,true)
end
else end
end
end
function FreezeSheets()
for x=1,get_segment_count() do
deselect_all()
if get_ss(x)=="E" then do
select_index(x)
do_freeze(true,true)
end
else end
end
end
function PushMePullYou()
reset_recent_best()
set_behavior_clash_importance(1)
BandLength=StartBandLength
the_list()
do_unfreeze_all()
band_disable()
--SheetStraightener()
for jj=1,PushBands do
for i=1,get_segment_count() do
if new_segment_list[jj].index-i>5 then do
if get_segment_distance(i,new_segment_list[jj].index) <= MinimumDistance then do
band_add_segment_segment(i,new_segment_list[jj].index)
end
else end
end
else end
end
end
NewBandNo=get_band_count()
for k=BandNo+1,NewBandNo do
band_set_strength(k,BandStrength)
band_set_length(k,BandLength)
end
--if ss==yes then do
--SheetStraightener()
--end
--else end
SewTheSheets()
print('Total No of Bands: ',get_band_count())
select_all()
set_behavior_clash_importance(pullingCI)
do_global_wiggle_all(3)
set_behavior_clash_importance(1)
--band_set_strength(0.3)
--do_global_wiggle_all(25)
NewBandNo=get_band_count()
for r=BandNo+1,NewBandNo do
band_delete(BandNo+1)
end
--band_delete()
band_disable()
quicksave(99)
do_global_wiggle_all(25)
quicksave(100)
Score100=get_score()
quickload(99)
do_shake(1)
do_global_wiggle_all(25)
if Score100>get_score() then do
quickload(100)
end
else end
band_disable()
--do_shake(1)
--do_global_wiggle_all(25)
ShortFuse()
--ShorteRFuse()
--blueRfuse()
band_enable()
end
--[[
Compressor v1
trying to compress protein
]]--
--[[
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 _MWC()
local S_Hi
local S_Lo
local C_Hi
local C_Lo
local F1
local F2
local F3
local T1
local T2
local T3
local A_Hi = 63551
local A_Lo = 25354
local M = 4294967296
local H = 65536
local S_Hi = math.floor(lngX / H)
local S_Lo = lngX - (S_Hi * H)
local C_Hi = math.floor(lngC / H)
local C_Lo = lngC - (C_Hi * H)
local F1 = A_Hi * S_Hi
local F2 = (A_Hi * S_Lo) + (A_Lo * S_Hi) + C_Hi
local F3 = (A_Lo * S_Lo) + C_Lo
local T1 = math.floor(F2 / H)
local T2 = F2 - (T1 * H)
lngX = (T2 * H) + F3
local T3 = math.floor(lngX / M)
lngX = lngX - (T3 * M)
lngC = math.floor((F2 / H) + F1)
return lngX
end
local function _abs(value)
if value < 0 then
value = -value
end
return value
end
local function _floor(value)
return value - (value % 1)
end
local function _randomseed(x)
lngX = x
end
local function _random(m,n)
if n == nil and m ~= nil then
n = m
m = 1
end
if (m == nil) and (n == nil) then
return _MWC() / 4294967296
else
if n < m then
return nil
end
return math.floor((_MWC() / 4294967296) * (n - m + 1)) + m
end
end
math=
{
abs = _abs,
floor = _floor,
random = _random,
randomseed = _randomseed,
}
--[[ End math library ]]--
function Score()
return get_score(true)
end
function seed()
local s=math.abs(Score())
s=s%0.001
s=1/s
while s<10000000 do s=s*10 end
s=s-s%1
math.randomseed(s)
end
seed()
segCnt=get_segment_count()
p=print
function round(x)--cut all afer 3-rd place
return x-x%0.001
end
function down(x)
return x-x%1
end
function Wiggle(how, iters, minppi)
if how==nil then how="wa" end
if iters==nil then iters=6 end
if minppi==nil then minppi=0.001 end
if iters>0 then
iters=iters-1
sp=Score()
if how == "s" then do_shake(1)
elseif how == "wb" then do_global_wiggle_backbone(1)
elseif how == "ws" then do_global_wiggle_sidechains(1)
elseif how == "wa" then do_global_wiggle_all(1)
end
ep = Score()
ig=ep-sp
if how~="s" then
if ig > minppi then Wiggle(how, iters, minppi) end
end
end
end
function AllLoop() --turning entire structure to loops
local ok=false
for i=1, segCnt do
local s=get_ss(i)
if s~="L" then
save_structure()
ok=true
break
end
end
if ok then
select_all()
replace_ss("L")
end
end
function BlueFuse()
p("BlueFuse...")
reset_recent_best()
select_all()
set_behavior_clash_importance(0.05)
do_shake(1)
set_behavior_clash_importance(1)
Wiggle()
set_behavior_clash_importance(0.07)
do_shake(1)
set_behavior_clash_importance(1)
Wiggle()
--restore_recent_best()
set_behavior_clash_importance(0.3)
do_global_wiggle_all(1)
set_behavior_clash_importance(1)
Wiggle()
restore_recent_best()
SaveBest()
quicksave(6)
end
bestScore=Score()
function SaveBest()
local g=Score()-bestScore
if g>0 then
p("Gained another ",round(g)," pts.")
bestScore=Score()
quicksave(3)
end
end
function FuseEnd()
set_behavior_clash_importance(1)
Wiggle()
Wiggle("s",1)
Wiggle()
SaveBest()
end
function Fuze1(ci1,ci2)
set_behavior_clash_importance(ci1)
Wiggle("s",1)
set_behavior_clash_importance(ci2)
Wiggle("wa",1)
FuseEnd()
end
function Fuze2(ci1,ci2)
set_behavior_clash_importance(ci1)
Wiggle("wa",1)
set_behavior_clash_importance(1)
Wiggle()
set_behavior_clash_importance(ci2)
Wiggle("wa",1)
FuseEnd()
end
function PinkFuse()
reset_recent_best()
p("PinkFuse...")
quicksave(4) -- store state before fuse
Fuze1(0.1,0.7)
quickload(4) -- load state before fuse
Fuze1(0.3,0.6)
quickload(4) -- load state before fuse
Fuze2(0.5,0.7)
quickload(4) -- load state before fuse
Fuze2(0.7,0.5)
restore_recent_best()
quicksave(5)
end
function qStab()
p("qStab...")
select_all()
set_behavior_clash_importance(0.1)
Wiggle("s",1)
set_behavior_clash_importance(1)
Wiggle("ws",1)
Wiggle()
Wiggle("s",1)
Wiggle()
SaveBest()
end
function MakeBandsOut(num)
local done=false
local s1=math.random(segCnt)
local s2=math.random(segCnt)
local blip1=math.random(segCnt)
local blip2=math.random(segCnt)
blip=(blip1-blip2)/segCnt
if s1>s2 then s1,s2=s2,s1 end
local d=get_segment_distance(s1,s2)
if s2-s1>=minSkip and d>=minDist and d<=maxDist then done=true end
if done then
num=num-1
band_add_segment_segment(s1,s2)
k=get_band_count()
band_set_length(k,d+1.44+blip)
--print('blip1= ',blip1)
--print('blip2= ',blip2)
--print('blip= ',blip)
--print(s1)
--print(s2)
--print(segCnt)
band_set_strength(k,bandStr)
end
if num>0 then MakeBandsOut(num) end
end
function MakeBandsIn(num)
local done=false
local s1=math.random(segCnt)
local s2=math.random(segCnt)
local blip1=math.random(segCnt)
local blip2=math.random(segCnt)
blip=(blip1-blip2)/segCnt
if s1>s2 then s1,s2=s2,s1 end
local d=get_segment_distance(s1,s2)
if s2-s1>=minSkip and d>=minDist and d<=maxDist then done=true end
if done then
num=num-1
band_add_segment_segment(s1,s2)
k=get_band_count()
band_set_length(k,d-1.76+blip)
--print('blip1= ',blip1)
--print('blip2= ',blip2)
--print('blip= ',blip)
--print(s1)
--print(s2)
--print(segCnt)
band_set_strength(k,bandStr)
end
if num>0 then MakeBandsIn(num) end
end
function Compressor()
numTries = 3
p("Starting Compressor, ",numTries," loops.")
quicksave(3)
badOnes=0
reset_recent_best()
if allLoop then AllLoop() end
local sscore=Score()
for i=1,numTries do
local ls=Score()
p("Compress loop ",i," of ",numTries," started. Current score: ",round(ls))
BBScore=0
for f=1,get_segment_count() do
BBScore=BBScore+get_segment_score_part('backbone',f)
end
print('Total Backbone Score= ',BBScore)
reset_recent_best()
quicksave(99)
for j=1,1 do
print('Round ',j)
band_enable()
--print('No of Bands: ',get_band_count())
MakeBandsOut(numBands)
set_behavior_clash_importance(pullingCI)
select_all()
--SewTheSheets()
do_global_wiggle_all(25)
--print('No of Bands: ',get_band_count())
NewBandNo=get_band_count()
for r=BandNo+1,NewBandNo do
band_delete(BandNo+1)
end
band_disable()
do_unfreeze_all()
set_behavior_clash_importance(1)
do_global_wiggle_all(25)
do_shake(1)
--ShorteRFuse()
band_enable()
print('No of Bands: ',get_band_count())
MakeBandsIn(numBands)
set_behavior_clash_importance(pullingCI)
select_all()
--SewTheSheets()
do_global_wiggle_all(25)
print('No of Bands: ',get_band_count())
NewBandNo=get_band_count()
for r=BandNo+1,NewBandNo do
band_delete(BandNo+1)
end
band_disable()
do_unfreeze_all()
set_behavior_clash_importance(1)
do_global_wiggle_all(25)
do_shake(1)
--ShorteRFuse()
end
--[[for k=1,3 do
band_enable()
print('No of Bands: ',get_band_count())
MakeBandsIn(numBands)
set_behavior_clash_importance(pullingCI)
select_all()
SewTheSheets()
do_global_wiggle_all(25)
print('No of Bands: ',get_band_count())
NewBandNo=get_band_count()
for r=BandNo+1,NewBandNo do
band_delete(BandNo+1)
end
band_disable()
do_unfreeze_all()
set_behavior_clash_importance(1)
do_global_wiggle_all(25)
do_shake(1)
ShorteRFuse()
end]]--
blueRfuse()
--BBANG()
quickload(99)
restore_recent_best()
quicksave(99)
--FreezeSheets()
--FreezeHelices()
--PushMePullYou()
band_enable()
end
end
reset_recent_best()
quicksave(99)
BandNo=get_band_count()
--SheetStraightener()
Compressor() --go!
end
function PushOut()
bcount = 0
count = structure.GetCount()
for i = 1, count-2 do
for j = i+6, count do
if contactmap.GetHeat(i, j) == 0 then
if contactmap.IsContact(i,j) then
b = band.AddBetweenSegments(i,j,5,5)
bcount = bcount + 1
band.SetGoalLength(b, 1.1 * band.GetLength(b))
band.SetStrength(b, 2)
end
end
end
end
end
function BlueFuse()
MaxCI=1
print('Blue Fuse')
behavior.SetClashImportance(.05)
structure.ShakeSidechainsAll(1)
behavior.SetClashImportance(MaxCI)
structure.WiggleAll(25)
behavior.SetClashImportance(.07)
structure.ShakeSidechainsAll(1)
behavior.SetClashImportance(MaxCI)
structure.WiggleAll(25)
--recentbest.Restore()
behavior.SetClashImportance(.3)
structure.WiggleAll(1)
behavior.SetClashImportance(MaxCI)
structure.WiggleAll(25)
--recentbest.Restore()
end
-- tlaloc scripts 4.00
--=================================================================================================|
-- You must keep the following attribution and notice in any republication of this script. Please
-- remove the word 'tlaloc' from the script name on the fold.it web site recipe page if you
-- publicly release a modification of the script.
--=======================================
-- Author: tlaloc (aka Greg Reddick)
-- Copyright 2010-2012 by Greg Reddick
-- Except for parts that are specifically excluded in the comments, which came from other sources,
-- this script is licensed as follows:
-- Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
-- http://creativecommons.org/licenses/by-nc-sa/3.0/
--=======================================
-- Conventions used in this file can be found at:
-- http://foldit.wikia.com/wiki/Tlaloc_Script_Standards
--=======================================
-- tlaloc standard library
fsl = {}
script = {}
group = {}
banding = {}
-----------------------------------------
-- fsl (Foldit Standard Library)
local _scoreRecentBest = -999999.9
local _initialized = false
local _scoreStart = -999999.9
local _saveSlots = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
local _printStatus = true
local _bandsAtStart = 0
local amino = {'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'y' }
local function _BandAddBetweenSegments(segmentIndex1, segmentIndex2)
fsl.Print('Adding band between segment '..segmentIndex1..' and '..segmentIndex2)
band.AddBetweenSegments(segmentIndex1, segmentIndex2)
end
local function _BandAddRandom()
local segmentCount = structure.GetCount()
local x = math.random(1, segmentCount)
local y
repeat
y = math.random(1, segmentCount)
until math.abs(x - y) >= 2
fsl.BandAddBetweenSegments(x, y)
return x, y
end
local function _BandDeleteScriptStart()
fsl.Print('Deleting created bands')
if fsl.BandsAtStart() == 0 then
band.DeleteAll()
else
for i=band.GetCount(), fsl.BandsAtStart() + 1, -1 do
band.Delete(i)
end
end
end
local function _BandDisable()
fsl.Print('Disabling bands')
band.DisableAll()
end
local function _BandDisableScriptStart()
fsl.Print('Disabling created bands')
if fsl.BandsAtStart() == 0 then
band.DisableAll()
else
for i=fsl.BandsAtStart() + 1, band.GetCount() do
band.Disable(i)
end
end
end
local function _BandEnable()
fsl.Print('Enabling bands')
band.EnableAll()
end
local function _BandEnableScriptStart()
fsl.Print('Enabling created bands')
if fsl.BandsAtStart() == 0 then
band.EnableAll()
else
for i=fsl.BandsAtStart() + 1, band.GetCount() do
band.Enable(i)
end
end
end
local function _BandStrength(strength)
-- Just modifies all bands strengths. The UI only lets the strength go from 0.5 to 1.5, and
-- it's tedious to modify a lot of bands. Great when you really, really want the backbone to
-- move and it's being stubborn.
fsl.Print('Setting band strength to '..strength)
for i=1, band.GetCount() do
band.SetStrength(i, strength)
end
end
local function _BandsAtStart()
return band.GetCount()
end
local function _BlueFuse(iterations, sigma, ...)
-- Based on vertex's BlueFuse
-- This function is not covered by the Creative Commons license given at the start of the
-- script since it a port of Vertex's BlueFuse algorithm, with some enhancements.
local arg = {...}
local saveSlot = fsl.RequestSaveSlot()
local scoreStart = current.GetScore()
local scoreBest = scoreStart
save.Quicksave(saveSlot)
fsl.SetBehaviorClashImportance(MaxCI)
for i=1, #arg do
fsl.SetBehaviorClashImportance(arg[i])
local printStatus = fsl.PrintStatus(false)
fsl.Shake(1)
fsl.SetBehaviorClashImportance(MaxCI)
fsl.WiggleAll(iterations)
fsl.MakeStable(false, sigma, iterations)
fsl.PrintStatus(printStatus)
local score = current.GetScore()
if score > scoreBest then
scoreBest = score
save.Quicksave(saveSlot)
fsl.ReportAndLockScoreIncrease()
end
end
save.Quickload(saveSlot)
fsl.ReleaseSaveSlot(saveSlot)
local delta = current.GetScore() - scoreStart
fsl.Print('Bluefuse complete. Score change='..delta)
return delta
end
local function _ConvertToLoops()
-- Converts the entire protein into loops, if it wasn't already all loops. It saves the
-- original structure so that it can be retrieved pressing Ctrl+9.
fsl.Print('Converting structure to loops')
local countSegments = structure.GetCount()
-- Only overwrite the saved structure if the current structure isn't all loops
local nonLoops = false
for i=1, countSegments do
if structure.GetSecondaryStructure(i) ~= 'L' then
nonLoops = true
break
end
end
if not nonLoops then
save.SaveSecondaryStructure()
end
local structure = {}
for i=1, countSegments do
structure[i] = structure.GetSecondaryStructure(i)
end
selection.SelectAll()
structure.SetSecondaryStructure('L')
return structure
end
local function _FindBestStart()
-- Performs a Select MultiStart, then shakes out each start to find the best one.
assert(band.GetCount() == 0, 'Must delete existing bands\nbefore running this code.')
local saveSlot = fsl.RequestSaveSlot()
local scoreBest = -999999.9
local indexBest = 0
local scores = fsl.SelectMultiStart(500, false)
local countTries = #scores
for i=1, countTries do
fsl.PrintTries('Find Best Start', i, countTries)
fsl.Print('Current best is start #'..indexBest..' with score '..scoreBest)
-- find start that has the score score
while true do
fsl.ResetPuzzle()
if current.GetScore() == scores[i] then
break
end
end
fsl.ResetRecentBest()
fsl.MakeStable(nil, .01, 1)
fsl.BlueFuse(1, .01, .05, .07, .03)
script.Settle(.1, 1, 1, 2, 1, 2, 2, 2)
local score = current.GetScore()
if score > scoreBest then
scoreBest = score
indexBest = i
save.Quicksave(saveSlot)
end
end
save.Quickload(saveSlot)
fsl.ResetRecentBest()
fsl.Print('Best start was #'..indexBest)
fsl.ReleaseSaveSlot(saveSlot)
end
local function _FindCenterSegment()
-- Finds the segment that is the least distance to all other segments
-- returns index of the center segment
fsl.Print('Finding the center segment')
local segmentCount = structure.GetCount()
local minDistance = 100000.0
local distance
local indexCenter
for i=1,segmentCount do
distance = 0
for j=1,segmentCount do
distance = distance + structure.GetDistance(i, j)
end
if(distance < minDistance) then
minDistance = distance
indexCenter = i
end
end
return indexCenter
end
local function _FindMutatableSegments()
local changeableSegments = {}
for i=1, structure.GetCount() do
if structure.IsMutable(i) then
changeableSegments[#changeableSegments + 1] = i
end
end
return changeableSegments
end
local function _FreezeAll()
fsl.Print('Freezing all segments')
selection.SelectAll()
freeze.FreezeSelected(true, true)
end
local function _FreezeSegments(interval, start)
fsl.Print('Freezing every '..interval..' segments')
fsl.Print(' starting at segment '..start)
selection.DeselectAll()
for i=start, structure.GetCount(), interval do
selection.Select(i)
end
freeze.FreezeSelected(true, true)
end
local function _GetScoreStart()
return _scoreStart
end
local function _GetSegmentScores(segmentFirst, segmentLast)
local score = 0
for i=segmentFirst, segmentLast do
score = score + current.GetSegmentEnergyScore(i)
end
return score
end
local function _LocalRebuild(iterations)
structure.RebuildSelected(iterations)
fsl.ReportAndLockScoreIncrease()
end
local function _LocalWiggleInterval(interval, start, iterations)
local saveSlot = fsl.RequestSaveSlot()
fsl.Print('LocalWiggle every '..interval..' segments')
fsl.Print(' starting at segment '..start)
local first
local segmentCount = structure.GetCount()
for i=start, segmentCount, interval do
selection.DeselectAll()
local first = i
if first < 1 then
first = 1
end
local last = i + interval
if last > segmentCount then
last = segmentCount
end
selection.SelectRange(first, last)
local score = current.GetScore()
save.Quicksave(saveSlot)
structure.LocalWiggleAll(iterations, true, true)
if current.GetScore() <= score then
save.Quickload(saveSlot)
end
fsl.ReportAndLockScoreIncrease()
end
fsl.ReleaseSaveSlot(saveSlot)
end
local function _MakeDeNovo()
assert(band.GetCount() == 0, 'Must delete existing bands\nbefore running this code.')
save.Quicksave(1)
fsl.SetPristine()
fsl.SetBehaviorClashImportance(0)
fsl.BandAddBetweenSegments(1, structure.GetCount())
band.SetGoalLength(i, 3000.0)
band.SetStrength(i, 10.0)
for i=1, 10 do
fsl.Shake(1)
fsl.WiggleAll(1)
end
fsl.BandDeleteScriptStart()
fsl.SetBehaviorClashImportance(MaxCI)
end
local _shakesWin = 0
local _wigglesWin = 0
local _tiesWin = 0
local function _MakeStable(shakeFirst, sigmaStableScore, iterations)
-- shakeFirst
-- if true shakes before wiggling
-- if false wiggles before shaking
-- if nil, tries it both ways and takes the best score
local saveSlotOriginal = fsl.RequestSaveSlot()
local saveSlotShake = fsl.RequestSaveSlot()
local prevScore = 0
local delta
local score
if shakeFirst == nil then
save.Quicksave(saveSlotOriginal)
fsl.Print('Trying shake first')
local scoreShakeFirst = fsl.MakeStable(true, sigmaStableScore, iterations)
save.Quicksave(saveSlotShake)
save.Quickload(saveSlotOriginal)
fsl.Print('Trying wiggle first')
local scoreWiggleFirst = fsl.MakeStable(false, sigmaStableScore, iterations)
fsl.Print('Shake='..scoreShakeFirst..' Wiggle='..scoreWiggleFirst)
if scoreShakeFirst > scoreWiggleFirst then
_shakesWin = _shakesWin + 1
fsl.Print('Restoring shake result')
save.Quickload(saveSlotShake)
else
if scoreShakeFirst == scoreWiggleFirst then
_tiesWin = _tiesWin + 1
else
_wigglesWin = _wigglesWin + 1
end
fsl.Print('Keeping wiggle result')
end
fsl.Print('Shakes win='.._shakesWin..' Wiggles win='.._wigglesWin..' ties='.._tiesWin)
else
repeat
local printStatus = fsl.PrintStatus(false)
if shakeFirst then
fsl.Shake(1)
fsl.WiggleAll(iterations)
fsl.WiggleBackbone(iterations)
fsl.WiggleSidechains(iterations)
else
fsl.WiggleAll(iterations)
fsl.WiggleBackbone(iterations)
fsl.WiggleSidechains(iterations)
fsl.Shake(1)
end
fsl.PrintStatus(printStatus)
score = current.GetScore()
delta = math.abs(score - prevScore)
if prevScore ~= 0 then
fsl.Print('delta='..delta..' goal='..sigmaStableScore)
end
prevScore = score
until delta <= sigmaStableScore
fsl.WiggleSidechains(iterations)
end
fsl.ReleaseSaveSlot(saveSlotShake)
fsl.ReleaseSaveSlot(saveSlotOriginal)
return current.GetScore()
end
local function _Mutate(iterations)
fsl.Print('Mutating for '..iterations..' iterations')
structure.MutateSidechainsAll(iterations)
fsl.ReportAndLockScoreIncrease()
end
local function _Print(...)
if _printStatus then
print(...)
end
end
local function _PrintStatus(status)
local prevStatus = _printStatus
_printStatus = status
return prevStatus
end
local function _PrintLine()
fsl.Print('--------------------------------------------------')
end
local function _PrintTries(functionName, try, tries, keyword)
if keyword == nil then
keyword = 'try'
end
if tries == nil then
fsl.Print('**** '..functionName..' '..keyword..' '..try..' ****')
else
fsl.Print('**** '..functionName..' '..keyword..' '..try..' of '..tries..' ****')
end
end
local function _ReleaseSaveSlot(slot)
_saveSlots[#_saveSlots + 1] = slot
end
local function _ReportAndLockScoreIncrease()
local score = recentbest.GetScore()
if score > _scoreRecentBest then
recipe.ReportStatus()
_scoreRecentBest = score
end
end
local function _ReportScoreImprovement(scoreRecentBest)
if scoreRecentBest == nil then
scoreRecentBest = recentbest.GetScore()
end
recipe.ReportStatus()
local improvement = scoreRecentBest - fsl.GetScoreStart()
return improvement
end
local function _RequestSaveSlot()
assert(#_saveSlots > 0, 'Out of save slots')
local saveSlot = _saveSlots[#_saveSlots]
_saveSlots[#_saveSlots] = nil
return saveSlot
end
local function _ResetPuzzle()
fsl.Print('Resetting puzzle')
puzzle.StartOver()
end
local function _ResetRecentBest()
fsl.Print('Saving recent best')
recentbest.Save()
_scoreRecentBest = current.GetScore()
end
local function _RestoreOriginalStructure()
-- Resets to the structure available at the time the puzzle is reset. Since alignment tool
-- applies structure after that time, this will not recover that structure. Furthermore, this
-- works randomly on puzzles that are multistart, where it always takes the reset structure,
-- which is random. If the original structure is all loops, then it refuses to do anything,
-- and will keep the current structure.
fsl.Print('Restoring original structure')
local saveSlot = fsl.RequestSaveSlot()
save.Quicksave(saveSlot)
fsl.ResetPuzzle()
local allLoops = true
for i=1, structure.GetCount() do
if structure.GetSecondaryStructure(i) ~= "L" then
allLoops = false
break
end
end
if allLoops then
save.Quickload(saveSlot)
else
save.SaveSecondaryStructure()
save.Quickload(saveSlot)
save.LoadSecondaryStructure()
end
fsl.ReleaseSaveSlot(saveSlot)
end
local function _RestoreRecentBest()
--fsl.Print('Restoring recent best')
--recentbest.Restore()
end
local function _RestoreStructure(structure)
fsl.Print('Restoring structure')
for i=1, structure.GetCount() do
selection.DeselectAll()
selection.Select(i)
structure.SetSecondaryStructure(structure[i])
end
end
local function _Round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
local function _ScriptBegin(functionName)
recipe.SectionStart(functionName)
fsl.ReportAndLockScoreIncrease()
return functionName, current.GetScore()
end
local function _ScriptEnd(functionName, scoreStart, noRestore, functionExecute, ...)
if not noRestore then
fsl.RestoreRecentBest()
end
local delta = current.GetScore() - scoreStart
recipe.ReportStatus()
fsl.Print(functionName..' complete. Score change='..delta)
if functionExecute ~= nil then
functionExecute(...)
fsl.ResetRecentBest()
end
recipe.SectionEnd()
return delta
end
local function _ScriptFinalize()
recipe.SectionEnd()
assert(#_saveSlots == 10, 'One or more save slots not released')
end
local function _ScriptInitialize()
assert(not _initialized, 'Initialized more than once')
_initialized = true
--math.randomseed(recipe.GetRandomSeed())
math.randomseed(os.clock() * 1000)
_scoreStart = current.GetScore()
_bandsAtStart = band.GetCount()
fsl.ResetRecentBest()
recipe.SectionStart("Script")
return _scoreStart
end
local function _SelectMultiStart(tries, saveStart, start)
-- This script figures out how many different starts there are, and saves them into the
-- quickload save spots. You can use ctrl+1, ctrl+2, or ctrl+3 to load the first 3 after
-- running this script. You can also change the parameter to SelectMultiStart to select ones
-- that appear beyond the first 3.
assert(band.GetCount() == 0, 'Must delete existing bands\nbefore running this code.')
local puzzle = {}
local scores = {}
local count = 0
fsl.SetPristine()
fsl.ResetRecentBest()
-- Find the unique starting scores
for i=1, tries do
fsl.ResetPuzzle()
local score = current.GetScore()
if puzzle[score] == nil then
count = count + 1
puzzle[score] = count
scores[count] = score
end
end
-- Bubble sort to sort by score. Inefficient, but
-- I don't care because the number will always be
-- small.
for i=1,count - 1 do
for j = count, i + 1, -1 do
if scores[i] < scores[j] then
scores[j], scores[i] = scores[i], scores[j]
puzzle[scores[j]] = i
puzzle[scores[i]] = j
end
end
end
if saveStart then
for i=1, count do
fsl.Print('puzzle #'..i..' has score '..scores[i])
if i < 10 then
while true do
fsl.ResetPuzzle()
if current.GetScore() == scores[i] then
save.Quicksave(i)
break
end
end
end
end
if start ~= nil then
if start > count then
start = count
fsl.Print('There are only '..count..' number of starts.')
end
fsl.Print('Loading start #'..start)
save.Quickload(start)
else
fsl.RestoreRecentBest()
end
else
fsl.RestoreRecentBest()
end
fsl.Print('There are '..count..' starts')
return scores
end
local function _SetBehaviorClashImportance(importance)
fsl.Print('Setting clash importance to '..importance)
behavior.SetClashImportance(importance)
end
local function _SetPristine(noClash, noUnfreeze, noDeleteBands, noSelectAll)
-- Clean up the environment
local printStatus = fsl.PrintStatus(false)
if not noClash then
fsl.SetBehaviorClashImportance(MaxCI)
end
if not noUnfreeze then
fsl.UnfreezeAll()
end
if not noDeleteBands then
band.DeleteAll()
_bandsAtStart = 0
end
if not noSelectAll then
selection.DeselectAll()
selection.SelectAll()
end
fsl.PrintStatus(printStatus)
end
local function _Shake(iterations)
fsl.Print('Shaking sidechains for '..iterations..' iterations')
structure.ShakeSidechainsAll(iterations)
fsl.ReportAndLockScoreIncrease()
end
local function _UnfreezeAll()
fsl.Print('Unfreezing all segments')
freeze.UnfreezeAll()
end
local function _WiggleAll(iterations)
fsl.Print('Wiggle all for '..iterations..' iterations')
structure.WiggleAll(iterations)
fsl.ReportAndLockScoreIncrease()
end
local function _WiggleBackbone(iterations)
fsl.Print('Wiggle backbone for '..iterations..' iterations')
structure.WiggleAll(iterations, true, false)
fsl.ReportAndLockScoreIncrease()
end
local function _WiggleSidechains(iterations)
fsl.Print('Wiggle sidechains for '..iterations..' iterations')
structure.WiggleAll(iterations, false, true)
fsl.ReportAndLockScoreIncrease()
end
fsl =
{
BandAddBetweenSegments = _BandAddBetweenSegments,
BandAddRandom = _BandAddRandom,
BandDeleteScriptStart = _BandDeleteScriptStart,
BandDisable = _BandDisable,
BandDisableScriptStart = _BandDisableScriptStart,
BandEnable = _BandEnable,
BandEnableScriptStart = _BandEnableScriptStart,
BandStrength = _BandStrength,
BandsAtStart = _BandsAtStart,
BlueFuse = _BlueFuse,
ConvertToLoops = _ConvertToLoops,
FindBestStart = _FindBestStart,
FindCenterSegment = _FindCenterSegment,
FindMutatableSegments = _FindMutatableSegments,
FreezeAll = _FreezeAll,
FreezeSegments = _FreezeSegments,
GetScoreStart = _GetScoreStart,
GetSegmentScores = _GetSegmentScores,
LocalRebuild = _LocalRebuild,
LocalWiggleInterval = _LocalWiggleInterval,
MakeDeNovo = _MakeDeNovo,
MakeStable = _MakeStable,
Mutate = _Mutate,
Print = _Print,
PrintLine = _PrintLine,
PrintStatus = _PrintStatus,
PrintTries = _PrintTries,
ReleaseSaveSlot = _ReleaseSaveSlot,
RequestSaveSlot = _RequestSaveSlot,
ReportAndLockScoreIncrease = _ReportAndLockScoreIncrease,
ReportScoreImprovement = _ReportScoreImprovement,
ResetPuzzle = _ResetPuzzle,
ResetRecentBest = _ResetRecentBest,
RestoreOriginalStructure = _RestoreOriginalStructure,
RestoreRecentBest = _RestoreRecentBest,
RestoreStructure = _RestoreStructure,
Round = _Round,
ScriptBegin = _ScriptBegin,
ScriptEnd = _ScriptEnd,
ScriptFinalize = _ScriptFinalize,
ScriptInitialize = _ScriptInitialize,
SelectMultiStart = _SelectMultiStart,
SetBehaviorClashImportance = _SetBehaviorClashImportance,
SetPristine = _SetPristine,
Shake = _Shake,
UnfreezeAll = _UnfreezeAll,
WiggleAll = _WiggleAll,
WiggleBackbone = _WiggleBackbone,
WiggleSidechains = _WiggleSidechains,
}
-- End fsl (Foldit Standard Library)
-------------------------------------------------
-- Banding library
local function _CreateBandsToCenter()
-- Partly based on some ideas in 'Bands from center' by srssmith92
fsl.Print('Creating bands to center')
local indexCenter = fsl.FindCenterSegment()
fsl.BandDisable()
for i=1, structure.GetCount() do
if(i ~= indexCenter) then
-- If hydrophobic
if structure.IsHydrophobic(i) then
fsl.BandAddBetweenSegments(i,indexCenter)
end
end
end
end
local function _CreateRandomBands()
fsl.Print('Creating random bands')
fsl.BandDisable()
for i=1, math.floor(structure.GetCount()/4) do
fsl.BandAddRandom()
end
end
local function _CreateHydrophobeBands()
fsl.Print('Creating hydrophobe bands')
local countSegments = structure.GetCount()
fsl.BandDisable()
for x=1, countSegments do
if structure.IsHydrophobic(x) then
for y=x+2, countSegments do
if structure.IsHydrophobic(y) then
fsl.BandAddBetweenSegments(x, y)
end
end
end
end
end
local banding =
{
CreateBandsToCenter = _CreateBandsToCenter,
CreateRandomBands = _CreateRandomBands,
CreateHydrophobeBands = _CreateHydrophobeBands,
}
-- End banding library
-------------------------------------------------
-- End tlaloc standard library
--===============================================
-------------------------------------------------
-- tlaloc BandsForNative
--[[
Creates bands from first "knuckle" of the sidechain
for each segment for Quest for the Native puzzles.
You will still need to position each of the bands,
but at least you don't have to create them.
--]]
local function _BandAdd(segment, length, goalLength, strength)
local countSegments = structure.GetCount()
local segmentOrigin = segment
local segmentXAxis = segment + 1
local segmentYAxis = segment + 2
if segment > countSegments - 2 then
segmentXAxis = segment - 1
segmentYAxis = segment - 2
end
local knuckle = 5
if segmentOrigin == countSegments then
knuckle = 6
end
b = band.Add(segmentOrigin, segmentXAxis, segmentYAxis, length, 0, 0, knuckle)
band.SetStrength(b, strength)
band.SetGoalLength(b, goalLength)
return b
end
local function _BandsForNative()
local countSegments = structure.GetCount()
local continue = false
local segmentCurrent = 1
local oldNote = nil
for i=1, countSegments do
if structure.GetNote(i) == "Current" then
oldNote = i
segmentCurrent = i + 1
if segmentCurrent > countSegments then
segmentCurrent = countSegments
end
i = countSegments
end
end
local ask = dialog.CreateDialog("tlaloc Bands for Native")
ask.Segment = dialog.AddSlider("Current segment", segmentCurrent, 1, countSegments, 0)
ask.Strength = dialog.AddSlider("Band Strength", 10, 1, 10, 1)
ask.Comment = dialog.AddLabel("Will remove all current bands and replace them")
ask.Reband = dialog.AddCheckbox("Reband", false)
-- ask.BandToHelix = dialog.AddCheckbox("Band to Helixes", true)
-- ask.BandToSheet = dialog.AddCheckbox("Band to Sheet", true)
ask.OK = dialog.AddButton("Start", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
if dialog.Show(ask) > 0 then
segmentCurrent = ask.Segment.value
local strength = ask.Strength.value
if ask.Reband.value then
band.DeleteAll()
for i=1, segmentCurrent - 1 do
_BandAdd(i, .001, .001, strength)
end
end
_BandAdd(segmentCurrent, 3, 0, strength)
if oldNote ~= nil then
structure.SetNote(oldNote, "")
end
structure.SetNote(segmentCurrent, "Current")
end
end
-------------------------------------------------
-- tlaloc BandStrength
--[[
Allows you to set the band strength of all current bands.
--]]
local function _BandStrengthDialog()
if band.GetCount() > 0 then
local ask = dialog.CreateDialog("tlaloc BandStrength")
ask.Comment = dialog.AddLabel("Set all current bands to this strength")
ask.Strength = dialog.AddSlider("Strength", 1, .1, 10, 1)
ask.OK = dialog.AddButton("Change", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
if (dialog.Show(ask) > 0) then
fsl.BandStrength(ask.Strength.value)
end
else
local tell = dialog.CreateDialog("tlaloc BandStrength")
tell.Message = dialog.AddLabel("There are no bands to change.")
tell.OK = dialog.AddButton("Close", 0)
dialog.Show(tell)
end
end
-------------------------------------------------
-- tlaloc Cataclysm
--[[
Works the same as tlaloc contract, but uses random bands instead of bands to center.
--]]
local function _Cataclysm(tries)
local functionName, scoreStart = fsl.ScriptBegin('tlaloc Cataclysm')
for i=1,tries do
fsl.PrintTries(functionName, i, tries)
script.RepeatContract(7, .03, 10, .03, 1, 1, banding.CreateRandomBands)
script.RepeatBlueFuse(1, .01, .05, .07, .03)
end
return fsl.ScriptEnd(functionName, scoreStart, false)
end
local function _CataclysmDialog()
local ask = dialog.CreateDialog("tlaloc Cataclysm")
ask.Label1 = dialog.AddLabel("Make this many different contractions")
ask.Tries = dialog.AddSlider("Tries", 4, 1, 10, 0)
ask.OK = dialog.AddButton("Start", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
if dialog.Show(ask) > 0 then
_Cataclysm(ask.Tries.value)
end
end
-------------------------------------------------
-- tlaloc Contract
--[[
Contracts bands and releases finding points. Works iteratively until no points are to
be found.
--]]
local function _SetEnableBands(startStrength, changeScore, deltaStrength)
local strength = startStrength
local score = nil
local delta = nil
local startScore = current.GetScore()
repeat
fsl.Print('Bands strength='..strength)
for i=fsl.BandsAtStart() + 1, band.GetCount() do
band.SetStrength(i, strength)
end
fsl.WiggleBackbone(1)
score = current.GetScore()
delta = math.abs(score - startScore)
strength = strength + deltaStrength
if strength > 10.0 then
-- no amount of strength will get it to move
strength = 10.0
break
end
until delta >= changeScore
strength = strength - deltaStrength
return strength
end
local contractprocs =
{
SetEnableBands = _SetEnableBands,
}
local strengthContract
local function _Contract(sigmaStableScore, changeScore, deltaStrength, strengthBackoffMultiplier, iterations, shakeFirst, repeating, bandingMethod)
-- sigmaStableScore is the maximum amount of score change for the structure to be consider stable.
-- changeScore is the minimum amount of score change for there to be a significant change in the structure of the protein.
-- deltaStrength is the amount of strength of bands added on each iteration. Smaller values take longer, larger values may cause too much change.
-- strengthBackoffMultiplier is the amount that it reduces the strength that it moved on the last pass for the next pass.
-- iterations is the parameter to the wiggle and shakes
-- shakeFirst is whether it should shake before wiggling
-- repeating is set to true when this function will be called multiple times without resetting in between
-- bandingMethod is a reference to the function that establishes the bands
local functionName, scoreStart = fsl.ScriptBegin('tlaloc Contract')
if not repeating then
if bandingMethod ~= nil then
bandingMethod()
end
strengthContract = 0
end
fsl.BandEnableScriptStart()
strengthContract = strengthContract - (strengthBackoffMultiplier * deltaStrength)
if strengthContract < 0 then
strengthContract = 0
end
strengthContract = contractprocs.SetEnableBands(strengthContract, changeScore, deltaStrength)
fsl.BandDisableScriptStart()
fsl.MakeStable(shakeFirst, sigmaStableScore, iterations)
return fsl.ScriptEnd(functionName, scoreStart, repeating)
end
local function _RepeatContract(tries, sigmaStableScore, changeScore, deltaStrength, strengthBackoffMultiplier, iterations, bandingMethod)
-- tries is the number of contractions without finding points before it gives up
-- sigmaStableScore is the maximum amount of score change for the structure to be consider stable.
-- changeScore is the minimum amount of score change for there to be a significant change in the structure of the protein.
-- deltaStrength is the amount of strength of bands added on each iteration. Smaller values take longer, larger values may cause too much change.
-- strengthBackoffMultiplier is the amount that it reduces the strength that it moved on the last pass for the next pass.
-- iterations is the parameter to the wiggle and shakes
-- bandingMethod is a reference to the function that establishes the bands
local functionName, scoreStart = fsl.ScriptBegin('tlaloc Repeat Contract')
if bandingMethod ~= nil then
bandingMethod()
end
strengthContract = 0
local foundpoints
local scoreBefore = scoreStart
repeat
foundpoints = false
for try=1, tries do
fsl.PrintLine()
fsl.PrintTries(functionName, try, tries)
_Contract(sigmaStableScore, changeScore, deltaStrength, strengthBackoffMultiplier, iterations, tries % 2 == 0, true, 0)
local score = current.GetScore()
local delta = score - scoreBefore
if delta > 0 then
foundpoints = true
scoreBefore = score
fsl.Print('Found '..delta..' points, starting over')
break
end
end
until not foundpoints
fsl.WiggleSidechains(20)
return fsl.ScriptEnd(functionName, scoreStart, false, fsl.BandDeleteScriptStart)
end
local function _ContractDialog()
--script.RepeatContract(7, .03, 10, .03, 1, 1, banding.CreateBandsToCenter)
-- tries is the number of contractions without finding points before it gives up
-- sigmaStableScore is the maximum amount of score change for the structure to be consider stable.
-- changeScore is the minimum amount of score change for there to be a significant change in the structure of the protein.
-- deltaStrength is the amount of strength of bands added on each iteration. Smaller values take longer, larger values may cause too much change.
-- strengthBackoffMultiplier is the amount that it reduces the strength that it moved on the last pass for the next pass.
-- iterations is the parameter to the wiggle and shakes
-- bandingMethod is a reference to the function that establishes the bands
local ask = dialog.CreateDialog("tlaloc Contract")
ask.TriesLabel = dialog.AddLabel("# of contractions with no points found before giving up")
ask.Tries = dialog.AddSlider("Tries", 7, 1, 100, 0)
ask.SigmaStableScoreLabel = dialog.AddLabel("Max score change for the structure to be stable")
ask.SigmaStableScore = dialog.AddSlider("Stable Score", .03, .01, 1.00, 2)
ask.ChangeScoreLabel1 = dialog.AddLabel("Min score change for there to be significant")
ask.ChangeScoreLabel2 = dialog.AddLabel("change in the structure of the protein")
ask.ChangeScore = dialog.AddSlider("Change Score", 10, 1, 100, 0)
ask.DeltaStrengthLabel = dialog.AddLabel("Strength of bands to add on each iteration")
ask.DeltaStrength = dialog.AddSlider("Delta", .03, .01, .25, 2)
ask.BackoffMultiplierLabel = dialog.AddLabel("Multiple of Delta to reduce band strength each pass")
ask.BackoffMultiplier = dialog.AddSlider("Back off", 1, 1, 10, 0)
ask.IterationsLabel = dialog.AddLabel("# of iterations to perform on wiggles and shakes")
ask.Iterations = dialog.AddSlider("Iterations", 1, 1, 25, 0)
ask.OK = dialog.AddButton("Start", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
if dialog.Show(ask) > 0 then
_RepeatContract(ask.Tries.value, ask.SigmaStableScore.value, ask.ChangeScore.value, ask.DeltaStrength.value, ask.BackoffMultiplier.value, ask.Iterations.value, banding.CreateBandsToCenter)
end
end
-------------------------------------------------
-- tlaloc Gyre
--[[
Gyres and Gimbles protein segments in the wabe. Pulls protein
segments in random directions, then shakes out.
--]]
local function comp(a, b)
return a.score < b.score
end
function _Gyre(rand)
local functionName, scoreStart = fsl.ScriptBegin('tlaloc Gyre')
--print ("tries: ", tries, " wiggles: ", wiggles, "Length: ",length, " Strength: ", strength)
tries=5
wiggles=6
length=5
strength=6
segCount = structure.GetCount()
local segments = {}
local count = 0
for i=1, structure.GetCount() do
if not structure.IsLocked(i) then
count = count + 1
segments[count]={segment=i, score=current.GetSegmentEnergyScore(i)}
end
end
table.sort(segments, comp)
max=0 un=0 deux=0
for i=1,segCount-1 do
for j=2,segCount do
local len=structure.GetDistance(i,j)
if len > max then
un=i
deux=j
max=len
end
end
end
for try=1, tries do
--local segmentOrigin
segmentOrigin = segments[math.random(1, #segments)].segment
fsl.PrintTries("Segment", try, tries, segmentOrigin)
if segmentOrigin== structure.GetCount() then segmentOrigin=segmentOrigin-1 end
local segmentXAxis = un
local segmentYAxis = deux
if segmentOrigin == segmentXAxis or segmentOrigin+1 == segmentXAxis then
segmentXAxis = segmentXAxis + 2
end
if segmentOrigin == segmentYAxis or segmentOrigin+1 == segmentYAxis then
segmentYAxis = segmentYAxis - 2
end
-- Add bands to space
bands = {}
ib=1
for i = 1, wiggles do
direction1= math.random(0, 180)
direction2=math.random(0, 360)
bands[ib] = band.Add(segmentOrigin, segmentXAxis, segmentYAxis, length, math.rad(direction1),math.rad(direction2))
band.SetStrength(bands[ib], strength)
band.Disable(bands[ib])
ib=ib+1
direction1=180-direction1
if direction2 >180 then direction2=direction2-180 else direction2=direction2+180 end
bandinutile = band.Add(segmentOrigin, segmentXAxis, segmentYAxis, length,math.rad(direction1),math.rad(direction2 ))
bands[ib]=band.AddToBandEndpoint(segmentOrigin+1,bandinutile)-1
band.Delete(bandinutile)
band.SetStrength(bands[ib], strength)
band.Disable(bands[ib])
ib=ib+1
end
ib=1
-- Pull segment in direction of band
for i = 1, wiggles do
band.Enable(bands[ib])
ib=ib+1
band.Enable(bands[ib])
structure.WiggleAll(2)
band.Disable(bands[ib])
band.Disable(bands[ib-1])
fsl.ReportAndLockScoreIncrease()
--structure.ShakeSidechainsAll(1)
--structure.WiggleAll(25)
ib=ib+1
--fsl.RestoreRecentBest()
end
-- fsl.RestoreRecentBest()
fsl.BandDeleteScriptStart()
--structure.ShakeSidechainsAll(1)
--structure.WiggleAll(25)
--fsl.MakeStable(true, .01, 1)
end
return fsl.ScriptEnd(functionName, scoreStart, false)
end
function _GyreDialog()
local segments = {}
local count = 0
for i=1, structure.GetCount() do
if not structure.IsLocked(i) then
count = count + 1
segments[count]={segment=i, score=current.GetSegmentEnergyScore(i)}
end
end
table.sort(segments, comp)
local tries = 5
if count < tries then
tries = count
end
ask = dialog.CreateDialog("tlaloc Gyre")
--ask.Tries = dialog.AddSlider("# tries", tries, 1, 5, 0)
ask.Wiggles = dialog.AddSlider("Wiggles", 5, 1, 25, 0)
ask.Length = dialog.AddSlider("Length", 5, .1, 20, 1)
ask.Strength = dialog.AddSlider("Strength", 2, .1, 10, 1)
ask.Random = dialog.AddCheckbox("Random segments,", false)
ask.OK = dialog.AddButton("Start", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
--tries=1
wiggles=ask.Wiggles.value
length=ask.Length.value
strength=ask.Strength.value
random=ask.Random.value
--[[if dialog.Show(ask) > 0 then
_Gyre(segments, ask.Tries.value, ask.Wiggles.value, ask.Length.value, ask.Strength.value, ask.Random.value)
end]]--
end
-------------------------------------------------
-- tlaloc Helixer
--[[
Tries to create regularly spaced helixes using bands.
--]]
local function _Helixer(spacing, strengthStart, strengthIncrement, iterations)
local functionName, scoreStart = fsl.ScriptBegin('tlaloc Helixer')
local countSegments = structure.GetCount()
assert(band.GetCount() == 0, 'Must delete existing bands\nbefore running this code.')
local bandStrength = strengthStart
local bands = {}
for i = 1, countSegments do
if structure.GetSecondaryStructure(i) == 'H' then
if i + 3 <= countSegments then
local helix = true
for dest = i+1, i+3 do
if structure.GetSecondaryStructure(dest) ~= 'H' then
helix = false
break
end
end
if helix then
fsl.BandAddBetweenSegments(i, i+3)
bands[#bands + 1] = {First = i, Last = i+3}
band.SetStrength(band.GetCount(), bandStrength)
band.SetGoalLength(band.GetCount(), spacing)
end
end
end
end
while true do
fsl.MakeStable(true, .1, iterations)
local allFixed = true
bandStrength = bandStrength + strengthIncrement
if bandStrength > 10 then
break
end
for i = 1, #bands do
local distance = structure.GetDistance(bands[i].First, bands[i].Last)
fsl.Print('Band '..i..' distance='..distance)
if math.abs(spacing - distance) > .1 then
fsl.Print('Changing band '..i..' '..bands[i].First..'-'..bands[i].Last..' to '..bandStrength)
band.SetStrength(i, bandStrength)
allFixed = false
end
end
if allFixed then
break
end
end
return fsl.ScriptEnd(functionName, scoreStart, true)
end
local function _HelixerDialog()
if band.GetCount() > 0 then
local tell = dialog.CreateDialog("tlaloc Helixer")
tell.Error = dialog.AddLabel("Must delete all existing bands before running.")
tell.OK = dialog.AddButton("Cancel", 0)
dialog.Show(tell)
else
local ask = dialog.CreateDialog("tlaloc Helixer")
ask.Label = dialog.AddLabel("Tries to create regularly spaced helixes using bands.")
ask.SpacingLabel = dialog.AddLabel("Maintain this spacing between bands")
ask.Spacing = dialog.AddSlider("Spacing", 5.5, .01, 10, 1)
ask.StrengthStartLabel = dialog.AddLabel("Start at this band strength")
ask.StrengthStart = dialog.AddSlider("Strength", 1.0, 0.1, 10.0, 1)
ask.StrengthIncrementLabel = dialog.AddLabel("Increment strength by this much")
ask.StrengthIncrement = dialog.AddSlider("Increment", 1.0, 0.1, 10.0, 1)
ask.IterationsLabel = dialog.AddLabel("Wiggle and shake for this many iterations")
ask.Iterations = dialog.AddSlider("Iterations", 10, 1, 25, 0)
ask.OK = dialog.AddButton("Start", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
if dialog.Show(ask) > 0 then
_Helixer(ask.Spacing.value, ask.StrengthStart.value, ask.StrengthIncrement.value, ask.Iterations.value)
end
end
end
-------------------------------------------------
-- tlaloc Hydrophobe
--[[
Pushes out hydrophyllic segments, pulls in hydrophobic segments. Good after threading to
stabilize. Also good when stuck.
--]]
local function _Hydrophobe(expand, percentBands)
local functionName, scoreStart = fsl.ScriptBegin('tlaloc Hydrophobe')
fsl.BandDisable()
local countSegments = structure.GetCount()
for x=1, countSegments - 2 do
for y = x + 2, countSegments do
local isHydrophobicX = structure.IsHydrophobic(x)
local isHydrophobicY = structure.IsHydrophobic(y)
if (isHydrophobicX == isHydrophobicY) and (math.random() <= percentBands) then
fsl.BandAddBetweenSegments(x, y)
local bandLast = band.GetCount()
local distance = structure.GetDistance(x, y)
if isHydrophobicX then
band.SetGoalLength(bandLast, distance - expand)
else
band.SetGoalLength(bandLast, distance + expand)
end
end
end
end
fsl.WiggleBackbone(1)
fsl.BandDeleteScriptStart()
fsl.MakeStable(false, .01, 1)
fsl.BlueFuse(1, .01, .05, .07, .03)
return fsl.ScriptEnd(functionName, scoreStart, true, fsl.BandDeleteScriptStart)
end
local function _HydrophobeDialog()
local ask = dialog.CreateDialog("tlaloc Hydrophobe")
ask.Label1 = dialog.AddLabel("Pushes hydrophilic segments out")
ask.Label2 = dialog.AddLabel("and hydrophobic segments in")
ask.ExpandLabel = dialog.AddLabel("Push or pull segments by this amount")
ask.Expand = dialog.AddSlider("Expand", 1, .1, 10, 1)
ask.PercentLabel = dialog.AddLabel("Percentage of bands")
ask.Percent = dialog.AddSlider("Percent", 10, 1, 100, 0)
ask.OK = dialog.AddButton("Start", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
if dialog.Show(ask) > 0 then
_Hydrophobe(ask.Expand.value, ask.Percent.value / 100)
end
end
-------------------------------------------------
-- tlaloc MutateAll
--[[
Only useful on design puzzles. Mutates every mutatable segment to every possibility, then
shakes out. Do not stop the script during the first part of the run (see output) as it
will leave the segments in a bad state. Time to run is proportional to the number of
mutatable segments.
--]]
local function _MutateAll(iterations, delta, shakeout)
local functionName, scoreStart = fsl.ScriptBegin('tlaloc MutateAll')
local saveSlot = fsl.RequestSaveSlot()
local countSegments = structure.GetCount()
local changeableSegments = fsl.FindMutatableSegments()
local originalSegments = {}
for i=1, countSegments do
originalSegments[i] = {AA=structure.GetAminoAcid(i), Score=0}
end
structure.MutateSidechainsAll(1)
-- Shake out the protein before starting, otherwise it will thrash
if shakeout then
fsl.MakeStable(true, delta, 25)
end
-- Create random list of changable segments
local randomSegments = {}
while #changeableSegments > 0 do
local i = math.random(1, #changeableSegments)
randomSegments[#randomSegments + 1] = changeableSegments[i]
table.remove(changeableSegments, i)
end
fsl.ResetRecentBest()
local scorePrevious = current.GetScore()
for i=1, #randomSegments do
local segment = randomSegments[i]
fsl.PrintTries('MutateAll', i, #randomSegments, 'segment')
local aa = structure.GetAminoAcid(segment)
fsl.Print('Segment #'..segment..' is '..aa)
for iAmino=1, #amino do
if aa ~= amino[iAmino] then
fsl.Print(i..' Trying amino acid '..iAmino..' '..amino[iAmino])
structure.SetAminoAcid(segment, amino[iAmino])
fsl.MakeStable(true, delta, iterations)
-- Loop until it iterates over all sidechains without finding any points
local tryagain
repeat
tryagain = false
local scoreBeforeSidechains = current.GetScore()
local scoreRecentBestBeforeSidechains = recentbest.GetScore()
local rotamers = rotamer.GetCount(segment)
for rotamerCur=1, rotamers do
fsl.PrintTries('MutateAll', rotamerCur, rotamers, 'rotamer')
save.Quicksave(saveSlot)
rotamer.SetRotamer(segment, rotamerCur)
local printStatus = fsl.PrintStatus(false)
fsl.WiggleAll(iterations)
fsl.PrintStatus(printStatus)
local scoreCur = current.GetScore()
local deltaCur = scoreCur - scoreBeforeSidechains
local scoreRecentBest = recentbest.GetScore()
local deltaRecentBest = scoreRecentBest - scoreRecentBestBeforeSidechains
if deltaCur <= 0.1 and deltaRecentBest <= 0 then
save.Quickload(saveSlot)
assert(rotamers == rotamer.GetCount(segment))
else
fsl.Print('Score improved by '..deltaCur..', trying rotamers again')
fsl.Print('Score='..scoreCur..' Best='..scoreRecentBest)
tryagain = true
break
end
end
until not tryagain
fsl.RestoreRecentBest()
fsl.ReportAndLockScoreIncrease()
fsl.MakeStable(true, delta, iterations)
structure.MutateSidechainsAll(1)
fsl.ReportAndLockScoreIncrease()
local score = current.GetScore()
if score > scorePrevious then
originalSegments[segment].Score = originalSegments[segment].Score + (score - scorePrevious)
scorePrevious = score
end
fsl.ReportScoreImprovement()
end
end
for i=1, countSegments do
local aa = structure.GetAminoAcid(i)
if aa ~= originalSegments[i].AA or originalSegments[i].Score ~= 0 then
fsl.Print('Segment #'..i..' '..originalSegments[i].AA..'->'..aa..' improved '..originalSegments[i].Score)
end
end
end
fsl.ReleaseSaveSlot(saveSlot)
return fsl.ScriptEnd(functionName, scoreStart, true)
end
local function _MutateAllDialog()
local ask = dialog.CreateDialog("tlaloc Mutate All")
ask.Label = dialog.AddLabel("Mutate all mutable segments")
ask.IterationsLabel = dialog.AddLabel("Number of iterations for WiggleAll")
ask.Iterations = dialog.AddSlider("Iterations", 1, 1, 25, 0)
ask.Delta = dialog.AddSlider("Delta", .1, .01, 1.00, 2)
ask.Line = dialog.AddLabel("--------------")
ask.Shakeout = dialog.AddCheckbox("Shakeout at start", true)
ask.OK = dialog.AddButton("Start", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
if dialog.Show(ask) > 0 then
_MutateAll(ask.Iterations.value, ask.Delta.value, ask.Shakeout.value)
end
end
-------------------------------------------------
-- tlaloc Push
--[[
Uses bands to "inflate" the protein, moving everything away from everything else, then
shaking out. Similar to tlaloc hydrophobe, but does not try to manipulate the hydrophobic
segments. Good in the mid-game when stuck at a local minimum. Unlike most of my scripts,
this one does not restore to the starting score if it does not exceed it, letting you try
other manipulation from where the script finishes. Manually Undo Restore Rcnt Best to get
to the best score since it started.
--]]
local function _Push(expand, percentBands)
local functionName, scoreStart = fsl.ScriptBegin('tlaloc Push')
fsl.BandDisable()
local countSegments = structure.GetCount()
for x=1, countSegments - 2 do
if not structure.IsHydrophobic(x) then
for y = x + 2, countSegments do
if (not structure.IsHydrophobic(y)) and (math.random() <= percentBands) then
local distance = structure.GetDistance(x, y)
fsl.BandAddBetweenSegments(x, y)
local bandLast = band.GetCount()
band.SetStrength(bandLast, 10.0)
band.SetGoalLength(bandLast, distance + expand)
end
end
end
end
fsl.WiggleBackbone(1)
fsl.BandDeleteScriptStart()
fsl.MakeStable(false, .01, 1)
fsl.BlueFuse(1, .01, .05, .07, .03)
return fsl.ScriptEnd(functionName, scoreStart, true, fsl.BandDeleteScriptStart)
end
local function _PushDialog()
local ask = dialog.CreateDialog("tlaloc Push")
ask.Label = dialog.AddLabel("Uses bands to 'inflate' the protein")
ask.ExpandLabel = dialog.AddLabel("Push or pull segments by this amount")
ask.Expand = dialog.AddSlider("Expand", 1, .1, 10, 1)
ask.PercentLabel = dialog.AddLabel("Percentage of bands")
ask.Percent = dialog.AddSlider("Percent", 10, 1, 100, 0)
ask.OK = dialog.AddButton("Start", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
if dialog.Show(ask) > 0 then
_Push(ask.Expand.value, ask.Percent.value / 100)
end
end
-------------------------------------------------
-- Repeat BlueFuse
--[[
Repeats vertex's Blue Fuse algorithm until no point are found. BlueFuse alters the
clashing importance to different values, wiggles, then sets the clashing importance to 1
and shakes out.
--]]
local function _RepeatBlueFuse(iterations, sigma, ...)
local functionName, scoreStart = fsl.ScriptBegin('tlaloc Repeat BlueFuse')
local try = 0
repeat
try = try + 1
fsl.PrintLine()
fsl.PrintTries(functionName, try)
until math.abs(fsl.BlueFuse(iterations, sigma, ...)) <= sigma
return fsl.ScriptEnd(functionName, scoreStart, false)
end
local function _RepeatBlueFuseDialog()
local ask = dialog.CreateDialog("tlaloc Repeat Blue Fuse")
ask.IterationsLabel = dialog.AddLabel("Number of iterations to wiggle and shake")
ask.Iterations = dialog.AddSlider("Iterations", 1, 1, 25, 0)
ask.SigmaLabel = dialog.AddLabel("Stop when point gain less than this")
ask.Sigma = dialog.AddSlider("Score", .01, .001, .1, 3)
ask.ClashImportanceLabel = dialog.AddLabel("Set the clashing importance these values:")
ask.ClashImportance1 = dialog.AddSlider("Clash1", .05, .01, 1.00, 2)
ask.ClashImportance2 = dialog.AddSlider("Clash2", .07, .01, 1.00, 2)
ask.ClashImportance3 = dialog.AddSlider("Clash3", .03, .01, 1.00, 2)
ask.OK = dialog.AddButton("Start", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
if dialog.Show(ask) > 0 then
_RepeatBlueFuse(ask.Iterations.value, ask.Sigma.value, ask.ClashImportance1.value, ask.ClashImportance2.value, ask.ClashImportance3.value)
end
end
-----------------------------------------
-- tlaloc Random Tug
--[[
Creates a band between two random segments and shakes out. Keeps trying different segments.
Sometimes finds points that tlaloc cataclysm does not. Good script when you are at a local
minimum and cannot find points anywhere else.
--]]
local function _Tug(sigmaStableScore, sigmaMovement, deltaChange, x, y, pull)
local score = current.GetScore()
-- either pull or push
if pull then
fsl.Print('Pulling')
for strength=deltaChange, 10.0, deltaChange do
assert(strength <= 10.0, 'Strength out of bounds')
if strength < 0 then
strength = 0
end
if strength > 10.0 then
strength = 10.0
end
band.SetStrength(1, strength)
fsl.WiggleBackbone(1)
if math.abs(current.GetScore() - score) >= sigmaMovement then
fsl.Print('Band strength='..strength)
break
end
end
else
fsl.Print('Pushing')
local lengthStart = structure.GetDistance(x, y)
strength = 1.0
for length=lengthStart, lengthStart + 20, 0.1 do
band.SetGoalLength(1, length)
fsl.WiggleBackbone(1)
if math.abs(current.GetScore() - score) >= sigmaMovement then
fsl.Print('length='..length)
break
end
band.SetStrength(1, strength)
strength = strength + deltaChange
if strength > 10.0 then
strength = 10.0
end
end
end
fsl.BandDeleteScriptStart()
fsl.MakeStable(nil, sigmaStableScore, 1)
end
local randomtugprocs =
{
Tug = _Tug,
}
local function _RandomTug(sigmaStableScore, sigmaMovement, deltaChange, noRestore)
local functionName, scoreStart = fsl.ScriptBegin('tlaloc Random Tug')
local x,y = fsl.BandAddRandom()
randomtugprocs.Tug(sigmaStableScore, sigmaMovement, deltaChange, x, y, math.random(0, 1) == 0)
return fsl.ScriptEnd(functionName, scoreStart, noRestore, fsl.BandDeleteScriptStart)
end
local function _RepeatRandomTug(tries, sigmaStableScore, sigmaMovement, deltaChange)
local functionName, scoreStart = fsl.ScriptBegin('tlaloc Repeat Random Tug')
for try=1, tries do
fsl.PrintLine()
fsl.PrintTries(functionName, try, tries)
if script.RandomTug(sigmaStableScore, sigmaMovement, deltaChange) > 0 then
fsl.BlueFuse(1, .01, .05, .07, .03)
end
end
return fsl.ScriptEnd(functionName, scoreStart, false)
end
local function _RepeatRandomTugDialog()
local ask = dialog.CreateDialog("tlaloc Repeat Random Tug")
ask.Label = dialog.AddLabel("Tugs or pushes between random segments")
ask.TriesLabel = dialog.AddLabel("Perform this many tugs")
ask.Tries = dialog.AddSlider("Tries", 100, 1, 1000, 0)
ask.StableScoreLabel = dialog.AddLabel("Shake and wiggle until this stable")
ask.StableScore = dialog.AddSlider("Stable Score", .5, .01, 1.00, 2)
ask.MovementLabel = dialog.AddLabel("This score change required before shaking out")
ask.Movement = dialog.AddSlider("Movement", 10, 1, 100, 0)
ask.DeltaLabel = dialog.AddLabel("Band strengths are incremented by this much")
ask.Delta = dialog.AddSlider("Delta", .10, .01, 1.00, 2)
ask.OK = dialog.AddButton("Start", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
if dialog.Show(ask) > 0 then
_RepeatRandomTug(ask.Tries.value, ask.StableScore.value, ask.Movement.value, ask.Delta.value)
end
end
-------------------------------------------------
-- tlaloc Rebuilder
--[[
Vigorously rebuilds the protein.
--]]
local rebuilderprocs = {}
local function _PrintImprovements(improvements)
fsl.PrintLine()
fsl.Print('Improvements:')
for i=1, #improvements do
fsl.Print(' range='..improvements[i].range..' index='..improvements[i].index..' rebuild='..improvements[i].rebuild..' segment='..improvements[i].segment..' ++'..improvements[i].improvement)
end
fsl.PrintLine()
end
local function _Rebuilder(segmentTarget, threshhold, sigma, range, maxRange, triesRebuild, triesFind, indexTarget, segments, improvements)
-- segmentTarget is the segment to work on
-- threshold is the amount a segment must improve before it moves on to the next segment
-- sigma is the minimum amount score must improve before it records an improvement and saves
-- range is how many segments to work with on either side of the worst segment
-- maxRange is the maximum number of segments it will work on (for reporting purposes)
-- triesRebuild is how many rebuilds it will perform on a given segment
-- triesFind is how many tries it makes at finding a rebuild before giving up
-- segments is the maximum number of segments it will rebuild
-- improvements is a table of the improvements it has found
local functionName, scoreStart = fsl.ScriptBegin('tlaloc Rebuilder')
fsl.Print('Working on segment '..segmentTarget)
local saveSlot = fsl.RequestSaveSlot()
save.Quicksave(saveSlot)
local countSegments = structure.GetCount()
-- If the target is at the ends of the protein, shift the target so that the entire range
-- so that the target +/- the range is all on the protein
if segmentTarget - range < 1 then
segmentTarget = segmentTarget + (1 - (segmentTarget - range))
end
if segmentTarget + range > countSegments then
segmentTarget = segmentTarget - ((segmentTarget + range) - countSegments)
end
local segmentFirst = segmentTarget - range
local segmentLast = segmentTarget + range
local scores = {}
for tryRebuild=1, triesRebuild do
local scoreBeforeRebuild = current.GetScore()
rebuilderprocs.PrintImprovements(improvements)
local scoreNew = false
-- try to find a rebuild we haven't done before
for tryNewScore=1, triesFind do
fsl.PrintTries('Range', range, maxRange, 'segments')
fsl.PrintTries('Working on worst index', indexTarget, segments, 'segment')
fsl.PrintTries('Rebuild', tryRebuild, triesRebuild)
fsl.PrintTries('Finding rebuild', tryNewScore, triesFind)
selection.DeselectAll()
selection.SelectRange(segmentFirst, segmentLast)
fsl.Print('Rebuilding segments '..segmentFirst..'-'..segmentLast)
fsl.Print('Segment score before rebuild='..fsl.GetSegmentScores(segmentFirst, segmentLast))
fsl.LocalRebuild(1)
local scoreSegmentsRebuild = fsl.Round(fsl.GetSegmentScores(segmentFirst, segmentLast), 9)
if not scores[scoreSegmentsRebuild] then
fsl.Print('Segment score after rebuild='..scoreSegmentsRebuild)
scoreNew = true
scores[scoreSegmentsRebuild] = true
break
end
end
-- When we get to here, either we found a new rebuild, or we did all the triesFind
if not scoreNew then
-- made all the triesFind and didn't find valid rebuild, so quit
break
else
fsl.Print('Working from rebuild score='..current.GetScore())
-- Actions to shake out rebuild improvement
fsl.MakeStable(true, .1, 3)
script.RepeatBlueFuse(3, .1, .05, .07, .03)
local scoreCurrent = current.GetScore()
fsl.Print('Stabilized at score='..scoreCurrent)
if scoreCurrent - sigma > scoreBeforeRebuild then
fsl.Print('Score improved...saving as current')
save.Quicksave(saveSlot)
improvements[#improvements + 1] = {index=indexTarget, range=range, rebuild=tryRebuild, segment=segmentTarget, improvement=scoreCurrent-scoreBeforeRebuild}
if scoreCurrent - threshhold > scoreBeforeRebuild then
break
end
else
save.Quickload(saveSlot)
end
end
end
fsl.ReleaseSaveSlot(saveSlot)
return fsl.ScriptEnd(functionName, scoreStart, false)
end
local function _RepeatRebuilder(maxRange, triesRebuild, maxScore, triesFind, threshhold, sigma, start, reverse)
-- Rebuilds all segments starting with the worst
-- maxRange is the # of segments adjacent to the segment to rebuild
-- triesRebuild is the number of rebuilds to attempt on each segment
-- maxScore is the segment score below which to rebuild
-- triesFind is how many attempts to find a good rebuild
-- threshhold is the minimum score improvement necessary to move on to another segment
-- sigma is how much of a score improvement is necessary to keep the rebuild
-- start is the segment to start the rebuild from (usually 1, but can be changed if you resume)
-- reverse true changes it to go from maxRange to 1 instead of 1 to maxRange
local functionName, scoreStart = fsl.ScriptBegin('tlaloc Repeat Rebuilder')
local countSegments = structure.GetCount()
assert(maxRange <= 10, 'range must be less than or equal to 10')
local scores = {}
for i=1, countSegments do
if not freeze.IsFrozen(i) then
scores[i]={segment=i, score=current.GetSegmentEnergyScore(i)}
end
end
for i=1,countSegments do
for j = countSegments, i+1, -1 do
if scores[i].score > scores[j].score then
scores[j], scores[i] = scores[i], scores[j]
end
end
end
for i=1,countSegments do
fsl.Print(i..' segment='..scores[i].segment..' score='..scores[i].score)
end
local segments = countSegments
fsl.Print('Segments to be worked on')
for i=1, countSegments do
if scores[i].score >= maxScore then
segments = i - 1
break
end
fsl.Print(i..' segment='..scores[i].segment..' score='..scores[i].score)
end
fsl.Print()
local improvements={}
local first = start
local last = maxRange
local increment = 1
if reverse then
first,last = last,first
increment = -1
end
for range=first, last, increment do
for indexTarget=start, segments do
fsl.PrintTries('Working on worst index', indexTarget, segments, 'segment')
fsl.Print('segment='..scores[indexTarget].segment..' score='..scores[indexTarget].score)
fsl.PrintTries('Range', range, maxRange, 'segments')
rebuilderprocs.Rebuilder(scores[indexTarget].segment, threshhold, sigma, range, maxRange, triesRebuild, triesFind, indexTarget, segments, improvements)
end
end
rebuilderprocs.PrintImprovements(improvements)
return fsl.ScriptEnd(functionName, scoreStart, false)
end
rebuilderprocs =
{
PrintImprovements = _PrintImprovements,
Rebuilder = _Rebuilder,
}
local function _RebuilderDialog()
local ask = dialog.CreateDialog("Tlaloc Rebuilder")
ask.Label1 = dialog.AddLabel("# of segments adjacent to the segment to rebuild")
ask.MaxRange = dialog.AddSlider("Range", 3, 1, 5, 0)
ask.Label2 = dialog.AddLabel("# of rebuilds to attempt on each segment")
ask.TriesRebuild = dialog.AddSlider("Rebuilds", 2, 1, 10, 0)
ask.Label3 = dialog.AddLabel("Segment score below which to rebuild")
ask.MaxScore = dialog.AddSlider("Score", 0, -50, 50, 1)
ask.Label4 = dialog.AddLabel("How many attempts to find a good rebuild")
ask.TriesFind = dialog.AddSlider("Tries", 50, 10, 100, 0)
ask.Label5 = dialog.AddLabel("Score improvement to move on to another segment")
ask.Threshhold = dialog.AddSlider("Improvement", 10, .1, 100, 1)
ask.Label6 = dialog.AddLabel("Range to 1 (vs 1 to Range)")
ask.Reverse = dialog.AddCheckbox("Reverse", true)
ask.Start = dialog.AddButton("Start", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
if (dialog.Show(ask) > 0) then
_RepeatRebuilder(ask.MaxRange.value, ask.TriesRebuild.value, ask.MaxScore.value, ask.TriesFind.value, ask.Threshhold.value, .1, 1, ask.Reverse.value)
end
end
-------------------------------------------------
-- tlaloc SelectMultiStart
--[[
This script figures out how many different starts there are, and saves them into the quickload save spots. You can use ctrl+1, ctrl+2, or ctrl+3 to load the first 3 after running this script.
--]]
local function _SelectMultiStartDialog()
local functionName, scoreStart = fsl.ScriptBegin('tlaloc SelectMultiStart')
local ask = dialog.CreateDialog("tlaloc SelectMultiStart")
ask.Description = dialog.AddLabel("Finds all the starts and lets you select one.")
ask.AttemptsLabel = dialog.AddLabel("How many attempts to find the start")
ask.Attempts = dialog.AddSlider("Attempts", 150, 50, 500, 0)
ask.SelectLabel = dialog.AddLabel("Select this start when done")
ask.Select = dialog.AddSlider("Start #", 1, 1, 10, 0)
ask.CommentLabel1 = dialog.AddLabel("A start number higher than the number of starts")
ask.CommentLabel2 = dialog.AddLabel("will select the last start.")
ask.OK = dialog.AddButton("Start", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
if dialog.Show(ask) > 0 then
fsl.SelectMultiStart(ask.Attempts.value, true, ask.Select.value)
end
return fsl.ScriptEnd(functionName, scoreStart, false)
end
-------------------------------------------------
-- tlaloc Settle
-- Based on CoLapses Settle
--[[
Repeats the settle algorithm until no points are found. Settle does local wiggles in different
patterns across the entire protein.
--]]
-- This function is not covered by the Creative Commons license given at the start of the script
-- since it a port of CoLapse's algorithm, with some enhancements.
local function _Settle(sigmaStable, iterations, finalStart, finalInterval, ...)
local functionName, scoreStart = fsl.ScriptBegin('tlaloc Settle')
local arg = {...}
local start
local interval
assert(#arg % 2 == 0)
for i=1, #arg, 2 do
start = arg[i]
interval = arg[i+1]
fsl.UnfreezeAll()
fsl.FreezeSegments(interval, start)
fsl.LocalWiggleInterval(interval, start - interval + 1, iterations)
end
fsl.UnfreezeAll()
fsl.FreezeSegments(finalInterval, finalStart)
fsl.LocalWiggleInterval(finalInterval, finalStart - finalInterval + 1, iterations)
fsl.WiggleBackbone(iterations)
fsl.UnfreezeAll()
fsl.MakeStable(nil, sigmaStable, iterations)
return fsl.ScriptEnd(functionName, scoreStart, false)
end
local function _RepeatSettle(sigmaImprovement, sigmaStable, iterations, finalStart, finalInterval, ...)
local functionName, scoreStart = fsl.ScriptBegin('tlaloc Repeat Settle')
local i = 0
repeat
fsl.PrintLine()
i = i + 1
fsl.PrintTries(functionName, i)
until _Settle(sigmaStable, iterations, finalStart, finalInterval, ...) <= sigmaImprovement
return fsl.ScriptEnd(functionName, scoreStart, false)
end
local function _RepeatSettleDialog()
local ask = dialog.CreateDialog("Tlaloc Repeat Settle")
ask.Label = dialog.AddLabel("Repeats co lapse's settle algorithm of local wiggles")
ask.ImprovementLabel = dialog.AddLabel("Repeat until this small of score gain")
ask.Improvement = dialog.AddSlider("Improvement", .1, .01, 1.00, 2)
ask.StableLabel = dialog.AddLabel("Score gain smaller than this is stable")
ask.Stable = dialog.AddSlider("Stable", .1, .01, 1.00, 2)
ask.IterationsLabel = dialog.AddLabel("Iterations for wiggles and shakes")
ask.Iterations = dialog.AddSlider("Iterations", 1, 1, 25, 0)
ask.PatternLabel = dialog.AddLabel("Use the following pattern of starts segments")
ask.PatternLabel2 = dialog.AddLabel("and segment intervals")
ask.Start1 = dialog.AddSlider("Start 1", 2, 1, 10, 0)
ask.Interval1 = dialog.AddSlider("Interval 1", 4, 1, 10, 0)
ask.Start2 = dialog.AddSlider("Start 2", 1, 1, 10, 0)
ask.Interval2 = dialog.AddSlider("Interval 2", 2, 1, 10, 0)
ask.Start3 = dialog.AddSlider("Start 3", 2, 1, 10, 0)
ask.Interval3 = dialog.AddSlider("Interval 3", 2, 1, 10, 0)
ask.Start4 = dialog.AddSlider("Start 4", 2, 1, 10, 0)
ask.Interval4 = dialog.AddSlider("Interval 4", 3, 1, 10, 0)
ask.StartF = dialog.AddSlider("Start Final", 1, 1, 10, 0)
ask.IntervalF = dialog.AddSlider("Interval Final", 2, 1, 10, 0)
ask.Start = dialog.AddButton("Start", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
if (dialog.Show(ask) > 0) then
_RepeatSettle(ask.Improvement.value, ask.Stable.value, ask.Iterations.value, ask.StartF.value, ask.IntervalF.value,
ask.Start1.value, ask.Interval1.value, ask.Start2.value, ask.Interval2.value,
ask.Start3.value, ask.Interval3.value, ask.Start4.value, ask.Interval3.value)
end
end
-------------------------------------------------
-- tlaloc Shakeout
--[[
Finds the best score between doing a shake/wiggle or a wiggle/shake. Then does a repeat Bluefuse
until no points are found. Very good to run any time you find points elsewhere.
--]]
local function _Shakeout(iterations, sigma, ...)
local functionName, scoreStart = fsl.ScriptBegin('tlaloc Shakeout')
fsl.MakeStable(nil, sigma, iterations)
script.RepeatBlueFuse(iterations, sigma, ...)
return fsl.ScriptEnd(functionName, scoreStart, false)
end
-----------------------------------------
-- tlaloc Twitch
--[[
Freezes all segments except the ones around where it is working, uses a band to
move the segment.
--]]
local function _Twitch(range, distance, strength, sigma, iterations)
local functionName, scoreStart = fsl.ScriptBegin('tlaloc Twitch')
local countSegments = structure.GetCount()
for segmentCur = 1, countSegments do
local segmentStart = segmentCur - range
local segmentEnd = segmentCur + range
if segmentStart < 1 then
segmentStart = 1
end
if segmentEnd > countSegments then
segmentEnd = countSegments
end
freeze.FreezeAll()
for i = segmentStart, segmentEnd do
freeze.Unfreeze(i, true, true)
end
local bandLength = distance + 1
local segment1 = 1
local segment2 = countSegments
if segmentCur == 1 then
segment1 = 2
end
if segmentCur == segment2 then
segment2 = segment2 - 1
end
local bandNumber = band.Add(segmentCur, segment1, segment2, bandLength, 0, 0)
local segmentLock = segmentStart - 1
if segmentLock == 0 then
segmentLock = segmentEnd + 1
end
local bandLock = band.Add(segmentLock, segmentCur, segment2, 1, 0, 0)
band.SetGoalLength(bandLock, 1)
band.SetStrength(bandLock, 10)
band.SetGoalLength(bandNumber, distance)
fsl.MakeStable(true, sigma, iterations)
fsl.ReportAndLockScoreIncrease()
fsl.RestoreRecentBest()
fsl.BandDeleteScriptStart()
freeze.UnfreezeAll()
end
return fsl.ScriptEnd(functionName, scoreStart, false)
end
local function _TwitchDialog()
local ask = dialog.CreateDialog("tlaloc Twitch")
ask.Range = dialog.AddSlider("Range", 1, 1, 5, 0)
ask.Distance = dialog.AddSlider("Distance", .5, .1, 1, 1)
ask.Strength = dialog.AddSlider("Strength", 1, .1, 10, 1)
ask.Sigma = dialog.AddSlider("Sigma", .03, .01, 1, 2)
ask.Iterations = dialog.AddSlider("Iterations", 1, 1, 25, 0)
ask.OK = dialog.AddButton("Start", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
if dialog.Show(ask) > 0 then
_Twitch(ask.Range.value, ask.Distance.value, ask.Strength.value, ask.Sigma.value, ask.Iterations.value)
end
end
----main
_GyreDialog()
BandNo=band.GetCount()
recentbest.Save()
for l = 1, Iterations do
band.EnableAll()
if DoMegalattice == true then
Megalattice()
end
Susband()
--PushOut()
print(band.GetCount(), "bands")
behavior.SetClashImportance(0.1)
structure.WiggleAll(25)
behavior.SetClashImportance(1)
_Gyre(rand)
behavior.SetClashImportance(1)
structure.ShakeSidechainsAll(1)
structure.WiggleAll(35)
structure.ShakeSidechainsAll(1)
structure.WiggleAll(35)
--[[for bands = BandNo + 1, band.GetCount() do
band.Delete(band.GetCount())
end]]---
band.DeleteAll()
structure.ShakeSidechainsAll(1)
structure.WiggleAll(35)
band.DisableAll()
structure.ShakeSidechainsAll(1)
structure.WiggleAll(35)
structure.ShakeSidechainsAll(1)
structure.WiggleAll(35)
BlueFuse()
if DoAnnealer == true then
Annealer()
end
--recentbest.Restore()
end
end
--[[
Rav3n_pl Compressor v2.1
ComputerMage - converted to V2.0 script.
trying to compress/decompress protein accepting loss of points between pulls
]]--
--drjr 2014 added a bunch of stuff -for contact map puzzles
----------- options below VVVVV ---------------------
cLoops = 3 --<<< SET NUMBER OF LOOPS
decomp = false --true --true for DeCompression instead of compression
modualtor = false --changing compression/decompression each loop
randomModulation = false
useRegions = { --set regions that have to be used in all bands
--{1,20}, --there are exaples, uncomment and edit
--{25,55},
--{100,210},
}
compressFrac = 15 --make bands shorter by that much percents
compressFracMin = 5 -- if this parameter set it will randomly select pecentage between this parameter and compressFrac
minSkip = 15 --minimum segment distance between banded segments
minBands = 3 -- if minBands less than 1 then it uses fixed amount of bands
-- defined in numBands, otherwise it generates random number of bands beween minBands and numBands for each iteration.
numBands = 13 --how many bands use at once
BiPAlways = false
fastQstab = true --false --true --only 1 shake and 1 wiglle when true
useFuze = true -- use Fuze after qStab
fuzeScore = 10 --how close we have to be to run Fuze
allLoop = false --work in all-loop mode. sometimes work better than structure mode :)
S2H = false --all bands are between sheets and helixes
useStructure = false --all bands have at least one end on structure (not loop)
noLoops=false --band can`t have any end on loop
minBandStrength = 0.3 -- 0.3 --starting band str
maxBandStrength = 1.5 -- 1.0 -- max band strenght
minDist = 7 --minimum band length
slowBands = false --bands strength are raised few times till score drops by %
percLoss = 1 --pulling stops when score drops by that percent (ie 2=200pts when 10k pts)
repeatGood = true --repeating good bands if true
pullingCI = 0.3 --0.6--clash impotrance during pull
maxLoss = 90 --maximum acceptable LOSS after Fuze. also lowering fuzeScore
reloadBest = 5 --reload best solution after that many worst ones
normal = true -- checks if this is exploration puzzle
mutate = false
mutateIterations = 2
PS = false
PackingCriterion = -75
DoNotBandFormedContacts = false
DoFilterScore = false
RatioLengthForMadeContacts = .9
RatioLengthForUnmadeContacts = .75
StrengthForMadeContacts = 0.5
StrengthForUnmadeContacts = 0.7
------------ end of options ^^^^^^
segCnt = 0
function CutNWiggle()
function BlueFuse()
behavior.SetClashImportance(0.05)
structure.ShakeSidechainsAll(1)
behavior.SetClashImportance(1)
structure.WiggleAll(35)
behavior.SetClashImportance(0.07)
structure.ShakeSidechainsAll(1)
behavior.SetClashImportance(1)
structure.WiggleAll(35)
behavior.SetClashImportance(0.3)
structure.WiggleAll(15)
behavior.SetClashImportance(1)
structure.WiggleAll(35)
end
math.randomseed(recipe.GetRandomSeed())
print(current.GetScore())
recentbest.Save()
for j = 1,3 do
for i = 1, structure.GetCount()-1 do
CutIt = math.random(10)
if CutIt < 4 then
structure.InsertCut(i)
end
end
behavior.SetClashImportance(0.3)
structure.WiggleAll(35)
behavior.SetClashImportance(1)
structure.WiggleAll(35)
behavior.SetClashImportance(1)
structure.ShakeSidechainsAll(1)
structure.WiggleAll(35)
for i = 1, structure.GetCount()-1 do
structure.DeleteCut(i)
end
behavior.SetClashImportance(1)
structure.ShakeSidechainsAll(1)
structure.WiggleAll(35)
structure.ShakeSidechainsAll(1)
structure.WiggleAll(35)
BlueFuse()
recentbest.Restore()
print(current.GetScore())
end
end
function PackingSnapper()
behavior.SetClashImportance(maxCI)
--PackingCriterion = -75
print('Packing Criterion=',PackingCriterion)
behavior.SetSlowFiltersDisabled(false)
--recentbest.Save()
save.Quicksave(99)
for l=1,1 do
for count =1,structure.GetCount() do
save.Quickload(99)
Packed=current.GetSegmentEnergySubscore(count, "packing")
if structure.IsHydrophobic(count)==true then
--print('Examining Segment',count)
NowAt=current.GetScore()
for p=1,rotamer.GetCount(count) do
if p<=rotamer.GetCount(count) then
rotamer.SetRotamer(count, p)
end
if current.GetSegmentEnergySubscore(count, "packing")>Packed then
if current.GetScore() - NowAt > PackingCriterion then
save.Quicksave(99)
Packed=current.GetSegmentEnergySubscore(count, "packing")
end
end
end
end
end
save.Quickload(99)
selection.DeselectAll()
for count =1,structure.GetCount() do
if structure.IsHydrophobic(count)==false then
selection.Select(count)
end
end
structure.ShakeSidechainsSelected(1)
--structure.WiggleAll(25)
save.Quicksave(99)
end
return PackingCriterion
end
function SusBands()
-- places a band wherever there is a green dot on the contact map
-- bands on unmade contacts are made shortter and stronger then made contacts
--[[
RatioLengthForMadeContacts = .9
RatioLengthForUnmadeContacts = .75
StrengthForMadeContacts = 0.5
StrengthForUnmadeContacts = 0.7
]]--
bcount = 0
count = structure.GetCount()
for i = 1, count-2 do
for j = i+2, count do
if contactmap.GetHeat(i, j) > 0 then
if contactmap.IsContact(i,j) then do
if DoNotBandFormedContacts == false then
b = band.AddBetweenSegments(i,j)
bcount = bcount + 1
band.SetGoalLength(b, RatioLengthForMadeContacts * band.GetLength(b))
band.SetStrength(b, StrengthForMadeContacts)
end
end
else
b = band.AddBetweenSegments(i,j)
bcount = bcount + 1
band.SetGoalLength(b, RatioLengthForUnmadeContacts * band.GetLength(b))
band.SetStrength(b, StrengthForUnmadeContacts)
end
end
end
end
print(bcount.." contact bands placed")
print(b.." total bands")
end
function ONS()
print("ONS")
behavior.SetClashImportance(maxCI)
function SortItWell(SubscorePart)
grid = {}
for i = 1, structure.GetCount() do
grid[i] = {}
grid[i][1] = current.GetSegmentEnergySubscore(i, SubscorePart)
grid[i][2]=i
end
switch = 1
while switch ~= 0 do
switch=0
for i=1, structure.GetCount()-1 do
if grid[i][1] > grid[i+1][1] then
grid[i][1],grid[i+1][1]=grid[i+1][1],grid[i][1]
grid[i][2],grid[i+1][2]=grid[i+1][2],grid[i][2]
switch = switch +1
--print(switch)
end
end
end
for i = 1, structure.GetCount() do
for j = 1, 2 do
--print(i)
--print(grid[i][j])
end
end
return grid
end
function OptimizeIt()
structure.WiggleSelected(10)
behavior.SetClashImportance(0.1)
structure.ShakeSidechainsSelected(1)
structure.WiggleSelected(10)
behavior.SetClashImportance(1)
structure.ShakeSidechainsSelected(1)
structure.WiggleSelected(10)
end
function BlueFuse()
print('Blue Fuse')
behavior.SetClashImportance(0.05)
structure.ShakeSidechainsAll(1)
behavior.SetClashImportance(1)
structure.WiggleAll(10)
behavior.SetClashImportance(0.07)
structure.ShakeSidechainsAll(1)
behavior.SetClashImportance(1)
structure.WiggleAll(10)
behavior.SetClashImportance(0.3)
structure.WiggleAll(10)
behavior.SetClashImportance(1)
structure.WiggleAll(10)
end
structure.ShakeSidechainsAll(2)
behavior.SetClashImportance(1)
for j = 1,2 do
SubscorePart="backbone"
SortItWell(SubscorePart)
for i=1,10 do
selection.DeselectAll()
if grid[i][2]-1>0 and structure.GetCount()-grid[i][2]>0 then
selection.SelectRange(grid[i][2]-1,grid[i][2]+1)
OptimizeIt()
end
end
end
end
function BBANG()
print("BBANG")
recentbest.Save()
save.Quicksave(1) --stores original
structure.WiggleAll(35)
save.Quickload(1)
structure.ShakeSidechainsAll(1)
structure.WiggleAll(35)
save.Quickload(1)
behavior.SetClashImportance(0.1)
structure.ShakeSidechainsAll(1)
behavior.SetClashImportance(1)
structure.WiggleAll(35)
recentbest.Restore()
save.Quicksave(1)
save.Quickload(1)
behavior.SetClashImportance(0.1)
structure.ShakeSidechainsAll(1)
structure.WiggleAll(15)
behavior.SetClashImportance(1)
structure.WiggleAll(35)
recentbest.Restore()
behavior.SetClashImportance(0.1)
structure.ShakeSidechainsAll(1)
structure.WiggleAll(15)
behavior.SetClashImportance(1)
structure.ShakeSidechainsAll(1)
structure.WiggleAll(35)
recentbest.Restore()
save.Quicksave(2)
behavior.SetClashImportance(0.1)
structure.ShakeSidechainsAll(1)
structure.WiggleAll(15)
behavior.SetClashImportance(1)
structure.WiggleAll(35)
save.Quickload(2)
behavior.SetClashImportance(0.1)
structure.ShakeSidechainsAll(1)
structure.WiggleAll(15)
behavior.SetClashImportance(1)
structure.ShakeSidechainsAll(1)
structure.WiggleAll(35)
recentbest.Restore()
end
function GetFilterScore()
--instead, this returns number of contacts made
bcount = 0
count = structure.GetCount()
for i = 1, count-2 do
for j = i+2, count do
if contactmap.GetHeat(i, j) > 0 then
if contactmap.IsContact(i,j) == true then
bcount = bcount + 1
end
end
end
end
return bcount
--[[
PartialFilterScore = 0
for ttt = 1, structure.GetCount() do
PartialFilterScore = PartialFilterScore + current.GetSegmentEnergyScore(ttt)
end
FilterScore = current.GetScore() - PartialFilterScore
print("PartialFilterScore",PartialFilterScore)
print("current.GetEnergyScore()",current.GetEnergyScore())
print("FilterScore", FilterScore)
--print(FilterScore)
return FilterScore]]--
end
function Score()
local s=0
if normal==true then
s=current.GetEnergyScore()
else
s=current.GetScore()
end
if DoFilterScore == true then
s = GetFilterScore()
end
return s
end
function round(x)--cut all afer 3-rd place
return x-x%0.001
end
function abs(x)
if x<0 then x=-x end
return x
end
function round(x)--cut all afer 3-rd place
return x-x%0.001
end
function down(x)
return x-x%1
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 structure.ShakeSidechainsAll(1)
elseif how == "wb" then structure.WiggleAll(35, true, false)
elseif how == "ws" then structure.WiggleAll(35, false, true)
elseif how == "wa" then structure.WiggleAll(35, true, true)
end
if Score()-sp > minppi then return Wiggle(how, iters, minppi) end
end
end
function DeleteBands(BandNo)
print("Deleting Compressor Bands")
NewBandNo=band.GetCount()
for w=BandNo,NewBandNo-1 do
band.Delete(BandNo+1)
end
end
SAVEDstructs=false
function AllLoop() --turning entire structure to loops
local anychange=false
for i=1,segCnt do
if structure.GetSecondaryStructure(i)~="L" then
anychange=true
break
end
end
if anychange then
save.SaveSecondaryStructure()
SAVEDstructs=true
selection.SelectAll()
structure.SetSecondaryStructureSelected("L")
end
end
function qStab()
behavior.SetClashImportance(0.1)
Wiggle("s",1)
if mutate == true then
structure.MutateSidechainsSelected(mutateIterations)
SaveBest();
end
selection.SelectAll()
if fastQstab==false then
if maxCI < 1 then do
behavior.SetClashImportance(maxCI)
end
else
behavior.SetClashImportance(0.4)
end
Wiggle("wa",1)
if maxCI < 1 then do
behavior.SetClashImportance(maxCI)
end
else
behavior.SetClashImportance(1)
end
Wiggle("s",1)
end
if maxCI < 1 then do
behavior.SetClashImportance(maxCI)
end
else
behavior.SetClashImportance(0.4)
end
behavior.SetClashImportance(maxCI)
Wiggle()
end
function FuzeEnd()
behavior.SetClashImportance(1)
if mutate == true then
structure.MutateSidechainsSelected(mutateIterations)
end
Wiggle("wa",1)
Wiggle("s",1)
Wiggle()
SaveBest()
end
function Fuze1(ci1,ci2)
behavior.SetClashImportance(ci1)
Wiggle("s",1)
behavior.SetClashImportance(ci2)
Wiggle("wa",1)
end
function Fuze2(ci1,ci2)
behavior.SetClashImportance(ci1)
Wiggle("wa",1)
behavior.SetClashImportance(1)
Wiggle("wa",1)
behavior.SetClashImportance(ci2)
Wiggle("wa",1)
end
function reFuze(scr,slot)
local s=Score()
if s<scr then
save.Quickload(slot)
else
scr=s
save.Quicksave(slot)
end
return scr
end
function Fuze(slot)
local scr=Score()
save.Quicksave(slot)
selection.SelectAll()
Fuze1(0.3 * maxCI,0.6 * maxCI) FuzeEnd()
scr=reFuze(scr,slot)
Fuze2(0.3 * maxCI,1 * maxCI) SaveBest()
scr=reFuze(scr,slot)
Fuze1(0.05,1 * maxCI) SaveBest()
scr=reFuze(scr,slot)
Fuze2(0.7 * maxCI,0.5 * maxCI) FuzeEnd()
scr=reFuze(scr,slot)
Fuze1(0.07,1 * maxCI) SaveBest()
reFuze(scr,slot)
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 ]]--
bestScore=Score()
function SaveBest()
local g=Score()-bestScore
if g>0 then
print("Gained another ",round(g)," pts.")
bestScore=Score()
save.Quicksave(3)
end
end
function MakeBands(compressFracMin, compressFrac, numBands, minBands, minSkip, minBandStrength, maxBandStrength, minDist, maxDist, slowBands)
local num = 0
if minBands > 0 then
if minBands > numBands then
minBands = 1
end
num = math.random(minBands, numBands)
else
num = numBands
end
if minBands < 1 then
print("Make "..num.." bands")
else
print("Make "..num.." bands, where min is "..minBands.." and max is "..numBands)
end
InternalMakeBands(num, compressFracMin, compressFrac, numBands, minBands, minSkip, minBandStrength, maxBandStrength, minDist, maxDist, slowBands)
end
function InternalMakeBands(num, compressFracMin, compressFrac, numBands, minBands, minSkip, minBandStrength, maxBandStrength, minDist, maxDist, slowBands)
local done=false
local s1=math.random(segCnt)
local s2=math.random(segCnt)
if s1>s2 then s1,s2=s2,s1 end
local d=structure.GetDistance(s1,s2)
if s2-s1>=minSkip and d>=minDist and d<=maxDist then done=true end
if (done and #useRegions>0) then
done=false
for a=1,#useRegions do
local ss=useRegions[a][1]
local se=useRegions[a][2]
if (s1>=ss and s1<=se) or (s2>=ss and s2<=se) then
done=true
break
end
end
end
local ss1=structure.GetSecondaryStructure(s1)
local ss2=structure.GetSecondaryStructure(s2)
if (done and noLoops) then
if ss1=="L" or ss2=="L" then done=false end
end
if (done and useStructure) then
if ss1=="L" and ss2=="L" then done=false end
end
if (done and S2H) then
if (ss1=="E" or ss2=="E") and (ss1=="H" or ss2=="H") and (ss1~=ss2) then
done=true
else
done=false
end
end
if done then
num=num-1
mkBand(s1,s2,compressFracMin, compressFrac)
bands[#bands+1]={s1,s2}
end
if num>0 then return InternalMakeBands(num, compressFracMin, compressFrac, numBands, minBands, minSkip, minBandStrength, maxBandStrength, minDist, maxDist, slowBands) end --tail call
end
function mkBand(s1,s2,compressFracMin, compressFrac)
band.AddBetweenSegments(s1,s2)
local len=structure.GetDistance(s1,s2)
local frac = compressFrac
if compressFracMin ~= nil then
frac = math.random(compressFracMin, compressFrac)
end
if randomModulation == false then
if decomp==true then
len=len*(1 + frac/100)
else
len=len/(1 + frac/100)
end
else
if math.random(1,10) > 5 then
len=len*(1 + frac/100)
else
len=len/(1 + frac/100)
end
end
if len<3 then len=3 end --not make shorter band, useless
band.SetGoalLength(band.GetCount(),len)
end
bands={}
function Repeat_bands(bands)
DeleteBands(BandNo)
band.EnableAll()
for i=1,#bands do
local s1=bands[i][1]
local s2=bands[i][2]
mkBand(s1,s2,compressFracMin, compressFrac)
end
end
function SetBandsStrength(str) --set all band strengt
if str<0.1 then str=0.1 end
if str>10 then str=10 end
for i=BandNo+1, band.GetCount() do
band.SetStrength(i, str)
end
end
function RandomBandStrength() --set all band strengt
if minBandStrength<0.1 then BandStrength=0.1 end
if maxBandStrength>10 then maxBandStrength=10 end
for i=BandNo+1, band.GetCount() do
band.SetStrength(i, math.random(minBandStrength, maxBandStrength))
end
end
function SaveRB(slot)
save.Quicksave(slot)
recentbest.Restore()
SaveBest()
save.Quickload(slot)
end
function Cleanup(err)
print("Restoring CI, best result and structures")
behavior.SetClashImportance(1)
save.Quickload(3)
if SAVEDstructs then save.LoadSecondaryStructure() end
print(err)
end
function InsertCutPoints()
for k = 1, structure.GetCount() -1 do
structure.InsertCut(k)
end
end
function DeleteCutPoints()
for k = 1, structure.GetCount() -1 do
structure.DeleteCut(k)
end
end
sscore=Score() --starting score
function StringOfPearls()
BandNo = band.GetCount()
print("Starting Compressor v2, ",cLoops," loops.")
if normal==false then print("Using exploration options.") end
if mutate==true then print("Puzzle has mutable segments. Enabling mutations.") end
if allLoop then AllLoop() end
save.Quicksave(3)
save.Quicksave(7) --save state for losing
badOnes=0
recentbest.Save()
local best=false
for i=1,cLoops do
loss=Score()*percLoss/100 --pulling till we lost some points
DeleteBands(BandNo)
band.EnableAll()
band.DeleteAll()
SusBands()
BandNo=band.GetCount()
if best==true and repeatGood==true then
print("Repeating last bands.")
if modualtor==true then --switch
decomp= not decomp
end
Repeat_bands(bands)
else
bands={}
MakeBands(compressFracMin, compressFrac, numBands, minBands, minSkip, minBandStrength, maxBandStrength, minDist, maxDist, slowBands)
end
local ls=Score()
local tx="ompressing."
if randomModulation == false then
if decomp==true then
tx="Dec"..tx
else
tx="C"..tx
end
else
tx = "Random modulation"
end
print("Loop ",i," of ",cLoops," started. ", tx)
print(" Current score: ",round(ls))
print(GetFilterScore(),"contacts")
if Randomize == true then
if math.random(10) < 4 then do
DoInsertCutpoints = true
end
else
DoInsertCutpoints = false
end
end
if DoInsertCutpoints == true then
InsertCutPoints()
end
behavior.SetClashImportance(pullingCI)
selection.SelectAll()
recentbest.Save()
if slowBands then
for str=minBandStrength,maxBandStrength,0.07 do--search enough band strenght to move
recentbest.Restore() --because sometimes it makes points during pull :D
local ss=Score()
SetBandsStrength(str)
Wiggle("wb",1)
if ss-Score()>loss then
break
end
end
else
RandomBandStrength(bandStr)
Wiggle("wb",1)
end
SaveRB(4) --because sometimes it missing fractions
behavior.SetClashImportance(maxCI)
structure.ShakeSidechainsAll(1)
structure.WiggleAll(5, true, true)
if Randomize == true then
if math.random(10) < 4 then do
DoPackingSnapper = true
end
else
DoPackingSnapper = false
end
end
if DoPackingSnapper == true then
PackingSnapper()
end
behavior.SetClashImportance(pullingCI)
structure.WiggleAll(5, true, true)
DeleteBands(BandNo)
if DoInsertCutpoints == true then
DeleteCutPoints()
end
if DoONS == true then
ONS()
end
if BiPAlways == false then
band.DisableAll()
end
if DoBBANG then
BBANG()
end
if DoCutNWiggle == true then
CutNWiggle()
end
SaveBest()
if mutate == true then
structure.MutateSidechainsSelected(mutateIterations)
end
SaveBest()
qStab()
if useFuze and Score()> (bestScore-fuzeScore) then
SaveBest()
if mutate == true then
structure.MutateSidechainsSelected(mutateIterations)
end
Fuze(4)
if mutate == true then
structure.MutateSidechainsSelected(mutateIterations)
end
else
SaveBest()
end
if maxLoss>0 then
if Score()>bestScore-maxLoss then
save.Quicksave(7) --save actual "best" solution
else
badOnes=badOnes+1
if badOnes >=reloadBest then
badOnes=0
save.Quickload(3)
else
save.Quickload(7) --load "second best"
end
end
else
save.Quickload(3)
end
local es=Score()
if es>ls then best=true else best=false end --repeating all bands making points
print("Loop ",i," gain ",round(es-ls)," ;total gain ",round(bestScore-sscore))
if modualtor==true then --switch
decomp= not decomp
end
end
save.Quickload(3)
if allLoop then save.LoadSecondaryStructure() end
print("Total gain: ",round(Score()-sscore))
end
function PackingSnapperDialog()
local pack = dialog.CreateDialog("Packing Snapper Settings:")
pack.PC = dialog.AddSlider("Packing Criterion:", PackingCriterion, -200, -20, 0)
pack.OK = dialog.AddButton("OK",1) pack.Cancel = dialog.AddButton("Cancel",0)
if dialog.Show(pack) > 0 then
PackingCriterion = pack.PC.value
end
end
--main call
math.randomseed(recipe.GetRandomSeed())
--print("Contact Compressor")
segCnt = structure.GetCount()
while structure.GetSecondaryStructure(segCnt)=="M" do segCnt=segCnt-1 end
if current.GetExplorationMultiplier() ~= 0 then
normal = false
end
for idx = 1,segCnt do
if structure.IsMutable(idx) then
mutate=true
break
end
end
-- Settings code
--end of scipt
function StringOfPearlsOptions()
local dlg = dialog.CreateDialog("String of Pearls Options:")
dlg.cLoops = dialog.AddSlider("Iterations:", cLoops, 0, 3000, 0)
dlg.decomp = dialog.AddCheckbox("Use Decompress instead?", decomp)
dlg.modulator = dialog.AddCheckbox("Modulate loops?", modulator)
dlg.randomModulation = dialog.AddCheckbox("Random modulation?", randomModulation)
dlg.ML = dialog.AddSlider("Maximum Loss:", maxLoss, 0, 300, 0)
dlg.repeatGood = dialog.AddCheckbox("Repeat good bands", repeatGood)
dlg.AB = dialog.AddCheckbox("Adjust Banding", DoAdjustBanding)
dlg.pullingCI = dialog.AddSlider("Pulling CI", pullingCI, 0, 1.0, 2)
dlg.maxCI = dialog.AddSlider("Maximum CI", 1, 0, 1.0, 2)
dlg.BiP = dialog.AddCheckbox("BiP always enabled", BiP)
dlg.AC = dialog.AddCheckbox("Adjust Contacts", AC)
dlg.DFS = dialog.AddCheckbox("Keep Contacts (sets maxLoss to 0)", DoFilterScore)
dlg.DB = dialog.AddCheckbox("Do BBANG (slow -sets CI to 1)", false)
dlg.DONS = dialog.AddCheckbox("Do ONS (slow -sets CI to 1)", false)
dlg.CNW = dialog.AddCheckbox("Cut N Wiggle (slow)", true)
dlg.PS = dialog.AddCheckbox("Packing Snapper (slow)", false)
dlg.IC = dialog.AddCheckbox("Insert Cutpoints", false)
dlg.RATC = dialog.AddCheckbox("Randomize Above Two Choices", true)
if mutate == true then
dlg.mutateIterations = dialog.AddSlider("Mutate iterations", mutateIterations, 0, 1.0, 0)
end
dlg.OK = dialog.AddButton("OK",1) dlg.Cancel = dialog.AddButton("Cancel",0)
dialog.Show(dlg)
-- percLoss = 1 --pulling stops when score drops by that percent (ie 2=200pts when 10k pts)
-- Set modified values
DoFilterScore = dlg.DFS.value
DoAdjustBanding = dlg.AB.value
BandsDialog(DoAdjustBanding)
DoPackingSnapper = dlg.PS.value
maxCI=dlg.maxCI.value
maxLoss = dlg.ML.value
DoInsertCutpoints = dlg.IC.value
DoCutNWiggle = dlg.CNW.value
if DoAdjustBanding == true then
BandsDialog()
end
if DoFilterScore == true then
maxLoss = 0
end
cLoops = dlg.cLoops.value
decomp = dlg.decomp.value
modulator = dlg.modulator.value
randomModulation = dlg.randomModulation.value
Randomize = dlg.RATC.value
DoONS = dlg.DONS.value
DoBBANG = dlg.DB.value
repeatGood = dlg.repeatGood.value
pullingCI = dlg.pullingCI.value
BiPAlways=dlg.BiP.value
if DoPackingSnapper == true then
PackingSnapperDialog()
end
if dlg.AC.value == true then
ContactsDialog()
end
if mutate == true then
mutateIterations = dlg.mutateIterations.value
end
end
function BandsDialog(DoAdjustBanding)
local dlg = dialog.CreateDialog("Band Adjustment")
dlg.l1 = dialog.AddLabel("Compression rate:")
dlg.compressFracMin = dialog.AddSlider("Minimum %", compressFracMin, 0, 100, 0)
dlg.compressFrac = dialog.AddSlider("Maximum %", compressFrac, 0, 100, 0)
dlg.l2 = dialog.AddLabel("Bands:")
dlg.minBands = dialog.AddSlider("Minimum", minBands, 0, segCnt, 0)
dlg.numBands = dialog.AddSlider("Maximum", numBands, 1, segCnt, 0)
dlg.l3 = dialog.AddLabel("Segments between band endpoints:")
dlg.minSkip = dialog.AddSlider("Minimum", minSkip, 3, segCnt, 0)
dlg.l4 = dialog.AddLabel("Band strength:")
dlg.minBandStrength = dialog.AddSlider("Minimum", minBandStrength, 0, 10, 1)
dlg.maxBandStrength = dialog.AddSlider("Maximum", maxBandStrength, 0, 10, 1)
dlg.minDist = dialog.AddSlider("Min band length", minDist, 0, 20, 0)
dlg.maxDist = dialog.AddSlider("Max band length", 30, 0, 100, 0)
dlg.slowBands = dialog.AddCheckbox("Slow Bands", slowBands)
if DoAdjustBanding == true then
dlg.OK = dialog.AddButton("OK",1) dlg.Cancel = dialog.AddButton("Cancel",0)
end
compressFracMin = dlg.compressFracMin.value
compressFrac = dlg.compressFrac.value
numBands = dlg.numBands.value
minBands = dlg.minBands.value
minSkip = dlg.minSkip.value
minBandStrength = dlg.minBandStrength.value
maxBandStrength = dlg.maxBandStrength.value
minDist = dlg.minDist.value
maxDist=dlg.maxDist.value
slowBands = dlg.slowBands.value
return compressFracMin, compressFrac, numBands, minBands, minSkip, minBandStrength, maxBandStrength, minDist, maxDist, slowBands
end
function ContactsDialog()
local contacts = dialog.CreateDialog("Contacts Settings:")
contacts.RLFMC = dialog.AddSlider("Length Multiplier for Made Contacts:", RatioLengthForMadeContacts, 0, 2, 2)
contacts.SFMC = dialog.AddSlider("Strength for Made Contacts:", StrengthForMadeContacts, 0, 2, 2)
contacts.DNBFC = dialog.AddCheckbox("Do Not Band Formed Contacts", DoNotBandFormedContacts)
contacts.RLFUC = dialog.AddSlider("Length Multiplier for Unmade Contacts:", RatioLengthForMadeContacts, 0, 2, 2)
contacts.SFUC = dialog.AddSlider("Strength for Unmade Contacts:", StrengthForUnmadeContacts, 0, 2, 2)
contacts.OK = dialog.AddButton("OK",1) contacts.Cancel = dialog.AddButton("Cancel",0)
if dialog.Show(contacts) > 0 then
RatioLengthForMadeContacts=contacts.RLFMC.value
StrengthForMadeContacts= contacts.SFMC.value
RatioLengthForUnmadeContacts=contacts.RLFUC.value
StrengthForUnmadeContacts= contacts.SFUC.value
DoNotBandFormedContacts = contacts.DNBFC.value
end
end
local function PearlOptions()
local ask = dialog.CreateDialog("Pearl Options")
ask.I = dialog.AddSlider("Iterations", 2, 1, 250, 0)
ask.ML = dialog.AddCheckbox("MegaLattice?", false)
ask.A = dialog.AddCheckbox("Annealer?", true)
ask.PC = dialog.AddCheckbox("Pull Clusters?", PullClusters)
ask.OK = dialog.AddButton("Start", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
if dialog.Show(ask) > 0 then
PullClusters = ask.PC.value
DoMegalattice = ask.ML.value
DoAnnealer = ask.A.value
Iterations = ask.I.value
if DoMegalattice == true then
DoStringer()
end
end
end
function DoStringer()
dialogTableStringer = dialog.CreateDialog("Stringer Values")
dialogTableStringer.SBL= dialog.AddSlider("Sheet Length Strong", 3.5, 1, 10, 1)
dialogTableStringer.SBLBSF= dialog.AddSlider("Band Strength", 0.9, 0, 10, 1)
dialogTableStringer.SSL= dialog.AddSlider("Short Sheet Lattitude", 6.1, 1, 10, 1)
dialogTableStringer.SSLBSF= dialog.AddSlider("Band Strength", 0.3, 0, 10, 1)
dialogTableStringer.LSL= dialog.AddSlider("Long Sheet Lattitude", 7.6, 1, 10, 1)
dialogTableStringer.LSLBSF= dialog.AddSlider("Band Strength", 0.3, 0, 10, 1)
dialogTableStringer.Long= dialog.AddSlider("Sheet Longitude", 7, 1, 10, 1)
dialogTableStringer.SLBSF= dialog.AddSlider("Band Strength", 2, 0, 10, 1)
dialogTableStringer.OneThreeH= dialog.AddSlider("1-3 Helix Length", 4.5, 1, 10, 1)
dialogTableStringer.OneThreeHBSF= dialog.AddSlider("Band Strength", 0.9, 0, 10, 1)
dialogTableStringer.OneFourH= dialog.AddSlider("1-4 Helix Length", 5.5, 1, 10, 1)
dialogTableStringer.OneFourHBSF= dialog.AddSlider("Band Strength", 0.9, 0, 10, 1)
dialogTableStringer.OneFiveH= dialog.AddSlider("1-5 Helix Length", 7.2, 1, 10, 1)
dialogTableStringer.OneFiveHBSF= dialog.AddSlider("Band Strength", 0.9, 0, 10, 1)
dialogTableStringer.LL= dialog.AddSlider("Lattice Length", 7, 1, 10, 1)
dialogTableStringer.LS= dialog.AddSlider("Lattice Strength", 1, 0, 10, 1)
dialogTableStringer.CLL= dialog.AddSlider("Cross-Lattice Length", 3.5, 1, 10, 1)
dialogTableStringer.CLS= dialog.AddSlider("Cross-Lattice Strength", 1, 0, 10, 1)
dialogTableStringer.Proceed = dialog.AddButton("It's All Good",1)
returnValue = dialog.Show( dialogTableStringer )
CrossLatticeLength=dialogTableStringer.CLL.value
CrossLatticeStrength=dialogTableStringer.CLS.value
ShortBandLength=dialogTableStringer.SBL.value
ShortSheetLattitude=dialogTableStringer.SSL.value
LongSheetLattitude=dialogTableStringer.LSL.value
OneThreeHelixLength=dialogTableStringer.OneThreeH.value
OneFourHelixLength=dialogTableStringer.OneFourH.value
OneFiveHelixLength=dialogTableStringer.OneFiveH.value
SBLBSF=dialogTableStringer.SBLBSF.value
SSLBSF=dialogTableStringer.SSLBSF.value
LSLBSF=dialogTableStringer.LSLBSF.value
SLBSF=dialogTableStringer.SLBSF.value
OneThreeHBSF=dialogTableStringer.OneThreeHBSF.value
OneFourHBSF=dialogTableStringer.OneFourHBSF.value
OneFiveHBSF=dialogTableStringer.OneFiveHBSF.value
StringSheetLength=dialogTableStringer.Long.value
LatticeLength=dialogTableStringer.LL.value
LatticeStrength=dialogTableStringer.LS.value
end
function MotherOfPearlOptions()
local ask = dialog.CreateDialog("Mother Of Pearl Options")
ask.MOPI = dialog.AddSlider("Iterations", 2, 1, 250, 0)
ask.M = dialog.AddCheckbox("Megalattice?", false)
ask.PC = dialog.AddCheckbox("Pull Clusters?", false)
ask.OK = dialog.AddButton("Start", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
if dialog.Show(ask) > 0 then
PullClusters = ask.PC.value
MOPIterations = ask.MOPI.value
DoMOPMegalattice = ask.M.value
if DoMOPMegalattice == true then
DoStringer()
end
end
end
local function TheFirstDialog()
local ask = dialog.CreateDialog("Oyster Metaphor Options")
ask.MOP = dialog.AddCheckbox("Mother Of Pearl?", true)
ask.P = dialog.AddCheckbox("Pearl?", true)
ask.SOP = dialog.AddCheckbox("String of Pearls?", true)
ask.TI = dialog.AddSlider("Total Iterations", 10, 1, 250, 0)
ask.OK = dialog.AddButton("Start", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
if dialog.Show(ask) > 0 then
DoMotherOfPearl = ask.MOP.value
DoPearl = ask.P.value
TotalIterations = ask.TI.value
DoStringOfPearls= ask.SOP.value
end
end
print("Oyster Metaphor -drjr August 2014")
print(" ")
print("For contact puzzles")
print("Mother of Pearl: coarse adjustment")
print("Pearl: refinement")
print("String of Pearls: more refinement")
print("Can choose all three and cycle.")
TheFirstDialog()
if DoMotherOfPearl == true then
MotherOfPearlOptions()
end
if DoPearl == true then
PearlOptions()
end
if DoStringOfPearls == true then
StringOfPearlsOptions()
end
for qqq = 1, TotalIterations do
if DoMotherOfPearl == true then
print("MotherOfPearl")
--print(math.rad(360))
MotherOfPearl()
end
if DoPearl == true then
print("Pearl")
Pearl()
end
if DoStringOfPearls == true then
print("String Of Pearls")
StringOfPearls()
end
end