# Link groups with make\_ndx

**URL:** <https://gromacs.bioexcel.eu/t/link-groups-with-make-ndx/285>\
**Category:** User discussions\
**Created:** [June 10, 2020, 5:59pm UTC](https://gromacs.bioexcel.eu/t/link-groups-with-make-ndx/285 "2020-06-10T17:59:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mariamartabranda](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@mariamartabranda](https://gromacs.bioexcel.eu/u/mariamartabranda)\
**Post date:** [June 10, 2020, 6:00pm UTC](https://gromacs.bioexcel.eu/t/link-groups-with-make-ndx/285/1 "2020-06-10T18:00:00Z")

</div>

I have generated a large number of groups through the gmx select command, now I need to link all these groups into one. Somebody can help me? Thanks!

---

<div class="post-metadata">

**Author:** ![Dr\_DBW](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/dr_dbw/32/42_2.png) [@Dr\_DBW](https://gromacs.bioexcel.eu/u/Dr_DBW)\
**Post date:** [June 10, 2020, 9:57pm UTC](https://gromacs.bioexcel.eu/t/link-groups-with-make-ndx/285/2 "2020-06-10T21:57:46Z")

</div>

Use `-on` to output the selections to an index file:  
`gmx select -on index_output.ndx`

Then you can combine them using `make_ndx` with the `|` (`or`) function:  
`gmx make_ndx -n index_output.ndx -o index_combined.ndx`

---

<div class="post-metadata">

**Author:** ![mariamartabranda](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@mariamartabranda](https://gromacs.bioexcel.eu/u/mariamartabranda)\
**Post date:** [June 11, 2020, 7:15am UTC](https://gromacs.bioexcel.eu/t/link-groups-with-make-ndx/285/3 "2020-06-11T07:15:32Z")

</div>

Thank you…but i have more than 12000 groups. Or is not usefull in this case.

---

<div class="post-metadata">

**Author:** ![jalemkul](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/jalemkul/32/18_2.png) [@jalemkul](https://gromacs.bioexcel.eu/u/jalemkul)\
**Post date:** [June 11, 2020, 9:59am UTC](https://gromacs.bioexcel.eu/t/link-groups-with-make-ndx/285/4 "2020-06-11T09:59:39Z")

</div>

With this many groups, I suggest trying to find a way to make fewer groups; there has to be a way to express your selections more generally so you don’t have to deal with so many.

---

<div class="post-metadata">

**Author:** ![mariamartabranda](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@mariamartabranda](https://gromacs.bioexcel.eu/u/mariamartabranda)\
**Post date:** [June 11, 2020, 6:22am UTC](https://gromacs.bioexcel.eu/t/link-groups-with-make-ndx/285/5 "2020-06-11T06:22:46Z")

</div>

Thanks! We solved this problem. mm

---

<div class="post-metadata">

**Author:** ![jalemkul](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/jalemkul/32/18_2.png) [@jalemkul](https://gromacs.bioexcel.eu/u/jalemkul)\
**Post date:** [June 11, 2020, 10:38am UTC](https://gromacs.bioexcel.eu/t/link-groups-with-make-ndx/285/6 "2020-06-11T10:38:36Z")

</div>

Could you please share what your solution was? That is the purpose of this forum. Other users may find it useful in the future to know what you did.

---

<div class="post-metadata">

**Author:** ![mariamartabranda](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@mariamartabranda](https://gromacs.bioexcel.eu/u/mariamartabranda)\
**Post date:** [June 12, 2020, 6:36pm UTC](https://gromacs.bioexcel.eu/t/link-groups-with-make-ndx/285/7 "2020-06-12T18:36:24Z")

</div>

Hi!!  
A collaborator wrote a code that links all groups into one. I ´ll ask him to share the program, MM

---

<div class="post-metadata">

**Author:** ![mariamartabranda](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@mariamartabranda](https://gromacs.bioexcel.eu/u/mariamartabranda)\
**Post date:** [June 13, 2020, 6:07pm UTC](https://gromacs.bioexcel.eu/t/link-groups-with-make-ndx/285/8 "2020-06-13T18:07:32Z")

</div>

Hi!!  
Here we share the script to link several groups avoiding redundance:

# MergeGroups script

# This script reads a ‘ndx’ file (INPUT) from GROMACS containing many groups of atoms,

# and writes-out a single merged file (OUTPUT) with non-redundant atom numbers.

# To run: 1) modify in lines 1 and 2 INPUT & OUTPUT names;

# 2) modify in line 3 the text in the OUTPUT header: [group of …];

# 3) execute this script from the command line.

# Diego Guerin; June 2020

# 

# 

export INPUT=IndexMut17\_wat4ALYR.ndx  
export OUTPUT=IndexMut17\_wat4ALYR\_mrg.ndx  
echo [group of TIP3 that reach a 4A distance from LYR] \> $OUTPUT  
awk ’ BEGIN {imin=1; imax=500000}  
{for (i=1; i\<16; i++) A[$i]=$i}  
END { for (j=imin; j\<imax+1; j++) {  
if (A[j] \> 0)  
{k=k+1; if (k\<15) printf " %5d", A[j]  
else {printf " %5d\n", A[j]; k=0}  
}  
}  
}’ $INPUT \>\> $OUTPUT
