Пример #1
0
    def test_get_name(self):
        deck = Deck()
        slot = Slot()
        c = Container()
        deck.add(slot, 'A1', (0, 0, 0))
        red = Well(properties={'radius': 5})
        blue = Well(properties={'radius': 5})
        c.add(red, "Red", (0, 0, 0))
        c.add(blue, "Blue", (10, 0, 0))
        slot.add(c)

        self.assertEqual(red.get_name(), 'Red')
Пример #2
0
    def generate_deck(self):
        deck = Deck()
        slot = Slot()
        deck.add(slot, 'A1', (5, 10, 0))
        c = Container()
        red = Well(properties={'radius': 5})
        blue = Well(properties={'radius': 5})
        c.add(red, "Red", (5, 5, 0))
        c.add(blue, "Blue", (15, 5, 0))
        slot.add(c, 'tube_rack')

        return deck
Пример #3
0
    def test_get_container_name(self):
        deck = Deck()
        slot = Slot()
        c = Container()
        deck.add(slot, 'A1', (0, 0, 0))
        red = Well(properties={'radius': 5})
        blue = Well(properties={'radius': 5})
        c.add(red, "Red", (0, 0, 0))
        c.add(blue, "Blue", (10, 0, 0))
        slot.add(c)

        self.assertEqual(red.get_name(), 'Red')
Пример #4
0
def _load_well_object_from_db(db, well_data):
    container_name, location, x, y, z, \
        depth, volume, diameter, length, width = well_data

    props = zip(
        ['depth', 'total-liquid-volume', 'diameter', 'length', 'width'],
        [depth, volume, diameter, length, width])
    property_dict = {k: v for k, v in props if v}
    well = Well(properties=property_dict)
    # subtract half the size, because
    # Placeable assigns X-Y to bottom-left corner,
    # but db assigns X-Y to well center
    x -= (well.x_size() / 2)
    y -= (well.y_size() / 2)
    well_coordinates = (x, y, z)
    return (well, location, well_coordinates)
Пример #5
0
def _parse_well_obj(well: Well):
    r_x, r_y, r_z = well._coordinates + well.bottom()[1]
    location, depth = well.get_name(), well.z_size()
    diameter = well.properties.get('diameter', None)
    volume = well.properties.get('total-liquid-volume', None)
    width, length = well.properties['width'], well.properties['length']
    return {
        'location': location,
        'x': r_x,
        'y': r_y,
        'z': r_z,
        'depth': depth,
        'volume': volume,
        'diameter': diameter,
        'length': length,
        'width': width
    }
Пример #6
0
        def generate_plate(wells, cols, spacing, offset, radius):
            c = Container()

            for i in range(0, wells):
                well = Well(properties={'radius': radius})
                row, col = divmod(i, cols)
                name = chr(row + ord('A')) + str(1 + col)
                coordinates = (col * spacing[0] + offset[0],
                               row * spacing[1] + offset[1], 0)
                c.add(well, name, coordinates)
            return c
Пример #7
0
def _json_to_well(
        json_well: dict) -> Tuple[Well, Tuple[Number, Number, Number]]:
    well_properties = json_well.copy()
    x = well_properties.pop('x')
    y = well_properties.pop('y')
    z = well_properties.pop('z')
    assert isinstance(x, Number)
    assert isinstance(y, Number)
    assert isinstance(z, Number)

    well = Well(properties=well_properties)

    well_coordinates = (x, y, z)
    return well, well_coordinates
Пример #8
0
def create_container_instance(name,
                              grid,
                              spacing,
                              diameter,
                              depth,
                              volume=0,
                              slot=None,
                              label=None,
                              Transposed=False):
    from opentrons import robot
    from opentrons.containers.placeable import Container, Well

    if slot is None:
        raise RuntimeError('"slot" argument is required.')
    if label is None:
        label = name
    columns, rows = grid
    col_spacing, row_spacing = spacing
    custom_container = Container()
    well_properties = {
        'type': 'custom',
        'diameter': diameter,
        'height': depth,
        'total-liquid-volume': volume
    }

    for r in range(rows):
        for c in range(columns):
            well = Well(properties=well_properties)
            well_name = chr(c + ord('A')) + str(1 + r)
            if Transposed:
                coordinates = (r * col_spacing, c * row_spacing, 0)
            else:
                coordinates = (c * col_spacing, r * row_spacing, 0)
            custom_container.add(well, well_name, coordinates)

    # if a container is added to Deck AFTER a Pipette, the Pipette's
    # Calibrator must update to include all children of Deck
    for _, instr in robot.get_instruments():
        if hasattr(instr, 'update_calibrator'):
            instr.update_calibrator()

    custom_container.properties['type'] = name
    custom_container.get_name = lambda: label

    # add to robot deck
    robot.deck[slot].add(custom_container, label)

    return custom_container
Пример #9
0
def generate_plate(wells, cols, spacing, offset, radius, height=0):
    c = Container()
    c.ordering = []
    n_rows = int(wells / cols)
    for i in range(n_rows):
        c.ordering.append([])
    for i in range(0, wells):
        well = Well(properties={'radius': radius, 'height': height})
        row, col = divmod(i, cols)
        name = chr(col + ord('A')) + str(1 + row)
        c.ordering[row].append(name)
        coordinates = (col * spacing[0] + offset[0],
                       row * spacing[1] + offset[1],
                       0)
        c.add(well, name, coordinates)
    return c
Пример #10
0
def create(name, grid, spacing, diameter, depth, volume=0):
    columns, rows = grid
    col_spacing, row_spacing = spacing
    custom_container = Container()
    properties = {
        'type': 'custom',
        'diameter': diameter,
        'height': depth,
        'total-liquid-volume': volume
    }

    for r in range(rows):
        for c in range(columns):
            well = Well(properties=properties)
            well_name = chr(c + ord('A')) + str(1 + r)
            coordinates = (c * col_spacing, r * row_spacing, 0)
            custom_container.add(well, well_name, coordinates)
    json_container = container_to_json(custom_container, name)
    save_custom_container(json_container)
    persisted_containers.load_all_persisted_containers_from_disk()
Пример #11
0
def create(name, grid, spacing, diameter, depth, volume=0):
    """
    Creates a labware definition based on a rectangular gird, depth, diameter,
    and spacing. Note that this function can only create labware with regularly
    spaced wells in a rectangular format, of equal height, depth, and radius.
    Irregular labware defintions will have to be made in other ways or modified
    using a regular definition as a starting point. Also, upon creation a
    definition always has its lower-left well at (0, 0, 0), such that this
    labware _must_ be calibrated before use.

    :param name: the name of the labware to be used with `labware.load`
    :param grid: a 2-tuple of integers representing (<n_columns>, <n_rows>)
    :param spacing: a 2-tuple of floats representing
        (<col_spacing, <row_spacing)
    :param diameter: a float representing the internal diameter of each well
    :param depth: a float representing the distance from the top of each well
        to the internal bottom of the same well
    :param volume: [optional] the maximum volume of each well
    :return: the labware object created by this function
    """
    columns, rows = grid
    col_spacing, row_spacing = spacing
    custom_container = Container()
    properties = {
        'type': 'custom',
        'diameter': diameter,
        'height': depth,
        'total-liquid-volume': volume
    }

    for r in range(rows):
        for c in range(columns):
            well = Well(properties=properties)
            well_name = chr(r + ord('A')) + str(1 + c)
            coordinates = (c * col_spacing, (rows - r - 1) * row_spacing, 0)
            custom_container.add(well, well_name, coordinates)
    database.save_new_container(custom_container, name)
    return database.load_container(name)
Пример #12
0
def create_container_obj_from_dict(container_data: dict) -> Container:
    """

    Example input:
    container data for a "24-plate":
    {
         "origin-offset":{
            "x":13.3,
            "y":17.5
         },
         "locations":{
            "A1":{
               "x":0.0,
               "total-liquid-volume":3400,
               "y":0.0,
               "depth":16.2,
               "z":0,
               "diameter":15.62
            },
            "A2":{
               "x":0.0,
               "total-liquid-volume":3400,
               "y":19.3,
               "depth":16.2,
               "z":0,
               "diameter":15.62
            }

    Exampl input #2:
    "trough-12row":

    {
         "locations":{
            "A1":{
               "x":0,
               "y":0,
               "z":0,
               "depth":40,
               "length":8,
               "width":70,
               "total-liquid-volume":22000
            },
            "A2":{
               "x":0,
               "y":9,
               "z":0,
               "depth":40,
               "length":8,
               "width":70,
               "total-liquid-volume":22000
            },
            "A3":{
               "x":0,
               "y":18,
               "z":0,
               "depth":40,
               "length":8,
               "width":70,
               "total-liquid-volume":22000
            }
    """
    container_data = copy.deepcopy(container_data)
    origin_offset_x = container_data.get('origin-offset', {}).get('x') or 0
    origin_offset_y = container_data.get('origin-offset', {}).get('y') or 0

    container = Container()
    locations = container_data.get('locations')

    for well_name, well_properties in locations.items():
        x = well_properties.pop('x')
        y = well_properties.pop('y')
        z = well_properties.pop('z')

        # assert 'depth' in well_properties
        # assert 'diameter' in well_properties
        # assert 'length' in well_properties
        # assert 'width' in well_properties
        # assert 'total-liquid-volume' in well_properties
        assert isinstance(x, numbers.Number)
        assert isinstance(y, numbers.Number)
        assert isinstance(z, numbers.Number)

        well = Well(properties=well_properties)

        # subtract half the size, because
        # Placeable assigns X-Y to bottom-left corner, but
        # persisted container files assign X-Y to center of each Well
        x -= (well.x_size() / 2)
        y -= (well.y_size() / 2)

        well_coordinates = (x + origin_offset_x, y + origin_offset_y, z)

        container.add(well, well_name, well_coordinates)

    return container
Пример #13
0
def _well_to_json(well: Well) -> dict:
    x, y, z = map(lambda num: round(num, 3), well.coordinates())
    well_json = {'x': x, 'y': y, 'z': z}
    well_json.update(well.properties)
    return well_json