signature:
def Tm ( counts ) :
    r'''Estimates the melting temperature of an organic compound using the
 Joback method as a function of chemical structure only .
 . . math : :
 T _ m = 122.5 + \ sum _ i { T _ { m , i } }
 For 388 compounds tested by Joback , the absolute average error was
 22.6 K and standard deviation was 24.68 K ; the average relative error
 was 11.2 % .
 Parameters
 counts : dict
 Dictionary of Joback groups present ( numerically indexed ) and their
 counts , [ - ]
 Returns
 Tm : float
 Estimated melting temperature , [ K ]
 Examples
 > > > Joback . Tm ( { 1 : 2 , 24 : 1 } )
 173.5'''

implementation:
tot = 0.0
for group , count in counts . items ( ) :
    tot += joback_groups_id_dict [ group ] . Tm * count
Tm = 122.5 + tot
return Tm


signature:
def Tc ( counts , Tb = None ) :
    r'''Estimates the critcal temperature of an organic compound using the
 Joback method as a function of chemical structure only , or optionally
 improved by using an experimental boiling point . If the experimental
 boiling point is not provided it will be estimated with the Joback
 method as well .
 . . math : :
 T _ c = T _ b \ left [ 0.584 + 0.965 \ sum _ i { T _ { c , i } }
 - \ left ( \ sum _ i { T _ { c , i } } \ right ) ^ 2 \ right ] ^ { - 1}
 For 409 compounds tested by Joback , the absolute average error was
 4.76 K and standard deviation was 6.94 K ; the average relative error
 was 0.81 % .
 Appendix BI of Joback ' s work lists 409 estimated critical temperatures .
 Parameters
 counts : dict
 Dictionary of Joback groups present ( numerically indexed ) and their
 counts , [ - ]
 Tb : float , optional
 Experimental normal boiling temperature , [ K ]
 Returns
 Tc : float
 Estimated critical temperature , [ K ]
 Examples
 > > > Joback . Tc ( { 1 : 2 , 24 : 1 } , Tb = 322.11)
 500.5590049525365'''

implementation:
if Tb is None :
    Tb = Joback . Tb ( counts )
tot = 0.0
for group , count in counts . items ( ) :
    tot += joback_groups_id_dict [ group ] . Tc * count
Tc = Tb / ( 0.584 + 0.965 * tot - tot * tot )
return Tc


signature:
def Pc ( counts , atom_count ) :
    r'''Estimates the critcal pressure of an organic compound using the
 Joback method as a function of chemical structure only . This
 correlation was developed using the actual number of atoms forming
 the molecule as well .
 . . math : :
 P _ c = \ left [ 0.113 + 0.0032N _ A - \ sum _ i { P _ { c , i } } \ right ] ^ { - 2}
 In the above equation , critical pressure is calculated in bar ; it is
 converted to Pa here .
 392 compounds were used by Joback in this determination , with an
 absolute average error of 2.06 bar , standard devaition 3.2 bar , and
 AARE of 5.2 % .
 Parameters
 counts : dict
 Dictionary of Joback groups present ( numerically indexed ) and their
 counts , [ - ]
 atom _ count : int
 Total number of atoms ( including hydrogens ) in the molecule , [ - ]
 Returns
 Pc : float
 Estimated critical pressure , [ Pa ]
 Examples
 > > > Joback . Pc ( { 1 : 2 , 24 : 1 } , 10)
 4802499.604994407'''

implementation:
tot = 0.0
for group , count in counts . items ( ) :
    tot += joback_groups_id_dict [ group ] . Pc * count
Pc = ( 0.113 + 0.0032 * atom_count - tot ) ** - 2
return Pc * 1E5


signature:
def Vc ( counts ) :
    r'''Estimates the critcal volume of an organic compound using the
 Joback method as a function of chemical structure only .
 . . math : :
 V _ c = 17.5 + \ sum _ i { V _ { c , i } }
 In the above equation , critical volume is calculated in cm ^ 3 / mol ; it
 is converted to m ^ 3 / mol here .
 310 compounds were used by Joback in this determination , with an
 absolute average error of 7.54 cm ^ 3 / mol , standard devaition 13.16
 cm ^ 3 / mol , and AARE of 2.27 % .
 Parameters
 counts : dict
 Dictionary of Joback groups present ( numerically indexed ) and their
 counts , [ - ]
 Returns
 Vc : float
 Estimated critical volume , [ m ^ 3 / mol ]
 Examples
 > > > Joback . Vc ( { 1 : 2 , 24 : 1 } )
 0.0002095'''

implementation:
tot = 0.0
for group , count in counts . items ( ) :
    tot += joback_groups_id_dict [ group ] . Vc * count
Vc = 17.5 + tot
return Vc * 1E-6


signature:
def Hf ( counts ) :
    r'''Estimates the ideal - gas enthalpy of formation at 298.15 K of an
 organic compound using the Joback method as a function of chemical
 structure only .
 . . math : :
 H _ { formation } = 68.29 + \ sum _ i { H _ { f , i } }
 In the above equation , enthalpy of formation is calculated in kJ / mol ;
 it is converted to J / mol here .
 370 compounds were used by Joback in this determination , with an
 absolute average error of 2.2 kcal / mol , standard devaition 2.0
 kcal / mol , and AARE of 15.2 % .
 Parameters
 counts : dict
 Dictionary of Joback groups present ( numerically indexed ) and their
 counts , [ - ]
 Returns
 Hf : float
 Estimated ideal - gas enthalpy of formation at 298.15 K , [ J / mol ]
 Examples
 > > > Joback . Hf ( { 1 : 2 , 24 : 1 } )
 -217829.999997'''

implementation:
tot = 0.0
for group , count in counts . items ( ) :
    tot += joback_groups_id_dict [ group ] . Hform * count
Hf = 68.29 + tot
return Hf * 1000


signature:
def Gf ( counts ) :
    r'''Estimates the ideal - gas Gibbs energy of formation at 298.15 K of an
 organic compound using the Joback method as a function of chemical
 structure only .
 . . math : :
 G _ { formation } = 53.88 + \ sum { G _ { f , i } }
 In the above equation , Gibbs energy of formation is calculated in
 kJ / mol ; it is converted to J / mol here .
 328 compounds were used by Joback in this determination , with an
 absolute average error of 2.0 kcal / mol , standard devaition 4.37
 kcal / mol , and AARE of 15.7 % .
 Parameters
 counts : dict
 Dictionary of Joback groups present ( numerically indexed ) and their
 counts , [ - ]
 Returns
 Gf : float
 Estimated ideal - gas Gibbs energy of formation at 298.15 K , [ J / mol ]
 Examples
 > > > Joback . Gf ( { 1 : 2 , 24 : 1 } )
 -154540.000003'''

implementation:
tot = 0.0
for group , count in counts . items ( ) :
    tot += joback_groups_id_dict [ group ] . Gform * count
Gf = 53.88 + tot
return Gf * 1000


signature:
def Hfus ( counts ) :
    r'''Estimates the enthalpy of fusion of an organic compound at its
 melting point using the Joback method as a function of chemical
 structure only .
 . . math : :
 \ Delta H _ { fus } = - 0.88 + \ sum _ i H _ { fus , i }
 In the above equation , enthalpy of fusion is calculated in
 kJ / mol ; it is converted to J / mol here .
 For 155 compounds tested by Joback , the absolute average error was
 485.2 cal / mol and standard deviation was 661.4 cal / mol ; the average
 relative error was 38.7 % .
 Parameters
 counts : dict
 Dictionary of Joback groups present ( numerically indexed ) and their
 counts , [ - ]
 Returns
 Hfus : float
 Estimated enthalpy of fusion of the compound at its melting point ,
 [ J / mol ]
 Examples
 > > > Joback . Hfus ( { 1 : 2 , 24 : 1 } )
 5125.0'''

implementation:
tot = 0.0
for group , count in counts . items ( ) :
    tot += joback_groups_id_dict [ group ] . Hfus * count
Hfus = - 0.88 + tot
return Hfus * 1000


signature:
def Hvap ( counts ) :
    r'''Estimates the enthalpy of vaporization of an organic compound at
 its normal boiling point using the Joback method as a function of
 chemical structure only .
 . . math : :
 \ Delta H _ { vap } = 15.30 + \ sum _ i H _ { vap , i }
 In the above equation , enthalpy of fusion is calculated in
 kJ / mol ; it is converted to J / mol here .
 For 368 compounds tested by Joback , the absolute average error was
 303.5 cal / mol and standard deviation was 429 cal / mol ; the average
 relative error was 3.88 % .
 Parameters
 counts : dict
 Dictionary of Joback groups present ( numerically indexed ) and their
 counts , [ - ]
 Returns
 Hvap : float
 Estimated enthalpy of vaporization of the compound at its normal
 boiling point , [ J / mol ]
 Examples
 > > > Joback . Hvap ( { 1 : 2 , 24 : 1 } )
 29018.0'''

implementation:
tot = 0.0
for group , count in counts . items ( ) :
    tot += joback_groups_id_dict [ group ] . Hvap * count
Hvap = 15.3 + tot
return Hvap * 1000


signature:
def Cpig_coeffs ( counts ) :
    r'''Computes the ideal - gas polynomial heat capacity coefficients
 of an organic compound using the Joback method as a function of
 chemical structure only .
 . . math : :
 C _ p ^ { ig } = \ sum _ i a _ i - 37.93 + \ left [ \ sum _ i b _ i + 0.210 \ right ] T
 + \ left [ \ sum _ i c _ i - 3.91 \ cdot 10 ^ { - 4 } \ right ] T ^ 2
 + \ left [ \ sum _ i d _ i + 2.06 \ cdot 10 ^ { - 7 } \ right ] T ^ 3
 288 compounds were used by Joback in this determination . No overall
 error was reported .
 The ideal gas heat capacity values used in developing the heat
 capacity polynomials used 9 data points between 298 K and 1000 K .
 Parameters
 counts : dict
 Dictionary of Joback groups present ( numerically indexed ) and their
 counts , [ - ]
 Returns
 coefficients : list [ float ]
 Coefficients which will result in a calculated heat capacity in
 in units of J / mol / K , [ - ]
 Examples
 > > > c = Joback . Cpig _ coeffs ( { 1 : 2 , 24 : 1 } )
 [7.52000003 , 0.26084 , - 0.0001207 , 1.545999998e - 08]
 > > > Cp = lambda T : c [ 0 ] + c [ 1 ] * T + c [ 2 ] * T * * 2 + c [ 3 ] * T * * 3
 > > > Cp ( 300)
 75.32642000001'''

implementation:
a , b , c , d = 0.0 , 0.0 , 0.0 , 0.0
for group , count in counts . items ( ) :
    a += joback_groups_id_dict [ group ] . Cpa * count
    b += joback_groups_id_dict [ group ] . Cpb * count
    c += joback_groups_id_dict [ group ] . Cpc * count
    d += joback_groups_id_dict [ group ] . Cpd * count
a -= 37.93
b += 0.210
c -= 3.91E-4
d += 2.06E-7
return [ a , b , c , d ]


signature:
def mul_coeffs ( counts ) :
    r'''Computes the liquid phase viscosity Joback coefficients
 of an organic compound using the Joback method as a function of
 chemical structure only .
 . . math : :
 \ mu _ { liq } = \ text { MW } \ exp \ left ( \ frac { \ sum _ i \ mu _ a - 597.82 } { T }
 + \ sum _ i \ mu _ b - 11.202 \ right )
 288 compounds were used by Joback in this determination . No overall
 error was reported .
 The liquid viscosity data used was specified to be at " several
 temperatures for each compound " only . A small and unspecified number
 of compounds were used in this estimation .
 Parameters
 counts : dict
 Dictionary of Joback groups present ( numerically indexed ) and their
 counts , [ - ]
 Returns
 coefficients : list [ float ]
 Coefficients which will result in a liquid viscosity in
 in units of Pa * s , [ - ]
 Examples
 > > > mu _ ab = Joback . mul _ coeffs ( { 1 : 2 , 24 : 1 } )
 > > > mu _ ab
 [839.10999998 , - 14.99]
 > > > MW = 58.041864812
 > > > mul = lambda T : MW * exp ( mu _ ab [ 0 ] / T + mu _ ab [ 1 ] )
 > > > mul ( 300)
 0.0002940378347162687'''

implementation:
a , b = 0.0 , 0.0
for group , count in counts . items ( ) :
    a += joback_groups_id_dict [ group ] . mua * count
    b += joback_groups_id_dict [ group ] . mub * count
a -= 597.82
b -= 11.202
return [ a , b ]


signature:
def Cpig ( self , T ) :
    r'''Computes ideal - gas heat capacity at a specified temperature
 of an organic compound using the Joback method as a function of
 chemical structure only .
 . . math : :
 C _ p ^ { ig } = \ sum _ i a _ i - 37.93 + \ left [ \ sum _ i b _ i + 0.210 \ right ] T
 + \ left [ \ sum _ i c _ i - 3.91 \ cdot 10 ^ { - 4 } \ right ] T ^ 2
 + \ left [ \ sum _ i d _ i + 2.06 \ cdot 10 ^ { - 7 } \ right ] T ^ 3
 Parameters
 T : float
 Temperature , [ K ]
 Returns
 Cpig : float
 Ideal - gas heat capacity , [ J / mol / K ]
 Examples
 > > > J = Joback ( ' CC ( = O ) C ' )
 > > > J . Cpig ( 300)
 75.32642000001'''

implementation:
if self . calculated_Cpig_coeffs is None :
    self . calculated_Cpig_coeffs = Joback . Cpig_coeffs ( self . counts )
return horner ( reversed ( self . calculated_Cpig_coeffs ) , T )


signature:
def mul ( self , T ) :
    r'''Computes liquid viscosity at a specified temperature
 of an organic compound using the Joback method as a function of
 chemical structure only .
 . . math : :
 \ mu _ { liq } = \ text { MW } \ exp \ left ( \ frac { \ sum _ i \ mu _ a - 597.82 } { T }
 + \ sum _ i \ mu _ b - 11.202 \ right )
 Parameters
 T : float
 Temperature , [ K ]
 Returns
 mul : float
 Liquid viscosity , [ Pa * s ]
 Examples
 > > > J = Joback ( ' CC ( = O ) C ' )
 > > > J . mul ( 300)
 0.0002940378347162687'''

implementation:
if self . calculated_mul_coeffs is None :
    self . calculated_mul_coeffs = Joback . mul_coeffs ( self . counts )
a , b = self . calculated_mul_coeffs
return self . MW * exp ( a / T + b )


signature:
def Laliberte_viscosity_i ( T , w_w , v1 , v2 , v3 , v4 , v5 , v6 ) :
    r'''Calculate the viscosity of a solute using the form proposed by [ 1 ] _
 Parameters are needed , and a temperature . Units are Kelvin and Pa * s .
 . . math : :
 \ mu _ i = \ frac { \ exp \ left ( \ frac { v _ 1(1 - w _ w ) ^ { v _ 2 } + v _ 3 } { v _ 4 t + 1 } \ right ) }
 { v _ 5(1 - w _ w ) ^ { v _ 6 } + 1}
 Parameters
 T : float
 Temperature of fluid [ K ]
 w _ w : float
 Weight fraction of water in the solution
 v1 - v6 : floats
 Function fit parameters
 Returns
 mu _ i : float
 Solute partial viscosity , Pa * s
 Notes
 Temperature range check is outside of this function .
 Check is performed using NaCl at 5 degC from the first value in [ 1 ] _ ' s spreadsheet .
 Examples
 > > > d = _ Laliberte _ Viscosity _ ParametersDict [ ' 7647-14-5 ' ]
 > > > Laliberte _ viscosity _ i ( 273.15 + 5 , 1-0.005810 , d [ " V1 " ] , d [ " V2 " ] , d [ " V3 " ] , d [ " V4 " ] , d [ " V5 " ] , d [ " V6 " ] )
 0.004254025533308794
 References
 . . [ 1 ] Laliberte , Marc . " A Model for Calculating the Heat Capacity of
 Aqueous Solutions , with Updated Density and Viscosity Data . " Journal of
 Chemical & Engineering Data 54 , no . 6 ( June 11 , 2009 ) : 1725-60.
 doi : 10.1021 / je8008123'''


signature:
def Laliberte_viscosity ( T , ws , CASRNs ) :
    r'''Calculate the viscosity of an aqueous mixture using the form proposed by [ 1 ] _ .
 Parameters are loaded by the function as needed . Units are Kelvin and Pa * s .
 . . math : :
 \ mu _ m = \ mu _ w ^ { w _ w } \ Pi \ mu _ i ^ { w _ i }
 Parameters
 T : float
 Temperature of fluid [ K ]
 ws : array
 Weight fractions of fluid components other than water
 CASRNs : array
 CAS numbers of the fluid components other than water
 Returns
 mu _ i : float
 Solute partial viscosity , Pa * s
 Notes
 Temperature range check is not used here .
 Check is performed using NaCl at 5 degC from the first value in [ 1 ] _ ' s spreadsheet .
 Examples
 > > > Laliberte _ viscosity ( 273.15 + 5 , [ 0.005810 ] , [ ' 7647-14-5 ' ] )
 0.0015285828581961414
 References
 . . [ 1 ] Laliberte , Marc . " A Model for Calculating the Heat Capacity of
 Aqueous Solutions , with Updated Density and Viscosity Data . " Journal of
 Chemical & Engineering Data 54 , no . 6 ( June 11 , 2009 ) : 1725-60.
 doi : 10.1021 / je8008123'''

implementation:
mu_w = Laliberte_viscosity_w ( T ) * 1000.
w_w = 1 - sum ( ws )
mu = mu_w ** ( w_w )
for i in range ( len ( CASRNs ) ) :
    d = _Laliberte_Viscosity_ParametersDict [ CASRNs [ i ] ]
    mu_i = Laliberte_viscosity_i ( T , w_w , d [ "V1" ] , d [ "V2" ] , d [ "V3" ] , d [ "V4" ] , d [ "V5" ] , d [ "V6" ] ) * 1000.
    mu = mu_i ** ( ws [ i ] ) * mu
return mu / 1000.


signature:
def Laliberte_density_w ( T ) :
    r'''Calculate the density of water using the form proposed by [ 1 ] _ .
 No parameters are needed , just a temperature . Units are Kelvin and kg / m ^ 3h .
 . . math : :
 \ rho _ w = \ frac { \ left \ { \ left ( [ ( - 2.8054253 \ times 10 ^ { - 10 } \ cdot t +
 1.0556302 \ times 10 ^ { - 7 } ) t - 4.6170461 \ times 10 ^ { - 5 } ] t
 -0.0079870401 \ right ) t + 16.945176 \ right \ } t + 999.83952}
 {1 + 0.01687985 \ cdot t }
 Parameters
 T : float
 Temperature of fluid [ K ]
 Returns
 rho _ w : float
 Water density , [ kg / m ^ 3]
 Notes
 Original source not cited
 No temperature range is used .
 Examples
 > > > Laliberte _ density _ w ( 298.15)
 997.0448954179155
 > > > Laliberte _ density _ w ( 273.15 + 50)
 988.0362916114763
 References
 . . [ 1 ] Laliberte , Marc . " A Model for Calculating the Heat Capacity of
 Aqueous Solutions , with Updated Density and Viscosity Data . " Journal of
 Chemical & Engineering Data 54 , no . 6 ( June 11 , 2009 ) : 1725-60.
 doi : 10.1021 / je8008123'''


signature:
def Laliberte_density_i ( T , w_w , c0 , c1 , c2 , c3 , c4 ) :
    r'''Calculate the density of a solute using the form proposed by Laliberte [ 1 ] _ .
 Parameters are needed , and a temperature , and water fraction . Units are Kelvin and Pa * s .
 . . math : :
 \ rho _ { app , i } = \ frac { ( c _ 0[1 - w _ w ] + c _ 1 ) \ exp ( 10 ^ { - 6 } [ t + c _ 4 ] ^ 2 ) }
 { ( 1 - w _ w ) + c _ 2 + c _ 3 t }
 Parameters
 T : float
 Temperature of fluid [ K ]
 w _ w : float
 Weight fraction of water in the solution
 c0 - c4 : floats
 Function fit parameters
 Returns
 rho _ i : float
 Solute partial density , [ kg / m ^ 3]
 Notes
 Temperature range check is TODO
 Examples
 > > > d = _ Laliberte _ Density _ ParametersDict [ ' 7647-14-5 ' ]
 > > > Laliberte _ density _ i ( 273.15 + 0 , 1-0.0037838838 , d [ " C0 " ] , d [ " C1 " ] , d [ " C2 " ] , d [ " C3 " ] , d [ " C4 " ] )
 3761.8917585699983
 References
 . . [ 1 ] Laliberte , Marc . " A Model for Calculating the Heat Capacity of
 Aqueous Solutions , with Updated Density and Viscosity Data . " Journal of
 Chemical & Engineering Data 54 , no . 6 ( June 11 , 2009 ) : 1725-60.
 doi : 10.1021 / je8008123'''


signature:
def Laliberte_density ( T , ws , CASRNs ) :
    r'''Calculate the density of an aqueous electrolyte mixture using the form proposed by [ 1 ] _ .
 Parameters are loaded by the function as needed . Units are Kelvin and Pa * s .
 . . math : :
 \ rho _ m = \ left ( \ frac { w _ w } { \ rho _ w } + \ sum _ i \ frac { w _ i } { \ rho _ { app _ i } } \ right ) ^ { - 1}
 Parameters
 T : float
 Temperature of fluid [ K ]
 ws : array
 Weight fractions of fluid components other than water
 CASRNs : array
 CAS numbers of the fluid components other than water
 Returns
 rho _ i : float
 Solution density , [ kg / m ^ 3]
 Notes
 Temperature range check is not used here .
 Examples
 > > > Laliberte _ density ( 273.15 , [ 0.0037838838 ] , [ ' 7647-14-5 ' ] )
 1002.6250120185854
 References
 . . [ 1 ] Laliberte , Marc . " A Model for Calculating the Heat Capacity of
 Aqueous Solutions , with Updated Density and Viscosity Data . " Journal of
 Chemical & Engineering Data 54 , no . 6 ( June 11 , 2009 ) : 1725-60.
 doi : 10.1021 / je8008123'''

implementation:
rho_w = Laliberte_density_w ( T )
w_w = 1 - sum ( ws )
rho = w_w / rho_w
for i in range ( len ( CASRNs ) ) :
    d = _Laliberte_Density_ParametersDict [ CASRNs [ i ] ]
    rho_i = Laliberte_density_i ( T , w_w , d [ "C0" ] , d [ "C1" ] , d [ "C2" ] , d [ "C3" ] , d [ "C4" ] )
    rho = rho + ws [ i ] / rho_i
return 1. / rho


signature:
def Laliberte_heat_capacity_i ( T , w_w , a1 , a2 , a3 , a4 , a5 , a6 ) :
    r'''Calculate the heat capacity of a solute using the form proposed by [ 1 ] _
 Parameters are needed , and a temperature , and water fraction .
 . . math : :
 Cp _ i = a _ 1 e ^ \ alpha + a _ 5(1 - w _ w ) ^ { a _ 6}
 \ alpha = a _ 2 t + a _ 3 \ exp ( 0.01t ) + a _ 4(1 - w _ w )
 Parameters
 T : float
 Temperature of fluid [ K ]
 w _ w : float
 Weight fraction of water in the solution
 a1 - a6 : floats
 Function fit parameters
 Returns
 Cp _ i : float
 Solute partial heat capacity , [ J / kg / K ]
 Notes
 Units are Kelvin and J / kg / K .
 Temperature range check is TODO
 Examples
 > > > d = _ Laliberte _ Heat _ Capacity _ ParametersDict [ ' 7647-14-5 ' ]
 > > > Laliberte _ heat _ capacity _ i ( 1.5 + 273.15 , 1-0.00398447 , d [ " A1 " ] , d [ " A2 " ] , d [ " A3 " ] , d [ " A4 " ] , d [ " A5 " ] , d [ " A6 " ] )
 -2930.7353945880477
 References
 . . [ 1 ] Laliberte , Marc . " A Model for Calculating the Heat Capacity of
 Aqueous Solutions , with Updated Density and Viscosity Data . " Journal of
 Chemical & Engineering Data 54 , no . 6 ( June 11 , 2009 ) : 1725-60.
 doi : 10.1021 / je8008123'''


signature:
def Laliberte_heat_capacity ( T , ws , CASRNs ) :
    r'''Calculate the heat capacity of an aqueous electrolyte mixture using the
 form proposed by [ 1 ] _ .
 Parameters are loaded by the function as needed .
 . . math : :
 TODO
 Parameters
 T : float
 Temperature of fluid [ K ]
 ws : array
 Weight fractions of fluid components other than water
 CASRNs : array
 CAS numbers of the fluid components other than water
 Returns
 Cp : float
 Solution heat capacity , [ J / kg / K ]
 Notes
 Temperature range check is not implemented .
 Units are Kelvin and J / kg / K .
 Examples
 > > > Laliberte _ heat _ capacity ( 273.15 + 1.5 , [ 0.00398447 ] , [ ' 7647-14-5 ' ] )
 4186.569908672113
 References
 . . [ 1 ] Laliberte , Marc . " A Model for Calculating the Heat Capacity of
 Aqueous Solutions , with Updated Density and Viscosity Data . " Journal of
 Chemical & Engineering Data 54 , no . 6 ( June 11 , 2009 ) : 1725-60.
 doi : 10.1021 / je8008123'''

implementation:
Cp_w = Laliberte_heat_capacity_w ( T )
w_w = 1 - sum ( ws )
Cp = w_w * Cp_w
for i in range ( len ( CASRNs ) ) :
    d = _Laliberte_Heat_Capacity_ParametersDict [ CASRNs [ i ] ]
    Cp_i = Laliberte_heat_capacity_i ( T , w_w , d [ "A1" ] , d [ "A2" ] , d [ "A3" ] , d [ "A4" ] , d [ "A5" ] , d [ "A6" ] )
    Cp = Cp + ws [ i ] * Cp_i
return Cp


signature:
def dilute_ionic_conductivity ( ionic_conductivities , zs , rhom ) :
    r'''This function handles the calculation of the electrical conductivity of
 a dilute electrolytic aqueous solution . Requires the mole fractions of
 each ion , the molar density of the whole mixture , and ionic conductivity
 coefficients for each ion .
 . . math : :
 \ lambda = \ sum _ i \ lambda _ i ^ \ circ z _ i \ rho _ m
 Parameters
 ionic _ conductivities : list [ float ]
 Ionic conductivity coefficients of each ion in the mixture [ m ^ 2 * S / mol ]
 zs : list [ float ]
 Mole fractions of each ion in the mixture , [ - ]
 rhom : float
 Overall molar density of the solution , [ mol / m ^ 3]
 Returns
 kappa : float
 Electrical conductivity of the fluid , [ S / m ]
 Notes
 The ionic conductivity coefficients should not be ` equivalent ` coefficients ;
 for example , 0.0053 m ^ 2 * S / mol is the equivalent conductivity coefficient of
 Mg + 2 , but this method expects twice its value - 0.0106 . Both are reported
 commonly in literature .
 Water can be included in this caclulation by specifying a coefficient of
 0 . The conductivity of any electrolyte eclipses its own conductivity by
 many orders of magnitude . Any other solvents present will affect the
 conductivity extensively and there are few good methods to predict this
 effect .
 Examples
 Complex mixture of electrolytes [ ' Cl - ' , ' HCO3 - ' , ' SO4-2 ' , ' Na + ' , ' K + ' ,
 ' Ca + 2 ' , ' Mg + 2 ' ] :
 > > > ionic _ conductivities = [ 0.00764 , 0.00445 , 0.016 , 0.00501 , 0.00735 , 0.0119 , 0.01061]
 > > > zs = [ 0.03104 , 0.00039 , 0.00022 , 0.02413 , 0.0009 , 0.0024 , 0.00103]
 > > > dilute _ ionic _ conductivity ( ionic _ conductivities = ionic _ conductivities , zs = zs , rhom = 53865.9)
 22.05246783663
 References
 . . [ 1 ] Haynes , W . M . , Thomas J . Bruno , and David R . Lide . CRC Handbook of
 Chemistry and Physics , 95E . Boca Raton , FL : CRC press , 2014.'''

implementation: return sum ( [ ci * ( zi * rhom ) for zi , ci in zip ( zs , ionic_conductivities ) ] )


signature:
def conductivity_McCleskey ( T , M , lambda_coeffs , A_coeffs , B , multiplier , rho = 1000. ) :
    r'''This function handles the calculation of the electrical conductivity of
 an electrolytic aqueous solution with one electrolyte in solution . It
 handles temperature dependency and concentrated solutions . Requires the
 temperature of the solution ; its molality , and four sets of coefficients
 ` lambda _ coeffs ` , ` A _ coeffs ` , ` B ` , and ` multiplier ` .
 . . math : :
 \ Lambda = \ frac { \ kappa } { C }
 \ Lambda = \ Lambda ^ 0 ( t ) - A ( t ) \ frac { m ^ { 1/2 } } { 1 + Bm ^ { 1/2 } }
 \ Lambda ^ \ circ ( t ) = c _ 1 t ^ 2 + c _ 2 t + c _ 3
 A ( t ) = d _ 1 t ^ 2 + d _ 2 t + d _ 3
 In the above equations , ` t ` is temperature in degrees Celcius ;
 ` m ` is molality in mol / kg , and C is the concentration of the elctrolytes
 in mol / m ^ 3 , calculated as the product of density and molality .
 Parameters
 T : float
 Temperature of the solution , [ K ]
 M : float
 Molality of the solution with respect to one electrolyte
 ( mol solute / kg solvent ) , [ mol / kg ]
 lambda _ coeffs : list [ float ]
 List of coefficients for the polynomial used to calculate ` lambda ` ;
 length - 3 coefficients provided in [ 1 ] _ , [ - ]
 A _ coeffs : list [ float ]
 List of coefficients for the polynomial used to calculate ` A ` ;
 length - 3 coefficients provided in [ 1 ] _ , [ - ]
 B : float
 Empirical constant for an electrolyte , [ - ]
 multiplier : float
 The multiplier to obtain the absolute conductivity from the equivalent
 conductivity ; ex 2 for CaCl2 , [ - ]
 rho : float , optional
 The mass density of the aqueous mixture , [ kg / m ^ 3]
 Returns
 kappa : float
 Electrical conductivity of the solution at the specified molality and
 temperature [ S / m ]
 Notes
 Coefficients provided in [ 1 ] _ result in conductivity being calculated in
 units of mS / cm ; they are converted to S / m before returned .
 Examples
 A 0.5 wt % solution of CaCl2 , conductivity calculated in mS / cm
 > > > conductivity _ McCleskey ( T = 293.15 , M = 0.045053 , A _ coeffs = [ . 03918 , 3.905,
 . . . 137.7 ] , lambda _ coeffs = [ 0.01124 , 2.224 , 72.36 ] , B = 3.8 , multiplier = 2)
 0.8482584585108555
 References
 . . [ 1 ] McCleskey , R . Blaine . " Electrical Conductivity of Electrolytes Found
 In Natural Waters from ( 5 to 90 ) ° C . " Journal of Chemical & Engineering
 Data 56 , no . 2 ( February 10 , 2011 ) : 317-27 . doi : 10.1021 / je101012n .'''

implementation:
t = T - 273.15
lambda_coeff = horner ( lambda_coeffs , t )
A = horner ( A_coeffs , t )
M_root = M ** 0.5
param = lambda_coeff - A * M_root / ( 1. + B * M_root )
C = M * rho / 1000.
# convert to mol / L to get concentration
return param * C * multiplier * 0.1


signature:
def conductivity ( CASRN = None , AvailableMethods = False , Method = None , full_info = True ) :
    r'''This function handles the retrieval of a chemical ' s conductivity .
 Lookup is based on CASRNs . Will automatically select a data source to use
 if no Method is provided ; returns None if the data is not available .
 Function has data for approximately 100 chemicals .
 Parameters
 CASRN : string
 CASRN [ - ]
 Returns
 kappa : float
 Electrical conductivity of the fluid , [ S / m ]
 T : float , only returned if full _ info = = True
 Temperature at which conductivity measurement was made
 methods : list , only returned if AvailableMethods = = True
 List of methods which can be used to obtain RI with the given inputs
 Other Parameters
 Method : string , optional
 A string for the method name to use , as defined by constants in
 conductivity _ methods
 AvailableMethods : bool , optional
 If True , function will determine which methods can be used to obtain
 conductivity for the desired chemical , and will return methods instead
 of conductivity
 full _ info : bool , optional
 If True , function will return the temperature at which the conductivity
 reading was made
 Notes
 Only one source is available in this function . It is :
 * ' LANGE _ COND ' which is from Lange ' s Handbook , Table 8.34 Electrical
 Conductivity of Various Pure Liquids ' , a compillation of data in [ 1 ] _ .
 Examples
 > > > conductivity ( ' 7732-18-5 ' )
 (4e - 06 , 291.15)
 References
 . . [ 1 ] Speight , James . Lange ' s Handbook of Chemistry . 16 edition .
 McGraw - Hill Professional , 2005.'''

implementation:
def list_methods ( ) :
    methods = [ ]
    if CASRN in Lange_cond_pure . index :
        methods . append ( LANGE_COND )
    methods . append ( NONE )
    return methods
if AvailableMethods :
    return list_methods ( )
if not Method :
    Method = list_methods ( ) [ 0 ]
if Method == LANGE_COND :
    kappa = float ( Lange_cond_pure . at [ CASRN , 'Conductivity' ] )
    if full_info :
        T = float ( Lange_cond_pure . at [ CASRN , 'T' ] )
elif Method == NONE :
    kappa , T = None , None
else :
    raise Exception ( 'Failure in in function' )
if full_info :
    return kappa , T
else :
    return kappa


signature:
def thermal_conductivity_Magomedov ( T , P , ws , CASRNs , k_w = None ) :
    r'''Calculate the thermal conductivity of an aqueous mixture of
 electrolytes using the form proposed by Magomedov [ 1 ] _ .
 Parameters are loaded by the function as needed . Function will fail if an
 electrolyte is not in the database .
 . . math : :
 \ lambda = \ lambda _ w \ left [ 1 - \ sum _ { i = 1 } ^ n A _ i ( w _ i + 2 \ times10 ^ { - 4}
 w _ i ^ 3 ) \ right ] - 2 \ times10 ^ { - 8 } PT \ sum _ { i = 1 } ^ n w _ i
 Parameters
 T : float
 Temperature of liquid [ K ]
 P : float
 Pressure of the liquid [ Pa ]
 ws : array
 Weight fractions of liquid components other than water
 CASRNs : array
 CAS numbers of the liquid components other than water
 k _ w : float
 Liquid thermal condiuctivity or pure water at T and P , [ W / m / K ]
 Returns
 kl : float
 Liquid thermal condiuctivity , [ W / m / K ]
 Notes
 Range from 273 K to 473 K , P from 0.1 MPa to 100 MPa . C from 0 to 25 mass % .
 Internal untis are MPa for pressure and weight percent .
 An example is sought for this function . It is not possible to reproduce
 the author ' s values consistently .
 Examples
 > > > thermal _ conductivity _ Magomedov ( 293 . , 1E6 , [ . 25 ] , [ ' 7758-94-3 ' ] , k _ w = 0.59827)
 0.548654049375
 References
 . . [ 1 ] Magomedov , U . B . " The Thermal Conductivity of Binary and
 Multicomponent Aqueous Solutions of Inorganic Substances at High
 Parameters of State . " High Temperature 39 , no . 2 ( March 1 , 2001 ) :
 221-26 . doi : 10.1023 / A : 1017518731726.'''

implementation:
P = P / 1E6
ws = [ i * 100 for i in ws ]
if not k_w :
    raise Exception ( 'k_w correlation must be provided' )
sum1 = 0
for i , CASRN in enumerate ( CASRNs ) :
    Ai = float ( Magomedovk_thermal_cond . at [ CASRN , 'Ai' ] )
    sum1 += Ai * ( ws [ i ] + 2E-4 * ws [ i ] ** 3 )
return k_w * ( 1 - sum1 ) - 2E-8 * P * T * sum ( ws )


signature:
def ionic_strength ( mis , zis ) :
    r'''Calculate the ionic strength of a solution in one of two ways ,
 depending on the inputs only . For Pitzer and Bromley models ,
 ` mis ` should be molalities of each component . For eNRTL models ,
 ` mis ` should be mole fractions of each electrolyte in the solution .
 This will sum to be much less than 1.
 . . math : :
 I = \ frac { 1 } { 2 } \ sum M _ i z _ i ^ 2
 I = \ frac { 1 } { 2 } \ sum x _ i z _ i ^ 2
 Parameters
 mis : list
 Molalities of each ion , or mole fractions of each ion [ mol / kg or - ]
 zis : list
 Charges of each ion [ - ]
 Returns
 I : float
 ionic strength , [ ? ]
 Examples
 > > > ionic _ strength ( [ 0.1393 , 0.1393 ] , [ 1 , - 1 ] )
 0.1393
 References
 . . [ 1 ] Chen , Chau - Chyun , H . I . Britt , J . F . Boston , and L . B . Evans . " Local
 Composition Model for Excess Gibbs Energy of Electrolyte Systems .
 Part I : Single Solvent , Single Completely Dissociated Electrolyte
 Systems . " AIChE Journal 28 , no . 4 ( July 1 , 1982 ) : 588-96.
 doi : 10.1002 / aic . 690280410
 . . [ 2 ] Gmehling , Jurgen . Chemical Thermodynamics : For Process Simulation .
 Weinheim , Germany : Wiley - VCH , 2012.'''

implementation: return 0.5 * sum ( [ mi * zi * zi for mi , zi in zip ( mis , zis ) ] )


signature:
def Kweq_1981 ( T , rho_w ) :
    r'''Calculates equilibrium constant for OH - and H + in water , according to
 [1 ] _ . Second most recent formulation .
 . . math : :
 \ log _ { 10 } K _ w = A + B / T + C / T ^ 2 + D / T ^ 3 + ( E + F / T + G / T ^ 2 ) \ log _ { 10 } \ rho _ w
 Parameters
 T : float
 Temperature of fluid [ K ]
 rho _ w : float
 Density of water , [ kg / m ^ 3]
 Returns
 Kweq : float
 Ionization constant of water , [ - ]
 Notes
 Density is internally converted to units of g / cm ^ 3.
 A = - 4.098;
 B = - 3245.2;
 C = 2.2362E5;
 D = - 3.984E7;
 E = 13.957;
 F = - 1262.3;
 G = 8.5641E5
 Examples
 > > > - 1 * log10 ( Kweq _ 1981(600 , 700 ) )
 11.274522047458206
 References
 . . [ 1 ] Marshall , William L . , and E . U . Franck . " Ion Product of Water
 Substance , 0-1000 degree C , 1010,000 Bars New International Formulation
 and Its Background . " Journal of Physical and Chemical Reference Data 10,
 no . 2 ( April 1 , 1981 ) : 295-304 . doi : 10.1063/1.555643.'''


signature:
def Kweq_IAPWS_gas ( T ) :
    r'''Calculates equilibrium constant for OH - and H + in water vapor ,
 according to [ 1 ] _ .
 This is the most recent formulation available .
 . . math : :
 - log _ { 10 } K _ w ^ G = \ gamma _ 0 + \ gamma _ 1 T ^ { - 1 } + \ gamma _ 2 T ^ { - 2 } + \ gamma _ 3 T ^ { - 3}
 Parameters
 T : float
 Temperature of H2O [ K ]
 Returns
 K _ w _ G : float
 Notes
 gamma0 = 6.141500E - 1;
 gamma1 = 4.825133E4;
 gamma2 = - 6.770793E4;
 gamma3 = 1.010210E7
 Examples
 > > > Kweq _ IAPWS _ gas ( 800)
 1.4379721554798815e - 61
 References
 . . [ 1 ] Bandura , Andrei V . , and Serguei N . Lvov . " The Ionization Constant
 of Water over Wide Ranges of Temperature and Density . " Journal of Physical
 and Chemical Reference Data 35 , no . 1 ( March 1 , 2006 ) : 15-30.
 doi : 10.1063/1.1928231'''


signature:
def Kweq_IAPWS ( T , rho_w ) :
    r'''Calculates equilibrium constant for OH - and H + in water , according to
 [1 ] _ .
 This is the most recent formulation available .
 . . math : :
 Q = \ rho \ exp ( \ alpha _ 0 + \ alpha _ 1 T ^ { - 1 } + \ alpha _ 2 T ^ { - 2 } \ rho ^ { 2/3 } )
 - \ log _ { 10 } K _ w = - 2n \ left [ \ log _ { 10 } ( 1 + Q ) - \ frac { Q } { Q + 1 } \ rho
 ( \ beta _ 0 + \ beta _ 1 T ^ { - 1 } + \ beta _ 2 \ rho ) \ right ]
 - \ log _ { 10 } K _ w ^ G + 2 \ log _ { 10 } \ frac { 18.015268 } { 1000}
 Parameters
 T : float
 Temperature of water [ K ]
 rho _ w : float
 Density of water at temperature and pressure [ kg / m ^ 3]
 Returns
 Kweq : float
 Ionization constant of water , [ - ]
 Notes
 Formulation is in terms of density in g / cm ^ 3 ; density
 is converted internally .
 n = 6;
 alpha0 = - 0.864671;
 alpha1 = 8659.19;
 alpha2 = - 22786.2;
 beta0 = 0.642044;
 beta1 = - 56.8534;
 beta2 = - 0.375754
 Examples
 Example from IAPWS check :
 > > > - 1 * log10 ( Kweq _ IAPWS ( 600 , 700 ) )
 11.203153057603775
 References
 . . [ 1 ] Bandura , Andrei V . , and Serguei N . Lvov . " The Ionization Constant
 of Water over Wide Ranges of Temperature and Density . " Journal of Physical
 and Chemical Reference Data 35 , no . 1 ( March 1 , 2006 ) : 15-30.
 doi : 10.1063/1.1928231'''


signature:
def ion_balance_proportional ( anion_charges , cation_charges , zs , n_anions , n_cations , balance_error , method ) :
    '''Helper method for balance _ ions for the proportional family of methods .
 See balance _ ions for a description of the methods ; parameters are fairly
 obvious .'''

implementation:
anion_zs = zs [ 0 : n_anions ]
cation_zs = zs [ n_anions : n_cations + n_anions ]
anion_balance_error = sum ( [ zi * ci for zi , ci in zip ( anion_zs , anion_charges ) ] )
cation_balance_error = sum ( [ zi * ci for zi , ci in zip ( cation_zs , cation_charges ) ] )
if method == 'proportional insufficient ions increase' :
    if balance_error < 0 :
        multiplier = - anion_balance_error / cation_balance_error
        cation_zs = [ i * multiplier for i in cation_zs ]
    else :
        multiplier = - cation_balance_error / anion_balance_error
        anion_zs = [ i * multiplier for i in anion_zs ]
elif method == 'proportional excess ions decrease' :
    if balance_error < 0 :
        multiplier = - cation_balance_error / anion_balance_error
        anion_zs = [ i * multiplier for i in anion_zs ]
    else :
        multiplier = - anion_balance_error / cation_balance_error
        cation_zs = [ i * multiplier for i in cation_zs ]
elif method == 'proportional cation adjustment' :
    multiplier = - anion_balance_error / cation_balance_error
    cation_zs = [ i * multiplier for i in cation_zs ]
elif method == 'proportional anion adjustment' :
    multiplier = - cation_balance_error / anion_balance_error
    anion_zs = [ i * multiplier for i in anion_zs ]
else :
    raise Exception ( 'Allowable methods are %s' % charge_balance_methods )
z_water = 1. - sum ( anion_zs ) - sum ( cation_zs )
return anion_zs , cation_zs , z_water


signature:
def balance_ions ( anions , cations , anion_zs = None , cation_zs = None , anion_concs = None , cation_concs = None , rho_w = 997.1 , method = 'increase dominant' , selected_ion = None ) :
    r'''Performs an ion balance to adjust measured experimental ion
 compositions to electroneutrality . Can accept either the actual mole
 fractions of the ions , or their concentrations in units of [ mg / L ] as well
 for convinience .
 The default method will locate the most prevalent ion in the type of
 ion not in excess - and increase it until the two ion types balance .
 Parameters
 anions : list ( ChemicalMetadata )
 List of all negatively charged ions measured as being in the solution ;
 ChemicalMetadata instances or simply objects with the attributes ` MW `
 and ` charge ` , [ - ]
 cations : list ( ChemicalMetadata )
 List of all positively charged ions measured as being in the solution ;
 ChemicalMetadata instances or simply objects with the attributes ` MW `
 and ` charge ` , [ - ]
 anion _ zs : list , optional
 Mole fractions of each anion as measured in the aqueous solution , [ - ]
 cation _ zs : list , optional
 Mole fractions of each cation as measured in the aqueous solution , [ - ]
 anion _ concs : list , optional
 Concentrations of each anion in the aqueous solution in the units often
 reported ( for convinience only ) [ mg / L ]
 cation _ concs : list , optional
 Concentrations of each cation in the aqueous solution in the units
 often reported ( for convinience only ) [ mg / L ]
 rho _ w : float , optional
 Density of the aqueous solutionr at the temperature and pressure the
 anion and cation concentrations were measured ( if specified ) , [ kg / m ^ 3]
 method : str , optional
 The method to use to balance the ionimbalance ; one of ' dominant ' ,
 ' decrease dominant ' , ' increase dominant ' ,
 ' proportional insufficient ions increase ' ,
 ' proportional excess ions decrease ' ,
 ' proportional cation adjustment ' , ' proportional anion adjustment ' ,
 ' Na or Cl increase ' , ' Na or Cl decrease ' , ' adjust ' , ' increase ' ,
 ' decrease ' , ' makeup ' ] .
 selected _ ion : ChemicalMetadata , optional
 Some methods adjust only one user - specified ion ; this is that input .
 For the case of the ' makeup ' method , this is a tuple of ( anion , cation )
 ChemicalMetadata instances and only the ion type not in excess will be
 used .
 Returns
 anions : list ( ChemicalMetadata )
 List of all negatively charged ions measured as being in the solution ;
 ChemicalMetadata instances after potentially adding in an ion which
 was not present but specified by the user , [ - ]
 cations : list ( ChemicalMetadata )
 List of all positively charged ions measured as being in the solution ;
 ChemicalMetadata instances after potentially adding in an ion which
 was not present but specified by the user , [ - ]
 anion _ zs : list ,
 Mole fractions of each anion in the aqueous solution after the charge
 balance , [ - ]
 cation _ zs : list
 Mole fractions of each cation in the aqueous solution after the charge
 balance , [ - ]
 z _ water : float
 Mole fraction of the water in the solution , [ - ]
 Notes
 The methods perform the charge balance as follows :
 * ' dominant ' : The ion with the largest mole fraction in solution has its
 concentration adjusted up or down as necessary to balance the solution .
 * ' decrease dominant ' : The ion with the largest mole fraction in the type
 of ion with * excess * charge has its own mole fraction decreased to balance
 the solution .
 * ' increase dominant ' : The ion with the largest mole fraction in the type
 of ion with * insufficient * charge has its own mole fraction decreased to
 balance the solution .
 * ' proportional insufficient ions increase ' : The ion charge type which is
 present insufficiently has each of the ions mole fractions * increased *
 proportionally until the solution is balanced .
 * ' proportional excess ions decrease ' : The ion charge type which is
 present in excess has each of the ions mole fractions * decreased *
 proportionally until the solution is balanced .
 * ' proportional cation adjustment ' : All * cations * have their mole fractions
 increased or decreased proportionally as necessary to balance the
 solution .
 * ' proportional anion adjustment ' : All * anions * have their mole fractions
 increased or decreased proportionally as necessary to balance the
 solution .
 * ' Na or Cl increase ' : Either Na + or Cl - is * added * to the solution until
 the solution is balanced ; the species will be added if they were not
 present initially as well .
 * ' Na or Cl decrease ' : Either Na + or Cl - is * removed * from the solution
 until the solution is balanced ; the species will be added if they were
 not present initially as well .
 * ' adjust ' : An ion specified with the parameter ` selected _ ion ` has its
 mole fraction * increased or decreased * as necessary to balance the
 solution . An exception is raised if the specified ion alone cannot
 balance the solution .
 * ' increase ' : An ion specified with the parameter ` selected _ ion ` has its
 mole fraction * increased * as necessary to balance the
 solution . An exception is raised if the specified ion alone cannot
 balance the solution .
 * ' decrease ' : An ion specified with the parameter ` selected _ ion ` has its
 mole fraction * decreased * as necessary to balance the
 solution . An exception is raised if the specified ion alone cannot
 balance the solution .
 * ' makeup ' : Two ions ase specified as a tuple with the parameter
 ` selected _ ion ` . Whichever ion type is present in the solution
 insufficiently is added ; i . e . if the ions were Mg + 2 and Cl - , and there
 was too much negative charge in the solution , Mg + 2 would be added until
 the solution was balanced .
 Examples
 > > > anions _ n = [ ' Cl - ' , ' HCO3 - ' , ' SO4-2 ' ]
 > > > cations _ n = [ ' Na + ' , ' K + ' , ' Ca + 2 ' , ' Mg + 2 ' ]
 > > > cations = [ pubchem _ db . search _ name ( i ) for i in cations _ n ]
 > > > anions = [ pubchem _ db . search _ name ( i ) for i in anions _ n ]
 > > > an _ res , cat _ res , an _ zs , cat _ zs , z _ water = balance _ ions ( anions , cations ,
 . . . anion _ zs = [ 0.02557 , 0.00039 , 0.00026 ] , cation _ zs = [ 0.0233 , 0.00075,
 . . . 0.00262 , 0.00119 ] , method = ' proportional excess ions decrease ' )
 > > > an _ zs
 [0.02557 , 0.00039 , 0.00026]
 > > > cat _ zs
 [0.01948165456267761 , 0.0006270918850647299 , 0.0021906409851594564 , 0.0009949857909693717]
 > > > z _ water
 0.9504856267761288
 References'''

implementation:
anions = list ( anions )
cations = list ( cations )
n_anions = len ( anions )
n_cations = len ( cations )
ions = anions + cations
anion_charges = [ i . charge for i in anions ]
cation_charges = [ i . charge for i in cations ]
charges = anion_charges + cation_charges + [ 0 ]
MW_water = [ 18.01528 ]
rho_w = rho_w / 1000
# Convert to kg / liter
if anion_concs is not None and cation_concs is not None :
    anion_ws = [ i * 1E-6 / rho_w for i in anion_concs ]
    cation_ws = [ i * 1E-6 / rho_w for i in cation_concs ]
    w_water = 1 - sum ( anion_ws ) - sum ( cation_ws )
    anion_MWs = [ i . MW for i in anions ]
    cation_MWs = [ i . MW for i in cations ]
    MWs = anion_MWs + cation_MWs + MW_water
    zs = ws_to_zs ( anion_ws + cation_ws + [ w_water ] , MWs )
else :
    if anion_zs is None or cation_zs is None :
        raise Exception ( 'Either both of anion_concs and cation_concs or ' 'anion_zs and cation_zs must be specified.' )
    else :
        zs = anion_zs + cation_zs
        zs = zs + [ 1 - sum ( zs ) ]
impacts = [ zi * ci for zi , ci in zip ( zs , charges ) ]
balance_error = sum ( impacts )
if abs ( balance_error ) < 1E-7 :
    anion_zs = zs [ 0 : n_anions ]
    cation_zs = zs [ n_anions : n_cations + n_anions ]
    z_water = zs [ - 1 ]
    return anions , cations , anion_zs , cation_zs , z_water
if 'dominant' in method :
    anion_zs , cation_zs , z_water = ion_balance_dominant ( impacts , balance_error , charges , zs , n_anions , n_cations , method )
    return anions , cations , anion_zs , cation_zs , z_water
elif 'proportional' in method :
    anion_zs , cation_zs , z_water = ion_balance_proportional ( anion_charges , cation_charges , zs , n_anions , n_cations , balance_error , method )
    return anions , cations , anion_zs , cation_zs , z_water
elif method == 'Na or Cl increase' :
    increase = True
    if balance_error < 0 :
        selected_ion = pubchem_db . search_name ( 'Na+' )
    else :
        selected_ion = pubchem_db . search_name ( 'Cl-' )
elif method == 'Na or Cl decrease' :
    increase = False
    if balance_error > 0 :
        selected_ion = pubchem_db . search_name ( 'Na+' )
    else :
        selected_ion = pubchem_db . search_name ( 'Cl-' )
# All of the below work with the variable selected _ ion
elif method == 'adjust' : # A single ion will be increase or decreased to fix the balance automatically
    increase = None
elif method == 'increase' :
    increase = True
    # Raise exception if approach doesn ' t work
elif method == 'decrease' :
    increase = False
    # Raise exception if approach doesn ' t work
elif method == 'makeup' : # selected ion starts out as a tuple in this case ; always adding the compound
    increase = True
    if balance_error < 0 :
        selected_ion = selected_ion [ 1 ]
    else :
        selected_ion = selected_ion [ 0 ]
else :
    raise Exception ( 'Method not recognized' )
if selected_ion is None :
    raise Exception ( "For methods 'adjust', 'increase', 'decrease', and " "'makeup', an ion must be specified with the " "`selected_ion` parameter" )
anion_zs , cation_zs , z_water = ion_balance_adjust_wrapper ( charges , zs , n_anions , n_cations , anions , cations , selected_ion , increase = increase )
return anions , cations , anion_zs , cation_zs , z_water


signature:
def permittivity_IAPWS ( T , rho ) :
    r'''Calculate the relative permittivity of pure water as a function of .
 temperature and density . Assumes the 1997 IAPWS [ 1 ] _ formulation .
 . . math : :
 \ epsilon ( \ rho , T ) = \ frac { 1 + A + 5B + ( 9 + 2A + 18B + A ^ 2 + 10AB +
 9B ^ 2 ) ^ { 0.5 } } { 4(1 - B ) }
 A ( \ rho , T ) = \ frac { N _ A \ mu ^ 2 \ rho g } { M \ epsilon _ 0 kT }
 B ( \ rho ) = \ frac { N _ A \ alpha \ rho } { 3M \ epsilon _ 0}
 g ( \ delta , \ tau ) = 1 + \ sum _ { i = 1 } ^ { 11 } n _ i \ delta ^ { I _ i } \ tau ^ { J _ i }
 + n _ { 12 } \ delta \ left ( \ frac { 647.096 } { 228 } \ tau ^ { - 1 } - 1 \ right ) ^ { - 1.2}
 \ delta = \ rho / ( 322 \ text { kg / m } ^ 3)
 \ tau = T / 647.096 \ text { K }
 Parameters
 T : float
 Temperature of water [ K ]
 rho : float
 Mass density of water at T and P [ kg / m ^ 3]
 Returns
 epsilon : float
 Relative permittivity of water at T and rho , [ - ]
 Notes
 Validity :
 273.15 < T < 323.15 K for 0 < P < iceVI melting pressure at T or 1000 MPa ,
 whichever is smaller .
 323.15 < T < 873.15 K 0 < p < 600 MPa .
 Coefficients :
 ih = [ 1 , 1 , 1 , 2 , 3 , 3 , 4 , 5 , 6 , 7 , 10 ] ;
 jh = [ 0.25 , 1 , 2.5 , 1.5 , 1.5 , 2.5 , 2 , 2 , 5 , 0.5 , 10 ] ;
 Nh = [ 0.978224486826 , - 0.957771379375 , 0.237511794148 , 0.714692244396,
 -0.298217036956 , - 0.108863472196 , 0.949327488264E - 1,
 - . 980469816509E - 2 , 0.165167634970E - 4 , 0.937359795772E - 4,
 -0.12317921872E - 9 ] ;
 polarizability = 1.636E - 40
 dipole = 6.138E - 30
 Examples
 > > > permittivity _ IAPWS ( 373 . , 958.46)
 55.56584297721836
 References
 . . [ 1 ] IAPWS . 1997 . Release on the Static Dielectric Constant of Ordinary
 Water Substance for Temperatures from 238 K to 873 K and Pressures up
 to 1000 MPa .'''


signature:
def load_all_methods ( self ) :
    r'''Method which picks out coefficients for the specified chemical
 from the various dictionaries and DataFrames storing it . All data is
 stored as attributes . This method also sets : obj : ` Tmin ` , : obj : ` Tmax ` ,
 and : obj : ` all _ methods ` as a set of methods for which the data exists for .
 Called on initialization only . See the source code for the variables at
 which the coefficients are stored . The coefficients can safely be
 altered once the class is initialized . This method can be called again
 to reset the parameters .'''

implementation:
methods = [ ]
Tmins , Tmaxs = [ ] , [ ]
if self . CASRN in CRC_Permittivity_data . index :
    methods . append ( CRC_CONSTANT )
    _ , self . CRC_CONSTANT_T , self . CRC_permittivity , A , B , C , D , Tmin , Tmax = _CRC_Permittivity_data_values [ CRC_Permittivity_data . index . get_loc ( self . CASRN ) ] . tolist ( )
    self . CRC_Tmin = Tmin
    self . CRC_Tmax = Tmax
    self . CRC_coeffs = [ 0 if np . isnan ( x ) else x for x in [ A , B , C , D ] ]
    if not np . isnan ( Tmin ) :
        Tmins . append ( Tmin ) ;
        Tmaxs . append ( Tmax )
    if self . CRC_coeffs [ 0 ] :
        methods . append ( CRC )
self . all_methods = set ( methods )
if Tmins and Tmaxs :
    self . Tmin = min ( Tmins )
    self . Tmax = max ( Tmaxs )


signature:
def calculate ( self , T , method ) :
    r'''Method to calculate permittivity of a liquid at temperature ` T `
 with a given method .
 This method has no exception handling ; see ` T _ dependent _ property `
 for that .
 Parameters
 T : float
 Temperature at which to calculate relative permittivity , [ K ]
 method : str
 Name of the method to use
 Returns
 epsilon : float
 Relative permittivity of the liquid at T , [ - ]'''

implementation:
if method == CRC :
    A , B , C , D = self . CRC_coeffs
    epsilon = A + B * T + C * T ** 2 + D * T ** 3
elif method == CRC_CONSTANT :
    epsilon = self . CRC_permittivity
elif method in self . tabular_data :
    epsilon = self . interpolate ( T , method )
return epsilon


signature:
def Hcombustion ( atoms , Hf = None , HfH2O = - 285825 , HfCO2 = - 393474 , HfSO2 = - 296800 , HfBr2 = 30880 , HfI2 = 62417 , HfHCl = - 92173 , HfHF = - 272711 , HfP4O10 = - 3009940 , HfO2 = 0 , HfN2 = 0 ) :
    '''Calculates the heat of combustion , in J / mol .
 Value non - hydrocarbons is not correct , but still calculable .
 Parameters
 atoms : dict
 Dictionary of atoms and their counts , [ ]
 Hf : float
 Heat of formation of given chemical , [ J / mol ]
 HfH2O : float , optional
 Heat of formation of water , [ J / mol ]
 HfCO2 : float , optional
 Heat of formation of carbon dioxide , [ J / mol ]
 HfSO2 : float , optional
 Heat of formation of sulfur dioxide , [ J / mol ]
 HfBr2 : float , optional
 Heat of formation of bromine , [ J / mol ]
 HfI2 : float , optional
 Heat of formation of iodine , [ J / mol ]
 HfHCl : float , optional
 Heat of formation of chlorine , [ J / mol ]
 HfHF : float , optional
 Heat of formation of hydrogen fluoride , [ J / mol ]
 HfP4O10 : float , optional
 Heat of formation of phosphorus pentoxide , [ J / mol ]
 HfO2 : float , optional
 Heat of formation of oxygen , [ J / mol ]
 HfN2 : float , optional
 Heat of formation of nitrogen , [ J / mol ]
 Returns
 Hc : float
 Heat of combustion of chemical , [ J / mol ]
 Notes
 Default heats of formation for chemicals are at 298 K , 1 atm .
 Examples
 Liquid methanol burning
 > > > Hcombustion ( { ' H ' : 4 , ' C ' : 1 , ' O ' : 1 } , Hf = - 239100)
 -726024.0'''

implementation:
if not Hf or not atoms :
    return None
nC , nH , nN , nO , nS , nBr , nI , nCl , nF , nP = 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
if 'C' in atoms and atoms [ 'C' ] != 0 :
    nC = atoms [ 'C' ]
else :
    return None
    # C is necessary for this formula
if 'H' in atoms :
    nH = atoms [ 'H' ]
if 'N' in atoms :
    nN = atoms [ 'N' ]
if 'O' in atoms :
    nO = atoms [ 'O' ]
if 'S' in atoms :
    nS = atoms [ 'S' ]
if 'Br' in atoms :
    nBr = atoms [ 'Br' ]
if 'I' in atoms :
    nI = atoms [ 'I' ]
if 'Cl' in atoms :
    nCl = atoms [ 'Cl' ]
if 'F' in atoms :
    nF = atoms [ 'F' ]
if 'P' in atoms :
    nP = atoms [ 'P' ]
nO2_req = nC + nS + nH / 4. + 5 * nP / 4. - ( nCl + nF ) / 4. - nO / 2.
nCO2 = nC
nBr2 = nBr / 2.
nI2 = nI / 2.
nHCl = nCl
nHF = nF
nSO2 = nS
nN2 = nN / 2.
nP4O10 = nP / 4.
nH2O = ( nH - nCl - nF ) / 2.
Hc = ( nBr2 * HfBr2 + nI2 * HfI2 ) + ( nHCl * HfHCl + nHF * HfHF ) + nSO2 * HfSO2 + nN2 * HfN2 + nP4O10 * HfP4O10 + nH2O * HfH2O - nO2_req * HfO2 + nCO2 * HfCO2 - Hf
return Hc


signature:
def REFPROP ( T , Tc , sigma0 , n0 , sigma1 = 0 , n1 = 0 , sigma2 = 0 , n2 = 0 ) :
    r'''Calculates air - liquid surface tension using the REFPROP [ 1 ] _
 regression - based method . Relatively recent , and most accurate .
 . . math : :
 \ sigma ( T ) = \ sigma _ 0 \ left ( 1 - \ frac { T } { T _ c } \ right ) ^ { n _ 0 } +
 \ sigma _ 1 \ left ( 1 - \ frac { T } { T _ c } \ right ) ^ { n _ 1 } +
 \ sigma _ 2 \ left ( 1 - \ frac { T } { T _ c } \ right ) ^ { n _ 2}
 Parameters
 T : float
 Temperature of fluid [ K ]
 Tc : float
 Critical temperature of fluid [ K ]
 sigma0 : float
 First emperical coefficient of a fluid
 n0 : float
 First emperical exponent of a fluid
 sigma1 : float , optional
 Second emperical coefficient of a fluid .
 n1 : float , optional
 Second emperical exponent of a fluid .
 sigma1 : float , optional
 Third emperical coefficient of a fluid .
 n2 : float , optional
 Third emperical exponent of a fluid .
 Returns
 sigma : float
 Liquid surface tension , N / m
 Notes
 Function as implemented in [ 1 ] _ . No example necessary ; results match
 literature values perfectly .
 Form of function returns imaginary results when T > Tc ; None is returned
 if this is the case .
 Examples
 Parameters for water at 298.15 K
 > > > REFPROP ( 298.15 , 647.096 , - 0.1306 , 2.471 , 0.2151 , 1.233)
 0.07205503890847453
 References
 . . [ 1 ] Diky , Vladimir , Robert D . Chirico , Chris D . Muzny , Andrei F .
 Kazakov , Kenneth Kroenlein , Joseph W . Magee , Ilmutdin Abdulagatov , and
 Michael Frenkel . " ThermoData Engine ( TDE ) : Software Implementation of
 the Dynamic Data Evaluation Concept . " Journal of Chemical Information
 and Modeling 53 , no . 12 ( 2013 ) : 3418-30 . doi : 10.1021 / ci4005699.'''

implementation:
Tr = T / Tc
sigma = sigma0 * ( 1. - Tr ) ** n0 + sigma1 * ( 1. - Tr ) ** n1 + sigma2 * ( 1. - Tr ) ** n2
return sigma


signature:
def Somayajulu ( T , Tc , A , B , C ) :
    r'''Calculates air - water surface tension using the [ 1 ] _
 emperical ( parameter - regressed ) method . Well regressed , no recent data .
 . . math : :
 \ sigma = aX ^ { 5/4 } + bX ^ { 9/4 } + cX ^ { 13/4}
 X = ( T _ c - T ) / T _ c
 Parameters
 T : float
 Temperature of fluid [ K ]
 Tc : float
 Critical temperature of fluid [ K ]
 A : float
 Regression parameter
 B : float
 Regression parameter
 C : float
 Regression parameter
 Returns
 sigma : float
 Liquid surface tension , N / m
 Notes
 Presently untested , but matches expected values . Internal units are mN / m .
 Form of function returns imaginary results when T > Tc ; None is returned
 if this is the case . Function is claimed valid from the triple to the
 critical point . Results can be evaluated beneath the triple point .
 Examples
 Water at 300 K
 > > > Somayajulu ( 300 , 647.126 , 232.713514 , - 140.18645 , - 4.890098)
 0.07166386387996757
 References
 . . [ 1 ] Somayajulu , G . R . " A Generalized Equation for Surface Tension from
 the Triple Point to the Critical Point . " International Journal of
 Thermophysics 9 , no . 4 ( July 1988 ) : 559-66 . doi : 10.1007 / BF00503154.'''


signature:
def Brock_Bird ( T , Tb , Tc , Pc ) :
    r'''Calculates air - water surface tension using the [ 1 ] _
 emperical method . Old and tested .
 . . math : :
 \ sigma = P _ c ^ { 2/3 } T _ c ^ { 1/3 } Q ( 1 - T _ r ) ^ { 11/9}
 Q = 0.1196 \ left [ 1 + \ frac { T _ { br } \ ln ( P _ c / 1.01325 ) } { 1 - T _ { br } } \ right ] - 0.279
 Parameters
 T : float
 Temperature of fluid [ K ]
 Tb : float
 Boiling temperature of the fluid [ K ]
 Tc : float
 Critical temperature of fluid [ K ]
 Pc : float
 Critical pressure of fluid [ Pa ]
 Returns
 sigma : float
 Liquid surface tension , N / m
 Notes
 Numerous arrangements of this equation are available .
 This is DIPPR Procedure 7A : Method for the Surface Tension of Pure ,
 Nonpolar , Nonhydrocarbon Liquids
 The exact equation is not in the original paper .
 If the equation yields a negative result , return None .
 Examples
 p - dichloribenzene at 412.15 K , from DIPPR ; value differs due to a slight
 difference in method .
 > > > Brock _ Bird ( 412.15 , 447.3 , 685 , 3.952E6)
 0.02208448325192495
 Chlorobenzene from Poling , as compared with a % error value at 293 K .
 > > > Brock _ Bird ( 293.15 , 404.75 , 633.0 , 4530000.0)
 0.032985686413713036
 References
 . . [ 1 ] Brock , James R . , and R . Byron Bird . " Surface Tension and the
 Principle of Corresponding States . " AIChE Journal 1 , no . 2
 ( June 1 , 1955 ) : 174-77 . doi : 10.1002 / aic . 690010208'''


signature:
def Pitzer ( T , Tc , Pc , omega ) :
    r'''Calculates air - water surface tension using the correlation derived
 by [ 1 ] _ from the works of [ 2 ] _ and [ 3 ] _ . Based on critical property CSP
 methods .
 . . math : :
 \ sigma = P _ c ^ { 2/3 } T _ c ^ { 1/3 } \ frac { 1.86 + 1.18 \ omega } { 19.05}
 \ left [ \ frac { 3.75 + 0.91 \ omega } { 0.291 - 0.08 \ omega } \ right ] ^ { 2/3 } ( 1 - T _ r ) ^ { 11/9}
 Parameters
 T : float
 Temperature of fluid [ K ]
 Tc : float
 Critical temperature of fluid [ K ]
 Pc : float
 Critical pressure of fluid [ Pa ]
 omega : float
 Acentric factor for fluid , [ - ]
 Returns
 sigma : float
 Liquid surface tension , N / m
 Notes
 The source of this equation has not been reviewed .
 Internal units of presure are bar , surface tension of mN / m .
 Examples
 Chlorobenzene from Poling , as compared with a % error value at 293 K .
 > > > Pitzer ( 293 . , 633.0 , 4530000.0 , 0.249)
 0.03458453513446387
 References
 . . [ 1 ] Poling , Bruce E . The Properties of Gases and Liquids . 5th edition .
 New York : McGraw - Hill Professional , 2000.
 . . [ 2 ] Curl , R . F . , and Kenneth Pitzer . " Volumetric and Thermodynamic
 Properties of Fluids - Enthalpy , Free Energy , and Entropy . " Industrial &
 Engineering Chemistry 50 , no . 2 ( February 1 , 1958 ) : 265-74.
 doi : 10.1021 / ie50578a047
 . . [ 3 ] Pitzer , K . S . : Thermodynamics , 3d ed . , New York , McGraw - Hill ,
 1995 , p . 521.'''


signature:
def Sastri_Rao ( T , Tb , Tc , Pc , chemicaltype = None ) :
    r'''Calculates air - water surface tension using the correlation derived by
 [1 ] _ based on critical property CSP methods and chemical classes .
 . . math : :
 \ sigma = K P _ c ^ xT _ b ^ y T _ c ^ z \ left [ \ frac { 1 - T _ r } { 1 - T _ { br } } \ right ] ^ m
 Parameters
 T : float
 Temperature of fluid [ K ]
 Tb : float
 Boiling temperature of the fluid [ K ]
 Tc : float
 Critical temperature of fluid [ K ]
 Pc : float
 Critical pressure of fluid [ Pa ]
 Returns
 sigma : float
 Liquid surface tension , N / m
 Notes
 The source of this equation has not been reviewed .
 Internal units of presure are bar , surface tension of mN / m .
 Examples
 Chlorobenzene from Poling , as compared with a % error value at 293 K .
 > > > Sastri _ Rao ( 293.15 , 404.75 , 633.0 , 4530000.0)
 0.03234567739694441
 References
 . . [ 1 ] Sastri , S . R . S . , and K . K . Rao . " A Simple Method to Predict
 Surface Tension of Organic Liquids . " The Chemical Engineering Journal
 and the Biochemical Engineering Journal 59 , no . 2 ( October 1995 ) : 181-86.
 doi : 10.1016/0923-0467(94)02946-6.'''


signature:
def Zuo_Stenby ( T , Tc , Pc , omega ) :
    r'''Calculates air - water surface tension using the reference fluids
 methods of [ 1 ] _ .
 . . math : :
 \ sigma ^ { ( 1 ) } = 40.520(1 - T _ r ) ^ { 1.287}
 \ sigma ^ { ( 2 ) } = 52.095(1 - T _ r ) ^ { 1.21548}
 \ sigma _ r = \ sigma _ r ^ { ( 1 ) } + \ frac { \ omega - \ omega ^ { ( 1 ) } }
 { \ omega ^ { ( 2 ) } - \ omega ^ { ( 1 ) } } ( \ sigma _ r ^ { ( 2 ) } - \ sigma _ r ^ { ( 1 ) } )
 \ sigma = T _ c ^ { 1/3 } P _ c ^ { 2/3 } [ \ exp { ( \ sigma _ r ) } - 1]
 Parameters
 T : float
 Temperature of fluid [ K ]
 Tc : float
 Critical temperature of fluid [ K ]
 Pc : float
 Critical pressure of fluid [ Pa ]
 omega : float
 Acentric factor for fluid , [ - ]
 Returns
 sigma : float
 Liquid surface tension , N / m
 Notes
 Presently untested . Have not personally checked the sources .
 I strongly believe it is broken .
 The reference values for methane and n - octane are from the DIPPR database .
 Examples
 Chlorobenzene
 > > > Zuo _ Stenby ( 293 . , 633.0 , 4530000.0 , 0.249)
 0.03345569011871088
 References
 . . [ 1 ] Zuo , You - Xiang , and Erling H . Stenby . " Corresponding - States and
 Parachor Models for the Calculation of Interfacial Tensions . " The
 Canadian Journal of Chemical Engineering 75 , no . 6 ( December 1 , 1997 ) :
 1130-37 . doi : 10.1002 / cjce . 5450750617'''


signature:
def Hakim_Steinberg_Stiel ( T , Tc , Pc , omega , StielPolar = 0 ) :
    r'''Calculates air - water surface tension using the reference fluids methods
 of [ 1 ] _ .
 . . math : :
 \ sigma = 4.60104 \ times 10 ^ { - 7 } P _ c ^ { 2/3 } T _ c ^ { 1/3 } Q _ p \ left ( \ frac { 1 - T _ r } { 0.4 } \ right ) ^ m
 Q _ p = 0.1574 + 0.359 \ omega - 1.769 \ chi - 13.69 \ chi ^ 2-0.51 \ omega ^ 2 + 1.298 \ omega \ chi
 m = 1.21 + 0.5385 \ omega - 14.61 \ chi - 32.07 \ chi ^ 2-1.65 \ omega ^ 2 + 22.03 \ omega \ chi
 Parameters
 T : float
 Temperature of fluid [ K ]
 Tc : float
 Critical temperature of fluid [ K ]
 Pc : float
 Critical pressure of fluid [ Pa ]
 omega : float
 Acentric factor for fluid , [ - ]
 StielPolar : float , optional
 Stiel Polar Factor , [ - ]
 Returns
 sigma : float
 Liquid surface tension , N / m
 Notes
 Original equation for m and Q are used . Internal units are atm and mN / m .
 Examples
 1 - butanol , as compared to value in CRC Handbook of 0.02493.
 > > > Hakim _ Steinberg _ Stiel ( 298.15 , 563.0 , 4414000.0 , 0.59 , StielPolar = - 0.07872)
 0.021907902575190447
 References
 . . [ 1 ] Hakim , D . I . , David Steinberg , and L . I . Stiel . " Generalized
 Relationship for the Surface Tension of Polar Fluids . " Industrial &
 Engineering Chemistry Fundamentals 10 , no . 1 ( February 1 , 1971 ) : 174-75.
 doi : 10.1021 / i160037a032.'''


signature:
def Miqueu ( T , Tc , Vc , omega ) :
    r'''Calculates air - water surface tension using the methods of [ 1 ] _ .
 . . math : :
 \ sigma = k T _ c \ left ( \ frac { N _ a } { V _ c } \ right ) ^ { 2/3}
 (4.35 + 4.14 \ omega ) t ^ { 1.26 } ( 1 + 0.19t ^ { 0.5 } - 0.487t )
 Parameters
 T : float
 Temperature of fluid [ K ]
 Tc : float
 Critical temperature of fluid [ K ]
 Vc : float
 Critical volume of fluid [ m ^ 3 / mol ]
 omega : float
 Acentric factor for fluid , [ - ]
 Returns
 sigma : float
 Liquid surface tension , N / m
 Notes
 Uses Avogadro ' s constant and the Boltsman constant .
 Internal units of volume are mL / mol and mN / m . However , either a typo
 is in the article or author ' s work , or my value of k is off by 10 ; this is
 corrected nonetheless .
 Created with 31 normal fluids , none polar or hydrogen bonded . Has an
 AARD of 3.5 % .
 Examples
 Bromotrifluoromethane , 2.45 mN / m
 > > > Miqueu ( 300 . , 340.1 , 0.000199 , 0.1687)
 0.003474099603581931
 References
 . . [ 1 ] Miqueu , C , D Broseta , J Satherley , B Mendiboure , J Lachaise , and
 A Graciaa . " An Extended Scaled Equation for the Temperature Dependence
 of the Surface Tension of Pure Compounds Inferred from an Analysis of
 Experimental Data . " Fluid Phase Equilibria 172 , no . 2 ( July 5 , 2000 ) :
 169-82 . doi : 10.1016 / S0378-3812(00)00384-8.'''


signature:
def Aleem ( T , MW , Tb , rhol , Hvap_Tb , Cpl ) :
    r'''Calculates vapor - liquid surface tension using the correlation derived by
 [1 ] _ based on critical property CSP methods .
 . . math : :
 \ sigma = \ phi \ frac { MW ^ { 1/3 } } { 6N _ A ^ { 1/3 } } \ rho _ l ^ { 2/3 } \ left [ H _ { vap }
 + C _ { p , l } ( T _ b - T ) \ right ]
 \ phi = 1 - 0.0047MW + 6.8 \ times 10 ^ { - 6 } MW ^ 2
 Parameters
 T : float
 Temperature of fluid [ K ]
 MW : float
 Molecular weight [ g / mol ]
 Tb : float
 Boiling temperature of the fluid [ K ]
 rhol : float
 Liquid density at T and P [ kg / m ^ 3]
 Hvap _ Tb : float
 Mass enthalpy of vaporization at the normal boiling point [ kg / m ^ 3]
 Cpl : float
 Liquid heat capacity of the chemical at T [ J / kg / K ]
 Returns
 sigma : float
 Liquid - vapor surface tension [ N / m ]
 Notes
 Internal units of molecuar weight are kg / mol . This model is dimensionally
 consistent .
 This model does not use the critical temperature . After it predicts a
 surface tension of 0 at a sufficiently high temperature , it returns
 negative results . The temperature at which this occurs ( the " predicted "
 critical temperature ) can be calculated as follows :
 . . math : :
 \ sigma = 0 \ to T _ { c , predicted } \ text { at } T _ b + \ frac { H _ { vap } } { Cp _ l }
 Because of its dependence on density , it has the potential to model the
 effect of pressure on surface tension .
 Claims AAD of 4.3 % . Developed for normal alkanes . Total of 472 data points .
 Behaves worse for higher alkanes . Behaves very poorly overall .
 Examples
 Methane at 90 K
 > > > Aleem ( T = 90 , MW = 16.04246 , Tb = 111.6 , rhol = 458.7 , Hvap _ Tb = 510870 . ,
 . . . Cpl = 2465 . )
 0.01669970221165325
 References
 . . [ 1 ] Aleem , W . , N . Mellon , S . Sufian , M . I . A . Mutalib , and D . Subbarao .
 " A Model for the Estimation of Surface Tension of Pure Hydrocarbon
 Liquids . " Petroleum Science and Technology 33 , no . 23-24 ( December 17,
 2015 ) : 1908-15 . doi : 10.1080/10916466.2015.1110593.'''

implementation:
MW = MW / 1000.
# Use kg / mol for consistency with the other units
sphericity = 1. - 0.0047 * MW + 6.8E-6 * MW * MW
return sphericity * MW ** ( 1 / 3. ) / ( 6. * N_A ** ( 1 / 3. ) ) * rhol ** ( 2 / 3. ) * ( Hvap_Tb + Cpl * ( Tb - T ) )


signature:
def Mersmann_Kind_surface_tension ( T , Tm , Tb , Tc , Pc , n_associated = 1 ) :
    r'''Estimates the surface tension of organic liquid substances
 according to the method of [ 1 ] _ .
 . . math : :
 \ sigma ^ * = \ frac { \ sigma n _ { ass } ^ { 1/3 } } { ( kT _ c ) ^ { 1/3 } T _ { rm } P _ c ^ { 2/3 } }
 \ sigma ^ * = \ left ( \ frac { T _ b - T _ m } { T _ m } \ right ) ^ { 1/3}
 \ left [ 6.25(1 - T _ r ) + 31.3(1 - T _ r ) ^ { 4/3 } \ right ]
 Parameters
 T : float
 Temperature of the fluid [ K ]
 Tm : float
 Melting temperature [ K ]
 Tb : float
 Boiling temperature of the fluid [ K ]
 Tc : float
 Critical temperature of the fluid [ K ]
 Pc : float
 Critical pressure of the fluid [ Pa ]
 n _ associated : float
 Number of associated molecules in a cluster ( 2 for alcohols , 1
 otherwise ) , [ - ]
 Returns
 sigma : float
 Liquid - vapor surface tension [ N / m ]
 Notes
 In the equation , all quantities must be in SI units . ` k ` is the boltzman
 constant .
 Examples
 MTBE at STP ( the actual value is 0.0181 ) :
 > > > Mersmann _ Kind _ surface _ tension ( 298.15 , 164.15 , 328.25 , 497.1 , 3430000.0)
 0.016744309508833335
 References
 . . [ 1 ] Mersmann , Alfons , and Matthias Kind . " Prediction of Mechanical and
 Thermal Properties of Pure Liquids , of Critical Data , and of Vapor
 Pressure . " Industrial & Engineering Chemistry Research , January 31,
 2017 . https : / / doi . org / 10.1021 / acs . iecr . 6b04323.'''


signature:
def Winterfeld_Scriven_Davis ( xs , sigmas , rhoms ) :
    r'''Calculates surface tension of a liquid mixture according to
 mixing rules in [ 1 ] _ and also in [ 2 ] _ .
 . . math : :
 \ sigma _ M = \ sum _ i \ sum _ j \ frac { 1 } { V _ L ^ { L2 } } \ left ( x _ i V _ i \ right )
 \ left ( x _ jV _ j \ right ) \ sqrt { \ sigma _ i \ cdot \ sigma _ j }
 Parameters
 xs : array - like
 Mole fractions of all components , [ - ]
 sigmas : array - like
 Surface tensions of all components , [ N / m ]
 rhoms : array - like
 Molar densities of all components , [ mol / m ^ 3]
 Returns
 sigma : float
 Air - liquid surface tension of mixture , [ N / m ]
 Notes
 DIPPR Procedure 7C : Method for the Surface Tension of Nonaqueous Liquid
 Mixtures
 Becomes less accurate as liquid - liquid critical solution temperature is
 approached . DIPPR Evaluation : 3-4 % AARD , from 107 nonaqueous binary
 systems , 1284 points . Internally , densities are converted to kmol / m ^ 3 . The
 Amgat function is used to obtain liquid mixture density in this equation .
 Raises a ZeroDivisionError if either molar volume are zero , and a
 ValueError if a surface tensions of a pure component is negative .
 Examples
 > > > Winterfeld _ Scriven _ Davis ( [ 0.1606 , 0.8394 ] , [ 0.01547 , 0.02877 ] ,
 . . . [ 8610 . , 15530 . ] )
 0.024967388450439824
 References
 . . [ 1 ] Winterfeld , P . H . , L . E . Scriven , and H . T . Davis . " An Approximate
 Theory of Interfacial Tensions of Multicomponent Systems : Applications
 to Binary Liquid - Vapor Tensions . " AIChE Journal 24 , no . 6
 ( November 1 , 1978 ) : 1010-14 . doi : 10.1002 / aic . 690240610.
 . . [ 2 ] Danner , Ronald P , and Design Institute for Physical Property Data .
 Manual for Predicting Chemical Process Design Data . New York , N . Y , 1982.'''

implementation:
if not none_and_length_check ( [ xs , sigmas , rhoms ] ) :
    raise Exception ( 'Function inputs are incorrect format' )
rhoms = [ i * 1E-3 for i in rhoms ]
Vms = [ 1. / i for i in rhoms ]
rho = 1. / mixing_simple ( xs , Vms )
cmps = range ( len ( xs ) )
rho2 = rho * rho
return sum ( [ rho2 * xs [ i ] / rhoms [ i ] * xs [ j ] / rhoms [ j ] * ( sigmas [ j ] * sigmas [ i ] ) ** 0.5 for i in cmps for j in cmps ] )


signature:
def Diguilio_Teja ( T , xs , sigmas_Tb , Tbs , Tcs ) :
    r'''Calculates surface tension of a liquid mixture according to
 mixing rules in [ 1 ] _ .
 . . math : :
 \ sigma = 1.002855 ( T ^ * ) ^ { 1.118091 } \ frac { T } { T _ b } \ sigma _ r
 T ^ * = \ frac { ( T _ c / T ) - 1 } { ( T _ c / T _ b ) - 1}
 \ sigma _ r = \ sum x _ i \ sigma _ i
 T _ b = \ sum x _ i T _ { b , i }
 T _ c = \ sum x _ i T _ { c , i }
 Parameters
 T : float
 Temperature of fluid [ K ]
 xs : array - like
 Mole fractions of all components
 sigmas _ Tb : array - like
 Surface tensions of all components at the boiling point , [ N / m ]
 Tbs : array - like
 Boiling temperatures of all components , [ K ]
 Tcs : array - like
 Critical temperatures of all components , [ K ]
 Returns
 sigma : float
 Air - liquid surface tension of mixture , [ N / m ]
 Notes
 Simple model , however it has 0 citations . Gives similar results to the
 ` Winterfeld _ Scriven _ Davis ` model .
 Raises a ValueError if temperature is greater than the mixture ' s critical
 temperature or if the given temperature is negative , or if the mixture ' s
 boiling temperature is higher than its critical temperature .
 [1 ] _ claims a 4.63 percent average absolute error on 21 binary and 4
 ternary non - aqueous systems . [ 1 ] _ also considered Van der Waals mixing
 rules for ` Tc ` , but found it provided a higher error of 5.58%
 Examples
 > > > Diguilio _ Teja ( T = 298.15 , xs = [ 0.1606 , 0.8394 ] ,
 . . . sigmas _ Tb = [ 0.01424 , 0.02530 ] , Tbs = [ 309.21 , 312.95 ] , Tcs = [ 469.7 , 508.0 ] )
 0.025716823875045505
 References
 . . [ 1 ] Diguilio , Ralph , and Amyn S . Teja . " Correlation and Prediction of
 the Surface Tensions of Mixtures . " The Chemical Engineering Journal 38,
 no . 3 ( July 1988 ) : 205-8 . doi : 10.1016/0300-9467(88)80079-0.'''

implementation:
if not none_and_length_check ( [ xs , sigmas_Tb , Tbs , Tcs ] ) :
    raise Exception ( 'Function inputs are incorrect format' )
Tc = mixing_simple ( xs , Tcs )
if T > Tc :
    raise ValueError ( 'T > Tc according to Kays rule - model is not valid in this range.' )
Tb = mixing_simple ( xs , Tbs )
sigmar = mixing_simple ( xs , sigmas_Tb )
Tst = ( Tc / T - 1. ) / ( Tc / Tb - 1 )
return 1.002855 * Tst ** 1.118091 * ( T / Tb ) * sigmar


implementation:
methods = [ ]
Tmins , Tmaxs = [ ] , [ ]
if self . CASRN in Mulero_Cachadina_data . index :
    methods . append ( STREFPROP )
    _ , sigma0 , n0 , sigma1 , n1 , sigma2 , n2 , Tc , self . STREFPROP_Tmin , self . STREFPROP_Tmax = _Mulero_Cachadina_data_values [ Mulero_Cachadina_data . index . get_loc ( self . CASRN ) ] . tolist ( )
    self . STREFPROP_coeffs = [ sigma0 , n0 , sigma1 , n1 , sigma2 , n2 , Tc ]
    Tmins . append ( self . STREFPROP_Tmin ) ;
    Tmaxs . append ( self . STREFPROP_Tmax )
if self . CASRN in Somayajulu_data_2 . index :
    methods . append ( SOMAYAJULU2 )
    _ , self . SOMAYAJULU2_Tt , self . SOMAYAJULU2_Tc , A , B , C = _Somayajulu_data_2_values [ Somayajulu_data_2 . index . get_loc ( self . CASRN ) ] . tolist ( )
    self . SOMAYAJULU2_coeffs = [ A , B , C ]
    Tmins . append ( self . SOMAYAJULU2_Tt ) ;
    Tmaxs . append ( self . SOMAYAJULU2_Tc )
if self . CASRN in Somayajulu_data . index :
    methods . append ( SOMAYAJULU )
    _ , self . SOMAYAJULU_Tt , self . SOMAYAJULU_Tc , A , B , C = _Somayajulu_data_values [ Somayajulu_data . index . get_loc ( self . CASRN ) ] . tolist ( )
    self . SOMAYAJULU_coeffs = [ A , B , C ]
    Tmins . append ( self . SOMAYAJULU_Tt ) ;
    Tmaxs . append ( self . SOMAYAJULU_Tc )
if self . CASRN in _VDISaturationDict :
    methods . append ( VDI_TABULAR )
    Ts , props = VDI_tabular_data ( self . CASRN , 'sigma' )
    self . VDI_Tmin = Ts [ 0 ]
    self . VDI_Tmax = Ts [ - 1 ]
    self . tabular_data [ VDI_TABULAR ] = ( Ts , props )
    Tmins . append ( self . VDI_Tmin ) ;
    Tmaxs . append ( self . VDI_Tmax )
if self . CASRN in Jasper_Lange_data . index :
    methods . append ( JASPER )
    _ , a , b , self . JASPER_Tmin , self . JASPER_Tmax = _Jasper_Lange_data_values [ Jasper_Lange_data . index . get_loc ( self . CASRN ) ] . tolist ( )
    self . JASPER_coeffs = [ a , b ]
    Tmins . append ( self . JASPER_Tmin ) ;
    Tmaxs . append ( self . JASPER_Tmax )
if all ( ( self . Tc , self . Vc , self . omega ) ) :
    methods . append ( MIQUEU )
    Tmins . append ( 0.0 ) ;
    Tmaxs . append ( self . Tc )
if all ( ( self . Tb , self . Tc , self . Pc ) ) :
    methods . append ( BROCK_BIRD )
    methods . append ( SASTRI_RAO )
    Tmins . append ( 0.0 ) ;
    Tmaxs . append ( self . Tc )
if all ( ( self . Tc , self . Pc , self . omega ) ) :
    methods . append ( PITZER )
    methods . append ( ZUO_STENBY )
    Tmins . append ( 0.0 ) ;
    Tmaxs . append ( self . Tc )
if self . CASRN in VDI_PPDS_11 . index :
    _ , Tm , Tc , A , B , C , D , E = _VDI_PPDS_11_values [ VDI_PPDS_11 . index . get_loc ( self . CASRN ) ] . tolist ( )
    self . VDI_PPDS_coeffs = [ A , B , C , D , E ]
    self . VDI_PPDS_Tc = Tc
    self . VDI_PPDS_Tm = Tm
    methods . append ( VDI_PPDS )
    Tmins . append ( self . VDI_PPDS_Tm ) ;
    Tmaxs . append ( self . VDI_PPDS_Tc ) ;
if all ( ( self . Tb , self . Hvap_Tb , self . MW ) ) : # Cache Cpl at Tb for ease of calculation of Tmax
    self . Cpl_Tb = self . Cpl ( self . Tb ) if hasattr ( self . Cpl , '__call__' ) else self . Cpl
    if self . Cpl_Tb :
        methods . append ( ALEEM )
        # Tmin and Tmax for this method is known
        Tmax_possible = self . Tb + self . Hvap_Tb / self . Cpl_Tb
        # This method will ruin solve _ prop as it is typically valid
        # well above Tc . If Tc is available , limit it to that .
        if self . Tc :
            Tmax_possible = min ( self . Tc , Tmax_possible )
        Tmins . append ( 0.0 ) ;
        Tmaxs . append ( Tmax_possible )
self . all_methods = set ( methods )
if Tmins and Tmaxs : # Note : All methods work right down to 0 K .
    self . Tmin = min ( Tmins )
    self . Tmax = max ( Tmaxs )


signature:
def calculate ( self , T , method ) :
    r'''Method to calculate surface tension of a liquid at temperature ` T `
 with a given method .
 This method has no exception handling ; see ` T _ dependent _ property `
 for that .
 Parameters
 T : float
 Temperature at which to calculate surface tension , [ K ]
 method : str
 Name of the method to use
 Returns
 sigma : float
 Surface tension of the liquid at T , [ N / m ]'''

implementation:
if method == STREFPROP :
    sigma0 , n0 , sigma1 , n1 , sigma2 , n2 , Tc = self . STREFPROP_coeffs
    sigma = REFPROP ( T , Tc = Tc , sigma0 = sigma0 , n0 = n0 , sigma1 = sigma1 , n1 = n1 , sigma2 = sigma2 , n2 = n2 )
elif method == VDI_PPDS :
    sigma = EQ106 ( T , self . VDI_PPDS_Tc , * self . VDI_PPDS_coeffs )
elif method == SOMAYAJULU2 :
    A , B , C = self . SOMAYAJULU2_coeffs
    sigma = Somayajulu ( T , Tc = self . SOMAYAJULU2_Tc , A = A , B = B , C = C )
elif method == SOMAYAJULU :
    A , B , C = self . SOMAYAJULU_coeffs
    sigma = Somayajulu ( T , Tc = self . SOMAYAJULU_Tc , A = A , B = B , C = C )
elif method == JASPER :
    sigma = Jasper ( T , a = self . JASPER_coeffs [ 0 ] , b = self . JASPER_coeffs [ 1 ] )
elif method == BROCK_BIRD :
    sigma = Brock_Bird ( T , self . Tb , self . Tc , self . Pc )
elif method == SASTRI_RAO :
    sigma = Sastri_Rao ( T , self . Tb , self . Tc , self . Pc )
elif method == PITZER :
    sigma = Pitzer ( T , self . Tc , self . Pc , self . omega )
elif method == ZUO_STENBY :
    sigma = Zuo_Stenby ( T , self . Tc , self . Pc , self . omega )
elif method == MIQUEU :
    sigma = Miqueu ( T , self . Tc , self . Vc , self . omega )
elif method == ALEEM :
    Cpl = self . Cpl ( T ) if hasattr ( self . Cpl , '__call__' ) else self . Cpl
    Vml = self . Vml ( T ) if hasattr ( self . Vml , '__call__' ) else self . Vml
    rhol = Vm_to_rho ( Vml , self . MW )
    sigma = Aleem ( T = T , MW = self . MW , Tb = self . Tb , rhol = rhol , Hvap_Tb = self . Hvap_Tb , Cpl = Cpl )
elif method in self . tabular_data :
    sigma = self . interpolate ( T , method )
return sigma


signature:
def load_all_methods ( self ) :
    r'''Method to initialize the object by precomputing any values which
 may be used repeatedly and by retrieving mixture - specific variables .
 All data are stored as attributes . This method also sets : obj : ` Tmin ` ,
 : obj : ` Tmax ` , and : obj : ` all _ methods ` as a set of methods which should
 work to calculate the property .
 Called on initialization only . See the source code for the variables at
 which the coefficients are stored . The coefficients can safely be
 altered once the class is initialized . This method can be called again
 to reset the parameters .'''

implementation:
methods = [ ]
methods . append ( SIMPLE )
# Needs sigma
methods . append ( WINTERFELDSCRIVENDAVIS )
# Nothing to load , needs rhoms , sigma
if none_and_length_check ( ( self . Tbs , self . Tcs ) ) :
    self . sigmas_Tb = [ i ( Tb ) for i , Tb in zip ( self . SurfaceTensions , self . Tbs ) ]
    if none_and_length_check ( [ self . sigmas_Tb ] ) :
        methods . append ( DIGUILIOTEJA )
self . all_methods = set ( methods )


signature:
def calculate ( self , T , P , zs , ws , method ) :
    r'''Method to calculate surface tension of a liquid mixture at
 temperature ` T ` , pressure ` P ` , mole fractions ` zs ` and weight fractions
 ` ws ` with a given method .
 This method has no exception handling ; see ` mixture _ property `
 for that .
 Parameters
 T : float
 Temperature at which to calculate the property , [ K ]
 P : float
 Pressure at which to calculate the property , [ Pa ]
 zs : list [ float ]
 Mole fractions of all species in the mixture , [ - ]
 ws : list [ float ]
 Weight fractions of all species in the mixture , [ - ]
 method : str
 Name of the method to use
 Returns
 sigma : float
 Surface tension of the liquid at given conditions , [ N / m ]'''

implementation:
if method == SIMPLE :
    sigmas = [ i ( T ) for i in self . SurfaceTensions ]
    return mixing_simple ( zs , sigmas )
elif method == DIGUILIOTEJA :
    return Diguilio_Teja ( T = T , xs = zs , sigmas_Tb = self . sigmas_Tb , Tbs = self . Tbs , Tcs = self . Tcs )
elif method == WINTERFELDSCRIVENDAVIS :
    sigmas = [ i ( T ) for i in self . SurfaceTensions ]
    rhoms = [ 1. / i ( T , P ) for i in self . VolumeLiquids ]
    return Winterfeld_Scriven_Davis ( zs , sigmas , rhoms )
else :
    raise Exception ( 'Method not valid' )


signature:
def load_group_assignments_DDBST ( ) :
    '''Data is stored in the format
 InChI key \t bool bool bool \t subgroup count . . . \t subgroup count \t subgroup count . . .
 where the bools refer to whether or not the original UNIFAC , modified
 UNIFAC , and PSRK group assignments were completed correctly .
 The subgroups and their count have an indefinite length .'''

implementation:
# Do not allow running multiple times
if DDBST_UNIFAC_assignments :
    return None
with open ( os . path . join ( folder , 'DDBST UNIFAC assignments.tsv' ) ) as f :
    _group_assignments = [ DDBST_UNIFAC_assignments , DDBST_MODIFIED_UNIFAC_assignments , DDBST_PSRK_assignments ]
    for line in f . readlines ( ) :
        key , valids , original , modified , PSRK = line . split ( '\t' )
        # list of whether or not each method was correctly identified or not
        valids = [ True if i == '1' else False for i in valids . split ( ' ' ) ]
        for groups , storage , valid in zip ( [ original , modified , PSRK ] , _group_assignments , valids ) :
            if valid :
                groups = groups . rstrip ( ) . split ( ' ' )
                d_data = { }
                for i in range ( int ( len ( groups ) / 2 ) ) :
                    d_data [ int ( groups [ i * 2 ] ) ] = int ( groups [ i * 2 + 1 ] )
                storage [ key ] = d_data


signature:
def UNIFAC_RQ ( groups , subgroup_data = None ) :
    r'''Calculates UNIFAC parameters R and Q for a chemical , given a dictionary
 of its groups , as shown in [ 1 ] _ . Most UNIFAC methods use the same subgroup
 values ; however , a dictionary of ` UNIFAC _ subgroup ` instances may be
 specified as an optional second parameter .
 . . math : :
 r _ i = \ sum _ { k = 1 } ^ { n } \ nu _ k R _ k
 q _ i = \ sum _ { k = 1 } ^ { n } \ nu _ k Q _ k
 Parameters
 groups : dict [ count ]
 Dictionary of numeric subgroup IDs : their counts
 subgroup _ data : None or dict [ UNIFAC _ subgroup ]
 Optional replacement for standard subgroups ; leave as None to use the
 original UNIFAC subgroup r and q values .
 Returns
 R : float
 R UNIFAC parameter ( normalized Van der Waals Volume ) [ - ]
 Q : float
 Q UNIFAC parameter ( normalized Van der Waals Area ) [ - ]
 Notes
 These parameters have some predictive value for other chemical properties .
 Examples
 Hexane
 > > > UNIFAC _ RQ ( { 1:2 , 2:4 } )
 (4.4998000005 , 3.856)
 References
 . . [ 1 ] Gmehling , Jurgen . Chemical Thermodynamics : For Process Simulation .
 Weinheim , Germany : Wiley - VCH , 2012.'''

implementation:
if subgroup_data is not None :
    subgroups = subgroup_data
else :
    subgroups = UFSG
ri = 0.
qi = 0.
for group , count in groups . items ( ) :
    ri += subgroups [ group ] . R * count
    qi += subgroups [ group ] . Q * count
return ri , qi


signature:
def UNIFAC_psi ( T , subgroup1 , subgroup2 , subgroup_data , interaction_data , modified = False ) :
    r'''Calculates the interaction parameter psi ( m , n ) for two UNIFAC
 subgroups , given the system temperature , the UNIFAC subgroups considered
 for the variant of UNIFAC used , the interaction parameters for the
 variant of UNIFAC used , and whether or not the temperature dependence is
 modified from the original form , as shown below .
 Original temperature dependence :
 . . math : :
 \ Psi _ { mn } = \ exp \ left ( \ frac { - a _ { mn } } { T } \ right )
 Modified temperature dependence :
 . . math : :
 \ Psi _ { mn } = \ exp \ left ( \ frac { - a _ { mn } - b _ { mn } T - c _ { mn } T ^ 2 } { T } \ right )
 Parameters
 T : float
 Temperature of the system , [ K ]
 subgroup1 : int
 First UNIFAC subgroup for identifier , [ - ]
 subgroup2 : int
 Second UNIFAC subgroup for identifier , [ - ]
 subgroup _ data : dict [ UNIFAC _ subgroup ]
 Normally provided as inputs to ` UNIFAC ` .
 interaction _ data : dict [ dict [ tuple ( a _ mn , b _ mn , c _ mn ) ] ]
 Normally provided as inputs to ` UNIFAC ` .
 modified : bool
 True if the modified temperature dependence is used by the interaction
 parameters , otherwise False
 Returns
 psi : float
 UNIFAC interaction parameter term , [ - ]
 Notes
 UNIFAC interaction parameters are asymmetric . No warning is raised if an
 interaction parameter is missing .
 Examples
 > > > from thermo . unifac import UFSG , UFIP , DOUFSG , DOUFIP2006
 > > > UNIFAC _ psi ( 307 , 18 , 1 , UFSG , UFIP )
 0.9165248264184787
 > > > UNIFAC _ psi ( 373.15 , 9 , 78 , DOUFSG , DOUFIP2006 , modified = True )
 1.3703140538273264
 References
 . . [ 1 ] Gmehling , Jurgen . Chemical Thermodynamics : For Process Simulation .
 Weinheim , Germany : Wiley - VCH , 2012.
 . . [ 2 ] Fredenslund , Aage , Russell L . Jones , and John M . Prausnitz . " Group
 Contribution Estimation of Activity Coefficients in Nonideal Liquid
 Mixtures . " AIChE Journal 21 , no . 6 ( November 1 , 1975 ) : 1086-99.
 doi : 10.1002 / aic . 690210607.'''

implementation:
main1 = subgroup_data [ subgroup1 ] . main_group_id
main2 = subgroup_data [ subgroup2 ] . main_group_id
if modified :
    try :
        a , b , c = interaction_data [ main1 ] [ main2 ]
    except :
        return 1.
    return exp ( ( - a / T - b - c * T ) )
else :
    try :
        return exp ( - interaction_data [ main1 ] [ main2 ] / T )
    except :
        return 1.


signature:
def UNIFAC ( T , xs , chemgroups , cached = None , subgroup_data = None , interaction_data = None , modified = False ) :
    r'''Calculates activity coefficients using the UNIFAC model ( optionally
 modified ) , given a mixture ' s temperature , liquid mole fractions ,
 and optionally the subgroup data and interaction parameter data of your
 choice . The default is to use the original UNIFAC model , with the latest
 parameters published by DDBST . The model supports modified forms ( Dortmund ,
 NIST ) when the ` modified ` parameter is True .
 Parameters
 T : float
 Temperature of the system , [ K ]
 xs : list [ float ]
 Mole fractions of all species in the system in the liquid phase , [ - ]
 chemgroups : list [ dict ]
 List of dictionaries of subgroup IDs and their counts for all species
 in the mixture , [ - ]
 subgroup _ data : dict [ UNIFAC _ subgroup ]
 UNIFAC subgroup data ; available dictionaries in this module are UFSG
 ( original ) , DOUFSG ( Dortmund ) , or NISTUFSG ( [ 4 ] _ ) .
 interaction _ data : dict [ dict [ tuple ( a _ mn , b _ mn , c _ mn ) ] ]
 UNIFAC interaction parameter data ; available dictionaries in this
 module are UFIP ( original ) , DOUFIP2006 ( Dortmund parameters as
 published by 2006 ) , DOUFIP2016 ( Dortmund parameters as published by
 2016 ) , and NISTUFIP ( [ 4 ] _ ) .
 modified : bool
 True if using the modified form and temperature dependence , otherwise
 False .
 Returns
 gammas : list [ float ]
 Activity coefficients of all species in the mixture , [ - ]
 Notes
 The actual implementation of UNIFAC is formulated slightly different than
 the formulas above for computational efficiency . DDBST switched to using
 the more efficient forms in their publication , but the numerical results
 are identical .
 The model is as follows :
 . . math : :
 \ ln \ gamma _ i = \ ln \ gamma _ i ^ c + \ ln \ gamma _ i ^ r
 * * Combinatorial component * *
 . . math : :
 \ ln \ gamma _ i ^ c = \ ln \ frac { \ phi _ i } { x _ i } + \ frac { z } { 2 } q _ i
 \ ln \ frac { \ theta _ i } { \ phi _ i } + L _ i - \ frac { \ phi _ i } { x _ i }
 \ sum _ { j = 1 } ^ { n } x _ j L _ j
 \ theta _ i = \ frac { x _ i q _ i } { \ sum _ { j = 1 } ^ { n } x _ j q _ j }
 \ phi _ i = \ frac { x _ i r _ i } { \ sum _ { j = 1 } ^ { n } x _ j r _ j }
 L _ i = 5 ( r _ i - q _ i ) - ( r _ i - 1)
 * * Residual component * *
 . . math : :
 \ ln \ gamma _ i ^ r = \ sum _ { k } ^ n \ nu _ k ^ { ( i ) } \ left [ \ ln \ Gamma _ k
 - \ ln \ Gamma _ k ^ { ( i ) } \ right ]
 \ ln \ Gamma _ k = Q _ k \ left [ 1 - \ ln \ sum _ m \ Theta _ m \ Psi _ { mk } - \ sum _ m
 \ frac { \ Theta _ m \ Psi _ { km } } { \ sum _ n \ Theta _ n \ Psi _ { nm } } \ right ]
 \ Theta _ m = \ frac { Q _ m X _ m } { \ sum _ { n } Q _ n X _ n }
 X _ m = \ frac { \ sum _ j \ nu ^ j _ m x _ j } { \ sum _ j \ sum _ n \ nu _ n ^ j x _ j }
 * * R and Q * *
 . . math : :
 r _ i = \ sum _ { k = 1 } ^ { n } \ nu _ k R _ k
 q _ i = \ sum _ { k = 1 } ^ { n } \ nu _ k Q _ k
 The newer forms of UNIFAC ( Dortmund , NIST ) calculate the combinatorial
 part slightly differently :
 . . math : :
 \ ln \ gamma _ i ^ c = 1 - { V ' } _ i + \ ln ( { V ' } _ i ) - 5q _ i \ left ( 1
 - \ frac { V _ i } { F _ i } + \ ln \ left ( \ frac { V _ i } { F _ i } \ right ) \ right )
 V ' _ i = \ frac { r _ i ^ { 3/4 } } { \ sum _ j r _ j ^ { 3/4 } x _ j }
 This is more clear when looking at the full rearranged form as in [ 3 ] _ .
 Examples
 > > > UNIFAC ( T = 333.15 , xs = [ 0.5 , 0.5 ] , chemgroups = [ { 1:2 , 2:4 } , { 1:1 , 2:1 , 18:1 } ] )
 [1.4276025835624173 , 1.3646545010104225]
 > > > UNIFAC ( 373.15 , [ 0.2 , 0.3 , 0.2 , 0.2 ] ,
 . . . [ { 9:6 } , { 78:6 } , { 1:1 , 18:1 } , { 1:1 , 2:1 , 14:1 } ] ,
 . . . subgroup _ data = DOUFSG , interaction _ data = DOUFIP2006 , modified = True )
 [1.186431113706829 , 1.440280133911197 , 1.204479833499608 , 1.9720706090299824]
 References
 . . [ 1 ] Gmehling , Jurgen . Chemical Thermodynamics : For Process Simulation .
 Weinheim , Germany : Wiley - VCH , 2012.
 . . [ 2 ] Fredenslund , Aage , Russell L . Jones , and John M . Prausnitz . " Group
 Contribution Estimation of Activity Coefficients in Nonideal Liquid
 Mixtures . " AIChE Journal 21 , no . 6 ( November 1 , 1975 ) : 1086-99.
 doi : 10.1002 / aic . 690210607.
 . . [ 3 ] Jakob , Antje , Hans Grensemann , Jürgen Lohmann , and Jürgen Gmehling .
 " Further Development of Modified UNIFAC ( Dortmund ) : Revision and
 Extension 5 . " Industrial & Engineering Chemistry Research 45 , no . 23
 ( November 1 , 2006 ) : 7924-33 . doi : 10.1021 / ie060355c .
 . . [ 4 ] Kang , Jeong Won , Vladimir Diky , and Michael Frenkel . " New Modified
 UNIFAC Parameters Using Critically Evaluated Phase Equilibrium Data . "
 Fluid Phase Equilibria 388 ( February 25 , 2015 ) : 128-41.
 doi : 10.1016 / j . fluid . 2014.12.042.'''

implementation:
cmps = range ( len ( xs ) )
if subgroup_data is None :
    subgroups = UFSG
else :
    subgroups = subgroup_data
if interaction_data is None :
    interactions = UFIP
else :
    interactions = interaction_data
# Obtain r and q values using the subgroup values
if not cached :
    rs = [ ]
    qs = [ ]
    for groups in chemgroups :
        ri = 0.
        qi = 0.
        for group , count in groups . items ( ) :
            ri += subgroups [ group ] . R * count
            qi += subgroups [ group ] . Q * count
        rs . append ( ri )
        qs . append ( qi )
    group_counts = { }
    for groups in chemgroups :
        for group , count in groups . items ( ) :
            if group in group_counts :
                group_counts [ group ] += count
            else :
                group_counts [ group ] = count
else :
    rs , qs , group_counts = cached
# Sum the denominator for calculating Xs
group_sum = sum ( count * xs [ i ] for i in cmps for count in chemgroups [ i ] . values ( ) )
# Caclulate each numerator for calculating Xs
group_count_xs = { }
for group in group_counts :
    tot_numerator = sum ( chemgroups [ i ] [ group ] * xs [ i ] for i in cmps if group in chemgroups [ i ] )
    group_count_xs [ group ] = tot_numerator / group_sum
rsxs = sum ( [ rs [ i ] * xs [ i ] for i in cmps ] )
Vis = [ rs [ i ] / rsxs for i in cmps ]
qsxs = sum ( [ qs [ i ] * xs [ i ] for i in cmps ] )
Fis = [ qs [ i ] / qsxs for i in cmps ]
if modified :
    rsxs2 = sum ( [ rs [ i ] ** 0.75 * xs [ i ] for i in cmps ] )
    Vis2 = [ rs [ i ] ** 0.75 / rsxs2 for i in cmps ]
    loggammacs = [ 1. - Vis2 [ i ] + log ( Vis2 [ i ] ) - 5. * qs [ i ] * ( 1. - Vis [ i ] / Fis [ i ] + log ( Vis [ i ] / Fis [ i ] ) ) for i in cmps ]
else :
    loggammacs = [ 1. - Vis [ i ] + log ( Vis [ i ] ) - 5. * qs [ i ] * ( 1. - Vis [ i ] / Fis [ i ] + log ( Vis [ i ] / Fis [ i ] ) ) for i in cmps ]
Q_sum_term = sum ( [ subgroups [ group ] . Q * group_count_xs [ group ] for group in group_counts ] )
area_fractions = { group : subgroups [ group ] . Q * group_count_xs [ group ] / Q_sum_term for group in group_counts . keys ( ) }
UNIFAC_psis = { k : { m : ( UNIFAC_psi ( T , m , k , subgroups , interactions , modified = modified ) ) for m in group_counts } for k in group_counts }
loggamma_groups = { }
for k in group_counts :
    sum1 , sum2 = 0. , 0.
    for m in group_counts :
        sum1 += area_fractions [ m ] * UNIFAC_psis [ k ] [ m ]
        sum3 = sum ( area_fractions [ n ] * UNIFAC_psis [ m ] [ n ] for n in group_counts )
        sum2 -= area_fractions [ m ] * UNIFAC_psis [ m ] [ k ] / sum3
    loggamma_groups [ k ] = subgroups [ k ] . Q * ( 1. - log ( sum1 ) + sum2 )
loggammars = [ ]
for groups in chemgroups :
    chem_loggamma_groups = { }
    chem_group_sum = sum ( groups . values ( ) )
    chem_group_count_xs = { group : count / chem_group_sum for group , count in groups . items ( ) }
    Q_sum_term = sum ( [ subgroups [ group ] . Q * chem_group_count_xs [ group ] for group in groups ] )
    chem_area_fractions = { group : subgroups [ group ] . Q * chem_group_count_xs [ group ] / Q_sum_term for group in groups . keys ( ) }
    for k in groups :
        sum1 , sum2 = 0. , 0.
        for m in groups :
            sum1 += chem_area_fractions [ m ] * UNIFAC_psis [ k ] [ m ]
            sum3 = sum ( chem_area_fractions [ n ] * UNIFAC_psis [ m ] [ n ] for n in groups )
            sum2 -= chem_area_fractions [ m ] * UNIFAC_psis [ m ] [ k ] / sum3
        chem_loggamma_groups [ k ] = subgroups [ k ] . Q * ( 1. - log ( sum1 ) + sum2 )
    tot = sum ( [ count * ( loggamma_groups [ group ] - chem_loggamma_groups [ group ] ) for group , count in groups . items ( ) ] )
    loggammars . append ( tot )
return [ exp ( loggammacs [ i ] + loggammars [ i ] ) for i in cmps ]


signature:
def dipole_moment ( CASRN , AvailableMethods = False , Method = None ) :
    r'''This function handles the retrieval of a chemical ' s dipole moment .
 Lookup is based on CASRNs . Will automatically select a data source to use
 if no Method is provided ; returns None if the data is not available .
 Prefered source is ' CCCBDB ' . Considerable variation in reported data has
 found .
 Parameters
 CASRN : string
 CASRN [ - ]
 Returns
 dipole : float
 Dipole moment , [ debye ]
 methods : list , only returned if AvailableMethods = = True
 List of methods which can be used to obtain dipole moment with the
 given inputs
 Other Parameters
 Method : string , optional
 The method name to use . Accepted methods are ' CCCBDB ' , ' MULLER ' , or
 ' POLING ' . All valid values are also held in the list ` dipole _ methods ` .
 AvailableMethods : bool , optional
 If True , function will determine which methods can be used to obtain
 the dipole moment for the desired chemical , and will return methods
 instead of the dipole moment
 Notes
 A total of three sources are available for this function . They are :
 * ' CCCBDB ' , a series of critically evaluated data for compounds in
 [1 ] _ , intended for use in predictive modeling .
 * ' MULLER ' , a collection of data in a
 group - contribution scheme in [ 2 ] _ .
 * ' POLING ' , in the appendix in [ 3 ] .
 This function returns dipole moment in units of Debye . This is actually
 a non - SI unit ; to convert to SI , multiply by 3.33564095198e - 30 and its
 units will be in ampere * second ^ 2 or equivalently and more commonly given ,
 coulomb * second . The constant is the result of 1E - 21 / c , where c is the
 speed of light .
 Examples
 > > > dipole _ moment ( CASRN = ' 64-17-5 ' )
 1.44
 References
 . . [ 1 ] NIST Computational Chemistry Comparison and Benchmark Database
 NIST Standard Reference Database Number 101 Release 17b , September 2015,
 Editor : Russell D . Johnson III http : / / cccbdb . nist . gov /
 . . [ 2 ] Muller , Karsten , Liudmila Mokrushina , and Wolfgang Arlt . " Second -
 Order Group Contribution Method for the Determination of the Dipole
 Moment . " Journal of Chemical & Engineering Data 57 , no . 4 ( April 12,
 2012 ) : 1231-36 . doi : 10.1021 / je2013395.
 . . [ 3 ] Poling , Bruce E . The Properties of Gases and Liquids . 5th edition .
 New York : McGraw - Hill Professional , 2000.'''

implementation:
def list_methods ( ) :
    methods = [ ]
    if CASRN in _dipole_CCDB . index and not np . isnan ( _dipole_CCDB . at [ CASRN , 'Dipole' ] ) :
        methods . append ( CCCBDB )
    if CASRN in _dipole_Muller . index and not np . isnan ( _dipole_Muller . at [ CASRN , 'Dipole' ] ) :
        methods . append ( MULLER )
    if CASRN in _dipole_Poling . index and not np . isnan ( _dipole_Poling . at [ CASRN , 'Dipole' ] ) :
        methods . append ( POLING )
    methods . append ( NONE )
    return methods
if AvailableMethods :
    return list_methods ( )
if not Method :
    Method = list_methods ( ) [ 0 ]
if Method == CCCBDB :
    _dipole = float ( _dipole_CCDB . at [ CASRN , 'Dipole' ] )
elif Method == MULLER :
    _dipole = float ( _dipole_Muller . at [ CASRN , 'Dipole' ] )
elif Method == POLING :
    _dipole = float ( _dipole_Poling . at [ CASRN , 'Dipole' ] )
elif Method == NONE :
    _dipole = None
else :
    raise Exception ( 'Failure in in function' )
return _dipole