Profile


Name
Jolter 1.0
ID
101691
Shared with
Public
Parent
Jo;ter 1.0
Children
None
Created on
December 17, 2015 at 03:05 AM UTC
Updated on
December 17, 2015 at 03:05 AM UTC
Description

See first comment

Best for


Code


best_score = 0 min_residue = 0 max_residue = 0 n_residues = 0 post_rebuild = 3 score_type = 1 original_slow_filters_setting = 0 kCurrBaseStructure = 1 curr_base_score = 0 kBestPostRebuild = 2 kTemp = 3 n_rebuilds = 8 rejection_threshold = 16 kMaxSphereDistance = 14 SphereSegList = {} -- store list of residues within kMaxSphereDistance of any residue in the segment. -- speeds things up when shaking -- SS info ss_starts = {} ss_ends = {} ss_types = {} helix_spacer = 3 sheet_spacer = 2 loop_spacer = 1 kMinSSLength = 3 function r3 ( x ) -- Round to 3 decimal places t = 10 ^ 3 return math.floor ( x*t + 0.5 ) / t end function GetScore () if ( score_type == 1 ) then score = current.GetScore () elseif ( score_type == 2 ) then behavior.SetFiltersDisabled ( false ) score = current.GetScore () behavior.SetFiltersDisabled ( true ) end return score end function GetSecondaryStructures () curr_s_type = false for i = 1, n_residues do s_type = structure.GetSecondaryStructure ( i ) if ( i == 1 ) then ss_starts [ 1 ] = i ss_types [ 1 ] = s_type elseif ( s_type ~= prev_s_type ) then ss_ends [ #ss_ends + 1 ] = i - 1 ss_starts [ #ss_starts + 1 ] = i ss_types [ #ss_types + 1 ] = s_type end prev_s_type = s_type end ss_ends [ #ss_ends + 1 ] = n_residues end function SelectSphere () selection.DeselectAll () for i = 1 , n_residues do if ( SphereSegList [ i ] == true ) then selection.Select ( i ) end end end function ConstructListOfResiduesWithinRange ( start_idx , end_idx ) for i = 1 , n_residues do SphereSegList [ i ] = false end for j = start_idx , end_idx do for i = 1 , n_residues do if ( ( i >= start_idx and i <= end_idx ) or ( structure.GetDistance ( i , j ) < kMaxSphereDistance ) ) then SphereSegList [ i ] = true end end end end function NudgeWiggle () selection.SelectAll () score_in_kTemp = GetScore () save.Quicksave ( kTemp) behavior.SetClashImportance ( 0.5 ) structure.WiggleSelected ( 1 ) behavior.SetClashImportance ( 1 ) structure.WiggleSelected ( 6 ) score = GetScore () if ( score < score_in_kTemp ) then save.Quickload ( kTemp ) end end function Rebuild ( start_idx , end_idx ) ConstructListOfResiduesWithinRange ( start_idx , end_idx ) improvement_made = false best_post_rebuild_score = -999999 i = 1 while ( ( i <= n_rebuilds ) and ( improvement_made == false ) ) do save.Quickload ( kCurrBaseStructure ) selection.DeselectAll () selection.SelectRange ( start_idx , end_idx ) structure.RebuildSelected ( 1 ) SelectSphere () structure.ShakeSidechainsSelected ( 1 ) if ( post_rebuild >= 2 ) then selection.SelectAll () score_before_wiggle = GetScore () structure.WiggleSelected ( 10 ) score_after_wiggle = GetScore () if ( score_after_wiggle - score_before_wiggle < 1 ) then -- The wiggle got stuck and didn't achieve anything NudgeWiggle () end if ( post_rebuild >= 3 ) then score_before_sm = GetScore () SelectSphere () if ( post_rebuild == 3 ) then structure.ShakeSidechainsSelected ( 1 ) else structure.MutateSidechainsSelected ( 1 ) end score_after_sm = GetScore () if ( score_after_sm - score_before_sm > 1e-3 ) then score_before_wiggle = score_after_sm structure.WiggleSelected ( 10 ) score_after_wiggle = GetScore () if ( score_after_wiggle - score_before_wiggle < 1 ) then -- The wiggle got stuck and didn't achieve anything NudgeWiggle () end end end -- ( post_rebuild >= 3 ) end -- ( post_rebuild >= 2 ) score = GetScore () if ( score > best_post_rebuild_score) then best_post_rebuild_score = score save.Quicksave ( kBestPostRebuild ) if ( score > curr_base_score ) then improvement_made = true end --print ( " New best post rebuild score " .. r3 ( score ) ) end i = i + 1 end if ( best_post_rebuild_score > curr_base_score - rejection_threshold ) then save.Quickload ( kBestPostRebuild ) save.Quicksave ( kCurrBaseStructure ) curr_base_score = best_post_rebuild_score print ( " new working score " .. r3 ( curr_base_score ) ) end end function Go () for j = 1 , 2 do for i = j , #ss_starts , 2 do start_idx = ss_starts [ i ] end_idx = ss_ends [ i ] print ( "rb " .. start_idx .. "-" .. end_idx .. " (" .. ss_types [ i ] .. ")" ) Rebuild ( start_idx , end_idx ) end end end function AddSpacers () for i = 1 , #ss_starts do start_idx = ss_starts [ i ] end_idx = ss_ends [ i ] if ( ss_types [ i ] == "H" ) then start_idx = start_idx - helix_spacer end_idx = end_idx + helix_spacer elseif ( ss_types [ i ] == "E" ) then start_idx = start_idx - sheet_spacer end_idx = end_idx + sheet_spacer elseif ( ss_types [ i ] == "L" ) then start_idx = start_idx - loop_spacer end_idx = end_idx + loop_spacer end ss_starts [ i ] = math.max ( 1 , start_idx ) ss_ends [ i ] = math.min ( n_residues , end_idx ) end end function BackboneFrozen ( start_idx , end_idx ) for i = start_idx , end_idx do seg_backbone_frozen, seg_sidechain_frozen = freeze.IsFrozen ( i ) if ( seg_backbone_frozen == true ) then return 1 end end return 0 end function FilterSS () -- Delete any Secondary structures that are outside the range, locked, or consist of small loops for i = #ss_types , 1 , -1 do if ( ( ss_starts [ i ] > max_residue ) or ( ss_ends [ i ] < min_residue ) or ( BackboneFrozen ( ss_starts [ i ] , ss_ends [ i ] ) == 1 ) or ( ss_ends [ i ] - ss_starts [ i ] + 1 < kMinSSLength ) ) then table.remove ( ss_starts , i ) table.remove ( ss_ends , i ) table.remove ( ss_types , i ) end end end function GetParameters () local dlog = dialog.CreateDialog ( "Jolter 1.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 ) dlog.n_rebuilds= dialog.AddSlider ( "N Rebuilds" , n_rebuilds , 1 , 30 , 0 ) dlog.post_rebuild = dialog.AddSlider ( "Post rebuild" , post_rebuild , 1 , 4 , 0 ) dlog.pr = dialog.AddLabel ( "1 = Sh : 2 = Sh/W : 3 = Sh/W/Sh/W : 4 = Sh/W/Mu/W" ) dlog.rejection_threshold = dialog.AddSlider ( "Rejection threshold" , rejection_threshold , 0 , 100 , 0 ) dlog.helix_spacer = dialog.AddSlider ( "Helix spacer" , helix_spacer , 0 , 4 , 0 ) dlog.sheet_spacer = dialog.AddSlider ( "Sheet spacer" , sheet_spacer , 0 , 4 , 0 ) dlog.loop_spacer = dialog.AddSlider ( "Loop spacer" , loop_spacer , 0 , 4 , 0 ) dlog.score_type = dialog.AddSlider ( "Score type" , score_type , 1 , 2 , 0 ) dlog.tp = dialog.AddLabel ( "1 = Normal : 2 = Normal for 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 n_rebuilds = dlog.n_rebuilds.value post_rebuild = dlog.post_rebuild.value rejection_threshold = dlog.rejection_threshold.value helix_spacer = dlog.helix_spacer.value sheet_spacer = dlog.sheet_spacer.value loop_spacer = dlog.loop_spacer.value score_type = dlog.score_type.value return true else return false end end function main () print ( "Jolter 1.0" ) n_residues = structure.GetCount () save.Quicksave ( kCurrBaseStructure ) curr_base_score = GetScore () print ( "Start score " .. r3 ( curr_base_score ) ) behavior.SetClashImportance ( 1 ) original_slow_filters_setting = behavior.GetSlowFiltersDisabled () if ( GetParameters () == false ) then return end max_residue = math.min ( n_residues , max_residue ) min_residue = math.max ( 1 , min_residue ) if ( max_residue < min_residue ) then print ( "Range error." ) print ( "Max residue (" .. max_residue .. ") must be greater than or equal to Min residue (" .. min_residue .. ")" ) return end print ( "Range " .. min_residue .. " to " .. max_residue ) print ( "N rebuilds " .. n_rebuilds ) print ( "Rejection threshold " .. r3 ( rejection_threshold ) ) print ( "Helix spacer " .. helix_spacer ) print ( "Sheet spacer " .. sheet_spacer ) print ( "Loop spacer " .. loop_spacer ) if ( post_rebuild == 1 ) then print ( "Post rebuild : Shake" ) elseif ( post_rebuild == 2 ) then print ( "Post rebuild : Shake/Wiggle" ) elseif ( post_rebuild == 3 ) then print ( "Post rebuild : Shake/Wiggle/Shake/Wiggle" ) elseif ( post_rebuild == 4 ) then print ( "Post rebuild : Shake/Wiggle/Mutate/Wiggle" ) end if ( score_type == 1 ) then print ( "Score type : Normal" ) elseif ( score_type == 2 ) then print ( "Score type : Normal/Slow Filters" ) end print () GetSecondaryStructures () --for i = 1 , #ss_types do --print ( ss_starts [ i ] .. " " .. ss_ends [ i ] .. " " .. ss_types [ i ] ) --end AddSpacers () FilterSS () --print ( "Post Filter" ) --for i = 1 , #ss_types do --print ( ss_starts [ i ] .. " " .. ss_ends [ i ] .. " " .. ss_types [ i ] ) --end while true do Go () end end function cleanup () print ( "Cleaning up" ) behavior.SetClashImportance ( 1.0 ) save.Quickload ( kCurrBaseStructure ) if ( score_type == 2 ) then behavior.SetSlowFiltersDisabled ( original_slow_filters_setting ) end end --main () xpcall ( main , cleanup )

Comments


spvincent Lv 1

Jolter is a rebuild script that's designed, as the name suggests, to jolt the protein out of a local minimum (that's the intent anyway), although it does seem useful in other circumstances. It successively rebuilds alternate structural elements in the protein, being prepared to accept a small loss in score after the usual quota of shakes and wiggles that normally follow a rebuild (gains are also accepted, needless to say).

The script never terminates: it's best run overnight or at least for a couple of hours. After cancelling the script you can start from the existing position, or, since the score meanders up and down when running the script. Suggested followup would be to run an Idealize script followed by the rebuilder of your choice.

Algorithm outline

Get list of secondary structure elements (helix, sheet, loop)

For each element (going alternately)
Repeat 8 times (value of N rebuilds below)
Rebuild element
Shake/Wiggle etc (Post Rebuild below)
end

Take best scoring position from above
If score is better than the current score minus the rejection threshhold then
make this the new current position
end
end

Min residue: max residue

Used to define the region of the protein to be rebuilt. Any secondary structure element that lies at least partially within this region will be processed. An element that contains a residue with a frozen backbone will not be processed.

N Rebuilds

How many times to rebuild each structure. Reducing this value may result in a more structurally diverse result, albeit at the likely expense of a poorer score.

Post Rebuild

The actions to be taken after each rebuild, The default is Shake/Wiggle/Shake/Wiggle (with nudges at low CI if things get stuck) but for design puzzles number 4 (Shake/Wiggle/Mutate/Wiggle) is likely preferable.

Rejection Threshold

Specifies how big a loss is permissible. The larger the value the greater the change in structure that will be allowed at the possiblee expense of score

Setting this to zero means that only gains will be permitted: useful in the earlier stages.

Helix spacer, Sheet spacer, Loop spacer

When rebuilding, specifies the length of a spacer at either end of the structural element that will be included in the rebuild. So if the value of Helix spacer were 3, then when working on a helix from 63 to 75, the actual rebuild length would be 60 to 78.

Score type

If set to 2, toggles filters off except when determining the score. For better performance on slow design puzzles.