Icon representing a recipe

Recipe: Freezing for Refinement

created by brow42

Profile


Name
Freezing for Refinement
ID
43403
Shared with
Public
Parent
Freezing for 598
Children
Created on
July 18, 2012 at 19:01 PM UTC
Updated on
July 18, 2012 at 19:01 PM UTC
Description

This script toggles between freezing known good parts and known bad parts in a refinement puzzle. Requires CASP notes, or you can manually set in script.

Best for


Code


--[[ =================================== * Freezing for Refinement * Original Author: Brow42 * Version 1.0 July 18 2012 * This freeze either the known good sections * or the known bad sections of a refinement * puzzle, if CASP has given us this information. * Each time you run it it will automatically switch * between the to groups. No dialog to make this easy. * * You can set the known bad regions manually at * the top of the script if there are no notes. * Or, you can add a note to any segment of the * form 'Regions a-b c-d e-f' where a b c d e f etc * are bad regions. --]] -- known bad regions, uncomment to specify -- regions = { {43,52}, {79,92}, {104,118} } N = structure.GetCount() -- autodetect regions from notes regions = regions or {} if #regions == 0 then for i = 1,N do note = structure.GetNote(i) if note:find('[rR]esidues +%d+ *- *%d+') then for u,v in note:gfind('(%d+) *- *(%d+)') do regions[#regions+1] = {tonumber(u),tonumber(v)} end end end if #regions == 0 then d = dialog.CreateDialog('No regions to refine specified!') d.l1 = dialog.AddLabel('Require list of regions that need refinement!') d.l2 = dialog.AddLabel('Either edit the regions variable in the script, or add a') d.l3 = dialog.AddLabel('note "Regions a-b c-d" listing bad regions a-b, c-d, etc.') d.ok = dialog.AddButton('Okay',1) dialog.Show(d) return end end -- complement of known bad = known good alt = {} -- pass in lower upper bad segments function AddBetween(a,b) a,b = a+1, b-1 if b >= a then alt[#alt+1] = {a,b} end end -- known good regions alt = {} AddBetween(0,regions[1][1]) for i=1,#regions-1 do AddBetween(regions[i][2],regions[i+1][1]) end AddBetween(regions[#regions][2],N+1) NAlt = 0 -- number frozen when only known good is frozen for i = 1,#alt do NAlt = NAlt + alt[i][2] - alt[i][1] + 1 end function freeze.GetCount() local n = 0 for i = 1,N do n = n + (freeze.IsFrozen(i) and 1 or 0) end return n end function Freeze(tab) selection.DeselectAll() freeze.UnfreezeAll() for i = 1,#tab do selection.SelectRange(unpack(tab[i])) end freeze.FreezeSelected(true,false) selection.DeselectAll() end NF = freeze.GetCount() if NF ~= NAlt then Freeze(alt) else Freeze(regions) end

Comments


brow42 Lv 1

  • Freezing for Refinement
  • Original Author: Brow42
  • Version 1.0 July 18 2012

This freeze either the known good sections or the known bad sections of a refinement puzzle, if CASP has given us this information. Each time you run it it will automatically switch between the to groups. No dialog so you just re-run it.

You can set the known bad regions manually at the top of the script if there are no notes. Or, you can add a note to any segment of the form 'Regions a-b c-d e-f' where a b c d e f etc are bad regions.