We consider the two-step method [A. R. Kuzmak and V. M. Tkachuk, Phys. Lett. A 378 (2014) 1469] for preparation of an arbitrary quantum gate on two spins with anisotropic Heisenberg interaction. At the first step, the system evolves during some period of time. At the second step, we apply pulsed magnetic field individually to each spin. We obtain the conditions for realization of SWAP, iSWAP, [Formula: see text] and entangled gates. Finally, we consider the implementation of this method on the physical system of ultracold atoms in optical lattice.