2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2012,2014,2015,2017,2018 by the GROMACS development team.
7 * Copyright (c) 2019,2020, by the GROMACS development team, led by
8 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
9 * and including many others, as listed in the AUTHORS file in the
10 * top-level source directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
38 /* This file is completely threadsafe - keep it that way! */
48 #include "gromacs/topology/atoms.h"
49 #include "gromacs/utility/cstringutil.h"
50 #include "gromacs/utility/fatalerror.h"
51 #include "gromacs/utility/snprintf.h"
54 static void atom_not_found(int fatal_errno
,
63 char message_buffer
[BUFSIZE
];
64 if (strcmp(bondtype
, "check") != 0)
66 if (0 != strcmp(bondtype
, "atom"))
68 snprintf(message_buffer
, 1024,
69 "Residue %d named %s of a molecule in the input file was mapped\n"
70 "to an entry in the topology database, but the atom %s used in\n"
71 "an interaction of type %s in that entry is not found in the\n"
72 "input file. Perhaps your atom and/or residue naming needs to be\n"
74 resind
+ 1, resname
, atomname
, bondtype
);
78 snprintf(message_buffer
, 1024,
79 "Residue %d named %s of a molecule in the input file was mapped\n"
80 "to an entry in the topology database, but the atom %s used in\n"
81 "that entry is not found in the input file. Perhaps your atom\n"
82 "and/or residue naming needs to be fixed.\n",
83 resind
+ 1, resname
, atomname
);
87 gmx_warning("WARNING: %s", message_buffer
);
91 gmx_fatal(fatal_errno
, file
, line
, "%s", message_buffer
);
96 int search_atom(const char* type
,
101 gmx::ArrayRef
<const int> cyclicBondsIndex
)
104 bool bPrevious
, bNext
, bOverring
;
105 int natoms
= atoms
->nr
;
106 t_atom
* at
= atoms
->atom
;
107 char** const* anm
= atoms
->atomname
;
108 gmx::ArrayRef
<const int>::iterator cyclicBondsIterator
;
110 bPrevious
= (strchr(type
, '-') != nullptr);
111 bNext
= (strchr(type
, '+') != nullptr);
115 resind
= at
[start
].resind
;
118 /* The next residue */
120 bOverring
= !cyclicBondsIndex
.empty()
121 && (cyclicBondsIterator
=
122 std::find(cyclicBondsIndex
.begin(), cyclicBondsIndex
.end(), resind
))
123 != cyclicBondsIndex
.end();
124 if (bOverring
&& ((cyclicBondsIterator
- cyclicBondsIndex
.begin()) & 1))
126 resind
= *(--cyclicBondsIterator
);
127 return search_res_atom(type
, resind
, atoms
, bondtype
, false);
131 while ((start
< natoms
) && (at
[start
].resind
== resind
))
137 resind
= at
[start
].resind
;
142 for (i
= start
; (i
< natoms
) && (bNext
|| (at
[i
].resind
== resind
)); i
++)
144 if (anm
[i
] && gmx_strcasecmp(type
, *(anm
[i
])) == 0)
149 if (!(bNext
&& at
[start
].resind
== at
[natoms
- 1].resind
))
151 atom_not_found(FARGS
, type
, at
[start
].resind
, *atoms
->resinfo
[resind
].name
, bondtype
,
157 /* The previous residue */
159 resind
= at
[start
].resind
;
160 bOverring
= !cyclicBondsIndex
.empty()
161 && (cyclicBondsIterator
=
162 std::find(cyclicBondsIndex
.begin(), cyclicBondsIndex
.end(), resind
))
163 != cyclicBondsIndex
.end();
165 if (bOverring
&& !((cyclicBondsIterator
- cyclicBondsIndex
.begin()) & 1))
167 resind
= *(++cyclicBondsIterator
);
168 return search_res_atom(type
, resind
, atoms
, bondtype
, false);
172 while ((start
>= 0) && (at
[start
].resind
== resind
))
178 resind
= at
[start
].resind
;
182 for (i
= start
- 1; (i
>= 0) && (at
[i
].resind
== resind
); i
--)
184 if (gmx_strcasecmp(type
, *(anm
[i
])) == 0)
191 atom_not_found(FARGS
, type
, at
[start
].resind
, *atoms
->resinfo
[resind
].name
, bondtype
,
198 int search_res_atom(const char* type
, int resind
, const t_atoms
* atoms
, const char* bondtype
, bool bAllowMissing
)
202 for (i
= 0; (i
< atoms
->nr
); i
++)
204 if (atoms
->atom
[i
].resind
== resind
)
206 return search_atom(type
, i
, atoms
, bondtype
, bAllowMissing
, gmx::ArrayRef
<const int>());