Skip to content

Output Parsers (parsers.py)

Output parsers for Multiwfn results.

pymultiwfn.analysis.parsers

Output parsers for Multiwfn results.

ClaudeCode-extracted regex patterns from Multiwfn 3.8 manual (6 Jan 2026).

Each parser class inherits from :class:OutputParser and exposes a :meth:parse_for_result classmethod that the :class:MultiwfnResult container calls. parse_for_result dispatches to the appropriate static parsing helpers and returns a flat list[ParsedMultiwfnResult].

AromaticityParser

Bases: OutputParser

Parser for aromaticity analysis output.

Source code in src/pymultiwfn/analysis/parsers.py
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
class AromaticityParser(OutputParser):
    """Parser for aromaticity analysis output."""

    @classmethod
    def _parse_nics_scan_or_none(cls, stdout: str) -> NICSScan | None:
        """Return parsed NICS scan only if it contains data."""
        scan = cls.parse_nics_scan(stdout)
        return scan if scan.distances else None

    @classmethod
    def parse_for_result(
        cls,
        analysis: Menu,
        stdout: str,
    ) -> list[ParsedMultiwfnResult]:
        case_map: dict[Menu, list] = {
            Menu.NICS_SCAN: [cls.parse, cls._parse_nics_scan_or_none],
            Menu.NICS_1D_SCAN: [cls.parse, cls._parse_nics_scan_or_none],
        }
        parsers = case_map.get(analysis, [cls.parse])
        return cls._collect(stdout, parsers)

    @staticmethod
    def parse(stdout: str) -> Aromaticity:
        """Extract aromaticity indices."""
        result = Aromaticity()

        patterns: dict[str, str] = {
            "NICS": rf"NICS\s*(?:\(0\))?[=:\s]+({FLOAT_PATTERN})",
            "NICS_1": rf"NICS\s*\(1\)[=:\s]+({FLOAT_PATTERN})",
            "NICS_ZZ": rf"NICS_?ZZ[=:\s]+({FLOAT_PATTERN})",
            "HOMA": rf"HOMA[=:\s]+({FLOAT_PATTERN})",
            "HOMAC": rf"HOMAC[=:\s]+({FLOAT_PATTERN})",
            "HOMER": rf"HOMER[=:\s]+({FLOAT_PATTERN})",
            "Bird": rf"Bird.*?index[=:\s]+({FLOAT_PATTERN})",
            "EN_GEO": rf"EN[_\s]*GEO[=:\s]+({FLOAT_PATTERN})",
            "EN_BLA": rf"EN[_\s]*BLA[=:\s]+({FLOAT_PATTERN})",
        }

        for key, pat in patterns.items():
            if match := re.search(pat, stdout, re.IGNORECASE):
                setattr(result, key, float(match[1]))

        return result

    @staticmethod
    def parse_nics_scan(stdout: str) -> NICSScan:
        """Extract NICS scan profile data."""
        distances: list[float] = []
        values: list[float] = []
        pattern = rf"^\s*({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s*$"
        in_scan = False
        for line in stdout.split("\n"):
            if "nics" in line.lower() and "scan" in line.lower():
                in_scan = True
                continue
            if in_scan and (match := re.match(pattern, line)):
                distances.append(float(match[1]))
                values.append(float(match[2]))
        return NICSScan(distances=distances, values=values)

parse(stdout) staticmethod

Extract aromaticity indices.

Source code in src/pymultiwfn/analysis/parsers.py
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
@staticmethod
def parse(stdout: str) -> Aromaticity:
    """Extract aromaticity indices."""
    result = Aromaticity()

    patterns: dict[str, str] = {
        "NICS": rf"NICS\s*(?:\(0\))?[=:\s]+({FLOAT_PATTERN})",
        "NICS_1": rf"NICS\s*\(1\)[=:\s]+({FLOAT_PATTERN})",
        "NICS_ZZ": rf"NICS_?ZZ[=:\s]+({FLOAT_PATTERN})",
        "HOMA": rf"HOMA[=:\s]+({FLOAT_PATTERN})",
        "HOMAC": rf"HOMAC[=:\s]+({FLOAT_PATTERN})",
        "HOMER": rf"HOMER[=:\s]+({FLOAT_PATTERN})",
        "Bird": rf"Bird.*?index[=:\s]+({FLOAT_PATTERN})",
        "EN_GEO": rf"EN[_\s]*GEO[=:\s]+({FLOAT_PATTERN})",
        "EN_BLA": rf"EN[_\s]*BLA[=:\s]+({FLOAT_PATTERN})",
    }

    for key, pat in patterns.items():
        if match := re.search(pat, stdout, re.IGNORECASE):
            setattr(result, key, float(match[1]))

    return result

parse_nics_scan(stdout) staticmethod

Extract NICS scan profile data.

Source code in src/pymultiwfn/analysis/parsers.py
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
@staticmethod
def parse_nics_scan(stdout: str) -> NICSScan:
    """Extract NICS scan profile data."""
    distances: list[float] = []
    values: list[float] = []
    pattern = rf"^\s*({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s*$"
    in_scan = False
    for line in stdout.split("\n"):
        if "nics" in line.lower() and "scan" in line.lower():
            in_scan = True
            continue
        if in_scan and (match := re.match(pattern, line)):
            distances.append(float(match[1]))
            values.append(float(match[2]))
    return NICSScan(distances=distances, values=values)

AtomListParser

Bases: OutputParser

Parser for atom list and HOMO-LUMO gap output.

Source code in src/pymultiwfn/analysis/parsers.py
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
class AtomListParser(OutputParser):
    """Parser for atom list and HOMO-LUMO gap output."""

    @classmethod
    def parse_for_result(
        cls,
        analysis: Menu,
        stdout: str,
    ) -> list[ParsedMultiwfnResult]:
        return cls._collect(stdout, [cls.parse_atoms, cls.parse_homo_lumo_gap])

    @staticmethod
    def parse_atoms(stdout: str) -> list[AtomInfo]:
        """Extract atom list entries."""
        pattern = (
            rf"^\s*(\d+)\s*\(([A-Za-z]+)\s*\)\s*-->\s*Charge:\s*({FLOAT_PATTERN})"
            rf"\s+x,y,z\(Bohr\):\s*({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
        )
        return [
            AtomInfo(
                atom_id=int(match[1]),
                element=match[2],
                nuclear_charge=float(match[3]),
                x_bohr=float(match[4]),
                y_bohr=float(match[5]),
                z_bohr=float(match[6]),
            )
            for match in re.finditer(pattern, stdout, re.MULTILINE)
        ]

    @staticmethod
    def parse_homo_lumo_gap(stdout: str) -> HOMOLUMOGap | None:
        """Extract HOMO, LUMO, and gap information."""
        homo_pattern = (
            rf"Orbital\s+(\d+)\s+is\s+HOMO.*?energy:\s*({FLOAT_PATTERN})\s*a\.u\.\s+"
            rf"({FLOAT_PATTERN})\s*eV"
        )
        lumo_pattern = (
            rf"Orbital\s+(\d+)\s+is\s+LUMO.*?energy:\s*({FLOAT_PATTERN})\s*a\.u\.\s+"
            rf"({FLOAT_PATTERN})\s*eV"
        )
        gap_pattern = (
            rf"HOMO-LUMO\s+gap:\s*({FLOAT_PATTERN})\s*a\.u\.\s+"
            rf"({FLOAT_PATTERN})\s*eV\s+({FLOAT_PATTERN})\s*kJ/mol"
        )

        homo = re.search(homo_pattern, stdout)
        lumo = re.search(lumo_pattern, stdout)
        gap = re.search(gap_pattern, stdout)

        if homo and lumo and gap:
            return HOMOLUMOGap(
                homo_index=int(homo[1]),
                homo_energy_au=float(homo[2]),
                homo_energy_eV=float(homo[3]),
                lumo_index=int(lumo[1]),
                lumo_energy_au=float(lumo[2]),
                lumo_energy_eV=float(lumo[3]),
                gap_au=float(gap[1]),
                gap_eV=float(gap[2]),
                gap_kJ_mol=float(gap[3]),
            )
        return None

parse_atoms(stdout) staticmethod

Extract atom list entries.

Source code in src/pymultiwfn/analysis/parsers.py
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
@staticmethod
def parse_atoms(stdout: str) -> list[AtomInfo]:
    """Extract atom list entries."""
    pattern = (
        rf"^\s*(\d+)\s*\(([A-Za-z]+)\s*\)\s*-->\s*Charge:\s*({FLOAT_PATTERN})"
        rf"\s+x,y,z\(Bohr\):\s*({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
    )
    return [
        AtomInfo(
            atom_id=int(match[1]),
            element=match[2],
            nuclear_charge=float(match[3]),
            x_bohr=float(match[4]),
            y_bohr=float(match[5]),
            z_bohr=float(match[6]),
        )
        for match in re.finditer(pattern, stdout, re.MULTILINE)
    ]

parse_homo_lumo_gap(stdout) staticmethod

Extract HOMO, LUMO, and gap information.

Source code in src/pymultiwfn/analysis/parsers.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
@staticmethod
def parse_homo_lumo_gap(stdout: str) -> HOMOLUMOGap | None:
    """Extract HOMO, LUMO, and gap information."""
    homo_pattern = (
        rf"Orbital\s+(\d+)\s+is\s+HOMO.*?energy:\s*({FLOAT_PATTERN})\s*a\.u\.\s+"
        rf"({FLOAT_PATTERN})\s*eV"
    )
    lumo_pattern = (
        rf"Orbital\s+(\d+)\s+is\s+LUMO.*?energy:\s*({FLOAT_PATTERN})\s*a\.u\.\s+"
        rf"({FLOAT_PATTERN})\s*eV"
    )
    gap_pattern = (
        rf"HOMO-LUMO\s+gap:\s*({FLOAT_PATTERN})\s*a\.u\.\s+"
        rf"({FLOAT_PATTERN})\s*eV\s+({FLOAT_PATTERN})\s*kJ/mol"
    )

    homo = re.search(homo_pattern, stdout)
    lumo = re.search(lumo_pattern, stdout)
    gap = re.search(gap_pattern, stdout)

    if homo and lumo and gap:
        return HOMOLUMOGap(
            homo_index=int(homo[1]),
            homo_energy_au=float(homo[2]),
            homo_energy_eV=float(homo[3]),
            lumo_index=int(lumo[1]),
            lumo_energy_au=float(lumo[2]),
            lumo_energy_eV=float(lumo[3]),
            gap_au=float(gap[1]),
            gap_eV=float(gap[2]),
            gap_kJ_mol=float(gap[3]),
        )
    return None

BasinParser

Bases: OutputParser

Parser for basin analysis output.

Source code in src/pymultiwfn/analysis/parsers.py
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
class BasinParser(OutputParser):
    """Parser for basin analysis output."""

    @classmethod
    def parse_for_result(
        cls,
        analysis: Menu,
        stdout: str,
    ) -> list[ParsedMultiwfnResult]:
        results: list[ParsedMultiwfnResult] = []
        results.extend(cls.parse(stdout))
        results.extend(cls.parse_charges(stdout))
        return results

    @staticmethod
    def parse(stdout: str) -> list[Basin]:
        """Extract basin integration results."""
        basins: list[Basin] = []

        pattern = (
            rf"Basin\s+(\d+).*?(?:attractor.*?atom\s+(\d+)\s*\(([^)]+)\))?"
            rf".*?population[=:\s]+({FLOAT_PATTERN})"
        )
        for match in re.finditer(pattern, stdout, re.IGNORECASE):
            basin = Basin(
                basin_id=int(match[1]),
                population=float(match[4]),
            )
            if match[2]:
                basin.attractor_atom = int(match[2])
                basin.attractor_element = match[3].strip()
            basins.append(basin)

        if not basins:
            simple = rf"^\s*(\d+)\s+([A-Za-z]+)\s+({FLOAT_PATTERN})"
            in_basin = False
            for line in stdout.split("\n"):
                if "basin" in line.lower() and (
                    "population" in line.lower() or "integral" in line.lower()
                ):
                    in_basin = True
                    continue
                if in_basin and (m := re.match(simple, line)):
                    basins.append(
                        Basin(
                            basin_id=int(m[1]),
                            population=float(m[3]),
                            attractor_element=m[2],
                        )
                    )

        return basins

    @staticmethod
    def parse_charges(stdout: str) -> list[Charge]:
        """Extract AIM/Bader charges from basin analysis."""
        pattern = (
            rf"(?:AIM|Bader)\s+charge.*?atom\s+(\d+).*?:\s+({FLOAT_PATTERN})"
        )
        return [
            Charge(atom_id=int(match[1]), charge=float(match[2]))
            for match in re.finditer(pattern, stdout, re.IGNORECASE)
        ]

parse(stdout) staticmethod

Extract basin integration results.

Source code in src/pymultiwfn/analysis/parsers.py
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
@staticmethod
def parse(stdout: str) -> list[Basin]:
    """Extract basin integration results."""
    basins: list[Basin] = []

    pattern = (
        rf"Basin\s+(\d+).*?(?:attractor.*?atom\s+(\d+)\s*\(([^)]+)\))?"
        rf".*?population[=:\s]+({FLOAT_PATTERN})"
    )
    for match in re.finditer(pattern, stdout, re.IGNORECASE):
        basin = Basin(
            basin_id=int(match[1]),
            population=float(match[4]),
        )
        if match[2]:
            basin.attractor_atom = int(match[2])
            basin.attractor_element = match[3].strip()
        basins.append(basin)

    if not basins:
        simple = rf"^\s*(\d+)\s+([A-Za-z]+)\s+({FLOAT_PATTERN})"
        in_basin = False
        for line in stdout.split("\n"):
            if "basin" in line.lower() and (
                "population" in line.lower() or "integral" in line.lower()
            ):
                in_basin = True
                continue
            if in_basin and (m := re.match(simple, line)):
                basins.append(
                    Basin(
                        basin_id=int(m[1]),
                        population=float(m[3]),
                        attractor_element=m[2],
                    )
                )

    return basins

parse_charges(stdout) staticmethod

Extract AIM/Bader charges from basin analysis.

Source code in src/pymultiwfn/analysis/parsers.py
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
@staticmethod
def parse_charges(stdout: str) -> list[Charge]:
    """Extract AIM/Bader charges from basin analysis."""
    pattern = (
        rf"(?:AIM|Bader)\s+charge.*?atom\s+(\d+).*?:\s+({FLOAT_PATTERN})"
    )
    return [
        Charge(atom_id=int(match[1]), charge=float(match[2]))
        for match in re.finditer(pattern, stdout, re.IGNORECASE)
    ]

BondOrderParser

Bases: OutputParser

Parser for bond orders (Menu 9).

Each bond order block is stored as a BondOrderSet with a standardized method name so multiple methods coexist without overwriting.

Source code in src/pymultiwfn/analysis/parsers.py
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
class BondOrderParser(OutputParser):
    """Parser for bond orders (Menu 9).

    Each bond order block is stored as a ``BondOrderSet`` with a
    standardized ``method`` name so multiple methods coexist
    without overwriting.
    """

    @classmethod
    def parse_for_result(
        cls,
        analysis: Menu,
        stdout: str,
    ) -> list[ParsedMultiwfnResult]:
        method = _BOND_ORDER_METHOD.get(analysis, "unknown")

        case_map: dict[Menu, list] = {
            Menu.MULTICENTER_BOND_ORDER: [cls.parse_multicenter],
            Menu.MULTICENTER_BOND_ORDER_NAO: [cls.parse_multicenter],
            Menu.MULLIKEN_BOND_ORDER_DECOMPOSE: [cls.parse_decomposition],
            Menu.WIBERG_DECOMPOSITION: [cls.parse_decomposition],
            Menu.IBSI_ANALYSIS: [
                lambda s: cls.parse_ibsi(s),
                lambda s: cls.parse_bond_order_sets(s, method),
            ],
        }
        default = [
            lambda s: cls.parse_bond_order_sets(s, method),
            cls.parse_valence,
        ]
        parsers = case_map.get(analysis, default)
        return cls._collect(stdout, parsers)

    # ── Bond order sets ──────────────────────────────────────────────

    @staticmethod
    def parse_bond_order_sets(
        stdout: str,
        method: str,
    ) -> list[BondOrderSet]:
        """Extract all bond order blocks, each as a BondOrderSet.

        Handles both formats:
        - "#  N:  atom1(X)  atom2(X)  value"
        - "atom1(X)  atom2(X)  ..."  (IBSI-style, but the bond order
          part is handled here for the "total bond order" blocks)

        Multiple blocks (e.g. different thresholds, or "The total
        bond order" after individual ones) each get their own set.
        """
        sets: list[BondOrderSet] = []

        # Threshold header:
        # "Bond orders with absolute value >=  0.050000"
        # "The total bond order >=  0.050000"
        threshold_pat = re.compile(
            rf"(?:Bond orders|bond order|total bond order)"
            rf".*?>=?\s+({FLOAT_PATTERN})",
            re.I,
        )

        # Bond order line:
        # "#    1:         1(C )    2(C )    1.45268106"
        # or without leading #:
        # "#    1:         1(C )    2(C )    1.45268106"
        numbered_pat = re.compile(
            rf"#\s*(\d+):\s+(\d+)\s*\([^)]+\)\s+(\d+)\s*\([^)]+\)\s+"
            rf"({FLOAT_PATTERN})"
        )

        current_threshold: float | None = None
        current_bonds: list[BondOrder] = []
        current_label = method

        def _flush() -> None:
            nonlocal current_bonds, current_threshold, current_label
            if current_bonds:
                sets.append(
                    BondOrderSet(
                        method=current_label,
                        threshold=current_threshold,
                        bond_orders=list(current_bonds),
                    )
                )
            current_bonds = []
            current_threshold = None

        for line in stdout.split("\n"):
            # New threshold header starts a new set
            if match := threshold_pat.search(line):
                _flush()
                current_threshold = float(match[1])
                # Detect if this is "total bond order" vs regular
                if "total bond order" in line.lower():
                    current_label = f"{method}_total"
                else:
                    current_label = method
                continue

            # Numbered bond order line
            if match := numbered_pat.search(line):
                atom1 = int(match[2])
                atom2 = int(match[3])
                bo = float(match[4])
                if atom1 > atom2:
                    atom1, atom2 = atom2, atom1
                current_bonds.append(
                    BondOrder(
                        atom1_id=atom1,
                        atom2_id=atom2,
                        bond_order=bo,
                    )
                )
                continue

        _flush()
        return sets

    # ── Valences ─────────────────────────────────────────────────────

    @staticmethod
    def parse_valence(stdout: str) -> list[Valence]:
        """Extract total valence and free valence for each atom.

        Handles the two-column format:
        "Atom     1(C ) :    3.94042232    0.00000000"
        where first value is total valence and second is free valence.

        Also handles the single-value format:
        "Total valence of atom  1(C ): 3.940"
        "Free valence of atom  1(C ): 0.000"
        """
        valences: list[Valence] = []

        # Two-column format (Mayer style)
        two_col_pat = re.compile(
            rf"Atom\s+(\d+)\s*\([^)]+\)\s*:\s+"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
        )
        in_valence_section = False
        for line in stdout.split("\n"):
            if "valences" in line.lower() and (
                "total" in line.lower() or "free" in line.lower()
            ):
                in_valence_section = True
                continue
            if in_valence_section:
                if match := two_col_pat.search(line):
                    atom_id = int(match[1])
                    valences.append(
                        Valence(
                            atom_id=atom_id,
                            type="total_valence",
                            valence=float(match[2]),
                        )
                    )
                    valences.append(
                        Valence(
                            atom_id=atom_id,
                            type="free_valence",
                            valence=float(match[3]),
                        )
                    )
                    continue
                # End of section if we hit a non-matching non-blank line
                if line.strip() and not two_col_pat.search(line):
                    in_valence_section = False

        if valences:
            return valences

        # Single-value format (fallback)
        total_pattern = (
            rf"Total valence of atom\s+(\d+)\s*\([^)]+\)\s*:\s+"
            rf"({FLOAT_PATTERN})"
        )
        free_pattern = (
            rf"Free valence of atom\s+(\d+)\s*\([^)]+\)\s*:\s+"
            rf"({FLOAT_PATTERN})"
        )

        valences.extend(
            Valence(
                atom_id=int(match[1]),
                type="total_valence",
                valence=float(match[2]),
            )
            for match in re.finditer(total_pattern, stdout)
        )
        valences.extend(
            Valence(
                atom_id=int(match[1]),
                type="free_valence",
                valence=float(match[2]),
            )
            for match in re.finditer(free_pattern, stdout)
        )
        return valences

    # ── IBSI analysis ────────────────────────────────────────────────

    @staticmethod
    def parse_ibsi(stdout: str) -> IBSIAnalysis | None:
        """Extract IBSI analysis entries.

        Format:
        "    1(C )    2(C )  Dist:  1.3950   Int(dg_pair): 0.87601   IBSI: 0.79442"
        """  # noqa: E501
        pattern = re.compile(
            rf"(\d+)\s*\([^)]+\)\s+(\d+)\s*\([^)]+\)\s+"
            rf"Dist:\s+({FLOAT_PATTERN})\s+"
            rf"Int\(dg_pair\):\s+({FLOAT_PATTERN})\s+"
            rf"IBSI:\s+({FLOAT_PATTERN})"
        )

        entries: list[IBSIEntry] = []
        for match in re.finditer(pattern, stdout):
            atom1 = int(match[1])
            atom2 = int(match[2])
            if atom1 > atom2:
                atom1, atom2 = atom2, atom1
            entries.append(
                IBSIEntry(
                    atom1_id=atom1,
                    atom2_id=atom2,
                    distance=float(match[3]),
                    int_dg_pair=float(match[4]),
                    ibsi=float(match[5]),
                )
            )

        if entries:
            return IBSIAnalysis(entries=entries)
        return None

    # ── Multicenter bond orders ──────────────────────────────────────

    @staticmethod
    def parse_multicenter(stdout: str) -> list[MultiCenterBondOrder]:
        """Extract multicenter bond order results."""
        results: list[MultiCenterBondOrder] = []
        pattern = (
            rf"Multi-center bond order of atoms\s+([\d\s]+):\s+"
            rf"({FLOAT_PATTERN})"
        )
        for match in re.finditer(pattern, stdout, re.IGNORECASE):
            atoms = [int(x) for x in match[1].split()]
            results.append(
                MultiCenterBondOrder(
                    atom_ids=atoms, bond_order=float(match[2])
                )
            )
        return results

    # ── Per-orbital decomposition ────────────────────────────────────

    @staticmethod
    def parse_decomposition(stdout: str) -> list[BondOrderDecomposition]:
        """Extract per-orbital bond order decomposition."""
        pattern = rf"Orbital\s+(\d+)\s*:\s+({FLOAT_PATTERN})"
        return [
            BondOrderDecomposition(
                orbital_id=int(match[1]),
                contribution=float(match[2]),
            )
            for match in re.finditer(pattern, stdout)
        ]

parse_bond_order_sets(stdout, method) staticmethod

Extract all bond order blocks, each as a BondOrderSet.

Handles both formats: - "# N: atom1(X) atom2(X) value" - "atom1(X) atom2(X) ..." (IBSI-style, but the bond order part is handled here for the "total bond order" blocks)

Multiple blocks (e.g. different thresholds, or "The total bond order" after individual ones) each get their own set.

Source code in src/pymultiwfn/analysis/parsers.py
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
@staticmethod
def parse_bond_order_sets(
    stdout: str,
    method: str,
) -> list[BondOrderSet]:
    """Extract all bond order blocks, each as a BondOrderSet.

    Handles both formats:
    - "#  N:  atom1(X)  atom2(X)  value"
    - "atom1(X)  atom2(X)  ..."  (IBSI-style, but the bond order
      part is handled here for the "total bond order" blocks)

    Multiple blocks (e.g. different thresholds, or "The total
    bond order" after individual ones) each get their own set.
    """
    sets: list[BondOrderSet] = []

    # Threshold header:
    # "Bond orders with absolute value >=  0.050000"
    # "The total bond order >=  0.050000"
    threshold_pat = re.compile(
        rf"(?:Bond orders|bond order|total bond order)"
        rf".*?>=?\s+({FLOAT_PATTERN})",
        re.I,
    )

    # Bond order line:
    # "#    1:         1(C )    2(C )    1.45268106"
    # or without leading #:
    # "#    1:         1(C )    2(C )    1.45268106"
    numbered_pat = re.compile(
        rf"#\s*(\d+):\s+(\d+)\s*\([^)]+\)\s+(\d+)\s*\([^)]+\)\s+"
        rf"({FLOAT_PATTERN})"
    )

    current_threshold: float | None = None
    current_bonds: list[BondOrder] = []
    current_label = method

    def _flush() -> None:
        nonlocal current_bonds, current_threshold, current_label
        if current_bonds:
            sets.append(
                BondOrderSet(
                    method=current_label,
                    threshold=current_threshold,
                    bond_orders=list(current_bonds),
                )
            )
        current_bonds = []
        current_threshold = None

    for line in stdout.split("\n"):
        # New threshold header starts a new set
        if match := threshold_pat.search(line):
            _flush()
            current_threshold = float(match[1])
            # Detect if this is "total bond order" vs regular
            if "total bond order" in line.lower():
                current_label = f"{method}_total"
            else:
                current_label = method
            continue

        # Numbered bond order line
        if match := numbered_pat.search(line):
            atom1 = int(match[2])
            atom2 = int(match[3])
            bo = float(match[4])
            if atom1 > atom2:
                atom1, atom2 = atom2, atom1
            current_bonds.append(
                BondOrder(
                    atom1_id=atom1,
                    atom2_id=atom2,
                    bond_order=bo,
                )
            )
            continue

    _flush()
    return sets

parse_decomposition(stdout) staticmethod

Extract per-orbital bond order decomposition.

Source code in src/pymultiwfn/analysis/parsers.py
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
@staticmethod
def parse_decomposition(stdout: str) -> list[BondOrderDecomposition]:
    """Extract per-orbital bond order decomposition."""
    pattern = rf"Orbital\s+(\d+)\s*:\s+({FLOAT_PATTERN})"
    return [
        BondOrderDecomposition(
            orbital_id=int(match[1]),
            contribution=float(match[2]),
        )
        for match in re.finditer(pattern, stdout)
    ]

parse_ibsi(stdout) staticmethod

Extract IBSI analysis entries.

Format: " 1(C ) 2(C ) Dist: 1.3950 Int(dg_pair): 0.87601 IBSI: 0.79442"

Source code in src/pymultiwfn/analysis/parsers.py
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
@staticmethod
def parse_ibsi(stdout: str) -> IBSIAnalysis | None:
    """Extract IBSI analysis entries.

    Format:
    "    1(C )    2(C )  Dist:  1.3950   Int(dg_pair): 0.87601   IBSI: 0.79442"
    """  # noqa: E501
    pattern = re.compile(
        rf"(\d+)\s*\([^)]+\)\s+(\d+)\s*\([^)]+\)\s+"
        rf"Dist:\s+({FLOAT_PATTERN})\s+"
        rf"Int\(dg_pair\):\s+({FLOAT_PATTERN})\s+"
        rf"IBSI:\s+({FLOAT_PATTERN})"
    )

    entries: list[IBSIEntry] = []
    for match in re.finditer(pattern, stdout):
        atom1 = int(match[1])
        atom2 = int(match[2])
        if atom1 > atom2:
            atom1, atom2 = atom2, atom1
        entries.append(
            IBSIEntry(
                atom1_id=atom1,
                atom2_id=atom2,
                distance=float(match[3]),
                int_dg_pair=float(match[4]),
                ibsi=float(match[5]),
            )
        )

    if entries:
        return IBSIAnalysis(entries=entries)
    return None

parse_multicenter(stdout) staticmethod

Extract multicenter bond order results.

Source code in src/pymultiwfn/analysis/parsers.py
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
@staticmethod
def parse_multicenter(stdout: str) -> list[MultiCenterBondOrder]:
    """Extract multicenter bond order results."""
    results: list[MultiCenterBondOrder] = []
    pattern = (
        rf"Multi-center bond order of atoms\s+([\d\s]+):\s+"
        rf"({FLOAT_PATTERN})"
    )
    for match in re.finditer(pattern, stdout, re.IGNORECASE):
        atoms = [int(x) for x in match[1].split()]
        results.append(
            MultiCenterBondOrder(
                atom_ids=atoms, bond_order=float(match[2])
            )
        )
    return results

parse_valence(stdout) staticmethod

Extract total valence and free valence for each atom.

Handles the two-column format: "Atom 1(C ) : 3.94042232 0.00000000" where first value is total valence and second is free valence.

Also handles the single-value format: "Total valence of atom 1(C ): 3.940" "Free valence of atom 1(C ): 0.000"

Source code in src/pymultiwfn/analysis/parsers.py
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
@staticmethod
def parse_valence(stdout: str) -> list[Valence]:
    """Extract total valence and free valence for each atom.

    Handles the two-column format:
    "Atom     1(C ) :    3.94042232    0.00000000"
    where first value is total valence and second is free valence.

    Also handles the single-value format:
    "Total valence of atom  1(C ): 3.940"
    "Free valence of atom  1(C ): 0.000"
    """
    valences: list[Valence] = []

    # Two-column format (Mayer style)
    two_col_pat = re.compile(
        rf"Atom\s+(\d+)\s*\([^)]+\)\s*:\s+"
        rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
    )
    in_valence_section = False
    for line in stdout.split("\n"):
        if "valences" in line.lower() and (
            "total" in line.lower() or "free" in line.lower()
        ):
            in_valence_section = True
            continue
        if in_valence_section:
            if match := two_col_pat.search(line):
                atom_id = int(match[1])
                valences.append(
                    Valence(
                        atom_id=atom_id,
                        type="total_valence",
                        valence=float(match[2]),
                    )
                )
                valences.append(
                    Valence(
                        atom_id=atom_id,
                        type="free_valence",
                        valence=float(match[3]),
                    )
                )
                continue
            # End of section if we hit a non-matching non-blank line
            if line.strip() and not two_col_pat.search(line):
                in_valence_section = False

    if valences:
        return valences

    # Single-value format (fallback)
    total_pattern = (
        rf"Total valence of atom\s+(\d+)\s*\([^)]+\)\s*:\s+"
        rf"({FLOAT_PATTERN})"
    )
    free_pattern = (
        rf"Free valence of atom\s+(\d+)\s*\([^)]+\)\s*:\s+"
        rf"({FLOAT_PATTERN})"
    )

    valences.extend(
        Valence(
            atom_id=int(match[1]),
            type="total_valence",
            valence=float(match[2]),
        )
        for match in re.finditer(total_pattern, stdout)
    )
    valences.extend(
        Valence(
            atom_id=int(match[1]),
            type="free_valence",
            valence=float(match[2]),
        )
        for match in re.finditer(free_pattern, stdout)
    )
    return valences

CDFTParser

Bases: OutputParser

Parser for conceptual DFT output (Menu 22).

Source code in src/pymultiwfn/analysis/parsers.py
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
class CDFTParser(OutputParser):
    """Parser for conceptual DFT output (Menu 22)."""

    @classmethod
    def parse_for_result(
        cls,
        analysis: Menu,
        stdout: str,
    ) -> list[ParsedMultiwfnResult]:
        results: list[ParsedMultiwfnResult] = []

        reactivity = cls.parse_reactivity(stdout)
        if reactivity is not None:
            results.append(reactivity)

        results.extend(cls.parse_condensed_fukui(stdout))
        results.extend(cls.parse_dual_descriptor(stdout))

        superdeloc = cls.parse_superdelocalizability(stdout)
        if superdeloc is not None:
            results.append(superdeloc)

        ow_fukui = cls.parse_orbital_weighted_fukui(stdout)
        if ow_fukui is not None:
            results.append(ow_fukui)

        results.extend(cls.parse_orbital_weight_decomposition(stdout))

        return results

    # ── Global reactivity indices ────────────────────────────────────

    @staticmethod
    def parse_reactivity(stdout: str) -> Reactivity | None:
        """Extract global reactivity indices."""
        r = Reactivity()
        found = False

        homo_pat = re.compile(
            rf"HOMO energy:\s+({FLOAT_PATTERN})\s+a\.u\.\s+"
            rf"({FLOAT_PATTERN})\s+eV"
        )
        lumo_pat = re.compile(
            rf"LUMO energy:\s+({FLOAT_PATTERN})\s+a\.u\.\s+"
            rf"({FLOAT_PATTERN})\s+eV"
        )
        mu_pat = re.compile(
            rf"Chemical potential:\s+({FLOAT_PATTERN})\s+a\.u\.\s+"
            rf"({FLOAT_PATTERN})\s+eV"
        )
        delta_pat = re.compile(
            rf"Delta parameter:\s+({FLOAT_PATTERN})\s+a\.u\.\s+"
            rf"({FLOAT_PATTERN})\s+eV"
        )
        hard_pat = re.compile(
            rf"(?:Chemical |Global )?[Hh]ardness:\s+"
            rf"({FLOAT_PATTERN})"
        )
        soft_pat = re.compile(
            rf"(?:Chemical |Global )?[Ss]oftness:\s+"
            rf"({FLOAT_PATTERN})"
        )
        electro_pat = re.compile(
            rf"[Ee]lectrophilicity.*?:\s+({FLOAT_PATTERN})"
        )
        nucleo_pat = re.compile(rf"[Nn]ucleophilicity.*?:\s+({FLOAT_PATTERN})")
        ip_pat = re.compile(
            rf"[Ii]onization potential.*?:\s+({FLOAT_PATTERN})"
        )
        ea_pat = re.compile(rf"[Ee]lectron affinity.*?:\s+({FLOAT_PATTERN})")

        if match := homo_pat.search(stdout):
            r.homo_energy_au = float(match[1])
            r.homo_energy_eV = float(match[2])
            found = True
        if match := lumo_pat.search(stdout):
            r.lumo_energy_au = float(match[1])
            r.lumo_energy_eV = float(match[2])
            found = True
        if match := mu_pat.search(stdout):
            r.chemical_potential = float(match[1])
            r.chemical_potential_eV = float(match[2])
            found = True
        if match := delta_pat.search(stdout):
            r.delta_parameter_au = float(match[1])
            r.delta_parameter_eV = float(match[2])
            found = True
        if match := hard_pat.search(stdout):
            r.hardness = float(match[1])
            found = True
        if match := soft_pat.search(stdout):
            r.softness = float(match[1])
            found = True
        if match := electro_pat.search(stdout):
            r.electrophilicity = float(match[1])
            found = True
        if match := nucleo_pat.search(stdout):
            r.nucleophilicity = float(match[1])
            found = True
        if match := ip_pat.search(stdout):
            r.ionization_potential = float(match[1])
            found = True
        if match := ea_pat.search(stdout):
            r.electron_affinity = float(match[1])
            found = True

        return r if found else None

    # ── Condensed Fukui ──────────────────────────────────────────────

    @staticmethod
    def parse_condensed_fukui(stdout: str) -> list[CondensedFukui]:
        """Extract condensed Fukui functions."""
        results: list[CondensedFukui] = []

        # Pattern for Fukui table rows
        # "     1(C )        0.14827        0.15436        0.15132"
        fukui_pat = re.compile(
            rf"^\s+(\d+)\s*\([A-Za-z]+\s*\)\s+"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+"
            rf"({FLOAT_PATTERN})\s*$"
        )

        in_fukui = False
        for line in stdout.split("\n"):
            if (
                re.search(r"Atom.*?f\+.*?f-.*?f0", line, re.I)
                and "OW" not in line
            ):
                in_fukui = True
                continue
            if in_fukui:
                if match := fukui_pat.match(line):
                    results.append(
                        CondensedFukui(
                            atom_id=int(match[1]),
                            fukui_plus=float(match[2]),
                            fukui_minus=float(match[3]),
                            fukui_zero=float(match[4]),
                        )
                    )
                    continue
                if line.strip() and not fukui_pat.match(line):
                    in_fukui = False

        return results

    # ── Dual descriptor ──────────────────────────────────────────────

    @staticmethod
    def parse_dual_descriptor(stdout: str) -> list[DualDescriptor]:
        """Extract dual descriptor values."""
        results: list[DualDescriptor] = []

        dd_pat = re.compile(
            rf"^\s+(\d+)\s*\([A-Za-z]+\s*\)\s+.*?"
            rf"({FLOAT_PATTERN})\s*$"
        )

        in_dd = False
        for line in stdout.split("\n"):
            if re.search(r"Atom.*?[Dd]ual\s+[Dd]escriptor", line):
                in_dd = True
                continue
            if in_dd:
                if match := dd_pat.match(line):
                    results.append(
                        DualDescriptor(
                            atom_id=int(match[1]),
                            value=float(match[2]),
                        )
                    )
                    continue
                if line.strip() and "Sum" not in line:
                    in_dd = False

        return results

    # ── Superdelocalizability ────────────────────────────────────────

    @staticmethod
    def parse_superdelocalizability(
        stdout: str,
    ) -> SuperdelocalizabilityResult | None:
        """Extract superdelocalizability analysis."""
        alpha_pat = re.compile(
            rf"alpha parameter:\s+({FLOAT_PATTERN})\s+Hartree"
        )
        entry_pat = re.compile(
            rf"^\s+(\d+)\s*\(([A-Za-z]+)\s*\)\s+"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
        )
        sum_dn_pat = re.compile(rf"Sum of D_N:\s+({FLOAT_PATTERN})")
        sum_de_pat = re.compile(rf"Sum of D_E:\s+({FLOAT_PATTERN})")
        sum_dn0_pat = re.compile(rf"Sum of D_N_0:\s+({FLOAT_PATTERN})")
        sum_de0_pat = re.compile(rf"Sum of D_E_0:\s+({FLOAT_PATTERN})")

        # Check if superdelocalizability output exists
        if "superdelocalizability" not in stdout.lower():
            return None

        result = SuperdelocalizabilityResult()

        if match := alpha_pat.search(stdout):
            result.alpha_parameter = float(match[1])

        in_table = False
        for line in stdout.split("\n"):
            if "Atom" in line and "D_N" in line and "D_E" in line:
                in_table = True
                continue
            if in_table:
                if match := entry_pat.match(line):
                    result.entries.append(
                        SuperdelocalizabilityEntry(
                            atom_id=int(match[1]),
                            atom_element=match[2].strip(),
                            d_n=float(match[3]),
                            d_e=float(match[4]),
                            d_n_0=float(match[5]),
                            d_e_0=float(match[6]),
                        )
                    )
                    continue
                if match := sum_dn_pat.search(line):
                    result.sum_d_n = float(match[1])
                    continue
                if match := sum_de_pat.search(line):
                    result.sum_d_e = float(match[1])
                    continue
                if match := sum_dn0_pat.search(line):
                    result.sum_d_n_0 = float(match[1])
                    continue
                if match := sum_de0_pat.search(line):
                    result.sum_d_e_0 = float(match[1])
                    in_table = False
                    continue

        if result.entries:
            return result
        return None

    # ── Orbital-weighted Fukui ───────────────────────────────────────

    @staticmethod
    def parse_orbital_weighted_fukui(
        stdout: str,
    ) -> OrbitalWeightedFukuiResult | None:
        """Extract orbital-weighted Fukui functions."""
        entry_pat = re.compile(
            rf"^\s+(\d+)\s*\(([A-Za-z]+)\s*\)\s+"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
        )
        sum_fplus_pat = re.compile(
            rf"Sum of orbital weighted f\+\s+({FLOAT_PATTERN})"
        )
        sum_fminus_pat = re.compile(
            rf"Sum of orbital weighted f-\s+({FLOAT_PATTERN})"
        )

        entries: list[OrbitalWeightedFukuiEntry] = []
        sum_fplus: float | None = None
        sum_fminus: float | None = None

        in_table = False
        for line in stdout.split("\n"):
            if "Atom" in line and "OW f+" in line:
                in_table = True
                continue
            if in_table:
                if match := entry_pat.match(line):
                    entries.append(
                        OrbitalWeightedFukuiEntry(
                            atom_id=int(match[1]),
                            atom_element=match[2].strip(),
                            ow_f_plus=float(match[3]),
                            ow_f_minus=float(match[4]),
                            ow_f_zero=float(match[5]),
                            ow_dd=float(match[6]),
                        )
                    )
                    continue
                if match := sum_fplus_pat.search(line):
                    sum_fplus = float(match[1])
                    continue
                if match := sum_fminus_pat.search(line):
                    sum_fminus = float(match[1])
                    in_table = False
                    continue

        if entries:
            return OrbitalWeightedFukuiResult(
                entries=entries,
                sum_ow_f_plus=sum_fplus,
                sum_ow_f_minus=sum_fminus,
            )
        return None

    # ── Orbital weight decomposition ─────────────────────────────────

    @staticmethod
    def parse_orbital_weight_decomposition(
        stdout: str,
    ) -> list[OrbitalWeightDecomposition]:
        """Extract orbital weight decompositions for f+ and f-."""
        results: list[OrbitalWeightDecomposition] = []

        # "10 Highest weights in orbital-weighted f+"
        header_pat = re.compile(
            r"Highest weights in orbital-weighted (f[+-])", re.I
        )
        # "Orbital    22 (LUMO  )   Weight:  48.16 %   E_diff:     3.410 eV"
        entry_pat = re.compile(
            rf"Orbital\s+(\d+)\s+\(([^)]+)\)\s+Weight:\s+"
            rf"({FLOAT_PATTERN})\s+%\s+E_diff:\s+({FLOAT_PATTERN})\s+eV"
        )
        # "Total weight of above listed orbitals: 100.00 %"
        total_pat = re.compile(
            rf"Total weight of above.*?:\s+({FLOAT_PATTERN})\s+%"
        )

        current_type: str | None = None
        current_entries: list[OrbitalWeightEntry] = []
        current_total: float | None = None

        def _flush() -> None:
            nonlocal current_entries, current_total, current_type
            if current_entries and current_type is not None:
                results.append(
                    OrbitalWeightDecomposition(
                        fukui_type=current_type,
                        entries=list(current_entries),
                        total_weight_pct=current_total,
                    )
                )
            current_entries = []
            current_total = None
            current_type = None

        for line in stdout.split("\n"):
            if match := header_pat.search(line):
                _flush()
                current_type = match[1]
                continue

            if current_type is not None:
                if match := entry_pat.search(line):
                    current_entries.append(
                        OrbitalWeightEntry(
                            orbital_id=int(match[1]),
                            orbital_label=match[2].strip(),
                            weight_pct=float(match[3]),
                            e_diff_eV=float(match[4]),
                        )
                    )
                    continue
                if match := total_pat.search(line):
                    current_total = float(match[1])
                    _flush()
                    continue

        _flush()
        return results

parse_condensed_fukui(stdout) staticmethod

Extract condensed Fukui functions.

Source code in src/pymultiwfn/analysis/parsers.py
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
@staticmethod
def parse_condensed_fukui(stdout: str) -> list[CondensedFukui]:
    """Extract condensed Fukui functions."""
    results: list[CondensedFukui] = []

    # Pattern for Fukui table rows
    # "     1(C )        0.14827        0.15436        0.15132"
    fukui_pat = re.compile(
        rf"^\s+(\d+)\s*\([A-Za-z]+\s*\)\s+"
        rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+"
        rf"({FLOAT_PATTERN})\s*$"
    )

    in_fukui = False
    for line in stdout.split("\n"):
        if (
            re.search(r"Atom.*?f\+.*?f-.*?f0", line, re.I)
            and "OW" not in line
        ):
            in_fukui = True
            continue
        if in_fukui:
            if match := fukui_pat.match(line):
                results.append(
                    CondensedFukui(
                        atom_id=int(match[1]),
                        fukui_plus=float(match[2]),
                        fukui_minus=float(match[3]),
                        fukui_zero=float(match[4]),
                    )
                )
                continue
            if line.strip() and not fukui_pat.match(line):
                in_fukui = False

    return results

parse_dual_descriptor(stdout) staticmethod

Extract dual descriptor values.

Source code in src/pymultiwfn/analysis/parsers.py
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
@staticmethod
def parse_dual_descriptor(stdout: str) -> list[DualDescriptor]:
    """Extract dual descriptor values."""
    results: list[DualDescriptor] = []

    dd_pat = re.compile(
        rf"^\s+(\d+)\s*\([A-Za-z]+\s*\)\s+.*?"
        rf"({FLOAT_PATTERN})\s*$"
    )

    in_dd = False
    for line in stdout.split("\n"):
        if re.search(r"Atom.*?[Dd]ual\s+[Dd]escriptor", line):
            in_dd = True
            continue
        if in_dd:
            if match := dd_pat.match(line):
                results.append(
                    DualDescriptor(
                        atom_id=int(match[1]),
                        value=float(match[2]),
                    )
                )
                continue
            if line.strip() and "Sum" not in line:
                in_dd = False

    return results

parse_orbital_weight_decomposition(stdout) staticmethod

Extract orbital weight decompositions for f+ and f-.

Source code in src/pymultiwfn/analysis/parsers.py
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
@staticmethod
def parse_orbital_weight_decomposition(
    stdout: str,
) -> list[OrbitalWeightDecomposition]:
    """Extract orbital weight decompositions for f+ and f-."""
    results: list[OrbitalWeightDecomposition] = []

    # "10 Highest weights in orbital-weighted f+"
    header_pat = re.compile(
        r"Highest weights in orbital-weighted (f[+-])", re.I
    )
    # "Orbital    22 (LUMO  )   Weight:  48.16 %   E_diff:     3.410 eV"
    entry_pat = re.compile(
        rf"Orbital\s+(\d+)\s+\(([^)]+)\)\s+Weight:\s+"
        rf"({FLOAT_PATTERN})\s+%\s+E_diff:\s+({FLOAT_PATTERN})\s+eV"
    )
    # "Total weight of above listed orbitals: 100.00 %"
    total_pat = re.compile(
        rf"Total weight of above.*?:\s+({FLOAT_PATTERN})\s+%"
    )

    current_type: str | None = None
    current_entries: list[OrbitalWeightEntry] = []
    current_total: float | None = None

    def _flush() -> None:
        nonlocal current_entries, current_total, current_type
        if current_entries and current_type is not None:
            results.append(
                OrbitalWeightDecomposition(
                    fukui_type=current_type,
                    entries=list(current_entries),
                    total_weight_pct=current_total,
                )
            )
        current_entries = []
        current_total = None
        current_type = None

    for line in stdout.split("\n"):
        if match := header_pat.search(line):
            _flush()
            current_type = match[1]
            continue

        if current_type is not None:
            if match := entry_pat.search(line):
                current_entries.append(
                    OrbitalWeightEntry(
                        orbital_id=int(match[1]),
                        orbital_label=match[2].strip(),
                        weight_pct=float(match[3]),
                        e_diff_eV=float(match[4]),
                    )
                )
                continue
            if match := total_pat.search(line):
                current_total = float(match[1])
                _flush()
                continue

    _flush()
    return results

parse_orbital_weighted_fukui(stdout) staticmethod

Extract orbital-weighted Fukui functions.

Source code in src/pymultiwfn/analysis/parsers.py
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
@staticmethod
def parse_orbital_weighted_fukui(
    stdout: str,
) -> OrbitalWeightedFukuiResult | None:
    """Extract orbital-weighted Fukui functions."""
    entry_pat = re.compile(
        rf"^\s+(\d+)\s*\(([A-Za-z]+)\s*\)\s+"
        rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+"
        rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
    )
    sum_fplus_pat = re.compile(
        rf"Sum of orbital weighted f\+\s+({FLOAT_PATTERN})"
    )
    sum_fminus_pat = re.compile(
        rf"Sum of orbital weighted f-\s+({FLOAT_PATTERN})"
    )

    entries: list[OrbitalWeightedFukuiEntry] = []
    sum_fplus: float | None = None
    sum_fminus: float | None = None

    in_table = False
    for line in stdout.split("\n"):
        if "Atom" in line and "OW f+" in line:
            in_table = True
            continue
        if in_table:
            if match := entry_pat.match(line):
                entries.append(
                    OrbitalWeightedFukuiEntry(
                        atom_id=int(match[1]),
                        atom_element=match[2].strip(),
                        ow_f_plus=float(match[3]),
                        ow_f_minus=float(match[4]),
                        ow_f_zero=float(match[5]),
                        ow_dd=float(match[6]),
                    )
                )
                continue
            if match := sum_fplus_pat.search(line):
                sum_fplus = float(match[1])
                continue
            if match := sum_fminus_pat.search(line):
                sum_fminus = float(match[1])
                in_table = False
                continue

    if entries:
        return OrbitalWeightedFukuiResult(
            entries=entries,
            sum_ow_f_plus=sum_fplus,
            sum_ow_f_minus=sum_fminus,
        )
    return None

parse_reactivity(stdout) staticmethod

Extract global reactivity indices.

Source code in src/pymultiwfn/analysis/parsers.py
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
@staticmethod
def parse_reactivity(stdout: str) -> Reactivity | None:
    """Extract global reactivity indices."""
    r = Reactivity()
    found = False

    homo_pat = re.compile(
        rf"HOMO energy:\s+({FLOAT_PATTERN})\s+a\.u\.\s+"
        rf"({FLOAT_PATTERN})\s+eV"
    )
    lumo_pat = re.compile(
        rf"LUMO energy:\s+({FLOAT_PATTERN})\s+a\.u\.\s+"
        rf"({FLOAT_PATTERN})\s+eV"
    )
    mu_pat = re.compile(
        rf"Chemical potential:\s+({FLOAT_PATTERN})\s+a\.u\.\s+"
        rf"({FLOAT_PATTERN})\s+eV"
    )
    delta_pat = re.compile(
        rf"Delta parameter:\s+({FLOAT_PATTERN})\s+a\.u\.\s+"
        rf"({FLOAT_PATTERN})\s+eV"
    )
    hard_pat = re.compile(
        rf"(?:Chemical |Global )?[Hh]ardness:\s+"
        rf"({FLOAT_PATTERN})"
    )
    soft_pat = re.compile(
        rf"(?:Chemical |Global )?[Ss]oftness:\s+"
        rf"({FLOAT_PATTERN})"
    )
    electro_pat = re.compile(
        rf"[Ee]lectrophilicity.*?:\s+({FLOAT_PATTERN})"
    )
    nucleo_pat = re.compile(rf"[Nn]ucleophilicity.*?:\s+({FLOAT_PATTERN})")
    ip_pat = re.compile(
        rf"[Ii]onization potential.*?:\s+({FLOAT_PATTERN})"
    )
    ea_pat = re.compile(rf"[Ee]lectron affinity.*?:\s+({FLOAT_PATTERN})")

    if match := homo_pat.search(stdout):
        r.homo_energy_au = float(match[1])
        r.homo_energy_eV = float(match[2])
        found = True
    if match := lumo_pat.search(stdout):
        r.lumo_energy_au = float(match[1])
        r.lumo_energy_eV = float(match[2])
        found = True
    if match := mu_pat.search(stdout):
        r.chemical_potential = float(match[1])
        r.chemical_potential_eV = float(match[2])
        found = True
    if match := delta_pat.search(stdout):
        r.delta_parameter_au = float(match[1])
        r.delta_parameter_eV = float(match[2])
        found = True
    if match := hard_pat.search(stdout):
        r.hardness = float(match[1])
        found = True
    if match := soft_pat.search(stdout):
        r.softness = float(match[1])
        found = True
    if match := electro_pat.search(stdout):
        r.electrophilicity = float(match[1])
        found = True
    if match := nucleo_pat.search(stdout):
        r.nucleophilicity = float(match[1])
        found = True
    if match := ip_pat.search(stdout):
        r.ionization_potential = float(match[1])
        found = True
    if match := ea_pat.search(stdout):
        r.electron_affinity = float(match[1])
        found = True

    return r if found else None

parse_superdelocalizability(stdout) staticmethod

Extract superdelocalizability analysis.

Source code in src/pymultiwfn/analysis/parsers.py
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
@staticmethod
def parse_superdelocalizability(
    stdout: str,
) -> SuperdelocalizabilityResult | None:
    """Extract superdelocalizability analysis."""
    alpha_pat = re.compile(
        rf"alpha parameter:\s+({FLOAT_PATTERN})\s+Hartree"
    )
    entry_pat = re.compile(
        rf"^\s+(\d+)\s*\(([A-Za-z]+)\s*\)\s+"
        rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+"
        rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
    )
    sum_dn_pat = re.compile(rf"Sum of D_N:\s+({FLOAT_PATTERN})")
    sum_de_pat = re.compile(rf"Sum of D_E:\s+({FLOAT_PATTERN})")
    sum_dn0_pat = re.compile(rf"Sum of D_N_0:\s+({FLOAT_PATTERN})")
    sum_de0_pat = re.compile(rf"Sum of D_E_0:\s+({FLOAT_PATTERN})")

    # Check if superdelocalizability output exists
    if "superdelocalizability" not in stdout.lower():
        return None

    result = SuperdelocalizabilityResult()

    if match := alpha_pat.search(stdout):
        result.alpha_parameter = float(match[1])

    in_table = False
    for line in stdout.split("\n"):
        if "Atom" in line and "D_N" in line and "D_E" in line:
            in_table = True
            continue
        if in_table:
            if match := entry_pat.match(line):
                result.entries.append(
                    SuperdelocalizabilityEntry(
                        atom_id=int(match[1]),
                        atom_element=match[2].strip(),
                        d_n=float(match[3]),
                        d_e=float(match[4]),
                        d_n_0=float(match[5]),
                        d_e_0=float(match[6]),
                    )
                )
                continue
            if match := sum_dn_pat.search(line):
                result.sum_d_n = float(match[1])
                continue
            if match := sum_de_pat.search(line):
                result.sum_d_e = float(match[1])
                continue
            if match := sum_dn0_pat.search(line):
                result.sum_d_n_0 = float(match[1])
                continue
            if match := sum_de0_pat.search(line):
                result.sum_d_e_0 = float(match[1])
                in_table = False
                continue

    if result.entries:
        return result
    return None

ChargeParser

Bases: OutputParser

Parser for atomic charges (Menu 7).

Each distinct charge block is stored as a ChargeSet with a standardized method name and optional stage, so users can filter by method unambiguously.

Source code in src/pymultiwfn/analysis/parsers.py
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
class ChargeParser(OutputParser):
    """Parser for atomic charges (Menu 7).

    Each distinct charge block is stored as a ``ChargeSet`` with a
    standardized ``method`` name and optional ``stage``, so users
    can filter by method unambiguously.
    """

    MENU_METHOD: dict[Menu, str] = {
        Menu.HIRSHFELD_CHARGE: "hirshfeld",
        Menu.VDD_POPULATION: "vdd",
        Menu.MULLIKEN_POPULATION: "mulliken",
        Menu.LOWDIN_POPULATION: "lowdin",
        Menu.SCPA_POPULATION: "scpa",
        Menu.STOUT_POLITZER_POPULATION: "stout_politzer",
        Menu.BICKELHAUPT_POPULATION: "bickelhaupt",
        Menu.BECKE_CHARGE: "becke",
        Menu.ADCH_CHARGE: "adch",
        Menu.CHELPG_CHARGE: "chelpg",
        Menu.MK_CHARGE: "mk",
        Menu.CM5_CHARGE: "cm5",
        Menu.EEM_CHARGE: "eem",
        Menu.RESP_CHARGE: "resp",
        Menu.GASTEIGER_CHARGE: "gasteiger",
        Menu.MBIS_CHARGE: "mbis",
    }
    _HEADER_METHOD: list[tuple[re.Pattern[str], str]] = []

    @classmethod
    def parse_for_result(
        cls,
        analysis: Menu,
        stdout: str,
    ) -> list[ParsedMultiwfnResult]:
        results: list[ParsedMultiwfnResult] = []
        base_method = cls.MENU_METHOD.get(analysis, "unknown")
        results.extend(cls.parse_charge_sets(stdout, base_method))
        if (dipole := cls.parse_dipole(stdout)) is not None:
            results.append(dipole)
        return results

    @classmethod
    def _detect_method_from_context(
        cls, context_lines: list[str]
    ) -> str | None:
        """Scan recent context lines to detect the charge method."""
        for line in reversed(context_lines):
            for pat, method in cls._HEADER_METHOD:
                if pat.search(line):
                    return method
        return None

    @classmethod
    def parse_charge_sets(
        cls,
        stdout: str,
        base_method: str = "unknown",
    ) -> list[ChargeSet]:
        """Extract all distinct charge blocks with method labels.

        Each block produces a separate ``ChargeSet`` with a
        standardized ``method`` and ``stage``.
        """
        sets: list[ChargeSet] = []

        # Track recent context for method detection
        context: list[str] = []
        current_method = base_method
        current_stage: str | None = None
        current_charges: list[Charge] = []
        current_total: float | None = None

        # ── Header patterns ──
        final_header = re.compile(r"Final atomic charges:", re.I)
        adc_header = re.compile(
            r"-+\s*(.*?(?:ADC|ADCH)\s+.*?charges)\s*-+", re.I
        )
        cm5_header = re.compile(r"-+\s*(.*?CM5\s+charges)\s*-+", re.I)
        resp_stage_pat = re.compile(
            r"\*+\s*(Stage\s+(\d+).*?RESP.*?)\s*$", re.I
        )
        center_header = re.compile(r"^\s*Center\s+Charge\s*$", re.I)
        atom_header = re.compile(r"^\s*Atom\s+Charge\s*$", re.I)
        pop_atoms_header = re.compile(r"Population of atoms:", re.I)

        # ── Charge line patterns ──
        # "Atom    1(C ):    -0.04351137"
        atom_colon_pat = re.compile(
            rf"Atom\s+(\d+)\s*\([A-Za-z]+\s*\)\s*:\s+({FLOAT_PATTERN})"
        )
        # "Atom:    1C   Corrected charge:   -0.041271"
        corrected_pat = re.compile(
            rf"Atom:\s+(\d+)[A-Za-z]+\s+Corrected\s+charge:\s+"
            rf"({FLOAT_PATTERN})",
            re.I,
        )
        # "Atom:    1C   CM5 charge:   -0.097209"
        cm5_pat = re.compile(
            rf"Atom:\s+(\d+)[A-Za-z]+\s+CM5\s+charge:\s+"
            rf"({FLOAT_PATTERN})",
            re.I,
        )
        # "     1(C )  -0.0912959843"
        center_pat = re.compile(
            rf"^\s+(\d+)\s*\([A-Za-z]+\s*\)\s+({FLOAT_PATTERN})\s*$"
        )
        # "Atom     1(C )  Population:  6.128  Net charge: -0.128"
        pop_charge_pat = re.compile(
            rf"Atom\s+(\d+)\s*\([A-Za-z]+\s*\)\s+Population:\s+"
            rf"{FLOAT_PATTERN}\s+(?:Atomic charge|Net charge):\s+"
            rf"({FLOAT_PATTERN})"
        )

        # ── Total patterns ──
        total_pat = re.compile(
            rf"(?:Total\s+(?:net\s+)?charge|Sum\s+of\s+charges|"
            rf"Total\s+charge)\s*:\s+({FLOAT_PATTERN})",
            re.I,
        )
        sum_pat = re.compile(
            rf"Summing up all.*?charges:\s+({FLOAT_PATTERN})", re.I
        )

        # State tracking
        in_center_block = False
        in_atom_block = False
        in_pop_atoms = False

        def _flush_current() -> None:
            nonlocal current_charges, current_total
            nonlocal current_method, current_stage
            if current_charges:
                sets.append(
                    ChargeSet(
                        method=current_method,
                        stage=current_stage,
                        charges=list(current_charges),
                        total_charge=current_total,
                    )
                )
            current_charges = []
            current_total = None
            current_stage = None

        for line in stdout.split("\n"):
            context.append(line)
            if len(context) > 20:
                context.pop(0)

            # ── Detect new section headers ──

            # ADC/ADCH header
            if match := adc_header.search(line):
                _flush_current()
                header_text = match[1].lower()
                if "adch" in header_text:
                    current_method = "adch"
                else:
                    detected = cls._detect_method_from_context(context[:-1])
                    if detected == "becke":
                        current_method = "becke"
                    else:
                        current_method = detected or base_method
                current_stage = "corrected"
                in_center_block = False
                in_atom_block = False
                in_pop_atoms = False
                continue

            # CM5 header
            if cm5_header.search(line):
                _flush_current()
                current_method = "cm5"
                current_stage = "raw"
                in_center_block = False
                in_atom_block = False
                in_pop_atoms = False
                continue

            # RESP stage header
            if match := resp_stage_pat.search(line):
                _flush_current()
                current_method = "resp"
                current_stage = f"stage_{match[2]}"
                in_center_block = False
                in_atom_block = False
                continue

            # "Final atomic charges:" header
            if final_header.search(line):
                _flush_current()
                detected = cls._detect_method_from_context(context[:-1])
                current_method = detected or base_method
                current_stage = "final"
                in_center_block = False
                in_atom_block = False
                in_pop_atoms = False
                continue

            # "Center  Charge" header (CHELPG/MK/RESP)
            if center_header.match(line):
                _flush_current()
                detected = cls._detect_method_from_context(context[:-1])
                current_method = detected or base_method
                current_stage = "esp_fit"
                in_center_block = True
                in_atom_block = False
                in_pop_atoms = False
                continue

            # "Atom  Charge" header (Gasteiger)
            if atom_header.match(line):
                _flush_current()
                detected = cls._detect_method_from_context(context[:-1])
                current_method = detected or base_method
                current_stage = "raw"
                in_atom_block = True
                in_center_block = False
                in_pop_atoms = False
                continue

            # "Population of atoms:" header
            if pop_atoms_header.search(line):
                _flush_current()
                current_method = base_method
                current_stage = "population"
                in_pop_atoms = True
                in_center_block = False
                in_atom_block = False
                continue

            # ── Parse charge lines ──

            # Center block format
            if in_center_block:
                if match := center_pat.match(line):
                    current_charges.append(
                        Charge(
                            atom_id=int(match[1]),
                            charge=float(match[2]),
                        )
                    )
                    continue
                if match := total_pat.search(line):
                    current_total = float(match[1])
                    in_center_block = False
                    continue
                if match := sum_pat.search(line):
                    current_total = float(match[1])
                    in_center_block = False
                    continue

            # Atom block format (Gasteiger)
            if in_atom_block:
                if match := center_pat.match(line):
                    current_charges.append(
                        Charge(
                            atom_id=int(match[1]),
                            charge=float(match[2]),
                        )
                    )
                    continue
                if match := total_pat.search(line):
                    current_total = float(match[1])
                    in_atom_block = False
                    continue

            # Population of atoms section
            if in_pop_atoms:
                if match := pop_charge_pat.search(line):
                    current_charges.append(
                        Charge(
                            atom_id=int(match[1]),
                            charge=float(match[2]),
                        )
                    )
                    continue
                if match := total_pat.search(line):
                    current_total = float(match[1])
                    in_pop_atoms = False
                    continue

            # ADC corrected charges
            if match := corrected_pat.search(line):
                current_charges.append(
                    Charge(
                        atom_id=int(match[1]),
                        charge=float(match[2]),
                    )
                )
                continue

            # CM5 charges
            if match := cm5_pat.search(line):
                current_charges.append(
                    Charge(
                        atom_id=int(match[1]),
                        charge=float(match[2]),
                    )
                )
                continue

            # "Atom N(X): charge" format (final charges)
            if match := atom_colon_pat.search(line):
                if not in_center_block and not in_atom_block:
                    current_charges.append(
                        Charge(
                            atom_id=int(match[1]),
                            charge=float(match[2]),
                        )
                    )
                continue

            # Totals outside blocks
            if match := total_pat.search(line):
                current_total = float(match[1])
                continue
            if match := sum_pat.search(line):
                current_total = float(match[1])
                continue

        _flush_current()
        return sets

    @staticmethod
    def parse_dipole(stdout: str) -> Dipole | None:
        """Extract molecular dipole moment from charge output."""
        pattern = (
            rf"Dipole moment.*?X=\s*({FLOAT_PATTERN})\s+"
            rf"Y=\s*({FLOAT_PATTERN})\s+Z=\s*({FLOAT_PATTERN})\s+"
            rf"Tot=\s*({FLOAT_PATTERN})"
        )
        if match := re.search(pattern, stdout, re.IGNORECASE):
            return Dipole(
                x=float(match[1]),
                y=float(match[2]),
                z=float(match[3]),
                total=float(match[4]),
            )
        return None

    @classmethod
    def parse_charges(cls, stdout: str) -> list[Charge]:
        """Backward-compatible flat charge parser."""
        sets = cls.parse_charge_sets(stdout, base_method="unknown")
        if not sets:
            return []
        return sets[-1].charges

parse_charge_sets(stdout, base_method='unknown') classmethod

Extract all distinct charge blocks with method labels.

Each block produces a separate ChargeSet with a standardized method and stage.

Source code in src/pymultiwfn/analysis/parsers.py
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
@classmethod
def parse_charge_sets(
    cls,
    stdout: str,
    base_method: str = "unknown",
) -> list[ChargeSet]:
    """Extract all distinct charge blocks with method labels.

    Each block produces a separate ``ChargeSet`` with a
    standardized ``method`` and ``stage``.
    """
    sets: list[ChargeSet] = []

    # Track recent context for method detection
    context: list[str] = []
    current_method = base_method
    current_stage: str | None = None
    current_charges: list[Charge] = []
    current_total: float | None = None

    # ── Header patterns ──
    final_header = re.compile(r"Final atomic charges:", re.I)
    adc_header = re.compile(
        r"-+\s*(.*?(?:ADC|ADCH)\s+.*?charges)\s*-+", re.I
    )
    cm5_header = re.compile(r"-+\s*(.*?CM5\s+charges)\s*-+", re.I)
    resp_stage_pat = re.compile(
        r"\*+\s*(Stage\s+(\d+).*?RESP.*?)\s*$", re.I
    )
    center_header = re.compile(r"^\s*Center\s+Charge\s*$", re.I)
    atom_header = re.compile(r"^\s*Atom\s+Charge\s*$", re.I)
    pop_atoms_header = re.compile(r"Population of atoms:", re.I)

    # ── Charge line patterns ──
    # "Atom    1(C ):    -0.04351137"
    atom_colon_pat = re.compile(
        rf"Atom\s+(\d+)\s*\([A-Za-z]+\s*\)\s*:\s+({FLOAT_PATTERN})"
    )
    # "Atom:    1C   Corrected charge:   -0.041271"
    corrected_pat = re.compile(
        rf"Atom:\s+(\d+)[A-Za-z]+\s+Corrected\s+charge:\s+"
        rf"({FLOAT_PATTERN})",
        re.I,
    )
    # "Atom:    1C   CM5 charge:   -0.097209"
    cm5_pat = re.compile(
        rf"Atom:\s+(\d+)[A-Za-z]+\s+CM5\s+charge:\s+"
        rf"({FLOAT_PATTERN})",
        re.I,
    )
    # "     1(C )  -0.0912959843"
    center_pat = re.compile(
        rf"^\s+(\d+)\s*\([A-Za-z]+\s*\)\s+({FLOAT_PATTERN})\s*$"
    )
    # "Atom     1(C )  Population:  6.128  Net charge: -0.128"
    pop_charge_pat = re.compile(
        rf"Atom\s+(\d+)\s*\([A-Za-z]+\s*\)\s+Population:\s+"
        rf"{FLOAT_PATTERN}\s+(?:Atomic charge|Net charge):\s+"
        rf"({FLOAT_PATTERN})"
    )

    # ── Total patterns ──
    total_pat = re.compile(
        rf"(?:Total\s+(?:net\s+)?charge|Sum\s+of\s+charges|"
        rf"Total\s+charge)\s*:\s+({FLOAT_PATTERN})",
        re.I,
    )
    sum_pat = re.compile(
        rf"Summing up all.*?charges:\s+({FLOAT_PATTERN})", re.I
    )

    # State tracking
    in_center_block = False
    in_atom_block = False
    in_pop_atoms = False

    def _flush_current() -> None:
        nonlocal current_charges, current_total
        nonlocal current_method, current_stage
        if current_charges:
            sets.append(
                ChargeSet(
                    method=current_method,
                    stage=current_stage,
                    charges=list(current_charges),
                    total_charge=current_total,
                )
            )
        current_charges = []
        current_total = None
        current_stage = None

    for line in stdout.split("\n"):
        context.append(line)
        if len(context) > 20:
            context.pop(0)

        # ── Detect new section headers ──

        # ADC/ADCH header
        if match := adc_header.search(line):
            _flush_current()
            header_text = match[1].lower()
            if "adch" in header_text:
                current_method = "adch"
            else:
                detected = cls._detect_method_from_context(context[:-1])
                if detected == "becke":
                    current_method = "becke"
                else:
                    current_method = detected or base_method
            current_stage = "corrected"
            in_center_block = False
            in_atom_block = False
            in_pop_atoms = False
            continue

        # CM5 header
        if cm5_header.search(line):
            _flush_current()
            current_method = "cm5"
            current_stage = "raw"
            in_center_block = False
            in_atom_block = False
            in_pop_atoms = False
            continue

        # RESP stage header
        if match := resp_stage_pat.search(line):
            _flush_current()
            current_method = "resp"
            current_stage = f"stage_{match[2]}"
            in_center_block = False
            in_atom_block = False
            continue

        # "Final atomic charges:" header
        if final_header.search(line):
            _flush_current()
            detected = cls._detect_method_from_context(context[:-1])
            current_method = detected or base_method
            current_stage = "final"
            in_center_block = False
            in_atom_block = False
            in_pop_atoms = False
            continue

        # "Center  Charge" header (CHELPG/MK/RESP)
        if center_header.match(line):
            _flush_current()
            detected = cls._detect_method_from_context(context[:-1])
            current_method = detected or base_method
            current_stage = "esp_fit"
            in_center_block = True
            in_atom_block = False
            in_pop_atoms = False
            continue

        # "Atom  Charge" header (Gasteiger)
        if atom_header.match(line):
            _flush_current()
            detected = cls._detect_method_from_context(context[:-1])
            current_method = detected or base_method
            current_stage = "raw"
            in_atom_block = True
            in_center_block = False
            in_pop_atoms = False
            continue

        # "Population of atoms:" header
        if pop_atoms_header.search(line):
            _flush_current()
            current_method = base_method
            current_stage = "population"
            in_pop_atoms = True
            in_center_block = False
            in_atom_block = False
            continue

        # ── Parse charge lines ──

        # Center block format
        if in_center_block:
            if match := center_pat.match(line):
                current_charges.append(
                    Charge(
                        atom_id=int(match[1]),
                        charge=float(match[2]),
                    )
                )
                continue
            if match := total_pat.search(line):
                current_total = float(match[1])
                in_center_block = False
                continue
            if match := sum_pat.search(line):
                current_total = float(match[1])
                in_center_block = False
                continue

        # Atom block format (Gasteiger)
        if in_atom_block:
            if match := center_pat.match(line):
                current_charges.append(
                    Charge(
                        atom_id=int(match[1]),
                        charge=float(match[2]),
                    )
                )
                continue
            if match := total_pat.search(line):
                current_total = float(match[1])
                in_atom_block = False
                continue

        # Population of atoms section
        if in_pop_atoms:
            if match := pop_charge_pat.search(line):
                current_charges.append(
                    Charge(
                        atom_id=int(match[1]),
                        charge=float(match[2]),
                    )
                )
                continue
            if match := total_pat.search(line):
                current_total = float(match[1])
                in_pop_atoms = False
                continue

        # ADC corrected charges
        if match := corrected_pat.search(line):
            current_charges.append(
                Charge(
                    atom_id=int(match[1]),
                    charge=float(match[2]),
                )
            )
            continue

        # CM5 charges
        if match := cm5_pat.search(line):
            current_charges.append(
                Charge(
                    atom_id=int(match[1]),
                    charge=float(match[2]),
                )
            )
            continue

        # "Atom N(X): charge" format (final charges)
        if match := atom_colon_pat.search(line):
            if not in_center_block and not in_atom_block:
                current_charges.append(
                    Charge(
                        atom_id=int(match[1]),
                        charge=float(match[2]),
                    )
                )
            continue

        # Totals outside blocks
        if match := total_pat.search(line):
            current_total = float(match[1])
            continue
        if match := sum_pat.search(line):
            current_total = float(match[1])
            continue

    _flush_current()
    return sets

parse_charges(stdout) classmethod

Backward-compatible flat charge parser.

Source code in src/pymultiwfn/analysis/parsers.py
1213
1214
1215
1216
1217
1218
1219
@classmethod
def parse_charges(cls, stdout: str) -> list[Charge]:
    """Backward-compatible flat charge parser."""
    sets = cls.parse_charge_sets(stdout, base_method="unknown")
    if not sets:
        return []
    return sets[-1].charges

parse_dipole(stdout) staticmethod

Extract molecular dipole moment from charge output.

Source code in src/pymultiwfn/analysis/parsers.py
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
@staticmethod
def parse_dipole(stdout: str) -> Dipole | None:
    """Extract molecular dipole moment from charge output."""
    pattern = (
        rf"Dipole moment.*?X=\s*({FLOAT_PATTERN})\s+"
        rf"Y=\s*({FLOAT_PATTERN})\s+Z=\s*({FLOAT_PATTERN})\s+"
        rf"Tot=\s*({FLOAT_PATTERN})"
    )
    if match := re.search(pattern, stdout, re.IGNORECASE):
        return Dipole(
            x=float(match[1]),
            y=float(match[2]),
            z=float(match[3]),
            total=float(match[4]),
        )
    return None

CriticalPointParser

Bases: OutputParser

Parser for critical point information from topology analysis.

Source code in src/pymultiwfn/analysis/parsers.py
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
class CriticalPointParser(OutputParser):
    """Parser for critical point information from topology analysis."""

    CP_TYPE_NAMES: dict[
        str, Literal["nuclear", "bond", "ring", "cage", "unknown"]
    ] = {
        "(3,-3)": "nuclear",
        "(3,-1)": "bond",
        "(3,+1)": "ring",
        "(3,+3)": "cage",
    }

    @classmethod
    def parse_for_result(
        cls,
        analysis: Menu,
        stdout: str,
    ) -> list[ParsedMultiwfnResult]:
        results: list[ParsedMultiwfnResult] = []
        results.extend(cls.parse(stdout))
        results.extend(cls.parse_topology_paths(stdout))
        results.extend(cls.parse_bond_paths(stdout))
        ph = cls.parse_poincare_hopf(stdout)
        if ph is not None:
            results.append(ph)
        return results

    @classmethod
    def parse(cls, stdout: str) -> list[CriticalPoint]:
        """Extract critical points from both short and long summaries.

        The long summary (from path generation) includes nucleus and
        bond labels.  The short summary (from initial search) does
        not.  If both are present the long summary takes precedence.
        """
        cps: list[CriticalPoint] = []

        # ── Long summary ──
        # "  1    0.000   -4.680   -0.000   (3,-3)   Nucleus:   10(H )"
        # " 13    0.000   -3.966   -0.000   (3,-1)   10(H ) --    4(C )"
        # " 19    0.000    0.000   -0.000   (3,+1)"
        long_pattern = (
            rf"^\s*(\d+)\s+"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+"
            rf"\((\d+),([+-]?\d+)\)"
            rf"(?:\s+Nucleus:\s*(\d+)\s*\(([A-Za-z]+)\s*\))?"
            rf"(?:\s+(\d+)\s*\([A-Za-z]+\s*\)\s*--\s*(\d+)\s*\([A-Za-z]+\s*\))?"
        )

        in_long_summary = False
        for line in stdout.split("\n"):
            if "Summary of found CPs" in line:
                in_long_summary = True
                cps.clear()
                continue
            if in_long_summary and (
                "number of critical points" in line.lower()
            ):
                in_long_summary = False
                continue

            if in_long_summary and (match := re.match(long_pattern, line)):
                cp_type_str = f"({match[5]},{match[6]})"
                cp = CriticalPoint(
                    index=int(match[1]),
                    x=float(match[2]),
                    y=float(match[3]),
                    z=float(match[4]),
                    type=cls.CP_TYPE_NAMES.get(cp_type_str, "unknown"),
                )
                if match[7]:
                    cp.nucleus_atom_id = int(match[7])
                    cp.nucleus_element = match[8].strip()
                if match[9]:
                    cp.bonded_atom1_id = int(match[9])
                    cp.bonded_atom2_id = int(match[10])
                cps.append(cp)

        if cps:
            return cps

        # ── Short summary (fallback) ──
        short_pattern = (
            rf"^\s*(\d+)\s+"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+"
            rf"\((\d+),([+-]?\d+)\)"
        )
        in_short_summary = False
        for line in stdout.split("\n"):
            if re.search(r"----\s*Summary\s*----", line):
                in_short_summary = True
                continue
            if in_short_summary and "Totally find" in line:
                in_short_summary = False
                continue

            if in_short_summary and (match := re.match(short_pattern, line)):
                cp_type_str = f"({match[5]},{match[6]})"
                cps.append(
                    CriticalPoint(
                        index=int(match[1]),
                        x=float(match[2]),
                        y=float(match[3]),
                        z=float(match[4]),
                        type=cls.CP_TYPE_NAMES.get(cp_type_str, "unknown"),
                    )
                )

        return cps

    @classmethod
    def parse_topology_paths(cls, stdout: str) -> list[TopologyPath]:
        """Extract topology gradient paths from path summary."""
        pattern = (
            rf"Path\s+(\d+),\s+CP:\s+(\d+)\s+\((\d+),([+-]?\d+)\)\s+"
            rf"-->\s+CP:\s+(\d+)\s+\((\d+),([+-]?\d+)\)\s+"
            rf"Length:\s+({FLOAT_PATTERN})"
        )
        return [
            TopologyPath(
                path_id=int(match[1]),
                bcp_index=int(match[2]),
                bcp_type=cls.CP_TYPE_NAMES.get(
                    f"({match[3]},{match[4]})", "unknown"
                ),
                target_cp_index=int(match[5]),
                target_cp_type=cls.CP_TYPE_NAMES.get(
                    f"({match[6]},{match[7]})", "unknown"
                ),
                length_bohr=float(match[8]),
            )
            for match in re.finditer(pattern, stdout)
        ]

    @staticmethod
    def parse_poincare_hopf(stdout: str) -> PoincareHopfCounts | None:
        """Extract Poincare-Hopf critical point counts."""
        count_pattern = (
            r"\(3,-3\):\s*(\d+).*?"
            r"\(3,-1\):\s*(\d+).*?"
            r"\(3,\+1\):\s*(\d+).*?"
            r"\(3,\+3\):\s*(\d+)"
        )
        if match := re.search(count_pattern, stdout):
            satisfied = bool(
                re.search(r"Poincare-Hopf relationship is satisfied", stdout)
            )
            return PoincareHopfCounts(
                nuclear=int(match[1]),
                bond=int(match[2]),
                ring=int(match[3]),
                cage=int(match[4]),
                satisfied=satisfied,
            )
        return None

    @staticmethod
    def parse_bond_paths(stdout: str) -> list[ParsedMultiwfnResult]:
        """Extract bond path information."""
        pattern = (
            rf"Bond path between atom\s+(\d+).*?and atom\s+(\d+).*?"
            rf"BCP\s+(\d+).*?length\s+({FLOAT_PATTERN})"
        )
        return [
            TopologyPath(
                path_id=int(match[3]),
                bcp_index=int(match[1]),
                bcp_type="unknown",
                target_cp_index=int(match[2]),
                target_cp_type="unknown",
                length_bohr=float(match[4]),
            )
            for match in re.finditer(pattern, stdout, re.IGNORECASE)
        ]

parse(stdout) classmethod

Extract critical points from both short and long summaries.

The long summary (from path generation) includes nucleus and bond labels. The short summary (from initial search) does not. If both are present the long summary takes precedence.

Source code in src/pymultiwfn/analysis/parsers.py
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
@classmethod
def parse(cls, stdout: str) -> list[CriticalPoint]:
    """Extract critical points from both short and long summaries.

    The long summary (from path generation) includes nucleus and
    bond labels.  The short summary (from initial search) does
    not.  If both are present the long summary takes precedence.
    """
    cps: list[CriticalPoint] = []

    # ── Long summary ──
    # "  1    0.000   -4.680   -0.000   (3,-3)   Nucleus:   10(H )"
    # " 13    0.000   -3.966   -0.000   (3,-1)   10(H ) --    4(C )"
    # " 19    0.000    0.000   -0.000   (3,+1)"
    long_pattern = (
        rf"^\s*(\d+)\s+"
        rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+"
        rf"\((\d+),([+-]?\d+)\)"
        rf"(?:\s+Nucleus:\s*(\d+)\s*\(([A-Za-z]+)\s*\))?"
        rf"(?:\s+(\d+)\s*\([A-Za-z]+\s*\)\s*--\s*(\d+)\s*\([A-Za-z]+\s*\))?"
    )

    in_long_summary = False
    for line in stdout.split("\n"):
        if "Summary of found CPs" in line:
            in_long_summary = True
            cps.clear()
            continue
        if in_long_summary and (
            "number of critical points" in line.lower()
        ):
            in_long_summary = False
            continue

        if in_long_summary and (match := re.match(long_pattern, line)):
            cp_type_str = f"({match[5]},{match[6]})"
            cp = CriticalPoint(
                index=int(match[1]),
                x=float(match[2]),
                y=float(match[3]),
                z=float(match[4]),
                type=cls.CP_TYPE_NAMES.get(cp_type_str, "unknown"),
            )
            if match[7]:
                cp.nucleus_atom_id = int(match[7])
                cp.nucleus_element = match[8].strip()
            if match[9]:
                cp.bonded_atom1_id = int(match[9])
                cp.bonded_atom2_id = int(match[10])
            cps.append(cp)

    if cps:
        return cps

    # ── Short summary (fallback) ──
    short_pattern = (
        rf"^\s*(\d+)\s+"
        rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+"
        rf"\((\d+),([+-]?\d+)\)"
    )
    in_short_summary = False
    for line in stdout.split("\n"):
        if re.search(r"----\s*Summary\s*----", line):
            in_short_summary = True
            continue
        if in_short_summary and "Totally find" in line:
            in_short_summary = False
            continue

        if in_short_summary and (match := re.match(short_pattern, line)):
            cp_type_str = f"({match[5]},{match[6]})"
            cps.append(
                CriticalPoint(
                    index=int(match[1]),
                    x=float(match[2]),
                    y=float(match[3]),
                    z=float(match[4]),
                    type=cls.CP_TYPE_NAMES.get(cp_type_str, "unknown"),
                )
            )

    return cps

parse_bond_paths(stdout) staticmethod

Extract bond path information.

Source code in src/pymultiwfn/analysis/parsers.py
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
@staticmethod
def parse_bond_paths(stdout: str) -> list[ParsedMultiwfnResult]:
    """Extract bond path information."""
    pattern = (
        rf"Bond path between atom\s+(\d+).*?and atom\s+(\d+).*?"
        rf"BCP\s+(\d+).*?length\s+({FLOAT_PATTERN})"
    )
    return [
        TopologyPath(
            path_id=int(match[3]),
            bcp_index=int(match[1]),
            bcp_type="unknown",
            target_cp_index=int(match[2]),
            target_cp_type="unknown",
            length_bohr=float(match[4]),
        )
        for match in re.finditer(pattern, stdout, re.IGNORECASE)
    ]

parse_poincare_hopf(stdout) staticmethod

Extract Poincare-Hopf critical point counts.

Source code in src/pymultiwfn/analysis/parsers.py
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
@staticmethod
def parse_poincare_hopf(stdout: str) -> PoincareHopfCounts | None:
    """Extract Poincare-Hopf critical point counts."""
    count_pattern = (
        r"\(3,-3\):\s*(\d+).*?"
        r"\(3,-1\):\s*(\d+).*?"
        r"\(3,\+1\):\s*(\d+).*?"
        r"\(3,\+3\):\s*(\d+)"
    )
    if match := re.search(count_pattern, stdout):
        satisfied = bool(
            re.search(r"Poincare-Hopf relationship is satisfied", stdout)
        )
        return PoincareHopfCounts(
            nuclear=int(match[1]),
            bond=int(match[2]),
            ring=int(match[3]),
            cage=int(match[4]),
            satisfied=satisfied,
        )
    return None

parse_topology_paths(stdout) classmethod

Extract topology gradient paths from path summary.

Source code in src/pymultiwfn/analysis/parsers.py
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
@classmethod
def parse_topology_paths(cls, stdout: str) -> list[TopologyPath]:
    """Extract topology gradient paths from path summary."""
    pattern = (
        rf"Path\s+(\d+),\s+CP:\s+(\d+)\s+\((\d+),([+-]?\d+)\)\s+"
        rf"-->\s+CP:\s+(\d+)\s+\((\d+),([+-]?\d+)\)\s+"
        rf"Length:\s+({FLOAT_PATTERN})"
    )
    return [
        TopologyPath(
            path_id=int(match[1]),
            bcp_index=int(match[2]),
            bcp_type=cls.CP_TYPE_NAMES.get(
                f"({match[3]},{match[4]})", "unknown"
            ),
            target_cp_index=int(match[5]),
            target_cp_type=cls.CP_TYPE_NAMES.get(
                f"({match[6]},{match[7]})", "unknown"
            ),
            length_bohr=float(match[8]),
        )
        for match in re.finditer(pattern, stdout)
    ]

CubeParser

Bases: OutputParser

Parser for cube generation and grid processing output.

Each cube export sequence in the stdout produces a separate Cube instance. The parser splits on cube file markers so that per-sequence grid metadata, statistics, and the output filename are kept together.

Source code in src/pymultiwfn/analysis/parsers.py
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
class CubeParser(OutputParser):
    """Parser for cube generation and grid processing output.

    Each cube export sequence in the stdout produces a separate
    ``Cube`` instance.  The parser splits on cube file markers so
    that per-sequence grid metadata, statistics, and the output
    filename are kept together.
    """

    @classmethod
    def parse_for_result(
        cls,
        analysis: Menu,
        stdout: str,
    ) -> list[ParsedMultiwfnResult]:
        return cls.parse(stdout)

    @classmethod
    def parse(cls, stdout: str) -> list[ParsedMultiwfnResult]:
        """Extract one ``Cube`` per exported cube file sequence."""
        # Split stdout into per-sequence chunks by cube file markers.
        file_pattern = r"(\S+\.cub[e]?)\s+in current folder"
        file_matches = list(re.finditer(file_pattern, stdout))

        if not file_matches:
            return []

        # Build chunk boundaries: each chunk ends at a file marker
        # and starts either at the beginning or after the previous
        # file marker.
        chunks: list[tuple[str, str]] = []
        for i, fm in enumerate(file_matches):
            start = file_matches[i - 1].end() if i > 0 else 0
            end = fm.end()
            chunks.append((stdout[start:end], fm[1]))

        results: list[ParsedMultiwfnResult] = []
        for chunk, file_name in chunks:
            results.append(cls._parse_chunk(chunk, file_name))

        return results

    @classmethod
    def _parse_chunk(cls, chunk: str, file_name: str) -> Cube:
        """Parse a single sequence chunk into a ``Cube``."""
        cube = Cube(file_name=file_name)

        # ── Origin ──
        origin_pat = (
            rf"Coordinate of origin.*?X,Y,Z\s+is\s+"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
        )
        if match := re.search(origin_pat, chunk):
            cube.origin_x = float(match[1])
            cube.origin_y = float(match[2])
            cube.origin_z = float(match[3])

        # ── End point ──
        end_pat = (
            rf"Coordinate of end point.*?X,Y,Z\s+is\s+"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
        )
        if match := re.search(end_pat, chunk):
            cube.end_x = float(match[1])
            cube.end_y = float(match[2])
            cube.end_z = float(match[3])

        # ── Spacing ──
        spacing_pat = (
            rf"Grid spacing.*?X,Y,Z\s+is\s+"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
        )
        if match := re.search(spacing_pat, chunk):
            cube.spacing_x = float(match[1])
            cube.spacing_y = float(match[2])
            cube.spacing_z = float(match[3])

        # ── Grid dimensions ──
        dim_pat = (
            r"Number of points.*?X,Y,Z\s+is\s+"
            r"(\d+)\s+(\d+)\s+(\d+)\s+Total:\s+(\d+)"
        )
        if match := re.search(dim_pat, chunk):
            cube.x_dim = int(match[1])
            cube.y_dim = int(match[2])
            cube.z_dim = int(match[3])
            cube.total_points = int(match[4])

        # ── Minimum ──
        min_pat = (
            rf"The minimum is\s+({FLOAT_PATTERN})\s+at\s+"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
        )
        if match := re.search(min_pat, chunk):
            cube.minimum = GridExtremum(
                value=float(match[1]),
                x_bohr=float(match[2]),
                y_bohr=float(match[3]),
                z_bohr=float(match[4]),
            )

        # ── Maximum ──
        max_pat = (
            rf"The maximum is\s+({FLOAT_PATTERN})\s+at\s+"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
        )
        if match := re.search(max_pat, chunk):
            cube.maximum = GridExtremum(
                value=float(match[1]),
                x_bohr=float(match[2]),
                y_bohr=float(match[3]),
                z_bohr=float(match[4]),
            )

        # ── Integrals ──
        total_pat = (
            rf"Summing up all value.*?multiply differential element:\s+"
            rf"({FLOAT_PATTERN})"
        )
        if match := re.search(total_pat, chunk, re.DOTALL):
            cube.integral_total = float(match[1])

        pos_pat = (
            rf"Summing up positive value.*?multiply differential element:\s+"
            rf"({FLOAT_PATTERN})"
        )
        if match := re.search(pos_pat, chunk, re.DOTALL):
            cube.integral_positive = float(match[1])

        neg_pat = (
            rf"Summing up negative value.*?multiply differential element:\s+"
            rf"({FLOAT_PATTERN})"
        )
        if match := re.search(neg_pat, chunk, re.DOTALL):
            cube.integral_negative = float(match[1])

        return cube

parse(stdout) classmethod

Extract one Cube per exported cube file sequence.

Source code in src/pymultiwfn/analysis/parsers.py
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
@classmethod
def parse(cls, stdout: str) -> list[ParsedMultiwfnResult]:
    """Extract one ``Cube`` per exported cube file sequence."""
    # Split stdout into per-sequence chunks by cube file markers.
    file_pattern = r"(\S+\.cub[e]?)\s+in current folder"
    file_matches = list(re.finditer(file_pattern, stdout))

    if not file_matches:
        return []

    # Build chunk boundaries: each chunk ends at a file marker
    # and starts either at the beginning or after the previous
    # file marker.
    chunks: list[tuple[str, str]] = []
    for i, fm in enumerate(file_matches):
        start = file_matches[i - 1].end() if i > 0 else 0
        end = fm.end()
        chunks.append((stdout[start:end], fm[1]))

    results: list[ParsedMultiwfnResult] = []
    for chunk, file_name in chunks:
        results.append(cls._parse_chunk(chunk, file_name))

    return results

DOSParser

Bases: OutputParser

Parser for density of states output.

Source code in src/pymultiwfn/analysis/parsers.py
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
class DOSParser(OutputParser):
    """Parser for density of states output."""

    @classmethod
    def parse_for_result(
        cls,
        analysis: Menu,
        stdout: str,
    ) -> list[ParsedMultiwfnResult]:
        results: list[ParsedMultiwfnResult] = []
        dos = cls.parse(stdout)
        if dos.energies_eV:
            results.append(dos)
        orb_energies = cls.parse_orbital_energies(stdout)
        results.extend(orb_energies)
        metadata = cls.parse_metadata(stdout)
        if metadata is not None:
            results.append(metadata)
        return results

    @staticmethod
    def parse(stdout: str) -> DensityOfStates:
        """Extract DOS curve data."""
        energies: list[float] = []
        dos_vals: list[float] = []
        pdos: dict[str, list[float]] = {}

        pattern2 = rf"^\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s*$"
        pattern_multi = rf"^\s+({FLOAT_PATTERN})((?:\s+{FLOAT_PATTERN})+)\s*$"

        in_data = False
        for line in stdout.split("\n"):
            if "TDOS" in line or "PDOS" in line or "OPDOS" in line:
                in_data = True
                continue
            if not in_data:
                continue

            if match := re.match(pattern_multi, line):
                energy = float(match[1])
                vals = [float(v) for v in match[2].split()]
                energies.append(energy)
                if vals:
                    dos_vals.append(vals[0])
                for k, v in enumerate(vals[1:], start=1):
                    key = f"pdos_{k}"
                    pdos.setdefault(key, []).append(v)
            elif match := re.match(pattern2, line):
                energies.append(float(match[1]))
                dos_vals.append(float(match[2]))

        return DensityOfStates(
            energies_eV=energies,
            dos=dos_vals,
            projected_dos=pdos if pdos else None,
        )

    @staticmethod
    def parse_orbital_energies(stdout: str) -> list[OrbitalEnergy]:
        """Extract orbital energies used in DOS."""
        pattern = rf"(\d+)\s+({FLOAT_PATTERN})\s+eV\s+Occ=\s*({FLOAT_PATTERN})"
        return [
            OrbitalEnergy(
                index=int(match[1]),
                energy_eV=float(match[2]),
                occupation=float(match[3]),
            )
            for match in re.finditer(pattern, stdout)
        ]

    @staticmethod
    def parse_metadata(stdout: str) -> DOSMetadata | None:
        """Extract TDOS center and HOMO level metadata."""
        tdos_center: float | None = None
        homo_level: float | None = None

        tdos_pat = re.compile(rf"Center of TDOS:\s+({FLOAT_PATTERN})\s*a\.u\.")
        homo_pat = re.compile(
            rf"vertical dash line corresponds to HOMO level at\s+"
            rf"({FLOAT_PATTERN})\s*a\.u\."
        )

        if match := tdos_pat.search(stdout):
            tdos_center = float(match[1])
        if match := homo_pat.search(stdout):
            homo_level = float(match[1])

        if tdos_center is not None or homo_level is not None:
            return DOSMetadata(
                tdos_center_au=tdos_center,
                homo_level_au=homo_level,
            )
        return None

parse(stdout) staticmethod

Extract DOS curve data.

Source code in src/pymultiwfn/analysis/parsers.py
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
@staticmethod
def parse(stdout: str) -> DensityOfStates:
    """Extract DOS curve data."""
    energies: list[float] = []
    dos_vals: list[float] = []
    pdos: dict[str, list[float]] = {}

    pattern2 = rf"^\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s*$"
    pattern_multi = rf"^\s+({FLOAT_PATTERN})((?:\s+{FLOAT_PATTERN})+)\s*$"

    in_data = False
    for line in stdout.split("\n"):
        if "TDOS" in line or "PDOS" in line or "OPDOS" in line:
            in_data = True
            continue
        if not in_data:
            continue

        if match := re.match(pattern_multi, line):
            energy = float(match[1])
            vals = [float(v) for v in match[2].split()]
            energies.append(energy)
            if vals:
                dos_vals.append(vals[0])
            for k, v in enumerate(vals[1:], start=1):
                key = f"pdos_{k}"
                pdos.setdefault(key, []).append(v)
        elif match := re.match(pattern2, line):
            energies.append(float(match[1]))
            dos_vals.append(float(match[2]))

    return DensityOfStates(
        energies_eV=energies,
        dos=dos_vals,
        projected_dos=pdos if pdos else None,
    )

parse_metadata(stdout) staticmethod

Extract TDOS center and HOMO level metadata.

Source code in src/pymultiwfn/analysis/parsers.py
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
@staticmethod
def parse_metadata(stdout: str) -> DOSMetadata | None:
    """Extract TDOS center and HOMO level metadata."""
    tdos_center: float | None = None
    homo_level: float | None = None

    tdos_pat = re.compile(rf"Center of TDOS:\s+({FLOAT_PATTERN})\s*a\.u\.")
    homo_pat = re.compile(
        rf"vertical dash line corresponds to HOMO level at\s+"
        rf"({FLOAT_PATTERN})\s*a\.u\."
    )

    if match := tdos_pat.search(stdout):
        tdos_center = float(match[1])
    if match := homo_pat.search(stdout):
        homo_level = float(match[1])

    if tdos_center is not None or homo_level is not None:
        return DOSMetadata(
            tdos_center_au=tdos_center,
            homo_level_au=homo_level,
        )
    return None

parse_orbital_energies(stdout) staticmethod

Extract orbital energies used in DOS.

Source code in src/pymultiwfn/analysis/parsers.py
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
@staticmethod
def parse_orbital_energies(stdout: str) -> list[OrbitalEnergy]:
    """Extract orbital energies used in DOS."""
    pattern = rf"(\d+)\s+({FLOAT_PATTERN})\s+eV\s+Occ=\s*({FLOAT_PATTERN})"
    return [
        OrbitalEnergy(
            index=int(match[1]),
            energy_eV=float(match[2]),
            occupation=float(match[3]),
        )
        for match in re.finditer(pattern, stdout)
    ]

EDAParser

Bases: OutputParser

Parser for energy decomposition analysis output.

Source code in src/pymultiwfn/analysis/parsers.py
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
class EDAParser(OutputParser):
    """Parser for energy decomposition analysis output."""

    @classmethod
    def parse_for_result(
        cls,
        analysis: Menu,
        stdout: str,
    ) -> list[ParsedMultiwfnResult]:
        case_map: dict[Menu, list] = {
            Menu.DISPERSION_ATOMIC_CONTRIBUTION: [
                cls.parse_dispersion_contributions
            ],
        }
        parsers = case_map.get(analysis, [cls.parse])
        return cls._collect(stdout, parsers)

    @staticmethod
    def parse(stdout: str) -> EnergyDecompositionAnalysis:
        """Extract EDA energy components."""
        components: dict[str, float] = {}

        patterns: dict[str, str] = {
            "electrostatic": rf"[Ee]lectrostatic.*?[=:\s]+({FLOAT_PATTERN})",
            "exchange": rf"[Ee]xchange.*?[=:\s]+({FLOAT_PATTERN})",
            "repulsion": (
                rf"(?:[Rr]epulsion|Pauli).*?[=:\s]+({FLOAT_PATTERN})"
            ),
            "polarization": (
                rf"[Pp]olari[sz]ation.*?[=:\s]+({FLOAT_PATTERN})"
            ),
            "dispersion": rf"[Dd]ispersion.*?[=:\s]+({FLOAT_PATTERN})",
            "orbital_interaction": (
                rf"[Oo]rbital\s+interaction.*?[=:\s]+({FLOAT_PATTERN})"
            ),
            "total_interaction": (
                rf"[Tt]otal\s+interaction.*?[=:\s]+({FLOAT_PATTERN})"
            ),
        }

        for key, pat in patterns.items():
            if match := re.search(pat, stdout):
                components[key] = float(match[1])

        return EnergyDecompositionAnalysis(**components)

    @staticmethod
    def parse_dispersion_contributions(
        stdout: str,
    ) -> list[DispersionContribution]:
        """Extract per-atom dispersion energy contributions."""
        pattern = (
            rf"Atom\s+(\d+).*?(?:dispersion|D[34]).*?[=:\s]+({FLOAT_PATTERN})"
        )
        return [
            DispersionContribution(
                atom_id=int(match[1]), contribution=float(match[2])
            )
            for match in re.finditer(pattern, stdout, re.IGNORECASE)
        ]

parse(stdout) staticmethod

Extract EDA energy components.

Source code in src/pymultiwfn/analysis/parsers.py
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
@staticmethod
def parse(stdout: str) -> EnergyDecompositionAnalysis:
    """Extract EDA energy components."""
    components: dict[str, float] = {}

    patterns: dict[str, str] = {
        "electrostatic": rf"[Ee]lectrostatic.*?[=:\s]+({FLOAT_PATTERN})",
        "exchange": rf"[Ee]xchange.*?[=:\s]+({FLOAT_PATTERN})",
        "repulsion": (
            rf"(?:[Rr]epulsion|Pauli).*?[=:\s]+({FLOAT_PATTERN})"
        ),
        "polarization": (
            rf"[Pp]olari[sz]ation.*?[=:\s]+({FLOAT_PATTERN})"
        ),
        "dispersion": rf"[Dd]ispersion.*?[=:\s]+({FLOAT_PATTERN})",
        "orbital_interaction": (
            rf"[Oo]rbital\s+interaction.*?[=:\s]+({FLOAT_PATTERN})"
        ),
        "total_interaction": (
            rf"[Tt]otal\s+interaction.*?[=:\s]+({FLOAT_PATTERN})"
        ),
    }

    for key, pat in patterns.items():
        if match := re.search(pat, stdout):
            components[key] = float(match[1])

    return EnergyDecompositionAnalysis(**components)

parse_dispersion_contributions(stdout) staticmethod

Extract per-atom dispersion energy contributions.

Source code in src/pymultiwfn/analysis/parsers.py
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
@staticmethod
def parse_dispersion_contributions(
    stdout: str,
) -> list[DispersionContribution]:
    """Extract per-atom dispersion energy contributions."""
    pattern = (
        rf"Atom\s+(\d+).*?(?:dispersion|D[34]).*?[=:\s]+({FLOAT_PATTERN})"
    )
    return [
        DispersionContribution(
            atom_id=int(match[1]), contribution=float(match[2])
        )
        for match in re.finditer(pattern, stdout, re.IGNORECASE)
    ]

ExcitationParser

Bases: OutputParser

Parser for electron excitation analysis output.

Source code in src/pymultiwfn/analysis/parsers.py
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
class ExcitationParser(OutputParser):
    """Parser for electron excitation analysis output."""

    @classmethod
    def parse_for_result(
        cls,
        analysis: Menu,
        stdout: str,
    ) -> list[ParsedMultiwfnResult]:
        default = [
            cls.parse_hole_electron,
            cls.parse_delta_r,
            cls.parse_lambda_index,
        ]
        case_map: dict[Menu, list] = {
            Menu.HOLE_ELECTRON_ANALYSIS: [cls.parse_hole_electron],
            Menu.CHARGE_TRANSFER_ANALYSIS: [cls.parse_charge_transfer],
            Menu.IFCT_ANALYSIS: [cls.parse_charge_transfer],
            Menu.CTS_ANALYSIS: [cls.parse_charge_transfer],
            Menu.DELTA_R_INDEX: [cls.parse_delta_r],
            Menu.LAMBDA_INDEX: [cls.parse_lambda_index],
        }
        parsers = case_map.get(analysis, default)
        return cls._collect(stdout, parsers)

    @staticmethod
    def parse_hole_electron(stdout: str) -> HoleElectron | None:
        """Extract hole-electron analysis descriptors."""
        result: dict[str, Any] = {}

        patterns: dict[str, str] = {
            "D_index": rf"D\s+index[=:\s]+({FLOAT_PATTERN})",
            "Sr": rf"Sr[=:\s]+({FLOAT_PATTERN})",
            "t_index": rf"t\s+index[=:\s]+({FLOAT_PATTERN})",
            "H_index": rf"H\s+index[=:\s]+({FLOAT_PATTERN})",
            "E_index": rf"E\s+index[=:\s]+({FLOAT_PATTERN})",
            "HDI": rf"HDI[=:\s]+({FLOAT_PATTERN})",
            "EDI": rf"EDI[=:\s]+({FLOAT_PATTERN})",
        }

        for key, pat in patterns.items():
            if match := re.search(pat, stdout, re.IGNORECASE):
                result[key] = float(match[1])

        centroid_pat = (
            rf"(hole|electron)\s+centroid.*?"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
        )
        centroids: dict[str, tuple[float, float, float]] = {}
        for match in re.finditer(centroid_pat, stdout, re.IGNORECASE):
            key = f"{match[1].lower()}_centroid"
            centroids[key] = (
                float(match[2]),
                float(match[3]),
                float(match[4]),
            )

        required = {
            "H_index",
            "E_index",
            "t_index",
            "EDI",
            "HDI",
            "Sr",
            "D_index",
        }
        if (
            required.issubset(result)
            and "hole_centroid" in centroids
            and "electron_centroid" in centroids
        ):
            return HoleElectron(
                hole_id=result["H_index"],
                electron_id=result["E_index"],
                transition_index=result["t_index"],
                electron_delocalisation_index=result["EDI"],
                hole_delocalisation_index=result["HDI"],
                Sr=result["Sr"],
                d_index=result["D_index"],
                hole_centroid=centroids["hole_centroid"],
                electron_centroid=centroids["electron_centroid"],
            )
        return None

    @staticmethod
    def parse_charge_transfer(stdout: str) -> ChargeTransfer:
        """Extract charge transfer analysis results."""
        ct_distance: float | None = None
        ct_amount: float | None = None

        ct_dist = rf"CT\s+distance[=:\s]+({FLOAT_PATTERN})"
        ct_amt = (
            rf"(?:transferred|CT)\s+(?:charge|amount)[=:\s]+({FLOAT_PATTERN})"
        )

        if match := re.search(ct_dist, stdout, re.IGNORECASE):
            ct_distance = float(match[1])
        if match := re.search(ct_amt, stdout, re.IGNORECASE):
            ct_amount = float(match[1])

        result = ChargeTransfer(
            distance=ct_distance,
            transfer_amount=ct_amount,
        )

        frag_pattern = (
            rf"Fragment\s+(\d+).*?hole[=:\s]+({FLOAT_PATTERN})"
            rf".*?electron[=:\s]+({FLOAT_PATTERN})"
        )
        fragments: list[ChargeTransferFragment] = []
        fragments.extend(
            ChargeTransferFragment(
                fragment_id=int(match[1]),
                hole_contribution=float(match[2]),
                electron_contribution=float(match[3]),
            )
            for match in re.finditer(frag_pattern, stdout, re.IGNORECASE)
        )
        if fragments:
            result.fragments = fragments

        return result

    @staticmethod
    def parse_delta_r(stdout: str) -> list[DeltaR]:
        """Extract Delta_r index for each excited state."""
        pattern = (
            rf"(?:State|Excited state)\s+(\d+).*?"
            rf"Delta_?r[=:\s]+({FLOAT_PATTERN})"
        )
        return [
            DeltaR(state_id=int(match[1]), delta_r=float(match[2]))
            for match in re.finditer(pattern, stdout, re.IGNORECASE)
        ]

    @staticmethod
    def parse_lambda_index(stdout: str) -> list[LambdaIndex]:
        """Extract Lambda diagnostic for each excited state."""
        pattern = (
            rf"(?:State|Excited state)\s+(\d+).*?"
            rf"Lambda[=:\s]+({FLOAT_PATTERN})"
        )
        return [
            LambdaIndex(state_id=int(match[1]), lambda_index=float(match[2]))
            for match in re.finditer(pattern, stdout, re.IGNORECASE)
        ]

parse_charge_transfer(stdout) staticmethod

Extract charge transfer analysis results.

Source code in src/pymultiwfn/analysis/parsers.py
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
@staticmethod
def parse_charge_transfer(stdout: str) -> ChargeTransfer:
    """Extract charge transfer analysis results."""
    ct_distance: float | None = None
    ct_amount: float | None = None

    ct_dist = rf"CT\s+distance[=:\s]+({FLOAT_PATTERN})"
    ct_amt = (
        rf"(?:transferred|CT)\s+(?:charge|amount)[=:\s]+({FLOAT_PATTERN})"
    )

    if match := re.search(ct_dist, stdout, re.IGNORECASE):
        ct_distance = float(match[1])
    if match := re.search(ct_amt, stdout, re.IGNORECASE):
        ct_amount = float(match[1])

    result = ChargeTransfer(
        distance=ct_distance,
        transfer_amount=ct_amount,
    )

    frag_pattern = (
        rf"Fragment\s+(\d+).*?hole[=:\s]+({FLOAT_PATTERN})"
        rf".*?electron[=:\s]+({FLOAT_PATTERN})"
    )
    fragments: list[ChargeTransferFragment] = []
    fragments.extend(
        ChargeTransferFragment(
            fragment_id=int(match[1]),
            hole_contribution=float(match[2]),
            electron_contribution=float(match[3]),
        )
        for match in re.finditer(frag_pattern, stdout, re.IGNORECASE)
    )
    if fragments:
        result.fragments = fragments

    return result

parse_delta_r(stdout) staticmethod

Extract Delta_r index for each excited state.

Source code in src/pymultiwfn/analysis/parsers.py
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
@staticmethod
def parse_delta_r(stdout: str) -> list[DeltaR]:
    """Extract Delta_r index for each excited state."""
    pattern = (
        rf"(?:State|Excited state)\s+(\d+).*?"
        rf"Delta_?r[=:\s]+({FLOAT_PATTERN})"
    )
    return [
        DeltaR(state_id=int(match[1]), delta_r=float(match[2]))
        for match in re.finditer(pattern, stdout, re.IGNORECASE)
    ]

parse_hole_electron(stdout) staticmethod

Extract hole-electron analysis descriptors.

Source code in src/pymultiwfn/analysis/parsers.py
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
@staticmethod
def parse_hole_electron(stdout: str) -> HoleElectron | None:
    """Extract hole-electron analysis descriptors."""
    result: dict[str, Any] = {}

    patterns: dict[str, str] = {
        "D_index": rf"D\s+index[=:\s]+({FLOAT_PATTERN})",
        "Sr": rf"Sr[=:\s]+({FLOAT_PATTERN})",
        "t_index": rf"t\s+index[=:\s]+({FLOAT_PATTERN})",
        "H_index": rf"H\s+index[=:\s]+({FLOAT_PATTERN})",
        "E_index": rf"E\s+index[=:\s]+({FLOAT_PATTERN})",
        "HDI": rf"HDI[=:\s]+({FLOAT_PATTERN})",
        "EDI": rf"EDI[=:\s]+({FLOAT_PATTERN})",
    }

    for key, pat in patterns.items():
        if match := re.search(pat, stdout, re.IGNORECASE):
            result[key] = float(match[1])

    centroid_pat = (
        rf"(hole|electron)\s+centroid.*?"
        rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
    )
    centroids: dict[str, tuple[float, float, float]] = {}
    for match in re.finditer(centroid_pat, stdout, re.IGNORECASE):
        key = f"{match[1].lower()}_centroid"
        centroids[key] = (
            float(match[2]),
            float(match[3]),
            float(match[4]),
        )

    required = {
        "H_index",
        "E_index",
        "t_index",
        "EDI",
        "HDI",
        "Sr",
        "D_index",
    }
    if (
        required.issubset(result)
        and "hole_centroid" in centroids
        and "electron_centroid" in centroids
    ):
        return HoleElectron(
            hole_id=result["H_index"],
            electron_id=result["E_index"],
            transition_index=result["t_index"],
            electron_delocalisation_index=result["EDI"],
            hole_delocalisation_index=result["HDI"],
            Sr=result["Sr"],
            d_index=result["D_index"],
            hole_centroid=centroids["hole_centroid"],
            electron_centroid=centroids["electron_centroid"],
        )
    return None

parse_lambda_index(stdout) staticmethod

Extract Lambda diagnostic for each excited state.

Source code in src/pymultiwfn/analysis/parsers.py
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
@staticmethod
def parse_lambda_index(stdout: str) -> list[LambdaIndex]:
    """Extract Lambda diagnostic for each excited state."""
    pattern = (
        rf"(?:State|Excited state)\s+(\d+).*?"
        rf"Lambda[=:\s]+({FLOAT_PATTERN})"
    )
    return [
        LambdaIndex(state_id=int(match[1]), lambda_index=float(match[2]))
        for match in re.finditer(pattern, stdout, re.IGNORECASE)
    ]

FuzzySpaceParser

Bases: OutputParser

Parser for fuzzy atomic space analysis output (Menu 15).

Source code in src/pymultiwfn/analysis/parsers.py
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
class FuzzySpaceParser(OutputParser):
    """Parser for fuzzy atomic space analysis output (Menu 15)."""

    @classmethod
    def parse_for_result(
        cls,
        analysis: Menu,
        stdout: str,
    ) -> list[ParsedMultiwfnResult]:
        results: list[ParsedMultiwfnResult] = []

        # Determine integrated property from Menu name
        prop = _FUZZY_PROPERTY_FROM_NAME.get(analysis.name, "unknown")

        # Fuzzy integration table
        integ = cls.parse_fuzzy_integration(stdout, prop)
        if integ is not None:
            results.append(integ)

        # Atomic multipoles
        results.extend(cls.parse_atomic_multipoles(stdout))

        # Molecular multipoles
        mol = cls.parse_molecular_multipole(stdout)
        if mol is not None:
            results.append(mol)

        # AOM diagnostics
        aom = cls.parse_aom_diagnostics(stdout)
        if aom is not None:
            results.append(aom)

        # Delocalization index matrices
        results.extend(cls.parse_di_matrices(stdout))

        # Overlap integration matrices
        results.extend(cls.parse_overlap_matrices(stdout, prop))

        # CLRK matrix
        clrk = cls.parse_clrk_matrix(stdout)
        if clrk is not None:
            results.append(clrk)

        # FLU reference parameters
        results.extend(cls.parse_flu_references(stdout))

        # Aromaticity indices
        results.extend(cls.parse_aromaticity_index(stdout))

        # Pairwise delocalization indices
        results.extend(cls.parse_delocalization_indices(stdout))

        return results

    # ── Fuzzy integration table ──────────────────────────────────────

    @staticmethod
    def parse_fuzzy_integration(
        stdout: str,
        integrated_property: str,
    ) -> FuzzyIntegrationResult | None:
        """Extract per-atom fuzzy integration values."""
        # "     1(C )            6.21199090            14.790461            14.790461"  # noqa: E501
        entry_pat = re.compile(
            rf"^\s+(\d+)\s*\(([A-Za-z]+)\s*\)\s+"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+"
            rf"({FLOAT_PATTERN})"
        )
        sum_pat = re.compile(rf"Summing up above values:\s+({FLOAT_PATTERN})")
        sum_abs_pat = re.compile(
            rf"Summing up absolute value.*?:\s+({FLOAT_PATTERN})"
        )

        entries: list[FuzzyIntegrationEntry] = []
        total_sum: float | None = None
        total_sum_abs: float | None = None

        in_table = False
        for line in stdout.split("\n"):
            if "Atomic space" in line and "Value" in line:
                in_table = True
                continue
            if in_table:
                if match := entry_pat.match(line):
                    entries.append(
                        FuzzyIntegrationEntry(
                            atom_id=int(match[1]),
                            atom_element=match[2].strip(),
                            value=float(match[3]),
                            pct_of_sum=float(match[4]),
                            pct_of_sum_abs=float(match[5]),
                        )
                    )
                    continue
                if match := sum_pat.search(line):
                    total_sum = float(match[1])
                    continue
                if match := sum_abs_pat.search(line):
                    total_sum_abs = float(match[1])
                    in_table = False
                    continue

        if entries:
            return FuzzyIntegrationResult(
                integrated_property=integrated_property,
                entries=entries,
                total_sum=total_sum,
                total_sum_abs=total_sum_abs,
            )
        return None

    # ── Atomic multipoles ────────────────────────────────────────────

    @staticmethod
    def parse_atomic_multipoles(
        stdout: str,
    ) -> list[AtomicMultipole]:
        """Extract per-atom multipole moments."""
        results: list[AtomicMultipole] = []

        # Section header: "*****  Atom     1(C )  *****"
        atom_header = re.compile(
            r"\*+\s*Atom\s+(\d+)\s*\(([A-Za-z]+)\s*\)\s*\*+"
        )

        charge_pat = re.compile(rf"Atomic charge:\s+({FLOAT_PATTERN})")
        monopole_pat = re.compile(
            rf"Atomic monopole moment.*?:\s+({FLOAT_PATTERN})"
        )
        dipole_pat = re.compile(
            rf"X=\s+({FLOAT_PATTERN})\s+Y=\s+({FLOAT_PATTERN})\s+"
            rf"Z=\s+({FLOAT_PATTERN})\s+Norm=\s+({FLOAT_PATTERN})"
        )
        quad_cart_pat = re.compile(rf"([XY][XYZ])=\s+({FLOAT_PATTERN})")
        quad_mag_pat = re.compile(
            rf"Magnitude of the traceless quadrupole.*?:\s+"
            rf"({FLOAT_PATTERN})"
        )
        extent_pat = re.compile(
            rf"Atomic electronic spatial extent.*?:\s+"
            rf"({FLOAT_PATTERN})"
        )
        extent_comp_pat = re.compile(
            rf"Components of <r\^2>:\s+X=\s+({FLOAT_PATTERN})\s+"
            rf"Y=\s+({FLOAT_PATTERN})\s+Z=\s+({FLOAT_PATTERN})"
        )
        octo_mag_pat = re.compile(
            rf"Magnitude:\s+\|Q_3\|=\s+({FLOAT_PATTERN})"
        )

        current: AtomicMultipole | None = None
        in_dipole = False
        in_contrib = False
        in_quad_traceless = False

        for line in stdout.split("\n"):
            if match := atom_header.search(line):
                if current is not None:
                    results.append(current)
                current = AtomicMultipole(
                    atom_id=int(match[1]),
                    atom_element=match[2].strip(),
                )
                in_dipole = False
                in_contrib = False
                in_quad_traceless = False
                continue

            if current is None:
                continue

            if "Molecular dipole" in line or "Molecular quadrupole" in line:
                if current is not None:
                    results.append(current)
                    current = None
                continue

            if match := charge_pat.search(line):
                current.atomic_charge = float(match[1])
                continue

            if match := monopole_pat.search(line):
                current.monopole_moment = float(match[1])
                continue

            if "Atomic dipole moments:" in line:
                in_dipole = True
                in_contrib = False
                continue
            if "Contribution to molecular dipole" in line:
                in_dipole = False
                in_contrib = True
                continue

            if (in_dipole or in_contrib) and (
                match := dipole_pat.search(line)
            ):
                if in_dipole:
                    current.dipole_x = float(match[1])
                    current.dipole_y = float(match[2])
                    current.dipole_z = float(match[3])
                    current.dipole_norm = float(match[4])
                    in_dipole = False
                elif in_contrib:
                    current.mol_dipole_contrib_x = float(match[1])
                    current.mol_dipole_contrib_y = float(match[2])
                    current.mol_dipole_contrib_z = float(match[3])
                    current.mol_dipole_contrib_norm = float(match[4])
                    in_contrib = False
                continue

            if "Traceless Cartesian form" in line:
                in_quad_traceless = True
                continue
            if in_quad_traceless:
                for qm in quad_cart_pat.finditer(line):
                    comp = qm[1]
                    val = float(qm[2])
                    if comp == "XX":
                        current.quadrupole_xx = val
                    elif comp == "XY":
                        current.quadrupole_xy = val
                    elif comp == "XZ":
                        current.quadrupole_xz = val
                    elif comp == "YY":
                        current.quadrupole_yy = val
                    elif comp == "YZ":
                        current.quadrupole_yz = val
                    elif comp == "ZZ":
                        current.quadrupole_zz = val
                        in_quad_traceless = False

            if match := quad_mag_pat.search(line):
                current.quadrupole_magnitude = float(match[1])
                continue

            if match := extent_pat.search(line):
                current.spatial_extent_r2 = float(match[1])
                continue
            if match := extent_comp_pat.search(line):
                current.spatial_extent_x = float(match[1])
                current.spatial_extent_y = float(match[2])
                current.spatial_extent_z = float(match[3])
                continue

            if match := octo_mag_pat.search(line):
                current.octopole_magnitude = float(match[1])
                continue

        if current is not None:
            results.append(current)

        return results

    # ── Molecular multipoles ─────────────────────────────────────────

    @staticmethod
    def parse_molecular_multipole(
        stdout: str,
    ) -> MolecularMultipole | None:
        """Extract molecular multipole moments."""
        if "Molecular dipole" not in stdout:
            return None

        mol = MolecularMultipole()
        found = False

        electrons_pat = re.compile(
            rf"Total number of electrons:\s+({FLOAT_PATTERN})\s+"
            rf"Net charge:\s+({FLOAT_PATTERN})"
        )
        if match := electrons_pat.search(stdout):
            mol.total_electrons = float(match[1])
            mol.net_charge = float(match[2])
            found = True

        dip_au_pat = re.compile(
            rf"Molecular dipole moment \(a\.u\.\):\s+"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+"
            rf"({FLOAT_PATTERN})"
        )
        if match := dip_au_pat.search(stdout):
            mol.dipole_x_au = float(match[1])
            mol.dipole_y_au = float(match[2])
            mol.dipole_z_au = float(match[3])
            found = True

        dip_debye_pat = re.compile(
            rf"Molecular dipole moment \(Debye\):\s+"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+"
            rf"({FLOAT_PATTERN})"
        )
        if match := dip_debye_pat.search(stdout):
            mol.dipole_x_debye = float(match[1])
            mol.dipole_y_debye = float(match[2])
            mol.dipole_z_debye = float(match[3])
            found = True

        dip_mag_pat = re.compile(
            rf"Magnitude of molecular dipole.*?a\.u\.&Debye\):\s+"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
        )
        if match := dip_mag_pat.search(stdout):
            mol.dipole_magnitude_au = float(match[1])
            mol.dipole_magnitude_debye = float(match[2])
            found = True

        # Traceless quadrupole
        traceless_start = stdout.find(
            "Molecular quadrupole moments (Traceless"
        )
        if traceless_start != -1:
            block = stdout[traceless_start : traceless_start + 500]
            comp_pat = re.compile(rf"([XY][XYZ])=\s+({FLOAT_PATTERN})")
            for qm in comp_pat.finditer(block):
                comp = qm[1]
                val = float(qm[2])
                if comp == "XX":
                    mol.quadrupole_xx = val
                elif comp == "XY":
                    mol.quadrupole_xy = val
                elif comp == "XZ":
                    mol.quadrupole_xz = val
                elif comp == "YY":
                    mol.quadrupole_yy = val
                elif comp == "YZ":
                    mol.quadrupole_yz = val
                elif comp == "ZZ":
                    mol.quadrupole_zz = val
            found = True

        quad_mag_pat = re.compile(
            rf"Magnitude of the traceless quadrupole moment tensor:\s+"
            rf"({FLOAT_PATTERN})"
        )
        # Find the one after "Molecular"
        mol_section = stdout[stdout.find("Molecular dipole") :]
        if match := quad_mag_pat.search(mol_section):
            mol.quadrupole_magnitude = float(match[1])

        mol_extent_pat = re.compile(
            rf"Molecular electronic spatial extent.*?:\s+"
            rf"({FLOAT_PATTERN})"
        )
        if match := mol_extent_pat.search(stdout):
            mol.spatial_extent_r2 = float(match[1])
            found = True

        mol_extent_comp = re.compile(
            rf"Components of <r\^2>:\s+X=\s+({FLOAT_PATTERN})\s+"
            rf"Y=\s+({FLOAT_PATTERN})\s+Z=\s+({FLOAT_PATTERN})"
        )
        # Take the last one (molecular, not atomic)
        matches = list(mol_extent_comp.finditer(stdout))
        if matches:
            m = matches[-1]
            mol.spatial_extent_x = float(m[1])
            mol.spatial_extent_y = float(m[2])
            mol.spatial_extent_z = float(m[3])

        octo_mag = re.compile(rf"Magnitude:\s+\|Q_3\|=\s+({FLOAT_PATTERN})")
        mol_octo_matches = list(octo_mag.finditer(mol_section))
        if mol_octo_matches:
            mol.octopole_magnitude = float(mol_octo_matches[-1][1])

        return mol if found else None

    # ── AOM diagnostics ──────────────────────────────────────────────

    @staticmethod
    def parse_aom_diagnostics(stdout: str) -> AOMDiagnostics | None:
        """Extract AOM quality diagnostics."""
        error_pat = re.compile(rf"Error of AOM is\s+({FLOAT_PATTERN})")
        diag_pat = re.compile(
            rf"Maximum diagonal deviation to 1:\s+({FLOAT_PATTERN})"
            rf"\s+at orbital\s+(\d+)"
        )
        nondiag_pat = re.compile(
            rf"Maximum nondiagonal deviation to 0:\s+"
            rf"({FLOAT_PATTERN})\s+between orbitals\s+(\d+)\s+(\d+)"
        )
        export_pat = re.compile(r"exported to\s+(\S+)\s+in current folder")

        aom = AOMDiagnostics()
        found = False

        if match := error_pat.search(stdout):
            aom.error = float(match[1])
            found = True
        if match := diag_pat.search(stdout):
            aom.max_diagonal_deviation = float(match[1])
            aom.max_diagonal_orbital = int(match[2])
            found = True
        if match := nondiag_pat.search(stdout):
            aom.max_nondiagonal_deviation = float(match[1])
            aom.max_nondiagonal_orbitals = (
                int(match[2]),
                int(match[3]),
            )
            found = True
        # Find AOM-specific export
        for m in export_pat.finditer(stdout):
            if "AOM" in m[1]:
                aom.exported_file = m[1]
                found = True

        return aom if found else None

    # ── Delocalization index matrices ────────────────────────────────

    @classmethod
    def parse_di_matrices(
        cls,
        stdout: str,
    ) -> list[DelocalizationIndexMatrix]:
        """Extract delocalization/localization index matrices."""
        results: list[DelocalizationIndexMatrix] = []

        header_pat = re.compile(
            r"\*+\s*(.*?(?:delocalization|localization)\s+index"
            r"\s+matrix)\s*\*+",
            re.I,
        )
        col_header_pat = re.compile(r"^\s+(\d+(?:\s+\d+)*)\s*$")
        row_pat = re.compile(rf"^\s+(\d+)((?:\s+{FLOAT_PATTERN})+)\s*$")
        li_pat = re.compile(
            rf"(\d+)\s*\(([A-Za-z]+)\s*\)\s*:\s+({FLOAT_PATTERN})"
        )

        in_matrix = False
        label = ""
        current_cols: list[int] = []
        data: dict[tuple[int, int], float] = {}
        max_idx = 0
        loc_indices: list[LocalizationIndex] = []

        def _flush() -> None:
            nonlocal data, max_idx, label, in_matrix, loc_indices
            if data:
                results.append(
                    DelocalizationIndexMatrix(
                        label=label,
                        n_atoms=max_idx,
                        data=dict(data),
                        localization_indices=list(loc_indices),
                    )
                )
            data = {}
            max_idx = 0
            label = ""
            in_matrix = False
            loc_indices = []

        for line in stdout.split("\n"):
            if match := header_pat.search(line):
                if in_matrix:
                    _flush()
                in_matrix = True
                label = match[1].strip()
                current_cols = []
                continue

            if not in_matrix:
                # Localization index lines outside matrix
                if "Localization index:" in line:
                    for m in li_pat.finditer(line):
                        loc_indices.append(
                            LocalizationIndex(
                                atom_id=int(m[1]),
                                atom_element=m[2].strip(),
                                index=float(m[3]),
                            )
                        )
                    # Also check subsequent lines
                    continue
                if loc_indices and (
                    match := re.search(
                        rf"(\d+)\s*\([A-Za-z]+\s*\)\s*:\s+"
                        rf"({FLOAT_PATTERN})",
                        line,
                    )
                ):
                    for m in li_pat.finditer(line):
                        loc_indices.append(
                            LocalizationIndex(
                                atom_id=int(m[1]),
                                atom_element=m[2].strip(),
                                index=float(m[3]),
                            )
                        )
                    continue
                continue

            # End markers
            if (
                "Localization index:" in line
                or "Note:" in line
                or "Current FLU" in line
                or "Integration of" in line
                or "Condensed linear" in line
            ):
                _flush()
                # Parse LI from this line if present
                if "Localization index:" in line:
                    for m in li_pat.finditer(line):
                        loc_indices.append(
                            LocalizationIndex(
                                atom_id=int(m[1]),
                                atom_element=m[2].strip(),
                                index=float(m[3]),
                            )
                        )
                continue

            if match := col_header_pat.match(line):
                current_cols = [int(v) for v in match[1].split()]
                continue

            if current_cols and (match := row_pat.match(line)):
                row_idx = int(match[1])
                vals = [float(v) for v in match[2].split()]
                for k, val in enumerate(vals):
                    if k < len(current_cols):
                        col_idx = current_cols[k]
                        data[(row_idx, col_idx)] = val
                        if row_idx > max_idx:
                            max_idx = row_idx
                        if col_idx > max_idx:
                            max_idx = col_idx

        if in_matrix and data:
            _flush()

        # Attach any trailing localization indices to last matrix
        if loc_indices and results:
            results[-1].localization_indices = loc_indices

        return results

    # ── Overlap integration matrices ─────────────────────────────────

    @classmethod
    def parse_overlap_matrices(
        cls,
        stdout: str,
        integrated_property: str,
    ) -> list[OverlapIntegrationMatrix]:
        """Extract positive/negative/all overlap integration matrices."""
        results: list[OverlapIntegrationMatrix] = []

        header_pat = re.compile(
            r"\*+\s*Integration of\s+(positive|negative|all)\s+"
            r"values in overlap region\s*\*+",
            re.I,
        )
        col_header_pat = re.compile(r"^\s+(\d+(?:\s+\d+)*)\s*$")
        row_pat = re.compile(rf"^\s+(\d+)((?:\s+{FLOAT_PATTERN})+)\s*$")
        sum_diag_pat = re.compile(
            rf"Summing up diagonal.*?:\s+({FLOAT_PATTERN})"
        )
        sum_nondiag_pat = re.compile(
            rf"Summing up non-diagonal.*?:\s+({FLOAT_PATTERN})"
        )
        sum_all_pat = re.compile(rf"Summing up all.*?:\s+({FLOAT_PATTERN})")

        in_matrix = False
        category = ""
        current_cols: list[int] = []
        data: dict[tuple[int, int], float] = {}
        max_idx = 0
        sum_d: float | None = None
        sum_nd: float | None = None
        sum_a: float | None = None

        def _flush() -> None:
            nonlocal data, max_idx, category, in_matrix
            nonlocal sum_d, sum_nd, sum_a
            if data or sum_d is not None:
                results.append(
                    OverlapIntegrationMatrix(
                        category=category,
                        integrated_property=integrated_property,
                        n_atoms=max_idx,
                        data=dict(data),
                        sum_diagonal=sum_d,
                        sum_nondiagonal=sum_nd,
                        sum_all=sum_a,
                    )
                )
            data = {}
            max_idx = 0
            sum_d = None
            sum_nd = None
            sum_a = None
            in_matrix = False

        for line in stdout.split("\n"):
            if match := header_pat.search(line):
                if in_matrix:
                    _flush()
                in_matrix = True
                category = match[1].lower()
                current_cols = []
                continue

            if not in_matrix:
                continue

            if match := sum_diag_pat.search(line):
                sum_d = float(match[1])
                continue
            if match := sum_nondiag_pat.search(line):
                sum_nd = float(match[1])
                continue
            if match := sum_all_pat.search(line):
                sum_a = float(match[1])
                _flush()
                continue

            if match := col_header_pat.match(line):
                current_cols = [int(v) for v in match[1].split()]
                continue

            if current_cols and (match := row_pat.match(line)):
                row_idx = int(match[1])
                vals = [float(v) for v in match[2].split()]
                for k, val in enumerate(vals):
                    if k < len(current_cols):
                        col_idx = current_cols[k]
                        data[(row_idx, col_idx)] = val
                        if row_idx > max_idx:
                            max_idx = row_idx
                        if col_idx > max_idx:
                            max_idx = col_idx

        if in_matrix:
            _flush()

        return results

    # ── CLRK matrix ──────────────────────────────────────────────────

    @staticmethod
    def parse_clrk_matrix(stdout: str) -> CLRKMatrix | None:
        """Extract condensed linear response kernel matrix."""
        header_pat = re.compile(
            r"\*+\s*.*?(?:CLRK|[Cc]ondensed linear response "
            r"kernel).*?matrix\s*\*+",
            re.I,
        )
        col_header_pat = re.compile(r"^\s+(\d+(?:\s+\d+)*)\s*$")
        row_pat = re.compile(rf"^\s+(\d+)((?:\s+{FLOAT_PATTERN})+)\s*$")

        in_matrix = False
        current_cols: list[int] = []
        data: dict[tuple[int, int], float] = {}
        max_idx = 0

        for line in stdout.split("\n"):
            if header_pat.search(line):
                in_matrix = True
                current_cols = []
                data = {}
                max_idx = 0
                continue

            if not in_matrix:
                continue

            # End on next section or blank
            if line.strip() and not re.match(r"^\s+[\d-]", line):
                if match := col_header_pat.match(line):
                    current_cols = [int(v) for v in match[1].split()]
                    continue
                if data:
                    break

            if current_cols and (match := row_pat.match(line)):
                row_idx = int(match[1])
                vals = [float(v) for v in match[2].split()]
                for k, val in enumerate(vals):
                    if k < len(current_cols):
                        col_idx = current_cols[k]
                        data[(row_idx, col_idx)] = val
                        if row_idx > max_idx:
                            max_idx = row_idx
                        if col_idx > max_idx:
                            max_idx = col_idx

        if data:
            return CLRKMatrix(n_atoms=max_idx, data=data)
        return None

    # ── FLU references ───────────────────────────────────────────────

    @staticmethod
    def parse_flu_references(
        stdout: str,
    ) -> list[FLUReferenceParameter]:
        """Extract FLU reference bond order parameters."""
        pattern = re.compile(
            rf"([A-Za-z]+)\s*-\s*([A-Za-z]+)\s*:\s+({FLOAT_PATTERN})"
        )
        results: list[FLUReferenceParameter] = []
        in_section = False
        for line in stdout.split("\n"):
            if "FLU reference parameters" in line:
                in_section = True
                continue
            if in_section:
                if match := pattern.search(line):
                    results.append(
                        FLUReferenceParameter(
                            element1=match[1].strip(),
                            element2=match[2].strip(),
                            reference_value=float(match[3]),
                        )
                    )
                elif line.strip() and not pattern.search(line):
                    in_section = False
        return results

    # ── Aromaticity indices ──────────────────────────────────────────

    @staticmethod
    def parse_aromaticity_index(
        stdout: str,
    ) -> list[AromaticityIndex]:
        """Extract aromaticity indices (PDI, FLU, etc.)."""
        result: list[AromaticityIndex] = []
        index_patterns: dict[str, str] = {
            "PDI": rf"PDI[=:\s]+({FLOAT_PATTERN})",
            "FLU": rf"FLU[=:\s]+({FLOAT_PATTERN})",
            "FLU_pi": rf"FLU.*?pi[=:\s]+({FLOAT_PATTERN})",
            "MCI": rf"MCI[=:\s]+({FLOAT_PATTERN})",
            "Iring": rf"Iring[=:\s]+({FLOAT_PATTERN})",
            "ITA": rf"ITA[=:\s]+({FLOAT_PATTERN})",
            "PLR": rf"PLR[=:\s]+({FLOAT_PATTERN})",
        }
        for name, pat in index_patterns.items():
            if match := re.search(pat, stdout, re.IGNORECASE):
                result.append(
                    AromaticityIndex(index_name=name, value=float(match[1]))
                )
        return result

    # ── Pairwise delocalization indices ──────────────────────────────

    @staticmethod
    def parse_delocalization_indices(
        stdout: str,
    ) -> list[DelocalizationIndex]:
        """Extract pairwise delocalization indices."""
        di_pattern = (
            rf"Delocalization index.*?atom\s+(\d+).*?atom\s+(\d+)"
            rf".*?:\s+({FLOAT_PATTERN})"
        )
        indices: list[DelocalizationIndex] = []
        for match in re.finditer(di_pattern, stdout, re.IGNORECASE):
            a1, a2 = int(match[1]), int(match[2])
            if a1 > a2:
                a1, a2 = a2, a1
            indices.append(
                DelocalizationIndex(
                    atom1_id=a1, atom2_id=a2, index=float(match[3])
                )
            )
        return indices

parse_aom_diagnostics(stdout) staticmethod

Extract AOM quality diagnostics.

Source code in src/pymultiwfn/analysis/parsers.py
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
@staticmethod
def parse_aom_diagnostics(stdout: str) -> AOMDiagnostics | None:
    """Extract AOM quality diagnostics."""
    error_pat = re.compile(rf"Error of AOM is\s+({FLOAT_PATTERN})")
    diag_pat = re.compile(
        rf"Maximum diagonal deviation to 1:\s+({FLOAT_PATTERN})"
        rf"\s+at orbital\s+(\d+)"
    )
    nondiag_pat = re.compile(
        rf"Maximum nondiagonal deviation to 0:\s+"
        rf"({FLOAT_PATTERN})\s+between orbitals\s+(\d+)\s+(\d+)"
    )
    export_pat = re.compile(r"exported to\s+(\S+)\s+in current folder")

    aom = AOMDiagnostics()
    found = False

    if match := error_pat.search(stdout):
        aom.error = float(match[1])
        found = True
    if match := diag_pat.search(stdout):
        aom.max_diagonal_deviation = float(match[1])
        aom.max_diagonal_orbital = int(match[2])
        found = True
    if match := nondiag_pat.search(stdout):
        aom.max_nondiagonal_deviation = float(match[1])
        aom.max_nondiagonal_orbitals = (
            int(match[2]),
            int(match[3]),
        )
        found = True
    # Find AOM-specific export
    for m in export_pat.finditer(stdout):
        if "AOM" in m[1]:
            aom.exported_file = m[1]
            found = True

    return aom if found else None

parse_aromaticity_index(stdout) staticmethod

Extract aromaticity indices (PDI, FLU, etc.).

Source code in src/pymultiwfn/analysis/parsers.py
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
@staticmethod
def parse_aromaticity_index(
    stdout: str,
) -> list[AromaticityIndex]:
    """Extract aromaticity indices (PDI, FLU, etc.)."""
    result: list[AromaticityIndex] = []
    index_patterns: dict[str, str] = {
        "PDI": rf"PDI[=:\s]+({FLOAT_PATTERN})",
        "FLU": rf"FLU[=:\s]+({FLOAT_PATTERN})",
        "FLU_pi": rf"FLU.*?pi[=:\s]+({FLOAT_PATTERN})",
        "MCI": rf"MCI[=:\s]+({FLOAT_PATTERN})",
        "Iring": rf"Iring[=:\s]+({FLOAT_PATTERN})",
        "ITA": rf"ITA[=:\s]+({FLOAT_PATTERN})",
        "PLR": rf"PLR[=:\s]+({FLOAT_PATTERN})",
    }
    for name, pat in index_patterns.items():
        if match := re.search(pat, stdout, re.IGNORECASE):
            result.append(
                AromaticityIndex(index_name=name, value=float(match[1]))
            )
    return result

parse_atomic_multipoles(stdout) staticmethod

Extract per-atom multipole moments.

Source code in src/pymultiwfn/analysis/parsers.py
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
@staticmethod
def parse_atomic_multipoles(
    stdout: str,
) -> list[AtomicMultipole]:
    """Extract per-atom multipole moments."""
    results: list[AtomicMultipole] = []

    # Section header: "*****  Atom     1(C )  *****"
    atom_header = re.compile(
        r"\*+\s*Atom\s+(\d+)\s*\(([A-Za-z]+)\s*\)\s*\*+"
    )

    charge_pat = re.compile(rf"Atomic charge:\s+({FLOAT_PATTERN})")
    monopole_pat = re.compile(
        rf"Atomic monopole moment.*?:\s+({FLOAT_PATTERN})"
    )
    dipole_pat = re.compile(
        rf"X=\s+({FLOAT_PATTERN})\s+Y=\s+({FLOAT_PATTERN})\s+"
        rf"Z=\s+({FLOAT_PATTERN})\s+Norm=\s+({FLOAT_PATTERN})"
    )
    quad_cart_pat = re.compile(rf"([XY][XYZ])=\s+({FLOAT_PATTERN})")
    quad_mag_pat = re.compile(
        rf"Magnitude of the traceless quadrupole.*?:\s+"
        rf"({FLOAT_PATTERN})"
    )
    extent_pat = re.compile(
        rf"Atomic electronic spatial extent.*?:\s+"
        rf"({FLOAT_PATTERN})"
    )
    extent_comp_pat = re.compile(
        rf"Components of <r\^2>:\s+X=\s+({FLOAT_PATTERN})\s+"
        rf"Y=\s+({FLOAT_PATTERN})\s+Z=\s+({FLOAT_PATTERN})"
    )
    octo_mag_pat = re.compile(
        rf"Magnitude:\s+\|Q_3\|=\s+({FLOAT_PATTERN})"
    )

    current: AtomicMultipole | None = None
    in_dipole = False
    in_contrib = False
    in_quad_traceless = False

    for line in stdout.split("\n"):
        if match := atom_header.search(line):
            if current is not None:
                results.append(current)
            current = AtomicMultipole(
                atom_id=int(match[1]),
                atom_element=match[2].strip(),
            )
            in_dipole = False
            in_contrib = False
            in_quad_traceless = False
            continue

        if current is None:
            continue

        if "Molecular dipole" in line or "Molecular quadrupole" in line:
            if current is not None:
                results.append(current)
                current = None
            continue

        if match := charge_pat.search(line):
            current.atomic_charge = float(match[1])
            continue

        if match := monopole_pat.search(line):
            current.monopole_moment = float(match[1])
            continue

        if "Atomic dipole moments:" in line:
            in_dipole = True
            in_contrib = False
            continue
        if "Contribution to molecular dipole" in line:
            in_dipole = False
            in_contrib = True
            continue

        if (in_dipole or in_contrib) and (
            match := dipole_pat.search(line)
        ):
            if in_dipole:
                current.dipole_x = float(match[1])
                current.dipole_y = float(match[2])
                current.dipole_z = float(match[3])
                current.dipole_norm = float(match[4])
                in_dipole = False
            elif in_contrib:
                current.mol_dipole_contrib_x = float(match[1])
                current.mol_dipole_contrib_y = float(match[2])
                current.mol_dipole_contrib_z = float(match[3])
                current.mol_dipole_contrib_norm = float(match[4])
                in_contrib = False
            continue

        if "Traceless Cartesian form" in line:
            in_quad_traceless = True
            continue
        if in_quad_traceless:
            for qm in quad_cart_pat.finditer(line):
                comp = qm[1]
                val = float(qm[2])
                if comp == "XX":
                    current.quadrupole_xx = val
                elif comp == "XY":
                    current.quadrupole_xy = val
                elif comp == "XZ":
                    current.quadrupole_xz = val
                elif comp == "YY":
                    current.quadrupole_yy = val
                elif comp == "YZ":
                    current.quadrupole_yz = val
                elif comp == "ZZ":
                    current.quadrupole_zz = val
                    in_quad_traceless = False

        if match := quad_mag_pat.search(line):
            current.quadrupole_magnitude = float(match[1])
            continue

        if match := extent_pat.search(line):
            current.spatial_extent_r2 = float(match[1])
            continue
        if match := extent_comp_pat.search(line):
            current.spatial_extent_x = float(match[1])
            current.spatial_extent_y = float(match[2])
            current.spatial_extent_z = float(match[3])
            continue

        if match := octo_mag_pat.search(line):
            current.octopole_magnitude = float(match[1])
            continue

    if current is not None:
        results.append(current)

    return results

parse_clrk_matrix(stdout) staticmethod

Extract condensed linear response kernel matrix.

Source code in src/pymultiwfn/analysis/parsers.py
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
@staticmethod
def parse_clrk_matrix(stdout: str) -> CLRKMatrix | None:
    """Extract condensed linear response kernel matrix."""
    header_pat = re.compile(
        r"\*+\s*.*?(?:CLRK|[Cc]ondensed linear response "
        r"kernel).*?matrix\s*\*+",
        re.I,
    )
    col_header_pat = re.compile(r"^\s+(\d+(?:\s+\d+)*)\s*$")
    row_pat = re.compile(rf"^\s+(\d+)((?:\s+{FLOAT_PATTERN})+)\s*$")

    in_matrix = False
    current_cols: list[int] = []
    data: dict[tuple[int, int], float] = {}
    max_idx = 0

    for line in stdout.split("\n"):
        if header_pat.search(line):
            in_matrix = True
            current_cols = []
            data = {}
            max_idx = 0
            continue

        if not in_matrix:
            continue

        # End on next section or blank
        if line.strip() and not re.match(r"^\s+[\d-]", line):
            if match := col_header_pat.match(line):
                current_cols = [int(v) for v in match[1].split()]
                continue
            if data:
                break

        if current_cols and (match := row_pat.match(line)):
            row_idx = int(match[1])
            vals = [float(v) for v in match[2].split()]
            for k, val in enumerate(vals):
                if k < len(current_cols):
                    col_idx = current_cols[k]
                    data[(row_idx, col_idx)] = val
                    if row_idx > max_idx:
                        max_idx = row_idx
                    if col_idx > max_idx:
                        max_idx = col_idx

    if data:
        return CLRKMatrix(n_atoms=max_idx, data=data)
    return None

parse_delocalization_indices(stdout) staticmethod

Extract pairwise delocalization indices.

Source code in src/pymultiwfn/analysis/parsers.py
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
@staticmethod
def parse_delocalization_indices(
    stdout: str,
) -> list[DelocalizationIndex]:
    """Extract pairwise delocalization indices."""
    di_pattern = (
        rf"Delocalization index.*?atom\s+(\d+).*?atom\s+(\d+)"
        rf".*?:\s+({FLOAT_PATTERN})"
    )
    indices: list[DelocalizationIndex] = []
    for match in re.finditer(di_pattern, stdout, re.IGNORECASE):
        a1, a2 = int(match[1]), int(match[2])
        if a1 > a2:
            a1, a2 = a2, a1
        indices.append(
            DelocalizationIndex(
                atom1_id=a1, atom2_id=a2, index=float(match[3])
            )
        )
    return indices

parse_di_matrices(stdout) classmethod

Extract delocalization/localization index matrices.

Source code in src/pymultiwfn/analysis/parsers.py
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
@classmethod
def parse_di_matrices(
    cls,
    stdout: str,
) -> list[DelocalizationIndexMatrix]:
    """Extract delocalization/localization index matrices."""
    results: list[DelocalizationIndexMatrix] = []

    header_pat = re.compile(
        r"\*+\s*(.*?(?:delocalization|localization)\s+index"
        r"\s+matrix)\s*\*+",
        re.I,
    )
    col_header_pat = re.compile(r"^\s+(\d+(?:\s+\d+)*)\s*$")
    row_pat = re.compile(rf"^\s+(\d+)((?:\s+{FLOAT_PATTERN})+)\s*$")
    li_pat = re.compile(
        rf"(\d+)\s*\(([A-Za-z]+)\s*\)\s*:\s+({FLOAT_PATTERN})"
    )

    in_matrix = False
    label = ""
    current_cols: list[int] = []
    data: dict[tuple[int, int], float] = {}
    max_idx = 0
    loc_indices: list[LocalizationIndex] = []

    def _flush() -> None:
        nonlocal data, max_idx, label, in_matrix, loc_indices
        if data:
            results.append(
                DelocalizationIndexMatrix(
                    label=label,
                    n_atoms=max_idx,
                    data=dict(data),
                    localization_indices=list(loc_indices),
                )
            )
        data = {}
        max_idx = 0
        label = ""
        in_matrix = False
        loc_indices = []

    for line in stdout.split("\n"):
        if match := header_pat.search(line):
            if in_matrix:
                _flush()
            in_matrix = True
            label = match[1].strip()
            current_cols = []
            continue

        if not in_matrix:
            # Localization index lines outside matrix
            if "Localization index:" in line:
                for m in li_pat.finditer(line):
                    loc_indices.append(
                        LocalizationIndex(
                            atom_id=int(m[1]),
                            atom_element=m[2].strip(),
                            index=float(m[3]),
                        )
                    )
                # Also check subsequent lines
                continue
            if loc_indices and (
                match := re.search(
                    rf"(\d+)\s*\([A-Za-z]+\s*\)\s*:\s+"
                    rf"({FLOAT_PATTERN})",
                    line,
                )
            ):
                for m in li_pat.finditer(line):
                    loc_indices.append(
                        LocalizationIndex(
                            atom_id=int(m[1]),
                            atom_element=m[2].strip(),
                            index=float(m[3]),
                        )
                    )
                continue
            continue

        # End markers
        if (
            "Localization index:" in line
            or "Note:" in line
            or "Current FLU" in line
            or "Integration of" in line
            or "Condensed linear" in line
        ):
            _flush()
            # Parse LI from this line if present
            if "Localization index:" in line:
                for m in li_pat.finditer(line):
                    loc_indices.append(
                        LocalizationIndex(
                            atom_id=int(m[1]),
                            atom_element=m[2].strip(),
                            index=float(m[3]),
                        )
                    )
            continue

        if match := col_header_pat.match(line):
            current_cols = [int(v) for v in match[1].split()]
            continue

        if current_cols and (match := row_pat.match(line)):
            row_idx = int(match[1])
            vals = [float(v) for v in match[2].split()]
            for k, val in enumerate(vals):
                if k < len(current_cols):
                    col_idx = current_cols[k]
                    data[(row_idx, col_idx)] = val
                    if row_idx > max_idx:
                        max_idx = row_idx
                    if col_idx > max_idx:
                        max_idx = col_idx

    if in_matrix and data:
        _flush()

    # Attach any trailing localization indices to last matrix
    if loc_indices and results:
        results[-1].localization_indices = loc_indices

    return results

parse_flu_references(stdout) staticmethod

Extract FLU reference bond order parameters.

Source code in src/pymultiwfn/analysis/parsers.py
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
@staticmethod
def parse_flu_references(
    stdout: str,
) -> list[FLUReferenceParameter]:
    """Extract FLU reference bond order parameters."""
    pattern = re.compile(
        rf"([A-Za-z]+)\s*-\s*([A-Za-z]+)\s*:\s+({FLOAT_PATTERN})"
    )
    results: list[FLUReferenceParameter] = []
    in_section = False
    for line in stdout.split("\n"):
        if "FLU reference parameters" in line:
            in_section = True
            continue
        if in_section:
            if match := pattern.search(line):
                results.append(
                    FLUReferenceParameter(
                        element1=match[1].strip(),
                        element2=match[2].strip(),
                        reference_value=float(match[3]),
                    )
                )
            elif line.strip() and not pattern.search(line):
                in_section = False
    return results

parse_fuzzy_integration(stdout, integrated_property) staticmethod

Extract per-atom fuzzy integration values.

Source code in src/pymultiwfn/analysis/parsers.py
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
@staticmethod
def parse_fuzzy_integration(
    stdout: str,
    integrated_property: str,
) -> FuzzyIntegrationResult | None:
    """Extract per-atom fuzzy integration values."""
    # "     1(C )            6.21199090            14.790461            14.790461"  # noqa: E501
    entry_pat = re.compile(
        rf"^\s+(\d+)\s*\(([A-Za-z]+)\s*\)\s+"
        rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+"
        rf"({FLOAT_PATTERN})"
    )
    sum_pat = re.compile(rf"Summing up above values:\s+({FLOAT_PATTERN})")
    sum_abs_pat = re.compile(
        rf"Summing up absolute value.*?:\s+({FLOAT_PATTERN})"
    )

    entries: list[FuzzyIntegrationEntry] = []
    total_sum: float | None = None
    total_sum_abs: float | None = None

    in_table = False
    for line in stdout.split("\n"):
        if "Atomic space" in line and "Value" in line:
            in_table = True
            continue
        if in_table:
            if match := entry_pat.match(line):
                entries.append(
                    FuzzyIntegrationEntry(
                        atom_id=int(match[1]),
                        atom_element=match[2].strip(),
                        value=float(match[3]),
                        pct_of_sum=float(match[4]),
                        pct_of_sum_abs=float(match[5]),
                    )
                )
                continue
            if match := sum_pat.search(line):
                total_sum = float(match[1])
                continue
            if match := sum_abs_pat.search(line):
                total_sum_abs = float(match[1])
                in_table = False
                continue

    if entries:
        return FuzzyIntegrationResult(
            integrated_property=integrated_property,
            entries=entries,
            total_sum=total_sum,
            total_sum_abs=total_sum_abs,
        )
    return None

parse_molecular_multipole(stdout) staticmethod

Extract molecular multipole moments.

Source code in src/pymultiwfn/analysis/parsers.py
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
@staticmethod
def parse_molecular_multipole(
    stdout: str,
) -> MolecularMultipole | None:
    """Extract molecular multipole moments."""
    if "Molecular dipole" not in stdout:
        return None

    mol = MolecularMultipole()
    found = False

    electrons_pat = re.compile(
        rf"Total number of electrons:\s+({FLOAT_PATTERN})\s+"
        rf"Net charge:\s+({FLOAT_PATTERN})"
    )
    if match := electrons_pat.search(stdout):
        mol.total_electrons = float(match[1])
        mol.net_charge = float(match[2])
        found = True

    dip_au_pat = re.compile(
        rf"Molecular dipole moment \(a\.u\.\):\s+"
        rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+"
        rf"({FLOAT_PATTERN})"
    )
    if match := dip_au_pat.search(stdout):
        mol.dipole_x_au = float(match[1])
        mol.dipole_y_au = float(match[2])
        mol.dipole_z_au = float(match[3])
        found = True

    dip_debye_pat = re.compile(
        rf"Molecular dipole moment \(Debye\):\s+"
        rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+"
        rf"({FLOAT_PATTERN})"
    )
    if match := dip_debye_pat.search(stdout):
        mol.dipole_x_debye = float(match[1])
        mol.dipole_y_debye = float(match[2])
        mol.dipole_z_debye = float(match[3])
        found = True

    dip_mag_pat = re.compile(
        rf"Magnitude of molecular dipole.*?a\.u\.&Debye\):\s+"
        rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
    )
    if match := dip_mag_pat.search(stdout):
        mol.dipole_magnitude_au = float(match[1])
        mol.dipole_magnitude_debye = float(match[2])
        found = True

    # Traceless quadrupole
    traceless_start = stdout.find(
        "Molecular quadrupole moments (Traceless"
    )
    if traceless_start != -1:
        block = stdout[traceless_start : traceless_start + 500]
        comp_pat = re.compile(rf"([XY][XYZ])=\s+({FLOAT_PATTERN})")
        for qm in comp_pat.finditer(block):
            comp = qm[1]
            val = float(qm[2])
            if comp == "XX":
                mol.quadrupole_xx = val
            elif comp == "XY":
                mol.quadrupole_xy = val
            elif comp == "XZ":
                mol.quadrupole_xz = val
            elif comp == "YY":
                mol.quadrupole_yy = val
            elif comp == "YZ":
                mol.quadrupole_yz = val
            elif comp == "ZZ":
                mol.quadrupole_zz = val
        found = True

    quad_mag_pat = re.compile(
        rf"Magnitude of the traceless quadrupole moment tensor:\s+"
        rf"({FLOAT_PATTERN})"
    )
    # Find the one after "Molecular"
    mol_section = stdout[stdout.find("Molecular dipole") :]
    if match := quad_mag_pat.search(mol_section):
        mol.quadrupole_magnitude = float(match[1])

    mol_extent_pat = re.compile(
        rf"Molecular electronic spatial extent.*?:\s+"
        rf"({FLOAT_PATTERN})"
    )
    if match := mol_extent_pat.search(stdout):
        mol.spatial_extent_r2 = float(match[1])
        found = True

    mol_extent_comp = re.compile(
        rf"Components of <r\^2>:\s+X=\s+({FLOAT_PATTERN})\s+"
        rf"Y=\s+({FLOAT_PATTERN})\s+Z=\s+({FLOAT_PATTERN})"
    )
    # Take the last one (molecular, not atomic)
    matches = list(mol_extent_comp.finditer(stdout))
    if matches:
        m = matches[-1]
        mol.spatial_extent_x = float(m[1])
        mol.spatial_extent_y = float(m[2])
        mol.spatial_extent_z = float(m[3])

    octo_mag = re.compile(rf"Magnitude:\s+\|Q_3\|=\s+({FLOAT_PATTERN})")
    mol_octo_matches = list(octo_mag.finditer(mol_section))
    if mol_octo_matches:
        mol.octopole_magnitude = float(mol_octo_matches[-1][1])

    return mol if found else None

parse_overlap_matrices(stdout, integrated_property) classmethod

Extract positive/negative/all overlap integration matrices.

Source code in src/pymultiwfn/analysis/parsers.py
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
@classmethod
def parse_overlap_matrices(
    cls,
    stdout: str,
    integrated_property: str,
) -> list[OverlapIntegrationMatrix]:
    """Extract positive/negative/all overlap integration matrices."""
    results: list[OverlapIntegrationMatrix] = []

    header_pat = re.compile(
        r"\*+\s*Integration of\s+(positive|negative|all)\s+"
        r"values in overlap region\s*\*+",
        re.I,
    )
    col_header_pat = re.compile(r"^\s+(\d+(?:\s+\d+)*)\s*$")
    row_pat = re.compile(rf"^\s+(\d+)((?:\s+{FLOAT_PATTERN})+)\s*$")
    sum_diag_pat = re.compile(
        rf"Summing up diagonal.*?:\s+({FLOAT_PATTERN})"
    )
    sum_nondiag_pat = re.compile(
        rf"Summing up non-diagonal.*?:\s+({FLOAT_PATTERN})"
    )
    sum_all_pat = re.compile(rf"Summing up all.*?:\s+({FLOAT_PATTERN})")

    in_matrix = False
    category = ""
    current_cols: list[int] = []
    data: dict[tuple[int, int], float] = {}
    max_idx = 0
    sum_d: float | None = None
    sum_nd: float | None = None
    sum_a: float | None = None

    def _flush() -> None:
        nonlocal data, max_idx, category, in_matrix
        nonlocal sum_d, sum_nd, sum_a
        if data or sum_d is not None:
            results.append(
                OverlapIntegrationMatrix(
                    category=category,
                    integrated_property=integrated_property,
                    n_atoms=max_idx,
                    data=dict(data),
                    sum_diagonal=sum_d,
                    sum_nondiagonal=sum_nd,
                    sum_all=sum_a,
                )
            )
        data = {}
        max_idx = 0
        sum_d = None
        sum_nd = None
        sum_a = None
        in_matrix = False

    for line in stdout.split("\n"):
        if match := header_pat.search(line):
            if in_matrix:
                _flush()
            in_matrix = True
            category = match[1].lower()
            current_cols = []
            continue

        if not in_matrix:
            continue

        if match := sum_diag_pat.search(line):
            sum_d = float(match[1])
            continue
        if match := sum_nondiag_pat.search(line):
            sum_nd = float(match[1])
            continue
        if match := sum_all_pat.search(line):
            sum_a = float(match[1])
            _flush()
            continue

        if match := col_header_pat.match(line):
            current_cols = [int(v) for v in match[1].split()]
            continue

        if current_cols and (match := row_pat.match(line)):
            row_idx = int(match[1])
            vals = [float(v) for v in match[2].split()]
            for k, val in enumerate(vals):
                if k < len(current_cols):
                    col_idx = current_cols[k]
                    data[(row_idx, col_idx)] = val
                    if row_idx > max_idx:
                        max_idx = row_idx
                    if col_idx > max_idx:
                        max_idx = col_idx

    if in_matrix:
        _flush()

    return results

OrbitalCompositionParser

Bases: OutputParser

Parser for orbital composition analysis (Menu 8).

Produces OrbitalBasisComposition for methods that give per-basis detail (Mulliken/SCPA/Stout-Politzer), and OrbitalAtomComposition for methods that give only per-atom contributions (Hirshfeld/Becke/fragment).

Each orbital is stored separately with its orbital_id, energy, occupation, and type so that multiple orbitals in one stdout do not overwrite each other.

Source code in src/pymultiwfn/analysis/parsers.py
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
class OrbitalCompositionParser(OutputParser):
    """Parser for orbital composition analysis (Menu 8).

    Produces ``OrbitalBasisComposition`` for methods that give
    per-basis detail (Mulliken/SCPA/Stout-Politzer), and
    ``OrbitalAtomComposition`` for methods that give only per-atom
    contributions (Hirshfeld/Becke/fragment).

    Each orbital is stored separately with its orbital_id, energy,
    occupation, and type so that multiple orbitals in one stdout
    do not overwrite each other.
    """

    _OC_METHOD: dict[Menu, str] = {
        Menu.ORBITAL_COMPOSITION_MULLIKEN_ALL: "mulliken",
        Menu.ORBITAL_COMPOSITION_SCPA_ALL: "scpa",
        Menu.ORBITAL_COMPOSITION_STOUT_POLITZER_ALL: "stout_politzer",
        Menu.ORBITAL_COMPOSITION_FRAGMENT_MULLIKEN: "mulliken",
        Menu.ORBITAL_COMPOSITION_FRAGMENT_STOUT: "stout_politzer",
        Menu.ORBITAL_COMPOSITION_FRAGMENT_SCPA: "scpa",
        Menu.ORBITAL_COMPOSITION_NAO: "nao",
        Menu.ORBITAL_COMPOSITION_HIRSHFELD: "hirshfeld",
        Menu.ORBITAL_COMPOSITION_BECKE: "becke",
        Menu.LOBA_OXIDATION_STATE: "loba",
    }

    @classmethod
    def parse_for_result(
        cls,
        analysis: Menu,
        stdout: str,
    ) -> list[ParsedMultiwfnResult]:
        if analysis == Menu.LOBA_OXIDATION_STATE:
            return cls._collect(stdout, [cls.parse_oxidation_states])

        method = cls._OC_METHOD.get(analysis, "unknown")

        # Try full basis composition first
        basis_results = cls.parse_basis_compositions(stdout, method)
        if basis_results:
            return list(basis_results)

        # Fall back to atom-only composition
        atom_results = cls.parse_atom_compositions(stdout, method)
        if atom_results:
            return list(atom_results)

        return []

    # ── Full basis composition (Mulliken/SCPA/Stout-Politzer) ────────

    @staticmethod
    def parse_basis_compositions(
        stdout: str,
        method: str,
    ) -> list[OrbitalBasisComposition]:
        """Extract per-orbital full basis compositions.

        Each orbital block starts with an orbital header, followed by
        basis contributions, shell compositions, shell-type
        composition, atom compositions, and a delocalization index.
        """
        results: list[OrbitalBasisComposition] = []

        # Orbital header:
        # "Orbital:    21  Energy(a.u.):     -0.246939  Occ:  2.000000  Type: Alpha&Beta"  # noqa: E501
        orb_header_pat = re.compile(
            rf"Orbital:\s+(\d+)\s+Energy\(a\.u\.\):\s+({FLOAT_PATTERN})"
            rf"\s+Occ:\s+({FLOAT_PATTERN})\s+Type:\s+(\S+)"
        )

        # Basis contribution:
        # "    20   Z        2(C )    9      8.67678 %      5.61233 %     14.28911 %"  # noqa: E501
        basis_pat = re.compile(
            rf"^\s+(\d+)\s+([A-Z]+)\s+(\d+)\s*\(([A-Za-z]+)\s*\)\s+"
            rf"(\d+)\s+({FLOAT_PATTERN})\s*%\s+({FLOAT_PATTERN})\s*%"
            rf"\s+({FLOAT_PATTERN})\s*%"
        )

        # Shell composition:
        # "Shell     9 Type: P    in atom    2(C ) :    14.28911 %"
        shell_pat = re.compile(
            rf"Shell\s+(\d+)\s+Type:\s+(\S+)\s+in\s+atom\s+(\d+)"
            rf"\s*\(([A-Za-z]+)\s*\)\s*:\s+({FLOAT_PATTERN})\s*%"
        )

        # Shell-type composition:
        # "s:   0.000  p:  99.010  d:   0.990  f:   0.000  g:   0.000  h:   0.000"  # noqa: E501
        shell_type_pat = re.compile(
            rf"^\s*s:\s+({FLOAT_PATTERN})\s+p:\s+({FLOAT_PATTERN})\s+"
            rf"d:\s+({FLOAT_PATTERN})\s+f:\s+({FLOAT_PATTERN})\s+"
            rf"g:\s+({FLOAT_PATTERN})\s+h:\s+({FLOAT_PATTERN})"
        )

        # Atom composition:
        # "Atom     1(C ) :     0.30819 %"
        atom_pat = re.compile(
            rf"Atom\s+(\d+)\s*\(([A-Za-z]+)\s*\)\s*:\s+"
            rf"({FLOAT_PATTERN})\s*%"
        )

        # Delocalization index:
        # "Orbital delocalization index:   24.69"
        deloc_pat = re.compile(
            rf"Orbital delocalization index:\s+({FLOAT_PATTERN})"
        )

        # "Composition of each shell" / "Composition of different types"
        # / "Composition of each atom:" are section markers
        section_shell = re.compile(r"Composition of each shell")
        section_type = re.compile(r"Composition of different types of shells")
        section_atom = re.compile(r"Composition of each atom:")

        current: OrbitalBasisComposition | None = None
        in_basis = False
        in_shell = False
        in_type = False
        in_atom = False

        for line in stdout.split("\n"):
            # New orbital header
            if match := orb_header_pat.search(line):
                # Check if this is followed by basis data (not just
                # a listing).  We can't know yet, so start a new one
                # and discard later if it stays empty.
                if current is not None and (
                    current.basis_contributions or current.atom_contributions
                ):
                    results.append(current)
                current = OrbitalBasisComposition(
                    method=method,
                    orbital_id=int(match[1]),
                    energy_au=float(match[2]),
                    occupation=float(match[3]),
                    orbital_type=match[4],
                )
                in_basis = True
                in_shell = False
                in_type = False
                in_atom = False
                continue

            if current is None:
                continue

            # Section markers
            if section_shell.search(line):
                in_basis = False
                in_shell = True
                in_type = False
                in_atom = False
                continue
            if section_type.search(line):
                in_basis = False
                in_shell = False
                in_type = True
                in_atom = False
                continue
            if section_atom.search(line):
                in_basis = False
                in_shell = False
                in_type = False
                in_atom = True
                continue

            # Basis contributions
            if in_basis and (match := basis_pat.match(line)):
                current.basis_contributions.append(
                    OrbitalBasisEntry(
                        basis_index=int(match[1]),
                        function_type=match[2].strip(),
                        atom_id=int(match[3]),
                        atom_element=match[4].strip(),
                        shell_index=int(match[5]),
                        local_pct=float(match[6]),
                        cross_pct=float(match[7]),
                        total_pct=float(match[8]),
                    )
                )
                continue

            # Shell compositions
            if in_shell and (match := shell_pat.search(line)):
                current.shell_contributions.append(
                    OrbitalShellEntry(
                        shell_index=int(match[1]),
                        shell_type=match[2].strip(),
                        atom_id=int(match[3]),
                        atom_element=match[4].strip(),
                        composition_pct=float(match[5]),
                    )
                )
                continue

            # Shell-type composition
            if in_type and (match := shell_type_pat.search(line)):
                current.shell_type_composition = OrbitalShellTypeComposition(
                    s=float(match[1]),
                    p=float(match[2]),
                    d=float(match[3]),
                    f=float(match[4]),
                    g=float(match[5]),
                    h=float(match[6]),
                )
                in_type = False
                continue

            # Atom compositions
            if in_atom and (match := atom_pat.search(line)):
                current.atom_contributions.append(
                    OrbitalAtomEntry(
                        atom_id=int(match[1]),
                        atom_element=match[2].strip(),
                        composition_pct=float(match[3]),
                    )
                )
                continue

            # Delocalization index (ends the block)
            if match := deloc_pat.search(line):
                if current is not None:
                    current.delocalization_index = float(match[1])
                    if (
                        current.basis_contributions
                        or current.atom_contributions
                    ):
                        results.append(current)
                    current = None
                    in_basis = False
                    in_shell = False
                    in_type = False
                    in_atom = False
                continue

        # Flush last orbital if not already flushed
        if current is not None and (
            current.basis_contributions or current.atom_contributions
        ):
            results.append(current)

        return results

    # ── Atom-only composition (Hirshfeld/Becke/fragment) ─────────────

    @staticmethod
    def parse_atom_compositions(
        stdout: str,
        method: str,
    ) -> list[OrbitalAtomComposition]:
        """Extract per-orbital atom-only compositions.

        These outputs have an orbital header, optionally a sum before
        normalization, then "Contributions after normalization:" with
        per-atom percentages, and a delocalization index.
        """
        results: list[OrbitalAtomComposition] = []

        # Orbital header (same format but may have different spacing)
        orb_header_pat = re.compile(
            rf"Orbital:\s+(\d+)\s+Energy\(a\.u\.\):\s+({FLOAT_PATTERN})"
            rf"\s+Occ:\s+({FLOAT_PATTERN})\s+Type:\s+(\S+)"
        )

        # "The sum of contributions before normalization   99.999199 %"
        sum_before_pat = re.compile(
            rf"sum of contributions before normalization\s+"
            rf"({FLOAT_PATTERN})\s*%",
            re.I,
        )

        # "Contributions after normalization:"
        contrib_header = re.compile(
            r"Contributions after normalization:", re.I
        )

        # "Atom     1(C ) :      4.109 %"
        atom_pat = re.compile(
            rf"Atom\s+(\d+)\s*\(([A-Za-z]+)\s*\)\s*:\s+"
            rf"({FLOAT_PATTERN})\s*%"
        )

        # Delocalization index
        deloc_pat = re.compile(
            rf"Orbital delocalization index:\s+({FLOAT_PATTERN})"
        )

        current: OrbitalAtomComposition | None = None
        in_contrib = False

        for line in stdout.split("\n"):
            # New orbital header
            if match := orb_header_pat.search(line):
                if current is not None and current.atom_contributions:
                    results.append(current)
                current = OrbitalAtomComposition(
                    method=method,
                    orbital_id=int(match[1]),
                    energy_au=float(match[2]),
                    occupation=float(match[3]),
                    orbital_type=match[4],
                )
                in_contrib = False
                continue

            if current is None:
                continue

            # Sum before normalization
            if match := sum_before_pat.search(line):
                current.sum_before_normalization = float(match[1])
                continue

            # Contributions header
            if contrib_header.search(line):
                in_contrib = True
                continue

            # Atom contributions
            if in_contrib and (match := atom_pat.search(line)):
                current.atom_contributions.append(
                    OrbitalAtomEntry(
                        atom_id=int(match[1]),
                        atom_element=match[2].strip(),
                        composition_pct=float(match[3]),
                    )
                )
                continue

            # Delocalization index (ends the block)
            if match := deloc_pat.search(line):
                if current is not None:
                    current.delocalization_index = float(match[1])
                    if current.atom_contributions:
                        results.append(current)
                    current = None
                    in_contrib = False
                continue

        # Flush last
        if current is not None and current.atom_contributions:
            results.append(current)

        return results

    # ── LOBA oxidation states ────────────────────────────────────────

    @staticmethod
    def parse_oxidation_states(stdout: str) -> list[OxidationState]:
        """Extract LOBA oxidation states."""
        pattern = (
            rf"Atom\s+(\d+)\s*\([A-Za-z]+\s*\).*?"
            rf"oxidation state.*?({FLOAT_PATTERN})"
        )
        return [
            OxidationState(
                atom_id=int(match[1]),
                oxidation_state=int(round(float(match[2]))),
            )
            for match in re.finditer(pattern, stdout, re.IGNORECASE)
        ]

parse_atom_compositions(stdout, method) staticmethod

Extract per-orbital atom-only compositions.

These outputs have an orbital header, optionally a sum before normalization, then "Contributions after normalization:" with per-atom percentages, and a delocalization index.

Source code in src/pymultiwfn/analysis/parsers.py
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
@staticmethod
def parse_atom_compositions(
    stdout: str,
    method: str,
) -> list[OrbitalAtomComposition]:
    """Extract per-orbital atom-only compositions.

    These outputs have an orbital header, optionally a sum before
    normalization, then "Contributions after normalization:" with
    per-atom percentages, and a delocalization index.
    """
    results: list[OrbitalAtomComposition] = []

    # Orbital header (same format but may have different spacing)
    orb_header_pat = re.compile(
        rf"Orbital:\s+(\d+)\s+Energy\(a\.u\.\):\s+({FLOAT_PATTERN})"
        rf"\s+Occ:\s+({FLOAT_PATTERN})\s+Type:\s+(\S+)"
    )

    # "The sum of contributions before normalization   99.999199 %"
    sum_before_pat = re.compile(
        rf"sum of contributions before normalization\s+"
        rf"({FLOAT_PATTERN})\s*%",
        re.I,
    )

    # "Contributions after normalization:"
    contrib_header = re.compile(
        r"Contributions after normalization:", re.I
    )

    # "Atom     1(C ) :      4.109 %"
    atom_pat = re.compile(
        rf"Atom\s+(\d+)\s*\(([A-Za-z]+)\s*\)\s*:\s+"
        rf"({FLOAT_PATTERN})\s*%"
    )

    # Delocalization index
    deloc_pat = re.compile(
        rf"Orbital delocalization index:\s+({FLOAT_PATTERN})"
    )

    current: OrbitalAtomComposition | None = None
    in_contrib = False

    for line in stdout.split("\n"):
        # New orbital header
        if match := orb_header_pat.search(line):
            if current is not None and current.atom_contributions:
                results.append(current)
            current = OrbitalAtomComposition(
                method=method,
                orbital_id=int(match[1]),
                energy_au=float(match[2]),
                occupation=float(match[3]),
                orbital_type=match[4],
            )
            in_contrib = False
            continue

        if current is None:
            continue

        # Sum before normalization
        if match := sum_before_pat.search(line):
            current.sum_before_normalization = float(match[1])
            continue

        # Contributions header
        if contrib_header.search(line):
            in_contrib = True
            continue

        # Atom contributions
        if in_contrib and (match := atom_pat.search(line)):
            current.atom_contributions.append(
                OrbitalAtomEntry(
                    atom_id=int(match[1]),
                    atom_element=match[2].strip(),
                    composition_pct=float(match[3]),
                )
            )
            continue

        # Delocalization index (ends the block)
        if match := deloc_pat.search(line):
            if current is not None:
                current.delocalization_index = float(match[1])
                if current.atom_contributions:
                    results.append(current)
                current = None
                in_contrib = False
            continue

    # Flush last
    if current is not None and current.atom_contributions:
        results.append(current)

    return results

parse_basis_compositions(stdout, method) staticmethod

Extract per-orbital full basis compositions.

Each orbital block starts with an orbital header, followed by basis contributions, shell compositions, shell-type composition, atom compositions, and a delocalization index.

Source code in src/pymultiwfn/analysis/parsers.py
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
@staticmethod
def parse_basis_compositions(
    stdout: str,
    method: str,
) -> list[OrbitalBasisComposition]:
    """Extract per-orbital full basis compositions.

    Each orbital block starts with an orbital header, followed by
    basis contributions, shell compositions, shell-type
    composition, atom compositions, and a delocalization index.
    """
    results: list[OrbitalBasisComposition] = []

    # Orbital header:
    # "Orbital:    21  Energy(a.u.):     -0.246939  Occ:  2.000000  Type: Alpha&Beta"  # noqa: E501
    orb_header_pat = re.compile(
        rf"Orbital:\s+(\d+)\s+Energy\(a\.u\.\):\s+({FLOAT_PATTERN})"
        rf"\s+Occ:\s+({FLOAT_PATTERN})\s+Type:\s+(\S+)"
    )

    # Basis contribution:
    # "    20   Z        2(C )    9      8.67678 %      5.61233 %     14.28911 %"  # noqa: E501
    basis_pat = re.compile(
        rf"^\s+(\d+)\s+([A-Z]+)\s+(\d+)\s*\(([A-Za-z]+)\s*\)\s+"
        rf"(\d+)\s+({FLOAT_PATTERN})\s*%\s+({FLOAT_PATTERN})\s*%"
        rf"\s+({FLOAT_PATTERN})\s*%"
    )

    # Shell composition:
    # "Shell     9 Type: P    in atom    2(C ) :    14.28911 %"
    shell_pat = re.compile(
        rf"Shell\s+(\d+)\s+Type:\s+(\S+)\s+in\s+atom\s+(\d+)"
        rf"\s*\(([A-Za-z]+)\s*\)\s*:\s+({FLOAT_PATTERN})\s*%"
    )

    # Shell-type composition:
    # "s:   0.000  p:  99.010  d:   0.990  f:   0.000  g:   0.000  h:   0.000"  # noqa: E501
    shell_type_pat = re.compile(
        rf"^\s*s:\s+({FLOAT_PATTERN})\s+p:\s+({FLOAT_PATTERN})\s+"
        rf"d:\s+({FLOAT_PATTERN})\s+f:\s+({FLOAT_PATTERN})\s+"
        rf"g:\s+({FLOAT_PATTERN})\s+h:\s+({FLOAT_PATTERN})"
    )

    # Atom composition:
    # "Atom     1(C ) :     0.30819 %"
    atom_pat = re.compile(
        rf"Atom\s+(\d+)\s*\(([A-Za-z]+)\s*\)\s*:\s+"
        rf"({FLOAT_PATTERN})\s*%"
    )

    # Delocalization index:
    # "Orbital delocalization index:   24.69"
    deloc_pat = re.compile(
        rf"Orbital delocalization index:\s+({FLOAT_PATTERN})"
    )

    # "Composition of each shell" / "Composition of different types"
    # / "Composition of each atom:" are section markers
    section_shell = re.compile(r"Composition of each shell")
    section_type = re.compile(r"Composition of different types of shells")
    section_atom = re.compile(r"Composition of each atom:")

    current: OrbitalBasisComposition | None = None
    in_basis = False
    in_shell = False
    in_type = False
    in_atom = False

    for line in stdout.split("\n"):
        # New orbital header
        if match := orb_header_pat.search(line):
            # Check if this is followed by basis data (not just
            # a listing).  We can't know yet, so start a new one
            # and discard later if it stays empty.
            if current is not None and (
                current.basis_contributions or current.atom_contributions
            ):
                results.append(current)
            current = OrbitalBasisComposition(
                method=method,
                orbital_id=int(match[1]),
                energy_au=float(match[2]),
                occupation=float(match[3]),
                orbital_type=match[4],
            )
            in_basis = True
            in_shell = False
            in_type = False
            in_atom = False
            continue

        if current is None:
            continue

        # Section markers
        if section_shell.search(line):
            in_basis = False
            in_shell = True
            in_type = False
            in_atom = False
            continue
        if section_type.search(line):
            in_basis = False
            in_shell = False
            in_type = True
            in_atom = False
            continue
        if section_atom.search(line):
            in_basis = False
            in_shell = False
            in_type = False
            in_atom = True
            continue

        # Basis contributions
        if in_basis and (match := basis_pat.match(line)):
            current.basis_contributions.append(
                OrbitalBasisEntry(
                    basis_index=int(match[1]),
                    function_type=match[2].strip(),
                    atom_id=int(match[3]),
                    atom_element=match[4].strip(),
                    shell_index=int(match[5]),
                    local_pct=float(match[6]),
                    cross_pct=float(match[7]),
                    total_pct=float(match[8]),
                )
            )
            continue

        # Shell compositions
        if in_shell and (match := shell_pat.search(line)):
            current.shell_contributions.append(
                OrbitalShellEntry(
                    shell_index=int(match[1]),
                    shell_type=match[2].strip(),
                    atom_id=int(match[3]),
                    atom_element=match[4].strip(),
                    composition_pct=float(match[5]),
                )
            )
            continue

        # Shell-type composition
        if in_type and (match := shell_type_pat.search(line)):
            current.shell_type_composition = OrbitalShellTypeComposition(
                s=float(match[1]),
                p=float(match[2]),
                d=float(match[3]),
                f=float(match[4]),
                g=float(match[5]),
                h=float(match[6]),
            )
            in_type = False
            continue

        # Atom compositions
        if in_atom and (match := atom_pat.search(line)):
            current.atom_contributions.append(
                OrbitalAtomEntry(
                    atom_id=int(match[1]),
                    atom_element=match[2].strip(),
                    composition_pct=float(match[3]),
                )
            )
            continue

        # Delocalization index (ends the block)
        if match := deloc_pat.search(line):
            if current is not None:
                current.delocalization_index = float(match[1])
                if (
                    current.basis_contributions
                    or current.atom_contributions
                ):
                    results.append(current)
                current = None
                in_basis = False
                in_shell = False
                in_type = False
                in_atom = False
            continue

    # Flush last orbital if not already flushed
    if current is not None and (
        current.basis_contributions or current.atom_contributions
    ):
        results.append(current)

    return results

parse_oxidation_states(stdout) staticmethod

Extract LOBA oxidation states.

Source code in src/pymultiwfn/analysis/parsers.py
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
@staticmethod
def parse_oxidation_states(stdout: str) -> list[OxidationState]:
    """Extract LOBA oxidation states."""
    pattern = (
        rf"Atom\s+(\d+)\s*\([A-Za-z]+\s*\).*?"
        rf"oxidation state.*?({FLOAT_PATTERN})"
    )
    return [
        OxidationState(
            atom_id=int(match[1]),
            oxidation_state=int(round(float(match[2]))),
        )
        for match in re.finditer(pattern, stdout, re.IGNORECASE)
    ]

OutputParser

Base class for output parsers.

Subclasses must implement :meth:parse_for_result which receives the :class:Menu enum and raw stdout, and returns a list of :class:ParsedMultiwfnResult instances.

Source code in src/pymultiwfn/analysis/parsers.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
class OutputParser:
    """Base class for output parsers.

    Subclasses must implement :meth:`parse_for_result` which receives
    the :class:`Menu` enum and raw stdout, and returns a list of
    :class:`ParsedMultiwfnResult` instances.
    """

    # Type alias for callables used in case maps.  Each callable
    # accepts ``stdout`` and returns either a single result, a list of
    # results, or ``None``.
    _Parser = Any  # Callable[[str], ParsedMultiwfnResult | list | None]

    @classmethod
    def parse_for_result(
        cls,
        analysis: Menu,
        stdout: str,
    ) -> list[ParsedMultiwfnResult]:
        """Dispatch to the appropriate static helpers and return results.

        Subclasses override this to call their specific ``parse_*``
        methods and return a flat list.
        """
        raise NotImplementedError

    @staticmethod
    def _collect(
        stdout: str,
        parsers: list[Any],
    ) -> list[ParsedMultiwfnResult]:
        """Run *parsers* against *stdout* and flatten into a single list.

        Each entry in *parsers* is a callable ``(str) -> T`` where *T*
        may be:

        * a single :class:`ParsedMultiwfnResult` — appended directly
        * a ``list`` of results — extended into the output
        * ``None`` — skipped

        For dataclasses whose "empty" state is meaningful (e.g.
        ``Spectrum`` with no frequencies), the caller should wrap the
        parser in a lambda that returns ``None`` when empty.
        """
        results: list[ParsedMultiwfnResult] = []
        for fn in parsers:
            value = fn(stdout)
            if value is None:
                continue
            if isinstance(value, list):
                results.extend(value)
            else:
                results.append(value)
        return results

parse_for_result(analysis, stdout) classmethod

Dispatch to the appropriate static helpers and return results.

Subclasses override this to call their specific parse_* methods and return a flat list.

Source code in src/pymultiwfn/analysis/parsers.py
123
124
125
126
127
128
129
130
131
132
133
134
@classmethod
def parse_for_result(
    cls,
    analysis: Menu,
    stdout: str,
) -> list[ParsedMultiwfnResult]:
    """Dispatch to the appropriate static helpers and return results.

    Subclasses override this to call their specific ``parse_*``
    methods and return a flat list.
    """
    raise NotImplementedError

ParserRoute

Routing from Menu enums to OutputParser classes.

Source code in src/pymultiwfn/analysis/parsers.py
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
class ParserRoute:
    """Routing from Menu enums to OutputParser classes."""

    ROUTE_TABLE: dict[Menu, type[OutputParser]] = {
        # Menu 0 - View Sttructure
        Menu.VIEW_STRUCTURE: AtomListParser,
        # Menu 7 — charges
        Menu.HIRSHFELD_CHARGE: ChargeParser,
        Menu.VDD_POPULATION: ChargeParser,
        Menu.MULLIKEN_POPULATION: ChargeParser,
        Menu.LOWDIN_POPULATION: ChargeParser,
        Menu.SCPA_POPULATION: ChargeParser,
        Menu.STOUT_POLITZER_POPULATION: ChargeParser,
        Menu.BICKELHAUPT_POPULATION: ChargeParser,
        Menu.BECKE_CHARGE: ChargeParser,
        Menu.ADCH_CHARGE: ChargeParser,
        Menu.CHELPG_CHARGE: ChargeParser,
        Menu.MK_CHARGE: ChargeParser,
        Menu.CM5_CHARGE: ChargeParser,
        Menu.EEM_CHARGE: ChargeParser,
        Menu.RESP_CHARGE: ChargeParser,
        Menu.GASTEIGER_CHARGE: ChargeParser,
        Menu.MBIS_CHARGE: ChargeParser,
        # Menu 8 — orbital composition
        Menu.ORBITAL_COMPOSITION_MULLIKEN_ALL: OrbitalCompositionParser,
        Menu.ORBITAL_COMPOSITION_SCPA_ALL: OrbitalCompositionParser,
        Menu.ORBITAL_COMPOSITION_STOUT_POLITZER_ALL: OrbitalCompositionParser,
        Menu.ORBITAL_COMPOSITION_FRAGMENT_MULLIKEN: OrbitalCompositionParser,
        Menu.ORBITAL_COMPOSITION_FRAGMENT_STOUT: OrbitalCompositionParser,
        Menu.ORBITAL_COMPOSITION_FRAGMENT_SCPA: OrbitalCompositionParser,
        Menu.ORBITAL_COMPOSITION_NAO: OrbitalCompositionParser,
        Menu.ORBITAL_COMPOSITION_HIRSHFELD: OrbitalCompositionParser,
        Menu.ORBITAL_COMPOSITION_BECKE: OrbitalCompositionParser,
        Menu.LOBA_OXIDATION_STATE: OrbitalCompositionParser,
        # Menu 9 — bond orders
        Menu.MAYER_BOND_ORDER: BondOrderParser,
        Menu.WIBERG_BOND_ORDER: BondOrderParser,
        Menu.MULLIKEN_BOND_ORDER: BondOrderParser,
        Menu.FUZZY_BOND_ORDER: BondOrderParser,
        Menu.LAPLACIAN_BOND_ORDER: BondOrderParser,
        Menu.IBSI_ANALYSIS: BondOrderParser,
        Menu.MULTICENTER_BOND_ORDER: BondOrderParser,
        Menu.MULTICENTER_BOND_ORDER_NAO: BondOrderParser,
        Menu.MULLIKEN_BOND_ORDER_DECOMPOSE: BondOrderParser,
        Menu.ORBITAL_PERTURBED_MAYER: BondOrderParser,
        Menu.WIBERG_DECOMPOSITION: BondOrderParser,
        Menu.AV1245_INDEX: FuzzySpaceParser,
        # Menu 2 — topology
        Menu.TOPOLOGY_VISUALISE_CPS: CriticalPointParser,
        Menu.TOPOLOGY_CP_NUCLEAR_POSITION: CriticalPointParser,
        Menu.TOPOLOGY_CP_MIDPOINTS: CriticalPointParser,
        Menu.TOPOLOGY_CP_TRIANGLE_CENTRES: CriticalPointParser,
        Menu.TOPOLOGY_CP_PYRAMID_CENTRES: CriticalPointParser,
        Menu.TOPOLOGY_CP_SPHERE_POINTS: CriticalPointParser,
        Menu.TOPOLOGY_CP_REAL_SPACE_POINTS: CriticalPointParser,
        Menu.TOPOLOGY_CP_PATHS_3MINUS3_3MINUS1: CriticalPointParser,
        Menu.TOPOLOGY_CP_PATHS_3PLUS1_3PLUS3: CriticalPointParser,
        # Menu 10 — density of states
        Menu.PLOT_TDOS: DOSParser,
        Menu.PLOT_TDOS_OPDOS: DOSParser,
        # Menu 11 — spectra
        Menu.PLOT_IR_SPECTRUM: SpectrumParser,
        Menu.PLOT_RAMAN_SPECTRUM: SpectrumParser,
        Menu.PLOT_UV_VIS_SPECTRUM: SpectrumParser,
        Menu.PLOT_ECD_SPECTRUM: SpectrumParser,
        Menu.PLOT_VCD_SPECTRUM: SpectrumParser,
        Menu.PLOT_ROA_SPECTRUM: SpectrumParser,
        Menu.PLOT_NMR_SPECTRUM: SpectrumParser,
        Menu.PLOT_FLUORESCENCE_SPECTRUM: SpectrumParser,
        Menu.PLOT_PVS: SpectrumParser,
        Menu.PREDICT_COLOR: SpectrumParser,
        # Menu 12 — surface analysis
        Menu.SURFACE_ANALYSIS_ESP: SurfaceParser,
        Menu.SURFACE_ANALYSIS_ALIE: SurfaceParser,
        Menu.SURFACE_AREA_VOLUME: SurfaceParser,
        Menu.BECKE_SURFACE: SurfaceParser,
        Menu.HIRSHFELD_SURFACE: SurfaceParser,
        Menu.SURFACE_EXTREMA: SurfaceParser,
        Menu.HIRSHFELD_SURFACE_FINGERPRINT: SurfaceParser,
        # Menu 15 — fuzzy atomic space
        Menu.FUZZY_INTEGRATE_EDENSITY: FuzzySpaceParser,
        Menu.FUZZY_MULTIPOLE: FuzzySpaceParser,
        Menu.ATOMIC_OVERLAP_MATRIX: FuzzySpaceParser,
        Menu.LOCALIZATION_DELOCALIZATION_INDEX: FuzzySpaceParser,
        Menu.PDI_AROMATICITY: FuzzySpaceParser,
        Menu.FLU_AROMATICITY: FuzzySpaceParser,
        Menu.FLU_PI_AROMATICITY: FuzzySpaceParser,
        Menu.CONDENSED_LINEAR_RESPONSE: FuzzySpaceParser,
        Menu.PARA_LINEAR_RESPONSE: FuzzySpaceParser,
        Menu.FUZZY_OVERLAP_EDENSITY: FuzzySpaceParser,
        # Menu 17 — basin analysis
        Menu.BASIN_ANALYSIS_AIM: BasinParser,
        Menu.BASIN_ANALYSIS_ELF: BasinParser,
        Menu.BASIN_INTEGRATE_PROPERTY: BasinParser,
        Menu.BASIN_ANALYSIS_ESP: BasinParser,
        Menu.BASIN_ANALYSIS_LOL: BasinParser,
        Menu.BASIN_ANALYSIS_LOL_ALPHA: BasinParser,
        Menu.BASIN_ANALYSIS_CUSTOM: BasinParser,
        # Menu 18 — excitation analysis
        Menu.HOLE_ELECTRON_ANALYSIS: ExcitationParser,
        Menu.CHARGE_TRANSFER_ANALYSIS: ExcitationParser,
        Menu.DELTA_R_INDEX: ExcitationParser,
        Menu.LAMBDA_INDEX: ExcitationParser,
        Menu.IFCT_ANALYSIS: ExcitationParser,
        Menu.CTS_ANALYSIS: ExcitationParser,
        # Menu 20 — weak interactions
        Menu.NCI_ANALYSIS: WeakInteractionParser,
        Menu.NCI_PROMOLECULAR: WeakInteractionParser,
        Menu.ANCI_ANALYSIS: WeakInteractionParser,
        Menu.IRI_ANALYSIS: WeakInteractionParser,
        Menu.DORI_ANALYSIS: WeakInteractionParser,
        Menu.VDW_POTENTIAL: WeakInteractionParser,
        Menu.IGM_ANALYSIS: WeakInteractionParser,
        Menu.IGMH_ANALYSIS: WeakInteractionParser,
        Menu.AIGM_ANALYSIS: WeakInteractionParser,
        Menu.MIGM_ANALYSIS: WeakInteractionParser,
        Menu.AMIGM_ANALYSIS: WeakInteractionParser,
        # Menu 21 — EDA
        Menu.EDA_FF: EDAParser,
        Menu.EDA_SBL: EDAParser,
        Menu.SOBEDA_ANALYSIS: EDAParser,
        Menu.DISPERSION_ATOMIC_CONTRIBUTION: EDAParser,
        # Menu 22 — CDFT
        Menu.CDFT_ANALYSIS: CDFTParser,
        Menu.CONDENSED_FUKUI: CDFTParser,
        Menu.ORBITAL_WEIGHTED_FUKUI: CDFTParser,
        Menu.GRID_FUKUI: CDFTParser,
        Menu.LOCAL_HARDNESS: CDFTParser,
        # Menu 24 — polarizability
        Menu.PARSE_POLARIZABILITY: PolarizabilityParser,
        Menu.SOS_POLARIZABILITY: PolarizabilityParser,
        Menu.POLARIZABILITY_DENSITY: PolarizabilityParser,
        Menu.UNIT_SPHERE_POLARIZABILITY: PolarizabilityParser,
        # Menu 25 — aromaticity
        Menu.AICD_ANALYSIS: AromaticityParser,
        Menu.NICS_POINT: AromaticityParser,
        Menu.ICSS_ANALYSIS: AromaticityParser,
        Menu.NICS_SCAN: AromaticityParser,
        Menu.BIRD_INDEX: AromaticityParser,
        Menu.HOMA_INDEX: AromaticityParser,
        Menu.HOMAC_HOMER: AromaticityParser,
        Menu.STANGER_INDEX: AromaticityParser,
        Menu.NICS_1D_SCAN: AromaticityParser,
        Menu.NICS_2D_MAP: AromaticityParser,
        # Menu 5 — cube generation
        Menu.CUBE_DENSITY: CubeParser,
        Menu.CUBE_SPIN_DENSITY: CubeParser,
        Menu.CUBE_ELF: CubeParser,
        Menu.CUBE_LOL: CubeParser,
        Menu.CUBE_ESP: CubeParser,
        Menu.CUBE_LAPLACIAN: CubeParser,
        Menu.CUBE_GRADIENT_NORM: CubeParser,
        Menu.CUBE_KINETIC_G: CubeParser,
        Menu.CUBE_KINETIC_K: CubeParser,
        Menu.CUBE_ALIE: CubeParser,
        Menu.CUBE_RDG: CubeParser,
        Menu.CUBE_SIGN_LAMBDA2_RHO: CubeParser,
        Menu.CUBE_SOURCE_FUNCTION: CubeParser,
        Menu.CUBE_ORBITAL_WAVEFUNCTION: CubeParser,
        Menu.CUBE_FUKUI_MINUS: CubeParser,
        Menu.CUBE_FUKUI_PLUS: CubeParser,
        Menu.CUBE_DUAL_DESCRIPTOR: CubeParser,
        Menu.CUBE_PROMOLECULAR_DENSITY: CubeParser,
        Menu.CUBE_DEFORMATION_DENSITY: CubeParser,
        Menu.CUBE_DENSITY_HIGH: CubeParser,
        Menu.CUBE_ESP_HIGH: CubeParser,
        Menu.CUBE_ELF_HIGH: CubeParser,
        # Menu 100 — utilities
        Menu.GEOMETRY_PROPERTIES: UtilityParser,
        Menu.ELECTRIC_MULTIPOLE_MOMENTS: UtilityParser,
        Menu.BLA_BOA_ANALYSIS: UtilityParser,
    }

PolarizabilityParser

Bases: OutputParser

Parser for polarizability output.

Source code in src/pymultiwfn/analysis/parsers.py
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
class PolarizabilityParser(OutputParser):
    """Parser for polarizability output."""

    @classmethod
    def parse_for_result(
        cls,
        analysis: Menu,
        stdout: str,
    ) -> list[ParsedMultiwfnResult]:
        return [cls.parse(stdout)]

    @staticmethod
    def parse(stdout: str) -> Polarizability:
        """Extract polarizability tensor data."""
        result = Polarizability()

        iso_pat = (
            rf"[Ii]sotropic.*?(?:alpha|polarizability)"
            rf".*?[=:\s]+({FLOAT_PATTERN})"
        )
        if match := re.search(iso_pat, stdout):
            result.isotropic = float(match[1])

        aniso_pat = rf"[Aa]nisotropy.*?[=:\s]+({FLOAT_PATTERN})"
        if match := re.search(aniso_pat, stdout):
            result.anisotropic = float(match[1])

        beta_pat = rf"[Bb]eta.*?total[=:\s]+({FLOAT_PATTERN})"
        if match := re.search(beta_pat, stdout):
            result.beta_total = float(match[1])

        gamma_pat = rf"[Gg]amma.*?(?:total|average)[=:\s]+({FLOAT_PATTERN})"
        if match := re.search(gamma_pat, stdout):
            result.gamma_total = float(match[1])

        components: dict[str, float] = {}
        for comp in ["xx", "xy", "xz", "yy", "yz", "zz"]:
            pat = rf"alpha[_\s]*{comp}[=:\s]+({FLOAT_PATTERN})"
            if match := re.search(pat, stdout, re.IGNORECASE):
                components[f"alpha_{comp}"] = float(match[1])

        if components:
            result.tensor = PolarizabilityTensor(
                alpha_xx=components.get("alpha_xx", 0.0),
                alpha_xy=components.get("alpha_xy", 0.0),
                alpha_xz=components.get("alpha_xz", 0.0),
                alpha_yy=components.get("alpha_yy", 0.0),
                alpha_yz=components.get("alpha_yz", 0.0),
                alpha_zz=components.get("alpha_zz", 0.0),
            )

        return result

parse(stdout) staticmethod

Extract polarizability tensor data.

Source code in src/pymultiwfn/analysis/parsers.py
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
@staticmethod
def parse(stdout: str) -> Polarizability:
    """Extract polarizability tensor data."""
    result = Polarizability()

    iso_pat = (
        rf"[Ii]sotropic.*?(?:alpha|polarizability)"
        rf".*?[=:\s]+({FLOAT_PATTERN})"
    )
    if match := re.search(iso_pat, stdout):
        result.isotropic = float(match[1])

    aniso_pat = rf"[Aa]nisotropy.*?[=:\s]+({FLOAT_PATTERN})"
    if match := re.search(aniso_pat, stdout):
        result.anisotropic = float(match[1])

    beta_pat = rf"[Bb]eta.*?total[=:\s]+({FLOAT_PATTERN})"
    if match := re.search(beta_pat, stdout):
        result.beta_total = float(match[1])

    gamma_pat = rf"[Gg]amma.*?(?:total|average)[=:\s]+({FLOAT_PATTERN})"
    if match := re.search(gamma_pat, stdout):
        result.gamma_total = float(match[1])

    components: dict[str, float] = {}
    for comp in ["xx", "xy", "xz", "yy", "yz", "zz"]:
        pat = rf"alpha[_\s]*{comp}[=:\s]+({FLOAT_PATTERN})"
        if match := re.search(pat, stdout, re.IGNORECASE):
            components[f"alpha_{comp}"] = float(match[1])

    if components:
        result.tensor = PolarizabilityTensor(
            alpha_xx=components.get("alpha_xx", 0.0),
            alpha_xy=components.get("alpha_xy", 0.0),
            alpha_xz=components.get("alpha_xz", 0.0),
            alpha_yy=components.get("alpha_yy", 0.0),
            alpha_yz=components.get("alpha_yz", 0.0),
            alpha_zz=components.get("alpha_zz", 0.0),
        )

    return result

SpectrumParser

Bases: OutputParser

Parser for spectrum data.

Source code in src/pymultiwfn/analysis/parsers.py
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
class SpectrumParser(OutputParser):
    """Parser for spectrum data."""

    @classmethod
    def _parse_spectrum_or_none(cls, stdout: str) -> Spectrum | None:
        """Return parsed spectrum only if it contains data."""
        s = cls.parse(stdout)
        return (
            s if (s.frequencies or s.wavelengths or s.atom_indices) else None
        )

    @classmethod
    def parse_for_result(
        cls,
        analysis: Menu,
        stdout: str,
    ) -> list[ParsedMultiwfnResult]:
        base: list = [
            cls._parse_spectrum_or_none,
            cls.parse_spectrum_curve_extrema,
            cls.parse_transitions,
        ]
        case_map: dict[Menu, list] = {
            Menu.PREDICT_COLOR: [*base, cls.parse_color],
        }
        parsers = case_map.get(analysis, base)
        return cls._collect(stdout, parsers)

    @staticmethod
    def parse(stdout: str) -> Spectrum:
        """Extract spectrum data (frequencies/wavelengths, intensities)."""
        spectrum: dict[str, list[float]] = {
            "frequencies": [],
            "intensities": [],
        }

        pattern1 = (
            rf"({FLOAT_PATTERN})\s+cm\^?-1.*?Intensity:\s+({FLOAT_PATTERN})"
        )
        pattern_uv = (
            rf"({FLOAT_PATTERN})\s+nm.*?(?:f=|Str[.=])\s*({FLOAT_PATTERN})"
        )
        pattern_nmr = rf"Atom\s+(\d+)\s*\([^)]+\)\s+shift:\s+({FLOAT_PATTERN})"
        pattern2 = rf"^\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s*$"

        for match in re.finditer(pattern1, stdout):
            spectrum["frequencies"].append(float(match[1]))
            spectrum["intensities"].append(float(match[2]))

        if spectrum["frequencies"]:
            return Spectrum(
                frequencies=spectrum["frequencies"],
                intensities=spectrum["intensities"],
            )

        uv_data: dict[str, list[float]] = {
            "wavelengths": [],
            "intensities": [],
        }
        for match in re.finditer(pattern_uv, stdout):
            uv_data["wavelengths"].append(float(match[1]))
            uv_data["intensities"].append(float(match[2]))
        if uv_data["wavelengths"]:
            return Spectrum(
                wavelengths=uv_data["wavelengths"],
                intensities=uv_data["intensities"],
            )

        nmr_data: dict[str, list[float]] = {
            "atom_indices": [],
            "chemical_shifts": [],
        }
        for match in re.finditer(pattern_nmr, stdout):
            nmr_data["atom_indices"].append(float(match[1]))
            nmr_data["chemical_shifts"].append(float(match[2]))
        if nmr_data["atom_indices"]:
            return Spectrum(
                atom_indices=[int(x) for x in nmr_data["atom_indices"]],
                chemical_shifts=nmr_data["chemical_shifts"],
            )

        for line in stdout.split("\n"):
            if match2 := re.match(pattern2, line):
                spectrum["frequencies"].append(float(match2[1]))
                spectrum["intensities"].append(float(match2[2]))

        return Spectrum(
            frequencies=spectrum["frequencies"],
            intensities=spectrum["intensities"],
        )

    @staticmethod
    def parse_transitions(stdout: str) -> list[Transition]:
        """Extract discrete transition data."""
        transitions: list[Transition] = []
        pattern = (
            rf"Excited state\s+(\d+).*?E=\s*({FLOAT_PATTERN})\s*eV.*?"
            rf"lam=\s*({FLOAT_PATTERN})\s*nm.*?"
            rf"f=\s*({FLOAT_PATTERN})"
        )
        rot_pattern = rf"R.*?=\s*({FLOAT_PATTERN})"

        lines = stdout.split("\n")
        for i, line in enumerate(lines):
            if match := re.search(pattern, line):
                rot_strength = None
                combined = line
                if i + 1 < len(lines):
                    combined += lines[i + 1]
                if rot_match := re.search(rot_pattern, combined):
                    rot_strength = float(rot_match[1])
                transitions.append(
                    Transition(
                        state=int(match[1]),
                        energy_eV=float(match[2]),
                        wavelength_nm=float(match[3]),
                        osc_strength=float(match[4]),
                        rot_strength=rot_strength,
                    )
                )
        return transitions

    @staticmethod
    def parse_spectrum_curve_extrema(
        stdout: str,
    ) -> SpectrumCurveExtrema | None:
        """Extract extrema reported under spectrum-curve extrema blocks."""
        if "Extrema on the spectrum curve" not in stdout:
            return None

        pattern = (
            rf"(Maximum|Minimum)\s+(\d+)\s+X:\s*({FLOAT_PATTERN})\s+"
            rf"Value:\s*({FLOAT_PATTERN})\.?"
        )

        extrema: list[SpectrumExtremum] = []
        for match in re.finditer(pattern, stdout, flags=re.IGNORECASE):
            kind = match[1].lower()
            extrema.append(
                SpectrumExtremum(
                    kind="maximum" if kind == "maximum" else "minimum",
                    index=int(match[2]),
                    x=float(match[3]),
                    value=float(match[4]),
                )
            )

        if not extrema:
            return None
        return SpectrumCurveExtrema(extrema=extrema)

    @staticmethod
    def parse_color(stdout: str) -> Color | None:
        """Extract predicted colour from PREDICT_COLOR output."""
        result: dict[str, Any] = {}
        for pat_name, pat in [
            ("X", rf"X=\s*({FLOAT_PATTERN})"),
            ("Y", rf"Y=\s*({FLOAT_PATTERN})"),
            ("Z", rf"Z=\s*({FLOAT_PATTERN})"),
            ("R", r"R=\s*(\d+)"),
            ("G", r"G=\s*(\d+)"),
            ("B", r"B=\s*(\d+)"),
        ]:
            if m := re.search(pat, stdout):
                result[pat_name] = (
                    int(m[1]) if pat_name in ("R", "G", "B") else float(m[1])
                )
        return Color(**result) if result else None

parse(stdout) staticmethod

Extract spectrum data (frequencies/wavelengths, intensities).

Source code in src/pymultiwfn/analysis/parsers.py
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
@staticmethod
def parse(stdout: str) -> Spectrum:
    """Extract spectrum data (frequencies/wavelengths, intensities)."""
    spectrum: dict[str, list[float]] = {
        "frequencies": [],
        "intensities": [],
    }

    pattern1 = (
        rf"({FLOAT_PATTERN})\s+cm\^?-1.*?Intensity:\s+({FLOAT_PATTERN})"
    )
    pattern_uv = (
        rf"({FLOAT_PATTERN})\s+nm.*?(?:f=|Str[.=])\s*({FLOAT_PATTERN})"
    )
    pattern_nmr = rf"Atom\s+(\d+)\s*\([^)]+\)\s+shift:\s+({FLOAT_PATTERN})"
    pattern2 = rf"^\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s*$"

    for match in re.finditer(pattern1, stdout):
        spectrum["frequencies"].append(float(match[1]))
        spectrum["intensities"].append(float(match[2]))

    if spectrum["frequencies"]:
        return Spectrum(
            frequencies=spectrum["frequencies"],
            intensities=spectrum["intensities"],
        )

    uv_data: dict[str, list[float]] = {
        "wavelengths": [],
        "intensities": [],
    }
    for match in re.finditer(pattern_uv, stdout):
        uv_data["wavelengths"].append(float(match[1]))
        uv_data["intensities"].append(float(match[2]))
    if uv_data["wavelengths"]:
        return Spectrum(
            wavelengths=uv_data["wavelengths"],
            intensities=uv_data["intensities"],
        )

    nmr_data: dict[str, list[float]] = {
        "atom_indices": [],
        "chemical_shifts": [],
    }
    for match in re.finditer(pattern_nmr, stdout):
        nmr_data["atom_indices"].append(float(match[1]))
        nmr_data["chemical_shifts"].append(float(match[2]))
    if nmr_data["atom_indices"]:
        return Spectrum(
            atom_indices=[int(x) for x in nmr_data["atom_indices"]],
            chemical_shifts=nmr_data["chemical_shifts"],
        )

    for line in stdout.split("\n"):
        if match2 := re.match(pattern2, line):
            spectrum["frequencies"].append(float(match2[1]))
            spectrum["intensities"].append(float(match2[2]))

    return Spectrum(
        frequencies=spectrum["frequencies"],
        intensities=spectrum["intensities"],
    )

parse_color(stdout) staticmethod

Extract predicted colour from PREDICT_COLOR output.

Source code in src/pymultiwfn/analysis/parsers.py
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
@staticmethod
def parse_color(stdout: str) -> Color | None:
    """Extract predicted colour from PREDICT_COLOR output."""
    result: dict[str, Any] = {}
    for pat_name, pat in [
        ("X", rf"X=\s*({FLOAT_PATTERN})"),
        ("Y", rf"Y=\s*({FLOAT_PATTERN})"),
        ("Z", rf"Z=\s*({FLOAT_PATTERN})"),
        ("R", r"R=\s*(\d+)"),
        ("G", r"G=\s*(\d+)"),
        ("B", r"B=\s*(\d+)"),
    ]:
        if m := re.search(pat, stdout):
            result[pat_name] = (
                int(m[1]) if pat_name in ("R", "G", "B") else float(m[1])
            )
    return Color(**result) if result else None

parse_spectrum_curve_extrema(stdout) staticmethod

Extract extrema reported under spectrum-curve extrema blocks.

Source code in src/pymultiwfn/analysis/parsers.py
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
@staticmethod
def parse_spectrum_curve_extrema(
    stdout: str,
) -> SpectrumCurveExtrema | None:
    """Extract extrema reported under spectrum-curve extrema blocks."""
    if "Extrema on the spectrum curve" not in stdout:
        return None

    pattern = (
        rf"(Maximum|Minimum)\s+(\d+)\s+X:\s*({FLOAT_PATTERN})\s+"
        rf"Value:\s*({FLOAT_PATTERN})\.?"
    )

    extrema: list[SpectrumExtremum] = []
    for match in re.finditer(pattern, stdout, flags=re.IGNORECASE):
        kind = match[1].lower()
        extrema.append(
            SpectrumExtremum(
                kind="maximum" if kind == "maximum" else "minimum",
                index=int(match[2]),
                x=float(match[3]),
                value=float(match[4]),
            )
        )

    if not extrema:
        return None
    return SpectrumCurveExtrema(extrema=extrema)

parse_transitions(stdout) staticmethod

Extract discrete transition data.

Source code in src/pymultiwfn/analysis/parsers.py
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
@staticmethod
def parse_transitions(stdout: str) -> list[Transition]:
    """Extract discrete transition data."""
    transitions: list[Transition] = []
    pattern = (
        rf"Excited state\s+(\d+).*?E=\s*({FLOAT_PATTERN})\s*eV.*?"
        rf"lam=\s*({FLOAT_PATTERN})\s*nm.*?"
        rf"f=\s*({FLOAT_PATTERN})"
    )
    rot_pattern = rf"R.*?=\s*({FLOAT_PATTERN})"

    lines = stdout.split("\n")
    for i, line in enumerate(lines):
        if match := re.search(pattern, line):
            rot_strength = None
            combined = line
            if i + 1 < len(lines):
                combined += lines[i + 1]
            if rot_match := re.search(rot_pattern, combined):
                rot_strength = float(rot_match[1])
            transitions.append(
                Transition(
                    state=int(match[1]),
                    energy_eV=float(match[2]),
                    wavelength_nm=float(match[3]),
                    osc_strength=float(match[4]),
                    rot_strength=rot_strength,
                )
            )
    return transitions

SurfaceParser

Bases: OutputParser

Parser for molecular surface analysis output (Menu 12).

Source code in src/pymultiwfn/analysis/parsers.py
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
class SurfaceParser(OutputParser):
    """Parser for molecular surface analysis output (Menu 12)."""

    _SURFACE_PROPERTY: dict[Menu, str] = {
        Menu.SURFACE_ANALYSIS_ESP: "esp",
        Menu.SURFACE_ANALYSIS_ALIE: "alie",
        Menu.SURFACE_AREA_VOLUME: "area_volume",
        Menu.BECKE_SURFACE: "becke",
        Menu.HIRSHFELD_SURFACE: "hirshfeld",
        Menu.SURFACE_EXTREMA: "surface_extrema",
        Menu.HIRSHFELD_SURFACE_FINGERPRINT: "hirshfeld_surface_fingerprint",
    }

    @classmethod
    def parse_for_result(
        cls,
        analysis: Menu,
        stdout: str,
    ) -> list[ParsedMultiwfnResult]:
        mapped_property = cls._SURFACE_PROPERTY.get(analysis, "unknown")
        result = cls.parse(stdout, mapped_property)
        return [result] if result is not None else []

    @classmethod
    def parse(
        cls,
        stdout: str,
        mapped_property: str,
    ) -> SurfaceAnalysisResult | None:
        """Parse full surface analysis output into one result."""
        geometry = cls.parse_geometry(stdout)
        minima = cls.parse_extrema(stdout, "min")
        maxima = cls.parse_extrema(stdout, "max")
        statistics = cls.parse_statistics(stdout, mapped_property)

        # Only return if we found something meaningful
        if (
            geometry is None
            and not minima
            and not maxima
            and statistics is None
        ):
            return None

        return SurfaceAnalysisResult(
            mapped_property=mapped_property,
            geometry=geometry,
            minima=minima,
            maxima=maxima,
            statistics=statistics,
        )

    # ── Geometry ─────────────────────────────────────────────────────

    @staticmethod
    def parse_geometry(stdout: str) -> SurfaceGeometry | None:
        """Extract isosurface geometry data."""
        geo = SurfaceGeometry()
        found = False

        # Volume
        vol_pat = re.compile(
            rf"Volume.*?:\s+({FLOAT_PATTERN})\s+Bohr\^3\s+"
            rf"\(\s*({FLOAT_PATTERN})\s+Angstrom\^3\)",
            re.I,
        )
        if match := vol_pat.search(stdout):
            geo.volume_bohr3 = float(match[1])
            geo.volume_angstrom3 = float(match[2])
            found = True

        # Area
        area_pat = re.compile(
            rf"(?:Isosurface|Overall surface)\s+area:\s+"
            rf"({FLOAT_PATTERN})\s+Bohr\^2\s+"
            rf"\(\s*({FLOAT_PATTERN})\s+Angstrom\^2\)",
            re.I,
        )
        if match := area_pat.search(stdout):
            geo.area_bohr2 = float(match[1])
            geo.area_angstrom2 = float(match[2])
            found = True

        # Sphericity
        sph_pat = re.compile(rf"Sphericity:\s+({FLOAT_PATTERN})")
        if match := sph_pat.search(stdout):
            geo.sphericity = float(match[1])
            found = True

        # Density
        dens_pat = re.compile(
            rf"Estimated density.*?:\s+({FLOAT_PATTERN})\s+g/cm\^3",
            re.I,
        )
        if match := dens_pat.search(stdout):
            geo.density_g_cm3 = float(match[1])
            found = True

        # Vertices/edges/facets (after elimination)
        vef_pat = re.compile(
            r"After elimination.*?V=\s*(\d+).*?E=\s*(\d+).*?"
            r"F=\s*(\d+)"
        )
        if match := vef_pat.search(stdout):
            geo.n_vertices = int(match[1])
            geo.n_edges = int(match[2])
            geo.n_facets = int(match[3])
            found = True

        return geo if found else None

    # ── Extrema ──────────────────────────────────────────────────────

    @staticmethod
    def parse_extrema(
        stdout: str,
        ext_type: Literal["min", "max"],
    ) -> list[SurfaceExtremum]:
        """Extract surface minima or maxima table."""
        extrema: list[SurfaceExtremum] = []

        # Section header
        if ext_type == "min":
            header_pat = re.compile(r"The number of surface minima:\s+(\d+)")
        else:
            header_pat = re.compile(r"The number of surface maxima:\s+(\d+)")

        # Entry line (with optional * for global):
        # "*    1 -0.02750965   -0.748576  -17.262580   -0.225  0.366  -1.831"
        # "     1 -0.02750962   -0.748575  -17.262563   -0.431  0.028  -1.831"
        entry_pat = re.compile(
            rf"^\s*(\*?)\s*(\d+)\s+({FLOAT_PATTERN})\s+"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+"
            rf"({FLOAT_PATTERN})"
        )

        in_section = False
        for line in stdout.split("\n"):
            if header_pat.search(line):
                in_section = True
                continue
            if in_section:
                # End of section: blank line or next section header
                if (
                    line.strip() == ""
                    or "The number of surface" in line
                    or "Summary of surface" in line
                ):
                    if extrema:
                        break
                    continue
                # Skip the column header line
                if "#" in line and "a.u." in line:
                    continue
                if match := entry_pat.match(line):
                    extrema.append(
                        SurfaceExtremum(
                            type=ext_type,
                            index=int(match[2]),
                            value_au=float(match[3]),
                            value_eV=float(match[4]),
                            value_kcal_mol=float(match[5]),
                            x_angstrom=float(match[6]),
                            y_angstrom=float(match[7]),
                            z_angstrom=float(match[8]),
                            is_global=match[1] == "*",
                        )
                    )

        return extrema

    # ── Statistics ───────────────────────────────────────────────────

    @staticmethod
    def parse_statistics(
        stdout: str,
        mapped_property: str,
    ) -> SurfaceStatistics | None:
        """Extract the Summary of surface analysis block."""
        # Find the summary section
        summary_start = stdout.find("Summary of surface analysis")
        if summary_start == -1:
            return None

        block = stdout[summary_start:]
        stats = SurfaceStatistics(mapped_property=mapped_property)
        found = False

        # Helper to search within block
        def _get(pattern: str, flags: int = re.I) -> re.Match[str] | None:
            return re.search(pattern, block, flags)

        # ── Global extrema from summary ──
        # "Minimal value:    -17.26258 kcal/mol   Maximal value:     11.82103 kcal/mol"  # noqa: E501
        minmax_pat = (
            rf"Minimal value:\s+({FLOAT_PATTERN})\s+kcal/mol\s+"
            rf"Maximal value:\s+({FLOAT_PATTERN})\s+kcal/mol"
        )
        if match := _get(minmax_pat):
            stats.global_min_kcal_mol = float(match[1])
            stats.global_max_kcal_mol = float(match[2])
            found = True

        # Global min/max in a.u. from the pre-summary lines
        gmin_pat = rf"Global surface minimum:\s+({FLOAT_PATTERN})\s+a\.u\."
        gmax_pat = rf"Global surface maximum:\s+({FLOAT_PATTERN})\s+a\.u\."
        if match := re.search(gmin_pat, stdout):
            stats.global_min_au = float(match[1])
            found = True
        if match := re.search(gmax_pat, stdout):
            stats.global_max_au = float(match[1])
            found = True

        # ── Areas ──
        # "Overall surface area:  448.293 Bohr^2  ( 125.535 Angstrom^2)"
        area_both = (
            rf"({FLOAT_PATTERN})\s+Bohr\^2\s+"
            rf"\(\s*({FLOAT_PATTERN})\s+Angstrom\^2\)"
        )
        if match := _get(r"Overall surface area:\s+" + area_both):
            stats.overall_area_bohr2 = float(match[1])
            stats.overall_area_angstrom2 = float(match[2])
            found = True
        if match := _get(r"Positive surface area:\s+" + area_both):
            stats.positive_area_bohr2 = float(match[1])
            stats.positive_area_angstrom2 = float(match[2])
            found = True
        if match := _get(r"Negative surface area:\s+" + area_both):
            stats.negative_area_bohr2 = float(match[1])
            stats.negative_area_angstrom2 = float(match[2])
            found = True

        # ── Averages ──
        # "Overall average value:  0.00002044 a.u. (  0.01282 kcal/mol)"
        avg_both = (
            rf"({FLOAT_PATTERN})\s+a\.u\.\s+"
            rf"\(\s*({FLOAT_PATTERN})\s+kcal/mol\)"
        )
        if match := _get(r"Overall average value:\s+" + avg_both):
            stats.overall_average_au = float(match[1])
            stats.overall_average_kcal_mol = float(match[2])
            found = True
        if match := _get(r"Positive average value:\s+" + avg_both):
            stats.positive_average_au = float(match[1])
            stats.positive_average_kcal_mol = float(match[2])
            found = True
        if match := _get(r"Negative average value:\s+" + avg_both):
            stats.negative_average_au = float(match[1])
            stats.negative_average_kcal_mol = float(match[2])
            found = True

        # ── Variances ──
        # "Overall variance (sigma^2_tot):  0.00009608 a.u.^2 (  37.83 (kcal/mol)^2)"  # noqa: E501
        var_both = (
            rf"({FLOAT_PATTERN})\s+a\.u\.\^2\s+"
            rf"\(\s*({FLOAT_PATTERN})\s+\(kcal/mol\)\^2\)"
        )
        if match := _get(r"Overall variance.*?sigma.*?:\s+" + var_both):
            stats.sigma2_total_au2 = float(match[1])
            stats.sigma2_total_kcal_mol2 = float(match[2])
            found = True
        if match := _get(r"Positive variance:\s+" + var_both):
            stats.positive_variance_au2 = float(match[1])
            stats.positive_variance_kcal_mol2 = float(match[2])
            found = True
        if match := _get(r"Negative variance:\s+" + var_both):
            stats.negative_variance_au2 = float(match[1])
            stats.negative_variance_kcal_mol2 = float(match[2])
            found = True

        # ── Nu ──
        # "Balance of charges (nu):   0.19601755"
        if match := _get(rf"Balance of charges.*?:\s+({FLOAT_PATTERN})"):
            stats.nu = float(match[1])
            found = True

        # ── sigma^2_tot * nu ──
        # "Product of sigma^2_tot and nu:  0.00001883 a.u.^2 (  7.416 (kcal/mol)^2)"  # noqa: E501
        if match := _get(r"Product of sigma.*?nu:\s+" + var_both):
            stats.sigma2_tot_times_nu_au2 = float(match[1])
            stats.sigma2_tot_times_nu_kcal_mol2 = float(match[2])
            found = True

        # ── Pi ──
        # "Internal charge separation (Pi):  0.01236 a.u. (  7.757 kcal/mol)"
        if match := _get(r"Internal charge separation.*?:\s+" + avg_both):
            stats.pi_au = float(match[1])
            stats.pi_kcal_mol = float(match[2])
            found = True

        # ── MPI ──
        # "Molecular polarity index (MPI):  0.33644 eV (  7.758 kcal/mol)"
        mpi_pat = (
            rf"Molecular polarity index.*?:\s+"
            rf"({FLOAT_PATTERN})\s+eV\s+"
            rf"\(\s*({FLOAT_PATTERN})\s+kcal/mol\)"
        )
        if match := _get(mpi_pat):
            stats.mpi_eV = float(match[1])
            stats.mpi_kcal_mol = float(match[2])
            found = True

        # ── Polar/nonpolar area ──
        # "Nonpolar surface area (|ESP| <= 10 kcal/mol):  88.18 Angstrom^2  ( 70.25 %)"  # noqa: E501
        nonpolar_pat = (
            rf"Nonpolar surface area.*?:\s+"
            rf"({FLOAT_PATTERN})\s+Angstrom\^2\s+"
            rf"\(\s*({FLOAT_PATTERN})\s*%\s*\)"
        )
        if match := _get(nonpolar_pat):
            stats.nonpolar_area_angstrom2 = float(match[1])
            stats.nonpolar_area_pct = float(match[2])
            found = True

        polar_pat = (
            rf"Polar surface area.*?:\s+"
            rf"({FLOAT_PATTERN})\s+Angstrom\^2\s+"
            rf"\(\s*({FLOAT_PATTERN})\s*%\s*\)"
        )
        if match := _get(polar_pat):
            stats.polar_area_angstrom2 = float(match[1])
            stats.polar_area_pct = float(match[2])
            found = True

        # ── Skewness ──
        if match := _get(rf"Overall skewness:\s+({FLOAT_PATTERN})"):
            stats.overall_skewness = float(match[1])
            found = True
        if match := _get(rf"Positive skewness:\s+({FLOAT_PATTERN})"):
            stats.positive_skewness = float(match[1])
            found = True
        if match := _get(rf"Negative skewness:\s+({FLOAT_PATTERN})"):
            stats.negative_skewness = float(match[1])
            found = True

        return stats if found else None

parse(stdout, mapped_property) classmethod

Parse full surface analysis output into one result.

Source code in src/pymultiwfn/analysis/parsers.py
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
@classmethod
def parse(
    cls,
    stdout: str,
    mapped_property: str,
) -> SurfaceAnalysisResult | None:
    """Parse full surface analysis output into one result."""
    geometry = cls.parse_geometry(stdout)
    minima = cls.parse_extrema(stdout, "min")
    maxima = cls.parse_extrema(stdout, "max")
    statistics = cls.parse_statistics(stdout, mapped_property)

    # Only return if we found something meaningful
    if (
        geometry is None
        and not minima
        and not maxima
        and statistics is None
    ):
        return None

    return SurfaceAnalysisResult(
        mapped_property=mapped_property,
        geometry=geometry,
        minima=minima,
        maxima=maxima,
        statistics=statistics,
    )

parse_extrema(stdout, ext_type) staticmethod

Extract surface minima or maxima table.

Source code in src/pymultiwfn/analysis/parsers.py
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
@staticmethod
def parse_extrema(
    stdout: str,
    ext_type: Literal["min", "max"],
) -> list[SurfaceExtremum]:
    """Extract surface minima or maxima table."""
    extrema: list[SurfaceExtremum] = []

    # Section header
    if ext_type == "min":
        header_pat = re.compile(r"The number of surface minima:\s+(\d+)")
    else:
        header_pat = re.compile(r"The number of surface maxima:\s+(\d+)")

    # Entry line (with optional * for global):
    # "*    1 -0.02750965   -0.748576  -17.262580   -0.225  0.366  -1.831"
    # "     1 -0.02750962   -0.748575  -17.262563   -0.431  0.028  -1.831"
    entry_pat = re.compile(
        rf"^\s*(\*?)\s*(\d+)\s+({FLOAT_PATTERN})\s+"
        rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+"
        rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+"
        rf"({FLOAT_PATTERN})"
    )

    in_section = False
    for line in stdout.split("\n"):
        if header_pat.search(line):
            in_section = True
            continue
        if in_section:
            # End of section: blank line or next section header
            if (
                line.strip() == ""
                or "The number of surface" in line
                or "Summary of surface" in line
            ):
                if extrema:
                    break
                continue
            # Skip the column header line
            if "#" in line and "a.u." in line:
                continue
            if match := entry_pat.match(line):
                extrema.append(
                    SurfaceExtremum(
                        type=ext_type,
                        index=int(match[2]),
                        value_au=float(match[3]),
                        value_eV=float(match[4]),
                        value_kcal_mol=float(match[5]),
                        x_angstrom=float(match[6]),
                        y_angstrom=float(match[7]),
                        z_angstrom=float(match[8]),
                        is_global=match[1] == "*",
                    )
                )

    return extrema

parse_geometry(stdout) staticmethod

Extract isosurface geometry data.

Source code in src/pymultiwfn/analysis/parsers.py
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
@staticmethod
def parse_geometry(stdout: str) -> SurfaceGeometry | None:
    """Extract isosurface geometry data."""
    geo = SurfaceGeometry()
    found = False

    # Volume
    vol_pat = re.compile(
        rf"Volume.*?:\s+({FLOAT_PATTERN})\s+Bohr\^3\s+"
        rf"\(\s*({FLOAT_PATTERN})\s+Angstrom\^3\)",
        re.I,
    )
    if match := vol_pat.search(stdout):
        geo.volume_bohr3 = float(match[1])
        geo.volume_angstrom3 = float(match[2])
        found = True

    # Area
    area_pat = re.compile(
        rf"(?:Isosurface|Overall surface)\s+area:\s+"
        rf"({FLOAT_PATTERN})\s+Bohr\^2\s+"
        rf"\(\s*({FLOAT_PATTERN})\s+Angstrom\^2\)",
        re.I,
    )
    if match := area_pat.search(stdout):
        geo.area_bohr2 = float(match[1])
        geo.area_angstrom2 = float(match[2])
        found = True

    # Sphericity
    sph_pat = re.compile(rf"Sphericity:\s+({FLOAT_PATTERN})")
    if match := sph_pat.search(stdout):
        geo.sphericity = float(match[1])
        found = True

    # Density
    dens_pat = re.compile(
        rf"Estimated density.*?:\s+({FLOAT_PATTERN})\s+g/cm\^3",
        re.I,
    )
    if match := dens_pat.search(stdout):
        geo.density_g_cm3 = float(match[1])
        found = True

    # Vertices/edges/facets (after elimination)
    vef_pat = re.compile(
        r"After elimination.*?V=\s*(\d+).*?E=\s*(\d+).*?"
        r"F=\s*(\d+)"
    )
    if match := vef_pat.search(stdout):
        geo.n_vertices = int(match[1])
        geo.n_edges = int(match[2])
        geo.n_facets = int(match[3])
        found = True

    return geo if found else None

parse_statistics(stdout, mapped_property) staticmethod

Extract the Summary of surface analysis block.

Source code in src/pymultiwfn/analysis/parsers.py
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
@staticmethod
def parse_statistics(
    stdout: str,
    mapped_property: str,
) -> SurfaceStatistics | None:
    """Extract the Summary of surface analysis block."""
    # Find the summary section
    summary_start = stdout.find("Summary of surface analysis")
    if summary_start == -1:
        return None

    block = stdout[summary_start:]
    stats = SurfaceStatistics(mapped_property=mapped_property)
    found = False

    # Helper to search within block
    def _get(pattern: str, flags: int = re.I) -> re.Match[str] | None:
        return re.search(pattern, block, flags)

    # ── Global extrema from summary ──
    # "Minimal value:    -17.26258 kcal/mol   Maximal value:     11.82103 kcal/mol"  # noqa: E501
    minmax_pat = (
        rf"Minimal value:\s+({FLOAT_PATTERN})\s+kcal/mol\s+"
        rf"Maximal value:\s+({FLOAT_PATTERN})\s+kcal/mol"
    )
    if match := _get(minmax_pat):
        stats.global_min_kcal_mol = float(match[1])
        stats.global_max_kcal_mol = float(match[2])
        found = True

    # Global min/max in a.u. from the pre-summary lines
    gmin_pat = rf"Global surface minimum:\s+({FLOAT_PATTERN})\s+a\.u\."
    gmax_pat = rf"Global surface maximum:\s+({FLOAT_PATTERN})\s+a\.u\."
    if match := re.search(gmin_pat, stdout):
        stats.global_min_au = float(match[1])
        found = True
    if match := re.search(gmax_pat, stdout):
        stats.global_max_au = float(match[1])
        found = True

    # ── Areas ──
    # "Overall surface area:  448.293 Bohr^2  ( 125.535 Angstrom^2)"
    area_both = (
        rf"({FLOAT_PATTERN})\s+Bohr\^2\s+"
        rf"\(\s*({FLOAT_PATTERN})\s+Angstrom\^2\)"
    )
    if match := _get(r"Overall surface area:\s+" + area_both):
        stats.overall_area_bohr2 = float(match[1])
        stats.overall_area_angstrom2 = float(match[2])
        found = True
    if match := _get(r"Positive surface area:\s+" + area_both):
        stats.positive_area_bohr2 = float(match[1])
        stats.positive_area_angstrom2 = float(match[2])
        found = True
    if match := _get(r"Negative surface area:\s+" + area_both):
        stats.negative_area_bohr2 = float(match[1])
        stats.negative_area_angstrom2 = float(match[2])
        found = True

    # ── Averages ──
    # "Overall average value:  0.00002044 a.u. (  0.01282 kcal/mol)"
    avg_both = (
        rf"({FLOAT_PATTERN})\s+a\.u\.\s+"
        rf"\(\s*({FLOAT_PATTERN})\s+kcal/mol\)"
    )
    if match := _get(r"Overall average value:\s+" + avg_both):
        stats.overall_average_au = float(match[1])
        stats.overall_average_kcal_mol = float(match[2])
        found = True
    if match := _get(r"Positive average value:\s+" + avg_both):
        stats.positive_average_au = float(match[1])
        stats.positive_average_kcal_mol = float(match[2])
        found = True
    if match := _get(r"Negative average value:\s+" + avg_both):
        stats.negative_average_au = float(match[1])
        stats.negative_average_kcal_mol = float(match[2])
        found = True

    # ── Variances ──
    # "Overall variance (sigma^2_tot):  0.00009608 a.u.^2 (  37.83 (kcal/mol)^2)"  # noqa: E501
    var_both = (
        rf"({FLOAT_PATTERN})\s+a\.u\.\^2\s+"
        rf"\(\s*({FLOAT_PATTERN})\s+\(kcal/mol\)\^2\)"
    )
    if match := _get(r"Overall variance.*?sigma.*?:\s+" + var_both):
        stats.sigma2_total_au2 = float(match[1])
        stats.sigma2_total_kcal_mol2 = float(match[2])
        found = True
    if match := _get(r"Positive variance:\s+" + var_both):
        stats.positive_variance_au2 = float(match[1])
        stats.positive_variance_kcal_mol2 = float(match[2])
        found = True
    if match := _get(r"Negative variance:\s+" + var_both):
        stats.negative_variance_au2 = float(match[1])
        stats.negative_variance_kcal_mol2 = float(match[2])
        found = True

    # ── Nu ──
    # "Balance of charges (nu):   0.19601755"
    if match := _get(rf"Balance of charges.*?:\s+({FLOAT_PATTERN})"):
        stats.nu = float(match[1])
        found = True

    # ── sigma^2_tot * nu ──
    # "Product of sigma^2_tot and nu:  0.00001883 a.u.^2 (  7.416 (kcal/mol)^2)"  # noqa: E501
    if match := _get(r"Product of sigma.*?nu:\s+" + var_both):
        stats.sigma2_tot_times_nu_au2 = float(match[1])
        stats.sigma2_tot_times_nu_kcal_mol2 = float(match[2])
        found = True

    # ── Pi ──
    # "Internal charge separation (Pi):  0.01236 a.u. (  7.757 kcal/mol)"
    if match := _get(r"Internal charge separation.*?:\s+" + avg_both):
        stats.pi_au = float(match[1])
        stats.pi_kcal_mol = float(match[2])
        found = True

    # ── MPI ──
    # "Molecular polarity index (MPI):  0.33644 eV (  7.758 kcal/mol)"
    mpi_pat = (
        rf"Molecular polarity index.*?:\s+"
        rf"({FLOAT_PATTERN})\s+eV\s+"
        rf"\(\s*({FLOAT_PATTERN})\s+kcal/mol\)"
    )
    if match := _get(mpi_pat):
        stats.mpi_eV = float(match[1])
        stats.mpi_kcal_mol = float(match[2])
        found = True

    # ── Polar/nonpolar area ──
    # "Nonpolar surface area (|ESP| <= 10 kcal/mol):  88.18 Angstrom^2  ( 70.25 %)"  # noqa: E501
    nonpolar_pat = (
        rf"Nonpolar surface area.*?:\s+"
        rf"({FLOAT_PATTERN})\s+Angstrom\^2\s+"
        rf"\(\s*({FLOAT_PATTERN})\s*%\s*\)"
    )
    if match := _get(nonpolar_pat):
        stats.nonpolar_area_angstrom2 = float(match[1])
        stats.nonpolar_area_pct = float(match[2])
        found = True

    polar_pat = (
        rf"Polar surface area.*?:\s+"
        rf"({FLOAT_PATTERN})\s+Angstrom\^2\s+"
        rf"\(\s*({FLOAT_PATTERN})\s*%\s*\)"
    )
    if match := _get(polar_pat):
        stats.polar_area_angstrom2 = float(match[1])
        stats.polar_area_pct = float(match[2])
        found = True

    # ── Skewness ──
    if match := _get(rf"Overall skewness:\s+({FLOAT_PATTERN})"):
        stats.overall_skewness = float(match[1])
        found = True
    if match := _get(rf"Positive skewness:\s+({FLOAT_PATTERN})"):
        stats.positive_skewness = float(match[1])
        found = True
    if match := _get(rf"Negative skewness:\s+({FLOAT_PATTERN})"):
        stats.negative_skewness = float(match[1])
        found = True

    return stats if found else None

UtilityParser

Bases: OutputParser

Parser for utility function outputs.

Source code in src/pymultiwfn/analysis/parsers.py
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
class UtilityParser(OutputParser):
    """Parser for utility function outputs."""

    @classmethod
    def parse_for_result(
        cls,
        analysis: Menu,
        stdout: str,
    ) -> list[ParsedMultiwfnResult]:
        case_map: dict[Menu, list] = {
            Menu.GEOMETRY_PROPERTIES: [
                cls.parse_bond_lengths,
                cls.parse_bond_angles,
                cls.parse_dihedral_angles,
            ],
            Menu.ELECTRIC_MULTIPOLE_MOMENTS: [
                cls.parse_electric_multipole_moment_report,
                cls.parse_dipole_moments,
                cls.parse_quadrupole_moments,
            ],
            Menu.BLA_BOA_ANALYSIS: [cls.parse_bla_boa],
        }
        default = [
            cls.parse_bond_lengths,
            cls.parse_bond_angles,
            cls.parse_dihedral_angles,
            cls.parse_dipole_moments,
            cls.parse_coordination_numbers,
        ]
        parsers = case_map.get(analysis, default)
        return cls._collect(stdout, parsers)

    @staticmethod
    def parse_bond_lengths(stdout: str) -> list[BondLength]:
        """Extract bond length information."""
        bl_pattern = (
            rf"Bond length.*?atom\s+(\d+).*?(?:and|atom)\s+(\d+).*?:\s+"
            rf"({FLOAT_PATTERN})"
        )
        return [
            BondLength(
                atom1_id=int(match[1]),
                atom2_id=int(match[2]),
                length=float(match[3]),
            )
            for match in re.finditer(bl_pattern, stdout, re.IGNORECASE)
        ]

    @staticmethod
    def parse_bond_angles(stdout: str) -> list[BondAngle]:
        """Extract bond angle information."""
        ang_pattern = (
            rf"[Aa]ngle\s+(\d+)\s*-\s*(\d+)\s*-\s*(\d+)\s*:\s+"
            rf"({FLOAT_PATTERN})"
        )
        return [
            BondAngle(
                atom1_id=int(match[1]),
                atom2_id=int(match[2]),
                atom3_id=int(match[3]),
                angle=float(match[4]),
            )
            for match in re.finditer(ang_pattern, stdout)
        ]

    @staticmethod
    def parse_dihedral_angles(stdout: str) -> list[DihedralAngle]:
        """Extract dihedral angle information."""
        dih_pattern = (
            rf"[Dd]ihedral\s+(\d+)\s*-\s*(\d+)\s*-\s*(\d+)\s*-\s*(\d+)"
            rf"\s*:\s+({FLOAT_PATTERN})"
        )
        return [
            DihedralAngle(
                atom1_id=int(match[1]),
                atom2_id=int(match[2]),
                atom3_id=int(match[3]),
                atom4_id=int(match[4]),
                angle=float(match[5]),
            )
            for match in re.finditer(dih_pattern, stdout)
        ]

    @staticmethod
    def parse_dipole_moments(stdout: str) -> DipoleMoment | None:
        """Extract electric dipole moment."""
        xyz_pat = (
            rf"[Dd]ipole.*?X[=:\s]+({FLOAT_PATTERN})\s+"
            rf"Y[=:\s]+({FLOAT_PATTERN})\s+Z[=:\s]+({FLOAT_PATTERN})"
        )
        plain_triplet_pat = (
            rf"[Dd]ipole moment\s*\((?:a\.u\.|Debye)\)\s*:\s*"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
        )
        if match := re.search(xyz_pat, stdout):
            return DipoleMoment(
                x=float(match[1]),
                y=float(match[2]),
                z=float(match[3]),
                total=(
                    float(match[1]) ** 2
                    + float(match[2]) ** 2
                    + float(match[3]) ** 2
                )
                ** 0.5,
            )
        if match := re.search(plain_triplet_pat, stdout, re.IGNORECASE):
            return DipoleMoment(
                x=float(match[1]),
                y=float(match[2]),
                z=float(match[3]),
                total=(
                    float(match[1]) ** 2
                    + float(match[2]) ** 2
                    + float(match[3]) ** 2
                )
                ** 0.5,
            )
        return None

    @staticmethod
    def parse_quadrupole_moments(stdout: str) -> QuadrupoleMoment | None:
        """Extract electric quadrupole moment."""
        moments: dict[str, float] = {}
        for comp in ["XX", "XY", "XZ", "YY", "YZ", "ZZ"]:
            pat = rf"[Qq]uadrupole.*?{comp}[=:\s]+({FLOAT_PATTERN})"
            if m := re.search(pat, stdout):
                moments[comp] = float(m[1])

        if moments:
            return QuadrupoleMoment(
                xx=moments.get("XX"),
                xy=moments.get("XY"),
                xz=moments.get("XZ"),
                yy=moments.get("YY"),
                yz=moments.get("YZ"),
                zz=moments.get("ZZ"),
            )
        return None

    @staticmethod
    def parse_coordination_numbers(
        stdout: str,
    ) -> list[CoordinationNumber]:
        """Extract atomic coordination numbers."""
        pattern = rf"Atom\s+(\d+).*?coordination.*?[=:\s]+({FLOAT_PATTERN})"
        return [
            CoordinationNumber(
                atom_id=int(match[1]),
                coordination_number=float(match[2]),
            )
            for match in re.finditer(pattern, stdout, re.IGNORECASE)
        ]

    @staticmethod
    def parse_bla_boa(stdout: str) -> BLA_BOA:
        """Extract Bond length alternation and bond order alternation."""
        bla = None
        boa = None

        bla_pat = rf"BLA[=:\s]+({FLOAT_PATTERN})"
        if match := re.search(bla_pat, stdout, re.IGNORECASE):
            bla = float(match[1])

        boa_pat = rf"BOA[=:\s]+({FLOAT_PATTERN})"
        if match := re.search(boa_pat, stdout, re.IGNORECASE):
            boa = float(match[1])

        return BLA_BOA(bla=bla, boa=boa)

    @staticmethod
    def parse_electric_multipole_moment_report(
        stdout: str,
    ) -> ElectricMultipoleMomentReport | None:
        """Extract Menu 300 electric multipole analysis report."""
        if (
            "Quadrupole moments" not in stdout
            and "Dipole moment" not in stdout
        ):
            return None

        def _vec(pattern: str) -> tuple[float, float, float] | None:
            if m := re.search(pattern, stdout, re.IGNORECASE):
                return (float(m[1]), float(m[2]), float(m[3]))
            return None

        def _section(start: str, end_markers: list[str]) -> str:
            start_idx = stdout.find(start)
            if start_idx < 0:
                return ""
            end_idx = len(stdout)
            for marker in end_markers:
                idx = stdout.find(marker, start_idx + len(start))
                if idx >= 0:
                    end_idx = min(end_idx, idx)
            return stdout[start_idx:end_idx]

        def _pairs(section_text: str, key_pattern: str) -> dict[str, float]:
            return {
                m[1].replace(" ", ""): float(m[2])
                for m in re.finditer(
                    rf"({key_pattern})\s*=\s*({FLOAT_PATTERN})",
                    section_text,
                    re.IGNORECASE,
                )
            }

        quadrupole_standard_text = _section(
            "Quadrupole moments (Standard Cartesian form):",
            ["Quadrupole moments (Traceless Cartesian form):"],
        )
        quadrupole_traceless_text = _section(
            "Quadrupole moments (Traceless Cartesian form):",
            [
                "Magnitude of the traceless quadrupole moment tensor:",
                "Quadrupole moments (Spherical harmonic form):",
            ],
        )
        quadrupole_spherical_text = _section(
            "Quadrupole moments (Spherical harmonic form):",
            ["Magnitude: |Q_2|="],
        )
        octopole_cartesian_text = _section(
            "Octopole moments (Cartesian form):",
            ["Octopole moments (Spherical harmonic form):"],
        )
        octopole_spherical_text = _section(
            "Octopole moments (Spherical harmonic form):",
            ["Magnitude: |Q_3|="],
        )
        hexadecapole_text = _section(
            "Hexadecapole moments:",
            ["Electronic spatial extent <r^2>:"],
        )

        quadrupole_traceless_magnitude = None
        if m := re.search(
            rf"Magnitude of the traceless quadrupole moment tensor:\s*"
            rf"({FLOAT_PATTERN})",
            stdout,
            re.IGNORECASE,
        ):
            quadrupole_traceless_magnitude = float(m[1])

        quadrupole_spherical_magnitude = None
        if m := re.search(
            rf"Magnitude:\s*\|Q_2\|=\s*({FLOAT_PATTERN})",
            stdout,
            re.IGNORECASE,
        ):
            quadrupole_spherical_magnitude = float(m[1])

        octopole_spherical_magnitude = None
        if m := re.search(
            rf"Magnitude:\s*\|Q_3\|=\s*({FLOAT_PATTERN})",
            stdout,
            re.IGNORECASE,
        ):
            octopole_spherical_magnitude = float(m[1])

        dipole_magnitude_au = None
        dipole_magnitude_debye = None
        if m := re.search(
            rf"Magnitude of dipole moment:\s*({FLOAT_PATTERN})\s*a\.u\.\s*"
            rf"({FLOAT_PATTERN})\s*Debye",
            stdout,
            re.IGNORECASE,
        ):
            dipole_magnitude_au = float(m[1])
            dipole_magnitude_debye = float(m[2])

        spatial_extent_r2 = None
        if m := re.search(
            rf"Electronic spatial extent\s*<r\^2>:\s*({FLOAT_PATTERN})",
            stdout,
            re.IGNORECASE,
        ):
            spatial_extent_r2 = float(m[1])

        spatial_extent_components = None
        if m := re.search(
            rf"Components of <r\^2>:\s*X=\s*({FLOAT_PATTERN})\s*"
            rf"Y=\s*({FLOAT_PATTERN})\s*Z=\s*({FLOAT_PATTERN})",
            stdout,
            re.IGNORECASE,
        ):
            spatial_extent_components = (
                float(m[1]),
                float(m[2]),
                float(m[3]),
            )

        report = ElectricMultipoleMomentReport(
            positive_charge_center_angstrom=_vec(
                rf"X,\s*Y,\s*Z of center of positive charges.*?\n\s*"
                rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
            ),
            negative_charge_center_angstrom=_vec(
                rf"X,\s*Y,\s*Z of center of negative charges.*?\n\s*"
                rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
            ),
            nuclear_dipole_au=_vec(
                rf"Dipole moment from nuclear charges\s*\(a\.u\.\):\s*"
                rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
            ),
            electronic_dipole_au=_vec(
                rf"Dipole moment from electrons\s*\(a\.u\.\):\s*"
                rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
            ),
            total_dipole_au=_vec(
                rf"Dipole moment\s*\(a\.u\.\):\s*"
                rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
            ),
            total_dipole_debye=_vec(
                rf"Dipole moment\s*\(Debye\):\s*"
                rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
            ),
            dipole_magnitude_au=dipole_magnitude_au,
            dipole_magnitude_debye=dipole_magnitude_debye,
            quadrupole_standard_cartesian=_pairs(
                quadrupole_standard_text,
                r"XX|XY|XZ|YX|YY|YZ|ZX|ZY|ZZ",
            ),
            quadrupole_traceless_cartesian=_pairs(
                quadrupole_traceless_text,
                r"XX|XY|XZ|YX|YY|YZ|ZX|ZY|ZZ",
            ),
            quadrupole_traceless_magnitude=quadrupole_traceless_magnitude,
            quadrupole_spherical_harmonic=_pairs(
                quadrupole_spherical_text,
                r"Q_2,\s*-?\d",
            ),
            quadrupole_spherical_magnitude=quadrupole_spherical_magnitude,
            octopole_cartesian=_pairs(
                octopole_cartesian_text,
                r"XXX|YYY|ZZZ|XYY|XXY|XXZ|XZZ|YZZ|YYZ|XYZ",
            ),
            octopole_spherical_harmonic=_pairs(
                octopole_spherical_text,
                r"Q_3,\s*-?\d",
            ),
            octopole_spherical_magnitude=octopole_spherical_magnitude,
            hexadecapole=_pairs(
                hexadecapole_text,
                r"XXXX|YYYY|ZZZZ|XXXY|XXXZ|YYYX|YYYZ|ZZZX|ZZZY|XXYY|XXZZ|YYZZ|XXYZ|YYXZ|ZZXY",
            ),
            electronic_spatial_extent_r2=spatial_extent_r2,
            electronic_spatial_extent_components=spatial_extent_components,
        )

        has_data = any(
            [
                report.positive_charge_center_angstrom is not None,
                report.negative_charge_center_angstrom is not None,
                report.nuclear_dipole_au is not None,
                report.electronic_dipole_au is not None,
                report.total_dipole_au is not None,
                report.total_dipole_debye is not None,
                report.dipole_magnitude_au is not None,
                bool(report.quadrupole_standard_cartesian),
                bool(report.quadrupole_traceless_cartesian),
                report.quadrupole_traceless_magnitude is not None,
                bool(report.quadrupole_spherical_harmonic),
                report.quadrupole_spherical_magnitude is not None,
                bool(report.octopole_cartesian),
                bool(report.octopole_spherical_harmonic),
                report.octopole_spherical_magnitude is not None,
                bool(report.hexadecapole),
                report.electronic_spatial_extent_r2 is not None,
                report.electronic_spatial_extent_components is not None,
            ]
        )
        return report if has_data else None

parse_bla_boa(stdout) staticmethod

Extract Bond length alternation and bond order alternation.

Source code in src/pymultiwfn/analysis/parsers.py
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
@staticmethod
def parse_bla_boa(stdout: str) -> BLA_BOA:
    """Extract Bond length alternation and bond order alternation."""
    bla = None
    boa = None

    bla_pat = rf"BLA[=:\s]+({FLOAT_PATTERN})"
    if match := re.search(bla_pat, stdout, re.IGNORECASE):
        bla = float(match[1])

    boa_pat = rf"BOA[=:\s]+({FLOAT_PATTERN})"
    if match := re.search(boa_pat, stdout, re.IGNORECASE):
        boa = float(match[1])

    return BLA_BOA(bla=bla, boa=boa)

parse_bond_angles(stdout) staticmethod

Extract bond angle information.

Source code in src/pymultiwfn/analysis/parsers.py
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
@staticmethod
def parse_bond_angles(stdout: str) -> list[BondAngle]:
    """Extract bond angle information."""
    ang_pattern = (
        rf"[Aa]ngle\s+(\d+)\s*-\s*(\d+)\s*-\s*(\d+)\s*:\s+"
        rf"({FLOAT_PATTERN})"
    )
    return [
        BondAngle(
            atom1_id=int(match[1]),
            atom2_id=int(match[2]),
            atom3_id=int(match[3]),
            angle=float(match[4]),
        )
        for match in re.finditer(ang_pattern, stdout)
    ]

parse_bond_lengths(stdout) staticmethod

Extract bond length information.

Source code in src/pymultiwfn/analysis/parsers.py
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
@staticmethod
def parse_bond_lengths(stdout: str) -> list[BondLength]:
    """Extract bond length information."""
    bl_pattern = (
        rf"Bond length.*?atom\s+(\d+).*?(?:and|atom)\s+(\d+).*?:\s+"
        rf"({FLOAT_PATTERN})"
    )
    return [
        BondLength(
            atom1_id=int(match[1]),
            atom2_id=int(match[2]),
            length=float(match[3]),
        )
        for match in re.finditer(bl_pattern, stdout, re.IGNORECASE)
    ]

parse_coordination_numbers(stdout) staticmethod

Extract atomic coordination numbers.

Source code in src/pymultiwfn/analysis/parsers.py
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
@staticmethod
def parse_coordination_numbers(
    stdout: str,
) -> list[CoordinationNumber]:
    """Extract atomic coordination numbers."""
    pattern = rf"Atom\s+(\d+).*?coordination.*?[=:\s]+({FLOAT_PATTERN})"
    return [
        CoordinationNumber(
            atom_id=int(match[1]),
            coordination_number=float(match[2]),
        )
        for match in re.finditer(pattern, stdout, re.IGNORECASE)
    ]

parse_dihedral_angles(stdout) staticmethod

Extract dihedral angle information.

Source code in src/pymultiwfn/analysis/parsers.py
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
@staticmethod
def parse_dihedral_angles(stdout: str) -> list[DihedralAngle]:
    """Extract dihedral angle information."""
    dih_pattern = (
        rf"[Dd]ihedral\s+(\d+)\s*-\s*(\d+)\s*-\s*(\d+)\s*-\s*(\d+)"
        rf"\s*:\s+({FLOAT_PATTERN})"
    )
    return [
        DihedralAngle(
            atom1_id=int(match[1]),
            atom2_id=int(match[2]),
            atom3_id=int(match[3]),
            atom4_id=int(match[4]),
            angle=float(match[5]),
        )
        for match in re.finditer(dih_pattern, stdout)
    ]

parse_dipole_moments(stdout) staticmethod

Extract electric dipole moment.

Source code in src/pymultiwfn/analysis/parsers.py
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
@staticmethod
def parse_dipole_moments(stdout: str) -> DipoleMoment | None:
    """Extract electric dipole moment."""
    xyz_pat = (
        rf"[Dd]ipole.*?X[=:\s]+({FLOAT_PATTERN})\s+"
        rf"Y[=:\s]+({FLOAT_PATTERN})\s+Z[=:\s]+({FLOAT_PATTERN})"
    )
    plain_triplet_pat = (
        rf"[Dd]ipole moment\s*\((?:a\.u\.|Debye)\)\s*:\s*"
        rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
    )
    if match := re.search(xyz_pat, stdout):
        return DipoleMoment(
            x=float(match[1]),
            y=float(match[2]),
            z=float(match[3]),
            total=(
                float(match[1]) ** 2
                + float(match[2]) ** 2
                + float(match[3]) ** 2
            )
            ** 0.5,
        )
    if match := re.search(plain_triplet_pat, stdout, re.IGNORECASE):
        return DipoleMoment(
            x=float(match[1]),
            y=float(match[2]),
            z=float(match[3]),
            total=(
                float(match[1]) ** 2
                + float(match[2]) ** 2
                + float(match[3]) ** 2
            )
            ** 0.5,
        )
    return None

parse_electric_multipole_moment_report(stdout) staticmethod

Extract Menu 300 electric multipole analysis report.

Source code in src/pymultiwfn/analysis/parsers.py
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
@staticmethod
def parse_electric_multipole_moment_report(
    stdout: str,
) -> ElectricMultipoleMomentReport | None:
    """Extract Menu 300 electric multipole analysis report."""
    if (
        "Quadrupole moments" not in stdout
        and "Dipole moment" not in stdout
    ):
        return None

    def _vec(pattern: str) -> tuple[float, float, float] | None:
        if m := re.search(pattern, stdout, re.IGNORECASE):
            return (float(m[1]), float(m[2]), float(m[3]))
        return None

    def _section(start: str, end_markers: list[str]) -> str:
        start_idx = stdout.find(start)
        if start_idx < 0:
            return ""
        end_idx = len(stdout)
        for marker in end_markers:
            idx = stdout.find(marker, start_idx + len(start))
            if idx >= 0:
                end_idx = min(end_idx, idx)
        return stdout[start_idx:end_idx]

    def _pairs(section_text: str, key_pattern: str) -> dict[str, float]:
        return {
            m[1].replace(" ", ""): float(m[2])
            for m in re.finditer(
                rf"({key_pattern})\s*=\s*({FLOAT_PATTERN})",
                section_text,
                re.IGNORECASE,
            )
        }

    quadrupole_standard_text = _section(
        "Quadrupole moments (Standard Cartesian form):",
        ["Quadrupole moments (Traceless Cartesian form):"],
    )
    quadrupole_traceless_text = _section(
        "Quadrupole moments (Traceless Cartesian form):",
        [
            "Magnitude of the traceless quadrupole moment tensor:",
            "Quadrupole moments (Spherical harmonic form):",
        ],
    )
    quadrupole_spherical_text = _section(
        "Quadrupole moments (Spherical harmonic form):",
        ["Magnitude: |Q_2|="],
    )
    octopole_cartesian_text = _section(
        "Octopole moments (Cartesian form):",
        ["Octopole moments (Spherical harmonic form):"],
    )
    octopole_spherical_text = _section(
        "Octopole moments (Spherical harmonic form):",
        ["Magnitude: |Q_3|="],
    )
    hexadecapole_text = _section(
        "Hexadecapole moments:",
        ["Electronic spatial extent <r^2>:"],
    )

    quadrupole_traceless_magnitude = None
    if m := re.search(
        rf"Magnitude of the traceless quadrupole moment tensor:\s*"
        rf"({FLOAT_PATTERN})",
        stdout,
        re.IGNORECASE,
    ):
        quadrupole_traceless_magnitude = float(m[1])

    quadrupole_spherical_magnitude = None
    if m := re.search(
        rf"Magnitude:\s*\|Q_2\|=\s*({FLOAT_PATTERN})",
        stdout,
        re.IGNORECASE,
    ):
        quadrupole_spherical_magnitude = float(m[1])

    octopole_spherical_magnitude = None
    if m := re.search(
        rf"Magnitude:\s*\|Q_3\|=\s*({FLOAT_PATTERN})",
        stdout,
        re.IGNORECASE,
    ):
        octopole_spherical_magnitude = float(m[1])

    dipole_magnitude_au = None
    dipole_magnitude_debye = None
    if m := re.search(
        rf"Magnitude of dipole moment:\s*({FLOAT_PATTERN})\s*a\.u\.\s*"
        rf"({FLOAT_PATTERN})\s*Debye",
        stdout,
        re.IGNORECASE,
    ):
        dipole_magnitude_au = float(m[1])
        dipole_magnitude_debye = float(m[2])

    spatial_extent_r2 = None
    if m := re.search(
        rf"Electronic spatial extent\s*<r\^2>:\s*({FLOAT_PATTERN})",
        stdout,
        re.IGNORECASE,
    ):
        spatial_extent_r2 = float(m[1])

    spatial_extent_components = None
    if m := re.search(
        rf"Components of <r\^2>:\s*X=\s*({FLOAT_PATTERN})\s*"
        rf"Y=\s*({FLOAT_PATTERN})\s*Z=\s*({FLOAT_PATTERN})",
        stdout,
        re.IGNORECASE,
    ):
        spatial_extent_components = (
            float(m[1]),
            float(m[2]),
            float(m[3]),
        )

    report = ElectricMultipoleMomentReport(
        positive_charge_center_angstrom=_vec(
            rf"X,\s*Y,\s*Z of center of positive charges.*?\n\s*"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
        ),
        negative_charge_center_angstrom=_vec(
            rf"X,\s*Y,\s*Z of center of negative charges.*?\n\s*"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
        ),
        nuclear_dipole_au=_vec(
            rf"Dipole moment from nuclear charges\s*\(a\.u\.\):\s*"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
        ),
        electronic_dipole_au=_vec(
            rf"Dipole moment from electrons\s*\(a\.u\.\):\s*"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
        ),
        total_dipole_au=_vec(
            rf"Dipole moment\s*\(a\.u\.\):\s*"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
        ),
        total_dipole_debye=_vec(
            rf"Dipole moment\s*\(Debye\):\s*"
            rf"({FLOAT_PATTERN})\s+({FLOAT_PATTERN})\s+({FLOAT_PATTERN})"
        ),
        dipole_magnitude_au=dipole_magnitude_au,
        dipole_magnitude_debye=dipole_magnitude_debye,
        quadrupole_standard_cartesian=_pairs(
            quadrupole_standard_text,
            r"XX|XY|XZ|YX|YY|YZ|ZX|ZY|ZZ",
        ),
        quadrupole_traceless_cartesian=_pairs(
            quadrupole_traceless_text,
            r"XX|XY|XZ|YX|YY|YZ|ZX|ZY|ZZ",
        ),
        quadrupole_traceless_magnitude=quadrupole_traceless_magnitude,
        quadrupole_spherical_harmonic=_pairs(
            quadrupole_spherical_text,
            r"Q_2,\s*-?\d",
        ),
        quadrupole_spherical_magnitude=quadrupole_spherical_magnitude,
        octopole_cartesian=_pairs(
            octopole_cartesian_text,
            r"XXX|YYY|ZZZ|XYY|XXY|XXZ|XZZ|YZZ|YYZ|XYZ",
        ),
        octopole_spherical_harmonic=_pairs(
            octopole_spherical_text,
            r"Q_3,\s*-?\d",
        ),
        octopole_spherical_magnitude=octopole_spherical_magnitude,
        hexadecapole=_pairs(
            hexadecapole_text,
            r"XXXX|YYYY|ZZZZ|XXXY|XXXZ|YYYX|YYYZ|ZZZX|ZZZY|XXYY|XXZZ|YYZZ|XXYZ|YYXZ|ZZXY",
        ),
        electronic_spatial_extent_r2=spatial_extent_r2,
        electronic_spatial_extent_components=spatial_extent_components,
    )

    has_data = any(
        [
            report.positive_charge_center_angstrom is not None,
            report.negative_charge_center_angstrom is not None,
            report.nuclear_dipole_au is not None,
            report.electronic_dipole_au is not None,
            report.total_dipole_au is not None,
            report.total_dipole_debye is not None,
            report.dipole_magnitude_au is not None,
            bool(report.quadrupole_standard_cartesian),
            bool(report.quadrupole_traceless_cartesian),
            report.quadrupole_traceless_magnitude is not None,
            bool(report.quadrupole_spherical_harmonic),
            report.quadrupole_spherical_magnitude is not None,
            bool(report.octopole_cartesian),
            bool(report.octopole_spherical_harmonic),
            report.octopole_spherical_magnitude is not None,
            bool(report.hexadecapole),
            report.electronic_spatial_extent_r2 is not None,
            report.electronic_spatial_extent_components is not None,
        ]
    )
    return report if has_data else None

parse_quadrupole_moments(stdout) staticmethod

Extract electric quadrupole moment.

Source code in src/pymultiwfn/analysis/parsers.py
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
@staticmethod
def parse_quadrupole_moments(stdout: str) -> QuadrupoleMoment | None:
    """Extract electric quadrupole moment."""
    moments: dict[str, float] = {}
    for comp in ["XX", "XY", "XZ", "YY", "YZ", "ZZ"]:
        pat = rf"[Qq]uadrupole.*?{comp}[=:\s]+({FLOAT_PATTERN})"
        if m := re.search(pat, stdout):
            moments[comp] = float(m[1])

    if moments:
        return QuadrupoleMoment(
            xx=moments.get("XX"),
            xy=moments.get("XY"),
            xz=moments.get("XZ"),
            yy=moments.get("YY"),
            yz=moments.get("YZ"),
            zz=moments.get("ZZ"),
        )
    return None

WavefunctionParser

Bases: OutputParser

Parser for wavefunction check/modify output (Menu 6).

Source code in src/pymultiwfn/analysis/parsers.py
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
class WavefunctionParser(OutputParser):
    """Parser for wavefunction check/modify output (Menu 6)."""

    @classmethod
    def parse_for_result(
        cls,
        analysis: Menu,
        stdout: str,
    ) -> list[ParsedMultiwfnResult]:
        case_map: dict[Menu, list] = {}
        default = [
            cls.parse_orbital_info,
            cls.parse_gtf_info,
            cls.parse_basis_info,
            cls.parse_coefficient_matrices,
            cls.parse_density_matrices,
            cls.parse_exported_matrices,
        ]
        parsers = case_map.get(analysis, default)
        return cls._collect(stdout, parsers)

    @staticmethod
    def parse_orbital_info(stdout: str) -> list[Orbital]:
        """Extract orbital information.

        Handles both formats:
        - "N  Alpha/Beta  Occ=  E=  a.u.  eV"
        - "Orb: N Ene(au/eV): E_au E_eV Occ: occ Type: type"
        """
        orbitals: list[Orbital] = []

        # Format 1: detailed listing
        pattern1 = (
            rf"(\d+)\s+(Alpha|Beta)\s+Occ=\s*({FLOAT_PATTERN})\s+"
            rf"E=\s*({FLOAT_PATTERN})\s*a\.u\.\s+({FLOAT_PATTERN})\s*eV"
        )
        for match in re.finditer(pattern1, stdout):
            spin: Literal["alpha", "beta"] | None = None
            if match[2].lower() == "alpha":
                spin = "alpha"
            elif match[2].lower() == "beta":
                spin = "beta"
            orbitals.append(
                Orbital(
                    orbital_id=int(match[1]),
                    spin=spin,
                    occupation=float(match[3]),
                    energy_au=float(match[4]),
                    energy_eV=float(match[5]),
                )
            )

        if orbitals:
            return orbitals

        # Format 2: "Orb: N Ene(au/eV): E_au E_eV Occ: occ Type: type"
        pattern2 = (
            rf"Orb:\s+(\d+)\s+Ene\(au/eV\):\s+({FLOAT_PATTERN})\s+"
            rf"({FLOAT_PATTERN})\s+Occ:\s+({FLOAT_PATTERN})\s+"
            rf"Type:\s*(\S+)"
        )
        for match in re.finditer(pattern2, stdout):
            orbitals.append(
                Orbital(
                    orbital_id=int(match[1]),
                    energy_au=float(match[2]),
                    energy_eV=float(match[3]),
                    occupation=float(match[4]),
                )
            )

        return orbitals

    @staticmethod
    def parse_gtf_info(stdout: str) -> list[GaussianTypeFunction]:
        """Extract Gaussian-type function listing."""
        pattern = (
            rf"(\d+)\s+Center:\s+(\d+)\s*\(([A-Za-z]+)\s*\)\s+"
            rf"Type:\s+(\S+)\s+Exponent:\s+({FLOAT_PATTERN})"
        )
        return [
            GaussianTypeFunction(
                gtf_index=int(match[1]),
                center_atom_id=int(match[2]),
                center_element=match[3].strip(),
                function_type=match[4].strip(),
                exponent=float(match[5]),
            )
            for match in re.finditer(pattern, stdout)
        ]

    @staticmethod
    def parse_basis_info(stdout: str) -> list[BasisFunction]:
        """Extract basis function to shell/GTF mapping."""
        pattern = (
            r"Basis:\s+(\d+)\s+Shell:\s+(\d+)\s+Center:\s+(\d+)"
            r"\s*\(([A-Za-z]+)\s*\)\s+Type:\s*(\S+)\s+"
            r"GTF:\s+(\d+)\s+to\s+(\d+)"
        )
        return [
            BasisFunction(
                basis_index=int(match[1]),
                shell_index=int(match[2]),
                center_atom_id=int(match[3]),
                center_element=match[4].strip(),
                function_type=match[5].strip(),
                gtf_start=int(match[6]),
                gtf_end=int(match[7]),
            )
            for match in re.finditer(pattern, stdout)
        ]

    @staticmethod
    def parse_coefficient_matrices(
        stdout: str,
    ) -> list[CoefficientMatrix]:
        """Extract MO coefficient matrices printed in column blocks.

        Multiple matrices may appear in a single stdout (e.g. alpha
        and beta).  Each is delimited by a header or section break.
        The block format prints 5 orbital columns at a time with row
        indices on the left.
        """
        results: list[CoefficientMatrix] = []

        # Split into sections by density matrix headers or end markers
        # to avoid mixing coefficient and density data.
        # Coefficient data has no "density matrix" header — it's just
        # rows of basis-index followed by floats, preceded by a
        # column-header row of orbital indices.
        col_header_pat = re.compile(r"^\s+(\d+(?:\s+\d+)+)\s*$")
        row_pat = re.compile(rf"^\s+(\d+)((?:\s+{FLOAT_PATTERN})+)\s*$")

        # Don't parse inside density matrix sections
        in_density = False
        current_cols: list[int] = []
        data: dict[tuple[int, int], float] = {}
        max_row = 0
        max_col = 0

        for line in stdout.split("\n"):
            if "density matrix" in line.lower():
                in_density = True
                continue
            if in_density:
                if "Trace of density matrix" in line:
                    in_density = False
                continue

            if "Basic information of all orbitals" in line:
                continue
            if "Orb:" in line or "Largest exponent" in line:
                continue
            if "Center:" in line and "Type:" in line and "Exponent:" in line:
                continue
            if "Basis:" in line and "Shell:" in line and "GTF:" in line:
                continue

            if match := col_header_pat.match(line):
                vals = match[1].split()
                # Column headers are orbital indices (usually 1-based)
                # Only treat as column header if values are sequential-ish
                # integers and there are <= 10 of them
                if len(vals) <= 10:
                    try:
                        cols = [int(v) for v in vals]
                        if all(c > 0 for c in cols):
                            current_cols = cols
                            continue
                    except ValueError:
                        pass

            if current_cols and (match := row_pat.match(line)):
                row_idx = int(match[1])
                vals = [float(v) for v in match[2].split()]
                for k, val in enumerate(vals):
                    if k < len(current_cols):
                        col_idx = current_cols[k]
                        data[(row_idx, col_idx)] = float(val)
                        if row_idx > max_row:
                            max_row = row_idx
                        if col_idx > max_col:
                            max_col = col_idx

        if data:
            results.append(
                CoefficientMatrix(
                    label="coefficient_matrix",
                    n_basis=max_row,
                    n_orbitals=max_col,
                    data=data,
                )
            )

        return results

    @staticmethod
    def parse_density_matrices(stdout: str) -> list[DensityMatrix]:
        """Extract density matrices (symmetric, lower triangle).

        Each density matrix section starts with a header like
        ``"*** Total density matrix ***"`` and ends at the trace
        lines.  Multiple sections produce multiple results.
        """
        results: list[DensityMatrix] = []

        dm_header_pat = re.compile(
            r"\*+\s*(.*?density matrix.*?)\s*\*+", re.IGNORECASE
        )
        col_header_pat = re.compile(r"^\s+(\d+(?:\s+\d+)*)\s*$")
        row_pat = re.compile(rf"^\s+(\d+)((?:\s+{FLOAT_PATTERN})+)\s*$")
        trace_pat = re.compile(
            rf"Trace of density matrix:\s+({FLOAT_PATTERN})"
        )
        trace_overlap_pat = re.compile(
            rf"Trace of density matrix multiplied by overlap matrix:\s+"
            rf"({FLOAT_PATTERN})"
        )

        in_dm = False
        label = ""
        current_cols: list[int] = []
        data: dict[tuple[int, int], float] = {}
        max_idx = 0
        trace: float | None = None
        trace_overlap: float | None = None

        def _flush() -> None:
            nonlocal data, max_idx, trace, trace_overlap, label
            if data:
                results.append(
                    DensityMatrix(
                        label=label,
                        n_basis=max_idx,
                        data=dict(data),
                        trace=trace,
                        trace_overlap=trace_overlap,
                    )
                )
            data = {}
            max_idx = 0
            trace = None
            trace_overlap = None
            label = ""

        for line in stdout.split("\n"):
            if match := dm_header_pat.search(line):
                if in_dm:
                    _flush()
                in_dm = True
                label = match[1].strip()
                current_cols = []
                continue

            if not in_dm:
                continue

            if match := trace_pat.search(line):
                trace = float(match[1])
                continue
            if match := trace_overlap_pat.search(line):
                trace_overlap = float(match[1])
                _flush()
                in_dm = False
                continue

            if match := col_header_pat.match(line):
                current_cols = [int(v) for v in match[1].split()]
                continue

            if current_cols and (match := row_pat.match(line)):
                row_idx = int(match[1])
                vals = [float(v) for v in match[2].split()]
                for k, val in enumerate(vals):
                    if k < len(current_cols):
                        col_idx = current_cols[k]
                        data[(row_idx, col_idx)] = val
                        if row_idx > max_idx:
                            max_idx = row_idx
                        if col_idx > max_idx:
                            max_idx = col_idx

        if in_dm and data:
            _flush()

        return results

    @staticmethod
    def parse_exported_matrices(stdout: str) -> list[ExportedMatrix]:
        """Extract matrix export file references."""
        pattern = (
            r"(?:matrix|The matrix)\s+has been\s+(?:outputted|exported)\s+"
            r"to\s+(\S+)\s+in current folder"
        )
        return [
            ExportedMatrix(file_name=match[1])
            for match in re.finditer(pattern, stdout, re.IGNORECASE)
        ]

parse_basis_info(stdout) staticmethod

Extract basis function to shell/GTF mapping.

Source code in src/pymultiwfn/analysis/parsers.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
@staticmethod
def parse_basis_info(stdout: str) -> list[BasisFunction]:
    """Extract basis function to shell/GTF mapping."""
    pattern = (
        r"Basis:\s+(\d+)\s+Shell:\s+(\d+)\s+Center:\s+(\d+)"
        r"\s*\(([A-Za-z]+)\s*\)\s+Type:\s*(\S+)\s+"
        r"GTF:\s+(\d+)\s+to\s+(\d+)"
    )
    return [
        BasisFunction(
            basis_index=int(match[1]),
            shell_index=int(match[2]),
            center_atom_id=int(match[3]),
            center_element=match[4].strip(),
            function_type=match[5].strip(),
            gtf_start=int(match[6]),
            gtf_end=int(match[7]),
        )
        for match in re.finditer(pattern, stdout)
    ]

parse_coefficient_matrices(stdout) staticmethod

Extract MO coefficient matrices printed in column blocks.

Multiple matrices may appear in a single stdout (e.g. alpha and beta). Each is delimited by a header or section break. The block format prints 5 orbital columns at a time with row indices on the left.

Source code in src/pymultiwfn/analysis/parsers.py
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
@staticmethod
def parse_coefficient_matrices(
    stdout: str,
) -> list[CoefficientMatrix]:
    """Extract MO coefficient matrices printed in column blocks.

    Multiple matrices may appear in a single stdout (e.g. alpha
    and beta).  Each is delimited by a header or section break.
    The block format prints 5 orbital columns at a time with row
    indices on the left.
    """
    results: list[CoefficientMatrix] = []

    # Split into sections by density matrix headers or end markers
    # to avoid mixing coefficient and density data.
    # Coefficient data has no "density matrix" header — it's just
    # rows of basis-index followed by floats, preceded by a
    # column-header row of orbital indices.
    col_header_pat = re.compile(r"^\s+(\d+(?:\s+\d+)+)\s*$")
    row_pat = re.compile(rf"^\s+(\d+)((?:\s+{FLOAT_PATTERN})+)\s*$")

    # Don't parse inside density matrix sections
    in_density = False
    current_cols: list[int] = []
    data: dict[tuple[int, int], float] = {}
    max_row = 0
    max_col = 0

    for line in stdout.split("\n"):
        if "density matrix" in line.lower():
            in_density = True
            continue
        if in_density:
            if "Trace of density matrix" in line:
                in_density = False
            continue

        if "Basic information of all orbitals" in line:
            continue
        if "Orb:" in line or "Largest exponent" in line:
            continue
        if "Center:" in line and "Type:" in line and "Exponent:" in line:
            continue
        if "Basis:" in line and "Shell:" in line and "GTF:" in line:
            continue

        if match := col_header_pat.match(line):
            vals = match[1].split()
            # Column headers are orbital indices (usually 1-based)
            # Only treat as column header if values are sequential-ish
            # integers and there are <= 10 of them
            if len(vals) <= 10:
                try:
                    cols = [int(v) for v in vals]
                    if all(c > 0 for c in cols):
                        current_cols = cols
                        continue
                except ValueError:
                    pass

        if current_cols and (match := row_pat.match(line)):
            row_idx = int(match[1])
            vals = [float(v) for v in match[2].split()]
            for k, val in enumerate(vals):
                if k < len(current_cols):
                    col_idx = current_cols[k]
                    data[(row_idx, col_idx)] = float(val)
                    if row_idx > max_row:
                        max_row = row_idx
                    if col_idx > max_col:
                        max_col = col_idx

    if data:
        results.append(
            CoefficientMatrix(
                label="coefficient_matrix",
                n_basis=max_row,
                n_orbitals=max_col,
                data=data,
            )
        )

    return results

parse_density_matrices(stdout) staticmethod

Extract density matrices (symmetric, lower triangle).

Each density matrix section starts with a header like "*** Total density matrix ***" and ends at the trace lines. Multiple sections produce multiple results.

Source code in src/pymultiwfn/analysis/parsers.py
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
@staticmethod
def parse_density_matrices(stdout: str) -> list[DensityMatrix]:
    """Extract density matrices (symmetric, lower triangle).

    Each density matrix section starts with a header like
    ``"*** Total density matrix ***"`` and ends at the trace
    lines.  Multiple sections produce multiple results.
    """
    results: list[DensityMatrix] = []

    dm_header_pat = re.compile(
        r"\*+\s*(.*?density matrix.*?)\s*\*+", re.IGNORECASE
    )
    col_header_pat = re.compile(r"^\s+(\d+(?:\s+\d+)*)\s*$")
    row_pat = re.compile(rf"^\s+(\d+)((?:\s+{FLOAT_PATTERN})+)\s*$")
    trace_pat = re.compile(
        rf"Trace of density matrix:\s+({FLOAT_PATTERN})"
    )
    trace_overlap_pat = re.compile(
        rf"Trace of density matrix multiplied by overlap matrix:\s+"
        rf"({FLOAT_PATTERN})"
    )

    in_dm = False
    label = ""
    current_cols: list[int] = []
    data: dict[tuple[int, int], float] = {}
    max_idx = 0
    trace: float | None = None
    trace_overlap: float | None = None

    def _flush() -> None:
        nonlocal data, max_idx, trace, trace_overlap, label
        if data:
            results.append(
                DensityMatrix(
                    label=label,
                    n_basis=max_idx,
                    data=dict(data),
                    trace=trace,
                    trace_overlap=trace_overlap,
                )
            )
        data = {}
        max_idx = 0
        trace = None
        trace_overlap = None
        label = ""

    for line in stdout.split("\n"):
        if match := dm_header_pat.search(line):
            if in_dm:
                _flush()
            in_dm = True
            label = match[1].strip()
            current_cols = []
            continue

        if not in_dm:
            continue

        if match := trace_pat.search(line):
            trace = float(match[1])
            continue
        if match := trace_overlap_pat.search(line):
            trace_overlap = float(match[1])
            _flush()
            in_dm = False
            continue

        if match := col_header_pat.match(line):
            current_cols = [int(v) for v in match[1].split()]
            continue

        if current_cols and (match := row_pat.match(line)):
            row_idx = int(match[1])
            vals = [float(v) for v in match[2].split()]
            for k, val in enumerate(vals):
                if k < len(current_cols):
                    col_idx = current_cols[k]
                    data[(row_idx, col_idx)] = val
                    if row_idx > max_idx:
                        max_idx = row_idx
                    if col_idx > max_idx:
                        max_idx = col_idx

    if in_dm and data:
        _flush()

    return results

parse_exported_matrices(stdout) staticmethod

Extract matrix export file references.

Source code in src/pymultiwfn/analysis/parsers.py
854
855
856
857
858
859
860
861
862
863
864
@staticmethod
def parse_exported_matrices(stdout: str) -> list[ExportedMatrix]:
    """Extract matrix export file references."""
    pattern = (
        r"(?:matrix|The matrix)\s+has been\s+(?:outputted|exported)\s+"
        r"to\s+(\S+)\s+in current folder"
    )
    return [
        ExportedMatrix(file_name=match[1])
        for match in re.finditer(pattern, stdout, re.IGNORECASE)
    ]

parse_gtf_info(stdout) staticmethod

Extract Gaussian-type function listing.

Source code in src/pymultiwfn/analysis/parsers.py
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
@staticmethod
def parse_gtf_info(stdout: str) -> list[GaussianTypeFunction]:
    """Extract Gaussian-type function listing."""
    pattern = (
        rf"(\d+)\s+Center:\s+(\d+)\s*\(([A-Za-z]+)\s*\)\s+"
        rf"Type:\s+(\S+)\s+Exponent:\s+({FLOAT_PATTERN})"
    )
    return [
        GaussianTypeFunction(
            gtf_index=int(match[1]),
            center_atom_id=int(match[2]),
            center_element=match[3].strip(),
            function_type=match[4].strip(),
            exponent=float(match[5]),
        )
        for match in re.finditer(pattern, stdout)
    ]

parse_orbital_info(stdout) staticmethod

Extract orbital information.

Handles both formats: - "N Alpha/Beta Occ= E= a.u. eV" - "Orb: N Ene(au/eV): E_au E_eV Occ: occ Type: type"

Source code in src/pymultiwfn/analysis/parsers.py
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
@staticmethod
def parse_orbital_info(stdout: str) -> list[Orbital]:
    """Extract orbital information.

    Handles both formats:
    - "N  Alpha/Beta  Occ=  E=  a.u.  eV"
    - "Orb: N Ene(au/eV): E_au E_eV Occ: occ Type: type"
    """
    orbitals: list[Orbital] = []

    # Format 1: detailed listing
    pattern1 = (
        rf"(\d+)\s+(Alpha|Beta)\s+Occ=\s*({FLOAT_PATTERN})\s+"
        rf"E=\s*({FLOAT_PATTERN})\s*a\.u\.\s+({FLOAT_PATTERN})\s*eV"
    )
    for match in re.finditer(pattern1, stdout):
        spin: Literal["alpha", "beta"] | None = None
        if match[2].lower() == "alpha":
            spin = "alpha"
        elif match[2].lower() == "beta":
            spin = "beta"
        orbitals.append(
            Orbital(
                orbital_id=int(match[1]),
                spin=spin,
                occupation=float(match[3]),
                energy_au=float(match[4]),
                energy_eV=float(match[5]),
            )
        )

    if orbitals:
        return orbitals

    # Format 2: "Orb: N Ene(au/eV): E_au E_eV Occ: occ Type: type"
    pattern2 = (
        rf"Orb:\s+(\d+)\s+Ene\(au/eV\):\s+({FLOAT_PATTERN})\s+"
        rf"({FLOAT_PATTERN})\s+Occ:\s+({FLOAT_PATTERN})\s+"
        rf"Type:\s*(\S+)"
    )
    for match in re.finditer(pattern2, stdout):
        orbitals.append(
            Orbital(
                orbital_id=int(match[1]),
                energy_au=float(match[2]),
                energy_eV=float(match[3]),
                occupation=float(match[4]),
            )
        )

    return orbitals

WeakInteractionParser

Bases: OutputParser

Parser for weak interaction analysis output.

Source code in src/pymultiwfn/analysis/parsers.py
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
class WeakInteractionParser(OutputParser):
    """Parser for weak interaction analysis output."""

    @classmethod
    def parse_for_result(
        cls,
        analysis: Menu,
        stdout: str,
    ) -> list[ParsedMultiwfnResult]:
        results: list[ParsedMultiwfnResult] = []
        interaction = cls.parse(stdout)
        if interaction is not None:
            results.append(interaction)
        return results

    @staticmethod
    def parse(stdout: str) -> WeakInteraction | None:
        """Extract summary statistics from weak interaction analysis."""
        vals: dict[str, float] = {}

        patterns: dict[str, str] = {
            "delta_g_inter": rf"delta_?g_?inter.*?[=:\s]+({FLOAT_PATTERN})",
            "delta_g_intra": rf"delta_?g_?intra.*?[=:\s]+({FLOAT_PATTERN})",
            "isosurface_integral": (
                rf"(?:Integral|integral).*?isosurface.*?[=:\s]+({FLOAT_PATTERN})"
            ),
        }

        for key, pat in patterns.items():
            if match := re.search(pat, stdout, re.IGNORECASE):
                vals[key] = float(match[1])

        if "delta_g_inter" not in vals and "delta_g_intra" not in vals:
            return None

        interaction = WeakInteraction(
            delta_g_inter=vals.get("delta_g_inter", 0.0),
            delta_g_intra=vals.get("delta_g_intra", 0.0),
        )

        if "isosurface_integral" in vals:
            interaction.isosurface_integral = vals["isosurface_integral"]

        if cubes := [
            match[1]
            for match in re.finditer(
                r"(\S+\.cube)\s+has been generated", stdout
            )
        ]:
            interaction.cube_names = cubes

        return interaction

parse(stdout) staticmethod

Extract summary statistics from weak interaction analysis.

Source code in src/pymultiwfn/analysis/parsers.py
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
@staticmethod
def parse(stdout: str) -> WeakInteraction | None:
    """Extract summary statistics from weak interaction analysis."""
    vals: dict[str, float] = {}

    patterns: dict[str, str] = {
        "delta_g_inter": rf"delta_?g_?inter.*?[=:\s]+({FLOAT_PATTERN})",
        "delta_g_intra": rf"delta_?g_?intra.*?[=:\s]+({FLOAT_PATTERN})",
        "isosurface_integral": (
            rf"(?:Integral|integral).*?isosurface.*?[=:\s]+({FLOAT_PATTERN})"
        ),
    }

    for key, pat in patterns.items():
        if match := re.search(pat, stdout, re.IGNORECASE):
            vals[key] = float(match[1])

    if "delta_g_inter" not in vals and "delta_g_intra" not in vals:
        return None

    interaction = WeakInteraction(
        delta_g_inter=vals.get("delta_g_inter", 0.0),
        delta_g_intra=vals.get("delta_g_intra", 0.0),
    )

    if "isosurface_integral" in vals:
        interaction.isosurface_integral = vals["isosurface_integral"]

    if cubes := [
        match[1]
        for match in re.finditer(
            r"(\S+\.cube)\s+has been generated", stdout
        )
    ]:
        interaction.cube_names = cubes

    return interaction