del(self.a, self.kappa, self.Tc)<EOL>

r'''Removes properties set by `setup_a_alpha_and_derivatives`; run by
        `GCEOSMIX.a_alpha_and_derivatives` after `a_alpha` is calculated for
        every component


from cmath import log<EOL>A = self.a_alpha*self.P/(R2*self.T*self.T)<EOL>B = self.b*self.P/(R*self.T)<EOL>phis = []<EOL>for i in self.cmps:<EOL><INDENT>t1 = self.bs[i]/self.b*(Z - <NUM_LIT:1.>) - log(Z - B).real<EOL>t2 = <NUM_LIT>/self.a_alpha*sum([zs[j]*self.a_alpha_ijs[i][j] for j in self.cmps])<EOL>t3 = t1 - A/(two_root_two*B)*(t2 - self.bs[i]/self.b)*log((Z + (root_two + <NUM_LIT:1.>)*B)/(Z - (root_two - <NUM_LIT:1.>)*B)).real<EOL>phis.append(exp(t3))<EOL><DEDENT>return phis<EOL>

r'''Literature formula for calculating fugacity coefficients for each
        species in a mixture. Verified numerically. Applicable to most
        derivatives of the Peng-Robinson equation of state as well.
        Called by `fugacities` on initialization, or by a solver routine
        which is performing a flash calculation.

        .. math::
            \ln \hat \phi_i = \frac{B_i}{B}(Z-1)-\ln(Z-B) + \frac{A}{2\sqrt{2}B}
            \left[\frac{B_i}{B} - \frac{2}{a\alpha}\sum_i y_i(a\alpha)_{ij}\right]
            \log\left[\frac{Z + (1+\sqrt{2})B}{Z-(\sqrt{2}-1)B}\right]

            A = \frac{(a\alpha)P}{R^2 T^2}

            B = \frac{b P}{RT}

        Parameters
        ----------
        Z : float
            Compressibility of the mixture for a desired phase, [-]
        zs : list[float], optional
            List of mole factions, either overall or in a specific phase, [-]

        Returns
        -------
        phis : float
            Fugacity coefficient for each species, [-]

        References
        ----------
        .. [1] Peng, Ding-Yu, and Donald B. Robinson. "A New Two-Constant
           Equation of State." Industrial & Engineering Chemistry Fundamentals
           15, no. 1 (February 1, 1976): 59-64. doi:10.1021/i160057a011.
        .. [2] Walas, Stanley M. Phase Equilibria in Chemical Engineering.
           Butterworth-Heinemann, 1985.


def setup_a_alpha_and_derivatives(self, i, T=None):

self.a, self.m, self.Tc = self.ais[i], self.ms[i], self.Tcs[i]<EOL>

r'''Sets `a`, `m`, and `Tc` for a specific component before the
        pure-species EOS's `a_alpha_and_derivatives` method is called. Both are
        called by `GCEOSMIX.a_alpha_and_derivatives` for every component.


del(self.a, self.m, self.Tc)<EOL>


A = self.a_alpha*self.P/R2/self.T**<NUM_LIT:2><EOL>B = self.b*self.P/R/self.T<EOL>phis = []<EOL>for i in self.cmps:<EOL><INDENT>Bi = self.bs[i]*self.P/R/self.T<EOL>t1 = Bi/B*(Z-<NUM_LIT:1>) - log(Z - B)<EOL>t2 = A/B*(Bi/B - <NUM_LIT>/self.a_alpha*sum([zs[j]*self.a_alpha_ijs[i][j] for j in self.cmps]))<EOL>t3 = log(<NUM_LIT:1.> + B/Z)<EOL>t4 = t1 + t2*t3<EOL>phis.append(exp(t4))<EOL><DEDENT>return phis<EOL>

r'''Literature formula for calculating fugacity coefficients for each
        species in a mixture. Verified numerically. Applicable to most
        derivatives of the SRK equation of state as well.
        Called by `fugacities` on initialization, or by a solver routine
        which is performing a flash calculation.

        .. math::
            \ln \hat \phi_i = \frac{B_i}{B}(Z-1) - \ln(Z-B) + \frac{A}{B}
            \left[\frac{B_i}{B} - \frac{2}{a \alpha}\sum_i y_i(a\alpha)_{ij}
            \right]\ln\left(1+\frac{B}{Z}\right)

            A=\frac{a\alpha P}{R^2T^2}

            B = \frac{bP}{RT}

        Parameters
        ----------
        Z : float
            Compressibility of the mixture for a desired phase, [-]
        zs : list[float], optional
            List of mole factions, either overall or in a specific phase, [-]

        Returns
        -------
        phis : float
            Fugacity coefficient for each species, [-]

        References
        ----------
        .. [1] Soave, Giorgio. "Equilibrium Constants from a Modified
           Redlich-Kwong Equation of State." Chemical Engineering Science 27,
           no. 6 (June 1972): 1197-1203. doi:10.1016/0009-2509(72)80096-4.
        .. [2] Walas, Stanley M. Phase Equilibria in Chemical Engineering.
           Butterworth-Heinemann, 1985.


self.a = self.ais[i]<EOL>

r'''Sets `a` for a specific component before the
        pure-species EOS's `a_alpha_and_derivatives` method is called. Both are
        called by `GCEOSMIX.a_alpha_and_derivatives` for every component.


del(self.a)<EOL>


phis = []<EOL>V = Z*R*self.T/self.P<EOL>for i in self.cmps:<EOL><INDENT>phi = self.bs[i]/(V-self.b) - log(Z*(<NUM_LIT:1.> - self.b/V)) - <NUM_LIT>*(self.a_alpha*self.ais[i])**<NUM_LIT:0.5>/(R*self.T*V)<EOL>phis.append(exp(phi))<EOL><DEDENT>return phis<EOL>

r'''Literature formula for calculating fugacity coefficients for each
        species in a mixture. Verified numerically.
        Called by `fugacities` on initialization, or by a solver routine
        which is performing a flash calculation.

        .. math::
            \ln \hat \phi_i = \frac{b_i}{V-b} - \ln\left[Z\left(1
            - \frac{b}{V}\right)\right] - \frac{2\sqrt{aa_i}}{RTV}

        Parameters
        ----------
        Z : float
            Compressibility of the mixture for a desired phase, [-]
        zs : list[float], optional
            List of mole factions, either overall or in a specific phase, [-]

        Returns
        -------
        phis : float
            Fugacity coefficient for each species, [-]

        References
        ----------
        .. [1] Walas, Stanley M. Phase Equilibria in Chemical Engineering.
           Butterworth-Heinemann, 1985.


if not hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.kappas = [kappa0 + kappa1*(<NUM_LIT:1> + (T/Tc)**<NUM_LIT:0.5>)*(<NUM_LIT> - (T/Tc)) for kappa0, kappa1, Tc in zip(self.kappa0s, self.kappa1s, self.Tcs)]<EOL><DEDENT>self.a, self.kappa, self.kappa0, self.kappa1, self.Tc = self.ais[i], self.kappas[i], self.kappa0s[i], self.kappa1s[i], self.Tcs[i]<EOL>

r'''Sets `a`, `kappa0`, `kappa1`, and `Tc` for a specific component before the
        pure-species EOS's `a_alpha_and_derivatives` method is called. Both are
        called by `GCEOSMIX.a_alpha_and_derivatives` for every component.


del(self.a, self.kappa, self.kappa0, self.kappa1, self.Tc)<EOL>


if not hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.kappas = []<EOL>for Tc, kappa0, kappa1, kappa2, kappa3 in zip(self.Tcs, self.kappa0s, self.kappa1s, self.kappa2s, self.kappa3s):<EOL><INDENT>Tr = T/Tc<EOL>kappa = kappa0 + ((kappa1 + kappa2*(kappa3 - Tr)*(<NUM_LIT:1.> - Tr**<NUM_LIT:0.5>))*(<NUM_LIT:1.> + Tr**<NUM_LIT:0.5>)*(<NUM_LIT> - Tr))<EOL>self.kappas.append(kappa)<EOL><DEDENT><DEDENT>(self.a, self.kappa, self.kappa0, self.kappa1, self.kappa2, <EOL>self.kappa3, self.Tc) = (self.ais[i], self.kappas[i], self.kappa0s[i],<EOL>self.kappa1s[i], self.kappa2s[i], self.kappa3s[i], self.Tcs[i])<EOL>

r'''Sets `a`, `kappa`, `kappa0`, `kappa1`, `kappa2`, `kappa3` and `Tc`
        for a specific component before the
        pure-species EOS's `a_alpha_and_derivatives` method is called. Both are
        called by `GCEOSMIX.a_alpha_and_derivatives` for every component.


del(self.a, self.kappa, self.kappa0, self.kappa1, self.kappa2, self.kappa3, self.Tc)<EOL>


self.a, self.Tc, self.omega  = self.ais[i], self.Tcs[i], self.omegas[i]<EOL>

r'''Sets `a`, `omega`, and `Tc` for a specific component before the
        pure-species EOS's `a_alpha_and_derivatives` method is called. Both are
        called by `GCEOSMIX.a_alpha_and_derivatives` for every component.


del(self.a, self.Tc, self.omega)<EOL>


self.a, self.Tc, self.S1, self.S2  = self.ais[i], self.Tcs[i], self.S1s[i], self.S2s[i]<EOL>

r'''Sets `a`, `S1`, `S2` and `Tc` for a specific component before the
        pure-species EOS's `a_alpha_and_derivatives` method is called. Both are
        called by `GCEOSMIX.a_alpha_and_derivatives` for every component.


del(self.a, self.Tc, self.S1, self.S2)<EOL>


mu = exp(A + B/T)<EOL>mu = mu/<NUM_LIT><EOL>mu = mu*<NUM_LIT:10><EOL>return mu<EOL>

This function is known to produce values 10 times too low.
The author's data must have an error.
I have adjusted it to fix this.

# DDBST has 0.0004580 as a value at this temperature
>>> ViswanathNatarajan2(348.15, -5.9719, 1007.0)
0.00045983686956829517


def ViswanathNatarajan2Exponential(T, C, D):

mu = C*T**D<EOL>return mu<EOL>

This function is genuinely bad at what it does.

>>> ViswanathNatarajan2Exponential(298.15, 4900800,  -3.8075)
0.0018571903840928496


mu = <NUM_LIT:10>**(A + B/(C - T))<EOL>return mu/<NUM_LIT><EOL>

r'''Calculate the viscosity of a liquid using the 3-term Antoine form
    representation developed in [1]_. Requires input coefficients. The `A`
    coefficient is assumed to yield coefficients in centipoise, as all
    coefficients found so far have been.

    .. math::
        \log_{10} \mu = A + B/(T + C)

    Parameters
    ----------
    T : float
        Temperature of fluid [K]

    Returns
    -------
    mu : float
        Liquid viscosity, [Pa*s]

    Notes
    -----
    No other source for these coefficients has been found.

    Examples
    --------
    >>> ViswanathNatarajan3(298.15, -2.7173, -1071.18, -129.51)
    0.0006129806445142112

    References
    ----------
    .. [1] Viswanath, Dabir S., and G. Natarajan. Databook On The Viscosity Of
       Liquids. New York: Taylor & Francis, 1989


Tr = T/Tc<EOL>xi0 = (<NUM_LIT>-<NUM_LIT>*Tr + <NUM_LIT>*Tr**<NUM_LIT:2>)*<NUM_LIT><EOL>xi1 = (<NUM_LIT>-<NUM_LIT>*Tr + <NUM_LIT>*Tr**<NUM_LIT:2>)*<NUM_LIT><EOL>xi = <NUM_LIT>*Tc**(<NUM_LIT:1>/<NUM_LIT>)/(MW**<NUM_LIT:0.5>*Pc**(<NUM_LIT:2>/<NUM_LIT>))<EOL>return (xi0 + omega*xi1)/xi<EOL>

r'''Calculates the viscosity of a liquid using an emperical model
    developed in [1]_. However. the fitting parameters for tabulated values
    in the original article are found in ChemSep.

    .. math::
        \xi = \frac{2173.424 T_c^{1/6}}{\sqrt{MW} P_c^{2/3}}

        \xi^{(0)} = (1.5174 - 2.135T_r + 0.75T_r^2)\cdot 10^{-5}

        \xi^{(1)} = (4.2552 - 7.674 T_r + 3.4 T_r^2)\cdot 10^{-5}

        \mu = (\xi^{(0)} + \omega \xi^{(1)})/\xi

    Parameters
    ----------
    T : float
        Temperature of fluid [K]
    MW : float
        Molwcular weight of fluid [g/mol]
    Tc : float
        Critical temperature of the fluid [K]
    Pc : float
        Critical pressure of the fluid [Pa]
    omega : float
        Acentric factor of compound

    Returns
    -------
    mu_l : float
        Viscosity of liquid, [Pa*S]

    Notes
    -----
    The form of this equation is a polynomial fit to tabulated data.
    The fitting was performed by the DIPPR. This is DIPPR Procedure 8G: Method
    for the viscosity of pure, nonhydrocarbon liquids at high temperatures
    internal units are SI standard. [1]_'s units were different.
    DIPPR test value for ethanol is used.

    Average error 34%. Range of applicability is 0.76 < Tr < 0.98.

    Examples
    --------
    >>> Letsou_Stiel(400., 46.07, 516.25, 6.383E6, 0.6371)
    0.0002036150875308151

    References
    ----------
    .. [1] Letsou, Athena, and Leonard I. Stiel. "Viscosity of Saturated
       Nonpolar Liquids at Elevated Pressures." AIChE Journal 19, no. 2 (1973):
       409-11. doi:10.1002/aic.690190241.


def Przedziecki_Sridhar(T, Tm, Tc, Pc, Vc, Vm, omega, MW):

Pc = Pc/<NUM_LIT>  <EOL>Vm, Vc = Vm*<NUM_LIT>, Vc*<NUM_LIT>  <EOL>Tr = T/Tc<EOL>Gamma = <NUM_LIT> - <NUM_LIT>*Tr - <NUM_LIT>*Tr**<NUM_LIT:2><EOL>VrT = <NUM_LIT>-<NUM_LIT>*Tr + <NUM_LIT>*Tr**<NUM_LIT:2> - <NUM_LIT>*Tr**<NUM_LIT:3> + <NUM_LIT>*Tr**<NUM_LIT:4><EOL>V = VrT*(<NUM_LIT:1>-omega*Gamma)*Vc<EOL>Vo = <NUM_LIT>*omega*Tc - <NUM_LIT> + Vm/(<NUM_LIT>*(Tm/Tc) + <NUM_LIT>)  <EOL>E = -<NUM_LIT> + Vc/(<NUM_LIT> + <NUM_LIT:0.1>*MW - <NUM_LIT>*Pc + <NUM_LIT>*Tm - <NUM_LIT>*(Tm/Tc))<EOL>return Vo/(E*(V-Vo))/<NUM_LIT><EOL>

r'''Calculates the viscosity of a liquid using an emperical formula
    developed in [1]_.

    .. math::
        \mu=\frac{V_o}{E(V-V_o)}

        E=-1.12+\frac{V_c}{12.94+0.10MW-0.23P_c+0.0424T_{m}-11.58(T_{m}/T_c)}

        V_o = 0.0085\omega T_c-2.02+\frac{V_{m}}{0.342(T_m/T_c)+0.894}

    Parameters
    ----------
    T : float
        Temperature of the fluid [K]
    Tm : float
        Melting point of fluid [K]
    Tc : float
        Critical temperature of the fluid [K]
    Pc : float
        Critical pressure of the fluid [Pa]
    Vc : float
        Critical volume of the fluid [m^3/mol]
    Vm : float
        Molar volume of the fluid at temperature [K]
    omega : float
        Acentric factor of compound
    MW : float
        Molwcular weight of fluid [g/mol]

    Returns
    -------
    mu_l : float
        Viscosity of liquid, [Pa*S]

    Notes
    -----
    A test by Reid (1983) is used, but only mostly correct.
    This function is not recommended. Its use has been removed from the Liquid Viscosity function.
    Internal units are bar and mL/mol.
    TODO: Test again with data from 5th ed table.

    Examples
    --------
    >>> Przedziecki_Sridhar(383., 178., 591.8, 41E5, 316E-6, 95E-6, .263, 92.14)
    0.0002198147995603383

    References
    ----------
    .. [1] Przedziecki, J. W., and T. Sridhar. "Prediction of Liquid
       Viscosities." AIChE Journal 31, no. 2 (February 1, 1985): 333-35.
       doi:10.1002/aic.690310225.


def Lucas(T, P, Tc, Pc, omega, P_sat, mu_l):

Tr = T/Tc<EOL>C = -<NUM_LIT>+<NUM_LIT>*Tr - <NUM_LIT>*Tr**<NUM_LIT:2> + <NUM_LIT>*Tr**<NUM_LIT:3> - <NUM_LIT>*Tr**<NUM_LIT:4>+ <NUM_LIT>*Tr**<NUM_LIT:5>-<NUM_LIT>*Tr**<NUM_LIT:6>+<NUM_LIT>*Tr**<NUM_LIT:7><EOL>D = <NUM_LIT>/((<NUM_LIT>-Tr**<NUM_LIT>)**<NUM_LIT>) - <NUM_LIT><EOL>A = <NUM_LIT> - <NUM_LIT>/(<NUM_LIT>*Tr**-<NUM_LIT> - <NUM_LIT>)<EOL>dPr = (P-P_sat)/Pc<EOL>if dPr < <NUM_LIT:0>:<EOL><INDENT>dPr = <NUM_LIT:0><EOL><DEDENT>return (<NUM_LIT:1.> + D*(dPr/<NUM_LIT>)**A)/(<NUM_LIT:1.> + C*omega*dPr)*mu_l<EOL>

r'''Adjustes for pressure the viscosity of a liquid using an emperical
    formula developed in [1]_, but as discussed in [2]_ as the original source
    is in German.

    .. math::
        \frac{\mu}{\mu_{sat}}=\frac{1+D(\Delta P_r/2.118)^A}{1+C\omega \Delta P_r}

        \Delta P_r = \frac{P-P^{sat}}{P_c}

        A=0.9991-\frac{4.674\times 10^{-4}}{1.0523T_r^{-0.03877}-1.0513}

        D = \frac{0.3257}{(1.0039-T_r^{2.573})^{0.2906}}-0.2086

        C = -0.07921+2.1616T_r-13.4040T_r^2+44.1706T_r^3-84.8291T_r^4+
        96.1209T_r^5-59.8127T_r^6+15.6719T_r^7

    Parameters
    ----------
    T : float
        Temperature of fluid [K]
    P : float
        Pressure of fluid [Pa]
    Tc: float
        Critical point of fluid [K]
    Pc : float
        Critical pressure of the fluid [Pa]
    omega : float
        Acentric factor of compound
    P_sat : float
        Saturation pressure of the fluid [Pa]
    mu_l : float
        Viscosity of liquid at 1 atm or saturation, [Pa*S]

    Returns
    -------
    mu_l_dense : float
        Viscosity of liquid, [Pa*s]

    Notes
    -----
    This equation is entirely dimensionless; all dimensions cancel.
    The example is from Reid (1987); all results agree.
    Above several thousand bar, this equation does not represent true behavior.
    If Psat is larger than P, the fluid may not be liquid; dPr is set to 0.

    Examples
    --------
    >>> Lucas(300., 500E5, 572.2, 34.7E5, 0.236, 0, 0.00068) # methylcyclohexane
    0.0010683738499316518

    References
    ----------
    .. [1] Lucas, Klaus. "Ein Einfaches Verfahren Zur Berechnung Der
       Viskositat von Gasen Und Gasgemischen." Chemie Ingenieur Technik 46, no. 4
       (February 1, 1974): 157-157. doi:10.1002/cite.330460413.
    .. [2] Reid, Robert C.; Prausnitz, John M.; Poling, Bruce E.
       Properties of Gases and Liquids. McGraw-Hill Companies, 1987.


Tr = T/Tc<EOL>xi = <NUM_LIT>*Tc**(<NUM_LIT:1>/<NUM_LIT>)/(MW**<NUM_LIT:0.5>*Pc**(<NUM_LIT:2>/<NUM_LIT>))<EOL>a = <NUM_LIT><EOL>b = <NUM_LIT><EOL>c = <NUM_LIT><EOL>d = -<NUM_LIT><EOL>e = <NUM_LIT><EOL>f = -<NUM_LIT><EOL>return (<NUM_LIT:1.> + a*Tr**b - c * exp(d*Tr) + e*exp(f*Tr))/(<NUM_LIT>*xi)<EOL>

r'''Calculates the viscosity of a gas using an emperical formula
    developed in [1]_.

    .. math::
        \eta \xi \times 10^8 = 46.10 T_r^{0.618} - 20.40 \exp(-0.449T_r) + 1
        9.40\exp(-4.058T_r)+1

        \xi = 2173.424 T_c^{1/6} MW^{-1/2} P_c^{-2/3}

    Parameters
    ----------
    T : float
        Temperature of the fluid [K]
    Tc : float
        Critical temperature of the fluid [K]
    Pc : float
        Critical pressure of the fluid [Pa]
    MW : float
        Molwcular weight of fluid [g/mol]

    Returns
    -------
    mu_g : float
        Viscosity of gas, [Pa*S]

    Notes
    -----
    This equation has been tested. The equation uses SI units only internally.
    The constant 2173.424 is an adjustment factor for units.
    Average deviation within 3% for most compounds.
    Greatest accuracy with dipole moments close to 0.
    Hydrogen and helium have different coefficients, not implemented.
    This is DIPPR Procedure 8B: Method for the Viscosity of Pure,
    non hydrocarbon, nonpolar gases at low pressures

    Examples
    --------
    >>> Yoon_Thodos(300., 556.35, 4.5596E6, 153.8)
    1.0194885727776819e-05

    References
    ----------
    .. [1]  Yoon, Poong, and George Thodos. "Viscosity of Nonpolar Gaseous
       Mixtures at Normal Pressures." AIChE Journal 16, no. 2 (1970): 300-304.
       doi:10.1002/aic.690160225.


Pc = Pc/<NUM_LIT><EOL>Tr = T/Tc<EOL>xi = Tc**(<NUM_LIT:1>/<NUM_LIT>)/(MW**<NUM_LIT:0.5>*Pc**(<NUM_LIT:2>/<NUM_LIT>))<EOL>if Tr > <NUM_LIT>:<EOL><INDENT>mu_g = <NUM_LIT>*(<NUM_LIT>*Tr-<NUM_LIT>)**<NUM_LIT>/xi<EOL><DEDENT>else:<EOL><INDENT>mu_g = <NUM_LIT>*Tr**<NUM_LIT>/xi<EOL><DEDENT>return mu_g/<NUM_LIT><EOL>

r'''Calculates the viscosity of a gas using an emperical formula
    developed in [1]_.

    .. math::
        TODO

    Parameters
    ----------
    T : float
        Temperature of the fluid [K]
    Tc : float
        Critical temperature of the fluid [K]
    Pc : float
        Critical pressure of the fluid [Pa]
    MW : float
        Molwcular weight of fluid [g/mol]

    Returns
    -------
    mu_g : float
        Viscosity of gas, [Pa*S]

    Notes
    -----
    Untested.
    Claimed applicability from 0.2 to 5 atm.
    Developed with data from 52 nonpolar, and 53 polar gases.
    internal units are poise and atm.
    Seems to give reasonable results.

    Examples
    --------
    >>> Stiel_Thodos(300., 556.35, 4.5596E6, 153.8) #CCl4
    1.0408926223608723e-05

    References
    ----------
    .. [1] Stiel, Leonard I., and George Thodos. "The Viscosity of Nonpolar
       Gases at Normal Pressures." AIChE Journal 7, no. 4 (1961): 611-15.
       doi:10.1002/aic.690070416.


def lucas_gas(T, Tc, Pc, Zc, MW, dipole=<NUM_LIT:0>, CASRN=None):

Tr = T/Tc<EOL>xi = <NUM_LIT>*(Tc/MW**<NUM_LIT:3>/(Pc/<NUM_LIT>)**<NUM_LIT:4>)**(<NUM_LIT:1>/<NUM_LIT>)  <EOL>if dipole is None:<EOL><INDENT>dipole = <NUM_LIT:0><EOL><DEDENT>dipoler = <NUM_LIT>*dipole**<NUM_LIT:2>*(Pc/<NUM_LIT>)/Tc**<NUM_LIT:2>  <EOL>if dipoler < <NUM_LIT>:<EOL><INDENT>Fp = <NUM_LIT:1><EOL><DEDENT>elif <NUM_LIT> <= dipoler < <NUM_LIT>:<EOL><INDENT>Fp = <NUM_LIT:1> + <NUM_LIT>*(<NUM_LIT> - Zc)**<NUM_LIT><EOL><DEDENT>else:<EOL><INDENT>Fp = <NUM_LIT:1> + <NUM_LIT>*(<NUM_LIT> - Zc)**<NUM_LIT>*abs(<NUM_LIT> + <NUM_LIT:0.1>*(Tr-<NUM_LIT>))<EOL><DEDENT>if CASRN and CASRN in _lucas_Q_dict:<EOL><INDENT>Q = _lucas_Q_dict[CASRN]<EOL>if Tr - <NUM_LIT:12> > <NUM_LIT:0>:<EOL><INDENT>value = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>value = -<NUM_LIT:1><EOL><DEDENT>FQ = <NUM_LIT>*Q**<NUM_LIT>*(<NUM_LIT:1> + <NUM_LIT>*((Tr-<NUM_LIT:12>)**<NUM_LIT:2>)**(<NUM_LIT:1.>/MW)*value)<EOL><DEDENT>else:<EOL><INDENT>FQ = <NUM_LIT:1><EOL><DEDENT>eta = (<NUM_LIT>*Tr**<NUM_LIT> - <NUM_LIT>*exp(-<NUM_LIT>*Tr) + <NUM_LIT>*exp(-<NUM_LIT>*Tr) + <NUM_LIT>)*Fp*FQ/xi<EOL>return eta/<NUM_LIT><EOL>

r'''Estimate the viscosity of a gas using an emperical
    formula developed in several sources, but as discussed in [1]_ as the
    original sources are in German or merely personal communications with the
    authors of [1]_.

    .. math::
        \eta  = \left[0.807T_r^{0.618}-0.357\exp(-0.449T_r) + 0.340\exp(-4.058
        T_r) + 0.018\right]F_p^\circ F_Q^\circ /\xi

        F_p^\circ=1, 0 \le \mu_{r} < 0.022

        F_p^\circ = 1+30.55(0.292-Z_c)^{1.72}, 0.022 \le \mu_{r} < 0.075

        F_p^\circ = 1+30.55(0.292-Z_c)^{1.72}|0.96+0.1(T_r-0.7)| 0.075 < \mu_{r}

        F_Q^\circ = 1.22Q^{0.15}\left\{ 1+0.00385[(T_r-12)^2]^{1/M}\text{sign}
        (T_r-12)\right\}

        \mu_r = 52.46 \frac{\mu^2 P_c}{T_c^2}

        \xi=0.176\left(\frac{T_c}{MW^3 P_c^4}\right)^{1/6}

    Parameters
    ----------
    T : float
        Temperature of fluid [K]
    Tc: float
        Critical point of fluid [K]
    Pc : float
        Critical pressure of the fluid [Pa]
    Zc : float
        Critical compressibility of the fluid [Pa]
    dipole : float
        Dipole moment of fluid [debye]
    CASRN : str, optional
        CAS of the fluid

    Returns
    -------
    mu_g : float
        Viscosity of gas, [Pa*s]

    Notes
    -----
    The example is from [1]_; all results agree.
    Viscosity is calculated in micropoise, and converted to SI internally (1E-7).
    Q for He = 1.38; Q for H2 = 0.76; Q for D2 = 0.52.

    Examples
    --------
    >>> lucas_gas(T=550., Tc=512.6, Pc=80.9E5, Zc=0.224, MW=32.042, dipole=1.7)
    1.7822676912698928e-05

    References
    ----------
    .. [1] Reid, Robert C.; Prausnitz, John M.; Poling, Bruce E.
       Properties of Gases and Liquids. McGraw-Hill Companies, 1987.


def Gharagheizi_gas_viscosity(T, Tc, Pc, MW):

Tr = T/Tc<EOL>mu_g = <NUM_LIT>*Pc*Tr + (<NUM_LIT> - <NUM_LIT>/MW)*T + MW*(<NUM_LIT>*Pc - <NUM_LIT:8>*MW**<NUM_LIT:2>/T**<NUM_LIT:2>)*(<NUM_LIT>/Tc - <NUM_LIT>/T)<EOL>return <NUM_LIT> * abs(mu_g)<EOL>

r'''Calculates the viscosity of a gas using an emperical formula
    developed in [1]_.

    .. math::
        \mu = 10^{-7} | 10^{-5} P_cT_r + \left(0.091-\frac{0.477}{M}\right)T +
        M \left(10^{-5}P_c-\frac{8M^2}{T^2}\right)
        \left(\frac{10.7639}{T_c}-\frac{4.1929}{T}\right)|

    Parameters
    ----------
    T : float
        Temperature of the fluid [K]
    Tc : float
        Critical temperature of the fluid [K]
    Pc : float
        Critical pressure of the fluid [Pa]
    MW : float
        Molwcular weight of fluid [g/mol]

    Returns
    -------
    mu_g : float
        Viscosity of gas, [Pa*S]

    Notes
    -----
    Example is first point in supporting information of article, for methane.
    This is the prefered function for gas viscosity.
    7% average relative deviation. Deviation should never be above 30%.
    Developed with the DIPPR database. It is believed theoretically predicted values
    are included in the correlation.

    Examples
    --------
    >>> Gharagheizi_gas_viscosity(120., 190.564, 45.99E5, 16.04246)
    5.215761625399613e-06

    References
    ----------
    .. [1] Gharagheizi, Farhad, Ali Eslamimanesh, Mehdi Sattari, Amir H.
       Mohammadi, and Dominique Richon. "Corresponding States Method for
       Determination of the Viscosity of Gases at Atmospheric Pressure."
       Industrial & Engineering Chemistry Research 51, no. 7
       (February 22, 2012): 3179-85. doi:10.1021/ie202591f.


if not none_and_length_check([zs, mus, MWs]):  <EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>MW_roots = [MWi**<NUM_LIT:0.5> for MWi in MWs]<EOL>denominator = sum([zi*MW_root_i for zi, MW_root_i in zip(zs, MW_roots)])<EOL>k = sum([zi*mui*MW_root_i for zi, mui, MW_root_i in zip(zs, mus, MW_roots)])<EOL>return k/denominator<EOL>

r'''Calculates viscosity of a gas mixture according to
    mixing rules in [1]_.

    .. math::
        TODO

    Parameters
    ----------
    zs : float
        Mole fractions of components
    mus : float
        Gas viscosities of all components, [Pa*S]
    MWs : float
        Molecular weights of all components, [g/mol]

    Returns
    -------
    mug : float
        Viscosity of gas mixture, Pa*S]

    Notes
    -----
    This equation is entirely dimensionless; all dimensions cancel.
    The original source has not been reviewed.

    Examples
    --------

    References
    ----------
    .. [1] Herning, F. and Zipperer, L,: "Calculation of the Viscosity of
       Technical Gas Mixtures from the Viscosity of Individual Gases, german",
       Gas u. Wasserfach (1936) 79, No. 49, 69.


if not none_and_length_check([ys, mus, MWs]):  <EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>cmps = range(len(ys))<EOL>phis = [[(<NUM_LIT:1> + (mus[i]/mus[j])**<NUM_LIT:0.5>*(MWs[j]/MWs[i])**<NUM_LIT>)**<NUM_LIT:2>/(<NUM_LIT:8>*(<NUM_LIT:1> + MWs[i]/MWs[j]))**<NUM_LIT:0.5><EOL>for j in cmps] for i in cmps]<EOL>return sum([ys[i]*mus[i]/sum([ys[j]*phis[i][j] for j in cmps]) for i in cmps])<EOL>

r'''Calculates viscosity of a gas mixture according to
    mixing rules in [1]_.

    .. math::
        \eta_{mix} = \sum_{i=1}^n \frac{y_i \eta_i}{\sum_{j=1}^n y_j \phi_{ij}}

        \phi_{ij} = \frac{(1 + \sqrt{\eta_i/\eta_j}(MW_j/MW_i)^{0.25})^2}
        {\sqrt{8(1+MW_i/MW_j)}}

    Parameters
    ----------
    ys : float
        Mole fractions of gas components
    mus : float
        Gas viscosities of all components, [Pa*S]
    MWs : float
        Molecular weights of all components, [g/mol]

    Returns
    -------
    mug : float
        Viscosity of gas mixture, Pa*S]

    Notes
    -----
    This equation is entirely dimensionless; all dimensions cancel.
    The original source has not been reviewed or found.

    Examples
    --------
    >>> Wilke([0.05, 0.95], [1.34E-5, 9.5029E-6], [64.06, 46.07])
    9.701614885866193e-06

    References
    ----------
    .. [1] TODO


def Brokaw(T, ys, mus, MWs, molecular_diameters, Stockmayers):

cmps = range(len(ys))<EOL>MDs = molecular_diameters<EOL>if not none_and_length_check([ys, mus, MWs, molecular_diameters, Stockmayers]): <EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>Tsts = [T/Stockmayer_i for Stockmayer_i in Stockmayers]<EOL>Sij = [[<NUM_LIT:0> for i in cmps] for j in cmps]<EOL>Mij = [[<NUM_LIT:0> for i in cmps] for j in cmps]<EOL>mij = [[<NUM_LIT:0> for i in cmps] for j in cmps]<EOL>Aij = [[<NUM_LIT:0> for i in cmps] for j in cmps]<EOL>phiij =[[<NUM_LIT:0> for i in cmps] for j in cmps]<EOL>for i in cmps:<EOL><INDENT>for j in cmps:<EOL><INDENT>Sij[i][j] = (<NUM_LIT:1>+(Tsts[i]*Tsts[j])**<NUM_LIT:0.5> + (MDs[i]*MDs[j])/<NUM_LIT>)/(<NUM_LIT:1> + Tsts[i] + (MDs[i]**<NUM_LIT:2>/<NUM_LIT>))**<NUM_LIT:0.5>/(<NUM_LIT:1> + Tsts[j] + (MDs[j]**<NUM_LIT:2>/<NUM_LIT>))**<NUM_LIT:0.5><EOL>if MDs[i] <= <NUM_LIT:0.1> and MDs[j] <= <NUM_LIT:0.1>:<EOL><INDENT>Sij[i][j] = <NUM_LIT:1><EOL><DEDENT>Mij[i][j] = MWs[i]/MWs[j]<EOL>mij[i][j] = (<NUM_LIT>/(<NUM_LIT:1>+Mij[i][j]**-<NUM_LIT:1>)/(<NUM_LIT:1>+Mij[i][j]))**<NUM_LIT><EOL>Aij[i][j] = mij[i][j]*Mij[i][j]**-<NUM_LIT:0.5>*(<NUM_LIT:1> + (Mij[i][j]-Mij[i][j]**<NUM_LIT>)/(<NUM_LIT:2>*(<NUM_LIT:1>+Mij[i][j]) + (<NUM_LIT:1>+Mij[i][j]**<NUM_LIT>)*mij[i][j]**-<NUM_LIT:0.5>/(<NUM_LIT:1>+mij[i][j])))<EOL>phiij[i][j] = (mus[i]/mus[j])**<NUM_LIT:0.5>*Sij[i][j]*Aij[i][j]<EOL><DEDENT><DEDENT>return sum([ys[i]*mus[i]/sum([ys[j]*phiij[i][j] for j in cmps]) for i in cmps])<EOL>

r'''Calculates viscosity of a gas mixture according to
    mixing rules in [1]_.

    .. math::
        \eta_{mix} = \sum_{i=1}^n \frac{y_i \eta_i}{\sum_{j=1}^n y_j \phi_{ij}}

        \phi_{ij} = \left( \frac{\eta_i}{\eta_j} \right)^{0.5} S_{ij} A_{ij}

        A_{ij} = m_{ij} M_{ij}^{-0.5} \left[1 +
        \frac{M_{ij} - M_{ij}^{0.45}}
        {2(1+M_{ij}) + \frac{(1 + M_{ij}^{0.45}) m_{ij}^{-0.5}}{1 + m_{ij}}} \right]

        m_{ij} = \left[ \frac{4}{(1+M_{ij}^{-1})(1+M_{ij})}\right]^{0.25}

        M_{ij} = \frac{M_i}{M_j}

        S_{ij} = \frac{1 + (T_i^* T_j^*)^{0.5} + (\delta_i \delta_j/4)}
        {[1+T_i^* + (\delta_i^2/4)]^{0.5}[1+T_j^*+(\delta_j^2/4)]^{0.5}}

        T^* = kT/\epsilon

    Parameters
    ----------
    T : float
        Temperature of fluid, [K]
    ys : float
        Mole fractions of gas components
    mus : float
        Gas viscosities of all components, [Pa*S]
    MWs : float
        Molecular weights of all components, [g/mol]
    molecular_diameters : float
        L-J molecular diameter  of all components, [angstroms]
    Stockmayers : float
        L-J Stockmayer energy parameters of all components, []

    Returns
    -------
    mug : float
        Viscosity of gas mixture, [Pa*S]

    Notes
    -----
    This equation is entirely dimensionless; all dimensions cancel.
    The original source has not been reviewed.

    This is DIPPR Procedure 8D: Method for the Viscosity of Nonhydrocarbon
    Vapor Mixtures at Low Pressure (Polar and Nonpolar)

    Examples
    --------
    >>> Brokaw(308.2, [0.05, 0.95], [1.34E-5, 9.5029E-6], [64.06, 46.07], [0.42, 0.19], [347, 432])
    9.699085099801568e-06

    References
    ----------
    .. [1] Brokaw, R. S. "Predicting Transport Properties of Dilute Gases."
       Industrial & Engineering Chemistry Process Design and Development
       8, no. 2 (April 1, 1969): 240-53. doi:10.1021/i260030a015.
    .. [2] Brokaw, R. S. Viscosity of Gas Mixtures, NASA-TN-D-4496, 1968.
    .. [3] Danner, Ronald P, and Design Institute for Physical Property Data.
       Manual for Predicting Chemical Process Design Data. New York, N.Y, 1982.


if i % <NUM_LIT> == <NUM_LIT:0>:<EOL><INDENT>if (i + <NUM_LIT:0.5>) % <NUM_LIT:2> == <NUM_LIT:0>:<EOL><INDENT>i = i + <NUM_LIT:0.5><EOL><DEDENT>else:<EOL><INDENT>i = i - <NUM_LIT:0.5><EOL><DEDENT><DEDENT>else:<EOL><INDENT>i = round(i, <NUM_LIT:0>)<EOL><DEDENT>return int(i)<EOL>

r'''Round a number to the nearest whole number. If the number is exactly
    between two numbers, round to the even whole number. Used by
    `viscosity_index`.

    Parameters
    ----------
    i : float
        Number, [-]

    Returns
    -------
    i : int
        Rounded number, [-]

    Notes
    -----
    Should never run with inputs from a practical function, as numbers on
    computers aren't really normally exactly between two numbers.

    Examples
    --------
    _round_whole_even(116.5)
    116


def viscosity_index(nu_40, nu_100, rounding=False):

nu_40, nu_100 = nu_40*<NUM_LIT>, nu_100*<NUM_LIT>  <EOL>if nu_100 < <NUM_LIT:2>:<EOL><INDENT>return None  <EOL><DEDENT>elif nu_100 < <NUM_LIT>:<EOL><INDENT>L = np.interp(nu_100, VI_nus, VI_Ls)<EOL>H = np.interp(nu_100, VI_nus, VI_Hs)<EOL><DEDENT>else:<EOL><INDENT>L = <NUM_LIT>*nu_100**<NUM_LIT:2> + <NUM_LIT>*nu_100 - <NUM_LIT><EOL>H = <NUM_LIT>*nu_100**<NUM_LIT:2> + <NUM_LIT>*nu_100 - <NUM_LIT><EOL><DEDENT>if nu_40 > H:<EOL><INDENT>VI = (L-nu_40)/(L-H)*<NUM_LIT:100><EOL><DEDENT>else:<EOL><INDENT>N = (log(H) - log(nu_40))/log(nu_100)<EOL>VI = (<NUM_LIT:10>**N-<NUM_LIT:1>)/<NUM_LIT> + <NUM_LIT:100><EOL><DEDENT>if rounding:<EOL><INDENT>VI = _round_whole_even(VI)<EOL><DEDENT>return VI<EOL>

r'''Calculates the viscosity index of a liquid. Requires dynamic viscosity
    of a liquid at 40°C and 100°C. Value may either be returned with or
    without rounding. Rounding is performed per the standard.

    if nu_100 < 70:

    .. math::
        L, H = interp(nu_100)

    else:

    .. math::
        L = 0.8353\nu_{100}^2 + 14.67\nu_{100} - 216

        H = 0.1684\nu_{100}^2 + 11.85\nu_{100} - 97

    if nu_40 > H:

    .. math::
        VI = \frac{L-nu_{40}}{L-H}\cdot 100

    else:

    .. math::
        N = \frac{\log(H) - \log(\nu_{40})}{\log (\nu_{100})}

         VI = \frac{10^N-1}{0.00715} + 100

    Parameters
    ----------
    nu_40 : float
        Dynamic viscosity of fluid at 40°C, [m^2/s]
    nu_100 : float
        Dynamic viscosity of fluid at 100°C, [m^2/s]
    rounding : bool, optional
        Whether to round the value or not.

    Returns
    -------
    VI: float
        Viscosity index [-]

    Notes
    -----
    VI is undefined for nu_100 under 2 mm^2/s. None is returned if this is the
    case. Internal units are mm^2/s. Higher values of viscosity index suggest
    a lesser decrease in kinematic viscosity as temperature increases.

    Note that viscosity is a pressure-dependent property, and that the
    viscosity index is defined for a fluid at whatever pressure it is at.
    The viscosity index is thus also a function of pressure.

    Examples
    --------
    >>> viscosity_index(73.3E-6, 8.86E-6, rounding=True)
    92

    References
    ----------
    .. [1] ASTM D2270-10(2016) Standard Practice for Calculating Viscosity
       Index from Kinematic Viscosity at 40 °C and 100 °C, ASTM International,
       West Conshohocken, PA, 2016, http://dx.doi.org/10.1520/D2270-10R16


def viscosity_converter(val, old_scale, new_scale, extrapolate=False):

def range_check(visc, scale):<EOL><INDENT>scale_min, scale_max, nu_min, nu_max = viscosity_converter_limits[scale]<EOL>if visc < scale_min*(<NUM_LIT:1.>-<NUM_LIT>) or visc > scale_max*(<NUM_LIT:1.>+<NUM_LIT>):<EOL><INDENT>raise Exception('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %(scale, visc, scale_min, scale_max))<EOL><DEDENT><DEDENT>def range_check_linear(val, c, tmin, scale):<EOL><INDENT>if val < tmin:<EOL><INDENT>raise Exception('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %(scale, val, tmin))<EOL><DEDENT><DEDENT>old_scale = old_scale.lower().replace('<STR_LIT>', '<STR_LIT>').replace('<STR_LIT>', '<STR_LIT>').strip()<EOL>new_scale = new_scale.lower().replace('<STR_LIT>', '<STR_LIT>').replace('<STR_LIT>', '<STR_LIT>').strip()<EOL>def Saybolt_universal_eq(nu):<EOL><INDENT>return (<NUM_LIT>*nu + (<NUM_LIT> + <NUM_LIT>*nu)/(nu*(nu*(<NUM_LIT>*nu + <NUM_LIT>) <EOL>+ <NUM_LIT>) + <NUM_LIT>))<EOL><DEDENT>if old_scale == '<STR_LIT>':<EOL><INDENT>val = <NUM_LIT>*val <EOL><DEDENT>elif old_scale == '<STR_LIT>':<EOL><INDENT>if not extrapolate:<EOL><INDENT>range_check(val, old_scale)<EOL><DEDENT>to_solve = lambda nu: Saybolt_universal_eq(nu) - val<EOL>val = newton(to_solve, <NUM_LIT:1>)<EOL><DEDENT>elif old_scale in viscosity_converters_to_nu:<EOL><INDENT>if not extrapolate:<EOL><INDENT>range_check(val, old_scale)<EOL><DEDENT>val = exp(viscosity_converters_to_nu[old_scale](log(val)))<EOL><DEDENT>elif old_scale in viscosity_scales_linear:<EOL><INDENT>c, tmin = viscosity_scales_linear[old_scale]<EOL>if not extrapolate:<EOL><INDENT>range_check_linear(val, c, tmin, old_scale)<EOL><DEDENT>val = c*val <EOL><DEDENT>else:<EOL><INDENT>keys = sorted(set(list(viscosity_scales.keys()) + list(viscosity_scales_linear.keys())))<EOL>raise Exception('<STR_LIT>' %(old_scale, keys))<EOL><DEDENT>if new_scale == '<STR_LIT>':<EOL><INDENT>val = <NUM_LIT>*val <EOL><DEDENT>elif new_scale == '<STR_LIT>':<EOL><INDENT>val = Saybolt_universal_eq(val)<EOL><DEDENT>elif new_scale in viscosity_converters_from_nu:<EOL><INDENT>val = exp(viscosity_converters_from_nu[new_scale](log(val)))<EOL>if not extrapolate:<EOL><INDENT>range_check(val, new_scale)<EOL><DEDENT><DEDENT>elif new_scale in viscosity_scales_linear:<EOL><INDENT>c, tmin = viscosity_scales_linear[new_scale]<EOL>val = val/c <EOL>if not extrapolate:<EOL><INDENT>range_check_linear(val, c, tmin, new_scale)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>keys = sorted(set(list(viscosity_scales.keys()) + list(viscosity_scales_linear.keys())))<EOL>raise Exception('<STR_LIT>' %(new_scale, keys))<EOL><DEDENT>return float(val)<EOL>

r'''Converts kinematic viscosity values from different scales which have
    historically been used. Though they may not be in use much, some standards
    still specify values in these scales.

    Parameters
    ----------
    val : float
        Viscosity value in the specified scale; [m^2/s] if
        'kinematic viscosity'; [degrees] if Engler or Barbey; [s] for the other
        scales.
    old_scale : str
        String representing the scale that `val` is in originally.
    new_scale : str
        String representing the scale that `val` should be converted to.
    extrapolate : bool
        If True, a conversion will be performed even if outside the limits of
        either scale; if False, and either value is outside a limit, an
        exception will be raised.

    Returns
    -------
    result : float
        Viscosity value in the specified scale; [m^2/s] if
        'kinematic viscosity'; [degrees] if Engler or Barbey; [s] for the other
        scales

    Notes
    -----
    The valid scales for this function are any of the following:

    ['a&w b', 'a&w crucible', 'american can', 'astm 0.07', 'astm 0.10',
    'astm 0.15', 'astm 0.20', 'astm 0.25', 'barbey', 'caspers tin plate',
    'continental can', 'crown cork and seal', 'demmier #1', 'demmier #10',
    'engler', 'ford cup #3', 'ford cup #4', 'kinematic viscosity',
    'mac michael', 'murphy varnish', 'parlin cup #10', 'parlin cup #15',
    'parlin cup #20', 'parlin cup #25', 'parlin cup #30', 'parlin cup #7',
    'pratt lambert a', 'pratt lambert b', 'pratt lambert c', 'pratt lambert d',
    'pratt lambert e', 'pratt lambert f', 'pratt lambert g', 'pratt lambert h',
    'pratt lambert i', 'redwood admiralty', 'redwood standard',
    'saybolt furol', 'saybolt universal', 'scott', 'stormer 100g load',
    'westinghouse', 'zahn cup #1', 'zahn cup #2', 'zahn cup #3', 'zahn cup #4',
    'zahn cup #5']

    Some of those scales are converted linearly; the rest use tabulated data
    and splines.

    Because the conversion is performed by spline functions, a re-conversion
    of a value will not yield exactly the original value. However, it is quite
    close.

    The method 'Saybolt universal' has a special formula implemented for its
    conversion, from [4]_. It is designed for maximum backwards compatibility
    with prior experimental data. It is solved by newton's method when
    kinematic viscosity is desired as an output.

    .. math::
        SUS_{eq} = 4.6324\nu_t + \frac{[1.0 + 0.03264\nu_t]}
        {[(3930.2 + 262.7\nu_t + 23.97\nu_t^2 + 1.646\nu_t^3)\times10^{-5})]}

    Examples
    --------
    >>> viscosity_converter(8.79, 'engler', 'parlin cup #7')
    52.5
    >>> viscosity_converter(700, 'Saybolt Universal Seconds', 'kinematic viscosity')
    0.00015108914751515542

    References
    ----------
    .. [1] Hydraulic Institute. Hydraulic Institute Engineering Data Book.
       Cleveland, Ohio: Hydraulic Institute, 1990.
    .. [2] Gardner/Sward. Paint Testing Manual. Physical and Chemical
       Examination of Paints, Varnishes, Lacquers, and Colors. 13th Edition.
       ASTM, 1972.
    .. [3] Euverard, M. R., The Efflux Type Viscosity Cup. National Paint,
       Varnish, and Lacquer Association, 1948.
    .. [4] API Technical Data Book: General Properties & Characterization.
       American Petroleum Institute, 7E, 2005.
    .. [5] ASTM. Standard Practice for Conversion of Kinematic Viscosity to
       Saybolt Universal Viscosity or to Saybolt Furol Viscosity. D 2161 - 93.


methods, methods_P = [], []<EOL>Tmins, Tmaxs = [], []<EOL>if has_CoolProp and self.CASRN in coolprop_dict:<EOL><INDENT>methods.append(COOLPROP); methods_P.append(COOLPROP)<EOL>self.CP_f = coolprop_fluids[self.CASRN]<EOL>Tmins.append(self.CP_f.Tmin); Tmaxs.append(self.CP_f.Tc)<EOL><DEDENT>if self.CASRN in _VDISaturationDict:<EOL><INDENT>methods.append(VDI_TABULAR)<EOL>Ts, props = VDI_tabular_data(self.CASRN, '<STR_LIT>')<EOL>self.VDI_Tmin = Ts[<NUM_LIT:0>]<EOL>self.VDI_Tmax = Ts[-<NUM_LIT:1>]<EOL>self.tabular_data[VDI_TABULAR] = (Ts, props)<EOL>Tmins.append(self.VDI_Tmin); Tmaxs.append(self.VDI_Tmax)<EOL><DEDENT>if self.CASRN in Dutt_Prasad.index:<EOL><INDENT>methods.append(DUTT_PRASAD)<EOL>_, A, B, C, self.DUTT_PRASAD_Tmin, self.DUTT_PRASAD_Tmax = _Dutt_Prasad_values[Dutt_Prasad.index.get_loc(self.CASRN)].tolist()<EOL>self.DUTT_PRASAD_coeffs = [A, B, C]<EOL>Tmins.append(self.DUTT_PRASAD_Tmin); Tmaxs.append(self.DUTT_PRASAD_Tmax)<EOL><DEDENT>if self.CASRN in VN3_data.index:<EOL><INDENT>methods.append(VISWANATH_NATARAJAN_3)<EOL>_, _, A, B, C, self.VISWANATH_NATARAJAN_3_Tmin, self.VISWANATH_NATARAJAN_3_Tmax = _VN3_data_values[VN3_data.index.get_loc(self.CASRN)].tolist()<EOL>self.VISWANATH_NATARAJAN_3_coeffs = [A, B, C]<EOL>Tmins.append(self.VISWANATH_NATARAJAN_3_Tmin); Tmaxs.append(self.VISWANATH_NATARAJAN_3_Tmax)<EOL><DEDENT>if self.CASRN in VN2_data.index:<EOL><INDENT>methods.append(VISWANATH_NATARAJAN_2)<EOL>_, _, A, B, self.VISWANATH_NATARAJAN_2_Tmin, self.VISWANATH_NATARAJAN_2_Tmax = _VN2_data_values[VN2_data.index.get_loc(self.CASRN)].tolist()<EOL>self.VISWANATH_NATARAJAN_2_coeffs = [A, B]<EOL>Tmins.append(self.VISWANATH_NATARAJAN_2_Tmin); Tmaxs.append(self.VISWANATH_NATARAJAN_2_Tmax)<EOL><DEDENT>if self.CASRN in VN2E_data.index:<EOL><INDENT>methods.append(VISWANATH_NATARAJAN_2E)<EOL>_, _, C, D, self.VISWANATH_NATARAJAN_2E_Tmin, self.VISWANATH_NATARAJAN_2E_Tmax = _VN2E_data_values[VN2E_data.index.get_loc(self.CASRN)].tolist()<EOL>self.VISWANATH_NATARAJAN_2E_coeffs = [C, D]<EOL>Tmins.append(self.VISWANATH_NATARAJAN_2E_Tmin); Tmaxs.append(self.VISWANATH_NATARAJAN_2E_Tmax)<EOL><DEDENT>if self.CASRN in Perrys2_313.index:<EOL><INDENT>methods.append(DIPPR_PERRY_8E)<EOL>_, C1, C2, C3, C4, C5, self.Perrys2_313_Tmin, self.Perrys2_313_Tmax = _Perrys2_313_values[Perrys2_313.index.get_loc(self.CASRN)].tolist()<EOL>self.Perrys2_313_coeffs = [C1, C2, C3, C4, C5]<EOL>Tmins.append(self.Perrys2_313_Tmin); Tmaxs.append(self.Perrys2_313_Tmax)<EOL><DEDENT>if self.CASRN in VDI_PPDS_7.index:<EOL><INDENT>methods.append(VDI_PPDS)<EOL>self.VDI_PPDS_coeffs = _VDI_PPDS_7_values[VDI_PPDS_7.index.get_loc(self.CASRN)].tolist()[<NUM_LIT:2>:]<EOL><DEDENT>if all((self.MW, self.Tc, self.Pc, self.omega)):<EOL><INDENT>methods.append(LETSOU_STIEL)<EOL>Tmins.append(self.Tc/<NUM_LIT:4>); Tmaxs.append(self.Tc) <EOL><DEDENT>if all((self.MW, self.Tm, self.Tc, self.Pc, self.Vc, self.omega, self.Vml)):<EOL><INDENT>methods.append(PRZEDZIECKI_SRIDHAR)<EOL>Tmins.append(self.Tm); Tmaxs.append(self.Tc) <EOL><DEDENT>if all([self.Tc, self.Pc, self.omega]):<EOL><INDENT>methods_P.append(LUCAS)<EOL><DEDENT>self.all_methods = set(methods)<EOL>self.all_methods_P = set(methods_P)<EOL>if Tmins and Tmaxs:<EOL><INDENT>self.Tmin, self.Tmax = min(Tmins), max(Tmaxs)<EOL><DEDENT>

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`,
        :obj:`all_methods` and obj:`all_methods_P` 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.


if method == DUTT_PRASAD:<EOL><INDENT>A, B, C = self.DUTT_PRASAD_coeffs<EOL>mu = ViswanathNatarajan3(T, A, B, C, )<EOL><DEDENT>elif method == VISWANATH_NATARAJAN_3:<EOL><INDENT>A, B, C = self.VISWANATH_NATARAJAN_3_coeffs<EOL>mu = ViswanathNatarajan3(T, A, B, C)<EOL><DEDENT>elif method == VISWANATH_NATARAJAN_2:<EOL><INDENT>A, B = self.VISWANATH_NATARAJAN_2_coeffs<EOL>mu = ViswanathNatarajan2(T, self.VISWANATH_NATARAJAN_2_coeffs[<NUM_LIT:0>], self.VISWANATH_NATARAJAN_2_coeffs[<NUM_LIT:1>])<EOL><DEDENT>elif method == VISWANATH_NATARAJAN_2E:<EOL><INDENT>C, D = self.VISWANATH_NATARAJAN_2E_coeffs<EOL>mu = ViswanathNatarajan2Exponential(T, C, D)<EOL><DEDENT>elif method == DIPPR_PERRY_8E:<EOL><INDENT>mu = EQ101(T, *self.Perrys2_313_coeffs)<EOL><DEDENT>elif method == COOLPROP:<EOL><INDENT>mu = CoolProp_T_dependent_property(T, self.CASRN, '<STR_LIT>', '<STR_LIT:l>')<EOL><DEDENT>elif method == LETSOU_STIEL:<EOL><INDENT>mu = Letsou_Stiel(T, self.MW, self.Tc, self.Pc, self.omega)<EOL><DEDENT>elif method == PRZEDZIECKI_SRIDHAR:<EOL><INDENT>Vml = self.Vml(T) if hasattr(self.Vml, '<STR_LIT>') else self.Vml<EOL>mu = Przedziecki_Sridhar(T, self.Tm, self.Tc, self.Pc, self.Vc, Vml, self.omega, self.MW)<EOL><DEDENT>elif method == VDI_PPDS:<EOL><INDENT>A, B, C, D, E = self.VDI_PPDS_coeffs<EOL>term = (C - T)/(T-D)<EOL>if term < <NUM_LIT:0>:<EOL><INDENT>term1 = -((T - C)/(T-D))**(<NUM_LIT:1>/<NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>term1 = term**(<NUM_LIT:1>/<NUM_LIT>)<EOL><DEDENT>term2 = term*term1<EOL>mu = E*exp(A*term1 + B*term2)<EOL><DEDENT>elif method in self.tabular_data:<EOL><INDENT>mu = self.interpolate(T, method)<EOL><DEDENT>return mu<EOL>

r'''Method to calculate low-pressure liquid viscosity at tempearture
        `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 viscosity, [K]
        method : str
            Name of the method to use

        Returns
        -------
        mu : float
            Viscosity of the liquid at T and a low pressure, [Pa*S]


if method == LUCAS:<EOL><INDENT>mu = self.T_dependent_property(T)<EOL>Psat = self.Psat(T) if hasattr(self.Psat, '<STR_LIT>') else self.Psat<EOL>mu = Lucas(T, P, self.Tc, self.Pc, self.omega, Psat, mu)<EOL><DEDENT>elif method == COOLPROP:<EOL><INDENT>mu = PropsSI('<STR_LIT>', '<STR_LIT:T>', T, '<STR_LIT:P>', P, self.CASRN)<EOL><DEDENT>elif method in self.tabular_data:<EOL><INDENT>mu = self.interpolate_P(T, P, method)<EOL><DEDENT>return mu<EOL>

r'''Method to calculate pressure-dependent liquid viscosity at
        temperature `T` and pressure `P` with a given method.

        This method has no exception handling; see `TP_dependent_property`
        for that.

        Parameters
        ----------
        T : float
            Temperature at which to calculate viscosity, [K]
        P : float
            Pressure at which to calculate viscosity, [K]
        method : str
            Name of the method to use

        Returns
        -------
        mu : float
            Viscosity of the liquid at T and P, [Pa*S]


methods = [MIXING_LOG_MOLAR, MIXING_LOG_MASS]<EOL>if len(self.CASs) > <NUM_LIT:1> and '<STR_LIT>' in self.CASs:<EOL><INDENT>wCASs = [i for i in self.CASs if i != '<STR_LIT>'] <EOL>if all([i in _Laliberte_Viscosity_ParametersDict for i in wCASs]):<EOL><INDENT>methods.append(LALIBERTE_MU)<EOL>self.wCASs = wCASs<EOL>self.index_w = self.CASs.index('<STR_LIT>')<EOL><DEDENT><DEDENT>self.all_methods = set(methods)<EOL>Tmins = [i.Tmin for i in self.ViscosityLiquids if i.Tmin]<EOL>Tmaxs = [i.Tmax for i in self.ViscosityLiquids if i.Tmax]<EOL>if Tmins:<EOL><INDENT>self.Tmin = max(Tmins)<EOL><DEDENT>if Tmaxs:<EOL><INDENT>self.Tmax = max(Tmaxs)<EOL><DEDENT>

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.


def calculate(self, T, P, zs, ws, method):

if method == MIXING_LOG_MOLAR:<EOL><INDENT>mus = [i(T, P) for i in self.ViscosityLiquids]<EOL>return mixing_logarithmic(zs, mus)<EOL><DEDENT>elif method == MIXING_LOG_MASS:<EOL><INDENT>mus = [i(T, P) for i in self.ViscosityLiquids]<EOL>return mixing_logarithmic(ws, mus)<EOL><DEDENT>elif method == LALIBERTE_MU:<EOL><INDENT>ws = list(ws) ; ws.pop(self.index_w)<EOL>return Laliberte_viscosity(T, ws, self.wCASs)<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>

r'''Method to calculate viscosity 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
        -------
        mu : float
            Viscosity of the liquid mixture, [Pa*s]


methods, methods_P = [], []<EOL>Tmins, Tmaxs = [], []<EOL>if self.CASRN in _VDISaturationDict:<EOL><INDENT>methods.append(VDI_TABULAR)<EOL>Ts, props = VDI_tabular_data(self.CASRN, '<STR_LIT>')<EOL>self.VDI_Tmin = Ts[<NUM_LIT:0>]<EOL>self.VDI_Tmax = Ts[-<NUM_LIT:1>]<EOL>self.tabular_data[VDI_TABULAR] = (Ts, props)<EOL>Tmins.append(self.VDI_Tmin); Tmaxs.append(self.VDI_Tmax)<EOL><DEDENT>if has_CoolProp and self.CASRN in coolprop_dict:<EOL><INDENT>methods.append(COOLPROP); methods_P.append(COOLPROP)<EOL>self.CP_f = coolprop_fluids[self.CASRN]<EOL>Tmins.append(self.CP_f.Tmin); Tmaxs.append(self.CP_f.Tmax)<EOL><DEDENT>if self.CASRN in Perrys2_312.index:<EOL><INDENT>methods.append(DIPPR_PERRY_8E)<EOL>_, C1, C2, C3, C4, self.Perrys2_312_Tmin, self.Perrys2_312_Tmax = _Perrys2_312_values[Perrys2_312.index.get_loc(self.CASRN)].tolist()<EOL>self.Perrys2_312_coeffs = [C1, C2, C3, C4]<EOL>Tmins.append(self.Perrys2_312_Tmin); Tmaxs.append(self.Perrys2_312_Tmax)<EOL><DEDENT>if self.CASRN in VDI_PPDS_8.index:<EOL><INDENT>methods.append(VDI_PPDS)<EOL>self.VDI_PPDS_coeffs = _VDI_PPDS_8_values[VDI_PPDS_8.index.get_loc(self.CASRN)].tolist()[<NUM_LIT:1>:]<EOL>self.VDI_PPDS_coeffs.reverse() <EOL><DEDENT>if all([self.Tc, self.Pc, self.MW]):<EOL><INDENT>methods.append(GHARAGHEIZI)<EOL>methods.append(YOON_THODOS)<EOL>methods.append(STIEL_THODOS)<EOL>Tmins.append(<NUM_LIT:0>); Tmaxs.append(<NUM_LIT>)  <EOL><DEDENT>if all([self.Tc, self.Pc, self.Zc, self.MW]):<EOL><INDENT>methods.append(LUCAS_GAS)<EOL>Tmins.append(<NUM_LIT:0>); Tmaxs.append(<NUM_LIT>)<EOL><DEDENT>self.all_methods = set(methods)<EOL>self.all_methods_P = set(methods_P)<EOL>if Tmins and Tmaxs:<EOL><INDENT>self.Tmin, self.Tmax = min(Tmins), max(Tmaxs)<EOL><DEDENT>


if method == GHARAGHEIZI:<EOL><INDENT>mu = Gharagheizi_gas_viscosity(T, self.Tc, self.Pc, self.MW)<EOL><DEDENT>elif method == COOLPROP:<EOL><INDENT>mu = CoolProp_T_dependent_property(T, self.CASRN, '<STR_LIT>', '<STR_LIT:g>')<EOL><DEDENT>elif method == DIPPR_PERRY_8E:<EOL><INDENT>mu = EQ102(T, *self.Perrys2_312_coeffs)<EOL><DEDENT>elif method == VDI_PPDS:<EOL><INDENT>mu =  horner(self.VDI_PPDS_coeffs, T)<EOL><DEDENT>elif method == YOON_THODOS:<EOL><INDENT>mu = Yoon_Thodos(T, self.Tc, self.Pc, self.MW)<EOL><DEDENT>elif method == STIEL_THODOS:<EOL><INDENT>mu = Stiel_Thodos(T, self.Tc, self.Pc, self.MW)<EOL><DEDENT>elif method == LUCAS_GAS:<EOL><INDENT>mu = lucas_gas(T, self.Tc, self.Pc, self.Zc, self.MW, self.dipole, CASRN=self.CASRN)<EOL><DEDENT>elif method in self.tabular_data:<EOL><INDENT>mu = self.interpolate(T, method)<EOL><DEDENT>return mu<EOL>

r'''Method to calculate low-pressure gas viscosity at
        tempearture `T` with a given method.

        This method has no exception handling; see `T_dependent_property`
        for that.

        Parameters
        ----------
        T : float
            Temperature of the gas, [K]
        method : str
            Name of the method to use

        Returns
        -------
        mu : float
            Viscosity of the gas at T and a low pressure, [Pa*S]


if method == COOLPROP:<EOL><INDENT>mu = PropsSI('<STR_LIT>', '<STR_LIT:T>', T, '<STR_LIT:P>', P, self.CASRN)<EOL><DEDENT>elif method in self.tabular_data:<EOL><INDENT>mu = self.interpolate_P(T, P, method)<EOL><DEDENT>return mu<EOL>

r'''Method to calculate pressure-dependent gas viscosity
        at temperature `T` and pressure `P` with a given method.

        This method has no exception handling; see `TP_dependent_property`
        for that.

        Parameters
        ----------
        T : float
            Temperature at which to calculate gas viscosity, [K]
        P : float
            Pressure at which to calculate gas viscosity, [K]
        method : str
            Name of the method to use

        Returns
        -------
        mu : float
            Viscosity of the gas at T and P, [Pa*]


methods = [SIMPLE]        <EOL>if none_and_length_check((self.MWs, self.molecular_diameters, self.Stockmayers)):<EOL><INDENT>methods.append(BROKAW)<EOL><DEDENT>if none_and_length_check([self.MWs]):<EOL><INDENT>methods.extend([WILKE, HERNING_ZIPPERER])<EOL><DEDENT>self.all_methods = set(methods)<EOL>Tmins = [i.Tmin for i in self.ViscosityGases if i.Tmin]<EOL>Tmaxs = [i.Tmax for i in self.ViscosityGases if i.Tmax]<EOL>if Tmins:<EOL><INDENT>self.Tmin = max(Tmins)<EOL><DEDENT>if Tmaxs:<EOL><INDENT>self.Tmax = max(Tmaxs)<EOL><DEDENT>


if method == SIMPLE:<EOL><INDENT>mus = [i(T, P) for i in self.ViscosityGases]<EOL>return mixing_simple(zs, mus)<EOL><DEDENT>elif method == HERNING_ZIPPERER:<EOL><INDENT>mus = [i(T, P) for i in self.ViscosityGases]<EOL>return Herning_Zipperer(zs, mus, self.MWs)<EOL><DEDENT>elif method == WILKE:<EOL><INDENT>mus = [i(T, P) for i in self.ViscosityGases]<EOL>return Wilke(zs, mus, self.MWs)<EOL><DEDENT>elif method == BROKAW:<EOL><INDENT>mus = [i(T, P) for i in self.ViscosityGases]<EOL>return Brokaw(T, zs, mus, self.MWs, self.molecular_diameters, self.Stockmayers)<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>

r'''Method to calculate viscosity of a gas 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
        -------
        mu : float
            Viscosity of gas mixture, [Pa*s]


def Tt(CASRN, AvailableMethods=False, Method=None):

def list_methods():<EOL><INDENT>methods = []<EOL>if CASRN in Staveley_data.index:<EOL><INDENT>methods.append(STAVELEY)<EOL><DEDENT>if Tm(CASRN):<EOL><INDENT>methods.append(MELTING)<EOL><DEDENT>methods.append(NONE)<EOL>return methods<EOL><DEDENT>if AvailableMethods:<EOL><INDENT>return list_methods()<EOL><DEDENT>if not Method:<EOL><INDENT>Method = list_methods()[<NUM_LIT:0>]<EOL><DEDENT>if Method == STAVELEY:<EOL><INDENT>Tt = Staveley_data.at[CASRN, "<STR_LIT>"]<EOL><DEDENT>elif Method == MELTING:<EOL><INDENT>Tt = Tm(CASRN)<EOL><DEDENT>elif Method == NONE:<EOL><INDENT>Tt = None<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>return Tt<EOL>

r'''This function handles the retrieval of a chemical's triple temperature.
    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.

    Returns data from [1]_, or a chemical's melting point if available.

    Parameters
    ----------
    CASRN : string
        CASRN [-]

    Returns
    -------
    Tt : float
        Triple point temperature, [K]
    methods : list, only returned if AvailableMethods == True
        List of methods which can be used to obtain Tt with the
        given inputs

    Other Parameters
    ----------------
    Method : string, optional
        A string for the method name to use, as defined by constants in
        Tt_methods
    AvailableMethods : bool, optional
        If True, function will determine which methods can be used to obtain
        the Tt for the desired chemical, and will return methods
        instead of the Tt

    Notes
    -----
    Median difference between melting points and triple points is 0.02 K.
    Accordingly, this should be more than good enough for engineering
    applications.

    Temperatures are on the ITS-68 scale.

    Examples
    --------
    Ammonia

    >>> Tt('7664-41-7')
    195.47999999999999

    References
    ----------
    .. [1] Staveley, L. A. K., L. Q. Lobo, and J. C. G. Calado. "Triple-Points
       of Low Melting Substances and Their Use in Cryogenic Work." Cryogenics
       21, no. 3 (March 1981): 131-144. doi:10.1016/0011-2275(81)90264-2.


def Pt(CASRN, AvailableMethods=False, Method=None):

def list_methods():<EOL><INDENT>methods = []<EOL>if CASRN in Staveley_data.index and not np.isnan(Staveley_data.at[CASRN, '<STR_LIT>']):<EOL><INDENT>methods.append(STAVELEY)<EOL><DEDENT>if Tt(CASRN) and VaporPressure(CASRN=CASRN).T_dependent_property(T=Tt(CASRN)):<EOL><INDENT>methods.append(DEFINITION)<EOL><DEDENT>methods.append(NONE)<EOL>return methods<EOL><DEDENT>if AvailableMethods:<EOL><INDENT>return list_methods()<EOL><DEDENT>if not Method:<EOL><INDENT>Method = list_methods()[<NUM_LIT:0>]<EOL><DEDENT>if Method == STAVELEY:<EOL><INDENT>Pt = Staveley_data.at[CASRN, '<STR_LIT>']<EOL><DEDENT>elif Method == DEFINITION:<EOL><INDENT>Pt = VaporPressure(CASRN=CASRN).T_dependent_property(T=Tt(CASRN))<EOL><DEDENT>elif Method == NONE:<EOL><INDENT>Pt = None<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>return Pt<EOL>

r'''This function handles the retrieval of a chemical's triple pressure.
    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.

    Returns data from [1]_, or attempts to calculate the vapor pressure at the
    triple temperature, if data is available.

    Parameters
    ----------
    CASRN : string
        CASRN [-]

    Returns
    -------
    Pt : float
        Triple point pressure, [Pa]
    methods : list, only returned if AvailableMethods == True
        List of methods which can be used to obtain Pt with the
        given inputs

    Other Parameters
    ----------------
    Method : string, optional
        A string for the method name to use, as defined by constants in
        Pt_methods
    AvailableMethods : bool, optional
        If True, function will determine which methods can be used to obtain
        the Pt for the desired chemical, and will return methods
        instead of the Pt

    Notes
    -----

    Examples
    --------
    Ammonia

    >>> Pt('7664-41-7')
    6079.5

    References
    ----------
    .. [1] Staveley, L. A. K., L. Q. Lobo, and J. C. G. Calado. "Triple-Points
       of Low Melting Substances and Their Use in Cryogenic Work." Cryogenics
       21, no. 3 (March 1981): 131-144. doi:10.1016/0011-2275(81)90264-2.


for i in range(len(values)):<EOL><INDENT>try:<EOL><INDENT>values[i] = float(values[i])<EOL><DEDENT>except:<EOL><INDENT>if values[i] == '<STR_LIT>':<EOL><INDENT>values[i] = None<EOL><DEDENT>else:<EOL><INDENT>values[i] = values[i].strip()<EOL>pass<EOL><DEDENT><DEDENT><DEDENT>return values<EOL>

r'''Legacy function to turn a list of strings into either floats
    (if numeric), stripped strings (if not) or None if the string is empty.
    Accepts any numeric formatting the float function does.

    Parameters
    ----------
    values : list
        list of strings

    Returns
    -------
    values : list
        list of floats, strings, and None values [-]

    Examples
    --------
    >>> to_num(['1', '1.1', '1E5', '0xB4', ''])
    [1.0, 1.1, 100000.0, '0xB4', None]


return int(i.replace('<STR_LIT:->', '<STR_LIT>'))<EOL>

r'''Converts CAS number of a compounds from a string to an int. This is
    helpful when storing large amounts of CAS numbers, as their strings take up
    more memory than their numerical representational. All CAS numbers fit into
    64 bit ints.

    Parameters
    ----------
    CASRN : string
        CASRN [-]

    Returns
    -------
    CASRN : int
        CASRN [-]

    Notes
    -----
    Accomplishes conversion by removing dashes only, and then converting to an
    int. An incorrect CAS number will change without exception.

    Examples
    --------
    >>> CAS2int('7704-34-9')
    7704349


i = str(i)<EOL>return i[:-<NUM_LIT:3>]+'<STR_LIT:->'+i[-<NUM_LIT:3>:-<NUM_LIT:1>]+'<STR_LIT:->'+i[-<NUM_LIT:1>]<EOL>

r'''Converts CAS number of a compounds from an int to an string. This is
    helpful when dealing with int CAS numbers.

    Parameters
    ----------
    CASRN : int
        CASRN [-]

    Returns
    -------
    CASRN : string
        CASRN [-]

    Notes
    -----
    Handles CAS numbers with an unspecified number of digits. Does not work on
    floats.

    Examples
    --------
    >>> int2CAS(7704349)
    '7704-34-9'


rhol, rhog = rhol*<NUM_LIT>, rhog*<NUM_LIT> <EOL>return sigma**<NUM_LIT>*MW/(rhol-rhog)<EOL>

r'''Calculate Parachor for a pure species, using its density in the
    liquid and gas phases, surface tension, and molecular weight.

    .. math::
        P = \frac{\sigma^{0.25} MW}{\rho_L - \rho_V}

    Parameters
    ----------
    MW : float
        Molecular weight, [g/mol]
    rhol : float
        Liquid density [kg/m^3]
    rhog : float
        Gas density [kg/m^3]
    sigma : float
        Surface tension, [N/m]

    Returns
    -------
    P : float
        Parachor, [N^0.25*m^2.75/mol]

    Notes
    -----
    To convert the output of this function to units of [mN^0.25*m^2.75/kmol],
    multiply by 5623.4132519.

    Values in group contribution tables for Parachor are often listed as
    dimensionless, in which they are multiplied by 5623413 and the appropriate
    units to make them dimensionless.

    Examples
    --------
    Calculating Parachor from a known surface tension for methyl isobutyl
    ketone at 293.15 K

    >>> Parachor(100.15888, 800.8088185536124, 4.97865317223119, 0.02672166960656005)
    5.088443542210164e-05

    Converting to the `dimensionless` form:

    >>> 5623413*5.088443542210164e-05
    286.14419565030687

    Compared to 274.9 according to a group contribution method described in
    [3]_.

    References
    ----------
    .. [1] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition.
       New York: McGraw-Hill Professional, 2000.
    .. [2] Green, Don, and Robert Perry. Perry's Chemical Engineers' Handbook,
       8E. McGraw-Hill Professional, 2007.
    .. [3] Danner, Ronald P, and Design Institute for Physical Property Data.
       Manual for Predicting Chemical Process Design Data. New York, N.Y, 1982.


return <NUM_LIT>/SG - <NUM_LIT><EOL>

r'''Calculates specific gravity of a liquid given its API, as shown in
    [1]_.

    .. math::
        \text{API gravity} = \frac{141.5}{\text{SG}} - 131.5

    Parameters
    ----------
    SG : float
        Specific gravity of the fluid at 60 degrees Farenheight [-]

    Returns
    -------
    API : float
        API of the fluid [-]

    Notes
    -----
    Defined only at 60 degrees Fahrenheit.

    Examples
    --------
    >>> SG_to_API(0.7365)
    60.62491513917175

    References
    ----------
    .. [1] API Technical Data Book: General Properties & Characterization.
    American Petroleum Institute, 7E, 2005.


return <NUM_LIT>/(API + <NUM_LIT>)<EOL>

r'''Calculates API of a liquid given its specific gravity, as shown in
    [1]_.

    .. math::
        \text{SG at}~60^\circ\text{F} = \frac{141.5}{\text{API gravity} +131.5}

    Parameters
    ----------
    API : float
        API of the fluid [-]

    Returns
    -------
    SG : float
        Specific gravity of the fluid at 60 degrees Farenheight [-]

    Notes
    -----
    Defined only at 60 degrees Fahrenheit.

    Examples
    --------
    >>> API_to_SG(60.62)
    0.7365188423901728

    References
    ----------
    .. [1] API Technical Data Book: General Properties & Characterization.
    American Petroleum Institute, 7E, 2005.


return rho/rho_ref<EOL>

r'''Calculates the specific gravity of a substance with respect to another
    substance; by default, this is water at 15.6 °C (60 °F). For gases,
    normally the reference density is 1.2 kg/m^3, that of dry air. However, in
    general specific gravity should always be specified with respect to the
    temperature and pressure of its reference fluid. This can vary widely.

    .. math::
        SG = \frac{\rho}{\rho_{ref}}

    Parameters
    ----------
    rho : float
        Density of the substance, [kg/m^3]
    rho_ref : float, optional
        Density of the reference substance, [kg/m^3]

    Returns
    -------
    SG : float
        Specific gravity of the substance with respect to the reference
        density, [-]

    Notes
    -----
    Another common reference point is water at 4°C (rho_ref=999.9748691393087).
    Specific gravity is often used by consumers instead of density.
    The reference for solids is normally the same as for liquids - water.

    Examples
    --------
    >>> SG(860)
    0.8608461408159591


return dV_dT/V<EOL>

r'''Calculate the isobaric coefficient of a thermal expansion, given its
    molar volume at a certain `T` and `P`, and its derivative of molar volume
    with respect to `T`.

    .. math::
        \beta = \frac{1}{V}\left(\frac{\partial V}{\partial T} \right)_P

    Parameters
    ----------
    V : float
        Molar volume at `T` and `P`, [m^3/mol]
    dV_dT : float
        Derivative of molar volume with respect to `T`, [m^3/mol/K]

    Returns
    -------
    beta : float
        Isobaric coefficient of a thermal expansion, [1/K]

    Notes
    -----
    For an ideal gas, this expression simplified to:

    .. math::
        \beta = \frac{1}{T}

    Examples
    --------
    Calculated for hexane from the PR EOS at 299 K and 1 MPa (liquid):

    >>> isobaric_expansion(0.000130229900873546, 1.58875261849113e-7)
    0.0012199599384121608

    References
    ----------
    .. [1] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition.
       New York: McGraw-Hill Professional, 2000.


return -dV_dP/V<EOL>

r'''Calculate the isothermal coefficient of a compressibility, given its
    molar volume at a certain `T` and `P`, and its derivative of molar volume
    with respect to `P`.

    .. math::
        \kappa = -\frac{1}{V}\left(\frac{\partial V}{\partial P} \right)_T

    Parameters
    ----------
    V : float
        Molar volume at `T` and `P`, [m^3/mol]
    dV_dP : float
        Derivative of molar volume with respect to `P`, [m^3/mol/Pa]

    Returns
    -------
    kappa : float
        Isothermal coefficient of a compressibility, [1/Pa]

    Notes
    -----
    For an ideal gas, this expression simplified to:

    .. math::
        \kappa = \frac{1}{P}

    Examples
    --------
    Calculated for hexane from the PR EOS at 299 K and 1 MPa (liquid):

    >>> isothermal_compressibility(0.000130229900873546, -2.72902118209903e-13)
    2.095541165119158e-09

    References
    ----------
    .. [1] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition.
       New York: McGraw-Hill Professional, 2000.


def phase_identification_parameter(V, dP_dT, dP_dV, d2P_dV2, d2P_dVdT):

return V*(d2P_dVdT/dP_dT - d2P_dV2/dP_dV)<EOL>

r'''Calculate the Phase Identification Parameter developed in [1]_ for
    the accurate and efficient determination of whether a fluid is a liquid or
    a gas based on the results of an equation of state. For supercritical
    conditions, this provides a good method for choosing which property
    correlations to use.

    .. math::
        \Pi = V \left[\frac{\frac{\partial^2 P}{\partial V \partial T}}
        {\frac{\partial P }{\partial T}}- \frac{\frac{\partial^2 P}{\partial
        V^2}}{\frac{\partial P}{\partial V}} \right]

    Parameters
    ----------
    V : float
        Molar volume at `T` and `P`, [m^3/mol]
    dP_dT : float
        Derivative of `P` with respect to `T`, [Pa/K]
    dP_dV : float
        Derivative of `P` with respect to `V`, [Pa*mol/m^3]
    d2P_dV2 : float
        Second derivative of `P` with respect to `V`, [Pa*mol^2/m^6]
    d2P_dVdT : float
        Second derivative of `P` with respect to both `V` and `T`, [Pa*mol/m^3/K]

    Returns
    -------
    PIP : float
        Phase Identification Parameter, [-]

    Notes
    -----
    Heuristics were used by process simulators before the invent of this
    parameter.

    The criteria for liquid is Pi > 1; for vapor, Pi <= 1.

    There is also a solid phase mechanism available. For solids, the Solid
    Phase Identification Parameter is greater than 1, like liquids; however,
    unlike liquids, d2P_dVdT is always >0; it is < 0 for liquids and gases.

    Examples
    --------
    Calculated for hexane from the PR EOS at 299 K and 1 MPa (liquid):

    >>> phase_identification_parameter(0.000130229900874, 582169.397484,
    ... -3.66431747236e+12, 4.48067893805e+17, -20518995218.2)
    11.33428990564796

    References
    ----------
    .. [1] Venkatarathnam, G., and L. R. Oellrich. "Identification of the Phase
       of a Fluid Using Partial Derivatives of Pressure, Volume, and
       Temperature without Reference to Saturation Properties: Applications in
       Phase Equilibria Calculations." Fluid Phase Equilibria 301, no. 2
       (February 25, 2011): 225-33. doi:10.1016/j.fluid.2010.12.001.
    .. [2] Jayanti, Pranava Chaitanya, and G. Venkatarathnam. "Identification
       of the Phase of a Substance from the Derivatives of Pressure, Volume and
       Temperature, without Prior Knowledge of Saturation Properties: Extension
       to Solid Phase." Fluid Phase Equilibria 425 (October 15, 2016): 269-277.
       doi:10.1016/j.fluid.2016.06.001.


def phase_identification_parameter_phase(d2P_dVdT, V=None, dP_dT=None, dP_dV=None, d2P_dV2=None):

if d2P_dVdT > <NUM_LIT:0>:<EOL><INDENT>return '<STR_LIT:s>'<EOL><DEDENT>else:<EOL><INDENT>PIP = phase_identification_parameter(V=V, dP_dT=dP_dT, dP_dV=dP_dV, <EOL>d2P_dV2=d2P_dV2, d2P_dVdT=d2P_dVdT)<EOL>return '<STR_LIT:l>' if PIP > <NUM_LIT:1> else '<STR_LIT:g>'<EOL><DEDENT>

r'''Uses the Phase Identification Parameter concept developed in [1]_ and
    [2]_ to determine if a chemical is a solid, liquid, or vapor given the
    appropriate thermodynamic conditions.

    The criteria for liquid is PIP > 1; for vapor, PIP <= 1.

    For solids, PIP(solid) is defined to be d2P_dVdT. If it is larger than 0,
    the species is a solid. It is less than 0 for all liquids and gases.

    Parameters
    ----------
    d2P_dVdT : float
        Second derivative of `P` with respect to both `V` and `T`, [Pa*mol/m^3/K]
    V : float, optional
        Molar volume at `T` and `P`, [m^3/mol]
    dP_dT : float, optional
        Derivative of `P` with respect to `T`, [Pa/K]
    dP_dV : float, optional
        Derivative of `P` with respect to `V`, [Pa*mol/m^3]
    d2P_dV2 : float, optionsl
        Second derivative of `P` with respect to `V`, [Pa*mol^2/m^6]

    Returns
    -------
    phase : str
        Either 's', 'l' or 'g'

    Notes
    -----
    The criteria for being a solid phase is checked first, which only
    requires d2P_dVdT. All other inputs are optional for this reason.
    However, an exception will be raised if the other inputs become
    needed to determine if a species is a liquid or a gas.

    Examples
    --------
    Calculated for hexane from the PR EOS at 299 K and 1 MPa (liquid):

    >>> phase_identification_parameter_phase(-20518995218.2, 0.000130229900874,
    ... 582169.397484, -3.66431747236e+12, 4.48067893805e+17)
    'l'

    References
    ----------
    .. [1] Venkatarathnam, G., and L. R. Oellrich. "Identification of the Phase
       of a Fluid Using Partial Derivatives of Pressure, Volume, and
       Temperature without Reference to Saturation Properties: Applications in
       Phase Equilibria Calculations." Fluid Phase Equilibria 301, no. 2
       (February 25, 2011): 225-33. doi:10.1016/j.fluid.2010.12.001.
    .. [2] Jayanti, Pranava Chaitanya, and G. Venkatarathnam. "Identification
       of the Phase of a Substance from the Derivatives of Pressure, Volume and
       Temperature, without Prior Knowledge of Saturation Properties: Extension
       to Solid Phase." Fluid Phase Equilibria 425 (October 15, 2016): 269-277.
       doi:10.1016/j.fluid.2016.06.001.


return -T*dP_dT**<NUM_LIT:2>/dP_dV<EOL>

r'''Calculate the difference between a real gas's constant-pressure heat
    capacity and constant-volume heat capacity, as given in [1]_, [2]_, and
    [3]_. The required derivatives should be calculated with an equation of
    state.

    .. math::
        C_p - C_v = -T\left(\frac{\partial P}{\partial T}\right)_V^2/
        \left(\frac{\partial P}{\partial V}\right)_T

    Parameters
    ----------
    T : float
        Temperature of fluid [K]
    dP_dT : float
        Derivative of `P` with respect to `T`, [Pa/K]
    dP_dV : float
        Derivative of `P` with respect to `V`, [Pa*mol/m^3]

    Returns
    -------
    Cp_minus_Cv : float
        Cp - Cv for a real gas, [J/mol/K]

    Notes
    -----
    Equivalent expressions are:

    .. math::
        C_p - C_v= -T\left(\frac{\partial V}{\partial T}\right)_P^2/\left(
        \frac{\partial V}{\partial P}\right)_T

        C_p - C_v = T\left(\frac{\partial P}{\partial T}\right)
        \left(\frac{\partial V}{\partial T}\right)

    Note that these are not second derivatives, only first derivatives, some
    of which are squared.

    Examples
    --------
    Calculated for hexane from the PR EOS at 299 K and 1 MPa (liquid):

    >>> Cp_minus_Cv(299, 582232.475794113, -3665180614672.253)
    27.654681381642394

    References
    ----------
    .. [1] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition.
       New York: McGraw-Hill Professional, 2000.
    .. [2] Walas, Stanley M. Phase Equilibria in Chemical Engineering.
       Butterworth-Heinemann, 1985.
    .. [3] Gmehling, Jurgen, Barbel Kolbe, Michael Kleiber, and Jurgen Rarey.
       Chemical Thermodynamics for Process Simulation. 1st edition. Weinheim:
       Wiley-VCH, 2012.


def speed_of_sound(V, dP_dV, Cp, Cv, MW=None):

if not MW:<EOL><INDENT>return (-V**<NUM_LIT:2>*dP_dV*Cp/Cv)**<NUM_LIT:0.5><EOL><DEDENT>else:<EOL><INDENT>return (-V**<NUM_LIT:2>*<NUM_LIT>/MW*dP_dV*Cp/Cv)**<NUM_LIT:0.5><EOL><DEDENT>

r'''Calculate a real fluid's speed of sound. The required derivatives should
    be calculated with an equation of state, and `Cp` and `Cv` are both the
    real fluid versions. Expression is given in [1]_ and [2]_; a unit conversion
    is further performed to obtain a result in m/s. If MW is not provided the
    result is returned in units of m*kg^0.5/s/mol^0.5.

    .. math::
        w = \left[-V^2 \left(\frac{\partial P}{\partial V}\right)_T \frac{C_p}
        {C_v}\right]^{1/2}

    Parameters
    ----------
    V : float
        Molar volume of fluid, [m^3/mol]
    dP_dV : float
        Derivative of `P` with respect to `V`, [Pa*mol/m^3]
    Cp : float
        Real fluid heat capacity at constant pressure, [J/mol/K]
    Cv : float
        Real fluid heat capacity at constant volume, [J/mol/K]
    MW : float, optional
        Molecular weight, [g/mol]

    Returns
    -------
    w : float
        Speed of sound for a real gas, [m/s or m*kg^0.5/s/mol^0.5 or MW missing]

    Notes
    -----
    An alternate expression based on molar density is as follows:

    .. math::
       w = \left[\left(\frac{\partial P}{\partial \rho}\right)_T \frac{C_p}
       {C_v}\right]^{1/2}

    The form with the unit conversion performed inside it is as follows:

    .. math::
        w = \left[-V^2 \frac{1000}{MW}\left(\frac{\partial P}{\partial V}
        \right)_T \frac{C_p}{C_v}\right]^{1/2}

    Examples
    --------
    Example from [2]_:

    >>> speed_of_sound(V=0.00229754, dP_dV=-3.5459e+08, Cp=153.235, Cv=132.435, MW=67.152)
    179.5868138460819

    References
    ----------
    .. [1] Gmehling, Jurgen, Barbel Kolbe, Michael Kleiber, and Jurgen Rarey.
       Chemical Thermodynamics for Process Simulation. 1st edition. Weinheim:
       Wiley-VCH, 2012.
    .. [2] Pratt, R. M. "Thermodynamic Properties Involving Derivatives: Using
       the Peng-Robinson Equation of State." Chemical Engineering Education 35,
       no. 2 (March 1, 2001): 112-115.


def Joule_Thomson(T, V, Cp, dV_dT=None, beta=None):

if dV_dT:<EOL><INDENT>return (T*dV_dT - V)/Cp<EOL><DEDENT>elif beta:<EOL><INDENT>return V/Cp*(beta*T - <NUM_LIT:1.>)<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>

r'''Calculate a real fluid's Joule Thomson coefficient. The required
    derivative should be calculated with an equation of state, and `Cp` is the
    real fluid versions. This can either be calculated with `dV_dT` directly,
    or with `beta` if it is already known.

    .. math::
        \mu_{JT} = \left(\frac{\partial T}{\partial P}\right)_H = \frac{1}{C_p}
        \left[T \left(\frac{\partial V}{\partial T}\right)_P - V\right]
        = \frac{V}{C_p}\left(\beta T-1\right)

    Parameters
    ----------
    T : float
        Temperature of fluid, [K]
    V : float
        Molar volume of fluid, [m^3/mol]
    Cp : float
        Real fluid heat capacity at constant pressure, [J/mol/K]
    dV_dT : float, optional
        Derivative of `V` with respect to `T`, [m^3/mol/K]
    beta : float, optional
        Isobaric coefficient of a thermal expansion, [1/K]

    Returns
    -------
    mu_JT : float
        Joule-Thomson coefficient [K/Pa]

    Examples
    --------
    Example from [2]_:

    >>> Joule_Thomson(T=390, V=0.00229754, Cp=153.235, dV_dT=1.226396e-05)
    1.621956080529905e-05

    References
    ----------
    .. [1] Walas, Stanley M. Phase Equilibria in Chemical Engineering.
       Butterworth-Heinemann, 1985.
    .. [2] Pratt, R. M. "Thermodynamic Properties Involving Derivatives: Using
       the Peng-Robinson Equation of State." Chemical Engineering Education 35,
       no. 2 (March 1, 2001): 112-115.


return Cp/Cv<EOL>

r'''Calculate the isentropic coefficient of a gas, given its constant-
    pressure and constant-volume heat capacity.

    .. math::
        k = \frac{C_p}{C_v}

    Parameters
    ----------
    Cp : float
        Gas heat capacity at constant pressure, [J/mol/K]
    Cv : float
        Gas heat capacity at constant volume, [J/mol/K]

    Returns
    -------
    k : float
        Isentropic exponent, [-]

    Examples
    --------
    >>> isentropic_exponent(33.6, 25.27)
    1.329639889196676

    References
    ----------
    .. [1] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition.
       New York: McGraw-Hill Professional, 2000.


return (Vm)**-<NUM_LIT:1>*MW/<NUM_LIT><EOL>

r'''Calculate the density of a chemical, given its molar volume and
    molecular weight.

    .. math::
        \rho = \frac{MW}{1000\cdot VM}

    Parameters
    ----------
    Vm : float
        Molar volume, [m^3/mol]
    MW : float
        Molecular weight, [g/mol]

    Returns
    -------
    rho : float
        Density, [kg/m^3]

    Examples
    --------
    >>> Vm_to_rho(0.000132, 86.18)
    652.8787878787879

    References
    ----------
    .. [1] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition.
       New York: McGraw-Hill Professional, 2000.


return (rho*<NUM_LIT>/MW)**-<NUM_LIT:1><EOL>

r'''Calculate the molar volume of a chemical, given its density and
    molecular weight.

    .. math::
        V_m = \left(\frac{1000 \rho}{MW}\right)^{-1}

    Parameters
    ----------
    rho : float
        Density, [kg/m^3]
    MW : float
        Molecular weight, [g/mol]

    Returns
    -------
    Vm : float
        Molar volume, [m^3/mol]

    Examples
    --------
    >>> rho_to_Vm(652.9, 86.18)
    0.00013199571144126206

    References
    ----------
    .. [1] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition.
       New York: McGraw-Hill Professional, 2000.


return V*P/T/R<EOL>

r'''Calculates the compressibility factor of a gas, given its
    temperature, pressure, and molar volume.

    .. math::
        Z = \frac{PV}{RT}

    Parameters
    ----------
    T : float
        Temperature, [K]
    P : float
        Pressure [Pa]
    V : float
        Molar volume, [m^3/mol]

    Returns
    -------
    Z : float
        Compressibility factor, [-]

    Examples
    --------
    >>> Z(600, P=1E6, V=0.00463)
    0.9281019876560912

    References
    ----------
    .. [1] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition.
       New York: McGraw-Hill Professional, 2000.


return <NUM_LIT:1.> + B*P/R/T<EOL>

r'''Calculates the compressibility factor of a gas, given its
    second virial coefficient.

    .. math::
        Z = 1 + \frac{BP}{RT}

    Parameters
    ----------
    B : float
        Second virial coefficient, [m^3/mol]
    T : float
        Temperature, [K]
    P : float
        Pressure [Pa]

    Returns
    -------
    Z : float
        Compressibility factor, [-]

    Notes
    -----
    Other forms of the virial coefficient exist.

    Examples
    --------
    >>> B_to_Z(-0.0015, 300, 1E5)
    0.9398638020957176

    References
    ----------
    .. [1] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition.
       New York: McGraw-Hill Professional, 2000.


return (Z - <NUM_LIT:1>)*R*T/P<EOL>

r'''Calculates the second virial coefficient of a pure species, given the
    compressibility factor of the gas.

    .. math::
        B = \frac{RT(Z-1)}{P}

    Parameters
    ----------
    Z : float
        Compressibility factor, [-]
    T : float
        Temperature, [K]
    P : float
        Pressure [Pa]

    Returns
    -------
    B : float
        Second virial coefficient, [m^3/mol]

    Notes
    -----
    Other forms of the virial coefficient exist.

    Examples
    --------
    >>> B_from_Z(0.94, 300, 1E5)
    -0.0014966027640000014

    References
    ----------
    .. [1] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition.
       New York: McGraw-Hill Professional, 2000.


def Z_from_virial_density_form(T, P, *args):

l = len(args)<EOL>if l == <NUM_LIT:1>:<EOL><INDENT>return <NUM_LIT:1>/<NUM_LIT> + (<NUM_LIT:4>*args[<NUM_LIT:0>]*P + R*T)**<NUM_LIT:0.5>/(<NUM_LIT:2>*(R*T)**<NUM_LIT:0.5>)<EOL><INDENT>return ((R*T*(<NUM_LIT:4>*args[<NUM_LIT:0>]*P + R*T))**<NUM_LIT:0.5> + R*T)/(<NUM_LIT:2>*P)<EOL><DEDENT><DEDENT>if l == <NUM_LIT:2>:<EOL><INDENT>B, C = args<EOL>return (P*(-(<NUM_LIT:3>*B*R*T/P + R**<NUM_LIT:2>*T**<NUM_LIT:2>/P**<NUM_LIT:2>)/(<NUM_LIT:3>*(-<NUM_LIT:1>/<NUM_LIT:2> + csqrt(<NUM_LIT:3>)*<NUM_LIT>/<NUM_LIT:2>)*(-<NUM_LIT:9>*B*R**<NUM_LIT:2>*T**<NUM_LIT:2>/(<NUM_LIT:2>*P**<NUM_LIT:2>) - <NUM_LIT>*C*R*T/(<NUM_LIT:2>*P) + csqrt(-<NUM_LIT:4>*(<NUM_LIT:3>*B*R*T/P + R**<NUM_LIT:2>*T**<NUM_LIT:2>/P**<NUM_LIT:2>)**(<NUM_LIT:3>+<NUM_LIT>) + (-<NUM_LIT:9>*B*R**<NUM_LIT:2>*T**<NUM_LIT:2>/P**<NUM_LIT:2> - <NUM_LIT>*C*R*T/P - <NUM_LIT:2>*R**<NUM_LIT:3>*T**<NUM_LIT:3>/P**<NUM_LIT:3>)**(<NUM_LIT:2>+<NUM_LIT>))/<NUM_LIT:2> - R**<NUM_LIT:3>*T**<NUM_LIT:3>/P**<NUM_LIT:3>)**(<NUM_LIT:1>/<NUM_LIT>+<NUM_LIT>)) - (-<NUM_LIT:1>/<NUM_LIT:2> + csqrt(<NUM_LIT:3>)*<NUM_LIT>/<NUM_LIT:2>)*(-<NUM_LIT:9>*B*R**<NUM_LIT:2>*T**<NUM_LIT:2>/(<NUM_LIT:2>*P**<NUM_LIT:2>) - <NUM_LIT>*C*R*T/(<NUM_LIT:2>*P) + csqrt(-<NUM_LIT:4>*(<NUM_LIT:3>*B*R*T/P + R**<NUM_LIT:2>*T**<NUM_LIT:2>/P**<NUM_LIT:2>)**(<NUM_LIT:3>+<NUM_LIT>) + (-<NUM_LIT:9>*B*R**<NUM_LIT:2>*T**<NUM_LIT:2>/P**<NUM_LIT:2> - <NUM_LIT>*C*R*T/P - <NUM_LIT:2>*R**<NUM_LIT:3>*T**<NUM_LIT:3>/P**<NUM_LIT:3>)**(<NUM_LIT:2>+<NUM_LIT>))/<NUM_LIT:2> - R**<NUM_LIT:3>*T**<NUM_LIT:3>/P**<NUM_LIT:3>)**(<NUM_LIT:1>/<NUM_LIT>+<NUM_LIT>)/<NUM_LIT:3> + R*T/(<NUM_LIT:3>*P))/(R*T)).real<EOL><DEDENT>if l == <NUM_LIT:3>:<EOL><INDENT>B, C, D = args<EOL>P2 = P**<NUM_LIT:2> <EOL>RT = R*T<EOL>BRT = B*RT<EOL>T2 = T**<NUM_LIT:2><EOL>R2 = R**<NUM_LIT:2><EOL>RT23 = <NUM_LIT:3>*R2*T2<EOL>mCRT = -C*RT<EOL>P2256 = <NUM_LIT>*P2<EOL>RT23P2256 = RT23/(P2256)<EOL>big1 = (D*RT/P - (-BRT/P - RT23/(<NUM_LIT:8>*P2))**<NUM_LIT:2>/<NUM_LIT:12> - RT*(mCRT/(<NUM_LIT:4>*P) - RT*(BRT/(<NUM_LIT:16>*P) + RT23P2256)/P)/P)<EOL>big3 = (-BRT/P - RT23/(<NUM_LIT:8>*P2))<EOL>big4 = (mCRT/P - RT*(BRT/(<NUM_LIT:2>*P) + R2*T2/(<NUM_LIT:8>*P2))/P)<EOL>big5 = big3*(-D*RT/P + RT*(mCRT/(<NUM_LIT:4>*P) - RT*(BRT/(<NUM_LIT:16>*P) + RT23P2256)/P)/P)<EOL>big2 = <NUM_LIT:2>*big1/(<NUM_LIT:3>*(big3**<NUM_LIT:3>/<NUM_LIT> - big5/<NUM_LIT:6> + big4**<NUM_LIT:2>/<NUM_LIT:16> + csqrt(big1**<NUM_LIT:3>/<NUM_LIT> + (-big3**<NUM_LIT:3>/<NUM_LIT> + big5/<NUM_LIT:3> - big4**<NUM_LIT:2>/<NUM_LIT:8>)**<NUM_LIT:2>/<NUM_LIT:4>))**(<NUM_LIT:1>/<NUM_LIT:3>))<EOL>big7 = <NUM_LIT:2>*BRT/(<NUM_LIT:3>*P) - big2 + <NUM_LIT:2>*(big3**<NUM_LIT:3>/<NUM_LIT> - big5/<NUM_LIT:6> + big4**<NUM_LIT:2>/<NUM_LIT:16> + csqrt(big1**<NUM_LIT:3>/<NUM_LIT> + (-big3**<NUM_LIT:3>/<NUM_LIT> + big5/<NUM_LIT:3> - big4**<NUM_LIT:2>/<NUM_LIT:8>)**<NUM_LIT:2>/<NUM_LIT:4>))**(<NUM_LIT:1>/<NUM_LIT:3>) + R2*T2/(<NUM_LIT:4>*P2)<EOL>return (P*(((csqrt(big7)/<NUM_LIT:2> + csqrt(<NUM_LIT:4>*BRT/(<NUM_LIT:3>*P) - (-<NUM_LIT:2>*C*RT/P - <NUM_LIT:2>*RT*(BRT/(<NUM_LIT:2>*P) + R2*T2/(<NUM_LIT:8>*P2))/P)/csqrt(big7) + big2 - <NUM_LIT:2>*(big3**<NUM_LIT:3>/<NUM_LIT> - big5/<NUM_LIT:6> + big4**<NUM_LIT:2>/<NUM_LIT:16> + csqrt(big1**<NUM_LIT:3>/<NUM_LIT> + (-big3**<NUM_LIT:3>/<NUM_LIT> + big5/<NUM_LIT:3> - big4**<NUM_LIT:2>/<NUM_LIT:8>)**<NUM_LIT:2>/<NUM_LIT:4>))**(<NUM_LIT:1>/<NUM_LIT:3>) + R2*T2/(<NUM_LIT:2>*P2))/<NUM_LIT:2> + RT/(<NUM_LIT:4>*P))))/R/T).real<EOL><DEDENT>args = list(args)<EOL>args.reverse()<EOL>args.extend([<NUM_LIT:1>, -P/R/T])<EOL>solns = np.roots(args)<EOL>rho = [i for i in solns if not i.imag and i.real > <NUM_LIT:0>][<NUM_LIT:0>].real <EOL>return P/rho/R/T<EOL>

r'''Calculates the compressibility factor of a gas given its temperature,
    pressure, and molar density-form virial coefficients. Any number of
    coefficients is supported.

    .. math::
        Z = \frac{PV}{RT} = 1 + \frac{B}{V} + \frac{C}{V^2} + \frac{D}{V^3}
        + \frac{E}{V^4} \dots

    Parameters
    ----------
    T : float
        Temperature, [K]
    P : float
        Pressure, [Pa]
    B to Z : float, optional
        Virial coefficients, [various]

    Returns
    -------
    Z : float
        Compressibility factor at T, P, and with given virial coefficients, [-]

    Notes
    -----
    For use with B or with B and C or with B and C and D, optimized equations
    are used to obtain the compressibility factor directly.
    If more coefficients are provided, uses numpy's roots function to solve
    this equation. This takes substantially longer as the solution is
    numerical.

    If no virial coefficients are given, returns 1, as per the ideal gas law.

    The units of each virial coefficient are as follows, where for B, n=1, and
    C, n=2, and so on.

    .. math::
        \left(\frac{\text{m}^3}{\text{mol}}\right)^n

    Examples
    --------
    >>> Z_from_virial_density_form(300, 122057.233762653, 1E-4, 1E-5, 1E-6, 1E-7)
    1.2843496002100001

    References
    ----------
    .. [1] Prausnitz, John M., Rudiger N. Lichtenthaler, and Edmundo Gomes de
       Azevedo. Molecular Thermodynamics of Fluid-Phase Equilibria. 3rd
       edition. Upper Saddle River, N.J: Prentice Hall, 1998.
    .. [2] Walas, Stanley M. Phase Equilibria in Chemical Engineering.
       Butterworth-Heinemann, 1985.


return <NUM_LIT:1> + P*sum([coeff*P**i for i, coeff in enumerate(args)])<EOL>

r'''Calculates the compressibility factor of a gas given its pressure, and
    pressure-form virial coefficients. Any number of coefficients is supported.

    .. math::
        Z = \frac{Pv}{RT} = 1 + B'P + C'P^2 + D'P^3 + E'P^4 \dots

    Parameters
    ----------
    P : float
        Pressure, [Pa]
    B to Z : float, optional
        Pressure form Virial coefficients, [various]

    Returns
    -------
    Z : float
        Compressibility factor at P, and with given virial coefficients, [-]

    Notes
    -----
    Note that although this function does not require a temperature input, it
    is still dependent on it because the coefficients themselves normally are
    regressed in terms of temperature.

    The use of this form is less common than the density form. Its coefficients
    are normally indicated with the "'" suffix.

    If no virial coefficients are given, returns 1, as per the ideal gas law.

    The units of each virial coefficient are as follows, where for B, n=1, and
    C, n=2, and so on.

    .. math::
        \left(\frac{1}{\text{Pa}}\right)^n

    Examples
    --------
    >>> Z_from_virial_pressure_form(102919.99946855308, 4.032286555169439e-09, 1.6197059494442215e-13, 6.483855042486911e-19)
    1.00283753944

    References
    ----------
    .. [1] Prausnitz, John M., Rudiger N. Lichtenthaler, and Edmundo Gomes de
       Azevedo. Molecular Thermodynamics of Fluid-Phase Equilibria. 3rd
       edition. Upper Saddle River, N.J: Prentice Hall, 1998.
    .. [2] Walas, Stanley M. Phase Equilibria in Chemical Engineering.
       Butterworth-Heinemann, 1985.


Mavg = sum(zi*MWi for zi, MWi in zip(zs, MWs))<EOL>ws = [zi*MWi/Mavg for zi, MWi in zip(zs, MWs)]<EOL>return ws<EOL>

r'''Converts a list of mole fractions to mass fractions. Requires molecular
    weights for all species.

    .. math::
        w_i = \frac{z_i MW_i}{MW_{avg}}

        MW_{avg} = \sum_i z_i MW_i

    Parameters
    ----------
    zs : iterable
        Mole fractions [-]
    MWs : iterable
        Molecular weights [g/mol]

    Returns
    -------
    ws : iterable
        Mass fractions [-]

    Notes
    -----
    Does not check that the sums add to one. Does not check that inputs are of
    the same length.

    Examples
    --------
    >>> zs_to_ws([0.5, 0.5], [10, 20])
    [0.3333333333333333, 0.6666666666666666]


tot = sum(w/MW for w, MW in zip(ws, MWs))<EOL>zs = [w/MW/tot for w, MW in zip(ws, MWs)]<EOL>return zs<EOL>

r'''Converts a list of mass fractions to mole fractions. Requires molecular
    weights for all species.

    .. math::
        z_i = \frac{\frac{w_i}{MW_i}}{\sum_i \frac{w_i}{MW_i}}

    Parameters
    ----------
    ws : iterable
        Mass fractions [-]
    MWs : iterable
        Molecular weights [g/mol]

    Returns
    -------
    zs : iterable
        Mole fractions [-]

    Notes
    -----
    Does not check that the sums add to one. Does not check that inputs are of
    the same length.

    Examples
    --------
    >>> ws_to_zs([0.3333333333333333, 0.6666666666666666], [10, 20])
    [0.5, 0.5]


vol_is = [zi*Vmi for zi, Vmi in zip(zs, Vms)]<EOL>tot = sum(vol_is)<EOL>return [vol_i/tot for vol_i in vol_is]<EOL>

r'''Converts a list of mole fractions to volume fractions. Requires molar
    volumes for all species.

    .. math::
        \text{Vf}_i = \frac{z_i V_{m,i}}{\sum_i z_i V_{m,i}}

    Parameters
    ----------
    zs : iterable
        Mole fractions [-]
    VMs : iterable
        Molar volumes of species [m^3/mol]

    Returns
    -------
    Vfs : list
        Molar volume fractions [-]

    Notes
    -----
    Does not check that the sums add to one. Does not check that inputs are of
    the same length.

    Molar volumes are specified in terms of pure components only. Function
    works with any phase.

    Examples
    --------
    Acetone and benzene example

    >>> zs_to_Vfs([0.637, 0.363], [8.0234e-05, 9.543e-05])
    [0.5960229712956298, 0.4039770287043703]


mols_i = [Vfi/Vmi for Vfi, Vmi in zip(Vfs, Vms)]<EOL>mols = sum(mols_i)<EOL>return [mol_i/mols for mol_i in mols_i]<EOL>

r'''Converts a list of mass fractions to mole fractions. Requires molecular
    weights for all species.

    .. math::
        z_i = \frac{\frac{\text{Vf}_i}{V_{m,i}}}{\sum_i
        \frac{\text{Vf}_i}{V_{m,i}}}

    Parameters
    ----------
    Vfs : iterable
        Molar volume fractions [-]
    VMs : iterable
        Molar volumes of species [m^3/mol]

    Returns
    -------
    zs : list
        Mole fractions [-]

    Notes
    -----
    Does not check that the sums add to one. Does not check that inputs are of
    the same length.

    Molar volumes are specified in terms of pure components only. Function
    works with any phase.

    Examples
    --------
    Acetone and benzene example

    >>> Vfs_to_zs([0.596, 0.404], [8.0234e-05, 9.543e-05])
    [0.6369779395901142, 0.3630220604098858]


if not length:<EOL><INDENT>length = len(all_inputs[<NUM_LIT:0>])<EOL><DEDENT>for things in all_inputs:<EOL><INDENT>if None in things or len(things) != length:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>return True<EOL>

r'''Checks inputs for suitability of use by a mixing rule which requires
    all inputs to be of the same length and non-None. A number of variations
    were attempted for this function; this was found to be the quickest.

    Parameters
    ----------
    all_inputs : array-like of array-like
        list of all the lists of inputs, [-]
    length : int, optional
        Length of the desired inputs, [-]

    Returns
    -------
    False/True : bool
        Returns True only if all inputs are the same length (or length `length`)
        and none of the inputs contain None [-]

    Notes
    -----
    Does not check for nan values.

    Examples
    --------
    >>> none_and_length_check(([1, 1], [1, 1], [1, 30], [10,0]), length=2)
    True


def allclose_variable(a, b, limits, rtols=None, atols=None):

l = float(len(a))<EOL>if rtols is None and atols is None:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>elif rtols is None:<EOL><INDENT>rtols = [<NUM_LIT:0> for i in atols]<EOL><DEDENT>elif atols is None:<EOL><INDENT>atols = [<NUM_LIT:0> for i in rtols]<EOL><DEDENT>for atol, rtol, lim in zip(atols, rtols, limits):<EOL><INDENT>matches = np.count_nonzero(np.isclose(a, b, rtol=rtol, atol=atol))<EOL>if <NUM_LIT:1>-matches/l > lim:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>return True<EOL>

Returns True if two arrays are element-wise equal within several
    different tolerances. Tolerance values are always positive, usually
    very small. Based on numpy's allclose function.

    Only atols or rtols needs to be specified; both are used if given.

    Parameters
    ----------
    a, b : array_like
        Input arrays to compare.
    limits : array_like
        Fractions of elements allowed to not match to within each tolerance.
    rtols : array_like
        The relative tolerance parameters.
    atols : float
        The absolute tolerance parameters.

    Returns
    -------
    allclose : bool
        Returns True if the two arrays are equal within the given
        tolerances; False otherwise.

    Examples
    --------
    10 random similar variables, all of them matching to within 1E-5, allowing
    up to half to match up to 1E-6.

    >>> x = [2.7244322249597719e-08, 3.0105683900110473e-10, 2.7244124924802327e-08, 3.0105259397637556e-10, 2.7243929226310193e-08, 3.0104990272770901e-10, 2.7243666849384451e-08, 3.0104101821236015e-10, 2.7243433745917367e-08, 3.0103707421519949e-10]
    >>> y = [2.7244328304561904e-08, 3.0105753470546008e-10, 2.724412872417824e-08,  3.0105303055834564e-10, 2.7243914341030203e-08, 3.0104819238021998e-10, 2.7243684057561379e-08, 3.0104299541023674e-10, 2.7243436694839306e-08, 3.010374130526363e-10]
    >>> allclose_variable(x, y, limits=[.0, .5], rtols=[1E-5, 1E-6])
    True


tot = <NUM_LIT:0><EOL>for c in coeffs:<EOL><INDENT>tot = tot * x + c<EOL><DEDENT>return tot<EOL>

r'''Simple function to calculate the value of a polynomial at a specific
    value of `x`, using the Horner evaluation scheme

    Parameters
    ----------
    coeffs : array-like
        Coefficients, where coeffs[0] is multiplied by the largest power of x,
        and coeffs[-1] is added to the sum with no multiplication.
    x : float
        Value to evaluate the polynomial at

    Returns
    -------
    y : float
        Evaluated result

    Notes
    -----
    Efficient. Faster than numpy.polyval.

    Examples
    --------
    >>> horner([1,2,3], 3)
    18


if <NUM_LIT:0> <= x <= <NUM_LIT>:<EOL><INDENT>p = [<NUM_LIT>, -<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT>, <NUM_LIT>]<EOL>q = [-<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT:1.0>]<EOL>offset = <NUM_LIT><EOL><DEDENT>elif <NUM_LIT> < x <= <NUM_LIT>:<EOL><INDENT>p = [<NUM_LIT>, -<NUM_LIT>, -<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT>]<EOL>q = [-<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT:1.0>]<EOL>offset = <NUM_LIT><EOL><DEDENT>elif <NUM_LIT> < x <= <NUM_LIT:1>:<EOL><INDENT>p = [<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT>]<EOL>q = [-<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>, <NUM_LIT:1.0>]<EOL>offset = <NUM_LIT><EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>x = x - offset<EOL>return horner(p, x)/horner(q, x)<EOL>

r'''Simple function to calculate PolyLog(2, x) from ranges 0 <= x <= 1,
    with relative error guaranteed to be < 1E-7 from 0 to 0.99999. This
    is a Pade approximation, with three coefficient sets with splits at 0.7
    and 0.99. An exception is raised if x is under 0 or above 1.

    Parameters
    ----------
    x : float
        Value to evaluate PolyLog(2, x) T

    Returns
    -------
    y : float
        Evaluated result

    Notes
    -----
    Efficient (2-4 microseconds). No implementation of this function exists in
    SciPy. Derived with mpmath's pade approximation.
    Required for the entropy integral of
    :obj:`thermo.heat_capacity.Zabransky_quasi_polynomial`.

    Examples
    --------
    >>> polylog2(0.5)
    0.5822405264516294


tot = sum(values)<EOL>return [i/tot for i in values]<EOL>

r'''Simple function which normalizes a series of values to be from 0 to 1,
    and for their sum to add to 1.

    .. math::
        x = \frac{x}{sum_i x_i}

    Parameters
    ----------
    values : array-like
        array of values

    Returns
    -------
    fractions : array-like
        Array of values from 0 to 1

    Notes
    -----
    Does not work on negative values.

    Examples
    --------
    >>> normalize([3, 2, 1])
    [0.5, 0.3333333333333333, 0.16666666666666666]


if not none_and_length_check([fracs, props]):<EOL><INDENT>return None<EOL><DEDENT>result = sum(frac*prop for frac, prop in zip(fracs, props))<EOL>return result<EOL>

r'''Simple function calculates a property based on weighted averages of
    properties. Weights could be mole fractions, volume fractions, mass
    fractions, or anything else.

    .. math::
        y = \sum_i \text{frac}_i \cdot \text{prop}_i

    Parameters
    ----------
    fracs : array-like
        Fractions of a mixture
    props: array-like
        Properties

    Returns
    -------
    prop : value
        Calculated property

    Notes
    -----
    Returns None if any fractions or properties are missing or are not of the
    same length.

    Examples
    --------
    >>> mixing_simple([0.1, 0.9], [0.01, 0.02])
    0.019000000000000003