I have a QVector of instances of an object Atom, where each Atom instance contains a set of cartesian coordinates and a unique index identifier, among other attributes. I have also defined a Dyad container, which is just a tuple of two Atom instances. Basically, if my two Atom instances satisfy a distance constraint, I want to be able to construct a QList of Dyads.
Say I had a Dyad of (Atom1,Atom2), how could I ensure that my QList did not already contain a Dyad of (Atom2, Atom1)?
I have already tried to use the QList .contains() function and have overloaded my == operator, but I cannot get it to work. I can attach the code that I have tried insofar as trying to use the contains() function if that would help.
// Function Definition
QList<AtomDyad> getUniqueAtomPairs(QVector<Atom> atomVector) {
QList<AtomDyad> AtomDyadPairList;
for (int iatom = 0; iatom < atomVector.size(); iatom++) {
for (int jatom = 0; jatom < atomVector.size(); jatom++) {
if (iatom == jatom) { continue; }
float x1 = atomVector[jatom].getX();
float x2 = atomVector[iatom].getX();
float y1 = atomVector[jatom].getY();
float y2 = atomVector[iatom].getY();
float z1 = atomVector[jatom].getZ();
float z2 = atomVector[iatom].getZ();
float Radii_Sum1 = atomVector[jatom].getvdW_radius(atomVector[jatom]) + atomVector[iatom].getvdW_radius(atomVector[iatom]);
if (DistanceBetween3DPoints(x1, x2, y1, y2, z1, z2) <= Radii_Sum1) {
AtomDyad MyDyad(atomVector[iatom], atomVector[jatom]);
// How can I ensure that MyDyad(atomVector[jatom], atomVector[iatom]) does not already exist?
AtomDyadPairList.append(MyDyad);
}
}
}
return AtomDyadPairList;