# Many-Body Expansion (MBE) Theory ## Introduction The many-body expansion (MBE) is a systematic approach to compute the energy of a molecular system as a sum of fragment energies and their interactions. It provides a rigorous framework for fragment-based quantum chemistry methods, enabling accurate calculations on systems too large for conventional approaches. ## Mathematical Foundation ### Total Energy Expression The exact energy of a system of $N$ fragments can be written as: $$ E_{\text{total}} = \sum_i E_i + \sum_{i dispersion > charge transfer 4. **Geometry**: Compact geometries converge slower ### Problematic Cases MBE converges slowly for: - Strong charge transfer - Significant covalent character across boundaries - Extended conjugation - Metal clusters In these cases, consider: - Larger fragments - Higher-order terms - Embedding approaches (EFP, QM/MM) ## Computational Scaling ### Number of Calculations | Order | Number of Calculations | Scaling | |-------|----------------------|---------| | 1-body | $N$ | $O(N)$ | | 2-body | $\binom{N}{2} = \frac{N(N-1)}{2}$ | $O(N^2)$ | | 3-body | $\binom{N}{3} = \frac{N(N-1)(N-2)}{6}$ | $O(N^3)$ | | n-body | $\binom{N}{n}$ | $O(N^n)$ | ### Distance Screening Reduce calculations by screening distant pairs: $$ \Delta E_{ij} \approx 0 \quad \text{if} \quad R_{ij} > R_{\text{cutoff}} $$ Typical cutoffs: - Two-body: 10-15 Å (electrostatics), 6-8 Å (exchange) - Three-body: 6-8 Å With screening, effective scaling drops to $O(N)$ for large systems. ### Parallelization MBE is **embarrassingly parallel**: - All $n$-body calculations at a given order are independent - Natural fit for distributed computing - Near-linear parallel speedup ## Hierarchy of Methods ### Electrostatically Embedded MBE (EE-MBE) Include electrostatic environment in fragment calculations: $$ E_i^{\text{embed}} = E_i^{\text{QM}} + \sum_{j \neq i} E_{ij}^{\text{point-charge}} $$ Improves two-body truncation by capturing polarization. ### Systematic Molecular Fragmentation (SMF) Uses graph-based fragmentation with overlapping fragments. Energy reconstructed via inclusion-exclusion. ### Generalized MBE (GMBE) Allows overlapping fragments with proper overcounting corrections. ## Implementation Notes ### Fragmentation with autofragment autofragment handles the fragmentation step of an MBE workflow — partitioning a molecular system into fragments and writing QC input files. The n-body expansion and energy assembly are performed externally after running the individual QC calculations. ```python import autofragment as af from autofragment.partitioners import MolecularPartitioner from autofragment.io.writers import write_gamess_fmo # Fragment a water cluster system = af.io.read_xyz("water20.xyz") partitioner = MolecularPartitioner(n_fragments=4, method="kmeans") tree = partitioner.partition(system) # Write input files for fragment-based calculations write_gamess_fmo(tree.fragments, "water_fmo.inp", basis="aug-cc-pVDZ", method="MP2") ``` See the [Water Clusters Tutorial](../guides/water_clusters.md) for a complete workflow. ### Energy Assembly For MBE(2): ```python E_total = sum(monomer_energies) for i, j in dimer_pairs: E_total += dimer_energies[(i,j)] - monomer_energies[i] - monomer_energies[j] ``` For MBE(3): ```python E_total = compute_mbe2() # Start with MBE(2) for i, j, k in trimer_triples: delta_3 = (trimer_energies[(i,j,k)] - dimer_energies[(i,j)] - dimer_energies[(j,k)] - dimer_energies[(i,k)] + monomer_energies[i] + monomer_energies[j] + monomer_energies[k]) E_total += delta_3 ``` ### Gradient Assembly MBE gradients follow the same pattern: $$ \frac{\partial E_{\text{MBE}}}{\partial R_\alpha} = \sum_i \frac{\partial E_i}{\partial R_\alpha} + \sum_{i