Icon representing a recipe

Recipe: HNetwork Probe 2.1

created by spvincent

Profile


Name
HNetwork Probe 2.1
ID
104038
Shared with
Public
Parent
None
Children
Created on
October 08, 2020 at 16:36 PM UTC
Updated on
October 08, 2020 at 16:36 PM UTC
Description

Bug fix: see first comment

Best for


Code


polar_aas = "stnqdehyw" n_polar_aas = 0 n_residues = 0 first_qs_slot = 13 last_qs_slot = 35 next_qs_slot = 0 start_slot = 1 select_unfrozen = true sidechain_minimum = -70 n_it = 0 mutate_list_ui = {} -- will be a list of 1's & 0's for each residue. 1 means can mutate. 0 means don't mutate. mutable_list = {} filter_list = {} init_filter_score = 0 function r3 ( x ) -- Round to 3 decimal places t = 10 ^ 3 return math.floor ( x*t + 0.5 ) / t end function GetFilterScore () filter_bonus = filter.GetBonus ( "Hydrogen Bond Network" ) return filter_bonus end function GetListOfMutablesUnfrozen () for i = 1 , n_residues do seg_backbone_frozen, seg_sidechain_frozen = freeze.IsFrozen ( i ) if ( ( seg_sidechain_frozen == false ) and -- ( seg_backbone_frozen == false ) and ( structure.IsMutable ( i ) == true ) ) then table.insert ( mutable_list , i ) end end end function GetListOfMutablesSelected () for i = 1 , n_residues do seg_backbone_frozen, seg_sidechain_frozen = freeze.IsFrozen ( i ) if ( ( seg_sidechain_frozen == false ) and ( mutate_list_ui [ i ] == 1 ) and ( structure.IsMutable ( i ) == true ) ) then table.insert ( mutable_list , i ) end end end -- getlist pinched from Loop Rebuild 9.0 -- http://www.lua.org/manual/5.2/manual.html#6.4 -- helped make this function 11/16/17 function getlist(liststr) local newlist={} local i,ilo,ihi,idir,substr for i=1,n_residues do newlist[i]=0 end -- for i -- below reads from liststr a series of substr's -- where each substr contains an integer -- followed by one or more '-' signs -- followed by an integer for substr in string.gmatch(liststr,"(%d+%-+%d+)") do -- substr includes one or more '-' characters in a row -- below gets ilo & ihi from substr ilo=string.gsub(substr,"(%d+)%-+(%d+)","%1")+0 ihi=string.gsub(substr,"(%d+)%-+(%d+)","%2")+0 -- above gets ilo & ihi from substr idir=1 -- the increment to use from ilo to ihi if ilo>ihi then idir= -1 end -- if ilo for i=ilo,ihi,idir do -- for i=ilo to ihi step idir if i>=1 and i<=n_residues then newlist[i]=1 end -- if i end -- for i end -- for substr -- below reads from liststr a series of substr's -- where each substr contains an integer for substr in string.gmatch(liststr,"(%d+)") do i=substr+0 -- converts substr into the number i if i>=1 and i<=n_residues then newlist[i]=1 end -- if i end -- for substr return newlist end function Init () save.Quickload ( start_slot ) for i = 1 , #mutable_list do k = math.random ( n_polar_aas ) replacement_aa = string.sub ( polar_aas , k , k ) if ( structure.CanMutate ( mutable_list [ i ] , replacement_aa ) == true ) then structure.SetAminoAcid ( mutable_list [ i ] , replacement_aa ) end end selection.SelectAll () structure.WiggleSelected ( 2 , false , true ) -- sidechains end function PrintParameters () print ( "HNetworkProbe 2.1" ) print ( " n mutables " .. #mutable_list ) print ( "Amino acids to use : " .. polar_aas ) print ( "Sidechain minimum " .. r3 ( sidechain_minimum ) ) print ( "Using slots " .. first_qs_slot .. " to " .. last_qs_slot ) end function GetParameters () local dlog = dialog.CreateDialog ( "HNetworkProbe 2.1" ) dlog.use_unfrozen = dialog.AddCheckbox ( "Select unfrozen" , select_unfrozen ) dlog.mutate_list = dialog.AddTextbox ( "Mutate segments" , "" ) dlog.mlabela = dialog.AddLabel('List segs to mutate like 1-3,6,19-30,45-62') dlog.aa_list = dialog.AddTextbox ( "Amino acids" , polar_aas ) dlog.sidechain_minimum = dialog.AddSlider ( "Side chain minimum" , sidechain_minimum , -200 , -20 , 0 ) dlog.start_qs_slot = dialog.AddSlider( "Start quick save" , first_qs_slot , 1 , 99 , 0 ) dlog.end_qs_slot = dialog.AddSlider ( "End quick save" , last_qs_slot ,1 , 99 , 0 ) dlog.ok = dialog.AddButton ( "OK" , 1 ) dlog.cancel = dialog.AddButton ( "Cancel" , 0 ) if ( dialog.Show ( dlog ) > 0 ) then select_unfrozen = dlog.use_unfrozen.value mutate_list_ui = getlist(dlog.mutate_list.value) polar_aas = dlog.aa_list.value sidechain_minimum = dlog.sidechain_minimum.value first_qs_slot = dlog.start_qs_slot.value last_qs_slot = dlog.end_qs_slot.value return true else return false end end function main () n_residues = structure.GetCount () save.Quicksave ( start_slot ) if ( GetParameters () == false ) then return -- graceful exit end n_polar_aas = string.len ( polar_aas ) if ( select_unfrozen == true ) then GetListOfMutablesUnfrozen () else GetListOfMutablesSelected () end PrintParameters () if ( #mutable_list == 0 ) then print ( "No mutable residues found" ) exit (0) end if ( first_qs_slot > last_qs_slot ) then print ( "Invalid quicksave slot values" ) return end filter_list = filter.GetNames () print ( "Filters" ) print ( "" ) for i = 1 , #filter_list do if ( filter_list [ i ] == "Hydrogen Bond Network" ) then filter.Enable ( filter_list [ i ] ) print ( "Enabling " .. filter_list [ i ] ) else filter.Disable ( filter_list [ i ] ) print ( "Disabling " .. filter_list [ i ] ) end end band.DisableAll () undo.SetUndo ( false ) init_filter_score = GetFilterScore () print ( "Init HNet score " .. r3 ( init_filter_score ) ) math.randomseed ( os.time () ) next_qs_slot = first_qs_slot Init () while ( next_qs_slot <= last_qs_slot ) do n_it = n_it + 1 i = math.random ( #mutable_list ) nn = 0 valid_replacement_found = false -- a bit untidy this code repeat nn = nn + 1 k = math.random ( n_polar_aas ) replacement_aa = string.sub ( polar_aas , k , k ) if ( structure.CanMutate ( mutable_list [ i ] , replacement_aa ) == true ) then structure.SetAminoAcid ( mutable_list [ i ] , replacement_aa ) sidechain_score = current.GetSegmentEnergySubscore ( mutable_list [ i ] , "Sidechain" ) --print ( "nn " .. nn .. " " .. mutable_list [ i ] .. " " .. replacement_aa .. " " .. r3 ( sidechain_score ) ) if ( sidechain_score > sidechain_minimum ) then valid_replacement_found = true end end until ( ( nn > 5 ) or ( valid_replacement_found == true ) ) selection.SelectAll () --structure.ShakeSidechainsSelected ( 1 ) structure.WiggleSelected ( 2 , false , true ) -- sidechains filter_score = GetFilterScore () if ( filter_score > init_filter_score ) then print ( "Found network ( gain " .. r3 ( filter_score - init_filter_score ) .. " ) storing in qs " .. next_qs_slot ) save.Quicksave ( next_qs_slot ) next_qs_slot = next_qs_slot + 1 Init () end end cleanup () end function cleanup () print ( "Cleaning up" ) print ( "n_it " .. n_it ) undo.SetUndo ( true ) if ( next_qs_slot > first_qs_slot ) then print ( "Loading quick saves " .. first_qs_slot .. " to " .. next_qs_slot - 1 ) for i = first_qs_slot , next_qs_slot - 1 do save.Quickload ( i ) end end band.EnableAll () end --main () xpcall ( main , cleanup )

Comments