ProteinMotion
Reference navigation
On this page

Protein

A molecular structure with fixed atom identities, coordinates, and display settings.

python
from proteinmotion import Protein

Constructor

python
Protein(topology, xyz, *, trajectory=None)

Parameters

ParameterDefaultDescription
topologyRequiredAtom identities, residues, bonds, and chains in a Topology object.
xyzRequiredFinite coordinates with shape (atoms, 3), in ångströms.
trajectorykeyword onlyNoneTrajectory with the same atom identities and order; None uses the protein’s trajectory.

Notes

Use from_file() for PDB/mmCIF or from_trajectory() for coordinate ensembles. Distances and radii use ångströms; rotation angles use radians. Immediate setters return the protein for chaining.

Attributes

NameDescription
topologyAtoms, residues, covalent bonds, and chain segments.
trajectoryCoordinate states associated with this protein.
positionWorld translation as a 3-vector.
orientation3 × 3 rotation matrix.
sizePositive uniform scale factor.
opacityGlobal opacity in [0, 1].
trajectory_frameCurrent fractional trajectory state, updated by PlayTrajectory and restored by seeking.

Example and output

This excerpt runs inside a scene’s construct() method. The full example file includes imports, structure loading, and camera setup. Run it from a repository checkout.

Code Scene excerpt
python
p = ubiquitin().surface(resolution=0.7).cartoon()
frame(self, p)
self.wait(1)
for name in ("ribbon", "ball_and_stick", "surface"):
    self.play(Representation(p, name), run_time=1.2)
    self.play(Rotate(p, 0.45), run_time=1.5)
Output Preview · 9.1 s · 60 fps
Representation changes

Cartoon, ribbon, ball-and-stick, and SES surface.

Methods and properties

NameDescription
select()methodSelect atoms by author chain, residue number, and atom name.
build()class methodBuild an ideal peptide with every heavy atom from one-letter codes and torsion angles.
secondary_structurepropertyCurrent H/E/C state of each residue, as the cartoon draws it.
set_secondary_structure()methodSet one H/E/C state per residue for drawing; can change between animations.
assign_secondary_structure()methodAssign helix, strand and coil with DSSP from the current coordinates.
torsions()methodMeasure φ, ψ, ω and χ1–χ5 in degrees for all residues, or a selection.
set_torsions()methodSet torsions in degrees immediately, for every residue; see SetTorsions.
summary()methodDescribe available molecular selections.
set_style()methodApply a reusable molecular representation style.
reset_style()methodClear atom appearance overrides and reset cartoon thickness.
show_atoms()methodShow ball-and-stick detail over the active representation. Chained animations may also change color, opacity, or transforms.
hide_atoms()methodHide ball-and-stick detail while retaining the active representation.
label_residues()methodCreate labels for the selected residues. Extra options go to ResidueLabels.
hydrogen_bonds()methodCreate a hydrogen-bond analysis. Options go to HydrogenBonds.
electrostatics()methodCreate a screened Coulomb analysis. Options go to Electrostatics.
from_file()class methodLoad PDB or mmCIF coordinates and retain all models with matching atom identities.
fetch()class methodDownload a PDB entry or AlphaFold DB model once, keep it in the cache, and load it.
from_trajectory()class methodCreate a protein from the trajectory’s topology and first frame.
positionspropertyCurrent atom coordinates in the protein’s local coordinate frame.
atom_progresspropertyCurrent interpolation fraction for each atom.
atom_opacitiespropertyCurrent per-atom opacity, including global opacity and residue fades.
set_positions()methodReplace coordinates while preserving atom identities and topology.
copy()methodCopy the protein’s current state for independent animation; topology and trajectory are shared.
center()methodMove the molecular centroid to the world origin.
shift()methodTranslate the object by an offset.
rotate()methodRotate around the molecular centroid.
scale()methodScale around the molecular centroid.
set_opacity()methodSet or animate opacity in [0, 1].
set_color()methodApply a tint across all representations. None restores the base palette.
color_by()methodApply residue property colors and optional cartoon thickness before adding the protein to a scene.
color_residues()methodApply a tint to the selected residues in every representation.
set_residue_opacity()methodSet opacity on the selected residues.
surface()methodShow a van der Waals, solvent-accessible, or voxel solvent-excluded surface.
cartoon()methodShow protein secondary structure and nucleotide backbone tubes with selectable base shapes.
ribbon()methodShow a continuous backbone ribbon.
set_bases()methodSet nucleotide base shapes and optional dimensions before a scene begins. Use BaseStyle for an animated change.
ball_and_stick()methodShow atom spheres and covalent bond cylinders, with element colors by default.
with_secondary_structure()methodAssign helix, sheet, and coil labels before adding the protein to a scene.
animatepropertyCreate a builder for protein transforms, opacity, and color animation.
model_matrixpropertyCurrent 4 × 4 transform from local to world coordinates.
snapshot()methodCapture the current state for deterministic timeline evaluation.
restore()methodRestore a state produced by snapshot().
python
Protein.select(
    *,
    chain=None,
    residues=None,
    atoms=None,
    resname=None,
    ligands=False,
    ions=False,
    water=False,
    within=None,
    of=None,
    residue_range=None,
    element=None,
    secondary=None,
    polymer=None,
    icode=None,
    required=True,
    updating=False,
)

Select atoms by author chain, residue number, and atom name.

ParameterDefaultDescription
chainkeyword onlyNoneAuthor chain ID or a collection of IDs; None selects all chains.
residueskeyword onlyNoneAuthor residue number, inclusive (first, last) tuple, or list of individual numbers.
atomskeyword onlyNoneAtom name or list of names, such as "CA"; None selects all atom names.
resnamekeyword onlyNoneResidue name or names, such as "ASP" or ["HEM", "ATP"]; case-insensitive.
ligandskeyword onlyFalseSelect non-polymer residues other than water and single-atom ions.
ionskeyword onlyFalseSelect single-atom, non-carbon residues outside the traced chains, such as Ca²⁺ or Zn²⁺.
waterkeyword onlyFalseSelect water residues (HOH, WAT, SOL, and common MD names); load them with include_water=True.
withinkeyword onlyNoneDistance in ångströms; keeps whole residues with any atom this close to of.
ofkeyword onlyNoneRegion or Protein used as the reference for within; its own residues are excluded when it belongs to the same protein.
residue_rangekeyword onlyNoneInclusive author residue-number range, e.g. (23, 34); do not also pass residues.
elementkeyword onlyNoneElement symbol or collection of symbols, e.g. C or [N, O].
secondarykeyword onlyNoneSecondary-structure code or collection: H (helix), E (sheet), C (coil).
polymerkeyword onlyNoneTrue selects polymer atoms, False selects non-polymers, None does not filter.
icodekeyword onlyNoneAuthor insertion code or collection; an empty string selects no insertion code.
requiredkeyword onlyTrueRaise if nothing matches; False returns None for an optional static selection.
updatingkeyword onlyFalseRe-evaluate membership on access. False (default) freezes membership.

Returns: Region

A residue tuple is an inclusive range. A list selects individual numbers. Empty selections raise ValueError.

python
Protein.build(
    sequence,
    conformation='extended',
    *,
    phi=None,
    psi=None,
    omega=180.0,
    chain='A',
    first=1,
    hydrogens=False,
)

Build an ideal peptide with every heavy atom from one-letter codes and torsion angles.

ParameterDefaultDescription
sequenceRequiredOne-letter codes for the 20 standard amino acids, or a list of residue names.
conformation'extended'helix, alpha, 310, pi, strand, beta, parallel, antiparallel, ppii, extended, or left.
phikeyword onlyNoneφ in degrees, one value or one per residue; overrides the conformation.
psikeyword onlyNoneψ in degrees, one value or one per residue; overrides the conformation.
omegakeyword only180.0ω in degrees, one value or one per residue.
chainkeyword only'A'Chain ID.
firstkeyword only1Number of the first residue.
hydrogenskeyword onlyFalseAdd amide H atoms.

Returns: The scene.

python
Protein.secondary_structure

Current H/E/C state of each residue, as the cartoon draws it.

python
Protein.set_secondary_structure(assignments)

Set one H/E/C state per residue for drawing; can change between animations.

ParameterDefaultDescription
assignmentsRequiredOne H, E, or C per topology residue.
python
Protein.assign_secondary_structure()

Assign helix, strand and coil with DSSP from the current coordinates.

python
Protein.torsions(*, chain=None, residues=None)

Measure φ, ψ, ω and χ1–χ5 in degrees for all residues, or a selection.

ParameterDefaultDescription
chainkeyword onlyNoneAuthor chain ID or IDs; None selects all chains.
residueskeyword onlyNoneAuthor residue number, list, or inclusive (first, last) range.
python
Protein.set_torsions(*, conformation=None, anchor='center', secondary='auto', **angles)

Set torsions in degrees immediately, for every residue; see SetTorsions.

ParameterDefaultDescription
conformationkeyword onlyNoneSets φ and ψ together, as in SetTorsions.
anchorkeyword only'center'Part that stays still, as in SetTorsions.
secondarykeyword only'auto'"auto" updates the cartoon to the new DSSP states; "keep" leaves it unchanged.
**angles—phi, psi, omega, or chi1–chi5 in degrees, as in SetTorsions.
python
Protein.summary()

Describe available molecular selections.

python
Protein.set_style(style)

Apply a reusable molecular representation style.

ParameterDefaultDescription
styleRequiredHighlight shape or line style; allowed values are specified by the constructor.
python
Protein.reset_style()

Clear atom appearance overrides and reset cartoon thickness.

python
Protein.show_atoms()

Show ball-and-stick detail over the active representation. Chained animations may also change color, opacity, or transforms.

python
Protein.hide_atoms()

Hide ball-and-stick detail while retaining the active representation.

python
Protein.label_residues(
    *,
    chain=None,
    residues=None,
    font_size=26,
    color='#edf3fc',
    format='three_letter',
    include_chain=True,
    avoid_overlap=True,
    offsets=None,
    **kwargs,
)

Create labels for the selected residues. Extra options go to ResidueLabels.

ParameterDefaultDescription
chainkeyword onlyNoneAuthor chain ID or a collection of IDs; None selects all chains.
residueskeyword onlyNoneAuthor residue number, inclusive (first, last) tuple, or list of individual numbers.
font_sizekeyword only26Font size in pixels at a 1080-pixel image height.
colorkeyword only'#edf3fc'Hex color or RGB values. For tint setters, None restores the representation’s base palette.
formatkeyword only'three_letter'Automatic residue name style: "three_letter" or "one_letter".
include_chainkeyword onlyTrueInclude the chain identifier in automatic residue names.
avoid_overlapkeyword onlyTrueAdjust labels in the group to reduce overlap.
offsetskeyword onlyNoneMap residue numbers or (chain, number, insertion_code) keys to label offsets.
**kwargs—Additional keyword options described below or in the linked constructor.

Returns: ResidueLabels

python
Protein.hydrogen_bonds(
    *,
    donors=None,
    acceptors=None,
    max_distance=3.5,
    min_angle=150,
    hydrogens='auto',
    donor_h_cutoff=1.3,
)

Create a hydrogen-bond analysis. Options go to HydrogenBonds.

ParameterDefaultDescription
donorskeyword onlyNoneDonor Region or atom indices; None uses standard amino-acid and canonical nucleotide base templates.
acceptorskeyword onlyNoneAcceptor Region or atom indices; None uses standard amino-acid and canonical nucleotide base templates.
max_distancekeyword only3.5Maximum donor–acceptor distance in ångströms.
min_anglekeyword only150Minimum donor–hydrogen–acceptor angle in degrees.
hydrogenskeyword only'auto'"explicit", "auto", or "backbone"; controls the use of loaded or inferred hydrogens.
donor_h_cutoffkeyword only1.3Maximum donor–hydrogen assignment distance in ångströms.

Returns: HydrogenBonds

python
Protein.electrostatics(
    charges='formal',
    *,
    dielectric=80,
    screening_length=8,
    cutoff=12,
    min_energy=0.05,
    exclude_same_residue=True,
    exclude_bonded=True,
)

Create a screened Coulomb analysis. Options go to Electrostatics.

ParameterDefaultDescription
charges'formal'"formal" side-chain templates or one charge per atom, in elementary charge units.
dielectrickeyword only80Positive relative dielectric constant.
screening_lengthkeyword only8Positive exponential screening length in ångströms; None disables screening.
cutoffkeyword only12Distance cutoff in ångströms.
min_energykeyword only0.05Minimum absolute pair energy to include, in kcal/mol.
exclude_same_residuekeyword onlyTrueExclude pairs within the same residue.
exclude_bondedkeyword onlyTrueExclude directly bonded pairs.

Returns: Electrostatics

python
Protein.from_file(
    path,
    *,
    chains=None,
    include_water=False,
    include_hydrogens=False,
    secondary='auto',
    assembly=None,
)

Load PDB or mmCIF coordinates and retain all models with matching atom identities.

ParameterDefaultDescription
pathRequiredInput or output file path, as specified by the operation.
chainskeyword onlyNoneAuthor chain ID or a collection of IDs; None loads all chains.
include_waterkeyword onlyFalseRetain crystallographic waters; default False.
include_hydrogenskeyword onlyFalseRetain explicit hydrogen/deuterium atoms; default False. Enable for side-chain and nucleotide hydrogen-bond analysis.
secondarykeyword only'auto'"auto" uses the file's helix and sheet records, or DSSP when it has none; "dssp" always computes; "file" uses records only.
assemblykeyword onlyNoneBiological assembly to build from the deposited chains, such as "1"; None keeps the deposited chains.

Returns: Protein

Keyword options: chains=None, include_water=False, include_hydrogens=False. Other hetero atoms are retained.

python
Protein.fetch(identifier, *, cache=None, **options)

Download a PDB entry or AlphaFold DB model once, keep it in the cache, and load it.

ParameterDefaultDescription
identifierRequiredFour-character PDB ID such as "4HHB", or AlphaFold DB ID such as "AF-P0DP23-F1".
cachekeyword onlyNoneDownload folder; None uses PROTEINMOTION_CACHE or ~/.cache/proteinmotion.
**options—from_file() options, such as assembly="1" or chains="A".
python
Protein.from_trajectory(trajectory)

Create a protein from the trajectory’s topology and first frame.

ParameterDefaultDescription
trajectoryRequiredTrajectory with the same atom identities and order; None uses the protein’s trajectory.

Returns: Protein

python
Protein.positions

Current atom coordinates in the protein’s local coordinate frame.

Returns: Array with shape (selected atoms, 3), in ångströms.

python
Protein.atom_progress

Current interpolation fraction for each atom.

python
Protein.atom_opacities

Current per-atom opacity, including global opacity and residue fades.

python
Protein.set_positions(xyz)

Replace coordinates while preserving atom identities and topology.

ParameterDefaultDescription
xyzRequiredFinite coordinates with shape (atoms, 3), in ångströms.

Returns: The protein.

python
Protein.copy()

Copy the protein’s current state for independent animation; topology and trajectory are shared.

Returns: Protein

python
Protein.center()

Move the molecular centroid to the world origin.

Returns: The protein.

python
Protein.shift(vector)

Translate the object by an offset.

ParameterDefaultDescription
vectorRequiredFinite 3D translation vector in ångströms.

Returns: The object or animation builder.

python
Protein.rotate(angle, axis=(0, 1, 0))

Rotate around the molecular centroid.

ParameterDefaultDescription
angleRequiredRotation angle in radians.
axis(0, 1, 0)Nonzero 3D rotation axis; it is normalized internally.

Returns: The protein or animation builder.

python
Protein.scale(factor)

Scale around the molecular centroid.

ParameterDefaultDescription
factorRequiredPositive scale or zoom factor.

Returns: The protein or animation builder.

python
Protein.set_opacity(opacity)

Set or animate opacity in [0, 1].

ParameterDefaultDescription
opacityRequiredOpacity in [0, 1], from transparent to opaque.

Returns: The object or animation builder.

python
Protein.set_color(color)

Apply a tint across all representations. None restores the base palette.

ParameterDefaultDescription
colorRequiredHex color or RGB values. For tint setters, None restores the representation’s base palette.

Returns: The object or a Colorize animation.

python
Protein.color_by(values, *, scale=None, thickness=None)

Apply residue property colors and optional cartoon thickness before adding the protein to a scene.

ParameterDefaultDescription
valuesRequiredNumerical input values; see the shape and missing-value rules for this object.
scalekeyword onlyNoneColorScale shared by the structure, plots, and legend. None derives limits from finite values.
thicknesskeyword onlyNoneOptional (minimum, maximum) positive cartoon cross-section scale factors. Missing values use 1.
python
Protein.color_residues(color, *, chain=None, residues=None)

Apply a tint to the selected residues in every representation.

ParameterDefaultDescription
colorRequiredHex color or RGB values. For tint setters, None restores the representation’s base palette.
chainkeyword onlyNoneAuthor chain ID or a collection of IDs; None selects all chains.
residueskeyword onlyNoneAuthor residue number, inclusive (first, last) tuple, or list of individual numbers.

Returns: The protein.

python
Protein.set_residue_opacity(opacity, *, chain=None, residues=None)

Set opacity on the selected residues.

ParameterDefaultDescription
opacityRequiredOpacity in [0, 1], from transparent to opaque.
chainkeyword onlyNoneAuthor chain ID or a collection of IDs; None selects all chains.
residueskeyword onlyNoneAuthor residue number, inclusive (first, last) tuple, or list of individual numbers.

Returns: The protein.

python
Protein.surface(
    *,
    kind='ses',
    probe_radius=1.4,
    resolution=None,
    grid_spacing=None,
    color='secondary',
    update='rebuild',
    max_voxels=8000000,
)

Show a van der Waals, solvent-accessible, or voxel solvent-excluded surface.

ParameterDefaultDescription
kindkeyword only'ses'Surface type: "vdw", "sas", or "ses".
probe_radiuskeyword only1.4Solvent probe radius in ångströms.
resolutionkeyword onlyNoneSpacing in Å between wire points.
grid_spacingkeyword onlyNoneSurface grid spacing in Å. Smaller values add detail; preferred over legacy resolution.
colorkeyword only'secondary'Palette: secondary, base, rainbow, chain, or a fixed color. Surfaces also accept element.
updatekeyword only'rebuild'"rebuild" recalculates the surface as coordinates change; "deform" moves the reference mesh.
max_voxelskeyword only8000000Maximum surface grid cells; increase this limit for large structures or finer grids.

Returns: The protein.

Additional option: max_voxels=8000000 limits the grid size. Configure surface settings before the first play() call. The ses surface is a voxel approximation.

python
Protein.cartoon(
    *,
    color='secondary',
    bases='slabs',
    backbone_radius=0.38,
    base_thickness=0.36,
    base_radius=0.16,
    atom_scale=None,
    bond_radius=None,
)

Show protein secondary structure and nucleotide backbone tubes with selectable base shapes.

ParameterDefaultDescription
colorkeyword only'secondary'Palette: secondary, base, rainbow, chain, or a fixed color. Surfaces also accept element.
baseskeyword only'slabs'Nucleotide base style: slabs, rings, sticks, ladder, or none. None in Representation preserves the current style.
backbone_radiuskeyword only0.38Positive nucleotide cartoon tube radius in ångströms.
base_thicknesskeyword only0.36Positive slab/ring thickness in ångströms.
base_radiuskeyword only0.16Positive base-stick and connector radius in ångströms.
atom_scalekeyword onlyNoneMultiplier applied to element van der Waals radii for ball-and-stick atoms.
bond_radiuskeyword onlyNoneCovalent bond cylinder radius in ångströms.

Returns: The protein.

python
Protein.ribbon(*, color='rainbow', width=1.05, bases='none')

Show a continuous backbone ribbon.

ParameterDefaultDescription
colorkeyword only'rainbow'Palette: secondary, base, rainbow, chain, or a fixed color. Surfaces also accept element.
widthkeyword only1.05Ribbon width in ångströms.
baseskeyword only'none'Nucleotide base style: slabs, rings, sticks, ladder, or none. None in Representation preserves the current style.

Returns: The protein.

python
Protein.set_bases(style, *, backbone_radius=None, base_thickness=None, base_radius=None)

Set nucleotide base shapes and optional dimensions before a scene begins. Use BaseStyle for an animated change.

ParameterDefaultDescription
styleRequiredslabs, rings, sticks, ladder, or none.
backbone_radiuskeyword onlyNonePositive nucleotide cartoon tube radius in ångströms.
base_thicknesskeyword onlyNonePositive slab/ring thickness in ångströms.
base_radiuskeyword onlyNonePositive base-stick and connector radius in ångströms.

Returns: The molecule.

python
Protein.ball_and_stick(*, atom_scale=0.3, bond_radius=0.14, color='element')

Show atom spheres and covalent bond cylinders, with element colors by default.

ParameterDefaultDescription
atom_scalekeyword only0.3Multiplier applied to element van der Waals radii for ball-and-stick atoms.
bond_radiuskeyword only0.14Covalent bond cylinder radius in ångströms.
colorkeyword only'element'Palette: element, base, chain, rainbow, secondary, or a fixed color.

Returns: The protein.

python
Protein.with_secondary_structure(assignments)

Assign helix, sheet, and coil labels before adding the protein to a scene.

ParameterDefaultDescription
assignmentsRequiredOne "H", "E", or "C" code per topology residue for helix, sheet, or coil.

Returns: The protein.

python
Protein.animate

Create a builder for protein transforms, opacity, and color animation.

Returns: Animate

python
Protein.model_matrix

Current 4 × 4 transform from local to world coordinates.

python
Protein.snapshot()

Capture the current state for deterministic timeline evaluation.

Returns: State dictionary.

python
Protein.restore(s)

Restore a state produced by snapshot().

ParameterDefaultDescription
sRequiredState returned by snapshot().

Returns: None