of structure-forming systems

Jan Korbel,1, 2 Simon David Lindner,1, 2 Rudolf Hanel,1, 2 and Stefan Thurner1, 2, 3, 4, ∗ 1Section for the Science of Complex Systems, CeMSIIS, Medical University of Vienna, Spitalgasse 23, A-1090, Vienna, Austria 2Complexity Science Hub Vienna, Josefst¨adterstrasse 39, A-1080 Vienna, Austria 3Santa Fe Institute, 1399 Hyde Park Road, Santa Fe, NM 87501, USA 4IIASA, Schlossplatz 1, A-2361 Laxenburg, Austria (Dated: January 28, 2021)

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 for structure-forming systems that differs from Boltzmann-Gibbs entropy by a term that explicitly captures ‘molecule’ states. For large systems and low concentrations the approach is equivalent to the grand-; 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.

INTRODUCTION ied, both experimentally and theoretically, often deal- ing with particular systems, such as Janus particles [31]. defined entropy as the logarithm Theoretical and computational work have explored self- of state multiplicity. The multiplicity of independent assembly under non-equilibrium conditions [32, 33]. A (but possibly interacting) systems is typically given by review can be found in [34]. multinomial factors that lead to the Boltzmann-Gibbs Here we present a canonical approach for closed sys- entropy and the exponential growth of phase space vol- tems where particles interact and form structures. The ume as a function of the degrees of freedom. In re- main idea is to start not with a grand-canonical approach cent decades much attention was given to systems with to structure forming systems but to see within a canon- long-range and co-evolving interactions that are some- ical description which terms in the entropy emerge that times referred to as complex systems [1]. Many com- play the role of the in large systems. plex systems do not exhibit an exponential growth of A simple example for a structure-forming system, the phase space [3, 4, 8, 9]. For correlated systems it typi- magnetic coin model, was recently introduced in [15]. cally grows sub-exponentially [6–12], systems with super- There n coins are in two possible states (head and tail), exponential phase space growth were recently identified and in addition, since coins are magnetic, they can form as those capable of forming structures from its compo- a third state, i.e. any two coins might create a bond

nents [9, 15]. A typical example of this kind are complex state. The phase space of this√ model, W (n), grows super- networks [16], where complex behavior may lead to en- exponentially, W (n) ∼ nn/2e2 n ∼ en log n. We first gen- semble in-equivalence [17]. The most prominent example eralize this model to arbitrary cluster sizes and to an of structure-forming systems are chemical reaction net- arbitrary number of states. We then derive the entropy works [18–20]. The usual approach to chemical reactions of the system from the corresponding log-multiplicity and – where free particles may compose molecules – is via use it to compute thermodynamic quantities, such as the grand-canonical ensemble, where particle reservoirs the Helmholtz free-energy. With respect to Boltzmann- make sure that the number of particles is conserved on Gibbs entropy there appears an additional term that average. Much attention has been given to finite-size captures the molecule states. By using stochastic ther- corrections of the chemical potential [14, 15] and non- modynamics, we obtain the appropriate second law for equilibrium thermodynamics of small chemical networks structure-forming systems. and derive the detailed fluc- arXiv:2004.06491v3 [cond-mat.stat-mech] 27 Jan 2021 [23–26]. However, for small closed systems, fluctuations tuation theorem. Under the assumption that external in particle reservoirs might become non-negligible and driving preserves micro-reversibility, i.e. detailed bal- predictions from the grand-canonical ensemble become ance of transition rates in quasi-stationary states, we inaccurate. In the context of nanotechnology and col- derive the non-equilibrium Crooks’ fluctuation theorem loidal physics, the theory of self-assembly [37] gained re- for structure-forming systems. It relates the probabil- cent interest. Examples of self-assembly include lipid bi- ity distribution of the stochastic work done on a non- layers and vesicles [27], microtubules, and molecular mo- equilibrium system to thermodynamic variables, such as tors [28], amphibolic particles [29], or RNA [30]. The the partial Helmholtz free-energy, , and size thermodynamics of self-assembly systems has been stud- of the initial and final cluster states. Finally, we apply 2 our results to several physical systems: We first calcu- clusters in state x(j). The mesostate is therefore char- i   late the phase diagram for the case of patchy particles acterized by a vector N = n(j) , which corresponds to described by the Kern-Frenkel potential. Second, we dis- i a frequency (histogram) of microstates [? ]. The nor- cuss the fully connected where molecule for- malization condition is given by the fact that the total mation is allowed. We show that the usual second-order P (j) transition in the fully connected Ising model changes to number of particles is n, i.e., ij jni = n. For exam- N first-order. ple, a mesostate, Ψ, corresponding to a microstate Ψ (1) (2)  is Nψ = n = 2, n = 1 , denoting that there are two free particles and one two-particle cluster. RESULTS The Boltzmann entropy [35] of this mesostate is given by Entropy of structure-forming systems S (N) = log W (N) , (1) To calculate the entropy of structure-forming sys- where W is the multiplicity of the mesostate, which is tems, we first define a set of possible microstates and the number of all distinct microstates corresponding to mesostates. Let’s consider a system of n particles. Each the same mesostate. To determine the number of all single particle can attain states from the set X (1) = distinct microstates corresponding to a given mesostate, {x(1), . . . , x(1) }. The superscript (1) indicates that the 1 m1 let us order the particles and number them from 1 to states correspond to a single particle state, and m1 de- n. By permutation of the particles we obtain the dif- notes the number of these states. A typical set of states ferent possible microstates. The number of all permuta- could be the spin of the particle {↑, ↓}, or a set of en- tions is simply n!. However, some permutations corre- ergy levels. Having only single-particle states, the mi- spond to the same microstate and we are over-counting. crostate of the system consisting of n particles is a vec- (1) In our example with one cluster and two free particles, tor (X1,X2,...,Xn), where Xk ∈ X is the state of the permutations (4, 2, 3, 1) and (1, 3, 2, 4) correspond to k-th particle. Let us now assume that any two parti- the same microstate Ψ = (x(1), x(2)(2, 3), x(2)(2, 3), x(1)). cles can create a two-particle state. This two-particle However, permutation (2, 1, 3, 4) corresponds to the mi- state can be a molecule composed of two atoms, a clus- crostate Ψ0 = (x(2)(1, 3), x(1), x(2)(1, 3), x(1)). This mi- ter of two colloidal particles, etc. We call this state crostate is a distinct microstate corresponding to the as a cluster. This two-particle cluster can attain states (1) (2)  same mesostate, NΨ ≡ NΨ0 = n = 2, n = 1 . X (2) = {x(2), . . . , x(2) }. A microstate of a system of n 1 m2 The number of microstates giving the same mesostate particles is again a vector (X1,X2,...,Xn), but now ei- can be expressed as the product of configurations with (1) (2) 2 ther X ∈ X or X ∈ X × . For instance, a state (j) k k Zn the same state for each x . Let’s begin with the particles of particle k belonging to a two-particle cluster can be i that do not form clusters. The number of equivalent rep- written as X = x(2)(k , k ). The indices in the brackets   k 1 1 2 resentations for one distinct state is n(1) !, which corre- tell us that the particle k belongs to the cluster of size i two in the state x(2) and the cluster is formed by particles sponds to the number of permutations of all particles in 1 the same state. For the cluster states one can think about k1 and k2 (k1 < k2). Indeed, either k1 = k or k2 = k. Now assume that particles can also form larger clus- equivalent representations of one microstate in two steps:  (j) ters up to a maximal size, m. Consider m as a fixed first permute all clusters, which gives ni ! possibili- number, m ≤ n. Generally, clusters of size j have states ties. Then permute the particles in the cluster, which (j) (j) (j) gives j! possibilities for every cluster, so that we end up X = {x1 , . . . , xmj }. The corresponding states of (j) j n(j) the particle are always elements from sets X × Zn with (j!) i combinations. with the restriction that if the k-th particle is in a As an example, consider the case of four parti- (j) state xi (k1, . . . , kj) then kl < kl+1, for all l and one cles. First, we look at free particles that attain states (1) (1) kl = k. Consider an example of four particles. Par- x or x . Let us consider a mesostate N1 = 1 2  ticles are either in a free state, or they form a cluster n(1) = 2, n(1) = 2 , i.e., two particles in the first state of size two. A state of each particle is either s(1) – a 1 2 and two particles in the second. The number of distinct free particle, or x(2)(i, j) – a cluster compound from par- microstates corresponding to the mesostate N is given ticles i and j. As an example, a typical microstate is 1 by W (N ) = 4!/(2!2!) = 6. All microstates that belong Ψ = (x(1), x(2)(2, 3), x(2)(2, 3), x(1)), which means that 1 to the mesostate N are particles 1 and 4 are free and particles 2 and 3 form a 1 cluster. (1) (1) (1) (1) (1) (1) (1) (1) Now consider a mesoscopic scale, where the mesostate (x1 , x1 , x2 , x2 )(x1 , x2 , x1 , x2 ) (1) (1) (1) (1) (1) (1) (1) (1) of the system is given only by the number of clusters (x1 , x2 , x2 , x1 )(x2 , x2 , x1 , x1 ) (j) (j) (1) (1) (1) (1) (1) (1) (1) (1) in each state xi . Let us denote ni as the number of (x2 , x1 , x2 , x1 )(x2 , x1 , x1 , x2 ) 3

Now imagine that the four particles are either free or or equivalently in terms of the probability distribution, form two-particle clusters. The microstate of a parti- (j) pi , as cle is either x(1) or x(2)(i, j). Let’s consider a mesostate (j) (j) ! N = n(1) = 0, n(2) = 2, i.e., two clusters of size two. X p p 2 S(P ) = − i log i − 1 The number of distinct microstates is just W (N2) = j j ij 4!/(2!(2!)2) = 3. The microstates corresponding to the (j) mesostate N are X p  j!  2 − i log . (6) j nj−1 ij (x(2)(1, 2), x(2)(1, 2), x(2)(3, 4), x(2)(3, 4)) (x(2)(1, 3), x(2)(2, 4), x(2)(1, 3), x(2)(2, 4)) Finite interaction range: Up to now we assumed an (x(2)(1, 4), x(2)(2, 3), x(2)(2, 3), x(2)(1, 4)) infinite range of interaction between particles, which is unrealistic for chemical reactions, where only atoms For example, a microstate within a short range form clusters. A simple correction (x(2)(2, 1), x(2)(2, 1), x(2)(4, 3), x(2)(4, 3)) is the same is obtained by dividing the system into a fixed number as the first microstate because we just relabel 1 ↔ 2 of boxes: particles within the same box can form clus- and 3 ↔ 4. In summary, the multiplicity corresponding ters, particles in different boxes can’t. We begin by cal- (j) (j) n(j) culating the multiplicity for two boxes. For simplicity, to x is (n )!(j!) i , and we can express the total i i assume that they both contain n/2 particles. The mul- multiplicity as ˜  (j) tiplicity of a system with two boxes, W ni , is given n! W (N) = . (2) by the sum of all possible partitions of n(j) clusters with  (j) (j)  i Q n (j) (j) (ni )!(j!) i 1 ij state xi into the first box (containing ni clusters) and the second box (containing 2n(j) clusters), such that Using Stirling’s formula log n! ≈ n log n − n, we get for i n(j) = 1n(j) + 2n(j). The multiplicity is therefore the entropy i i i ˜  (j) X 1 (j) 2 (j) S(N) ≈ n log n − n W ni = W ni W ni , (7) 1 (j) 2 (j) (j) X  (j) (j) (j) (j)  ni + ni =ni − ni log ni − ni + ni log j! . (3) ij where W is the multiplicity in Eq. (2). The dominant contribution to the sum comes from the term, where (j) P (j) (j) (j) Using the normalization condition, n = jni , and 1 2 ij ni = ni = ni /2, so that we can approximate the combining the first term with the remaining ones, we get ˜ (j) (j) 2 (j) (j) multiplicity by W (ni ) ≈ W (ni /2) . Similarly, for b the entropy per particle in terms of ratios ℘i = ni /n, boxes we obtain the multiplicity

(j) " (j) (j) ! S({n }) X n n [(n/b)!]b S(N) = i = − i log i W˜ (n(j)) = W (n(j)/b)b = . (8) i i  (j)  n n n Q (j) b n ij ij [(ni /b)!] (j!) i # n(j)  j!  n(j) jn(j) i i i By defining the concentration of particles asc ¯ = n/b, the − log j−1 − + . (4) n n n n entropy per particle becomes

X (j)  (j)  P (j) S(℘) = − ℘ log ℘ − 1 Normalization is given by ij j℘i = 1. Therefore, i i (j) (j) ij pi = j℘i can be interpreted as the probability that (j)  j!  a particle is a part of a cluster in state x . On the X (j) i − ℘i log j−1 , (9) (j) c¯ ij other hand, the quantity ℘i is the relative number of (j) P jni clusters. Since ij n = 1, we neglect the constant or, respectively, without changing the thermodynamic relations. (j) (j) ! X p p In the remainder, we denote thermodynamic quantities S(P ) = − i log i − 1 j j per particle by calligraphic script and total quantities by ij normal script. We express the entropy per particle as (j) X p  j!  − i log . (10) X (j)  (j)  j c¯j−1 S(℘) = − ℘i log ℘i − 1 ij ij   Note that the entropy of structure-forming systems is X (j) j! − ℘ log , (5) both additive and extensive in the sense of Lieb and Yn- i nj−1 ij gvason [2]. It is also concave, ensuring the uniqueness 4

3000 4 of the maximum entropy principle. For more details and n=10 ▲◼ -1 ● ▲◼ connections to axiomatic frameworks, see Supplementary ● 10 ● ◼ ● ▲ ● ●T=1 2500 -4 ● ◼ - 1 ● ▲ Discussion. 10 ● ●T=10 ● ● ▲◼ -7 ● GC ●●T=100 10 ●● ▲◼ ● 3 / c ● -10 ● ▲◼ n=10 C ● ◼ ●● 2000 10 ●● ◼ ▲ c ▲ ▲◼ 2 8 14 20 ▲◼ ▲◼ Equilibrium thermodynamics of structure-forming 10 10 10 10 ▲◼ ▲◼ ▲◼ ▲◼ systems n ◼ ▲◼ 1500 ▲ ▲◼ ▲◼ ▲◼ 2 ▲◼ ▲◼ n=10 ▲◼ ▲◼ ◼ ▲◼ ▲◼ ◼ ◼ ▲◼ ▲◼ ◼ ▲▲ We now focus on the equilibrium thermodynamics ob- 1000 ▲◼ ▲◼ ◼ ◼ ▲ ▲◼ ◼ ▲◼ ◼ ▲▲ ▲◼ ▲◼ ▲ ◼ ◼ ▲▲ tained, for example, by considering the maximum en- ▲◼ ▲◼ ◼ ◼ ▲▲ ▲◼ ◼ ▲◼ ◼ ◼ ▲▲ ▲◼ ▲◼ ▲ ◼ ▲▲ 500 ▲◼ ▲◼ ◼ ▲◼ ◼ ▲◼ ▲ tropy principle. Consider the ▲◼ ▲◼ ▲ ◼ ◼ ▲◼ ▲ ◼C Specific heat c ( T ) ▲◼ ▲◼ ◼ ▲▲ ▲◼ ▲◼ ▲◼ ▲◼ ◼ ◼ ▲◼ ▲ ▲◼ ▲◼ ▲◼ ▲◼ ▲◼ ◼ ▲◼ ▲◼ ▲▲ ▲◼ ▲◼ ▲◼ ▲◼ ▲◼ ▲◼ ▲◼ ▲ (j) X (j) (j) X (j) (j) (j) ▲◼ ▲◼ ▲◼ ▲◼ ▲◼ ▲◼ ▲◼ ▲◼ ▲◼ ▲◼ ▲ ▲GC U(ni ) = ni i = n ℘i i = n U(℘i ) . 0 0 5 10 15 20 ij ij (11) Temperature(k BT) Using Lagrange multipliers to maximize the functional FIG. 1 Specific heat, c(T ), for the reaction 2X X2     for the presented canonical approach (C, X (j) X (j) (j) squares) with an exact number of particles in S(℘)−α  j℘i − 1−β  ℘i i − U , (12) ij ij comparison to the grand-canonical ensemble (GC, triangles). n denotes the number of leads to the equations, particles. For small systems the difference of the   approaches becomes apparent. The inset shows (j) j! (j) the ratio of the specific heat calculated from the − log℘ ˆi − log j−1 − αj − βi = 0 , (13) c exact approach to the one obtained from the and the resulting distribution is grand-canonical ensemble, cC /cGC − 1. For large n the quantity decays to zero for any cj−1   temperature. ℘ˆ(j) = exp −jα − β(j) . (14) i j! i

Here we introduce the partial partition functions, Zj = Comparison with the grand-canonical ensemble: To j−1 (j) c P −βi −α j! i e , and the quantity Λ = e . Λ is obtained compare the presented exact approach with the grand- from canonical ensemble, consider the simple chemical reac- m tion, 2X X2. Without loss of generality, assume that X (j) X j j℘ˆi = j Zj Λ = 1 , (15) free particles carry some energy, . We calculate the ij j=1 Helmholtz free-energy for both approaches in the Supple- mentary Information. In Fig. 1, we show the correspond- which is a polynomial equation of order m in Λ. The con- 2 ing specific heat, c(T ) = −T ∂ F . For large systems the nection with thermodynamics follows through Eq. (13). ∂T 2 (j) usual grand-canonical ensemble approach and the exact By multiplying with℘ ˆi and summing over i, j, we get calculation with a strictly conserved number of particles P (j) P (j) S(℘) − ij ℘ˆi − α − β U = 0. Note that ij ℘ˆi = converge. For small systems, however, there appear no- P (j) table differences. This is visible in Fig. 1, where only ij nˆi /n = M/n = M is the number of clusters, di- vided by the number of particles in the system. The for large n and low concentrations,c ¯, the specific heat number of clusters per particle is for the exact approach (squares) and the grand-canonical ensemble (triangles) become identical. The inset shows X (j) X j M = ℘ˆi = Zj Λ . (16) the ratio of the specific heat, cC /cGC − 1, vanishing for ij j large n. For large systems the exact approach and the the grand-canonical ensemble are equivalent. The Helmholz free-energy is thus obtained as 1 α 1 F = U − S = − − M . (17) β β β Relation to the theory of self-assembly

Finally, we can write the total partition function as In many applications, the number of energetic config- m urations for each cluster-size is so large that one is only 1 Y Z = exp(−βF) = exp(ΛjZ ) . (18) interested in the distribution of cluster-sizes. For this Λ j j=1 case it is possible to formulate an effective theory consid- ering contributions from all configurations that is known 5 as the theory of self-assembly. For an overview, see [37]. Kern-Frenkel model of patchy particles: Recently, the To compute the free-energy in terms of the cluster-size theory of soft-matter self-assembly has successfully pre- distribution, we define the latter as dicted the creation of various structures of colloidal par-

(j) X (j) j ticles, including clusters of Janus particles [31], polymer- ℘ˆ = ℘ˆi = Λ Zj . (19) ization of colloids [38], and the crystallization of multi- i patch colloidal particles [39]. Kern and Frenkel [40] in- This is the distribution obtained from a free-energy of troduced a simple model to describe the self-assembly of the ideal gas of clusters, as discussed in [31] for the case amphibolic particles with two-particle interactions. rij of Janus particles and in [38] for the more general case of denotes a unit vector connecting the centers of parti- one-patch colloids. The entropy of the relative cluster- cles i and j, rij is the corresponding distance, and ni size can be introduced as and nj are unit vectors encoding the directions of patchy m spheres. The Kern-Frenkel potential was defined as X (j)  (j)  Sc(℘) = − ℘ log ℘ − 1 . (20) KF j=1 Uij = u(rij)Ω(rij, ni, nj) , (24) By introducing the partial free-energy as where 1 Φj = − log Zj , (21)  β  ∞, rij ≤ σ u(rij) = −, σ < rij < σ + ∆ the energy constraint takes the form of the expected  0, r > σ + ∆. Pm (j) ij free-energy, averaged over cluster-size, Φ = j=1 ℘ Φj. The cluster-size distribution is obtained by maximization and of the functional       rij · ni > cos θ and m m  −1 if X X Ω(r , n , n ) = r · n > cos θ S (℘) − α j℘(j) − 1 − β ℘(j)Φ − Φ . ij i j ij j c c    j   0, otherwise. j=1 j=1 (22) The characteristic quantity, χ = sin2(θ/2), is the parti- It is clear that Eq. (19) is the solution of the maximiza- cle coverage. In the theory of self-assembly the cluster- tion. The free-energy can be now expressed as size distribution is determined by the partial partition αc M functions (19). Due to the enormous number of possible Fc = Φ − 1/βSc = − − , (23) β β configurations it is impossible to calculate Zj analyti- which has the same structure as when calculated in terms cally and simulation methods were introduced, including of ℘(j). a grand-canonical Monte Carlo method, and Successive i Umbrella Sampling; for a review, see [41]. Instead of cal- culating the exact value of Zj, we use a stylized model Examples for thermodynamics of structure-forming based on [31]. There the partial partition function is pa- systems log Zj rameterized as j = b tanh(aj), where b < 0 and a > 0 are the model parameters. While for small cluster-sizes, We now apply the results obtained in the previous sec- the free-energy per particle decreases linearly with the tion to several examples of structure-forming systems. size, for larger clusters, it saturates at b. To calculate We particularly focus on how the presence of mesco- the average cluster-size Eq. (16) one has to solve the scopic structures of clustered states leads to the macro- equation for Λ, (15). In Fig. 2, we show the phase dia- scopic physical properties. In the presence of structure- gram of the patchy particles for b = −3 and a = 25 and formation there exists a phase transition between a free n = 100. The average number of clusters, M, plays the particle fluid phase and a condensed phase, containing role of the order parameter. In the phase diagram one clusters of particles. This phase transition is demon- can clearly distinguish three phases. At high tempera- strated in two examples. ture, we observe the liquid phase, where most particles The first example on soft-matter self-assembly de- are not bound to others. At low we have scribes the process of condensation of one-patch colloidal a condensed phase with macroscopic clusters. The two amphibolic particles. This condensation is relevant in phases are separated by a coexistence phase, where both, applications in nanomaterials and biophysics. The sec- large clusters and unbounded particles are present. The ond example covers the phase transition of the Curie- coexistence phase (gray region) is characterized by a bi- Weiss spin model for the situation where particles form modal distribution that can be recognized by calculating molecules. In the Supplementary Information we discuss the bimodality coefficient [42]. Results presented in Fig. the additional examples of a magnetic gas and a size- 2 qualitatively correspond to results obatined in [31] for dependent chemical potential. the case of Janus particles with ξ = 0.5. 6

M analytical n=50 n=50 analytical n=200 n=200 )

m 1.0 1

( analytical 80 n n=400 o i t a s i t

a 0.5 n

60 g 0 a 0 1 2 M

0.0 40 0.0 0.1 0.2 0.3 0.4 0.5 Temperature (kBT)

FIG. 3 Magnetization of the fully connected Ising model 20 with molecule states for n = 50 and n = 200 particles, for a spin-spin coupling constant, J = 1. Results of the mean-field approximation (solid lines) are in good agreement with Monte-Carlo simulations (symbols). Errorbars show the standard deviation of the average value FIG. 2 Phase diagram for the self-assembly of patchy obtained from 1000 independent runs of the particles for n = 100 particles. The average simulations (see Supplementary Information for cluster size (M) as a function of temperature more details). The inset shows the well-known (T ) and concentration (c) is seen. The result for the fully connected Ising model cluster-size is given by the color and ranges from without molecule states. Without molecule M = 0 (purple) to M = 100 (red). We observe formation we observe the usual second-order three phases: The liquid and condensed phase transition. With molecules, the critical are divided by a coexistence phase (gray area). temperature decreases with the number of Coexistence is characterized by a bimodal particles and the phase transition becomes distribution that can be detected with a shift in first-order. the bimodality coefficient.

Curie-Weiss model with molecule formation: To dis- towards zero for increasing n. We performed Monte- cuss an example of a spin system with molecule states, Carlo simulations to check the result of the mean-field consider the fully connected Ising model [43–46] with a approximation; see Supplementary Information. Hamiltonian that allows for possible molecule states J X X H(σ ) = − σ σ − h σ . (25) i n − 1 i j j Stochastic thermodynamics of structure-forming i6=j, free j, free systems Molecule states neither feel the spin-spin interac- tion nor the external magnetic field, h. There- Consider an arbitrary non-equilibrium state given by fore, the sum only extends over free particles. In (j) (j) ℘i ≡ ℘i (t), and and imagine that the evolution of a mean-field approximation we use the magnetiza- the probability distribution is defined by a first-order 1 P tion, m = n−1 i6=j σi, and express the Hamiltonian as Markovian linear master equation, as is usually assumed MF P H (σi) = −(Jm + h) j,free σj. The self-consistency in stochastic thermodynamics [47, 48] ∂F equation m = − ∂h |h=0 leads to an equation for m that is calculated numerically (Supplementary Information) (j) X jl (l) X  jl (l) lj (j) ℘˙i = wik℘k = wik℘k − wki℘i . (26) and that is shown in Fig. 3. Contrary to the mean- kl kl field approximation of the usual fully connected Ising model (without molecule states), the phase transition is jl wik are the transition rates. Note that probability nor- no longer second-order but becomes first-order. There (j) malization leads to P j℘˙ = 0. Given that detailed exists a bifurcation where solutions for m = 0 and m > 0 ij i jl (l) lj (j) are stable. The second-order transition is recovered for balance holds, wik℘ˆk = wki℘ˆi , the underlying station- (j) small systems, n → 0. The critical temperature is shifted ary distribution, obtained from℘ ˙i = 0, coincides with 7 the equilibrium distribution (14). From this we get If we start in an equilibrium distribution with j(τ = 0) = j0 and the reverse experiment also starts in an equi- wjl j! h  i ˜ ˜ ik = cl−j exp α(l − j) + β (l) − (j) . (27) librium distribution with j(τ = 0) = j0, by plugging this lj l! k i into Eq. (31) and a simple manipulation we have wki The time derivative of the entropy per particle is P(x(τ)|j0)  h ˜ i = exp βw − β Φ˜ (l(0)) − Φj (l(0)) , ˜ ˜ j0 0   P(x˜(τ)|j0) dS X (j) (j) X (j) j! = − ℘˙ log ℘ − ℘˙ log . (28) (32) dt i i i cj−1 ij ij where Φj is the partial free-energy (21). Finally, by a straightforward calculation we obtain Crooks’ fluctuation Using the master equation (26) and some straightforward theorem [49, 50], calculations, we end up with the usual second law of ther- P (w|j0) modynamics, = exp(β(w − ∆Φj)) (33) P˜(−w|˜j0) dS ˙ ˙ ˜ = Si + βQ , (29) where ∆Φj = Φ˜ (l(0))−Φj (l(0)). For technical details, dt j0 0 see Supplementary Information. where Q˙ is the heat flow per particle and S˙i is the non- negative entropy production per particle, see Supplemen- tary Information. DISCUSSION Let us now consider a stochastic trajectory, x(τ) = (i(τ), j(τ)), denoting that at time τ, the particle is in We presented a straight forward way to establish state x(j(τ)). We introduce the time-dependent protocol, the thermodynamics of structure-forming systems (e.g. i(τ) molecules made from atoms or clusters of colloidal par- l(τ), that controls the energy spectrum of the system. ticles) based on the canonical ensemble with a modified The stochastic energy for trajectory x(τ) and protocol entropy that is obtained by the proper counting of the l(τ) can be expressed as (τ) ≡ (j(τ))(l(τ)). We as- i(τ) system’s configurations. The approach is an alternative sume micro-reversibility from which follows that detailed to the grand-canonical ensemble that yields identical re- balance is valid even when the energy spectrum is time- sults for large systems. However, there are significant dependent (due to protocol l(τ)). We define the stochas- deviations that might have important consequences for tic entropy as small systems, where the interaction range becomes com- parable with system-size. Note that our results are valid    j(τ)!  s(x(τ)) = − log ℘(j(τ))(τ) − 1 − log . (30) for large systems (in the ) as well i(τ) j(τ)−1 c as small systems at nano-scales. We showed that funda- We show thats ˙(x(τ)) =s ˙ (x(τ)) +s ˙ (x(τ)), wheres ˙ mental relations such as the second law of thermodynam- i e i ics and fluctuation theorems remain valid for structure- is the stochastic entropy production rate ands ˙e is the entropy flow equal toq/T ˙ , whereq ˙ is the heat flow in the forming systems. In addition, we demonstrated that the Supplementary Information. choice of a proper entropic functional has profound phys- The time-reversed trajectory is x˜(τ) = (i(T −τ), j(T − ical consequences. It determines, for example, the order τ)), and the time reversed protocol, ˜l(τ) = l(T − τ). The of phase-transitions in spin models. log-ratio of the probability, P, of a forward trajectory We mention that we follow a similar reasoning as has and the probability, P˜, of the time-reversed trajectory been used in the case of Shannon’s entropy: Originally, Shannon entropy was derived by Gibbs in the thermo- under the time-reversed protocol is equal to ∆σ = ∆si + j0 dynamic limit using a frequentist approach to statistics log , where j0 = j(τ = 0) and ej0 = ej(τ = 0), see ej0 (probability is given by a large number of repetitions). Supplementary Information. Hence, log P(x(τ)) = ∆σ, P˜(x˜(τ)) However, once the formula for entropy had been de- which leads to the fluctuation theorem [49] rived, its validity was extended beyond the thermody- namic limit, which corresponds to the Bayesian approach. P (∆σ) It has been shown, e.g., by methods of stochastic thermo- log = ∆σ . (31) P˜(−∆σ) dynamics, that the formula for the Shannon entropy and the remain valid for systems of Assuming that the initial state is an equilibrium state, in- arbitrary size (with the exception of systems with quan- troducing the stochastic free-energy, f(τ) = (τ)−T s(τ), tum corrections) and arbitrarily far from equilibrium [47]. and combining the first and the second law of thermody- In this paper, we follow the same type of reasoning for namics, we get ∆si = β(w − ∆f). The stochastic free- the case of structure-forming systems. (j) α 1 energy of an equilibrium state is f(℘ ˆi ) = −j β − β , see Typical examples where our results apply are chem- Supplementary Information. ical reactions at small scales, the self-assembly of col- 8 loidal particles, active matter, and nano-particles. The [7] A.K. Rajagopal, Dynamic linear response theory for a presented results might also be of direct use for chem- nonextensive system based on the Tsallis prescription. ical nano-motors [51] and non-equilibrium self-assembly Phys. Rev. Lett. 76 (1996) 3469. [34]. A natural question is how the framework can be ex- [8] G. Kaniadakis, in the context of special relativity. Phys. Rev. E 66 (2002) 056125. tended to the well-known of chemical [9] P. Jizba and T. Arimitsu, The world according to Renyi: reactions [23–26] where systems are composed of more thermodynamics of multifractal systems. Ann. Phys. 312 than one type of atom. (2004) 17. [10] C. Anteneodo and A. R. Plastino, Maximum entropy ap- proach to stretched exponential probability distributions. ACKNOWLEDGEMENTS J. Phys. A 32(7) (1999) 1089. [11] E. Lutz and F. Renzoni, Beyond Boltzmann-Gibbs sta- tistical mechanics in optical lattices. Nat. Phys. 9 (2013) We acknowledge support from the Austrian Science 615-619. fund Projects I 3073 and P 29252 and the Austrian Re- [12] A. Dechant, D.A. Kessler and E. Barkai, Deviations from search Promotion agency FFG under Project 857136. We Boltzmann-Gibbs statistics in confined optical lattices. thank Tuan Pham for helpful discussions. Phys. Rev. Lett. 115 (2015) 173006. [13] P. Jizba and J. Korbel, Maximum Entropy Principle in Statistical Inference: Case for Non-Shannonian En- tropies. Phys. Rev. Lett. 122 (2019) 120601. DATA AVAILABILITY [14] P. Jizba and J. Korbel, When Shannon and Khinchin meet Shore and Johnson: Equivalence of information All relevant data are available at: theory and statistical inference axiomatics. Phys. Rev. https://github.com/complexity-science- E 101 (2020) 042126. [15] H. J. Jensen, R. H. Pazuki, G. Pruessner and P. Tem- hub/Thermodynamics-of-structure-forming-systems. pesta, Statistical mechanics of exploding phase spaces: ontic open systems. J. Phys. A 51 (2018) 375002. [16] V. Latora, V. Nicosia, and G. Russo, Complex networks: AUTHOR CONTRIBUTIONS principles, methods and applications. Cambridge Univer- sity Press, Cambridge, (2017). J.K., R.H. and S.T. conceptualized the work, S.D.L. [17] T. Squartini, J. de Mol, F. den Hollander and D. Gar- laschelli, Breaking of Ensemble Equivalence in Networks. performed the computational work, all authors con- Phys. Rev. Lett. 115 (2015) 268701. tributed to analytic calculations and wrote the paper. [18] C. Berge, Graphs and Hypergraphs. North-Holland mathematical library (1973). [19] O. N. Temkin, A. V. Zeigarnik, and D. G. Bonchev, COMPETING INTERESTS Chemical reaction networks: a graph-theoretical ap- proach. CRC Press (1996). [20] C. Flamm, B. M. R. Stadler, and P. F. Stadler, General- The authors declare no competing interests. ized topologies: hypergraphs, chemical reactions, and bi- ological evolution. Advances in Mathematical Chemistry and Applications. Bentham Science Publishers, (2015) 300-328. [21] B. Smit and D. Frenkel, Explicit expression for finite size ∗ Correspondence to: [email protected] corrections to the chemical potential. J. Phys.: Condens. [1] S. Thurner, P. Klimek, and R. Hanel, Introduction to the Matt. 1 (1989) 8659. Theory of Complex Systems. Oxford University Press, [22] J. I. Siepmann, I. R. McDonald, and D. Frenkel, Finite- Oxford (2018). size corrections to the chemical potential. J. Phys.: Con- [2] R. Hanel and S. Thurner, A comprehensive classification dens. Matt. 4(3) (1992) 679. of complex statistical systems and an axiomatic deriva- [23] D. Chandler and L. R. Pratt, Statistical mechanics of tion of their entropy and distribution functions. Euro- chemical equilibria and intramolecular structures of non- phys. Lett. 93 (2011) 20006. rigid molecules in condensed phases. J. Chem. Phys. [3] R. Hanel and S. Thurner, When do generalized 65(8) (1976) 2925-2940. apply? How phase space volume determines entropy. Eu- [24] H. J. Kreuzer, Nonequilibrium thermodynamics and its rophys. Lett. 96 (2011) 50003. statistical foundations. Clarendon Press, Oxford and [4] R. Hanel, S. Thurner, and M. Gell-Mann, How multiplic- New York (1981). ity determines entropy and the derivation of the maxi- [25] P. T. Cummings and G. Stell, Statistical mechanical mum entropy principle for complex systems. Proc. Natl. models of chemical reactions: Analytic solution of mod- Acad. Sci. U.S.A. 111, 6905 (2014). els of A + B AB in the Percus-Yevick approximation. [5] J. Korbel, R. Hanel and S. Thurner, Classification of Mol. Phys. 51(2) (1984) 253-287. complex systems by their sample-space scaling expo- [26] T. Schmiedl and U. Seifert, Stochastic thermodynamics nents. New J. Phys. 20 (2018) 093007. of chemical reaction networks. J. Chem. Phys. 126(4) [6] C. Tsallis, Possible generalization of Boltzmann-Gibbs (2007) 044101. statistics. J. Stat. Phys. 52 (1988) 479. 9

[27] J. N. Israelachvili, D. J. Mitchell, and J. W. Ninham, [47] U. Seifert, Stochastic thermodynamics: principles and Theory of self-assembly of lipid bilayers and vesicles. perspectives. Eur. Phys. J. B 64 (2008) 423–431. Biochimica et Biophysica Acta (BBA)-Biomembranes [48] M. Esposito and C. Van den Broeck, The Three Faces of 470(2) (1977) 185-201. the Second Law: I. Master Equation Formulation. Phys. [28] I. S. Aranson, and L. S. Tsimring, Theory of self- Rev. E 82 (2010) 011143. assembly of microtubules and motors. Phys. Rev. E [49] M. Esposito and C. Van den Broeck, Three Detailed Fluc- 74(3) (2006) 031915. tuation Theorems. Phys. Rev. Lett. 104 (2010) 090601. [29] A. Walther and A. H. E. Muller, Janus particles: synthe- [50] G. E. Crooks, Entropy production fluctuation theorem sis, self-assembly, physical properties, and applications. and the nonequilibrium work relation for free-energy dif- Chem. Rev. 113(7) (2013) 5194-5261. ferences. Phys. Rev. E 60(3) (1999) 2721. [30] W. W. Grabow and L. Jaeger, RNA self-assembly and [51] D. Kagan et al., Chemical sensing based on catalytic RNA nanotechnology. Accounts of chemical research nanomotors: motion-based detection of trace silver. J. 47(6) (2014) 1871-1880. Am. Chem. Soc. 131(34) (2009) 12082-12083. [31] R. Fantoni, A. Giacometti, F. Sciortino and G. Pastore, Cluster theory of Janus particles. Soft Matter 2011(7) (2011) 2419-2427. [32] M. Nguyen and S. Vaikuntanathan, Design principles for nonequilibrium self-assembly. Proc. Nat. Acad. Sci. USA 113 (50) (2016) 14231-14236. [33] G. Bisker and J. L. England, Nonequilibrium associative retrieval of multiple stored self-assembly targets- Proc. Nat. Acad. Sci. USA 115 (45) (2018) E10531-E10538. [34] A. Arango-Restrepo, D. Barrag´anand J. M. Rubi, Self- assembling outside equilibrium: emergence of structures mediated by dissipation. Phys. Chem. Chem. Phys. 21 (2019) 17475-17493. [35] L. Boltzmann, Uber¨ das Arbeitsquantum, welches bei chemischen Verbindungen gewonnen werden kann. An- nalen der Physik 258(5) (1884) 39-72. [36] E. H. Lieb and J. Yngvason, The physics and mathe- matics of the second law of thermodynamics. Phys. Rep. 310(1) (1999) 1-96. [37] C. N. Likos, F. Sciortino, E. Zaccarelli and P. Ziherl, Soft Matter Self-Assembly. Proceedings of the International School of Physics ”” 193 (2016). [38] T. Vissersa, F. Smallenburga, G. Munao, Z. Preisler and F. Sciortino, Cooperative polymerization of one-patch colloids. J. Chem. Phys. 140 (2014) 144902. [39] Z. Preisler, T. Vissers, G. Munao, F. Smallenburg, and F.. Sciortino, Equilibrium phases of one-patch colloids with short-range attractions. Soft Matter 10 (2014) 5121- 5128. [40] N. Kern and D. Frenkel, Fluid–fluid coexistence in col- loidal systems with short-ranged strongly directional at- traction, J. Chem. Phys. 118 (2003) 9882–9889. [41] L. Rovigatti, J. Russo, and F. Romano, How to simulate patchy particles. Eur. Phys. J. E 41 (2018) 59. [42] R. Pfister, K. Schwarz, M. Janczyk, R. Dale, and J. Free- man, Good things peak in pairs: a note on the bimodality coefficient. Front. Psychol. 4 (2013) 700. [43] R. B. Griffiths, C.-Y. Weng, and J. S. Langer, Relaxation Times for Metastable States in the Mean-Field Model of a Ferromagnet. Phys. Rev. 149 (1966) 301. [44] R. Botet, R. Jullien, and P. Pfeuty, Size Scaling for In- finitely Coordinated Systems. Phys. Rev. Lett. 49 (1982) 478. [45] N. Gulbahce, H. Gould, and W. Klein, Zeros of the par- tition function and pseudospinodals in long-range Ising models. Phys. Rev. E 69 (2004) 036119. [46] L. Colonna-Romano, Harvey Gould, and W. Klein, Anomalous mean-field behavior of the fully connected Ising model. Phys. Rev. E 90(4) (2014) 042111. 10

Supplementary Information

This Supplementary Information to the paper Thermodynamics of structure-forming systems contains additional information, mainly on details of analytical and numerical computations. It also contains more examples that we mention in the main text.

Supplementary Methods

Equivalence of the exact calculation of the sample space with the grand-canonical ensemble in the thermodynamic limit

Here we show the equivalence of the presented approach with the grand-canonical ensemble in the thermodynamic limit and the limit of low concentrations. Let us consider a chemical reaction, 2X X2, with n particles. Let us denote the number of particles X as nX and the number of molecules X2 as nX2 . Without loss of generality, let us consider that free particles have an energy  and molecules have zero energy. Exact calculation: Let us start with entropy 2 S(℘ , ℘ ) = −℘ log ℘ − ℘ (log ℘ + 1) − ℘ log (34) X X2 X X X2 X2 X2 c

normalization constraint, ℘X + 2℘X2 = 1, and the energy constraint, ℘X = U. From this we obtain

℘X = exp(−(α) − β) , (35) c ℘ = exp(−2(α)) . (36) X2 2 The Lagrange multiplier α can be calculated from the normalization constraint c exp(−(α) − β) + 2 · exp(−2(α)) = 1 . (37) 2 We obtain two solutions of the quadratic equation, of which only one has a physical meaning, i.e.,

 2ce−1+β  α = log √ . (38) −1 + 1 + 4ce2β Helmholtz free-energy can be obtained as  √  √ ! −2β 2β 2β αn n(℘ + ℘ ) n −1 + 1 + 4ce2β n e 2ce + 4ce + 1 F = − − X X2 = log − (39) β β β 2ceβ−1 β 4c

Grand-canonical ensemble: Let’s now compare the exact result with the usual approach using the grand-canonical ensemble. The partition function of the grand-canonical ensemble can be expressed as

∞ X 1 1   βµX2 −β(−µX ) Z = exp(−β( − µX )nX ) exp(βµX2 nX2 ) = exp e + e , (40) nX ! nX2 ! nX ,nX2 =0

where µX and µX2 are the chemical potentials. From the Gibbs-Duhem relation, we get that µX2 = 2µX . We denote the chemical potential by µ. The average number of particles can be calculated as ∂ log hni = Z = 2e2βµ + eβ(µ−) . (41) β∂µ This relation serves as an equation for µ, which has the same form as Eq. (37), and the solution can be found as  √  −1+ 1+8hnie2β log 4eβ µ = . (42) β 11

Helmholtz free-energy can be expressed from the grand-potential Ω = −β log Z as F = Ω + µhni By plugging in the chemical potential, we obtain that   ! −2β 2β p 2β hni −1p1 + 8hnie2β e 4hnie + 8hnie + 1 − 1 F = log − . − hni loghnin (43) β 4eβ 8β

For large hni, the fluctuations of particles diminish, so only the states with the average number of particles become relevant and we can set hni = n. Moreover, the first term becomes dominant, so

! hni −1 + p1 + 8hnie2β F (β, , n) ≈ µ = log , (44) β 4eβ and we see that the free-energies of both approaches coincide for c = n/2.

Derivation of the second law of thermodynamics for non-equilibrium structure-forming systems

The time derivative of entropy can be expressed as   dS X (j) (j) X (j) X (j) j! = − ℘˙ (log ℘ − 1) − ℘˙ − ℘˙ log . (45) dt i i i i cj−1 ij ij ij

By plugging in the master equation we can further obtain that   X (l) (j) X (l) j! S˙ = − wjl ℘ log ℘ − wjl ℘ log ik k i ik k cj−1 ijkl ijkl (j)   1 X (j) (l) ℘ 1 X (j) (l) j! = + (wlj ℘ − wjl ℘ ) log i + (wlj ℘ − wjl ℘ ) log cl−j 2 ki i ik k (l) 2 ki i ik k l! ijkl ℘k ijkl lj (j) lj ! 1 X (j) (l) w ℘ 1 X (j) (l) j! w = (wlj ℘ − wjl ℘ ) log ki i + (wlj ℘ − wjl ℘ ) log cl−j ki 2 ki i ik k jl (l) 2 ki i ik k l! jl ijkl wik℘k ijkl wik | {z } S˙i≥0 β X (j) (l) (j) (l) α X (j) (l) = S˙ + (wlj ℘ − wjl ℘ )( −  ) + (wlj ℘ − wjl ℘ )(j − l) . (46) i 2 ki i ik k i k 2 ki i ik k ijkl ijkl | {z } S˙e=βQ˙

Let us note that from the first law of thermodynamics,

˙ X (j) (j) X (j) (j) ˙ ˙ U = ℘˙i i + ℘i ˙i = Q + W , (47) ij ij the entropy flow is equal to the heat flow over the temperature. Let us focus on last term, which can be expressed as

1 X (j) (l) X (j) (wlj ℘ − wjl ℘ )(l − j) = ℘˙ j≡ 0 (48) 2 ki i ik k i ijkl ij is the time derivative of the normalization condition, i.e., the number of particles in the system and therefore it is identical to zero. Therefore, the second law of thermodynamics can be expressed in the form

dS = S˙ + βQ˙ . (49) dt i 12

Derivation of the detailed fluctuation theorem for non-equilibrium structure-forming systems

Let us now focus on the derivation of entropy production along a stochastic trajectory. We define entropy along a stochastic trajectory |bt = (i(τ), j(τ)) in the following form  (j(τ))!  s(x(τ)) = − log ℘(j(τ))(τ) − 1 + log (50) i(τ) cj(τ)−1

− − + + Let us consider that the stochastic trajectory has jumps at times tz from (iz , jz ) to (iz , jz ) with transition rate + − jz ,jz w + − . By taking the time derivative we obtain iz ,iz  (j+)  ℘ z + j−−1 ! 1 (j(τ)) X i+ X (j )! c z s˙ = − ∂ ℘ − δ(τ − t ) log z − δ(τ − t ) log z . (51) (j(τ)) τ i(τ) z  −  z − + (jz ) (jz )! cjz −1 ℘i(τ) z ℘ − z iz With a little bit of care, we can recognize that the entropy can be decomposed into two terms. First is entropy flow rate  j−j+  w z z + j−−1 X i−i+ (j )! c z X (j−) (j+) s˙ = δ(τ − t ) log z z z = β δ(τ − t )( z −  z ) (52) e z  + − − +  z i− i+ jz jz (jz )! jz −1 z z z w + − c z iz iz and second, entropy production rate along a stochastic trajectory

− + +  jz jz jz  w − + ℘ + 1 (j(τ)) X iz iz iz s˙i = − ∂τ ℘i(τ) − δ(τ − tz) log  + − −  . (53) (j(τ)) jz jz jz ℘i(τ) z w + − ℘ − iz iz iz

Thus, we obtains ˙ =s ˙i +s ˙e. The ensemble second law of thermodynamics can be recovered by multiplying the (j) trajectory second law by ℘i and summing over i, j. Let us consider a stochastic trajectory x(τ) = (i(τ), j(τ)), where τ ∈ [0,T ]. Let us consider that jumps happen at times τz, z ∈ {1,...,N} from (iz−1, jz−1) to (iz, jz). Let us also time-dependent protocol l(τ) that controls the energy spectrum of the system. We define a quantity

" N j j # R τz 0 z−1 z−1 0 R T 0 jN jN 0 (j0) Y dτ wi i (l(τ )) jz jz−1 dτ w (l(τ )) ℘(x(τ)) = ℘ (0) e τz−1 z−1 z−1 w (l(τ )) e τN iN iN (54) i0 iz iz−1 z z=1 that corresponds to a “probability” of the trajectory x(τ). We can interpret this quantity as the relative number of clusters in the state x(τ) over the total number of particles. Indeed, this quantity does not sum up to one. Similarly, consider reverse trajectory x˜(τ) = (i(T − τ), j(T − τ)) and reverse protocol ˜l(τ) = l(T − τ). We consider microreversibility, i.e., that the detailed balance holds also under the external protocol. Then, we define

" N # R T 0 j0j0 ˜ 0 R T −τz dτ 0wjz jz (l(τ 0)) ˜ dτ wi i (l(τ )) Y jz−1jz T −τ iz iz (jN ) ℘(x˜(τ)) = e T −τ1 0 0 w (˜l(T − τ ))e z+1 ℘ (T ) . (55) iz−1iz z iN z=1 The log-ratio of both quantities can be expressed as ℘ N wjz jz−1 (l(τ )) (x(τ)) (j0) (jN ) X iz iz−1 z log = log ℘i (0) − log ℘i (T ) + log ℘˜ 0 N wjz−1jz (˜l(T − τ )) (x˜(τ)) z=1 iz−1iz z

(j0) j0! (jN ) jN ! = log ℘i (0) + log − log ℘i (T ) − log 0 cj0−1 N cjN −1 N jz jz−1 ! w (l(τ )) jz −1 X iz iz−1 z jz−1! c + log j j j −1 = ∆s − ∆se = ∆si (56) w z−1 z (˜l(T − τ )) jz! c z−1 z=1 iz−1iz z (j) (j) Let us now consider the master equation for probability pi = j℘i that a particle belongs to the cluster of size j (j) with energy i :

(j) X (l) X j (l) p˙ = W jlp ≡ wjl p (57) i ik k l ik k kl kl 13

jl j jl From this, we obtain that Wik = l wik. Thus, the probability of observing the trajectory x(τ) with the protocol l(τ) can be expressed as

" N j j # R τz 0 z−1 z−1 0 R T 0 jN jN 0 (j0) Y dτ Wi i (l(τ )) jz jz−1 dτ W (l(τ )) P(x(τ)) = p (0) e τz−1 z−1 z−1 W (l(τ )) e τN iN iN (58) i0 iz iz−1 z z=1 and similarly the probability of the time-reversed trajectory under the time-reversed protocol can be written as

" N # R T 0 j0j0 ˜ 0 R T −τz 0 jz jz 0 dτ W (l(τ )) Y jz−1jz dτ Wi i (l(τ )) (jN ) P˜(x˜(τ)) = e T −τ1 i0i0 W (˜l(T − τ ))e T −τz+1 z z p (T ) . (59) iz−1iz z iN z=1 Therefore, the log-ratio can be expressed as

N W jz jz−1 (l(τ )) P(x(τ)) (j0) (jN ) X iz iz−1 z log = log pi (0) − log pi (T ) + log P˜(x˜(τ)) 0 N W jz−1jz (˜l(T − τ )) z=1 iz−1iz z N  2 wjz jz−1 (l(τ )) (j ) (j ) X jz iz iz−1 z = log p 0 (0) − log p N (T ) + log i0 iN j j jz−1 w z−1 z (˜l(T − τ )) z=1 iz−1iz z N wjz jz−1 (l(τ )) (j0) (jN ) X iz iz−1 z = log pi (0) − log pi (T ) + 2 log j0 − 2 log jN + log 0 N wjz−1jz (˜l(T − τ )) z=1 iz−1iz z p(j0)(0) p(jN )(T ) i0 j0! iN jN ! = log + log j − log − log j j0 c 0 jN c N N jz jz−1 ! w (l(τ )) jz j0 X iz iz−1 z jz−1! c + log + log jz−1jz jN w (˜l(T − τ )) jz! cjz−1 z=1 iz−1iz z

℘(x(τ)) j0 j0 = log + log = ∆si + log . (60) ℘˜ (x˜(τ)) jN jN Therefore, we can write down that

P(x(τ)) j0 log = ∆si + log = ∆σ . (61) P˜(x˜(τ)) jN

We can express the probability of observing ∆σ as Z  P(x(τ)) P (∆σ) = D[x(τ)]P(x(τ))δ ∆σ − log P˜(x˜(τ)) ! Z P˜ (x˜(τ)) = exp(∆σ) D[x˜(τ)]P˜ (x˜(τ)) δ −∆σ − log P˜(x(τ)) = exp(∆σ)P˜(−∆σ) . (62) This gives us the detailed fluctuation theorem for ∆σ. Let us now assume that the initial state is in equilibrium. We rewrite ∆si as

∆si = ∆s − βq = β(w + q − ∆f) − βq + ∆m = βw − β∆f . (63)

Let us now express free-energy f of the equilibrium distribution  cj−1  j!  α 1 f(℘ ˆ (j)) = (j) − T s(℘(j)) = (j) + T log − jα − β(j) − 1 + log = −j − . (64) i i i i j! i cj−1 β β From the ensemble averaging we obtain that

X (j) (j) α X (j) 1 X (j) α 1 X (j) α M ℘ˆ f(℘ ˆ ) = − j℘ − ℘ˆ = − − ℘ˆ = − − = F . (65) i i β i β i β β i β β ij ij ij ij 14

By plugging (64) into (61) we obtain

P(x(τ)) j0 = exp (βw + (jf αf − j0α0)) . (66) P˜(x˜(τ)) jN

(j) By substitution j exp(−αj) = p /Zj, we obtain

(j ) P(x(τ)) p 0 Zj = f exp(βw) (67) ˜ (jf ) P(x˜(τ)) p Zj0 which can be further rewritten as

P(x(τ)|j0) = exp(βw − β(Φjf (l(T )) − Φj0 (l(0)) (68) P˜(x˜(τ)|jf )

1 where Φj = − β log Zj. The probability observing work w starting from an equilibrium state with j0 can be expressed as Z ! P(x(τ)|j0) P0(w|j0) = D[x(τ)]P(x(τ)|j0)δ βw − β(Φjf − Φj0 ) − log P˜(x˜(τ)|jf ) Z ! P˜(x˜(τ)|jf ) = exp(βw − β(Φjf − Φj0 )) D[x˜0(τ)]P(x˜(τ)|jf )δ −βw − β(Φj0 − Φjf ) − log P(x(τ)|j0) ˜ = exp(βw − β(Φjf − Φj0 ))P0(−w|jf ) (69) which gives us the Crooks’ work fluctuation theorem for structure-forming systems.

Derivation of the self-consistency equation for magnetization in the fully connected Ising model

The free-energy for the fully connected Ising model is given by α M F = − − , (70) β β where α are the same as for the molecule gas in the magnetic field (see the following section on the molecule gas in the presence of the magnetic field), just with the effective field heff = (Jm + h). The self-consistency equation is obtained from the relation ∂F m = − | , (71) ∂h h=0 which leads to the following equation   sinh(Jmβ)  n  m = 1 +  . (72) pn + cosh(Jmβ)2   q 2   cosh(βJm) + cosh2(βJm) + n 

This equation has to be solved numerically, similarly to the case of the fully connected Ising model without molecule states. The solution is depicted in Fig. 4 in the main text.

Monte Carlo simulation of the fully connected Ising model

We describe now Monte Carlo simulation applied to a system of free particles with two states {↑, ↓} and the two- particle molecule with one state {k} and a Hamiltonian H(n↑, n↓, nk) = −h(n↑ − n↓). The algorithm puts particles into two boxes, one box for free particles and one box for two particle molecules. The approach is similar to how Panagiotopoulos described in [1]. For example consider boxes, one for “Atoms” and one for two particle molecules. 15

Here Box 1 contains the states {↑, ↓} and Box 2 the states {k}. Two kinds of MC-moves are tried. The first kind of move randomly chooses a particle in the ↑ or ↓ state and changes it to the other state. The move is then accepted with the probability min (1, exp(−β∆H)). The second kind of move is either dividing a state {k} particle in two states {↑, ↓}, or combining two random particles from Box 1 to a state {k} particle. Which one of the two moves is tried is chosen randomly with equal probability. The division move takes a Box 2 particle (two particle molecule) and deletes it and two new Box 1 particle (one-atomic particles) are generated in its stead. The state of the new particle is either ↑ or ↓. Which of the two states the particles are created in is chosen randomly with the probability of the current distribution of the two states in Box 1. The move is then accepted with the probability  2nkn↑!n↓!  min 1, exp(−β∆H) , wheren ˜↑ andn ˜↓ are the numbers for ↑ and ↓ particles after the move, respectively. n˜↑!˜n↓! The combination move takes two random particles in Box 1 deletes them and creates a new particle in Box 2. The  n↑!n↓!  move is then accepted with min 1, exp(−β∆H) . Here,n ˜↑ andn ˜↓ are once again the number of ↑ and ↓ n˜↑!˜n↓!(2nk+2) particles after the move, respectively. The simulation ends after the ensemble does not change significantly anymore and reaches an equilibrium. The final output is the mean over 1000 simulations at a certain temperature value. Each simulation consists of 2 million steps.

SUPPLEMENTARY DISCUSSION

Relation of the entropy for molecule system to axiomatic frameworks

In this section, we discuss the relation of the entropy for molecule systems to existing axiomatic frameworks, including axiomatics of Shannon and Khinchin and its generalizations according to Tempesta and Jensen, and Hanel and Thurner, and also axiomatics according to Shore and Johnson. Lieb-Yngvason axioms Let’s discuss the main properties of the entropic functional (10). We start with additivity and extensivity, as introduced by Lieb and Yngvason [2]. Additivity can be formulated as S((X,Y )) = S(X) + S(Y ) (see Eq. (2.4) in [2]) where (X,Y ) is a cartesian product of two systems, i.e., a state of the composed systems is a pair (x, y), where x ∈ X and y ∈ Y . We consider two systems, one with χ particles, the other with ξ particles. For simplicity, consider that the particles can attain the same states for both systems. We denote the number of (j) (j) (j) clusters in state xi in the first and second subsystem as χi and ξi , respectively. Since the two subsystems are (j) (j) (j) independent, the total multiplicity for ni = χi + ξi is simply given by the product of two multiplicities, so that

(j) (j) (j) W (ni ) = W (χi )W (ξi ) , (73)

(j) (j) (j) from which we immediately see that S(ni ) = S(χi ) + S(ξi ). The second property, extensivity, states that S(tX) = tS(X), where tX is the rescaled version of the system (see Eq. (2.5) in [2]). For simplicity, let us consider (j) that we double the system, i.e., t = 2. This means that we have 2n particles and there are 2ni particles in the state (j) xi . We also have to double the systems’ volume, i.e., we divide the total system into 2b boxes. The entropy of the double system is then equal to

(j) ! 2n X (j) 2n S(2n) = 2n log − 2n − 2n log i − 1 2b i 2b ij X (j) − 2ni log j! = 2S(n) . (74) ij Thus, the entropy is extensive. Another important property is concavity of entropy, ensuring the uniqueness of the maximum entropy principle. Since it is straightforward to show that

∂2S(P ) 1 = − δ 0 δ 0 , (75) (j) (j0) (j) ii jj ∂pi ∂pi0 jpi we conclude that the entropy is a concave function of probability distribution. Classes of entropies and joint entropies: Before we move to particular axiomatic frameworks based on information- theoretic approaches, let us discuss typical classes of entropies that are taken into account. These are P 1. Trace-class entropies S(P ) = i g(pi) 16

P 2. Sum-class entropies S(P ) = f( i g(pi)). These entropies are widely used in information theory and statistical physics because of its nice properties. However, neither of the classes is suitable for our case. One of the issues that occur is that these entropy classes are symmetric functions of all probabilities, which is a consequence of the principle that relabeling the states should not change the entropy (also called permutational invariance - see the next section about Shore-Johnson axioms). It is, however, not the case of a system with molecule states. Here, switching the order of molecules (e.g., from free particle states to molecule states) changes the system’s entropy since the states corresponding to molecules of different orders are states of different types, and one cannot expect that the symmetry argument holds. There is another assumption that is implicitly considered by these classes of entropy. Namely, it is the assumption that the joint entropy, i.e., the entropy of the joint distribution has the same functional form as the entropy of the marginal distribution, i.e., in the case of the joint probability of two random variables, we have X S(pij) = f( g(pij)) (76) ij

This assumption makes perfect sense for systems with exponential sample spaces, where the joint distribution can also be interpreted as a marginal distribution of a system that is obtained by merging the two systems together, i.e., X × X ∼ 2X, where on the left-hand side is the cartesian product of two systems and on the right-hand side is the rescaled version of the system. However, in our case W (2n) ≥ W (n)2 so there is no such correspondence. Let us demonstrate this on an example of two systems A and B with n and m molecules. Corresponding probability (j) (j0) distributions areu ˜i andv ˜i0 . The entropy of the composed system (A, B) ≡ A × B is given by the sum of the entropies of two systems, as demonstrated above. If we try to express this entropy in terms of joint distribution (jj0) (j) (j0) p˜ii0 =u ˜i v˜i0 we obtain

(j) (j) ! (j) ! X u˜ u˜ X u˜ j! S(A, B) = − i log i − 1 − i log j j j j−1 ij ij cA 0 0 0 (j ) (j ) ! (j ) 0 ! X v˜ 0 v˜ 0 X v˜ 0 j ! − i log i − 1 − i log j0 j0 j0 j0−1 i0j0 i0j0 cB  P (jj0) P (jj0)  X (jj0) 1 i0j0 p˜ii0 1 ij p˜ii0 = − p˜ 0 log − 1 + log − 1 ii  j j j0 j0  iji0j0

0 ! X (jj0) 1 j! 1 j ! − p˜ 0 log + log (77) ii j j−1 j0 j0−1 iji0j0 cA cB

So we see that the joint entropy is expressible in terms of the joint distribution, but the functional form is different from the entropy of the marginal distribution. Let us note that the composed system created from systems with n1 particles and n2 particles is, in general, different from a system with n1 + n2 particles. Therefore, one cannot expect that the system’s entropy can be obtained as a sum of the subsystems. The system’s state space with n1 + n2 particles cannot be represented as a cartesian product of states from the subsystems. A simple example can exemplify this issue: we can consider a molecule state consisting of two particles in a system. The first particle is taken from the first n1 particles, and the other particle is taken from the remaining n2 particles. Such a state has no representation in the Cartesian product. It is the consequence of the fact that the sample space grows super-exponentially, and therefore W (n) > W (n1)W (n2). Shannon-Khinchin axioms: Shannon-Khinchin (SK) axioms characterize the properties of the Shannon entropy from the information-theoretic point of view. They were proposed independently by Shannon [3] and Khinchin [4] to determine the Shannon entropy uniquely. In the original formulation, the Shannon-Khinchin axioms are the following: 1. Continuity: Entropy is a continuous function of probability distribution. 2. Maximality: Entropy is maximal for the uniform distribution. 3. Expansibility: Adding an elementary event with probability zero does not change the entropy. P 4. Additivity: H(A, B) = H(A) + H(B|A), where H(B|A) = i piH(B|A = ai). 17

P Since the original four axioms uniquely determine Shannon entropy H(P ) = − i pi log pi, several authors proposed generalizations of the original scheme. The typical approach is to weaken the fourth axiom to obtain a wider class of entropies while the first three axioms remain unchanged. Thus, before discussing the generalizations of the fourth SK axiom, let us focus on the first three axioms. It is easy to show that the molecule entropy fulfills the first and the third axiom. As we have discussed in the main text, the entropy is not maximized by the uniform distribution when molecules of different sizes are present. The maximality axiom results from a similar requirement, i.e., that the entropic functional should be symmetric and Schur-concave function of the probability distribution. In the last section, we have discussed that the assumption of symmetry is not suitable for our system. Therefore, it is more natural to weaken the maximality axiom to the following form:

2. Maximality: Entropy is maximal for a distribution, where each microstate contributes with equal probability.

By a generalization of SK2, the entropy of molecule states fulfills the first three SK axioms, plus the first part of the fourth one, i.e., S(A × B) = S(A) + S(B), where A × B is the Cartesian product of random variables. It means that the state space is a Cartesian product of A and B and joint probability is simply a marginal probabilities product, as demonstrated in the previous section, when we discussed entropy’s additivity. Let us now omit discussion about the definition of conditional probability, which is quite technical and would deserve a separate paper. Tempesta axioms and group entropies: Tempesta proposed in the series of papers [5–7] a generalization of SK axioms, but weakening the fourth axiom by imposing that the entropy should fulfill the group property:

4. Group composability: S(A, B) = Φ(S(A),S(B)) where x, y 7→ Φ(x, y) is the group action. In the previous section, we have shown that the entropy of molecule systems is additive and therefore fulfills the composability property with Φ(x, y) = x + y. However, the whole calculation was done in the framework of sum-class of entropies. Therefore, the entropy of structure-forming systems does not fall into this reduced class of entropies that work with states of the same structure. However, when relaxing the second SK axiom and omitting the requirement of symmetric entropies, the entropy of molecule systems belongs to the class of group entropies. Relaxing 2nd SK axiom in the framework of group entropies would an important step in the future research. Hanel-Thurner axioms and entropy scaling: Hanel and Thurner generalized the fourth axiom differently. They did not require any particular composition law; they only examined the asymptotic scaling of the entropy for the case of distribution that maximizes the entropy as a function of the system size (here the number of particles) [8, 9]. The resulting classification leads to the set of scaling exponents (originally (c, d)) that determined universality classes of entropic functionals. Since the entropic functionals are considered to be trace-class, asymptotic scaling was examined for uniform distribution. Nevertheless, for the entropy of structure-forming systems, the distribution that maximizes the entropy does not have to be uniform. Actually, by plugging the MaxEnt distribution into the entropy of molecule systems, we obtain that S(n) ∼ log n, so we obtain that (c, d) = (0, 1), which is the case of additive entropies (including Shannon entropy). Shore-Johnson axioms: Shore and Johnson considered the principle of maximum entropy as a statistical inference method and formulated a set of consistency requirements [10, 11]. They considered the class of inductive inference (i.e., they are in the form of averaged quantities). The requirements are the following:

• Uniqueness: the result should be unique.

• Permutation invariance: the permutation of states should not matter.

• Subset independence: It should not matter whether one treats disjoint subsets of system states in terms of separate conditional distributions or in terms of the full distribution.

• System independence: It should not matter whether one accounts for independent constraints related to inde- pendent systems separately in terms of marginal distributions or in terms of full system.

• Maximality: In absence of any prior information, the uniform distribution should be the solution. In [11] was shown, these axioms are equivalent to Tempesta’s group composability under the assumption of sum-class entropies. Indeed, some of the axioms are not fulfilled for the case of molecule entropy. Especially axioms 2 and 5 are other forms of the same assumption that entropy should be a symmetric function of its variables. Therefore, a generalization of SJ axioms for state spaces with states of different types should be reasonable. 18

FIG. 4: Specific heat of the molecule model with magnetic field. We observe a phase transition for the magnetic model. The critical temperature decreases with n to zero very slowly (inset).

Presence of magnetic gas phase for molecule-forming particles in presence of magnetic field

Let us consider a system of n particles where free particles can have two states {↑, ↓} and two-particle molecules have one state {k}. Let us assume the case when the system is small and dense so that all particles can interact with each other. The Hamiltonian corresponding to the magnetic field is

H(n↑, n↓, nk) = −h(n↑ − n↓) . (78)

d2F We calculate the specific heat c = −T dT 2 and we see that there is a phase transition between the magnetic phase and molecule phase which grows with n, as shown in Fig. 4 Let us note that the dependence of critical temperature on n, where limN→∞ Tc(N) = 0. However, as shown in the inset, the critical temperature is well separated from zero even for large, but finite systems, since the convergence is very slow. It should be mentioned that the magnetic gas has been observed for low temperatures experimentally [12, 13].

Finite-size correction to chemical potential

Let us consider again the chemical reaction 2X X2. Without loss of generality, assume that free particles carry some energy . The equilibrium constant of the chemical reaction can be expressed as

nX2 ℘X2  c  Kc = 2 = 2 = exp 2β + log . (79) nX (℘X ) 2

eff 1 c Thus, we obtain the effective chemical potential, ∆µ = 2 + β log 2 , where the first term can be obtained from the ordinary grand-canonical ensemble of two-gas system and the second one is the correction which is obtained from the molecule entropy. This means that if the two gases are perfectly mixed in a small region so that every particle can interact with each other particle, the value of the chemical potential explicitly depends on the number of particles — with an increasing number of particles the chemical potential increases. In fact, the finite-size corrections to the chemical potential have been considered in several aspects, especially in case of interacting particles [14, 15]. In our case, the correction is simply because of the structure-forming states. 19

SUPPLEMENTARY REFERENCES

∗ Correspondence to: [email protected] [1] A. Z. Panagiotopoulos, Monte Carlo methods for phase equilibria of fluids. J. Phys.: Condens. Matt. 12(3) (1999) 25-52. [2] E. H. Lieb and J. Yngvason, The physics and mathematics of the second law of thermodynamics. Phys. Rep. 310(1) (1999) 1-96. [3] C. Shannon, A mathematical theory of communication. Bell Syst. Tech. J. 27 (1948) 379. [4] A.I. Khinchin, Mathematical Foundations of Information Theory. Dover Publications, New York (1957). [5] P. Tempesta, Beyond the Shannon–Khinchin formulation: The composability axiom and the universal-group entropy. Ann. Phys. 365 (2016) 180. [6] H. J. Jensen and P. Tempesta, Group entropies: From Phase Space Geometry to Entropy Functionals via Group Theory. Entropy 20 (2018) 804. [7] P. Tempesta and H. J. Jensen, Universality Classes and Information-Theoretic Mesure of Complexity via Group Entropies. Sci. Rep. 10 (2020) 5952. [8] R. Hanel and S. Thurner, A comprehensive classification of complex statistical systems and an axiomatic derivation of their entropy and distribution functions. Europhys. Lett. 93 (2011) 20006. [9] J. Korbel, R. Hanel and S. Thurner, Classification of complex systems by their sample-space scaling exponents. New J. Phys. 20 (2018) 093007. [10] P. Jizba and J. Korbel, Maximum Entropy Principle in Statistical Inference: Case for Non-Shannonian Entropies. Phys. Rev. Lett. 122 (2019) 120601. [11] P. Jizba and J. Korbel, When Shannon and Khinchin meet Shore and Johnson: Equivalence of information theory and statistical inference axiomatics. Phys. Rev. E 101 (2020) 042126. [12] G.-B. Jo, Y.-R. Lee, J.-H. Choi, C. A. Christensen, T. H. Kim, J. H. Thywissen, D. E. Pritchard, and W. Ketterle, Itinerant Ferromagnetism in a of Ultracold Atoms. Science 325 (2009) 5947. [13] R. A. Duine and A. H. MacDonald Itinerant Ferromagnetism in an Ultracold Atom Fermi Gas.- Phys. Rev. Lett. 95 (2005) 230403. [14] B. Smit and D. Frenkel, Explicit expression for finite size corrections to the chemical potential. J. Phys.: Condens. Matt. 1 (1989) 8659. [15] J. I. Siepmann, I. R. McDonald, and D. Frenkel, Finite-size corrections to the chemical potential. J. Phys.: Condens. Matt. 4(3) (1992) 679.