Merge branch release-5-1
[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, 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 "gromacs/fileio/pdbio.h"
42 #include "gromacs/gmxpreprocess/gpp_atomtype.h"
43 #include "gromacs/gmxpreprocess/grompp-impl.h"
44 #include "gromacs/legacyheaders/typedefs.h"
45 #include "gromacs/topology/symtab.h"
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 typedef struct {
61     char  *a[MAXATOMLIST]; /* atom names */
62     char  *s;              /* optional define string which gets copied from
63                               .rtp/.tdb to .top and will be parsed by cpp
64                               during grompp */
65     gmx_bool match;        /* boolean to mark that the entry has been found */
66 } t_rbonded;
67
68 typedef struct {
69     int        type;     /* The type of bonded interaction */
70     int        nb;       /* number of bondeds */
71     t_rbonded *b;        /* bondeds */
72 } t_rbondeds;
73
74 /* RESIDUES (rtp) */
75 typedef struct {
76     char         *resname;
77     /* The base file name this rtp entry was read from */
78     char         *filebase;
79     /* atom data */
80     int           natom;
81     t_atom       *atom;
82     char       ***atomname;
83     int          *cgnr;
84     /* Bonded interaction setup */
85     gmx_bool      bKeepAllGeneratedDihedrals;
86     int           nrexcl;
87     gmx_bool      bGenerateHH14Interactions;
88     gmx_bool      bRemoveDihedralIfWithImproper;
89     /* list of bonded interactions to add */
90     t_rbondeds    rb[ebtsNR];
91 } t_restp;
92
93 /* Block to hack residues */
94 typedef struct {
95     int      nr;      /* Number of atoms to hack    */
96     char    *oname;   /* Old name                   */
97     char    *nname;   /* New name                   */
98     /* the type of hack depends on the setting of oname and nname:
99      * if oname==NULL                we're adding, must have tp>0 also!
100      * if oname!=NULL && nname==NULL we're deleting
101      * if oname!=NULL && nname!=NULL we're replacing
102      */
103     t_atom     *atom; /* New atom data              */
104     int         cgnr; /* chargegroup number. if not read will be NOTSET */
105     int         tp;   /* Type of attachment (1..11) */
106     int         nctl; /* How many control atoms there are */
107     char       *a[4]; /* Control atoms i,j,k,l    */
108     gmx_bool    bAlreadyPresent;
109     gmx_bool    bXSet;
110     rvec        newx; /* calculated new position    */
111     atom_id     newi; /* new atom index number (after additions) */
112 } t_hack;
113
114 typedef struct {
115     char      *name;     /* Name of hack block (residue or terminus) */
116     char      *filebase; /* The base file name this entry was read from */
117     int        nhack;    /* Number of atoms to hack                  */
118     int        maxhack;  /* used for efficient srenew-ing            */
119     t_hack    *hack;     /* Hack list                                */
120     /* list of bonded interactions to add */
121     t_rbondeds rb[ebtsNR];
122 } t_hackblock;
123
124 /* all libraries and other data to protonate a structure or trajectory */
125 typedef struct {
126     gmx_bool        bInit; /* true after init; set false by init_t_protonate */
127     /* force field name: */
128     char            FF[10];
129     /* libarary data: */
130     int            *nab;
131     t_hack        **ab;
132     t_hackblock    *ah, *ntdb, *ctdb;
133     t_hackblock   **sel_ntdb, **sel_ctdb;
134     int             nah;
135     t_symtab        tab;
136     /* residue indices (not numbers!) of the N and C termini */
137     int            *rN, *rC;
138     gpp_atomtype_t  atype;
139     /* protonated topology: */
140     t_atoms        *patoms;
141     /* unprotonated topology: */
142     t_atoms        *upatoms;
143
144 } t_protonate;
145
146 typedef struct {
147     char *res1, *res2;
148     char *atom1, *atom2;
149     char *newres1, *newres2;
150     int   nbond1, nbond2;
151     real  length;
152 } t_specbond;
153
154 t_specbond *get_specbonds(int *nspecbond);
155 void done_specbonds(int nsb, t_specbond sb[]);
156
157 void free_t_restp(int nrtp, t_restp **rtp);
158 void free_t_hack(int nh, t_hack **h);
159 void free_t_hackblock(int nhb, t_hackblock **hb);
160 /* free the whole datastructure */
161
162 void clear_t_hackblock(t_hackblock *hb);
163 void clear_t_hack(t_hack *hack);
164 /* reset struct */
165
166 gmx_bool merge_t_bondeds(t_rbondeds s[], t_rbondeds d[],
167                          gmx_bool bMin, gmx_bool bPlus);
168 /* add s[].b[] to d[].b[]
169  * If bMin==TRUE, don't copy bondeds with atoms starting with '-'
170  * If bPlus==TRUE, don't copy bondeds with atoms starting with '+'
171  * Returns if bonds were removed at the termini.
172  */
173
174 void copy_t_restp(t_restp *s, t_restp *d);
175 void copy_t_hack(t_hack *s, t_hack *d);
176 void copy_t_hackblock(t_hackblock *s, t_hackblock *d);
177 /* make copy of whole datastructure */
178
179 void merge_hacks_lo(int ns, t_hack *s, int *nd, t_hack **d);
180 /* add s[] to *d[] */
181
182 void merge_hacks(t_hackblock *s, t_hackblock *d);
183 /* add s->hacks[] to d->hacks[] */
184
185 void merge_t_hackblock(t_hackblock *s, t_hackblock *d);
186 /* add s->hacks[] and s->rb[] to d*/
187
188 void dump_hb(FILE *out, int nres, t_hackblock hb[]);
189 /* print out whole datastructure */
190
191 void init_t_protonate(t_protonate *protonate);
192 /* initialize t_protein struct */
193
194 #endif