Shrinkable muscular crystal with chemical logic gates driven by external ion environment