Lattice dynamics studies of grain boundary structures: I. Method and application to stability