Icon representing a recipe

Recipe: Idealize 3.0

created by spvincent

Profile


Name
Idealize 3.0
ID
100708
Shared with
Public
Parent
None
Children
Created on
February 21, 2015 at 02:47 AM UTC
Updated on
February 21, 2015 at 02:47 AM UTC
Description

See first comment

Best for


Code


kFallApartThreshold = 800 -- If Idealize results in a loss greater than this, skip the subsequent wiggle as the protein has probably exploded n_residues = 0 min_residue = 1 max_residue = 999 ss_starts = {} ss_ends = {} ss_types = {} kOriginalStructureOrNewBest = 8 kWiggleDuration = 10 score_type = 1 original_slow_filters_setting = 0 function r3 ( i ) -- printing convenience return i - i % 0.001 end function GetScore () if ( score_type == 1 ) then score = current.GetEnergyScore () elseif ( score_type == 2 ) then behavior.SetSlowFiltersDisabled ( false ) score = current.GetScore () behavior.SetSlowFiltersDisabled ( true ) end return score end function DoesPuzzleHaveSlowFilters () init_setting = behavior.GetSlowFiltersDisabled () if ( init_setting == false ) then score_without_sf = current.GetScore () behavior.SetSlowFiltersDisabled ( true ) score_with_sf = current.GetScore () else score_with_sf = current.GetScore () behavior.SetSlowFiltersDisabled ( false ) score_without_sf = current.GetScore () end behavior.SetSlowFiltersDisabled ( init_setting ) if ( math.abs ( score_without_sf - score_with_sf ) > 1e-3 ) then return true else return false end end function GetStructures () curr_type = 'x' for i = 1, n_residues do ss_type = structure.GetSecondaryStructure ( i ) if ( ss_type ~= curr_type ) then -- start of a new struct curr_type = ss_type ss_starts [ #ss_starts + 1 ] = i if ( i > 1 ) then ss_ends [ #ss_ends + 1 ] = i -1 end ss_types [ #ss_types + 1 ] = curr_type end end -- for i ss_ends [ #ss_ends + 1 ] = n_residues end function IdealizeSection ( s_idx , e_idx , ss_type ) if ( ( s_idx > max_residue ) or ( e_idx < min_residue ) ) then return end start_idx = math.max ( s_idx , min_residue ) end_idx = math.min ( e_idx , max_residue ) save.Quickload ( kOriginalStructureOrNewBest ) selection.DeselectAll () selection.SelectRange ( start_idx , end_idx ) print ( "Idealizing " .. start_idx .. "-" .. end_idx .. " (" .. ss_type .. ")" ) structure.IdealizeSelected () score_after_idealize = GetScore () selection.SelectAll () if ( ( curr_best_score - score_after_idealize ) > kFallApartThreshold ) then structure.WiggleAll ( 1, false , true ) -- wiggle sidechains end if ( math.abs ( score - curr_best_score ) > 1e-3 ) then structure.WiggleSelected ( kWiggleDuration ) score_after_wiggle = GetScore () if ( score_after_wiggle > curr_best_score ) then curr_best_score = score_after_wiggle save.Quicksave ( kOriginalStructureOrNewBest ) print ( "Improvement to : " .. r3 ( curr_best_score ) ) end end end function GetParameters () local dlog = dialog.CreateDialog ( "Idealize 3.0" ) dlog.min_residue = dialog.AddSlider ( "Min residue" , 1 , 1 , n_residues , 0 ) dlog.max_residue = dialog.AddSlider ( "Max residue" , n_residues , 1 , n_residues , 0 ) if ( DoesPuzzleHaveSlowFilters () == true ) then score_type = 2 end dlog.score_type = dialog.AddSlider ( "Score type" , score_type , 1 , 2 , 0 ) dlog.tp = dialog.AddLabel ( "1 = Normal : 2 = Normal for Slow Filters" ) dlog.ok = dialog.AddButton ( "OK" , 1 ) dlog.cancel = dialog.AddButton ( "Cancel" , 0 ) if ( dialog.Show ( dlog ) > 0 ) then min_residue = dlog.min_residue.value max_residue = dlog.max_residue.value score_type = dlog.score_type.value return true else return false end end function main () print ( "Idealize 3.0" ) n_residues = structure.GetCount () behavior.SetClashImportance ( 1 ) GetStructures () original_slow_filters_setting = behavior.GetSlowFiltersDisabled () if ( GetParameters () == false ) then print ( "error" ) error () end if ( max_residue < min_residue ) then print ( "Rebuild range error" ) return end print ( "Idealizing structures from " .. min_residue .. " to " .. max_residue ) curr_best_score = GetScore () print ( "Init score : " .. r3 ( curr_best_score ) ) save.Quicksave ( kOriginalStructureOrNewBest ) for i = 1 , #ss_starts do if ( ss_types [ i ] == "H" ) then IdealizeSection ( ss_starts [ i ] , ss_ends [ i ] , "H" ) end end for i = 1 , #ss_starts do if ( ss_types [ i ] == "E" ) then IdealizeSection ( ss_starts [ i ] , ss_ends [ i ] , "E" ) end end for i = 1 , #ss_starts do if ( ss_types [ i ] == "L" ) then IdealizeSection ( ss_starts [ i ] , ss_ends [ i ] , "L" ) end end cleanup () end function cleanup () behavior.SetClashImportance ( 1.0 ) save.Quickload ( kOriginalStructureOrNewBest ) behavior.SetSlowFiltersDisabled ( original_slow_filters_setting ) end --main () xpcall ( main , cleanup )

Comments


spvincent Lv 1

A quick-running script that idealizes secondary structure elements. Useful after running a rebuild script.

The principal change since 2.0 is to add a mode for Slow Filters

Algorithm outline

For each secondary structure element
    Idealize
    If the score drop is significant
         Wiggle Sidechains
    end
    Wiggle
    Record any gain
end

It does helices, sheets, then loops: mostly out of a general sense that it's better not to go through the protein in a linear way.

Min residue, Max residue

Only structures that lie at least partially within this range will be processed: by default the entire protein is used.

Score type

Default is Normal. Normal/Slow Filters is for slow design/symmetry puzzles (for such puzzles the score type defaults to this mode): it sets slow filters off apart from scoring.