Theoretical study of perfect and defective TiO2 crystals