def _load_container_object_from_db(db, container_name: str): db_data = db_queries.get_container_by_name(db, container_name) if not db_data: raise ValueError( "No container with name {} found in Containers database" .format(container_name) ) container_type, *rel_coords = db_data wells = db_queries.get_wells_by_container_name(db, container_name) if not wells: raise ResourceWarning( "No wells for container {} found in ContainerWells database" .format(container_name) ) if container_name in SUPPORTED_MODULES: container: Placeable = Module() else: container = Container() container.properties['type'] = container_type container._coordinates = Vector(rel_coords) log.debug("Loading {} with coords {}".format(rel_coords, container_type)) for well in wells: container.add(*_load_well_object_from_db(db, well)) return container
def test_get_name(robot): 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) assert red.get_name() == 'Red'
def test_named_well(robot): 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) assert deck['A1'][0]['Red'] == red
def json_to_labware(json_defn: dict) -> Container: container_data = json_defn.copy() container = Container() container._coordinates = Vector(0, 0, 0) wells = container_data['wells'] for well_name, json_well in wells.items(): well, coordinates = _json_to_well(json_well) container.add(well, well_name, coordinates) container.ordering = json_defn['ordering'] return container
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
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 origin_offset_z = container_data.get('origin-offset', {}).get('z') or 0 container = Container() locations = container_data['locations'] container._coordinates = Vector( origin_offset_x, origin_offset_y, origin_offset_z ) for well_name, well_properties in locations.items(): x = well_properties.pop('x') y = well_properties.pop('y') z = well_properties.pop('z') 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, y, z) container.add(well, well_name, well_coordinates) return container