How to extract the Potential Energy of Protein and Ligand from the Entire System after MD Simulation

The only problem I will mention is not a technical one, but a theoretical one. Extracting individual energies of various components has no physical meaning. No force field is parametrized in such a way that the absolute potential energies are targeted. You can calculate the quantity as shown, but the results will not tell you anything.