From 68ae8ae75a9ad7f5587bae735b475e3ad402785f Mon Sep 17 00:00:00 2001 From: Lester Hedges Date: Tue, 20 Aug 2024 12:08:55 +0100 Subject: [PATCH] Backport fix from PR #229. [ci skip] --- corelib/src/libs/SireIO/grotop.cpp | 58 +++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/corelib/src/libs/SireIO/grotop.cpp b/corelib/src/libs/SireIO/grotop.cpp index 43c169a15..87908ea6b 100644 --- a/corelib/src/libs/SireIO/grotop.cpp +++ b/corelib/src/libs/SireIO/grotop.cpp @@ -2869,6 +2869,7 @@ static QStringList writeAtomTypes(QMap, GroMolType> &moltyps QString particle_type = "A"; // A is for Atom + // This is a dummy atom. if (elem.nProtons() == 0 and lj.isDummy()) { if (is_perturbable) @@ -2877,6 +2878,9 @@ static QStringList writeAtomTypes(QMap, GroMolType> &moltyps // Only label dummies for regular simulations. else if (not was_perturbable) particle_type = "D"; + + // Flag that we need to update the atoms. + update_atoms0 = true; } // This is a new atom type. @@ -2893,6 +2897,15 @@ static QStringList writeAtomTypes(QMap, GroMolType> &moltyps // Hash the atom type against its parameter string, minus the type. param_hash.insert(atomtypes[atomtype].mid(6), atomtype); + + if (update_atoms0) + { + // Set the type. + atom.setAtomType(atomtype); + + // Update the atoms in the vector. + atoms[i] = atom; + } } // This type has been seen before. else @@ -2977,6 +2990,17 @@ static QStringList writeAtomTypes(QMap, GroMolType> &moltyps update_atoms0 = true; } } + else + { + if (update_atoms0) + { + // Set the type. + atom.setAtomType(atomtype); + + // Update the atoms in the vector. + atoms[i] = atom; + } + } } } @@ -3019,9 +3043,15 @@ static QStringList writeAtomTypes(QMap, GroMolType> &moltyps QString particle_type = "A"; // A is for Atom + // This is a dummy atom. if (elem.nProtons() == 0 and lj.isDummy()) + { atomtype += "_du"; + // Flag that we need to update the atoms. + update_atoms1 = true; + } + // This is a new atom type. if (not atomtypes.contains(atomtype)) { @@ -3036,6 +3066,15 @@ static QStringList writeAtomTypes(QMap, GroMolType> &moltyps // Hash the atom type against its parameter string, minus the type. param_hash.insert(atomtypes[atomtype].mid(6), atomtype); + + if (update_atoms1) + { + // Set the type. + atom.setAtomType(atomtype); + + // Update the atoms in the vector. + atoms[i] = atom; + } } // This type has been seen before. @@ -3121,6 +3160,17 @@ static QStringList writeAtomTypes(QMap, GroMolType> &moltyps update_atoms1 = true; } } + else + { + if (update_atoms1) + { + // Set the type. + atom.setAtomType(atomtype); + + // Update the atoms in the vector. + atoms[i] = atom; + } + } } } @@ -3217,14 +3267,6 @@ static QStringList writeMolType(const QString &name, const GroMolType &moltype, elem1 = Element::elementWithMass(mol.property("mass1").asA()[cgatomidx]); } - // Update the atom types. - - if (elem0.nProtons() == 0) - atomtype0 += "_du"; - - if (elem1.nProtons() == 0) - atomtype1 += "_du"; - QString resnum = QString::number(atom0.residueNumber().value()); if (not atom0.chainName().isNull())