Profile


Name
Quickfix 3.6.4
ID
109072
Shared with
Public
Parent
Quickfix 3.6.3
Children
None
Created on
June 12, 2025 at 14:19 PM UTC
Updated on
October 21, 2025 at 13:08 PM UTC
Description

Option to keep freezes and bands, manage slow filters, faster cleanup

Best for


Code


--[[Quickfix 3.6 by spvincent and BK from Quickfix 3.0 by spvincent v 3.1 I just added the option to keep freezes and bands (Bruno Kestemont 29/10/2014) v3.1.1 added filter management v3.1.2 replaces shake selected by quick shake and added notes V3.1.3 change options each loop (for very long run) + added (not used) thresholds per seg for skipping functions at end game internal loops until no gain on soft recipes (no rebuilds) v3.1.4 added experimental hiding shake & wiggle v3.1.5 check if segments are not freezed or locked (will be faster) and added option for all loops v3.1.6 added disjunct and do not revisit (experimental) added a generic idealize function v3.1.7 added save big steps for an undo show at the end added filter management in wiggle sidechains v3.2 Generic filter management v3.2.1: added recentbest save at beginning. Note: change track before running (creditbest is high) 15/4/2015 cleaning and big steps with filters on (experimental) v3.2.2 Ligand bug fixed 19/4/2015 v3.2.3 Fixed quadruplet out of length v3.2.4 Added cutting worst v3.2.5 Fixed sym bug v3.2.6 Hopefully fixed no GENERICFILTER v3.2.7 Added rebuild to solve unideal segments v3.2.8 Fixed: Don't shake or mutate freezed ones when option checked v3.2.9 filter observed on contact puzzles v3.3.0 partly fixed freezed bug (remains on some puzzles see line 444) v3.3.1 fixed KEEPFREEZE bug v3.3.2 fixed KEEPFREEZEALL bug v3.3.3 undo.SetUndo v3.3.4 fixed unideal loop bug v3.3.5 reduces moves for Sketchbook puzzles v3.3.6 smaller stepscores and trying to get track of improvements in undo.SetUndo v3.4 CI can be something else than 1 (idea from vredeman child recipes) Filter loss condition for design puzzles v.3.4.1 refinements in the log and filter management v3.5 added idealize One with rangei, then debugged cuts v3.5.1 displays filtered score (bug disabled score displayed) v3.5.2 SKETCHBOOK hard decision if score not met (to be tested): load old best v3.5.3 small corrections v3.5.4 fixed uncutted segments bug after several loops v3.5.5 filter management for design puzzles v3.5.6 simplified the filter score calculation (should be faster) v3.6 Fixed movie steps, added remix v3.6.1 identify "bonus" in the description as well. Better recognition of filtered puzzles. adapted for old foldit versions v3.6.2 trying to fix remix bug v3.6.3 deleting the DEBUGprints v3.6.4 fast cleanup by Artoria2e5: remember all cuts in a list to clean up faster ]] -- --TO DO: behaviour out of subscores recipename = "Quickfix 3.6.4" undo.SetUndo(false) --START Generic Filter Management by BitSpawn 21/12/2014 --Source: http://fold.it/portal/node/1998917 --identifying filtered puzzles and all properties n_residues = structure.GetCount() segCnt2 = n_residues while structure.GetSecondaryStructure(segCnt2) == "M" do segCnt2 = segCnt2 - 1 end OriginalFilterSetting = behavior.GetSlowFiltersDisabled() HASLIGAND = segCnt2 < n_residues PROBABLEFILTER = false GENERICFILTER = false FILTERMANAGE = false HASMUTABLE = false -- not used IDEALCHECK = false -- not used PROBABLESYM = false SEPSIS = false ELECTRON = false CENTROID = false HOTSPOT = false NEVERWIGGLEALL = true -- wiggle all appears late in the process SKETCHBOOK = false CONDITIONS = false sym = 1 defminppi = 0 -- default OLDFOLDIT = false if filter.GetNames == nil or structure.GetSymCount == nil then OLDFOLDIT = true print("OLD FOLDIT VERSION DETECTED") end Cuts = {} function InsCut(idx) Cuts[idx] = true return structure.InsertCut(idx) end function DelCut(idx) Cuts[idx] = nil return structure.DeleteCut(idx) end function DelAllCuts() for idx, _ in pairs(Cuts) do structure.DeleteCut(idx) end Cuts = {} if not current.AreConditionsMet() then -- it does not always work print("Conditions not met, trying to delete remaining cuts ?") for i = 1, segCnt2 do structure.DeleteCut(i) end end end recentbest.Save() -- most of the time, recentbest is very high when using this recipe after hand folding --there is no way to reset creditebest: you should change track before to use this recipe. function detectfilterandmut() -- new BK 10/10/2013; 13/2/2015 local descrTxt = puzzle.GetDescription() local puzzletitle = puzzle.GetName() if #descrTxt > 0 and (descrTxt:find("Sketchbook") or descrTxt:find("Sketchbook")) then SKETCHBOOK = true end if #puzzletitle > 0 and puzzletitle:find("Sketchbook") then -- new BK 17/6/2013 SKETCHBOOK = true end if #descrTxt > 0 and (descrTxt:find("filter") or descrTxt:find("filters") or descrTxt:find("contact") or descrTxt:find("Contacts") or descrTxt:find("bonus") or (not OLDFOLDIT and filter.GetBonusTotal() ~= nil)) then PROBABLEFILTER = true FILTERMANAGE = true -- default yes during wiggle (will always be activate when scoring) GENERICFILTER = false -- actually not recommended end if #puzzletitle > 0 and (puzzletitle:find("filter") or puzzletitle:find("filters") or puzzletitle:find("Filter") or puzzletitle:find("Filters") or puzzletitle:find("Contacts") or puzzletitle:find("Design") or puzzletitle:find("design")) then PROBABLEFILTER = true FILTERMANAGE = true -- default yes during wiggle (will always be activate when scoring) GENERICFILTER = false -- actually not recommended end if #descrTxt > 0 and (descrTxt:find("design") or descrTxt:find("designs")) then HASMUTABLE = true IDEALCHECK = true PROBABLEFILTER = true FILTERMANAGE = true -- default yes during wiggle (will always be activate when scoring) GENERICFILTER = false -- actually not recommended end if #descrTxt > 0 and (descrTxt:find("De-novo") or descrTxt:find("de-novo") or descrTxt:find("freestyle") or descrTxt:find("prediction") or descrTxt:find("predictions")) then IDEALCHECK = true end if #puzzletitle > 0 then if (puzzletitle:find("Sym") or puzzletitle:find("Symmetry") or puzzletitle:find("Symmetric") or puzzletitle:find("Dimer") or puzzletitle:find("Trimer") or puzzletitle:find("Tetramer") or puzzletitle:find("Pentamer")) then PROBABLESYM = true if puzzletitle:find("Dimer") and not puzzletitle:find("Dimer of Dimers") then sym = 2 elseif puzzletitle:find("Trimer") or puzzletitle:find("Tetramer") then sym = 3 elseif puzzletitle:find("Dimer of Dimers") or puzzletitle:find("Tetramer") then sym = 4 elseif puzzletitle:find("Pentamer") then sym = 5 else sym = 6 end end end if #descrTxt > 0 and (descrTxt:find("Sym") or descrTxt:find("Symmetry") or descrTxt:find("Symmetric") or descrTxt:find("sym") or descrTxt:find("symmetry") or descrTxt:find("symmetric")) then PROBABLESYM = true if (descrTxt:find("Dimer") or descrTxt:find("dimer")) and not (descrTxt:find("Dimer of Dimers") or descrTxt:find("dimer of dimers")) then sym = 2 elseif descrTxt:find("Trimer") or descrTxt:find("trimer") then sym = 3 elseif (descrTxt:find("Dimer of Dimers") or descrTxt:find("Tetramer")) and not (descrTxt:find("dimer of dimers") or descrTxt:find("tetramer")) then sym = 4 elseif descrTxt:find("Pentamer") or descrTxt:find("pentamer") then sym = 5 end end --print resulting sym info if PROBABLESYM then print("Symmetric") if sym == 2 then print("Dimer") elseif sym == 3 then print("Trimer") elseif sym == 4 then print("Tetramer") elseif sym == 5 then print("Pentamer") elseif sym > 5 then print("Terrible polymer") end else print("Monomer") end if #puzzletitle > 0 and puzzletitle:find("Sepsis") then -- new BK 17/6/2013 SEPSIS = true --p(true,"-Sepsis") print("Sepsis") end if #puzzletitle > 0 and puzzletitle:find("Electron Density") then -- for Electron Density --p(true,"-Electron Density") ELECTRON = true print("Electron density") end if #puzzletitle > 0 and puzzletitle:find("Centroid") then -- New BK 20/10/2013 --p(true,"-Centroid") CENTROID = true print("Centroid") end if #puzzletitle > 0 and puzzletitle:find("Hotspot") then -- New BK 21/01/2014 HOTSPOT = true print("Hotspot") end return end detectfilterandmut() -- function to copy class/table function CopyTable(orig) local copy = {} for orig_key, orig_value in pairs(orig) do copy[orig_key] = orig_value end return copy end -- functions for filters function FiltersOn() if behavior.GetSlowFiltersDisabled() then behavior.SetSlowFiltersDisabled(false) end end function FiltersOff() if behavior.GetSlowFiltersDisabled() == false then behavior.SetSlowFiltersDisabled(true) end end -- function to overload a funtion function mutFunction(func) local currentfunc = func local function mutate(func, newfunc) local lastfunc = currentfunc currentfunc = function(...) return newfunc(lastfunc, ...) end end local wrapper = function(...) return currentfunc(...) end return wrapper, mutate end -- function to overload a class -- to do: set the name of function classes_copied = 0 myclcp = {} function MutClass(cl, filters) classes_copied = classes_copied + 1 myclcp[classes_copied] = CopyTable(cl) local mycl = myclcp[classes_copied] for orig_key, orig_value in pairs(cl) do myfunc, mutate = mutFunction(mycl[orig_key]) if filters == true then mutate(myfunc, function(...) FiltersOn() if table.getn(arg) > 1 then -- first arg is self (function pointer), we pack from second argument local arguments = {} for i = 2, table.getn(arg) do arguments[i - 1] = arg[i] end return mycl[orig_key](unpack(arguments)) else --print("No arguments") return mycl[orig_key]() end end) cl[orig_key] = myfunc else mutate(myfunc, function(...) FiltersOff() if table.getn(arg) > 1 then local arguments = {} for i = 2, table.getn(arg) do arguments[i - 1] = arg[i] end return mycl[orig_key](unpack(arguments)) -- BUG here index out of bond ?? else return mycl[orig_key]() end end) cl[orig_key] = myfunc end end end -- how to use: --setting default options if filters BK 4/2/2015 --MutClass(structure, false) --MutClass(band, false) --MutClass(current, true) --STOP Generic Filter Management -- Constants defIters = 1 -- number of iterations for wiggles etc kWiggleBackbonePairsThreshold = -2000 kIdealityTripletsThreshold_a = -100 kIdealityTripletsThreshold_b = -30 kIdealityQuadripletsThreshold_a = 100 -- min gain on 3 rounds rebuilds kIdealityQuadripletsThreshold_b = 50 kIdealityPairsThreshold_a = -20 -- New kWiggleBackboneTripletsThreshold = 200 kWiggleBackboneQuadrupletsThreshold = 100 kRebuildQuadrupletsThreshold_a = 100 -- min gain on 3 rounds rebuilds kRebuildQuadrupletsThreshold_b = 50 kRemixBackboneQuadrupletsThreshold_a = 100 -- min gain on rounds remix kRemixBackboneQuadrupletsThreshold_b = 50 kMaxRemixSlots_a = 5 kMaxRemixSlots_b = 50 kNWorstClashesPt1 = 10 -- not used here, random number of worst ckash used instead kShakeDistanceThreshold = 12 kLoopRepeatThreshold = 10 -- we will not run rebuild until the soft ones are finished NEW maxfiltercost = 10 -- default recommended on begin game, it's less than a small core loss (no core or loop ideality loss would be accepted) FormerBonus = -99999 KEEPBANDS = false KEEPFREEZE = false -- keep backbone freezes only KEEPFREEZEALL = false -- keep current freezes ALLLOOP = false -- all loops during rebuild NOTIDEAL = false --Not used --because what is important is not the mean but individual excesses kTotalBackboneThresholdPerSeg = 2 -- if greater, we skip this function (To be fine tuned) kTotalIdealityThresholdPerSeg = -.5 -- if greater, we skip this function (To be fine tuned) kTotalClashThresholdPerSeg = -1 -- if greater, we skip this function (To be fine tuned) kTotalAllThresholdPerSeg = 23 -- if greater, we are end game and we use Global thresholds to gain time GLOBALTHRESHOLDS = false --end not used -- Globals leave_sheet_backbones_alone = false leave_helix_backbones_alone = false score = 0 best_score = 0 residue_scores = {} backbone_scores = {} ideality_scores = {} clashing_scores = {} sequence_scores = {} ids = {} secondary_structures = {} hiding_scores = {} mutate_not_shake = false -- Quicksave slots kOriginalStructureOrNewBest = 3 -- the starting structure, or any subsequent improvement, will be stored in this quicksave slot kbestremixslot1 = 13 -- the best remix slot (temp) quicksave_start_remix = 14 -- the starting remix slot (temp) quicksave_max_remix = 84 SlotStepStart = 85 -- I must let enough place for the remixes, limited to 100 MaxRemixSlots = kMaxRemixSlots_a -- quicksave_max_remix-quicksave_start_remix-1 -- could be in an option, max 80 I think function r3(i) -- printing convenience return i - i % 0.001 end CIfactor = 1 function CI(CInr) behavior.SetClashImportance(CInr * CIfactor) end function CheckCI() local ask = dialog.CreateDialog("Clash importance reset to 1") ask.l1 = dialog.AddLabel("Last change to change it") ask.l2 = dialog.AddLabel("CI settings will be multiplied by set CI") ask.continue = dialog.AddButton("Continue", 1) dialog.Show(ask) end if behavior.GetClashImportance() < 0.98 then CI(1) CheckCI() end -- default = 1 it's rare we want something else CIfactor = behavior.GetClashImportance() function down(x) return x - x % 1 end function IsPuzzleMutable() for i = 1, n_residues do if (structure.IsMutable(i)) then return true end end return false end function Score() --return score, exploration too if energy == true then return current.GetEnergyScore() else return current.GetScore() end end function GetScore() score = current.GetEnergyScore() if (score < -999998) then score = 8000 for i = 1, n_residues do score = score + current.GetSegmentEnergyScore(i) end end return score end function GetScores() -- of the residues for i = 1, n_residues do residue_scores[i] = current.GetSegmentEnergyScore(i) end end function CheckFilter(maxfiltercost) local maxfiltercost = maxfiltercost or 999 local Bonus = -999998 if maxfiltercost > 998 then return true end -- to save time of checking filters if OLDFOLDIT then local OriginalFilterSetting = behavior.GetSlowFiltersDisabled() behavior.SetSlowFiltersDisabled(false) -- enabling local scoreOn = Score() -- normal with filters enabled behavior.SetSlowFiltersDisabled(true) -- disabling local scoreOff = Score() -- without the filters Bonus = scoreOn - scoreOff behavior.SetSlowFiltersDisabled(OriginalFilterSetting) else Bonus = filter.GetBonusTotal() --Total bonus score of the filters end BonusCost = FormerBonus - Bonus if BonusCost > maxfiltercost then print("Filter loss > ", maxfiltercost, " rejecting this solution") return false else FormerBonus = Bonus -- global return true end end if PROBABLEFILTER then local temp = CheckFilter(maxfiltercost) -- to inititlize the starting bonus (FormerBonus) end function ShellSort(ids, sequence_scores, n) -- BUG 444 on some puzzles here -- Adapted from Numerical Recipes in C local inc = 1 repeat inc = inc * 3 + 1 -- inc = 4, 13, 40, 121, 364 until inc > n repeat inc = inc / 3 -- inc= 121.3333 inc = inc - inc % 1 -- inc= 121 for i = inc + 1, n do -- for i= 122 to 199 v = sequence_scores[i] w = ids[i] j = i flag = false while (flag == false and sequence_scores[j - inc] > v) do -- BUG 444 on some puzzles here sequence_scores[j] = sequence_scores[j - inc] ids[j] = ids[j - inc] j = j - inc if (j <= inc) then flag = true end end sequence_scores[j] = v ids[j] = w end until inc <= 1 end function rebuild(start_idx, end_idx) selection.DeselectAll() selection.SelectRange(start_idx, end_idx) if ALLLOOP then structure.SetSecondaryStructureSelected("L") end -- Rebuild structure.RebuildSelected(1) recentbest.Save() structure.RebuildSelected(3) recentbest.Restore() -- Wiggle sidechains selection.DeselectAll() mid_x = (start_idx + end_idx) / 2 for i = 1, n_residues do d = structure.GetDistance(i, mid_x) if (d < kShakeDistanceThreshold) then selection.Select(i) end end structure.WiggleAll(defIters, false, true) -- sidechains -- Wiggle recentbest.Save() selection.DeselectAll() selection.SelectRange(start_idx, end_idx) structure.LocalWiggleSelected(12) recentbest.Restore() if ALLLOOP then save.LoadSecondaryStructure() end end function IsSequenceValid(start_idx, end_idx) n_illegitimate_residues = 0 for i = start_idx, end_idx do if (((secondary_structures[i] == "E") and (leave_sheet_backbones_alone == true)) or ((secondary_structures[i] == "H") and (leave_helix_backbones_alone == true))) or freeze.IsFrozen(i) or structure.IsLocked(i) or CheckDone(start_idx, end_idx) then -- new 30/11/2014 n_illegitimate_residues = n_illegitimate_residues + 1 end end if (n_illegitimate_residues <= 1) then return true else return false end end function GetSequenceScores(input_scores, length, respect_ss_restrictions) -- gives the ids where to work idx = 0 for i = 1, n_residues - length + 1 do if ((respect_ss_restrictions == false) or (IsSequenceValid(i, i + length - 1))) then idx = idx + 1 total_scores = 0 for j = i, i + length - 1 do total_scores = total_scores + input_scores[j] end sequence_scores[idx] = total_scores ids[idx] = i end end ShellSort(ids, sequence_scores, idx) end function record_improvement(ChckZone, from, to) local ChckZone = ChckZone or false local from = from or 1 local to = to or segCnt2 local FILTEROK = true -- new for filter test if PROBABLEFILTER and not GENERICFILTER then FILTEROK = CheckFilter(maxfiltercost) end if (score > best_score + defminppi) and FILTEROK and not (CONDITIONS and not current.AreConditionsMet()) then undo.SetUndo(true) -- keep track of it ! gain = score - best_score best_score = score save.LoadSecondaryStructure() save.Quicksave(kOriginalStructureOrNewBest) if gain > 0.00099 then print(" Improvement to " .. r3(score)) end WhriteNote(loop_nb) -- new 9/11/2014 undo.SetUndo(false) else gain = 0 if disjunct and ChckZone then -- new 30/11/2014 AddDone(from, to) ChkDoneList() end if SKETCHBOOK then save.Quickload(kOriginalStructureOrNewBest) -- TO BE VERIFIED end end return gain end --START Archive in Notes, -- New 4/11/2014 function SelectNote(recipename) store = {} store.label = recipename or "" -- edit here the recipe name store.note_number = structure.GetCount() for seg = structure.GetCount(), 1, -1 do if structure.GetNote(seg) ~= "" then break end store.note_number = seg end print(string.format("Recording results in Note for segment %i", store.note_number)) store.starting_score = current.GetScore() --structure.SetNote(store.note_number,string.format("(%s) %.3f + FSP",user.GetPlayerName(),store.starting_score)) end SelectNote(recipename) loop_nb = 1 -- init global function WhriteNote(loop_nb) -- all inits are in SelectNote function local loop_count = loop_nb or 1 structure.SetNote(store.note_number, string.format("(%s) %.3f + %s (%i) %.3f", user.GetPlayerName(), store.starting_score, store.label, loop_count, current.GetScore())) end --END Archive in Notes --START quick shake algorithm function QuickShake(iter) local iter = iter or defIters --[[------------------------------------------------------------------------------------------------ -- Algorithm for faster shake REFERENCES 1. N/A Copyright (C) 2014 Seagat2011 <http://fold.it/port/user/1992490> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. $Id$ ------------------------------------------------------------------------------------------------]] -- --[[ v1 - Inception 1.2 - Loops until nogain ]] -- local idx = 1 local idx2 = structure.GetCount() local hash = {} local cs = current.GetScore() --print ( 'Quick Shake Algorithm v1.2 SG2011 - Current Score: '..cs ) local function New(obj) return obj -- pass-new-obj-by-value end local _gses = New(current.GetSegmentEnergySubscore) local function SmartShake(iters) local gain = true while (gain) do gain = false for i = idx, idx2 do local ci = _gses(i, 'clashing') if ci < _gses(i, 'hiding') and ci < _gses(i, 'packing') and ci < _gses(i, 'ideality') and ci < _gses(i, 'sidechain') and ci < _gses(i, 'bonding') and ci < _gses(i, 'other') and ci < _gses(i, 'reference') then selection.Select(i) end -- test ci -- end -- loop -- if selection.GetCount() then local css = current.GetScore() structure.ShakeSidechainsSelected(iters) selection.DeselectAll() if current.GetScore() > css then gain = true end -- test -- end -- test -- end -- loopf -- end structure.SmartShake = SmartShake structure.SmartShake(iter) --print ( 'Done.' ) end --END quick shake algorithm -- START part to administrate what has been done By TvdL (copied 20/11/2014) Donepart = {} --To find fast if to be skipped Blocked = {} --A simple list so we can clear Donepart Disj = {} --To administrate which segments have be touched disjunct = true donotrevisit = true clrdonelistgain = structure.GetCount() curclrscore = Score() function AddDone(first, last) if donotrevisit then Donepart[first + (last - first) * segCnt2] = true Blocked[#Blocked + 1] = first + (last - first) * segCnt2 end if disjunct then for i = first, last do Disj[i] = true end end end function CheckDone(first, last) if not donotrevisit then return false end local result = Donepart[first + (last - first) * segCnt2] if disjunct then for i = first, last do if Disj[i] then result = true end end end return result end function ChkDisjunctList(n) if not disjunct then return end local maxlen = 0 for i = 1, segCnt2 do if Disj[i] then maxlen = 0 else maxlen = maxlen + 1 end if maxlen == n then return end end -- No part is big enough so clear Disjunctlist print("Clearing disjunct list") for i = 1, segCnt2 do Disj[i] = false end end function ClearDoneList() --clear donelist for i = 1, #Blocked do Donepart[Blocked[i]] = false end if disjunct then print("Clearing disjunct list") --clear disjunctlist also for i = 1, segCnt2 do Disj[i] = false end end Blocked = {} curclrscore = Score() end function ChkDoneList() if not donotrevisit and not disjunct then return end if Score() > curclrscore + clrdonelistgain then if donotrevisit then ClearDoneList() end end end --END of administration part already done function IsOK(seg) if (freeze.IsFrozen(seg) and not KEEPFREEZE) or structure.IsLocked(seg) then return false else return true end end function Do_Remix(start_idx, end_idx) recentbest.Save() save.Quicksave(kbestremixslot1) CutScoreBeforeRemix = GetScore() bestremixscore = CutScoreBeforeRemix - 800000 -- threshold to be adapted --local replacement = true -- was 'local replacements = true' selection.DeselectAll() selection.SelectRange(start_idx, end_idx) local rmx_found = structure.RemixSelected(quicksave_start_remix, MaxRemixSlots) --get remixes if rmx_found == nil then print("remix found is nil DEBUG") end if rmx_found > 0 then print(rmx_found .. " remixes found") -- DEBUG --for i = 0, rmx_found - 1 do --iterate thru returned remixes for i = 0, rmx_found - 1 do --iterate thru returned remixes save.Quickload(quicksave_start_remix + i) --load next remix curr_score = GetScore() --no threshold value here ??? --------------------------------------------------------------------------------------- if curr_score > bestremixscore then -- local best only for this remix attempt bestremixscore = curr_score save.Quicksave(kbestremixslot1) --this is saved with cuts in !!! end end -- ================================================================================ save.Quickload(kbestremixslot1) -- take the best attempt for this zone curr_score = GetScore() if curr_score ~= CutScoreBeforeRemix then behavior.SetClashImportance(0.05) structure.ShakeSidechainsSelected(1) behavior.SetClashImportance(1) QuickShake(1) end end selection.DeselectAll() end function ShakeSidechains(n) -- Shake or Mutate the n worst-clashing sidechains local ids = {} local clashing_scores = {} local countOK = 0 n = math.min(n, n_residues) if (n == n_residues and not KEEPFREEZEALL) then -- selection.SelectAll() else for i = 1, n_residues do -- we got a smaller list if KEEPFREEZE (backbones) if IsOK(i) then countOK = countOK + 1 clashing_scores[#clashing_scores + 1] = current.GetSegmentEnergySubscore(i, "clashing") ids[#ids + 1] = countOK end end ShellSort(ids, clashing_scores, #ids) -- BUG 444 on some puzzles here selection.DeselectAll() n = math.min(n, #ids) for i = 1, n do selection.Select(ids[i]) end end if (mutate_not_shake == true and n < 11) then -- I don't like the idea of mutating all in a recipe print("mu") structure.MutateSidechainsSelected(defIters) else print("sh") --QuickShake(1) structure.ShakeSidechainsSelected(defIters) end score = GetScore() tempgain = record_improvement() -- tempgain has no use actually end function WiggleSimple(val, how) -- with filter management local val = val or defIters -- new 01/09/2014 local how = how or "wa" if FILTERMANAGE then behavior.SetSlowFiltersDisabled(true) end -- new BK 8/4/2013, always disable filter here if how == "s" then ds(defIters) elseif how == "wb" then structure.WiggleSelected(val, true, false) -- backbones elseif how == "ws" then structure.WiggleSelected(val, false, true) -- sidechains print("ws") elseif how == "wa" then structure.WiggleSelected(val, true, true) -- all elseif how == "lw" then structure.LocalWiggleSelected(val) -- new end if FILTERMANAGE then behavior.SetSlowFiltersDisabled(OriginalFilterSetting) end -- new BK 8/4/2013, always back to user settings end function WiggleSidechains() print("ws") save.Quickload(kOriginalStructureOrNewBest) if FILTERMANAGE then behavior.SetSlowFiltersDisabled(true) end -- new BK 8/4/2013, always disable filter here if not KEEPFREEZEALL then selection.SelectAll() structure.WiggleAll(defIters, false, true) -- sidechains else selection.DeselectAll() for i = 1, n_residues do if IsOK(i) then selection.Select(i) end end WiggleSimple(defIters, "ws") -- note= wiggle selected sidechains instead end if FILTERMANAGE then behavior.SetSlowFiltersDisabled(OriginalFilterSetting) end -- new BK 8/4/2013, always back to user settings selection.DeselectAll() score = GetScore() tempgain = record_improvement() end function WiggleBackbonePairs() -- Look for consecutive segments each of whose backbone score is less than kWiggleBackbonePairsThreshold. -- Default value is such that this will address mostly cutpoint closure issues. save.Quickload(kOriginalStructureOrNewBest) for i = 1, n_residues do backbone_scores[i] = current.GetSegmentEnergySubscore(i, "backbone") end GetSequenceScores(backbone_scores, 2, false) for i = 1, n_residues - 1 do if (sequence_scores[i] < kWiggleBackbonePairsThreshold) then save.Quickload(kOriginalStructureOrNewBest) selection.DeselectAll() selection.SelectRange(ids[i], ids[i] + 1) print("lw " .. i - 1 .. "-" .. i) WiggleSimple(2, "lw") --structure.LocalWiggleSelected ( 2 ) score = GetScore() tempgain = record_improvement() end end end function IdealizeBackboneTriplets(threshold) -- Correct really bad Idealities for i = 1, n_residues do ideality_scores[i] = current.GetSegmentEnergySubscore(i, "ideality") end GetSequenceScores(ideality_scores, 3, false) for i = 1, n_residues - 2 do if (sequence_scores[i] < threshold) then NOTIDEAL = true -- NEW once we find unideality, we'll go for deep idealize save.Quickload(kOriginalStructureOrNewBest) start_idx = ids[i] end_idx = start_idx + 2 print("Idealizing " .. start_idx .. "-" .. end_idx) if (start_idx > 1) then InsCut(start_idx - 1) end if (end_idx < n_residues) then InsCut(end_idx - 1) end selection.DeselectAll() selection.SelectRange(start_idx, end_idx) structure.IdealizeSelected() if (start_idx > 1) then DelCut(start_idx - 1) end if (end_idx < n_residues) then DelCut(end_idx - 1) end selection.DeselectAll() selection.SelectRange(start_idx, end_idx) structure.LocalWiggleSelected(2) score = GetScore() tempgain = record_improvement(true, start_idx, end_idx) end end end function IdealizeBackbone(length, threshold) -- new by BK local length = length or 3 -- Correct really bad Idealities for i = 1, n_residues do ideality_scores[i] = current.GetSegmentEnergySubscore(i, "ideality") end GetSequenceScores(ideality_scores, length, false) for i = 1, n_residues - (length - 1) do if (sequence_scores[i] < threshold) then save.Quickload(kOriginalStructureOrNewBest) start_idx = ids[i] end_idx = start_idx + (length - 1) print("Idealizing " .. start_idx .. "-" .. end_idx) if (start_idx > 1) then InsCut(start_idx - 1) end if (end_idx < n_residues) then InsCut(end_idx - 1) end selection.DeselectAll() selection.SelectRange(start_idx, end_idx) structure.IdealizeSelected() if (start_idx > 1) then DelCut(start_idx - 1) end if (end_idx < n_residues) then DelCut(end_idx - 1) end selection.DeselectAll() selection.SelectRange(start_idx, end_idx) structure.LocalWiggleSelected(2) score = GetScore() tempgain = record_improvement(true, start_idx, end_idx) end end end function DeepIdealizeOneBackbone(length, threshold) local length = length or 1 -- Correct really bad Idealities of one segment for i = 1, n_residues do ideality_scores[i] = current.GetSegmentEnergySubscore(i, "ideality") end GetSequenceScores(ideality_scores, length, false) for i = 1, n_residues - (length - 1) do if (sequence_scores[i] < threshold) then save.Quickload(kOriginalStructureOrNewBest) for rangei = 0, 5 do start_idx = ids[i] - rangei end_idx = start_idx + (length - 1) + rangei if start_idx < 1 then start_idx = 1 end if start_idx > n_residues then start_idx = n_residues end if end_idx > n_residues then end_idx = n_residues end if end_idx < 2 then end_idx = 2 end print("Idealizing " .. start_idx .. "-" .. end_idx) if (start_idx > 1) then InsCut(start_idx - 1) end if (end_idx < n_residues) then InsCut(end_idx) -- was -1; changed 13/12/2017 end selection.DeselectAll() selection.SelectRange(start_idx, end_idx) structure.IdealizeSelected() if (start_idx > 1) then DelCut(start_idx - 1) end if (end_idx < n_residues) then DelCut(end_idx) -- was -1; changed 2/5/2019 (was a bug, see above !) end selection.DeselectAll() selection.SelectRange(start_idx, end_idx) structure.LocalWiggleSelected(2) score = GetScore() tempgain = record_improvement(true, start_idx, end_idx) end end end end function WiggleBackboneTriplets() local p2gains = {} prev_idx = -1 prev_prev_idx = -1 ns = 0 repeat ns = ns + 1 save.Quickload(kOriginalStructureOrNewBest) for i = 1, n_residues do backbone_scores[i] = current.GetSegmentEnergySubscore(i, "backbone") end GetSequenceScores(backbone_scores, 3, false) start_idx = ids[1] if ((start_idx == prev_idx) or (start_idx == prev_prev_idx)) then start_idx = ids[2] if ((start_idx == prev_idx) or (start_idx == prev_prev_idx)) then start_idx = ids[3] end end end_idx = start_idx + 2 prev_prev_idx = prev_idx prev_idx = start_idx print("lw " .. start_idx .. "-" .. end_idx) selection.DeselectAll() selection.SelectRange(start_idx, end_idx) --structure.LocalWiggleSelected ( 2 ) WiggleSimple(2, "lw") score = GetScore() gain = record_improvement() p2gains[ns] = gain until (ns > 2 and (p2gains[ns] + p2gains[ns - 1] + p2gains[ns - 2] < kWiggleBackboneTripletsThreshold)) end function RemixBackboneQuadruplets(minppi) -- will work on the worst 4 segments backbone scores, 3 times local minppi = minppi or kRemixBackboneQuadrupletsThreshold_a local p2gains = {} prev_idx = -1 prev_prev_idx = -1 ns = 0 repeat ns = ns + 1 save.Quickload(kOriginalStructureOrNewBest) for i = 1, n_residues do backbone_scores[i] = current.GetSegmentEnergySubscore(i, "backbone") end GetSequenceScores(backbone_scores, 4, false) start_idx = ids[1] if ((start_idx == prev_idx) or (start_idx == prev_prev_idx)) then start_idx = ids[2] if ((start_idx == prev_idx) or (start_idx == prev_prev_idx)) then start_idx = ids[3] end end end_idx = start_idx + 3 prev_prev_idx = prev_idx prev_idx = start_idx print("rx " .. start_idx .. "-" .. end_idx) selection.DeselectAll() selection.SelectRange(start_idx, end_idx) Do_Remix(start_idx, end_idx) score = GetScore() gain = record_improvement() p2gains[ns] = gain until (ns > 2 and (p2gains[ns] + p2gains[ns - 1] + p2gains[ns - 2] < minppi)) end function WiggleQuadruplets() local p2gains = {} prev_idx = -1 prev_prev_idx = -1 ns = 0 repeat ns = ns + 1 save.Quickload(kOriginalStructureOrNewBest) for i = 1, n_residues do residue_scores[i] = current.GetSegmentEnergyScore(i) end GetSequenceScores(residue_scores, 4, true) start_idx = ids[1] if ((start_idx == prev_idx) or (start_idx == prev_prev_idx)) then start_idx = ids[2] if ((start_idx == prev_idx) or (start_idx == prev_prev_idx)) then start_idx = ids[3] end end end_idx = start_idx + 3 if end_idx > n_residues then break end prev_prev_idx = prev_idx prev_idx = start_idx print("lw " .. start_idx .. "-" .. end_idx) selection.DeselectAll() selection.SelectRange(start_idx, end_idx) WiggleSimple(4, "lw") --structure.LocalWiggleSelected ( 4 ) score = GetScore() gain = record_improvement() p2gains[ns] = gain until (ns > 2 and (p2gains[ns] + p2gains[ns - 1] + p2gains[ns - 2] < kWiggleBackboneQuadrupletsThreshold)) end function RebuildQuadruplets(minppi, length) -- minppi is for the gains at the end only, it will rebuild 3 worst min 3 times local length = length or 4 -- new local p2gains = {} prev_idx = -1 prev_prev_idx = -1 ns = 0 repeat ns = ns + 1 save.Quickload(kOriginalStructureOrNewBest) for i = 1, segCnt2 do residue_scores[i] = current.GetSegmentEnergyScore(i) end GetSequenceScores(residue_scores, 4, true) start_idx = ids[1] if ((start_idx == prev_idx) or (start_idx == prev_prev_idx)) then start_idx = ids[2] if ((start_idx == prev_idx) or (start_idx == prev_prev_idx)) then start_idx = ids[3] end end end_idx = start_idx + 3 prev_prev_idx = prev_idx prev_idx = start_idx if end_idx + length - 4 >= segCnt2 then break end -- no rebuild of ligand print("rb" .. ns .. " " .. start_idx .. "-" .. end_idx + length - 4) selection.DeselectAll() selection.SelectRange(start_idx, end_idx + length - 4) rebuild(start_idx, end_idx + length - 4) score = GetScore() gain = record_improvement() p2gains[ns] = gain until (ns > 2 and (p2gains[ns] + p2gains[ns - 1] + p2gains[ns - 2] < minppi)) end function RebuildUnidealQuadruplets(minppi, length) -- minppi is for the gains at the end only, it will rebuild 3 worst min 3 times NEW 31/5/2015 local length = length or 4 -- new local p2gains = {} prev_idx = -1 prev_prev_idx = -1 ns = 0 repeat ns = ns + 1 save.Quickload(kOriginalStructureOrNewBest) for i = 1, n_residues do ideality_scores[i] = current.GetSegmentEnergySubscore(i, "ideality") end GetSequenceScores(ideality_scores, length, false) start_idx = ids[1] if ((start_idx == prev_idx) or (start_idx == prev_prev_idx)) then start_idx = ids[2] if ((start_idx == prev_idx) or (start_idx == prev_prev_idx)) then start_idx = ids[3] end end end_idx = start_idx + 3 prev_prev_idx = prev_idx prev_idx = start_idx if end_idx + length - 4 >= segCnt2 then break end -- no rebuild of ligand print("rb i " .. ns .. " " .. start_idx .. "-" .. end_idx + length - 4) selection.DeselectAll() selection.SelectRange(start_idx, end_idx + length - 4) rebuild(start_idx, end_idx + length - 4) score = GetScore() gain = record_improvement() p2gains[ns] = gain until (ns > 2 and (p2gains[ns] + p2gains[ns - 1] + p2gains[ns - 2] < minppi)) end function CutWorstAndWiggle(minppi, length, where) -- new 1/5/2015 local length = length or 4 -- new local p2gains = {} local point = 5 local where = where or 2 -- in the length --1 = cut before --2 = cut in --3 = cut after prev_idx = -1 prev_prev_idx = -1 ns = 0 repeat ns = ns + 1 save.Quickload(kOriginalStructureOrNewBest) for i = 1, segCnt2 do residue_scores[i] = current.GetSegmentEnergyScore(i) end GetSequenceScores(residue_scores, length, true) start_idx = ids[1] if ((start_idx == prev_idx) or (start_idx == prev_prev_idx)) then start_idx = ids[2] if ((start_idx == prev_idx) or (start_idx == prev_prev_idx)) then start_idx = ids[3] end end end_idx = start_idx + 3 prev_prev_idx = prev_idx prev_idx = start_idx if end_idx + length - 4 >= segCnt2 then break end -- no cut on ligand print("cw" .. ns .. " " .. start_idx .. "-" .. end_idx + length - 4) selection.DeselectAll() if where == 2 then point = start_idx + 1 elseif where > 2 then point = end_idx + 1 else point = start_idx - 1 end if point >= segCnt2 then break end -- no cut on ligand if point <= 1 then break end -- no cut on first segment InsCut(point) print("Cutting seg" .. point) structure.WiggleAll(25) DelCut(point) structure.WiggleAll(25) score = GetScore() gain = record_improvement() p2gains[ns] = gain until (ns > 2 and (p2gains[ns] + p2gains[ns - 1] + p2gains[ns - 2] < minppi)) end function ShakeWiggleHiding(n) -- experimental -- Shake or wiggle the n worst-hiding sidechains local ids = {} local hiding_scores = {} local countOK = 0 n = math.min(n, n_residues) if (n == n_residues and not KEEPFREEZEALL) then -- selection.SelectAll() else for i = 1, n_residues do if IsOK(i) then countOK = countOK + 1 hiding_scores[countOK] = current.GetSegmentEnergySubscore(i, "hiding") ids[countOK] = countOK end end ShellSort(ids, hiding_scores, #ids) selection.DeselectAll() n = math.min(n, #ids) for i = 1, n do selection.Select(ids[i]) end end if (mutate_not_shake == true and n < 11) then print("mu h") structure.MutateSidechainsSelected(defIters) else print("sh h") QuickShake(defIters) end WiggleSimple(defIters, "ws") -- note= wiggle selected sidechains print("ws h") score = GetScore() tempgain = record_improvement() end --START List all subscores LAS p = print --"quicker" print segCnt = structure.GetCount() --segCnt=segCnt-1 -- for lingard puzzles only! sera initialise par seglock --segCnt=structure.GetCount() flagligand = false segCnt2 = segCnt -- cas de ligands while structure.GetSecondaryStructure(segCnt2) == "M" do segCnt2 = segCnt2 - 1 flagligand = true end segStart = 1 --start from (Default option for JET) segEnd = segCnt2 --end seg: nil=end of protein (Default option for JET) -- duplicat a verifier subscorelist = puzzle.GetPuzzleSubscoreNames() wrst = true subs = true function Sort3(tabl) -- on 3th column (scores) table.sort(tabl, function(a, b) return a[3] < b[3] end) end function Sort2(tabl) -- on 2th column (scores) local a = {} local b = {} table.sort(tabl, function(a, b) return a[2] < b[2] end) end function LAS() -- not very useful here, only for info in the log subscore = 0 -- made global & reinitialized each loop segscores = {} -- made global & reinitialized each loop segscoresub = {} -- made global & reinitialized each loop subscoretot = {} -- made global & reinitialized each loop subscoremeant = {} -- made global & reinitialized each loop lowerstring = "sidechain" -- made global & reinitialized each loop TotalSubscore = 0 -- made global & reinitialized each loop subscoremean = 0 p('=============================') p('Total all segments subscores:') p('-----------------------------') for i = 1, #subscorelist do subscore = 0 lowerstring = string.lower(subscorelist[i]) for seg = segStart, segEnd do subscore = subscore + current.GetSegmentEnergySubscore(seg, lowerstring) end subscoremean = subscore / segEnd subscoretot[i] = { i, lowerstring, subscore } subscoremeant[i] = { i, lowerstring, subscoremean } TotalSubscore = TotalSubscore + subscore end TotalSubscorePerSeg = TotalSubscore / segEnd local Fscore = Score() - TotalSubscore - 8000 print("Filters= " .. r3(Fscore)) print("mean score per segment= " .. r3(TotalSubscorePerSeg)) print("-----------------------") if subs then Sort3(subscoretot) Sort3(subscoremeant) end local subscorei = 0 local subscoremeani = 0 for i = 1, #subscoretot do subscorei = subscoretot[i][3] subscoremeani = subscoremeant[i][3] if math.abs(subscorei) - 0.1 > 0.1 then print(subscoremeant[i][2] .. " per segment: " .. r3(subscoremeani)) end end --[[ p('=============================') p('Total score for each segment:') p('-----------------------------') for seg=segStart, segEnd do segscore=0 for i=1,#subscorelist do lowerstring=string.lower (subscorelist[i]) segscorepart=current.GetSegmentEnergySubscore(seg, lowerstring) segscore=segscore+segscorepart table.insert(segscoresub,{seg,lowerstring,segscorepart}) end segscores [seg]={seg,seg,segscore} end if subs then Sort3(segscores) Sort3(segscoresub) end for i=1,#segscores do if wrst and i>9 then break end print("segment " ..segscores [i][2]..": ".. r3(segscores [i][3])) end p('=============================') p('Segments with worst score parts:') p('-----------------------------') for i=1,#segscoresub do if wrst and i>9 then break end if i>30 then break end if segscoresub [i][3]>10 then break end print("segment " ..segscoresub [i][1].." ".. segscoresub [i][2] ..": ".. r3(segscoresub [i][3])) end if blublublub then -- not used p('=============================') p('Detail worst subscore by segments:') p('-----------------------------') subscore=0 for seg=segStart, segEnd do for i=1,#subscorelist do lowerstring=string.lower (subscorelist[i]) subscore=current.GetSegmentEnergySubscore(seg, lowerstring) if subscore ~= 0 then print ('Segment '..seg..subscorelist[i]..': '..subscore) end end end end --]] end --STOP list all subscores --START Movie store big steps by Bruno Kestemont (free use) v2 9/10/2019 SlotStepStart = 85 -- I must let enough place for the remixes SlotStep = SlotStepStart SlotStepMax = SlotStep -- new StepScore = Score() StepScore1 = 7000 StepScore2 = 9000 StepScore3 = 10000 StepScore4 = 12000 StepGain1 = 1000 StepGain2 = 50 StepGain3 = 20 StepGain4 = 10 function StoreBigStep() -- protection of max slot number StepScore = Score() -- reinitialized, global StepScore4 = StepScore * 1.01 StepGain4 = StepScore * 0.001 save.Quicksave(SlotStep) if SlotStepMax < 100 then -- will stay max at 100 SlotStepMax = SlotStep end SlotStep = SlotStep + 1 if SlotStep > 100 then SlotStep = SlotStepStart -- sorry I have to delete the oldest steps end end function SaveBigSteps() -- in order to be able to display big steps afterwards in undos local s = Score() local g = s - StepScore if s > 0 and ((s < StepScore1 and g > StepGain1) or (s < StepScore2 and g > StepGain2) or (s < StepScore3 and g > StepGain3) or (s > StepScore4 and g > StepGain4)) then StoreBigStep() end end function MovieSteps() -- fixed 9/10/2019 undo.SetUndo(true) for i = SlotStepStart, SlotStepMax do save.Quickload(i) end --save.Quickload(3) print("See remembering of big steps in undos") end SaveBigSteps() -- init for start pose --END Movie store big steps if SKETCHBOOK then defIters = 5 defminppi = 1 CONDITIONS = true end function get_parameters() local dlog = dialog.CreateDialog(recipename) dlog.leave_sheets_alone = dialog.AddCheckbox("Keep sheet backbones", leave_sheet_backbones_alone) dlog.leave_helices_alone = dialog.AddCheckbox("Keep helix backbones", leave_helix_backbones_alone) dlog.KEEPBANDS = dialog.AddCheckbox("Keep bands", KEEPBANDS) dlog.KEEPFREEZE = dialog.AddCheckbox("Keep freezes (backbones)", KEEPFREEZE) dlog.KEEPFREEZEALL = dialog.AddCheckbox("Keep freezes (all)", KEEPFREEZEALL) if SKETCHBOOK then dlog.defminppi = dialog.AddSlider("Min gain/iter", defminppi, 0, 100, 2) end design_puzzle = IsPuzzleMutable() if (design_puzzle == true) then dlog.mutate_not_shake = dialog.AddCheckbox("Worst mutate, not shake", false) end if PROBABLEFILTER then FILTERMANAGE = true dlog.FILTERMANAGE = dialog.AddCheckbox("Disable filter during wiggle (fast)", FILTERMANAGE) dlog.maxfiltercost = dialog.AddSlider("Max Filtr cost/act", maxfiltercost, 0, 999, 0) dlog.GENERICFILTER = dialog.AddCheckbox("OR no filter unless for score", GENERICFILTER) end dlog.NEVERWIGGLEALL = dialog.AddCheckbox("Never Wiggle all backbones", NEVERWIGGLEALL) dlog.ok = dialog.AddButton("OK", 1) dlog.cancel = dialog.AddButton("Cancel", 0) if (dialog.Show(dlog) > 0) then leave_sheet_backbones_alone = dlog.leave_sheets_alone.value leave_helix_backbones_alone = dlog.leave_helices_alone.value KEEPFREEZE = dlog.KEEPFREEZE.value KEEPBANDS = dlog.KEEPBANDS.value NEVERWIGGLEALL = dlog.NEVERWIGGLEALL.value KEEPFREEZEALL = dlog.KEEPFREEZEALL.value if SKETCHBOOK then defminppi = dlog.defminppi.value end if (design_puzzle == true) then mutate_not_shake = dlog.mutate_not_shake.value end if PROBABLEFILTER then FILTERMANAGE = dlog.FILTERMANAGE.value GENERICFILTER = dlog.GENERICFILTER.value maxfiltercost = dlog.maxfiltercost.value end return true else return false end end function changesettings() -- new if loop_nb > 1 then FILTERMANAGE = not FILTERMANAGE print("Changing slow filter settings") end if loop_nb == 3 then MaxRemixSlots = kMaxRemixSlots_b print("Changing max number of remix from " .. kMaxRemixSlots_a .. " to " .. kMaxRemixSlots_b) end if loop_nb > 3 then leave_helix_backbones_alone = not leave_helix_backbones_alone print("Changing helix settings") end if loop_nb > 4 then leave_sheet_backbones_alone = not leave_sheet_backbones_alone print("Changing sheet settings") end if loop_nb > 6 then KEEPBANDS = not KEEPBANDS print("Changing bands settings") end if loop_nb > 7 then KEEPFREEZEALL = not KEEPFREEZEALL print("Changing freeze all settings") end if loop_nb > 8 then ALLLOOP = not ALLLOOP print("Changing all loop settings") end if loop_nb > 9 then KEEPFREEZE = not KEEPFREEZE print("Changing freeze settings") end if loop_nb > 10 then disjunct = not disjunct print("Changing disjunct setting") end -- experimental if loop_nb > 11 then donotrevisit = not donotrevisit print("Changing donotrevisit setting") end -- experimental if loop_nb == 2 or loop_nb == 5 or loop_nb == 10 or loop_nb == 15 or loop_nb > 20 then print("Reducing all thresholds") print("It's time to stop the recipe, it will not gain much more") kWiggleBackbonePairsThreshold = kWiggleBackbonePairsThreshold / 2 kIdealityTripletsThreshold_a = kIdealityTripletsThreshold_a / 2 kIdealityTripletsThreshold_b = kIdealityTripletsThreshold_b / 2 kIdealityPairsThreshold_a = kIdealityPairsThreshold_a / 2 kWiggleBackboneTripletsThreshold = kWiggleBackboneTripletsThreshold / 2 kWiggleBackboneQuadrupletsThreshold = kWiggleBackboneQuadrupletsThreshold / 2 kRebuildQuadrupletsThreshold_a = kRebuildQuadrupletsThreshold_a / 2 kRebuildQuadrupletsThreshold_b = kRebuildQuadrupletsThreshold_b / 2 kRemixBackboneQuadrupletsThreshold_a = kRemixBackboneQuadrupletsThreshold_a / 2 kRemixBackboneQuadrupletsThreshold_b = kRemixBackboneQuadrupletsThreshold_b / 2 kShakeDistanceThreshold = kShakeDistanceThreshold + 1 kLoopRepeatThreshold = kLoopRepeatThreshold / 2 end end function ArchiveSecundaryStructure() for i = 1, n_residues do secondary_structures[i] = structure.GetSecondaryStructure(i) end end function main() print(recipename) print("") --n_residues = structure.GetCount () save.SaveSecondaryStructure() ArchiveSecundaryStructure() CI(1) best_score = GetScore() print("Start score : " .. r3(best_score)) if best_score > 8000 + n_residues * 10 then maxfiltercost = 999 end --to speed up (on end game, filters are strong enough to maintain) if not PROBABLEFILTER then -- otherwise it takes too much time LAS() -- for info only, not very useful for this recipe end if (get_parameters() == false) then error() end if GENERICFILTER then print("Always disabling filter unless for scoring") MutClass(structure, false) MutClass(band, true) MutClass(current, true) MutClass(recentbest, true) -- otherwise, it remembers cut solutions MutClass(save, true) -- better to save with full score else print("No generic filter disabling") end save.Quicksave(kOriginalStructureOrNewBest) print("lw = Local Wiggle") print("id = Idealize") print("rb = Rebuild") print("ws = Wiggle Sidechains") print("ws h= Wiggle worst hiding Sidechains") print("cw= Cut Worst and wiggle all") print("rb i= Rebuild worst ideality") print("sh = Quick Shake") print("rx = Remix") if (mutate_not_shake == true) then print("mu = Mutate worst clashing") print("mu h= Mutate worst hiding") else print("sh h= Quick Shake worst hiding") end print("") print("######################") for i = 1, 1000 do if not KEEPBANDS then -- one shot: once disabled, remains disabled band.DisableAll() end if not KEEPFREEZEALL then -- one shot: once unfreezed, remains unfreezed if KEEPFREEZE then for i = 1, segCnt2 do freeze.Unfreeze(i, false, true) -- unfreezes only sidechains end else freeze.UnfreezeAll() end end save.Quicksave(kOriginalStructureOrNewBest) -- to avoid bug 444 local ii = 0 repeat local g = 0 local ss = GetScore() print("----") print("LOOP " .. i .. "." .. ii) print("----") WiggleBackbonePairs() WiggleSidechains() ShakeSidechains(10) WiggleBackboneTriplets() g = GetScore() - ss ii = ii + 1 until g < kLoopRepeatThreshold RemixBackboneQuadruplets(kRemixBackboneQuadrupletsThreshold_a) -- new IdealizeBackboneTriplets(kIdealityTripletsThreshold_a) WiggleSidechains() ShakeWiggleHiding(10) -- new experimental ShakeSidechains(20) WiggleQuadruplets() ShakeSidechains(n_residues) RebuildQuadruplets(kRebuildQuadrupletsThreshold_a, 4) RemixBackboneQuadruplets(kRemixBackboneQuadrupletsThreshold_b) -- new IdealizeBackboneTriplets(kIdealityTripletsThreshold_b) -- will reinitialize NOTIDEAL RebuildQuadruplets(kRebuildQuadrupletsThreshold_b, 3) -- not sure it's useful here RebuildUnidealQuadruplets(kIdealityQuadripletsThreshold_a, 4) -- NEW experimental if NOTIDEAL then IdealizeBackbone(2, kIdealityPairsThreshold_a) if loop_nb == 2 then IdealizeBackbone(4, kIdealityTripletsThreshold_a) end if loop_nb > 3 and loop_nb < segCnt2 / 2 then IdealizeBackbone(loop_nb, loop_nb * kIdealityPairsThreshold_a / 2) RebuildUnidealQuadruplets(kIdealityQuadripletsThreshold_b, 4) -- NEW experimental end if loop_nb == 2 or loop_nb == 8 or loop_nb == 20 then DeepIdealizeOneBackbone(1, kIdealityPairsThreshold_a / 2) end NOTIDEAL = false -- reinitialized end -- new if (loop_nb > 7 or (loop_nb > 3 and best_score > 9000)) and not NEVERWIGGLEALL then -- the protein should already be stabilized enough !!! CutWorstAndWiggle(kRebuildQuadrupletsThreshold_a, 4, 2) -- new if loop_nb > 4 then CutWorstAndWiggle(kRebuildQuadrupletsThreshold_a, 4, 1) -- new end if loop_nb > 5 then CutWorstAndWiggle(kRebuildQuadrupletsThreshold_a, 4, 3) -- new end end print("######################") ChkDoneList() -- delete old done list if needed loop_nb = loop_nb + 1 SaveBigSteps() -- new changesettings() end cleanup() end function cleanup() undo.SetUndo(true) print("Cleaning up") save.LoadSecondaryStructure() save.Quickload(kOriginalStructureOrNewBest) WhriteNote(loop_nb) behavior.SetSlowFiltersDisabled(OriginalFilterSetting) -- new test 15/4/2015 MovieSteps() recentbest.Restore() band.EnableAll() behavior.SetSlowFiltersDisabled(OriginalFilterSetting) -- new print ("Deleting added cuts") DelAllCuts() end function DumpErr(err) --03/02/2014 start, stop, line, msg = err:find(":(%d+):%s()") err = err:sub(msg, #err) print('---') if err:find('Cancelled') ~= nil then print("User stop.") else print("unexpected error detected.") print("Error line:", line) print("Error:", err) end cleanup() end --main () xpcall(main, DumpErr)

Comments