"Algebras/MFE/alg_ali_mfe.gap" is similar to Algebras/MFE/alg_mfe.gap, but the free energy for a structural motif is now the sum of the energies for this motif for all subsequences in the alignment. This is realized by a for-loop, which iterates over the rows of the alignment. Due to gaps, the situation becomes more complicated, because the motifs might change between the alignment rows, e.g. a left bulge loop might become a stem, if all bases of the loop are gaps for a specific alignment row. An internal-loop might transform into a bulge or a stem, an hairpin can have zero bases in it's loop, ... All those cases are hidden within the interface to the energy parameters.
The "score" has now two components: the energy - as in single sequence folding - and a covariance term. This value rises if paired position shows a high covariance. The final score is simply the sum of both components; their influence can be weighted by special parameters, see alifold.hh