Esempio n. 1
0
def test_invalid_container_name():
    if ff.split_labware_definitions():
        error_type = FileNotFoundError
    else:
        error_type = ValueError
    with pytest.raises(error_type):
        database.load_container("fake_container")
def test_labware_create(dummy_db):
    from opentrons import labware
    lw_name = '15-well-plate'
    if lw_name in labware.list():
        database.delete_container(lw_name)
    n_cols = 5
    n_rows = 3
    col_space = 12
    row_space = 18
    diameter = 5
    height = 20
    volume = 3.14 * (diameter / 2.0)**2
    res = labware.create(lw_name, (n_cols, n_rows), (col_space, row_space),
                         diameter, height, volume)
    lw = database.load_container(lw_name)
    database.delete_container(lw_name)

    assert len(lw.wells()) is n_cols * n_rows
    for well in lw.wells():
        name = well.get_name()
        assert res[name].coordinates() == well.coordinates()
        for prop in ['height', 'diameter']:
            assert res[name].properties[prop] == well.properties[prop]
    assert lw.well("B5").coordinates() == ((n_cols - 1) * col_space, row_space,
                                           0)
    assert lw.well("C3").coordinates() == (2 * col_space, 0, 0)

    assert lw.well(2).get_name() == 'C1'
Esempio n. 3
0
def _setup_container(container_name):
    try:
        container = database.load_container(container_name)

    # Database.load_container throws ValueError when a container name is not
    # found.
    except ValueError:
        # First must populate "get persisted container" list
        old_container_loading.load_all_containers_from_disk()
        # Load container from old json file
        container = old_container_loading.get_persisted_container(
            container_name)
        # Rotate coordinates to fit the new deck map
        rotated_container = database_migration.rotate_container_for_alpha(
            container)
        # Save to the new database
        database.save_new_container(rotated_container, container_name)

    container.properties['type'] = container_name
    container_x, container_y, container_z = container._coordinates

    if not fflags.split_labware_definitions():
        # infer z from height
        if container_z == 0 and 'height' in container[0].properties:
            container_z = container[0].properties['height']

    from opentrons.util.vector import Vector
    container._coordinates = Vector(container_x, container_y, container_z)

    return container
Esempio n. 4
0
def test_load_persisted_container():
    plate = database.load_container("24-vial-rack")
    assert isinstance(plate, Container)
    assert isinstance(plate, Container)
    assert all([isinstance(w, Well) for w in plate])

    assert plate[0].coordinates() == (8.19, 63.76, 0)
    assert plate['A2'].coordinates() == (27.49, 63.76, 0)
Esempio n. 5
0
def test_seralizer_all_containers():
    new_defs = ['opentrons-tiprack-300ul', 'tube-rack-5ml-96', '4-well-plate']
    plates = [item for item in ldef.list_all_labware() if item not in new_defs]
    for plate in plates:
        old_container = sqldb.load_container(plate)

        json_from_file = ldef._load_definition(test_defn_root, plate)
        json_from_container = ser.container_to_json(old_container)

        assert json_from_container['ordering'] == json_from_file['ordering']
        assert json_from_container['wells'] == json_from_file['wells']
Esempio n. 6
0
def test_load_persisted_container(robot):
    plate = database.load_container("96-flat")
    assert isinstance(plate, Container)
    assert isinstance(plate, Container)
    assert all([isinstance(w, Well) for w in plate])

    offset_x = 11.24
    offset_y = 14.34
    width = 85.48
    well_a1 = (offset_y, width - offset_x, 0)
    well_d6 = (offset_y + 45, width - (offset_x + 27), 0)
    assert plate[0].coordinates() == well_a1
    assert plate['D6'].coordinates() == well_d6
Esempio n. 7
0
def test_one_serializer():
    plate = '6-well-plate'
    old_container = sqldb.load_container(plate)

    json_from_file = ldef._load_definition(test_defn_root, plate)
    json_from_container = ser.container_to_json(old_container)

    # Metadata comparison does not work in test, because the constructed
    # Container does not have a parent, and Container does not keep track of
    # its own name--the name is saved by the parent, so
    # new_json['metadata']['name'] in this test will be None

    assert json_from_container['ordering'] == json_from_file['ordering']
    assert json_from_container['wells'] == json_from_file['wells']
Esempio n. 8
0
def test_one_deserializer():
    plate = '6-well-plate'
    new_container = ser.json_to_container(
        ldef._load_definition(test_defn_root, plate))
    old_container = sqldb.load_container(plate)

    old_wells = {
        wellname: [
            round(well._coordinates[i] + old_container._coordinates[i], 3)
            for i in [0, 1, 2]
        ]
        for wellname, well in old_container.children_by_name.items()
    }

    new_wells = {
        wellname: [well._coordinates[i] for i in [0, 1, 2]]
        for wellname, well in new_container.children_by_name.items()
    }

    assert old_wells == new_wells
Esempio n. 9
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)
Esempio n. 10
0
def test_invalid_container_name(robot):
    error_type = ValueError
    with pytest.raises(error_type):
        database.load_container("fake_container")