def combine(self, name_all=None, out_ndx=None, operation='<STR_LIT:|>', defaultgroups=False):
if not operation in ('<STR_LIT:|>', '<STR_LIT:&>', False):<EOL><INDENT>raise ValueError("<STR_LIT>".format(<EOL>operation))<EOL><DEDENT>if name_all is None and operation:<EOL><INDENT>name_all = self.name_all or operation.join(self.indexfiles)<EOL><DEDENT>if out_ndx is None:<EOL><INDENT>out_ndx = self.output<EOL><DEDENT>if defaultgroups:<EOL><INDENT>fd, default_ndx = tempfile.mkstemp(suffix='<STR_LIT>', prefix='<STR_LIT>')<EOL>try:<EOL><INDENT>self.make_ndx(o=default_ndx, input=['<STR_LIT:q>'])<EOL><DEDENT>except:<EOL><INDENT>utilities.unlink_gmx(default_ndx)<EOL>raise<EOL><DEDENT>ndxfiles = [default_ndx]<EOL><DEDENT>else:<EOL><INDENT>ndxfiles = []<EOL><DEDENT>ndxfiles.extend(self.indexfiles.values())<EOL>if operation:<EOL><INDENT>try:<EOL><INDENT>fd, tmp_ndx = tempfile.mkstemp(suffix='<STR_LIT>', prefix='<STR_LIT>')<EOL>operation = '<STR_LIT:U+0020>'+operation.strip()+'<STR_LIT:U+0020>'<EOL>cmd = [operation.join(['<STR_LIT>'.format(gname) for gname in self.indexfiles]),<EOL>'<STR_LIT>', '<STR_LIT:q>']<EOL>rc,out,err = self.make_ndx(n=ndxfiles, o=tmp_ndx, input=cmd)<EOL>if self._is_empty_group(out):<EOL><INDENT>warnings.warn("<STR_LIT>".format(**vars()),<EOL>category=BadParameterWarning)<EOL><DEDENT>groups = parse_ndxlist(out)<EOL>last = groups[-<NUM_LIT:1>]<EOL>name_cmd = ["<STR_LIT>".format(last['<STR_LIT>'], name_all), '<STR_LIT:q>']<EOL>rc,out,err = self.make_ndx(n=tmp_ndx, o=out_ndx, input=name_cmd)<EOL><DEDENT>finally:<EOL><INDENT>utilities.unlink_gmx(tmp_ndx)<EOL>if defaultgroups:<EOL><INDENT>utilities.unlink_gmx(default_ndx)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>rc,out,err = self.make_ndx(n=ndxfiles, o=out_ndx, input=['<STR_LIT>','<STR_LIT:q>'])<EOL><DEDENT>return name_all, out_ndx<EOL>
Combine individual groups into a single one and write output.

        :Keywords:
           name_all : string
              Name of the combined group, ``None`` generates a name.  [``None``]
           out_ndx : filename
              Name of the output file that will contain the individual groups
              and the combined group. If ``None`` then default from the class
              constructor is used. [``None``]
           operation : character
              Logical operation that is used to generate the combined group from
              the individual groups: "|" (OR) or "&" (AND); if set to ``False``
              then no combined group is created and only the individual groups
              are written. ["|"]
           defaultgroups : bool
              ``True``: append everything to the default groups produced by
              :program:`make_ndx` (or rather, the groups provided in the ndx file on
              initialization --- if this was ``None`` then these are truly default groups);
              ``False``: only use the generated groups

        :Returns:
           ``(combinedgroup_name, output_ndx)``, a tuple showing the
           actual group name and the name of the file; useful when all names are autogenerated.

        .. Warning:: The order of the atom numbers in the combined group is
                     *not* guaranteed to be the same as the selections on input because
                     ``make_ndx`` sorts them ascending. Thus you should be careful when
                     using these index files for calculations of angles and dihedrals.
                     Use :class:`gromacs.formats.NDX` in these cases.

        .. SeeAlso:: :meth:`IndexBuilder.write`.