Improve use of gmxpreprocess headers
[alexxy/gromacs.git] / src / gromacs / gmxpreprocess / hackblock.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) 2013,2014,2015,2018,2019, 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
38 #ifndef GMX_GMXPREPROCESS_HACKBLOCK_H
39 #define GMX_GMXPREPROCESS_HACKBLOCK_H
40
41 #include <cstdio>
42
43 #include "gromacs/topology/ifunc.h"
44
45 struct t_atom;
46
47 /* Used for reading .rtp/.tdb */
48 /* ebtsBONDS must be the first, new types can be added to the end */
49 /* these *MUST* correspond to the arrays in hackblock.c */
50 enum {
51     ebtsBONDS, ebtsANGLES, ebtsPDIHS, ebtsIDIHS, ebtsEXCLS, ebtsCMAP, ebtsNR
52 };
53 extern const char *btsNames[ebtsNR];
54 extern const int   btsNiatoms[ebtsNR];
55
56 /* if changing any of these structs, make sure that all of the
57    free/clear/copy/merge_t_* functions stay updated */
58
59 /* BONDEDS */
60 struct t_rbonded
61 {
62     char  *a[MAXATOMLIST]; /* atom names */
63     char  *s;              /* optional define string which gets copied from
64                               .rtp/.tdb to .top and will be parsed by cpp
65                               during grompp */
66     bool     match;        /* boolean to mark that the entry has been found */
67     char*   &ai() { return a[0]; }
68     char*   &aj() { return a[1]; }
69     char*   &ak() { return a[2]; }
70     char*   &al() { return a[3]; }
71     char*   &am() { return a[4]; }
72 };
73
74 struct t_rbondeds
75 {
76     int        type;     /* The type of bonded interaction */
77     int        nb;       /* number of bondeds */
78     t_rbonded *b;        /* bondeds */
79 };
80
81 /* RESIDUES (rtp) */
82 struct t_restp
83 {
84     char         *resname;
85     /* The base file name this rtp entry was read from */
86     char         *filebase;
87     /* atom data */
88     int           natom;
89     t_atom       *atom;
90     char       ***atomname;
91     int          *cgnr;
92     /* Bonded interaction setup */
93     bool          bKeepAllGeneratedDihedrals;
94     int           nrexcl;
95     bool          bGenerateHH14Interactions;
96     bool          bRemoveDihedralIfWithImproper;
97     /* list of bonded interactions to add */
98     t_rbondeds    rb[ebtsNR];
99 };
100
101 /* Block to hack residues */
102 struct t_hack
103 {
104     int      nr;      /* Number of atoms to hack    */
105     char    *oname;   /* Old name                   */
106     char    *nname;   /* New name                   */
107     /* the type of hack depends on the setting of oname and nname:
108      * if oname==NULL                we're adding, must have tp>0 also!
109      * if oname!=NULL && nname==NULL we're deleting
110      * if oname!=NULL && nname!=NULL we're replacing
111      */
112     t_atom     *atom; /* New atom data              */
113     int         cgnr; /* chargegroup number. if not read will be NOTSET */
114     int         tp;   /* Type of attachment (1..11) */
115     int         nctl; /* How many control atoms there are */
116     char       *a[4]; /* Control atoms i,j,k,l    */
117     bool        bAlreadyPresent;
118     bool        bXSet;
119     rvec        newx; /* calculated new position    */
120     int         newi; /* new atom index number (after additions) */
121     char*      &ai() { return a[0]; }
122     char*      &aj() { return a[1]; }
123     char*      &ak() { return a[2]; }
124     char*      &al() { return a[3]; }
125 };
126
127 struct t_hackblock
128 {
129     char      *name;     /* Name of hack block (residue or terminus) */
130     char      *filebase; /* The base file name this entry was read from */
131     int        nhack;    /* Number of atoms to hack                  */
132     int        maxhack;  /* used for efficient srenew-ing            */
133     t_hack    *hack;     /* Hack list                                */
134     /* list of bonded interactions to add */
135     t_rbondeds rb[ebtsNR];
136 };
137
138 void free_t_restp(int nrtp, t_restp **rtp);
139 void free_t_hack(int nh, t_hack **h);
140 void free_t_hackblock(int nhb, t_hackblock **hb);
141 /* free the whole datastructure */
142
143 void clear_t_hackblock(t_hackblock *hb);
144 void clear_t_hack(t_hack *hack);
145 /* reset struct */
146
147 bool merge_t_bondeds(t_rbondeds s[], t_rbondeds d[],
148                      bool bMin, bool bPlus);
149 /* add s[].b[] to d[].b[]
150  * If bMin==TRUE, don't copy bondeds with atoms starting with '-'
151  * If bPlus==TRUE, don't copy bondeds with atoms starting with '+'
152  * Returns if bonds were removed at the termini.
153  */
154
155 void copy_t_restp(t_restp *s, t_restp *d);
156 void copy_t_hack(t_hack *s, t_hack *d);
157 void copy_t_hackblock(t_hackblock *s, t_hackblock *d);
158 /* make copy of whole datastructure */
159
160 void merge_hacks_lo(int ns, t_hack *s, int *nd, t_hack **d);
161 /* add s[] to *d[] */
162
163 void merge_hacks(t_hackblock *s, t_hackblock *d);
164 /* add s->hacks[] to d->hacks[] */
165
166 void merge_t_hackblock(t_hackblock *s, t_hackblock *d);
167 /* add s->hacks[] and s->rb[] to d*/
168
169 void dump_hb(FILE *out, int nres, t_hackblock hb[]);
170 /* print out whole datastructure */
171
172 #endif