Fix random typos
[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,2020,2021, 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 /*! \file
38  * \libinternal \brief
39  * Methods to modify atoms during preprocessing.
40  */
41 #ifndef GMX_GMXPREPROCESS_HACKBLOCK_H
42 #define GMX_GMXPREPROCESS_HACKBLOCK_H
43
44 #include <cstdio>
45
46 #include <array>
47 #include <string>
48 #include <vector>
49
50 #include "gromacs/gmxpreprocess/notset.h"
51 #include "gromacs/topology/ifunc.h"
52 #include "gromacs/utility/enumerationhelpers.h"
53
54 struct t_atom;
55 struct t_symtab;
56
57 namespace gmx
58 {
59 template<typename>
60 class ArrayRef;
61 }
62
63 /*! \brief
64  * Used for reading .rtp/.tdb
65  * BondedTypes::Bonds must be the first, new types can be added to the end
66  * these *MUST* correspond to the arrays in hackblock.cpp
67  */
68 enum class BondedTypes : int
69 {
70     Bonds,
71     Angles,
72     ProperDihedrals,
73     ImproperDihedrals,
74     Exclusions,
75     Cmap,
76     Count
77 };
78 //! Names for interaction type entries
79 const char* enumValueToString(BondedTypes enumValue);
80 //! Numbers for atoms in the interactions.
81 int enumValueToNumIAtoms(BondedTypes enumValue);
82
83 /* if changing any of these structs, make sure that all of the
84    free/clear/copy/merge_t_* functions stay updated */
85
86 /*! \libinternal \brief
87  * Information about single bonded interaction.
88  */
89 struct BondedInteraction
90 {
91     //! Atom names in the bond.
92     std::array<std::string, MAXATOMLIST> a;
93     /*! \brief
94      * Optional define string which gets copied from
95      * .rtp/.tdb to .top and will be parsed by cpp
96      * during grompp.
97      */
98     std::string s;
99     //! Has the entry been found?
100     bool match = false;
101     //! Get name of first atom in bonded interaction.
102     const std::string& ai() const { return a[0]; }
103     //! Get name of second atom in bonded interaction..
104     const std::string& aj() const { return a[1]; }
105     //! Get name of third atom in bonded interaction.
106     const std::string& ak() const { return a[2]; }
107     //! Get name of fourth atom in bonded interaction.
108     const std::string& al() const { return a[3]; }
109     //! Get name of fifth atom in bonded interaction.
110     const std::string& am() const { return a[4]; }
111 };
112
113 /*! \libinternal \brief
114  * Accumulation of different bonded types for preprocessing.
115  * \todo This should be merged with BondedInteraction.
116  */
117 struct BondedInteractionList
118 {
119     //! The type of bonded interaction.
120     int type = -1;
121     //! The actual bonded interactions.
122     std::vector<BondedInteraction> b;
123 };
124
125 /*! \libinternal \brief
126  * Information about preprocessing residues.
127  */
128 struct PreprocessResidue
129 {
130     //! Name of the residue.
131     std::string resname;
132     //! The base file name this rtp entry was read from.
133     std::string filebase;
134     //! Atom data.
135     std::vector<t_atom> atom;
136     //! Atom names.
137     std::vector<char**> atomname;
138     //! Charge group numbers.
139     std::vector<int> cgnr;
140     //! Delete autogenerated dihedrals or not.
141     bool bKeepAllGeneratedDihedrals = false;
142     //! Number of bonded exclusions.
143     int nrexcl = -1;
144     //! If Hydrogen only 1-4 interactions should be generated.
145     bool bGenerateHH14Interactions = false;
146     //! Delete dihedrals also defined by impropers.
147     bool bRemoveDihedralIfWithImproper = false;
148     //! List of bonded interactions to potentially add.
149     gmx::EnumerationArray<BondedTypes, BondedInteractionList> rb;
150     //! Get number of atoms in residue.
151     int natom() const { return atom.size(); }
152 };
153
154 //! Declare different types of hacks for later check.
155 enum class MoleculePatchType
156 {
157     //! Hack adds atom to structure/rtp.
158     Add,
159     //! Hack deletes atom.
160     Delete,
161     //! Hack replaces atom.
162     Replace
163 };
164
165 /*! \libinternal \brief
166  * Block to modify individual residues
167  */
168 struct MoleculePatch
169 {
170     //! Number of new are deleted atoms. NOT always equal to atom.size()!
171     int nr;
172     //! Old name for entry.
173     std::string oname;
174     //! New name for entry.
175     std::string nname;
176     //! New atom data.
177     std::vector<t_atom> atom;
178     //! Chargegroup number.
179     int cgnr = NOTSET;
180     //! Type of attachment.
181     int tp = 0;
182     //! Number of control atoms.
183     int nctl = 0;
184     //! Name of control atoms.
185     std::array<std::string, 4> a;
186     //! Is an atom to be hacked already present?
187     bool bAlreadyPresent = false;
188     //! Are coordinates for a new atom already set?
189     bool bXSet = false;
190     //! New position for hacked atom.
191     rvec newx = { NOTSET };
192     //! New atom index number after additions.
193     int newi = -1;
194
195     /*! \brief
196      * Get type of hack.
197      *
198      * This depends on the setting of oname and nname
199      * for legacy reasons. If oname is empty, we are adding,
200      * if oname is set and nname is empty, an atom is deleted,
201      * if both are set replacement is going on. If both are unset,
202      * an error is thrown.
203      */
204     MoleculePatchType type() const;
205
206     //! Control atom i name.
207     const std::string& ai() const { return a[0]; }
208     //! Control atom j name.
209     const std::string& aj() const { return a[1]; }
210     //! Control atom k name.
211     const std::string& ak() const { return a[2]; }
212     //! Control atom l name.
213     const std::string& al() const { return a[3]; }
214 };
215 /*! \libinternal \brief
216  * A set of modifications to apply to atoms.
217  */
218 struct MoleculePatchDatabase
219 {
220     //! Name of block
221     std::string name;
222     //! File that entry was read from.
223     std::string filebase;
224     //! List of changes to atoms.
225     std::vector<MoleculePatch> hack;
226     //! List of bonded interactions to potentially add.
227     gmx::EnumerationArray<BondedTypes, BondedInteractionList> rb;
228     //! Number of atoms to modify
229     int nhack() const { return hack.size(); }
230 };
231
232 /*!\brief
233  * Reset modification block.
234  *
235  * \param[inout] globalPatches Block to reset.
236  * \todo Remove once constructor/destructor takes care of all of this.
237  */
238 void clearModificationBlock(MoleculePatchDatabase* globalPatches);
239
240 /*!\brief
241  * Copy residue information.
242  *
243  * \param[in] s Source information.
244  * \param[in] d Destination to copy to.
245  * \param[inout] symtab Symbol table for names.
246  * \todo Remove once copy can be done directly.
247  */
248 void copyPreprocessResidues(const PreprocessResidue& s, PreprocessResidue* d, t_symtab* symtab);
249
250 /*! \brief
251  * Add bond information in \p s to \p d.
252  *
253  * \param[in] s Source information to copy.
254  * \param[inout] d Destination to copy to.
255  * \param[in] bMin don't copy bondeds with atoms starting with '-'.
256  * \param[in] bPlus don't copy bondeds with atoms starting with '+'.
257  * \returns if bonds were removed at the termini.
258  */
259 bool mergeBondedInteractionList(gmx::ArrayRef<const BondedInteractionList> s,
260                                 gmx::ArrayRef<BondedInteractionList>       d,
261                                 bool                                       bMin,
262                                 bool                                       bPlus);
263
264 /*! \brief
265  * Copy all information from datastructure.
266  *
267  * \param[in] s Source information.
268  * \param[inout] d Destination to copy to.
269  */
270 void copyModificationBlocks(const MoleculePatchDatabase& s, MoleculePatchDatabase* d);
271
272 /*!\brief
273  * Add the individual modifications in \p s to \p d.
274  *
275  * \param[in] s Source information.
276  * \param[inout] d Destination to copy to.
277  */
278 void mergeAtomModifications(const MoleculePatchDatabase& s, MoleculePatchDatabase* d);
279
280 //! \copydoc mergeAtomModifications
281 void mergeAtomAndBondModifications(const MoleculePatchDatabase& s, MoleculePatchDatabase* d);
282
283 #endif