2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2014, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
37 #include "gromacs/topology/index.h"
50 #include "gromacs/legacyheaders/macros.h"
51 #include "gromacs/legacyheaders/txtdump.h"
53 #include "gromacs/fileio/gmxfio.h"
54 #include "gromacs/fileio/strdb.h"
55 #include "gromacs/topology/atoms.h"
56 #include "gromacs/topology/block.h"
57 #include "gromacs/topology/invblock.h"
58 #include "gromacs/utility/cstringutil.h"
59 #include "gromacs/utility/fatalerror.h"
60 #include "gromacs/utility/futil.h"
61 #include "gromacs/utility/smalloc.h"
63 const char gmx_residuetype_undefined[] = "Other";
65 struct gmx_residuetype
74 static gmx_bool gmx_ask_yesno(gmx_bool bASK)
82 c = toupper(fgetc(stdin));
84 while ((c != 'Y') && (c != 'N'));
94 void write_index(const char *outf, t_blocka *b, char **gnames, gmx_bool bDuplicate, int natoms)
99 out = gmx_fio_fopen(outf, "w");
100 /* fprintf(out,"%5d %5d\n",b->nr,b->nra); */
101 for (i = 0; (i < b->nr); i++)
103 fprintf(out, "[ %s ]\n", gnames[i]);
104 for (k = 0, j = b->index[i]; j < b->index[i+1]; j++, k++)
106 fprintf(out, "%4d ", b->a[j]+1);
115 /* Duplicate copy, useful for computational electrophysiology double-layer setups */
118 fprintf(stderr, "Duplicating the whole system with an atom offset of %d atoms.\n", natoms);
119 for (i = 0; (i < b->nr); i++)
121 fprintf(out, "[ %s_copy ]\n", gnames[i]);
122 for (k = 0, j = b->index[i]; j < b->index[i+1]; j++, k++)
124 fprintf(out, "%4d ", b->a[j]+1 + natoms );
137 void add_grp(t_blocka *b, char ***gnames, int nra, atom_id a[], const char *name)
141 srenew(b->index, b->nr+2);
142 srenew(*gnames, b->nr+1);
143 (*gnames)[b->nr] = strdup(name);
145 srenew(b->a, b->nra+nra);
146 for (i = 0; (i < nra); i++)
148 b->a[b->nra++] = a[i];
151 b->index[b->nr] = b->nra;
154 /* compare index in `a' with group in `b' at `index',
155 when `index'<0 it is relative to end of `b' */
156 static gmx_bool grp_cmp(t_blocka *b, int nra, atom_id a[], int index)
162 index = b->nr-1+index;
166 gmx_fatal(FARGS, "no such index group %d in t_blocka (nr=%d)", index, b->nr);
169 if (nra != b->index[index+1] - b->index[index])
173 for (i = 0; i < nra; i++)
175 if (a[i] != b->a[b->index[index]+i])
184 p_status(const char **restype, int nres, const char **typenames, int ntypes)
189 snew(counter, ntypes);
190 for (i = 0; i < ntypes; i++)
194 for (i = 0; i < nres; i++)
196 for (j = 0; j < ntypes; j++)
198 if (!gmx_strcasecmp(restype[i], typenames[j]))
205 for (i = 0; (i < ntypes); i++)
209 printf("There are: %5d %10s residues\n", counter[i], typenames[i]);
218 mk_aid(t_atoms *atoms, const char ** restype, const char * typestring, int *nra, gmx_bool bMatch)
219 /* Make an array of atom_ids for all atoms with residuetypes matching typestring, or the opposite if bMatch is false */
227 for (i = 0; (i < atoms->nr); i++)
229 res = !gmx_strcasecmp(restype[atoms->atom[i].resind], typestring);
249 static void analyse_other(const char ** restype, t_atoms *atoms,
250 t_blocka *gb, char ***gn, gmx_bool bASK, gmx_bool bVerb)
252 restp_t *restp = NULL;
255 atom_id *other_ndx, *aid, *aaid;
256 int i, j, k, l, resind, naid, naaid, natp, nrestp = 0;
258 for (i = 0; (i < atoms->nres); i++)
260 if (gmx_strcasecmp(restype[i], "Protein") && gmx_strcasecmp(restype[i], "DNA") && gmx_strcasecmp(restype[i], "RNA") && gmx_strcasecmp(restype[i], "Water"))
270 printf("Analysing residues not classified as Protein/DNA/RNA/Water and splitting into groups...\n");
272 snew(other_ndx, atoms->nr);
273 for (k = 0; (k < atoms->nr); k++)
275 resind = atoms->atom[k].resind;
276 rname = *atoms->resinfo[resind].name;
277 if (gmx_strcasecmp(restype[resind], "Protein") && gmx_strcasecmp(restype[resind], "DNA") &&
278 gmx_strcasecmp(restype[resind], "RNA") && gmx_strcasecmp(restype[resind], "Water"))
281 for (l = 0; (l < nrestp); l++)
283 if (strcmp(restp[l].rname, rname) == 0)
290 srenew(restp, nrestp+1);
291 restp[nrestp].rname = strdup(rname);
292 restp[nrestp].bNeg = FALSE;
293 restp[nrestp].gname = strdup(rname);
299 for (i = 0; (i < nrestp); i++)
301 snew(aid, atoms->nr);
303 for (j = 0; (j < atoms->nr); j++)
305 rname = *atoms->resinfo[atoms->atom[j].resind].name;
306 if ((strcmp(restp[i].rname, rname) == 0 && !restp[i].bNeg) ||
307 (strcmp(restp[i].rname, rname) != 0 && restp[i].bNeg))
312 add_grp(gb, gn, naid, aid, restp[i].gname);
315 printf("split %s into atoms (y/n) ? ", restp[i].gname);
317 if (gmx_ask_yesno(bASK))
320 for (k = 0; (k < naid); k++)
322 aname = *atoms->atomname[aid[k]];
323 for (l = 0; (l < natp); l++)
325 if (strcmp(aname, attp[l]) == 0)
332 srenew(attp, ++natp);
333 attp[natp-1] = aname;
338 for (l = 0; (l < natp); l++)
342 for (k = 0; (k < naid); k++)
344 aname = *atoms->atomname[aid[k]];
345 if (strcmp(aname, attp[l]) == 0)
347 aaid[naaid++] = aid[k];
350 add_grp(gb, gn, naaid, aaid, attp[l]);
365 * Cata necessary to construct a single (protein) index group in
368 typedef struct gmx_help_make_index_group
370 /** The set of atom names that will be used to form this index group */
371 const char **defining_atomnames;
372 /** Size of the defining_atomnames array */
373 int num_defining_atomnames;
374 /** Name of this index group */
375 const char *group_name;
376 /** Whether the above atom names name the atoms in the group, or
377 those not in the group */
378 gmx_bool bTakeComplement;
379 /** The index in wholename gives the first item in the arrays of
380 atomnames that should be tested with 'gmx_strncasecmp' in stead of
381 gmx_strcasecmp, or -1 if all items should be tested with strcasecmp
382 This is comparable to using a '*' wildcard at the end of specific
383 atom names, but that is more involved to implement...
386 /** Only create this index group if it differs from the one specified in compareto,
387 where -1 means to always create this group. */
389 } t_gmx_help_make_index_group;
391 static void analyse_prot(const char ** restype, t_atoms *atoms,
392 t_blocka *gb, char ***gn, gmx_bool bASK, gmx_bool bVerb)
394 /* lists of atomnames to be used in constructing index groups: */
395 static const char *pnoh[] = { "H", "HN" };
396 static const char *pnodum[] = {
397 "MN1", "MN2", "MCB1", "MCB2", "MCG1", "MCG2",
398 "MCD1", "MCD2", "MCE1", "MCE2", "MNZ1", "MNZ2"
400 static const char *calpha[] = { "CA" };
401 static const char *bb[] = { "N", "CA", "C" };
402 static const char *mc[] = { "N", "CA", "C", "O", "O1", "O2", "OC1", "OC2", "OT", "OXT" };
403 static const char *mcb[] = { "N", "CA", "CB", "C", "O", "O1", "O2", "OC1", "OC2", "OT", "OXT" };
404 static const char *mch[] = {
405 "N", "CA", "C", "O", "O1", "O2", "OC1", "OC2", "OT", "OXT",
406 "H1", "H2", "H3", "H", "HN"
409 static const t_gmx_help_make_index_group constructing_data[] =
410 {{ NULL, 0, "Protein", TRUE, -1, -1},
411 { pnoh, asize(pnoh), "Protein-H", TRUE, 0, -1},
412 { calpha, asize(calpha), "C-alpha", FALSE, -1, -1},
413 { bb, asize(bb), "Backbone", FALSE, -1, -1},
414 { mc, asize(mc), "MainChain", FALSE, -1, -1},
415 { mcb, asize(mcb), "MainChain+Cb", FALSE, -1, -1},
416 { mch, asize(mch), "MainChain+H", FALSE, -1, -1},
417 { mch, asize(mch), "SideChain", TRUE, -1, -1},
418 { mch, asize(mch), "SideChain-H", TRUE, 11, -1},
419 { pnodum, asize(pnodum), "Prot-Masses", TRUE, -1, 0}, };
420 const int num_index_groups = asize(constructing_data);
426 char ndx_name[STRLEN], *atnm;
431 printf("Analysing Protein...\n");
433 snew(aid, atoms->nr);
435 /* calculate the number of protein residues */
437 for (i = 0; (i < atoms->nres); i++)
439 if (0 == gmx_strcasecmp(restype[i], "Protein"))
444 /* find matching or complement atoms */
445 for (i = 0; (i < (int)num_index_groups); i++)
448 for (n = 0; (n < atoms->nr); n++)
450 if (0 == gmx_strcasecmp(restype[atoms->atom[n].resind], "Protein"))
453 for (j = 0; (j < constructing_data[i].num_defining_atomnames); j++)
455 /* skip digits at beginning of atomname, e.g. 1H */
456 atnm = *atoms->atomname[n];
457 while (isdigit(atnm[0]))
461 if ( (constructing_data[i].wholename == -1) || (j < constructing_data[i].wholename) )
463 if (0 == gmx_strcasecmp(constructing_data[i].defining_atomnames[j], atnm))
470 if (0 == gmx_strncasecmp(constructing_data[i].defining_atomnames[j], atnm, strlen(constructing_data[i].defining_atomnames[j])))
476 if (constructing_data[i].bTakeComplement != match)
482 /* if we want to add this group always or it differs from previous
484 if (-1 == constructing_data[i].compareto || !grp_cmp(gb, nra, aid, constructing_data[i].compareto-i) )
486 add_grp(gb, gn, nra, aid, constructing_data[i].group_name);
492 for (i = 0; (i < (int)num_index_groups); i++)
494 printf("Split %12s into %5d residues (y/n) ? ", constructing_data[i].group_name, npres);
495 if (gmx_ask_yesno(bASK))
499 for (n = 0; ((atoms->atom[n].resind < npres) && (n < atoms->nr)); )
501 resind = atoms->atom[n].resind;
502 for (; ((atoms->atom[n].resind == resind) && (n < atoms->nr)); n++)
505 for (j = 0; (j < constructing_data[i].num_defining_atomnames); j++)
507 if (0 == gmx_strcasecmp(constructing_data[i].defining_atomnames[j], *atoms->atomname[n]))
512 if (constructing_data[i].bTakeComplement != match)
517 /* copy the residuename to the tail of the groupname */
521 ri = &atoms->resinfo[resind];
522 sprintf(ndx_name, "%s_%s%d%c",
523 constructing_data[i].group_name, *ri->name, ri->nr, ri->ic == ' ' ? '\0' : ri->ic);
524 add_grp(gb, gn, nra, aid, ndx_name);
530 printf("Make group with sidechain and C=O swapped (y/n) ? ");
531 if (gmx_ask_yesno(bASK))
533 /* Make swap sidechain C=O index */
536 for (n = 0; ((atoms->atom[n].resind < npres) && (n < atoms->nr)); )
538 resind = atoms->atom[n].resind;
540 for (; ((atoms->atom[n].resind == resind) && (n < atoms->nr)); n++)
542 if (strcmp("CA", *atoms->atomname[n]) == 0)
548 else if (strcmp("C", *atoms->atomname[n]) == 0)
552 gmx_incons("Atom naming problem");
556 else if (strcmp("O", *atoms->atomname[n]) == 0)
560 gmx_incons("Atom naming problem");
564 else if (strcmp("O1", *atoms->atomname[n]) == 0)
568 gmx_incons("Atom naming problem");
578 /* copy the residuename to the tail of the groupname */
581 add_grp(gb, gn, nra, aid, "SwapSC-CO");
591 /* Return 0 if the name was found, otherwise -1.
592 * p_restype is set to a pointer to the type name, or 'Other' if we did not find it.
595 gmx_residuetype_get_type(gmx_residuetype_t rt, const char * resname, const char ** p_restype)
600 for (i = 0; i < rt->n && rc; i++)
602 rc = gmx_strcasecmp(rt->resname[i], resname);
605 *p_restype = (rc == 0) ? rt->restype[i-1] : gmx_residuetype_undefined;
611 gmx_residuetype_add(gmx_residuetype_t rt, const char *newresname, const char *newrestype)
614 const char * p_oldtype;
616 found = !gmx_residuetype_get_type(rt, newresname, &p_oldtype);
618 if (found && gmx_strcasecmp(p_oldtype, newrestype))
620 fprintf(stderr, "Warning: Residue '%s' already present with type '%s' in database, ignoring new type '%s'.",
621 newresname, p_oldtype, newrestype);
626 srenew(rt->resname, rt->n+1);
627 srenew(rt->restype, rt->n+1);
628 rt->resname[rt->n] = strdup(newresname);
629 rt->restype[rt->n] = strdup(newrestype);
638 gmx_residuetype_init(gmx_residuetype_t *prt)
642 char resname[STRLEN], restype[STRLEN], dum[STRLEN];
643 struct gmx_residuetype *rt;
652 db = libopen("residuetypes.dat");
654 while (get_a_line(db, line, STRLEN))
660 if (sscanf(line, "%s %s %s", resname, restype, dum) != 2)
662 gmx_fatal(FARGS, "Incorrect number of columns (2 expected) for line in residuetypes.dat");
664 gmx_residuetype_add(rt, resname, restype);
676 gmx_residuetype_destroy(gmx_residuetype_t rt)
680 for (i = 0; i < rt->n; i++)
682 sfree(rt->resname[i]);
683 sfree(rt->restype[i]);
693 gmx_residuetype_get_alltypes(gmx_residuetype_t rt,
694 const char *** p_typenames,
698 const char ** my_typename;
702 for (i = 0; i < rt->n; i++)
704 const char *const p = rt->restype[i];
706 for (int j = 0; j < n && !bFound; j++)
708 assert(my_typename != NULL);
709 bFound = !gmx_strcasecmp(p, my_typename[j]);
713 srenew(my_typename, n+1);
719 *p_typenames = my_typename;
727 gmx_residuetype_is_protein(gmx_residuetype_t rt, const char *resnm)
732 if (gmx_residuetype_get_type(rt, resnm, &p_type) == 0 &&
733 gmx_strcasecmp(p_type, "Protein") == 0)
745 gmx_residuetype_is_dna(gmx_residuetype_t rt, const char *resnm)
750 if (gmx_residuetype_get_type(rt, resnm, &p_type) == 0 &&
751 gmx_strcasecmp(p_type, "DNA") == 0)
763 gmx_residuetype_is_rna(gmx_residuetype_t rt, const char *resnm)
768 if (gmx_residuetype_get_type(rt, resnm, &p_type) == 0 &&
769 gmx_strcasecmp(p_type, "RNA") == 0)
780 /* Return the size of the arrays */
782 gmx_residuetype_get_size(gmx_residuetype_t rt)
787 /* Search for a residuetype with name resnm within the
788 * gmx_residuetype database. Return the index if found,
792 gmx_residuetype_get_index(gmx_residuetype_t rt, const char *resnm)
797 for (i = 0; i < rt->n && rc; i++)
799 rc = gmx_strcasecmp(rt->resname[i], resnm);
802 return (0 == rc) ? i-1 : -1;
805 /* Return the name of the residuetype with the given index, or
806 * NULL if not found. */
808 gmx_residuetype_get_name(gmx_residuetype_t rt, int index)
810 if (index >= 0 && index < rt->n)
812 return rt->resname[index];
822 void analyse(t_atoms *atoms, t_blocka *gb, char ***gn, gmx_bool bASK, gmx_bool bVerb)
824 gmx_residuetype_t rt = NULL;
827 const char ** restype;
831 const char ** p_typename;
838 printf("Analysing residue names:\n");
840 /* Create system group, every single atom */
841 snew(aid, atoms->nr);
842 for (i = 0; i < atoms->nr; i++)
846 add_grp(gb, gn, atoms->nr, aid, "System");
849 /* For every residue, get a pointer to the residue type name */
850 gmx_residuetype_init(&rt);
853 snew(restype, atoms->nres);
856 for (i = 0; i < atoms->nres; i++)
858 resnm = *atoms->resinfo[i].name;
859 gmx_residuetype_get_type(rt, resnm, &(restype[i]));
861 /* Note that this does not lead to a N*N loop, but N*K, where
862 * K is the number of residue _types_, which is small and independent of N.
865 for (k = 0; k < ntypes && !found; k++)
867 assert(p_typename != NULL);
868 found = !strcmp(restype[i], p_typename[k]);
872 srenew(p_typename, ntypes+1);
873 p_typename[ntypes++] = strdup(restype[i]);
879 p_status(restype, atoms->nres, p_typename, ntypes);
882 for (k = 0; k < ntypes; k++)
884 aid = mk_aid(atoms, restype, p_typename[k], &nra, TRUE);
886 /* Check for special types to do fancy stuff with */
888 if (!gmx_strcasecmp(p_typename[k], "Protein") && nra > 0)
892 analyse_prot(restype, atoms, gb, gn, bASK, bVerb);
894 /* Create a Non-Protein group */
895 aid = mk_aid(atoms, restype, "Protein", &nra, FALSE);
896 if ((nra > 0) && (nra < atoms->nr))
898 add_grp(gb, gn, nra, aid, "non-Protein");
902 else if (!gmx_strcasecmp(p_typename[k], "Water") && nra > 0)
904 add_grp(gb, gn, nra, aid, p_typename[k]);
905 /* Add this group as 'SOL' too, for backward compatibility with older gromacs versions */
906 add_grp(gb, gn, nra, aid, "SOL");
910 /* Solvent, create a negated group too */
911 aid = mk_aid(atoms, restype, "Water", &nra, FALSE);
912 if ((nra > 0) && (nra < atoms->nr))
914 add_grp(gb, gn, nra, aid, "non-Water");
921 add_grp(gb, gn, nra, aid, p_typename[k]);
923 analyse_other(restype, atoms, gb, gn, bASK, bVerb);
929 gmx_residuetype_destroy(rt);
931 /* Create a merged water_and_ions group */
937 for (i = 0; i < gb->nr; i++)
939 if (!gmx_strcasecmp((*gn)[i], "Water"))
942 nwater = gb->index[i+1]-gb->index[i];
944 else if (!gmx_strcasecmp((*gn)[i], "Ion"))
947 nion = gb->index[i+1]-gb->index[i];
951 if (nwater > 0 && nion > 0)
953 srenew(gb->index, gb->nr+2);
954 srenew(*gn, gb->nr+1);
955 (*gn)[gb->nr] = strdup("Water_and_ions");
956 srenew(gb->a, gb->nra+nwater+nion);
959 for (i = gb->index[iwater]; i < gb->index[iwater+1]; i++)
961 gb->a[gb->nra++] = gb->a[i];
966 for (i = gb->index[iion]; i < gb->index[iion+1]; i++)
968 gb->a[gb->nra++] = gb->a[i];
972 gb->index[gb->nr] = gb->nra;
977 void check_index(char *gname, int n, atom_id index[], char *traj, int natoms)
981 for (i = 0; i < n; i++)
983 if (index[i] >= natoms)
985 gmx_fatal(FARGS, "%s atom number (index[%d]=%d) is larger than the number of atoms in %s (%d)",
986 gname ? gname : "Index", i+1, index[i]+1,
987 traj ? traj : "the trajectory", natoms);
989 else if (index[i] < 0)
991 gmx_fatal(FARGS, "%s atom number (index[%d]=%d) is less than zero",
992 gname ? gname : "Index", i+1, index[i]+1);
997 t_blocka *init_index(const char *gfile, char ***grpname)
1003 char line[STRLEN], *pt, str[STRLEN];
1005 in = gmx_fio_fopen(gfile, "r");
1013 while (get_a_line(in, line, STRLEN))
1015 if (get_header(line, str))
1018 srenew(b->index, b->nr+1);
1019 srenew(*grpname, b->nr);
1024 b->index[b->nr] = b->index[b->nr-1];
1025 (*grpname)[b->nr-1] = strdup(str);
1031 gmx_fatal(FARGS, "The first header of your indexfile is invalid");
1034 while (sscanf(pt, "%s", str) == 1)
1036 i = b->index[b->nr];
1037 if (i >= maxentries)
1040 srenew(b->a, maxentries);
1042 assert(b->a != NULL); // for clang analyzer
1043 b->a[i] = strtol(str, NULL, 10)-1;
1046 pt = strstr(pt, str)+strlen(str);
1052 for (i = 0; (i < b->nr); i++)
1054 assert(b->a != NULL); // for clang analyzer
1055 for (j = b->index[i]; (j < b->index[i+1]); j++)
1059 fprintf(stderr, "\nWARNING: negative index %d in group %s\n\n",
1060 b->a[j], (*grpname)[i]);
1068 static void minstring(char *str)
1072 for (i = 0; (i < (int)strlen(str)); i++)
1081 int find_group(char s[], int ngrps, char **grpname)
1084 char string[STRLEN];
1090 /* first look for whole name match */
1093 for (i = 0; i < ngrps; i++)
1095 if (gmx_strcasecmp_min(s, grpname[i]) == 0)
1105 /* second look for first string match */
1108 for (i = 0; i < ngrps; i++)
1110 if (gmx_strncasecmp_min(s, grpname[i], n) == 0)
1120 /* last look for arbitrary substring match */
1125 for (i = 0; i < ngrps; i++)
1127 strcpy(string, grpname[i]);
1130 if (strstr(string, s) != NULL)
1142 printf("Error: Multiple groups '%s' selected\n", s);
1148 static int qgroup(int *a, int ngrps, char **grpname)
1157 fprintf(stderr, "Select a group: ");
1160 if (scanf("%s", s) != 1)
1162 gmx_fatal(FARGS, "Cannot read from input");
1164 trim(s); /* remove spaces */
1166 while (strlen(s) == 0);
1167 aa = strtol(s, &end, 10);
1168 if (aa == 0 && end[0] != '\0') /* string entered */
1170 aa = find_group(s, ngrps, grpname);
1172 bInRange = (aa >= 0 && aa < ngrps);
1175 printf("Error: No such group '%s'\n", s);
1179 printf("Selected %d: '%s'\n", aa, grpname[aa]);
1184 static void rd_groups(t_blocka *grps, char **grpname, char *gnames[],
1185 int ngrps, int isize[], atom_id *index[], int grpnr[])
1191 gmx_fatal(FARGS, "Error: no groups in indexfile");
1193 for (i = 0; (i < grps->nr); i++)
1195 fprintf(stderr, "Group %5d (%15s) has %5d elements\n", i, grpname[i],
1196 grps->index[i+1]-grps->index[i]);
1198 for (i = 0; (i < ngrps); i++)
1204 gnr1 = qgroup(&grpnr[i], grps->nr, grpname);
1205 if ((gnr1 < 0) || (gnr1 >= grps->nr))
1207 fprintf(stderr, "Select between %d and %d.\n", 0, grps->nr-1);
1210 while ((gnr1 < 0) || (gnr1 >= grps->nr));
1214 fprintf(stderr, "There is one group in the index\n");
1217 gnames[i] = strdup(grpname[gnr1]);
1218 isize[i] = grps->index[gnr1+1]-grps->index[gnr1];
1219 snew(index[i], isize[i]);
1220 for (j = 0; (j < isize[i]); j++)
1222 index[i][j] = grps->a[grps->index[gnr1]+j];
1227 void rd_index(const char *statfile, int ngrps, int isize[],
1228 atom_id *index[], char *grpnames[])
1237 gmx_fatal(FARGS, "No index file specified");
1239 grps = init_index(statfile, &gnames);
1240 rd_groups(grps, gnames, grpnames, ngrps, isize, index, grpnr);
1243 void rd_index_nrs(char *statfile, int ngrps, int isize[],
1244 atom_id *index[], char *grpnames[], int grpnr[])
1251 gmx_fatal(FARGS, "No index file specified");
1253 grps = init_index(statfile, &gnames);
1255 rd_groups(grps, gnames, grpnames, ngrps, isize, index, grpnr);
1258 void get_index(t_atoms *atoms, const char *fnm, int ngrps,
1259 int isize[], atom_id *index[], char *grpnames[])
1262 t_blocka *grps = NULL;
1269 grps = init_index(fnm, gnames);
1274 snew(grps->index, 1);
1275 analyse(atoms, grps, gnames, FALSE, FALSE);
1279 gmx_incons("You need to supply a valid atoms structure or a valid index file name");
1282 rd_groups(grps, *gnames, grpnames, ngrps, isize, index, grpnr);
1285 t_cluster_ndx *cluster_index(FILE *fplog, const char *ndx)
1291 c->clust = init_index(ndx, &c->grpname);
1293 for (i = 0; (i < c->clust->nra); i++)
1295 c->maxframe = std::max(c->maxframe, c->clust->a[i]);
1297 fprintf(fplog ? fplog : stdout,
1298 "There are %d clusters containing %d structures, highest framenr is %d\n",
1299 c->clust->nr, c->clust->nra, c->maxframe);
1302 pr_blocka(debug, 0, "clust", c->clust, TRUE);
1303 for (i = 0; (i < c->clust->nra); i++)
1305 if ((c->clust->a[i] < 0) || (c->clust->a[i] > c->maxframe))
1307 gmx_fatal(FARGS, "Range check error for c->clust->a[%d] = %d\n"
1308 "should be within 0 and %d", i, c->clust->a[i], c->maxframe+1);
1312 c->inv_clust = make_invblocka(c->clust, c->maxframe);