Files
ACLC26/ACLC26_utility_functions.ipynb

6.3 KiB

Utility Functions

In [1]:
# Import packages
import numpy as np
import pandas as pd
In [2]:
def solution_prep(dict):
    """
    Calculates gramms needed for solution with concentration C [M=mol/L] volume V [mL] of substance with molar mass M [g/mol] and solubility S [g/L] at 20°C.
    Input as dictionary with the necessary parameters, e.g.
        dict_ca = { "Name": "citric acid",
                    'M': 192.124, # molar mass [g/mol]
                    'V': 100, # volume of solution [mL]
                    'C': 4, # concentration [mol/L]
                    "S": 1330 # solubility in water [g/L] at 20°C
                }
    Returns gramms needed for mixing, mole fraction x and mass fraction w of the solution. Checks if that many gramms are soluble at 20°C.
    """

    vol = dict["V"] / 1000 # volume conversion from mL to L

    # gramms
    n_mols = dict["C"] * vol
    gramms = n_mols * dict["M"]
    print("To make {} mL of a {} mol/L solution, {:.4f} gramms of {} are needed.".format(dict["V"], dict["C"], gramms, dict["Name"]))

    # solubility
    if dict["S"]=="NA" or dict["S"]==None or dict["S"]=="" or dict["S"]==0:
        print("No solubility information was provided.")
    else:
        soluble = dict["S"] * vol
        if soluble > gramms:
            print(f"This amount is soluble at 20°C. ({gramms:.2f} < {soluble} g)")
        else:
            print(f"This amount is not soluble at 20°C. ({gramms:.2f} > {soluble} g)")

    # mass fraction
    M_h2o = 18.01528 #g/mol
    n_h2o = vol*1000 / M_h2o # moles of water
    n2 = dict['C'] * vol # moles of second component

    x = n2 / (n_h2o+n2) # mole fraction
    w = x * dict['M'] / (x*dict['M'] + (1-x)*M_h2o)
    print(f"The solution has a mole fraction x of {x:.3f} and a mass fraction w of {w:.3f}.")
    
    return gramms, x, w
In [ ]:
dict_ca = {"Name": "citric acid",
           'M': 192.124, # molar mass [g/mol] (anhydrous)
           'V': 10, # volume of solution [mL]
           'C': 0.1, # concentration [mol/L]
           "S": 1330 # solubility in water [g/L] at 20°C
        }
In [4]:
g, x, w = solution_prep(dict_ca)
print(g, x, w)
To make 10 mL of a 0.1 mol/L solution, 0.1921 gramms of citric acid are needed.
This amount is soluble at 20°C. (0.19 < 13.3 g)
The solution has a mole fraction x of 0.002 and a mass fraction w of 0.019.
0.192124 0.001798288333215639 0.018850241617939502
In [ ]:
dict_fecit = {"Name": "FeCit",
           'M': 244.94, # molar mass [g/mol] (monohydrate)
           'V': 10, # volume of solution [mL]
           'C': 0.001, # concentration [mol/L]
           "S": None # solubility in water [g/L] at 20°C
        }
g, x, w = solution_prep(dict_fecit)
To make 10 mL of a 0.001 mol/L solution, 0.0024 gramms of FeCit are needed.
No solubility information was provided.
The solution has a mole fraction x of 0.000 and a mass fraction w of 0.000.
In [10]:
dict_nacl = {"Name": "NaCl",
           'M': 58.44, # molar mass [g/mol]
           'V': 50, # volume of solution [mL]
           'C': 5, # concentration [mol/L]
           "S": 360 # solubility in water [g/L] at 20°C
        }
g, x, w = solution_prep(dict_nacl)
To make 50 mL of a 5 mol/L solution, 14.6100 gramms of NaCl are needed.
This amount is soluble at 20°C. (14.61 < 18.0 g)
The solution has a mole fraction x of 0.083 and a mass fraction w of 0.226.
In [7]:
dict_nano3 = {"Name": "NaNO3",
           'M': 84.9947, # molar mass [g/mol]
           'V': 10, # volume of solution [mL]
           'C': 0.1, # concentration [mol/L]
           "S": None # solubility in water [g/L] at 20°C
        }
g, x, w = solution_prep(dict_nano3)
To make 10 mL of a 0.1 mol/L solution, 0.0850 gramms of NaNO3 are needed.
No solubility information was provided.
The solution has a mole fraction x of 0.002 and a mass fraction w of 0.008.
In [ ]: