gigablochs.backends.manim_cairo.BlochScene

gigablochs.backends.manim_cairo.BlochScene#

class gigablochs.backends.manim_cairo.BlochScene(camera_class=<class 'manim.camera.three_d_camera.ThreeDCamera'>, ambient_camera_rotation=None, default_angled_camera_orientation_kwargs=None, **kwargs)[source]#
__init__(camera_class=<class 'manim.camera.three_d_camera.ThreeDCamera'>, ambient_camera_rotation=None, default_angled_camera_orientation_kwargs=None, **kwargs)#

Methods

__init__([camera_class, ...])

add(*mobjects)

Mobjects will be displayed, from background to foreground in the order with which they are added.

add_fixed_in_frame_mobjects(*mobjects)

This method is used to prevent the rotation and movement of mobjects as the camera moves around.

add_fixed_orientation_mobjects(*mobjects, ...)

This method is used to prevent the rotation and tilting of mobjects as the camera moves around.

add_foreground_mobject(mobject)

Adds a single mobject to the foreground, and internally to the list foreground_mobjects, and mobjects.

add_foreground_mobjects(*mobjects)

Adds mobjects to the foreground, and internally to the list foreground_mobjects, and mobjects.

add_mobjects_from_animations(animations)

add_sound(sound_file[, time_offset, gain])

This method is used to add a sound to the animation.

add_subcaption(content[, duration, offset])

Adds an entry in the corresponding subcaption file at the current time stamp.

add_updater(func)

Add an update function to the scene.

begin_3dillusion_camera_rotation([rate, ...])

This method creates a 3D camera rotation illusion around the current camera orientation.

begin_ambient_camera_rotation([rate, about])

This method begins an ambient rotation of the camera about the Z_AXIS, in the anticlockwise direction

begin_animations()

Start the animations of the scene.

bring_to_back(*mobjects)

Removes the mobject from the scene and adds them to the back of the scene.

bring_to_front(*mobjects)

Adds the passed mobjects to the scene again, pushing them to he front of the scene.

check_interactive_embed_is_valid()

clear()

Removes all mobjects present in self.mobjects and self.foreground_mobjects from the scene.

compile_animation_data(*animations, ...)

Given a list of animations, compile the corresponding static and moving mobjects, and gather the animation durations.

compile_animations(*args, **kwargs)

Creates _MethodAnimations from any _AnimationBuilders and updates animation kwargs with kwargs passed to play().

construct()

Add content to the Scene.

embed()

get_attrs(*keys)

Gets attributes of a scene given the attribute's identifier/name.

get_mobject_family_members()

Returns list of family-members of all mobjects in scene.

get_moving_and_static_mobjects(animations)

get_moving_mobjects(*animations)

This method returns a list of all of the Mobjects in the Scene that are moving, that are also in the animations passed.

get_restructured_mobject_list(mobjects, ...)

Given a list of mobjects and a list of mobjects to be removed, this filters out the removable mobjects from the list of mobjects.

get_run_time(animations)

Gets the total run time for a list of animations.

get_time_progression(run_time, description)

You will hardly use this when making your own animations.

get_top_level_mobjects()

Returns all mobjects which are not submobjects.

interact(shell, keyboard_thread)

interactive_embed()

Like embed(), but allows for screen interaction.

is_current_animation_frozen_frame()

Returns whether the current animation produces a static frame (generally a Wait).

mouse_drag_orbit_controls(point, d_point, ...)

mouse_scroll_orbit_controls(point, offset)

move_camera([phi, theta, gamma, zoom, ...])

This method animates the movement of the camera to the given spherical coordinates.

next_section([name, section_type, ...])

Create separation here; the last section gets finished and a new one gets created.

on_key_press(symbol, modifiers)

on_key_release(symbol, modifiers)

on_mouse_drag(point, d_point, buttons, modifiers)

on_mouse_motion(point, d_point)

on_mouse_press(point, button, modifiers)

on_mouse_scroll(point, offset)

pause([duration])

Pauses the scene (i.e., displays a frozen frame).

play(*args[, subcaption, ...])

Plays an animation in this scene.

play_internal([skip_rendering])

This method is used to prep the animations for rendering, apply the arguments and parameters required to them, render them, and write them to the video file.

remove(*mobjects)

Removes mobjects in the passed list of mobjects from the scene and the foreground, by removing them from "mobjects" and "foreground_mobjects"

remove_fixed_in_frame_mobjects(*mobjects)

This method undoes what add_fixed_in_frame_mobjects does.

remove_fixed_orientation_mobjects(*mobjects)

This method "unfixes" the orientation of the mobjects passed, meaning they will no longer be at the same angle relative to the camera.

remove_foreground_mobject(mobject)

Removes a single mobject from the foreground, and internally from the list foreground_mobjects.

remove_foreground_mobjects(*to_remove)

Removes mobjects from the foreground, and internally from the list foreground_mobjects.

remove_updater(func)

Remove an update function from the scene.

render([preview])

Renders this Scene.

replace(old_mobject, new_mobject)

Replace one mobject in the scene with another, preserving draw order.

restructure_mobjects(to_remove[, ...])

tl:wr

set_camera_orientation([phi, theta, gamma, ...])

This method sets the orientation of the camera in the scene.

set_data(magnetization, B_field, time_increments)

Set the data for the Bloch sphere animation.

set_key_function(char, func)

set_to_default_angled_camera_orientation(...)

This method sets the default_angled_camera_orientation to the keyword arguments passed, and sets the camera to that orientation.

setup()

This is meant to be implemented by any scenes which are commonly subclassed, and have some common setup involved before the construct method is called.

should_update_mobjects()

Returns True if the mobjects of this scene should be updated.

stop_3dillusion_camera_rotation()

This method stops all illusion camera rotations.

stop_ambient_camera_rotation([about])

This method stops all ambient camera rotation.

tear_down()

This is meant to be implemented by any scenes which are commonly subclassed, and have some common method to be invoked before the scene ends.

update_meshes(dt)

update_mobjects(dt)

Begins updating all mobjects in the Scene.

update_self(dt)

Run all scene updater functions.

update_to_time(t)

validate_run_time(run_time, method[, ...])

wait([duration, stop_condition, frozen_frame])

Plays a "no operation" animation.

wait_until(stop_condition[, max_time])

Wait until a condition is satisfied, up to a given maximum duration.

Attributes

camera

time

The time since the start of the scene.

construct()[source]#

Add content to the Scene.

From within Scene.construct(), display mobjects on screen by calling Scene.add() and remove them from screen by calling Scene.remove(). All mobjects currently on screen are kept in Scene.mobjects. Play animations by calling Scene.play().

Notes

Initialization code should go in Scene.setup(). Termination code should go in Scene.tear_down().

Examples

A typical manim script includes a class derived from Scene with an overridden Scene.construct() method:

class MyScene(Scene):
    def construct(self):
        self.play(Write(Text("Hello World!")))

See also

Scene.setup(), Scene.render(), Scene.tear_down()

set_data(magnetization, B_field, time_increments, speed=None, traces=('magnetization', 'B_field_projection'), prologue=True)[source]#

Set the data for the Bloch sphere animation.

Parameters:
  • magnetization (ndarray, shape (time, n, 3)) – Magnetization vectors.

  • B_field (tuple(ndarray, float)) – Tuple containing the normalized/rescaled effective B field and the maximum B field magnitude.

  • time_increments (ndarray, shape (time,)) – Time increments for each animation step in seconds.

  • speed (float, optional) – Displayed speed factor of the animation. Default is None.

  • traces (sequence, optional) – Traced paths to display, ‘magnetization’ traces the value of the magnetization vector tip, ‘B_field’ traces the value of the B_field vector tip, ‘magnetization_projection’ traces the projection of the magnetization vector onto the unit sphere, and ‘B_field_projection’ traces the projection of the B_field vector onto the unit sphere. Default is (‘magnetization’, ‘B_field_projection’).

Example

import numpy as np
from gigablochs.backends.manim_cairo import BlochScene
from gigablochs.animation import rescale_Beff
sample_rate = 10 # Hz
time = np.arange(0, 3, 1/sample_rate)
time_increments = np.gradient(time)
B_eff = np.repeat(np.array([[0, -1, 0]]), time.size, axis=0) * 1e-6 # T
period = 10 # s
mag = np.array([np.sin(2 * np.pi * time / period), np.zeros_like(time), np.cos(2 * np.pi * time / period)]).T
scene = BlochScene()
scene.set_data(mag, rescale_Beff(B_eff), time_increments)
scene.render()