First principles calculations of surfaces and layered materials