Chain metallicity and competition between paramagnetism and antiferromagnetism in underdoped YBa2Cu3O6+x: A first principles description