# Tutorial 2: entropy of mixing of methanol+water

When two pure liquids are put in contact the new configurations that the molecules can adopt and the new molecular interactions will lead to a change in entropy. Typically, this change is positive because of disorder, although in principle specific molecular interactions can lead to a decrease in entropy in some cases. For ideal gases, the entropy of mixing has an analytical expression, and it depends only on the relative number of molecules of each component in the mixture. The total entropy of a mixture of ideal gases is:

$S_\text{mixture}^\text{ideal} = \sum\limits_\Lambda N_\Lambda \bar{S}_\Lambda - k_\text{B} \sum\limits_\Lambda N_\Lambda \ln{\left(\frac{N_\Lambda}{N}\right)},$

where $N_\Lambda$ is the number of molecules of component $\Lambda$ and $N$ is the total number of molecules. $\bar{S}_\Lambda$ refers to the entropy per molecule in the pure component $\Lambda$. For real mixtures, one defines the excess entropy of mixture $S_\text{mix}^\text{E}$ to account for the deviation of the mixing entropy with respect to what one would expect for ideal systems:

$S_\text{mix}^\text{E} = S_\text{mixture}^\text{real} - S_\text{mixture}^\text{ideal}$.

In this tutorial we will calculate $S_\text{mix}^\text{E}$ for a 2:1 mixture of water and methanol. More detailed information can be found in Ref.

## Generating the trajectories

For this tutorial we will use Gromacs to generate the mixture of liquids and the pure liquids. We will use the OPLS force field and the SPCE water model. For methanol we will use the topology available from virtualchemistry.org. We will constrain all bonds with H atoms.

You can skip this section and download the trajectories that we will be analyzing from Zenodo. Then continue with the 2PT analysis section.

### Generating the starting configurations

We need the OPLS topology file for methanol (methanol.itp), which we retrieved from virtualchemistry.org. If you reuse this topology file make sure to properly credit the authors. We also need two sample molecules to generate our liquids, one for water, "water.gro":

One water
3
1SOL     OW    1   0.114   0.845   0.401 -0.5236  0.3981  0.1442
1SOL    HW1    2   0.118   0.886   0.491  1.8112 -1.0518 -0.9491
1SOL    HW2    3   0.147   0.758   0.425  1.3601  2.0733  3.6058
1.20000   1.20000   1.20000


and one for methanol, "methanol.gro":

One methanol
6
1MET    C      1   0.697   0.788   0.843
1MET    H      2   0.600   0.829   0.873
1MET    H      3   0.781   0.853   0.870
1MET    H      4   0.706   0.773   0.736
1MET    O      5   0.701   0.664   0.911
1MET    H      6   0.761   0.600   0.875
1.20000   1.20000   1.20000


We are going to work with 2400 atoms total. This means that our pure water box will contain 800 molecules, our pure methanol box will contain 400 methanol molecules, and our 2:1 mixture will contain 400 water molecules and 200 methanol molecules. We can build our pure water and pure methanol boxes as follows:

gmx insert-molecules -box 3.0 3.0 3.0 -ci water.gro -nmol 800 -try 20 -o pure_water.gro
gmx insert-molecules -box 3.1 3.1 3.1 -ci methanol.gro -nmol 400 -try 20 -o pure_methanol.gro


For the mixture we are going to generate 10 different configurations. This is so that we can obtain statistics. It is important that these initial configurations are completely uncorrelated, and so we will use bash random variables as seed for the generation:

for i in seq 1 1 10; do
gmx insert-molecules -box 3.1 3.1 3.1 -ci water.gro -nmol 400 -try 20 -o temp1.gro -seed $RANDOM gmx insert-molecules -f temp1.gro -ci methanol.gro -nmol 200 -try 20 -o temp2.gro -seed$RANDOM


### Running DoSPT

Make sure that "groups", "supergroups" and cell inside "input" are consistent with the number of molecules in the .gro file. Let's rock:

for i in "pure_methanol" "pure_water" "mixture_1" "mixture_2" "mixture_3" "mixture_4" "mixture_5" "mixture_6" "mixture_7" "mixture_8" "mixture_9" "mixture_10"; do

if [ $i == "pure_methanol" ]; then sup="1-400" nmet=400; nwat=0 elif [$i == "pure_water" ]; then
sup="1-800"
nmet=0; nwat=800
else
sup="1-400\n401-600"
nmet=200; nwat=400
fi

echo -e $sup > supergroups cat>generate_groups.py<<eof nwat=$nwat
nmet=$nmet print nwat*3+nmet*6, nwat+nmet for i in range(0,nwat): print 3,2 print i*3+1, i*3+2, i*3+3 for i in range(0,nmet): print 6,1 print nwat*3+i*6+1, nwat*3+i*6+2, nwat*3+i*6+3, nwat*3+i*6+4, nwat*3+i*6+5, nwat*3+i*6+6 eof python generate_groups.py > groups cp input.bk input l=tail -1 NPT_${i}.gro
echo "cell = $l" >> input mv traj_${i}.gro traj.gro
DoSPT
mv traj.gro traj_${i}.gro cp entropy entropy_$i
done


### Extracting the entropies

Now the entropies have been calculated and saved to the different entropy_* files. We can check the end of file "entropy_pure_water":

tail -6 entropy_pure_water


This is the output:

# Supergroup; Entropies in eV/K [trans, rot, vib]; Total entropy in eV/K; Total entropy in J/K
1   4.13456046E-01   8.80711771E-02   9.52792811E-11   5.01527224E-01   4.83908071E+04

# Entropy results with DoS normalized to the expected degrees of freedom
# Supergroup; Entropies in eV/K [trans, rot, vib]; Total entropy in eV/K; Total entropy in J/K
1   4.12011614E-01   8.81638786E-02   8.28867038E-05   5.00258379E-01   4.82683802E+04


We can see that for this pure liquid the results with and without DoS renormalization are quite similar: 60.5 J/mol/K and 60.3 J/mol/K, respectively. Let's check for one of the mixtures:

tail -8 entropy_mixture_4


with output:

# Supergroup; Entropies in eV/K [trans, rot, vib]; Total entropy in eV/K; Total entropy in J/K
1   2.25777654E-01   4.17108936E-02   4.75239016E-11   2.67488547E-01   2.58091407E+04
2   1.40468723E-01   9.53297770E-02   1.40387307E-02   2.49837231E-01   2.41060199E+04

# Entropy results with DoS normalized to the expected degrees of freedom
# Supergroup; Entropies in eV/K [trans, rot, vib]; Total entropy in eV/K; Total entropy in J/K
1   2.25115191E-01   4.17555990E-02   3.15295619E-05   2.66902319E-01   2.57525774E+04
2   1.37401314E-01   9.35018991E-02   1.42622772E-02   2.45165490E-01   2.36552581E+04


So the molar entropies of the [water; methanol] components are [64.5; 120.5] J/mol/K and [64.4; 118.3] J/mol/K without and with DoS renormalization, respectively. We can see that for methanol the results with and without DoS renormalization start to vary significantly. But let's get some statistics:

for i in "pure_methanol" "pure_water" "mixture_1" "mixture_2" "mixture_3" "mixture_4" "mixture_5" "mixture_6" "mixture_7" "mixture_8" "mixture_9" "mixture_10"; do

if [ $i == "pure_methanol" ]; then echo "# System; S_raw (J/mol/K); S_ren (J/mol/K)" S_raw=tail -6 entropy_$i | awk 'NR == 2{print $6/400}' S_ren=tail -1 entropy_$i | awk '{print $6/400}' elif [$i == "pure_water" ]; then
S_raw=tail -6 entropy_$i | awk 'NR == 2{print$6/800}'
S_ren=tail -1 entropy_$i | awk '{print$6/800}'
else
S_raw=tail -8 entropy_$i | awk '{if(NR == 2){wat=$6} else if(NR == 3){met=$6}} END {print (wat+met)/600}' S_ren=tail -2 entropy_$i | awk '{if(NR == 1){wat=$6} else if(NR == 2){met=$6}} END {print (wat+met)/600}'
fi

echo $i${S_raw} ${S_ren} done  with the following output: # System; S_raw (J/mol/K); S_ren (J/mol/K) pure_methanol 121.118 119.765 pure_water 60.4885 60.3355 mixture_1 82.4227 82.2495 mixture_2 82.4857 82.3186 mixture_3 83.2054 82.4541 mixture_4 83.1919 82.3464 mixture_5 82.2207 82.047 mixture_6 82.0043 81.8674 mixture_7 83.0834 82.2327 mixture_8 82.7768 82.3641 mixture_9 81.7088 81.751 mixture_10 82.1603 81.8783  You can already see that the DoS renormalization is stabilizing the mixture results. We would also be able to see similar stabilization for the pure liquids, but we would need more samples. But don't take my word for it, put these results in a file ("file") and use awk to print averages and standard deviation: av=awk 'NR>3{raw +=$2/10.; ren += $3/10.} END {print raw, ren}' file av=($av)
std=awk -v av_raw=${av} -v av_ren=${av} 'NR>3{raw += ($2-av_raw)**2/10.; ren += ($3-av_ren)**2/10.} END {print sqrt(raw), sqrt(ren)}' file
std=($std) printf " Raw: %.1f +- %.1f J/mol/K\n Ren: %.1f +- %.1f J/mol/K\n"${av} ${std}${av} \${std}


And we get the final results, showcasing the utility of the DoS renormalization scheme:

Raw: 82.5 +- 0.5 J/mol/K
Ren: 82.2 +- 0.2 J/mol/K


### Computing the excess entropy of mixing

To compute the excess entropy of mixing we will use the DoS-renormalized results. The standard molar entropies of the pure liquids are $\bar{S}_\text{wat} = 60.3$ J/mol/K and $\bar{S}_\text{met} = 119.8$ J/mol/K, the entropy of the mixture is $\bar{S}_\text{mixture} = 82.2$ J/mol/K. The excess entropy of mixing is:

$\bar{S}^\text{E}_\text{mix} = \bar{S}_\text{mixture} - \frac{400}{600} \bar{S}_\text{wat} - \frac{200}{600} \bar{S}_\text{met} + R \frac{400}{600} \ln{\left( \frac{400}{600} \right)} + R \frac{200}{600} \ln{\left( \frac{200}{600} \right)},$

where $R = 8.314$ J/mol/K is the gas constant ($R = N_\text{A} k_\text{B}$). The final result is $\bar{S}^\text{E}_\text{mix} = -3.2$ J/mol/K. The experimental value is approximately $-3.8$ J/mol/K.

## Homework

We didn't check the statistical variation of the pure liquid, which can in fact be large for methanol. Check the effect of that quantity on the final result. You can also check the effect of using different combinatorial entropy of mixing (entropy_mixture tag) and diffusivity models (hs_formalism tag) on the results.