Origin of planets and atmospheres