Simulation of structural phase transitions by metadynamics