Magnetic coupling and dynamics in solid alpha and beta-O2. I. An ab initio theoretical approach