As far as I know, free energy can not directly calculated from the trajactory output of molecular dynamics simlations. I have modified the lammps source code a little in order to have the useful output for helmholtz free energy calculations. Here is my paper and also the reference I used for free energy calculations. Hope it helps.
1. H. Zhao, and N. R. Aluru, ``Molecular Dynamics Simulation of Bulk Silicon Under Strain’’, Journal of Interaction and Multiscale Mechanics, Vol. 1, No. 2, 303-315, 2008.
2. D. Frenkel and A J C Ladd, “New Monte Carlo method to compute the free energy of arbitrary solids: Applications to the free and hcp phases of hard spheres”, J. Chem. Phys. 81(7) 3188-3193 (1984).