Skip to content
Snippets Groups Projects
Commit 1e42e298 authored by Eliane Briand's avatar Eliane Briand :100: Committed by Szilárd Páll
Browse files

Fix segfault on calling `make_ndx` without structure file

Fix segfault on calling `make_ndx` with only an index file input (no structure file).

Cause: Migration away from `t_blocka` in d7fca736 was not fully equivalent to previous code - natoms was not set. (`+1` comes from [this](d7fca736) )

Not sure how to emulate inputs at the interactive prompt to add a test for this.

Fixes #4717
parent 5fa933a3
No related branches found
No related tags found
Loading
......@@ -33,6 +33,13 @@ Fix crash in ``gmx solvate`` when using solvent box in PDB format
Now a PDB file can be passed to the ``-cs`` option in ``gmx solvate``.
In previous releases (since at least 2016) this lead to a segfault.
Fix creating index file from another index file
""""""""""""""""""""""""""""""""""""""""""""""""
``gmx make_ndx`` can again accept an index file alone as input, without associated structure file.
:issue:`4717`
Fixes that affect portability
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
......
......@@ -1376,19 +1376,20 @@ static void edit_index(int natoms,
sfree(index2);
}
static int maxAtomIndex(gmx::ArrayRef<const IndexGroup> indexGroups)
//! Find the number of atoms in the system implied by the largest atom index
static int impliedNumberOfAtom(gmx::ArrayRef<const IndexGroup> indexGroups)
{
int maxAtom = -1;
int maxAtomIndex = -1;
for (const auto& indexGroup : indexGroups)
{
for (const int a : indexGroup.particleIndices)
{
maxAtom = std::max(maxAtom, a);
maxAtomIndex = std::max(maxAtomIndex, a);
}
}
return maxAtom;
return maxAtomIndex + 1;
}
int gmx_make_ndx(int argc, char* argv[])
......@@ -1500,8 +1501,8 @@ int gmx_make_ndx(int argc, char* argv[])
if (!bNatoms)
{
const int maxAtom = maxAtomIndex(indexGroups);
printf("Counted atom numbers up to %d in index file\n", 1 + maxAtom);
natoms = impliedNumberOfAtom(indexGroups);
printf("Deducing %d atoms in the system from indices in the index file\n", natoms);
}
edit_index(natoms, &atoms, x, &indexGroups, bVerbose);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment