Is it possible to attach the endpoints of a curve to two spheres, so that the endpoints would always move with the spheres even when moving the spheres independently of each other? Optimally it should also stretch and compress as the spheres move further apart and closer to each other. I'm doing animations of chemical reactions where I'm depicting the bonds between atoms with a curve which should stay attached to the animated atoms and I'd rather not calculate the transformations for the bonds separately.
This is a great case for hooks.
Position your two spheres where you want. Then add the curve between then with the two ends where you want them to touch on the spheres.
In object mode select one of the spheres then select the curve; hit Tab to go in to edit mode. In the curve's edit mode select the end point of the curve on the same end as the selected sphere, then press ctrl H. Choose hook to selected object.
Repeat for the other end of the curve on the other sphere.
Use hooks to attach each end of the curve to a sphere. You will most likely want to set the curve handles to vector so the curve stays straight between the two points.
I would then add a driver to the curve's bevel depth to have it change size based on the distance between the two spheres.
Using hooks is a good idea. I'll add that the laplacian deform modifier works well with hooks for creating deformation effects that resemble natural tug. This short video shows the effect of the modifier and how to apply it using hooks. https://www.youtube.com/watch?v=VgiekNOK0Vw I created a simple example to demonstrate how this could be useful for this particular problem. https://www.dropbox.com/s/9dpgvb9ht0bh9vj/laplacian_deform_test.blend