ResourceHolder#

ResourceHolder is a mixin class for resources that can hold exactly one other resource. Examples include the sites of plate carriers which hold a single plate, or the docking position of a module that accepts one plate or trough.

ResourceHolder ensures that the child resource is placed correctly inside the holder. When the holder is rotated the child resource is automatically shifted so that its local origin lines up with the correct corner of the holder. This avoids having to manually adjust coordinates for every rotation.

Why use a ResourceHolder?#

Many pieces of labware are designed to accommodate another resource at a fixed position. A PlateHolder inside a carrier for example always contains exactly one plate. The ResourceHolder abstraction models this behaviour. It guarantees that only one resource is assigned at a time and exposes convenient methods to work with the contained resource.

By subclassing from ResourceHolder your own holder classes immediately gain these behaviours without duplicating logic.

Basic usage#

from pylabrobot.resources import Resource, ResourceHolder

holder = ResourceHolder(name="holder", size_x=100, size_y=80, size_z=10)
plate  = Resource(name="plate", size_x=100, size_y=80, size_z=15)

holder.assign_child_resource(plate)
holder.resource.name

After assignment the resource property returns the held item.

holder.resource is plate

Custom child location#

By default the child is positioned at the holder’s origin. You can offset this by passing child_location when constructing the holder.

from pylabrobot.resources import Coordinate

offset_holder = ResourceHolder(
    name="offset_holder",
    size_x=100,
    size_y=80,
    size_z=10,
    child_location=Coordinate(x=10, y=5, z=0),
)
lid = Resource(name="lid", size_x=95, size_y=75, size_z=5)
offset_holder.assign_child_resource(lid)
offset_holder.resource.location