New Lua functions, any suggestions?

Started by Timo van der Laan

jeff101 Lv 1

It might be better to save the screenshots to
the same directory where scriptlog.default.xml
resides. This way if you have Foldit clients in
different folders on the same machine, they won't
overwrite each other's screenshots.

It might also be good to allow the integer in:

void SaveScreenshot(integer)

to be 0 to a number much larger than 9.

If the integer is 0, SaveScreenshot can pick
its own name for the output png file. This
could be a unique name based on the date and
time the image is created, a name a bit like
those used for manually saved and shared puzzle
solution *.ir_solution files.

If the integer is >0, the screenshot
gets saved to a standard filename like
screenshot00001.png.

Having SaveScreenshot like above would let
players adapt recipes like GAB and DRW to
automatically make snapshots every time
the score rises by a certain amount, and
these snapshots could be viewed like a
slideshow to follow the moves taken by
the recipe to raise the protein's score.

It would help if SaveScreenshot would work
for minimized clients as well.

jeff101 Lv 1

If there were a LUA command equivalent
to pressing the Home key, that would be
helpful too. It could be used with the
SaveScreenshot command above to re-center
and rescale the protein image before
automatically taking a snapshot of the
protein.

Timo van der Laan Lv 1

Already there.
bool structure.InsertResidue(nr) Inserts after nr and
bool structure.DeleteResidue(nr) Delete the segment nr.
So to reverse the first operation you should use nr+1 in the Delete.

LociOiling Lv 1

Working on an update to "print protein", I've found that looking at the rotamer count is one way to find unlocked sidechains of locked segments. (A rotamer count greater than one indicates an unlocked sidechain.)

The drawback is that rotamer.GetCount () is really slow. For puzzle 1443, which was 252 segments including the ligands, getting the amino acid or secondary structure for all segments takes less than a second. Getting the rotamer count for all segments takes around 39 seconds.

Puzzle 1443 was also an exception: it has locked sidechains, but unlocked backbone. I think we've seen this type of thing before, but locked backbone with unlocked sidechains is probably more common. For "print protein", I'd like to avoid getting rotamer counts unless needed, but puzzles like 1443 make this difficult.

LociOiling Lv 1

Expose read-only tables of structure info.

The existing functions like structure.GetSecondaryStructure are slow relative to retrieving the same information from a Lua table. As an example, reading the secondary structure from a table 50,000 times for a 75-segment protein took 8 seconds. Calling the Foldit function instead took 37 seconds. (Not exactly bad, but much slower than using tables.)

Nothing is stopping us from making our own tables. The sample code below will probably go into "print protein 2.8". The Foldit core code could create these tables and update them as needed.

Conversion to tables is simple. A recipe calls protNfo.setNfo early on.

Later in the recipe, the code

local ss = structure.GetSecondaryStructure ( seg )

becomes

local ss = protNfo [ seg ]

The example below doesn't include selects, freezes, and some other possible items of interest. The rotamer.GetCount function is slow, so I've left it out here. The print protein version will include it, since it's used to detect locked sidechains (until someone writes a function for that).

Writers of long-running recipes might want to consider this code as well.

protNfo = {
    aa = {},
    ss = {},
    atom = {},
    phobe = {},
    lock = {},
    
    setNfo = function ()
        for ii = 1, structure.GetCount () do
            protNfo.aa [ #protNfo.aa + 1 ] = structure.GetAminoAcid ( ii )
            protNfo.ss [ #protNfo.ss + 1 ] = structure.GetSecondaryStructure ( ii )
            protNfo.atom [ #protNfo.atom + 1 ] = structure.GetAtomCount ( ii )
            protNfo.phobe [ #protNfo.phobe + 1 ] = structure.IsHydrophobic ( ii )
            protNfo.lock [ #protNfo.lock + 1 ] = structure.IsLocked ( ii )
        end
    end,
}

Seagat2011 Lv 1

Access to the free-form MOVE tool:

// After performing a Cut and or Selection..
structure.moveTo(X offset,Y offset, Z offset)

Seagat2011 Lv 1

And also set custom color for a segment

local colorstruct = { [ [ red:[C1], green:[C1], blue:[C1] ] value:[C2] ], brightness:[I] }

structure.SetSegmentColor( colorstruct )

– Where [C1] can be 0-256
– Where [C2] can be 'r'|'g'|'b'|0x000000-0xffffff
– Where [I] can be 0-100