Icon representing a recipe

Recipe: Compare Solutions 1.0

created by spvincent

Profile


Name
Compare Solutions 1.0
ID
49496
Shared with
Public
Parent
None
Children
None
Created on
June 28, 2014 at 23:34 PM UTC
Updated on
June 28, 2014 at 23:34 PM UTC
Description

See first comment

Best for


Code


compare_with_best = true compare_with_qs = not compare_with_best qs_slot = 9 components = { "Backbone" , "Clashing" , "Ideality" , "Bonding" , "Packing" , "Hiding" , "Sidechain" , "Disulfides" , "Reference" } sequence = false residue = true use_components = {} sequence_data = {} residue_data = {} component_data = {} threshold_value = 10 kTempQuicksaveSlot = 99 -- 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 aa1_to_aa3 ( k ) for j = 1, 20 do if ( k == single_letter_codes [ j ] ) then return three_letter_codes [ j ] end end return "Unk" end 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 aa1_to_aa3 ( k ) end function r2 ( x ) -- Round to 3 decimal places t = 10 ^ 3 return math.floor ( x*t + 0.5 ) / t end function GetData ( start_idx ) if ( sequence == true ) then for i = 1 , n_residues do sequence_data [ i + start_idx ] = structure.GetAminoAcid ( i ) end end if ( residue == true ) then for i = 1 , n_residues do residue_data [ i + start_idx ] = current.GetSegmentEnergyScore ( i ) end end for k = 1 , #components do if ( use_components [ k ] == true ) then for i = 1 , n_residues do component_data [ k ] [ i + start_idx ] = current.GetSegmentEnergySubscore ( i , components [ k ] ) end end end end function TotalDifferences ( nn ) start_total = 0 for i = 1 , n_residues do start_total = start_total + nn [ i ] end end_total = 0 for i = 1 , n_residues do end_total = end_total + nn [ i + n_residues ] end return start_total - end_total end function PrintData () if ( sequence == true ) then print ( "" ) print ( "Mutate differences" ) print ( "" ) for i = 1 , n_residues do if ( sequence_data [ i ] ~= sequence_data [ i + n_residues ] ) then print ( i .. " : " .. aa1_to_aa3 ( sequence_data [ i ] ) .. " -> " .. aa1_to_aa3 ( sequence_data [ i + n_residues ] ) ) end end end if ( residue == true ) then print ( "" ) print ( "Residue differences" .. " ( total " .. r2 ( TotalDifferences ( residue_data ) ) .. " )" ) print ( "" ) for i = 1 , n_residues do delta = residue_data [ i ] - residue_data [ i + n_residues ] if ( math.abs ( delta ) > threshold_value ) then print ( i .. " : " .. get_aa3 ( i ) .. " " .. r2 ( delta ) ) end end end for k = 1 , #components do if ( use_components [ k ] == true ) then print ( "" ) print ( components [ k ] .. " differences" .. " ( total " .. r2 ( TotalDifferences ( component_data [ k ] ) ) .. " )" ) print ( "" ) for i = 1 , n_residues do delta = component_data [ k ] [ i ] - component_data [ k ] [ i + n_residues ] if ( math.abs ( delta ) > threshold_value ) then print ( i .. " : " .. get_aa3 ( i ) .. " " .. r2 ( delta ) ) end end end end end function GetParameters () local dlog = dialog.CreateDialog ( "Compare solutions" ) dlog.use_best = dialog.AddCheckbox ( "Compare with best" , compare_with_best ) dlog.use_qs = dialog.AddCheckbox ( "Compare with quicksave" , compare_with_qs ) dlog.qs_slot = dialog.AddSlider ( "Quicksave" , qs_slot , 1 , 99 , 0 ) dlog.div_1 = dialog.AddLabel ( "__________________________" ) dlog.sequence = dialog.AddCheckbox ( "Sequence" , sequence ) dlog.residue = dialog.AddCheckbox ( "Residue" , residue ) for i = 1 , #components do dlog [ "comp_" .. i ] = dialog.AddCheckbox ( components [ i ] , false ) end dlog.div_2 = dialog.AddLabel ( "__________________________" ) dlog.threshold = dialog.AddSlider ( "Threshold" , threshold_value , 0 , 100 , 1 ) dlog.ok = dialog.AddButton ( "OK" , 1 ) dlog.cancel = dialog.AddButton ( "Cancel" , 0 ) if ( dialog.Show ( dlog ) > 0 ) then compare_with_best = dlog.use_best.value compare_with_qs = dlog.use_qs.value qs_slot = dlog.qs_slot.value sequence = dlog.sequence.value residue = dlog.residue.value for i = 1 , #components do use_components [ i ] = dlog [ "comp_" .. i ].value end threshold_value = dlog.threshold.value return true else return false end end function main () n_residues = structure.GetCount () if ( GetParameters () == false ) then return -- graceful exit end if ( compare_with_best == compare_with_qs ) then print ( "One and only one of the top two checkboxes should be selected" ) return end for i = 1 , #components do component_data [ i ] = {} end GetData ( 0 ) save.Quicksave ( kTempQuicksaveSlot ) if ( compare_with_best == true ) then absolutebest.Restore () else save.Quickload ( qs_slot ) end new_residues = structure.GetCount () if ( n_residues ~= new_residues ) then print ( "Different number of residues in compared solutions" ) return end GetData ( n_residues ) PrintData () save.Quickload ( kTempQuicksaveSlot ) end main ()

Comments


spvincent Lv 1

A utility script that compares the current solution with the best solution (or, optionally, the pose held in a specified Quicksave slot).

Where the absolute value of the difference between the scores for a residue is greater than some specified amount (default=10), the value will be printed out.

Differences in component scores can be detected in a similar way; just check the appropriate box.

For design puzzles, differences in amino acid sequence can be printed.

The contents of slot 99, should such exist, will be overwritten.