Icon representing a recipe

Recipe: Comp 2.2 Rav3n for Conditions

created by brow42


Comp 2.2 Rav3n for Conditions
Shared with
Comp 2.2 from Rav3n V1toV2
Created on
September 08, 2013 at 20:35 PM UTC
Updated on
September 08, 2013 at 20:35 PM UTC

Modification of Rav3n's Compress 2.2, that only accepts valid scores.

Best for


--[[ Rav3n_pl Compressor v2.1 trying to compress/decompress protein accepting loss of points between pulls ]]-- ----------- options below VVVVV --------------------- cLoops=150 --<<< SET NUMBER OF LOOPS decomp=false --true --true for DeCompression instead of compression modualtor=false --true --changing compression/decompression each loop useRegions={ --set regions that have to be used in all bands --{1,20}, --there are exaples, uncomment and edit --{25,55}, --{100,210}, } compressFrac=5 --make bands shorter by that much points minSkip=15 --minimum segment distance between banded segments numBands=8 --how many bands use at once fastQstab=true --false --true --only 1 shake and 1 wiglle when true useFuze=true -- use Fuze after qStab fuzeScore=-1 --how close we have to be to run Fuze allLoop=true --false --work in all-loop mode. sometimes work better than structure mode :) S2H=false --all bands are between sheets and helixes struct=false --all bands have at least one end on structure (not loop) noLoops=false --band can`t have any end on loop lastBands=0.3 --starting band str bandStr=1.0 -- max band strenght minDist=7 --mimum band length slowBands=true --bands strenght are raised few times till score drops by % percLoss=1 --pulling stops when score drops by that percent (ie 2=200pts when 10k pts) repeatGood=false --true --repeating good bands if true pullingCI=1 --0.6--clash impotrance during pull maxLoss=30 --maximum acceptable LOSS after Fuze. also lowering fuzeScore reloadBest=5 --reload best solution after that many worst ones normal=true --set false for exploration puzles ------------ end of options ^^^^^^ -- "lua v1 in v2" library by rav3n_pl --just add it in front of your v1 code and use v2 and v1 code in v2 scripts :) -- print(arg1[,...,argN]) no change :) function are_conditions_met() return current.AreConditionsMet() end function band_add_segment_segment(sgi1, sgi2) band.AddBetweenSegments(sgi1, sgi2) end function band_delete(bndIdx) if bndIdx~= nil then band.Delete(bndIdx) else band.DeleteAll() end end function band_disable(bndIdx) if bndIdx~=nil then band.Disable(bndIdx) else band.DisableAll() end end function band_enable(bndIdx) if bndIdx~=nil then band.Enable(bndIdx) else band.EnableAll() end end function band_set_length(bndIdx, len) band.SetGoalLength(bndIdx, len) end function band_set_strength(bndIdx, str) band.SetStrength(bndIdx, str) end function get_band_count() return band.GetCount() end function deselect_all() selection.DeselectAll() end function deselect_index(sgn) selection.Deselect(sgn) end function select_all() selection.SelectAll() end function select_index(sgn) selection.Select(sgn) end function select_index_range(sg1,sg2) selection.SelectRange(sg1,sg2) end function do_freeze(bbone,schain) freeze.FreezeSelected(bbone,schain) end function do_unfreeze_all() freeze.UnfreezeAll() end function do_global_wiggle_all(iters) structure.WiggleAll(iters,true,true) end function do_global_wiggle_backbone(iters) structure.WiggleAll(iters, true,false) end function do_global_wiggle_sidechains(iters) structure.WiggleAll(iters,false,true) end function do_local_rebuild(iters) structure.RebuildSelected(iters) end function do_local_wiggle(iters) structure.LocalWiggleSelected(iters,true,true) end function do_mutate(iters) structure.MutateSidechainsSelected(iters) end function do_shake(iters) structure.ShakeSidechainsSelected(iters) end function do_sidechain_snap(sgn, snap) rotamer.SetRotamer(sgn, snap) end function get_sidechain_snap_count(sgn) return rotamer.GetCount(sgn) end function load_structure() save.LoadSecondaryStructure() end function save_structure() save.SaveSecondaryStructure() end function quickload(slot) save.Quickload(slot) end function quicksave(slot) save.Quicksave(slot) end function get_exploration_score() return current.GetExplorationMultiplier() end function get_ranked_score() return current.GetScore() end function get_score() return current.GetEnergyScore() end function get_segment_distance(sg1,sg2) return structure.GetDistance(sg1,sg2) end function get_aa(sn) return structure.GetAminoAcid(sn) end function get_segment_count() return structure.GetCount() end function get_ss(sn) return structure.GetSecondaryStructure(sn) end function is_hydrophobic(sn) return structure.IsHydrophobic(sn) end function replace_aa(aa) for i=1,structure.GetCount() do if selection.IsSelected(i) then structure.SetAminoAcid(i, aa) end end end function replace_ss(ss) for i=1,structure.GetCount() do if selection.IsSelected(i) then structure.SetSecondaryStructure(i,ss) end end end function get_segment_score(sg) return current.GetSegmentEnergyScore(sg) end function get_segment_score_part(score_part,sg) return current.GetSegmentEnergySubscore(sg,score_part) end function reset_puzzle() puzzle.StartOver() end function restore_abs_best() absolutebest.Restore() end function restore_credit_best() creditbest.Restore() end function reset_recent_best() recentbest.Save() end function restore_recent_best() recentbest.Restore() end function set_behavior_clash_importance(ci) behavior.SetClashImportance(ci) end -- end of library p=print CI=set_behavior_clash_importance segCnt=get_segment_count() while get_ss(segCnt)=="M" do segCnt=segCnt-1 end function Score() local s=0 if normal==true then s=get_score(true) else s=get_ranked_score(true) end return s end function round(x)--cut all afer 3-rd place return x-x%0.001 end function abs(x) if x<0 then x=-x end return x end function round(x)--cut all afer 3-rd place return x-x%0.001 end function down(x) return x-x%1 end function Wiggle(how, iters, minppi) --score conditioned recursive wiggle/shake if how==nil then how="wa" end if iters==nil then iters=6 end if minppi==nil then minppi=0.1 end if iters>0 then iters=iters-1 local sp=Score() if how == "s" then do_shake(1) elseif how == "wb" then do_global_wiggle_backbone(2) elseif how == "ws" then do_global_wiggle_sidechains(2) elseif how == "wa" then do_global_wiggle_all(2) end if Score()-sp > minppi then return Wiggle(how, iters, minppi) end end end function AllLoop() --turning entire structure to loops local ok=false for i=1, segCnt do local s=get_ss(i) if s~="L" then save_structure() ok=true break end end if ok then select_all() replace_ss("L") end end function qStab() CI(0.1) Wiggle("s",1) select_all() if fastQstab==false then CI(0.4) Wiggle("wa",1) CI(1) Wiggle("s",1) end CI(1) Wiggle() end function FuzeEnd() CI(1) Wiggle("wa",1) Wiggle("s",1) Wiggle() SaveBest() end function Fuze1(ci1,ci2) CI(ci1) Wiggle("s",1) CI(ci2) Wiggle("wa",1) end function Fuze2(ci1,ci2) CI(ci1) Wiggle("wa",1) CI(1) Wiggle("wa",1) CI(ci2) Wiggle("wa",1) end function reFuze(scr,slot) local s=Score() if s<scr then quickload(slot) else scr=s quicksave(slot) end return scr end function Fuze(slot) local scr=Score() quicksave(slot) select_all() Fuze1(0.3,0.6) FuzeEnd() scr=reFuze(scr,slot) Fuze2(0.3,1) SaveBest() scr=reFuze(scr,slot) Fuze1(0.05,1) SaveBest() scr=reFuze(scr,slot) Fuze2(0.7,0.5) FuzeEnd() scr=reFuze(scr,slot) Fuze1(0.07,1) SaveBest() reFuze(scr,slot) end --[[ Tlaloc`s math library ------------------------------------------------------------------------ The original random script this was ported from has the following notices: Copyright (c) 2007 Richard L. Mueller Hilltop Lab web site - http://www.rlmueller.net Version 1.0 - January 2, 2007 You have a royalty-free right to use, modify, reproduce, and distribute this script file in any way you find useful, provided that you agree that the copyright owner above has no warranty, obligations, or liability for such use. ------------------------------------------------------------------------ ]]-- local lngX = 1000 local lngC = 48313 local function _random(m,n) local A_Hi = 63551 local A_Lo = 25354 local M = 4294967296 local H = 65536 function _MWC() local S_Hi = math.floor(lngX / H) local S_Lo = lngX - (S_Hi * H) local C_Hi = math.floor(lngC / H) local F1 = A_Hi * S_Hi local F2 = (A_Hi * S_Lo) + (A_Lo * S_Hi) + C_Hi lngX = ((F2 - (math.floor(F2 / H) * H)) * H) + (A_Lo * S_Lo) + lngC - (C_Hi * H) lngX = lngX - (math.floor(lngX / M) * M) lngC = math.floor((F2 / H) + F1) return lngX end if n == nil and m ~= nil then n = m m = 1 end if (m == nil) and (n == nil) then return _MWC() / M else if n < m then return nil end return math.floor((_MWC() / M) * (n - m + 1)) + m end end local function _abs(value) if value < 0 then return -value else return value end end local function _floor(value) return value - (value % 1) end local function _randomseed(s) if s==nil then s=math.abs(Score()) s=s%0.001 s=1/s while s<10000000 do s=s*10 end s=s-s%1 end lngX = s end math= { abs = _abs, floor = _floor, random = _random, randomseed = _randomseed, } math.randomseed() --[[ End math library ]]-- bestScore=Score() function SaveBest() if not current.AreConditionsMet() then return end local g=Score()-bestScore if g>0 then p("Gained another ",round(g)," pts.") bestScore=Score() quicksave(3) end end function MakeBands(num) local done=false local s1=math.random(segCnt) local s2=math.random(segCnt) if s1>s2 then s1,s2=s2,s1 end local d=get_segment_distance(s1,s2) if s2-s1>=minSkip and d>=minDist then done=true end if (done and #useRegions>0) then done=false for a=1,#useRegions do local ss=useRegions[a][1] local se=useRegions[a][2] if (s1>=ss and s1<=se) or (s2>=ss and s2<=se) then done=true break end end end local ss1=get_ss(s1) local ss2=get_ss(s2) if (done and noLoops) then if ss1=="L" or ss2=="L" then done=false end end if (done and struct) then if ss1=="L" and ss2=="L" then done=false end end if (done and S2H) then if (ss1=="E" or ss2=="E") and (ss1=="H" or ss2=="H") and (ss1~=ss2) then done=true else done=false end end if done then num=num-1 mkBand(s1,s2) bands[#bands+1]={s1,s2} end if num>0 then return MakeBands(num) end --tail call end function mkBand(s1,s2) band_add_segment_segment(s1,s2) local len=get_segment_distance(s1,s2) if decomp==true then len=len+compressFrac else len=len-compressFrac end if len<3 then len=3 end --not make shorter band, useless band_set_length(get_band_count(),len) end bands={} function Repeat_bands(bands) band_delete() for i=1,#bands do local s1=bands[i][1] local s2=bands[i][2] mkBand(s1,s2) end end function Bandstr(str) --set all band strengt if str<0.1 then str=0.1 end if str>10 then str=10 end for i=1, get_band_count() do band_set_strength(i, str) end end function SaveRB(slot) quicksave(slot) restore_recent_best() SaveBest() quickload(slot) end sscore=Score() --starting score function Compressor(numTries) p("Starting Compressor v2, ",numTries," loops.") if normal==false then p("Using exploration options.") end if allLoop then AllLoop() end quicksave(3) quicksave(7) --save state for losing badOnes=0 reset_recent_best() local best=false for i=1,numTries do loss=Score()*percLoss/100 --pulling till we lost some points band_delete() if best==true and repeatGood==true then p("Repeating last bands.") if modualtor==true then --switch decomp= not decomp end Repeat_bands(bands) else bands={} MakeBands(numBands) end local ls=Score() local tx="ompressing." if decomp==true then tx="Dec"..tx else tx="C"..tx end p("Loop ",i," of ",numTries," started. ",tx," Current score: ",round(ls)) CI(pullingCI) select_all() reset_recent_best() if slowBands then for str=lastBands,bandStr,0.07 do--search enough band strenght to move restore_recent_best() --because sometimes it makes points during pull :D local ss=Score() Bandstr(str) Wiggle("wb",1) if ss-Score()>loss then lastBands=str-0.1 break end end else Bandstr(bandStr) Wiggle("wb",1) end SaveRB(4) --because sometimes it missing fractions band_delete() qStab() if useFuze and Score()> (bestScore-fuzeScore) then SaveBest() Fuze(4) else SaveBest() end if maxLoss>0 then if Score()>bestScore-maxLoss then quicksave(7) --save actual "best" solution else badOnes=badOnes+1 if badOnes >=reloadBest then badOnes=0 quickload(3) else quickload(7) --load "second best" end end else quickload(3) end local es=Score() if es>ls then best=true else best=false end --repeating all bands making points p("Loop ",i," gain ",round(es-ls)," ;total gain ",round(bestScore-sscore)) if modualtor==true then --switch decomp= not decomp end end quickload(3) if allLoop then load_structure() end p("Total gain: ",round(Score()-sscore)) end --main call Compressor(cLoops) --end of scipt


brow42 Lv 1

This is identical to regular Compress, except only solutions that satisfy the required conditions are kept. It does this with the AreConditionsMet() call instead of creditbest.Quickload(). Its solutions won't be as high, but they won't sit on the edge of validity, either.

Only required conditions are checked….bonus/penalties do not affect validity.