diff --git a/modelling/src/setup_scorer.cc b/modelling/src/setup_scorer.cc
index 793cc7cefc11a5d8d0be86275eea830459643c53..51703fcf8e8148ce29a2d361a10353cd54091e94 100644
--- a/modelling/src/setup_scorer.cc
+++ b/modelling/src/setup_scorer.cc
@@ -283,8 +283,9 @@ void AttachDistanceConstraints(promod3::loop::BackboneLoopScorerPtr scorer,
ExtractPositions(aln, valid_residues, positions);
//Generate DisCo scores and update the scorer
- for(int i = 0; i < aln.GetLength(); ++i){
- for(int j = i + 1; j < aln.GetLength(); ++j){
+ int seqres_length = aln.GetSequence(0).GetGaplessString().size();
+ for(int i = 0; i < seqres_length; ++i){
+ for(int j = i + 1; j < seqres_length; ++j){
std::vector<Real> disco;
bool contains_info = GenerateDisCo(valid_residues, positions,
clusters, cluster_weights,