As Ψ A is the wavefunction of fragment A, P B pq can then be defined as the 1-PDM of the overlapping orbitals between fragment A and B. We loop over all fragments B A to enumerate all the matching conditions for A. One can apply this to all fragments, leading to the following Lagrangian for constrained optimisation when summing over all the fragments: