Implement ReplaceAtoms.