Molecular geometries from spin Hamiltonian calculations through simultaneous optimization of geometry and wave function