Icon representing a recipe

Recipe: Quickfix 1.1

created by spvincent

Profile


Name
Quickfix 1.1
ID
44264
Shared with
Public
Parent
None
Children
None
Created on
September 27, 2012 at 19:22 PM UTC
Updated on
September 27, 2012 at 19:22 PM UTC
Description

See first comment

Best for


Code


-- Parameters local_rebuild_length = 4 -- used for wiggle also -- Constants kIterationsBetweenShakesPass1 = 3 kIterationsBetweenShakesPass2 = 4 kRequiredPass1WiggleGain = 5000 kShakeDistanceThreshold = 14 -- Globals original_secondary_structure = {} residue_scores = {} residue_sequence_scores = {} ids = {} score = 0 best_score = 0 -- Quicksave slots kOriginalStructureOrNewBest = 1 -- the starting structure, or any subsequent improvement, will be stored in this quicksave slot function r3 ( i ) -- printing convenience return i - i % 0.001 end function GetScore () score = current.GetEnergyScore () if ( score < -999998 ) then score = 8000 for i = 1 , n_residues do score = score + current.GetSegmentEnergyScore ( i ) end end return score end function GetScores () for i = 1 , n_residues do residue_scores [ i ] = current.GetSegmentEnergyScore ( i ) end end function GetSequenceScores () for i = 1 , n_residues - local_rebuild_length + 1 do residue_sequence_scores [ i ] = 0 for j = i , i + local_rebuild_length - 1 do residue_sequence_scores [ i ] = residue_sequence_scores [ i ] + residue_scores [ j ] end end end function ShellSort ( ids , sequence_scores , n ) -- Adapted from Numerical Recipes in C local inc = 1 repeat inc = inc * 3 + 1 until inc > n repeat inc = inc / 3 inc = inc - inc % 1 for i = inc + 1 , n do v = sequence_scores [ i ] w = ids [ i ] j = i flag = false while ( flag == false and sequence_scores [ j - inc ] > v ) do sequence_scores [ j ] = sequence_scores [ j - inc ] ids [ j ] = ids [ j - inc ] j = j - inc if ( j <= inc ) then flag = true end end sequence_scores [ j ] = v ids [ j ] = w end until inc <= 1 end function rebuild ( start_idx , end_idx ) selection.DeselectAll ( ) selection.SelectRange ( start_idx , end_idx ) structure.SetSecondaryStructureSelected ( "L" ) -- Rebuild structure.RebuildSelected ( 1 ) recentbest.Save () structure.RebuildSelected ( 3 ) recentbest.Restore () -- Wiggle sidechains selection.DeselectAll ( ) mid_x = ( start_idx + end_idx ) / 2 for i = 1 , n_residues do d = structure.GetDistance ( i , mid_x ) if ( d < kShakeDistanceThreshold ) then selection.Select ( i ) end end structure.WiggleAll ( 1, false , true ) -- Wiggle selection.DeselectAll ( ) selection.SelectRange ( start_idx , end_idx ) structure.LocalWiggleSelected ( 12 ) end function record_improvement () if ( score > best_score ) then best_score = score save.LoadSecondaryStructure () save.Quicksave ( kOriginalStructureOrNewBest ) print ( " Improvement to " .. r3 ( score ) ) end end function main () print ( "Quickfix 1.1" ) print ( "" ) band.DisableAll () freeze.UnfreezeAll () n_residues = structure.GetCount () for i = 1, n_residues do original_secondary_structure [ i ] = structure.GetSecondaryStructure ( i ) end save.SaveSecondaryStructure () behavior.SetClashImportance ( 1 ) best_score = GetScore () print ( "Start score : " .. r3 ( best_score ) ) save.Quicksave ( kOriginalStructureOrNewBest ) print ( "lw = Local Wiggle" ) print ( "rb = Rebuild" ) print ( "ws = Wiggle Sidechains" ) print ( "" ) -- Make sure we don't hammer precisely the same region each time prev_idx = -1 prev_prev_idx = -1 gain_from_local_wiggle = 0 ns = 0 repeat if ( ns % kIterationsBetweenShakesPass1 == 0 ) then print ( "ws" ) save.Quickload ( kOriginalStructureOrNewBest ) selection.SelectAll ( ) structure.WiggleAll ( 1, false , true ) score = GetScore () record_improvement () end ns = ns + 1 save.Quickload ( kOriginalStructureOrNewBest ) GetScores () GetSequenceScores () for i = 1 , n_residues - local_rebuild_length + 1 do ids [ i ] = i end ShellSort ( ids , residue_sequence_scores , n_residues - local_rebuild_length + 1 ) start_idx = ids [ 1 ] if ( ( start_idx == prev_idx ) or ( start_idx == prev_prev_idx ) ) then start_idx = ids [ 2 ] if ( ( start_idx == prev_idx ) or ( start_idx == prev_prev_idx ) ) then start_idx = ids [ 3 ] end end end_idx = start_idx + local_rebuild_length - 1 prev_prev_idx = prev_idx prev_idx = start_idx print ( "lw " .. start_idx .. "-" .. end_idx ) selection.DeselectAll ( ) selection.SelectRange( start_idx , end_idx ) structure.SetSecondaryStructureSelected ( "L" ) structure.LocalWiggleSelected ( 9 ) score = GetScore () gain_from_local_wiggle = score - best_score record_improvement () until ( gain_from_local_wiggle < kRequiredPass1WiggleGain ) -- Pass 2 ns = 0 while true do save.Quickload ( kOriginalStructureOrNewBest ) GetScores () GetSequenceScores () for i = 1 , n_residues - local_rebuild_length + 1 do ids [ i ] = i end ShellSort ( ids , residue_sequence_scores , n_residues - local_rebuild_length + 1 ) start_idx = ids [ 1 ] if ( ( start_idx == prev_idx ) or ( start_idx == prev_prev_idx ) ) then start_idx = ids [ 2 ] if ( ( start_idx == prev_idx ) or ( start_idx == prev_prev_idx ) ) then start_idx = ids [ 3 ] end end end_idx = start_idx + local_rebuild_length - 1 prev_prev_idx = prev_idx prev_idx = start_idx print ( "lw " .. start_idx .. "-" .. end_idx ) selection.DeselectAll ( ) selection.SelectRange( start_idx , end_idx ) structure.SetSecondaryStructureSelected ( "L" ) structure.LocalWiggleSelected ( 9 ) score = GetScore () record_improvement () save.Quickload ( kOriginalStructureOrNewBest ) print ( "rb " .. start_idx .. "-" .. end_idx ) rebuild ( start_idx , end_idx ) score = GetScore () record_improvement () ns = ns + 1 if ( ns % kIterationsBetweenShakesPass2 == 0 ) then print ( "ws" ) save.Quickload ( kOriginalStructureOrNewBest ) selection.SelectAll ( ) structure.WiggleAll ( 1, false , true ) score = GetScore () record_improvement () end end -- while true end function cleanup () print ( "Cleaning up" ) save.LoadSecondaryStructure () save.Quickload ( kOriginalStructureOrNewBest ) band.EnableAll () end xpcall ( main , cleanup )

Comments


spvincent Lv 1

The purpose of this script is to repair a very low scoring solution; such as might be produced after fixing cut points or doing a register shift. It use a combination of local wiggles, rebuilds, and side chain wiggles to improve the score from -478094 (or whatever) to something respectable like 9000 or so while maintaining the general structure of the protein.

The script doesn't terminate: quit when it doesn't seem to producing points at a reasonable rate. By that time the protein should be in a state where you can wiggle without it blowing apart.

1.1 : added workaround for initial scores < 1e6

phallicies Lv 1

This would probably go a lot quicker if you did multiple wiggle areas at once. I know when i manually select all the cut-points and wiggle them all at the same time the score increase sooo much. maybe if you could pick like 5 or 10 of the worst areas to local wiggle at the same time.