Profile


Name
TANDEM2
ID
104344
Shared with
Public
Parent
None
Children
None
Created on
January 14, 2021 at 12:02 PM UTC
Updated on
December 30, 2024 at 20:07 PM UTC
Description

CONSTRUCTOR + COMPRESSOR

Best for


Code


--[[ 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' } } -- Base on Local Quake 1.0 by spvinvent with helep by thom -- Bands radiate from a structure (helix, loop or sheet) to spatially close neighbours -- one round with the strcuture frozen one round not -- Foregoes Fuses and generally tries to optimize for speed use_ranked_score = 1 -- if 1, use the score being used for ranking (best normally). If 0, use the -- old style scoring system max_bands_per_residue = 6 -- Increase this for more bands at each segment max_segment_length = 999 -- Don't create bands greater than this length. Set to 999 or something if you're -- not worried about the potential for long bands creeping in, min_exclusion = 999 -- These can be set to establish an "exclusion zone", within which no bands will -- be created. This might be used to prevent banding to a wayward loop. -- If min_exclusion > max_exclusion no exclusion will be set. max_exclusion = 1 target_wiggle_reduction = 150 -- On wiggle, try and reduce the score by this amount after creating the bands. -- If it's wildly out, reduce/increase band strength -- for the next try (don't try to adjust for the current scramble). max_segment_length = 10 -- Don't create bands greater than this length. Set to 999 or something if you're -- not worried about the potential for long bands creeping in, n_quakes = 50000 -- Go crazy band_to_minima = true -- Band to minima or maxima in the distance. See bands_from_segment for meaning. do_second_shake = false -- After creating the bands and pulling with them do a Shake/Wiggle/Shake -- if do_second_shake is false (best I think) don't do the last shake. -- Speeds things up quite a bit scale_band_strength = true -- If true, band strength will be scaled inversely with length monit =false ---------- A few more globals candidate_ids_start = {} candidate_ids_end = {} candidate_distances = {} n_candidates = 0 best_score = 0 function GetScore () if ( use_ranked_score == 1 ) then return get_ranked_score ( true ) else return get_score () end end function Coprime ( n ) if ( n < 31 ) then return 1 elseif ( n >= 31*37 ) then return 1 elseif ( n%31 ~= 0 ) then return 31 else return 37 end end function pseudorandom ( score ) -- Returns a pseudorandom number >= 0 and < 1. -- Based on the fractional part of the score if ( score >= 0 ) then return score % 1 else return (-score ) % 1 end end function delete_all_bands () band_delete () --band_count = get_band_count () -- for i = band_count , 1 , -1 do -- band_delete ( i ) --end end function ShellSort ( ids , distances , n ) -- Adapted from Numerical Recipes in C local inc = 1 repeat inc = inc * 3 + 1 until inc > n repeat inc = inc / 3 inc = inc - inc % 1 for i = inc + 1 , n do v = distances [ i ] w = ids [ i ] j = i flag = false while ( flag == false and distances [ j - inc ] > v ) do distances [ j ] = distances [ j - inc ] ids [ j ] = ids [ j - inc ] j = j - inc if ( j <= inc ) then flag = true end end distances [ j ] = v ids [ j ] = w end until inc <= 1 end function test_for_minimum ( i , seg , seg_distances ) if ( ( i ~= seg ) and ( seg_distances [ i ] <= seg_distances [ i - 1 ] ) and ( seg_distances [ i ] <= seg_distances [ i - 2 ] ) and ( seg_distances [ i ] <= seg_distances [ i + 1 ] ) and ( seg_distances [ i ] <= seg_distances [ i + 2 ] ) ) then return true else return false end end function test_for_maximum ( i , seg , seg_distances ) if ( ( seg_distances [ i ] >= seg_distances [ i - 1 ] ) and ( seg_distances [ i ] >= seg_distances [ i - 2 ] ) and ( seg_distances [ i ] >= seg_distances [ i + 1 ] ) and ( seg_distances [ i ] >= seg_distances [ i + 2 ] ) ) then return true else return false end end function get_band_segment_data ( seg ) seg_distances = {} -- Get the function that looks like this: -- x = residue number -- y = distance of that segment from seg -- ignore the degenerate minimum n_segments = 0 segment_ids = {} segment_distances = {} for i = 1, n_residues do segment_distances [ i ] = get_segment_distance ( seg , i ) end for i = 3 , n_residues - 3 do k = segment_distances [ i ] if ( ( band_to_minima == true ) and ( test_for_minimum ( i , seg , segment_distances ) == true ) ) then n_segments = n_segments + 1 segment_ids [ n_segments ] = i segment_distances [ n_segments ] = segment_distances [ i ] elseif ( ( band_to_minima == false ) and ( test_for_maximum ( i , seg , segment_distances ) == true ) ) then n_segments = n_segments + 1 segment_ids [ n_segments ] = i segment_distances [ n_segments ] = segment_distances [ i ] end end ShellSort ( segment_ids , segment_distances , n_segments ) if ( n_segments >= max_bands_per_residue ) then n_c = max_bands_per_residue else n_c = n_segments end for i = 1 , n_c do if ( ( segment_distances [ i ] <= max_segment_length ) and ( seg < min_exclusion or seg > max_exclusion ) and ( segment_ids [ i ] < min_exclusion or segment_ids [ i ] > max_exclusion ) ) then n_candidates = n_candidates + 1 candidate_ids_start [ n_candidates ] = seg candidate_ids_end [ n_candidates ] = segment_ids [ i ] candidate_distances [ n_candidates ] = segment_distances [ i ] end end end function create_bands () if ( scale_band_strength == true ) then total_band_length = 0 for i = 1 , n_candidates do total_band_length = total_band_length + candidate_distances [ i ] end average_band_length = total_band_length / n_candidates end for i = 1 , n_candidates do band_add_segment_segment ( candidate_ids_start [ i ] , candidate_ids_end [ i ] ) if ( scale_band_strength == true ) then band_set_strength ( i , band_strength * average_band_length / candidate_distances [ i ] ) else band_set_strength ( i , band_strength ) end end end function Quake ( seg ) select_all () do_unfreeze_all() --print(GetScore()) init_score = GetScore () do_global_wiggle_backbone ( 5 ) --print(GetScore()) score_after_wiggle = GetScore () score_reduction_after_wiggle = init_score - score_after_wiggle if ( monit ) then print ( "seg ", seg , " score loss " , score_reduction_after_wiggle ) end -- Adaptively change band strength based on how much the previous wiggle overshot/undershot the target. Could -- be made much more elaborate. if ( score_reduction_after_wiggle > target_wiggle_reduction * 1.2 ) then band_strength = band_strength * ( 0.85 + 0.1 *pseudorandom ( score_after_wiggle ) ) elseif ( score_reduction_after_wiggle < target_wiggle_reduction * 0.8 ) then band_strength = band_strength + ( 1 - band_strength ) * ( 0.05 + 0.1 *pseudorandom ( score_after_wiggle ) ) end if ( monit ) then print ( " band_strength ", band_strength ) end delete_all_bands () do_unfreeze_all() --print(GetScore()) quicksave(1) do_shake ( 1 ) quicksave(2) --print(GetScore()) gas = GetScore () - score_after_wiggle if ( monit ) then print ( " gas ", gas ) end do_unfreeze_all() --print(GetScore()) do_global_wiggle_all ( 10 ) --print(GetScore()) if ( do_second_shake == true ) then score_a2w = GetScore () do_shake ( 1 ) score_a2s = GetScore () if ( score_a2s - score_a2w > 1 ) then do_global_wiggle_all ( 6 ) --print(GetScore()) end end end n_residues = get_segment_count () band_strength = 0.5 set_behavior_clash_importance ( 1 ) reset_recent_best () best_score = GetScore () print ( " init score ", best_score ) idx = 1 gel=1 for i = 1, n_quakes do restore_recent_best () -- Need to record any improvements from the previous iteration score = GetScore() if ( score > best_score ) then best_score = score print ( "Improvement to " , score ) end do_unfreeze_all() delete_all_bands () n_candidates = 0 debut=0 if (idx==1) then debut=1 else if ( get_ss(idx)~=get_ss(idx-1) ) then debut =idx end end if ( debut>0) then while (idx < n_residues+1 and get_ss(idx)==get_ss(debut)) do get_band_segment_data ( idx ) if gel ==1 then deselect_all() select_index(idx) do_freeze(true,false) end -- of gel idx=idx+1 end end select_all() if ( n_candidates > 0 ) then create_bands () print ( "i: " , i , " seg ", debut," " ,idx-1 ) Quake ( idx ) end if idx>n_residues then idx=1 if gel==1 then gel=0 else gel=1 end end end -- to see every line --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 390-394 --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_15_87_97.BT_15_103_113.RW_2_1_10.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 --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 390-394 --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 3x2 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 solution every "..userTimeInterval.." seconds") end --End of Isaksson Share

Comments