Profile


Name
untrim
ID
108774
Shared with
Public
Parent
None
Children
None
Created on
July 19, 2024 at 15:56 PM UTC
Updated on
July 19, 2024 at 15:58 PM UTC
Description

Quick demo of the structure.UntrimPose function. The function can throw an error, to the demo uses pcall () to catch it.

Best for


Code


--[[ untrim - quick demo of structure.UntrimPose use pcall to catch errors which otherwise end the recipe LociOiling 20240719 ]]-- -- -- ParseError -- common routine used by safe functions -- function ParseError ( errmsg ) local reason local start, stop, line, msg start, stop, line, msg = errmsg:find ( ":(%d+):%s()" ) if msg ~= nil then errmsg = errmsg:sub ( msg, #errmsg ) end return errmsg end -- -- SafeUntrim uses pcall -- to call structure.UntrimPose, returning -- a numeric return code and an error message. -- -- The return codes are: -- -- 0 - successful, error message is nil -- -1 - pose wasn't trimmed -- -999 - other error -- function SafeUntrim () -- local BADTRIM = "Cannot untrim pose that isn't trimmed." -- local good, errmsg = pcall ( structure.UntrimPose ) if good then return 0, nil else local err2 = ParseError ( errmsg ) local errp = err2:find ( BADTRIM ) if errp ~= nil then return -1, err2 end return -999, err2 end end print ( "untrim demo" ) startsegs = structure.GetCount () print ( "before untrim, segment count = " .. startsegs ) local rc,trimerr = SafeUntrim () if rc ~= 0 then print ( "untrim error: \"" .. trimerr .. "\"" ) end untrimsegs = structure.GetCount () print ( "after untrim, segment count = " .. untrimsegs ) if untrimsegs == startsegs then print ( "untrim didn't change segment count" ) if rc == -1 then print ( "protein was not trimmed" ) elseif rc ~= 0 then print ( "unknown error" ) end end

Comments