The attached file contains a script contributed by Ed O'Brien to calculate the excess chemical potential using the Widom particle insertion method.
widom_insertion.txt (462 downloads)
The code is based on the algorithm described by Frenkel in his book 'Understanding Molecular Simulation.' Please look there for details.
In the script, the chemical potential is printed out using the variable @chempot.
L Nilsson made some changes for increased file reading efficiency.