Skip to content

Commit

Permalink
Fixed the merge code by making sure that the AtomIdx of the added ato…
Browse files Browse the repository at this point in the history
…m is correct

for its position in the molecule (i.e. is one higher than the AtomIdx of the last
atom in the residue)
  • Loading branch information
chryswoods committed Jun 22, 2024
1 parent b1db53c commit 26a79ee
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions corelib/src/libs/SireSystem/merge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,26 @@ namespace SireSystem

auto res = mol.residue(residx);

// get the AtomIdx of the last atom in this residue
AtomIdx last_atomidx(0);

if (res.nAtoms() > 0)
{
last_atomidx = res.atom(res.nAtoms() - 1).index();
}

// add the atom - it has the name "Xxx" as it doesn't exist
// in the reference state
auto atom = res.add(AtomName("Xxx"));
largest_atomnum = AtomNum(largest_atomnum.value() + 1);
atom.renumber(largest_atomnum);

// ensure that its index follows on from the index of the
// last atom in the residue - this is so that we keep
// the AtomIdx and CGAtomIdx orders in sync, and don't
// force a complex reordering of the atoms when we commit
atom.reindex(last_atomidx + 1);

// reparent this atom to the CutGroup for this residue
atom.reparent(cgidx);

Expand Down
13 changes: 13 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ organisation on `GitHub <https://github.com/openbiosim/sire>`__.
* Added a map option (fix_perturbable_zero_sigmas) to prevent perturbation of
the Lennard-Jones sigma parameter for ghost atoms during alchemical free energy simulations.

* [CHANGE IN BEHAVIOUR] - added code that ensures that, when editing molecules,
the CGAtomIdx order will always follow the AtomIdx order of atoms. This is
because a lot of code had implicitly assumed this, and so it was a cause
of bugs when this wasn't the case. Now, when you edit a molecule, on committing,
the orders will be checked. If they don't agree, then the CutGroups will be
reordered, with atoms reordered as necessary to make the CGAtomIdx order match
the AtomIdx order. If this isn't possible (e.g. because atoms in CutGroups
are not contiguous), then the molecule will be converted to a single-cutgroup
molecule, with the atoms placed in AtomIdx order. As part of this change,
the merge code will now also ensure that added atoms are added with the
correct AtomIdx, rather than added as the last atoms in the molecule. This
is also more natural. This fixes issue #202.

* Please add an item to this changelog when you create your PR

`2024.1.0 <https://github.com/openbiosim/sire/compare/2023.5.2...2024.1.0>`__ - April 2024
Expand Down

0 comments on commit 26a79ee

Please sign in to comment.