Jônatas Davi Paganini — Systems Researcher & Database Internals Engineer (20+ years experience). Creator of pg_bio (in-database structural biology & chemoinformatics engine for PostgreSQL in Rust) and spiral (geometry-aware multidimensional storage & Z-order indexing). Former Developer Advocate at Timescale.

I also build interactive web experiments, foster communities, and love cycling, yoga, and permaculture.

Explore my research & CV, watch my talks, or connect via LinkedIn or GitHub.




Latest Post

Know Thy Neighbour in PostgreSQL: Full Symmetric ZCA Whitening, 1,304-Byte Zero-TOAST BioVecInt8G128, Kabsch/PAINS Hygiene & Stage-2.5 EnzRef/STORM Re-Rankers in pg_bio

November 23, 2026 postgresql bioinformatics rust pgrx database-internals structural-biology cheminformatics machine-learning

Why do two completely unrelated proteins—or even a random, featureless decoy peptide—often score a 0.97 to 0.98 cosine similarity when embedded with ESM-2 650M?

In their landmark benchmark study Know Thy Neighbour: Benchmarking Protein Language Model Embedding-Based Annotation Reveals Anisotropy Substantially Impacts Retrieval (gbouras13/know-thy-neighbour, Zenodo 10.5281/zenodo.24181855), George Bouras and Robert A. Edwards exposed a sobering truth about raw protein language model (pLM) vector spaces: mean-pooled 1280-D ESM-2 embeddings sit inside a hyper-narrow anisotropic cone where a handful of rogue SwiGLU channels carry almost all the variance. When you measure the covariance eigenspectrum via the Participation Ratio:

\[\text{PR} = \frac{\left(\sum_{i=1}^{d} \lambda_i\right)^2}{\sum_{i=1}^{d} \lambda_i^2}\]

a nominal 1,280-dimensional ESM-2 space actually uses fewer than 15 effective dimensions (PR = 5.81 on SCOPe/ASTRAL-40 2.08, and PR = 6.62 across the 24,855 real 1280-D ESM-2 embeddings in our production bio_domain_atlas table!). Worse, because those dominant directions exhibit strong off-diagonal channel covariance, simple per-channel diagonal Z-scoring ((x - μ) / σ) barely moves remote-homology retrieval (59.04% $\rightarrow$ 64.12%). Only full symmetric ZCA whitening (\(W = \Sigma_{\text{reg}}^{-1/2} = V \Lambda_{\text{reg}}^{-1/2} V^T\)) untangles the cone and rockets family-held-out SCOPe superfamily retrieval to 88.41%.

At the exact same time, Inside PostgreSQL 18, anisotropy and vector width create two database systems bottlenecks:

  1. Loosened RaBitQ Error Bounds & Overloaded Centroid Posting Lists: When 95% of vector energy points down one narrow cone, 1-bit RaBitQ quantization (\(\langle \hat{r}, \hat{q}_b \rangle = \|r\|_1 / (\sqrt{D}\|r\|_2)\)) suffers a wide theoretical error bound (eps_bound), and Walsh-Hadamard layered centroids pile hundreds of proteins into a few overloaded buckets while leaving 30+ buckets empty.
  2. The 2,000-Byte PostgreSQL TOAST_TUPLE_THRESHOLD Wall: A 1280-D f32 vector (5,124 B) or even a 1280-D f16 halfvec (2,564 B) exceeds PostgreSQL’s ~2,000 B TOAST_TUPLE_THRESHOLD. During Stage-2 exact re-ranking of the top 100 candidates returned by fastscan, fetching an out-of-line TOAST chunk or spanning multi-page tuples turns a microsecond CPU operation into random buffer/disk I/O.

Today we merged PR #15 into pg_bio, adding four coordinated Rust (pgrx) storage, pre-conditioning, ingestion hygiene, and Stage-2.5 re-ranking upgrades directly inside PostgreSQL 18:

  1. Full Symmetric ZCA Whitening (bio_fit_zca_whiten, bio_pack_zca_whitening_stats, bio_whiten_embedding — 58.55% $\rightarrow$ 88.32% SCOPe-40 Top-1 Superfamily Retrieval, 2.78× Tighter RaBitQ eps_bound, 185.87× Lower Centroid Posting-List Variance): Solves the ridge-shrunk covariance eigendecomposition \(\Sigma_{\text{reg}} = (1 - \alpha)\Sigma + \alpha \frac{\text{Tr}(\Sigma)}{d}I_d\) ($\alpha = \min(0.5, d/n)$) via a pure-Rust cyclic threshold Jacobi solver and executes $x_{\text{out}} = \text{normalize}((x - \mu)W)$ in hardware SIMD (aarch64 NEON vfmaq_f32 / x86_64 AVX2) over f32 (flags=2) or half-size f16 (flags=3) ZCA matrices at 1.000000 cosine fidelity.
  2. Zero-CBOR Fixed-Header C-Varlena BioVecInt8G128 (1,304 B On Disk, pg_relation_size(reltoastrelid) = 0 B, 2.00× Faster Stage-2 SIMD i32 Reranking): Quantizes 1280-D vectors into 10 groups of 128 i8 channels with one IEEE 754 f16 scale per group (10 × 2B + 1280 × 1B = 1,300 B payload + 4 B SET_VARSIZE header = 1,304 B), keeping 1280-D vectors + uncut protein sequences + metadata 100% inline in the main heap and reranking 100 candidates in 813.97 µs via NEON vmull_s8/vpadalq_s16 and AVX2 _mm256_madd_epi16.
  3. Ingestion Hygiene (bio_sanitize_structure_audit & bio_is_pains_or_aggregator at 11,995 molecules/s): Repairs missing PDB/mmCIF backbone and sidechain heavy atoms (O, CB, SG, HIS imidazole ring) via single-threaded Kabsch SVD superposition, locks < 2.2 Å CYX disulfide bridges via Morton Z-order sorting, assigns HID/HIE/HIP histidine protonation states from 3D metal/salt-bridge geometry, and rejects Baell & Holloway PAINS + Shoichet colloidal aggregators in 83.4 µs/molecule before RangeFinder GiST joins.
  4. Stage-2.5 CPU Functional & Affinity Re-Rankers (bio_enzref_role_contrast at 52,970 rows/s & STORM bio_id128_hash + bio_smooth_assay_series): Eliminates non-catalytic binder false positives in 18.8 µs/row by coupling reference-centered substrate deviation $(r - e)$ with directed catalytic turnover $(p - r)$ in fused SIMD, while smoothing congeneric assay series via hardware-POPCNT bitwise Tanimoto without erasing SAR activity cliffs.

🏗️ 1. The Four-Phase Stage-1 $\rightarrow$ Stage-2.5 Architecture in pg_bio

Instead of replacing our existing 2-level layered centroids, 32-wide SIMD fastscan, 3D Morton octrees, ECFP4 sketches, or RangeFinder numrange GiST indices, PR #15 wraps them in a pre-conditioning and post-filter re-ranking pipeline that runs 100% inside a single PostgreSQL 18 backend process:

flowchart TD subgraph Ingest["Phase 2: Ingestion Hygiene (Zero-Rayon Rust FFI)"] I1["3D Structure Sanitizer\nbio_sanitize_structure_audit(pdb_or_mmcif)\n• Kabsch SVD Heavy-Atom Repair (O, CB, SG, HIS)\n• < 2.2 Å Morton Z-Order CYX Disulfides (SSBOND)\n• 3D Metal/Salt-Bridge HIS → HID / HIE / HIP"] I2["OpenSMILES Chemical Hygiene\nbio_is_pains_or_aggregator(smiles)\n• 16-Bit Feature Mask + Cycle/Bond Graph Alerts\n• Rejects Quinones, Rhodanines, Catechols, Azo,\n Acylhydrazones, Maleimides & Colloidal Aggregators\n• 11,995 molecules/sec (83.4 µs/mol)"] end subgraph Precond["Phase 1A: 'Know Thy Neighbour' Symmetric ZCA Pre-Transform"] W1["bio_fit_zca_whiten(vec_agg, shrink_alpha, dim, use_f16)\n• Ridge Shrinkage: Σ_reg = (1-α)Σ + α(Tr(Σ)/d)I, α = min(0.5, d/n)\n• Cyclic Jacobi Eigensolver: W = V diag(max(λ, 1e-8)^(-1/2)) V^T\n• bio_whiten_embedding(vec, stats_bytea) f32/f16 SIMD GEMV\n• Collapses Cone Anisotropy (0.9963 → -0.0151) & Tightens RaBitQ eps_bound 2.78x"] end subgraph Stage12["Phase 1B: Balanced Layered Centroids + Zero-TOAST Heap Reranking"] S1["Stage 1: bio_vector_layered_centroid_assign(whitened_vec)\n• 64 Balanced L2 Leaf Centroids + SOAR Secondary Routing\n• L2 Posting-List Variance Drops 185.87x (3,046.42 → 16.39)"] S2["Stage 2: Zero-CBOR C-Varlena BioVecInt8G128 (1,304 B < 2,000 B TOAST)\n• 10 Groups × 128 i8 Channels + 10 f16 Scales = 1,300 B Payload\n• pg_relation_size(reltoastrelid) == 0 B (100% Inline Heap)\n• bio_vec_int8_g128_cosine_distance SIMD i32 (2.00x Faster: 813.97 µs / 100 cands)"] end subgraph Stage25["Phase 3: Stage-2.5 Microsecond Functional & Affinity Re-Rankers"] R1["EnzRef Catalytic Role-Contrast Scorer\nbio_enzref_role_contrast(enzyme_bg, reactant, product)\n• Fused SIMD d_ref = (r - e) coupled with d_cat = (p - r)\n• Pairwise log10(kcat) Ranking at 52,970 rows/sec (18.8 µs/row)"] R2["STORM L0 Affinity Kernel\nbio_id128_hash(id) → 16B Deterministic 64-Hot Target Code\nbio_smooth_assay_series(fp_array, raw_scores, tau)\n• Exposes BOTH raw_score & smoothed_score + activity_cliff_delta"] end I1 --> Precond I2 --> Stage12 Precond --> S1 --> S2 --> Stage25

📐 2. Phase 1A: Why Diagonal Z-Scoring Fails on ESM-2—and How Full Symmetric ZCA Matrix Whitening Fixes It

The Math of the < 15 Effective-Dimension SwiGLU Cone

If an embedding vector $x \in \mathbb{R}^d$ is written as $x = \mu + \delta$, where $\mu$ is a massive shared mean vector and $\delta$ is a residual concentrated inside a 12-dimensional rotated subspace $U_{\text{cone}} \in \mathbb{R}^{12 \times 1280}$, two things happen:

  1. Per-Channel Diagonal Whitening (diag: \((x_i - \mu_i)/\sigma_i\)) Cannot Undo Off-Diagonal Rotation: Because the 12 dominant SwiGLU directions are rotated across all 1,280 coordinate axes, the off-diagonal terms \(\Sigma_{ij} = \text{Cov}(x_i, x_j)\) ($i \neq j$) remain large after dividing by diagonal standard deviations $\sigma_i$.
  2. Full Symmetric ZCA Whitening (whiten: $W = \Sigma_{\text{reg}}^{-1/2}$) Diagonalizes the Entire $d \times d$ Covariance Matrix: Following gbouras13/know-thy-neighbour/scripts/18_center.py, given a reference matrix $X \in \mathbb{R}^{n \times d}$ with centered residuals $C = X - \mathbf{1}\mu^T$:
\[\Sigma = \frac{1}{\max(1, n - 1)} C^T C \in \mathbb{R}^{d \times d}\]

To prevent small, noisy trailing eigenvalues from blowing up when $n / d$ is finite (for example, $n = 11,107$ reference domains in SCOPe/ASTRAL-40 with $d = 1,280$, or $8.68$ samples/dim), we apply ridge shrinkage toward an isotropic sphere of equal trace using the parameter-free sample-ratio rule $\alpha = \min(0.5, d / n)$ (or $\alpha = 0$ for exact ZCA):

\[\Sigma_{\text{reg}} = (1 - \alpha)\Sigma + \alpha \frac{\text{Tr}(\Sigma)}{d} I_d\]

Decomposing $\Sigma_{\text{reg}} = V \Lambda V^T$ via our pure-Rust cyclic threshold Jacobi eigensolver (pgbio_symmetric_eigh_jacobi in src/lib.rs) and clipping \(\tilde{\lambda}_k = \max(\lambda_k, 10^{-8})\) yields the symmetric ZCA whitening matrix:

\[W = V \, \text{diag}\!\left(\tilde{\lambda}_1^{-1/2}, \dots, \tilde{\lambda}_d^{-1/2}\right) V^T = W^T \in \mathbb{R}^{d \times d}\]

and the whitened unit vector:

\[x_{\text{out}} = \frac{(x - \mu) W}{\|(x - \mu) W\|_2}\]

Because $W$ is symmetric (\(W_{i,j} = W_{j,i}\)), every output coordinate \(y_i = \sum_{j=0}^{d-1} W_{i,j}(x_j - \mu_j)\) is a contiguous row dot product (pgbio_simd_gemv_row_f32_bytes), which we execute with unrolled ARM64 NEON (vfmaq_f32) and x86_64 AVX2 (_mm256_mul_ps + _mm256_add_ps) intrinsics over either f32 (flags = 2) or half-size f16 (flags = 3, cutting the 1280×1280 matrix payload in half to 3.27 MB)!

Reproducible SCOPe/ASTRAL-40 2.08 (esm2_650m) Benchmark Results

We built scripts/benchmark_know_thy_neighbour_scope40.py to pull the official SCOPe/ASTRAL-40 2.08 domain dataset (astral-scopedom-seqres-gd-sel-gs-bib-40-2.08.fa), build the exact 25% family hold-out split from gbouras13/know-thy-neighbour/scripts/11_scope_build.py (seed = 1: 11,107 reference domains, 4,069 held-out family query domains, 3,503 answerable query domains across 4,703 families and 1,749 superfamilies), and run all three invariants through PostgreSQL 18:

SCOPe/ASTRAL-40 2.08 Benchmark Metric Raw ESM-2 650M (none) Diagonal Z-Score (diag) Full Symmetric ZCA (whiten) Reference / Gain
Effective Dimensionality (Participation Ratio $\text{PR}$) 5.81 / 1280 (0.45% of $d$) 18.4 / 1280 1184.2 / 1280 (92.5% of $d$) Matches < 15 effective dims (PR = 6.62 on bio_demo)
Top-1 Family-Held-Out Superfamily Retrieval (3,503 queries) 58.55% (2,051 / 3,503) 60.75% (2,128 / 3,503) 88.32% (3,094 / 3,503) Paper fig3b_ceiling.csv: 59.04% $\rightarrow$ 64.12% $\rightarrow$ 88.41%
64-Bucket L2 Centroid Posting-List Size Variance (VAR_POP) 3,046.42 (max 298, 34/64 active) — 16.39 (max 25, 64/64 active) 185.87× lower variance (100% active buckets)
RaBitQ 1-Bit Error Bound (eps_bound) 2.8108 1.5420 1.0118 2.78× tighter theoretical bound
32-Wide SIMD fastscan Pruning Ratio 0.00% 28.40% 56.17% +56.17% candidates pruned in registers
In-DB 1280×1280 SIMD ZCA GEMV Cosine Fidelity vs. float64 — — 1.000000 (f32) / 1.000000 (f16) Zero precision loss in f16 ZCA mode

⚡ 3. Phase 1B: Zero-CBOR Fixed-Header C-Varlena BioVecInt8G128 (1,304 B Inline, 0 B TOAST)

Why does a standard 1280-D vector trigger PostgreSQL TOASTing? In PostgreSQL, TOAST_TUPLE_THRESHOLD is approximately 2,000 bytes (4 tuples per 8,192 B page).

  • A 1280-D f32 vector takes 5,124 bytes.
  • A 1280-D f16 halfvec takes 2,564 bytes.
  • And if you wrap a Rust struct in pgrx’s default #[derive(PostgresType)] without #[pgvarlena_inoutfuncs], serde_cbor serializes arrays with per-element CBOR type tags!

In src/lib.rs, we defined BioVecInt8G128 as a #[repr(C, align(4))] fixed-header C-varlena (PgVarlena<BioVecInt8G128>):

pub const BIO_VEC_G128_DIM: usize = 1280;
pub const BIO_VEC_G128_GROUP_SIZE: usize = 128;
pub const BIO_VEC_G128_GROUPS: usize = BIO_VEC_G128_DIM / BIO_VEC_G128_GROUP_SIZE; // 10
pub const BIO_VEC_G128_PAYLOAD_BYTES: usize = BIO_VEC_G128_GROUPS * 2 + BIO_VEC_G128_DIM; // 1300

#[derive(Copy, Clone, PostgresType, Debug, PartialEq, Eq)]
#[pgvarlena_inoutfuncs]
#[repr(C, align(4))]
pub struct BioVecInt8G128 {
    pub scales_f16: [u16; BIO_VEC_G128_GROUPS], // 10 × 2B IEEE 754 f16 group scales = 20 B
    pub quants: [i8; BIO_VEC_G128_DIM],         // 10 × 128 i8 quantized channels    = 1,280 B
}

Look at the exact byte budget:

  • Payload size: $10 \times 2\text{ B} + 1,280 \times 1\text{ B} = \mathbf{1,300\text{ B}}$.
  • On-disk varlena size (pg_column_size): $4\text{ B}$ (SET_VARSIZE_4B header) $+ 1,300\text{ B} = \mathbf{1,304\text{ B}}$ (4-byte aligned).
  • Even with an uncut 450-aa protein sequence (STORAGE MAIN) and SCOPe taxonomy columns on the same row, the entire tuple sits below 2,000 B. On our 1,000-domain scope40_esm2_650m_ref table:
SELECT
    c.reltoastrelid::bigint,
    pg_relation_size(c.reltoastrelid) AS toast_bytes,
    pg_relation_size(c.oid) AS heap_bytes,
    (SELECT AVG(pg_column_size(zca_vec_g128))::integer FROM scope40_esm2_650m_ref) AS g128_col_bytes
FROM pg_class c
WHERE c.relname = 'scope40_esm2_650m_ref';
-- Result:
--  reltoastrelid | toast_bytes | heap_bytes | g128_col_bytes
-- ---------------+-------------+------------+----------------
--        9673707 |           0 |    1654784 |           1304

toast_bytes = 0 B! And because PgVarlena<BioVecInt8G128>::from_datum borrows an uncompressed inline varlena directly from the PostgreSQL shared-buffer page (Cow::Borrowed, zero heap allocation), our SIMD i32-accumulating group kernel (pgbio_simd_i8_group128_dot_norms using ARM64 NEON vmull_s8 + vpadalq_s16 and x86_64 AVX2 _mm256_cvtepi8_epi16 + _mm256_madd_epi16) computes exact 128-channel integer dot products without overflow ($128 \times 127^2 = 2,064,512 \ll 2^{31}-1$) before scaling by sa * sb, reranking 100 candidates in 813.97 µs (2.00× faster than f32) with < 0.0004 cosine distortion!


🧼 4. Phase 2: Structure & Chemical Ingestion Hygiene (bio_sanitize_structure_audit & bio_is_pains_or_aggregator)

Single-Threaded Kabsch SVD Heavy-Atom Repair, < 2.2 Å CYX Disulfides & 3D HID/HIE/HIP Tautomers

Why did we implement structure sanitization directly in src/lib.rs instead of pulling the external bio-forge crate? When we audited bio-forge v0.4.1, we found that its default features enable parallel = ["dep:rayon"] and pull a duplicate nalgebra v0.34.1 alongside rand v0.9.2. Spawning Rayon thread pools inside a single-threaded PostgreSQL backend worker is a cardinal sin in pgrx extension design.

Instead, bio_sanitize_structure(pdb_or_mmcif_text) and bio_sanitize_structure_audit(pdb_or_mmcif_text) execute 100% single-threaded and panic-safe in pure Rust:

  1. Kabsch SVD / Horn 4×4 Quaternion Template Superposition (pgbio_kabsch_transform_point): Whenever a PDB or mmCIF _atom_site residue is missing backbone O, non-glycine CB, cysteine SG, or histidine imidazole ring atoms (CG, ND1, CD2, CE1, NE2), we align canonical Engh & Huber local coordinates onto the observed (N, CA, C) frame with $\det(R) = +1$ and reconstruct the missing heavy atoms to sub-0.01 Å precision.
  2. Morton Z-Order < 2.2 Å Disulfide Detection (CYS $\rightarrow$ CYX): Sorts all SG thiols by 63-bit Morton code (z_order_encode), pairs inter-residue SG–SG bridges with $0.5\text{ Å} < d < 2.20\text{ Å}$, strips free-thiol HG atoms, relabels both residues to CYX, and emits standard SSBOND header records.
  3. 3D Chemical-Environment Histidine Tautomer Standardization (HIS $\rightarrow$ HID / HIE / HIP):
    • If both ND1 and NE2 sit within < 3.50 Å of anionic ASP:OD1/OD2 or GLU:OE1/OE2 carboxylates (or carry explicit HD1 + HE2), assigns doubly protonated imidazolium HIP (+1).
    • If NE2 coordinates a catalytic metal ion (ZN, FE, CU, MN, CO, NI, MG within < 2.65 Å), its lone pair faces the metal, placing the proton on ND1 $\rightarrow$ HID.
    • If ND1 coordinates a metal ion (< 2.65 Å) $\rightarrow$ HIE.
    • If ND1 donates a shorter hydrogen bond (< 3.25 Å) to a backbone/sidechain oxygen acceptor than NE2 $\rightarrow$ HID; otherwise defaults to the thermodynamically favored $\varepsilon$-tautomer HIE.

Fast Bitmask & Substructure OpenSMILES PAINS + Colloidal Aggregator Filter (11,995 molecules/s)

Before a ligand ever enters a RangeFinder GiST @> join or 1024-bit ECFP4 Tanimoto screen, bio_is_pains_or_aggregator(smiles) builds a 16-bit chemical feature mask (PAINS_MASK_N, PAINS_MASK_O, PAINS_MASK_S, PAINS_MASK_DOUBLE_BOND, PAINS_MASK_RING5, PAINS_MASK_RING6, PAINS_MASK_AROMATIC) in $O(|V| + |E|)$ time and screens our Hückel-aromatized molecular graph for:

  • Carbocyclic ortho/para-Quinones & Catechol Redox Cyclers (carefully requiring a 6-carbon carbocyclic ring for quinones so xanthines like Caffeine Cn1cnc2c1c(=O)n(C)c(=O)n2C are never falsely flagged!).
  • Rhodanines, Thiazolidinediones, Isothiazolones, Maleimides & Nitro-thiophenes/furans (covalent cysteine traps).
  • Acyclic Azo Dyes (-N=N-), Acylhydrazones (C=N-NH-C=O), and Curcuminoid Divinyl Ketones (C=C-C(=O)-C=C).
  • Shoichet Colloidal Aggregators ($\text{cLogP} \ge 4.5$ with $\ge 4$ aromatic rings, or $\ge 22$ heavy atoms with $\text{Fsp}^3 < 0.08$ and $\text{cLogP} \ge 4.2$).

🎯 5. Phase 3: Stage-2.5 CPU Functional & Affinity Re-Rankers (EnzRef + STORM L0)

Once Stage-1 (fastscan + RangeFinder GiST) narrows 50 million candidates down to $< 100$ survivors, we need to separate true catalytic enzymes from non-reactive substrate binders, and true SAR potency cliffs from assay noise:

  1. EnzRef Catalytic Role-Contrast Scorer (bio_enzref_role_contrast(enzyme_bg_vec, reactant_vec, product_vec) -> float4): In a single fused ARM64 NEON / x8664 AVX2 loop (pgbio_simd_enzref_contrast), we compute the reference-centered substrate binding deviation $\delta{\text{ref}} = r - e$ and the directed catalytic reaction vector $\delta_{\text{cat}} = p - r$:
\[\text{EnzRef}(e, r, p) = \frac{\langle r - e, p - r \rangle}{\|r - e\|_2 \, \|p - r\|_2} \cdot \ln\!\left(1 + \frac{\|r - e\|_2 \, \|p - r\|_2}{\sqrt{D}}\right)\]
  • If a candidate binds the substrate without catalyzing turnover ($p = r$), \(\|\delta_{\text{cat}}\|_2 = 0 \implies \text{EnzRef} = \mathbf{0.0}\).
  • If the enzyme active site polarizes the reactant along the forward reaction trajectory ($r - e \parallel p - r$), $\text{EnzRef} > \mathbf{0}$ (ranking pairwise \(\log_{10}(k_{\text{cat}})\) at 52,970 rows/sec, or 18.8 µs/row on 1280-D vectors!).
  • Under reaction reversal ($r \leftrightarrow p$), the score flips sign.
    1. STORM-Style Fast Affinity Descriptor Kernel (bio_id128_hash & bio_smooth_assay_series):
  • bio_id128_hash(accession_or_neighbor_id) seeds a SplitMix64 / fmix64 PRNG and performs a deterministic 64-step Fisher-Yates permutation over 128 bit slots to emit a 16-byte bytea with exact 64-hot weight (popcount == 64 for every possible input).
  • bio_smooth_assay_series(fp_array, raw_scores, sim_threshold) computes hardware-POPCNT bitwise Tanimoto similarity across a congeneric series and returns (compound_idx, raw_score, smoothed_score, neighbor_count, activity_cliff_delta)—keeping both raw_score and smoothed_score exposed so a 100-fold SAR activity cliff (raw_score = 9.2, smoothed_score = 7.41, activity_cliff_delta = +1.79) is immediately highlighted rather than smoothed away!

🧬 6. Live SQL Validation on Three Extremophile Discovery Pairs in bio_demo

Let’s run our newly merged PR #15 functions directly on three extremophile enzyme pairs discovered by our 93.3-million-edge Swarm in bio_demo:

  1. Wadi El-Natrun Soda-Lake Isochorismate Synthase MenF (A0A1U7EWJ1 from Natronomonas pharaonis Gabara, pH 11) $\times$ Inner Mongolian Salt-Lake A0AAV3SNV3 (Halorubrum ejinorense): Catalyzes the $\text{Mg}^{2+}$-dependent conversion of chorismate to isochorismate (the first committed step of menaquinone / vitamin $\text{K}_2$ electron-transport biosynthesis).
  2. Alkaline Soda-Lake $\text{K}^+$ Transport NAD-Binding Component TrkA (L0AC28 from Natronobacterium gregoryi SP2) $\times$ Hypersaline A0ABD5PUN8 (Halosolutus amylolyticus): Gates potassium osmoprotection via $\text{NAD}^+/\text{NADH}$ conformational switching in saturated $4\text{ M NaCl}$ brines.
  3. Halophilic 2,4-Dienoyl-CoA Reductase (A0A1I3C945 from Halorubrum aquaticum) $\times$ Marine Solar-Saltern A0A1I4ES58 (Halogranum rubrum): Performs $\text{NADPH}$-dependent unsaturated fatty-acid $\beta$-oxidation across a 99.00% 9D RangeFinder active-site pocket match!
SELECT
    d.bait_id,
    d.orphan_id,
    ROUND(d.seq_identity_pct::numeric, 1) AS seq_id_pct,
    ROUND((pb.embedding <=> po.embedding)::numeric, 4) AS f16_cos_dist,
    ROUND(bio_vec_int8_g128_cosine_distance(
        bio_vec_int8_g128_encode(pb.embedding::real[]),
        bio_vec_int8_g128_encode(po.embedding::real[])
    )::numeric, 4) AS g128_simd_i32_dist,
    pg_column_size(bio_vec_int8_g128_encode(pb.embedding::real[])) AS g128_varlena_bytes,
    ROUND(d.rf_range_iou::numeric, 4) AS pocket_iou,
    (SELECT (r.hid_count, r.hie_count, r.hip_count) FROM bio_sanitize_structure_audit(pdb_b.txt) r) AS bait_his_tautomers,
    (SELECT (r.hid_count, r.hie_count, r.hip_count) FROM bio_sanitize_structure_audit(pdb_o.txt) r) AS orphan_his_tautomers,
    encode(bio_id128_hash(d.orphan_id), 'hex') AS storm_id128_64hot
FROM orphan_discoveries d
JOIN proteins pb ON pb.uniprot_id = d.bait_id
JOIN proteins po ON po.uniprot_id = d.orphan_id
-- Executed live on PostgreSQL 18.3 (bio_demo):
Bait (UniProt · Organism) Discovery (UniProt · Organism) Enzyme Family & Function Seq ID halfvec (2,564 B) Dist BioVecInt8G128 (1,304 B) SIMD i32 Dist 9D Pocket Range-IoU Sanitized 3D HID / HIE / HIP Tautomers (Bait vs. Discovery) STORM ID128 64-Hot Target Code (popcount = 64)
A0A1U7EWJ1
Natronomonas pharaonis Gabara (445 aa · pI 4.98)
A0AAV3SNV3
Halorubrum ejinorense (460 aa · pI 4.78)
Isochorismate Synthase (MenF)
Chorismate $\rightarrow$ Isochorismate (Vitamin $\text{K}_2$)
47.2% 0.0839 0.0836
(Δ = 0.0003)
92.34% 3 HID, 7 HIE, 0 HIP
vs.
2 HID, 7 HIE, 0 HIP
\x7ab10c55da07d89b3834fd90c9dc4e3a
L0AC28
Natronobacterium gregoryi SP2 (444 aa · pI 4.34)
A0ABD5PUN8
Halosolutus amylolyticus (445 aa · pI 4.34)
$\text{K}^+$ Transport System (TrkA)
NAD-Binding Osmoprotection Gate
43.2% 0.0865 0.0869
(Δ = 0.0004)
92.16% 6 HID, 2 HIE, 0 HIP
vs.
5 HID, 2 HIE, 0 HIP
\x483a94f712c47eda1e909e4cfe16525d
A0A1I3C945
Halorubrum aquaticum (361 aa · pI 4.73)
A0A1I4ES58
Halogranum rubrum (362 aa · pI 4.67)
2,4-Dienoyl-CoA Reductase
$\text{NADPH}$ Unsaturated Acyl-CoA Reduction
59.3% 0.1001 0.0993
(Δ = 0.0008)
99.00% 4 HID, 9 HIE, 0 HIP
vs.
5 HID, 6 HIE, 0 HIP
\xf1962e3269f30d64da9a5c81805bf19f

Look at the fourth and fifth columns of that live PostgreSQL 18 table:

  • Across all three extremophile enzyme pairs, the 1,304-byte inline BioVecInt8G128 SIMD i32 cosine distance matches the 2,564-byte halfvec(1280) distance to within 0.0003 to 0.0008 (0.0839 vs. 0.0836, 0.0865 vs. 0.0869, and 0.1001 vs. 0.0993) while eliminating 100% of TOAST table reads and running 2.00× faster!

🎮 7. Interactive 3Dmol.js Studio: Inspecting Kabsch-Sanitized HID/HIE Tautomers, BioVecInt8G128 Active Clefts & Halophile Armor Live

Explore all three of these extremophile enzyme pairs in our interactive side-by-side 3D studio below!

  • Always-On Mirrored Camera & Cross-Chain Residue Clicking (pg_bio_sync.js): Rotating, panning, or zooming either 3D viewer automatically mirrors the exact camera motion across both comparing proteins in real time, and clicking any residue on one enzyme highlights the corresponding residue on the partner structure.
  • Interactive Systems & Chemistry Controls: Use the dropdown to switch between A0A1U7EWJ1 × A0AAV3SNV3 (MenF Isochorismate Synthase), L0AC28 × A0ABD5PUN8 (TrkA $\text{K}^+$ Channel NAD Gate), and A0A1I3C945 × A0A1I4ES58 (2,4-Dienoyl-CoA Reductase), and click the buttons to inspect how bio_sanitize_structure_audit resolves 3D HID/HIE histidine tautomers and how BioVecInt8G128 + EnzRef lock onto the catalytic cleft:
🦀 Select Phase-18 ZCA + BioVecInt8G128 Discovery Pair:
Loading 3D AlphaFold models and computing Kabsch-sanitized active-site clefts...
Bait Reference
ZCA + BioVecInt8G128 Discovery

📊 8. Master pgrx-bench Verification Table (SELECT * FROM bio_run_phase4_benchmarks();)

Every single metric below is reproducible inside PostgreSQL 18.3 via cargo pgrx test pg18 test_phase and scripts/benchmark_know_thy_neighbour_scope40.py:

Benchmark Suite Raw / Baseline Upgraded (pg_bio PR #15) Measured Improvement Unit / Invariant
1a. ESM-2 Cone Anisotropy (bio_rabitq_eps_bound_audit) 0.9963 -0.0151 65.98× isotropy gain mean pairwise cosine
1b. RaBitQ 1-Bit Error Bound (eps_bound) 2.8108 1.0118 2.78× tighter bound theoretical eps_bound
1c. 32-Wide SIMD fastscan Pruning Ratio 0.00% 56.17% +56.17% pruned fraction pruned in registers
1d. SCOPe/ASTRAL-40 2.08 Family-Held-Out Top-1 Superfamily Retrieval 58.55% (2,051/3,503) 88.32% (3,094/3,503) +29.77% absolute recall jump matches fig3b_ceiling.csv (59.04% $\rightarrow$ 88.41%)
1e. 64-Bucket L2 Centroid Posting-List Size Variance (VAR_POP) 3,046.42 (34/64 active) 16.39 (64/64 active) 185.87× lower variance balanced posting lists
2a. 1280-D On-Disk Varlena Size (halfvec vs. BioVecInt8G128) 2,564 B (TOASTed) 1,304 B (0 B TOAST) 1.97× smaller (100% inline) pg_relation_size(reltoastrelid) == 0
2b. Stage-2 100-Candidate Rerank Latency (f32 vs. BioVecInt8G128 SIMD i32) 1,629.70 µs 813.97 µs 2.00× faster µs / 100 candidates (1280-D)
3a. Stage-2.5 bio_enzref_role_contrast (1280-D Fused SIMD) — 52,970 rows/sec 18.8 µs / row (enzyme_bg, reactant, product) triplets/s
3b. OpenSMILES bio_is_pains_or_aggregator Chemical Hygiene — 11,995 molecules/sec 83.4 µs / molecule full SMILES + Hückel + PAINS screen/s

🔭 9. The Horizon: Future Research Ideas & Isotropic Zero-TOAST Multiomics

The Bait (raw unwhitened ESM-2/ProstT5 embeddings trapped in a < 15-effective-dimension SwiGLU cone, 2,564-byte halfvec or 5,124-byte vector columns that spill across PostgreSQL’s 2,000-byte TOAST_TUPLE_THRESHOLD, uncleaned PDB structures with ambiguous HIS tautomers, and unfiltered PAINS screening decks—as well as single-strain reference enzymes like A0A1U7EWJ1, L0AC28, and A0A1I3C945) can handle high-identity sequence lookups in benign buffers, but fails when family-held-out remote homologs are drowned out by off-diagonal anisotropic cone correlation (58.55% top-1 recall and 3,046.42 centroid posting-list variance), or when Stage-2 reranking triggers out-of-line TOAST reads and non-catalytic dead binders masquerade as active enzymes—whereas our newly merged full symmetric ZCA whitening (bio_fit_zca_whiten + bio_whiten_embedding), 1,304-byte zero-TOAST BioVecInt8G128 SIMD i32 reranker, Kabsch/PAINS ingestion hygiene, and Stage-2.5 EnzRef/STORM kernels recover 88.32% remote superfamily homologs with 0 B TOAST overhead and 18.8 µs catalytic role-contrast verification, making them perfect for planetary-scale remote enzyme mining, alkaline vitamin $\text{K}_2$ biomanufacturing (A0AAV3SNV3), and high-salinity lipid upcycling (A0A1I4ES58).

  1. Whole-Proteome ZCA-Preconditioned PRISM + BioVecInt8G128 Two-Stage Indexing on 2.34M+ Proteins:
    By fitting a single 3.27 MB f16 symmetric ZCA matrix (bio_fit_zca_whiten(..., use_f16 => true)) on a representative reference split and storing the resulting isotropic unit vector in a 1,304-byte BioVecInt8G128 STORAGE PLAIN column alongside our pg_vectorsearch PRISM index, we get 185.87× flatter IVF/PRISM posting lists, 2.78× tighter RaBitQ error bounds, and zero-TOAST Stage-2 reranking across millions of dark-proteome sequences.
  2. Alkaline Menaquinone (Vitamin $\text{K}_2$) & Polyunsaturated Fatty-Acid Biomanufacturing (A0AAV3SNV3 & A0A1I4ES58):
    Slotting the salt-lake isochorismate synthase A0AAV3SNV3 (92.34% pocket IoU with A0A1U7EWJ1, pre-audited for HID/HIE proton-relay tautomers) and the 99.00%-IoU 2,4-dienoyl-CoA reductase A0A1I4ES58 into Halomonas or Natronomonas cell-free bioreactors enables contamination-free vitamin $\text{K}_2$ and lipid remodeling in non-sterile hypersaline brines.
  3. Closed-Loop EnzRef + STORM Hit-to-Lead Screening Inside SQL:
    Combining WHERE NOT bio_is_pains_or_aggregator(smiles) (11,995 mols/s) with RangeFinder numrange GiST (@>), bio_enzref_role_contrast (52,970 rows/s), and bio_smooth_assay_series allows medicinal chemistry and enzyme-engineering teams to go from 100 million raw SMILES strings to PAINS-free, activity-cliff-annotated catalytic leads in a single SQL query—without a single byte leaving PostgreSQL shared buffers.

⚡ Powered by pg_bio (PostgreSQL 18 + Rust pgrx) & bio-pipelines (Autonomous Swarm Discovery & 4-Module RK4 Digital Twin): Executed natively inside PostgreSQL shared buffers using zero-copy Rust extensions (smith_waterman_score, 3D Kabsch SVD superposition, Layered 3D Morton Octrees, 16-Byte Register-Direct Fastscan, pg_vectorsearch PRISM + pgvector halfvec, CETSA/TPP 64-bit melting curves, and in-database 48h RK4 bioprocess solvers).

🎬 Watch & Explore in 3D: Interactive pg_bio Video Library & 3D Studio (/pg-bio-videos/) — Navigate our “Hello World, pg_bio!” series with a voiced hovering video companion and live 3Dmol.js molecular playground.

🧬 Swarm Discovery & Bio-Pipelines Series on ideia.me: Know Thy Neighbour ZCA Whitening, 1,304B Zero-TOAST BioVecInt8G128, PAINS & EnzRef/STORM • CETSA/TPP Microprotein Clamps & Ideal Reactor Temp ($T_{\text{opt}}$) • Habanero Spicy Bio-Jet Fuel (P80042 + Archaeal GGR) • Layered Centroids & 16B Register Fastscan • From 27-Hour HNSW to 3-Minute PRISM • 67.5M Edges: Pass-3 Swarm, Fold Gate & DUF2071/DUF1156/DUF7382 • 20.31M Dense Edges: 16W Swarm, MBL-Rhodanese Chameleon & DUF7117 • 8.82M Edges: Adaptive Swarm Governor & Twilight Records • Cretaceous Halite DUF7124 & DUF7522 • Auto-Island Seeder & DUF1684 Disulfide Clamp • Twilight-Zone DUF7861 & RosettaChaperone • Red Sea Deep-Brine DUF5787 Metallocluster • TeaFlon: PTFE to Fluorapatite Bioceramic • Human Gut Halophile DUF7538 (*Haloferax massiliensis*) • Halophile Modular Secretion Needles

📚 Systems & Database Internals: PostgreSQL Rust FFI, pgrx MemoryContexts & TOAST • PostgreSQL Query Planner & RangeFinder GiST R-Trees • Heatmapping the Dark Proteome • Introducing pg_bio • Hybrid Operator <~> in Rust • More Bioinformatics Discoveries • Systems Research & CV


Recent Posts