Icon representing a recipe

Recipe: Show Worst 2.4

created by spvincent

Profile


Name
Show Worst 2.4
ID
109354
Shared with
Public
Parent
Show Worst 2.2
Children
None
Created on
February 07, 2026 at 01:38 AM UTC
Updated on
February 10, 2026 at 01:41 AM UTC
Description

Added Density component + Optional Selection

Best for


Code


components = { "Backbone" , "Clashing" , "Ideality" , "Bonding" , "Packing" , "Hiding" , "Sidechain" , "Disulfides" , "Density" , "Reference" } use_components = {} scores = {} ids = {} residue = true show_best = false show_select = false -- added in 2.4 : if set then the worst residues are selected in game show_n = 6 -- 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 ) ) if ( show_select == true ) then selection.Select ( id ) end 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.4" ) 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.show_select = dialog.AddCheckbox ( "Select" , show_select ) 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 show_select = dlog.show_select.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

Changes from previous:

1) Allows for the detection of residues with bad Density.
2) When the Select checkbox is selected, any residue appearing in the Recipe Output will also be selected in game.

So, for example, to see the 20 residues with worst Density subscore

a) Ensure nothing is selected.
b) Invoke this recipe.
c) Uncheck the Residue checkbox
d) Check the Density checkbox
e) Drag the slider from 6 to 20

hit ok. As well as printing the ids and density values in the recipe output window, the relevant residues will be selected for easier visualization.