3 * This source code is part of
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
32 * \brief Implementations of simple keyword selection methods.
39 #include <selmethod.h>
41 /** Evaluates the \p all selection keyword. */
43 evaluate_all(t_topology *top, t_trxframe *fr, t_pbc *pbc,
44 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
45 /** Evaluates the \p none selection keyword. */
47 evaluate_none(t_topology *top, t_trxframe *fr, t_pbc *pbc,
48 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
49 /** Evaluates the \p atomnr selection keyword. */
51 evaluate_atomnr(t_topology *top, t_trxframe *fr, t_pbc *pbc,
52 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
53 /** Evaluates the \p resnr selection keyword. */
55 evaluate_resnr(t_topology *top, t_trxframe *fr, t_pbc *pbc,
56 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
57 /** Evaluates the \p resindex selection keyword. */
59 evaluate_resindex(t_topology *top, t_trxframe *fr, t_pbc *pbc,
60 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
61 /** Checks whether molecule information is present in the topology. */
63 check_molecules(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
64 /** Evaluates the \p molindex selection keyword. */
66 evaluate_molindex(t_topology *top, t_trxframe *fr, t_pbc *pbc,
67 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
68 /** Evaluates the \p name selection keyword. */
70 evaluate_atomname(t_topology *top, t_trxframe *fr, t_pbc *pbc,
71 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
72 /** Checks whether atom types are present in the topology. */
74 check_atomtype(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
75 /** Evaluates the \p type selection keyword. */
77 evaluate_atomtype(t_topology *top, t_trxframe *fr, t_pbc *pbc,
78 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
79 /** Evaluates the \p insertcode selection keyword. */
81 evaluate_insertcode(t_topology *top, t_trxframe *fr, t_pbc *pbc,
82 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
83 /** Evaluates the \p chain selection keyword. */
85 evaluate_chain(t_topology *top, t_trxframe *fr, t_pbc *pbc,
86 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
87 /** Evaluates the \p mass selection keyword. */
89 evaluate_mass(t_topology *top, t_trxframe *fr, t_pbc *pbc,
90 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
91 /** Evaluates the \p charge selection keyword. */
93 evaluate_charge(t_topology *top, t_trxframe *fr, t_pbc *pbc,
94 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
95 /** Checks whether PDB info is present in the topology. */
97 check_pdbinfo(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
98 /** Evaluates the \p altloc selection keyword. */
100 evaluate_altloc(t_topology *top, t_trxframe *fr, t_pbc *pbc,
101 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
102 /** Evaluates the \p occupancy selection keyword. */
104 evaluate_occupancy(t_topology *top, t_trxframe *fr, t_pbc *pbc,
105 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
106 /** Evaluates the \p betafactor selection keyword. */
108 evaluate_betafactor(t_topology *top, t_trxframe *fr, t_pbc *pbc,
109 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
110 /** Evaluates the \p resname selection keyword. */
112 evaluate_resname(t_topology *top, t_trxframe *fr, t_pbc *pbc,
113 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
115 /** Evaluates the \p x selection keyword. */
117 evaluate_x(t_topology *top, t_trxframe *fr, t_pbc *pbc,
118 gmx_ana_pos_t *pos, gmx_ana_selvalue_t *out, void *data);
119 /** Evaluates the \p y selection keyword. */
121 evaluate_y(t_topology *top, t_trxframe *fr, t_pbc *pbc,
122 gmx_ana_pos_t *pos, gmx_ana_selvalue_t *out, void *data);
123 /** Evaluates the \p z selection keyword. */
125 evaluate_z(t_topology *top, t_trxframe *fr, t_pbc *pbc,
126 gmx_ana_pos_t *pos, gmx_ana_selvalue_t *out, void *data);
128 /** \internal Selection method data for \p all selection keyword. */
129 gmx_ana_selmethod_t sm_all = {
130 "all", GROUP_VALUE, 0,
142 /** \internal Selection method data for \p none selection keyword. */
143 gmx_ana_selmethod_t sm_none = {
144 "none", GROUP_VALUE, 0,
156 /** \internal Selection method data for \p atomnr selection keyword. */
157 gmx_ana_selmethod_t sm_atomnr = {
158 "atomnr", INT_VALUE, 0,
170 /** \internal Selection method data for \p resnr selection keyword. */
171 gmx_ana_selmethod_t sm_resnr = {
172 "resnr", INT_VALUE, SMETH_REQTOP,
184 /** \internal Selection method data for \p resindex selection keyword. */
185 gmx_ana_selmethod_t sm_resindex = {
186 "resindex", INT_VALUE, SMETH_REQTOP,
198 /** \internal Selection method data for \p molindex selection keyword. */
199 gmx_ana_selmethod_t sm_molindex = {
200 "molindex", INT_VALUE, SMETH_REQTOP,
212 /** \internal Selection method data for \p name selection keyword. */
213 gmx_ana_selmethod_t sm_atomname = {
214 "name", STR_VALUE, SMETH_REQTOP,
226 /** \internal Selection method data for \p type selection keyword. */
227 gmx_ana_selmethod_t sm_atomtype = {
228 "type", STR_VALUE, SMETH_REQTOP,
240 /** \internal Selection method data for \p resname selection keyword. */
241 gmx_ana_selmethod_t sm_resname = {
242 "resname", STR_VALUE, SMETH_REQTOP,
254 /** \internal Selection method data for \p chain selection keyword. */
255 gmx_ana_selmethod_t sm_insertcode = {
256 "insertcode", STR_VALUE, SMETH_REQTOP | SMETH_CHARVAL,
264 &evaluate_insertcode,
268 /** \internal Selection method data for \p chain selection keyword. */
269 gmx_ana_selmethod_t sm_chain = {
270 "chain", STR_VALUE, SMETH_REQTOP | SMETH_CHARVAL,
282 /** \internal Selection method data for \p mass selection keyword. */
283 gmx_ana_selmethod_t sm_mass = {
284 "mass", REAL_VALUE, SMETH_REQTOP,
296 /** \internal Selection method data for \p charge selection keyword. */
297 gmx_ana_selmethod_t sm_charge = {
298 "charge", REAL_VALUE, SMETH_REQTOP,
310 /** \internal Selection method data for \p chain selection keyword. */
311 gmx_ana_selmethod_t sm_altloc = {
312 "altloc", STR_VALUE, SMETH_REQTOP | SMETH_CHARVAL,
324 /** \internal Selection method data for \p occupancy selection keyword. */
325 gmx_ana_selmethod_t sm_occupancy = {
326 "occupancy", REAL_VALUE, SMETH_REQTOP,
338 /** \internal Selection method data for \p betafactor selection keyword. */
339 gmx_ana_selmethod_t sm_betafactor = {
340 "betafactor", REAL_VALUE, SMETH_REQTOP,
348 &evaluate_betafactor,
352 /** \internal Selection method data for \p x selection keyword. */
353 gmx_ana_selmethod_t sm_x = {
354 "x", REAL_VALUE, SMETH_DYNAMIC,
366 /** \internal Selection method data for \p y selection keyword. */
367 gmx_ana_selmethod_t sm_y = {
368 "y", REAL_VALUE, SMETH_DYNAMIC,
380 /** \internal Selection method data for \p z selection keyword. */
381 gmx_ana_selmethod_t sm_z = {
382 "z", REAL_VALUE, SMETH_DYNAMIC,
395 * See sel_updatefunc() for description of the parameters.
396 * \p data is not used.
398 * Copies \p g to \p out->u.g.
401 evaluate_all(t_topology *top, t_trxframe *fr, t_pbc *pbc,
402 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
404 gmx_ana_index_copy(out->u.g, g, FALSE);
409 * See sel_updatefunc() for description of the parameters.
410 * \p data is not used.
412 * Returns an empty \p out->u.g.
415 evaluate_none(t_topology *top, t_trxframe *fr, t_pbc *pbc,
416 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
423 * See sel_updatefunc() for description of the parameters.
424 * \p data is not used.
426 * Returns the indices for each atom in \p out->u.i.
429 evaluate_atomnr(t_topology *top, t_trxframe *fr, t_pbc *pbc,
430 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
435 for (i = 0; i < g->isize; ++i)
437 out->u.i[i] = g->index[i] + 1;
443 * See sel_updatefunc() for description of the parameters.
444 * \p data is not used.
446 * Returns the residue numbers for each atom in \p out->u.i.
449 evaluate_resnr(t_topology *top, t_trxframe *fr, t_pbc *pbc,
450 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
456 for (i = 0; i < g->isize; ++i)
458 resind = top->atoms.atom[g->index[i]].resind;
459 out->u.i[i] = top->atoms.resinfo[resind].nr;
465 * See sel_updatefunc() for description of the parameters.
466 * \p data is not used.
468 * Returns the residue indices for each atom in \p out->u.i.
471 evaluate_resindex(t_topology *top, t_trxframe *fr, t_pbc *pbc,
472 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
477 for (i = 0; i < g->isize; ++i)
479 out->u.i[i] = top->atoms.atom[g->index[i]].resind + 1;
485 * \param[in] top Topology structure.
486 * \param npar Not used.
487 * \param param Not used.
488 * \param data Not used.
489 * \returns 0 if molecule info is present in the topology, -1 otherwise.
491 * If molecule information is not found, also prints an error message.
494 check_molecules(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
498 bOk = (top != NULL && top->mols.nr > 0);
501 fprintf(stderr, "Molecule information not available in topology!\n");
508 * See sel_updatefunc() for description of the parameters.
509 * \p data is not used.
511 * Returns the molecule indices for each atom in \p out->u.i.
514 evaluate_molindex(t_topology *top, t_trxframe *fr, t_pbc *pbc,
515 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
520 for (i = j = 0; i < g->isize; ++i)
522 while (top->mols.index[j + 1] <= g->index[i]) ++j;
529 * See sel_updatefunc() for description of the parameters.
530 * \p data is not used.
532 * Returns the atom name for each atom in \p out->u.s.
535 evaluate_atomname(t_topology *top, t_trxframe *fr, t_pbc *pbc,
536 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
541 for (i = 0; i < g->isize; ++i)
543 out->u.s[i] = *top->atoms.atomname[g->index[i]];
549 * \param[in] top Topology structure.
550 * \param npar Not used.
551 * \param param Not used.
552 * \param data Not used.
553 * \returns 0 if atom types are present in the topology, -1 otherwise.
555 * If the atom types are not found, also prints an error message.
558 check_atomtype(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
562 bOk = (top != NULL && top->atoms.atomtype != NULL);
565 fprintf(stderr, "Atom types not available in topology!\n");
572 * See sel_updatefunc() for description of the parameters.
573 * \p data is not used.
575 * Returns the atom type for each atom in \p out->u.s.
576 * Segfaults if atom types are not found in the topology.
579 evaluate_atomtype(t_topology *top, t_trxframe *fr, t_pbc *pbc,
580 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
585 for (i = 0; i < g->isize; ++i)
587 out->u.s[i] = *top->atoms.atomtype[g->index[i]];
593 * See sel_updatefunc() for description of the parameters.
594 * \p data is not used.
596 * Returns the residue name for each atom in \p out->u.s.
599 evaluate_resname(t_topology *top, t_trxframe *fr, t_pbc *pbc,
600 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
606 for (i = 0; i < g->isize; ++i)
608 resind = top->atoms.atom[g->index[i]].resind;
609 out->u.s[i] = *top->atoms.resinfo[resind].name;
615 * See sel_updatefunc() for description of the parameters.
616 * \p data is not used.
618 * Returns the insertion code for each atom in \p out->u.s.
621 evaluate_insertcode(t_topology *top, t_trxframe *fr, t_pbc *pbc,
622 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
628 for (i = 0; i < g->isize; ++i)
630 resind = top->atoms.atom[g->index[i]].resind;
631 out->u.s[i][0] = top->atoms.resinfo[resind].ic;
637 * See sel_updatefunc() for description of the parameters.
638 * \p data is not used.
640 * Returns the chain for each atom in \p out->u.s.
643 evaluate_chain(t_topology *top, t_trxframe *fr, t_pbc *pbc,
644 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
650 for (i = 0; i < g->isize; ++i)
652 resind = top->atoms.atom[g->index[i]].resind;
653 out->u.s[i][0] = top->atoms.resinfo[resind].chainid;
659 * See sel_updatefunc() for description of the parameters.
660 * \p data is not used.
662 * Returns the mass for each atom in \p out->u.r.
665 evaluate_mass(t_topology *top, t_trxframe *fr, t_pbc *pbc,
666 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
671 for (i = 0; i < g->isize; ++i)
673 out->u.r[i] = top->atoms.atom[g->index[i]].m;
679 * See sel_updatefunc() for description of the parameters.
680 * \p data is not used.
682 * Returns the charge for each atom in \p out->u.r.
685 evaluate_charge(t_topology *top, t_trxframe *fr, t_pbc *pbc,
686 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
691 for (i = 0; i < g->isize; ++i)
693 out->u.r[i] = top->atoms.atom[g->index[i]].q;
699 * \param[in] top Topology structure.
700 * \param npar Not used.
701 * \param param Not used.
702 * \param data Not used.
703 * \returns 0 if PDB info is present in the topology, -1 otherwise.
705 * If PDB info is not found, also prints an error message.
708 check_pdbinfo(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
712 bOk = (top != NULL && top->atoms.pdbinfo != NULL);
715 fprintf(stderr, "PDB info not available in topology!\n");
722 * See sel_updatefunc() for description of the parameters.
723 * \p data is not used.
725 * Returns the alternate location identifier for each atom in \p out->u.s.
728 evaluate_altloc(t_topology *top, t_trxframe *fr, t_pbc *pbc,
729 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
734 for (i = 0; i < g->isize; ++i)
736 out->u.s[i][0] = top->atoms.pdbinfo[g->index[i]].altloc;
742 * See sel_updatefunc() for description of the parameters.
743 * \p data is not used.
745 * Returns the occupancy numbers for each atom in \p out->u.r.
746 * Segfaults if PDB info is not found in the topology.
749 evaluate_occupancy(t_topology *top, t_trxframe *fr, t_pbc *pbc,
750 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
755 for (i = 0; i < g->isize; ++i)
757 out->u.r[i] = top->atoms.pdbinfo[g->index[i]].occup;
763 * See sel_updatefunc() for description of the parameters.
764 * \p data is not used.
766 * Returns the B-factors for each atom in \p out->u.r.
767 * Segfaults if PDB info is not found in the topology.
770 evaluate_betafactor(t_topology *top, t_trxframe *fr, t_pbc *pbc,
771 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
776 for (i = 0; i < g->isize; ++i)
778 out->u.r[i] = top->atoms.pdbinfo[g->index[i]].bfac;
784 * Internal utility function for position keyword evaluation.
786 * \param[in] fr Current frame.
787 * \param[in] g Index group for which the coordinates should be evaluated.
788 * \param[out] out Output array.
789 * \param[in] pos Position data to use instead of atomic coordinates
791 * \param[in] d Coordinate index to evaluate (\p XX, \p YY or \p ZZ).
793 * This function is used internally by evaluate_x(), evaluate_y() and
794 * evaluate_z() to do the actual evaluation.
797 evaluate_coord(t_trxframe *fr, gmx_ana_index_t *g, real out[],
798 gmx_ana_pos_t *pos, int d)
805 for (b = 0; b < pos->nr; ++b)
808 for (i = pos->m.mapb.index[b]; i < pos->m.mapb.index[b+1]; ++i)
816 for (i = 0; i < g->isize; ++i)
818 out[i] = fr->x[g->index[i]][d];
824 * See sel_updatefunc_pos() for description of the parameters.
825 * \p data is not used.
827 * Returns the \p x coordinate for each atom in \p out->u.r.
830 evaluate_x(t_topology *top, t_trxframe *fr, t_pbc *pbc,
831 gmx_ana_pos_t *pos, gmx_ana_selvalue_t *out, void *data)
833 out->nr = pos->g->isize;
834 evaluate_coord(fr, pos->g, out->u.r, pos, XX);
839 * See sel_updatefunc() for description of the parameters.
840 * \p data is not used.
842 * Returns the \p y coordinate for each atom in \p out->u.r.
845 evaluate_y(t_topology *top, t_trxframe *fr, t_pbc *pbc,
846 gmx_ana_pos_t *pos, gmx_ana_selvalue_t *out, void *data)
848 out->nr = pos->g->isize;
849 evaluate_coord(fr, pos->g, out->u.r, pos, YY);
854 * See sel_updatefunc() for description of the parameters.
855 * \p data is not used.
857 * Returns the \p z coordinate for each atom in \p out->u.r.
860 evaluate_z(t_topology *top, t_trxframe *fr, t_pbc *pbc,
861 gmx_ana_pos_t *pos, gmx_ana_selvalue_t *out, void *data)
863 out->nr = pos->g->isize;
864 evaluate_coord(fr, pos->g, out->u.r, pos, ZZ);