Icon representing a recipe

Recipe: Bravo Find Terminals With Bands v1.2

created by SemperRabbit

Profile


Name
Bravo Find Terminals With Bands v1.2
ID
109306
Shared with
Public
Parent
Bravo Find Terminals With Bands v1.1
Children
None
Created on
January 03, 2026 at 01:40 AM UTC
Updated on
January 03, 2026 at 05:14 AM UTC
Description

Best for


Code


-- This is an alternative method to identify terminal segments. works off the idea that you can creat a band on connected atoms. -- correctly identifies seperate proteins, ligands, RNA, and DNA. -- like most things in fold.it this recipe is faster with the window minimized. -- utilizes save.Quicksave(80) for clean up.change this if save slot is need. -- v1.1 -- removed false positives cause from cuts. -- band search more effiecent in a single pass. -- removed false positives from trim. -- v1.2 SemperRabbit 20260102 -- removed need to delete previous bands, leveraging the return value of band.AddBetweenSegments(). -- refactored everything into a single loop -- removes bands after detection and documentation -- removed quicksave restore at end still saves for error recovery -- Finds terminal segments using bands between atom 3 of segment i and atom 1 of segment i+1 (adjacent segments) -- returns Table or Terminals that is sorted with no duplicates function findTerminalsWithBands() save.Quicksave(80) -- for error recovery only, will not restore local segmentCount = structure.GetCount() -- Clear any existing bands to avoid interference -- check and remove false positives from trim. local success, err = pcall(structure.UntrimPose) local trim_total_segments = structure.GetCount() -- get total segments after untrim if trim_total_segments == segmentCount then --print("Pose was NOT trimmed") else print("Pose is trimmed at start of recipe") segmentCount = structure.GetCount() end -- identify false positives from cuts local table_of_cuts = structure.GetCuts() local k = 1 local Terminals = {} -- first segment and last segment wont have bands but are always terminals table.insert(Terminals, 1) -- table is sorted for i = 1, segmentCount - 1 do -- minus 1 so that we don't call a non existant segment with (i+1) if table_of_cuts[k] == i then k = k + 1 -- this is a cut, a false positive for terminals. skip it else -- Create a band between atom 3 of segment i and atom 1 of segment i+1 local tempBand = band.AddBetweenSegments(i, i + 1, 3, 1) if(tempBand ~= 0) then -- successful band; found some terminals! -- base before end to keep Terminals table sorted -- don't add a duplicate if Terminals[#Terminals] ~= i then table.insert(Terminals, i) end table.insert(Terminals, (i+1)) band.Delete(tempBand) end end end -- first segment and last segment wont have bands but are always terminals -- don't add a duplicate if Terminals[#Terminals] ~= segmentCount then table.insert(Terminals, segmentCount) -- table is sorted end -- Print all Terminal segment indicies in one line, comma-separated print(" Terminals") print(table.concat(Terminals, ", ")) -- remove bands and return user created bands --save.Quickload(80) -- return Terminals is sorted with no duplicates return Terminals end function cleanup(err) save.Quickload(80) print(" Error: " .. err) return {} end local Terminals = xpcall(findTerminalsWithBands,cleanup)

Comments


bravosk8erboy Lv 1

table.insert is slow in fold it because of the table api overhead. use "Terminals[#Terminals + 1] =" instead.
i also figured the single quick load was faster then the multiple band deletes.