Profile
- Name
- Rav3n_pl Hydro PulleR v2.1
- ID
- 103351
- Shared with
- Public
- Parent
- Rav3n_pl Hydro PulleR v2
- Children
- Created on
- March 30, 2020 at 20:35 PM UTC
- Updated on
- March 30, 2020 at 20:35 PM UTC
- Description
Pull random hyrophobic to all other hydrophobics
Best for
Code
--[[
Random Hydro Puller v2.1
Pulling all hydrophobes to random hydrophope segment
Using 1st sidechain atom to pull.
]] --
--- OPTIONS
qLoops = 50 --number of tries
minBS = 0.3 --starning minimum bands strenght
maxBS = 1.0 --maximum bads str
maxLoss = 10 --minimum percentage loss when pulling. ie 5% of 10000 is 500pts
pullingCI = 0.6 --clash importance while pulling
fastQstab = true -- for 1s1w as stabilize (faster)
doFuze = 100 --run fuze when score after qstabilize is close to best. If negative run fuze only if gain after qstab
energy = false --set true for exploration puzzles if want seek stability
pullDist = 4 --make bands shorter by that many units
minDist = 10 --minimum distance between segments
-- end of options
math.randomseed(recipe.GetRandomSeed())
p = print
CI = behavior.SetClashImportance
segCnt = structure.GetCount()
while structure.GetSecondaryStructure(segCnt) == 'M' do
segCnt = segCnt - 1
end
function Score()
local s
if energy == true then
s = current.GetEnergyScore()
else
s = current.GetScore()
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 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.ShakeSidechainsSelected(1)
elseif how == 'wb' then
structure.WiggleAll(2, true, false)
elseif how == 'ws' then
structure.WiggleAll(2, false, true)
elseif how == 'wa' then
structure.WiggleAll(2)
end
if Score() - sp > minppi then
return Wiggle(how, iters, minppi)
end
end
end
function AllLoop() --turning entire structure to loops
local ok = false
for i = 1, segCnt do
local s = structure.GetSecondaryStructure(i)
if s ~= 'L' then
save.SaveSecondaryStructure()
ok = true
break
end
end
if ok then
selection.SelectAll()
structure.SetSecondaryStructureSelected('L')
end
end
function RandomInt(high)
return math.random(high)
end
bestScore = Score()
function SaveBest()
local s = Score()
local g = s - bestScore
if g > 0 then
if g > 0.01 then
p('Gained another ' .. round(g) .. ' pts.')
end
bestScore = s
save.Quicksave(3)
end
end
function bandstr(str) --set all band strengt
for i = 1, band.GetCount() do
band.SetStrength(i, str)
end
end
function down(x) --cut all after comma
return x - x % 1
end
function round(x) --cut all afer 3-rd place
return x - x % 0.001
end
function SaveRB()
save.Quicksave(4)
recentbest.Restore()
SaveBest()
save.Quickload(4)
end
function qStab()
selection.SelectAll()
CI(0.1)
Wiggle('s', 1)
if fastQstab == false then
CI(0.4)
Wiggle('wa', 1)
CI(1)
Wiggle('s', 1)
end
CI(1)
Wiggle()
end
function FuzeEnd()
CI(1)
Wiggle('wa', 1)
Wiggle('s', 1)
Wiggle()
srb()
end
function Fuze1(ci1, ci2)
CI(ci1)
Wiggle('s', 1)
CI(ci2)
Wiggle('wa', 1)
end
function Fuze2(ci1, ci2)
CI(ci1)
Wiggle('wa', 1)
CI(1)
Wiggle('wa', 1)
CI(ci2)
Wiggle('wa', 1)
end
function srb()
recentbest.Restore()
SaveBest()
end
function Fuze()
p('Fuzing...')
selection.SelectAll()
recentbest.Save()
Fuze1(0.3, 0.6)
FuzeEnd()
Fuze2(0.3, 1)
srb()
Fuze1(0.05, 1)
srb()
Fuze2(0.7, 0.5)
FuzeEnd()
Fuze1(0.07, 1)
srb()
end
function MakeBands(pullSg)
band.DeleteAll()
for i = 1, segCnt do
if structure.IsHydrophobic(i) then
local bn1 = band.GetCount()
local setDist = structure.GetDistance(i, pullSg) - pullDist - minDist
if setDist > 1 then
band.AddBetweenSegments(i, pullSg, 5, 5) --pull using 1st sidechain segment
bn1 = band.GetCount() - bn1
if bn1 > 0 then
band.SetGoalLength(band.GetCount(), setDist)
end
end
end
end
end
function HP()
local pullSg
local lastBS = minBS
local qsc = Score()
save.Quicksave(3)
p('Starting Hydro Puller, ' .. qLoops .. ' tries. Start score: ' .. round(qsc))
for x = 1, qLoops do
local pullSg
while true do --random hydro segment
pullSg = RandomInt(segCnt)
if structure.IsHydrophobic(pullSg) then
break
end
end
local ls = Score()
local loss = round(ls * (maxLoss / 100))
p('Pass ' .. x .. ' of ' .. qLoops .. ' pulling sg: ' .. pullSg)
MakeBands(pullSg)
p('Made ' .. band.GetCount() .. ' bands, pulling until loss of ' .. loss .. ' pts.')
-- selection.SelectAll()
CI(pullingCI)
recentbest.Save()
for str = lastBS, maxBS, 0.07 do --search enough band strenght to move
recentbest.Restore() --because sometimes it makes points during pull :D
local ss = Score()
bandstr(str)
structure.WiggleAll(1, true, false)
if ss - Score() > loss then
lastBS = str - 0.1
if lastBS < minBS then
lastBS = minBS
end
break
end
end
band.DeleteAll()
SaveRB() --because sometimes it missing fractions
p('Stabilizing...')
CI(1)
recentbest.Save() --after pulling
qStab()
if Score() > ls + doFuze then
SaveBest()
Fuze(4)
end
SaveBest()
save.Quickload(3) --load best state
p('Current score: ' .. round(Score()) .. ' Total gain: ' .. round(Score() - qsc))
end
p('Total HP gain: ' .. round(Score() - qsc))
end
--main call
HP()
-- end of script