1
$\begingroup$

Using the following Gromacs utility execited from Bash, I can create a new group in the ndx file:

gmx make_ndx -f ref.pdb -o new.ndx << EOF
ri 8-195 & 3
q
EOF

Is it possible to change the number of this new group e.g. setting it to the 0 (without explicit definition of the number of the new group) ?

For the moment I could found only one possibility to add "keep number_of_new_group" in the EOF script that will delete all other groups. But in this case I still need to define the number of new group.

$\endgroup$
4
  • 1
    $\begingroup$ If I have followed your question correctly, how about changing the name of the group instead? $\endgroup$ Jan 9 at 12:29
  • $\begingroup$ it could be an option but if we call the group via execution of some other gromacs utility, we need always indicate the number of the group (Regardless of its name). Moreover, additionally I do not know how to change the name of the group without indication of its number :-) $\endgroup$ Jan 9 at 14:20
  • 1
    $\begingroup$ If you know the number of default groups you already have, it shouldn't be a problem I believe. For example, if you already have 5 default groups from 0, 1, 2, 3, and 4, then you can just name 5 0 in your script. But, remember that the name of your group will now be 0. $\endgroup$ Jan 9 at 15:38
  • $\begingroup$ I can only echo @RoshanShrestha's comment -- I personally make separate index files for each of the sets of analysis that I'm interested in. I then always know that the indexing of my custom groups starts after the default list of groups. $\endgroup$ Jan 9 at 20:52

1 Answer 1

3
$\begingroup$

Try these:

  1. Call make_ndx with a prepared, empty .ndx file:
touch new.ndx
gmx make_ndx -n new.ndx -o output.ndx ...
rm new.ndx

Now output.ndx should contain only the new group.

  1. Count index groups manually:
n_last_group=$( grep '\[' index.ndx | wc -l )
echo "$n_last_group" | gmx traj -n index.ndx ...

Explanation: grep returns every line in index.ndx with the open-bracket symbol [, and wc -l counts the number of lines returned, so the combined operation counts the number of groups defined in index.ndx, which is stored in the variable n_last_group (once you understand how this works, you can of course use a shorter variable name).

BONUS: You can return a specific group's number with:

n_group=$( grep '\[' index.ndx | awk '/MyAwesomeGroup/ {print FNR} END {print "Error"}' | sed -n '1p' )

As before grep returns all group names; but now awk prints the line numbers of all lines containing the string MyAwesomeGroup. sed returns the first line of that output, giving the number of the first group matching the string (if there is more than one) and "Error" if none was found, which then errors the subsequent GROMACS call.

$\endgroup$
1
  • $\begingroup$ Thanks so much buddy ! $\endgroup$ Jan 10 at 10:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .