Icon representing a recipe

Recipe: Create Backbone v1

created by SemperRabbit

Profile


Name
Create Backbone v1
ID
106929
Shared with
Public
Parent
None
Children
None
Created on
June 08, 2022 at 13:08 PM UTC
Updated on
June 08, 2022 at 13:08 PM UTC
Description

Sets backbone to given sequence; will add optional add/remove residues to match length. Designed primarily for sandbox levels.

Best for


Code


------------------------------------------------------------------------------------ -- Create Backbone v1.0 -- -- This recipe allows a player to input a string of single-character residues, and -- it will resize the backbone, and mutate the residues to match the input string. -- -- This recipe is designed primarily for the sandbox, and not intended for other -- puzzles. -- -- This does not adjust the secondary structure, although I may try to toy with it -- later. -- -- Change Log -- v1.0 (20220608): initial release by SemperRabbit ------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------ -- USER DIALOG BOX ------------------------------------------------------------------------------------ sequence = "" length=0 function GetParams( ) dlg = dialog.CreateDialog( "Create Backbone" ) dlg.sequence = dialog.AddTextbox("Add Sequence", "") dlg.ok = dialog.AddButton( "OK", 1 ) dlg.cancel = dialog.AddButton( "Cancel", 0 ) if dialog.Show( dlg ) > 0 then print( "dialog success" ) sequence = dlg.sequence.value length = tonumber(string.len(sequence)) return true else print( "dialog cancelled" ) return false end end ------------------------------------------------------------------------------------ -- MAIN ENTRY ------------------------------------------------------------------------------------ function main( ) if GetParams() then print( "Original in slot 2" ) save.Quicksave( 2 ) --starting position print( "Length: " .. length ) print( "Sequence: " .. sequence) print( "CurLen: " .. structure.GetCount()) -- resize backbone if too short while structure.GetCount() < length do structure.InsertResidue(structure.GetCount()) end -- resize backbone if too long while structure.GetCount() < length do structure.DeleteResidue(structure.GetCount()) end -- mutate residues to match input string for i = 1, length do structure.SetAminoAcid( i, string.sub(sequence, i, i) ) end else print("Dialog failed to load") end end main ()

Comments