Nearest neighbor thermodynamic algorithm