Icon representing a recipe

Recipe: TEST QUAKE SHEAR CONSTRUCT

created by Vincera

Profile


Name
TEST QUAKE SHEAR CONSTRUCT
ID
104394
Shared with
Public
Parent
None
Children
None
Created on
January 23, 2021 at 14:28 PM UTC
Updated on
December 30, 2024 at 20:01 PM UTC
Description

TEST

Best for


Code


--[[ Quake shear - a Quake by slice with shearing by Marie Suchard based on Rav3n Quake R and Quake slice V1.3 ]]-- --- options there VVVV maxLoss=0.5 --minimum percentage loss when pulling. ie 5% of 10000 is 500pts pullingCI=0.9 --clash importance while pulling doFuze=-1 --run fuze when score after qstabilize is close to best (negative - if gain after qstab) maxns=10 -- maximum number of slices fastQstab=false --if true ony 1s1w as stabilize after pull --- end of options ^^^ local function _abs(value) if value < 0 then value = -value end return value end math= { abs = _abs, } function Score() return get_score(true) end P = print --a short p=P CI=set_behavior_clash_importance segCount = get_segment_count() --always the same function qStab() select_all() 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() SaveBest() 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 reFuze(scr) local s=Score() if s<scr then quickload(4) else scr=s quicksave(4) end return scr end function Fuze() local scr=Score() quicksave(4) select_all() Fuze1(0.3,0.6) FuzeEnd() scr=reFuze(scr) Fuze2(0.3,1) SaveBest() scr=reFuze(scr) Fuze1(0.05,1) SaveBest() scr=reFuze(scr) Fuze2(0.7,0.5) FuzeEnd() scr=reFuze(scr) Fuze1(0.07,1) SaveBest() reFuze(scr) end bestScore=Score() function SaveBest() local s=Score() local g=s-bestScore if g>0 then P("Gained another ",round(g)," pts.") bestScore=s quicksave(3) end end function Wiggle(how, iters, minppi) --score conditioned recursive wiggle/shake if how==nil then how="wa" end if iters==nil then iters=6 end if minppi==nil then minppi=0.04 end if iters>0 then iters=iters-1 local sp=Score() if how == "s" then do_shake(1) elseif how == "wb" then do_global_wiggle_backbone(2) elseif how == "ws" then do_global_wiggle_sidechains(2) elseif how == "wa" then do_global_wiggle_all(2) end local ig=Score()-sp if ig > minppi then return Wiggle(how, iters, minppi) end --recurence tail call ;] end end function bandstr(str) --set all band strengt for i=1, get_band_count() do band_set_strength(i, str) end end function delBands() --delete all bands band_delete() 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() quicksave(4) restore_recent_best() SaveBest() quickload(4) end function Quakel()--a Quake --do_unfreeze_all() quicksave(3) P("Starting Quake shear. Start score: ",round(qsc)) deselect_all() local loss=math.abs(down(Score()*maxLoss/100)) P("Pulling until loss of ",loss," pts.") untrois=1 for ns=1,maxns do for sl=1 ,ns do delBands() maxl=0 unl=0 deuxl=0 maxr=0 troisl=0 quatrel=0 for i=1,segCount-1 do local liun=get_segment_distance(i,un) for j=i+1,segCount do local ljun=get_segment_distance(j,un) local lij=get_segment_distance(i,j) if liun>=(sl-1)*max /ns and liun<=sl*max/ns and ljun>=(sl-1)*max /ns and ljun<=sl*max/ns then if lij> maxl then unl=i deuxl=j maxl=lij end -- great than maxl end -- in the slice end --j end --i if unl>0 and deuxl>0 and maxl>0 then for i=1,segCount-1 do local liun=get_segment_distance(i,un) local litrois=get_segment_distance(i,unl) if litrois< maxl/2 +2 and litrois > maxl/2 - 2 then for j=i+1,segCount do local ljun=get_segment_distance(i,un) local ljtrois=get_segment_distance(j,unl) if ljtrois< maxl/2 +2 and ljtrois > maxl/2 - 2 then local lij=get_segment_distance(i,j) if liun>=(sl-1)*max /ns and liun<=sl*max/ns and ljun>=(sl-1)*max /ns and ljun<=sl*max/ns then if lij> maxr then troisl=i quatrel=j maxr=lij end -- great than maxr end -- end -- in the slice end --j end --if middle end --i end if ns==1 then trois=troisl end untrois=-1*untrois print(sl,'/',ns,'/',maxns,' pole1: ', unl, ' pole2: ', deuxl, ' mountain1: ', troisl, ' moutain2: ',quatrel) if unl>0 and deuxl>0 and maxl>0 and troisl>0 and quatrel>0 then --check possibility for y=1,segCount do local lyun=get_segment_distance(y,un) if lyun>=(sl-1)*max /ns and lyun<=sl*max/ns then if (get_segment_distance(y,troisl) - get_segment_distance(y,quatrel) ) * untrois <0 then mins=deuxl else mins=unl end if get_segment_distance(y,deuxl)>4.5 and math.abs(y-mins)>5 and get_segment_distance (y,unl)>4.5 then band_add_segment_segment(y,mins) --band only if segments are not so close end -- not close to one of the pole end -- in the slice end -- y end -- check possibility if get_band_count()>0 then --check do we have any band select_all() set_behavior_clash_importance(pullingCI) reset_recent_best() for str=0.1,1.2,0.07 do--search enough band strenght to move restore_recent_best()--because sometimes it makes points during pull :D ss=Score() bandstr(str) do_global_wiggle_backbone(1) if ss-Score()>loss then break end end set_behavior_clash_importance(1) delBands() SaveRB() --because sometimes it missing fractions reset_recent_best() --after pulling qStab() if bestScore-Score()<doFuze then SaveBest() Fuze() end SaveBest() quickload(3) --load best state P("Current score: ",round(Score())," Total gain: ",round(Score()-qsc)) end end -- slice end -- number of slice end -- quake max=0 un=0 deux=0 P("Searching for central axe...") for i=1,segCount-1 do for j=2,segCount do local len=get_segment_distance(i,j) if len > max then un=i deux=j max=len end end end --main call qsc=Score() --starting score Quakel() un=trois --other side Quakel() --[[ Greetings! It is a script that contains many other scripts and allows you to run any of them. Just choose which one to run after the start. Alos there is an Autobot script that allows you to predefine the run sequence of basic scripts with given parameters. So you can create your own Score gain algorythm. How it works: 1. Each basic script have a code and some of them have a parameters. When you want to include a basic script to sequence, print code and print all the parameters with the undescore. After the each basic script print the dot. For example, if you want to use BlueFuze just include "BF." in the sequence. If you want to use Band Test include "BT_15_87_97.", where 15, 87 and 97 - script parameters (see description). 2. When sequence is completed, write it to text field and start the script. 3. Script will be sequentially running your predefined scripts. When All scripts completed, it checks how much score is gained. If its exceed the limit, then the sequence runs for one more time. If not, then the Iterations ends and the new Iteration starts (from the structure when the script was started). The example of sequence, that I use: "CL.FR.BT_15_87_97.BT_15_103_113.RW_2_1_10.QU_15.BF.RW_1_1_10.LW_12_2.SR." Basic scripts. 1. Clashing. Script code: CL Script Parameters: none Script Description: Making a sequence of wiggles and shakes with different clashing. 2. FastRelax. Script code: FR Script Parameters: none Script Description: Well known FastRelax script :) 3. BlueFuze. Script code: BF Script Parameters: none Script Description: BlueFuze. 4. WS or SW. Script code: WS Script Parameters: none Script Description: Tries 4 different WS/SW tactics to improve score from destabilized status. 5. Band Test. Script code: BT Script Parameters: 1) Number of iterations. 2) Lowest length (in % from original). 3) Highest length (in % from original). Script Description: Creates a random band with the length in given boundaries. Wiggle structure with band enabled, then delete band and wiggle out. Repeat given number of Iterations. Script example: "BT_15_87_97.". 6. Local Wiggle. Script code: LW Script Parameters: 1) Wiggle segment Length 2) Number of wiggle iterations. Script Description: Makes local wiggle. Script example: "LW_12_2.". 7. Local Rebuild. Script code: LR Script Parameters: 1) Rebuild segment Length Script Description: Makes local rebuildes from the begin to the end of structure. Script example: "LW_12_2.". 8. Quake. Script code: QU Script Parameters: 1) Distance between segments with bands. Script Description: Makes bands with the given length between segments. Wiggle structure with band enabled, then delete band and wiggle out. Script example: "QU_15.". 9. Sidechain Test. Script code: ST Script Parameters: 1) Segment Number Script Description: Test every possible position of sidechain at given segment. Script example: "ST_10.". 10. Mutate. Script code: MU Script Parameters: none Script Description: Just do mutate once. 11. Mutate and Test. Script code: MT Script Parameters: 1) Function number. 2) Number of tries (affects only 3rd function). Script Description: Depending on the function number it does: 1) Test all posible changes of AA for one segment (very long). 2) Test all posible changes of AA for two segment (impossible long). 3) Test random change of 2 AAs for given number of times. Script example: "MT_3.". 12. New Mutate Script code: NM Script Parameters: none Script Description: Sequentially mutate each segment for all possible AAs. 13. Rebuilder Script code: RE Script Parameters: 1) Start segment. 2) End segment. 3) Number of tries. Script Description: Rebuild the segment and check the structure by wiggles and shake. Script example: "RE_10_13_5.". 14. Sidechain Flipper. Script code: SF Script Parameters: none Script Description: Sequentially flips each sidechain. 15. Soft Relax Script code: SR Script Parameters: none Script Description: The variation of FastRelax. 16. Rebuild Worst. Script code: RW Script Parameters: 1) Length of segment to rebuild. 2) Number of tries for each segment. 3) Number of segments to rebuild. Script Description: Rebuilds the worst scoring segments of given length. Script example: "RW_1_1_10.". ]]-- --v1.0: original --v1.1: with dialog for Tandem run (check box) --v1.2: changed dialog for Tandem run (save resolution) --v1.2.1 Isaksson Share v1.4 --v1.2.2 Isaksson Share v1.5.1 --v1.2.3 small fix thanks to DodoBird, Isaksson Share v1.5.2 fsl={} fsl.aminosLetterIndex=1 fsl.aminosShortIndex=2 fsl.aminosLongIndex=3 fsl.aminosPolarityIndex=4 fsl.aminosAcidityIndex=5 fsl.aminosHydropathyIndex=6 fsl.aminos = { {'a','Ala','Alanine', 'nonpolar','neutral', 1.8}, -- {'b','Asx','Asparagine or Aspartic acid' }, {'c','Cys','Cysteine', 'nonpolar','neutral', 2.5}, {'d','Asp','Aspartic acid', 'polar','negative', -3.5}, {'e','Glu','Glutamic acid', 'polar','negative', -3.5}, {'f','Phe','Phenylalanine','nonpolar','neutral', 2.8}, {'g','Gly','Glycine', 'nonpolar','neutral', -0.4}, {'h','His','Histidine', 'polar','neutral', -3.2}, {'i','Ile','Isoleucine', 'nonpolar','neutral', 4.5}, -- {'j','Xle','Leucine or Isoleucine' }, {'k','Lys','Lysine', 'polar','positive', -3.9}, {'l','Leu','Leucine', 'nonpolar','neutral', 3.8}, {'m','Met','Methionine ', 'nonpolar','neutral', 1.9}, {'n','Asn','Asparagine', 'polar','neutral', -3.5}, -- {'o','Pyl','Pyrrolysine' }, {'p','Pro','Proline', 'nonpolar','neutral', -1.6}, {'q','Gln','Glutamine', 'polar','neutral', -3.5}, {'r','Arg','Arginine', 'polar','positive', -4.5}, {'s','Ser','Serine', 'polar','neutral', -0.8}, {'t','Thr','Threonine', 'polar','neutral', -0.7}, -- {'u','Sec','Selenocysteine' }, {'v','Val','Valine', 'nonpolar','neutral', 4.2}, {'w','Trp','Tryptophan', 'nonpolar','neutral', -0.9}, -- {'x','Xaa','Unspecified or unknown amino acid' }, {'y','Tyr','Tyrosine', 'polar','neutral', -1.3}, -- {'z','Glx','Glutamine or glutamic acid' } } --START Isaksson Share v1.5.2 --Copy this into your recipe and call before and after every period of time. --Warning: all saves onto you hard disk will have to be removed manually afterwards ! --reference: supplementary material for Koepnick et al (2019) De novo protein design by citizen scientists, Nature, volume 570, pages 390394 --https://static-content.springer.com/esm/art%3A10.1038%2Fs41586-019-1274-4/MediaObjects/41586_2019_1274_MOESM1_ESM.pdf --v1: script by Isaksson --v1.2 added the dialog (BK 1/10/2019) --v1.3 added time intervals when no gain --v1.4 PrintVerbose, check every 60 seconds --v1.5 option Temp name --v1.5.2 fixed timeleft, Name to save timeLeft=os.difftime(puzzle.GetExpirationTime(),os.time())/3600 -- in hours print("Remaining time: "..timeLeft) startTime=os.time() -- in seconds userTimeInterval= 60 -- in seconds lastchecktime = startTime -- in seconds verbose = false -- print more or less info save_resolution=1000 function timeLeft() local result=os.difftime(puzzle.GetExpirationTime(),os.time())/3600 -- in hours return result end function PrintVerbose(text) if verbose then print(text) end end function ItsCheckTime() local currentTime= os.time() -- in seconds if currentTime-lastchecktime > userTimeInterval then PrintVerbose(timeLeft().." hours remaining") return true end return false end function rounding(x)--cut all afer 3-rd place return x-x%0.001 end function before_Solution(rnd,str_name) if save_resolution > 999 then return end -- New BK 1/10/2019 PrintVerbose("-Before-") hi_score = 0 hi_idx = 1 sol = save.GetSolutions() if (sol[0] == nil) then print("0 solutions found") --save.SaveSolution("auto_"..rnd) else PrintVerbose((#sol+1) .. " solutions found") for idx = 0, #sol do soli = sol[idx] if (string.find(soli.name,rnd) ~= nil) then PrintVerbose(soli.name .. " : " .. soli.score) if (soli.score > hi_score) then hi_score = soli.score hi_idx = idx end end end --print("Load the solution ...") if(current.GetEnergyScore()+save_resolution < hi_score) then save.LoadSolution(sol[hi_idx]) soli = sol[hi_idx] print("Load solution: "..soli.name.." : "..rounding(soli.score,value_score_resolution)) end end end function after_Solution(rnd,str_name) if save_resolution > 999 then return end -- New BK 1/10/2019 PrintVerbose("-After-") hi_score = 0 hi_idx = 1 sol = save.GetSolutions() if (sol[0] == nil) then print("0 solutions found") str = "auto".."-"..rnd.."-"..rounding(current.GetEnergyScore(),value_score_resolution) print("Save solution "..str) save.SaveSolution(str) else PrintVerbose((#sol+1) .. " solutions found") for idx = 0, #sol do soli = sol[idx] if (string.find(soli.name,rnd) ~= nil) then PrintVerbose(soli.name .. " : " .. soli.score) if (soli.score > hi_score) then hi_score = soli.score hi_idx = idx end end end PrintVerbose("Save the solution ...") band.DeleteAll() if(current.GetEnergyScore()-save_resolution > hi_score) then str = str_name.."-"..rnd.."-"..rounding(current.GetEnergyScore(),value_score_resolution) print("Save solution: "..str) save.SaveSolution(str) end end end str_name= ui.GetTrackName() -- copy-paste anywhere on top of the recipe rnd= "Temp" -- Warning: edit before in order to cach the right loop name --How to use: --Uncomment and insert the following 2 lines on the right places, before or after each loop: --if ItsCheckTime() then before_Solution(rnd,str_name) end -- as often as possible after score evaluations, e.g. in savebest(), or before any action --after_Solution(rnd,str_name) -- after any gain (will not save any loaded solution) --Uncommend and copy-paste the following 2x2 lines within the dialog on the right places: --ask.LabelRowBeforeSave = dialog.AddLabel("Keep save resolution to 1000 to avoid local saves") --(optional) copy-paste and adapt in the dialog --ask.save_resolution = dialog.AddSlider("Save resolution:", 1000, 0.3, 1000, 1) --copy-paste and adapt in the dialog (parameters)-- 1000 means no sharing --ask.save_Name = dialog.AddTextbox("Name to save: ", rnd) --rnd=ask.save_Name.value --save_resolution=ask.save_resolution.value -- copy-paste and adapt after the dialog.show --if save_resolution < 1000 then print("Checking for solutioun every "..userTimeInterval.." seconds") end --End of Isaksson Share function BlueFuze() if ItsCheckTime() then before_Solution(rnd,str_name) end -- as often as possible after score evaluations, e.g. in savebest(), or before any action behavior.SetClashImportance(.05) structure.ShakeSidechainsAll(1) behavior.SetClashImportance(1) structure.WiggleAll(8) behavior.SetClashImportance(.07) structure.ShakeSidechainsAll(1) behavior.SetClashImportance(1) structure.WiggleAll(8) recentbest.Restore() behavior.SetClashImportance(.3) structure.WiggleAll(1) behavior.SetClashImportance(1) structure.WiggleAll(8) recentbest.Restore() after_Solution(rnd,str_name) end function SoftRelaxFull() if ItsCheckTime() then before_Solution(rnd,str_name) end -- local function SoftRelax() local function StepC(Clashing,Shakes,Wiggles) behavior.SetClashImportance(Clashing) structure.ShakeSidechainsAll(Shakes) structure.WiggleAll(Wiggles) end local shakes=2 --number of shakes local wiggles=3 --number of wiggles StepC(0.55,shakes,wiggles) StepC(0.25,shakes,wiggles) StepC(0.05,shakes,wiggles) StepC(0.25,shakes,wiggles) StepC(0.55,shakes,wiggles) StepC(1,shakes,wiggles) end local ss local minPpi=1 local Step=1 repeat ss=current.GetEnergyScore() SoftRelax() print(Step..". Score: "..math.max(current.GetEnergyScore(),ss).." gain: "..math.max(current.GetEnergyScore()-ss,0)) Step = Step+1 recentbest.Restore() until current.GetEnergyScore()-ss<minPpi after_Solution(rnd,str_name) end function FastRelaxFull() if ItsCheckTime() then before_Solution(rnd,str_name) end -- local function FastRelax() local function StepC(Clashing,Shakes,Wiggles) behavior.SetClashImportance(Clashing) structure.ShakeSidechainsAll(Shakes) structure.WiggleAll(Wiggles) end local shakes=2 --number of shakes local wiggles=5 --number of wiggles StepC(0.02,shakes,wiggles) StepC(0.25,shakes,wiggles) StepC(0.55,shakes,wiggles) StepC(1,shakes,wiggles) end local ss local minPpi=2 local Step=1 repeat ss=current.GetEnergyScore() FastRelax() print(Step..". Score: "..math.max(current.GetEnergyScore(),ss).." gain: "..math.max(current.GetEnergyScore()-ss,0)) Step = Step+1 recentbest.Restore() until current.GetEnergyScore()-ss<minPpi after_Solution(rnd,str_name) end function clashing(Repeat) if ItsCheckTime() then before_Solution(rnd,str_name) end -- local i = 1 local sc while i<10 do sc = current.GetEnergyScore() behavior.SetClashImportance(i/10) structure.WiggleAll(i) behavior.SetClashImportance(1) structure.MutateSidechainsAll(1) structure.WiggleAll(20) structure.MutateSidechainsAll(1) structure.WiggleAll(4) print("Clashing: " .. i/10 .. ", score: " .. current.GetEnergyScore()-sc) if sc<current.GetEnergyScore() and Repeat==1 and i < 8 then i = 1 else i = i+1 end recentbest.Restore() end after_Solution(rnd,str_name) end function ws_or_sw(params) if ItsCheckTime() then before_Solution(rnd,str_name) end -- local function ws_or_sw_1() structure.WiggleAll(15) structure.MutateSidechainsAll(1) structure.WiggleAll(10) structure.MutateSidechainsAll(1) structure.WiggleAll(5) print("WS score: "..current.GetEnergyScore()) end local function ws_or_sw_2() structure.MutateSidechainsAll(1) structure.WiggleAll(15) structure.MutateSidechainsAll(1) structure.WiggleAll(10) structure.ShakeSidechainsAll(1) structure.WiggleAll(5) print("SW score: "..current.GetEnergyScore()) end local function ws_or_sw_3() behavior.SetClashImportance(0.5) structure.WiggleAll(4) behavior.SetClashImportance(1) structure.MutateSidechainsAll(1) structure.WiggleAll(15) structure.MutateSidechainsAll(1) structure.WiggleAll(10) structure.ShakeSidechainsAll(1) structure.WiggleAll(5) print("SW 0.5 score: "..current.GetEnergyScore()) end local function ws_or_sw_4() for i=3, 10 do behavior.SetClashImportance(i/10) structure.WiggleAll(1) if i==3 or i==6 then structure.ShakeSidechainsAll(1) end end structure.ShakeSidechainsAll(1) structure.WiggleAll(15) structure.ShakeSidechainsAll(1) structure.WiggleAll(5) print("Step clash: "..current.GetEnergyScore()) end selection.SelectAll() save.Quicksave(100) if params[1]==1 then save.Quickload(100) ws_or_sw_1() end if params[2]==1 then save.Quickload(100) ws_or_sw_2() end if params[3]==1 then save.Quickload(100) ws_or_sw_3() end if params[4]==1 then save.Quickload(100) ws_or_sw_4() end recentbest.Restore() after_Solution(rnd,str_name) end function Band_tests(Start_LengthP,End_LengthP,Clashing,Iteration,TotalIteration) if ItsCheckTime() then before_Solution(rnd,str_name) end -- local function PullPart(Segment1,Segment2,LengthP,Strength) band.DeleteAll() band.AddBetweenSegments(Segment1,Segment2) band.SetStrength(1,Strength) band.SetGoalLength(1,structure.GetDistance(Segment1,Segment2)*LengthP) structure.WiggleAll(1) band.DeleteAll() end local startSeg=math.random(1,structure.GetCount()-9) while structure.IsLocked(startSeg) do startSeg=math.random(1,structure.GetCount()-9) end local endSeg=math.random(startSeg+8,structure.GetCount()) local LengthP=math.random(Start_LengthP,End_LengthP) local startScore = current.GetEnergyScore() if TotalIteration == 0 then TotalIterationStr = "inf" else TotalIterationStr = TotalIteration end if LengthP>97 and LengthP<=100 then LengthP=Start_LengthP end if LengthP>100 and LengthP<103 then LengthP=End_LengthP end PullPart(startSeg,endSeg,LengthP/100,10) structure.MutateSidechainsAll(1) structure.WiggleAll(15) structure.MutateSidechainsAll(1) structure.WiggleAll(5) behavior.SetClashImportance(Clashing) structure.WiggleAll(5) behavior.SetClashImportance(1) structure.WiggleAll(15) recentbest.Restore() print(Iteration .."/".. TotalIterationStr .. "; " .. startSeg .. "-" .. endSeg .. ", score: " ..math.max(startScore,current.GetEnergyScore()) .. ", gain: " .. math.max(0,current.GetEnergyScore()-startScore)) after_Solution(rnd,str_name) end function local_wiggle(Len,Num) if ItsCheckTime() then before_Solution(rnd,str_name) end -- local NumSegm = structure.GetCount() local sc1 for i = 1, NumSegm-Len+1, 1 do Score = current.GetEnergyScore() selection.DeselectAll() selection.SelectRange(i, i+Len-1) structure.LocalWiggleSelected(Num) sc1=current.GetEnergyScore()-Score if sc1 <0.0001 then sc1=0 end print(i .. "-" .. i+Len-1 .. "/" .. NumSegm .. ", score: " .. current.GetEnergyScore() .. ", gain: " .. sc1) recentbest.Restore() end after_Solution(rnd,str_name) end function local_rebuild_all(Length,Clashing) if ItsCheckTime() then before_Solution(rnd,str_name) end -- local function local_rebuild(Start,Len,Clsh) local sc=current.GetEnergyScore() local newScore selection.DeselectAll() selection.SelectRange(Start,Start+Len-1) for i=1,3 do if current.GetEnergyScore()-sc<0.05 and sc-current.GetEnergyScore()<0.05 then structure.RebuildSelected(i) end end if current.GetEnergyScore()-sc>0.05 or sc-current.GetEnergyScore()>0.05 then selection.SelectAll() structure.MutateSidechainsSelected(1) structure.WiggleAll(20) structure.ShakeSidechainsAll(1) selection.DeselectAll() selection.SelectRange(Start,Start+Len-1) structure.LocalWiggleSelected(15) selection.SelectAll() structure.WiggleAll(15) newScore=current.GetEnergyScore() if Clsh<1 then behavior.SetClashImportance(Clsh) structure.WiggleAll(4) behavior.SetClashImportance(1) structure.MutateSidechainsSelected(1) structure.WiggleAll(15) structure.ShakeSidechainsAll(1) structure.WiggleAll(10) if current.GetEnergyScore()>newScore then newScore=current.GetEnergyScore() end end if newScore-sc<0.0001 then sc=0 else sc=newScore-sc end print(Start .. "-" .. Start+Len-1 .. "/" .. structure.GetCount() .. ", score: " .. current.GetEnergyScore() .. ", gain: " .. sc) end end for z=1,structure.GetCount()-Length do recentbest.Save() local_rebuild(z,Length,Clashing) recentbest.Restore() end after_Solution(rnd,str_name) end function RebuildWorst(Length,RebuildsTries,Clashing,NumSegsForRebuild) if ItsCheckTime() then before_Solution(rnd,str_name) end -- local function Worst_Segments(Length) local function Sort(tab) for x=1,#tab-1 do for y=x+1,#tab do if tab[x][3]>tab[y][3] then tab[x],tab[y]=tab[y],tab[x] end end end return tab end local NumSegs=structure.GetCount() local segsInfo={} for i=1, NumSegs-Length+1 do segsInfo[i]={i,i+Length-1,current.GetSegmentEnergyScore(i)} for j=2, Length do segsInfo[i]={segsInfo[i][1],segsInfo[i][2],segsInfo[i][3] + current.GetSegmentEnergyScore(i+j-1)} end end segsInfo=Sort(segsInfo) return segsInfo end local NumSegs=structure.GetCount() local WorstSegs=Worst_Segments(Length) local segsForRebuild={} local Step=1 local str="" local sc=current.GetEnergyScore() for i=1,math.min(#WorstSegs,NumSegsForRebuild) do segsForRebuild={} selection.DeselectAll() for j=math.max(WorstSegs[i][1]-1,1), math.min(WorstSegs[i][2]+1,NumSegs) do segsForRebuild[#segsForRebuild + 1] = j end Step=1 str="" RebuildsTriesNum=RebuildsTries+1 RebuildsTriesNum=RebuildsTriesNum-1 while Step<=RebuildsTriesNum do sc=current.GetEnergyScore() for l=1, #segsForRebuild do selection.Select(segsForRebuild[l]) end for l=1,10 do if current.GetEnergyScore()-sc<0.05 and sc-current.GetEnergyScore()<0.05 then structure.RebuildSelected(i) end end if current.GetEnergyScore()-sc>0.05 or sc-current.GetEnergyScore()>0.05 then structure.MutateSidechainsAll(1) structure.WiggleAll(15) structure.ShakeSidechainsAll(1) structure.WiggleSelected(10) structure.WiggleAll(10) if Clashing<1 then behavior.SetClashImportance(Clashing) structure.WiggleAll(4) behavior.SetClashImportance(1) structure.MutateSidechainsAll(1) structure.WiggleAll(10) structure.ShakeSidechainsAll(1) structure.WiggleAll(5) end end str=Step .." Try " .. ", " .. segsForRebuild[1] .. "-" .. segsForRebuild[#segsForRebuild] .. ", score: " .. current.GetEnergyScore() if current.GetEnergyScore()-sc > 0.0001 then str = str .. ", +" .. current.GetEnergyScore()-sc Step=0 end print(str) Step = Step + 1 recentbest.Restore() sc=current.GetEnergyScore() end end after_Solution(rnd,str_name) end function quake(Length,ScoreDelta,Shake,Clashing) if ItsCheckTime() then before_Solution(rnd,str_name) end -- function quake_one(Start,Diff,Delta,Shk,Clsh) local function set_bands(Str) for z=1, band.GetCount() do band.SetStrength(z,Str) end end local numSegments=structure.GetCount() local sc=current.GetEnergyScore() local sc1 band.DeleteAll() selection.DeselectAll() for i=0, numSegments/Diff do for j=i+1, numSegments/Diff do if Start+i*Diff<=numSegments and Start+j*Diff<=numSegments then band.AddBetweenSegments(Start+i*Diff,Start+j*Diff) end end end Band_str=0.08 selection.SelectAll() while math.abs(current.GetEnergyScore()-sc)<=Delta do set_bands(Band_str) structure.WiggleAll(1) Band_str=Band_str+0.03 end band.DeleteAll() if Shk==2 then structure.MutateSidechainsAll(1) end if Shk==1 then structure.ShakeSidechainsAll(1) end structure.WiggleAll(15) structure.ShakeSidechainsAll(1) structure.WiggleAll(10) structure.ShakeSidechainsAll(1) structure.WiggleAll(5) sc1=current.GetEnergyScore() if Clsh<1 then behavior.SetClashImportance(Clsh) structure.WiggleAll(1) behavior.SetClashImportance(1) structure.ShakeSidechainsAll(1) structure.WiggleAll(10) structure.ShakeSidechainsAll(1) structure.WiggleAll(5) end if current.GetEnergyScore()>sc1 then sc2=current.GetEnergyScore() else sc2=sc1 end print(Start .. ":" .. Diff .. ", score: " .. sc2 .. ", gain: " .. sc2-sc) end for i=1, Length-1 do quake_one(i,Length,ScoreDelta,Shake,Clashing) recentbest.Restore() band.DeleteAll() recentbest.Save() end after_Solution(rnd,str_name) end function sidechain_shock(Seg) if ItsCheckTime() then before_Solution(rnd,str_name) end -- local SnapCnt=rotamer.GetCount(Seg) local sc=current.GetEnergyScore() print("Segment: " .. Seg .. ", snaps: " .. SnapCnt .. ", start: " .. current.GetEnergyScore()) save.Quicksave(100) for i=1, SnapCnt do save.Quickload(100) rotamer.SetRotamer(Seg,i) if SnapCnt>2 and current.GetEnergyScore~=sc then selection.DeselectAll() selection.Select(Seg) structure.LocalWiggleSelected(20) selection.SelectAll() structure.WiggleAll(10) structure.ShakeSidechainsAll(1) selection.DeselectAll() selection.Select(Seg) structure.LocalWiggleSelected(20) selection.SelectAll() structure.ShakeSidechainsAll(1) structure.WiggleAll(10) structure.WiggleAll(10,false,true) end print(Seg .. "/" .. structure.GetCount() .. ", " .. i .. "/" .. SnapCnt .. ", score: " .. current.GetEnergyScore() .. ", gain: " .. current.GetEnergyScore()-sc) end after_Solution(rnd,str_name) end function sidechain_test_all() if ItsCheckTime() then before_Solution(rnd,str_name) end -- for j=1, structure.GetCount() do recentbest.Save() if rotamer.GetCount(j)>2 then sidechain_shock(j) end recentbest.Restore() end after_Solution(rnd,str_name) end function mutate(Shk, Num) if ItsCheckTime() then before_Solution(rnd,str_name) end -- selection.SelectAll() if Shk==1 then structure.ShakeSidechainsAll(Num) end if Shk==2 then structure.MutateSidechainsAll(Num) end after_Solution(rnd,str_name) end function Mutate_And_Test(RunFunction,NumTries) if ItsCheckTime() then before_Solution(rnd,str_name) end -- local function mutate_and_test_1(n,Clsh,IsAll,Num) local score1 structure.SetAminoAcid(n,fsl.aminos[Num][fsl.aminosLetterIndex]) score1 = current.GetEnergyScore() structure.ShakeSidechainsAll(1) behavior.SetClashImportance(Clsh) structure.WiggleAll(10) behavior.SetClashImportance(1) if current.GetEnergyScore()-score1>0.003 or score1-current.GetEnergyScore()>0.003 then if IsAll==0 then selection.DeselectAll() selection.Select(n) structure.MutateSidechainsSelected(1) else structure.MutateSidechainsAll(1) end structure.WiggleAll(10) end end local function full_1_step(Clsh) local str_dop = "" local score0 for i = 1, #mutable do for j = 1, 20 do score0 = current.GetEnergyScore() str_dop = "" mutate_and_test_1(mutable[i],Clsh,0,j) str_dop = mutable[i] .. "_" .. fsl.aminos[j][fsl.aminosLetterIndex] .. ": " .. current.GetEnergyScore() recentbest.Restore() if current.GetEnergyScore() > score0 + 0.0001 then str_dop = str_dop .. ", +" .. current.GetEnergyScore() - score0 end print(str_dop) end end end local function full_2_step(Clsh) local str = "" local str_dop = "" local score0 for i1 = 1, #mutable-1 do for j1 = 1, 20 do str = mutable[i1] .. "_" .. fsl.aminos[j1][fsl.aminosLetterIndex] .. " + " for i2 = i1+1, #mutable do for j2 = 1, 20 do score0 = current.GetEnergyScore() structure.SetAminoAcid(i1,fsl.aminos[j1][fsl.aminosLetterIndex]) mutate_and_test_1(mutable[i2],Clsh,0,j2) str_dop = mutable[i2] .. "_" .. fsl.aminos[j2][fsl.aminosLetterIndex] .. ": " .. current.GetEnergyScore() recentbest.Restore() if current.GetEnergyScore() > score0 + 0.0001 then str_dop = str_dop .. ", +" .. current.GetEnergyScore() - score0 end print(str .. str_dop) end end end end end function random_2_step(Clsh,NumTries) local str = "" local str_dop = "" local score0 local step = 1 NumTries=NumTries+1 NumTries=NumTries-1 while step <= NumTries do score0 = current.GetEnergyScore() i1 = math.random(#mutable) j1 = math.random(20) str = mutable[i1] .. "_" .. fsl.aminos[j1][fsl.aminosLetterIndex] .. " + " i2 = math.random(#mutable) j2 = math.random(20) structure.SetAminoAcid(i1,fsl.aminos[j1][fsl.aminosLetterIndex]) mutate_and_test_1(mutable[i2],Clsh,step%2,j2) str_dop = mutable[i2] .. "_" .. fsl.aminos[j2][fsl.aminosLetterIndex] .. ": " .. current.GetEnergyScore() recentbest.Restore() if current.GetEnergyScore() > score0 + 0.0001 then str_dop = str_dop .. ", +" .. current.GetEnergyScore() - score0 end step = step + 1 print(str .. str_dop) end end mutable={} Clsh = 0.9 for i=1, structure.GetCount() do if structure.IsMutable(i) then mutable[#mutable+1]=i end end if RunFunction == 1 then full_1_step(Clsh) end if RunFunction == 2 then full_2_step(Clsh) end if RunFunction == 3 then random_2_step(Clsh,NumTries) end after_Solution(rnd,str_name) end function new_mutate(Num) if ItsCheckTime() then before_Solution(rnd,str_name) end -- structure.SetAminoAcid(Num,fsl.aminos[1][1]) maxScore=current.GetEnergyScore() bestAcid=fsl.aminos[1][1] for i=2, #fsl.aminos do structure.SetAminoAcid(Num,fsl.aminos[i][1]) if current.GetEnergyScore()>maxScore then maxScore=current.GetEnergyScore() bestAcid=fsl.aminos[i][1] end end structure.SetAminoAcid(Num,bestAcid) after_Solution(rnd,str_name) end function new_mutate_all() if ItsCheckTime() then before_Solution(rnd,str_name) end -- mutable={} for i=1, structure.GetCount() do if structure.IsMutable(i) then mutable[#mutable+1]=i end end for j=1, #mutable do new_mutate(mutable[j]) recentbest.Restore() print(mutable[j].."_"..structure.GetAminoAcid(mutable[j])..", score: "..current.GetEnergyScore()) end after_Solution(rnd,str_name) end function rebuilder(startSegm,endSegm,Clashing,Num) if ItsCheckTime() then before_Solution(rnd,str_name) end -- local Cnt=1 local str="" local segsForRebuild={} local NumSegs=structure.GetCount() local sc=current.GetEnergyScore() for i=math.max(startSegm,1), math.min(endSegm,NumSegs) do segsForRebuild[#segsForRebuild + 1] = i end RebuildTries=Num+1 RebuildTries=RebuildTries-1 while Cnt<=RebuildTries do selection.DeselectAll() for i=1, #segsForRebuild do selection.Select(segsForRebuild[i]) end for i=1,10 do if current.GetEnergyScore()-sc<0.05 and sc-current.GetEnergyScore()<0.05 then structure.RebuildSelected(i) end end if current.GetEnergyScore()-sc>0.05 or sc-current.GetEnergyScore()>0.05 then structure.MutateSidechainsAll(1) structure.WiggleAll(20) structure.ShakeSidechainsAll(1) structure.WiggleSelected(15) structure.WiggleAll(15) if Clashing<1 then behavior.SetClashImportance(Clashing) structure.WiggleAll(4) behavior.SetClashImportance(1) structure.MutateSidechainsAll(1) structure.WiggleAll(15) structure.ShakeSidechainsAll(1) structure.WiggleAll(10) end end str=Cnt .." Try " .. ", " .. segsForRebuild[1] .. "-" .. segsForRebuild[#segsForRebuild] .. ", score: " .. current.GetEnergyScore() if current.GetEnergyScore()-sc > 0.0001 then str = str .. ", +" .. current.GetEnergyScore()-sc end print(str) Cnt = Cnt + 1 recentbest.Restore() sc=current.GetEnergyScore() end after_Solution(rnd,str_name) end function sidechain_flip_all() if ItsCheckTime() then before_Solution(rnd,str_name) end -- local function sidechain_flip(Seg) local SnapCnt=rotamer.GetCount(Seg) for i=1, SnapCnt do rotamer.SetRotamer(Seg,i) end end local sc=current.GetEnergyScore() for j=1, structure.GetCount() do recentbest.Save() sc=current.GetEnergyScore() if rotamer.GetCount(j)>2 then sidechain_flip(j) end recentbest.Restore() print(j .. "/" .. structure.GetCount() .. " (" .. rotamer.GetCount(j) .. "), score: " .. current.GetEnergyScore() .. ", gain: " .. current.GetEnergyScore()-sc) end after_Solution(rnd,str_name) end function p_Time(startTime,ScoreGain) local ss=(os.time()-startTime)*60 local mm=(((os.time()-startTime-ss)*3600)/60) local hh=(os.time()-startTime-mm*60-ss)/3600 print("Time: "..hh..":"..mm..":"..ss..". ".."Score: "..current.GetEnergyScore()..", Total: +"..ScoreGain) end --------------------------------------------------------------- --------------------- MAIN PROGRAM ------------------- --------------------------------------------------------------- recentbest.Save() startScore=current.GetEnergyScore() startTime=os.time() math.randomseed(startTime) local ask = dialog.CreateDialog("All in One.") ask.LabelRow000 = dialog.AddLabel("Please choose the script to run:") ask.LabelRow001 = dialog.AddLabel("1. BlueFuze.") ask.LabelRow002 = dialog.AddLabel("2. Clashing.") ask.LabelRow003 = dialog.AddLabel("3. FastRelax.") ask.LabelRow004 = dialog.AddLabel("4. WS or SW.") ask.LabelRow005 = dialog.AddLabel("5. Band Test.") ask.LabelRow006 = dialog.AddLabel("6. Local Wiggle.") ask.LabelRow007 = dialog.AddLabel("7. Local Rebuild.") ask.LabelRow008 = dialog.AddLabel("8. Rebuild Worst.") ask.LabelRow009 = dialog.AddLabel("9. Quake.") ask.LabelRow010 = dialog.AddLabel("10. Sidechain Test.") ask.LabelRow011 = dialog.AddLabel("11. Mutate.") ask.LabelRow012 = dialog.AddLabel("12. Mutate and Test.") ask.LabelRow013 = dialog.AddLabel("13. New Mutate.") ask.LabelRow014 = dialog.AddLabel("14. Rebuilder.") ask.LabelRow015 = dialog.AddLabel("15. Sidechain Flipper.") ask.LabelRow016 = dialog.AddLabel("16. SoftRelax.") ask.LabelRow017 = dialog.AddLabel("17. Autobot.") ask.Script = dialog.AddSlider("Function to run:", 17, 1, 17, 0) ask.save_resolution = dialog.AddSlider("Save after gain > ", 1000, 0.3, 1000, 1) -- from isaksson share ask.save_Name = dialog.AddTextbox("Name2share", rnd) ask.OK = dialog.AddButton("OK", 1) ask.Cancel = dialog.AddButton("Cancel", 0) ask.About = dialog.AddButton("About", 2) DialogResult = dialog.Show(ask) ScriptNumber = ask.Script.value save_resolution=ask.save_resolution.value -- from isaksson share if save_resolution < 1000 then print("Checking for solution every "..userTimeInterval.." seconds") end rnd=ask.save_Name.value if (DialogResult == 1) then if (ScriptNumber == 1) then print("Start score: "..startScore) recipe.SectionStart("BlueFuze") BlueFuze() p_Time(startTime,recipe.SectionEnd()-startScore) elseif (ScriptNumber == 2) then ScriptAsk = dialog.CreateDialog("Script Dialog. Clashing.") ScriptAsk.Repeat = dialog.AddCheckbox("Repeat when gain score", false) ScriptAsk.OK = dialog.AddButton("OK", 1) ScriptAsk.Cancel = dialog.AddButton("Cancel", 0) ScriptDialogResult = dialog.Show(ScriptAsk) if ScriptAsk.Repeat.value==true then Repeat=1 else Repeat=0 end print("Start score: "..startScore) recipe.SectionStart("Clashing") clashing(Repeat) p_Time(startTime,recipe.SectionEnd()-startScore) elseif (ScriptNumber == 3) then print("Start score: "..startScore) recipe.SectionStart("FastRelax") FastRelaxFull() p_Time(startTime,recipe.SectionEnd()-startScore) elseif (ScriptNumber == 4) then params = { 1, -- WS 1, -- SW 1, -- WS_0.5 1 -- WS Step } print("Start score: "..startScore) recipe.SectionStart("WS or SW") ws_or_sw(params) p_Time(startTime,recipe.SectionEnd()-startScore) elseif (ScriptNumber == 5) then ScriptAsk = dialog.CreateDialog("Script Dialog. Band Test.") ScriptAsk.Start_LengthP = dialog.AddSlider("Start Length (percents):", 90, 10, 300, 0) ScriptAsk.End_LengthP = dialog.AddSlider("Start Length (percents):", 110, 10, 300, 0) ScriptAsk.Clashing = dialog.AddSlider("Clashing", 0.5, 0, 1, 1) ScriptAsk.OK = dialog.AddButton("OK", 1) ScriptAsk.Cancel = dialog.AddButton("Cancel", 0) ScriptDialogResult = dialog.Show(ScriptAsk) Start_LengthP=ScriptAsk.Start_LengthP.value End_LengthP=ScriptAsk.End_LengthP.value Clashing=ScriptAsk.Clashing.value print("Start score: "..startScore) Iteration = 1 while Iteration>0 do Band_tests(Start_LengthP,End_LengthP,Clashing,Iteration,0) Iteration = Iteration + 1 end elseif (ScriptNumber == 6) then ScriptAsk = dialog.CreateDialog("Script Dialog. Local Wiggle.") ScriptAsk.Length = dialog.AddSlider("Segment Length", 7, 1, structure.GetCount()/2, 0) ScriptAsk.Wig_Num = dialog.AddSlider("Number of Wiggles", 2, 1, 30, 0) ScriptAsk.TotalWiggle = dialog.AddCheckbox("Total wiggle", false) ScriptAsk.OK = dialog.AddButton("OK", 1) ScriptAsk.Cancel = dialog.AddButton("Cancel", 0) ScriptDialogResult = dialog.Show(ScriptAsk) Length=ScriptAsk.Length.value Wig_Num=ScriptAsk.Wig_Num.value TotalWiggle=ScriptAsk.TotalWiggle.value print("Start score: "..startScore) recipe.SectionStart("Local Wiggle") if TotalWiggle then Length=15 for i=Length,1,-1 do local_wiggle(i,Wig_Num) end else local_wiggle(Length,Wig_Num) end p_Time(startTime,recipe.SectionEnd()-startScore) elseif (ScriptNumber == 7) then ScriptAsk = dialog.CreateDialog("Script Dialog. Local Rebuild.") ScriptAsk.Length = dialog.AddSlider("Segment Length", 3, 1, structure.GetCount()/2, 0) ScriptAsk.Clashing = dialog.AddSlider("Clashing", 0.6, 0, 1, 1) ScriptAsk.OK = dialog.AddButton("OK", 1) ScriptAsk.Cancel = dialog.AddButton("Cancel", 0) ScriptDialogResult = dialog.Show(ScriptAsk) Length=ScriptAsk.Length.value Clashing=ScriptAsk.Clashing.value print("Start score: "..startScore) recipe.SectionStart("Local Rebuild") local_rebuild_all(Length,Clashing) p_Time(startTime,recipe.SectionEnd()-startScore) elseif (ScriptNumber == 8) then ScriptAsk = dialog.CreateDialog("Script Dialog. Rebuild Worst.") ScriptAsk.Length = dialog.AddSlider("Segment Length", 1, 1, structure.GetCount()/2, 0) ScriptAsk.Clashing = dialog.AddSlider("Clashing", 0.6, 0, 1, 1) ScriptAsk.Rebuilds = dialog.AddSlider("Rebuild tries", 3, 1, 100, 0) ScriptAsk.OK = dialog.AddButton("OK", 1) ScriptAsk.Cancel = dialog.AddButton("Cancel", 0) ScriptDialogResult = dialog.Show(ScriptAsk) Length=ScriptAsk.Length.value Clashing=ScriptAsk.Clashing.value RebuildsTries=ScriptAsk.Rebuilds.value print("Start score: "..startScore) recipe.SectionStart("Rebuild Worst") RebuildWorst(Length,RebuildsTries,Clashing,100) p_Time(startTime,recipe.SectionEnd()-startScore) elseif (ScriptNumber == 9) then ScriptAsk = dialog.CreateDialog("Script Dialog. Quake.") ScriptAsk.Length = dialog.AddSlider("Segment Length", 15, 1, structure.GetCount()/2, 0) ScriptAsk.Clashing = dialog.AddSlider("Clashing", 0.6, 0, 1, 1) ScriptAsk.Shake = dialog.AddSlider("Shake", 1, 0, 2, 0) ScriptAsk.ScoreDelta = dialog.AddSlider("ScoreDelta", 15, 0, 200, 1) ScriptAsk.OK = dialog.AddButton("OK", 1) ScriptAsk.Cancel = dialog.AddButton("Cancel", 0) ScriptDialogResult = dialog.Show(ScriptAsk) Length=ScriptAsk.Length.value Clashing=ScriptAsk.Clashing.value Shake=ScriptAsk.Shake.value ScoreDelta=ScriptAsk.ScoreDelta.value print("Start score: "..startScore) recipe.SectionStart("Quake") quake(Length,ScoreDelta,Shake,Clashing) p_Time(startTime,recipe.SectionEnd()-startScore) elseif (ScriptNumber == 10) then print("Start score: "..startScore) recipe.SectionStart("Sidechain Test") sidechain_test_all() p_Time(startTime,recipe.SectionEnd()-startScore) elseif (ScriptNumber == 11) then Shake_Type = 2 -- 1: Shake, 2: Mutate Shake_times = 1 -- Number of shake times print("Start score: "..startScore) recipe.SectionStart("Mutate") mutate(Shake_Type,Shake_times) p_Time(startTime,recipe.SectionEnd()-startScore) elseif (ScriptNumber == 12) then ScriptAsk = dialog.CreateDialog("Script Dialog. Mutate and Test.") ScriptAsk.RunFunction = dialog.AddSlider("Function to run:", 3, 1, 3, 0) ScriptAsk.OK = dialog.AddButton("OK", 1) ScriptAsk.Cancel = dialog.AddButton("Cancel", 0) ScriptDialogResult = dialog.Show(ScriptAsk) RunFunction=ScriptAsk.RunFunction.value print("Start score: "..startScore) recipe.SectionStart("Mutate and Test") Mutate_And_Test(RunFunction,10000) p_Time(startTime,recipe.SectionEnd()-startScore) elseif (ScriptNumber == 13) then print("Start score: "..startScore) recipe.SectionStart("New Mutate") new_mutate_all() p_Time(startTime,recipe.SectionEnd()-startScore) elseif (ScriptNumber == 14) then ScriptAsk = dialog.CreateDialog("Script Dialog. Rebuilder.") ScriptAsk.startSegm = dialog.AddSlider("Start segment", 1, 1, structure.GetCount()-1, 0) ScriptAsk.endSegm = dialog.AddSlider("End segment", 2, 2, structure.GetCount(), 0) ScriptAsk.Clashing = dialog.AddSlider("Clashing", 0.6, 0, 1, 1) ScriptAsk.OK = dialog.AddButton("OK", 1) ScriptAsk.Cancel = dialog.AddButton("Cancel", 0) ScriptDialogResult = dialog.Show(ScriptAsk) startSegm=ScriptAsk.startSegm.value endSegm=ScriptAsk.endSegm.value Clashing=ScriptAsk.Clashing.value if startSegm>endSegm then print("Start segment should be no more than End segment") else print("Start score: "..startScore) rebuilder(startSegm,endSegm,Clashing,10000) p_Time(startTime,recipe.SectionEnd()-startScore) end elseif (ScriptNumber == 15) then print("Start score: "..startScore) recipe.SectionStart("Sidechain Flipper") sidechain_flip_all() p_Time(startTime,recipe.SectionEnd()-startScore) elseif (ScriptNumber == 16) then print("Start score: "..startScore) recipe.SectionStart("SoftRelax") SoftRelaxFull() p_Time(startTime,recipe.SectionEnd()-startScore) elseif (ScriptNumber == 17) then ScriptAsk = dialog.CreateDialog("Script Dialog. Autobot.") ScriptAsk.RestartGain = dialog.AddSlider("Score threshold:", 0, 0, 100, 1) ScriptAsk.Sequence = dialog.AddTextbox("Sequence:", CL.FR.BT_10_87_97.MT_3_20.BT_10_103_113.NM.RW_2_1_10.MT_3_20.QU_15.BF.RW_1_1_10.LW_12_2.SR.") ScriptAsk.OK = dialog.AddButton("OK", 1) ScriptAsk.Cancel = dialog.AddButton("Cancel", 0) ScriptDialogResult = dialog.Show(ScriptAsk) RestartGain=ScriptAsk.RestartGain.value SequenceStr = ScriptAsk.Sequence.value local Sequence = {} local i=0 for Script in string.gmatch(SequenceStr, "[%w_]+%.") do i=i+1 Sequence[i] = {} Sequence[i][1] = string.sub(Script,1,2) local j=1 for ScriptParam in string.gmatch(string.sub(Script,4), "%w+[_%.]") do j=j+1 Sequence[i][j] = string.sub(ScriptParam,1,string.len(ScriptParam)-1) end end print("The Sequence.") for i=1,#Sequence do if Sequence[i][1] == "CL" then print(i..": Clashing") elseif Sequence[i][1] == "FR" then print(i..": FastRelax") elseif Sequence[i][1] == "BF" then print(i..": BlueFuze") elseif Sequence[i][1] == "WS" then print(i..": WS or SW") elseif Sequence[i][1] == "BT" then print(i..": Band Test,"..Sequence[i][2]..","..Sequence[i][3]..","..Sequence[i][4]) elseif Sequence[i][1] == "LW" then print(i..": Local Wiggle,"..Sequence[i][2]..","..Sequence[i][3]) elseif Sequence[i][1] == "LR" then print(i..": Local Rebuild,"..Sequence[i][2]..","..Sequence[i][3]) elseif Sequence[i][1] == "QU" then print(i..": Quake,"..Sequence[i][2]) elseif Sequence[i][1] == "ST" then print(i..": Sidechain Test,"..Sequence[i][2]) elseif Sequence[i][1] == "MU" then print(i..": Mutate") elseif Sequence[i][1] == "MT" then print(i..": Mutate and Test,"..Sequence[i][2]..","..Sequence[i][3]) elseif Sequence[i][1] == "NM" then print(i..": New Mutate") elseif Sequence[i][1] == "RE" then print(i..": Rebuilder,"..Sequence[i][2]..","..Sequence[i][3]..","..Sequence[i][4]) elseif Sequence[i][1] == "SF" then print(i..": Sidechain Flipper") elseif Sequence[i][1] == "SR" then print(i..": Soft Relax") elseif Sequence[i][1] == "RW" then print(i..": Rebuild Worst,"..Sequence[i][2]..","..Sequence[i][3]..","..Sequence[i][4]) else print(i..": UNKNOWN") end end print("Start score: "..startScore) p_Time(startTime,0) save.Quicksave(1) Iteration=1 while Iteration<100 do print("Start of Iteration: "..Iteration) save.Quickload(1) recentbest.Save() ScoreGain=RestartGain + 1 step=1 while ScoreGain>=RestartGain do startScoreStep=current.GetEnergyScore() startTimeStep=os.time() for i=1,#Sequence do if Sequence[i][1] == "CL" then recipe.SectionStart("Clashing") clashing(0) elseif Sequence[i][1] == "FR" then recipe.SectionStart("FastRelax") FastRelaxFull() elseif Sequence[i][1] == "BF" then recipe.SectionStart("BlueFuze") BlueFuze() elseif Sequence[i][1] == "WS" then recipe.SectionStart("WS or SW") params = {1,1,1,1} ws_or_sw(params) elseif Sequence[i][1] == "BT" then recipe.SectionStart("Band Test") for l=1,Sequence[i][2] do Band_tests(Sequence[i][3],Sequence[i][4],0.5,l,Sequence[i][2]) end elseif Sequence[i][1] == "LW" then recipe.SectionStart("Local Wiggle") local_wiggle(Sequence[i][2],Sequence[i][3]) elseif Sequence[i][1] == "LR" then recipe.SectionStart("Local Rebuild") local_rebuild_all(Sequence[i][2],0.6) elseif Sequence[i][1] == "QU" then recipe.SectionStart("Quake") quake(Sequence[i][2],15,1,0.6) elseif Sequence[i][1] == "ST" then recipe.SectionStart("Sidechain Test") sidechain_shock(Sequence[i][2]) elseif Sequence[i][1] == "MU" then recipe.SectionStart("Mutate") mutate(2,1) elseif Sequence[i][1] == "MT" then recipe.SectionStart("Mutate and Test") Mutate_And_Test(Sequence[i][2],Sequence[i][3]) elseif Sequence[i][1] == "NM" then recipe.SectionStart("New Mutate") new_mutate_all() elseif Sequence[i][1] == "RE" then recipe.SectionStart("Rebuilder") rebuilder(Sequence[i][2],Sequence[i][3],0.6,Sequence[i][4]) elseif Sequence[i][1] == "SF" then recipe.SectionStart("Sidechain Flipper") sidechain_flip_all() elseif Sequence[i][1] == "SR" then recipe.SectionStart("Soft Relax") SoftRelaxFull() elseif Sequence[i][1] == "RW" then recipe.SectionStart("Rebuild Worst") RebuildWorst(Sequence[i][2],Sequence[i][3],0.6,Sequence[i][4]) else recipe.SectionStart("UNKNOWN") print(i..": UNKNOWN") end print("Score: "..current.GetEnergyScore()..", +"..recipe.SectionEnd()) p_Time(startTime,current.GetEnergyScore()-startScore) end print("Iteration: "..Iteration..". Step: "..step) p_Time(startTime,current.GetEnergyScore()-startScore) step=step+1 ScoreGain=current.GetEnergyScore()-startScoreStep end print("End of Iteration: "..Iteration) Iteration=Iteration+1 end end elseif (DialogResult == 2) then ScriptAsk = dialog.CreateDialog("About.") ScriptAsk.NewLabel = dialog.AddLabel("Made by Grom.") ScriptAsk.OK = dialog.AddButton("OK", 1) ScriptDialogResult = dialog.Show(ScriptAsk) end --end

Comments