We consider the two-step method [A. R. Kuzmak, V. M. Tkachuk, Phys. Lett. A 378, 1469(2014] 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, √ SW AP and entangled gates. Finally, we consider the implementation of this method on the physical system of ultracold atoms in optical lattice.