Code
--Maaa (Mute to Autorized Amino Acids) by Bruno Kestemont 2/10/2013 - 16/11/2015
--[[
--Mutate autorized amino acids
--Essaie tous les aa preferes sur un segment selectionne -- on an idea by roukess
--Mute alowed aa
--start generic variables section-------------------------
--NEW: if there is something else than AA in note, autorised by default
--25/8/2013: Stanley 1.1 update
--24/9/2013 random order of segments + fixed cancel bug
--13/11/2013: preserve protein stability on first round and on low score
--03/03/2014 1.3.1 added log score max after mutates
--29/03/14 1.4 best preserve from exploding in dialog
--14/04/2014 best display and best kill best management ver1.6
--12/04/2014 added prohibided ver 1.7
--21/04/2004 randomize order of chains ver 1.8
-- ver 1.9 16/10/2014 delete wiggle segment on preserve (it was disturbing the structure)
--disable filter management (most design puzzles need the filter)
-- ver 1.9.1 replaced Shake by QuickShake; added notes
-- ver 1.9.2 corrected prohibided aa list
-- ver 1.9.3 debugged alienkill + achieved translation to en
-- ver 2.0 select AAs to mutate
-- ver 2.1 option to work on locked -- 14/05/2015
-- ver 2.2 added rotamers (only for potential H-binders), experimental
-- ver 2.2.1 added list of donors-receptors, informing on neutral in dialog
-- ver 2.2.2 fixed selection AAs
-- ver 2.2.3 more conservative on further loops (wiggle all comes later)
-- ver 2.2.4 options for mix segment table -- 16/11/2015
-- ver 2.2.5 random seed for random in order not to always start from same list
-- ver 2.2.6 filter bonus condition afcppg (accepted filter cost per point gained)
-- ver 2.2.7 probabilistic check on jeff101 AA properties
-- default = frequency in Nature
-- if SSOOC, the frequency is given by the AA preference of existing SS
-- ver 2.2.8 undo.SetUndo
-- ver 2.3 added option preserve hydrophobicity
-- ver 2.4 GRRR adapted filter setting to new lua commands: return2GlobalOriginalFilterSetting()
-- ver 2.4.1 corrected some things in filter management
Updated Stanley to ver 1.2
-- ver 2.4.2 I forgot to enable HBonding !!!!!!!!!!! 17/4/2020
-- ver 2.4.3 changed default selection (mutate only !) thanks to malphis
-- when HBonding puzzle, default not structure prefered (otherwise we have no bonding candidate for helices)
-- ver 2.4.4 Not trying lysine (k) and arginine (r) in Hbond puzzles
fixed segment setminus
-- ver 2.4.5 better filter settings 18/9/2020 (avoiding to changing filters when not choosing fast filters)
-- ver 2.4.6 added selection of unfrozen sidechains
-- ver 2.5.0 adding an option to select sidechains of the same volume range (quicker): CompareVolume
-- ver 2.5.1 fixed log "mutated to" when it's not mutated using same volume.
-- TO DO: work only on hydrophobic etc (add in tvdl?)
--TO DO: come back to main menu after selection
--TO DO (hbond network): Trying all combinations of pairs of linked segments (on very small number of segments !!)
--TO DO: better filter management in order to be able to choose (or weigt) filters
SLOTS:
3= best
4= preferred (could be low in case of alienkill)
5= rotamers (temp)
8= archive solution before 9
9 --pour initialiser l'antepenultieme solution
10 --pour initialiser la version evoluable
11 --pour initialiser la version actuelle (peut descendre si alienkill)
]]--
recipename="Maaa 2.5"
undo.SetUndo(false)
global_ci=1 -- on peut changer
--chains={"g";"a";"v";"c";"p";"t";"s";"i";"l";"n";"d";"m";"h";"q";"e";"f";"k";"y";"r";"w"}--all of them
chains={'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'y'} -- all of them
--chains={"G";"A";"V";"C";"P";"T";"S";"I";"L";"N";"M";"Q";"F";"Y";"W"} --desired for TNT: no ASP, GLU, ARG, LYS, HIS
aaall={'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'y'}
aaphilic={'d','e','h','k','n','q','r','s','t'}
aaphobic={'a','c','f','g','i','l','m','p','v','w','y'}
aasheet={'t','c','f','i','v','w','y'}
aahelix={'e','k','q','r','a','l','m'}
aaloop={'d','h','n','s','g','p'}
aanotloop={'t','c','f','i','v','w','y','e','k','q','r','a','l','m'}
aanothelix={'d','h','n','s','g','p','t','c','f','i','v','w','y'}
aanotsheet={'e','k','q','r','a','l','m','d','h','n','s','g','p'}
aasheetphilic={'t'}
aasheetphobic={'c','f','i','v','w','y'}
aahelixphilic={'e','k','q','r'}
aahelixphobic={'a','l','m'}
aaloopphilic={'d','h','n','s'}
aaloopphobic={'g','p'}
aanotloopphilic={'t','e','k','q','r'}
aanotloopphobic={'c','f','i','v','w','y','a','l','m'}
aanothelixphilic={'t','e','k','q','r'}
aanothelixphobic={'c','f','i','v','w','y','g','p'}
aanotsheetphilic={'d','e','h','k','n','q','r','s'}
aanotsheetphobic={'a','l','m','g','p'}
aadonnors= {'s','t','n','q','r','h','k','d','e','w','y'} -- +1 (or may be it's acceptor? To verify
aaacceptors= {'s','t','n','q','h','d','e','y'} -- -1
aaneutral= {'v','l','m','p','i','a','c','f','g'} -- non H binding {v l m p i a c f g}
aabonding= {'s','t','n','q','r','h','k','d','e','w','y'} -- = aadonnors {s t n q r h k d e w y}
aahelixbonding= {'q','r','k','e'}
aasheetbonding= {'t','w','y'}
aaloopbonding= {'s','n','h','d'}
aabondingbuns= {'k','r'} -- new to retrieve from Hbond neworks
aabondingphilic= {'s','t','n','q','r','h','k','d','e','w','y'} -- = aadonnors
aahelixbondingphilic= {'q','r','k','e'} -- = aahelixphilic
aasheetbondingphilic= {'t'} -- = aasheetphilic
aaloopbondingphilic= {'s','n','h','d'} -- = aaloopphilic
CompareVolume= true -- skip sidechains with very different volumes (quick)
MaxVolumeRatio = 1.2 -- 1.39 is the ratio between serine and glycine. Its from 1 to 3.4
rapide= true
superquick=false
FiltreRap=500
AlienKill=false
preserve=false -- new BK 13/11/13 no local wiggle all to preserve the stability, started true for score<7000
preserveH=false -- new BK 17/10/2014 no wiggle (neither selected wiggle) only for first loop
hydropreserve=false -- new BK 30/5/2018 preserve hydrophobicity
autorisestr= true -- reinitialized in saasooc for each segment
filtermgt=false
OriginalFilterSetting = filter.AreAllEnabled()
save.Quicksave(9) --pour initialiser l'antepenultieme solution
save.Quicksave(10) --pour initialiser la version evoluable
save.Quicksave(11) --pour initialiser la version actuelle (peut descendre si alienkill)
--other slots:
--slot 4= best avant et apres aftermute
compteur=0 -- intialise le compteur de WORKONBIS
useRegionBool={}
--useSpeclistBool={}
--start generic Stanley variables section-------------------------
p=print --"quicker" print
segCnt=structure.GetCount()
--segCnt=segCnt-1 -- for lingard puzzles only! sera initialise par seglock
flagligand=false
segCnt2=segCnt -- cas de ligands
while structure.GetSecondaryStructure(segCnt2)=="M" do segCnt2=segCnt2-1 flagligand=true end
segStart=1 --start from (Default option for JET)
segEnd=segCnt2 --end seg: nil=end of protein (Default option for JET) -- duplicat a verifier
badpuzzle={'713'} -- list of not implemented puzzles - to be edited on each bug
NOTIMPLEMENTED=false
WORKON={{1,segCnt2}}
WORKONBIS={}
normal= (current.GetExplorationMultiplier() == 0)
Cyslist={}
savebridges=false --default no bridgechecking
nrofbridges=0
HASMUTABLE=false
HASOTHER=false
OTHERWEIGHT=0
PROBABLESYM=false
PROBABLEFILTER=false
afcppg=1 -- accepted filter cost per point gained -1 forces filter gains
FILTERON=filter.AreAllEnabled()
SEPSIS=false
ELECTRON=false
HBONDPUZZLE=false
sym= 1 --Options: 1 normal; 2 dimer; 3 trimer; 4 tetramer (dimer of dimer) etc.
FREEDESIGN=false
timeLeft=os.difftime(puzzle.GetExpirationTime(),os.time())/86400 -- en heures
startTime=os.time() -- en secondes
startTimeLoop=os.time()
pprankrel=0.015*timeLeft/8 --pts per rank relative to score. Actuellement calibr sur 670 a 8 jours de la fin
groupscore=10*(800-scoreboard.GetGroupScore())
grouprank=scoreboard.GetGroupRank()
absbestscore=10*(800-absolutebest.GetEnergyScore())
--WorkOnLocked=false --will also mutate locked (no wiggle? to be implemented)
lang="en"
--end generic Stanley variables section--------------------------
---------------------------------------------------------
--Start merged Stanley and recipe functions
function checkbadpuzzle()
if NOTIMPLEMENTED then
print(i18.maaa.WARNING)
end
end
function setlanguage()-- New BK 10/4/13
local player=user.GetPlayerName()
local group=user.GetGroupName()
if group=="L'Alliance Francophone" or player=="marie_s" or player=="bruno.kestemont" or player=="roukess" then
lang="fr"
else
lang="en"
end
return lang
end
function multilingual(lang)-- New BK 10/4/13, 25/8/13 WARNING: TO BE EDITTED FOR EACH RECIPE
if lang=="fr" then
-- translation table. do NOT replace %-letter combos
i18={
intro={
title="Stanley explorer 1.1 par BK",
exploration="Exploration du puzzle:"
},
ask={
ok="OK",
cancel="Annuler",
abandon="Pas de mutable. Rien muter !",
options={
segStart="Du segment ",
segEnd="au segment ",
possibleaa="AAs permis: ",
prohibided="aa interdits: ",
randomly="Ordre alatoire",
mixtablesIntro="1=croiss.; 2=dcr.; 3=alat.; 4=ext.; 5=int.; 6=feuilles",
mixtables="Ordre: ",
prefHbond="H-bonding",
Hydrophobic="Hydrophe",
Hydrophilic="Hydrophile",
prefhelix="pour helice",
prefsheet="pour feuillet",
prefloop="pour loop",
sooc="OU seulement pour structure actuelle",
AlienKill="Eliminer les intrus (peut engendrer des pertes)",
l1="(peut engendrer des pertes)",
rapide="Vite !",
preserve="Protger la structure (plus rapide, moins de points)",
superquick="Seulement muter (trs rapide)",
onlymutate="Ne pas tester les rotamers (plus rapide)",
hydropreserve="Prserver l'hydrophobicit",
filtermgt="Wiggle sans filtre (rapide)"
},
selection={
-- pas traduit pour garder exportabilite de ce module tvdl
},
},
stanley={
unlocked="-Libre: ",
bridges=" ponts;",
currenttarget="Objectif actuel: ",
cysteins=" cystides;",
distance2target="Distance l'objectif = ",
endstanley="Fin du module d'exploration Stanley",
to=" to ",
thereare="-Il y a ",
nolock="-pas de lock; ",
ligands="-ligands: ",
nobridge="-pas de pont;",
nobridgepossible="-pas de possibilit de pont;",
noligand="-pas de ligand;",
sepsis="Sepsis",
electron="Electron Density",
freedesign="-probablement free design;",
lookingtarget="Recherche d'un objectif",
maybe=" -peut-tre ",
nofreedesign="-pas free design;",
nomutable="-pas mutable;",
otherscore="-autres scores d'un poids suppplmentaire de ",
nootherscore="-pas d'autre score;",
mutable="-mutable;",
mutables=" mutables;",
setoftargets="Jeu de cibles: ",
sym="-symtrique",
symdescr="-la destription parle de symtrique ...",
topscore="Top score estim, sans filtre: ",
nosym=" ... pas symtrique",
dimer=" ... dimre",
trimer=" ... trimre",
tetramer=" ... tetramre ou dimre de dimre",
pentamer=" ... pentamre"
},
recipe={
is3="tat du script restaur.",
m3a="Traitement des paramtres initiaux termin.",
m3b="Parcours systmatique de la protine.",
lw1="Rtablissement du meilleur score.",
lw2="Rtablissement de la structure secondaire.",
lw3="Rtablissement des bandes.",
lw4="Sauvegarde de l'tat du script dans note 1",
de1="Arrt utilisateur.",
de2="Erreur inattendue dtecte.",
de3="Ligne d'erreur : %i.",
de4="Message d'erreur : %s."
},
maaa={
intro1="Muter vers AAs autoriss ("..recipename..")",
intro2="Score de DEPART= ",
intro3="1 nuit de travail PC. Bonne nuit ",
running1="",
running2=" en cours ",
runningdessert="PETIT DESSERT n ",
maindishes="PLAT PRINCIPAL",
nogain="... ne gagna plus rien en ",
gain1="... gagna ",
gain2=" points en ",
score="Score actuel ",
muteseg="Mute le segment ",
initially="Initialis vers: ",
trying="Essai vers: ",
cost=". Cout: ",
gainT=". >>>>Gain Maaa= ",
gainin="<<<< en ",
gaining="(gain en cours: ",
BestSegGain="Meilleur gain AA: ",
gained=">>Gain: ",
sorry="Dsol ! Aliens muts avec perte de: ",
timeleft="Temps restant: ",
hours=" heures.",
optionsFast="Options: Rapide =",
optionsPreserve="Protger structure= ",
maygain="Peut encore gagner ",
cleaning="Nettoyage",
restorestructure="Rtablissement de la structure secondaire",
savingbest="Enregistrement du meilleur rsultat",
notmutated="Pas mut",
mutatedTo="Segment mut vers ",
mutatedsegs="segments muts:",
alreadydone=" a dja te utilise.",
signalerror="Merci de signaler ce bug a l'auteur",
WARNING="ATTENTION: puzzle non couvert"
}
}
else
i18={
intro={
title="Stanley explorer 1.1 by BK",
exploration="Puzzle exploration:"
},
ask={
ok="OK",
cancel="Cancel",
abandon="No mutable found. Nothing to mutate !",
options={
segStart="From segment ",
segEnd="to ",
possibleaa="Included AAs: ",
prohibided="Excluded AAs: ",
randomly="Random segments",
mixtablesIntro="1=up; 2=back; 3=random; 4=out; 5=in; 6=slice",
mixtables="Order: ",
prefHbond="Only try H-bonding AAs",
Hydrophobic="Try hydrophobic",
Hydrophilic="Try hydrophilic",
prefhelix="for helix",
prefsheet="for sheet",
prefloop="for loop",
sooc="OR try best AA for current Sec. Struct",
AlienKill="Kill aliens (can cause losses)",
l1="(can cause losses)",
rapide="Quick !",
preserve="Protect structure (fast, less points)",
superquick="Express (only mutate)",
onlymutate="Don't test rotamers (quicker)",
hydropreserve="Keep hydrophobicity",
filtermgt="Wiggle without slow filter"
},
selection={
-- not translated in order to maintain exportabilty of this tvdl module
},
},
stanley={
unlocked="-Unlocked: ",
to=" to ",
bridges=" bridges;",
currenttarget="Current target: ",
cysteins=" cysteins;",
distance2target="Distance to target = ",
endstanley="End of Stanley exploration module",
thereare="-There are ",
nolock="-no lock; ",
ligands="-ligands: ",
nobridge="-no bridge;",
nobridgepossible="-no possibility of bridge;",
noligand="-no ligand;",
sepsis="Sepsis",
electron="Electron Density",
freedesign="-probable free design;",
lookingtarget="Looking for a target",
maybe=" -may be ",
nofreedesign="-not free design;",
nomutable="-no mutable;",
mutable="-mutable;",
mutables=" mutables;",
otherscore="-other scores; additional weight of ",
nootherscore="-no other score;",
setoftargets="Set of targets: ",
sym="-symmetric",
symdescr="-description says symmetric ...",
topscore="Estimated unfiltered top score: ",
nosym=" ... not symmetric",
dimer=" ... Dimer",
trimer=" ... Trimer",
tetramer=" ... Tetramer or dimer of dimer",
pentamer=" ... Pentamer"
},
recipe={
is3="Script state loaded.",
m3a="Initial parameters treatment completed.",
m3b="Whole protein walking.",
lw1="Loading Highscore...",
lw2="Loading secondary structure...",
lw3="Loading bands...",
lw4="Saving script state in note 1", -- added BK 21/3/13
de1="User stop.",
de2="unexpected error detected.",
de3="Error line: %i.",
de4="Error : %s."
},
maaa={
intro1="Mutate to Autorised AAs ("..recipename..")",
intro2="START Score= ",
intro3="1 night PC work. Good night ",
running1="Running ",
running2="",
runningdessert="Now running dssert n ",
maindishes="MAIN DISHES",
nogain="... no additional gain in ",
gain1="... gained another ",
gain2=" points in ",
score="Current score ",
muteseg="Mutate segment ",
initially="Initially mutated to: ",
trying="Trying ",
cost=". Cost: ",
gainT=". >>>>Maaa gain= ",
gainin="<<<< in ",
gaining="(gaining: ",
BestSegGain="Best AA gained: ",
gained=">>Gained another: ",
sorry="Sorry! Aliens mutated with a loose: ",
timeleft="Time left: ",
hours=" hours.",
optionsFast="Options: Fast =",
optionsPreserve="Protger structure= ",
maygain="May gain additional ",
cleaning="Cleaning",
restorestructure="Restoring secundary structure",
savingbest="Saving best result",
notmutated="No mutation",
mutatedTo="Segment mutated to ",
mutatedsegs="mutated segments:",
alreadydone=" has already been used.",
signalerror="Thanks to signal this to the author",
WARNING="WARNING: Puzzle non implemented"
}
}
end
return
end
--end merged Stanley and recipes functions
--Start generic Stanley functions section------------------------
function round(x)--cut all afer 3-rd place
return x-x%0.001
end
function down(x)
return x-x%1
end
function p(fmt, ...) --NEW 17/5/13
if #arg==0 then print(fmt or '')
elseif arg==nil then print(fmt or '')-- added BK 23/3/13
elseif fmt==nil then print('')-- added BK 23/3/13
else print(string.format(fmt, unpack(arg))) end
end
function Score() -- old style score (could be with or without bonus)
return current.GetEnergyScore()
end
-- functions for filters NEW for Stanley 19/1/2016
function FiltersOn()
if not FILTERON then
filter.EnableAll()
FILTERON=true
end
end
function FiltersOff()
if FILTERON then
filter.DisableAll()
FILTERON=false
end
end
function AllScores() -- new 19/1/2016
local score=Score() -- current with or fithout filters
FilterBonus=filter.GetBonusTotal() -- Total bonus score of the filters (global)
CurrentFilterSetting = filter.AreAllEnabled() -- ALL !! (not partial)
if CurrentFilterSetting then
ScoreOn=score
ScoreOff=score-FilterBonus
FILTERON = true
else
ScoreOn=score+FilterBonus
ScoreOff=score
FILTERON= false
end
end -- returns score On (enabled), Score Off (disabled) and Filter Bonus
AllScores()
--end functions for filters
function random(n1,n2) --random function returns int or float depends on input vars
if n2==nil and n1==nil then
return math.random() --float
else
if n2==nil then
if n1%1==0 then
return math.random(n1) --integer
else
return math.random()*n1 --float
end
else
if n1%1==0 and n2%1==0 then
return math.random(n1,n2) --integer between
else
return math.random()*(n2-n1)+n1 --float between
end
end
end
end
if OriginalFilterSetting then -- for startingscore (all of them)
startingscore=ScoreOn-- for recipes
else
startingscore=ScoreOff-- for recipe
end
maxScore=startingscore-- for recipes
evolbase=down(startingscore)--initialise decimales pour cherchevol() in jet
StartFilterBonus=FilterBonus
StartBonus=filter.GetBonusTotal() --Total bonus score of the filters
print(">>>>>>Start Score = "..round(startingscore))
print(" (disabled "..down(ScoreOff)..") + Filter ("..down(FilterBonus)..") = "..down(ScoreOn))
print("Check bonus = "..down(StartBonus))
if startingscore<7000 then
preserve=true
end
--[[GetScore and GetGroupScore return the rosetta energy. To convert this to your score use this:
10 * (800 - Rosetta Energy) = Foldit Score
The rosetta energy is a negative number and lower is better]]--
--Trouver le score de reference en fonction des resultats de l'equipe
function TopScore() -- by B.Kestemont 7/2/2013
local TopScorevalue=8000
if scoreboard.GetGroupScore()==nil then
if absbestscore==nil then TopScore=current.GetEnergyScore()+1000
else
if scoreboard.GetRank()<6 then
TopScorevalue=(absbestscore-8000)*(1+0.039*scoreboard.GetRank())+8000
else
TopScorevalue=(absbestscore-8000)*(1+(0.010*(scoreboard.GetRank()-5)+0.039*5))+8000
end
end
else
if grouprank<6 then
TopScorevalue=(groupscore-8000)*(1+pprankrel*grouprank)+8000
else
TopScorevalue=(groupscore-8000)*(1+0.0038*(grouprank-5)+pprankrel*5)+8000
end
end
if TopScorevalue<8000+15*segCnt then TopScorevalue=8000+17.94*segCnt end -- le minimum observ en fin de compte
return TopScorevalue
end
--end generic Stanley functions section------------------------
--Start generic functions section------------------------
--for Maa
function noteread(sg)
saveNote=structure.GetNote(sg)
end
--From JET3:
function CI(val)
global_ci=val
behavior.SetClashImportance(global_ci)
end
--end generic functions section------------------------
-- Module Stanley 1.2.1, by B. Kestemont 19/06/2013, 25/8/2013, 4/1/2019, 7/9/2020
-- To find puzzle properties and targets
-- properties based on Tvdl 14-12-2012
-- Autonomous enhanced version (BK 25/1/2013)
-- Targets by B. Kestemont
----------------------------------------------------------
--generic variables section merged to top -------------------------
--generic functions section merged to top------------------------
------------------------------------------------------
-- START Segment set and list module
--Copy this to an existing program and use the commands to deal with tables (lists and sets)
-- Notice that most functions assume that the sets are well formed
-- (=ordered and no overlaps)
-- 02-05-2012 TvdL Free to use for non commercial purposes
-- 05-02-2014 BK enhanced for printing (also Free for non commercial purposes)
-- 12-12-2014 Bruno Kestemont added some lists functions
-- 07-09-2020 Bruno Kestemont fixed SegmentListMinus and deleted SegmentInvertList
--To Do: find something more generic for multidimensional tables
-- a list is {1,2,3,8,9,10}.
--A set is a list of pairs like {{1,4},{8,10}} or something like that in a 2-dimentional table:
--i {[1],[2]}
--___________
--1 { 1 , 4 }
--2 { 8 , 10}
--set[1][1] = 1
--set[1][2] = 4
--1) Functions on lists
function SegmentListMinus(list1,list2) -- list1-lists2 NEW BK 12/12/2014, fixed 7/9/2020
local result={}
for i=1,#list1 do
if not SegmentInList(list1[i],list2) then
result[#result+1]=list1[i]
end
end
return result
end
function SegmentListToBool(list, fullList) -- NEW BK 12/12/2014 for all segments, true or false in the list
local result={}
local fullList=fullList or {}
if #fullList==0 then
for i=1,structure.GetCount() do
fullList[i]=i
end
end
for i=1,#fullList do
result[i]=SegmentInList(i,list) -- true or false
end
return result
end
function SegmentListToSet(list) --note: clean duplicates in a list and makes a set
local result={}
local f=0
local l=-1
table.sort(list)
for i=1,#list do
if list[i] ~= l+1 and list[i] ~= l then
-- note: duplicates are removed
if l>0 then result[#result+1]={f,l} end
f=list[i]
end
l=list[i]
end
if l>0 then result[#result+1]={f,l} end
--print("list to set")
--SegmentPrintSet(result)
return result
end
function SegmentInList(s,list) -- reports if s in the list
table.sort(list)
for i=1,#list do
if list[i]==s then return true
elseif list[i]>s then return false
end
end
return false
end
function SegmentJoinList(list1,list2) -- duplicates allowed: list1+list2
local result=list1
if result == nil then return list2 end
for i=1,#list2 do result[#result+1]=list2[i] end
table.sort(result)
return result
end
function SegmentCommList(list1,list2) -- what is common to 2 lists (intersection list1, list2)
local result={}
table.sort(list1)
table.sort(list2)
if #list2==0 then return result end
local j=1
for i=1,#list1 do
while list2[j]<list1[i] do
j=j+1
if j>#list2 then return result end
end
if list1[i]==list2[j] then result[#result+1]=list1[i] end
end
return result
end
function SegmentCleanList(list) -- clean duplicates in a list
-- Makes it well formed and clean duplicates
return SegmentSetToList(SegmentListToSet(list))
end
function SegmentListToString(list) -- pour pouvoir imprimer liste NEW BK 16/9/2015
local line = ""
for i=1,#list do
if i~=1 then line=line.." " end
if list[i][1]~= nil then
line=line..list[i][1]
else
line=line..list[i]
end
end
return line
end
function SegmentPrintListToSet(list) -- NEW BK 14/04/2014 prints a list in a set format
SegmentPrintSet(SegmentListToSet(list))
end
--2) Functions on sets and ranges:
function SegmentExtendSet(set,x,y) -- New BK 05/02/2014 x, y= nb of seg to add before and after each zone
local result={}
local x,y=x or 1, y or 1
for i=1,#set do
if set[i][1]<1+x then --first segment
result[i]={set[i][1],set[i][2]+y}
elseif set[i][2]>set[#set][2]-y then --last segment
result[i]={set[i][1]-x,set[i][2]}
else
result[i]={(set[i][1]-x and set[i][1]>x) or set[i][1] , (set[i][2]<=set[#set][2]-y and set[i][2]+y) or set[i][2]}
result[i]={set[i][1]-x ,set[i][2]+y}
end
end
return result -- overlaps are possible
end
function SegmentSetToList(set)
local result={}
for i=1,#set do
--print(set[i][1],set[i][2])
for k=set[i][1],set[i][2] do
result[#result+1]=k
end
end
return result
end
function SegmentCleanSet(set) -- clean duplicates in a set
-- Makes it well formed and clean duplicates
return SegmentListToSet(SegmentSetToList(set))
end
--This one is limited to sets of segments (not generic for any set):
function SegmentInvertSet(set,maxseg)
-- Gives back all segments not in the set
-- maxseg is added for ligand
local result={}
if maxseg==nil then maxseg=structure.GetCount() end
if #set==0 then return {{1,maxseg}} end
if set[1][1] ~= 1 then result[1]={1,set[1][1]-1} end
for i=2,#set do
result[#result+1]={set[i-1][2]+1,set[i][1]-1}
end
if set[#set][2] ~= maxseg then result[#result+1]={set[#set][2]+1,maxseg} end
return result
end
function SegmentInSet(set,s)
for i=1,#set do
if s>=set[i][1] and s<=set[i][2] then return true
elseif s<set[i][1] then return false
end
end
return false
end
function SegmentJoinSet(set1,set2) -- no duplicates, no overlap
return SegmentListToSet(SegmentJoinList(SegmentSetToList(set1),SegmentSetToList(set2)))
end
function SegmentCommSet(set1,set2) -- what is common to set 1 and set 2 (no duplicate)
return SegmentListToSet(SegmentCommList(SegmentSetToList(set1),SegmentSetToList(set2)))
end
function SegmentSetMinus(set1,set2) -- set1 minus set2 (set1 minus what is common to set 1 and set2)(no duplicate)
return SegmentCommSet(set1,SegmentInvertSet(set2))
end
function SegmentPrintSet(set)
print(SegmentSetToString(set))
end
function SegmentSetToString(set)
local line = ""
for i=1,#set do
if i~=1 then line=line..", " end
line=line..set[i][1].."-"..set[i][2]
end
return line
end
function SegmentSetInSet(set,sub)
if sub==nil then return true end
-- Checks if sub is a proper subset of set
for i=1,#sub do
if not SegmentRangeInSet(set,sub[i]) then return false end
end
return true
end
function SegmentRangeInSet(set,range) -- range is a pair {from,to}
if range==nil or #range==0 then return true end
local b=range[1]
local e=range[2]
for i=1,#set do
if b>=set[i][1] and b<=set[i][2] then
return (e<=set[i][2])
elseif e<=set[i][1] then return false end
end
return false
end
function SegmentSetToBool(set) -- gives false or true
local result={}
for i=1,structure.GetCount() do
result[i]=SegmentInSet(set,i)
end
return result
end
helptext="" -- for dialog
--3) Generic lists and tables multidimensional printing by BK
function SegmentMatrixToString(matrix, dimension, fieldD, field, recorD, record, printN) -- New BK 14/10/2014
local fieldD=fieldD or ";" -- field delimiter for print
local recorD=recorD or "," -- record delimiter for print
local field=field or 1 -- if we decide only to print one field (field number)
local record=record or nil -- if nil, we print all records
local dimension=dimension or 1 -- the dimension of the matrix must be specified if not 1 (simple list)
local printN=printN or false
local line = ""
if #matrix>0 then
if record== nil then
for i=1,#matrix do
if i~=1 then line=line..recorD end -- add record delimiter unless for first record
if printN then line=line.." "..i..") " end
for j=1,dimension do
line=line..matrix[i][j] -- add data
if j~=dimension then line=line..fieldD end -- add field delimiter unless for latest field
end
end
else
if printN then line=line..record..") " end
for j=1,dimension do
line=line..matrix[record][j] -- add data
if j~=dimension then line=line..fieldD end -- add field delimiter unless for latest field
end
end
helptext="Text to be added as help in the dialog box"
helpdesk2=[[and/or a longer text here]]
return line
else
helptext="No valid matrix found"
return ""
end
end -- this function can only report a line
function SegmentPrintMatrix(matrix,dimension, fieldD, field, recorD, record, printN, display) -- New BK 14/10/2014
local matrix=matrix or {}
local fieldD=fieldD or ";" -- field delimiter for print
local recorD=recorD or "," -- record delimiter for print
local field=field or 1 -- if we decide only to print one field (field number)
local record=record -- if nil, we print all records
local dimension=dimension or 1 -- the dimension of the matrix must be specified if not 1 (simple list)
local printN=printN or false
local display=display or "list" -- can be "table" or "list"
if display=="list" then -- prints all in one line
print(SegmentMatrixToString(matrix,dimension, fieldD, field, recorD, record, printN))
elseif display=="table" then
for i=1,#matrix do
print(SegmentMatrixToString(matrix,dimension, fieldD, field, recorD, i, printN))
end
end
end
-- END Segment set and list module-------------
------------------------------------------------------------
------------------------------------------------------------
-- Module Find Segment Types
function FindMutablesList()
local result={}
for i=1,segCnt2 do if structure.IsMutable(i) then result[#result+1]=i end end
return result
end
function FindMutables()
return SegmentListToSet(FindMutablesList())
end
function FindFrozenList() -- only frozen backbones I think
local result={}
for i=1,segCnt2 do if freeze.IsFrozen(i) then result[#result+1]=i end end
return result
end
function FindFrozen()
return SegmentListToSet(FindFrozenList())
end
function FindFrozenSidechainList() -- NEW 23/9/2020
local result={}
for i=1,segCnt2 do
local FrozenBackbone, FrozenSidechain =freeze.IsFrozen(i) -- 2 boolean results thanks to Lua
if FrozenSidechain then
result[#result+1]=i
end
end
return result
end
function FindFrozenSidechains() -- NEW 23/9/2020
return SegmentListToSet(FindFrozenSidechainList())
end
function FindLockedList()
local result={}
for i=1,segCnt2 do if structure.IsLocked(i) then result[#result+1]=i end end
return result
end
function FindLocked()
return SegmentListToSet(FindLockedList())
end
function FindSelectedList()
local result={}
for i=1,segCnt do if selection.IsSelected(i) then result[#result+1]=i end end
return result
end
function FindSelected()
return SegmentListToSet(FindSelectedList())
end
function FindAAtypeList(aa) -- SS only
local result={}
for i=1,segCnt2 do
if structure.GetSecondaryStructure(i)== aa then result[#result+1]=i end
end
return result
end
function FindAAtype(aa)
return SegmentListToSet(FindAAtypeList(aa))
end
function FindAminotype(at) --NOTE: only this one gives a list not a set
local result={}
for i=1,segCnt2 do
if structure.GetAminoAcid(i) == at then result[#result+1]=i end
end
return result
end
-- end Module Find Segment Types
-- Module to compute subscores
-- TvdL, 14-12-2012
function GetSubscore(types,seg1,seg2,pose)
local result=0
if type(types) == "table" then
for i=1,#types do result=result+GetSubscore(types[i],seg1,seg2,pose) end
else
if types==nil and seg1==nil and seg2==nil then return Score(pose) end
if seg1==nil then seg1=1 end
if seg2==nil then seg2=segCnt end --includes ligands!
if seg1>seg2 then seg1,seg2=seg2,seg1 end
if pose==nil then pose=current end
if types==nil then
for i=seg1,seg2 do result=result+pose.GetSegmentEnergyScore(i) end
else
for i=seg1,seg2 do result=result+pose.GetSegmentEnergySubscore(i,types) end
end --rappel: current.GetSegmentEnergySubscore(integer segmentIndex, string scorePart)
end
return result
end
-- End module to compute subscores
-------------------------------------------------------
-- Start of module for bridgechecking-------------------
function setCyslist()
Cyslist=FindAminotype("c")
nrofbridges=CountBridges()
end
function IsBridge(i)
return ''..current.GetSegmentEnergySubscore(i,'disulfides') ~= '-0'
end
function CountBridges()
local count = 0
for i = 1,#Cyslist do
if IsBridge(Cyslist[i]) then count = count + 1 end
end
return count
end
function BridgesBroken()
return savebridges == true and CountBridges() < nrofbridges
end
function Bridgesave()
if savebridges then PushPosition() end
end
function Bridgerestore()
if savebridges then
if BridgesBroken() then PopPosition() else ClrTopPosition() end
end
end
-- End module bridgechecking
---Start Module to find segment properties------------
function SetPuzzleProperties()
--p("Exploration du puzzle")
p(i18.intro.exploration)
--check if the puzzle has ligands and computes LastSeg
--DetectLigand()
--DetectLock()
-- Find out if the puzzle has mutables
local MutList=FindMutablesList()
HASMUTABLE= (#MutList>0)
if HASMUTABLE then
--p("-il y a "..#MutList.." mutables;")
p(i18.stanley.thereare..#MutList..i18.stanley.mutables)
else
--p("-pas de mutable;")
--p(i18.stanley.nomutable)
end
FREEDESIGN= (segCnt2/2 < #MutList)
if FREEDESIGN then
--p("-probablement free design;")
p(i18.stanley.freedesign)
else
--p("-pas free design")
--p(i18.stanley.nofreedesign)
end
-- Find out if the puzzle has possible bridges
setCyslist()
--p("- "..#Cyslist.." cystides;")
p(i18.stanley.thereare..#Cyslist..i18.stanley.cysteins)
if #Cyslist > 1 then
if nrofbridges > 0 then
--p(" -il y a "..nrofbridges.." ponts;")
p(" -there are "..nrofbridges.." bridges;")
p(i18.stanley.thereare..nrofbridges..i18.stanley.bridges)
savebridges=true
else
--p(" -pas de pont;")
p(i18.stanley.nobridge)
end
else
--p(" -pas de possibilite de pont;")
p(i18.stanley.nobridgepossible)
end
-- Find out is the puzzle has other scores and their weight if any (e.g. ED)
local othertot=GetSubscore("density")
local segtot=GetSubscore(nil,1,segCnt) -- attention sera nil si lock
HASOTHER= math.abs(othertot) > 0.0001
if normal and HASOTHER then
OTHERWEIGHT=(Score()-segtot-8000)/othertot -- c'est pas l'inverse?
--p("-autres scores; poids supplementaire de "..round(OTHERWEIGHT))
p(i18.stanley.otherscore..round(OTHERWEIGHT))
else
--p("-pas d'autre score;")
p(i18.stanley.nootherscore)
end
-- Check if the puzzle is a probable symmetry one
if normal and not HASOTHER then
PROBABLESYM=math.abs(Score()-segtot-8000) > 2 -- c'est pas plutot diviser?
end
end
--START extraction of information from puzzle metadata --Extrait des infos
function detectfilterandmut() -- Bruno Kestemont 10/10/2013; 13/2/2015; 5/1/2019
local descrTxt=puzzle.GetDescription()
local puzzletitle=puzzle.GetName()
local function SymetryFinder() -- by Bruno Kestemont 7/2/2013, 25/8/2013
local segMeanScore=(TopScore()-8000)/segCnt -- top score pour eviter les debuts de puzzle
--p("Score moyen par segment= "..segMeanScore)
if PROBABLESYM then
if segMeanScore<33.39 then sym=1
PROBABLESYM=false
elseif segMeanScore<85 then sym=2
elseif segMeanScore<132 then sym=3
elseif segMeanScore<197 then sym=4
else sym=5
end
else sym=1
end
return
end
if #descrTxt>0 and (descrTxt:find("filter") or descrTxt:find("filters") or descrTxt:find("bonus") or descrTxt:find("bonuses") and not descrTxt:find("disabled"))then
PROBABLEFILTER=true
FILTERMANAGE=true -- default yes during wiggle (will always be activate when scoring)
GENERICFILTER=false -- to be evaluated
end
if #descrTxt>0 and (descrTxt:find("H-bond networks") or descrTxt:find("Hydrogen Bond Networks") or descrTxt:find("H-bond Networks")
or descrTxt:find("H-bond Network") and not descrTxt:find("disabled"))then
PROBABLEFILTER=true
FILTERMANAGE=false -- default no
GENERICFILTER=false -- to be evaluated
HBONDPUZZLE=true
end
if #descrTxt>0 and (descrTxt:find("design") or descrTxt:find("designs")) then
HASMUTABLE=true
IDEALCHECK=true
HANDFOLD=true
end
if #descrTxt>0 and (descrTxt:find("De-novo") or descrTxt:find("de-novo") or descrTxt:find("freestyle")
or descrTxt:find("prediction") or descrTxt:find("predictions")) then
IDEALCHECK=true
HANDFOLD=true
end
if #puzzletitle>0 then
if (puzzletitle:find("Sym") or puzzletitle:find("Symmetry") or puzzletitle:find("Symmetric")
or puzzletitle:find("Dimer") or puzzletitle:find("Trimer") or puzzletitle:find("Tetramer")
or puzzletitle:find("Pentamer")) then
PROBABLESYM=true
if puzzletitle:find("Dimer") and not puzzletitle:find("Dimer of Dimers") then sym=2
elseif puzzletitle:find("Trimer") or puzzletitle:find("trimer") then sym=3
elseif puzzletitle:find("Dimer of Dimers") or puzzletitle:find("Tetramer") then sym=4
elseif puzzletitle:find("Pentamer") then sym=5
else SymetryFinder()
end
end
end
if #descrTxt>0 and (descrTxt:find("Sym") or descrTxt:find("Symmetry") or descrTxt:find("Symmetric")
or descrTxt:find("sym") or descrTxt:find("symmetry") or descrTxt:find("symmetric")) then
PROBABLESYM=true
if (descrTxt:find("Dimer") or descrTxt:find("dimer") or descrTxt:find("C2 symmetry") or descrTxt:find("twoo symmetric"))
and not (descrTxt:find("Dimer of Dimers") or descrTxt:find("dimer of dimers")) then sym=2
elseif descrTxt:find("Trimer") or descrTxt:find("trimer") or descrTxt:find("C3 symmetry") or descrTxt:find("three symmetric") then sym=3
elseif (descrTxt:find("Dimer of Dimers") or descrTxt:find("Tetramer") or descrTxt:find("C4 symmetry") or descrTxt:find("four symmetric"))
and not (descrTxt:find("dimer of dimers") or descrTxt:find("tetramer"))then sym=4
elseif descrTxt:find("Pentamer") or descrTxt:find("pentamer") or descrTxt:find("C5 symmetry") or descrTxt:find("five symmetric") then sym=5
else SymetryFinder()
end
end
--print resulting sym info
if PROBABLESYM then
print("Symmetric")
if sym==2 then
print("Dimer")
elseif sym==3 then
print("Trimer")
elseif sym==4 then
print("Tetramer")
elseif sym==5 then
print("Pentamer")
elseif sym>5 then
print("Terrible polymer")
end
else print("Monomer")
end
if #puzzletitle>0 and puzzletitle:find("Sepsis") then -- new BK 17/6/2013
SEPSIS=true
HANDFOLD=true
--p(true,"-Sepsis")
print("Sepsis")
end
if #puzzletitle>0 and puzzletitle:find("Electron Density") then -- for Electron Density
--p(true,"-Electron Density")
ELECTRON=true
HANDFOLD=true
print("Electron density")
end
if #puzzletitle>0 and puzzletitle:find("Centroid") then -- New BK 20/10/2013
--p(true,"-Centroid")
CENTROID=true
print("Centroid")
end
if #puzzletitle>0 and puzzletitle:find("Hotspot") then -- New BK 21/01/2014
HOTSPOT=true
print("Hotspot")
end
return
end
detectfilterandmut()
--END extraction of information from puzzle metadata --Extrait des infos
---End of Module to find segment properties------------
--Start module target settings
function TargetFinder(sym) -- by Bruno Kestemont 16/2/2013 -- Stanley V2 version
--sym= 1 --Options: 1 normal; 2 dimer; 3 trimer; 4 tetramer (dimer of dimer) etc.
--p("Recherche d'un objectif")
p(i18.stanley.lookingtarget)
-- note: the bonus is only approximated by current bonus
local k=1 -- Option: k= 4 if symetric puzzle Dimer, k=6 for trimer, k=8 for tetramer
if sym > 1 then k=2*sym -- reassigning k in function of symetry
TargetMin= 13.18*k*segCnt +8000 + StartBonus -- based on 8000 + min score per segment
TargetLow= 17.81*k*segCnt +8000 + StartBonus
TargetMean= 21.14*k*segCnt +8000 + StartBonus
TargetHigh= 24.46*k*segCnt +8000 + StartBonus
TargetMax= 24.65*k*segCnt +8000 + StartBonus
else
TargetMin= 14.03*k*segCnt +8000 + StartBonus
TargetLow= 19.05*k*segCnt +8000 + StartBonus
TargetMean= 22.87*k*segCnt +8000 + StartBonus
TargetHigh= 26.69*k*segCnt +8000 + StartBonus
TargetMax= 33.39*k*segCnt +8000 + StartBonus
end
--p("Jeu de cibles: "..down(TargetMin)..", ".. down(TargetLow)..", ".. down(TargetMean)..", ".. down(TargetHigh)..", ".. down(TargetMax))
p(i18.stanley.setoftargets..down(TargetMin)..", ".. down(TargetLow)..", ".. down(TargetMean)..", ".. down(TargetHigh)..", ".. down(TargetMax))
return
end
function Dist2target(Target)
--p("Objectif actuel: "..down(Target))
p(i18.stanley.currenttarget..down(Target))
D2target=Target-Score()
relD2target=D2target/Target -- ratio, relative distance to target
--p("Distance a l'objectif = "..down(D2target).." ("..down(relD2target*100).." %)")
p(i18.stanley.distance2target..down(D2target).." ("..down(relD2target*100).." %)")
return
end
function TargetReset()
local topscore=TopScore() -- includes current bonus
--p("Top score estim: "..down(topscore))
p(i18.stanley.topscore..down(topscore))
if topscore>TargetMax then Dist2target(topscore+10) p("Il y a qque chose qui cloche")
elseif topscore>TargetHigh then Dist2target(TargetMax)
elseif topscore>TargetMean then Dist2target(TargetHigh)
elseif topscore>TargetLow then Dist2target(TargetMean)
elseif topscore>TargetMin then Dist2target(TargetLow)
else Dist2target(TargetMin)
end -- revoit les ambitions en fonction de la situation de l'equipe
end
-- section to compute segmentscore(part)s from tvdl
function getPartscore(ss,se,attr)
local s=0
if attr=='total' then
s=Score()
elseif attr==nil then --is only called from findWorst
for i=ss,se do
s=s+SegmentScores[i]
end
elseif attr=='loctotal' then --total segment scores
s=GetSubscore(nil,ss,se)
else
s=GetSubscore(attr,ss,se)
end
return s
end
-- Do not try to work on frozen or locked parts or ligands or non mutable
--WORKON=SegmentSetMinus(WORKON,FindFrozen()) -- backbones
WORKON=SegmentSetMinus(WORKON,FindFrozenSidechains()) -- only avoiding frozen sidechains
WORKON=SegmentSetMinus(WORKON,FindLocked()) -- to be evaluated, locked might mutate ?
WORKON=SegmentSetMinus(WORKON,FindAAtype("M"))
WORKON=SegmentSetMinus(WORKON,SegmentInvertSet(FindMutables(),nil)) -- new 6/9/2020
WORKONbool={}
function InitWORKONbool()
WORKONbool=SegmentSetToBool(WORKON)
end
function MustWorkon(i,j) -- not used here in stanley
for k=i,j do if not WORKONbool[k] then return false end end
return true
end
SegmentScores={} --Optimalisation for fast worst search
lastSegScores=0
function GetSegmentScores()
if lastSegScores~=Score() then
lastSegScores=Score()
for i=1,segCnt2 do
if WORKONbool[i] then
if #scrPart==0 then
-- if nothing specified by user default is
-- segmentenergy - reference + extra other score
SegmentScores[i]=current.GetSegmentEnergyScore(i)
if not structure.IsMutable(i) then --ignore reference part but NOT for mutables)
SegmentScores[i]=SegmentScores[i]-current.GetSegmentEnergySubscore(i,'reference')
end
if math.abs(OTHERWEIGHT) > 0 then --the other component has extra weight
SegmentScores[i]=SegmentScores[i]+OTHERWEIGHT*current.GetSegmentEnergySubscore(i,'density')
end
else
SegmentScores[i]=GetSubscore(scrPart,i,i)
end
end
end
end
end
-- end section segmentscore(part)s
-- End of module Target settings
function Stanley()
p("------------------")
p(i18.intro.title)
InitWORKONbool() -- new 18/5/13
SetPuzzleProperties()
--detectfilterandmut()
--SymetryFinder() --deja appele par puzzleprop
TargetFinder(sym)
TargetReset()
p(i18.stanley.endstanley)
p("------------------")
end
--END STANLEY MODULE
------------------------------------------------------------------
--START Archive in Notes, -- New 4/11/2014
function SelectNote(recipename)
store={}
store.label=recipename or "" -- edit here the recipe name
store.note_number=structure.GetCount()
for seg=structure.GetCount(),1,-1 do
if structure.GetNote(seg)~="" then break end
store.note_number=seg
end
print(string.format("Recording results in Note for segment %i",store.note_number))
store.starting_score=current.GetScore()
--structure.SetNote(store.note_number,string.format("(%s) %.3f + FSP",user.GetPlayerName(),store.starting_score))
end
SelectNote(recipename)
function WhriteNote(loop_nb) -- all inits are in SelectNote function. Call this in the loop or "gained another" of the recipe
local loop_count= loop_nb or 1
structure.SetNote(store.note_number,string.format("(%s) %.3f + %s(%i) %.3f",user.GetPlayerName(),store.starting_score,store.label,loop_count,current.GetScore()))
end
--END Archive in Notes
--START quick save algorithm
function QuickShake(val)
--[[------------------------------------------------------------------------------------------------
-- Algorithm for faster shake
REFERENCES
1. N/A
Copyright (C) 2014 Seagat2011 <http://fold.it/port/user/1992490>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
$Id$
------------------------------------------------------------------------------------------------]]--
--[[
v1
- Inception
1.2
- Loops until nogain
]]--
local val= val or 1
local idx = 1
local idx2 = structure.GetCount ()
local hash = {}
local cs = current.GetScore ()
--print ( 'Quick Shake Algorithm v1.2 SG2011 - Current Score: '..cs )
local function New ( obj )
return obj -- pass-new-obj-by-value
end
local _gses = New ( current.GetSegmentEnergySubscore )
local function SmartShake ( iters )
local gain = true
while (gain) do
gain = false
for i=idx,idx2 do
local ci = _gses ( i,'clashing' )
if ci < _gses ( i,'hiding' ) and
ci < _gses ( i,'packing' ) and
ci < _gses ( i,'ideality' ) and
ci < _gses ( i,'sidechain') and
ci < _gses ( i,'bonding' ) and
ci < _gses ( i,'other' ) and
ci < _gses ( i,'reference') then
selection.Select ( i )
end -- test ci --
end -- loop --
if selection.GetCount () then
local css = current.GetScore ()
structure.ShakeSidechainsSelected ( iters )
selection.DeselectAll ()
if current.GetScore () > css then
gain = true
end -- test --
end -- test --
end -- loopf --
end
structure.SmartShake = SmartShake
structure.SmartShake ( val )
--print ( 'Done.' )
end
--END quick save algorithm
--calculate REALLY good seed for the pseudorandom in random (avoids to always have the same sequence)
seed=os.time()/math.abs(Score())
seed=seed%0.001
seed=1/seed
while seed<10000000 do seed=seed*1000 end
seed=seed-seed%1
p("Seed is: "..seed)
math.randomseed(seed)
--REALLY good seed made by rav3n_pl :P
--START MIX TABLE subroutine by Bruno Kestemont 16/11/2015, idea by Puxatudo & Jeff101 from Go Science
function ShuffleTable(tab) --randomize order of elements
local cnt=#tab
for i=1,cnt do
local r=math.random(cnt)
tab[i],tab[r]=tab[r],tab[i]
end
return tab
end
function MixInwardTable(tab) -- 1234567 = 7254361 WARNING: if done twice, it returns to the original table/ BUG ??
local cnt=#tab -- 1234567 = 7254361
local mid=down(cnt/2)
local adjust=1 -- case of pair number of segments
local result={}
local pair=true
if mid<cnt/2 then adjust=0 end -- case of impair number of segments
for i=1,mid-adjust do -- mid remains untouched if impair cnt
pair = not pair
if pair then
result[i],result[cnt+1-i]=tab[i],tab[cnt+1-i] -- pair segs are kept untouched
else
result[i],result[cnt+1-i]=tab[cnt+1-i],tab[i] -- impairs segs are shifted (loop starts with last seg)
end
end
return result
end
function InwardTable(tab) -- 1234567 = 7162534 WARNING: if done twice, it mixes everything like a feuillete bakery
local cnt=#tab -- 1234567 = 7162534
local cntup=1
local result={}
local pair=true
for i=1,#tab do
pair = not pair
if pair then
result[i]=tab[cntup] -- pairs segments are taken from bottom
cntup=cntup+1
else
result[i]=tab[cnt] -- impairs segs are taken from end (loop starts with last seg)
cnt=cnt-1
end
end
return result
end
function Reverselist(tab) -- 1234567=7654321
local cnt=#tab
local result={}
for i=1,#tab do -- simply inverts the table 7162534=4536271
result[i]=tab[cnt+1-i]
end
return result
end
function OutwardTable(tab) --1234567=4352617
local result={}
result=Reverselist(InwardTable(tab))
return result
end
--END MIX TABLE
function ds(val)
--structure.ShakeSidechainsSelected(val)
QuickShake(val)
end
function SelectSphere(sg, radius)
selection.DeselectAll()
for i=1, segCnt do
if structure.GetDistance(sg,i)<radius then selection.Select(i) end
end
end
function WiggleSimple(val,how)
--NB: les filtres sont ici geres en amont dans Brute
if how == "s" then ds(1)
elseif how == "wb" then structure.WiggleSelected(val, true, false) -- backbones
elseif how == "ws" then structure.WiggleSelected(val, false, true) -- sidechains
elseif how == "wa" then structure.WiggleSelected(val, true, true) -- all
elseif how== "lw" then structure.LocalWiggleSelected(val) -- new
end
end
function WiggleAT(ss, how, iters, minppi) -- from JET3, adapted to options mutate Combo by CG
local valiter=2
local val=1
if fast==true then valiter=1 end
if how==nil then how="wa" end
if iters==nil then iters=3 end
if ((minppi==nil) or (minppi<0.1)) then
minppi=0.1
end
if global_ci==1.00 then val=valiter end
if iters>0 then
iters=iters-1
local sp=Score()
WiggleSimple(val,how)-- new function BK 8/4/2013
local ep = Score()
local ig=ep-sp
if how~="s" then
if ig > minppi then WiggleAT(ss, how, iters, minppi) end
end
end
end
function Aftermut(sg) -- sorte de fuze sur sphres de plus en plus grandes, filtres geres en amont dans brute
behavior.SetClashImportance(0.1)
WiggleAT(sg,"s",1)-- on selected sphere around segment
selection.SelectAll() -- was deselect all BK 28/3/13
behavior.SetClashImportance(1)
if not preserve then -- new BK 29/03/14
WiggleAT(sg, "lw", 1) -- NEW BK 28/3/13: local wiggle toute la proteine
end
if sg~=nil then
SelectSphere(sg,12) -- larger sphere
end
WiggleAT(sg,"s",1) -- shake selected (segment and surround)
WiggleAT(sg, "ws", 1) -- NEW BK 28/3/13: wiggle sidechains (segment and surround)
if not preserve and not preserveH then
if not preserveH then
WiggleAT(sg, "lw", 1) -- NEW BK 16/10/2014: local wiggle (segment and surround)
end
selection.SelectAll()
WiggleAT(sg, "wa", 1) -- NEW BK 28/3/13: all wiggle toute la proteine A EVALUER
end
selection.DeselectAll()
end
function rotamers(sg) -- new 9/6/2015
local num_rotamers=5 -- init
save.Quicksave(5) -- slot for rotamers
local ss=Score()
local se=ss
local bestrotascore=ss
for n=1,math.min(num_rotamers,rotamer.GetCount(sg)) do
rotamer.SetRotamer(sg,n)
se=Score()
if se > bestrotascore then
bestrotascore=se
save.Quicksave(5)
end
end
save.Quickload(5)
end
ThisSegKilled=false -- 13/04/2014
function AlienMutate(sg) -- new BK 10/5/13 starting with an aaa
selection.DeselectAll()
selection.Select(sg)
local aa3=structure.GetAminoAcid(sg) -- maintenant verifier s'il n'est pas deja bon !!
local aa3long=amino.long(aa3) -- new BK 14/04/2014
local aa3abrevcap=amino.abbrevcap(aa3)-- new BK 14/04/2014
notefind(sg,aa3abrevcap) -- donne autorise
autorisestr=true -- si pas sooc, il faut tout autoriser
if sooc then saasooc(sg,aa3) end --new BK 14/04/2014, verifie autorisestr
if hydropreserve then GoodHydro(sg,aa3) end -- doit toujours suivre saasooc, jamais prcder. Sinon => autorisestr= false
if autorise and autorisestr and SegmentInList(aa3,chains) and not interditaa(aa3) then -- 14/04/2014 si son AA est dans la liste
--print(" ok, ne pas initialiser !!")
else -- initialiser vers un AA autorise
p("AA initial: "..aa3long.. ". Score: "..Score())
for i=1,#chains do
local aailong=amino.long(chains[i]) -- new BK 22/3/13
local aaiabrevcap=amino.abbrevcap(chains[i])-- new BK 22/3/13
notefind(sg,aaiabrevcap)
if sooc then saasooc(sg,chains[i]) end --new BK 14/04/2014, donne autorisestr
if hydropreserve then GoodHydro(sg,chains[i]) end -- doit toujours suivre saasooc, jamais prcder. Sinon => autorisestr= false
if autorise and autorisestr and not interditaa(chains[i]) then -- des qu'on en trouve un autorise, ca va s'arreter
structure.SetAminoAcidSelected(chains[i])
if aa3 ~= chains[i] then -- corrected BK 13/11/2013 On arrete des qu'on a trouve un AA autorise
local fsco=Score()
local floss=fsco-Best1
--p("Initially mutated to: "..aailong..". Cost= "..round(floss).." pts")
p(i18.maaa.initially..aailong..i18.maaa.cost..round(floss).." pts")
ThisSegKilled=true -- 13/04/2014
break
else -- new BK 13/11/13 si c'est deja un bon, on arrete
break
end
end
end
end
end
-- size ranking: chains
function SameVolume(aa1, aa2) -- check if similar AA sizes
if MaxVolumeRatio > 3.3 then return true end
if not CompareVolume then return true end
local aa1, aa2 = aa1, aa2 -- single letter like 'a'
local aa1Number, aa2Number=25, 25
local VolumeVDW1, VolumeVDW2 = 200, 200
for i =1,#chains do -- when we have the number of the AAs, we compare their volume
if chains[i]==aa1 then
VolumeVDW1=VolumeVDW[i]
end
if chains[i]==aa2 then
VolumeVDW2=VolumeVDW[i]
end
end
--print("DEBUG Volumes : ".. VolumeVDW2.."-"..VolumeVDW1)
if VolumeVDW2 < VolumeVDW1 then -- ranking
VolumeVDW1, VolumeVDW2 = VolumeVDW2, VolumeVDW1
end
if VolumeVDW2 / VolumeVDW1 < MaxVolumeRatio then
return true
end
--print("DEBUG different volumes ".. VolumeVDW2.."-"..VolumeVDW1)
return false
end
Best1=Score() -- best solution
Best2=Best1-- Second best solution
Best3=Best1-- bckup 3th best solution
BestFilter=FilterBonus -- NEW 19/1/2016
nbmutateseg=0 -- number of mutate segments
mutatesegs={} -- list of mutate segments
function Brute(sg) -- MAAA is here ! ne mute que ce segment sg dans une liste predefinie
local sg=sg or 2 -- for debug
ShuffleTable(chains) -- 21/04/2014 randomize order of AAs
selection.DeselectAll()
print("--------")
p(i18.maaa.muteseg .. sg) -- "Mute le segment "
local sco1=Score()
local aa1=structure.GetAminoAcid(sg)
local aailong1=amino.long(aa1)
noteread(sg)
if AlienKill then
AlienMutate(sg)
end
local sco2=Score()
local g=sco2-Best1
local afermutbest=Score()-10000 -- pour eviter le score de depart
local bestgain=0 -- gain nul s'il ne se passe rien
local somethingtested=false -- pour ne pas imprimer info inutile
local probabilitylist= FreqInProt -- list of probabilities to use if probabilistic // default is frequ in proteins
if sooc and probabilistic then --here the probabilistic list is ONLY linked to SS thus all AAs are possible
local SS=structure.GetSecondaryStructure(sg)
if SS== "H" then probabilitylist= Pa
elseif SS== "E" then probabilitylist= Pb
elseif SS== "L" then probabilitylist= Pt
end
end
save.Quicksave(4) -- NB: reinitialise beaucoup plus bas que le score de depart a cause d'AlienKill
for i=1,#chains do
local aa2 = chains[i]
local c1=Score()
selection.DeselectAll()
selection.Select(sg)
autorisestr=true
if sooc and not probabilistic then saasooc(sg,aa2) end --new BK 3/6/13, donne autorisestr //
if hydropreserve then GoodHydro(sg,aa2) end -- doit toujours suivre saasooc, jamais prcder. Sinon => autorisestr= false
local aailong=amino.long(aa2) -- new BK 22/3/13
local aaiabrevcap=amino.abbrevcap(aa2)-- new BK 22/3/13
notefind(sg,aaiabrevcap)
if autorise and autorisestr and not interditaa(aa2)
and probabilisticAction(aa2, probabilitylist) --bk 22/1/2016 added prob
and SameVolume(aa1, aa2) -- added 19/1/2021
then
--local aailong=amino.long(chains[i]) -- new BK 22/3/13
--p("Essai vers: ", aailong)
structure.SetAminoAcidSelected(aa2)
--NEW rotamers:
if not onlymutate and not SegmentInList(aa2,aaneutral) then -- experimental to save time: only rotate the H-binders
rotamers(sg)
end
if aa1 ~= aa2 then
SelectSphere(sg,9)
if not rapide or Score()>c1-FiltreRap then -- meme si rapide, exception pour les bons scores
--p("Essai vers: ".. aailong.. " .Score: ".. Score())
p(i18.maaa.trying .. aailong.. " .Score: ".. Score())
if not superquick then
if PROBABLEFILTER and filtermgt and FILTERON then FiltersOff() end-- new BK 7/4/13 retirer filtres avant wiggles
Aftermut(sg)
if PROBABLEFILTER and filtermgt and FILTERON then FiltersOn() end-- new BK 7/4/13 remettre suivant options de depart
if Score()>afermutbest and Score() ~= c1 then --13/04/2014
afermutbest=Score()
aminoacid=aailong
bestgain=afermutbest-sco1
somethingtested=true
end
end
end
--p("... Score: ", Score())
if Score()<c1 then
save.Quickload(4) -- reprendre la solution initiale autorisee
else
save.Quicksave(4)
end
end
--else print("Skipping "..aailong)
end
end
if somethingtested then print("Best= ",aminoacid, " Score: ",round(afermutbest), i18.maaa.BestSegGain,round(bestgain)) end
save.Quickload(4)
local aaMut=structure.GetAminoAcid(sg) -- reassigning variable after mutate
local aaMutlong=amino.long(aaMut) -- new BK 22/3/13
local m=false
local es=Score()
if aa1==aaMut then
--p("Pas mut")
p(i18.maaa.notmutated.." (Score: "..round(es)..")")
else
--p("Segment mut vers "..aaMutlong) -- new BK 22/3/13
p(i18.maaa.mutatedTo..aaMutlong.." (Score: "..round(es)..")") -- new BK 22/3/13, 19/1/2021
m=true
selection.DeselectAll()
recentbest.Save()
WiggleAT(sg, "ws", 10) -- NEW BK 6/4/13: wiggle sidechains (segment and surround)
recentbest.Restore() -- because it could lower the score by loosing a Hbond filter
nbmutateseg=nbmutateseg+1 --14/04/2014
mutatesegs[nbmutateseg]=sg -- add this segment to the list
end
--SaveBestMaaa()
end
function SaveBestMaaa() --adapted to Maaa
local sp=-999998
local aafc=-999 -- absolute accepted filter cost
if afcppg<1 then -- we need the filter bonus to decide
AllScores() -- gives ScoreOn, ScoreOff and FilterBonus
if FILTERON then sp=ScoreOn else sp=ScoreOff end-- depends on the starting position
if FilterBonus <(sp-Best1)*afcppg then print("Filter break, rejecting this solution") return end -- or break?
else
sp=Score()
end
local g1=sp-Best1
local g2=sp-Best2
local g3=sp-Best3
if g1>0 then
--p("DEBUG Gained "..g1)
p(i18.maaa.gained.. g1) -- "gained another ..."
save.Quicksave(11)
BackupSolutions(1)
elseif g1<0 then
if ThisSegKilled then -- cas ou ce segment a ete killed, faut garder la perte
--p("Sorry! Alien mutated with a loose: "..g1)
p(i18.maaa.sorry.. g1)
save.Quicksave(11) -- reinitialiser tous les backups a la baisse
Best1= Score() -- nouveau score 1
if g2<0 then
save.Quicksave(10)
Best2= Score() -- nouveau score 2
if g3<0 then
save.Quicksave(9)
save.Quicksave(8)
Best3= Score() -- nouveau score 3
end
end
else -- cas normal ou pas eu de kill: verifier les backups 2 et 3
if g2>0 then
save.Quicksave(10)
BackupSolutions(2)
elseif g2<0 then
if g3>0 then
save.Quicksave(9)
BackupSolutions(3)
end
end
end
ThisSegKilled=false -- reinitialiser pour le suivant!
end
end
function BackupSolutions(ranking)
save.Quickload(9) --reprendre l'avant derniere version
save.Quicksave(8) --en faire l'antepenultienne version
Best3= Score() -- nouveau score 3
if ranking==1 or ranking==2 then
save.Quickload(10) --reprendre la derniere version
save.Quicksave(9) --en faire l'avant derniere version
Best2= Score()
end
if ranking==1 then
save.Quickload(11) --reprendre la meilleure version
save.Quicksave(10) --la sauver en 10 -- donc la 10 sera toujours le backup
Best1= Score() -- reinitialiser le meilleur score
end
end
function Zone(zStart,zEnd) -- seg start & segend are not necesserally first and last segments
for i=zStart, zEnd do
j=WORKONBIS[i] -- NEW 24/9/2013 to be able to treat segments in any order defined in WORKON
if j==nil then break end -- I hope this would resolve the bug on slice order
Brute(j)
SaveBestMaaa()
end
end
--[[------------------------------------------------------------------------------------------------
-- ST - mini rosetta energy model v1.0.0.0.
-- v1.3 Included codon bases
-- Quickly scores a fold based on compactness, hiding, clashing, and disulfide bridges. recommended for Puzzles ( Exploration, Design, Multi-start, Freestyle ) + combinations, thereof. Rosetta 3 is a library based object-oriented software suite which provides a robust system for predicting and designing protein structures, protein folding mechanisms, and protein-protein interactions. The library contains the various tools that Rosetta uses, such as Atom, ResidueType, Residue, Conformation, Pose, ScoreFunction, ScoreType, and so forth. These components provide the data and services Rosetta uses to carry out its computations.[1]
REFERENCES
1. Rosetta 3.0 User-guide - http://www.rosettacommons.org/manuals/rosetta3_user_guide/index.html
Copyright (C) 2011 Seagat2011 <http://fold.it/port/user/1992490>
Copyright (C) 2011 thom001 <http://fold.it/port/user/172510>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
$Id$
-----------------------------------------------------------------------------]]--
-- Amino Acid library
--amino_segs
--amino_part
--amino_table
amino_segs = {'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'y'} -- all of them
amino_part = { short = 1, abbrev = 2, longname = 3, hydro = 4, scale = 5, pref = 6, mol = 7, pl = 8, vdw_vol = 9, abbrevcap= 10 }
amino_part.codon = {
['GCU'] = 1, ['GCC'] = 2, ['GCA'] = 3, ['GCG'] = 4,
['UGU'] = 1, ['UGC'] = 2,
['GAU'] = 1, ['GAC'] = 2,
['GAA'] = 1, ['GAG'] = 2,
['UUU'] = 1, ['UUC'] = 2,
['GGU'] = 1, ['GGC'] = 2, ['GGA'] = 3, ['GGG'] = 4,
['CAU'] = 1, ['CAC'] = 2,
['AUU'] = 1, ['AUC'] = 2, ['AUA'] = 3,
['AAA'] = 1, ['AAG'] = 2,
['UUA'] = 1, ['UUG'] = 2, ['CUU'] = 3, ['CUC'] = 4, ['CUA'] = 5, ['CUG'] = 6,
['AUG'] = 1,
['AAU'] = 1, ['AAC'] = 2,
['CCU'] = 1, ['CCC'] = 2, ['CCA'] = 3, ['CCG'] = 4,
['CAA'] = 1, ['CAG'] = 2,
['CGU'] = 1, ['CGC'] = 2, ['CGA'] = 3, ['CGG'] = 4, ['AGA'] = 5, ['AGG'] = 6,
['UCU'] = 1, ['UCC'] = 2, ['UCA'] = 3, ['UCG'] = 4, ['AGU'] = 5, ['AGC'] = 6,
['ACU'] = 1, ['ACC'] = 2, ['ACA'] = 3, ['ACG'] = 4,
['GUU'] = 1, ['GUC'] = 2, ['GUA'] = 3, ['GUG'] = 4,
['UGG'] = 1,
['UAU'] = 1, ['UAC'] = 2,
-- ['UAG'] = 1,
-- ['UGA'] = 1,
-- Stop codon: ['UAA'] = 1, ['UAG'] = 2, ['UGA'] = 3,
}
amino_table = {
-- {short, abbrev, longname, hydro, scale, pref, mol wt, isoelectric point (pl), van der waals volume, abbrevcap, codon}
['a'] = {'a', 'Ala', 'Alanine', 'phobic', -1.6, 'H', 89.09404, 6.01, 67, 'ALA', codon = { [1] = 'GCU', [2] = 'GCC', [3] = 'GCA', [4] = 'GCG', }, },
['c'] = {'c', 'Cys', 'Cysteine', 'phobic', -17, 'E', 121.15404, 5.05, 86, 'CYS', codon = { [1] = 'UGU', [2] = 'UGC', }, },
['d'] = {'d', 'Asp', 'Aspartic acid', 'philic', 6.7, 'L', 133.10384, 2.85, 91, 'ASP', codon = { [1] = 'GAU', [2] = 'GAC', }, },
['e'] = {'e', 'Glu', 'Glutamic acid', 'philic', 8.1, 'H', 147.13074, 3.15, 109, 'GLU', codon = { [1] = 'GAA', [2] = 'GAG', }, },
['f'] = {'f', 'Phe', 'Phenylalanine', 'phobic', -6.3, 'E', 165.19184, 5.49, 135, 'PHE', codon = { [1] = 'UUU', [2] = 'UUC', }, },
['g'] = {'g', 'Gly', 'Glycine', 'phobic', 1.7, 'L', 75.06714, 6.06, 48, 'GLY', codon = { [1] = 'GGU', [2] = 'GGC', [3] = 'GGA', [4] = 'GGG', }, },
['h'] = {'h', 'His', 'Histidine', 'philic', -5.6, 'L', 155.15634, 7.60, 118, 'HIS', codon = { [1] = 'CAU', [2] = 'CAC', }, },--Note: Histidine has no conformational 'pref'
['i'] = {'i', 'Ile', 'Isoleucine', 'phobic', -2.4, 'E', 131.17464, 6.05, 124, 'ILE', codon = { [1] = 'AUU', [2] = 'AUC', [3] = 'AUA', }, },
['k'] = {'k', 'Lys', 'Lysine', 'philic', 6.5, 'H', 146.18934, 9.60, 135, 'LYS', codon = { [1] = 'AAA', [2] = 'AAG', }, },
['l'] = {'l', 'Leu', 'Leucine', 'phobic', 1, 'H', 131.17464, 6.01, 124, 'LEU', codon = { [1] = 'UUA', [2] = 'UUG', [3] = 'CUU', [4] = 'CUC', [5] = 'CUA', [6] = 'CUG', }, },
['m'] = {'m', 'Met', 'Methionine', 'phobic', 3.4, 'H', 149.20784, 5.74, 124, 'MET', codon = { [1] = 'AUG', }, },
['n'] = {'n', 'Asn', 'Asparagine', 'philic', 8.9, 'L', 132.11904, 5.41, 96, 'ASN', codon = { [1] = 'AAU', [2] = 'AAC', }, },
['p'] = {'p', 'Pro', 'Proline', 'phobic', -0.2, 'L', 115.13194, 6.30, 90, 'PRO', codon = { [1] = 'CCU', [2] = 'CCC', [3] = 'CCA', [4] = 'CCG', }, },
['q'] = {'q', 'Gln', 'Glutamine', 'philic', 9.7, 'H', 146.14594, 5.65, 114, 'GLN', codon = { [1] = 'CAA', [2] = 'CAG', }, },
['r'] = {'r', 'Arg', 'Arginine', 'philic', 9.8, 'H', 174.20274, 10.76, 148, 'ARG', codon = { [1] = 'CGU', [2] = 'CGC', [3] = 'CGA', [4] = 'CGG', [5] = 'AGA', [6] = 'AGG', }, },
['s'] = {'s', 'Ser', 'Serine', 'philic', 3.7, 'L', 105.09344, 5.68, 73, 'SER', codon = { [1] = 'UCU', [2] = 'UCC', [3] = 'UCA', [4] = 'UCG', [5] = 'AGU', [6] = 'AGC', }, },
['t'] = {'t', 'Thr', 'Threonine', 'philic', 2.7, 'E', 119.12034, 5.60, 93, 'THR', codon = { [1] = 'ACU', [2] = 'ACC', [3] = 'ACA', [4] = 'ACG', }, },
['v'] = {'v', 'Val', 'Valine', 'phobic', -2.9, 'E', 117.14784, 6.00, 105, 'VAL', codon = { [1] = 'GUU', [2] = 'GUC', [3] = 'GUA', [4] = 'GUG', }, },
['w'] = {'w', 'Trp', 'Tryptophan', 'phobic', -9.1, 'E', 204.22844, 5.89, 163, 'TRP', codon = { [1] = 'UGG', }, },
['y'] = {'y', 'Tyr', 'Tyrosine', 'phobic', -5.1, 'E', 181.19124, 5.64, 141, 'TYR', codon = { [1] = 'UAU', [2] = 'UAC', }, },
--[[ ['b'] = {'b', 'Asx', 'Asparagine or Aspartic acid'},
['j'] = {'j', 'Xle', 'Leucine or Isoleucine'},
['o'] = {'o', 'Pyl', 'Pyrrolysine'},
['u'] = {'u', 'Sec', 'Selenocysteine'},
['x'] = {'x', 'Xaa', 'Unspecified or unknown amino acid'},
['z'] = {'z', 'Glx', 'Glutamine or glutamic acid'},
]]--
}
-- Note: * UAG is normally the amber stop codon, but encodes pyrrolysine if a PYLIS element is present.
-- Note: ** UGA is normally the opal (or umber) stop codon, but encodes selenocysteine if a SECIS element is present.
--Amino Acid properties
--[[
Amino Acid Abbrev. Remarks
------------------------------------------------------------------------------
Alanine A Ala Very abundant, very versatile. More stiff than glycine, but small enough to pose only small steric limits for the protein conformation. It behaves fairly neutrally, and can be located in both hydrophilic regions on the protein outside and the hydrophobic areas inside.
Asparagine or aspartic acid B Asx A placeholder when either amino acid may occupy a position.
Cysteine C Cys The sulfur atom bonds readily to heavy metal ions. Under oxidizing conditions, two cysteines can join together in a disulfide bond to form the amino acid cystine. When cystines are part of a protein, insulin for example, the tertiary structure is stabilized, which makes the protein more resistant to denaturation; therefore, disulfide bonds are common in proteins that have to function in harsh environments including digestive enzymes (e.g., pepsin and chymotrypsin) and structural proteins (e.g., keratin). Disulfides are also found in peptides too small to hold a stable shape on their own (eg. insulin).
Aspartic acid D Asp Behaves similarly to glutamic acid. Carries a hydrophilic acidic group with strong negative charge. Usually is located on the outer surface of the protein, making it water-soluble. Binds to positively-charged molecules and ions, often used in enzymes to fix the metal ion. When located inside of the protein, aspartate and glutamate are usually paired with arginine and lysine.
Glutamic acid E Glu Behaves similar to aspartic acid. Has longer, slightly more flexible side chain.
Phenylalanine F Phe Essential for humans. Phenylalanine, tyrosine, and tryptophan contain large rigid aromatic group on the side-chain. These are the biggest amino acids. Like isoleucine, leucine and valine, these are hydrophobic and tend to orient towards the interior of the folded protein molecule. Phenylalanine can be converted into Tyrosine.
Glycine G Gly Because of the two hydrogen atoms at the alpha carbon, glycine is not optically active. It is the smallest amino acid, rotates easily, adds flexibility to the protein chain. It is able to fit into the tightest spaces, e.g., the triple helix of collagen. As too much flexibility is usually not desired, as a structural component it is less common than alanine.
Histidine H His In even slightly acidic conditions protonation of the nitrogen occurs, changing the properties of histidine and the polypeptide as a whole. It is used by many proteins as a regulatory mechanism, changing the conformation and behavior of the polypeptide in acidic regions such as the late endosome or lysosome, enforcing conformation change in enzymes. However only a few histidines are needed for this, so it is comparatively scarce.
Isoleucine I Ile Essential for humans. Isoleucine, leucine and valine have large aliphatic hydrophobic side chains. Their molecules are rigid, and their mutual hydrophobic interactions are important for the correct folding of proteins, as these chains tend to be located inside of the protein molecule.
Leucine or isoleucine J Xle A placeholder when either amino acid may occupy a position
Lysine K Lys Essential for humans. Behaves similarly to arginine. Contains a long flexible side-chain with a positively-charged end. The flexibility of the chain makes lysine and arginine suitable for binding to molecules with many negative charges on their surfaces. E.g., DNA-binding proteins have their active regions rich with arginine and lysine. The strong charge makes these two amino acids prone to be located on the outer hydrophilic surfaces of the proteins; when they are found inside, they are usually paired with a corresponding negatively-charged amino acid, e.g., aspartate or glutamate.
Leucine L Leu Essential for humans. Behaves similar to isoleucine and valine. See isoleucine.
Methionine M Met Essential for humans. Always the first amino acid to be incorporated into a protein; sometimes removed after translation. Like cysteine, contains sulfur, but with a methyl group instead of hydrogen. This methyl group can be activated, and is used in many reactions where a new carbon atom is being added to another molecule.
Asparagine N Asn Similar to aspartic acid. Asn contains an amide group where Asp has a carboxyl.
Pyrrolysine O Pyl Similar to lysine, with a pyrroline ring attached.
Proline P Pro Contains an unusual ring to the N-end amine group, which forces the CO-NH amide sequence into a fixed conformation. Can disrupt protein folding structures like alpha helix or beta sheet, forcing the desired kink in the protein chain. Common in collagen, where it often undergoes a posttranslational modification to hydroxyproline.
Glutamine Q Gln Similar to glutamic acid. Gln contains an amide group where Glu has a carboxyl. Used in proteins and as a storage for ammonia. The most abundant Amino Acid in the body.
Arginine R Arg Functionally similar to lysine.
Serine S Ser Serine and threonine have a short group ended with a hydroxyl group. Its hydrogen is easy to remove, so serine and threonine often act as hydrogen donors in enzymes. Both are very hydrophilic, therefore the outer regions of soluble proteins tend to be rich with them.
Threonine T Thr Essential for humans. Behaves similarly to serine.
Selenocysteine U Sec Selenated form of cysteine, which replaces sulfur.
Valine V Val Essential for humans. Behaves similarly to isoleucine and leucine. See isoleucine.
Tryptophan W Trp Essential for humans. Behaves similarly to phenylalanine and tyrosine (see phenylalanine). Precursor of serotonin. Naturally fluorescent.
Unknown X Xaa Placeholder when the amino acid is unknown or unimportant.
Tyrosine Y Tyr Behaves similarly to phenylalanine (precursor to Tyrosine) and tryptophan (see phenylalanine). Precursor of melanin, epinephrine, and thyroid hormones. Naturally fluorescent, although fluorescence is usually quenched by energy transfer to tryptophans.
Glutamic acid or glutamine Z Glx A placeholder when either amino acid may occupy a position.
REFERENCES
http://en.wikipedia.org/wiki/List_of_standard_amino_acids
Bonding power: (source: enzyme)
+: {'s','t','n','q','r','h','k','d','e','w','y'}
1+: {'n','q','h','k','d','e','w'}
3+: {'r'}
+-: {'s','t','y'}
1+, 1-: {'n','q','h','d','e'}
-: {'s','t','n','q','h','d','e','y'}
1-: {'n','q','h','d','e'}
0: {'v','l','m','p','i','a','c','f','g'}
PrimaryStructureDialog.serineInd = dialog.AddCheckbox("serine(s) 1+-", structure.ApprovedResidues.s)
PrimaryStructureDialog.threonineInd = dialog.AddCheckbox("threonine(t) 1+-", structure.ApprovedResidues.t)
PrimaryStructureDialog.asparagineInd = dialog.AddCheckbox("asparagine(n) 1+, 1-", structure.ApprovedResidues.n)
PrimaryStructureDialog.glutamineInd = dialog.AddCheckbox("glutamine(q) 1+, 1-", structure.ApprovedResidues.q)
PrimaryStructureDialog.arginineInd = dialog.AddCheckbox("arginine(r) 3+", structure.ApprovedResidues.r)
PrimaryStructureDialog.histidineInd = dialog.AddCheckbox("histidine(h) 1+, 1-", structure.ApprovedResidues.h)
PrimaryStructureDialog.lysineInd = dialog.AddCheckbox("lysine(k) 1+", structure.ApprovedResidues.k)
PrimaryStructureDialog.aspartateInd = dialog.AddCheckbox("aspartic acid(d) 1+, 1-", structure.ApprovedResidues.d)
PrimaryStructureDialog.glutamateInd = dialog.AddCheckbox("glutamic acid(e) 1+, 1-", structure.ApprovedResidues.e)
PrimaryStructureDialog.valineInd = dialog.AddCheckbox("valine(v)", structure.ApprovedResidues.v)
PrimaryStructureDialog.tryptophanInd = dialog.AddCheckbox("tryptophan(w) 1+", structure.ApprovedResidues.w)
PrimaryStructureDialog.tyrosineInd = dialog.AddCheckbox("tyrosine(y) 1+-", structure.ApprovedResidues.y)
PrimaryStructureDialog.leucineInd = dialog.AddCheckbox("leucine(l)", structure.ApprovedResidues.l)
PrimaryStructureDialog.methionineInd = dialog.AddCheckbox("methionine(m)", structure.ApprovedResidues.m)
PrimaryStructureDialog.prolineInd = dialog.AddCheckbox("proline(p)", structure.ApprovedResidues.p)
PrimaryStructureDialog.isoleucineInd = dialog.AddCheckbox("isoleucine(i)", structure.ApprovedResidues.i)
PrimaryStructureDialog.alanineInd = dialog.AddCheckbox("alanine(a)", structure.ApprovedResidues.a)
PrimaryStructureDialog.cystineInd = dialog.AddCheckbox("cystine(c) sulfide", structure.ApprovedResidues.c)
PrimaryStructureDialog.phenylalanineInd = dialog.AddCheckbox("phenylalanine(f)", structure.ApprovedResidues.f)
PrimaryStructureDialog.glycineInd = dialog.AddCheckbox("glycine(g)", structure.ApprovedResidues.g)
]]--
--Library of Amino Acid properties by jeff101 (Foldit player)
--v1 22 Jan 2016
-----------------------------------------------------------------
--START Library of Amino Acid properties by jeff101
--Free for non commercial use providing the source is aknowledged
--Source: jeff101 (Copyright) based on the following sources:
-- L75=Biochemistry by Lehninger 2nd Ed 1975 ISBN=0-87901-047-9
-- from Sigma 1998 catalog
-- JJR Frausto da Silva and RJP Williams' The Biological Chemistry of the Elements ISBN=0-19-855802-3
-- L&B=SJ Lippard and JM Berg's Principles of Bioinorganic Chemistry ISBN=0-935702-73-3
-- Alberts' Molecular Biology of the Cell ISBN=0-8240-3695-6
-- CRC 1980-1 61st Edition
-- C&SI=Cantor & Schimmel's Biophysical Chemistry Part I: The conformation of biological macromolecules ISBN=0-7167-1188-5
-- B&T=Branden & Tooze's Introduction to Protein Structure ISBN=0-8153-0270-3
-- Stryer=Lubert Stryer's Biochemistry 4th Edition ISBN=0-7167-2009-4
--
-- LUA transposed by Bruno Kestemont
--USE: All the AAs and properties are in the same order
--Copy-paste the properties you need in your recipes, comment the other ones in order to avoid duplications of names.
--EXTRACT this only an extract for Maaa
AAshort ={'a','c','d','e','f','g','h','i','k','l','m','n','p','q','r','s','t','v','w','y'} --
AAname ={'Alanine','Cysteine','Aspartic Acid','Glutamic Acid','Phenylalanine','Glycine','Histidine','Isoleucine','Lysine','Leucine','Methionine','Asparagine','Proline','Glutamine','Arginine','Serine','Threonine','Valine','Tryptophan','Tyrosine'} --p.73 L75
FreqInProt ={8.3,1.7,5.3,6.2,3.9,7.2,2.2,5.2,5.7,9,2.4,4.4,5.1,4,5.7,6.9,5.8,6.6,1.3,3.2} --frequency in proteins (%)
VolumeVDW ={67,86,91,109,135,48,118,124,135,124,124,96,90,114,148,73,93,105,163,141} --VDW volume in cubic A
Pa ={1.41,0.66,0.99,1.59,1.16,0.43,1.05,1.09,1.23,1.34,1.3,0.76,0.34,1.27,1.21,0.57,0.76,0.9,1.02,0.74} --Pa=a-helix preference
Pb ={0.72,1.4,0.39,0.52,1.33,0.58,0.8,1.67,0.69,1.22,1.14,0.48,0.31,0.98,0.84,0.96,1.17,1.87,1.35,1.45} --Pb=b-strand preference
Pt ={0.82,0.54,1.24,1.01,0.59,1.77,0.81,0.47,1.07,0.57,0.52,1.34,1.32,0.84,0.9,1.22,0.9,0.41,0.65,0.76} --Pt=reverse turn preference
fa ={0.522,0.278,0.351,0.549,0.402,0.19,0.446,0.358,0.383,0.48,0.429,0.263,0.212,0.421,0.282,0.282,0.295,0.409,0.409,0.22} --fa=freq helical
pb ={0.167,0.222,0.137,0.044,0.219,0.138,0.122,0.274,0.126,0.209,0.286,0.113,0.106,0.211,0.154,0.124,0.205,0.282,0.203,0.22} --fb=freq beta
Hfreq ={1.29,1.11,1.04,1.44,1.07,0.56,1.22,0.97,1.23,1.3,1.47,0.9,0.52,1.27,0.96,0.82,0.82,0.91,0.99,0.72} --alpha-helix frequency
Sfreq ={0.9,0.74,0.72,0.75,1.32,0.92,1.08,1.45,0.77,1.02,0.97,0.76,0.64,0.8,0.99,0.95,1.21,1.49,1.14,1.25} --beta-sheet frequency
Lfreq ={0.78,0.8,1.41,1,0.58,1.64,0.69,0.51,0.96,0.59,0.39,1.28,1.91,0.97,0.88,1.33,1.03,0.47,0.75,1.05} --beta-turn frequency
--END Amino Acid properties by jeff101 (EXTRACT)
amino = {}
function amino.abbrev_to_short(abbrev)
end -- function amino.abbrev_to_short
function amino.longname_to_short(longname)
end -- function amino.longname_to_short
function amino.abbrev(seg)
return amino_table[seg][amino_part.abbrev]
end -- function _abbrev
function amino.abbrevcap(seg) -- New BK 22/3/13
return amino_table[seg][amino_part.abbrevcap]
end -- function _abbrev capitals
function amino.long(seg)
return amino_table[seg][amino_part.longname]
end -- function _long
function amino.h(seg)
return amino_table[seg][amino_part.hydro]
end -- function _h
function amino.hscale(seg)
return amino_table[seg][amino_part.scale]
end -- function _hscale
function amino.pref(seg)
return amino_table[seg][amino_part.pref]
end -- function _pref
function amino.size(seg)
return amino_table[seg][amino_part.mol]
end -- function _mol
function amino.charge(seg)
return amino_table[seg][amino_part.pl]
end -- function _pl
function amino.vdw_vol (seg)
return amino_table[seg][amino_part.vdw_vol]
end -- _vdw_vol
function amino.codon(_cdn)
return amino_table[seg].codon[amino_part.codon [ _cdn ] ]
end -- function _codon
-- is there another way to do this? string.subs I guess
function string.at(str,i) return string.char(string.byte(str,i)) end-- from Brow42
--pas utilise
function WritePrimaryStructure() -- from Brow42
local n = structure.GetCount()
local tab
local input = string.lower(dlg.possibleaa.value)
local aalist = string.lower('ACDEFGHIKLMNPQRSTVWY +#')
local aa = {} -- valid aa lookup table
for i = 1,#aalist do aa[string.at(aalist,i)] = true end
--tab = StringToTable(input,dialogs.write.range.value)
if tab == nil then return false end
return true
end
--fin pas utilise
prohibidedText= "a g p c"
--Speclist={} -- where to work on
SpecListAAText="a g p v l m i c f s t r h k d e w y n q"
possibleaa= SpecListAAText
onlymutate= true
useRegion={} -- where to work on
prefHbond=false
mixtables=1
randomly=false
Hydrophobic=false
Hydrophilic=false
prefhelix=false
prefsheet=false
prefloop=false
AlienKill=false
sooc=true -- should be false for HBond puzzles in order to allow alanin and serine
if HBONDPUZZLE then sooc=false end
Probabilistic=false
function AAnb(AA) -- returns the number of the AA
for i= 1, #AAshort do
if AA== AAshort[i] then return i end
end
end
function Max(list) -- returns the bigger value of a list
local result = -999999
for i= 1, #list do
if list[i]> result then result=list[i] end
end
return result
end
function Min(list) -- returns the bigger value of a list
local result = 999999
for i= 1, #list do
if list[i]< result then result=list[i] end
end
return result
end
function probabilisticAction(AA, ProbList) -- returns true following a list of probabilities
if list==nil or AA== nil then return true end
local result=true
local n=AAnb(AA)
local prob=100
local lottery=100
if Probabilistic then
lottery=random(Min(ProbList),Max(ProbList))
prob=ProbList[n]
if prob< lottery then result = false end
end
return result
end
function InitUseregionBool()--init
local useRegion1={} -- start with 1 dimension (list)
for i=1,segCnt do
useRegion1[i]=i
end
--useRegion=SegmentListMinus(useRegion,FindLockedList()) -- 14/05/2015
useRegionBool=SegmentListToBool(useRegion1)
end
function GetParam()
local askresult
repeat
local dlg = dialog.CreateDialog(i18.maaa.intro1)
--dlg.l=dialog.AddLabel("Format: Dbut1[,Fin1-Dbut2,Fin2...]")
--dlg.numseg=dialog.AddTextbox("Segment num.", "")
dlg.segStart=dialog.AddTextbox(i18.ask.options.segStart, segStart)
dlg.segEnd=dialog.AddTextbox(i18.ask.options.segEnd, segEnd)
--dlg.l1=dialog.AddLabel("AAs: a c d e f g h i k l m n p q r s t v w y")
dlg.possibleaa= dialog.AddTextbox(i18.ask.options.possibleaa, possibleaa)
--dlg.l1aa=dialog.AddLabel("Non Bonding: a g p v l m i c f")
dlg.l1a=dialog.AddLabel("a= ALA, g= GLY, p= PRO, ... cf Wiki")
--dlg.prohibidedaa= dialog.AddTextbox("aa interdit", 'a')
dlg.prohibidedText= dialog.AddTextbox(i18.ask.options.prohibided, prohibidedText)
--dlg.randomly = dialog.AddCheckbox(i18.ask.options.randomly, randomly)
dlg.l1aaa=dialog.AddLabel(i18.ask.options.mixtablesIntro)
dlg.mixtables = dialog.AddSlider(i18.ask.options.mixtables, mixtables, 1, 6, 0)
dlg.l1aab=dialog.AddLabel("--------------")
dlg.prefHbond = dialog.AddCheckbox(i18.ask.options.prefHbond, prefHbond)
dlg.Hydrophobic = dialog.AddCheckbox(i18.ask.options.Hydrophobic, Hydrophobic)
dlg.Hydrophilic = dialog.AddCheckbox(i18.ask.options.Hydrophilic, Hydrophilic)
dlg.l1ab=dialog.AddLabel("--------------")
dlg.prefhelix = dialog.AddCheckbox(i18.ask.options.prefhelix, prefhelix)
dlg.prefsheet = dialog.AddCheckbox(i18.ask.options.prefsheet, prefsheet)
dlg.prefloop = dialog.AddCheckbox(i18.ask.options.prefloop, prefloop)
dlg.sooc = dialog.AddCheckbox(i18.ask.options.sooc, sooc)--new BK 3/6/13
dlg.Probabilistic = dialog.AddCheckbox("Probabilistic mutation", Probabilistic)--new BK 22/1/2016
--dlg.CompareVolume = dialog.AddCheckbox("Same volume (fast)", CompareVolume)--new BK 5/1/2021
dlg.MaxVolumeRatio = dialog.AddSlider("Max volume ratio", MaxVolumeRatio, 1, 3.4, 1)
dlg.AlienKill = dialog.AddCheckbox(i18.ask.options.AlienKill, AlienKill)
--dlg.l1=dialog.AddLabel(i18.ask.options.l1)
dlg.rapide = dialog.AddCheckbox(i18.ask.options.rapide, rapide)
dlg.preserve = dialog.AddCheckbox(i18.ask.options.preserve, preserve)
dlg.hydropreserve = dialog.AddCheckbox(i18.ask.options.hydropreserve, hydropreserve)
dlg.superquick = dialog.AddCheckbox(i18.ask.options.superquick, superquick)
dlg.onlymutate = dialog.AddCheckbox(i18.ask.options.onlymutate, onlymutate)
dlg.filtermgt = dialog.AddCheckbox(i18.ask.options.filtermgt, filtermgt)
--dlg.afcppg = dialog.AddSlider(i18.ask.options.afcppg, afcppg, -1, 1, 1)
dlg.afcppg = dialog.AddSlider("Filter cost allowed per gain", afcppg, -1, 1, 1)
--dlg.selected=dialog.AddCheckbox("Set selection where to work NOT USED YET",false)
dlg.selection=dialog.AddButton("Select",2)
dlg.ok = dialog.AddButton(i18.ask.ok, 1)
dlg.cancel = dialog.AddButton(i18.ask.cancel, 0)
askresult=dialog.Show(dlg)
if askresult > 0 then
--numseg = dlg.numseg.value
segStart= dlg.segStart.value
segEnd= dlg.segEnd.value
--prohibidedaa= dlg.prohibidedaa.value
prohibidedText=dlg.prohibidedText.value
prefHbond=dlg.prefHbond.value
prohibidedList={}
if prohibidedText ~= "" then
for text in prohibidedText:gmatch('(%S*)') do -- %g*: represents all list of printable characters except space
table.insert(prohibidedList,text) -- va donner une liste
end
prohibidedText=SegmentListToString(prohibidedList) -- for DEBUG
p("Exclude: " ..prohibidedText) -- for DEBUG
end
mixtables=dlg.mixtables.value
--randomly=dlg.randomly.value
Hydrophobic=dlg.Hydrophobic.value
Hydrophilic=dlg.Hydrophilic.value
sooc=dlg.sooc.value
Probabilistic=dlg.Probabilistic.value
--CompareVolume=dlg.CompareVolume.value
MaxVolumeRatio=dlg.MaxVolumeRatio.value
if sooc then--new BK 3/6/13
prefhelix=false
prefsheet=false
prefloop=false
else
prefhelix=dlg.prefhelix.value
prefsheet=dlg.prefsheet.value
prefloop=dlg.prefloop.value
end
AlienKill=dlg.AlienKill.value
rapide=dlg.rapide.value
preserve=dlg.preserve.value
hydropreserve=dlg.hydropreserve.value
superquick=dlg.superquick.value
onlymutate=dlg.onlymutate.value
filtermgt=dlg.filtermgt.value
afcppg=dlg.afcppg.value
if Hydrophobic then
if Hydrophilic then
if prefhelix then
if prefsheet then
if prefloop then chains=aaall--tout
else chains=aanotloop --tout sauf loop
end
else
if prefloop then chains=aanotsheet--tout sauf sheet
else chains=aahelix --seulement helix (ni sheet ni loop)
end
end
else -- pas d'helice
if prefsheet then
if prefloop then chains=aanothelix--tout sauf helice
else chains=aasheet --seulement sheet (ni loop ni helice)
end
else
if prefloop then chains=aaloop--seulement loop (ni sheet ni helice)
else chains=aaall --tout si rien n'est coche
end
end
end
else -- rien que hydrophobe
if prefhelix then
if prefsheet then
if prefloop then chains=aaphobic--tout hydrophobe
else chains=aanotloopphobic --tout hydrophobe sauf loop
end
else
if prefloop then chains=aanotsheetphobic--tout hydrophobe sauf sheet
else chains=aahelixphobic --hydrophobe seulement helix (ni sheet ni loop)
end
end
else -- pas d'helice
if prefsheet then
if prefloop then chains=aanothelixphobic--tout hydrophobe sauf helice
else chains=aasheetphobic --hydrophobe seulement sheet (ni loop ni helice)
end
else
if prefloop then chains=aaloopphobic--hydrophobe seulement loop (ni sheet ni helice)
else chains=aaphobic--tout hydrophobe si rien n'est coche
end
end
end
end
else --pas hydrophobe
if Hydrophilic then
if prefhelix then
if prefsheet then
if prefloop then chains=aaphilic--tout hydrophile
else chains=aanotloopphilic --tout hydrophile sauf loop
end
else
if prefloop then chains=aanotsheetphilic--tout hydrophile sauf sheet
else chains=aahelixphilic --hydrophile seulement helix (ni sheet ni loop)
end
end
else -- hydrophile pas d'helice
if prefsheet then
if prefloop then chains=aanothelixphilic--tout hydrophile sauf helice
else chains=aasheetphilic --hydrophile seulement sheet (ni loop ni helice)
end
else
if prefloop then chains=aaloopphilic--hydrophile seulement loop (ni sheet ni helice)
else chains=aaphilic --tout hydrophile si rien n'est coche
end
end
end
else -- rien coche entraine hydrophile ET hydrophobe
if prefhelix then
if prefsheet then
if prefloop then chains=aaall--tout
else chains=aanotloop --tout sauf loop
end
else
if prefloop then chains=aanotsheet--tout sauf sheet
else chains=aahelix -- seulement helix (ni sheet ni loop)
end
end
else -- pas d'helice
if prefsheet then
if prefloop then chains=aanothelix--tout sauf helice
else chains=aasheet -- seulement sheet (ni loop ni helice)
end
else
if prefloop then chains=aaloop-- seulement loop (ni sheet ni helice)
else chains=aaall--tout si rien n'est coche
end
end
end
end
end
if prefHbond then
chains=SegmentCommList(chains, aabonding) -- only what is common to the 2 lists
end
possibleaa = dlg.possibleaa.value
possibleList={}
if possibleaa ~= "" then
for text in possibleaa:gmatch('(%S*)') do -- %g*: represents all list of printable characters except space
table.insert(possibleList,text) -- va donner une liste {"a","b",...}
end
possibleaa=SegmentListToString(possibleList) -- for DEBUG
p("Include: " ..possibleaa) -- for DEBUG
end
--print("Options:\nfast =",rapide," \Dbut =",segStart, " \Fin =", segEnd)
if rapide then printfast="true. " else printfast="false. " end
if preserve then printpreserve="true. " else printpreserve="false. " end
p(i18.maaa.optionsFast.. printfast..i18.ask.options.segStart.." "..segStart.." "..i18.ask.options.segEnd.." "..segEnd)
if AlienKill then print(i18.ask.options.AlienKill) end
if preserve then preserveH=true print(i18.ask.options.preserve) end
print("=======================")
-- new to ask where to work on (from tvdl)
--[[
if dlg.selected.value then -- NOT USED
local SelMode={}
SelMode.askligands=true --override the defaults
SelMode.defligands=true
SelMode.defignorelocks=false
SelMode.defignorefrozen=false
local PullFrom=AskForSelections("Set where to work",SelMode)
for i=1,segCnt do
if SegmentInSet(PullFrom,i) then Speclist[#Speclist+1]=i end
end
useSpeclistBool=SegmentListToBool(Speclist)
end
]]--
if askresult ==2 then
local SelMode={}
useRegionBool={}
--useSpeclistBool={}
SelMode.askligands=true --override the defaults
SelMode.defligands=true
SelMode.askignorelocks=true -- 14/05/2015
SelMode.defignorelocks=false -- 14/05/2015
SelMode.defignorefrozen=false
useRegion=AskForSelections("Set where to work",SelMode) -- attention va etre un set
useRegionBool=SegmentSetToBool(useRegion)
print("Selection is now, reselect if not ok:")
SegmentPrintSet(useRegion)
end
--end new added to ask where to work on (from tvdl)
if askresult < 2 then
return true
end
end
--return false
until askresult < 2
return askresult > 0
end
--TO DO: DEBUG asklist
-- Module AskSelections
-- 02-05-2012 Timo van der Laan, Free to use for non commercial purposes
-- 16-09-2015 Bruno Kestemont added AA lists
function AskForSelections(title,mode)
local result={{1,structure.GetCount()}} -- All segments, WARNING: bidimensional (a set like {n-m,o-p})
if mode == nil then mode={} end
if mode.askloops==nil then mode.askloops=true end
if mode.asksheets==nil then mode.asksheets=true end
if mode.askhelixes==nil then mode.askhelixes=true end
if mode.askligands==nil then mode.askligands=false end
if mode.askselected==nil then mode.askselected=true end
if mode.asknonselected==nil then mode.asknonselected=true end
if mode.askmutateonly==nil then mode.askmutateonly=true end
if mode.askignorelocks==nil then mode.askignorelocks=true end
if mode.askignorefrozen==nil then mode.askignorefrozen=true end
if mode.askignorefrozenSidechains==nil then mode.askignorefrozenSidechains=true end -- NEW 23/9/2020
if mode.askranges==nil then mode.askranges=true end
if mode.asklist==nil then mode.asklist=false end -- NEW BK BUG, put true to activate and debug
if mode.askAA==nil then mode.askAA=true end-- NEW BK 16/9/2015
if mode.defloops==nil then mode.defloops=true end
if mode.defsheets==nil then mode.defsheets=true end
if mode.defhelixes==nil then mode.defhelixes=true end
if mode.defligands==nil then mode.defligands=false end
if mode.defselected==nil then mode.defselected=false end
if mode.defnonselected==nil then mode.defnonselected=false end
if mode.defmutateonly==nil then mode.defmutateonly=true end -- changed 2.4.3 ! Of course !!
if mode.defignorelocks==nil then mode.defignorelocks=false end
if mode.defignorefrozen==nil then mode.defignorefrozen=false end
if mode.defignorefrozenSidechains==nil then mode.defignorefrozenSidechains=false end -- NEW 23/9/2020
local Errfound=false
repeat
local ask = dialog.CreateDialog(title)
if Errfound then
ask.E1=dialog.AddLabel("Try again, ERRORS found, check output box")
result={{1,structure.GetCount()}} --reset start
Errfound=false
end
if mode.askloops then
ask.loops = dialog.AddCheckbox("Work on loops",mode.defloops)
elseif not mode.defloops then
ask.noloops= dialog.AddLabel("Loops will be auto excluded")
end
if mode.askhelixes then
ask.helixes = dialog.AddCheckbox("Work on helixes",mode.defhelixes)
elseif not mode.defhelixes then
ask.nohelixes= dialog.AddLabel("Helixes will be auto excluded")
end
if mode.asksheets then
ask.sheets = dialog.AddCheckbox("Work on sheets",mode.defsheets)
elseif not mode.defsheets then
ask.nosheets= dialog.AddLabel("Sheets will be auto excluded")
end
if mode.askligands then
ask.ligands = dialog.AddCheckbox("Work on ligands",mode.defligands)
elseif not mode.defligands then
ask.noligands= dialog.AddLabel("Ligands will be auto excluded")
end
if mode.askselected then ask.selected = dialog.AddCheckbox("Work only on selected",mode.defselected) end
if mode.asknonselected then ask.nonselected = dialog.AddCheckbox("Work only on nonselected",mode.defnonselected) end
if mode.askmutateonly then ask.mutateonly = dialog.AddCheckbox("Work only on mutateonly",mode.defmutateonly) end
if mode.askignorelocks then
ask.ignorelocks =dialog.AddCheckbox("Dont work on locked ones",false) -- 14/05/2015
elseif mode.defignorelocks then
ask.nolocks=dialog.AddLabel("Locked ones will be auto excluded")
end
if mode.askignorefrozen then
ask.ignorefrozen = dialog.AddCheckbox("Dont work on frozen backbones",false) -- changed true to false 23/9/2020
elseif mode.defignorefrozen then
ask.nofrozen=dialog.AddLabel("Frozen backbones will be auto excluded")
end
if mode.askignorefrozenSidechains then
ask.ignorefrozenSidechains = dialog.AddCheckbox("Dont work on frozen sidechains",true)
elseif mode.defignorefrozenSidechains then
ask.nofrozenSidechains=dialog.AddLabel("Frozen sidechains will be auto excluded")
end
if mode.askranges then
ask.R1=dialog.AddLabel("Or put segment ranges n-m, o-p (Above also counts)")
ask.ranges=dialog.AddTextbox("Ranges","")
end
if mode.asklist then
ask.R1=dialog.AddLabel("Or put in segment list. Above selections also count")
ask.list=dialog.AddTextbox("List","")
end
if mode.askAA then
ask.R11=dialog.AddLabel("Or put AA list (Above also counts)")
ask.AA=dialog.AddTextbox("AAs: ",SpecListAAText)
end
ask.OK = dialog.AddButton("OK",1) ask.Cancel = dialog.AddButton("Cancel",0)
if dialog.Show(ask) > 0 then
-- We start with all the segments including ligands
if mode.askloops then mode.defloops=ask.loops.value end
if not mode.defloops then
result=SegmentSetMinus(result,FindAAtype("L"))
end
if mode.asksheets then mode.defsheets=ask.sheets.value end
if not mode.defsheets then
result=SegmentSetMinus(result,FindAAtype("E"))
end
if mode.askhelixes then mode.defhelixes=ask.helixes.value end
if not mode.defhelixes then
result=SegmentSetMinus(result,FindAAtype("H"))
end
if mode.askligands then mode.defligands=ask.ligands.value end
if not mode.defligands then
result=SegmentSetMinus(result,FindAAtype("M"))
end
if mode.askignorelocks then mode.defignorelocks=ask.ignorelocks.value end
if mode.defignorelocks then
result=SegmentSetMinus(result,FindLocked())
end
if mode.askignorefrozen then mode.defignorefrozen=ask.ignorefrozen.value end
if mode.defignorefrozen then
result=SegmentSetMinus(result,FindFrozen())
end
if mode.askignorefrozenSidechains then mode.defignorefrozenSidechains=ask.ignorefrozenSidechains.value end-- NEW 23/9/2020
if mode.defignorefrozenSidechains then -- NEW 23/9/2020
result=SegmentSetMinus(result,FindFrozenSidechains())
end
if mode.askselected then mode.defselected=ask.selected.value end
if mode.defselected then
result=SegmentCommSet(result,FindSelected())
end
if mode.asknonselected then mode.defnonselected=ask.nonselected.value end
if mode.defnonselected then
result=SegmentCommSet(result,SegmentInvertSet(FindSelected()))
end
if mode.askranges and ask.ranges.value ~= "" then
local rangetext=ask.ranges.value
local function Checknums(nums)
-- Now checking
if #nums%2 ~= 0 then -- we must have pairs of numbers !
print("Not an even number of segments found")
return false
end
for i=1,#nums do
if nums[i]==0 or nums[i]>structure.GetCount() then
print("Number "..nums[i].." is not a segment")
return false
end
end
return true
end
local function ReadSegmentSet(data)
local nums = {}
local NoNegatives='%d+' -- - is not part of a number
local result={}
for v in string.gfind(data,NoNegatives) do
table.insert(nums, tonumber(v)) -- nums is a set here
end
if Checknums(nums) then
for i=1,#nums/2 do
result[i]={nums[2*i-1],nums[2*i]}
end
result=SegmentCleanSet(result)
else Errfound=true result={} end
return result
end
local rangelist=ReadSegmentSet(rangetext)
if not Errfound then
result=SegmentCommSet(result,rangelist)
end
end
if mode.asklist and ask.list.value ~= "" then -- TO DO !!! DOIT SORTIR EN SET !!
local listtext=ask.list.value
local function Checknums(nums)
-- Now checking
for i=1,#nums do
if nums[i]==0 or nums[i]>structure.GetCount() then
print("Number "..nums[i].." is not a segment")
return false
end
end
return true
end
local function ReadSegmentList(data) -- TO DO !!!
local nums = {}
local NoNegatives='%d+' -- - is not part of a number
local result={}
for v in string.gfind(data,NoNegatives) do
table.insert(nums, tonumber(v)) -- nums is a list here
end
if Checknums(nums) then
result=SegmentCleanList(nums)
result=SegmentListToSet(result)
else Errfound=true result={} end
return result
end
local listlist=ReadSegmentList(listtext)
if not Errfound then
--result=SegmentListToSet(SegmentCommList(result,listlist)) -- returns a set
result=SegmentListToSet(listlist)
end
print("Result now: ")
SegmentPrintSet(result) -- DEBUG
end
if mode.askAA and ask.AA.value ~= "" then -- returns a set of segments with selected AAs BK 16/9/2015
local AAText=ask.AA.value
local listAAlist={}
for text in AAText:gmatch('(%S*)') do -- %g*: represents all list of printable characters except space
table.insert(listAAlist,{text}) -- va donner une liste sous forme "a", "b", ...
end
SpecListAAText=SegmentListToString(listAAlist) -- update of the default list displayed
p("Selecting segments with: " ..SpecListAAText)
local function AA2Seg(listAA) -- gives a list of segments with selected AAs
local listseg={}
local CurrentAA=""
for i= 1, segCnt2 do
CurrentAA= structure.GetAminoAcid(i)
if listAA:find(CurrentAA) then
table.insert(listseg,i)
end
end
return listseg -- a list (table)
end
result=SegmentCommSet(result,SegmentListToSet(AA2Seg(SpecListAAText)))
end
end
until not Errfound
return result
end
-- end of module AskSelections
function Adieu()
local askresult
repeat
local dlg = dialog.CreateDialog(i18.maaa.intro1)
dlg.abandon=dialog.AddLabel(i18.ask.abandon)
dlg.ok = dialog.AddButton(i18.ask.ok, 1)
askresult=dialog.Show(dlg)
if askresult > 0 then return end
until askresult < 2
return askresult > 0
end
function Scoremodule()
p(i18.maaa.intro2..startingscore)
local score=Score()
startTimeLoop=os.time()
local RecTime=(os.time()-startTime)/60 -- en minutes
if not AlienKill and score<=maxScore then
--print("... ne gagna rien en "..RecTime.." minutes")
p(i18.maaa.nogain..RecTime.." minutes")
recentbest.Restore()
else -- note: if allien kill, prints negative gain
gainT=score-startingscore
save.Quicksave(3)
--print("... gagna ".. round(gainRecipe).." points en "..down(RecTime).." minutes".."Mutated segs:")
p(i18.maaa.gainT..round(gainT)..i18.maaa.gain2..down(RecTime).." minutes.")
if AlienKill then print("Note: "..i18.ask.options.AlienKill.." !") end
print(nbmutateseg, i18.maaa.mutatedsegs)
SegmentPrintListToSet(mutatesegs) -- 14/04/2014
--SegmentListToSet(mutatesegs) -- 14/04/2014
end
end
function saasooc(sg,aaa) --new BK 3/6/13 aa structure out of content
autorisestr=true
local aas=structure.GetSecondaryStructure(sg)
local aaapref=amino.pref(aaa)
if aas==aaapref then
autorisestr=true
else autorisestr=false
end
end
function GoodHydro(sg,aaa) -- new BK 30/05/2018 for case hydropreserve
if autorisestr then -- autorisestr is already defined before for SS in saasooc
local hydrophobicSeg= "philic"
local aaaH=amino.h(aaa) -- gets phobic or philic
if structure.IsHydrophobic(sg) then hydrophobicSeg= "phobic" end
if aaaH==hydrophobicSeg then
--autorisestr=true
else autorisestr=false
end
end
end
function interditaa(aaa) --12/4/2014 says if aaa is prohibided
if prohibidedText:find(aaa)then -- aaa is whritten short, ex: "a" for alanine
return true
else return false
end
end
function notefind(sg,aaa) -- not sure Foldit still uses the notes to write authorised AAs.
notelibre=false
autorise= true
--noteread(sg)
if #saveNote>0 and saveNote:find(aaa) then
autorise= true
notelibre=false
elseif #saveNote>0 then
autorise= false
if saveNote:find("+") or saveNote:find("1") or saveNote:find("JET") then
autorise= true
end
if saveNote:find("Bruno") or saveNote:find("Ebola") or saveNote:find("2") or saveNote:find("pauldunn") then
autorise= true
end
notelibre=false
else
autorise= true
notelibre=true
end
end
function prepareundo() -- appelle chaque backups
undo.SetUndo(true)
save.Quickload(8)
save.Quickload(9)
save.Quickload(10)
save.Quickload(11)
end
function DumpErr(err) -- Based on Jean-Bob
start,stop,line,msg=err:find(":(%d+):%s()")
err=err:sub(msg,#err)
p("---")
if err:find("Cancelled")~=nil then
--p("Arrt utilisateur.")
p(i18.recipe.de1)
prepareundo()
Scoremodule()
WhriteNote() -- New 4/11/2014
else
--p("Erreur inattendue dtecte.")
--p("Ligne d'erreur : "..line)
--p("Message d'erreur : "..err)
p(i18.recipe.de2)
p(i18.recipe.de3..line)
p(i18.recipe.de4..err)
prepareundo()
Scoremodule()
if note1libre then
--p("Sauvegarde de l'tat du script")
p("Saving script settings in note 1")
p(i18.recipe.lw4)
structure.SetNote(1,err)
end
end
CI(1)
end
--MAIN
function main()
checkbadpuzzle()
setlanguage()
multilingual(lang)
--p("Mutate to autorised AAs by Bruno Kestemont")
p(i18.maaa.intro1)
--p("Score de depart: "..startingscore)
p(i18.maaa.intro2..startingscore)
recentbest.Save()
Stanley() -- necessaire pour identifier filtres
if not HASMUTABLE then
Adieu()
return
end
--GetParam()
InitUseregionBool()
if GetParam()==false then
return
end
compteur=0
compteur2=0
for i = segStart, segEnd do
if useRegionBool[i] then -- only in selected list of segments
compteur=compteur+1
WORKONBIS[compteur]=i
end
end
if WORKONBIS =={} then
print("No segment left") return
else
-- retain only the selection
print("Working on: ")
SegmentPrintListToSet(WORKONBIS)
end
chains=SegmentCommList(chains, possibleList)
if HBONDPUZZLE then
chains=SegmentListMinus(chains,aabondingbuns)
print("Not trying lysine (k) and arginine (r)")
end
if chains =={} then
print("No AA left") return
else
-- retain only the selection
print("Try AAs: "..SegmentListToString(chains))
print("...unless: "..prohibidedText)
end
for i=1,10 do
undo.SetUndo(false) -- reset to true at each prepareundo() calls
if mixtables==2 then WORKONBIS=Reverselist(WORKONBIS)
elseif mixtables==3 then randomly=true WORKONBIS=ShuffleTable(WORKONBIS)
elseif mixtables==4 then WORKONBIS=OutwardTable(WORKONBIS)
elseif mixtables==5 then WORKONBIS=InwardTable(WORKONBIS)
elseif mixtables==6 then WORKONBIS=MixInwardTable(WORKONBIS)
end -- else normal from first to last in the list
if onlymutate and i>3 then onlymutate=false end -- desactiver apres 3 rounds
if superquick and i>4 and not onlymutate then superquick=false end -- desactiver apres 4 rounds
if rapide and i>5 and not onlymutate and not superquick then rapide=false end -- desactiver apres 5 rounds
--Zone(segStart,segEnd) -- appelle Brute(sg) pour chaque segment
Zone(1,#WORKONBIS)
FiltreRap=FiltreRap*5 -- exponentiel
if i>1 then AlienKill=false end-- toujours desactiver apres 1 round
if not superquick and not onlymutate and i>2 then
preserveH=false -- toujours desactiver apres 2 rounds
if (i >2 and relD2target<10) or i>7 then preserve=false end -- allow risky wiggle all from 4th round NEW BK 13/11/2013
end -- only when score is high enough: at least 10% from target
prepareundo() -- reprise des meilleurs 14/04/2014
Scoremodule() -- desactiver si stanley desactive
WhriteNote(i) -- New 4/11/2014
print("-----------------------------")
if preserve then print(i18.ask.options.preserve) end
print("-----------------------------")
end
--prepareundo()
end
xpcall(main, DumpErr)