Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.20.0"
".": "0.20.1"
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 0.20.1 (2026-12-01)


### Features

* **models:** sample structure ensembles with bioemu2

## 0.20.0 (2026-12-01)


Expand Down
4 changes: 4 additions & 0 deletions openprotein/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
AlphaFlow,
AlphaFlowInput,
BioEmu,
BioEmu2,
BioEmu2Input,
BioEmuInput,
ESMFlow,
ESMFlowInput,
Expand Down Expand Up @@ -87,6 +89,8 @@
"AlphaFlowInput",
"AlphaFold2",
"BioEmu",
"BioEmu2",
"BioEmu2Input",
"BioEmuInput",
"Boltz1",
"Boltz1x",
Expand Down
3 changes: 3 additions & 0 deletions openprotein/models/ensemble/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
from .alphaflow import AlphaFlow, AlphaFlowInput
from .base import StructureEnsemblePredictionModel
from .bioemu import BioEmu, BioEmuInput
from .bioemu2 import BioEmu2, BioEmu2Input
from .esmflow import ESMFlow, ESMFlowInput
from .gibbs import Gibbs, GibbsInput

__all__ = [
"AlphaFlow",
"AlphaFlowInput",
"BioEmu",
"BioEmu2",
"BioEmu2Input",
"BioEmuInput",
"ESMFlow",
"ESMFlowInput",
Expand Down
125 changes: 125 additions & 0 deletions openprotein/models/ensemble/bioemu2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
"""BioEmu2."""

from collections.abc import Sequence
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Literal

from openprotein.jobs import futures

from . import _inputs
from .base import StructureEnsemblePredictionModel

if TYPE_CHECKING:
from openprotein.align import MSAFuture
from openprotein.data.msa import MSA
from openprotein.molecules import Protein

__all__ = ["BioEmu2", "BioEmu2Input"]


@dataclass(frozen=True)
class BioEmu2Input:
"""One BioEmu2 ensemble: a protein chain and, optionally, its MSA.

Attributes
----------
sequence : Protein, str or bytes
The protein chain to sample.
msa : str, MSAFuture, MSA or None
An MSA whose query is ``sequence``. ``None`` or
``Protein.single_sequence_mode`` samples from the sequence alone.
"""

sequence: "Protein | str | bytes"
msa: "str | MSAFuture | MSA | type[Protein.NullMSA] | None"


class BioEmu2(StructureEnsemblePredictionModel):
"""BioEmu2 samples protein ensembles from a sequence and, optionally, its MSA.

Its checkpoint is ``bioemu2``.
"""

Input = BioEmu2Input
_default_id = "bioemu2"

def sample(
self,
inputs: Sequence[BioEmu2Input],
n_samples: int = 1,
mode: Literal["structure", "equilibrium"] = "equilibrium",
num_steps: int = 200,
step_scale: float | None = None,
constraints: list[dict[str, Any]] | None = None,
allow_msa_seed_mismatch: bool = False,
random_seed: int | None = None,
) -> futures.StructurePredictionFuture:
"""Sample one ensemble per input.

Parameters
----------
inputs : sequence of BioEmu2Input
One entry per ensemble.
n_samples : int
Conformations to sample per input.
mode : {"equilibrium", "structure"}
``equilibrium`` samples the approximate equilibrium ensemble;
``structure`` predicts a single folded structure.
num_steps : int
Denoising steps per sample, at least 2.
step_scale : float or None
Diffusion step scale. ``None`` uses the mode's default, 1.0 for
``equilibrium`` and 1.5 for ``structure``.
constraints : list of dict or None
Contacts and bonds in Boltz's shapes, such as
``{"contact": {"token1": ["A", 10], "token2": ["A", 42]}}``. Each
applies to every input, so every input's chain ``A`` must have the
residues and atoms it names.
allow_msa_seed_mismatch : bool
Sample a sequence against an MSA whose query has the same length
but differs, such as a point mutant against its wild-type MSA.
random_seed : int or None
Random seed. ``None`` lets the model pick its own, so every call
is a fresh sample.

Returns
-------
StructurePredictionFuture
One ensemble per input, in input order.

Examples
--------
One protein with its MSA:

>>> bioemu2 = session.models.bioemu2
>>> future = bioemu2.sample(
... [bioemu2.Input(sequence=sequence, msa=msa)],
... n_samples=10,
... )
>>> ensembles = future.get()

Several proteins without an MSA:

>>> future = bioemu2.sample(
... [bioemu2.Input(sequence=s, msa=None) for s in sequences],
... n_samples=10,
... )
"""
complexes = [
_inputs.protein_complex(
_inputs.sequence_text(entry.sequence, f"inputs[{i}].sequence"),
_inputs.msa_id(entry.msa, f"inputs[{i}].msa", required=False),
takes_msa=True,
)
for i, entry in enumerate(_inputs.input_list(inputs, BioEmu2Input))
]
return self._sample(
complexes=complexes,
n_samples=n_samples,
mode=mode,
num_steps=num_steps,
step_scale=step_scale,
constraints=constraints,
allow_msa_seed_mismatch=allow_msa_seed_mismatch,
random_seed=random_seed,
)
7 changes: 6 additions & 1 deletion openprotein/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from openprotein.errors import HTTPError

from . import _api, estimators, gp, svd, umap
from .ensemble import AlphaFlow, BioEmu, ESMFlow, Gibbs
from .ensemble import AlphaFlow, BioEmu, BioEmu2, ESMFlow, Gibbs
from .fold import (
AlphaFold2,
Boltz1,
Expand Down Expand Up @@ -365,6 +365,11 @@ def bioemu(self) -> BioEmu:
"""``bioemu-v1-1``."""
return self.bioemu_v1_1

@property
def bioemu2(self) -> BioEmu2:
"""``bioemu2``."""
return self._handle("bioemu2", BioEmu2)

@property
def alphaflow_md_base_v1(self) -> AlphaFlow:
"""``alphaflow-md-base-v1``."""
Expand Down
16 changes: 16 additions & 0 deletions tests/data/ensemble_cards.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,21 @@
"variant": null,
"base": true,
"max_sequence_length": 1500
},
"bioemu2": {
"input_types": [
"protein",
"dna",
"rna",
"ligand"
],
"multichain": true,
"tags": [
"structure",
"fold"
],
"variant": null,
"base": true,
"max_sequence_length": 1024
}
}
Loading
Loading