-
Notifications
You must be signed in to change notification settings - Fork 0
/
BufferUtils.R
57 lines (46 loc) · 1.61 KB
/
BufferUtils.R
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
#Buffer utils
# A0 = 1
# HA0 = 1
# pKa = 4.5
buffer = c("AC", "PO", "tris")
pH = c(5.75,7.21,7.12)
pKa = c(4.75,7.21,8.12)
#in Mol/L
HA = c(0.009091,0.05,0.09091)
A = c(0.09091,0.05,0.009091)
data = data.frame(buffer, pH,pKa,HA,A, row.names = buffer)
get_pH = function(A,HA,pKa){
return(pKa + log(A/HA,10))
}
get_A = function(aTot, pH, pKa){
c = 10^(pH-pKa)
return(aTot*c/(1+c))
}
get_buffer_region = function(pH0, pKa, A, HA,bufferName = "n", bufferDelta){
cp = 10^(pH0+bufferDelta-pKa)
bufferCap = (cp*HA - A)/(cp+1)
return(data.frame(bufferName, bufferCap))
}
#buffer Regions in delta Mol/L
bufferRegionsAcid = get_buffer_region(data$pH,data$pKa, data$A, data$HA,bufferName = data$buffer,bufferDelta = -1)
bufferRegionsAcid$bufferCap = bufferRegionsAcid$bufferCap * -1
bufferRegionsBase = get_buffer_region(data$pH,data$pKa, data$A, data$HA,bufferName = data$buffer,bufferDelta = 1)
#calculate back to pH
#default
get_pH(data$A,data$HA,data$pKa)
#acidic
get_pH(data$A - bufferRegionsAcid$bufferCap,data$HA + bufferRegionsAcid$bufferCap,data$pKa)
#basic
get_pH(data$A + bufferRegionsBase$bufferCap,data$HA - bufferRegionsBase$bufferCap,data$pKa)
#bufferRegions in delta mmol
sampleSize = 5 #in mL
bufferRegionsAcid$bufferCap = sampleSize *bufferRegionsAcid$bufferCap
bufferRegionsBase$bufferCap = sampleSize *bufferRegionsBase$bufferCap
#Calculate in mL
#concentrations in Mol/L
ConcentrationBase = 0.00891
ConcentrationAcid = 0.01
bufferRegionsAcid$bufferCap = bufferRegionsAcid$bufferCap/ConcentrationAcid
bufferRegionsBase$bufferCap = bufferRegionsBase$bufferCap/ConcentrationBase
bufferRegionsAcid
bufferRegionsBase