Equilibrium and non-equilibrium thermodynamics of templating reactions for the formation of nanowires