Generating optical nonlinearity using trapped atoms