a, b = self.a, self.b<EOL>if quick:<EOL><INDENT>x1 = -<NUM_LIT>*<NUM_LIT> + <NUM_LIT:1.><EOL>x2 = V - b<EOL>x3 = x2/R<EOL>x4 = V + b<EOL>x5 = (<NUM_LIT>*(x2*x2*(-<NUM_LIT>*P*P*P*x3 + <NUM_LIT>*a*a/(V*V*x4*x4))/(R*R))**<NUM_LIT:0.5> - <NUM_LIT>*a*x3/(V*x4) +<NUM_LIT>)**(<NUM_LIT:1.>/<NUM_LIT>)<EOL>return (<NUM_LIT>*(<NUM_LIT>*P*x3/(x1*x5) + <NUM_LIT>*x1*x5)**<NUM_LIT:2>/<NUM_LIT>).real<EOL><DEDENT>else:<EOL><INDENT>return ((-(-<NUM_LIT:1>/<NUM_LIT:2> + sqrt(<NUM_LIT:3>)*<NUM_LIT>/<NUM_LIT:2>)*(sqrt(<NUM_LIT>*(-V*a + a*b)**<NUM_LIT:2>/(R*V**<NUM_LIT:2> + R*V*b)**<NUM_LIT:2> + <NUM_LIT>*(-P*V + P*b)**<NUM_LIT:3>/R**<NUM_LIT:3>)/<NUM_LIT:2> + <NUM_LIT>*(-V*a + a*b)/(<NUM_LIT:2>*(R*V**<NUM_LIT:2> + R*V*b))+<NUM_LIT>)**(<NUM_LIT:1>/<NUM_LIT:3>)/<NUM_LIT:3> + (-P*V + P*b)/(R*(-<NUM_LIT:1>/<NUM_LIT:2> + sqrt(<NUM_LIT:3>)*<NUM_LIT>/<NUM_LIT:2>)*(sqrt(<NUM_LIT>*(-V*a + a*b)**<NUM_LIT:2>/(R*V**<NUM_LIT:2> + R*V*b)**<NUM_LIT:2> + <NUM_LIT>*(-P*V + P*b)**<NUM_LIT:3>/R**<NUM_LIT:3>)/<NUM_LIT:2> + <NUM_LIT>*(-V*a + a*b)/(<NUM_LIT:2>*(R*V**<NUM_LIT:2> + R*V*b))+<NUM_LIT>)**(<NUM_LIT:1>/<NUM_LIT:3>)))**<NUM_LIT:2>).real<EOL><DEDENT>

r'''Method to calculate `T` from a specified `P` and `V` for the RK
        EOS. Uses `a`, and `b`, obtained from the class's namespace.

        Parameters
        ----------
        P : float
            Pressure, [Pa]
        V : float
            Molar volume, [m^3/mol]
        quick : bool, optional
            Whether to use a SymPy cse-derived expression (3x faster) or
            individual formulas

        Returns
        -------
        T : float
            Temperature, [K]

        Notes
        -----
        The exact solution can be derived as follows; it is excluded for
        breviety.

        >>> from sympy import *
        >>> P, T, V, R = symbols('P, T, V, R')
        >>> Tc, Pc = symbols('Tc, Pc')
        >>> a, b = symbols('a, b')

        >>> RK = Eq(P, R*T/(V-b) - a/sqrt(T)/(V*V + b*V))
        >>> # solve(RK, T)


def a_alpha_and_derivatives(self, T, full=True, quick=True):

a, Tc, m = self.a, self.Tc, self.m<EOL>sqTr = (T/Tc)**<NUM_LIT:0.5><EOL>a_alpha = a*(m*(<NUM_LIT:1.> - sqTr) + <NUM_LIT:1.>)**<NUM_LIT:2><EOL>if not full:<EOL><INDENT>return a_alpha<EOL><DEDENT>else:<EOL><INDENT>da_alpha_dT = -a*m*sqTr*(m*(-sqTr + <NUM_LIT:1.>) + <NUM_LIT:1.>)/T<EOL>d2a_alpha_dT2 =  a*m*sqTr*(m + <NUM_LIT:1.>)/(<NUM_LIT>*T*T)<EOL>return a_alpha, da_alpha_dT, d2a_alpha_dT2<EOL><DEDENT>

r'''Method to calculate `a_alpha` and its first and second
        derivatives for this EOS. Returns `a_alpha`, `da_alpha_dT`, and
        `d2a_alpha_dT2`. See `GCEOS.a_alpha_and_derivatives` for more
        documentation. Uses the set values of `Tc`, `m`, and `a`.

        .. math::
            a\alpha = a \left(m \left(- \sqrt{\frac{T}{Tc}} + 1\right)
            + 1\right)^{2}

            \frac{d a\alpha}{dT} = \frac{a m}{T} \sqrt{\frac{T}{Tc}} \left(m
            \left(\sqrt{\frac{T}{Tc}} - 1\right) - 1\right)

            \frac{d^2 a\alpha}{dT^2} = \frac{a m \sqrt{\frac{T}{Tc}}}{2 T^{2}}
            \left(m + 1\right)


a, b, Tc, m = self.a, self.b, self.Tc, self.m<EOL>if quick:<EOL><INDENT>x0 = R*Tc<EOL>x1 = V*b<EOL>x2 = x0*x1<EOL>x3 = V*V<EOL>x4 = x0*x3<EOL>x5 = m*m<EOL>x6 = a*x5<EOL>x7 = b*x6<EOL>x8 = V*x6<EOL>x9 = (x2 + x4 + x7 - x8)**<NUM_LIT:2><EOL>x10 = x3*x3<EOL>x11 = R*R*Tc*Tc<EOL>x12 = a*a<EOL>x13 = x5*x5<EOL>x14 = x12*x13<EOL>x15 = b*b<EOL>x16 = x3*V<EOL>x17 = a*x0<EOL>x18 = x17*x5<EOL>x19 = <NUM_LIT>*b*x16<EOL>x20 = -<NUM_LIT>*V*b*x14 + <NUM_LIT>*V*x15*x18 + x10*x11 + x11*x15*x3 + x11*x19 + x14*x15 + x14*x3 - <NUM_LIT:2>*x16*x18<EOL>x21 = V - b<EOL>x22 = <NUM_LIT:2>*m*x17<EOL>x23 = P*x4<EOL>x24 = P*x8<EOL>x25 = x1*x17<EOL>x26 = P*R*Tc<EOL>x27 = x17*x3<EOL>x28 = V*x12<EOL>x29 = <NUM_LIT>*m*m*m<EOL>x30 = b*x12<EOL>return -Tc*(<NUM_LIT>*a*m*x9*(V*x21*x21*x21*(V + b)*(P*x2 + P*x7 + x17 + x18 + x22 + x23 - x24))**<NUM_LIT:0.5>*(m + <NUM_LIT:1.>) - x20*x21*(-P*x16*x6 + x1*x22 + x10*x26 + x13*x28 - x13*x30 + x15*x23 + x15*x24 + x19*x26 + x22*x3 + x25*x5 + x25 + x27*x5 + x27 + x28*x29 + x28*x5 - x29*x30 - x30*x5))/(x20*x9)<EOL><DEDENT>else:<EOL><INDENT>return Tc*(-<NUM_LIT:2>*a*m*sqrt(V*(V - b)**<NUM_LIT:3>*(V + b)*(P*R*Tc*V**<NUM_LIT:2> + P*R*Tc*V*b - P*V*a*m**<NUM_LIT:2> + P*a*b*m**<NUM_LIT:2> + R*Tc*a*m**<NUM_LIT:2> + <NUM_LIT:2>*R*Tc*a*m + R*Tc*a))*(m + <NUM_LIT:1>)*(R*Tc*V**<NUM_LIT:2> + R*Tc*V*b - V*a*m**<NUM_LIT:2> + a*b*m**<NUM_LIT:2>)**<NUM_LIT:2> + (V - b)*(R**<NUM_LIT:2>*Tc**<NUM_LIT:2>*V**<NUM_LIT:4> + <NUM_LIT:2>*R**<NUM_LIT:2>*Tc**<NUM_LIT:2>*V**<NUM_LIT:3>*b + R**<NUM_LIT:2>*Tc**<NUM_LIT:2>*V**<NUM_LIT:2>*b**<NUM_LIT:2> - <NUM_LIT:2>*R*Tc*V**<NUM_LIT:3>*a*m**<NUM_LIT:2> + <NUM_LIT:2>*R*Tc*V*a*b**<NUM_LIT:2>*m**<NUM_LIT:2> + V**<NUM_LIT:2>*a**<NUM_LIT:2>*m**<NUM_LIT:4> - <NUM_LIT:2>*V*a**<NUM_LIT:2>*b*m**<NUM_LIT:4> + a**<NUM_LIT:2>*b**<NUM_LIT:2>*m**<NUM_LIT:4>)*(P*R*Tc*V**<NUM_LIT:4> + <NUM_LIT:2>*P*R*Tc*V**<NUM_LIT:3>*b + P*R*Tc*V**<NUM_LIT:2>*b**<NUM_LIT:2> - P*V**<NUM_LIT:3>*a*m**<NUM_LIT:2> + P*V*a*b**<NUM_LIT:2>*m**<NUM_LIT:2> + R*Tc*V**<NUM_LIT:2>*a*m**<NUM_LIT:2> + <NUM_LIT:2>*R*Tc*V**<NUM_LIT:2>*a*m + R*Tc*V**<NUM_LIT:2>*a + R*Tc*V*a*b*m**<NUM_LIT:2> + <NUM_LIT:2>*R*Tc*V*a*b*m + R*Tc*V*a*b + V*a**<NUM_LIT:2>*m**<NUM_LIT:4> + <NUM_LIT:2>*V*a**<NUM_LIT:2>*m**<NUM_LIT:3> + V*a**<NUM_LIT:2>*m**<NUM_LIT:2> - a**<NUM_LIT:2>*b*m**<NUM_LIT:4> - <NUM_LIT:2>*a**<NUM_LIT:2>*b*m**<NUM_LIT:3> - a**<NUM_LIT:2>*b*m**<NUM_LIT:2>))/((R*Tc*V**<NUM_LIT:2> + R*Tc*V*b - V*a*m**<NUM_LIT:2> + a*b*m**<NUM_LIT:2>)**<NUM_LIT:2>*(R**<NUM_LIT:2>*Tc**<NUM_LIT:2>*V**<NUM_LIT:4> + <NUM_LIT:2>*R**<NUM_LIT:2>*Tc**<NUM_LIT:2>*V**<NUM_LIT:3>*b + R**<NUM_LIT:2>*Tc**<NUM_LIT:2>*V**<NUM_LIT:2>*b**<NUM_LIT:2> - <NUM_LIT:2>*R*Tc*V**<NUM_LIT:3>*a*m**<NUM_LIT:2> + <NUM_LIT:2>*R*Tc*V*a*b**<NUM_LIT:2>*m**<NUM_LIT:2> + V**<NUM_LIT:2>*a**<NUM_LIT:2>*m**<NUM_LIT:4> - <NUM_LIT:2>*V*a**<NUM_LIT:2>*b*m**<NUM_LIT:4> + a**<NUM_LIT:2>*b**<NUM_LIT:2>*m**<NUM_LIT:4>))<EOL><DEDENT>

r'''Method to calculate `T` from a specified `P` and `V` for the SRK
        EOS. Uses `a`, `b`, and `Tc` obtained from the class's namespace.

        Parameters
        ----------
        P : float
            Pressure, [Pa]
        V : float
            Molar volume, [m^3/mol]
        quick : bool, optional
            Whether to use a SymPy cse-derived expression (3x faster) or
            individual formulas

        Returns
        -------
        T : float
            Temperature, [K]

        Notes
        -----
        The exact solution can be derived as follows; it is excluded for
        breviety.

        >>> from sympy import *
        >>> P, T, V, R, a, b, m = symbols('P, T, V, R, a, b, m')
        >>> Tc, Pc, omega = symbols('Tc, Pc, omega')
        >>> a_alpha = a*(1 + m*(1-sqrt(T/Tc)))**2
        >>> SRK = R*T/(V-b) - a_alpha/(V*(V+b)) - P
        >>> # solve(SRK, T)


a, Tc, S1, S2 = self.a, self.Tc, self.S1, self.S2<EOL>if not full:<EOL><INDENT>return a*(S1*(-(T/Tc)**<NUM_LIT:0.5> + <NUM_LIT:1.>) + S2*(-(T/Tc)**<NUM_LIT:0.5> + <NUM_LIT:1>)*(T/Tc)**-<NUM_LIT:0.5> + <NUM_LIT:1>)**<NUM_LIT:2><EOL><DEDENT>else:<EOL><INDENT>if quick:<EOL><INDENT>x0 = (T/Tc)**<NUM_LIT:0.5><EOL>x1 = x0 - <NUM_LIT:1.><EOL>x2 = x1/x0<EOL>x3 = S2*x2<EOL>x4 = S1*x1 + x3 - <NUM_LIT:1.><EOL>x5 = S1*x0<EOL>x6 = S2 - x3 + x5<EOL>x7 = <NUM_LIT>*S2<EOL>a_alpha = a*x4*x4<EOL>da_alpha_dT = a*x4*x6/T<EOL>d2a_alpha_dT2 = a*(-x4*(-x2*x7 + x5 + x7) + x6*x6)/(<NUM_LIT>*T*T)<EOL><DEDENT>else:<EOL><INDENT>a_alpha = a*(S1*(-sqrt(T/Tc) + <NUM_LIT:1>) + S2*(-sqrt(T/Tc) + <NUM_LIT:1>)/sqrt(T/Tc) + <NUM_LIT:1>)**<NUM_LIT:2><EOL>da_alpha_dT = a*((S1*(-sqrt(T/Tc) + <NUM_LIT:1>) + S2*(-sqrt(T/Tc) + <NUM_LIT:1>)/sqrt(T/Tc) + <NUM_LIT:1>)*(-S1*sqrt(T/Tc)/T - S2/T - S2*(-sqrt(T/Tc) + <NUM_LIT:1>)/(T*sqrt(T/Tc))))<EOL>d2a_alpha_dT2 = a*(((S1*sqrt(T/Tc) + S2 - S2*(sqrt(T/Tc) - <NUM_LIT:1>)/sqrt(T/Tc))**<NUM_LIT:2> - (S1*sqrt(T/Tc) + <NUM_LIT:3>*S2 - <NUM_LIT:3>*S2*(sqrt(T/Tc) - <NUM_LIT:1>)/sqrt(T/Tc))*(S1*(sqrt(T/Tc) - <NUM_LIT:1>) + S2*(sqrt(T/Tc) - <NUM_LIT:1>)/sqrt(T/Tc) - <NUM_LIT:1>))/(<NUM_LIT:2>*T**<NUM_LIT:2>))<EOL><DEDENT>return a_alpha, da_alpha_dT, d2a_alpha_dT2<EOL><DEDENT>

r'''Method to calculate `a_alpha` and its first and second
        derivatives for this EOS. Returns `a_alpha`, `da_alpha_dT`, and
        `d2a_alpha_dT2`. See `GCEOS.a_alpha_and_derivatives` for more
        documentation. Uses the set values of `Tc`, `a`, `S1`, and `S2`.

        .. math::
            a\alpha(T) = a\left[1 + S_1\left(1-\sqrt{T_r}\right) + S_2\frac{1
            - \sqrt{T_r}}{\sqrt{T_r}}\right]^2

            \frac{d a\alpha}{dT} = a\frac{Tc}{T^{2}} \left(- S_{2} \left(\sqrt{
            \frac{T}{Tc}} - 1\right) + \sqrt{\frac{T}{Tc}} \left(S_{1} \sqrt{
            \frac{T}{Tc}} + S_{2}\right)\right) \left(S_{2} \left(\sqrt{\frac{
            T}{Tc}} - 1\right) + \sqrt{\frac{T}{Tc}} \left(S_{1} \left(\sqrt{
            \frac{T}{Tc}} - 1\right) - 1\right)\right)

            \frac{d^2 a\alpha}{dT^2} = a\frac{1}{2 T^{3}} \left(S_{1}^{2} T
            \sqrt{\frac{T}{Tc}} - S_{1} S_{2} T \sqrt{\frac{T}{Tc}} + 3 S_{1}
            S_{2} Tc \sqrt{\frac{T}{Tc}} + S_{1} T \sqrt{\frac{T}{Tc}}
            - 3 S_{2}^{2} Tc \sqrt{\frac{T}{Tc}} + 4 S_{2}^{2} Tc + 3 S_{2}
            Tc \sqrt{\frac{T}{Tc}}\right)


if self.S2 == <NUM_LIT:0>:<EOL><INDENT>self.m = self.S1<EOL>return SRK.solve_T(self, P, V, quick=quick)<EOL><DEDENT>else:<EOL><INDENT>return super(SRK, self).solve_T(P, V, quick=quick) <EOL>

r'''Method to calculate `T` from a specified `P` and `V` for the API
        SRK EOS. Uses `a`, `b`, and `Tc` obtained from the class's namespace.

        Parameters
        ----------
        P : float
            Pressure, [Pa]
        V : float
            Molar volume, [m^3/mol]
        quick : bool, optional
            Whether to use a SymPy cse-derived expression (3x faster) or
            individual formulas

        Returns
        -------
        T : float
            Temperature, [K]

        Notes
        -----
        If S2 is set to 0, the solution is the same as in the SRK EOS, and that
        is used. Otherwise, newton's method must be used to solve for `T`.
        There are 8 roots of T in that case, six of them real. No guarantee can
        be made regarding which root will be obtained.


return TWU_a_alpha_common(T, self.Tc, self.omega, self.a, full=full, quick=quick, method='<STR_LIT>')<EOL>

r'''Method to calculate `a_alpha` and its first and second
        derivatives for this EOS. Returns `a_alpha`, `da_alpha_dT`, and
        `d2a_alpha_dT2`. See `GCEOS.a_alpha_and_derivatives` for more
        documentation. Uses the set values of `Tc`, `omega`, and `a`.

        Because of its similarity for the TWUSRK EOS, this has been moved to an
        external `TWU_a_alpha_common` function. See it for further
        documentation.


r'''Method to calculate `a_alpha` and its first and second
        derivatives for this EOS. Returns `a_alpha`, `da_alpha_dT`, and
        `d2a_alpha_dT2`. See `GCEOS.a_alpha_and_derivatives` for more
        documentation. Uses the set values of `Tc`, `omega`, and `a`.

        Because of its similarity for the TWUPR EOS, this has been moved to an
        external `TWU_a_alpha_common` function. See it for further
        documentation.


def Tb(CASRN, AvailableMethods=False, Method=None, IgnoreMethods=[PSAT_DEFINITION]):

def list_methods():<EOL><INDENT>methods = []<EOL>if CASRN in CRC_inorganic_data.index and not np.isnan(CRC_inorganic_data.at[CASRN, '<STR_LIT>']):<EOL><INDENT>methods.append(CRC_INORG)<EOL><DEDENT>if CASRN in CRC_organic_data.index and not np.isnan(CRC_organic_data.at[CASRN, '<STR_LIT>']):<EOL><INDENT>methods.append(CRC_ORG)<EOL><DEDENT>if CASRN in Yaws_data.index:<EOL><INDENT>methods.append(YAWS)<EOL><DEDENT>if PSAT_DEFINITION not in IgnoreMethods:<EOL><INDENT>try:<EOL><INDENT>VaporPressure(CASRN=CASRN).solve_prop(<NUM_LIT>)<EOL>methods.append(PSAT_DEFINITION)<EOL><DEDENT>except:  <EOL><INDENT>pass<EOL><DEDENT><DEDENT>if IgnoreMethods:<EOL><INDENT>for Method in IgnoreMethods:<EOL><INDENT>if Method in methods:<EOL><INDENT>methods.remove(Method)<EOL><DEDENT><DEDENT><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 == CRC_INORG:<EOL><INDENT>return float(CRC_inorganic_data.at[CASRN, '<STR_LIT>'])<EOL><DEDENT>elif Method == CRC_ORG:<EOL><INDENT>return float(CRC_organic_data.at[CASRN, '<STR_LIT>'])<EOL><DEDENT>elif Method == YAWS:<EOL><INDENT>return float(Yaws_data.at[CASRN, '<STR_LIT>'])<EOL><DEDENT>elif Method == PSAT_DEFINITION:<EOL><INDENT>return VaporPressure(CASRN=CASRN).solve_prop(<NUM_LIT>)<EOL><DEDENT>elif Method == NONE:<EOL><INDENT>return None<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>

r'''This function handles the retrieval of a chemical's boiling
    point. Lookup is based on CASRNs. Will automatically select a data
    source to use if no Method is provided; returns None if the data is not
    available.

    Prefered sources are 'CRC Physical Constants, organic' for organic
    chemicals, and 'CRC Physical Constants, inorganic' for inorganic
    chemicals. Function has data for approximately 13000 chemicals.

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

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

    Other Parameters
    ----------------
    Method : string, optional
        A string for the method name to use, as defined by constants in
        Tb_methods
    AvailableMethods : bool, optional
        If True, function will determine which methods can be used to obtain
        Tb for the desired chemical, and will return methods instead of Tb
    IgnoreMethods : list, optional
        A list of methods to ignore in obtaining the full list of methods,
        useful for for performance reasons and ignoring inaccurate methods

    Notes
    -----
    A total of four methods are available for this function. They are:

        * 'CRC_ORG', a compillation of data on organics
          as published in [1]_.
        * 'CRC_INORG', a compillation of data on
          inorganic as published in [1]_.
        * 'YAWS', a large compillation of data from a
          variety of sources; no data points are sourced in the work of [2]_.
        * 'PSAT_DEFINITION', calculation of boiling point from a
          vapor pressure calculation. This is normally off by a fraction of a
          degree even in the best cases. Listed in IgnoreMethods by default
          for performance reasons.

    Examples
    --------
    >>> Tb('7732-18-5')
    373.124

    References
    ----------
    .. [1] Haynes, W.M., Thomas J. Bruno, and David R. Lide. CRC Handbook of
       Chemistry and Physics, 95E. Boca Raton, FL: CRC press, 2014.
    .. [2] Yaws, Carl L. Thermophysical Properties of Chemicals and
       Hydrocarbons, Second Edition. Amsterdam Boston: Gulf Professional
       Publishing, 2014.


def Tm(CASRN, AvailableMethods=False, Method=None, IgnoreMethods=[]):

def list_methods():<EOL><INDENT>methods = []<EOL>if CASRN in Tm_ON_data.index:<EOL><INDENT>methods.append(OPEN_NTBKM)<EOL><DEDENT>if CASRN in CRC_inorganic_data.index and not np.isnan(CRC_inorganic_data.at[CASRN, '<STR_LIT>']):<EOL><INDENT>methods.append(CRC_INORG)<EOL><DEDENT>if CASRN in CRC_organic_data.index and not np.isnan(CRC_organic_data.at[CASRN, '<STR_LIT>']):<EOL><INDENT>methods.append(CRC_ORG)<EOL><DEDENT>if IgnoreMethods:<EOL><INDENT>for Method in IgnoreMethods:<EOL><INDENT>if Method in methods:<EOL><INDENT>methods.remove(Method)<EOL><DEDENT><DEDENT><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 == OPEN_NTBKM:<EOL><INDENT>return float(Tm_ON_data.at[CASRN, '<STR_LIT>'])<EOL><DEDENT>elif Method == CRC_INORG:<EOL><INDENT>return float(CRC_inorganic_data.at[CASRN, '<STR_LIT>'])<EOL><DEDENT>elif Method == CRC_ORG:<EOL><INDENT>return float(CRC_organic_data.at[CASRN, '<STR_LIT>'])<EOL><DEDENT>elif Method == NONE:<EOL><INDENT>return None<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>

r'''This function handles the retrieval of a chemical's melting
    point. Lookup is based on CASRNs. Will automatically select a data
    source to use if no Method is provided; returns None if the data is not
    available.

    Prefered sources are 'Open Notebook Melting Points', with backup sources
    'CRC Physical Constants, organic' for organic chemicals, and
    'CRC Physical Constants, inorganic' for inorganic chemicals. Function has
    data for approximately 14000 chemicals.

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

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

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

    Notes
    -----
    A total of three sources are available for this function. They are:

        * 'OPEN_NTBKM, a compillation of data on organics
          as published in [1]_ as Open Notebook Melting Points; Averaged
          (median) values were used when
          multiple points were available. For more information on this
          invaluable and excellent collection, see
          http://onswebservices.wikispaces.com/meltingpoint.
        * 'CRC_ORG', a compillation of data on organics
          as published in [2]_.
        * 'CRC_INORG', a compillation of data on
          inorganic as published in [2]_.

    Examples
    --------
    >>> Tm(CASRN='7732-18-5')
    273.15

    References
    ----------
    .. [1] Bradley, Jean-Claude, Antony Williams, and Andrew Lang.
       "Jean-Claude Bradley Open Melting Point Dataset", May 20, 2014.
       https://figshare.com/articles/Jean_Claude_Bradley_Open_Melting_Point_Datset/1031637.
    .. [2] Haynes, W.M., Thomas J. Bruno, and David R. Lide. CRC Handbook of
       Chemistry and Physics, 95E. Boca Raton, FL: CRC press, 2014.


def Clapeyron(T, Tc, Pc, dZ=<NUM_LIT:1>, Psat=<NUM_LIT>):

Tr = T/Tc<EOL>return R*T*dZ*log(Pc/Psat)/(<NUM_LIT:1.> - Tr)<EOL>

r'''Calculates enthalpy of vaporization at arbitrary temperatures using the
    Clapeyron equation.

    The enthalpy of vaporization is given by:

    .. math::
        \Delta H_{vap} = RT \Delta Z \frac{\ln (P_c/Psat)}{(1-T_{r})}

    Parameters
    ----------
    T : float
        Temperature of fluid [K]
    Tc : float
        Critical temperature of fluid [K]
    Pc : float
        Critical pressure of fluid [Pa]
    dZ : float
        Change in compressibility factor between liquid and gas, []
    Psat : float
        Saturation pressure of fluid [Pa], optional

    Returns
    -------
    Hvap : float
        Enthalpy of vaporization, [J/mol]

    Notes
    -----
    No original source is available for this equation.
    [1]_ claims this equation overpredicts enthalpy by several percent.
    Under Tr = 0.8, dZ = 1 is a reasonable assumption.
    This equation is most accurate at the normal boiling point.

    Internal units are bar.

    WARNING: I believe it possible that the adjustment for pressure may be incorrect

    Examples
    --------
    Problem from Perry's examples.

    >>> Clapeyron(T=294.0, Tc=466.0, Pc=5.55E6)
    26512.354585061985

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


Tr = T/Tc<EOL>return R*Tc * (<NUM_LIT>*(<NUM_LIT:1.> - Tr)**<NUM_LIT> + <NUM_LIT>*omega*(<NUM_LIT:1.> - Tr)**<NUM_LIT>)<EOL>

r'''Calculates enthalpy of vaporization at arbitrary temperatures using a
    fit by [2]_ to the work of Pitzer [1]_; requires a chemical's critical
    temperature and acentric factor.

    The enthalpy of vaporization is given by:

    .. math::
        \frac{\Delta_{vap} H}{RT_c}=7.08(1-T_r)^{0.354}+10.95\omega(1-T_r)^{0.456}

    Parameters
    ----------
    T : float
        Temperature of fluid [K]
    Tc : float
        Critical temperature of fluid [K]
    omega : float
        Acentric factor [-]

    Returns
    -------
    Hvap : float
        Enthalpy of vaporization, [J/mol]

    Notes
    -----
    This equation is listed in [3]_, page 2-487 as method #2 for estimating
    Hvap. This cites [2]_.

    The recommended range is 0.6 to 1 Tr. Users should expect up to 5% error.
    T must be under Tc, or an exception is raised.

    The original article has been reviewed and found to have a set of tabulated
    values which could be used instead of the fit function to provide additional
    accuracy.

    Examples
    --------
    Example as in [3]_, p2-487; exp: 37.51 kJ/mol

    >>> Pitzer(452, 645.6, 0.35017)
    36696.736640106414

    References
    ----------
    .. [1] Pitzer, Kenneth S. "The Volumetric and Thermodynamic Properties of
       Fluids. I. Theoretical Basis and Virial Coefficients."
       Journal of the American Chemical Society 77, no. 13 (July 1, 1955):
       3427-33. doi:10.1021/ja01618a001
    .. [2] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition.
       New York: McGraw-Hill Professional, 2000.
    .. [3] Green, Don, and Robert Perry. Perry's Chemical Engineers' Handbook,
       Eighth Edition. McGraw-Hill Professional, 2007.


omegaR1, omegaR2 = <NUM_LIT>, <NUM_LIT><EOL>A10 = <NUM_LIT><EOL>A20 = -<NUM_LIT><EOL>A30 = -<NUM_LIT><EOL>B10 = <NUM_LIT><EOL>B20 = <NUM_LIT><EOL>B30 = -<NUM_LIT><EOL>A11 = -<NUM_LIT><EOL>A21 = -<NUM_LIT><EOL>A31 = -<NUM_LIT><EOL>B11 = <NUM_LIT><EOL>B21 = <NUM_LIT><EOL>B31 = -<NUM_LIT><EOL>tau = <NUM_LIT:1.> - T/Tc<EOL>L0 = A10*tau**(<NUM_LIT:1>/<NUM_LIT>) + A20*tau**(<NUM_LIT:5>/<NUM_LIT>) + A30*tau**(<NUM_LIT:1>-<NUM_LIT:1>/<NUM_LIT> + <NUM_LIT:1>/<NUM_LIT>) +B10*tau + B20*tau**<NUM_LIT:2> + B30*tau**<NUM_LIT:3><EOL>L1 = A11*tau**(<NUM_LIT:1>/<NUM_LIT>) + A21*tau**(<NUM_LIT:5>/<NUM_LIT>) + A31*tau**(<NUM_LIT:1>-<NUM_LIT:1>/<NUM_LIT> + <NUM_LIT:1>/<NUM_LIT>) +B11*tau + B21*tau**<NUM_LIT:2> + B31*tau**<NUM_LIT:3><EOL>domega = (omega - omegaR1)/(omegaR2 - omegaR1)<EOL>return R*Tc*(L0 + domega*L1)<EOL>

r'''Calculates enthalpy of vaporization at arbitrary temperatures using a
    the work of [1]_; requires a chemical's critical temperature and
    acentric factor.

    The enthalpy of vaporization is given by:

    .. math::
         \frac{\Delta H_{vap}} {RT_c} =
         \left( \frac{\Delta H_{vap}} {RT_c} \right)^{(R1)} + \left(
         \frac{\omega - \omega^{(R1)}} {\omega^{(R2)} - \omega^{(R1)}} \right)
         \left[\left( \frac{\Delta H_{vap}} {RT_c} \right)^{(R2)} - \left(
         \frac{\Delta H_{vap}} {RT_c} \right)^{(R1)} \right]

        \left( \frac{\Delta H_{vap}} {RT_c} \right)^{(R1)}
        = 6.537 \tau^{1/3} - 2.467 \tau^{5/6} - 77.251 \tau^{1.208} +
        59.634 \tau + 36.009 \tau^2 - 14.606 \tau^3

        \left( \frac{\Delta H_{vap}} {RT_c} \right)^{(R2)} - \left(
        \frac{\Delta H_{vap}} {RT_c} \right)^{(R1)}=-0.133 \tau^{1/3} - 28.215
        \tau^{5/6} - 82.958 \tau^{1.208} + 99.00 \tau  + 19.105 \tau^2 -2.796 \tau^3

        \tau = 1-T/T_c

    Parameters
    ----------
    T : float
        Temperature of fluid [K]
    Tc : float
        Critical temperature of fluid [K]
    omega : float
        Acentric factor [-]

    Returns
    -------
    Hvap : float
        Enthalpy of vaporization, [J/mol]

    Notes
    -----
    The original article has been reviewed and found to have coefficients with
    slightly more precision. Additionally, the form of the equation is slightly
    different, but numerically equivalent.

    The refence fluids are:

    :math:`\omega_0` = benzene = 0.212

    :math:`\omega_1` = carbazole = 0.461

    A sample problem in the article has been verified. The numerical result
    presented by the author requires high numerical accuracy to obtain.

    Examples
    --------
    Problem in [1]_:

    >>> SMK(553.15, 751.35, 0.302)
    39866.17647797959

    References
    ----------
    .. [1] Sivaraman, Alwarappa, Joe W. Magee, and Riki Kobayashi. "Generalized
       Correlation of Latent Heats of Vaporization of Coal-Liquid Model Compounds
       between Their Freezing Points and Critical Points." Industrial &
       Engineering Chemistry Fundamentals 23, no. 1 (February 1, 1984): 97-100.
       doi:10.1021/i100013a017.


bs = [[<NUM_LIT>, <NUM_LIT>, <NUM_LIT>],<EOL>[<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>],<EOL>[<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>],<EOL>[-<NUM_LIT>, -<NUM_LIT>, <NUM_LIT>],<EOL>[<NUM_LIT>, -<NUM_LIT>, <NUM_LIT>],<EOL>[-<NUM_LIT>, <NUM_LIT>, -<NUM_LIT>]]<EOL>tau = <NUM_LIT:1.> - T/Tc<EOL>H0 = (bs[<NUM_LIT:0>][<NUM_LIT:0>]*tau**(<NUM_LIT>) + bs[<NUM_LIT:1>][<NUM_LIT:0>]*tau**(<NUM_LIT>) + bs[<NUM_LIT:2>][<NUM_LIT:0>]*tau**(<NUM_LIT>) +<EOL>bs[<NUM_LIT:3>][<NUM_LIT:0>]*tau + bs[<NUM_LIT:4>][<NUM_LIT:0>]*tau**(<NUM_LIT:2>) + bs[<NUM_LIT:5>][<NUM_LIT:0>]*tau**(<NUM_LIT:3>))*R*Tc<EOL>H1 = (bs[<NUM_LIT:0>][<NUM_LIT:1>]*tau**(<NUM_LIT>) + bs[<NUM_LIT:1>][<NUM_LIT:1>]*tau**(<NUM_LIT>) + bs[<NUM_LIT:2>][<NUM_LIT:1>]*tau**(<NUM_LIT>) +<EOL>bs[<NUM_LIT:3>][<NUM_LIT:1>]*tau + bs[<NUM_LIT:4>][<NUM_LIT:1>]*tau**(<NUM_LIT:2>) + bs[<NUM_LIT:5>][<NUM_LIT:1>]*tau**(<NUM_LIT:3>))*R*Tc<EOL>H2 = (bs[<NUM_LIT:0>][<NUM_LIT:2>]*tau**(<NUM_LIT>) + bs[<NUM_LIT:1>][<NUM_LIT:2>]*tau**(<NUM_LIT>) + bs[<NUM_LIT:2>][<NUM_LIT:2>]*tau**(<NUM_LIT>) +<EOL>bs[<NUM_LIT:3>][<NUM_LIT:2>]*tau + bs[<NUM_LIT:4>][<NUM_LIT:2>]*tau**(<NUM_LIT:2>) + bs[<NUM_LIT:5>][<NUM_LIT:2>]*tau**(<NUM_LIT:3>))*R*Tc<EOL>return H0 + omega*H1 + omega**<NUM_LIT:2>*H2<EOL>

r'''Calculates enthalpy of vaporization at arbitrary temperatures using a
    the work of [1]_; requires a chemical's critical temperature and
    acentric factor.

    The enthalpy of vaporization is given by:

    .. math::
        \Delta H_{vap} =  \Delta H_{vap}^{(0)} + \omega \Delta H_{vap}^{(1)} + \omega^2 \Delta H_{vap}^{(2)}

        \frac{\Delta H_{vap}^{(i)}}{RT_c} = b^{(j)} \tau^{1/3} + b_2^{(j)} \tau^{5/6}
        + b_3^{(j)} \tau^{1.2083} + b_4^{(j)}\tau + b_5^{(j)} \tau^2 + b_6^{(j)} \tau^3

        \tau = 1-T/T_c

    Parameters
    ----------
    T : float
        Temperature of fluid [K]
    Tc : float
        Critical temperature of fluid [K]
    omega : float
        Acentric factor [-]

    Returns
    -------
    Hvap : float
        Enthalpy of vaporization, [J/mol]

    Notes
    -----
    The original article has been reviewed. A total of 18 coefficients are used:

    WARNING: The correlation has been implemented as described in the article,
    but its results seem different and with some error.
    Its results match with other functions however.

    Has poor behavior for low-temperature use.

    Examples
    --------
    Problem in article for SMK function.

    >>> MK(553.15, 751.35, 0.302)
    38727.993546377205

    References
    ----------
    .. [1] Morgan, David L., and Riki Kobayashi. "Extension of Pitzer CSP
       Models for Vapor Pressures and Heats of Vaporization to Long-Chain
       Hydrocarbons." Fluid Phase Equilibria 94 (March 15, 1994): 51-87.
       doi:10.1016/0378-3812(94)87051-9.


return (<NUM_LIT> + <NUM_LIT>*omega + <NUM_LIT>*omega**<NUM_LIT:2>)*(<NUM_LIT:1>-T/Tc)**<NUM_LIT>*R*Tc<EOL>

r'''Calculates enthalpy of vaporization at arbitrary temperatures using a
    the work of [1]_; requires a chemical's critical temperature and
    acentric factor.

    The enthalpy of vaporization is given by:

    .. math::
        \Delta_{vap} H = RT_c(7.2729 + 10.4962\omega + 0.6061\omega^2)(1-T_r)^{0.38}

    Parameters
    ----------
    T : float
        Temperature of fluid [K]
    Tc : float
        Critical temperature of fluid [K]
    omega : float
        Acentric factor [-]

    Returns
    -------
    Hvap : float
        Enthalpy of vaporization, [J/mol]

    Notes
    -----
    The original article has been reviewed. It is regressed from enthalpy of
    vaporization values at 0.7Tr, from 121 fluids in REFPROP 9.1.
    A value in the article was read to be similar, but slightly too low from
    that calculated here.

    Examples
    --------
    From graph, in [1]_ for perfluoro-n-heptane.

    >>> Velasco(333.2, 476.0, 0.5559)
    33299.41734936356

    References
    ----------
    .. [1] Velasco, S., M. J. Santos, and J. A. White. "Extended Corresponding
       States Expressions for the Changes in Enthalpy, Compressibility Factor
       and Constant-Volume Heat Capacity at Vaporization." The Journal of
       Chemical Thermodynamics 85 (June 2015): 68-76.
       doi:10.1016/j.jct.2015.01.011.


Pc = Pc/<NUM_LIT>  <EOL>Tbr = Tb/Tc<EOL>return <NUM_LIT>*Tb*R*(log(Pc) - <NUM_LIT>)/(<NUM_LIT> - Tbr)<EOL>

r'''Calculates enthalpy of vaporization at the boiling point, using the
    Ridel [1]_ CSP method. Required information are critical temperature
    and pressure, and boiling point. Equation taken from [2]_ and [3]_.

    The enthalpy of vaporization is given by:

    .. math::
        \Delta_{vap} H=1.093 T_b R\frac{\ln P_c-1.013}{0.930-T_{br}}

    Parameters
    ----------
    Tb : float
        Boiling temperature of fluid [K]
    Tc : float
        Critical temperature of fluid [K]
    Pc : float
        Critical pressure of fluid [Pa]

    Returns
    -------
    Hvap : float
        Enthalpy of vaporization at the normal boiling point, [J/mol]

    Notes
    -----
    This equation has no example calculation in any source. The source has not
    been verified. It is equation 4-144 in Perry's. Perry's also claims that
    errors seldom surpass 5%.

    [2]_ is the source of example work here, showing a calculation at 0.0%
    error.

    Internal units of pressure are bar.

    Examples
    --------
    Pyridine, 0.0% err vs. exp: 35090 J/mol; from Poling [2]_.

    >>> Riedel(388.4, 620.0, 56.3E5)
    35089.78989646058

    References
    ----------
    .. [1] Riedel, L. "Eine Neue Universelle Dampfdruckformel Untersuchungen
       Uber Eine Erweiterung Des Theorems Der Ubereinstimmenden Zustande. Teil
       I." Chemie Ingenieur Technik 26, no. 2 (February 1, 1954): 83-89.
       doi:10.1002/cite.330260206.
    .. [2] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition.
       New York: McGraw-Hill Professional, 2000.
    .. [3] Green, Don, and Robert Perry. Perry's Chemical Engineers' Handbook,
       Eighth Edition. McGraw-Hill Professional, 2007.


Tbr = Tb/Tc<EOL>Pc = Pc/<NUM_LIT>  <EOL>return R*Tb*(<NUM_LIT>*Tbr - <NUM_LIT> + <NUM_LIT>*log(Pc))/(<NUM_LIT> - Tbr)<EOL>

r'''Calculates enthalpy of vaporization using the Chen [1]_ correlation
    and a chemical's critical temperature, pressure and boiling point.

    The enthalpy of vaporization is given by:

    .. math::
        \Delta H_{vb} = RT_b \frac{3.978 T_r - 3.958 + 1.555 \ln P_c}{1.07 - T_r}

    Parameters
    ----------
    Tb : float
        Boiling temperature of the fluid [K]
    Tc : float
        Critical temperature of fluid [K]
    Pc : float
        Critical pressure of fluid [Pa]

    Returns
    -------
    Hvap : float
        Enthalpy of vaporization, [J/mol]

    Notes
    -----
    The formulation presented in the original article is similar, but uses
    units of atm and calorie instead. The form in [2]_ has adjusted for this.
    A method for estimating enthalpy of vaporization at other conditions
    has also been developed, but the article is unclear on its implementation.
    Based on the Pitzer correlation.

    Internal units: bar and K

    Examples
    --------
    Same problem as in Perry's examples.

    >>> Chen(294.0, 466.0, 5.55E6)
    26705.893506174052

    References
    ----------
    .. [1] Chen, N. H. "Generalized Correlation for Latent Heat of Vaporization."
       Journal of Chemical & Engineering Data 10, no. 2 (April 1, 1965): 207-10.
       doi:10.1021/je60025a047
    .. [2] Poling, Bruce E. The Properties of Gases and Liquids. 5th edition.
       New York: McGraw-Hill Professional, 2000.


Tbr = Tb/Tc<EOL>return R*Tb*(Tb/<NUM_LIT>)**<NUM_LIT>*(<NUM_LIT:1.> - Tbr)**<NUM_LIT>*log(Pc/<NUM_LIT>)/ (<NUM_LIT:1> - Tbr + <NUM_LIT>*Tbr*log(Tbr))<EOL>

r'''Calculates enthalpy of vaporization at the normal boiling point using
    the Liu [1]_ correlation, and a chemical's critical temperature, pressure
    and boiling point.

    The enthalpy of vaporization is given by:

    .. math::
        \Delta H_{vap} = RT_b \left[ \frac{T_b}{220}\right]^{0.0627} \frac{
        (1-T_{br})^{0.38} \ln(P_c/P_A)}{1-T_{br} + 0.38 T_{br} \ln T_{br}}

    Parameters
    ----------
    Tb : float
        Boiling temperature of the fluid [K]
    Tc : float
        Critical temperature of fluid [K]
    Pc : float
        Critical pressure of fluid [Pa]

    Returns
    -------
    Hvap : float
        Enthalpy of vaporization, [J/mol]

    Notes
    -----
    This formulation can be adjusted for lower boiling points, due to the use
    of a rationalized pressure relationship. The formulation is taken from
    the original article.

    A correction for alcohols and organic acids based on carbon number,
    which only modifies the boiling point, is available but not implemented.

    No sample calculations are available in the article.

    Internal units: Pa and K

    Examples
    --------
    Same problem as in Perry's examples

    >>> Liu(294.0, 466.0, 5.55E6)
    26378.566319606754

    References
    ----------
    .. [1] LIU, ZHI-YONG. "Estimation of Heat of Vaporization of Pure Liquid at
       Its Normal Boiling Temperature." Chemical Engineering Communications
       184, no. 1 (February 1, 2001): 221-28. doi:10.1080/00986440108912849.


Tbr = Tb/Tc<EOL>taub = <NUM_LIT:1>-Tb/Tc<EOL>Pc = Pc/<NUM_LIT><EOL>term = taub**<NUM_LIT>*(log(Pc)-<NUM_LIT> + <NUM_LIT>/Pc/Tbr**<NUM_LIT:2>) / (taub + F*(<NUM_LIT:1>-taub**<NUM_LIT>)*log(Tbr))<EOL>return R*Tb*term<EOL>

r'''Calculates enthalpy of vaporization at the boiling point, using the
    Vetere [1]_ CSP method. Required information are critical temperature
    and pressure, and boiling point. Equation taken from [2]_.

    The enthalpy of vaporization is given by:

    .. math::
        \frac {\Delta H_{vap}}{RT_b} = \frac{\tau_b^{0.38}
        \left[ \ln P_c - 0.513 + \frac{0.5066}{P_cT_{br}^2}\right]}
        {\tau_b + F(1-\tau_b^{0.38})\ln T_{br}}

    Parameters
    ----------
    Tb : float
        Boiling temperature of fluid [K]
    Tc : float
        Critical temperature of fluid [K]
    Pc : float
        Critical pressure of fluid [Pa]
    F : float, optional
        Constant for a fluid, [-]

    Returns
    -------
    Hvap : float
        Enthalpy of vaporization at the boiling point, [J/mol]

    Notes
    -----
    The equation cannot be found in the original source. It is believed that a
    second article is its source, or that DIPPR staff have altered the formulation.

    Internal units of pressure are bar.

    Examples
    --------
    Example as in [2]_, p2-487; exp: 25.73

    >>> Vetere(294.0, 466.0, 5.55E6)
    26363.430021286465

    References
    ----------
    .. [1] Vetere, Alessandro. "Methods to Predict the Vaporization Enthalpies
       at the Normal Boiling Temperature of Pure Compounds Revisited."
       Fluid Phase Equilibria 106, no. 1-2 (May 1, 1995): 1–10.
       doi:10.1016/0378-3812(94)02627-D.
    .. [2] Green, Don, and Robert Perry. Perry's Chemical Engineers' Handbook,
       Eighth Edition. McGraw-Hill Professional, 2007.


def Watson(T, Hvap_ref, T_Ref, Tc, exponent=<NUM_LIT>):

Tr = T/Tc<EOL>Trefr = T_Ref/Tc<EOL>H2 = Hvap_ref*((<NUM_LIT:1>-Tr)/(<NUM_LIT:1>-Trefr))**exponent<EOL>return H2<EOL>

Adjusts enthalpy of vaporization of enthalpy for another temperature, for one temperature.


def Hfus(T=<NUM_LIT>, P=<NUM_LIT>, MW=None, AvailableMethods=False, Method=None, CASRN='<STR_LIT>'):

def list_methods():<EOL><INDENT>methods = []<EOL>if CASRN in CRCHfus_data.index:<EOL><INDENT>methods.append('<STR_LIT>')<EOL><DEDENT>methods.append('<STR_LIT: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 == '<STR_LIT>':<EOL><INDENT>_Hfus = CRCHfus_data.at[CASRN, '<STR_LIT>']<EOL><DEDENT>elif Method == '<STR_LIT:None>' or not MW:<EOL><INDENT>_Hfus = None<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>_Hfus = property_molar_to_mass(_Hfus, MW)<EOL>return _Hfus<EOL>

This function handles the calculation of a chemical's enthalpy of fusion.
    Generally this, is used by the chemical class, as all parameters are passed.
    Calling the function directly works okay.

    Enthalpy of fusion is a weak function of pressure, and its effects are
    neglected.

    This API is considered experimental, and is expected to be removed in a
    future release in favor of a more complete object-oriented interface.


def Hsub(T=<NUM_LIT>, P=<NUM_LIT>, MW=None, AvailableMethods=False, Method=None, CASRN='<STR_LIT>'):

def list_methods():<EOL><INDENT>methods = []<EOL><INDENT>if Hfus(T=T, P=P, MW=MW, CASRN=CASRN) and Hvap(T=T, P=P, MW=MW, CASRN=CASRN):<EOL><INDENT>methods.append('<STR_LIT>')<EOL><DEDENT><DEDENT>if CASRN in GharagheiziHsub_data.index:<EOL><INDENT>methods.append('<STR_LIT>')<EOL><DEDENT>methods.append('<STR_LIT: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>

This function handles the calculation of a chemical's enthalpy of sublimation.
    Generally this, is used by the chemical class, as all parameters are passed.

    This API is considered experimental, and is expected to be removed in a
    future release in favor of a more complete object-oriented interface.


def Tliquidus(Tms=None, ws=None, xs=None, CASRNs=None, AvailableMethods=False,<EOL>Method=None):

def list_methods():<EOL><INDENT>methods = []<EOL>if none_and_length_check([Tms]):<EOL><INDENT>methods.append('<STR_LIT>')<EOL>methods.append('<STR_LIT>')<EOL><DEDENT>methods.append('<STR_LIT: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 == '<STR_LIT>':<EOL><INDENT>_Tliq = max(Tms)<EOL><DEDENT>elif Method == '<STR_LIT>':<EOL><INDENT>_Tliq = mixing_simple(xs, Tms)<EOL><DEDENT>elif Method == '<STR_LIT:None>':<EOL><INDENT>return None<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>return _Tliq<EOL>

This function handles the retrival of a mixtures's liquidus point.

    This API is considered experimental, and is expected to be removed in a
    future release in favor of a more complete object-oriented interface.

    >>> Tliquidus(Tms=[250.0, 350.0], xs=[0.5, 0.5])
    350.0
    >>> Tliquidus(Tms=[250, 350], xs=[0.5, 0.5], Method='Simple')
    300.0
    >>> Tliquidus(Tms=[250, 350], xs=[0.5, 0.5], AvailableMethods=True)
    ['Maximum', 'Simple', 'None']


methods = []<EOL>Tmins, Tmaxs = [], []<EOL>if has_CoolProp and self.CASRN in coolprop_dict:<EOL><INDENT>methods.append(COOLPROP)<EOL>self.CP_f = coolprop_fluids[self.CASRN]<EOL>Tmins.append(self.CP_f.Tt); 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 Alibakhshi_Cs.index and self.Tc:<EOL><INDENT>methods.append(ALIBAKHSHI)<EOL>self.Alibakhshi_C = float(Alibakhshi_Cs.at[self.CASRN, '<STR_LIT:C>'])<EOL>Tmaxs.append( max(self.Tc-<NUM_LIT>, <NUM_LIT:0>) )<EOL><DEDENT>if self.CASRN in CRCHvap_data.index and not np.isnan(CRCHvap_data.at[self.CASRN, '<STR_LIT>']):<EOL><INDENT>methods.append(CRC_HVAP_TB)<EOL>self.CRC_HVAP_TB_Tb = float(CRCHvap_data.at[self.CASRN, '<STR_LIT>'])<EOL>self.CRC_HVAP_TB_Hvap = float(CRCHvap_data.at[self.CASRN, '<STR_LIT>'])<EOL><DEDENT>if self.CASRN in CRCHvap_data.index and not np.isnan(CRCHvap_data.at[self.CASRN, '<STR_LIT>']):<EOL><INDENT>methods.append(CRC_HVAP_298)<EOL>self.CRC_HVAP_298 = float(CRCHvap_data.at[self.CASRN, '<STR_LIT>'])<EOL><DEDENT>if self.CASRN in GharagheiziHvap_data.index:<EOL><INDENT>methods.append(GHARAGHEIZI_HVAP_298)<EOL>self.GHARAGHEIZI_HVAP_298_Hvap = float(GharagheiziHvap_data.at[self.CASRN, '<STR_LIT>'])<EOL><DEDENT>if all((self.Tc, self.omega)):<EOL><INDENT>methods.extend(self.CSP_methods)<EOL>Tmaxs.append(self.Tc); Tmins.append(<NUM_LIT:0>)<EOL><DEDENT>if all((self.Tc, self.Pc)):<EOL><INDENT>methods.append(CLAPEYRON)<EOL>Tmaxs.append(self.Tc); Tmins.append(<NUM_LIT:0>)<EOL><DEDENT>if all((self.Tb, self.Tc, self.Pc)):<EOL><INDENT>methods.extend(self.boiling_methods)<EOL>Tmaxs.append(self.Tc); Tmins.append(<NUM_LIT:0>)<EOL><DEDENT>if self.CASRN in Perrys2_150.index:<EOL><INDENT>methods.append(DIPPR_PERRY_8E)<EOL>_, Tc, C1, C2, C3, C4, self.Perrys2_150_Tmin, self.Perrys2_150_Tmax = _Perrys2_150_values[Perrys2_150.index.get_loc(self.CASRN)].tolist()<EOL>self.Perrys2_150_coeffs = [Tc, C1, C2, C3, C4]<EOL>Tmins.append(self.Perrys2_150_Tmin); Tmaxs.append(self.Perrys2_150_Tmax)<EOL><DEDENT>if self.CASRN in VDI_PPDS_4.index:<EOL><INDENT>_,  MW, Tc, A, B, C, D, E = _VDI_PPDS_4_values[VDI_PPDS_4.index.get_loc(self.CASRN)].tolist()<EOL>self.VDI_PPDS_coeffs = [A, B, C, D, E]<EOL>self.VDI_PPDS_Tc = Tc<EOL>self.VDI_PPDS_MW = MW<EOL>methods.append(VDI_PPDS)<EOL>Tmaxs.append(self.VDI_PPDS_Tc); <EOL><DEDENT>self.all_methods = set(methods)<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`,
        and :obj:`all_methods` as a set of methods for which the data exists for.

        Called on initialization only. See the source code for the variables at
        which the coefficients are stored. The coefficients can safely be
        altered once the class is initialized. This method can be called again
        to reset the parameters.


if method == COOLPROP:<EOL><INDENT>Hvap = PropsSI('<STR_LIT>', '<STR_LIT:T>', T, '<STR_LIT>', <NUM_LIT:1>, self.CASRN) - PropsSI('<STR_LIT>', '<STR_LIT:T>', T, '<STR_LIT>', <NUM_LIT:0>, self.CASRN)<EOL><DEDENT>elif method == DIPPR_PERRY_8E:<EOL><INDENT>Hvap = EQ106(T, *self.Perrys2_150_coeffs)<EOL><DEDENT>elif method == VDI_PPDS:<EOL><INDENT>A, B, C, D, E = self.VDI_PPDS_coeffs<EOL>tau = <NUM_LIT:1.> - T/self.VDI_PPDS_Tc<EOL>Hvap = R*self.VDI_PPDS_Tc*(A*tau**(<NUM_LIT:1>/<NUM_LIT>) + B*tau**(<NUM_LIT:2>/<NUM_LIT>) + C*tau<EOL>+ D*tau**<NUM_LIT:2> + E*tau**<NUM_LIT:6>)<EOL><DEDENT>elif method == ALIBAKHSHI:<EOL><INDENT>Hvap = (<NUM_LIT>*pi*N_A)**(<NUM_LIT:1>/<NUM_LIT>)*<NUM_LIT>*(self.Tc-<NUM_LIT>) - R/<NUM_LIT>*T*log(T) + self.Alibakhshi_C*T<EOL><DEDENT>elif method == MORGAN_KOBAYASHI:<EOL><INDENT>Hvap = MK(T, self.Tc, self.omega)<EOL><DEDENT>elif method == SIVARAMAN_MAGEE_KOBAYASHI:<EOL><INDENT>Hvap = SMK(T, self.Tc, self.omega)<EOL><DEDENT>elif method == VELASCO:<EOL><INDENT>Hvap = Velasco(T, self.Tc, self.omega)<EOL><DEDENT>elif method == PITZER:<EOL><INDENT>Hvap = Pitzer(T, self.Tc, self.omega)<EOL><DEDENT>elif method == CLAPEYRON:<EOL><INDENT>Zg = self.Zg(T) if hasattr(self.Zg, '<STR_LIT>') else self.Zg<EOL>Zl = self.Zl(T) if hasattr(self.Zl, '<STR_LIT>') else self.Zl<EOL>Psat = self.Psat(T) if hasattr(self.Psat, '<STR_LIT>') else self.Psat<EOL>if Zg:<EOL><INDENT>if Zl:<EOL><INDENT>dZ = Zg-Zl<EOL><DEDENT>else:<EOL><INDENT>dZ = Zg<EOL><DEDENT><DEDENT>Hvap = Clapeyron(T, self.Tc, self.Pc, dZ=dZ, Psat=Psat)<EOL><DEDENT>elif method == RIEDEL:<EOL><INDENT>Hvap = Riedel(self.Tb, self.Tc, self.Pc)<EOL><DEDENT>elif method == CHEN:<EOL><INDENT>Hvap = Chen(self.Tb, self.Tc, self.Pc)<EOL><DEDENT>elif method == VETERE:<EOL><INDENT>Hvap = Vetere(self.Tb, self.Tc, self.Pc)<EOL><DEDENT>elif method == LIU:<EOL><INDENT>Hvap = Liu(self.Tb, self.Tc, self.Pc)<EOL><DEDENT>elif method == CRC_HVAP_TB:<EOL><INDENT>Hvap = self.CRC_HVAP_TB_Hvap<EOL><DEDENT>elif method == CRC_HVAP_298:<EOL><INDENT>Hvap = self.CRC_HVAP_298<EOL><DEDENT>elif method == GHARAGHEIZI_HVAP_298:<EOL><INDENT>Hvap = self.GHARAGHEIZI_HVAP_298_Hvap<EOL><DEDENT>elif method in self.tabular_data:<EOL><INDENT>Hvap = self.interpolate(T, method)<EOL><DEDENT>if method in self.boiling_methods or (self.Tc and method in [CRC_HVAP_TB, CRC_HVAP_298, GHARAGHEIZI_HVAP_298]):<EOL><INDENT>if method in self.boiling_methods:<EOL><INDENT>Tref = self.Tb<EOL><DEDENT>elif method == CRC_HVAP_TB:<EOL><INDENT>Tref = self.CRC_HVAP_TB_Tb<EOL><DEDENT>elif method in [CRC_HVAP_298, GHARAGHEIZI_HVAP_298]:<EOL><INDENT>Tref = <NUM_LIT><EOL><DEDENT>Hvap = Watson(T, Hvap, Tref, self.Tc, self.Watson_exponent)<EOL><DEDENT>return Hvap<EOL>

r'''Method to calculate heat of vaporization of a liquid at
        temperature `T` with a given method.

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

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

        Returns
        -------
        Hvap : float
            Heat of vaporization of the liquid at T, [J/mol]


def refractive_index(CASRN, T=None, AvailableMethods=False, Method=None,<EOL>full_info=True):

def list_methods():<EOL><INDENT>methods = []<EOL>if CASRN in CRC_RI_organic.index:<EOL><INDENT>methods.append(CRC)<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 == CRC:<EOL><INDENT>_RI = float(CRC_RI_organic.at[CASRN, '<STR_LIT>'])<EOL>if full_info:<EOL><INDENT>_T = float(CRC_RI_organic.at[CASRN, '<STR_LIT>'])<EOL><DEDENT><DEDENT>elif Method == NONE:<EOL><INDENT>_RI, _T = None, None<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>if full_info:<EOL><INDENT>return _RI, _T<EOL><DEDENT>else:<EOL><INDENT>return _RI<EOL><DEDENT>

r'''This function handles the retrieval of a chemical's refractive
    index. Lookup is based on CASRNs. Will automatically select a data source
    to use if no Method is provided; returns None if the data is not available.

    Function has data for approximately 4500 chemicals.

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

    Returns
    -------
    RI : float
        Refractive Index on the Na D line, [-]
    T : float, only returned if full_info == True
        Temperature at which refractive index reading was made
    methods : list, only returned if AvailableMethods == True
        List of methods which can be used to obtain RI with the given inputs

    Other Parameters
    ----------------
    Method : string, optional
        A string for the method name to use, as defined by constants in
        RI_methods
    AvailableMethods : bool, optional
        If True, function will determine which methods can be used to obtain
        RI for the desired chemical, and will return methods instead of RI
    full_info : bool, optional
        If True, function will return the temperature at which the refractive
        index reading was made

    Notes
    -----
    Only one source is available in this function. It is:

        * 'CRC', a compillation of Organic RI data in [1]_.

    Examples
    --------
    >>> refractive_index(CASRN='64-17-5')
    (1.3611, 293.15)

    References
    ----------
    .. [1] Haynes, W.M., Thomas J. Bruno, and David R. Lide. CRC Handbook of
       Chemistry and Physics, 95E. Boca Raton, FL: CRC press, 2014.


return <NUM_LIT:3>/(<NUM_LIT:4>*pi*N_A)*(RI**<NUM_LIT:2>-<NUM_LIT:1>)/(RI**<NUM_LIT:2>+<NUM_LIT:2>)*Vm<EOL>

r'''Returns the polarizability of a fluid given its molar volume and
    refractive index.

    .. math::
        \alpha = \left(\frac{3}{4\pi N_A}\right)
        \left(\frac{n^2-1}{n^2+2}\right)V_m

    Parameters
    ----------
    RI : float
        Refractive Index on Na D line, [-]
    Vm : float
        Molar volume of fluid, [m^3/mol]

    Returns
    -------
    alpha : float
        Polarizability [m^3]

    Notes
    -----
    This Lorentz-Lorentz-expression is most correct when van der Waals
    interactions dominate. Alternate conversions have been suggested.
    This is often expressed in units of cm^3 or Angstrom^3. To convert to these
    units, multiply by 1E9 or 1E30 respectively.

    Examples
    --------
    >>> polarizability_from_RI(1.3611, 5.8676E-5)
    5.147658123614415e-30

    References
    ----------
    .. [1] Panuganti, Sai R., Fei Wang, Walter G. Chapman, and Francisco M.
       Vargas. "A Simple Method for Estimation of Dielectric Constants and
       Polarizabilities of Nonpolar and Slightly Polar Hydrocarbons."
       International Journal of Thermophysics 37, no. 7 (June 6, 2016): 1-24.
       doi:10.1007/s10765-016-2075-8.


return (RI**<NUM_LIT:2> - <NUM_LIT:1.>)/(RI**<NUM_LIT:2> + <NUM_LIT>)*Vm<EOL>

r'''Returns the molar refractivity of a fluid given its molar volume and
    refractive index.

    .. math::
        R_m = \left(\frac{n^2-1}{n^2+2}\right)V_m

    Parameters
    ----------
    RI : float
        Refractive Index on Na D line, [-]
    Vm : float
        Molar volume of fluid, [m^3/mol]

    Returns
    -------
    Rm : float
        Molar refractivity [m^3/mol]

    Notes
    -----

    Examples
    --------
    >>> molar_refractivity_from_RI(1.3611, 5.8676E-5)
    1.2985217089649597e-05

    References
    ----------
    .. [1] Panuganti, Sai R., Fei Wang, Walter G. Chapman, and Francisco M.
       Vargas. "A Simple Method for Estimation of Dielectric Constants and
       Polarizabilities of Nonpolar and Slightly Polar Hydrocarbons."
       International Journal of Thermophysics 37, no. 7 (June 6, 2016): 1-24.
       doi:10.1007/s10765-016-2075-8.


Rm = ((-<NUM_LIT:2>*Rm - Vm)/(Rm-Vm))**<NUM_LIT:0.5><EOL>return Rm<EOL>

r'''Returns the refractive index of a fluid given its molar volume and
    molar refractivity.

    .. math::
        RI = \sqrt{\frac{-2R_m - V_m}{R_m-V_m}}

    Parameters
    ----------
    Rm : float
        Molar refractivity [m^3/mol]
    Vm : float
        Molar volume of fluid, [m^3/mol]

    Returns
    -------
    RI : float
        Refractive Index on Na D line, [-]

    Notes
    -----

    Examples
    --------
    >>> RI_from_molar_refractivity(1.2985e-5, 5.8676E-5)
    1.3610932757685672

    References
    ----------
    .. [1] Panuganti, Sai R., Fei Wang, Walter G. Chapman, and Francisco M.
       Vargas. "A Simple Method for Estimation of Dielectric Constants and
       Polarizabilities of Nonpolar and Slightly Polar Hydrocarbons."
       International Journal of Thermophysics 37, no. 7 (June 6, 2016): 1-24.
       doi:10.1007/s10765-016-2075-8.


t = T-<NUM_LIT><EOL>mu_w = (t + <NUM_LIT>)/((<NUM_LIT>*t+<NUM_LIT>)*t + <NUM_LIT>)<EOL>return mu_w/<NUM_LIT><EOL>

r'''Calculate the viscosity of a water using the form proposed by [1]_.
    No parameters are needed, just a temperature. Units are Kelvin and Pa*s.
    t is temperature in degrees Celcius.

    .. math::
        \mu_w = \frac{t + 246}{(0.05594t+5.2842)t + 137.37}

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

    Returns
    -------
    mu_w : float
        Water viscosity, Pa*s

    Notes
    -----
    Original source or pure water viscosity is not cited.
    No temperature range is given for this equation.

    Examples
    --------
    >>> Laliberte_viscosity_w(298)
    0.0008932264487033279

    References
    ----------
    .. [1] Laliberte, Marc. "A Model for Calculating the Heat Capacity of
       Aqueous Solutions, with Updated Density and Viscosity Data." Journal of
       Chemical & Engineering Data 54, no. 6 (June 11, 2009): 1725-60.
       doi:10.1021/je8008123


def Laliberte_viscosity_i(T, w_w, v1, v2, v3, v4, v5, v6):

t = T-<NUM_LIT><EOL>mu_i = exp((v1*(<NUM_LIT:1>-w_w)**v2 + v3)/(v4*t+<NUM_LIT:1>))/(v5*(<NUM_LIT:1>-w_w)**v6 + <NUM_LIT:1>)<EOL>return mu_i/<NUM_LIT><EOL>

r'''Calculate the viscosity of a solute using the form proposed by [1]_
    Parameters are needed, and a temperature. Units are Kelvin and Pa*s.

    .. math::
        \mu_i = \frac{\exp\left( \frac{v_1(1-w_w)^{v_2}+v_3}{v_4 t +1}\right)}
            {v_5(1-w_w)^{v_6}+1}

    Parameters
    ----------
    T : float
        Temperature of fluid [K]
    w_w : float
        Weight fraction of water in the solution
    v1-v6 : floats
        Function fit parameters

    Returns
    -------
    mu_i : float
        Solute partial viscosity, Pa*s

    Notes
    -----
    Temperature range check is outside of this function.
    Check is performed using NaCl at 5 degC from the first value in [1]_'s spreadsheet.

    Examples
    --------
    >>> d =  _Laliberte_Viscosity_ParametersDict['7647-14-5']
    >>> Laliberte_viscosity_i(273.15+5, 1-0.005810, d["V1"], d["V2"], d["V3"], d["V4"], d["V5"], d["V6"] )
    0.004254025533308794

    References
    ----------
    .. [1] Laliberte, Marc. "A Model for Calculating the Heat Capacity of
       Aqueous Solutions, with Updated Density and Viscosity Data." Journal of
       Chemical & Engineering Data 54, no. 6 (June 11, 2009): 1725-60.
       doi:10.1021/je8008123


mu_w = Laliberte_viscosity_w(T)*<NUM_LIT><EOL>w_w = <NUM_LIT:1> - sum(ws)<EOL>mu = mu_w**(w_w)<EOL>for i in range(len(CASRNs)):<EOL><INDENT>d = _Laliberte_Viscosity_ParametersDict[CASRNs[i]]<EOL>mu_i = Laliberte_viscosity_i(T, w_w, d["<STR_LIT>"], d["<STR_LIT>"], d["<STR_LIT>"], d["<STR_LIT>"], d["<STR_LIT>"], d["<STR_LIT>"])*<NUM_LIT><EOL>mu = mu_i**(ws[i])*mu<EOL><DEDENT>return mu/<NUM_LIT><EOL>

r'''Calculate the viscosity of an aqueous mixture using the form proposed by [1]_.
    Parameters are loaded by the function as needed. Units are Kelvin and Pa*s.

    .. math::
        \mu_m = \mu_w^{w_w} \Pi\mu_i^{w_i}

    Parameters
    ----------
    T : float
        Temperature of fluid [K]
    ws : array
        Weight fractions of fluid components other than water
    CASRNs : array
        CAS numbers of the fluid components other than water

    Returns
    -------
    mu_i : float
        Solute partial viscosity, Pa*s

    Notes
    -----
    Temperature range check is not used here.
    Check is performed using NaCl at 5 degC from the first value in [1]_'s spreadsheet.

    Examples
    --------
    >>> Laliberte_viscosity(273.15+5, [0.005810], ['7647-14-5'])
    0.0015285828581961414

    References
    ----------
    .. [1] Laliberte, Marc. "A Model for Calculating the Heat Capacity of
       Aqueous Solutions, with Updated Density and Viscosity Data." Journal of
       Chemical & Engineering Data 54, no. 6 (June 11, 2009): 1725-60.
       doi:10.1021/je8008123


t = T-<NUM_LIT><EOL>rho_w = (((((-<NUM_LIT>*t + <NUM_LIT>)*t - <NUM_LIT>)*t - <NUM_LIT>)*t + <NUM_LIT>)*t + <NUM_LIT>)/ (<NUM_LIT:1> + <NUM_LIT>*t)<EOL>return rho_w<EOL>

r'''Calculate the density of water using the form proposed by [1]_.
    No parameters are needed, just a temperature. Units are Kelvin and kg/m^3h.

    .. math::
        \rho_w = \frac{\left\{\left([(-2.8054253\times 10^{-10}\cdot t +
        1.0556302\times 10^{-7})t - 4.6170461\times 10^{-5}]t
        -0.0079870401\right)t + 16.945176   \right\}t + 999.83952}
        {1 + 0.01687985\cdot t}

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

    Returns
    -------
    rho_w : float
        Water density, [kg/m^3]

    Notes
    -----
    Original source not cited
    No temperature range is used.

    Examples
    --------
    >>> Laliberte_density_w(298.15)
    997.0448954179155
    >>> Laliberte_density_w(273.15 + 50)
    988.0362916114763

    References
    ----------
    .. [1] Laliberte, Marc. "A Model for Calculating the Heat Capacity of
       Aqueous Solutions, with Updated Density and Viscosity Data." Journal of
       Chemical & Engineering Data 54, no. 6 (June 11, 2009): 1725-60.
       doi:10.1021/je8008123


def Laliberte_density_i(T, w_w, c0, c1, c2, c3, c4):

t = T - <NUM_LIT><EOL>return ((c0*(<NUM_LIT:1> - w_w)+c1)*exp(<NUM_LIT>*(t + c4)**<NUM_LIT:2>))/((<NUM_LIT:1> - w_w) + c2 + c3*t)<EOL>

r'''Calculate the density of a solute using the form proposed by Laliberte [1]_.
    Parameters are needed, and a temperature, and water fraction. Units are Kelvin and Pa*s.

    .. math::
        \rho_{app,i} = \frac{(c_0[1-w_w]+c_1)\exp(10^{-6}[t+c_4]^2)}
        {(1-w_w) + c_2 + c_3 t}

    Parameters
    ----------
    T : float
        Temperature of fluid [K]
    w_w : float
        Weight fraction of water in the solution
    c0-c4 : floats
        Function fit parameters

    Returns
    -------
    rho_i : float
        Solute partial density, [kg/m^3]

    Notes
    -----
    Temperature range check is TODO

    Examples
    --------
    >>> d = _Laliberte_Density_ParametersDict['7647-14-5']
    >>> Laliberte_density_i(273.15+0, 1-0.0037838838, d["C0"], d["C1"], d["C2"], d["C3"], d["C4"])
    3761.8917585699983

    References
    ----------
    .. [1] Laliberte, Marc. "A Model for Calculating the Heat Capacity of
       Aqueous Solutions, with Updated Density and Viscosity Data." Journal of
       Chemical & Engineering Data 54, no. 6 (June 11, 2009): 1725-60.
       doi:10.1021/je8008123


rho_w = Laliberte_density_w(T)<EOL>w_w = <NUM_LIT:1> - sum(ws)<EOL>rho = w_w/rho_w<EOL>for i in range(len(CASRNs)):<EOL><INDENT>d = _Laliberte_Density_ParametersDict[CASRNs[i]]<EOL>rho_i = Laliberte_density_i(T, w_w, d["<STR_LIT>"], d["<STR_LIT>"], d["<STR_LIT>"], d["<STR_LIT>"], d["<STR_LIT>"])<EOL>rho = rho + ws[i]/rho_i<EOL><DEDENT>return <NUM_LIT:1.>/rho<EOL>

r'''Calculate the density of an aqueous electrolyte mixture using the form proposed by [1]_.
    Parameters are loaded by the function as needed. Units are Kelvin and Pa*s.

    .. math::
        \rho_m = \left(\frac{w_w}{\rho_w} + \sum_i \frac{w_i}{\rho_{app_i}}\right)^{-1}

    Parameters
    ----------
    T : float
        Temperature of fluid [K]
    ws : array
        Weight fractions of fluid components other than water
    CASRNs : array
        CAS numbers of the fluid components other than water

    Returns
    -------
    rho_i : float
        Solution density, [kg/m^3]

    Notes
    -----
    Temperature range check is not used here.

    Examples
    --------
    >>> Laliberte_density(273.15, [0.0037838838], ['7647-14-5'])
    1002.6250120185854

    References
    ----------
    .. [1] Laliberte, Marc. "A Model for Calculating the Heat Capacity of
       Aqueous Solutions, with Updated Density and Viscosity Data." Journal of
       Chemical & Engineering Data 54, no. 6 (June 11, 2009): 1725-60.
       doi:10.1021/je8008123


return float(Laliberte_heat_capacity_w_interp(T - <NUM_LIT>))<EOL>

r'''Calculate the heat capacity of water using the interpolation proposed by [1]_.
    No parameters are needed, just a temperature.

    .. math::
        Cp_w = Cp_1 + (Cp_2-Cp_1) \left( \frac{t-t_1}{t_2-t_1}\right)
        + \frac{(Cp_3 - 2Cp_2 + Cp_1)}{2}\left( \frac{t-t_1}{t_2-t_1}\right)
        \left( \frac{t-t_1}{t_2-t_1}-1\right)

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

    Returns
    -------
    Cp_w : float
        Water heat capacity, [J/kg/K]

    Notes
    -----
    Units are Kelvin and J/kg/K.
    Original source not cited
    No temperature range is used.
    The original equation is not used, but rather a cubic scipy interpolation routine.

    Examples
    --------
    >>> Laliberte_heat_capacity_w(273.15+3.56)
    4208.878020261102

    References
    ----------
    .. [1] Laliberte, Marc. "A Model for Calculating the Heat Capacity of
       Aqueous Solutions, with Updated Density and Viscosity Data." Journal of
       Chemical & Engineering Data 54, no. 6 (June 11, 2009): 1725-60.
       doi:10.1021/je8008123


def Laliberte_heat_capacity_i(T, w_w, a1, a2, a3, a4, a5, a6):

t = T - <NUM_LIT><EOL>alpha = a2*t + a3*exp(<NUM_LIT>*t) + a4*(<NUM_LIT:1.> - w_w)<EOL>Cp_i = a1*exp(alpha) + a5*(<NUM_LIT:1.> - w_w)**a6<EOL>return Cp_i*<NUM_LIT><EOL>

r'''Calculate the heat capacity of a solute using the form proposed by [1]_
    Parameters are needed, and a temperature, and water fraction.

    .. math::
        Cp_i = a_1 e^\alpha + a_5(1-w_w)^{a_6}
        \alpha = a_2 t + a_3 \exp(0.01t) + a_4(1-w_w)

    Parameters
    ----------
    T : float
        Temperature of fluid [K]
    w_w : float
        Weight fraction of water in the solution
    a1-a6 : floats
        Function fit parameters

    Returns
    -------
    Cp_i : float
        Solute partial heat capacity, [J/kg/K]

    Notes
    -----
    Units are Kelvin and J/kg/K.
    Temperature range check is TODO

    Examples
    --------
    >>> d = _Laliberte_Heat_Capacity_ParametersDict['7647-14-5']
    >>> Laliberte_heat_capacity_i(1.5+273.15, 1-0.00398447, d["A1"], d["A2"], d["A3"], d["A4"], d["A5"], d["A6"])
    -2930.7353945880477

    References
    ----------
    .. [1] Laliberte, Marc. "A Model for Calculating the Heat Capacity of
       Aqueous Solutions, with Updated Density and Viscosity Data." Journal of
       Chemical & Engineering Data 54, no. 6 (June 11, 2009): 1725-60.
       doi:10.1021/je8008123


def Laliberte_heat_capacity(T, ws, CASRNs):

Cp_w = Laliberte_heat_capacity_w(T)<EOL>w_w = <NUM_LIT:1> - sum(ws)<EOL>Cp = w_w*Cp_w<EOL>for i in range(len(CASRNs)):<EOL><INDENT>d = _Laliberte_Heat_Capacity_ParametersDict[CASRNs[i]]<EOL>Cp_i = Laliberte_heat_capacity_i(T, w_w, d["<STR_LIT>"], d["<STR_LIT>"], d["<STR_LIT>"], d["<STR_LIT>"], d["<STR_LIT>"], d["<STR_LIT>"])<EOL>Cp = Cp + ws[i]*Cp_i<EOL><DEDENT>return Cp<EOL>

r'''Calculate the heat capacity of an aqueous electrolyte mixture using the
    form proposed by [1]_.
    Parameters are loaded by the function as needed.

    .. math::
        TODO

    Parameters
    ----------
    T : float
        Temperature of fluid [K]
    ws : array
        Weight fractions of fluid components other than water
    CASRNs : array
        CAS numbers of the fluid components other than water

    Returns
    -------
    Cp : float
        Solution heat capacity, [J/kg/K]

    Notes
    -----
    Temperature range check is not implemented.
    Units are Kelvin and J/kg/K.

    Examples
    --------
    >>> Laliberte_heat_capacity(273.15+1.5, [0.00398447], ['7647-14-5'])
    4186.569908672113

    References
    ----------
    .. [1] Laliberte, Marc. "A Model for Calculating the Heat Capacity of
       Aqueous Solutions, with Updated Density and Viscosity Data." Journal of
       Chemical & Engineering Data 54, no. 6 (June 11, 2009): 1725-60.
       doi:10.1021/je8008123


def dilute_ionic_conductivity(ionic_conductivities, zs, rhom):

return sum([ci*(zi*rhom) for zi, ci in zip(zs, ionic_conductivities)])<EOL>

r'''This function handles the calculation of the electrical conductivity of
    a dilute electrolytic aqueous solution. Requires the mole fractions of
    each ion, the molar density of the whole mixture, and ionic conductivity
    coefficients for each ion.

    .. math::
        \lambda = \sum_i \lambda_i^\circ z_i \rho_m

    Parameters
    ----------
    ionic_conductivities : list[float]
        Ionic conductivity coefficients of each ion in the mixture [m^2*S/mol]
    zs : list[float]
        Mole fractions of each ion in the mixture, [-]
    rhom : float
        Overall molar density of the solution, [mol/m^3]

    Returns
    -------
    kappa : float
        Electrical conductivity of the fluid, [S/m]

    Notes
    -----
    The ionic conductivity coefficients should not be `equivalent` coefficients;
    for example, 0.0053 m^2*S/mol is the equivalent conductivity coefficient of
    Mg+2, but this method expects twice its value - 0.0106. Both are reported
    commonly in literature.

    Water can be included in this caclulation by specifying a coefficient of
    0. The conductivity of any electrolyte eclipses its own conductivity by
    many orders of magnitude. Any other solvents present will affect the
    conductivity extensively and there are few good methods to predict this
    effect.

    Examples
    --------
    Complex mixture of electrolytes ['Cl-', 'HCO3-', 'SO4-2', 'Na+', 'K+',
    'Ca+2', 'Mg+2']:

    >>> ionic_conductivities = [0.00764, 0.00445, 0.016, 0.00501, 0.00735, 0.0119, 0.01061]
    >>> zs = [0.03104, 0.00039, 0.00022, 0.02413, 0.0009, 0.0024, 0.00103]
    >>> dilute_ionic_conductivity(ionic_conductivities=ionic_conductivities, zs=zs, rhom=53865.9)
    22.05246783663

    References
    ----------
    .. [1] Haynes, W.M., Thomas J. Bruno, and David R. Lide. CRC Handbook of
       Chemistry and Physics, 95E. Boca Raton, FL: CRC press, 2014.


def conductivity_McCleskey(T, M, lambda_coeffs, A_coeffs, B, multiplier, rho=<NUM_LIT>):

t = T - <NUM_LIT><EOL>lambda_coeff = horner(lambda_coeffs, t)<EOL>A = horner(A_coeffs, t)<EOL>M_root = M**<NUM_LIT:0.5><EOL>param = lambda_coeff - A*M_root/(<NUM_LIT:1.> + B*M_root)<EOL>C = M*rho/<NUM_LIT> <EOL>return param*C*multiplier*<NUM_LIT:0.1><EOL>

r'''This function handles the calculation of the electrical conductivity of
    an electrolytic aqueous solution with one electrolyte in solution. It
    handles temperature dependency and concentrated solutions. Requires the
    temperature of the solution; its molality, and four sets of coefficients
    `lambda_coeffs`, `A_coeffs`, `B`, and `multiplier`.

    .. math::
        \Lambda = \frac{\kappa}{C}

        \Lambda = \Lambda^0(t) - A(t) \frac{m^{1/2}}{1+Bm^{1/2}}

        \Lambda^\circ(t) = c_1 t^2 + c_2 t + c_3

        A(t) = d_1 t^2 + d_2 t + d_3

    In the above equations, `t` is temperature in degrees Celcius;
    `m` is molality in mol/kg, and C is the concentration of the elctrolytes
    in mol/m^3, calculated as the product of density and molality.

    Parameters
    ----------
    T : float
        Temperature of the solution, [K]
    M : float
        Molality of the solution with respect to one electrolyte
        (mol solute / kg solvent), [mol/kg]
    lambda_coeffs : list[float]
        List of coefficients for the polynomial used to calculate `lambda`;
        length-3 coefficients provided in [1]_,  [-]
    A_coeffs : list[float]
        List of coefficients for the polynomial used to calculate `A`;
        length-3 coefficients provided in [1]_, [-]
    B : float
        Empirical constant for an electrolyte, [-]
    multiplier : float
        The multiplier to obtain the absolute conductivity from the equivalent
        conductivity; ex 2 for CaCl2, [-]
    rho : float, optional
        The mass density of the aqueous mixture, [kg/m^3]

    Returns
    -------
    kappa : float
        Electrical conductivity of the solution at the specified molality and
        temperature [S/m]

    Notes
    -----
    Coefficients provided in [1]_ result in conductivity being calculated in
    units of mS/cm; they are converted to S/m before returned.

    Examples
    --------
    A 0.5 wt% solution of CaCl2, conductivity calculated in mS/cm

    >>> conductivity_McCleskey(T=293.15, M=0.045053, A_coeffs=[.03918, 3.905,
    ... 137.7], lambda_coeffs=[0.01124, 2.224, 72.36], B=3.8, multiplier=2)
    0.8482584585108555

    References
    ----------
    .. [1] McCleskey, R. Blaine. "Electrical Conductivity of Electrolytes Found
       In Natural Waters from (5 to 90) °C." Journal of Chemical & Engineering
       Data 56, no. 2 (February 10, 2011): 317-27. doi:10.1021/je101012n.


def conductivity(CASRN=None, AvailableMethods=False, Method=None, full_info=True):

def list_methods():<EOL><INDENT>methods = []<EOL>if CASRN in Lange_cond_pure.index:<EOL><INDENT>methods.append(LANGE_COND)<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 == LANGE_COND:<EOL><INDENT>kappa = float(Lange_cond_pure.at[CASRN, '<STR_LIT>'])<EOL>if full_info:<EOL><INDENT>T = float(Lange_cond_pure.at[CASRN, '<STR_LIT:T>'])<EOL><DEDENT><DEDENT>elif Method == NONE:<EOL><INDENT>kappa, T = None, None<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>if full_info:<EOL><INDENT>return kappa, T<EOL><DEDENT>else:<EOL><INDENT>return kappa<EOL><DEDENT>

r'''This function handles the retrieval of a chemical's conductivity.
    Lookup is based on CASRNs. Will automatically select a data source to use
    if no Method is provided; returns None if the data is not available.

    Function has data for approximately 100 chemicals.

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

    Returns
    -------
    kappa : float
        Electrical conductivity of the fluid, [S/m]
    T : float, only returned if full_info == True
        Temperature at which conductivity measurement was made
    methods : list, only returned if AvailableMethods == True
        List of methods which can be used to obtain RI with the given inputs

    Other Parameters
    ----------------
    Method : string, optional
        A string for the method name to use, as defined by constants in
        conductivity_methods
    AvailableMethods : bool, optional
        If True, function will determine which methods can be used to obtain
        conductivity for the desired chemical, and will return methods instead
        of conductivity
    full_info : bool, optional
        If True, function will return the temperature at which the conductivity
        reading was made

    Notes
    -----
    Only one source is available in this function. It is:

        * 'LANGE_COND' which is from Lange's Handbook, Table 8.34 Electrical
        Conductivity of Various Pure Liquids', a compillation of data in [1]_.

    Examples
    --------
    >>> conductivity('7732-18-5')
    (4e-06, 291.15)

    References
    ----------
    .. [1] Speight, James. Lange's Handbook of Chemistry. 16 edition.
       McGraw-Hill Professional, 2005.


def thermal_conductivity_Magomedov(T, P, ws, CASRNs, k_w=None):

P = P/<NUM_LIT><EOL>ws = [i*<NUM_LIT:100> for i in ws]<EOL>if not k_w:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>sum1 = <NUM_LIT:0><EOL>for i, CASRN in enumerate(CASRNs):<EOL><INDENT>Ai = float(Magomedovk_thermal_cond.at[CASRN, '<STR_LIT>'])<EOL>sum1 += Ai*(ws[i] + <NUM_LIT>*ws[i]**<NUM_LIT:3>)<EOL><DEDENT>return k_w*(<NUM_LIT:1> - sum1) - <NUM_LIT>*P*T*sum(ws)<EOL>

r'''Calculate the thermal conductivity of an aqueous mixture of
    electrolytes using the form proposed by Magomedov [1]_.
    Parameters are loaded by the function as needed. Function will fail if an
    electrolyte is not in the database.

    .. math::
        \lambda = \lambda_w\left[ 1 - \sum_{i=1}^n A_i (w_i + 2\times10^{-4}
        w_i^3)\right] - 2\times10^{-8} PT\sum_{i=1}^n w_i

    Parameters
    ----------
    T : float
        Temperature of liquid [K]
    P : float
        Pressure of the liquid [Pa]
    ws : array
        Weight fractions of liquid components other than water
    CASRNs : array
        CAS numbers of the liquid components other than water
    k_w : float
        Liquid thermal condiuctivity or pure water at T and P, [W/m/K]

    Returns
    -------
    kl : float
        Liquid thermal condiuctivity, [W/m/K]

    Notes
    -----
    Range from 273 K to 473 K, P from 0.1 MPa to 100 MPa. C from 0 to 25 mass%.
    Internal untis are MPa for pressure and weight percent.

    An example is sought for this function. It is not possible to reproduce
    the author's values consistently.

    Examples
    --------
    >>> thermal_conductivity_Magomedov(293., 1E6, [.25], ['7758-94-3'], k_w=0.59827)
    0.548654049375

    References
    ----------
    .. [1] Magomedov, U. B. "The Thermal Conductivity of Binary and
       Multicomponent Aqueous Solutions of Inorganic Substances at High
       Parameters of State." High Temperature 39, no. 2 (March 1, 2001):
       221-26. doi:10.1023/A:1017518731726.


return <NUM_LIT:0.5>*sum([mi*zi*zi for mi, zi in zip(mis, zis)])<EOL>

r'''Calculate the ionic strength of a solution in one of two ways,
    depending on the inputs only. For Pitzer and Bromley models,
    `mis` should be molalities of each component. For eNRTL models,
    `mis` should be mole fractions of each electrolyte in the solution.
    This will sum to be much less than 1.

    .. math::
        I = \frac{1}{2} \sum M_i z_i^2

        I = \frac{1}{2} \sum x_i z_i^2

    Parameters
    ----------
    mis : list
        Molalities of each ion, or mole fractions of each ion [mol/kg or -]
    zis : list
        Charges of each ion [-]

    Returns
    -------
    I : float
        ionic strength, [?]

    Examples
    --------
    >>> ionic_strength([0.1393, 0.1393], [1, -1])
    0.1393

    References
    ----------
    .. [1] Chen, Chau-Chyun, H. I. Britt, J. F. Boston, and L. B. Evans. "Local
       Composition Model for Excess Gibbs Energy of Electrolyte Systems.
       Part I: Single Solvent, Single Completely Dissociated Electrolyte
       Systems." AIChE Journal 28, no. 4 (July 1, 1982): 588-96.
       doi:10.1002/aic.690280410
    .. [2] Gmehling, Jurgen. Chemical Thermodynamics: For Process Simulation.
       Weinheim, Germany: Wiley-VCH, 2012.


rho_w = rho_w/<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>G = <NUM_LIT><EOL>return <NUM_LIT:10>**(A + B/T + C/T**<NUM_LIT:2> + D/T**<NUM_LIT:3> + (E + F/T + G/T**<NUM_LIT:2>)*log10(rho_w))<EOL>

r'''Calculates equilibrium constant for OH- and H+ in water, according to
    [1]_. Second most recent formulation.

    .. math::
        \log_{10} K_w= A + B/T + C/T^2 + D/T^3 + (E+F/T+G/T^2)\log_{10} \rho_w

    Parameters
    ----------
    T : float
        Temperature of fluid [K]
    rho_w : float
        Density of water, [kg/m^3]

    Returns
    -------
    Kweq : float
        Ionization constant of water, [-]

    Notes
    -----
    Density is internally converted to units of g/cm^3.

    A = -4.098;
    B = -3245.2;
    C = 2.2362E5;
    D = -3.984E7;
    E = 13.957;
    F = -1262.3;
    G = 8.5641E5

    Examples
    --------
    >>> -1*log10(Kweq_1981(600, 700))
    11.274522047458206

    References
    ----------
    .. [1] Marshall, William L., and E. U. Franck. "Ion Product of Water
       Substance, 0-1000  degree C, 1010,000 Bars New International Formulation
       and Its Background." Journal of Physical and Chemical Reference Data 10,
       no. 2 (April 1, 1981): 295-304. doi:10.1063/1.555643.


gamma0 = <NUM_LIT><EOL>gamma1 = <NUM_LIT><EOL>gamma2 = -<NUM_LIT><EOL>gamma3 = <NUM_LIT><EOL>K_w_G = <NUM_LIT:10>**(-<NUM_LIT:1>*(gamma0 + gamma1/T + gamma2/T**<NUM_LIT:2> + gamma3/T**<NUM_LIT:3>))<EOL>return K_w_G<EOL>

r'''Calculates equilibrium constant for OH- and H+ in water vapor,
    according to [1]_.
    This is the most recent formulation available.

    .. math::
        -log_{10}  K_w^G = \gamma_0 + \gamma_1 T^{-1} + \gamma_2 T^{-2} + \gamma_3 T^{-3}

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

    Returns
    -------
    K_w_G : float

    Notes
    -----
    gamma0 = 6.141500E-1;
    gamma1 = 4.825133E4;
    gamma2 = -6.770793E4;
    gamma3 = 1.010210E7

    Examples
    --------
    >>> Kweq_IAPWS_gas(800)
    1.4379721554798815e-61

    References
    ----------
    .. [1] Bandura, Andrei V., and Serguei N. Lvov. "The Ionization Constant
       of Water over Wide Ranges of Temperature and Density." Journal of Physical
       and Chemical Reference Data 35, no. 1 (March 1, 2006): 15-30.
       doi:10.1063/1.1928231


K_w_G = Kweq_IAPWS_gas(T)<EOL>rho_w = rho_w/<NUM_LIT><EOL>n = <NUM_LIT:6><EOL>alpha0 = -<NUM_LIT><EOL>alpha1 = <NUM_LIT><EOL>alpha2 = -<NUM_LIT><EOL>beta0 = <NUM_LIT><EOL>beta1 = -<NUM_LIT><EOL>beta2 = -<NUM_LIT><EOL>Q = rho_w*exp(alpha0 + alpha1/T + alpha2/T**<NUM_LIT:2>*rho_w**(<NUM_LIT:2>/<NUM_LIT>))<EOL>K_w = <NUM_LIT:10>**(-<NUM_LIT:1>*(-<NUM_LIT:2>*n*(log10(<NUM_LIT:1>+Q)-Q/(Q+<NUM_LIT:1>) * rho_w *(beta0 + beta1/T + beta2*rho_w)) -<EOL>log10(K_w_G) + <NUM_LIT:2>*log10(<NUM_LIT>/<NUM_LIT:1000>) ))<EOL>return K_w<EOL>

r'''Calculates equilibrium constant for OH- and H+ in water, according to
    [1]_.
    This is the most recent formulation available.

    .. math::
        Q = \rho \exp(\alpha_0 + \alpha_1 T^{-1} + \alpha_2 T^{-2} \rho^{2/3})

        - \log_{10} K_w = -2n \left[ \log_{10}(1+Q) - \frac{Q}{Q+1} \rho
        (\beta_0 + \beta_1 T^{-1} + \beta_2 \rho) \right]
        -\log_{10} K_w^G + 2 \log_{10} \frac{18.015268}{1000}

    Parameters
    ----------
    T : float
        Temperature of water [K]
    rho_w : float
        Density of water at temperature and pressure [kg/m^3]

    Returns
    -------
    Kweq : float
        Ionization constant of water, [-]

    Notes
    -----
    Formulation is in terms of density in g/cm^3; density
    is converted internally.

    n = 6;
    alpha0 = -0.864671;
    alpha1 = 8659.19;
    alpha2 = -22786.2;
    beta0 = 0.642044;
    beta1 = -56.8534;
    beta2 = -0.375754

    Examples
    --------
    Example from IAPWS check:

    >>> -1*log10(Kweq_IAPWS(600, 700))
    11.203153057603775

    References
    ----------
    .. [1] Bandura, Andrei V., and Serguei N. Lvov. "The Ionization Constant
       of Water over Wide Ranges of Temperature and Density." Journal of Physical
       and Chemical Reference Data 35, no. 1 (March 1, 2006): 15-30.
       doi:10.1063/1.1928231


def ion_balance_proportional(anion_charges, cation_charges, zs, n_anions, <EOL>n_cations, balance_error, method):

anion_zs = zs[<NUM_LIT:0>:n_anions]<EOL>cation_zs = zs[n_anions:n_cations+n_anions]<EOL>anion_balance_error = sum([zi*ci for zi, ci in zip(anion_zs, anion_charges)])<EOL>cation_balance_error = sum([zi*ci for zi, ci in zip(cation_zs, cation_charges)])<EOL>if method == '<STR_LIT>':<EOL><INDENT>if balance_error < <NUM_LIT:0>:<EOL><INDENT>multiplier = -anion_balance_error/cation_balance_error<EOL>cation_zs = [i*multiplier for i in cation_zs]<EOL><DEDENT>else:<EOL><INDENT>multiplier = -cation_balance_error/anion_balance_error<EOL>anion_zs = [i*multiplier for i in anion_zs]<EOL><DEDENT><DEDENT>elif method == '<STR_LIT>':<EOL><INDENT>if balance_error < <NUM_LIT:0>:<EOL><INDENT>multiplier = -cation_balance_error/anion_balance_error<EOL>anion_zs = [i*multiplier for i in anion_zs]<EOL><DEDENT>else:<EOL><INDENT>multiplier = -anion_balance_error/cation_balance_error<EOL>cation_zs = [i*multiplier for i in cation_zs]<EOL><DEDENT><DEDENT>elif method == '<STR_LIT>':<EOL><INDENT>multiplier = -anion_balance_error/cation_balance_error<EOL>cation_zs = [i*multiplier for i in cation_zs]<EOL><DEDENT>elif method == '<STR_LIT>':<EOL><INDENT>multiplier = -cation_balance_error/anion_balance_error<EOL>anion_zs = [i*multiplier for i in anion_zs]<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>' %charge_balance_methods)<EOL><DEDENT>z_water = <NUM_LIT:1.> - sum(anion_zs) - sum(cation_zs)<EOL>return anion_zs, cation_zs, z_water<EOL>

Helper method for balance_ions for the proportional family of methods.
    See balance_ions for a description of the methods; parameters are fairly
    obvious.


def balance_ions(anions, cations, anion_zs=None, cation_zs=None, <EOL>anion_concs=None, cation_concs=None, rho_w=<NUM_LIT>, <EOL>method='<STR_LIT>', selected_ion=None):

anions = list(anions)<EOL>cations = list(cations)<EOL>n_anions = len(anions)<EOL>n_cations = len(cations)<EOL>ions = anions + cations<EOL>anion_charges = [i.charge for i in anions]<EOL>cation_charges = [i.charge for i in cations]<EOL>charges = anion_charges + cation_charges + [<NUM_LIT:0>]<EOL>MW_water = [<NUM_LIT>]<EOL>rho_w = rho_w/<NUM_LIT:1000> <EOL>if anion_concs is not None and cation_concs is not None:<EOL><INDENT>anion_ws = [i*<NUM_LIT>/rho_w for i in anion_concs]<EOL>cation_ws = [i*<NUM_LIT>/rho_w for i in cation_concs]<EOL>w_water = <NUM_LIT:1> - sum(anion_ws) - sum(cation_ws)<EOL>anion_MWs = [i.MW for i in anions]<EOL>cation_MWs = [i.MW for i in cations]<EOL>MWs = anion_MWs + cation_MWs + MW_water<EOL>zs = ws_to_zs(anion_ws + cation_ws + [w_water], MWs)<EOL><DEDENT>else:<EOL><INDENT>if anion_zs is None or cation_zs is None:<EOL><INDENT>raise Exception('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>zs = anion_zs + cation_zs<EOL>zs = zs + [<NUM_LIT:1> - sum(zs)]<EOL><DEDENT><DEDENT>impacts = [zi*ci for zi, ci in zip(zs, charges)]<EOL>balance_error = sum(impacts)<EOL>if abs(balance_error) < <NUM_LIT>:<EOL><INDENT>anion_zs = zs[<NUM_LIT:0>:n_anions]<EOL>cation_zs = zs[n_anions:n_cations+n_anions]<EOL>z_water = zs[-<NUM_LIT:1>]<EOL>return anions, cations, anion_zs, cation_zs, z_water<EOL><DEDENT>if '<STR_LIT>' in method:<EOL><INDENT>anion_zs, cation_zs, z_water = ion_balance_dominant(impacts,<EOL>balance_error, charges, zs, n_anions, n_cations, method)<EOL>return anions, cations, anion_zs, cation_zs, z_water<EOL><DEDENT>elif '<STR_LIT>' in method:<EOL><INDENT>anion_zs, cation_zs, z_water = ion_balance_proportional(<EOL>anion_charges, cation_charges, zs, n_anions, n_cations,<EOL>balance_error, method)<EOL>return anions, cations, anion_zs, cation_zs, z_water<EOL><DEDENT>elif method == '<STR_LIT>':<EOL><INDENT>increase = True<EOL>if balance_error < <NUM_LIT:0>:<EOL><INDENT>selected_ion = pubchem_db.search_name('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>selected_ion = pubchem_db.search_name('<STR_LIT>')<EOL><DEDENT><DEDENT>elif method == '<STR_LIT>':<EOL><INDENT>increase = False<EOL>if balance_error > <NUM_LIT:0>:<EOL><INDENT>selected_ion = pubchem_db.search_name('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>selected_ion = pubchem_db.search_name('<STR_LIT>')<EOL><DEDENT><DEDENT>elif method == '<STR_LIT>':<EOL><INDENT>increase = None<EOL><DEDENT>elif method == '<STR_LIT>':<EOL><INDENT>increase = True<EOL><DEDENT>elif method == '<STR_LIT>':<EOL><INDENT>increase = False<EOL><DEDENT>elif method == '<STR_LIT>':<EOL><INDENT>increase = True<EOL>if balance_error < <NUM_LIT:0>:<EOL><INDENT>selected_ion = selected_ion[<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>selected_ion = selected_ion[<NUM_LIT:0>]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>if selected_ion is None:<EOL><INDENT>raise Exception("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>anion_zs, cation_zs, z_water = ion_balance_adjust_wrapper(charges, zs, n_anions, n_cations,<EOL>anions, cations, selected_ion, increase=increase)<EOL>return anions, cations, anion_zs, cation_zs, z_water<EOL>

r'''Performs an ion balance to adjust measured experimental ion
    compositions to electroneutrality. Can accept either the actual mole
    fractions of the ions, or their concentrations in units of [mg/L] as well
    for convinience.

    The default method will locate the most prevalent ion in the type of
    ion not in excess - and increase it until the two ion types balance.

    Parameters
    ----------
    anions : list(ChemicalMetadata)
        List of all negatively charged ions measured as being in the solution;
        ChemicalMetadata instances or simply objects with the attributes `MW`
        and `charge`, [-]
    cations : list(ChemicalMetadata)
        List of all positively charged ions measured as being in the solution;
        ChemicalMetadata instances or simply objects with the attributes `MW`
        and `charge`, [-]
    anion_zs : list, optional
        Mole fractions of each anion as measured in the aqueous solution, [-]
    cation_zs : list, optional
        Mole fractions of each cation as measured in the aqueous solution, [-]
    anion_concs : list, optional
        Concentrations of each anion in the aqueous solution in the units often
        reported (for convinience only) [mg/L]
    cation_concs : list, optional
        Concentrations of each cation in the aqueous solution in the units
        often reported (for convinience only) [mg/L]
    rho_w : float, optional
        Density of the aqueous solutionr at the temperature and pressure the
        anion and cation concentrations were measured (if specified), [kg/m^3]
    method : str, optional
        The method to use to balance the ionimbalance; one of 'dominant',
        'decrease dominant', 'increase dominant',
        'proportional insufficient ions increase',
        'proportional excess ions decrease',
        'proportional cation adjustment', 'proportional anion adjustment',
        'Na or Cl increase', 'Na or Cl decrease', 'adjust', 'increase',
        'decrease', 'makeup'].
    selected_ion : ChemicalMetadata, optional
        Some methods adjust only one user-specified ion; this is that input.
        For the case of the 'makeup' method, this is a tuple of (anion, cation)
        ChemicalMetadata instances and only the ion type not in excess will be
        used.

    Returns
    -------
    anions : list(ChemicalMetadata)
        List of all negatively charged ions measured as being in the solution;
        ChemicalMetadata instances after potentially adding in an ion which
        was not present but specified by the user, [-]
    cations : list(ChemicalMetadata)
        List of all positively charged ions measured as being in the solution;
        ChemicalMetadata instances after potentially adding in an ion which
        was not present but specified by the user, [-]
    anion_zs : list,
        Mole fractions of each anion in the aqueous solution after the charge
        balance, [-]
    cation_zs : list
        Mole fractions of each cation in the aqueous solution after the charge
        balance, [-]
    z_water : float
        Mole fraction of the water in the solution, [-]

    Notes
    -----
    The methods perform the charge balance as follows:

    * 'dominant' : The ion with the largest mole fraction in solution has its
      concentration adjusted up or down as necessary to balance the solution.
    * 'decrease dominant' : The ion with the largest mole fraction in the type
      of ion with *excess* charge has its own mole fraction decreased to balance
      the solution.
    * 'increase dominant' : The ion with the largest mole fraction in the type
      of ion with *insufficient* charge has its own mole fraction decreased to
      balance the solution.
    * 'proportional insufficient ions increase' : The ion charge type which is
      present insufficiently has each of the ions mole fractions *increased*
      proportionally until the solution is balanced.
    * 'proportional excess ions decrease' :  The ion charge type which is
      present in excess has each of the ions mole fractions *decreased*
      proportionally until the solution is balanced.
    * 'proportional cation adjustment' : All *cations* have their mole fractions
      increased or decreased proportionally as necessary to balance the
      solution.
    * 'proportional anion adjustment' : All *anions* have their mole fractions
      increased or decreased proportionally as necessary to balance the
      solution.
    * 'Na or Cl increase' : Either Na+ or Cl- is *added* to the solution until
      the solution is balanced; the species will be added if they were not
      present initially as well.
    * 'Na or Cl decrease' : Either Na+ or Cl- is *removed* from the solution
      until the solution is balanced; the species will be added if they were
      not present initially as well.
    * 'adjust' : An ion specified with the parameter `selected_ion` has its
      mole fraction *increased or decreased* as necessary to balance the
      solution. An exception is raised if the specified ion alone cannot
      balance the solution.
    * 'increase' : An ion specified with the parameter `selected_ion` has its
      mole fraction *increased* as necessary to balance the
      solution. An exception is raised if the specified ion alone cannot
      balance the solution.
    * 'decrease' : An ion specified with the parameter `selected_ion` has its
      mole fraction *decreased* as necessary to balance the
      solution. An exception is raised if the specified ion alone cannot
      balance the solution.
    * 'makeup' : Two ions ase specified as a tuple with the parameter
      `selected_ion`. Whichever ion type is present in the solution
      insufficiently is added; i.e. if the ions were Mg+2 and Cl-, and there
      was too much negative charge in the solution, Mg+2 would be added until
      the solution was balanced.

    Examples
    --------
    >>> anions_n = ['Cl-', 'HCO3-', 'SO4-2']
    >>> cations_n = ['Na+', 'K+', 'Ca+2', 'Mg+2']
    >>> cations = [pubchem_db.search_name(i) for i in cations_n]
    >>> anions = [pubchem_db.search_name(i) for i in anions_n]
    >>> an_res, cat_res, an_zs, cat_zs, z_water = balance_ions(anions, cations,
    ... anion_zs=[0.02557, 0.00039, 0.00026], cation_zs=[0.0233, 0.00075,
    ... 0.00262, 0.00119], method='proportional excess ions decrease')
    >>> an_zs
    [0.02557, 0.00039, 0.00026]
    >>> cat_zs
    [0.01948165456267761, 0.0006270918850647299, 0.0021906409851594564, 0.0009949857909693717]
    >>> z_water
    0.9504856267761288

    References
    ----------


def K_value(P=None, Psat=None, phi_l=None, phi_g=None, gamma=None, Poynting=<NUM_LIT:1>):

try:<EOL><INDENT>if gamma:<EOL><INDENT>if phi_l:<EOL><INDENT>return gamma*Psat*phi_l*Poynting/(phi_g*P)<EOL><DEDENT>return gamma*Psat*Poynting/P<EOL><DEDENT>elif phi_l:<EOL><INDENT>return phi_l/phi_g<EOL><DEDENT>return Psat/P<EOL><DEDENT>except TypeError:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>

r'''Calculates the equilibrium K-value assuming Raoult's law,
    or an equation of state model, or an activity coefficient model,
    or a combined equation of state-activity model.

    The calculation procedure will use the most advanced approach with the
    provided inputs:

        * If `P`, `Psat`, `phi_l`, `phi_g`, and `gamma` are provided, use the
          combined approach.
        * If `P`, `Psat`, and `gamma` are provided, use the modified Raoult's
          law.
        * If `phi_l` and `phi_g` are provided, use the EOS only method.
        * If `P` and `Psat` are provided, use Raoult's law.

    Definitions:

    .. math::
        K_i=\frac{y_i}{x_i}

    Raoult's law:

    .. math::
        K_i = \frac{P_{i}^{sat}}{P}

    Activity coefficient, no EOS (modified Raoult's law):

    .. math::
        K_i = \frac{\gamma_i P_{i}^{sat}}{P}

    Equation of state only:

    .. math::
        K_i = \frac{\phi_i^l}{\phi_i^v} = \frac{f_i^l}{f_i^v}

    Combined approach (liquid reference fugacity coefficient is normally
    calculated the saturation pressure for it as a pure species; vapor fugacity
    coefficient calculated normally):

    .. math::
        K_i = \frac{\gamma_i P_i^{sat} \phi_i^{l,ref}}{\phi_i^v P}

    Combined approach, with Poynting Correction Factor (liquid molar volume in
    the integral is for i as a pure species only):

    .. math::
        K_i = \frac{\gamma_i P_i^{sat} \phi_i^{l, ref} \exp\left[\frac{
        \int_{P_i^{sat}}^P V_i^l dP}{RT}\right]}{\phi_i^v P}

    Parameters
    ----------
    P : float
        System pressure, optional
    Psat : float
        Vapor pressure of species i, [Pa]
    phi_l : float
        Fugacity coefficient of species i in the liquid phase, either
        at the system conditions (EOS-only case) or at the saturation pressure
        of species i as a pure species (reference condition for the combined
        approach), optional [-]
    phi_g : float
        Fugacity coefficient of species i in the vapor phase at the system
        conditions, optional [-]
    gamma : float
        Activity coefficient of species i in the liquid phase, optional [-]
    Poynting : float
        Poynting correction factor, optional [-]

    Returns
    -------
    K : float
        Equilibrium K value of component i, calculated with an approach
        depending on the provided inputs [-]

    Notes
    -----
    The Poynting correction factor is normally simplified as follows, due to
    a liquid's low pressure dependency:

    .. math::
        K_i = \frac{\gamma_i P_i^{sat} \phi_i^{l, ref} \exp\left[\frac{V_l
        (P-P_i^{sat})}{RT}\right]}{\phi_i^v P}

    Examples
    --------
    Raoult's law:

    >>> K_value(101325, 3000.)
    0.029607698001480384

    Modified Raoult's law:

    >>> K_value(P=101325, Psat=3000, gamma=0.9)
    0.026646928201332347

    EOS-only approach:

    >>> K_value(phi_l=1.6356, phi_g=0.88427)
    1.8496613025433408

    Gamma-phi combined approach:

    >>> K_value(P=1E6, Psat=1938800, phi_l=1.4356, phi_g=0.88427, gamma=0.92)
    2.8958055544121137

    Gamma-phi combined approach with a Poynting factor:

    >>> K_value(P=1E6, Psat=1938800, phi_l=1.4356, phi_g=0.88427, gamma=0.92,
    ... Poynting=0.999)
    2.8929097488577016

    References
    ----------
    .. [1] Gmehling, Jurgen, Barbel Kolbe, Michael Kleiber, and Jurgen Rarey.
       Chemical Thermodynamics for Process Simulation. 1st edition. Weinheim:
       Wiley-VCH, 2012.
    .. [2] Skogestad, Sigurd. Chemical and Energy Process Engineering. 1st
       edition. Boca Raton, FL: CRC Press, 2008.


def Rachford_Rice_flash_error(V_over_F, zs, Ks):

return sum([zi*(Ki-<NUM_LIT:1.>)/(<NUM_LIT:1.>+V_over_F*(Ki-<NUM_LIT:1.>)) for Ki, zi in zip(Ks, zs)])<EOL>

r'''Calculates the objective function of the Rachford-Rice flash equation.
    This function should be called by a solver seeking a solution to a flash
    calculation. The unknown variable is `V_over_F`, for which a solution
    must be between 0 and 1.

    .. math::
        \sum_i \frac{z_i(K_i-1)}{1 + \frac{V}{F}(K_i-1)} = 0

    Parameters
    ----------
    V_over_F : float
        Vapor fraction guess [-]
    zs : list[float]
        Overall mole fractions of all species, [-]
    Ks : list[float]
        Equilibrium K-values, [-]

    Returns
    -------
    error : float
        Deviation between the objective function at the correct V_over_F
        and the attempted V_over_F, [-]

    Notes
    -----
    The derivation is as follows:

    .. math::
        F z_i = L x_i + V y_i

        x_i = \frac{z_i}{1 + \frac{V}{F}(K_i-1)}

        \sum_i y_i = \sum_i K_i x_i = 1

        \sum_i(y_i - x_i)=0

        \sum_i \frac{z_i(K_i-1)}{1 + \frac{V}{F}(K_i-1)} = 0

    Examples
    --------
    >>> Rachford_Rice_flash_error(0.5, zs=[0.5, 0.3, 0.2],
    ... Ks=[1.685, 0.742, 0.532])
    0.04406445591174976

    References
    ----------
    .. [1] Rachford, H. H. Jr, and J. D. Rice. "Procedure for Use of Electronic
       Digital Computers in Calculating Flash Vaporization Hydrocarbon
       Equilibrium." Journal of Petroleum Technology 4, no. 10 (October 1,
       1952): 19-3. doi:10.2118/952327-G.


Kmin = min(Ks)<EOL>Kmax = max(Ks)<EOL>z_of_Kmax = zs[Ks.index(Kmax)]<EOL>V_over_F_min = ((Kmax-Kmin)*z_of_Kmax - (<NUM_LIT:1.>-Kmin))/((<NUM_LIT:1.>-Kmin)*(Kmax-<NUM_LIT:1.>))<EOL>V_over_F_max = <NUM_LIT:1.>/(<NUM_LIT:1.>-Kmin)<EOL>V_over_F_min2 = max(<NUM_LIT:0.>, V_over_F_min)<EOL>V_over_F_max2 = min(<NUM_LIT:1.>, V_over_F_max)<EOL>x0 = (V_over_F_min2 + V_over_F_max2)*<NUM_LIT:0.5><EOL>try:<EOL><INDENT>V_over_F = newton(Rachford_Rice_flash_error, x0=x0, args=(zs, Ks))<EOL>assert V_over_F >= V_over_F_min2<EOL>assert V_over_F <= V_over_F_max2<EOL><DEDENT>except:<EOL><INDENT>V_over_F = brenth(Rachford_Rice_flash_error, V_over_F_max-<NUM_LIT>, V_over_F_min+<NUM_LIT>, args=(zs, Ks))<EOL><DEDENT>xs = [zi/(<NUM_LIT:1.>+V_over_F*(Ki-<NUM_LIT:1.>)) for zi, Ki in zip(zs, Ks)]<EOL>ys = [Ki*xi for xi, Ki in zip(xs, Ks)]<EOL>return V_over_F, xs, ys<EOL>

r'''Solves the objective function of the Rachford-Rice flash equation.
    Uses the method proposed in [2]_ to obtain an initial guess.

    .. math::
        \sum_i \frac{z_i(K_i-1)}{1 + \frac{V}{F}(K_i-1)} = 0

    Parameters
    ----------
    zs : list[float]
        Overall mole fractions of all species, [-]
    Ks : list[float]
        Equilibrium K-values, [-]

    Returns
    -------
    V_over_F : float
        Vapor fraction solution [-]
    xs : list[float]
        Mole fractions of each species in the liquid phase, [-]
    ys : list[float]
        Mole fractions of each species in the vapor phase, [-]

    Notes
    -----
    The initial guess is the average of the following, as described in [2]_.

    .. math::
        \left(\frac{V}{F}\right)_{min} = \frac{(K_{max}-K_{min})z_{of\;K_{max}}
        - (1-K_{min})}{(1-K_{min})(K_{max}-1)}

        \left(\frac{V}{F}\right)_{max} = \frac{1}{1-K_{min}}

    Another algorithm for determining the range of the correct solution is
    given in [3]_; [2]_ provides a narrower range however. For both cases,
    each guess should be limited to be between 0 and 1 as they are often
    negative or larger than 1.

    .. math::
        \left(\frac{V}{F}\right)_{min} = \frac{1}{1-K_{max}}

        \left(\frac{V}{F}\right)_{max} = \frac{1}{1-K_{min}}

    If the `newton` method does not converge, a bisection method (brenth) is
    used instead. However, it is somewhat slower, especially as newton will
    attempt 50 iterations before giving up.

    Examples
    --------
    >>> Rachford_Rice_solution(zs=[0.5, 0.3, 0.2], Ks=[1.685, 0.742, 0.532])
    (0.6907302627738542, [0.3394086969663436, 0.3650560590371706, 0.2955352439964858], [0.571903654388289, 0.27087159580558057, 0.15722474980613044])

    References
    ----------
    .. [1] Rachford, H. H. Jr, and J. D. Rice. "Procedure for Use of Electronic
       Digital Computers in Calculating Flash Vaporization Hydrocarbon
       Equilibrium." Journal of Petroleum Technology 4, no. 10 (October 1,
       1952): 19-3. doi:10.2118/952327-G.
    .. [2] Li, Yinghui, Russell T. Johns, and Kaveh Ahmadi. "A Rapid and Robust
       Alternative to Rachford-Rice in Flash Calculations." Fluid Phase
       Equilibria 316 (February 25, 2012): 85-97.
       doi:10.1016/j.fluid.2011.12.005.
    .. [3] Whitson, Curtis H., and Michael L. Michelsen. "The Negative Flash."
       Fluid Phase Equilibria, Proceedings of the Fifth International
       Conference, 53 (December 1, 1989): 51-71.
       doi:10.1016/0378-3812(89)80072-X.