A bit more modular selection position handling.
[gromacs/qmmm-gamess-us.git] / src / gmxlib / selection / test_selection.c
blob877b0cce0af8cbf9244c82bd5f72d4b023a05169
1 /*
3 * This source code is part of
5 * G R O M A C S
7 * GROningen MAchine for Chemical Simulations
9 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11 * Copyright (c) 2001-2009, The GROMACS development team,
12 * check out http://www.gromacs.org for more information.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * If you want to redistribute modifications, please consider that
20 * scientific software is very special. Version control is crucial -
21 * bugs must be traceable. We will be happy to consider code for
22 * inclusion in the official distribution, but derived work must not
23 * be called official GROMACS. Details are found in the README & COPYING
24 * files - if they are missing, get the official version at www.gromacs.org.
26 * To help us fund GROMACS development, we humbly ask that you cite
27 * the papers on the package - you can find them in the top README file.
29 * For more info, check our website at http://www.gromacs.org
31 /*! \internal \file
32 * \brief Testing/debugging tool for the selection engine.
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
38 #include <copyrite.h>
39 #include <filenm.h>
40 #include <macros.h>
41 #include <smalloc.h>
42 #include <statutil.h>
44 #include <trajana.h>
46 typedef struct
48 bool bFrameTree;
49 int nmaxind;
50 gmx_ana_selcollection_t *sc;
51 } t_dumpdata;
53 int
54 dump_frame(t_topology * top, t_trxframe * fr, t_pbc * pbc,
55 int nr, gmx_ana_selection_t *sel[], void *data)
57 t_dumpdata *d = (t_dumpdata *)data;
58 int g, i, n;
60 fprintf(stderr, "\n");
61 if (d->bFrameTree)
63 gmx_ana_selcollection_print_tree(stderr, d->sc, TRUE);
65 for (g = 0; g < nr; ++g)
67 gmx_ana_index_dump(sel[g]->g, g, d->nmaxind);
68 fprintf(stderr, " Positions (%d pcs):\n", sel[g]->p.nr);
69 n = sel[g]->p.nr;
70 if (d->nmaxind >= 0 && n > d->nmaxind)
72 n = d->nmaxind;
74 for (i = 0; i < n; ++i)
76 fprintf(stderr, " (%.2f,%.2f,%.2f) r=%d, m=%d, b=%d-%d\n",
77 sel[g]->p.x[i][XX], sel[g]->p.x[i][YY], sel[g]->p.x[i][ZZ],
78 sel[g]->p.m.refid[i], sel[g]->p.m.mapid[i],
79 sel[g]->p.m.mapb.index[i]+1,
80 sel[g]->p.m.mapb.index[i+1]);
82 if (n < sel[g]->p.nr)
84 fprintf(stderr, " ...\n");
87 fprintf(stderr, "\n");
88 return 0;
91 static void
92 print_selections(int nr, gmx_ana_selection_t **sel, int nmaxind)
94 int g, i, n;
96 fprintf(stderr, "\nSelections:\n");
97 for (g = 0; g < nr; ++g)
99 fprintf(stderr, " ");
100 gmx_ana_selection_print_info(sel[g]);
101 fprintf(stderr, " ");
102 gmx_ana_index_dump(sel[g]->g, g, nmaxind);
104 fprintf(stderr, " Block (size=%d):", sel[g]->p.m.mapb.nr);
105 if (!sel[g]->p.m.mapb.index)
107 fprintf(stderr, " (null)");
109 else
111 n = sel[g]->p.m.mapb.nr;
112 if (nmaxind >= 0 && n > nmaxind)
113 n = nmaxind;
114 for (i = 0; i <= n; ++i)
115 fprintf(stderr, " %d", sel[g]->p.m.mapb.index[i]);
116 if (n < sel[g]->p.m.mapb.nr)
117 fprintf(stderr, " ...");
119 fprintf(stderr, "\n");
121 n = sel[g]->p.m.nr;
122 if (nmaxind >= 0 && n > nmaxind)
123 n = nmaxind;
124 fprintf(stderr, " RefId:");
125 if (!sel[g]->p.m.refid)
127 fprintf(stderr, " (null)");
129 else
131 for (i = 0; i < n; ++i)
132 fprintf(stderr, " %d", sel[g]->p.m.refid[i]);
133 if (n < sel[g]->p.m.nr)
134 fprintf(stderr, " ...");
136 fprintf(stderr, "\n");
138 fprintf(stderr, " MapId:");
139 if (!sel[g]->p.m.mapid)
141 fprintf(stderr, " (null)");
143 else
145 for (i = 0; i < n; ++i)
146 fprintf(stderr, " %d", sel[g]->p.m.mapid[i]);
147 if (n < sel[g]->p.m.nr)
148 fprintf(stderr, " ...");
150 fprintf(stderr, "\n");
152 fprintf(stderr, "\n");
156 gmx_test_selection(int argc, char *argv[])
158 const char *desc[] = {
159 "This is a test program for selections.",
162 bool bMaskOnly = FALSE;
163 bool bFrameTree = FALSE;
164 int nref = 0;
165 int nmaxind = 20;
166 t_pargs pa[] = {
167 {"-mask", FALSE, etBOOL, {&bMaskOnly},
168 "Test position mask functionality"},
169 {"-frtree", FALSE, etBOOL, {&bFrameTree},
170 "Print the whole evaluation tree for each frame"},
171 {"-nref", FALSE, etINT, {&nref},
172 "Number of reference selections to ask for"},
173 {"-pmax", FALSE, etINT, {&nmaxind},
174 "Maximum number of indices to print in lists (-1 = print all)"},
177 t_filenm fnm[] = {
178 {efDAT, "-o", "debug", ffOPTWR},
181 gmx_ana_traj_t *trj;
182 t_dumpdata d;
183 int ngrps;
184 gmx_ana_selection_t **sel;
185 output_env_t oenv;
187 #define NFILE asize(fnm)
189 CopyRight(stderr, argv[0]);
191 gmx_ana_traj_create(&trj, ANA_DEBUG_SELECTION | ANA_USER_SELINIT | ANA_USE_FULLGRPS);
192 gmx_ana_get_selcollection(trj, &d.sc);
193 gmx_ana_set_nanagrps(trj, -1);
194 parse_trjana_args(trj, &argc, argv, 0,
195 NFILE, fnm, asize(pa), pa, asize(desc), desc, 0, NULL,
196 &oenv);
197 if (bMaskOnly)
199 gmx_ana_add_flags(trj, ANA_USE_POSMASK);
200 gmx_ana_selcollection_set_outpostype(d.sc, NULL, TRUE);
202 gmx_ana_set_nrefgrps(trj, nref);
203 gmx_ana_init_selections(trj);
204 gmx_ana_get_ngrps(trj, &ngrps);
205 gmx_ana_get_anagrps(trj, &sel);
207 d.bFrameTree = bFrameTree;
208 d.nmaxind = nmaxind;
210 print_selections(ngrps, sel, d.nmaxind);
212 gmx_ana_do(trj, 0, &dump_frame, &d);
214 print_selections(ngrps, sel, d.nmaxind);
216 gmx_ana_traj_free(trj);
218 return 0;
222 main(int argc, char *argv[])
224 gmx_test_selection(argc, argv);
225 return 0;