Adding an energy based on some vertices of one mesh (fenicsx)

Hello,
I use the hyper elasticity tutorial as a basis ( Hyperelasticity — FEniCSx tutorial)
Now, I would like to attach a spring-like structure to some vertices.
The vertices are indicated in a xdmf file.
So my elastic energy should be like \frac12(x[0]-x[1])^2.
Is there a way to add it to the system ?

Best,
Raphaël