Foldit Wiki
(Added missing functions.)
Line 111: Line 111:
   
   
 
'''void set_behavior_clash_importance(number importance)'''<br />Set the clashing importance to 'importance' (between 0 and 1).
   
  +
'''void restore_abs_best()'''<br />Restore to the absolute best pose.
'''void set_behavior_clash_importance(number importance)'''<br />
 
   
  +
'''void restore_credit_best()'''<br />Restore to the best pose for which you have gotten credit.
Set the clashing importance to 'importance' (between 0 and 1).<br /><br />'''number get_score()'''<br />Return the current score.<br /><br />'''number get_segment_score(integer segment_index_1[,..., integer segment_index_n])'''<br />Return the score of the given segments. More than one segment index may be specified.<br /><br />'''string get_ss(integer segment_index_1[,..., integer segment_index_n])'''<br />Get residue's secondary structure type at given segment indices.<br /><br />'''number get_segment_distance(integer segment_index_1, integer segment_index_2)'''<br />Return distance between 2 segments.<br /><br />'''integer get_band_count()'''<br />Return the number of bands.<br /><br />'''integer get_segment_count()'''<br />Return the number of segments.<br /><br />'''void reset_recent_best()'''<br />Set this pose as recent best<br /><br />'''void band_add_segment_segment(integer segment_index_1, integer segment_index_2)'''<br />Add a band between the segments at 'segment_index_1' and at 'segment_index_2'.<br /><br />'''void restore_abs_best()'''<br />Restore to the absolute best pose<br /><br />'''void restore_recent_best()'''<br />Restore to the recent best pose<br /><br />'''void reset_puzzle()'''<br />Reset puzzle to the starting structure<br /><br />'''void band_disable(integer band_index_1[, ..., integer band_index_n])'''<br />Disable the bands at the given band indices.<br /><br />'''void band_enable(integer band_index_1[, ..., integer band_index_n])'''<br />Enable the bands at the given band indices.<br /><br />'''void band_delete(integer band_index_1[, ..., integer band_index_n])'''<br />Delete the bands at the given band indices.<br /><br />'''void do_mutate([integer iterations])'''<br />Run mutate. Run for 'iterations' iterations if given; otherwise, until stopped.<br /><br />'''void do_local_rebuild([integer iterations])'''<br />Run local rebuild on selection. Run for 'iterations' iterationas if given; otherwise, until stopped.<br /><br />'''void deselect_all()'''<br />Clear Selection.<br /><br />'''void select_all()'''<br />Select all segments.<br /><br />'''void do_shake([integer iterations])'''<br />Run shake. Run for 'iterations' iterations if given; otherwise, until stopped.<br /><br />'''void do_global_wiggle_sidechains([integer iterations])'''<br />Run global wiggle on sidechains. Run for 'iterations' iterations if given; otherwise, until stopped.<br /><br />'''void do_global_wiggle_backbone([integer iterations])'''<br />Run global wiggle on backbone. Run for 'iterations' iterations if given; otherwise, until stopped.<br /><br />'''void do_global_wiggle_all([integer iterations])'''<br />Run global wiggle on backbone and sidechains. Run for 'iterations' iterations if given; otherwise, until stopped.<br /><br />'''number [[get_segment_score_part]](string score_part, integer segment_index_1[, ..., integer segment_index_n])'''<br />Return the current backbone score of the given segments.&nbsp; More than one segment index may be specified.<br /><br />'''void replace_ss(string ss)'''<br />Replace residues' secondary structure within selection with 'ss'.<br /><br />'''void replace_aa(string aa)'''<br />Replace residues' amino acid within selection with 'aa'.<br /><br />'''void deselect_index(integer segment_index_1[, ..., integer segment_index_n])'''<br />Deselect segments at the given indices.&nbsp; More than one segment index may be specified.<br /><br />'''void select_index_range(integer segment_index_1, integer segment_index_2)'''<br />Select all segments from (including) 'segment_index_1' to (including) 'segment_index_2'.<br /><br />'''void select_index(integer segment_index_1[, ..., integer segment_index_n])'''<br />Select segments at the given indices.&nbsp; More than one segment index may be specified.<br /><br />'''void help(void)'''<br />Prints to Recipe Output, an unannotated list of Foldit functions.<br /><br />'''string get_aa(integer segment_index_1[, ..., integer segment_index_n])'''<br />Get residue's amino acid type at given segment indices.
 
  +
  +
'''void restore_recent_best()'''<br />Restore to the recent best pose.
  +
  +
'''void reset_recent_best()'''<br />Set this pose as recent best.
  +
  +
'''void reset_puzzle()'''<br />Reset puzzle to the starting configuration.
  +
  +
'''void quicksave(integer slot_number)'''<br />Quicksave to a slot.
  +
  +
'''void quickload(integer slot_number)'''<br />Quickload from a slot.
  +
  +
'''void save_structure()'''<br />Save current structure assignment.
  +
  +
'''void load_structure()'''<br />Load previously saved structure assignment.
  +
  +
'''void do_unfreeze_all()'''<br />Unfreeze all segments.
  +
  +
'''number get_score([boolean negative_score])'''<br />Return the current score. If negative_score is present and true, will return negative score, otherwise, negative scores will be 0.
  +
  +
'''number get_segment_score(integer segment_index_1[, ..., integer segment_index_n])'''<br />Return the current score of the given segments. More than one segment index may be specified.
  +
  +
'''integer get_segment_count()'''<br />Return the number of segments.
  +
  +
'''integer get_band_count()'''<br />Return the number of bands.
  +
  +
'''void band_add_segment_segment(integer segment_index_1, integer segment_index_2)'''<br />Add a band between the segments at 'segment_index_1' and at 'segment_index_2'.
  +
  +
'''void band_set_strength(integer band_index, number strength)'''<br />Set the strength of the band at the given index.
  +
  +
'''void band_set_length(integer band_index, number length)'''<br />Set the length of the band at the given index.
  +
  +
'''number get_segment_distance(integer segment_index_1, integer segment_index_2)'''<br />Return distance between 2 segments.
  +
  +
'''boolean is_hydrophobic(integer segment_index_1[, ..., integer segment_index_n])'''<br />Get segments' hydrophobicity at given segment indices.
  +
  +
'''string get_ss(integer segment_index_1[, ..., integer segment_index_n])'''<br />Get segments' secondary structure type at given segment indices.
  +
  +
'''integer get_sidechain_snap_count(integer segment_index)'''<br />Return the number of positions the sidechain at the given index can snap to. NOTE: this number can change if the protein is moved.
  +
  +
'''void do_sidechain_snap(integer segment_index, integer snap_index)'''<br />Snap the position of the sidechain at the given index to the given snap position.
  +
  +
'''void band_delete(integer band_index_1[, ..., integer band_index_n])'''<br />Delete the bands at the given band indices.
  +
  +
'''void band_enable(integer band_index_1[, ..., integer band_index_n])'''<br />Enable the bands at the given band indices.
  +
  +
'''void band_disable(integer band_index_1[, ..., integer band_index_n])'''<br />Disable the bands at the given band indices.
  +
  +
'''string get_aa(integer segment_index_1[, ..., integer segment_index_n])'''<br />Get segments' amino acid type at given segment indices.
  +
  +
'''void do_shake([integer iterations])'''<br />Run shake. Run for 'iterations' iterations if given; otherwise, until stopped.
  +
  +
'''void do_mutate([integer iterations])'''<br />Run mutate. Run for 'iterations' iterations if given; otherwise, until stopped.
  +
  +
'''void do_global_wiggle_all([integer iterations])'''<br />Run global wiggle on backbone and sidechains. Run for 'iterations' iterations if given; otherwise, until stopped.
  +
  +
'''void do_global_wiggle_backbone([integer iterations])'''<br />Run global wiggle on backbone. Run for 'iterations' iterations if given; otherwise, until stopped.
  +
  +
'''void do_global_wiggle_sidechains([integer iterations])'''<br />Run global wiggle on sidechains. Run for 'iterations' iterations if given; otherwise, until stopped.
  +
  +
'''void do_local_wiggle([integer iterations])'''<br />Run local wiggle. Run for 'iterations' iterations if given; otherwise, until stopped.
  +
  +
'''void do_local_rebuild([integer iterations])'''<br />Run local rebuild on selection. Run for 'iterations' iterations if given; otherwise, until stopped.
  +
  +
'''void do_freeze(boolean backbone, boolean sidechain)'''<br />Freeze segments. If 'backbone' or 'sidechain' is true, freeze that part of the segment.
  +
  +
'''void select_all()'''<br />Select all segments.
  +
  +
'''void select_index(integer segment_index_1[, ..., integer segment_index_n])'''<br />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)'''<br />Select all segments from (including) 'segment_index_1' to (including) 'segment_index_2'.
  +
  +
'''void deselect_all()'''<br />Clear selection.
  +
  +
'''void deselect_index(integer segment_index_1[, ..., integer segment_index_n])'''<br />Deselect segments at the given indices. More than one segment index may be specified.
  +
  +
'''void replace_aa(string aa)'''<br />Replace segments' amino acid within selection with 'aa'.
  +
  +
'''void replace_ss(string ss)'''<br />Replace segments' secondary structure within selection with 'ss'.
  +
  +
'''number [[get_segment_score_part]](string score_part, integer segment_index_1[, ..., integer segment_index_n])'''<br />Return the current score part of the given segments. More than one segment index may be specified.
  +
  +
'''void help()'''<br />Prints to Recipe Output, an unannotated list of Foldit functions.

Revision as of 01:48, 16 August 2010


INTRODUCTION

As you may know, the newest Fold-it update 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 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.


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!


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

RESOURCES

Lua Scripting Tutorial (Beginner 1) (browsing, loading and running scripts, open output window)

Lua Scripting Tutorial (Beginner 2) (Lua commands)

Lua Scripting Tutorial (Beginner 3) (using game commands)

Lua Scripting Tutorial (Intermediate) (similar to Beginner 1-3, but more compact)

Lua Scripting Tutorial (Advanced) (using functions)

Simplified List of Lua Commands

Lua Export and Import of Scripts using Text and HEX editor

Lua Export and Import of Scripts using WORDPAD++

Foldit Recipes and Scripts Homepage

Lua 5.1 Reference Manual

Lua-users wiki

Foldit Scripting Preview

Foldit Cookbook Scripting

Lua Wiki for WOW (WOW-specific but contains a lot of useful resources)

Programming in Lua Book (First Edition)

Lua Script Advice

Lua_Functions_That_Should_Be_Implemented

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

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


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

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 reset_recent_best()
Set this pose as recent best.

void reset_puzzle()
Reset puzzle to the starting configuration.

void quicksave(integer slot_number)
Quicksave to a slot.

void quickload(integer slot_number)
Quickload from a slot.

void save_structure()
Save current structure assignment.

void load_structure()
Load previously saved structure assignment.

void do_unfreeze_all()
Unfreeze all segments.

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.

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.

integer get_segment_count()
Return the number of segments.

integer get_band_count()
Return the number of bands.

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_set_strength(integer band_index, number strength)
Set the strength of the band at the given index.

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

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

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

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

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.

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 band_delete(integer band_index_1[, ..., integer band_index_n])
Delete 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_disable(integer band_index_1[, ..., integer band_index_n])
Disable the bands at the given band indices.

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

void do_shake([integer iterations])
Run shake. 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_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_wiggle([integer iterations])
Run local wiggle. 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_freeze(boolean backbone, boolean sidechain)
Freeze segments. If 'backbone' or 'sidechain' is true, freeze that part of the segment.

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 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 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'.

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.

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