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 name selection keyword. */
59 evaluate_atomname(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 atom types are present in the topology. */
63 check_atomtype(t_topology
*top
, int npar
, gmx_ana_selparam_t
*param
, void *data
);
64 /** Evaluates the \p type selection keyword. */
66 evaluate_atomtype(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 insertcode selection keyword. */
70 evaluate_insertcode(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
71 gmx_ana_index_t
*g
, gmx_ana_selvalue_t
*out
, void *data
);
72 /** Evaluates the \p chain selection keyword. */
74 evaluate_chain(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
75 gmx_ana_index_t
*g
, gmx_ana_selvalue_t
*out
, void *data
);
76 /** Evaluates the \p mass selection keyword. */
78 evaluate_mass(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
79 gmx_ana_index_t
*g
, gmx_ana_selvalue_t
*out
, void *data
);
80 /** Evaluates the \p charge selection keyword. */
82 evaluate_charge(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
83 gmx_ana_index_t
*g
, gmx_ana_selvalue_t
*out
, void *data
);
84 /** Checks whether PDB info is present in the topology. */
86 check_pdbinfo(t_topology
*top
, int npar
, gmx_ana_selparam_t
*param
, void *data
);
87 /** Evaluates the \p altloc selection keyword. */
89 evaluate_altloc(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 occupancy selection keyword. */
93 evaluate_occupancy(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
94 gmx_ana_index_t
*g
, gmx_ana_selvalue_t
*out
, void *data
);
95 /** Evaluates the \p betafactor selection keyword. */
97 evaluate_betafactor(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
98 gmx_ana_index_t
*g
, gmx_ana_selvalue_t
*out
, void *data
);
99 /** Evaluates the \p resname selection keyword. */
101 evaluate_resname(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
102 gmx_ana_index_t
*g
, gmx_ana_selvalue_t
*out
, void *data
);
104 /** Evaluates the \p x selection keyword. */
106 evaluate_x(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
107 gmx_ana_pos_t
*pos
, gmx_ana_selvalue_t
*out
, void *data
);
108 /** Evaluates the \p y selection keyword. */
110 evaluate_y(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
111 gmx_ana_pos_t
*pos
, gmx_ana_selvalue_t
*out
, void *data
);
112 /** Evaluates the \p z selection keyword. */
114 evaluate_z(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
115 gmx_ana_pos_t
*pos
, gmx_ana_selvalue_t
*out
, void *data
);
117 /** \internal Selection method data for \p all selection keyword. */
118 gmx_ana_selmethod_t sm_all
= {
119 "all", GROUP_VALUE
, 0,
131 /** \internal Selection method data for \p none selection keyword. */
132 gmx_ana_selmethod_t sm_none
= {
133 "none", GROUP_VALUE
, 0,
145 /** \internal Selection method data for \p atomnr selection keyword. */
146 gmx_ana_selmethod_t sm_atomnr
= {
147 "atomnr", INT_VALUE
, 0,
159 /** \internal Selection method data for \p resnr selection keyword. */
160 gmx_ana_selmethod_t sm_resnr
= {
161 "resnr", INT_VALUE
, SMETH_REQTOP
,
173 /** \internal Selection method data for \p name selection keyword. */
174 gmx_ana_selmethod_t sm_atomname
= {
175 "name", STR_VALUE
, SMETH_REQTOP
,
187 /** \internal Selection method data for \p type selection keyword. */
188 gmx_ana_selmethod_t sm_atomtype
= {
189 "type", STR_VALUE
, SMETH_REQTOP
,
201 /** \internal Selection method data for \p resname selection keyword. */
202 gmx_ana_selmethod_t sm_resname
= {
203 "resname", STR_VALUE
, SMETH_REQTOP
,
215 /** \internal Selection method data for \p chain selection keyword. */
216 gmx_ana_selmethod_t sm_insertcode
= {
217 "insertcode", STR_VALUE
, SMETH_REQTOP
| SMETH_CHARVAL
,
225 &evaluate_insertcode
,
229 /** \internal Selection method data for \p chain selection keyword. */
230 gmx_ana_selmethod_t sm_chain
= {
231 "chain", STR_VALUE
, SMETH_REQTOP
| SMETH_CHARVAL
,
243 /** \internal Selection method data for \p mass selection keyword. */
244 gmx_ana_selmethod_t sm_mass
= {
245 "mass", REAL_VALUE
, SMETH_REQTOP
,
257 /** \internal Selection method data for \p charge selection keyword. */
258 gmx_ana_selmethod_t sm_charge
= {
259 "charge", REAL_VALUE
, SMETH_REQTOP
,
271 /** \internal Selection method data for \p chain selection keyword. */
272 gmx_ana_selmethod_t sm_altloc
= {
273 "altloc", STR_VALUE
, SMETH_REQTOP
| SMETH_CHARVAL
,
285 /** \internal Selection method data for \p occupancy selection keyword. */
286 gmx_ana_selmethod_t sm_occupancy
= {
287 "occupancy", REAL_VALUE
, SMETH_REQTOP
,
299 /** \internal Selection method data for \p betafactor selection keyword. */
300 gmx_ana_selmethod_t sm_betafactor
= {
301 "betafactor", REAL_VALUE
, SMETH_REQTOP
,
309 &evaluate_betafactor
,
313 /** \internal Selection method data for \p x selection keyword. */
314 gmx_ana_selmethod_t sm_x
= {
315 "x", REAL_VALUE
, SMETH_DYNAMIC
,
327 /** \internal Selection method data for \p y selection keyword. */
328 gmx_ana_selmethod_t sm_y
= {
329 "y", REAL_VALUE
, SMETH_DYNAMIC
,
341 /** \internal Selection method data for \p z selection keyword. */
342 gmx_ana_selmethod_t sm_z
= {
343 "z", REAL_VALUE
, SMETH_DYNAMIC
,
356 * See sel_updatefunc() for description of the parameters.
357 * \p data is not used.
359 * Copies \p g to \p out->u.g.
362 evaluate_all(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
363 gmx_ana_index_t
*g
, gmx_ana_selvalue_t
*out
, void *data
)
365 gmx_ana_index_copy(out
->u
.g
, g
, FALSE
);
370 * See sel_updatefunc() for description of the parameters.
371 * \p data is not used.
373 * Returns an empty \p out->u.g.
376 evaluate_none(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
377 gmx_ana_index_t
*g
, gmx_ana_selvalue_t
*out
, void *data
)
384 * See sel_updatefunc() for description of the parameters.
385 * \p data is not used.
387 * Returns the indices for each atom in \p out->u.i.
390 evaluate_atomnr(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
391 gmx_ana_index_t
*g
, gmx_ana_selvalue_t
*out
, void *data
)
396 for (i
= 0; i
< g
->isize
; ++i
)
398 out
->u
.i
[i
] = g
->index
[i
] + 1;
404 * See sel_updatefunc() for description of the parameters.
405 * \p data is not used.
407 * Returns the residue numbers for each atom in \p out->u.i.
410 evaluate_resnr(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
411 gmx_ana_index_t
*g
, gmx_ana_selvalue_t
*out
, void *data
)
417 for (i
= 0; i
< g
->isize
; ++i
)
419 resind
= top
->atoms
.atom
[g
->index
[i
]].resind
;
420 out
->u
.i
[i
] = top
->atoms
.resinfo
[resind
].nr
;
426 * See sel_updatefunc() for description of the parameters.
427 * \p data is not used.
429 * Returns the atom name for each atom in \p out->u.s.
432 evaluate_atomname(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
433 gmx_ana_index_t
*g
, gmx_ana_selvalue_t
*out
, void *data
)
438 for (i
= 0; i
< g
->isize
; ++i
)
440 out
->u
.s
[i
] = *top
->atoms
.atomname
[g
->index
[i
]];
446 * \param[in] top Topology structure.
447 * \param npar Not used.
448 * \param param Not used.
449 * \param data Not used.
450 * \returns 0 if atom types are present in the topology, -1 otherwise.
452 * If the atom types are not found, also prints an error message.
455 check_atomtype(t_topology
*top
, int npar
, gmx_ana_selparam_t
*param
, void *data
)
459 bOk
= (top
!= NULL
&& top
->atoms
.atomtype
!= NULL
);
462 fprintf(stderr
, "Atom types not available in topology!\n");
469 * See sel_updatefunc() for description of the parameters.
470 * \p data is not used.
472 * Returns the atom type for each atom in \p out->u.s.
473 * Segfaults if atom types are not found in the topology.
476 evaluate_atomtype(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
477 gmx_ana_index_t
*g
, gmx_ana_selvalue_t
*out
, void *data
)
482 for (i
= 0; i
< g
->isize
; ++i
)
484 out
->u
.s
[i
] = *top
->atoms
.atomtype
[g
->index
[i
]];
490 * See sel_updatefunc() for description of the parameters.
491 * \p data is not used.
493 * Returns the residue name for each atom in \p out->u.s.
496 evaluate_resname(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
497 gmx_ana_index_t
*g
, gmx_ana_selvalue_t
*out
, void *data
)
503 for (i
= 0; i
< g
->isize
; ++i
)
505 resind
= top
->atoms
.atom
[g
->index
[i
]].resind
;
506 out
->u
.s
[i
] = *top
->atoms
.resinfo
[resind
].name
;
512 * See sel_updatefunc() for description of the parameters.
513 * \p data is not used.
515 * Returns the insertion code for each atom in \p out->u.s.
518 evaluate_insertcode(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
519 gmx_ana_index_t
*g
, gmx_ana_selvalue_t
*out
, void *data
)
525 for (i
= 0; i
< g
->isize
; ++i
)
527 resind
= top
->atoms
.atom
[g
->index
[i
]].resind
;
528 out
->u
.s
[i
][0] = top
->atoms
.resinfo
[resind
].ic
;
534 * See sel_updatefunc() for description of the parameters.
535 * \p data is not used.
537 * Returns the chain for each atom in \p out->u.s.
540 evaluate_chain(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
541 gmx_ana_index_t
*g
, gmx_ana_selvalue_t
*out
, void *data
)
547 for (i
= 0; i
< g
->isize
; ++i
)
549 resind
= top
->atoms
.atom
[g
->index
[i
]].resind
;
550 out
->u
.s
[i
][0] = top
->atoms
.resinfo
[resind
].chain
;
556 * See sel_updatefunc() for description of the parameters.
557 * \p data is not used.
559 * Returns the mass for each atom in \p out->u.r.
562 evaluate_mass(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
563 gmx_ana_index_t
*g
, gmx_ana_selvalue_t
*out
, void *data
)
568 for (i
= 0; i
< g
->isize
; ++i
)
570 out
->u
.r
[i
] = top
->atoms
.atom
[g
->index
[i
]].m
;
576 * See sel_updatefunc() for description of the parameters.
577 * \p data is not used.
579 * Returns the charge for each atom in \p out->u.r.
582 evaluate_charge(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
583 gmx_ana_index_t
*g
, gmx_ana_selvalue_t
*out
, void *data
)
588 for (i
= 0; i
< g
->isize
; ++i
)
590 out
->u
.r
[i
] = top
->atoms
.atom
[g
->index
[i
]].q
;
596 * \param[in] top Topology structure.
597 * \param npar Not used.
598 * \param param Not used.
599 * \param data Not used.
600 * \returns 0 if PDB info is present in the topology, -1 otherwise.
602 * If PDB info is not found, also prints an error message.
605 check_pdbinfo(t_topology
*top
, int npar
, gmx_ana_selparam_t
*param
, void *data
)
609 bOk
= (top
!= NULL
&& top
->atoms
.pdbinfo
!= NULL
);
612 fprintf(stderr
, "PDB info not available in topology!\n");
619 * See sel_updatefunc() for description of the parameters.
620 * \p data is not used.
622 * Returns the alternate location identifier for each atom in \p out->u.s.
625 evaluate_altloc(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
626 gmx_ana_index_t
*g
, gmx_ana_selvalue_t
*out
, void *data
)
631 for (i
= 0; i
< g
->isize
; ++i
)
633 out
->u
.s
[i
][0] = top
->atoms
.pdbinfo
[g
->index
[i
]].altloc
;
639 * See sel_updatefunc() for description of the parameters.
640 * \p data is not used.
642 * Returns the occupancy numbers for each atom in \p out->u.r.
643 * Segfaults if PDB info is not found in the topology.
646 evaluate_occupancy(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
647 gmx_ana_index_t
*g
, gmx_ana_selvalue_t
*out
, void *data
)
652 for (i
= 0; i
< g
->isize
; ++i
)
654 out
->u
.r
[i
] = top
->atoms
.pdbinfo
[g
->index
[i
]].occup
;
660 * See sel_updatefunc() for description of the parameters.
661 * \p data is not used.
663 * Returns the B-factors for each atom in \p out->u.r.
664 * Segfaults if PDB info is not found in the topology.
667 evaluate_betafactor(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
668 gmx_ana_index_t
*g
, gmx_ana_selvalue_t
*out
, void *data
)
673 for (i
= 0; i
< g
->isize
; ++i
)
675 out
->u
.r
[i
] = top
->atoms
.pdbinfo
[g
->index
[i
]].bfac
;
681 * Internal utility function for position keyword evaluation.
683 * \param[in] fr Current frame.
684 * \param[in] g Index group for which the coordinates should be evaluated.
685 * \param[out] out Output array.
686 * \param[in] pos Position data to use instead of atomic coordinates
688 * \param[in] d Coordinate index to evaluate (\p XX, \p YY or \p ZZ).
690 * This function is used internally by evaluate_x(), evaluate_y() and
691 * evaluate_z() to do the actual evaluation.
694 evaluate_coord(t_trxframe
*fr
, gmx_ana_index_t
*g
, real out
[],
695 gmx_ana_pos_t
*pos
, int d
)
702 for (b
= 0; b
< pos
->nr
; ++b
)
705 for (i
= pos
->m
.mapb
.index
[b
]; i
< pos
->m
.mapb
.index
[b
+1]; ++i
)
713 for (i
= 0; i
< g
->isize
; ++i
)
715 out
[i
] = fr
->x
[g
->index
[i
]][d
];
721 * See sel_updatefunc_pos() for description of the parameters.
722 * \p data is not used.
724 * Returns the \p x coordinate for each atom in \p out->u.r.
727 evaluate_x(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
728 gmx_ana_pos_t
*pos
, gmx_ana_selvalue_t
*out
, void *data
)
730 out
->nr
= pos
->g
->isize
;
731 evaluate_coord(fr
, pos
->g
, out
->u
.r
, pos
, XX
);
736 * See sel_updatefunc() for description of the parameters.
737 * \p data is not used.
739 * Returns the \p y coordinate for each atom in \p out->u.r.
742 evaluate_y(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
743 gmx_ana_pos_t
*pos
, gmx_ana_selvalue_t
*out
, void *data
)
745 out
->nr
= pos
->g
->isize
;
746 evaluate_coord(fr
, pos
->g
, out
->u
.r
, pos
, YY
);
751 * See sel_updatefunc() for description of the parameters.
752 * \p data is not used.
754 * Returns the \p z coordinate for each atom in \p out->u.r.
757 evaluate_z(t_topology
*top
, t_trxframe
*fr
, t_pbc
*pbc
,
758 gmx_ana_pos_t
*pos
, gmx_ana_selvalue_t
*out
, void *data
)
760 out
->nr
= pos
->g
->isize
;
761 evaluate_coord(fr
, pos
->g
, out
->u
.r
, pos
, ZZ
);