Skill Tracer
Skills › Scientific Agent Skills › esm › esm3-api.md

esm3-api.md

125 lines · skills/esm/references/esm3-api.md at 5f2bc03

Open on GitHub
1# ESM3 generation: esm 3.4.1.post1
2

ESM3 generation: esm 3.4.1.post1

Raw lines 1 to 2
3## Model and interface
4
5Local `ESM3.from_pretrained("esm3-sm-open-v1", device=torch.device("cpu"))`
6loads the open 1.4B checkpoint. Hosted `esm.sdk.client()` uses Biohub, with
7`esm3-small-2024-08`, `esm3-medium-2024-08` (7B), and `esm3-large-2024-03`
8(98B) listed in the current ESM3 README. Access depends on the account; model
9listing is not an authenticated availability test. Do not rely on the old
10unverified `esm3-medium-multimer-2024-09` example.
12`ESMProtein` contains optional sequence, secondary-structure, SASA, function and
13coordinate tracks. Sequence masking uses `_`. Use consistent track lengths and
14explicit chain/residue mappings; plain single-chain recipes here exclude `|`
15chain breaks. Coordinates are `torch.Tensor` atom37 arrays `(L,37,3)` in angstroms,
16with missing atoms represented by NaN, not Python `None` entries in a tensor.
18`ESMProtein.from_pdb(path, chain_id="A")` selects an author chain. The current
19default `chain_id="all"` combines chains, so specify the desired chain explicitly.
20`to_pdb(path)` writes a file; `to_pdb_string()` returns text. Preserve original
21residue numbers/insertion codes externally when sequence indices differ.

Model and interface

Local ESM3.from_pretrained("esm3-sm-open-v1", device=torch.device("cpu")) loads the open 1.4B checkpoint. Hosted esm.sdk.client() uses Biohub, with esm3-small-2024-08, esm3-medium-2024-08 (7B), and esm3-large-2024-03 (98B) listed in the current ESM3 README. Access depends on the account; model listing is not an authenticated availability test. Do not rely on the old unverified esm3-medium-multimer-2024-09 example.

ESMProtein contains optional sequence, secondary-structure, SASA, function and coordinate tracks. Sequence masking uses _. Use consistent track lengths and explicit chain/residue mappings; plain single-chain recipes here exclude | chain breaks. Coordinates are torch.Tensor atom37 arrays (L,37,3) in angstroms, with missing atoms represented by NaN, not Python None entries in a tensor.

ESMProtein.from_pdb(path, chain_id="A") selects an author chain. The current default chain_id="all" combines chains, so specify the desired chain explicitly. to_pdb(path) writes a file; to_pdb_string() returns text. Preserve original residue numbers/insertion codes externally when sequence indices differ.

Raw lines 3 to 22
23## Generation controls
25`GenerationConfig` supports tracks `sequence`, `structure`,
26`secondary_structure`, `sasa`, and `function`. Relevant released defaults are
27`num_steps=20`, `temperature=1.0`, `temperature_annealing=True`, `top_p=1.0`,
28`strategy="random"`, `schedule="cosine"`, and
29`condition_on_coordinates_only=True`. Source comments about earlier defaults
30can differ from the actual field values; record explicit settings.
32- Use a positive step count suited to the missing positions. Local generation
33 caps excessive steps at the number of masks; the hosted client also caps by
34 sequence length and can mutate the config. Create a separate config per request.
35- `top_p` is a float; `1.0` disables nucleus restriction. Do not pass `None`.
36- Temperature has no maximum of 1.0. At zero, sampling can select argmax, but
37 default annealing has a positive floor and random unmasking remains stochastic.
38 Temperature zero alone is not a reproducibility guarantee.
39- `condition_on_coordinates_only` selects coordinates instead of discrete
40 structure tokens as structure conditioning. It does **not** clear the sequence
41 or every other track. For inverse folding, remove the sequence explicitly.
42- `.generate()` fills masked positions. It does not resample all fixed residues;
43 a temperature schedule made from repeated calls on completed sequences is not
44 refinement. Remask intended sites, or use the SDK's actual annealing option.
46The unified low-level inference path is `encoded = model.encode(protein)` then
47`output = model.logits(encoded, LogitsConfig(...))`. Inspect `output.logits.sequence`
48for sequence logits. `model.forward(encoded)` followed by `model.decode(output)`
49is invalid: `forward` has lower-level batched tensor arguments and `decode`
50expects an `ESMProteinTensor`, not a logits object.

Generation controls

GenerationConfig supports tracks sequence, structure, secondary_structure, sasa, and function. Relevant released defaults are num_steps=20, temperature=1.0, temperature_annealing=True, top_p=1.0, strategy="random", schedule="cosine", and condition_on_coordinates_only=True. Source comments about earlier defaults can differ from the actual field values; record explicit settings.

  • Use a positive step count suited to the missing positions. Local generation caps excessive steps at the number of masks; the hosted client also caps by sequence length and can mutate the config. Create a separate config per request.
  • top_p is a float; 1.0 disables nucleus restriction. Do not pass None.
  • Temperature has no maximum of 1.0. At zero, sampling can select argmax, but default annealing has a positive floor and random unmasking remains stochastic. Temperature zero alone is not a reproducibility guarantee.
  • condition_on_coordinates_only selects coordinates instead of discrete structure tokens as structure conditioning. It does not clear the sequence or every other track. For inverse folding, remove the sequence explicitly.
  • .generate() fills masked positions. It does not resample all fixed residues; a temperature schedule made from repeated calls on completed sequences is not refinement. Remask intended sites, or use the SDK's actual annealing option.

The unified low-level inference path is encoded = model.encode(protein) then output = model.logits(encoded, LogitsConfig(...)). Inspect output.logits.sequence for sequence logits. model.forward(encoded) followed by model.decode(output) is invalid: forward has lower-level batched tensor arguments and decode expects an ESMProteinTensor, not a logits object.

Raw lines 23 to 51
52## Inverse folding and independent checking
54Illustrative pretrained inference; `model` is a loaded ESM3 inference client.
56```python
57from esm.sdk.api import ESMProtein, ESMProteinError, GenerationConfig
59original = ESMProtein.from_pdb("target.pdb", chain_id="A")
60assert original.coordinates is not None and original.sequence
61prompt = ESMProtein(coordinates=original.coordinates.clone())
62design = model.generate(prompt, GenerationConfig(
63 track="sequence", num_steps=min(20, len(original.sequence)),
64 temperature=0.7, condition_on_coordinates_only=True,
65))
66if isinstance(design, ESMProteinError):
67 raise design
68assert design.sequence is not None and len(design.sequence) == len(original.sequence)
70# Sequence-only input avoids conditioning the structural check on the target.
71predicted = model.generate(ESMProtein(sequence=design.sequence), GenerationConfig(
72 track="structure", num_steps=min(20, len(design.sequence)),
73))
74if isinstance(predicted, ESMProteinError):
75 raise predicted
76predicted.to_pdb("independently_predicted.pdb")
77```
79Compare matched, finite atoms after structural superposition; report alignment
80coverage and confidence, not just an RMSD number. Successful coordinate generation
81is not evidence that a design is stable or functional. A same-model round trip
82also is not independent experimental validation.

Inverse folding and independent checking

Illustrative pretrained inference; model is a loaded ESM3 inference client.

from esm.sdk.api import ESMProtein, ESMProteinError, GenerationConfig

original = ESMProtein.from_pdb("target.pdb", chain_id="A")
assert original.coordinates is not None and original.sequence
prompt = ESMProtein(coordinates=original.coordinates.clone())
design = model.generate(prompt, GenerationConfig(
    track="sequence", num_steps=min(20, len(original.sequence)),
    temperature=0.7, condition_on_coordinates_only=True,
))
if isinstance(design, ESMProteinError):
    raise design
assert design.sequence is not None and len(design.sequence) == len(original.sequence)

# Sequence-only input avoids conditioning the structural check on the target.
predicted = model.generate(ESMProtein(sequence=design.sequence), GenerationConfig(
    track="structure", num_steps=min(20, len(design.sequence)),
))
if isinstance(predicted, ESMProteinError):
    raise predicted
predicted.to_pdb("independently_predicted.pdb")

Compare matched, finite atoms after structural superposition; report alignment coverage and confidence, not just an RMSD number. Successful coordinate generation is not evidence that a design is stable or functional. A same-model round trip also is not independent experimental validation.

Raw lines 52 to 83
84## Function conditioning
86`FunctionAnnotation` is exported from `esm.sdk.api` and defined in
87`esm.utils.types`. Its `start` and `end` are **1-based, inclusive**. Labels must
88occur in the selected function/residue-annotation tokenizer vocabulary: supported
89InterPro IDs or exact keyword entries, not invented natural-language underscored
90labels. A range specifies where a function annotation applies; it is not a
91constraint fixing a catalytic residue or GFP chromophore.
93For a local loaded ESM3 model, inspect the supported vocabulary before constructing
94annotations (illustrative; vocabulary assets were not downloaded in this review):
96```python
97from esm.sdk.api import ESMProtein, FunctionAnnotation, GenerationConfig
99label = selected_supported_label # Chosen from this model's vocabulary.
100tokenizer = model.tokenizers.function
101assert label in tokenizer.interpro_labels or label in tokenizer.keyword_vocabulary
102annotation = FunctionAnnotation(label=label, start=1, end=150)
103prompt = ESMProtein(sequence="_" * 150, function_annotations=[annotation])
104result = model.generate(prompt, GenerationConfig(track="sequence", num_steps=20))
105```
107Function-track predictions are annotation hypotheses. Low temperature is not
108calibrated confidence. Confirm with curated evidence and task-specific assays;
109function conditioning alone cannot guarantee fluorescence or enzyme activity.

Function conditioning

FunctionAnnotation is exported from esm.sdk.api and defined in esm.utils.types. Its start and end are 1-based, inclusive. Labels must occur in the selected function/residue-annotation tokenizer vocabulary: supported InterPro IDs or exact keyword entries, not invented natural-language underscored labels. A range specifies where a function annotation applies; it is not a constraint fixing a catalytic residue or GFP chromophore.

For a local loaded ESM3 model, inspect the supported vocabulary before constructing annotations (illustrative; vocabulary assets were not downloaded in this review):

from esm.sdk.api import ESMProtein, FunctionAnnotation, GenerationConfig

label = selected_supported_label  # Chosen from this model's vocabulary.
tokenizer = model.tokenizers.function
assert label in tokenizer.interpro_labels or label in tokenizer.keyword_vocabulary
annotation = FunctionAnnotation(label=label, start=1, end=150)
prompt = ESMProtein(sequence="_" * 150, function_annotations=[annotation])
result = model.generate(prompt, GenerationConfig(track="sequence", num_steps=20))

Function-track predictions are annotation hypotheses. Low temperature is not calibrated confidence. Confirm with curated evidence and task-specific assays; function conditioning alone cannot guarantee fluorescence or enzyme activity.

Raw lines 84 to 110
111## Multitrack designs
113A useful sequence is: complete masked sequence -> predict structure -> optionally
114remask selected sequence positions while retaining chosen structural conditions
115-> create a fresh sequence-only prompt for structural checking. Explicitly clear
116`coordinates` before predicting a new structure on an existing protein object.
117Keep the initial prompt, each generated candidate and the exact mutations.
118Avoid splitting long proteins into arbitrary independent chunks and claiming a
119coherent full-length fold.
121Sources: [ESM3 README](https://github.com/Biohub/esm/blob/main/_assets/ESM3_README.md),
122[SDK types](https://github.com/Biohub/esm/blob/main/esm/sdk/api.py),
123[generation](https://github.com/Biohub/esm/blob/main/esm/utils/generation.py),
124[annotation coordinates](https://github.com/Biohub/esm/blob/main/esm/utils/types.py),
125[function tokenizer](https://github.com/Biohub/esm/blob/main/esm/tokenization/function_tokenizer.py).

Multitrack designs

A useful sequence is: complete masked sequence -> predict structure -> optionally remask selected sequence positions while retaining chosen structural conditions -> create a fresh sequence-only prompt for structural checking. Explicitly clear coordinates before predicting a new structure on an existing protein object. Keep the initial prompt, each generated candidate and the exact mutations. Avoid splitting long proteins into arbitrary independent chunks and claiming a coherent full-length fold.

Sources: ESM3 README, SDK types, generation, annotation coordinates, function tokenizer.

Raw lines 111 to 125