Learn Scripting!

Started by themarquis

Steven Pletsch Lv 1

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.

themarquis Lv 1

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.

themarquis Lv 1

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 Lv 1

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!!