How to derive the relation between gibbs energy and equilibrium constant?

I want to understand the derivation between gibbs energy and equillibrium constant $$\Delta G=\Delta G^o+RT\ln Q?$$ I have seen a similar post on CSE Derivation of relationship between equilibrium constant and Gibbs free energy change which seems to be incomplete and still confusing so I am again asking this question.

The derivation that was written in the post was as follows:

Using the fundamental equations for the state function (and its natural variables):_ $$dG=-SdT+VdP$$ $$V=(\dfrac {\partial G}{\partial P})_T$$ $$\bar G(T,P_2)=\bar G(T,P_1)+\int_{P_1}^{P_2}\bar V dp$$ Here $$\bar x$$ represents molar $$x$$, i.e. $$x$$ per mole $$\bar V=\frac {RT}{P}$$ $$\bar G(T,P_2)=\bar G(T,P_1)+RT \ln\frac {P_2}{P_1}$$ Defining standard state as $$P=1\text{bar}$$ and $$\bar G=\mu$$ $$\mu(T,P)=\mu^o (T)+RT\ln \frac{P}{P_o}$$ consider the general gaseous reaction $$aA+bB\rightarrow cC+dD$$ $$\Delta G=(c\mu_C+d\mu_D-a\mu_A-b\mu_B)$$ for "unit progress" in reaction. Using $$\mu_i=\mu^o_i+RT\ln \frac{P_i}{1bar}$$ $$\Delta G=(c\mu^o_C+d\mu^o_D-a\mu^o_A-b\mu^o_B)+RT\ln \frac{P_C^cP_D^d}{P_A^aP_B^b}$$ $$\Delta G=\Delta G^o+RT\ln Q$$

1. I know the relation between Gibbs free energy,Enthalpy,Entropy and Temperature as $$G = H - TS$$ how is the relation $$dG=-SdT+VdP$$ derived from the above formula?
2. Why do we take a path where Entropy and volume are constant in the equation $$dG=-SdT+VdP$$ as in a chemical reaction both volume and entropy can change?
• When you are talking about the change in a state function like G, it is important to precisely define the initial and final thermodynamic equilibrium states of the system you are considering. In your equation describing $\Delta G$, what is your understanding of the initial and final thermodynamic equilibrium states that are being considered? Nov 28 '18 at 15:43
• @ChesterMiller It must involve some change in pressure and volume under constant temperature. Nov 28 '18 at 16:16

Firstly, if you know the relation $$G= H-TS$$, you can reach at the differential form of it just by taking differential at both sides, i.e.$$dG= dH-SdT-TdS$$ Now, recall the definition of enthalpy as $$H= U +PV$$, So, we can write, $$dH= dU + PdV + VdP$$, and also recall the heat supplied to the system as $$dQ= TdS$$ and by the first law of Thermodynamics, $$dQ= dU+ PdV$$ .Thus combining we have $$dG= dU+PdV+VdP-SdT-dQ = VdP -SdT$$ Thus you derive the required relationship.
Now coming to your next question, it's not about taking path where Entropy and volume remains constant. A state in a thermodynamic system can be defined in terms of three parametrs which are interrelated i.e Pressure, Temperature and Volume. In fact, you can only independently vary any two out of these three parameters and third one will automatically get adjusted. Here the independent variables are Temperature and Pressure. By changing the Pressure and Temperature independently, the change in the Gibbs' Free Energy is calculated. The coefficients are volume and Entropy only but that doesn't mean they are kept constant. So, the interpretation of the equation $$dG= VdP- SdT$$ needs to be done correctly.
For a pure species, the general equation for dG is $$dG = -SdT+VdP$$. This equation does not assume that S and V are constant. To get the free energy of each species at an arbitrary pressure and temperature T, we integrate VdP from one bar to the arbitrary pressure (using the ideal gas law); at a pressure of 1 bar and temperature T, the free energy of the pure species is equal to $$\mu^0(T)$$, the free energy of formation of the species (from its elements) at T and 1 bar.
That basically summarizes the initial and final states, and how $$\Delta G$$ is calculated for the change between these states.