示例#1
0
    def _parse_SURFACE_SPECIES(self, lines):
        """
sample :
        Hfo_sOH  + H+ = Hfo_sOH2+
        log_k  7.29    # = pKa1,int

relevant info:
        - name Hfo_sOH2+, first term of right member
        - log_k 7.29
        - equation
        """
        species = {}
        it = iter(lines)
        line = self._skipEmptyLinesAndComments(it)

        # parse format1
        entry = None
        while line is not None:
            if line and line[0] != COMMENT:
                eq = Equation(line)
                species[str(eq.getMainTerm())] = entry = {EQUATION: eq}

                line = self._readNextLine(it)
                logk = line.split()[1]
                entry[LOGK] = logk

            line = self._readNextLine(it)
        return species

        return ""
示例#2
0
    def _parse_SURFACE_SPECIES(self, lines):
        """
sample :
        Hfo_sOH  + H+ = Hfo_sOH2+
        log_k  7.29    # = pKa1,int

relevant info:
        - name Hfo_sOH2+, first term of right member
        - log_k 7.29
        - equation
        """
        species = {}
        it = iter(lines)
        line = self._skipEmptyLinesAndComments(it)

        # parse format1
        entry = None
        while line is not None:
            if line and line[0] != COMMENT:
                eq = Equation(line)
                species[str(eq.getMainTerm())] = entry = {EQUATION:eq}

                line = self._readNextLine(it)
                logk = line.split()[1]
                entry[LOGK] = logk

            line = self._readNextLine(it)
        return species

        return ""
示例#3
0
    def _parse_PHASES(self, lines):
        """
        parses the PHASES part

        here is a sample of an entry:

Acanthite
        Ag2S +1.0000 H+  =  + 1.0000 HS- + 2.0000 Ag+
        log_k           -36.0346
    -delta_H    226.982 kJ/mol  # Calculated enthalpy of reaction   Acanthite
#   Enthalpy of formation:  -7.55 kcal/mol
        -analytic -1.6067e+002 -4.7139e-002 -7.4522e+003 6.6140e+001 -1.1624e+002
#       -Range:  0-300

        The relevant parts are :
            - the name Acanthite
            - the symbol Ag2S
            - the formula Ag2S +1.0000 H+  =  + 1.0000 HS- + 2.0000 Ag+
            - the log_k -36.0346
            - the optional delta_H : 226.982 kJ/mol
        """
        phases = {}
        it = iter(lines)
        line = self._skipEmptyLinesAndComments(it)
        eq = None
        name = None
        logk_pattern = re.compile('log_k')
        deltah_pattern = re.compile('delta_h', re.IGNORECASE)
        while line is not None:
            if line and line[0] != COMMENT:
                if not line[0].isspace(): # new entry
                    name = line.rstrip()
                    # next line should be the equation
                    line = self._skipEmptyLinesAndComments(it)
                    try:
                        # PHASES equations may use the ":" symbol
                        # let's convert it to a ' + '

                        eq = Equation(line.replace(":", " + "))
                    except type, msg:
                        warnings.warn("error parsing equation for PHASES : " + line)
                        warnings.warn( msg )
                        #raise
                    phases[name] = {NAME:name, EQUATION:eq, FORMULA:eq.parseLeftMembers()[0][0],
                                    LOGK:"", DELTAH:"", DENSITY:""}
                elif logk_pattern.search(line):
                    phases[name][LOGK] = line.split()[1]
                elif deltah_pattern.search(line):
                    li = line.split()
                    d = li[1]
                    if len(li) > 2 and li[2][0] != COMMENT:
                        d += " " + li[2]
                    phases[name][DELTAH] = d

            line = self._readNextLine(it)
示例#4
0
    def _parse_SOLUTION_SPECIES(self, lines):
        """
        format a bit complex, seems to be several variants :
        anyways the first line of an entry is an equation
        followed by several other lines, but the only other
        line that seems of interest for us is the log_k

        the equation line has to be parsed : the main name of the element is
        the first member of the right part

        Return: a list of [Equation, logk]
        """

        species = {}
        it = iter(lines)
        line = self._skipEmptyLinesAndComments(it)
        eq = None
        # parse format1
        entry = None
        while line is not None:
            if line and line[0] != COMMENT:
                if line.find(EQUALS) != -1:  # new entry
                    try:
                        eq = Equation(line)
                    except Exception, err:
                        warnings.warn(
                            "got exception parsing SOLUTION_SPECIES equation, line is \n"
                            + line + "\n error is " + str(err))
                        raise

                    elt = str(eq.getMainTerm())
                    species[elt] = entry = {
                        ELEMENT: elt,
                        FORMULA: elt,
                        EQUATION: eq
                    }
                elif line.find('log_k') != -1:
                    logk = line.split()[1]
                    entry[LOGK] = self._makeFloat(logk)

            line = self._readNextLine(it)
示例#5
0
    def _parse_SOLUTION_SPECIES(self, lines):
        """
        format a bit complex, seems to be several variants :
        anyways the first line of an entry is an equation
        followed by several other lines, but the only other
        line that seems of interest for us is the log_k

        the equation line has to be parsed : the main name of the element is
        the first member of the right part

        Return: a list of [Equation, logk]
        """

        species = {}
        it = iter(lines)
        line = self._skipEmptyLinesAndComments(it)
        eq = None
        # parse format1
        entry = None
        while line is not None:
            if line and line[0] != COMMENT:
                if line.find(EQUALS) != -1: # new entry
                    try:
                        eq = Equation(line)
                    except Exception, err:
                        warnings.warn("got exception parsing SOLUTION_SPECIES equation, line is \n" +
                                      line + "\n error is " + str(err))
                        raise

                    elt = str(eq.getMainTerm())
                    species[elt] = entry = {ELEMENT: elt, FORMULA: elt, EQUATION:eq}
                elif line.find('log_k') != -1:
                    logk = line.split()[1]
                    entry[LOGK] = self._makeFloat(logk)

            line = self._readNextLine(it)
示例#6
0
    def _parse_EXCHANGE_SPECIES(self, lines):
        """"
        excerpt from the phreeqc manual:
Example

Line 0:  EXCHANGE_SPECIES
Line 1a:      X- = X-
Line 2a:           log_k     0.0
Line 1b:      X- + Na+ = NaX
Line 2b:           log_k     0.0
Line 1c:      2X- + Ca+2 = CaX2
Line 2c:           log_k     0.8
Line 1d:      Xa- = Xa-
Line 2d:           log_k     0.0
Line 1e:      X- + Na+ = NaX
Line 2e:           log_k     0.0
Line 1f:      2Xa- + Ca+2 = CaXa2
Line 2f:           log_k     2.0

Explanation
Line 0: EXCHANGE_SPECIES

    Keyword for the data block. No other data are input on the keyword line.

Line 1: Association reaction

    Association reaction for exchange species.
    The defined species must be the first species to the right of the equal sign.
    The association reaction must precede any identifiers related to the exchange species.
    Master species have an identity reaction (lines 1a and 1d).

Line 2: log_k log K

    log_k--Identifier for log K at 25oC. Optionally, -log_k, logk, -l[og_k], or -l[ogk].

    log K--Log K at 25oC for the reaction. Default 0.0. Unlike log K for aqueous species, the log K for exchange species is implicitly relative to a single exchange species. In the default database file, sodium (NaX) is used as the reference and the reaction X- + Na+ = NaX is given a log K of 0.0 (line 2b). The log K for the exchange reaction for the reaction given in line 2c is then numerically equal to the log K for the reaction 2NaX + Ca+2 = CaX2 + 2Na+. Master species have log K of 0.0 (lines 2a and 2d); reference species have log K of 0.0 (lines 2b and 2e).
        """

        species = {}
        it = iter(lines)
        line = self._skipEmptyLinesAndComments(it)
        eq = None
        # parse format1
        entry = None
        while line is not None:
            if line and line[0] != COMMENT:
                if line.find(EQUALS) != -1:  # new entry
                    try:
                        eq = Equation(line)
                    except Exception, err:
                        msg = "error parsing EXCHANGE_SPECIES equation, line %s \n error: %s \n" % (
                            line, str(err))
                        warnings.warn(msg)
                        raise

                    elt = str(eq.getMainTerm())
                    species[elt] = entry = {
                        ELEMENT: elt,
                        FORMULA: elt,
                        EQUATION: eq,
                        LOGK: 0.0,
                        ACTIVITY_LAW: [ACTIVITY_LAW_NONE]
                    }
                elif line.find('og') != -1:
                    logk = line.split()[1]
                    entry[LOGK] = self._makeFloat(logk)

            line = self._readNextLine(it)
示例#7
0
    def _parse_PHASES(self, lines):
        """
        parses the PHASES part

        here is a sample of an entry:

Acanthite
        Ag2S +1.0000 H+  =  + 1.0000 HS- + 2.0000 Ag+
        log_k           -36.0346
    -delta_H    226.982 kJ/mol  # Calculated enthalpy of reaction   Acanthite
#   Enthalpy of formation:  -7.55 kcal/mol
        -analytic -1.6067e+002 -4.7139e-002 -7.4522e+003 6.6140e+001 -1.1624e+002
#       -Range:  0-300

        The relevant parts are :
            - the name Acanthite
            - the symbol Ag2S
            - the formula Ag2S +1.0000 H+  =  + 1.0000 HS- + 2.0000 Ag+
            - the log_k -36.0346
            - the optional delta_H : 226.982 kJ/mol
        """
        phases = {}
        it = iter(lines)
        line = self._skipEmptyLinesAndComments(it)
        eq = None
        name = None
        logk_pattern = re.compile('log_k')
        deltah_pattern = re.compile('delta_h', re.IGNORECASE)
        while line is not None:
            if line and line[0] != COMMENT:
                if not line[0].isspace():  # new entry
                    name = line.rstrip()
                    # next line should be the equation
                    line = self._skipEmptyLinesAndComments(it)
                    try:
                        # PHASES equations may use the ":" symbol
                        # let's convert it to a ' + '

                        eq = Equation(line.replace(":", " + "))
                    except type, msg:
                        warnings.warn("error parsing equation for PHASES : " +
                                      line)
                        warnings.warn(msg)
                        #raise
                    phases[name] = {
                        NAME: name,
                        EQUATION: eq,
                        FORMULA: eq.parseLeftMembers()[0][0],
                        LOGK: "",
                        DELTAH: "",
                        DENSITY: ""
                    }
                elif logk_pattern.search(line):
                    phases[name][LOGK] = line.split()[1]
                elif deltah_pattern.search(line):
                    li = line.split()
                    d = li[1]
                    if len(li) > 2 and li[2][0] != COMMENT:
                        d += " " + li[2]
                    phases[name][DELTAH] = d

            line = self._readNextLine(it)
示例#8
0
    def _parse_EXCHANGE_SPECIES(self, lines):
        """"
        excerpt from the phreeqc manual:
Example

Line 0:  EXCHANGE_SPECIES
Line 1a:      X- = X-
Line 2a:           log_k     0.0
Line 1b:      X- + Na+ = NaX
Line 2b:           log_k     0.0
Line 1c:      2X- + Ca+2 = CaX2
Line 2c:           log_k     0.8
Line 1d:      Xa- = Xa-
Line 2d:           log_k     0.0
Line 1e:      X- + Na+ = NaX
Line 2e:           log_k     0.0
Line 1f:      2Xa- + Ca+2 = CaXa2
Line 2f:           log_k     2.0

Explanation
Line 0: EXCHANGE_SPECIES

    Keyword for the data block. No other data are input on the keyword line.

Line 1: Association reaction

    Association reaction for exchange species.
    The defined species must be the first species to the right of the equal sign.
    The association reaction must precede any identifiers related to the exchange species.
    Master species have an identity reaction (lines 1a and 1d).

Line 2: log_k log K

    log_k--Identifier for log K at 25oC. Optionally, -log_k, logk, -l[og_k], or -l[ogk].

    log K--Log K at 25oC for the reaction. Default 0.0. Unlike log K for aqueous species, the log K for exchange species is implicitly relative to a single exchange species. In the default database file, sodium (NaX) is used as the reference and the reaction X- + Na+ = NaX is given a log K of 0.0 (line 2b). The log K for the exchange reaction for the reaction given in line 2c is then numerically equal to the log K for the reaction 2NaX + Ca+2 = CaX2 + 2Na+. Master species have log K of 0.0 (lines 2a and 2d); reference species have log K of 0.0 (lines 2b and 2e).
        """

        species = {}
        it = iter(lines)
        line = self._skipEmptyLinesAndComments(it)
        eq = None
        # parse format1
        entry = None
        while line is not None:
            if line and line[0] != COMMENT:
                if line.find(EQUALS) != -1: # new entry
                    try:
                        eq = Equation(line)
                    except Exception, err:
                        msg = "error parsing EXCHANGE_SPECIES equation, line %s \n error: %s \n" %(line, str(err))
                        warnings.warn( msg )
                        raise

                    elt = str(eq.getMainTerm())
                    species[elt] = entry = {ELEMENT: elt, FORMULA:elt, EQUATION:eq
                                            , LOGK:0.0,
                                             ACTIVITY_LAW:[ACTIVITY_LAW_NONE] }
                elif line.find('og') != -1:
                    logk = line.split()[1]
                    entry[LOGK] = self._makeFloat(logk)

            line = self._readNextLine(it)