Electronic Structures and Optical Properties of Open and Capped Carbon Nanotubes