Profile


Name
eke3
ID
44419
Shared with
Public
Parent
None
Children
None
Created on
October 27, 2012 at 03:48 AM UTC
Updated on
October 27, 2012 at 03:48 AM UTC
Description

copied 743pm 10/25/12 from eke3dx.txt

Best for


Code


function Main() -- eke by jeff101 9/30/12 3pm -- goal is to randomly do shake and wiggle to improve the score -- -- adapted 10/17/12 from eke0d3.txt(=eke0d2.txt=eke0d.txt) to eke1.txt -- adapted 10/22/12 from eke1d.txt to eke2.txt -- adapted 10/25/12 from eke2d.txt to eke3.txt -- -- last updated 1030pm 10/25/12 -- rtot=structure.GetCount() btot=band.GetCount() ostime=os.time() math.randomseed(ostime) print('Running eke on puzzle '..puzzle.GetName()..'\n with Puzzle ID '..puzzle.GetPuzzleID()..', '..rtot..' residues, and '..btot..' bands:') print(' ') print('ntries is how many loops since last score improvement.') print('length of each loop generally rises as ntries rises.') print('eke will run until you force it to quit.') print(' ') mutok=0 mutstr=' ' canmut={} for num=1,rtot do if structure.IsMutable(num) then if mutok>0 and mutok==10*math.floor(mutok/10) then mutstr=(mutstr..'\n ') end -- if mutok mutok=mutok+1 canmut[num]=1 mutstr=(mutstr..num..' ') else -- not mutable canmut[num]=0 end -- if IsMutable end -- for num if mutok>0 then print('Residues'..mutstr..'('..mutok..' in all) can be mutated.\n ') end -- if mutok qflag=0 steps={5, 5, 5, 5, 1, 5, 5, 5, 5, 1, 1, 1, 1} ways=#steps -- set ways to length of steps newscore=current.GetScore() -- get current score recentbest.Save() -- save current score's pose indx=0 ntries=1 while qflag==0 do way=round(1+(ways-1)*math.random()) -- random number from 1 to ways if (mutok>0 and way~=11) or (mutok==0 and way~=11 and way~=12) then -- mutation is allowed -- 1 step of way 11 takes too long for 30 residues 10/25/12 if mutok==0 and (way==11 or way==12) then print('ERROR: way='..way..' (mutation) is not allowed when mutok='..mutok..'.') end -- if mutok osdate=os.date() indx=indx+1 ciold=behavior.GetClashImportance() if way==4 or way==9 then ci=math.random() -- random number from 0 to 1 behavior.SetClashImportance(ci) else ci=ciold end -- if way==4 or way==9 print('Loop '..indx..': score='..round3(newscore)..' ci='..round3(ci)..' ntries='..ntries..' ('..osdate..'):') stp=round(1+(math.ceil(steps[way]*ntries*5/ways)-1)*math.random()) -- random number from 1 to math.ceil(steps[way]*ntries*5/ways) if way==1 then print(' (1) WiggleAll '..stp..' steps.') structure.WiggleAll(stp) elseif way==2 then print(' (2) WiggleAll Backbone '..stp..' steps.') structure.WiggleAll(stp,true,false) elseif way==3 or way==4 then print(' ('..way..') WiggleAll Sidechains '..stp..' steps.') structure.WiggleAll(stp,false,true) if way==4 then behavior.SetClashImportance(ciold) -- reset to old clashing importance end -- if way==4 elseif way==5 or way==10 then print(' ('..way..') ShakeSidechainsAll '..stp..' steps.') structure.ShakeSidechainsAll(stp) elseif way==6 then print(' (6) LocalWiggleAll '..stp..' steps.') structure.LocalWiggleAll(stp) elseif way==7 then print(' (7) LocalWiggleAll Backbone '..stp..' steps.') structure.LocalWiggleAll(stp,true,false) elseif way==8 or way==9 then print(' ('..way..') LocalWiggleAll Sidechains '..stp..' steps.') structure.LocalWiggleAll(stp,false,true) if way==9 then behavior.SetClashImportance(ciold) -- reset to old clashing importance end -- if way==9 elseif way==11 then print(' (11) MutateSidechainsAll '..stp..' steps.') oldseq=getseq(1,rtot) structure.MutateSidechainsAll(stp) checkseq(oldseq,1,rtot) elseif way==12 or way==13 then indok=0 while indok==0 do indok=1 indx2=round(1+(5-1)*math.random()) -- random number from 1 to 5 indx1=round(1+(rtot-indx2)*math.random()) -- random number from 1 to rtot-indx2 indx2=indx1+indx2 if way==12 then for num=indx1,indx2 do indok=indok*canmut[num] -- any zeros in canmut will make indok be 0 end -- for num end -- if way end -- while indok -- all indices must be mutable to use way 12 oldsel=getsel(rtot) -- find & print original selection selection.DeselectAll() -- select none selection.SelectRange(indx1,indx2) -- select just from indx1 to indx2 newsel=getsel(rtot) -- find & print new selection if way==12 then print(' (12) MutateSidechainsSelected '..indx1..'-'..indx2..' for '..stp..' steps.') oldseq=getseq(indx1,indx2) structure.MutateSidechainsSelected(stp) checkseq(oldseq,indx1,indx2) elseif way==13 then print(' (13) RebuildSelected '..indx1..'-'..indx2..' for '..stp..' steps.') structure.RebuildSelected(stp) end -- if way setsel(oldsel,rtot) -- restore & print original selection end -- if way oldscore=newscore newscore1=current.GetScore() -- get current score recentbest.Restore() -- restore best since last recentbest.Save() newscore=current.GetScore() -- get current score recentbest.Save() -- save best again if newscore>oldscore then str=(' Score rose from '..round3(oldscore)..' to '..round3(newscore)) elseif newscore==oldscore then str=(' Score did not rise above '..round3(oldscore)) else str=(' Score fell from '..round3(oldscore)..' to '..round3(newscore)) end if newscore1<newscore then str1='but' str2='restoring' elseif newscore1==newscore then str1='and' str2='keeping' else str1='and' str2='mistakenly restoring' end print(str..' '..str1..' ended with '..round3(newscore1)..', so '..str2..' '..round3(newscore)..'.') if newscore1>newscore then print(' ERROR: '..round3(newscore1)..' > '..round3(newscore)..' should not occur.') end if oldscore>=newscore then ntries=ntries+1 else ntries=1 end -- if oldscore>=newscore end -- if mutok end -- while qflag end -- Main() -- below rounds val to the nearest thousandth to get res function round3(val) local res=round(val*1000)/1000 return res end -- round3() -- below rounds val to the nearest integer to get res function round(val) local res=math.floor(val) if val-res>=0.5 then res=res+1 end return res end -- round() function getsel(rtot) local sel={} local num local seltot=0 local selstr=' ' for num=1,rtot do sel[num]=selection.IsSelected(num) if sel[num] then selstr=(selstr..num..' ') seltot=seltot+1 end -- if sel end -- for num print(' '..seltot..' residues'..selstr..'are selected.') return sel end -- getsel() function setsel(sel,rtot) selection.DeselectAll() local num local seltot=0 local selstr=' ' for num=1,rtot do if sel[num] then selection.Select(num) selstr=(selstr..num..' ') seltot=seltot+1 end -- if sel end -- for num print(' '..seltot..' residues'..selstr..'just got re-selected.') end -- setsel() function getseq(indx1,indx2) local seq={} local num for num=indx1,indx2 do seq[num]=structure.GetAminoAcid(num) end -- for num return seq end -- getseq() function checkseq(seq,indx1,indx2) local num local tot=0 local str=' ' for num=indx1,indx2 do aa=structure.GetAminoAcid(num) if aa~=seq[num] then tot=tot+1 str=(str..seq[num]..num..'->'..aa..num..' ') end -- if aa end -- for num if tot>0 then print(' Mutated residues'..str..' ('..tot..' in all).') else print(' No mutations succeeded.') end -- if tot end -- checkseq() Main()

Comments


jeff101 Lv 1

eke3 does rebuild, mutate, shake, or wiggle all, backbone, or sidechains at random to improve the score. Sometimes changes clashing importance randomly before wiggling sidechains. Does not tolerate loss. Spends longer with each method if stuck. If score rises and then falls during a particular stage, it keeps the highest score found during the stage. eke3 runs until you force it to quit.