Skip to content

cvc::pocket_tunnel: PocketTunnel on the shared cocone core, with its legacy A/B (TexMol T5 part 1) - #1439

Merged
transfix merged 8 commits into
masterfrom
tfx/tmol-t5-pockettunnel
Nov 22, 2026
Merged

transfix merged 8 commits into
masterfrom
tfx/tmol-t5-pockettunnel

Conversation

@transfix

@transfix transfix commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

TexMol roadmap T5, first part: PocketTunnel (Goswami and Bajaj, UT 2008; transfix/volrover src/PocketTunnel, UT LGPL-2.1) as a headless cvc:: core. It finds the pockets, tunnels and voids of a surface as the stable manifolds of the distance function's maxima outside it. SecondaryStructures stays out (its licence waits on UT). The CLI, pycvc, DSL intrinsics, a mesh_lab request and a molecule demo are later PRs.

One cocone core

P1's cocone port moves from src/cvc/geometry/skeleton/ to src/cvc/geometry/cocone/: cocone.h, datastruct.*, stepping.h, init, util, tcocone and rcocone, as git renames. The skeleton keeps its own stages in skeleton/ and gets a skeleton_stages.h; the tiler's stepping.h include follows the move. PocketTunnel's legacy init.cpp and tcocone.cpp are this same code, and its util.cpp adds only cell_volume, which now lives in the core. No other copy is vendored. The skeleton, tiler and tet_complex tests pass unchanged.

cvc::pocket_tunnel

  • inc/cvc/geometry/pocket_tunnel.h and src/cvc/geometry/pocket_tunnel/pocket_tunnel.cpp port smax.cpp (grow_maximum, merging the touching outside clusters, the volumes and their sort), handle.cpp (the mouths) and op.cpp (the output) as one coroutine on the core.
  • pocket_tunnel_stepper is resumable, with phases from "checking" through "output". pocket_tunnel_job wraps it as a result_job. The parameters are a param_table (pocket_tunnel_params.h).
  • The result is the legacy library's coloured surface, plus every cluster with its kind, mouths, volume, cells and maxima, which the legacy code only printed.
  • No statics, no files, no stderr. Bad input throws pocket_tunnel_error with a reason: empty input, too few points, all in one plane or on one line, the same point repeated, a coordinate that is not finite, or bad parameters.
  • The legacy code's quadratic pieces are replaced. Its linked-list cluster merges are now a union-find, its per-cell linear search for volumes a table, its selection sort a stable merge sort, and its facet scan per shown feature a single scan. Its caps of 100 tunnels and 100 pockets are gone.

Legacy A/B (tools/volrover-goldens, at the pinned volrover sha)

pockettunnel_driver.cpp runs pocket_tunnel_fromsurf() once per process. A read-only hook patched into the legacy pocket_tunnel.cpp records its clusters, the geometry it returns, and Tight Cocone's marking. make_goldens.py --check compares a remade golden by content. There are five committed inputs. Four are synthetic: a ball with a chamber and one neck (a pocket), with two necks (a tunnel), three chambers, and an enclosed cavity. The fifth is PDB 1GRL's surface (2,609 points): its heavy atoms blurred by cvc::mol::blur at blobbiness -0.2 on a 3 Å grid, then cvc::iso at 10. That became possible once #1428 landed; master is merged in.

The legacy result is not a function of its input. CGAL's facet iterator reports a facet from the cell at the lower address, and Tight Cocone's peeling is greedy in that order. In one process, 1 of 5 triangulations of the tunnel input marked 33 more cells outside, which made five extra 1–2 cell pockets. The port walks in tet_complex's order instead. So pocket_tunnel_test compares at two levels:

  • After Tight Cocone, exactly: given the legacy marking (internal pocket_tunnel_marked.h), the port's own stages give every cluster with the same kind, mouths, cells and maxima, volumes to 1e-12, every shown triangle with its cluster and class, and every point's colour. This holds on all five cases, 1GRL included (19 clusters, 490 triangles, 251 coloured points).
  • End to end: pocket, tunnel and cavity are identical to the legacy result. On the tunnel, that is a tunnel of 3,085 cells and five pockets of one or two cells. On the three chambers, each cluster has 3 to 6 more cells than the legacy's. On 1GRL, the large pocket is the legacy's cell for cell (259 cells, 1,102 ų). The tunnel has 317 cells to the legacy's 307 (1,195 ų to 1,180), and both find three one-cell pockets. Clusters of more than 100 cells are compared to 5%.

The goldens are Linux's (f60500f). CI's first Linux check of the Windows-made goldens remade three of them differently, because glibc's and MSVC's heaps order the cells differently. On Windows, the tunnel's marking has 33 fewer outside cells and a single tunnel of 3,083 cells. The three chambers' has 41 more, and the port matches it to the cell. 1GRL's has 67 more, a tunnel of 309 cells and 17 one-cell pockets. As with Skeletonization's goldens, the committed set is CI's (ubuntu-24.04, GCC, cvcpkg's CGAL), taken from run 44987475380's artifact. Given either platform's marking, the port's stages make that platform's result exactly.

Tests (pocket_tunnel_test, natively and in the wasm-mt ports lane)

  • Known shapes: the right kinds, and volumes near the chambers'.
  • A protein (native only, where libcvc has its mesher): 1GRL at the skeleton lab's 2 Å (10,881 points), whose largest feature is a two-mouth tunnel of about 2,600 ų. At 3 Å the test also checks the committed input against a live blur and isosurface: exactly on x86, where Linux and Windows make the same 2,609 points. On aarch64 the mesher's multiply-adds are fused and macOS makes 2,606, so there it checks the count to 1% (b4bf921).
  • Output invariants: each shown cluster's triangles form a closed, consistently oriented surface whose enclosed volume equals the cluster's.
  • Colours follow the legacy rule.
  • Bad and degenerate input: everything listed above throws. Four or five points, lattices, near-cospherical points and duplicates run to the end.
  • Point order: the large clusters keep their kind and mouths, and their cells within 1%. The order matters for the same reason as above, because tet_complex numbers its cells by insertion order. A same-on-every-platform shuffle keeps the test deterministic.
  • No shared state: calls are independent across threads, and two cvc::apps run jobs at once, each from its own state-tree parameters on its own scheduler.
  • T7: resumability and cancel.
  • Parameter keys on the state tree.

Local runs:

  • Windows MSVC Release: 15/15, plus skeleton 11/11, tiler 21/21, tiler_legacy 58/58, tet_complex 10/10, skeleton_intrinsics 9/9.
  • wasm-mt under node: pocket_tunnel 14/14, skeleton 11/11.
  • --check reproduces the Linux goldens on Linux only. A Windows build makes its own goldens the same way in each new process, and they differ on three cases (above).

CI

  • pocket_tunnel_test joins SAN_CXX_TESTS.
  • The cgal-ab path filter watches src/cvc/geometry/cocone.
  • The volrover goldens job builds and checks PocketTunnel by default.
  • ci.yml stays CRLF (+4 / -2 lines).
  • An LBIE fix (01ebf3b). The asan-ubsan job stopped OnAProtein at 1GRL's 3 Å surface: octree.cpp:2656, "shift exponent -1 is negative". An edge on the volume's far boundary is stored in a cell outside the grid, so is_eflag_on() and eflag_on() shifted by a negative count. Both now treat that edge as having no flag. The mesh does not change: is_min_edge() never makes a quad for such an edge, and the old eflag_on() changed nothing for it. lbie_mesher, algorithm, geometry, skeleton and pocket_tunnel pass natively, and the 3 Å surface still matches the committed 1grl.pts.
  • macOS arm64 (b4bf921). recipe / macos-latest / Debug ran OnAProtein for the first time on 01ebf3b (every earlier macOS run was cancelled). Its 3 Å surface had 2,606 points to the committed 2,609, the arm64 FMA effect that blur.cpp, the tiler, nav and others already build around with -ffp-contract=off. The mesher isn't built that way. Changing that would move every macOS mesh, so the test's exact comparison is limited to targets without __FP_FAST_FMA instead.
  • The numpy pin is gone. 7090d8e carried ci: pin numpy-cp312 to cvc.6, its last JS-exceptions wasm bundle, until JX2 #1445's numpy-cp312 cvc.6 pin while master's required ariglx-web (wasm) check was red on cvc.7. JX2 (wasm: wasm exceptions and JSPI for libcvc's web hosts (JX2, first part) #1409) has since landed, and it deletes the pin script, so the merge of master (9f1b585) takes that deletion. The PR no longer changes anything under .github/scripts.

…legacy A/B (TexMol T5 part 1)

PocketTunnel (Goswami and Bajaj, UT 2008; transfix/volrover src/PocketTunnel, UT LGPL-2.1):
the pockets, tunnels and voids of a surface, as the stable manifolds of the distance
function's maxima outside it.

- The cocone core P1 ported (init, util, tcocone, rcocone, datastruct, stepping) moves from
  src/cvc/geometry/skeleton to src/cvc/geometry/cocone, shared by both ports. The skeleton's
  own stages keep their files and get skeleton_stages.h. PocketTunnel's init.cpp and
  tcocone.cpp were this code; its util.cpp adds only cell_volume, now in the core.
- cvc::pocket_tunnel (inc/cvc/geometry/pocket_tunnel.h): S_max (grow_maximum, merging the
  touching outside clusters, volumes and their sort), the mouths (detect_handle) and the
  output (convert_pocket_tunnel_to_rawc_geometry) as one coroutine, a resumable
  pocket_tunnel_stepper and its result_job, with a param_table (pocket_tunnel_params.h). The
  result lists every cluster with its kind, mouths, volume, cells and maxima, which the
  legacy library only printed; the coloured surface keeps the legacy colours. No statics,
  no files, no stderr; bad input throws pocket_tunnel_error with a reason. The quadratic
  legacy pieces (the linked-list merges, the volume table, the selection sort, a facet scan
  per shown feature) are a union-find, a table, a stable merge sort and one scan.
- pocket_tunnel_test: the four chambered-ball inputs (a pocket, a tunnel, three chambers, a
  cavity), the output's invariants (closed, consistently oriented boundaries whose enclosed
  volume is the cluster's), bad and degenerate input, point order (which moves only a few
  surface cells: Tight Cocone walks in tet_complex's insertion order), independent calls, two
  apps at once on their own schedulers and state trees, T7 resumability and cancel, the
  parameter keys on the state tree; natively and in the wasm-mt ports lane.
- The legacy A/B (tools/volrover-goldens): pockettunnel_driver.cpp runs the legacy entry
  once a process, through a read-only hook patched into pocket_tunnel.cpp, and records its
  clusters, geometry and Tight Cocone marking; make_goldens.py --check compares by content.
  Given the legacy marking, the port's own stages match the legacy library exactly on all
  four cases (clusters, triangles, colours). End to end they match exactly on three; Tight
  Cocone's greedy peeling walks in the cells' order, which in the legacy code is their
  addresses, and on the tunnel case that marks a few surface cells differently (the legacy
  library itself gives the other result in one run of five within a process).
- CI: pocket_tunnel_test joins SAN_CXX_TESTS; the cgal-ab path filter watches the cocone
  core's new directory; the volrover goldens job checks PocketTunnel too.
…l::blur is on master

- tools/volrover-goldens/inputs/pockettunnel/1grl.pts: 1GRL's heavy atoms blurred by
  cvc::mol::blur (blobbiness -0.2, a 3 A grid) and cvc::iso at 10, 2,609 points as floats;
  its golden from the legacy library. make_inputs.py leaves it alone (it needs libcvc).
- OnAProtein (native, where libcvc has its mesher): makes the surface at the skeleton lab's
  2 A (10,881 points; the largest feature a two-mouth tunnel of about 2,600 A^3) and at 3 A,
  checks the committed points against the latter, and writes them again with
  CVC_POCKETTUNNEL_WRITE_1GRL.
- The A/B covers 1grl: after Tight Cocone, the port is the legacy library exactly (19
  clusters, 490 triangles, 251 coloured points). End to end the large pocket is the legacy's
  cell for cell, the tunnel has 317 cells to its 309 (1,195 A^3 to 1,181), and the legacy
  run finds 17 one-cell pockets to the port's 3; large clusters are compared to 5%.
…il JX2

numpy-cp312 2.4.6+cvc.7 was published for wasm and wasm-mt on 2026-11-21 (23:43Z), built with
-fwasm-exceptions for JX2 (#1409). libcvc still links ariglx with Emscripten's JS exceptions, so
every ariglx-web job that has installed it since fails to link bin/ariglx.js:

  wasm-ld: error: .../numpy/_core/_multiarray_umath.cpython-312-wasm32-emscripten.so:
    undefined symbol: __cpp_exception (also __wasm_lpad_context, _Unwind_CallPersonality)

pin-wasm-pre-jx1.sh now puts cvc.6 back, as it does for the JX1 bundles. cvc.6 is the bundle
#1417's ariglx-web jobs linked on both columns. Checked locally on wasm and wasm-mt: with cvc.7
installed, 2 of numpy's 19 extensions import __cpp_exception; after the script, the lockfile
says cvc.6 and none do. JX2 deletes the script and its calls.
JX2 deletes .github/scripts/pin-wasm-pre-jx1.sh, where 7090d8e (cherry-picked
from #1445) pinned numpy-cp312 to cvc.6. With JX2's wasm exceptions, master
links cvc.7, so the pin is moot: the deletion is taken.
… check makes them

The first Linux run of the volrover goldens check (run 44987475380) remade three of the five
PocketTunnel goldens differently from the Windows ones. The legacy result follows the cells'
heap order, so glibc's and MSVC's heaps mark different cells outside on tunnel (33 more on
Linux), three_chambers (41 fewer) and 1grl (67 fewer). As with Skeletonization's goldens, the
committed set is now CI's (ubuntu-24.04, GCC, cvcpkg's CGAL), from that run's artifact.

- MatchesTheLegacyLibraryAfterTightCocone: unchanged and exact on all five; given either
  platform's marking, the port's stages make that platform's result.
- MatchesTheLegacyLibrary: tunnel is now exact end to end (a tunnel of 3,085 cells and five
  pockets of one or two, as the port finds); three_chambers moves to the 5% group (each
  cluster 3 to 6 cells more than the legacy's); 1grl's tunnel is 317 cells to 307.
- README: the table, the end-to-end numbers and the platform note.
The asan-ubsan job stopped pocket_tunnel_test's OnAProtein at 1GRL's 3 A
surface: octree.cpp:2656, "shift exponent -1 is negative". An edge on the
volume's far boundary is stored in a cell outside the grid; xyz2octcell
gives -1 there, so is_eflag_on() and eflag_on() computed idx -3 to -1 and
shifted by idx%8. Both now treat such an edge as having no flag.

The mesh does not change. Every caller makes a quad only through
is_min_edge(), which returns 0 for these edges before it touches the
frame, because is_refined() is 1 outside the grid. eflag_on() already
changed nothing for them, since the shifted bit fell outside the char.
pocket_tunnel 15, lbie_mesher 69, algorithm 10, geometry 122 and
skeleton 11 pass natively, and the 3 A surface still matches the
committed 1grl.pts.
…rch64

recipe / macos-latest / Debug ran OnAProtein for the first time on this
PR (every earlier macOS run was cancelled), and its 3 A surface had 2,606
points to the committed 1grl.pts's 2,609. x86 Linux and Windows make the
same 2,609. On aarch64 the compilers' default fuses the mesher's
multiply-adds; the mesher is not built with -ffp-contract=off, as
blur.cpp is, and the 2 A surface still has the same 10,881 points.

So the committed-copy check stays exact where __FP_FAST_FMA is not
defined (x86, and MSVC everywhere), and on a target with fused
multiply-add it checks the point count to 1%. The README says so.
pocket_tunnel_test passes 15/15 natively (Windows, exact path).
@transfix
transfix merged commit 0ab1438 into master Nov 22, 2026
32 checks passed
@transfix
transfix deleted the tfx/tmol-t5-pockettunnel branch November 22, 2026 21:09
transfix added a commit that referenced this pull request Nov 22, 2026
…-secondary

#1439 moved the cocone core to src/cvc/geometry/cocone and the skeleton's U1/U2 declarations to
skeleton/skeleton_stages.h, so secondary.h now includes that. The eight conflicts are adjacent
additions, and both sides are kept: the build lists, the goldens tool (CMakeLists, make_goldens.py,
make_inputs.py, README) and the TexMol roadmap. The shared cvcgeom.h shim is #1439's plus line_t
and lines(). With that shim, the legacy SecondaryStructures makes the same bytes as before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant