Method and apparatus for depositing atomic layers on a substrate