Thermodynamics of structure-forming systems

Structure-forming systems are ubiquitous in nature, ranging from atoms building molecules to self-assembly of colloidal amphibolic particles. The understanding of the underlying thermodynamics of such systems remains an important problem. Here, we derive the entropy for structure-forming systems that differs from Boltzmann-Gibbs entropy by a term that explicitly captures clustered states. For large systems and low concentrations the approach is equivalent to the grand-canonical ensemble; for small systems we find significant deviations. We derive the detailed fluctuation theorem and Crooks’ work fluctuation theorem for structure-forming systems. The connection to the theory of particle self-assembly is discussed. We apply the results to several physical systems. We present the phase diagram for patchy particles described by the Kern-Frenkel potential. We show that the Curie-Weiss model with molecule structures exhibits a first-order phase transition.

L udwig Boltzmann defined entropy as the logarithm of state multiplicity. The multiplicity of independent (but possibly interacting) systems is typically given by multinomial factors that lead to the Boltzmann-Gibbs entropy and the exponential growth of phase space volume as a function of the degrees of freedom. In recent decades, much attention was given to systems with long-range and coevolving interactions that are sometimes referred to as complex systems 1 . Many complex systems do not exhibit an exponential growth of phase space [2][3][4][5] . For correlated systems, it typically grows subexponentially [6][7][8][9][10][11][12][13][14] , systems with superexponential phase space growth were recently identified as those capable of forming structures from its components 5,15 . A typical example of this kind are complex networks 16 , where complex behavior may lead to ensemble inequivalence 17 . The most prominent example of structure-forming systems are chemical reaction networks [18][19][20] . The usual approach to chemical reactionswhere free particles may compose molecules-is via the grandcanonical ensemble, where particle reservoirs make sure that the number of particles is conserved on average. Much attention has been given to finite-size corrections of the chemical potential 21,22 and nonequilibrium thermodynamics of small chemical networks [23][24][25][26] . However, for small closed systems, fluctuations in particle reservoirs might become nonnegligible and predictions from the grand-canonical ensemble become inaccurate. In the context of nanotechnology and colloidal physics, the theory of selfassembly 27 gained recent interest. Examples of self-assembly include lipid bilayers and vesicles 28 , microtubules, molecular motors 29 , amphibolic particles 30 , or RNA 31 . The thermodynamics of self-assembly systems has been studied, both experimentally and theoretically, often dealing with particular systems, such as Janus particles 32 . Theoretical and computational work have explored selfassembly under nonequilibrium conditions 33,34 . A review can be found in Arango-Restrepo et al. 35 .
Here, we present a canonical approach for closed systems where particles interact and form structures. The main idea is to start not with a grand-canonical approach to structure-forming systems but to see within a canonical description which terms in the entropy emerge that play the role of the chemical potential in large systems. A simple example for a structure-forming system, the magnetic coin model, was recently introduced in Jensen et al. 15 . There n coins are in two possible states (head and tail), and in addition, since coins are magnetic, they can form a third state, i.e., any two coins might create a bond state. The phase space of this model, W(n), grows superexponentially, WðnÞ $ n n=2 e 2 ffiffi n p $ e nlog n . We first generalize this model to arbitrary cluster sizes and to an arbitrary number of states. We then derive the entropy of the system from the corresponding log multiplicity and use it to compute thermodynamic quantities, such as the Helmholtz free energy. With respect to Boltzmann-Gibbs entropy, there appears an additional term that captures the molecule states. By using stochastic thermodynamics, we obtain the appropriate second law for structureforming systems and derive the detailed fluctuation theorem. Under the assumption that external driving preserves microreversibility, i.e., detailed balance of transition rates in quasi-stationary states, we derive the nonequilibrium Crooks' fluctuation theorem for structure-forming systems. It relates the probability distribution of the stochastic work done on a nonequilibrium system to thermodynamic variables, such as the partial Helmholtz free energy, temperature, and size of the initial and final cluster states. Finally, we apply our results to several physical systems: we first calculate the phase diagram for the case of patchy particles described by the Kern-Frenkel potential. Second, we discuss the fully connected Ising model where molecule formation is allowed. We show that the usual second-order transition in the fully connected Ising model changes to first-order.

Results
Entropy of structure-forming systems. To calculate the entropy of structure-forming systems, we first define a set of possible microstates and mesostates. Let us consider a system of n particles. Each single particle can attain states from the set X ð1Þ ¼ fx ð1Þ 1 ; ; x ð1Þ m 1 g. The superscript number (1) indicates that the states correspond to a single-particle state, and m 1 denotes the number of these states. A typical set of states could be the spin of the particle {↑,↓}, or a set of energy levels. Having only singleparticle states, the microstate of the system consisting of n particles is a vector (X 1 , X 2 , …, X n ), where X k 2 X ð1Þ is the state of kth particle. Let us now assume that any two particles can create a two-particle state. This two-particle state can be a molecule composed of two atoms, a cluster of two colloidal particles, etc. We call this state as a cluster. This two-particle cluster can attain states X ð2Þ ¼ fx ; x ð2Þ m 2 g. A microstate of a system of n particles is again a vector (X 1 , X 2 , …, X n ), but now either X k 2 X ð1Þ or X k 2 X ð2Þ Z 2 n . For instance, a state of particle k belonging to a two-particle cluster can be written as The indices in the brackets tell us that the particle k belongs to the cluster of size two in the state x ð2Þ 1 and the cluster is formed by particles k 1 and k 2 (k 1 < k 2 ). Indeed, either k 1 = k or k 2 = k. Now assume that particles can also form larger clusters up to a maximal size, m. Consider m as a fixed number, m ≤ n. Generally, clusters of size j have states X ðjÞ ¼ fx ðjÞ 1 ; ; x ðjÞ m j g. The corresponding states of the particle are always elements from sets X ðjÞ Z j n with the restriction that if the kth particle is in a state x ðjÞ i ðk 1 ; ; k j Þ then k l < k l+1 , for all l and one k l = k. Consider an example of four particles. Particles are either in a free state or they form a cluster of size two. A state of each particle is either s (1) -a free particle, or x (2) (i, j)-a cluster compound from particles i and j. As an example, a typical microstate is Ψ = (x (1)  , which corresponds to a frequency (histogram) of microstates. The normalization condition is given by the fact that the total number of particles is n, i.e., P ij jn ðjÞ i ¼ n. For example, a mesostate, N Ψ , corresponding to a microstate Ψ is N ψ ¼ n ð1Þ ¼ 2; n ð2Þ ¼ 1 À Á , denoting that there are two free particles and one two-particle cluster.
The Boltzmann entropy 36 of this mesostate is given by where W is the multiplicity of the mesostate, which is the number of all distinct microstates corresponding to the same mesostate.
To determine the number of all distinct microstates corresponding to a given mesostate, let us order the particles and number them from 1 to n. By permutation of the particles we obtain the different possible microstates. The number of all permutations is simply n!. However, some permutations correspond to the same microstate and we are overcounting. In our example with one cluster and two free particles, the permutations (4, 2, 3, 1) and (1, 3, 2, 4) correspond to the same microstate Ψ = (x (1) , , two particles in the first state and two particles in the second. The number of distinct microstates corresponding to the mesostate N 1 is given by 2 Þ Now imagine that the four particles are either free or form twoparticle clusters. The microstate of a particle is either x (1) , two clusters of size two. The number of distinct microstates is just For example, a microstate (x (2) (2, 1), x (2) (2, 1), x (2) (4, 3), x (2) (4,3)) is the same as the first microstate because we just relabel 1↔2 and 3↔4. In summary, the multiplicity corresponding to x ðjÞ i is ðn ðjÞ i Þ!ðj!Þ n ðjÞ i , and we can express the total multiplicity as Using Stirling's formula log n! % nlog n À n, we get for the entropy Using the normalization condition, n ¼ P ij jn ðjÞ i , and combining the first term with the remaining ones, we get the entropy per particle in terms of ratios } Normalization is given by can be interpreted as the probability that a particle is a part of a cluster in state x ðjÞ i . On the other hand, the quantity } ðjÞ i is the relative number of clusters. Since P ij jn ðjÞ i n ¼ 1, we neglect the constant without changing the thermodynamic relations.
In the remainder, we denote thermodynamic quantities per particle by calligraphic script and total quantities by normal script. We express the entropy per particle as or equivalently in terms of the probability distribution, p ðjÞ i , as Finite interaction range. Up to now, we assumed an infinite range of interaction between particles, which is unrealistic for chemical reactions, where only atoms within a short range form clusters. A simple correction is obtained by dividing the system into a fixed number of boxes: particles within the same box can form clusters, particles in different boxes cannot. We begin by calculating the multiplicity for two boxes. For simplicity, assume that they both contain n/2 particles. The multiplicity of a system with two boxes, W n By defining the concentration of particles as c ¼ n=b, the entropy per particle becomes or, respectively, Note that the entropy of structure-forming systems is both additive and extensive in the sense of Lieb and Yngvason 37 . It is also concave, ensuring the uniqueness of the maximum entropy principle. For more details and connections to axiomatic frameworks, see Supplementary Discussion.
Equilibrium thermodynamics of structure-forming systems. We now focus on the equilibrium thermodynamics obtained, for example, by considering the maximum entropy principle. Consider the internal energy Using Lagrange multipliers to maximize the functional leads to the following: and the resulting distribution iŝ Here, we introduce the partial partition functions, which is a polynomial equation of order m in Λ. The connection with thermodynamics follows through Eq. (13). By multiplying witĥ } ðjÞ i and summing over i,j, we get Sð}Þ À is the number of clusters, divided by the number of particles in the system. The number of clusters per particle is The Helmholz free energy is thus obtained as Finally, we can write the total partition function as Comparison with the grand-canonical ensemble. To compare the presented exact approach with the grand-canonical ensemble, consider the simple chemical reaction, 2X⇌X 2 . Without loss of generality, assume that free particles carry some energy, ϵ. We calculate the Helmholtz free energy for both approaches in Supplementary Information. In Fig. 1, we show the corresponding specific heat, cðTÞ ¼ ÀT ∂ 2 F ∂T 2 . For large systems, the usual grandcanonical ensemble approach and the exact calculation with a strictly conserved number of particles converge. For small systems, however, there appear notable differences. This is visible in Fig. 1, where only for large n and low concentrations, c, the specific heat for the exact approach (squares) and the grandcanonical ensemble (triangles) become identical. The inset shows the ratio of the specific heat, c C /c GC − 1, vanishing for large n. For large systems, the exact approach and the the grand-canonical ensemble are equivalent.
Relation to the theory of self-assembly. In many applications, the number of energetic configurations for each cluster size is so large that one is only interested in the distribution of cluster sizes. For this case, it is possible to formulate an effective theory considering contributions from all configurations that is known as the theory of self-assembly. For an overview, see Likos et al. 27 .
To compute the free energy in terms of the cluster-size distribution, we define the latter aŝ This is the distribution obtained from a free energy of the ideal gas of clusters, as discussed in Fantoni et al. 32 for the case of Janus particles and in Vissersa et al. 38 for the more general case of onepatch colloids. The entropy of the relative cluster size can be introduced as By introducing the partial free energy as the energy constraint takes the form of the expected free energy, averaged over cluster size, Φ ¼ P m j¼1 } ðjÞ Φ j . The cluster-size distribution is obtained by maximization of the functional It is clear that Eq. (19) is the solution of the maximization. The free energy can be now expressed as which has the same structure as when calculated in terms of } ðjÞ i . Examples for thermodynamics of structure-forming systems. We now apply the results obtained in the previous section to several examples of structure-forming systems. We particularly focus on how the presence of mescoscopic structures of clustered states leads to the macroscopic physical properties. In the presence of structure formation, there exists a phase transition between a free particle fluid phase and a condensed phase, containing clusters of particles. This phase transition is demonstrated in two examples.
The first example on soft-matter self-assembly describes the process of condensation of one-patch colloidal amphibolic particles. This condensation is relevant in applications in nanomaterials and biophysics. The second example covers the phase transition of the Curie-Weiss spin model for the situation where particles form molecules. In Supplementary Information, we discuss the additional examples of a magnetic gas and a sizedependent chemical potential.
Kern-Frenkel model of patchy particles. Recently, the theory of soft-matter self-assembly has successfully predicted the creation of various structures of colloidal particles, including clusters of Janus particles 32 , polymerization of colloids 38 , and the crystallization of multipatch colloidal particles 39 . Kern and Frenkel 40 introduced a simple model to describe the self-assembly of amphibolic particles with two-particle interactions. r ij denotes a unit vector connecting the centers of particles i and j, r ij is the corresponding distance, and n i and n j are unit vectors encoding the directions of patchy spheres. The Kern-Frenkel potential was defined as where uðr ij Þ ¼ 1; r ij ≤ σ Àϵ; σ < r ij <σ þ Δ 0; r ij > σ þ Δ: and Ωðr ij ; n i ; n j Þ ¼ 1 if r ij Á n i > cos θ and r ij Á n j > cos θ ( 0; otherwise: The characteristic quantity, χ ¼ sin 2 ðθ=2Þ, is the particle coverage. In the theory of self-assembly, the cluster-size distribution is determined by the partial partition functions Eq. (19). Due to the enormous number of possible configurations, it is impossible to calculate Z j analytically and simulation methods were introduced, including a grand-canonical Monte Carlo method and successive umbrella sampling; for a review, see Rovigatti et al. 41 . Instead of calculating the exact value of Z j , we use a stylized model based on Fantoni et al. 32 . There the partial partition function is parameterized as log Z j jϵ ¼ b tanhðajÞ, where b < 0 and a > 0 are the model parameters. While for small cluster sizes, the free energy per particle decreases linearly with the size, for larger clusters, it saturates at b. To calculate the average cluster size, Eq. (16), one has to solve the equation for Λ, Eq. (15). In Fig. 2, we show the phase diagram of the patchy particles for b = − 3 and a = 25 and n = 100. The average number of clusters, M, plays the role of the order parameter. In the phase diagram, one can clearly distinguish three phases. At high temperature, we observe the liquid phase, where most particles are not bound to others. At low temperatures, we have a condensed phase with macroscopic clusters. The two phases are separated by a coexistence phase, where both large clusters and unbounded particles are present.
The coexistence phase (gray region) is characterized by a bimodal distribution that can be recognized by calculating the bimodality coefficient 42 . Results presented in Fig. 2 qualitatively correspond to results obatined in Fantoni et al. 32 for the case of Janus particles with χ = 0.5. Curie-Weiss model with molecule formation. To discuss an example of a spin system with molecule states, consider the fully connected Ising model [43][44][45][46] with a Hamiltonian that allows for possible molecule states Molecule states neither feel the spin-spin interaction nor the external magnetic field, h. Therefore, the sum only extends over free particles. In a mean-field approximation, we use the magnetization, m ¼ 1 nÀ1 P i≠j σ i , and express the Hamiltonian as H MF (σ i ) = −(Jm + h)∑ j,free σ j . The self-consistency equation m ¼ À ∂F ∂h j h¼0 leads to an equation for m that is calculated numerically (Supplementary Information) and that is shown in Fig. 3. Contrary to the mean-field approximation of the usual fully connected Ising model (without molecule states), the phase transition is no longer second-order but becomes firstorder. There exists a bifurcation where solutions for m = 0 and m > 0 are stable. The second-order transition is recovered for small systems, n→0. The critical temperature is shifted toward zero for increasing n. We performed Monte Carlo simulations to check the result of the mean-field approximation; see Supplementary Information.
Stochastic thermodynamics of structure-forming systems. Consider an arbitrary nonequilibrium state given by } The time derivative of the entropy per particle is Using the master Eq. (26) and some straightforward calculations, we end up with the usual second law of thermodynamics where _ Q is the heat flow per particle and _ S i is the nonnegative entropy production per particle, see Supplementary Information.
Let us now consider a stochastic trajectory, x(τ) = (i(τ),j(τ)), denoting that at time τ, the particle is in state x ðjðτÞÞ iðτÞ . We introduce the time-dependent protocol, l(τ), that controls the energy spectrum of the system. The stochastic energy for trajectory x (τ) and protocol l(τ) can be expressed as ϵðτÞ ϵ ðjðτÞÞ iðτÞ ðlðτÞÞ. We assume microreversibility from which follows that detailed balance is valid even when the energy spectrum is timedependent (due to protocol l(τ)). We define the stochastic entropy as We show that _ sðxðτÞÞ ¼ _ s i ðxðτÞÞ þ _ s e ðxðτÞÞ, where _ s i is the stochastic entropy production rate and _ s e is the entropy flow equal to _ q=T, where _ q is the heat flow in Supplementary Information.
The time-reversed trajectory isxðτÞ ¼ ðiðT À τÞ; jðT À τÞÞ, and the time-reversed protocol islðτÞ ¼ lðT À τÞ. The log-ratio of the probability, P, of a forward trajectory and the probability, P, of the time-reversed trajectory under the time-reversed protocol is equal to Δσ ¼ Δs i þ log Assuming that the initial state is an equilibrium state, introducing the stochastic free energy, f(τ) = ϵ(τ) − Ts(τ), and combining the first and the second law of thermodynamics, we get Δs i = β(w − Δf). The stochastic free energy of an equilibrium state is f ð} ðjÞ i Þ ¼ Àj α β À 1 β , see Supplementary Information. If we start in an equilibrium distribution with j(τ = 0) = j 0 and the reverse experiment also starts in an equilibrium distribution withjðτ ¼ 0Þ ¼j 0 , by plugging this into Eq. (31) and a simple manipulation, we have where Φ j is the partial free energy Eq. (21). Finally, by a straightforward calculation, we obtain Crooks' fluctuation theorem 49,50 Pðwjj 0 Þ where ΔΦ j ¼ Φ~j 0 ðlð0ÞÞ À Φ j 0 ðlð0ÞÞ. For technical details, see Supplementary Information.

Discussion
We presented a straightforward way to establish the thermodynamics of structure-forming systems (e.g., molecules made from atoms or clusters of colloidal particles) based on the canonical ensemble with a modified entropy that is obtained by the proper counting of the system's configurations. The approach is an alternative to the grand-canonical ensemble that yields identical results for large systems. However, there are significant deviations that might have important consequences for small systems, where the interaction range becomes comparable with system size. Note that our results are valid for large systems (in the thermodynamic limit) as well as small systems at nanoscales. We showed that fundamental relations such as the second law of thermodynamics and fluctuation theorems remain valid for structure-forming systems. In addition, we demonstrated that the choice of a proper entropic functional has profound physical consequences. It determines, for example, the order of phase transitions in spin models.
We mention that we follow a similar reasoning as has been used in the case of Shannon's entropy: originally, Shannon's entropy was derived by Gibbs in the thermodynamic limit using a frequentist approach to statistics (probability is given by a large number of repetitions). However, once the formula for entropy had been derived, its validity was extended beyond the thermodynamic limit, which corresponds to the Bayesian approach. It has been shown, e.g., by methods of stochastic thermodynamics, that the formula for the Shannon's entropy and the laws of thermodynamics remain valid for systems of arbitrary size (with the exception of systems with quantum corrections) and arbitrarily far from equilibrium 47 . In this paper, we follow the same type of reasoning for the case of structure-forming systems.
Typical examples where our results apply are chemical reactions at small scales, the self-assembly of colloidal particles, active matter, and nanoparticles. The presented results might also be of direct use for chemical nanomotors 51 and nonequilibrium self-assembly 35 . A natural question is how the framework can be extended to the wellknown statistical physics of chemical reactions [23][24][25][26] where systems are composed of more than one type of atom.

Data availability
Source Data are provided with this paper. All relevant data are available at: https://github. com/complexity-science-hub/Thermodynamics-of-structure-forming-systems.