Molecular dynamics (MD) is a method for computer simulation of the complex interplay between atoms and molecules at finite temperature. For this purpose we calculate the time evolution of atoms by solving Newton's equations of motion. In contrast to MD simulations with empirical interaction potentials, the forces are obtained ”on the flyâ with the aid of parameter-free electronic structure calculations. A key advantage of this method is transferability, which is important if one aims to make predictions for unknown systems under conditions that have not been realized yet. Another very important advantage is high accuracy, but the computational effort is generally of order O(N^3), where N denotes the number of atoms. With a new formalism, based on the grand-canonical potential and a factorization of the density matrix, we avoid the diagonalization of the corresponding Hamiltonian matrix. Additionally we make use of the fact that the Hamiltonian and the density matrix are sparse due to localization. In this way we reduce the complexity of the calculations, which include the determination of the interaction potential, so that we achieve linear scaling with respect to the system's size. We are going to apply our code on a system with 1000 methane molecules, which we expose to extreme pressure and temperature. We can observe the dissociation of methane and the formation of carbon chains.