The following is what I believe is necessary to solve Exercise 1.3.4 in Shorter Model Theory by Hodges.
Given two structure $\mathcal {A, B}$ of the same signature $\tau$, a set $S$ of generators of $\mathcal A$ and a map $\phi: A \rightarrow B$ (where $A, B$ are the domains of $\mathcal {A, B}$, resp.) such that for any atomic $\tau$-formula $\psi(\vec x)$ and any $\vec s \in S^n$ if $\mathcal A \models \phi(\vec s)$ then $\mathcal B \models \psi(\phi(\vec s))$, show that for any function symbol $f$, we have $f^{\mathcal B}(\phi(\vec s)) = \phi(f^{\mathcal A}(\vec s))$.
An obvious try is that replace $\phi(\dots)$ in the desired property with variables. However, this doesn't work since $f^{\mathcal A}(\vec s)$ is not known to be in $S$.
How can I prove this?
EDIT: The precondition for $\psi$ should be that it is atomic. Sorry for the confusion.
This is a mistake in Hodges. What is true (and a good exercise!) is that if $f$ is a partial map $A\to B$ defined on a set $S$ of generators for $A$, then $f$ can be extended to some homomorphism $A\to B$ if and only if it preserves atomic formulas (i.e. for $\overline{s}$ from $S$ and an atomic formula $\psi$, if $A\models \psi(\overline{s})$, then $B\models \psi(f(\overline{s})$).