harijay / protein-crystallization-gridmaker

A module of python classes that create 96 well crystallization screen dispense lists for the Formulatrix liquid handling robot

This URL has Read+Write access

100644 106 lines (89 sloc) 4.124 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python
# encoding: utf-8
"""
well.py
 
Created by Hariharan Jayaram on 2009-01-24.
Copyright (c) 2009 __SciForward LLC__. All rights reserved.
"""
 
import componentlist
import plateliberror
class Well(object):
# A well class that modifies itself by adding components and reports to the
# Componentlist when any component is added
# well.about is a tostring() method
wellcomponentlist = componentlist.ComponentList()
def __init__(self,alpha,num,vol):
self.alpha = alpha
self.num = num
self.components = []
self.vol = vol
self.wellcomponentdict = {}
self.volleft = vol
                self.component_name_object_map = {}
 
def deplete(self,vol):
self.volleft = self.volleft - vol
                if "100.00 % Water" in self.wellcomponentdict.keys():
                        raise plateliberror.PlatelibException("Well volume exceeded when trying to add component to Well :%s%s.\nBut you have already Added water\n Please Add water last to prevent this\n" % (self.alpha,self.num))
if round(self.volleft) < 0:
                        raise plateliberror.PlatelibException("Well volume exceeded when trying to add component to Well :%s%s.\nIncrease concentration of stock for any component and retry" %(self.alpha,self.num))
 
def addcomponent(self,Component,finalconc):
key = Component.name
if key not in Well.wellcomponentlist.componentfactory:
Well.wellcomponentlist.insertcomponent(Component)
if key in self.wellcomponentdict:
#If a component has already been added to well . Then repeating additing will mess up concentration intended
inconsistent_conc_warning = plateliberror.PlatelibException("Component %s already dispensed into Well:%s,%s: Inconsistent concentrations will result from Repeat DISPENSE.Please check plate configuration or combine both additions into one" % (Component.name,self.alpha,self.num))
raise inconsistent_conc_warning
voltoadd = (self.vol * finalconc)/(Component.stockconc)
# print "Adding %s of\t%s to well %s,%s get a conc of\t%s" % (voltoadd,Component.name,self.alpha,self.num,finalconc)
Component.deplete(voltoadd)
self.wellcomponentdict[Component.name] = voltoadd
self.deplete(voltoadd)
                self.components.append(Component.name)
                self.component_name_object_map[Component.name] = Component
                
def calctotalvol(self):
total = 0
for i in self.wellcomponentdict:
total = total + self.wellcomponentdict[i]
return total
 
def about(self):
aboutstr = "WELL:%s%s\t" % (self.alpha , self.num)
total = self.calctotalvol()
for i in self.wellcomponentdict:
aboutstr = aboutstr + "Component %s : %3.3f " % (i,self.wellcomponentdict[i]) + "Total:%s" % total
return aboutstr
 
 
def fillwithwater(self,Component):
key = Component.name
newname = "100.00 % Water"
if key != "100.00 % Water":
                    Component.name = newname
                if self.volleft == 0:
                    # If the well is already full Do nothing
                    pass
                else:
                    if key not in Well.wellcomponentlist.componentfactory:
                        Well.wellcomponentlist.insertcomponent(Component)
                    self.wellcomponentdict[Component.name] = self.volleft
                    self.component_name_object_map[Component.name] = Component
                    # Fixed Bug when other components were added after Water : and self.volleft was not calling deplete to
                    # update self.volleft
                    # Alternative approach call self.deplete(self.volleft)
                    self.volleft = 0
 
 
def getmastercomponentlist(self):
return Well.wellcomponentlist
 
def main():
import component
w = Well("A",1,2000)
rack = w.getmastercomponentlist()
c1 = component.Component("peg400",50,100)
rack.insertcomponent(c1)
 
c2 = component.Component("CaCl2",2000,100000)
rack.insertcomponent(c2)
 
c = rack.getcomponent("CaCl2")
 
w.addcomponent(c,200)
x = w.about()
print x
 
print "Volume of %s left:%s" % (c.name,c.getmls())
rack.listcontents()
if __name__ == '__main__':
main()