mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2026-02-14 11:45:11 +00:00
Refactor Bioyond resource handling: update warehouse mapping retrieval, add TipBox support, and improve liquid tracking logic. Migrate TipBox creation to bottle_carriers.py for better structure.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from pylabrobot.resources import create_homogeneous_resources, Coordinate, ResourceHolder, create_ordered_items_2d
|
||||
from pylabrobot.resources import create_homogeneous_resources, Coordinate, ResourceHolder, create_ordered_items_2d, Container
|
||||
|
||||
from unilabos.resources.itemized_carrier import BottleCarrier
|
||||
from unilabos.resources.bioyond.bottles import (
|
||||
@@ -9,6 +9,28 @@ from unilabos.resources.bioyond.bottles import (
|
||||
BIOYOND_PolymerStation_Reagent_Bottle,
|
||||
BIOYOND_PolymerStation_Flask,
|
||||
)
|
||||
|
||||
|
||||
def BIOYOND_PolymerStation_Tip(name: str, size_x: float = 8.0, size_y: float = 8.0, size_z: float = 50.0) -> Container:
|
||||
"""创建单个枪头资源
|
||||
|
||||
Args:
|
||||
name: 枪头名称
|
||||
size_x: 枪头宽度 (mm)
|
||||
size_y: 枪头长度 (mm)
|
||||
size_z: 枪头高度 (mm)
|
||||
|
||||
Returns:
|
||||
Container: 枪头容器
|
||||
"""
|
||||
return Container(
|
||||
name=name,
|
||||
size_x=size_x,
|
||||
size_y=size_y,
|
||||
size_z=size_z,
|
||||
category="tip",
|
||||
model="BIOYOND_PolymerStation_Tip",
|
||||
)
|
||||
# 命名约定:试剂瓶-Bottle,烧杯-Beaker,烧瓶-Flask,小瓶-Vial
|
||||
|
||||
|
||||
@@ -322,3 +344,88 @@ def BIOYOND_Electrolyte_1BottleCarrier(name: str) -> BottleCarrier:
|
||||
carrier.num_items_z = 1
|
||||
carrier[0] = BIOYOND_PolymerStation_Solution_Beaker(f"{name}_beaker_1")
|
||||
return carrier
|
||||
|
||||
|
||||
def BIOYOND_PolymerStation_TipBox(
|
||||
name: str,
|
||||
size_x: float = 127.76, # 枪头盒宽度
|
||||
size_y: float = 85.48, # 枪头盒长度
|
||||
size_z: float = 100.0, # 枪头盒高度
|
||||
barcode: str = None,
|
||||
) -> BottleCarrier:
|
||||
"""创建4×6枪头盒 (24个枪头) - 使用 BottleCarrier 结构
|
||||
|
||||
Args:
|
||||
name: 枪头盒名称
|
||||
size_x: 枪头盒宽度 (mm)
|
||||
size_y: 枪头盒长度 (mm)
|
||||
size_z: 枪头盒高度 (mm)
|
||||
barcode: 条形码
|
||||
|
||||
Returns:
|
||||
BottleCarrier: 包含24个枪头孔位的枪头盒载架
|
||||
|
||||
布局说明:
|
||||
- 4行×6列 (A-D, 1-6)
|
||||
- 枪头孔位间距: 18mm (x方向) × 18mm (y方向)
|
||||
- 起始位置居中对齐
|
||||
- 索引顺序: 列优先 (0=A1, 1=B1, 2=C1, 3=D1, 4=A2, ...)
|
||||
"""
|
||||
# 枪头孔位参数
|
||||
num_cols = 6 # 1-6 (x方向)
|
||||
num_rows = 4 # A-D (y方向)
|
||||
tip_diameter = 8.0 # 枪头孔位直径
|
||||
tip_spacing_x = 18.0 # 列间距 (增加到18mm,更宽松)
|
||||
tip_spacing_y = 18.0 # 行间距 (增加到18mm,更宽松)
|
||||
|
||||
# 计算起始位置 (居中对齐)
|
||||
total_width = (num_cols - 1) * tip_spacing_x + tip_diameter
|
||||
total_height = (num_rows - 1) * tip_spacing_y + tip_diameter
|
||||
start_x = (size_x - total_width) / 2
|
||||
start_y = (size_y - total_height) / 2
|
||||
|
||||
# 使用 create_ordered_items_2d 创建孔位
|
||||
# create_ordered_items_2d 返回的 key 是数字索引: 0, 1, 2, ...
|
||||
# 顺序是列优先: 先y后x (即 0=A1, 1=B1, 2=C1, 3=D1, 4=A2, 5=B2, ...)
|
||||
sites = create_ordered_items_2d(
|
||||
klass=ResourceHolder,
|
||||
num_items_x=num_cols,
|
||||
num_items_y=num_rows,
|
||||
dx=start_x,
|
||||
dy=start_y,
|
||||
dz=5.0,
|
||||
item_dx=tip_spacing_x,
|
||||
item_dy=tip_spacing_y,
|
||||
size_x=tip_diameter,
|
||||
size_y=tip_diameter,
|
||||
size_z=50.0, # 枪头深度
|
||||
)
|
||||
|
||||
# 更新 sites 中每个 ResourceHolder 的名称
|
||||
for k, v in sites.items():
|
||||
v.name = f"{name}_{v.name}"
|
||||
|
||||
# 创建枪头盒载架
|
||||
# 注意:不设置 category,使用默认的 "bottle_carrier",这样前端会显示为完整的矩形载架
|
||||
tip_box = BottleCarrier(
|
||||
name=name,
|
||||
size_x=size_x,
|
||||
size_y=size_y,
|
||||
size_z=size_z,
|
||||
sites=sites, # 直接使用数字索引的 sites
|
||||
model="BIOYOND_PolymerStation_TipBox",
|
||||
)
|
||||
|
||||
# 设置自定义属性
|
||||
tip_box.barcode = barcode
|
||||
tip_box.tip_count = 24 # 4行×6列
|
||||
tip_box.num_items_x = num_cols
|
||||
tip_box.num_items_y = num_rows
|
||||
tip_box.num_items_z = 1
|
||||
|
||||
# ⭐ 枪头盒不需要放入子资源
|
||||
# 与其他 carrier 不同,枪头盒在 Bioyond 中是一个整体
|
||||
# 不需要追踪每个枪头的状态,保持为空的 ResourceHolder 即可
|
||||
# 这样前端会显示24个空槽位,可以用于放置枪头
|
||||
|
||||
return tip_box
|
||||
|
||||
@@ -116,7 +116,9 @@ def BIOYOND_PolymerStation_TipBox(
|
||||
size_z: float = 100.0, # 枪头盒高度
|
||||
barcode: str = None,
|
||||
):
|
||||
"""创建4×6枪头盒 (24个枪头)
|
||||
"""创建4×6枪头盒 (24个枪头) - 使用 BottleCarrier 结构
|
||||
|
||||
注意:此函数已弃用,请使用 bottle_carriers.py 中的版本
|
||||
|
||||
Args:
|
||||
name: 枪头盒名称
|
||||
@@ -126,55 +128,11 @@ def BIOYOND_PolymerStation_TipBox(
|
||||
barcode: 条形码
|
||||
|
||||
Returns:
|
||||
TipBoxCarrier: 包含24个枪头孔位的枪头盒
|
||||
BottleCarrier: 包含24个枪头孔位的枪头盒载架
|
||||
"""
|
||||
from pylabrobot.resources import Container, Coordinate
|
||||
|
||||
# 创建枪头盒容器
|
||||
tip_box = Container(
|
||||
name=name,
|
||||
size_x=size_x,
|
||||
size_y=size_y,
|
||||
size_z=size_z,
|
||||
category="tip_rack",
|
||||
model="BIOYOND_PolymerStation_TipBox_4x6",
|
||||
)
|
||||
|
||||
# 设置自定义属性
|
||||
tip_box.barcode = barcode
|
||||
tip_box.tip_count = 24 # 4行×6列
|
||||
tip_box.num_items_x = 6 # 6列
|
||||
tip_box.num_items_y = 4 # 4行
|
||||
|
||||
# 创建24个枪头孔位 (4行×6列)
|
||||
# 假设孔位间距为 9mm
|
||||
tip_spacing_x = 9.0 # 列间距
|
||||
tip_spacing_y = 9.0 # 行间距
|
||||
start_x = 14.38 # 第一个孔位的x偏移
|
||||
start_y = 11.24 # 第一个孔位的y偏移
|
||||
|
||||
for row in range(4): # A, B, C, D
|
||||
for col in range(6): # 1-6
|
||||
spot_name = f"{chr(65 + row)}{col + 1}" # A1, A2, ..., D6
|
||||
x = start_x + col * tip_spacing_x
|
||||
y = start_y + row * tip_spacing_y
|
||||
|
||||
# 创建枪头孔位容器
|
||||
tip_spot = Container(
|
||||
name=spot_name,
|
||||
size_x=8.0, # 单个枪头孔位大小
|
||||
size_y=8.0,
|
||||
size_z=size_z - 10.0, # 略低于盒子高度
|
||||
category="tip_spot",
|
||||
)
|
||||
|
||||
# 添加到枪头盒
|
||||
tip_box.assign_child_resource(
|
||||
tip_spot,
|
||||
location=Coordinate(x=x, y=y, z=0)
|
||||
)
|
||||
|
||||
return tip_box
|
||||
# 重定向到 bottle_carriers.py 中的实现
|
||||
from unilabos.resources.bioyond.bottle_carriers import BIOYOND_PolymerStation_TipBox as TipBox_Carrier
|
||||
return TipBox_Carrier(name=name, size_x=size_x, size_y=size_y, size_z=size_z, barcode=barcode)
|
||||
|
||||
|
||||
def BIOYOND_PolymerStation_Flask(
|
||||
|
||||
Reference in New Issue
Block a user