Skip to main content

Overview

The template processing module searches for and featurises structural templates from the Protein Data Bank. Templates provide structural constraints that guide AlphaFold 3’s predictions, especially for proteins with known homologous structures.

Classes

Hit

Represents a single template hit from structure database search.
str
required
PDB ID of the hit (lowercase).
str
required
Author chain ID from the PDB structure.
str
required
Hit sequence as returned by hmmsearch in A3M format (may contain gaps and lowercase insertions).
str
required
Full sequence from the PDB structure.
Sequence[int] | None
required
0-based indices of unresolved residues in the structure. None if structure is unavailable.
str
required
The query sequence used for template search.
int
required
Start index of alignment relative to full PDB seqres sequence (0-based, inclusive).
int
required
End index of alignment relative to full PDB seqres sequence (0-based, exclusive).
int
required
Length of the full PDB seqres sequence.
datetime.date
required
Release date of the PDB structure.
str
required
Polymer type (PROTEIN_CHAIN, RNA_CHAIN, or DNA_CHAIN).
Properties:
Mapping[int, int]
0-based query index to hit structure index mapping. Handles realignment when seqres doesn’t match structure sequence.
str
Hit sequence with deletions uppercased and gaps removed.
str
Final template sequence aligned to query (gaps represented as ’-’).
float
Ratio of hit sequence length to query length.
float
Ratio of aligned residues to query length.
bool
Whether hit can be used as template (has resolved residues at alignment positions).
str
Full template name in format {pdb_id}_{auth_chain_id}.

Methods

keep
Determine if hit should be kept based on filtering criteria.
datetime.date | None
Maximum release date for templates. Hits with later dates are excluded.
float | None
Maximum length ratio for exact subsequences. Excludes hits that are exact subsequences of query and exceed this ratio (prevents ground truth leakage).
int | None
Minimum residue count. Excludes shorter hits.
float | None
Minimum ratio of aligned residues to query length. Excludes hits with fewer alignments.
bool
True if hit passes all filters and has resolved residues, False otherwise.
Example:

Templates

Container for template hits with featurisation and filtering capabilities.
str
required
The query sequence for which templates were found.
Sequence[Hit]
required
Template hits found for the query.
datetime.date
required
Maximum template date for filtering (prevents test set leakage).
structure_stores.StructureStore
required
Structure store for fetching template structures.
datetime.date | None
Release date of query structure. Used to ensure templates don’t leak future structural information.
Properties:
str
The query sequence.
tuple[Hit, ...]
Template hits (immutable).
int
Number of template hits.
datetime.date | None
Query release date if provided.
datetime.date
Effective release date cutoff (minimum of max_template_date and query_release_date minus 60 days).
Iterator[structure.Structure]
Iterator over unique template structures. Yields one Structure per unique PDB ID.

Class Methods

from_seq_and_a3m
Create templates by running hmmsearch against a custom MSA.
str
required
Target polymer sequence.
str
required
MSA in A3M format used to create HMM profile for hmmsearch.
datetime.date
required
Maximum template release date (for training, prevents ground truth leakage).
os.PathLike[str] | str
required
Path to sequence database to search for templates.
msa_config.HmmsearchConfig
required
Hmmsearch configuration.
int | None
required
Maximum MSA sequences to use for profile construction.
structure_stores.StructureStore
required
Structure store to fetch template structures.
msa_config.TemplateFilterConfig | None
Optional filtering configuration. More performant than constructing all templates then filtering.
datetime.date | None
Query release date for temporal filtering.
str
default:"mmcif_names.PROTEIN_CHAIN"
Polymer type of templates.
Templates
Templates object with hits initialized from structure store metadata and alignments.
Example:
from_hmmsearch_a3m
Create templates from hmmsearch results in A3M format.
str
required
Target polymer sequence.
str
required
Hmmsearch results in A3M format containing template alignments and PDB codes.
datetime.date
required
Maximum template release date.
structure_stores.StructureStore
required
Structure store to fetch templates.
msa_config.TemplateFilterConfig | None
Optional filtering configuration.
datetime.date | None
Query release date.
str
default:"mmcif_names.PROTEIN_CHAIN"
Polymer type.
Templates
Templates object with hits from A3M.
Example:

Instance Methods

filter
Return new Templates object with filtered hits.
float | None
Exclude hits that are exact subsequences of query exceeding this ratio.
float | None
Exclude hits where aligned residues are less than this proportion of query length.
int | None
Exclude hits with fewer residues than this.
bool
required
Whether to exclude duplicate template sequences (keeps first occurrence).
int | None
Maximum number of hits to keep.
Templates
New Templates object with filtered hits.
Example:
get_hits_with_structures
Get hits paired with their filtered Structure objects.
Sequence[tuple[Hit, structure.Structure]]
List of (Hit, Structure) tuples. Each Structure is filtered to the hit’s chain.
Raises:
  • InvalidTemplateError: If hits haven’t been filtered before calling (contains invalid hits)
Example:
featurize
Featurise templates for model input.
bool
default:"True"
Whether to compute ligand features from template structures.
TemplateFeatures
Dictionary mapping feature names to values:
  • template_aatype: Encoded residue types (int32 array)
  • template_all_atom_masks: Atom presence masks (float64 array)
  • template_all_atom_positions: Atom coordinates (float64 array)
  • template_domain_names: Template names (bytes objects)
  • template_release_date: Release dates (bytes objects)
  • template_sequence: Template sequences (bytes objects)
  • ligand_features: (if include_ligand_features=True) Nested dict of ligand features per chain
Raises:
  • InvalidTemplateError: If hits haven’t been filtered before featurization
Example:

Functions

run_hmmsearch_with_a3m

Run hmmsearch to find template hits using an MSA.
os.PathLike[str] | str
required
Path to sequence database (e.g., PDB seqres).
msa_config.HmmsearchConfig
required
Hmmsearch configuration.
int | None
required
Maximum MSA sequences to use for HMM profile construction. None uses all sequences.
str | None
required
MSA in A3M format. Used to build HMM profile.
str
Hmmsearch results in A3M format.
Example:

get_polymer_features

Extract polymer features from a template structure chain.
structure.Structure
required
Structure object filtered to a single polymer chain.
str
required
Polymer type (PROTEIN_CHAIN, RNA_CHAIN, or DNA_CHAIN).
int
required
Length of the query sequence.
Mapping[int, int]
required
0-based query index to hit index mapping.
Mapping[str, Any]
Dictionary with polymer features:
  • template_all_atom_positions: Atom coordinates aligned to query
  • template_all_atom_masks: Atom presence masks
  • template_sequence: Template sequence as bytes
  • template_aatype: Encoded residue types
  • template_domain_names: Template name as bytes
  • template_release_date: Release date as bytes
Raises:
  • ValueError: If structure doesn’t have a name, lacks release date, or contains multiple chains
Example:

package_template_features

Stack and package features from multiple template hits.
Sequence[Mapping[str, Any]]
required
List of feature dictionaries, one per hit.
bool
required
Whether to include ligand features in output.
Mapping[str, Any]
Dictionary with stacked polymer features and unstacked ligand features (if included).

Template Search Workflow

Complete workflow for finding and using templates:

Error Handling