Custom Loss Function in Keras to minimize a vector

I’m trying to implement a custom loss function for a neural network in Keras. The model must be trained to predict quaternion (a specific vector with four elements)
Y_pred = [w x y z]

Y_true and Y_pred are quaternion and the error is calculated by quaternion multiplication:

Error = Y_true * inverse(Y_pred)

Error = [w_err x_err y_err z_err]

Ideally, the first element must be 1 and other elements must be 0:

Error = [1 0 0 0]

How can I create such a custom loss function?

The inverse is calculated by

inverse(Y_pred) = [w, -x, -y, -z]

I just want to know that I would advise you to use Keras backend functions instead of Numpy functions to avoid any misadventure. Keras backend functions work almost similar to Numpy functions.