band.AddBetweenSegments can return zero on error

Case number:845813-2001490
Topic:Game: Tools
Opened by:LociOiling
Status:Closed
Type:Suggestion
Opened on:Saturday, November 21, 2015 - 19:26
Last modified:Tuesday, July 31, 2018 - 20:52

There's an inconsistency in how band.AddBetweenSegments handles errors. Recipes which generate random bands, such as GAB family of recipes, may suffer rare crashes as a result.

A call like

bIdx= band.AddBetweenSegments ( 21, -21 )

"throws" an error with a "bad argument #2" message. Unless the pcall function is used to call AddBetweenSegments, the error terminates the recipe.

However, a call like

bIdx = band.AddBetweenSegments ( 21, 21 )

does not issue an error, but does return zero for the band index (bIdx = 0).

It would be more consistent to throw an error in this case. As far as I know, the case of segment index 1 == segment index 2 is the *only* one which gets a zero return code instead of a thrown error from this function. In general, the foldit Lua functions throw errors instead of setting return codes.

Many recipes generate random bands. Once in a while, these recipes will draw the same number twice. The band.AddBetweenSegments won't seem to fail, but functions like band.SetStrength will crash, if passed band index zero. The solution is to either check for band index 1 == band index2 or check for a zero return code. A careful recipe "cook" will do both.

(Sat, 11/21/2015 - 19:26  |  3 comments)


LociOiling's picture
User offline. Last seen 7 hours 31 min ago. Offline
Joined: 12/27/2012
Groups: Beta Folders

Here's a oddball corollary that makes the initial case look more like a bug.

bc1 = band.AddBetweenSegments ( 1, 21 )

bc2 = band.AddToBandEndpoint ( 21, bc1 )

print ( "band index 2 = " .. bc2 )

if bc2 ~= 0 then 
    band.SetStrength ( bc2, 10 )
    band.SetGoalLength ( bc2, 10 )
end

In other words, create a band from segment x to segment y. Then create another band to the endpoint of the first, using segment y as the origin of the second band. A strange band is created in this case.

For consistency, AddToBandEndpoint should return a zero band index in this case. This would create an information leak, however, allowing a recipe to detect at least one endpoint of an existing band.

My next step is to add atom indexes to see if I can pull a residue apart.

LociOiling's picture
User offline. Last seen 7 hours 31 min ago. Offline
Joined: 12/27/2012
Groups: Beta Folders

Here's the next illogical step. For puzzle 1158, it attempts to pull the sidechain of the tryptophan at segment 54 off the backbone. Sadly, the attempt fails.

bc1 = band.AddBetweenSegments ( 20, 54 )

at2 = structure.GetAtomCount ( 54 )

bc2 = band.AddToBandEndpoint ( 54, bc1, at2 )

print ( "band index 2 = " .. bc2 )

if bc2 ~= 0 then 
    band.SetStrength ( bc2, 10 )
    band.SetGoalLength ( bc2, 10000 )
end

for ii = 1, 999 do
   local bcx = band.AddToBandEndpoint ( 54, bc1, at2 )
   band.SetStrength ( bcx, 10 )
   band.SetGoalLength ( bcx, 10000 )
end

band.Delete ( bc1 )

structure.WiggleAll ( 10 )
LociOiling's picture
User offline. Last seen 7 hours 31 min ago. Offline
Joined: 12/27/2012
Groups: Beta Folders
Status: Open » Closed

Finally decided this is more feature than bug, closing.

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