valid atom-mapping algorithm