Knowing the name of the Lua functions is a first step to adapting a GUI recipe.
- 1 Ingredients
- 2 Commands
- 2.1 Shake Sidechains
- 2.2 Wiggle
- 2.3 Local Wiggle Sequence
- 2.4 Freeze
- 2.5 Unfreeze
- 2.6 Set structure
- 2.7 Set amino acid
- 2.8 Mutate
- 2.9 Add bands
- 2.10 Disable Band
- 2.11 Enable Band
- 2.12 Delete Band
- 2.13 Change Band Strength
- 2.14 Clashing Importance
- 2.15 Reset Puzzle
- 2.16 Restore Very Best
- 2.17 Set Recent Best
- 2.18 Restore Recent Best
- 2.19 Quicksave
- 2.20 Quickload
- 2.21 Comment
The next step is understanding the "ingredients" that the commands use. In Lua, these ingredients are called "arguments" or "parameters", and are listed in parenthesis after the function name. When a recipe runs, a function gets "called", and "passed" a list of arguments.
Many of the Lua functions have an "all" version. For example, freeze.FreezeAll will freeze all segments. Using this function is similar to picking the "all" option for the segments ingredient of the Freeze command.
The "by stride" option is available for specifying segments on many GUI commands. This option doesn't have a direct equivalent in Lua. There are several ways to achieve the same effect. Many of the Lua functions have a "selected" version. For example, there's structure.WiggleSelected. Segments can be selected using the functions selection.Select, selection.SelectAll, and selection.SelectRange. In the selection interface, the user can also select segments before the recipe starts.
The "user pick" option is the third way to select segments in a GUI recipe. A user pick is similar to selecting segments in the selection interface, but it occurs while the recipe is running. There's no straightforward way to do the same thing in a Lua recipe.
After an initial "user pick", the option of reusing the selection in a user pick becomes available for the segments ingredient. While Lua recipes don't offer a way to make an initial user pick, using a set of segments is easy, and a common feature in Lua recipes.
For a GUI recipe, the segment ingredient is selected using sliders. This prevents errors. In Lua, errors are possible. For example, it's an error to specify segment 101 if there are only 100 segments. It's also an error to specify segment -1. Errors of this type cause the recipe to terminate.
Another key ingredient is the number of iterations, which applies to commands like Shake Sidechains, Wiggle, and Mutate. The GUI commands allow an "until stopped" option, meaning the user must manually terminate the command. The Lua functions don't allow an "until stopped" option. The number of iterations is a required argument.
Several of the GUI commands work with existing bands. See Bands Ingredient for details on this ingredient.
Much like specifying segments, there's an "all" option to process all bands. There are "all" versions of the corresponding Lua functions, which are direct replacement. The GUI band commands also have a "connected" options, which limits them to bands which connect two segments. There's not a direct Lua replacement for the "connected" option, but it's possible to gets the same results using some additional functions.
GUI band commands may also have a "user pick" option. As with the similar option for segments, there's no way to achieve the same results in a Lua recipe.
As with segments, an initial user pick for bands can be reused on subsequent commands in a GUI recipe. Tracking different sets of bands is simple in Lua.
The GUI commands are listed below, along with the equivalent Lua functions.
See Shake Sidechains for details of the GUI command.
The ShakeSidechainsAll function is the same as specifying "all" for the segments ingredient of the Shake Sidechains command.
With ShakeSidechainsSelected, segments can be selected using the functions selection.Select, selection.SelectAll, and selection.SelectRange. Any existing user selections are also included. The function selection.DeselectAll can be used to clear all selections, or selection.Deselect can clear a single selected segment.
See Wiggle for details of the GUI command.
As with the Shake Sidechains command, these two Lua functions work either on all segments or only on selected segments.
Local Wiggle Sequence
See Local Wiggle Sequence for details of the GUI command.
As with Wiggle and Shake Sidechains, there are two flavors of the Lua equivalent.
See Freeze for details of the GUI command.
For the Freeze command, there are once again "all" and "selected" equivalents. The function freeze.Freeze is also available, and freezes just a single segment.
See Unfreeze for details of the GUI command.
See Set structure for details of the GUI command.
Both versions of "set secondary structure" use the codes H for helix, E for sheet, and L for loop. Also, the special code A for "auto" is available, and sets the secondary structure using the auto structures tool. The auto option is not available in GUI recipes.
SetSecondaryStructure sets a single segment, and SetSecondaryStructureSelected sets the selected segments.
Set amino acid
See Set amino acid for details of the GUI command.
Both versions use single-letter codes, which can be found in the amino acids table.
SetAminoAcid sets a single segment, while SetAminoAcidSelected sets all selected segments to same amino acid.
See Mutate for details of the GUI command.
See Add bands for details of the GUI command.
The equivalent Lua function is band.AddBetweenSegments.
The function band.AddToBandEndpoint adds a band which ends at the endpoint of an existing band.
In Lua, all bands are identified by a "band index", which is returned when a band is created by one of the "add" functions.
See Disable Band for details of the GUI command.
Here the "all" version refers to bands, not segments. DisableAll disables all bands, Disable disables a single band, identified by its band index.
The GUI command includes a "connected" option, meaning bands which connect two segments. This type of band can be created by the "Add bands" command in a GUI recipe. Users can also create spacebands, which start on a segment, but end at a point in space. Lua recipes can also create spacebands. There's not a direct replacement for the "connected" option in Lua, but it's possible to achieve the same results by scanning all bands.
See Enable Band for details of the GUI command.
As with the Disable band command, Enable band has a "connected" option, which doesn't have a direct replacement in Lua.
Once again, Delete band has a "connected" option, with no direct Lua replacement.
Change Band Strength
See Change Band Strength for details of the GUI command.
The equivalent Lua function is band.SetStrength, which sets the strength of a single band.
The "Change band strength" command again has a "connected" option.
See Clashing Importance for details of the GUI command.
The equivalent Lua function is behavior.SetClashImportance.
See Reset Puzzle for details of the GUI command.
The equivalent Lua function is puzzle.StartOver.
Restore Very Best
See Restore Very Best for details of the GUI command.
The equivalent Lua function is creditbest.Restore.
Set Recent Best
See Set Recent Best for details of the GUI command.
The equivalent Lua function is recentbest.Save.
Restore Recent Best
See Restore Recent Best for details of the GUI command.
The equivalent Lua function is recentbest.Restore.
See Quicksave for details of the GUI command.
The equivalent Lua function is save.Quicksave.
See Quickload for details of the GUI command.
The equivalent Lua function is save.Quickload.
See Comment for details of the GUI command.
A comment doesn't do anything. In Lua, anything following two dashes ("--") on a line is considered a comment, and is ignored.
Lua also supports block comments. Block comments start with --[[ and end with ]]--. (Alternately, --]] can also be used to close a block comment.)
--[[ This is a block comment. Anything in between the open and close comment markers is ignored. Block comments are often used to comment out blocks of code. ]]-- --[[ This is another block comment. This one uses the alternate close. --]] -- -- this is another type of comment, an in-line comment -- save.Quicksave ( 1 ) -- this is a comment too