コード例 #1
0
    def test_effective_pitzer_mgcl2_activity(self):
        # test the activity coefficient of MgCl2
        # corresponds to 0.515m, 1.03m, 2.58m, and 4.1m
        multiple = [1, 2, 5, 8]
        expected = [0.5, 0.5, 0.67, 1.15]

        # import the parameters database
        from pyEQL import paramsDB as db

        for item in range(len(multiple)):
            s1 = self.mock_seawater(multiple[item])
            Salt = pyEQL.salt_ion_match.Salt('Mg+2', 'Cl-')
            db.search_parameters(Salt.formula)
            param = db.get_parameter(Salt.formula,
                                     'pitzer_parameters_activity')
            alpha1 = 2
            alpha2 = 0
            molality = Salt.get_effective_molality(s1.get_ionic_strength())
            temperature = str(s1.get_temperature())

            activity_coefficient=pyEQL.activity_correction.get_activity_coefficient_pitzer(s1.get_ionic_strength(), \
            molality,alpha1,alpha2,param.get_value()[0],param.get_value()[1],param.get_value()[2],param.get_value()[3], \
            Salt.z_cation,Salt.z_anion,Salt.nu_cation,Salt.nu_anion,temperature)

            # convert the result to a rational activity coefficient
            result = activity_coefficient * (
                1 + pyEQL.unit('0.018 kg/mol') * s1.get_total_moles_solute() /
                s1.get_solvent_mass())
            #print(result,expected[item])
            self.assertWithinExperimentalError(result, expected[item],
                                               self.tol)
コード例 #2
0
 def test_effective_pitzer_mgcl2_activity(self):
     # test the activity coefficient of MgCl2
     # corresponds to 0.515m, 1.03m, 2.58m, and 4.1m
     multiple = [1,2,5,8]
     expected=[0.5,0.5,0.67,1.15]
     
     # import the parameters database
     from pyEQL import paramsDB as db
         
     for item in range(len(multiple)):
         s1 = self.mock_seawater(multiple[item])
         Salt = pyEQL.salt_ion_match.Salt('Mg+2','Cl-')
         db.search_parameters(Salt.formula)
         param = db.get_parameter(Salt.formula,'pitzer_parameters_activity')
         alpha1 = 2
         alpha2 = 0
         molality = Salt.get_effective_molality(s1.get_ionic_strength())
         temperature = str(s1.get_temperature())
         
         activity_coefficient=pyEQL.activity_correction.get_activity_coefficient_pitzer(s1.get_ionic_strength(), \
         molality,alpha1,alpha2,param.get_value()[0],param.get_value()[1],param.get_value()[2],param.get_value()[3], \
         Salt.z_cation,Salt.z_anion,Salt.nu_cation,Salt.nu_anion,temperature)
         
         # convert the result to a rational activity coefficient
         result = activity_coefficient * (1+pyEQL.unit('0.018 kg/mol')*s1.get_total_moles_solute()/s1.get_solvent_mass())
         #print(result,expected[item])
         self.assertWithinExperimentalError(result,expected[item],self.tol) 
コード例 #3
0
ファイル: solute.py プロジェクト: qize/pyEQL
    def __init__(self, formula, amount, volume, solvent_mass, parameters={}):
        """
        Parameters
        ----------
        formula : str
                    Chemical formula for the solute. 
                    Charged species must contain a + or - and (for polyvalent solutes) a number representing the net
                    charge (e.g. 'SO4-2').
        amount : str
                    The amount of substance in the specified unit system. The string should contain both a quantity and
                    a pint-compatible representation of a unit. e.g. '5 mol/kg' or '0.1 g/L'
        volume : pint Quantity
                    The volume of the solution
        solvent_mass : pint Quantity
                    The mass of solvent in the parent solution.
        parameters : dictionary, optional
                    Dictionary of custom parameters, such as diffusion coefficients, transport numbers, etc. Specify 
                    parameters as key:value pairs separated by commas within curly braces, e.g. 
                    {diffusion_coeff:5e-10,transport_number:0.8}. The 'key' is the name that will be used to access 
                    the parameter, the value is its value.
        """
        # import the chemical formula interpreter module
        import pyEQL.chemical_formula as chem

        # check that 'formula' is a valid chemical formula
        if not chem.is_valid_formula:
            logger.error("Invalid chemical formula specified.")
            return None
        else:
            self.formula = formula

            # set molecular weight
            self.mw = chem.get_molecular_weight(formula) * unit("g/mol")

            # set formal charge
            self.charge = chem.get_formal_charge(formula)

            # translate the 'amount' string into a pint Quantity
            quantity = unit(amount)

            self.moles = quantity.to("moles",
                                     "chem",
                                     mw=self.mw,
                                     volume=volume,
                                     solvent_mass=solvent_mass)

            # trigger the function that checks whether parameters already exist for this species, and if not,
            # searches the database files and creates them
            db.search_parameters(self.formula)
コード例 #4
0
    def __init__(self,formula,amount,volume,solvent_mass,parameters={}):
        '''
        Parameters
        ----------
        formula : str
                    Chemical formula for the solute. 
                    Charged species must contain a + or - and (for polyvalent solutes) a number representing the net charge (e.g. 'SO4-2').
        amount : str
                    The amount of substance in the specified unit system. The string should contain both a quantity and
                    a pint-compatible representation of a unit. e.g. '5 mol/kg' or '0.1 g/L'
        volume : pint Quantity
                    The volume of the solution
        solvent_mass : pint Quantity
                    The mass of solvent in the parent solution.
        parameters : dictionary, optional
                    Dictionary of custom parameters, such as diffusion coefficients, transport numbers, etc. Specify parameters as key:value pairs separated by commas within curly braces, e.g. {diffusion_coeff:5e-10,transport_number:0.8}. The 'key' is the name that will be used to access the parameter, the value is its value.
        '''             
        # import the chemical formula interpreter module
        import pyEQL.chemical_formula as chem
        
        # check that 'formula' is a valid chemical formula
        if not chem.is_valid_formula:
            logger.error('Invalid chemical formula specified.')
            return None
        else:
            self.formula = formula

            # set molecular weight 
            self.mw = chem.get_molecular_weight(formula) * unit('g/mol')
            
            # set formal charge
            self.charge = chem.get_formal_charge(formula)
            
            # translate the 'amount' string into a pint Quantity
            quantity = unit(amount)
            
            self.moles = quantity.to('moles','chem',mw=self.mw,volume=volume,solvent_mass=solvent_mass)                

            # trigger the function that checks whether parameters already exist for this species, and if not,
            # searches the database files and creates them
            db.search_parameters(self.formula)