ed2b5ae7de7303bee75e1cbbccfd79585f9186f5
[alexxy/gromacs.git] / src / gromacs / topology / topology.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team.
6  * Copyright (c) 2011,2014,2015,2016, 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.
10  *
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.
15  *
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.
20  *
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.
25  *
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.
33  *
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.
36  */
37 #ifndef GMX_TOPOLOGY_TOPOLOGY_H
38 #define GMX_TOPOLOGY_TOPOLOGY_H
39
40 #include <cstdio>
41
42 #include "gromacs/math/vectypes.h"
43 #include "gromacs/topology/atoms.h"
44 #include "gromacs/topology/block.h"
45 #include "gromacs/topology/idef.h"
46 #include "gromacs/topology/symtab.h"
47
48 enum {
49     egcTC,    egcENER,   egcACC, egcFREEZE,
50     egcUser1, egcUser2,  egcVCM, egcCompressedX,
51     egcORFIT, egcQMMM,
52     egcNR
53 };
54 /* Names corresponding to groups */
55 extern const char *gtypes[egcNR+1];
56
57 typedef struct gmx_moltype_t
58 {
59     char          **name;         /* Name of the molecule type            */
60     t_atoms         atoms;        /* The atoms in this molecule           */
61     t_ilist         ilist[F_NRE]; /* Interaction list with local indices  */
62     t_block         cgs;          /* The charge groups                    */
63     t_blocka        excls;        /* The exclusions                       */
64 } gmx_moltype_t;
65
66 /*! \brief Block of molecules of the same type, used in gmx_mtop_t */
67 typedef struct gmx_molblock_t
68 {
69     int     type;               /**< The molecule type index in mtop.moltype  */
70     int     nmol;               /**< The number of molecules in this block    */
71     int     nposres_xA;         /**< The number of posres coords for top A    */
72     rvec   *posres_xA;          /**< Position restraint coordinates for top A */
73     int     nposres_xB;         /**< The number of posres coords for top B    */
74     rvec   *posres_xB;          /**< Position restraint coordinates for top B */
75
76     /* Convenience information, derived from other gmx_mtop_t contents     */
77     int     natoms_mol;         /**< The number of atoms in one molecule      */
78     int     globalAtomStart;    /**< Global atom index of the first atom in the block */
79     int     globalAtomEnd;      /**< Global atom index + 1 of the last atom in the block */
80     int     globalResidueStart; /**< Global residue index of the first residue in the block */
81     int     residueNumberStart; /**< Residue numbers start from this value if the number of residues per molecule is <= maxres_renum */
82 } gmx_molblock_t;
83
84 typedef struct gmx_groups_t
85 {
86     t_grps            grps[egcNR];  /* Groups of things                     */
87     int               ngrpname;     /* Number of groupnames                 */
88     char           ***grpname;      /* Names of the groups                  */
89     int               ngrpnr[egcNR];
90     unsigned char    *grpnr[egcNR]; /* Group numbers or NULL                */
91 } gmx_groups_t;
92
93 /* This macro gives the group number of group type egc for atom i.
94  * This macro is useful, since the grpnr pointers are NULL
95  * for group types that have all entries 0.
96  */
97 #define ggrpnr(groups, egc, i) ((groups)->grpnr[egc] ? (groups)->grpnr[egc][i] : 0)
98
99 /* The global, complete system topology struct, based on molecule types.
100    This structure should contain no data that is O(natoms) in memory. */
101 typedef struct gmx_mtop_t
102 {
103     char           **name;      /* Name of the topology                 */
104     gmx_ffparams_t   ffparams;
105     int              nmoltype;
106     gmx_moltype_t   *moltype;
107     int              nmolblock;
108     gmx_molblock_t  *molblock;
109     gmx_bool         bIntermolecularInteractions; /* Are there intermolecular
110                                                    * interactions?            */
111     t_ilist         *intermolecular_ilist;        /* List of intermolecular interactions
112                                                    * using system wide atom indices,
113                                                    * either NULL or size F_NRE           */
114     int              natoms;
115     int              maxres_renum;                /* Parameter for residue numbering      */
116     int              maxresnr;                    /* The maximum residue number in moltype */
117     t_atomtypes      atomtypes;                   /* Atomtype properties                  */
118     t_block          mols;                        /* The molecules                        */
119     gmx_groups_t     groups;
120     t_symtab         symtab;                      /* The symbol table                     */
121 } gmx_mtop_t;
122
123 /* The mdrun node-local topology struct, completely written out */
124 typedef struct gmx_localtop_t
125 {
126     t_idef        idef;         /* The interaction function definition  */
127     t_atomtypes   atomtypes;    /* Atomtype properties                  */
128     t_block       cgs;          /* The charge groups                    */
129     t_blocka      excls;        /* The exclusions                       */
130 } gmx_localtop_t;
131
132 /* The old topology struct, completely written out, used in analysis tools */
133 typedef struct t_topology
134 {
135     char          **name;                        /* Name of the topology                 */
136     t_idef          idef;                        /* The interaction function definition  */
137     t_atoms         atoms;                       /* The atoms                            */
138     t_atomtypes     atomtypes;                   /* Atomtype properties                  */
139     t_block         cgs;                         /* The charge groups                    */
140     t_block         mols;                        /* The molecules                        */
141     gmx_bool        bIntermolecularInteractions; /* Inter.mol. int. ?   */
142     t_blocka        excls;                       /* The exclusions                       */
143     t_symtab        symtab;                      /* The symbol table                     */
144 } t_topology;
145
146 void init_mtop(gmx_mtop_t *mtop);
147 void init_top(t_topology *top);
148 void done_moltype(gmx_moltype_t *molt);
149 void done_molblock(gmx_molblock_t *molb);
150 void done_gmx_groups_t(gmx_groups_t *g);
151 void done_mtop(gmx_mtop_t *mtop);
152 void done_top(t_topology *top);
153 // Frees both t_topology and gmx_mtop_t when the former has been created from
154 // the latter.
155 void done_top_mtop(t_topology *top, gmx_mtop_t *mtop);
156
157 bool gmx_mtop_has_masses(const gmx_mtop_t *mtop);
158 bool gmx_mtop_has_charges(const gmx_mtop_t *mtop);
159 bool gmx_mtop_has_atomtypes(const gmx_mtop_t *mtop);
160 bool gmx_mtop_has_pdbinfo(const gmx_mtop_t *mtop);
161
162 void pr_mtop(FILE *fp, int indent, const char *title, const gmx_mtop_t *mtop,
163              gmx_bool bShowNumbers);
164 void pr_top(FILE *fp, int indent, const char *title, const t_topology *top, gmx_bool bShowNumbers);
165
166 void cmp_top(FILE *fp, const t_topology *t1, const t_topology *t2, real ftol, real abstol);
167 void cmp_groups(FILE *fp, const gmx_groups_t *g0, const gmx_groups_t *g1,
168                 int natoms0, int natoms1);
169
170 #endif