molforge.wrappers.folding¶
folding ¶
Folding-engine wrappers.
Concrete engines
- :class:
ESMFold— implemented (single-sequence transformer; fast) - :class:
AlphaFold— implemented (MSA-based via ColabFold) - :class:
Boltz— implemented (Boltz-1 / Boltz-2 via subprocess; AlphaFold-3-style multi-component prediction) - :class:
Chai1— implemented (Chai-1 via Python API; AlphaFold-3- style multi-component prediction; natural cross-check for Boltz) - :class:
RoseTTAFold— implemented (RoseTTAFold All-Atom; subprocess)
All engines write per-residue confidence to
protein.metadata["confidence_per_residue"] so downstream code can
read confidence uniformly regardless of which engine produced the
structure.
FoldingEngine ¶
Bases: ABC
Abstract base for sequence-to-structure prediction engines.
Subclasses must implement :meth:predict. The default implementation
of :meth:predict_many is a simple loop; engines that support
batching (most do) should override it for efficiency.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Human-readable engine name (set by subclasses). |
predict
abstractmethod
¶
Predict a single structure from a sequence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequence
|
str
|
One-letter amino-acid sequence. Whitespace is
stripped; non-letter characters raise :class: |
required |
**kwargs
|
object
|
Per-call options, if the engine has any.
Engines reject keywords they don't consume rather than
silently dropping them — see :func: |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
Protein
|
class: |
Protein
|
at minimum |
|
Protein
|
produces one, |
predict_many ¶
Predict structures for a batch of sequences.
The default implementation is a serial loop. Engines with batch APIs (almost all of them) should override this.
FoldingEngineNotInstalledError ¶
Bases: ImportError
Raised when a folding engine's heavy dependencies aren't installed.
The message points at the relevant pip install extras so users
can fix it without grepping the docs.
AlphaFold ¶
AlphaFold(
*,
mode: Literal["local", "server"] = "local",
num_models: int = 5,
num_recycles: int = 3,
msa_mode: str = "mmseqs2_uniref_env",
device: str | None = None,
model_type: str = "AlphaFold2-ptm",
)
Bases: FoldingEngine
Wrapper around AlphaFold via ColabFold's Python API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
Literal['local', 'server']
|
|
'local'
|
num_models
|
int
|
How many of the 5 AlphaFold models to run. Default 5 (full ensemble). Set to 1 for faster preview predictions; the AlphaFold paper showed that the top-1-of-5 best model captures most of the accuracy. |
5
|
num_recycles
|
int
|
AlphaFold recycling iterations. Default 3 matches the original paper. More = slower but slightly better; useful for low-confidence regions. |
3
|
msa_mode
|
str
|
ColabFold MSA pipeline. |
'mmseqs2_uniref_env'
|
device
|
str | None
|
|
None
|
model_type
|
str
|
|
'AlphaFold2-ptm'
|
Example
from molforge.wrappers.folding import AlphaFold engine = AlphaFold(num_models=1, num_recycles=3) # fastest preview protein = engine.predict("MKTVRQERLKSIVRILERSK") protein.metadata["mean_confidence"] 87.2
predict ¶
Fold a single sequence into a :class:Protein.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequence
|
str
|
One-letter amino-acid sequence. |
required |
**kwargs
|
object
|
None accepted. AlphaFold's options are set on
the constructor; any keyword passed here raises
:class: |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
Protein
|
class: |
Protein
|
|
|
Protein
|
|
|
Protein
|
|
|
Protein
|
|
|
Protein
|
|
|
Protein
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If any keyword argument is passed. |
Boltz ¶
Boltz(
*,
model_version: Literal["boltz1", "boltz2"] = "boltz2",
use_msa_server: bool = True,
msa_depth: int | None = None,
templates: TemplatePolicy | str | None = None,
recycling_steps: int | None = None,
diffusion_samples: int | None = None,
sampling_steps: int | None = None,
seed: int | None = None,
device: str | None = None,
executable: str | None = None,
cache_dir: str | None = None,
)
Bases: FoldingEngine
Wrapper around the Boltz biomolecular prediction model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_version
|
Literal['boltz1', 'boltz2']
|
|
'boltz2'
|
use_msa_server
|
bool
|
If |
True
|
msa_depth
|
int | None
|
Cap the number of MSA sequences the model may use, as
|
None
|
templates
|
TemplatePolicy | str | None
|
A :class: |
None
|
recycling_steps
|
int | None
|
How many trunk-recycling rounds Boltz runs.
Default |
None
|
diffusion_samples
|
int | None
|
Number of diffusion samples drawn per
prediction. Default |
None
|
sampling_steps
|
int | None
|
Number of diffusion sampling steps. Default
|
None
|
seed
|
int | None
|
Seed for Boltz's random number generator, passed through as
|
None
|
device
|
str | None
|
Which device to use. Default |
None
|
executable
|
str | None
|
Path to the |
None
|
cache_dir
|
str | None
|
Where Boltz looks for / downloads its weights.
|
None
|
Example
from molforge.wrappers.folding import Boltz engine = Boltz(model_version="boltz2", use_msa_server=True) protein = engine.predict("MKTVRQERLKSIVRILERSK") protein.metadata["mean_confidence"] 87.3 protein.metadata["ptm"] 0.84
predict ¶
Fold a single sequence into a :class:Protein via the boltz CLI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequence
|
str
|
One-letter amino-acid sequence. |
required |
**kwargs
|
object
|
Per-call options. Only |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
Protein
|
class: |
Protein
|
|
|
Protein
|
|
|
Protein
|
|
|
Protein
|
|
|
Protein
|
|
|
Protein
|
|
|
Protein
|
|
|
Protein
|
|
Raises:
| Type | Description |
|---|---|
FoldingEngineNotInstalledError
|
If the |
RuntimeError
|
If the CLI runs but produces no output, or its output can't be parsed. |
TypeError
|
If an unsupported keyword argument is passed. |
predict_complex ¶
Fold a multi-component complex via the boltz CLI.
This is the headline AlphaFold-3-style capability: predict
the structure of multiple protein chains, DNA/RNA, and/or
small-molecule ligands in a single forward pass. See
:class:molforge.folding.ComplexSpec for input shape and
examples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
ComplexSpec
|
A :class: |
required |
**kwargs
|
object
|
Per-call options. Only |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
Protein
|
class: |
Protein
|
metadata as documented in :meth: |
|
Protein
|
|
|
Protein
|
|
Raises:
| Type | Description |
|---|---|
FoldingEngineNotInstalledError
|
If the |
RuntimeError
|
If the CLI runs but produces no parseable output. |
TypeError
|
If an unsupported keyword argument is passed. |
Examples:
Protein-ligand complex::
from molforge.folding import ComplexSpec
from molforge.wrappers.folding import Boltz
spec = ComplexSpec.protein_ligand(
protein_sequence="MVTPEG...",
ligand_smiles="CC(=O)OC1=CC=CC=C1C(=O)O",
)
complex_struct = Boltz().predict_complex(spec)
# complex_struct.atom_array has chain A (protein) and
# chain B (ligand atoms).
predict_affinity ¶
Predict a protein-ligand complex and its binding affinity (Boltz-2).
Boltz-2's headline capability: alongside the folded complex, it
predicts how tightly the ligand binds. This method folds spec
with an affinity property on the ligand and surfaces the result
in the returned structure's metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
ComplexSpec
|
A :class: |
required |
**kwargs
|
object
|
Per-call options. Only |
{}
|
Returns:
| Type | Description |
|---|---|
Protein
|
The folded complex as a :class: |
Protein
|
on top of the usual confidence keys: |
Protein
|
|
Protein
|
|
Protein
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If this engine wasn't constructed with
|
TypeError
|
If an unsupported keyword argument is passed. |
Chai1 ¶
Chai1(
*,
device: str | None = None,
use_msa_server: bool = False,
msa_server_url: str | None = None,
msa_depth: int | None = None,
templates: TemplatePolicy | str | None = None,
num_trunk_recycles: int | None = None,
num_diffn_timesteps: int | None = None,
seed: int | None = None,
cache_dir: str | None = None,
)
Bases: FoldingEngine
Wrapper around the Chai-1 biomolecular prediction model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
str | None
|
Torch device string ( |
None
|
use_msa_server
|
bool
|
If |
False
|
msa_server_url
|
str | None
|
Override the MSA server URL. Only used when
|
None
|
msa_depth
|
int | None
|
Cap the number of MSA sequences the model may use,
passed to Chai-1 as Note the engines differ in where the cap bites: Chai-1
subsamples during trunk recycling, leaving the first trunk
pass with the full alignment, whereas Boltz's
|
None
|
templates
|
TemplatePolicy | str | None
|
A :class: |
None
|
num_trunk_recycles
|
int | None
|
Trunk-recycling rounds. |
None
|
num_diffn_timesteps
|
int | None
|
Diffusion denoising steps. |
None
|
seed
|
int | None
|
PyTorch random seed for reproducibility. |
None
|
cache_dir
|
str | None
|
Override the Chai-lab weights cache directory by
setting the |
None
|
predict ¶
Fold a single sequence into a :class:Protein via Chai-1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequence
|
str
|
One-letter amino-acid sequence. |
required |
**kwargs
|
object
|
None accepted. Chai-1's options — including
|
{}
|
Returns:
| Type | Description |
|---|---|
Protein
|
The best of Chai-1's 5 diffusion samples (by |
Protein
|
|
Protein
|
|
Protein
|
|
Protein
|
|
Protein
|
|
Protein
|
|
Protein
|
|
Protein
|
|
Protein
|
|
Protein
|
|
Raises:
| Type | Description |
|---|---|
FoldingEngineNotInstalledError
|
If |
RuntimeError
|
If Chai-1 produces no parseable output. |
TypeError
|
If any keyword argument is passed. |
predict_complex ¶
Fold a multi-component complex via Chai-1.
The headline AlphaFold-3-style capability: predict the
structure of multiple protein chains, DNA/RNA, and/or
small-molecule ligands in a single forward pass. See
:class:molforge.folding.ComplexSpec for input shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
ComplexSpec
|
A :class: |
required |
**kwargs
|
object
|
None accepted. Chai-1's options — including
|
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
Protein
|
class: |
Protein
|
the metadata documented in :meth: |
|
Protein
|
|
|
Protein
|
|
|
Protein
|
|
|
Protein
|
Only the best-scoring of Chai-1's five diffusion samples; |
|
Protein
|
meth: |
Raises:
| Type | Description |
|---|---|
FoldingEngineNotInstalledError
|
If |
RuntimeError
|
If Chai-1 produces no parseable output. |
TypeError
|
If any keyword argument is passed. |
Examples:
Protein-ligand complex::
from molforge.folding import ComplexSpec
from molforge.wrappers.folding import Chai1
spec = ComplexSpec.protein_ligand(
protein_sequence="MVTPEG...",
ligand_smiles="CC(=O)OC1=CC=CC=C1C(=O)O",
)
complex_struct = Chai1().predict_complex(spec)
predict_samples ¶
Fold a sequence and return every diffusion sample, best first.
Chai-1 always computes five diffusion samples per call;
:meth:predict returns the highest-scoring one and drops the
other four structures. They cost nothing extra — the GPU time is
already spent — so for ensemble, occupancy, or pose-diversity
work this is five times the usable output per run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequence
|
str
|
One-letter amino-acid sequence. |
required |
Returns:
| Type | Description |
|---|---|
list[Protein]
|
The run's :class: |
list[Protein]
|
|
list[Protein]
|
is what :meth: |
list[Protein]
|
documented in :meth: |
list[Protein]
|
|
list[Protein]
|
|
Raises:
| Type | Description |
|---|---|
FoldingEngineNotInstalledError
|
If |
RuntimeError
|
If Chai-1 produces no parseable output. |
Examples:
A conformational ensemble from one call::
from molforge.wrappers.folding import Chai1
samples = Chai1().predict_samples("MVTPEG...")
len(samples) # 5
spread = [s.metadata["mean_confidence"] for s in samples]
predict_complex_samples ¶
Fold a complex and return every diffusion sample, best first.
The :meth:predict_complex counterpart of :meth:predict_samples.
For ligand work this is the interesting one: five poses per call
rather than one, at no extra inference cost.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
ComplexSpec
|
A :class: |
required |
Returns:
| Type | Description |
|---|---|
list[Protein]
|
The run's :class: |
list[Protein]
|
|
list[Protein]
|
|
list[Protein]
|
meth: |
list[Protein]
|
meth: |
list[Protein]
|
|
Raises:
| Type | Description |
|---|---|
FoldingEngineNotInstalledError
|
If |
RuntimeError
|
If Chai-1 produces no parseable output. |
Examples:
Five ligand poses from one call::
from molforge.folding import ComplexSpec
from molforge.wrappers.folding import Chai1
spec = ComplexSpec.protein_ligand(
protein_sequence="MVTPEG...",
ligand_smiles="CC(=O)OC1=CC=CC=C1C(=O)O",
)
poses = Chai1().predict_complex_samples(spec)
ESMFold ¶
ESMFold(
*,
model_name: str = "facebook/esmfold_v1",
device: str | None = None,
chunk_size: int | None = None,
dtype: str = "float32",
)
Bases: FoldingEngine
Wrapper around Meta AI's ESMFold (single-sequence transformer folder).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
HuggingFace model identifier. Defaults to
|
'facebook/esmfold_v1'
|
device
|
str | None
|
Where to run inference. |
None
|
chunk_size
|
int | None
|
Axial-attention chunk size (lower = less memory but
slower). |
None
|
dtype
|
str
|
|
'float32'
|
Example
from molforge.wrappers.folding import ESMFold engine = ESMFold(device="cuda") protein = engine.predict("MKTVRQERLKSIVRILERSKEPVSGAQLAEELSVS") protein.metadata["mean_confidence"] 82.4
predict ¶
Fold a single sequence into a :class:Protein.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequence
|
str
|
One-letter amino-acid sequence. |
required |
**kwargs
|
object
|
None accepted. ESMFold's options are set on the
constructor; any keyword passed here raises
:class: |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
Protein
|
class: |
Protein
|
structure, and: |
|
Protein
|
|
|
Protein
|
|
|
Protein
|
|
|
Protein
|
|
|
Protein
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If any keyword argument is passed. |
RoseTTAFold ¶
RoseTTAFold(
*,
repo_dir: str | None = None,
python_executable: str | None = None,
max_cycle: int | None = None,
job_name: str = "molforge_prediction",
extra_overrides: list[str] | None = None,
)
Bases: FoldingEngine
Wrapper around RoseTTAFold All-Atom (RFAA) for single-chain protein folding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_dir
|
str | None
|
Path to the cloned |
None
|
python_executable
|
str | None
|
Path to the Python interpreter that has the
RFAA environment activated. Default |
None
|
max_cycle
|
int | None
|
Hydra override for |
None
|
job_name
|
str
|
Name used for output files. Defaults to
|
'molforge_prediction'
|
extra_overrides
|
list[str] | None
|
Additional Hydra-style overrides (e.g.
|
None
|
Example
from molforge.wrappers.folding import RoseTTAFold engine = RoseTTAFold(repo_dir="/opt/RoseTTAFold-All-Atom", ... max_cycle=10) protein = engine.predict("MKTVRQERLKSIVRILERSK") protein.metadata["mean_confidence"] 82.4 protein.metadata["pae_inter"] # RFAA's headline confidence 4.8
predict ¶
Fold a single sequence into a :class:Protein via RFAA.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequence
|
str
|
One-letter amino-acid sequence. |
required |
**kwargs
|
object
|
None accepted. RFAA's options are set on the
constructor (including |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
Protein
|
class: |
Protein
|
|
|
Protein
|
|
|
Protein
|
|
|
Protein
|
|
|
Protein
|
|
|
Protein
|
|
|
Protein
|
|
|
Protein
|
|
|
Protein
|
|
Raises:
| Type | Description |
|---|---|
FoldingEngineNotInstalledError
|
If |
RuntimeError
|
If the CLI fails or produces no output. |
TypeError
|
If any keyword argument is passed. |