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