Pull Request №696 RosettaCommons/rosetta/main ← lyskov-ai/rosetta/fix/incorrect-comparison-operators
Merge: d10f3af574b60550f256856d5a9742600ce1128b←8fc631652510bbfa47c5575107e9de808b7804ce
Fix incorrect comparison logic in operator< / difference_from
----------------
Merge commit message:
Fix incorrect comparison logic in operator< / difference_from
Four independent classes had broken comparison logic that violated
either the contract of `operator<` (strict weak ordering) or the
intended semantics of `difference_from`:
* `core/chemical/sdf/mol_util.cc`: `BondData::operator<` was
`(lower < other.lower) || (upper < other.upper)`. This is not a
strict weak ordering — for `(5,1)` vs `(3,7)`, both compare less
than each other, breaking antisymmetry. `BondData` is used inside
`std::set<BondData>` (see `parse_bond_type_data`), so the broken
ordering directly affects the set. Replaced with a proper
lexicographic compare via `std::tie`.
* `core/scoring/motif/motif_hash_stuff.cc`:
`ResPairMotif::operator<` returned `0 < memcmp(...)`, i.e. it
reported "less than" exactly when memcmp said "greater than" —
the comparison was inverted. Switched to `memcmp(...) < 0`, which
matches the correct convention (and matches `MotifHit::operator<`
in the same file).
* `core/io/StructFileReaderOptions.cc`: `operator<` was using `==`
instead of `!=` for the short-circuit "return false" lines. The
intent of the pattern is "if a < b return true; if a != b return
false; otherwise fall through to the next member" (this is exactly
what the parent `StructFileRepOptions::operator<` does), but the
`==` form returned false when members were equal — short-circuiting
before the rest of the members were ever compared, *and* failed to
return false when members satisfied `>`. Fixed every `==` to `!=`
and added the missing `!=` follow-up after `glycam_pdb_format_`.
* `core/chemical/gasteiger/GasteigerAtomTypeData.cc`:
`difference_from` short-circuited "return Other" when
`charge_ == OTHER.charge_ || element_type_ != ... || ...`.
The first clause is inverted: the function should return Other
when these fundamental properties *differ*, not when they match.
Otherwise, two types with equal charge but otherwise comparable
properties were misclassified as `Other` and the rest of the
function (which uses `charge_` to compute lone-pair / s-orbital
/ p-orbital differences) was unreachable. Fixed `==` to `!=`.