Ab initio simulations of the molecular switch on the base of the STM induced isomerization of the naphtalocyanine molecule is presented. The free energy profile and reaction path were analyzed using the metadynamics method within the scope of the Car-Parrinello Molecular Dynamics (CPMD) code. Simulations were done on the IBM Blue Gene/P supercomputer at Moscow State University. The barrier height for the reaction along the coordination variable is found for the hydrogen isomerization reaction. Electronic density evolution in the switching process is analyzed.