Confusion about Free Energy and the Hamiltonian I'm probably making a relatively basic mistake here, but I'm a bit confused about the relation between the Hamiltonian and Helmholtz free energy.
From what I can see, the free energy can be written as a function of the partition function as:
$$
A= -\frac{1}{\beta}log(Z)
$$
And the partition function can be written as a function of the Hamiltonian as:
$$
Z = tr(e^{-\beta H})
$$
(This is for the quantum case, but my question applies equally to the classical case)
From this, as far as I can see the free energy depends only on the Hamiltonian, not on the actual state of the system (other than its temperature), which I find hard to understand. 
For example, imagine the free energy of a free particle before and after it collides with another particle. It will have the same Hamiltonian before and after the collision, but conceptually it seems like the free energy should change (for example if the collision increases its momentum)
Could somebody unravel my confusion here?
 A: The formulae you quote are not the cleanest for understanding. Let's re-write them: $$e^{-\beta F} = \mathrm{tr}\left(e^{-\beta H}\right).$$ On the left, $F$ is just a number, whereas on the right, $H$ is an operator. The trace can be thought of as an average — which raises the question of what ensemble are we averaging over. The answer, as Lubos alludes to, is the unique mixed state (the Gibbs state) defined by the temperature and the Hamiltonian. If there are more relevant quantities which constrain the macroscopic state, then the expression should be changed. For example, if number of particles is allowed to fluctuate, then we get: $$e^{-\beta F} = \mathrm{tr}\left(e^{-\beta H - \beta \mu N}\right).$$ However, you are certainly at liberty to define other kinds of free energies, depending on the ensemble you choose.
A: When you specify a precise temperature of a physical system, then you are specifying the exact (mixed) state whose probability distribution is $\exp(-\beta E(p_i,q_i))$ (up to the overall normalization coefficient) classically or whose density matrix is proportional to $\exp(-\beta H)$ quantum mechanically.
These formulae are supposed to be used for systems with many degrees of freedom that interact with each other. They're either in thermal equilibrium or not. If they are, the formulae are applicable and the state – equilibrium state at a given temperature – is essentially unique.
It's not a good idea to talk about the entropy or free energy in the context of one particle or two particles (e.g. your colliding pair) because the entropy (which also enters free energy) is ill-defined and/or ambiguous for such small systems. Equivalently, the precise density matrix and/or probability distribution for one or two particles or other similar systems is a subjective concept.
A: No one has pointed out that you are correct - the Hamiltonian can remain the same while the free energy still changes.
This can happen when a system loses energy to friction you aren't modeling, but it can also happen when a system loses degrees of freedom.  Think for example of two particles that collide with each other and then stick together perfectly.  In this case, the Hamiltonian energy will remain the same, but the free energy must decrease since the system has lost an available state for its partition function to count.
