Icon representing a recipe

Recipe: Show Worst 2.0

created by spvincent

Profile


Name
Show Worst 2.0
ID
48582
Shared with
Public
Parent
None
Children
None
Created on
March 18, 2014 at 01:25 AM UTC
Updated on
March 18, 2014 at 01:25 AM UTC
Description

Some improvements

Best for


Code


components = { "Backbone" , "Clashing" , "Ideality" , "Bonding" , "Packing" , "Hiding" , "Sidechain" , "Disulfides" , "Reference" } use_components = {} scores = {} ids = {} residue = true show_best = false show_n = 5 -- Amino acids. single_letter_codes = { "g","a","v","l","i","m","f","w","p","s","t","c","y","n","q","d","e","k","r","h"} three_letter_codes = { "Gly","Ala","Val","Leu","Ile","Met","Phe","Trp","Pro","Ser","Thr","Cys","Tyr","Asn","Gln","Asp","Glu","Lys","Arg","His"} function get_aa3 ( i ) k = structure.GetAminoAcid ( i ) for j = 1, 20 do if ( k == single_letter_codes [ j ] ) then return three_letter_codes [ j ] end end return "Unk" end function r3 ( i ) -- printing convenience return i - i % 0.001 end function print_line ( id , v ) print ( get_aa3 ( id ) .. " " .. id .. " " .. r3 ( v ) ) end function BestWorstString () if ( show_best == false ) then return "Worst " else return "Best " end end function sigma () total = 0 for i = 1 , n_residues do total = total + scores [ i ] end return total end function print_dataset () print ( " " ) if ( show_best == false ) then for j = 1, math.min ( show_n , n_residues ) do print_line ( ids [ j ] , scores [ j ] ) end else for j = n_residues , math.max ( n_residues - show_n + 1 , 1 ) , -1 do print_line ( ids [ j ] , scores [ j ] ) end end print ( " " ) end function ShellSort () -- Adapted from Numerical Recipes in C inc = 1 repeat inc = inc * 3 + 1 until inc > n_residues repeat inc = inc / 3 inc = inc - inc % 1 for i = inc + 1 , n_residues do v = scores [ i ] w = ids [ i ] j = i flag = false while ( flag == false and scores [ j - inc ] > v ) do scores [ j ] = scores [ j - inc ] ids [ j ] = ids [ j - inc ] j = j - inc if ( j <= inc ) then flag = true end end scores [ j ] = v ids [ j ] = w end until inc <= 1 end function GetParameters () local dlog = dialog.CreateDialog ( "Show Worst 2" ) dlog.residue = dialog.AddCheckbox ( "Residue" , residue ) dlog.div_1 = dialog.AddLabel ( "__________________________" ) for i = 1 , #components do dlog [ "comp_" .. i ] = dialog.AddCheckbox ( components [ i ] , false ) end dlog.div_2 = dialog.AddLabel ( "__________________________" ) dlog.show_best = dialog.AddCheckbox ( "Show best" , show_best ) dlog.show_n = dialog.AddSlider ( "Show" , show_n , 2 , n_residues , 0 ) dlog.ok = dialog.AddButton ( "OK" , 1 ) dlog.cancel = dialog.AddButton ( "Cancel" , 0 ) if ( dialog.Show ( dlog ) > 0 ) then residue = dlog. residue.value for i = 1 , #components do use_components [ i ] = dlog [ "comp_" .. i ].value end show_best = dlog.show_best.value show_n = dlog.show_n.value return true else return false end end function main () n_residues = structure.GetCount () if ( GetParameters () == false ) then return -- graceful exit end mid_pt = math.ceil ( n_residues / 2 ) if ( residue == true ) then for j = 1 , n_residues do scores [ j ] = current.GetSegmentEnergyScore ( j ) ids [ j ] = j end ShellSort () print ( BestWorstString () .. " residues ( Total = " .. r3 ( sigma () ) .. " : Median = " .. r3 ( scores [ mid_pt ] ) .. " )" ) print_dataset () end for i = 1 , #components do if ( use_components [ i ] == true ) then for j = 1 , n_residues do scores [ j ] = current.GetSegmentEnergySubscore ( j , components [ i ] ) ids [ j ] = j end ShellSort () print ( BestWorstString () .. components [ i ] .. " ( Total = " .. r3 ( sigma () ) .. " : Median = " .. r3 ( scores [ mid_pt ] ) .. " )" ) print_dataset () end end end function cleanup () end main () --xpcall ( main , cleanup )

Comments


spvincent Lv 1

A couple of modest enhancements: prints out totals and medians of the selected properties, and allows numbers up to and including the number of residues to be printed.

gitwut Lv 1

Spvincent,

I got this error when trying to run Show Worst 2.0 on puzzle 935 using Residue, Backbone and Ideality:

ERROR: [string "components = { "Backbone" ,…"]:44: attempt to perform arithmetic on local 'i' (a nil value)

Working on sgmnt 69 with delta -11.463679135896
Working on sgmnts 86-87 with delta -5.2383567686684