ProteinMotion
Reference navigation
On this page

Region

A selection of atoms that follows its parent protein’s coordinates.

python
from proteinmotion import Region

Constructor

python
Region(protein, atom_indices, *, allow_empty=False)

Parameters

ParameterDefaultDescription
proteinRequiredProtein object to read or animate.
atom_indicesRequiredNonempty collection of zero-based atom indices.
allow_emptykeyword onlyFalseAllow an empty Region, as used internally by set operations.

Notes

Use Protein.select(). Combine static selections with |, &, -, and ~. Use residue_range for inclusive author ranges. Updating queries re-evaluate membership; freeze() captures it. optional static queries use required=False.

Attributes

NameDescription
proteinParent Protein object.
atom_indicesRead-only, sorted atom indices.
residue_indicesRead-only topology residue indices represented in the selection.

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()
frame(self, p)
helix = p.select(chain="A", residues=(23, 34))
marker = helix.highlight(
    style="box",
    color="#f2ba67",
    padding=1.5,
)
self.play(FadeIn(marker), run_time=0.6)
self.focus(helix, margin=1.6, run_time=1.5)
self.play(self.camera.animate.orbit(0.4), run_time=2)
self.play(FadeOut(marker), run_time=0.6)
self.focus(p, run_time=1.5)
Output Preview · 6.2 s · 60 fps
Camera focus

Ubiquitin residues 23–34.

Methods and properties

NameDescription
atom_indicespropertyCurrent selected atom indices.
residue_indicespropertyCurrent topology residue indices.
residue_idspropertyAuthor identities (chain, residue number, insertion code).
__len__()methodReturn the number of frames with len(trajectory).
freeze()methodCapture current selection membership.
filter()methodFilter within this region.
select()class methodSelect atoms by author chain, residue number, and atom name.
positionspropertyCurrent atom coordinates in the protein’s local coordinate frame.
model_matrixpropertyCurrent 4 × 4 transform from local to world coordinates.
positionpropertyTranslation of the parent protein in world coordinates.
world_positionspropertySelected atom coordinates after the parent’s display transform.
__or__()methodCombine selections from the same protein with region_a | region_b.
highlight()methodCreate a sphere, box, or atom highlight around the selection.
set_color()methodApply a tint across all representations. None restores the base palette.
set_opacity()methodSet or animate opacity in [0, 1].
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.
side_chains()methodA region with the side chains of this region's amino acids, joined at Cα.
animatepropertyCreate a builder for residue color and opacity animations.
distance_to()methodCreate a ruler to another region. Extra options go to Distance.
torsions()methodMeasure φ, ψ, ω and χ1–χ5 in degrees for this region's residues.
set_torsions()methodSet this region's torsions in degrees immediately; see SetTorsions.
torsion_marker()methodA live protractor showing one torsion of this single-residue region.
callout()methodCreate a label connected by a line to this region. Extra options go to Callout.
label()methodCreate one amino-acid label. Extra options go to ResidueLabel.
python
Region.atom_indices

Current selected atom indices.

python
Region.residue_indices

Current topology residue indices.

python
Region.residue_ids

Author identities (chain, residue number, insertion code).

python
Region.__len__()

Return the number of frames with len(trajectory).

Returns: int

python
Region.freeze()

Capture current selection membership.

python
Region.filter(**criteria)

Filter within this region.

ParameterDefaultDescription
**criteria—Protein selection keyword filters to apply within this region.
python
Region.select(
    protein,
    *,
    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
proteinRequiredProtein object to read or animate.
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
Region.positions

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

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

python
Region.model_matrix

Current 4 × 4 transform from local to world coordinates.

python
Region.position

Translation of the parent protein in world coordinates.

python
Region.world_positions

Selected atom coordinates after the parent’s display transform.

python
Region.__or__(other)

Combine selections from the same protein with region_a | region_b.

ParameterDefaultDescription
otherRequiredAnother Region from the same protein for a union, or an endpoint Region for a distance.

Returns: Region

python
Region.highlight(
    *,
    style='sphere',
    color='#f2ba67',
    opacity=None,
    padding=None,
    line_width=0.12,
)

Create a sphere, box, or atom highlight around the selection.

ParameterDefaultDescription
stylekeyword only'sphere'Highlight shape or line style; allowed values are specified by the constructor.
colorkeyword only'#f2ba67'Hex color or RGB values. For tint setters, None restores the representation’s base palette.
opacitykeyword onlyNoneOpacity in [0, 1], from transparent to opaque.
paddingkeyword onlyNoneExtra highlight size in ångströms. None selects a default for the highlight style.
line_widthkeyword only0.12Line width in design pixels at 1080p for overlays; ångströms for 3D highlight boxes.

Returns: RegionHighlight

python
Region.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
Region.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
Region.show_atoms()

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

python
Region.hide_atoms()

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

python
Region.side_chains()

A region with the side chains of this region's amino acids, joined at Cα.

python
Region.animate

Create a builder for residue color and opacity animations.

Returns: Animate

python
Region.distance_to(other, **kwargs)

Create a ruler to another region. Extra options go to Distance.

ParameterDefaultDescription
otherRequiredAnother Region from the same protein for a union, or an endpoint Region for a distance.
**kwargs—Additional keyword options described below or in the linked constructor.

Returns: Distance

python
Region.torsions()

Measure φ, ψ, ω and χ1–χ5 in degrees for this region's residues.

python
Region.set_torsions(*, conformation=None, anchor='center', secondary='auto', **angles)

Set this region's torsions in degrees immediately; 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
Region.torsion_marker(torsion='phi', **kwargs)

A live protractor showing one torsion of this single-residue region.

ParameterDefaultDescription
torsion'phi'phi, psi, omega, or chi1–chi5.
**kwargs—TorsionMarker options.
python
Region.callout(text, **kwargs)

Create a label connected by a line to this region. Extra options go to Callout.

ParameterDefaultDescription
textRequiredText to display.
**kwargs—Additional keyword options described below or in the linked constructor.

Returns: Callout

python
Region.label(text=None, **kwargs)

Create one amino-acid label. Extra options go to ResidueLabel.

ParameterDefaultDescription
textNoneText to display.
**kwargs—Additional keyword options described below or in the linked constructor.

Returns: ResidueLabel