Chemistry of precipitation and scale formation in geological systems