Skip to main content

foldenv — per-residue structural context from AlphaFold

foldenv computes a protein residue's structural microenvironment from its AlphaFold-predicted fold: relative solvent accessibility (RSA), secondary structure (helix/strand/coil via DSSP), spatial contacts / packing, a pLDDT confidence flag, and an optional per-residue protein-language-model (PLM) embedding. One call takes a UniProt accession + residue position and returns a strict-JSON-safe dict — enough to tell a buried structural residue apart from a functional surface residue, or to featurize a mutation site for downstream ML.

from foldenv import get_structural_context

get_structural_context("P04637", 175)   # TP53 R175
# → {"uniprot_id": "P04637", "position": 175, "wildtype_aa": "R",
#    "rsa": 0.022, "secondary_structure": "C", "contact_count": 14,
#    "nearest_contacts": [...], "embedding": [...1536-d...],
#    "embedding_model": "ankh", "plddt": 96.6}

Keywords: AlphaFold · relative solvent accessibility · RSA · secondary structure · DSSP · residue contacts · contact map · pLDDT · residue microenvironment · protein language model · per-residue embedding · structural bioinformatics · mutation effect featurization.

Install

pip install foldenv
pip install "foldenv[saprot]"   # + mini3di, for SaProt's 3Di embeddings

esmc_600m additionally needs the EvolutionaryScale SDK (pip install esm), which conflicts with the pinned transformers and so belongs in its own environment.

External binary: secondary structure + RSA need the mkdssp binary (DSSP v4).

  • macOS: brew tap brewsci/bio && brew install brewsci/bio/dssp
  • Debian/Ubuntu: apt-get install dssp (provides mkdssp)

Without it, the low-level contact and sequence helpers still work, but every documented entry point — get_structural_context, structural_profile, tool.invoke, analysis.summarize, validation.crystal_crosscheck — needs secondary structure and so fails. PLM weights download on first use (Ankh-large ~2 GB).

Usage

Agent-tool wrapper (fast, interpretable). tool.invoke omits the raw embedding by default, so it returns quickly (no PLM download) and gives an LLM the interpretable fields:

from foldenv import tool

tool.invoke({"uniprot_id": "P04637", "position": 175})            # dict or JSON string
tool.invoke({"uniprot_id": "P04637", "position": 175, "include_embedding": True})  # +1536-d vector
tool.tool_spec("anthropic")   # tool descriptor: {name, description, input_schema}  (also "openai"/"plain")

Direct Python API. get_structural_context computes the embedding by default (loads the PLM). Pass embedding.model="none" for the structural fields only:

from foldenv import get_structural_context, config

cfg = config.load(overrides={"embedding": {"model": "none"}})   # skip the PLM forward pass
ctx = get_structural_context("P62593", 68, config=cfg)          # TEM-1 catalytic S70 (Ambler) = UniProt 68
ctx["rsa"], ctx["contact_count"], ctx["plddt"]                  # 0.052, 11, ...

Other entry points:

from foldenv import structural_profile, analysis, validation

structural_profile("P62593")                     # {pos: {aa, rsa, ss3, contact_count, plddt}} for every residue
analysis.summarize("P04637")                      # functional-site structural signature
validation.crystal_crosscheck("P62593", "1BTL")   # AlphaFold-vs-experimental agreement report

Config is overridable per call via config.load(overrides=...); all outputs are strict-JSON-safe.

Returned fields

Field Meaning
rsa relative solvent accessibility (Tien 2013 theoretical MaxASA)
secondary_structure 3-state H/E/C from DSSP; G,I→H and B→E (Cuff & Barton Method A, as in MDTraj/MDAnalysis — see SS8_TO_SS3). SS-prediction benchmarks often send G,I,B→C instead, which reports less H and E
contact_count number of residues in the Cα-8 Å neighborhood (pLDDT-masked)
nearest_contacts list of {resnum, aa, distance} for the closest contacts
embedding / embedding_model per-residue PLM vector + which model produced it (default Ankh-large, 1536-d)
plddt AlphaFold per-residue confidence

Embedding models

embedding.EMBEDDING_MODELS registry — set embedding.model in decisions.yaml or via config.load(overrides=...):

name model dim notes
ankh Ankh-large 1536 default
ankh3_large Ankh3-large 1536 T5 encoder, [NLU] prefix
ankh3_xl Ankh3-XL 2560 T5 encoder, [NLU] prefix
prostt5_aa ProstT5 AA-mode 1024
saprot SaProt 650M 1280 structure-aware; 3Di from the AF backbone via mini3di ([saprot] extra)
saprot_1.3b SaProt 1.3B 1280 structure-aware; deeper (not wider) than 650M
esm2_3b ESM2-3B 2560 sequence-only
esm2_650m ESM2-650M 1280 lighter sequence-only
esmc_600m ESM C 600M 1152 via the esm SDK
esmc_6b ESM C 6B 2560 best PLM; needs transformers>=4.57 (separate env); never on Apple MPS

The sequence models (Ankh, Ankh3×2, ProstT5, ESM2×2) are tested on transformers 4.27–4.45. Device is picked automatically (MPS → CUDA → CPU); ESM C is routed off MPS.

Configuration (decisions)

Defaults live in foldenv/decisions.yaml (overridable via config.load(overrides=...)): Cα-8 Å contacts (Cβ-5 Å optional), mask pLDDT < 50, RSA via Tien 2013 theoretical MaxASA, per-protein in-memory cache + optional L2 disk cache, Ankh-large embedding, mkdssp with --output-format=dssp. The on-disk cache location is ./.foldenv_cache by default, overridable via FOLDENV_CACHE_DIR or the cache.dir config leaf.

Tests

pip install -e ".[dev,saprot]"
pytest -q

Live tests self-skip when AlphaFold-DB is unreachable or mkdssp is absent; weight-loading forward-pass tests are opt-in (RUN_HEAVY_EMB=1). See tests/TESTS.md for the full inventory, and docs/SETUP_NOTES.md for environment setup and the RSA/secondary-structure validation notes.

Provenance & license

foldenv was developed inside a private research fork of MuLAN and extracted here. Two helper modules (constants.py, plm.py) adapt small routines from MuLAN — see NOTICE. Licensed under CC BY-NC-SA 4.0 (see LICENSE), the same license as MuLAN: free for attributed, non-commercial use; derivatives must share alike.

Acknowledgements

This work was carried out during a 2026 summer research internship at the Laboratoire de Biologie Computationnelle, Quantitative et Synthétique — the Laboratory of Computational, Quantitative and Synthetic Biology (CQSB, UMR 7238, CNRS–Sorbonne Université), Paris.

The internship was supported by a fellowship from the France-Stanford Center for Interdisciplinary Studies, Stanford Global Studies Division, Stanford University.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

foldenv-0.1.1.tar.gz (71.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

foldenv-0.1.1-py3-none-any.whl (60.2 kB view details)

Uploaded Python 3

File details

Details for the file foldenv-0.1.1.tar.gz.

File metadata

  • Download URL: foldenv-0.1.1.tar.gz
  • Upload date:
  • Size: 71.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for foldenv-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b1b1d7931c2950d6937c32ec17d25e8c94798504a334076963967cea5d4c3fc0
MD5 f02901c01512bab751f4901b9a6f8771
BLAKE2b-256 61c6b6434a97f52cc8be9ec05630e258656569403c0868e7d725b003d68ffc74

See more details on using hashes here.

Provenance

The following attestation bundles were made for foldenv-0.1.1.tar.gz:

Publisher: publish.yml on cchin29/foldenv

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file foldenv-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: foldenv-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 60.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for foldenv-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e43d62929ef5cc7e292c5ea6522e200bbbbc6585c51e0152a3726e4fbabc8ebc
MD5 afa192abbf8e5b8a042671da43a06c95
BLAKE2b-256 e198eb8b7520e21b8f4ce2154e54cb3ba5e88f35f51afc0d61b283844123a44d

See more details on using hashes here.

Provenance

The following attestation bundles were made for foldenv-0.1.1-py3-none-any.whl:

Publisher: publish.yml on cchin29/foldenv

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.3.0

2 files

0.2.0

2 files

0.1.2

2 files

This release

0.1.1 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page