Icon representing a recipe

Recipe: Local Mutate 2.0

created by spvincent

Profile


Name
Local Mutate 2.0
ID
101057
Shared with
Public
Parent
Loca Mutate 2.0
Children
Created on
May 30, 2015 at 16:17 PM UTC
Updated on
May 30, 2015 at 16:17 PM UTC
Description

See first comment

Best for


Code


min_residue = 1 max_residue = 999 n_residues = 0 delta_residue = 5 kMaxDelta = 20 best_score = 0 clash_importance_during_modify = 0.1 kWiggleIterations = 15 modify_radius = 14 modifier_type = 2 original_slow_filters_setting = 0 score_type = 2 loss_from_modify = {} -- Amino acids. Hydrophobics first. 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"} -- Use of quicksave slots kOriginalStructureOrNewBest = 10 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 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 PostModify () behavior.SetClashImportance ( 1.0 ) selection.SelectAll () structure.WiggleSelected ( 1 , false , true ) -- sidechains structure.WiggleSelected ( kWiggleIterations ) end function MutateResidue ( i ) save.Quickload ( kOriginalStructureOrNewBest ) selection.DeselectAll () for j = 1 , n_residues do if ( structure.GetDistance ( i , j ) < modify_radius ) then selection.Select ( j ) end end behavior.SetClashImportance ( clash_importance_during_modify ) if ( modifier_type == 1 ) then structure.WiggleSelected ( 1 ) structure.ShakeSidechainsSelected ( 1 ) elseif ( modifier_type == 2 ) then structure.MutateSidechainsSelected ( 1 ) end score = GetScore () table.insert ( loss_from_modify , best_score - score ) if ( math.abs ( score - best_score ) > 0.5 ) then PostModify() score = GetScore () if ( score > best_score ) then save.Quicksave ( kOriginalStructureOrNewBest ) best_score = score print ( "Improvement to " .. r3 ( best_score ) ) end end end function MutateAll () n = 1 for start_idx = 1 , delta_residue do i = min_residue - 1 + start_idx while ( i < max_residue ) do print ( get_aa3 (i) .. " " .. i .. " (" .. n .. "/" .. max_residue - min_residue + 1 .. ")" ) MutateResidue ( i ) i = i + delta_residue n = n + 1 end end end function GetParameters () local dlog = dialog.CreateDialog ( "Local Mutate 2.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.delta_residue = dialog.AddSlider ( "Delta residue" , delta_residue , 1 , kMaxDelta , 0 ) dlog.cidm = dialog.AddSlider ( "Clash importance" , clash_importance_during_modify , 0 , 1.0 , 2 ) dlog.modifier = dialog.AddSlider ( "Modifier" , modifier_type , 1 , 2 , 0 ) dlog.tp = dialog.AddLabel ( "1 = W/S : 2 = Mutate" ) dlog.modify_radius = dialog.AddSlider ( "Sphere radius" , modify_radius , 1 , 30 , 1 ) dlog.score_type = dialog.AddSlider ( "Score type" , score_type , 1 , 2 , 0 ) dlog.tp2 = 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 delta_residue = dlog.delta_residue.value clash_importance_during_modify = dlog.cidm.value modifier_type = dlog.modifier.value modify_radius = dlog.modify_radius.value score_type = dlog.score_type.value return true else return false end end function main () band.DisableAll () n_residues = structure.GetCount () save.Quicksave ( kOriginalStructureOrNewBest ) original_slow_filters_setting = behavior.GetSlowFiltersDisabled () if ( GetParameters () == false ) then return -- graceful exit end print ( "Local Mutate 2.0" ) max_residue = math.min ( n_residues , max_residue ) min_residue = math.max ( 1 , min_residue ) print ( "Rebuild range " .. min_residue .. " to " .. max_residue ) if ( max_residue < min_residue ) then print ( "Rebuild range error." ) return end print ( "Delta " .. delta_residue ) print ( "Modifier " .. modifier_type ) print ( "CI on modify " .. r3 ( clash_importance_during_modify ) ) print ( "Selection radius " .. r3 ( modify_radius ) ) print ( "Score type " .. score_type ) print ( "" ) best_score = GetScore () print ( "Start score : " .. r3 ( best_score ) ) MutateAll () cleanup () end function cleanup () print ( "Cleaning up" ) behavior.SetClashImportance ( 1.0 ) save.Quickload ( kOriginalStructureOrNewBest ) selection.SelectAll () band.EnableAll () behavior.SetSlowFiltersDisabled ( original_slow_filters_setting ) if ( #loss_from_modify > 1 ) then table.sort ( loss_from_modify ) mid_pt = math.ceil ( #loss_from_modify / 2 ) print ( "Median loss from modify " .. r3 ( loss_from_modify [ mid_pt ] ) ) end end --main () xpcall ( main , cleanup )

Comments


spvincent Lv 1

A script similar in style to Rav Mutate, intended for design puzzles.

Algorithm outline

For each amino acid
Set the Clash Importance to something low
Select everything in the immediate neighbourhood of that residue
Mutate
Set the CI to 1 and select the whole protein
Wiggle sidechains
Wiggle
Record any improvement
end

Dialog settings

Min residue, Max residue

The range to be mutated : by default the whole protein.

Delta residue

Processing each residue in turn is inefficient: the selection in each case will be largely duplicated. This setting indicates the difference between successive residues. For example, if the min and max residues above are 1 and 100 respectively and the delta value is 5, then residues will be processed in the order 1,5,10,15,etc…..2,6,11 and so on.

Clash importance

The value during the initial mutate. Something that reduces the energy score by about 200 seems about right (the median reduction is printed out at the end of the script)

Modifier

The operation at low CI that reduces the score. By default Mutate, but a Wiggle/Shake option is present for non-design puzzles.

Sphere radius

Every amino acid within this distance of the one currently being processed will be mutated. Reduce to make the script run faster.

Score type

If set to 2 (default), filters are toggled on to determine the score only: other operations such as wiggle are done with filters off. If set to 1, the initial filter setting will be used throughout.