restrict atoms inplace=False

Fix for #508.

I don't think restrict_atoms is a very good name for this function. If anyone can come up with a better one, that would be good.