Foldit Wiki
No edit summary
Line 6: Line 6:
   
   
 
Lua scripting adds an exciting layer of gameplay to Foldit!  Fortunately, lua is easy enough to learn that everyone can use it, even people who have never programmed or scripted before.  The best place to get started if you don't have any programming experience is to work through the [[Lua Scripting Tutorial (Beginner 1)]] (followed by [[Lua Scripting Tutorial (Beginner 2)]] and the upcoming [[Lua Scripting Tutorial (Beginner 3)]]. If you're not interested in scripting yourself but just want to download and run other people's scripts, Beginner 1 is all you need!  But if you want to go a bit further and modify scripts and write your own, you can move onto Beginner 2 and 3.
 
Lua scripting adds an exciting new layer of gameplay to Foldit!  Fortunately, lua is easy enough to learn that everyone can use it, even people who have never programmed or scripted before.  The best place to get started if you don't have any programming experience is to work through the [[Lua Scripting Tutorial (Beginner 1)]] (followed by [[Lua Scripting Tutorial (Beginner 2)]] and the upcoming [[Lua Scripting Tutorial (Beginner 3)]]. If you're not interested in scripting yourself but just want to download and run other people's scripts, Beginner 1 is all you need!  But if you want to go a bit further and modify scripts and write your own, you can move onto Beginner 2 and 3.
 
   
   
Line 17: Line 16:
 
Another option for experienced programmers is to use the full Lua Interface listing (below) in combination with the Lua Reference Manual to learn the material on your own.  If you already know how to program, you'll find that it's a  simple issue of learning Lua's simple syntax and the Foldit command set.  Additional resources for working with Lua are listed below, including guides to exporting and importing scripts and more!
 
Another option for experienced programmers is to use the full Lua Interface listing (below) in combination with the Lua Reference Manual to learn the material on your own.  If you already know how to program, you'll find that it's a  simple issue of learning Lua's simple syntax and the Foldit command set.  Additional resources for working with Lua are listed below, including guides to exporting and importing scripts and more!
   
  +
Foldit functions in LUA had a new version by [http://fold.it/portal/user/57765 Tlaloc] since 2011.
 
   
 
Whatever option you choose, best of luck and happy scripting!
 
Whatever option you choose, best of luck and happy scripting!

Revision as of 10:45, 5 August 2013


INTRODUCTION

As you may know, Foldit includes support for Lua Scripting. In very basic terms, Lua is a simple programming language that we can use to manipulate proteins and automate repetitive tasks -- much like we already do with the Cookbook. A script is actually quite similar to a Cookbook recipe (as well as to a real-life recipe for say, a cake) -- it contains a series of instructions (called commands) that tell Foldit what to do with your protein (just as a real-life recipe has step by step instructions about how to combine ingredients to create a cake!)


Lua scripting adds an exciting layer of gameplay to Foldit!  Fortunately, lua is easy enough to learn that everyone can use it, even people who have never programmed or scripted before.  The best place to get started if you don't have any programming experience is to work through the Lua Scripting Tutorial (Beginner 1) (followed by Lua Scripting Tutorial (Beginner 2) and the upcoming Lua Scripting Tutorial (Beginner 3). If you're not interested in scripting yourself but just want to download and run other people's scripts, Beginner 1 is all you need!  But if you want to go a bit further and modify scripts and write your own, you can move onto Beginner 2 and 3.


If, on the other hand, you have some programming experience or want to get a quicker start, begin with Lua Scripting Tutorial (Intermediate). This intermediate tutorial starts from the ground up and assumes no prior knowledge but moves through material at a more rapid pace, including basics about how to run and modify scripts as well as core programming concepts like looping and variables.


Another option for experienced programmers is to use the full Lua Interface listing (below) in combination with the Lua Reference Manual to learn the material on your own.  If you already know how to program, you'll find that it's a  simple issue of learning Lua's simple syntax and the Foldit command set.  Additional resources for working with Lua are listed below, including guides to exporting and importing scripts and more!

Foldit functions in LUA had a new version by Tlaloc since 2011.

Whatever option you choose, best of luck and happy scripting!

RESOURCES

Cookbook / Recipe Scripting Tutorials

Commands / Functions

Recipes

External / Other

LUA LANGUAGE

Here is a condensed summary of the keywords and operators available in LUA:

-- - use double dash to immediately precede comments on any line.

--[ [ x ] ] - multi-line comments provided by enclosing comment body in double brackets

+ (addition) - (negation/subtraction) * (multiplication) / (division) ^ (exponent) % (modulo) .. (string concatenation)

> < >= <= == ~= - relational operators

= - assignment. Note that Lua allows multiple assignments like a,b = 1,2.

a={} - creates empty table

a[1]=3; a["apple"]=4; a[12]="red" - sets some values in table

#a - indexing upward from zero, this returns the index of the last non-nil value. For example, if a[1] is nil, #a returns zero.

nil - a non-value that indicates non-existent variables

true false - Boolean values. Note everything except false and nil evaluates as true (including zero and empty string!)

and or not - Boolean operators

if then elseif else end - keywords for structuring if/then statements

while do end - keywords for while statement

repeat until - keywords for repeat statement

for i=1,N,delta do end - numeric "for" statement

for i in iterator(table) do end - generic "for" statement

break - terminates a loop

local - limits scope of variable to the current block. Use this in functions to avoid corrupting global variables.

function name(arg) return end - keywords for structuring function.

Note that functions can return multiple values. Functions can also take variable numbers of arguments by including an ellipsis at the end of the argument list. The following example illustrates this:

function test(...)
  local args={...}
  for i=1,#args do  print(args[i])  end
  return args[1], args[2]
end
a,b = test(1,2,3)

LUA INTERFACE to FOLD.IT (V1)

The following Fold.It function calls are available from the Lua interface. For a format of this interface more appropriate for beginners, as well as code snippets, see the Simplified List of Lua Commands. For the latest version of Fold.It function calls (V2), see Foldit Lua Functions.

boolean are_conditions_met()
Return whether the pose? satisfies all conditions.

void band_add_segment_segment(integer segment_index_1, integer segment_index_2)
Add a band between the segments at 'segment_index_1' and at 'segment_index_2'.

void band_delete(integer band_index_1[, ..., integer band_index_n])
Delete the bands at the given band indices.

void band_disable(integer band_index_1[, ..., integer band_index_n])
Disable the bands at the given band indices.

void band_enable(integer band_index_1[, ..., integer band_index_n])
Enable the bands at the given band indices.

void band_set_length(integer band_index, number length)
Set the length of the band at the given index.

void band_set_strength(integer band_index, number strength)
Set the strength of the band at the given index.

void deselect_all()
Clear selection.

void deselect_index(integer segment_index_1[, ..., integer segment_index_n])
Deselect segments at the given indices. More than one segment index may be specified.

void do_freeze(boolean backbone, boolean sidechain)
Freeze segments. If 'backbone' or 'sidechain' is true, freeze that part of the segment.

void do_global_wiggle_all([integer iterations])
Run global wiggle on backbone and sidechains. Run for 'iterations' iterations if given; otherwise, until stopped.

void do_global_wiggle_backbone([integer iterations])
Run global wiggle on backbone. Run for 'iterations' iterations if given; otherwise, until stopped.

void do_global_wiggle_sidechains([integer iterations])
Run global wiggle on sidechains. Run for 'iterations' iterations if given; otherwise, until stopped.

void do_local_rebuild([integer iterations])
Run local rebuild on selection. Run for 'iterations' iterations if given; otherwise, until stopped.

void do_local_wiggle([integer iterations])
Run local wiggle. Run for 'iterations' iterations if given; otherwise, until stopped.

void do_mutate([integer iterations])
Run mutate. Run for 'iterations' iterations if given; otherwise, until stopped.

void do_shake([integer iterations])
Run shake. Run for 'iterations' iterations if given; otherwise, until stopped.

void do_sidechain_snap(integer segment_index, integer snap_index)
Snap the position of the sidechain at the given index to the given snap position.

void do_unfreeze_all()
Unfreeze all segments.

string get_aa(integer segment_index_1[, ..., integer segment_index_n])
Get segments' amino acid type at given segment indices.

integer get_band_count()
Return the number of bands.

number get_exploration_score()
Return the exploration score?

number get_ranked_score(boolean negative_score)
Return the ranked score? If negative_score is present and true, will return negative score, otherwise, negative scores will be 0.

number get_score([boolean negative_score])
Return the current score. If negative_score is present and true, will return negative score, otherwise, negative scores will be 0.

integer get_segment_count()
Return the number of segments.

number get_segment_distance(integer segment_index_1, integer segment_index_2)
Return distance between 2 segments.

number get_segment_score(integer segment_index_1[, ..., integer segment_index_n])
Return the current score of the given segments. More than one segment index may be specified.

number get_segment_score_part(string score_part, integer segment_index_1[, ..., integer segment_index_n])
Return the current score part of the given segments. More than one segment index may be specified.

integer get_sidechain_snap_count(integer segment_index)
Return the number of positions the sidechain at the given index can snap to. NOTE: this number can change if the protein is moved.

string get_ss(integer segment_index_1[, ..., integer segment_index_n])
Get segments' secondary structure type at given segment indices.

void help()
Prints to Recipe Output, an unannotated list of Foldit functions.

boolean is_hydrophobic(integer segment_index_1[, ..., integer segment_index_n])
Get segments' hydrophobicity at given segment indices.

void load_structure()
Load previously saved structure assignment.

void print(arg1[,...,argN])
Print values to the output window and log file.

void quickload(integer slot_number)
Quickload from a slot.

void quicksave(integer slot_number)
Quicksave to a slot.

void replace_aa(string aa)
Replace segments' amino acid within selection with 'aa'.

void replace_ss(string ss)
Replace segments' secondary structure within selection with 'ss'.

void reset_puzzle()
Reset puzzle to the starting configuration.

void reset_recent_best()
Set this pose as recent best.

void restore_abs_best()
Restore to the absolute best pose.

void restore_credit_best()
Restore to the best pose for which you have gotten credit.

void restore_recent_best()
Restore to the recent best pose.

void save_structure()
Save current structure assignment.

void select_all()
Select all segments.

void select_index(integer segment_index_1[, ..., integer segment_index_n])
Select segments at the given indices. More than one segment index may be specified.

void select_index_range(integer segment_index_1, integer segment_index_2)
Select all segments from (including) 'segment_index_1' to (including) 'segment_index_2'.

void set_behavior_clash_importance(number importance)
Set the clashing importance to 'importance' (between 0 and 1).