43 replies [Last post]
Joined: 04/13/2009
Groups: Contenders

Hi folks,

I just wanted everyone to know that there are now three Lua Scripting tutorials up on the wiki that you can find here: http://foldit.wikia.com/wiki/Lua_Scripting . Lua is an easy-to-use programming language that we can now use to manipulate proteins. Like cookbook recipes, scripts are a great way to automate repetitive folding tasks, help you fold while you're not home or sleeping :), and maybe increase your score!! I designed these tutorials for beginners (thanks to mat747 for helping get them at a good level for "absolute" beginners), so you don't have to know anything about programming to use them. If you have never programmed before, you will want to start with:

Beginner 1
http://foldit.wikia.com/wiki/Lua_Scripting_Tutorial_(Beginner_1)
This tutorial will get you to the point of downloading and running other people's scripts.

Beginner 2
http://foldit.wikia.com/wiki/Lua_Scripting_Tutorial_(Beginner_2)
This tutorial gets you to the level of modifying scripts and understanding some basics of commands.

There will be a Beginner 3 tutorial soon (I'll update this thread when it's up) which will work with the rest of the commands and get you to the point of writing your own script with any commands you like in it.

Currently, there is also a very long intermediate tutorial on the wiki ( http://foldit.wikia.com/wiki/Lua_Scripting_Tutorial_(Intermediate) ). I recommend it for folks who either have worked through the beginner tutorials and want more to sink their teeth into or who have some programming experience and want to go at a more accelerated pace (it is actually a standalone tutorial so you don't need to have read Beginner). I will most likely split it into three bits like I did for beginner and then add more, but it is up now and complete for folks who want to take a look.

Scripting is a really fun way of getting deeper into Foldit, learning some basic programming concepts, and maybe even discovering new and exciting ways of folding that no one has used before. There's been some criticism of the addition of scripting to foldit, but my position is that it won't automate our folding completely or make what we do by hand obsolete -- rather, it's a way of taking our unique folding abilities -- our spatial sensibilities -- and extending, deepening, and codifying them. In this sense, scripting becomes a tool we can use to realize our human folding abilities in the form of heuristics, rather than a wholesale automation of folding that would replace us.

Please let me know if you have any suggestions or ideas for the current (and future) tutorials, and of course everyone is invited to modify them directly on the wiki and/or add their own!

Joined: 04/13/2009
Groups: Contenders
Oh dear ... this forum really

Oh dear ... this forum really does not like urls.

The first beginner script is at:
http://foldit.wikia.com/wiki/Lua_Scripting_Tutorial_(Beginner_1)

and the second is at:

http://foldit.wikia.com/wiki/Lua_Scripting_Tutorial_(Beginner_2)

Joined: 09/18/2009
Groups: SETI.Germany
themarquis keep up the good work!

In addition, I've made some tutorials about how to get scripts out of FoldIt, edit them externally and insert them back again into the game:

http://foldit.wikia.com/wiki/Lua_Export_and_Import_of_Scripts

and

http://foldit.wikia.com/wiki/Lua_Export_and_Import_of_Scripts_using_WORDPAD%2B%2B

When I've got the time and feel healthy, I'll write an (regarding to Mat747) "expert" tutorial about functions and loops which work nestably stacked.

Joined: 04/13/2009
Groups: Contenders
Crashguard, your tutorials

Crashguard, your tutorials look great!

I was actually just thinking about "advanced" tutorials -- my skills are still quite rudimentary, so I think Intermediate is as far as I can reasonably go with tutorials. But ... you might just be the perfect man for the job!!

I'd be happy to provide assistance or edit for grammar, etc. if you like!

Joined: 09/18/2009
Groups: SETI.Germany
Yes!

That would be good, because I'm just writing english all the time, but I'm not used anymore to speak it, so partwise, I'm just guessing.

Plus, there are some programming-routines I maybe take myself for granted or self-evident, but it will make other people scratching their head and wonder, so it is good if there is someone, who can say: "This point I don't understand, it's not explained percisely enough".

When I've done the Gamma-ray therapy tomorrow and feel good these days, I will create a tutorial for the new script.

regards,
Alex

Joined: 09/18/2009
Groups: SETI.Germany
Functions

Themarquis, are you just on the way to explain functions or should I explain them in the advanced tutorial?
I've created some basic math functions,which are not accessible in the game like integer, absolute and sinus (just beagan), for example.

I've already made a placeholder for your Beginner 3 Tutorial and a placeholder for my advanced tutorial.

There are two question anymore:

1.: If we want to discuss changes in the wikia, which link should be use?
On the german Wiki we have a site

, but I couldn't find 'the right one' on the english one, as the discussion page was deleted.

2.: May I give some extra information about your tutorials in brackets at the links on the wiki?

For example:
Lua Scripting Tutorial (Beginner 1)

Transform to:
Lua Scripting Tutorial (Beginner 1: browse and load scripts, output window)

This won't change the name of link, but give some extra info for the one who wants to know in brief what this tuoriual is dealing, and we know, which info is alerady given.

Joined: 09/18/2009
Groups: SETI.Germany
What the ...

Not again!
Do you know where you have to stick your stuff?

Joined: 09/18/2009
Groups: SETI.Germany
Update

According to so many requests, I plan to write tutorials for the functions Rescale (very important!!!),
Multi-Tool, Smart-Rebuild and Random Bonds.

But please be patient, as I now go to work again, so I'm not that long time at home and I'm still not that pretty fit, which is normal for the next 6 months after ray-treatment.

But be sure I participate more in writing codes and Wiki than playing FoldIt at the time.

Extra:
Because I must to get it working, I'm on the way to create some basic math functions, which are locked here, as far as the standard library is not included in the game.

Absolute, Integer and morph/scaling functions (percentage for example) are finished (a text-percentage-bar can be created, too), now I do some research on Sinus (including factorial function), sawtooth, triangle and rectangle.

Joined: 09/18/2009
Groups: SETI.Germany
Plans

I plan to start explaining functions with a simple factorial-function, then percentage-calculation, and the Rescale (a better version of percentage).

Joined: 09/18/2009
Groups: SETI.Germany
Discovery!

Rachel, you CAN overwrite recipes!!!

Just click into the recipe info (do as if you were changing the script information), and then leave the info box!

The SAVE-button will appear again!

Joined: 04/13/2009
Groups: Contenders
Hey Alex, I'm in the process

Hey Alex,
I'm in the process of recovering from the h1n1 flu (that's why you haven't heard from me), but I'm excited to see your work!

I'll get on later today and respond in more detail.

Joined: 04/13/2009
Groups: Contenders
all right!

all right, onto your question:

Yes, I think you should move ahead with the advanced tutorial(s) -- I'm excited to see what you come up with. Here are some thoughts of what content might be needed (some of which you already mentioned)

-writing and using functions
-a section about the issue of the "missing" library functions and how to reproduce some of them: random numbers, abs, integer functions, factorial, etc (or whatever you think is important.) (also see next message for another thought about libraries).
-control structures (I do a for loop in intermediate, but it would be nice to cover how to use all the different control structures in lua: while, repeat, etc.)
-table constructors (basically arrays in lua)
-error messages/debugging (I do a bit on this in intermediate, but there is lots more to cover. For non-programmers especially, dealing with errors is a difficult process that they could use some pointers on. For programmer types, a list of the common error messages and what they mean might be useful.)

Joined: 04/13/2009
Groups: Contenders
library functions!!!!

On another note, I had a thought about library functions. This is a big project, but wouldn't it be great if we wrote our own "libraries" for foldit lua?

Alex, maybe you should make a new page on the wiki that will be a collection of foldit lua “library” functions (or I will make it if I get the chance). The “library” is going to be written by us (or so far, by you :) ). It can include functions that reproduce standard lua libraries that are woefully missing, as well as specialized functions that serve a general purpose in foldit and that many people might want to use as “building blocks” for their own programs. In other words, what are some common folding tasks that people might want to do that are very useful but a bit complicated to implement? If we write library functions for them, then people don't have to worry about how to code them -- they can just use them like the standard commands. Of course, they will have to cut/paste the library functions into their programs, but that should be easy.

For example, a function that returns a random segment index. There could be an overriden version of it that takes parameters representing an index range. So get_random_segment() or get_random_segment(5, 20). Similarly, add_random_band() and add_random_band(5,20) (add random band between seg 5 and 20). select_random_index(), wiggle_random_index, and so on (that might be overkill, but you get the idea).

Mcurtis' print_segment_details might be a good foldit lua library function. Something like get_structure_indices might be nice (takes a structure type and a start index and returns an index range representing the next location where that structure is located). Or get_all_structure_indices() would return sets of ordered pairs (table?) representing where each structure starts and ends. We could also do a similar thing for residue types: get_residue_indices() that takes a residue type.

There could be something like select_lowest_scoring_segments() that takes an int and finds the n lowest scorers. A select_lowest_scoring_structures() would find the n lowest scoring structures.

A save_structure() uses get_structure_indices to store the protein's current structures in memory, then a restore_structure() can restore it.

Finally, we could try to replicate the local wiggle sequence from the cookbook (though as far as I know, the local/global wiggle is still an issue in scripting) for folks who might “miss” it! It would just be a loop w/ wiggle by 2s or 3s or whatever (since by 1s doesn't work right).

Anyway, I'm just throwing out some ideas! Anyone else have thoughts?

Joined: 09/18/2009
Groups: SETI.Germany
h1n1

So, you got infected by your gf?
Ow....
But it's good to know that we both do better now :)

"Alex, maybe you should make a new page on the wiki that will be a collection of foldit lua “library” functions (or I will make it if I get the chance)"

Yes, a library for those functions which are not accessible due to restrictions are a MUST!

"It can include functions that reproduce standard lua libraries that are woefully missing, as well as specialized functions that serve a general purpose in foldit and that many people might want to use as “building blocks” for their own programs. In other words, what are some common folding tasks that people might want to do that are very useful but a bit complicated to implement? If we write library functions for them, then people don't have to worry about how to code them -- they can just use them like the standard commands. Of course, they will have to cut/paste the library functions into their programs, but that should be easy."

Accepted!

"For example, a function that returns a random segment index. There could be an overriden version of it that takes parameters representing an index range. So get_random_segment() or get_random_segment(5, 20). Similarly, add_random_band() and add_random_band(5,20) (add random band between seg 5 and 20). select_random_index(), wiggle_random_index, and so on (that might be overkill, but you get the idea)."

I've just created a new "random"-bond-algorithm, whre you can choose, how the numbers are generated!
http://fold.it/portal/recipe/1987

"Mcurtis' print_segment_details might be a good foldit lua library function. Something like get_structure_indices might be nice (takes a structure type and a start index and returns an index range representing the next location where that structure is located). Or get_all_structure_indices() would return sets of ordered pairs (table?) representing where each structure starts and ends. We could also do a similar thing for residue types: get_residue_indices() that takes a residue type."

I'm still missing a description of all segment attributes, for example what "other" means.

"A save_structure() uses get_structure_indices to store the protein's current structures in memory, then a restore_structure() can restore it."

This is what I also want!

kind regards,
Alex

Joined: 04/13/2009
Groups: Contenders
I'm glad you're feeling

I'm glad you're feeling better, too! How long until your next treatment?

We both got the flu. She got sick about a day before me, but in retrospect, I might have started the illness that day too because I had awful chest pains (I thought I had strained a muscle or something)! Then we were both very sick for about 5-6 days -- just sat around the house coughing and complaining. The worst part was that we were so sick that we couldn't even take care of each other. But much much better now ... still coughing, but feeling fine.

I'm happy we agree with the "library". Maybe I will work on a couple of these when I get the chance -- save and restore structures?

Your new randomization algorithm is great and i think we should use that as the basis for all our randomization library functions.

I was talking to someone -- gneutral? About the lack of library functions (which he was understandably not very happy about) and we went back and forth a bit about whether we can replicate missing library functions ourselves. I think we argued about integer functions and how to convert a float to an int without the library. It's tedious, but you'd have to grab the digits after the decimal using mod or something, then use if statements:

say that our original number is x. The code would look something like this:

i = x mod 1 // integer part
d = x - i // decimal part
if d < .5 then n = i
if d > .5 then n = i + 1

(n is returned as the int)

We can replicate floor and ceiling this way, too.

Joined: 04/13/2009
Groups: Contenders
I made a new page on the wiki

I made a new page on the wiki for foldit library functions:

http://foldit.wikia.com/wiki/FoldIt_Lua_Library

for links or cut/paste code. but we should consider it a short-term strategy. Code should live in a repository somewhere and we can just link to it from the wiki.

Joined: 09/18/2009
Groups: SETI.Germany
Nice!

That's great!

I'm on the way to paste some functions.
Should we separate the functions by ==name==?, so we can create an index?

I've got a shorter (and faster) way for integer:
Note, that using many IF-conditions slow down computing.
The CPU has to run more internal commands on assembler-layer, where all program languages are transformed to at last, than on a single addition-task, so I'm trying to use as less conditions as possible.

Have a look into my latest random-Bond recipe, where I also use integer.

Joined: 09/18/2009
Groups: SETI.Germany
Example:

If you have a value, which should be activated or deactivated, you can do it this way:

function (value,active)
if active==1 then y=value end
elseif active==0 then y=0 end
return y
end

OR

function (value,active)
y=value*active
return y
end

Whereas the second solution runs faster, because it uses CPU calculationg functions and gets only memory information some times.

The first solution has to get memory values more times to compare the values (program-lanugages use data-arrays for the varable names and assign them to a memory adress, for example value->Addr 00FF, so they have to reget them from there by using the array).

So, as I meantioned arrays here, I'm happy that mentioned them before and you want to describe them, too!

Something other:
At first, I have to wait for 6 months to have another MRI, so they can check if the therapy was effective, and how the tumor did change.
Then we can think about a second therapy, as it is required (I hope not!)

best regards,
Alex

Joined: 04/13/2009
Groups: Contenders
Alex, you're much better at

Alex, you're much better at programming efficiently than I am! Which is why I hope you write many library functions :)

>I'm on the way to paste some functions.
>Should we separate the functions by ==name==?, so we can create an index?

Yes, that's a good idea. Or if you just set each function name to h3 on the wiki editor, it will make headers and an index for us. I'd recommend using the PRE setting for all the code so that it's marked as code and it's easier for people to cut and paste (see my "simplified list of lua commands" where I have super, super easy code snippets http://foldit.wikia.com/wiki/Simplified_List_of_Lua_Commands).

I'm still having the feeling like using wiki to store a bunch of code is not optimal. And in fact, our little "lua scripting working group" does not have a home anywhere, but we have a couple of forum posts and in-game messaging and the wiki, but that is not enough! So we will have to think more about that.

speaking of library functions, I wrote up a couple of functions yesterday for saving and restoring secondary structures. The big problem, though, is that the functions are not very useful because there's no way to store info about the structures to access at a later time (after script is done running). For example, you can't run a script to store the structure data, then do folding or run other scripts or whatever, and then run a script to restore structure data. Because we cannot store anything in memory after a script exits. (as far as I know) Yet again, reading/writing files would be the way to go on this, but it's not possible (and the devs don't seem to be working on this at all).

So save/restore structures can only work in two ways: 1) if you had a script that saved, then changed structures, then restored all in one script (how often will people do this?) or 2) output structures as a concat string to output window, cut(which we can't do with output!?!?!) and then paste the string and pass as parameter to restore. Very tedious and annoying!!

But one of my group members makes cookbook recipes that set structures for some puzzles, which must be a lot of work, so this would be an easier method for him. But for most people, it would not be very useful.

Any thoughts??

You can tell that I'm obsessed with reading/writing files from foldit lua. Can you think of any other way to pass information from foldit lua to somewhere else? We can get the scripts themselves, but can we get the output or store data somehow?

Joined: 09/18/2009
Groups: SETI.Germany
structures and files

I'm also for file access, for the reasons you meant.

Copying data out of the output window doesn't work, so it is my idea, as we made it with the all.macro-files, that we take the puzzle-files and get the structure information out of them, so we can paste them back into the script editor.

But my question of the puzzle-file structure wasn't answered.
I'll give it a try and check them with a HEX-edior or Notepad++

Or, maybe Judecca has got an idea?

Joined: 04/13/2009
Groups: Contenders
Yes, now I realize it's

Yes, now I realize it's obvious that we should be grabbing the structure data from the puzzle files. I can't remember which question you are referring to -- I will go look.

Joined: 04/13/2009
Groups: Contenders
I realized you asked a couple

I realized you asked a couple other questions that I missed ...

1.: If we want to discuss changes in the wikia, which link should be use?
On the german Wiki we have a site

I'm not sure what you're referring to, but each page has it's own discussion page that we can use.

we could use the discussion page for lua scripting for general talk about scripting-related wiki changes: http://foldit.wikia.com/wiki/Talk:Lua_Scripting . I'm not sure what you mean by the "right one"?

2.: May I give some extra information about your tutorials in brackets at the links on the wiki?

Yes! Please feel free. It's a good idea.

Joined: 04/13/2009
Groups: Contenders
Was your question about files

Was your question about files this one:

"For re-getting solutions, it would be nice to know, HOW the solutions are stored (I want to know the structure of the files), so if checksum (if there is one) and/or header are defect, you could fix them with a HEX-file-editor."

I agree, but I don't think the devs have been very forthcoming about files and other game-related details.

I think I've found the sequences in the solution/puzzle files. They look like this:

SSTR (some garbage chars) LLLLLLLHHHHHHHHHHHHHHLLLEE

The E is for sheet, I think. (L for loop, H for helix). You should play w/ this and confirm (if you haven't already. They should be easy to extract.

Joined: 09/18/2009
Groups: SETI.Germany
YES!!!

You are right, Rachel!
This is how they must are stored!

I could write A QBASIC-Program compiled as .exe-file which gets the data.
Maybe V-Basic, too, but only after some training.

Another way is to cut these data out with NOTEPAD++
Too bad,that search and replace isn't available for macro-functions in Notepad at the moment.
I hope, they will do it in some time.

"I agree, but I don't think the devs have been very forthcoming about files and other game-related details."
For releasing it, you should vote here:

http://fold.it/portal/node/986241

Joined: 04/13/2009
Groups: Contenders
I'm trying to think about

I'm trying to think about what would be the easiest (and most useful) way of pulling out those structures. Maybe I will chat with CFC (he is the one in my group who is interested in saving/restoring structures) and see what he thinks.

The big question would be what format others would like to use to obtain the structures. An .exe would be easiest, but we can also consider putting something online (use javascript form or applet) that will do this. That may take a bit more work, but it's still very easy. I can put it up on my webspace.

I like what you've put up on the library page!

Maybe I'll put up a couple of random number functions (using your new algorithm) and my save/restore functions (as noted earlier, they're not that useful yet, but they will be at some point).

Another thing that strikes me ... strings!!!

We so badly need some string functions!!!

It is driving me crazy ... I can't figure out how to replicate string functionality. Like getting a substring or a char out of a string. Maybe I am being stupid, but I don't think it can be done without the libraries. This could be a problem w/ restoring structures, because I assume we would paste in strings of structures. Grr!!

ETA: I know we can use .. (concatenation) and # (length). But what else? Are strings stored as char arrays? I'm looking at metatables in the lua manual -- maybe that will help us? I don't understand it though.

Joined: 04/13/2009
Groups: Contenders
okay, I was responding and my

okay, I was responding and my laptop shut down.... it gets so hot when running foldit that I think it shuts itself down!

Basically, I said ... "I'm stupid".

The program just needs to return a formatted string looking like this:

{"H", "H", "L", "E" ... }

and then it can be cut and pasted in as a table constructor:

structTable = // paste here!

then I was writing something like ... in English we say "duh!" when someone is being really stupid ...

Joined: 09/18/2009
Groups: SETI.Germany
String tables

"I know we can use .. (concatenation) and # (length). But what else? Are strings stored as char arrays? I'm looking at metatables in the lua manual -- maybe that will help us? I don't understand it though"

I also didn't get it completely with the tables and only know the .. and # operation :(

Again, the standrad library would help much for processing strings:
http://lua-users.org/wiki/StringLibraryTutorial

But, as far as I know, the whole content of a string is like a single value (like one cell in in MS-Excel, and not a list).

Maybe the user, who made this recipe can say more?

http://fold.it/portal/recipe/1915

Btw:
Now, you can delete the old multi-tool upload-tries.
uploading it works again.

Joined: 04/13/2009
Groups: Contenders
I know ... I wish we had the

I know ... I wish we had the string library.

If we're using an external program to get the structs, we have something like this:

startIndex = first occurance of “SSTR”
startIndex = first occurrence of “S”, “L”, or “E” after startIndex
endIndex = first occurrence of any char other than “S” “L” or “E” - 1
structString = substring(startIndex, endIndex)

// the string is formatted to look like this: {“S”, “S”, “L”, “E” … }
structString += “{ “ + structString + “ }”
for each char c in structString
structString = “ “ “ “ + c + “ “ “ “ + “ , “
end

we just return a formatted string that gets plugged in to the table constructor and magically becomes a lua table.

Then in lua, we'd have something like :

structTable = // paste that string here
for i = 1, i < # structTable, i++
{
replace_ss(structTable[i])
}

But the bigger question is ... how do we work with strings in Lua only (without string functions? It seems like it will often be necessary to not use a string at all but instead initialize a string as a table, so
"hello" becomes

{"h", "e", "l", "l", "o"}

We can do a lot with a table by just looping through it, iterating, grabbing bits of it, etc.. We can reproduce most of the functionality of the String library by using char tables.

Joined: 04/13/2009
Groups: Contenders
here's a useful function:

here's a useful function: given an index i, return two indices s and e -- the start and end points of i's structure. Then people can use that to wiggle/manipulate/rebuild the structure as a whole.

This is rough and I haven't tried running it. I'm sure you have a better/more efficient way of doing it -- you're the master of efficiency!

function getStructIndices (i)

s = i -- initialize start and end pts
e = i

-- look forward
for j = i+1, j <= get_segment_count(), j++
if get_ss(j) != get+ss(i)
break -- make sure break works the same in lua as I'm used to!
end
e = j
end

-- look back
for k = i-1, k >= 1, j--
if get_ss(k) != get+ss(i)
break
end
s = k
end

return s, e

end

Joined: 04/13/2009
Groups: Contenders
One more (can you tell I'm

One more (can you tell I'm bored? :) )

It would be nice to have a function that returns some results based on which segments are worst-scoring, because if we know what segments have problems, we can target those segments with our scripts. I mentioned this earlier.

What would be the most useful way of generating this kind of information?

Continuing with the idea of tables, what about a function that takes an attribute (either a segment score part like "clashing", "packing", etc. or "all" for the overall score) and returns a table ordered from worst to best of all segments in the protein. Optionally, there could be an int parameter that indicates the number of segments we want. So getWorst("packing", 5) would return the five most badly packed segments in the protein from most bad to least bad, while getWorst("backbone") would return all the segments in the protein from worst to least backbone score.

Then the user could do all kinds of things with this table. For example, why not wiggle all the worst segments? Or just select them so that he/she can look at them and decide what to do. Or band them and give them a tug. It should be easy for people to use the basic protein loop and substitute the table instead of the protein as a whole.

Basically, this idea and the previous one (get start and end indexes of a structure) involve separating out a subset of segments. Then we can do whatever we would do to the whole protein but to the subset. Some of the functions in the command set will take a set of indices, so the results of our library functions can just be fed into the appropriate commands.

Joined: 09/18/2009
Groups: SETI.Germany
5 worst

It's some time ago, when I programmed a sorting alogrithm only for a one-dimensional array, but for two, it's similar.

To get the 5 worst scores, at first you have to check ALL scores.
You have to create two 1-dimensional arrays which store ALL segment-numbers and scores.

For example, if the puzzle is 200 sgements, and we want to check the chlashing score per segment.
The array is index[1to200], score[1to200]

so, index[1]=1 and score[1]=get_segment_score_part("clashing",1),
index[2]=2 and score[2]=get_segment_score_part("clashing",2)
...
until index[200]=200 and score[200]=get_segment_score_part("clashing",200)

Then you have to run a loop from 200 to 2 backwards (let's call it k)

and IN this loop another loop, (let's call it l, running from k-1 to 1 backwards)

You have to check if score[l]>score[k]

IF so, swap score[k] with score[l] and index[k] with index[l]

QBASIC had a SWAP-function, we do this by:
temp=score[k] score[k]=score[l] score[l]=temp
temp=index[k] index[k]=index[l] index[l]=temp

to pull all worst scores AND their index-number upwards within the list.

This will give you a list with indexnumber and score, starting with index[1] and score[1] is worst and index[1] and score[1] is best.

So, fetching index[1to5] and score[1to5] will give you the 5 segment-numbers with the 5 worst scores.

I can write the algorithm this this week, but today I'm to exhausted from work, sorry :(

Btw I: To make a Best list, you ONLY have to change the condition 'score[l]>score[k]' to score[l]

Btw II: Where are the functions in the wiki gone?

regards,
Alex

Joined: 09/18/2009
Groups: SETI.Germany
Sorry...

...couldn't edit my text.

"This will give you a list with indexnumber and score, starting with index[1] and score[1] is worst and index[1] and score[1] is best."

has to be:

This will give you a list with indexnumber and score, starting with index[1] and score[1] is worst and index[200] and score[200] is best.

Maybe, there is a way to make the alogithm run shorter, if you only want to have 5 values.

I'll think about it.

Joined: 09/18/2009
Groups: SETI.Germany
YES, we can!

Okay, I thought about it.

The shorter version needs a flag-array, where we mark the segments we have already found!

Again, index values between 1 and 200

dimensions:
flag[1 to 200], index[1to5], score[1to5]

Process k from 1 to 5 (position of new list)
set score[k]=10000 (a very high value)
Process l from 1 to 200 (check all segments)
Check if score[k]>get_segment_score_part("clashing",l) and flag[l]~=1 (index has not to be used already?)
If yes, score[k]=get_segment_score_part("clashing",l) and index[k]=l (take actual values)
end
set flag[index[k]] to 1 (mark the found index, so it is not used anymore)
end

Joined: 09/18/2009
Groups: SETI.Germany
Question:

How do I declare an array at the beginning?
I don't know the command in Lua, only on other programming-languages.

Joined: 04/13/2009
Groups: Contenders
there are a lot of different

there are a lot of different sorting algorithms out there. I don't think it matters which one we use. What you describe sounds great. I was thinking of something similar to your flag aray, but instead we just remove an element from the unsorted array and insert into sorted array or something like that.

Re: tables and arrays in lua,

Lua is a bit strange, because tables and arrays are the same thing. They are both objects where one set of values is associated with another set of values (of any type). So we can initialize a table:

days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
nums = {1, 2, 4, 5, 7}

These are technically tables, but they work just like arrays. days[1] is Sunday, nums[3] is 4, and so on (note that indexes start at 1).

But we can also make tables where the indices are other kinds of values. So:

opnames = {["+"] = "add", ["-"] = "sub",
["*"] = "mul", ["/"] = "div"}

or
days = {["M"] = "Monday", ["T"] = "Tuesday" ... }

and so on. Any value of any type can be associated with any other value of any type. We can even put functions in tables, which is very interesting!

I think they can be used like records or complex data types. Like this:

segment = {["index"] = 1, ["score"] = 12, ["aa"] = "GLY"}

There are some interesting possibilities....

Joined: 09/18/2009
Groups: SETI.Germany
Wow!

Sounds nice!

And we don't need to give the dimensions in the beginning, we just can start with filling them?

Normally, some programs want to know the dimensions before, so they can reserve memory at first, and only then you can use it.

Joined: 04/13/2009
Groups: Contenders
tables

No -- Lua automaically manages the size of tables/arrays. I really like the way tables work in Lua -- so simple and powerful.

Joined: 09/18/2009
Groups: SETI.Germany
Well...

This sounds promisingly.
On some programmng-languages, you can't change an array again, if the dimensions were set once.

Joined: 04/13/2009
Groups: Contenders
yes! a table can expand and

yes! a table can expand and contract as needed and it's easy to add or change items.

unfortunately, there is a library of table functions with things like add, remove, iterate functions, etc. that we can't use (grr!).

I put up a couple of functions on our "library" page. they may or may not be that useful but they involve forming tables of data pulled from the protein. A person can just call the function and then they have all the data at their disposal.

I'm working on a generalized version of this (may replace one of the ones I have up) that works like this:

function getProteinTable()
pTable = {}

curSeg = 1

while curSeg <= get_segment_count() do
pTable[curSeg] = {} -- table of tables!
pTable[curSeg]["struct"] = get_ss(curSeg)
pTable[curSeg]["amino"] = get_aa(curSeg)
... many other things like subscores
curSeg = curSeg + 1
end
end

I want to set it up to pull out every bit of information we can get about segments, for example, all the segment score parts. The user can call the function once and it populates pTable for them. Ptable is a table of tables (one separate table for each segment in protein). They can grab things out of the pTable whenever desired with an easy method: for example, pTable[5]["amino"] will return the amino acid at segment 5. we can also make a simple print function to iterate thru ptable and print in a formatted manner. we can also have simple search and sort functions.

Maybe this is how we can tackle that issue of "worst score" sorting. We can use genralized methods instead of building a special worst score function. The user just calls the function to make the ptable and then can call something like pTableSort(backbone) (or somethng similar). pTableSort iterates thru ptable looking at backbone subscores, sorts them from worst to best (or best to worst?) and populates new table and returns that. New table has all the same info as the original ptable, just sorted based on backbone score (or whatever). Then the user can do whatever they want with the sorted table or part of it, like feed it into another function.

On a similar note of table functions, it would be cool (and simple) to alter some elements of the command set so that they take tables. For example, replace_ss(). We can make our own function pt_replace_ss() (pt for ptable) that takes a ptable of whatever size. The code would be simple, something like this:

pt_replace_ss(ptable)
for i = 1, # ptable
replace_ss(ptable[i])
end
end

We can make select and band commands do this, too (and probably others). Then a user can say make the ptable, sort for five worst scoring segments (the sort function returns a table), then send the new table to overloaded select, then run some algorithm like wiggle shake band rebuild whatever -- the result is you can do whatever you want but all of it targets the worst scoring segments in the protein and leaves best scoring segs alone.

heather-1's picture
User offline. Last seen 12 hours 20 min ago. Offline
Joined: 10/16/2008
Groups: None
Recipes and scripting

This all looks easy enough. I guess I am late in looking into this. I once opened cookbook to see what it was and kept right on using regular folding methods. Have now tried a couple of scripts!!

I have several problems: (1) My receipe menu won't add any functions beyond the first one I put in and
sometimes not even that. Thus I can't construct an experimental recipe.
What do I do to fix that? re-download fold.it? or something else?

(2) I have now written a couple of scripts-before I run these is there someone
who would look them over before I crash my computer? Where would I send
it? [Like sometimes one uses 'end' sometimes not. [I am not an
experienced programer, but have dibbeled and dabbeled in the past].

Joined: 05/26/2008
Groups: Hold My Beer
Just wanted to say great job

Just wanted to say great job on the wiki, and keep up the good work, muddled through a couple simple scripts this week, still working on adding to one of them as i find time, and looking forward to doing a few more. The wiki was really helpful in finding info. And thanks for pointing me in the right direction.

Joined: 04/13/2009
Groups: Contenders
Pletsch, I'm happy that

Pletsch, I'm happy that you're scripting! Looks like you've put up a couple of really useful scripts that my teammates have been talking about using successfully. I've been very busy in the last week and havne't had a chance, bu t I will look at them soon.

Keep up the great work -- and please add to the wiki if you have time -- we'd really appreciate your input and additions.

Joined: 04/13/2009
Groups: Contenders
Here was my comment in pm to

Here was my comment in pm to Heather's post above.

Hello Heather -- I'm so happy that you're working on learning scripting!! I had to take a bit of a break from writing tutorials because I've been very busy with work, but I will get back to it soon!

1) I'm not totally sure what you're referring to here. Are you having trouble saving a new script? I have noticed that occasionally I save a script and it does not appear in the recipes list (if that is what you are refering to). But if I exit the new interface and go to the old interface, it suddenly appears in the list. YOu could try this or try closing foldit and then re-opening it and see if your new recipe shows up.

2) I'd be happy to look at your scripts before you run them -- please feel free to post them in one of the forum threads going on about scripting (or we can make a new one titled something like "help me with my script!"). Or you can message them to me... of course one issue is that you cannot cut/paste from the foldit script window. Grr!

One way to do it is to write scripts in an external editor. So for example, you can use windows notepad. Then when you're done writing them, cut and paste them into foldit (this works even though it doesn't work to cut/paste FROM foldit -- why I don't know!). So then if you'd like some feedback, just cut and paste the script from notepad into a forum post or a message.

Here is another way to get the text of your scripts. Navigate to C:\Documents and Settings\All Users\Application Data\foldit . Find all.macro and open it with notepad or a text editor. It will look like a bunch of garbage but your script is hidden somewhere in it! Just use edit >> find and type in the word "script". Now you may have to hit the find next button a few times but you will eventually see your script. It will not be formatted very nicely, but you can cut and paste it from there.

Re: crashing your computer, there are a couple things that can crash things in scripts. First, if you have any segments frozen when you run the script, it will not like that. So make sure you unfreeze everything before running scripts (and in answer to your question, no, we can't use freeze in scripts, but you can use select to do all the things that freeze does. It is like the reverse of freeze -- so instead of freezing areas around the segments you want to manipulate, simply select the segments you want to manipulate and then run some commands.) Second, if you try to exit a script while it's running, it sometimes crashes things.

Another way to crash is to use too many bands. This is not really a script problem -- it can happen even if you're not running a script. There is a limit on the number of bands that can be placed in foldit. I don't know what it is, but when you have a larger protein and band each segment or each other segment or whatever, sometimes you will hit the limit and it will crash foldit.

Finally, the one other thing I can think of that causes issues is something called an "infinite loop". This is something that can happen in programming any language -- basicaally, you are looping (maybe using a "for" loop, for example) but there is nothing in your loop that tells the computer when to STOP looping, so it will loop forever! Oops! So in Lua, we say:

for int i = 1, i < 10 (or something like that!)

and what if inside your loop you do something to i ... like ...

i = i - 1

well, this is a problem, because the loop will only stop when it hits 10, but it will never hit 10 because every time it increments (it goes up by 1 automatically each time around the loop) it also decrements (goes down by one).

Finally, you mentioned "crashing" when not using end. This probably shouldn't crash foldit, but you will get error messages in your output window. My advice to you would be to forge through and go ahead and run your scripts, look carefully at what the error is telling you, and then try to correct it and run it again. This is called "debugging" and it is something that programmers in every language do a lot of! It's hard to write programs perfectly, so you have to just run them and see what happens. Believe me, I do this A LOT!

Hope that all helps! Let me know if you have more questions/thoughts and I'll try to address them. I'm happy you're getting into scripting -- it's fun, isn't it?

heather-1's picture
User offline. Last seen 12 hours 20 min ago. Offline
Joined: 10/16/2008
Groups: None
scripting and non-functioning receipe menu

Themarquis:

Oh, I see it now. I twerent sure about the segment select. I was concerned with the aspect that one freezes the protein in normal mode yet to some extent-presumably-the "energy" continues down the chain. So I thought in LUA I might be able to provide a "barrier" to this as well, beyond just the segment select. Really what all this wiggling and shaking and pulling is about is to get the protein to "twist" to it's most desirable conformation. However, someone seems to have made the protein parts resistant to conformational changes!! Theoretically-or at infinity-if this protein were actually in solution and these wiggles and shakes were actually random all folders would acheive the exact same outcome!! So can one come up with a twist seg command in LUA?

I'll have to "clean-up" my script in light of your statements!
I had discovered the other problems-like copying-in the script window that you mention!

I do not know what is wrong with the recipe generator in fold.it. When I click on the dotted format line, the dropdown menu appears. If I am lucky, the chosen step will appear in the list pane. However after this, nothing else will list in the list pane!! Sometimes even the first step will not initialize into the list pane. This might be an old problem as I only just tried to use the recipe function!!

Sitemap

Developed by: UW Center for Game Science, UW Institute for Protein Design, Northeastern University, Vanderbilt University Meiler Lab, UC Davis
Supported by: DARPA, NSF, NIH, HHMI, Amazon, Microsoft, Adobe, RosettaCommons