RFD4-Proteina / examples /README.md
kierandidi's picture
Include provenance sidecars explicitly in remote loading example
95a7d24 verified
|
Raw History Blame Contribute Delete
5.02 kB

BCIF/Zstandard loading examples

These 64 examples cover all 16 distinct structure stores used by the 19 metadata configurations in this repository. Four records per store were copied from the published snapshot aa86df1eb9e3529a0f39279f216dce3a95bb3dc2. Shared PDB interface views use the same underlying store; these examples do not claim to satisfy every view's sampling filters. They are format/loading examples, not a representative sample or a new training split. The complete original corpus and its configurations remain unchanged.

bcif-zstd/<component>/ contains standalone .bcif.zst files and metadata.jsonl. manifest.json records source IDs, original index/shard offsets, hashes and conversion checks. Conversion preserves every CIF category, column, lexical value and missing-value mask. Coordinates and core atom annotations were checked against decoding the original text CIF. No chemistry cleanup or quality filtering was applied during conversion. Original component caveats, including the unresolved OMol source-ID mismatch, still apply.

indexed-bcif/index.parquet and indexed-bcif/data/records-00000.bin contain the same 64 compressed records in an indexed shard. Each record is an independent Zstandard frame containing BinaryCIF. Offsets and lengths address compressed bytes. A .bin suffix describes the container, not the molecular payload format. The original training shards still contain Zstandard-compressed text CIF.

Load standalone files with Datasets

Requires Python 3.12+, AtomWorks 3.1.0+ and the Datasets implementation from PR #8895 until it is released. Resolve the Hub revision once and retain it for reproducibility.

from huggingface_hub import HfApi
from datasets import load_dataset

repo = "nvidia/RFD4-Proteina"
revision = HfApi().dataset_info(repo).sha
root = f"hf://datasets/{repo}@{revision}/examples"
rows = load_dataset(
    "mmcif",
    data_files=[f"{root}/bcif-zstd/*/*.bcif.zst", f"{root}/bcif-zstd/*/metadata.jsonl"],
    split="train", streaming=True,
)
atoms = next(iter(rows))["structure"]
print(atoms.coord.shape)

Set streaming=False for a regular Dataset. The explicit file pattern selects structures; the explicit metadata.jsonl pattern includes each component's provenance. Calling load_dataset(repo, "pdb_glycan", ...) continues to load the original sampling metadata, not these examples.

Without the Datasets PR, download an individual .bcif.zst file with hf_hub_download and read it with atomworks.io.atom_array_from_file.

Read an indexed record with AtomWorks

AtomWorks 3.1.0 supports revision-pinned Hugging Face range reads. Its ML BlobStore adapter requires its ML dependencies (including PyTorch); only the requested compressed record is fetched and then decompressed.

import io
import pyarrow.parquet as pq
from biotite.structure.io.pdbx import BinaryCIFFile
from huggingface_hub import HfApi, hf_hub_download
from atomworks.ml.utils.blob_store import BlobStore

repo = "nvidia/RFD4-Proteina"
revision = HfApi().dataset_info(repo).sha
prefix = "examples/indexed-bcif"
index_path = hf_hub_download(repo, f"{prefix}/index.parquet", repo_type="dataset", revision=revision)
row = pq.read_table(index_path).slice(0, 1).to_pylist()[0]
store = BlobStore(f"hf://datasets/{repo}@{revision}/{prefix}/data")
bcif = store.get_bytes(row["shard"], int(row["offset"]), int(row["length"]))
file = BinaryCIFFile.read(io.BytesIO(bcif))

Stream indexed records with Datasets

Datasets can stream the Parquet index and map each row to its ranged structure payload. This is an explicit adapter: the mmcif folder builder does not discover records inside arbitrary .bin files. read_hf_bytes fetches compressed bytes; AtomicStructure decompresses and decodes them on access. This helper does not require PyTorch.

from datasets import AtomicStructure, Features, load_dataset
from atomworks.ml.utils.huggingface import read_hf_bytes

# Reuse the pinned repo/revision/prefix from above.
root = f"hf://datasets/{repo}@{revision}/{prefix}"
index = load_dataset("parquet", data_files=f"{root}/index.parquet", split="train", streaming=True)

def fetch_structure(row):
    payload = read_hf_bytes(
        f"{root}/data/{row['shard']}", offset=int(row["offset"]), length=int(row["length"]),
    )
    return {"structure": {"bytes": payload, "path": None}}

features = Features({**index.features, "structure": AtomicStructure()})
rows = index.map(fetch_structure, features=features)
atoms = next(iter(rows))["structure"]

Keep each index and its shards at the same commit. For sequential training through Datasets, Parquet shards containing embedded AtomicStructure bytes offer a direct row-streaming layout. Indexed independent BCIF/Zstandard frames are useful for random access and AtomWorks samplers. Converting a full existing shard requires rebuilding offsets and lengths; renaming a text-CIF shard does not convert its payloads.