Energy Conservation¶
This section provides detailed theory of energy conservation in cavity-coupled molecular dynamics.
Total Energy Decomposition¶
Complete Energy Expression¶
The total energy of a cavity-coupled molecular system is:
Molecular kinetic energy:
Cavity kinetic energy:
Potential energy:
Includes bonds, angles, dihedrals, Lennard-Jones, Coulomb, etc.
Cavity harmonic energy:
Coupling energy:
Self-energy:
Conservation Laws¶
Microcanonical (NVE) Ensemble¶
Without thermostats:
Energy is exactly conserved (within numerical precision).
Numerical conservation:
Typically \(\epsilon < 10^{-4}\) for good integrators.
Canonical (NVT) Ensemble¶
With thermostats:
where \(P_{\text{thermostat}}\) is power injected/removed by thermostats.
Temperature is conserved:
Energy fluctuates:
where \(C_V\) is heat capacity.
Energy Conservation During Coupling Switch¶
For time-dependent \(g(t)\):
Step function switch (t = t_switch):
Total energy is conserved across the switch.
Energy redistribution:
Before switch (g=0):
After switch (g=g_0):
Conservation requires:
This is automatically satisfied by the cavity particle position jump in finite-q mode.
Numerical Energy Drift¶
Sources of Energy Drift¶
1. Integration error:
Finite timestep \(\Delta t\) introduces truncation error:
where p is integrator order (p=2 for Velocity Verlet).
2. Force discontinuities:
Cutoffs in pair potentials
Bond breaking/formation
Domain decomposition boundaries
3. Thermostat artifacts:
Improper thermostat implementation
Too-strong coupling
4. Numerical precision:
Round-off errors
Accumulation over long simulations
Minimizing Energy Drift¶
1. Reduce timestep:
For systems with high-frequency modes.
2. Use smooth potentials:
Continuous forces (no sharp cutoffs)
Switching functions for long-range interactions
3. Proper thermostats:
Use well-tested implementations (Bussi, Langevin)
Reasonable coupling constants
4. Monitor energy:
Regular checks during simulation:
energy_drift = abs(E[-1] - E[0]) / abs(E[0])
if energy_drift > 1e-3:
print("WARNING: Significant energy drift!")
Energy Analysis in Practice¶
Monitoring Energy Components¶
Track all components:
import numpy as np
data = np.loadtxt('energy_tracker.txt', skiprows=1, delimiter='\t')
time = data[:, 0]
E_kin = data[:, 1]
E_pot = data[:, 2]
E_cav = data[:, 3]
E_coup = data[:, 4]
E_self = data[:, 5]
E_tot = data[:, 6]
# Check conservation
drift = (E_tot[-1] - E_tot[0]) / E_tot[0]
print(f"Energy drift: {drift*100:.4f}%")
Expected behavior:
NVE: Total energy constant
NVT: Total energy fluctuates, temperature constant
Components exchange energy dynamically
Energy Equipartition¶
At equilibrium:
Check:
T_kinetic = 2 * np.mean(E_kin) / (3 * N * k_B)
T_target = 100.0 # K
if abs(T_kinetic - T_target) / T_target < 0.05:
print("Equipartition satisfied")
Virial and Pressure¶
Virial theorem:
For bound systems at equilibrium:
Cavity contribution to pressure:
Usually negligible compared to molecular pressure.
Next Sections¶
Analysis Tools for practical energy analysis
Time-Varying Coupling for energy during coupling switches
Thermostats for energy exchange with thermostats