Fandom

Foldit Wiki

Simplified List of Lua Commands

1,464pages on
this wiki
Add New Page
Comments2 Share

Note: the commands (functions) described here are from Version 1 (V1) of the Foldit Lua Interface.

Version 1 recipes are still supported, but using Version 2 is strongly recommended for new recipes. See Foldit Lua Functions for a complete list of version 2 functions.

See Lua Scripting for more on how to write Foldit recipes in Lua. There's also a series of tutorials, starting with Lua Scripting Tutorial (Beginner 1).

The version 1 Lua commands on this page have been divided into three basic categories:

  • "doer" commands
  • "getter" commands
  • "setter" commands

Each command is briefly described and one or more examples are given.

A few of the more complex and infrequently used commands are omitted. See Foldit Lua Functions (v1) for a complete list.

You can copy and paste these commands, then insert your own parameters. Parameters are the things inside the parentheses -- they are italicized in this list to make them easier to identify. There can be zero, one, two, or more parameters depending on the command, so read the description and look at the examples. When a parameter is surrounded by brackets [like this], that means it's optional whether you include it or not.

Remember that you can paste into the Foldit editor with control-V – you may notice a character that looks like an envelope at the end of pasted lines, which is a byproduct of pasting. Don't worry – this won't affect your script – delete the “envelopes” or leave them in as desired.

Doer Commands

Doer commands do something to the protein. The commands do_global_wiggle_all, do_global_wiggle_backbone, and do_local_rebuild can change the shape of all or part of the protein. The commands do_shake and do_global_wiggle_sidechains change the positions of the sidechains, but don't affect the overall shape.

The command do_mutate can change the amino acids that make up the protein. Mutating may effect the score, but it doesn't change the overall shape of the protein.

do_shake([iterations])

Shakes the protein. If nothing is put in parentheses, it shakes forever (until stopped by user.) If a whole number is put in the parentheses, it shakes for iterations rounds.

do_shake()                   -- shakes forever until stopped by user
do_shake(2)                  -- shakes for two rounds

do_global_wiggle_all([iterations])

Global wiggles both sidechains and backbone. If nothing is put in parentheses, it global wiggles all forever (until stopped by user). If a whole number is put in the parentheses, it shakes for iterations rounds.

do_global_wiggle_all()    -- global wiggles all forever until stopped by user
do_global_wiggle_all(3)   -- global wiggles all for three rounds

do_global_wiggle_sidechains([iterations])

Global wiggles sidechains. If nothing is put in parentheses, it global wiggles the sidechains forever (until stopped by user). If a whole number is put in the parenthese, it shakes for iterations rounds.

do_global_wiggle_sidechains()    -- global wiggles sidechains forever until  
                                 -- stopped by user
do_global_wiggle_sidechains(6)   -- global wiggles sidechains for six rounds

do_global_wiggle_backbone([iterations])

Global wiggles backbone. If nothing is put in parentheses, it global wiggles the backbone forever (until stopped by user). If a whole number is put in the parentheses, it shakes for iterations rounds.

do_global_wiggle_backbone()     -- global wiggles backbone forever until
                                -- stopped by user
do_global_wiggle_backbone(4)    -- global wiggles backbone for four rounds

do_local_rebuild([iterations])

Rebuilds the current selection. If nothing is selected, it won't work! If nothing is put in parentheses, it rebuilds forever (until stopped by user). If a whole number is put in the parentheses, it rebuilds for iterations rounds.

do_local_rebuild()        -- rebuilds selection forever until stopped by user
do_local_rebuild(5)       -- rebuilds selection for five rounds

do_mutate([iterations])

Mutates the protein (for design puzzles only, of course!). If nothing is put in the parentheses, mutate runs forever (until stopped by user). If a number (must be a whole number) is put in the parentheses, mutate runs for iterations rounds.

do_mutate()                 -- mutates forever until stopped by user
do_mutate(3)                -- mutates for three rounds

Setter Commands

Setter commands set or store information about, the condition of, or the state of the protein. They don't directly alter a protein like "doers". Saving, loading, banding, and setting secondary structures are all setters because they don't directly change the protein itself. The distinction is a bit tricky -- as one example, consider the fact that bands don't actually change the protein, so adding bands is a set command; but wiggling with bands on does change the protein, so wiggle is a do command.

restore_abs_best()

Restore to the point in the game when you had the absolute best score.

restore_abs_best()

reset_recent_best()

Saves the current game as your "recent best".  You can later restore to this point using restore_recent_best(). 

reset_recent_best()

restore_recent_best()

Restore to the point in the game when you had the recent best score. (Note that the recent best must be set first, either by hand or earlier in the script)

restore_recent_best()

reset_puzzle()

Reset the puzzle, including the secondary structures (loops, helixes, sheets) it had in the beginning.

reset_puzzle()

quicksave(saveslot)

Save the puzzle into the saveslot. There are 10 saveslots you can use.

quicksave(1)               -- save the puzzle into save slot 1

quickload(saveslot)

Load the puzzle last saved in saveslot. There are 10 saveslots you can use.

quickload(1)               -- load the puzzle from save slot 1

band_add_segment_segment(segment1, segment2)

Add a band between segment1 and segment2. Note that both segment1 and segment2 are required!

band_add_segment_segment(1, 5)  -- add band between first and fifth segments

band_set_length(band, length)

Set a band's length. Length must be between 0 and 20.

band_add_segment_segment(1, 5)  -- add band between first and fifth segments
band=get_band_count()           -- find the band's index number
band_set_length(band,5)         -- set the band to length 5

band_set_strength(band, strength)

Set a band's strength. Strength must be between 0 and 10.

band_add_segment_segment(1, 5)  -- add band between first and fifth segments
band=get_band_count()           -- find the band's index number
band_set_strength(band,5)       -- set the band to strength 5

band_disable(band1[, band2] [ ,...] [band_n])

Disable the bands at the specified locations. You must include at least one parameter (band1). If desired, you can include as many more parameters as you like (band1, band2, band3 ...), but it is not required. Note that this command will only work if there are actually bands at these locations!

band_disable(7)             -- disable band at index 7
band_disable(3,4,5,6,10)    -- disable bands at indexes 3, 4, 5, 6, and 10

band_enable(band1[, band2] [ ,...] [band_n])

Enable the bands at the specified locations. You must include at least one parameter (band1). If desired, you can include as many more parameters as you like (band1, band2, band3 ...), but it is not required. Note that this command will only work if there are actually disabled bands at these locations to enable!

band_enable(4)             -- enable band at index 4
band_enable(12, 24, 36)    -- enable bands at index 12, 24, and 36

band_delete(band1[, band2] [ ,...] [band_n])

Delete the bands at the specified index. If desired, you can include as many more parameters as you like (band1, band2, band3 ...), but it is not required. Note that there must actually be bands at these indexes to delete!

Use get_band_count() to find out how many bands exist. Don't delete bands one wants to reference because the index on bands added later will be moved up. Instead, disable them until you want to delete the full set.

band_delete(25)             -- delete band 25
band_delete(4, 7, 9, 12)    -- delete bands 4, 7 , 9, and 12
band_delete()               -- delete all bands

do_freeze(boolean backbone, boolean sidechain)

Freeze previously selected segments. If 'backbone' or 'sidechain' is true, freeze that part of the segment

deselect_all()            -- limit segments to only the following
select_index(2, 4, 6)     -- select segments 2, 4, and 6
do_freeze()               -- freeze the selected segments
do_freeze(true,false)     -- freeze the backbone on the selected segments
do_freeze(false,true)     -- freeze the sidechains of the selected segments

do_unfreeze_all()

Unfreeze all segments

do_unfreeze_all()           -- unfreeze all segments and sidechains

set_behavior_clash_importance(importance)

Set the "behavior" slider to importance.  Importance needs to be a number between 0 and 1 (0 for least important, 1 for most important).

set_behavior_clash_importance(1)      -- set behavior to 1 (high)
set_behavior_clash_importance(0)      -- set behavior to 0 (low)
set_behavior_clash_importance(.25)    -- set behavior to .25 
                                      -- (somewhere in the middle)

deselect_index(segment1 [, ...] [, segment_n])

Deselect segment 1, and optionally, deselect as many more segments as you like.

deselect_index(14)                  -- deselect index 14
deselect_index(30, 31, 35)          -- deselect indexes 30, 31, and 35

select_index(segment1 [, ...] [, segment_n])

Select segment 1, and optionally, select as many more segments as you like.

select_index(14)                  -- select index 14
select_index(30, 31, 35)          -- select indexes 30, 31, and 35

select_index_range(segment1, segment2)

Select all the indexes in between segment 1 and segment 2 (inclusively)

select_index_range(14, 18)        -- select indexes 14, 15, 16, 17, and 18.

select_all()

Select all segments in the protein.

select_all()


deselect_all()

Deselects all segments in the protein.

deselect_all()

replace_ss(structure)

For the selected segment or segments, replaces its current secondary structure (helix, loop, or sheet) with another secondary structure of your choice.  Use 'H' for helix, 'L' for loop and 'E' for sheet.

replace_ss('H')                 -- replace selected indices with helixes
replace_ss('L')                 -- replace selected indices with loops
replace_ss('E')                 -- replace selected indices with sheets

Getter Commands

Getter commands don't hange the protein. They simply provide you with some information about the protein or game. A simple way of using getters is to use them to output information to the screen, so all our examples here are going to use print().

get_score()

As you might expect, get_score provides you with your overall game score.

print(get_score())

get_segment_score(segment1 [, ...] [,segment_n])

Gives you the score of a specific segment.  You must specify at least one segment index, but optionally you can specify as many as you want.

print(get_segment_score(18))                -- prints score of segment 18
print(get_segment_score(18, 20, 22))        -- prints scores of segments 18, 
                                            -- 20, and 22

get_ss(segment1 [,segment2] [,...] [,segment_n])

Gives you the secondary structure type at the given segment or segments.  Remember that secondary structure means a helix ('H'), loop('L'), sheet('E'), or ligand('M').  Inside the parentheses, put a whole number representing a segment index.  Optionally, you can put as many more segment indices as you like separated by commas.

print(get_ss(5))           -- prints secondary structure type at segment 5
print(get_ss(2, 4, 6))     -- prints secondary structure types at
                           -- segments 2, 4, and 6.

get_segment_distance(segment1, segment2)

This is functionality unique to scripting!  Gives you the distance between any two segments.

print(get_segment_distance(12, 20)) -- prints the distance between
                                    -- segments 12 and 20

get_segment_count()

Gets the total number of segments in the protein.

print(get_segment_count())

get_band_count()

Gives you the total number of bands that have been placed.

print(get_band_count())

get_segment_score_part(score_part, segment1[, ... segment_n])

This command is a bit tricky (see Get segment score part for a more detailed description!)  We can use it to give us part of the current backbone score of segment1, and optionally, segment 2, segment 3, and so on.  The parameter score_part refers to a particular part of the segment's score -- possibilities include "clashing", "packing", "hiding", "bonding, "backbone", "sidechain", "reference", "disulfides" and "other".  These are the same as the individual components of a score that pop up if you tab over a segment in the game. 

print(get_segment_score_part("clashing", 5)) -- prints the "clashing" 
                                             -- part of the score of segment 5
print(get_segment_score_part("bonding", 20, 30, 40)) -- prints the "bonding" 
                                             -- part of the score of segment 
                                             -- 20, segment 30, and segment 40

is_hydrophobic (segment)

Return true if the segment is hydrophobic.

seg=4
if is_hydrophobic (seg) then               
  print("segment ",seg," is hydrophobic")
else
  print("segment ",seg," is hydrophilic")
end

help()

Prints the complete list of commands to the output window.

help()

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.