ProteinMotion
Reference navigation
On this page

SetOpacity

Animate transparency on a whole protein or a selected region.

python
from proteinmotion import SetOpacity

Constructor

python
SetOpacity(target, opacity, *, scope=None, **kwargs)

Parameters

ParameterDefaultDescription
targetRequiredProtein or Region to style.
opacityRequiredOpacity in [0, 1], from transparent to opaque.
scopekeyword onlyNoneOpacity scope: object for a Protein by default, residues for a Region; explicit residues affects all per-atom opacities of a Protein.
**kwargs—Additional keyword options described below or in the linked constructor.

Additional keyword arguments

ParameterDefaultDescription
residue_delaykeyword only0Delay in seconds between successive residue starts.
delay_secondskeyword onlyNoneDelay between successive residue, chain, or glyph starts, in seconds. Choose one delay option.
staggerkeyword onlyNoneTotal fraction of the clip reserved for residue starts, in [0, 1).
reversekeyword onlyFalseReverse residue or glyph order.
easingkeyword only'smooth'Named easing (smooth, linear, ease_in_out_sine, there_and_back) or callable mapping [0, 1] to [0, 1]. Per-item easing preserves stagger timing.

Notes

Protein targets change global opacity, matching Protein.set_opacity(). Region targets change per-atom opacity. Use scope=residues for legacy whole-protein per-atom styling and staggered opacity.

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().ball_and_stick()
helix = p.select(residues=(23, 34))
helix.set_color("#50e0d0")
frame(self, p)
self.wait(0.5)
self.play(
    SetOpacity(helix, 0.1, residue_delay=0.06),
    run_time=2,
)
self.wait(0.7)
self.play(SetOpacity(helix, 1), run_time=1.5)
self.wait(0.5)
Output Preview · 5.2 s · 60 fps
Residue transparency

The selected helix fades and returns.

Methods and properties

NameDescription
bind()methodCapture starting values when the scene schedules the animation.
apply()methodEvaluate the animation at eased progress alpha. Called by the timeline.
during()method · inherited from AnimationSet this animation duration and start delay in seconds.
targetsproperty · inherited from AnimationObjects whose state this animation changes.
python
SetOpacity.bind()

Capture starting values when the scene schedules the animation.

Returns: None

Called by ProteinScene.play(). An animation instance can be bound once.

python
SetOpacity.apply(alpha)

Evaluate the animation at eased progress alpha. Called by the timeline.

ParameterDefaultDescription
alphaRequiredEased animation progress in [0, 1].

Returns: None

Inherited from animation.Animation.

python
SetOpacity.during(seconds, *, delay=0)

Set this animation duration and start delay in seconds.

ParameterDefaultDescription
secondsRequiredPositive animation duration in seconds.
delaykeyword only0Nonnegative animation start delay in seconds.

Inherited from animation.Animation.

python
SetOpacity.targets

Objects whose state this animation changes.