openprotein.molecules
SDK release/v0.18.0These data primitives represent a unified interface to working with our platform, whether it be structure prediction, binder design or inverse folding.
Protein is a fundamental primitive for working with proteins on the platform. These can be uploaded to our platform as a Query to be used with models like ProteinMPNN or ESMIF1 (e.g. for inverse-folding), as well as for ease of reuse. Construct a chain with Protein(sequence) and attach an MSA or templates with its properties or setters before folding. Use the mask methods to describe masked sequence or structure positions.
23source
Represents a protein with an optional name.
This class supports partial or complete information: users may create a Protein with only a sequence, only a structure, or both. The class ensures that all provided fields have consistent residue-level lengths and provides convenient methods for indexing, masking, and structural comparisons.
- Missing or unknown residues in the sequence are denoted by b"X".
- Missing structural data (coordinates or pLDDT) are represented by NaN.
- Residue indices are 1-indexed for user-facing methods suffixed with
atE.g..at,mask_sequence_at
Create a Protein from sequence only: Protein(sequence="ACDEFGHIK")
Create a Protein from sequence and name: Protein(sequence="ACDEFGHIK", name="my_protein")
sequencebytes | strnamebytes | str | None= Nonepropertysequence:bytessource
propertycoordinates:npt.NDArray[np.float32]source
propertyplddt:npt.NDArray[np.float32]source
propertycyclic:boolsource
classsingle_sequence_modesource
propertymsa:str | MSAFuture | MSA | None | Type[NullMSA]source
A reference identifier to the MSA associated to this protein.
propertytemplates:Sequence[Protein | Complex | Template]source
A list of templates for guiding the structure prediction of this protein.
methodat(positions)→Proteinsource
Return a new Protein object containing residues at given 1-indexed positions.
positionsSequence[int] | npt.NDArray[np.integer]methodmask_sequence_at(positions)→Proteinsource
Mask sequence at given 1-indexed positions.
positionsSequence[int] | npt.NDArray[np.integer]methodmask_sequence_except_at(positions)→Proteinsource
Mask sequence at all positions except the given 1-indexed positions.
positionsSequence[int] | npt.NDArray[np.integer]methodmask_structure(side_chain_only=False)→Proteinsource
Mask entire structure.
side_chain_onlybool= Falsemethodmask_structure_at(positions, side_chain_only=False)→Proteinsource
Mask structure at given 1-indexed positions.
positionsSequence[int] | npt.NDArray[np.integer]side_chain_onlybool= Falsemethodmask_structure_except_at(positions, side_chain_only=False)→Proteinsource
Mask structure at all positions except the given 1-indexed positions.
positionsSequence[int] | npt.NDArray[np.integer]side_chain_onlybool= Falsemethodget_structure_mask()→npt.NDArray[np.bool_]source
Computes the structure mask of the protein. The structure mask is a boolean array indicating, at each position, whether the structure is undefined at that position.
propertyhas_structure:boolsource
Whether or not the structure is known at any position in the protein.
methodrmsd(tgt, backbone_only=False, return_transform=False)→float | tuple[float, npt.NDArray[np.floating], npt.NDArray[np.floating]]source
Compute the root-mean-square deviation (RMSD) between this Protein and a target Protein.
Only atoms that are present (i.e., not NaN) in both structures are included in the calculation.
tgtProteinThe target Protein to compare against.
backbone_onlybool | str | Sequence[str]= FalseSpecifies which atoms to include in the RMSD calculation.
- If False (default), all atom types are included.
- If True, only backbone atoms ("N", "CA", "C") are included.
- If a string, it must be a single atom type (e.g., "CA").
- If a sequence of strings, it must be a non-empty list of atom types (e.g., ["CA", "CB", "O"]). All specified atom types must be valid.
return_transformbool= FalseIf True, returns both the rmsd and the transformation that
should be applied to tgt to superimpose it onto this Protein. If False
(default), returns only the rmsd value.
The RMSD value (float) if return_transform is False (default).
If return_transform is True, a tuple
(float, np.ndarray, np.ndarray) containing the RMSD value, the
rotation matrix, and the translation vector.
This method assumes that sequences of self and tgt are already aligned.
methodto_string(format='cif')→strsource
Serialize this Protein to a string. Note that format="pdb" may not serialize all aspects of this object, so format="cif", the default, is preferred.
formatLiteral['cif', 'pdb']= 'cif'methodfrom_expr(expr, name=None)→Proteinsource
Create a Protein from a sequence expression.
A sequence expression allows you to define protein sequences using a concise notation that mixes fixed sequences, design regions, and length ranges.
Useful for creating a design Query.
exprstr | intSequence expression string or integer
- Fixed sequences: "ACGT" (literal amino acids)
- Design regions: "6" or 6 (any 6 amino acids)
- Length ranges: "3..5" (between 3-5 amino acids)
- Combined: "AAAA6C3..5" (AAAA + 6 design + C + 3-5 design)
namestr | None= NoneOptional name for the protein
Protein object with the parsed sequence
# Fixed sequence with 6 flexible positions and fixed end
Protein.from_expr("MKLL6VVAA").sequence
b'MKLLXXXXXXVVAA'# Design region of any 15 amino acids
Protein.from_expr(15).sequence
b'XXXXXXXXXXXXXXX'# Variable length region between 10-20 residues
Protein.from_expr("10..20").sequence
b'XXXXXXXXXX??????????'methodfrom_filepath(path, chain_id, use_bfactor_as_plddt=None, model_idx=0, verbose=True)→Proteinsource
Create a Protein from a structure file.
If the structure file has multiple conformers, the first conformer is always used.
pathPath | strpath to structure file (e.g. pdb or cif file)
chain_idstrid of the chain in the structure file to use
use_bfactor_as_plddtbool | None= Nonewhether or not to use bfactors as pLDDTs. If None, this parameter will be determined based on heuristics. These heuristics may change over time.
model_idxint= 0index of the model in the structure file to use
verbosebool= Truewhether or not to print debugging information such as oddities in the structure e.g. missing atoms
methodformatted(include=('sequence',), width=60, value_maps=None)→strsource
Format the sequence and/or additional feature tracks aligned and wrapped to a specific width.
includeSequence[Literal['sequence', 'structure_mask', 'binding', 'group']]= ('sequence',)widthint= 60value_mapsdict[str, dict[Any, str]] | None= NoneComplex describes a molecular complex representation. These can be uploaded to our platform as a Query to be used with models like RFdiffusion, (e.g. for multi-chain binder design) as well as for easy reuse. Inspect chains with get_chains() or get_chain() and build or update them with insert_chain() and set_chain().
Construct a complex from chain IDs and molecule objects:
from openprotein.molecules import Complex, Ligand, Protein
complex = Complex({"A": Protein("ACDEFGHIK"), "B": Ligand(ccd="ATP")})
proteins = complex.get_proteins()15source
Bases: MutableMapping
propertyname:str | Nonesource
propertytemplates:Sequence[Protein | Complex | Template]source
A list of templates for guiding the structure prediction of this molecular complex.
methodget_chain_ids()source
Returns the Chain IDs in this Complex
methodget_chains()→Mapping[str, Protein | DNA | RNA | Ligand]source
Get all chains as a {chain_id: chain} mapping
methodget_chain(chain_id)source
Get the chain for this chain_id
chain_idstrmethodremove_chain(chain_id)source
Remove a chain from this complex
chain_idstrmethodinsert_chain(chain)source
methodupdate(**kwargs)source
Add a collection of chains to this complex
methodclear()source
Remove all chains and templates from this complex
methodrmsd(tgt, backbone_only=False, return_transform=False)→float | tuple[float, npt.NDArray[np.floating], npt.NDArray[np.floating]]source
methodto_string(format='cif')→strsource
Serialize this Complex to a string. Note that format="pdb" may not serialize all aspects of this object, so format="cif", the default, is preferred.
formatLiteral['cif', 'pdb']= 'cif'Structure describes a collection of Complex instances. These are typically created when parsing structure files (e.g., CIF, PDB) that contain multiple models of the same molecular complex, such as NMR ensembles or computational predictions with multiple conformations.
6source
Represents a collection of Complex instances.
complexesSequence[Complex]namebytes | str | None= Nonepropertyname:str | Nonesource
methodto_string(format='cif')→strsource
Serialize this Structure to a string. Note that format="pdb" may not serialize all aspects of this object, so format="cif", the default, is preferred.
formatLiteral['cif', 'pdb']= 'cif'methodfrom_filepath(path, use_bfactor_as_plddt=None, verbose=True)→Structuresource
pathPath | struse_bfactor_as_plddtbool | None= Noneverbosebool= Truemethodfrom_string(filestring, format, use_bfactor_as_plddt=None, verbose=True)→Structuresource
filestringbytes | strformatLiteral['pdb', 'cif']use_bfactor_as_plddtbool | None= Noneverbosebool= Truemethodfrom_pdb_id(pdb_id, verbose=True)→Structuresource
Creates a Structure instance by downloading data from the RCSB PDB.
This method performs an HTTP GET request to the RCSB web server to fetch the structure file (in CIF format) associated with the given PDB ID.
pdb_idstrThe 4-character PDB identifier (e.g. "1XYZ").
verbosebool= TrueWhether to print warnings to stdout. Defaults to True.
StructureStructureA new instance containing the parsed structure data.
If the PDB ID is invalid, the server is unreachable, or the request returns a 404/500 status code.
Ligand represents a ligand that can be described either by smiles or ccd. These are intended to be used as part of a Complex.
Provide exactly one of ccd or smiles; providing both or neither raises ValueError.
2source
Represents a ligand with optional Chemical Component Dictionary (CCD) identifier and SMILES string.
Requires either a CCD identifier or SMILES string.
ccdstr | None= Nonesmilesstr | None= NoneTemplate describes a template that can be used for constraining fold jobs.
5source
A structural template used to guide the folding of a target chain or complex.
This class wraps a structural source (Protein or Complex) and defines how it should map to the target(s).
templateTemplateSourcemappingChainMapping= NoneindexSequence[int] | None= Noneindex_intervalsSequence[tuple[int, int]] | None= Noneattributetemplate:TemplateSourcesource
The structural object to be used as a template. Must contain structural data (coordinates).
attributemapping:ChainMapping= Nonesource
The rule for assigning this template to the target.
- Mapping[str, str]: Explicitly maps {template_chain_id: target_chain_id}.
- str: Apply this template to a specific target_chain_id. (If template is a Complex, a selection algorithm is used to pick the best source chain).
- None: Automatic assignment. The folding algorithm will determine which chain(s) this template applies to.
attributeindex:Sequence[int] | None= Nonesource
Restrict this template to specific sequence
positions in the batched fold job. The default (None) applies the
template to every sequence. Populate to scope a template to a subset,
e.g. in a binder-design refold where structure M[k] templates only
sequences [k*N, k*N+N).
attributeindex_intervals:Sequence[tuple[int, int]] | None= Nonesource
Range-form alternative
to index for scoping the template to contiguous spans of sequence
positions. Each tuple is a half-open [start, end) range. Useful
when the subset is large and contiguous (e.g. [(0, 1000)] instead
of list(range(1000))). May be combined with index; the two are
unioned.
methodvalidate_for_target(target)→Nonesource
Ensures this Template is compatible with a specific target Molecule.
targetTargetMoleculeThe Protein or Complex that is being folded.
If this Template is invalid, or if chain IDs referenced in mapping do not exist in the target.
If the template/target combination is structurally incompatible.