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) 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.
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.
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.
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.
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.
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.
37 #include "gromacs/topology/atoms.h"
41 #include "gromacs/topology/symtab.h"
42 #include "gromacs/utility/smalloc.h"
44 void init_atom(t_atoms *at)
56 void init_atomtypes(t_atomtypes *at)
61 at->atomnumber = NULL;
66 void done_atom(t_atoms *at)
81 void done_atomtypes(t_atomtypes *atype)
86 sfree(atype->surftens);
87 sfree(atype->atomnumber);
88 sfree(atype->gb_radius);
92 void add_t_atoms(t_atoms *atoms, int natom_extra, int nres_extra)
98 srenew(atoms->atomname, atoms->nr+natom_extra);
99 srenew(atoms->atom, atoms->nr+natom_extra);
100 if (NULL != atoms->pdbinfo)
102 srenew(atoms->pdbinfo, atoms->nr+natom_extra);
104 if (NULL != atoms->atomtype)
106 srenew(atoms->atomtype, atoms->nr+natom_extra);
108 if (NULL != atoms->atomtypeB)
110 srenew(atoms->atomtypeB, atoms->nr+natom_extra);
112 for (i = atoms->nr; (i < atoms->nr+natom_extra); i++)
114 atoms->atomname[i] = NULL;
115 memset(&atoms->atom[i], 0, sizeof(atoms->atom[i]));
116 if (NULL != atoms->pdbinfo)
118 std::memset(&atoms->pdbinfo[i], 0, sizeof(atoms->pdbinfo[i]));
120 if (NULL != atoms->atomtype)
122 atoms->atomtype[i] = NULL;
124 if (NULL != atoms->atomtypeB)
126 atoms->atomtypeB[i] = NULL;
129 atoms->nr += natom_extra;
133 srenew(atoms->resinfo, atoms->nres+nres_extra);
134 for (i = atoms->nres; (i < atoms->nres+nres_extra); i++)
136 std::memset(&atoms->resinfo[i], 0, sizeof(atoms->resinfo[i]));
138 atoms->nres += nres_extra;
142 void init_t_atoms(t_atoms *atoms, int natoms, gmx_bool bPdbinfo)
146 snew(atoms->atomname, natoms);
147 atoms->atomtype = NULL;
148 atoms->atomtypeB = NULL;
149 snew(atoms->resinfo, natoms);
150 snew(atoms->atom, natoms);
153 snew(atoms->pdbinfo, natoms);
157 atoms->pdbinfo = NULL;
161 t_atoms *copy_t_atoms(t_atoms *src)
167 init_t_atoms(dst, src->nr, (NULL != src->pdbinfo));
169 if (NULL != src->atomname)
171 snew(dst->atomname, src->nr);
173 if (NULL != src->atomtype)
175 snew(dst->atomtype, src->nr);
177 if (NULL != src->atomtypeB)
179 snew(dst->atomtypeB, src->nr);
181 for (i = 0; (i < src->nr); i++)
183 dst->atom[i] = src->atom[i];
184 if (NULL != src->pdbinfo)
186 dst->pdbinfo[i] = src->pdbinfo[i];
188 if (NULL != src->atomname)
190 dst->atomname[i] = src->atomname[i];
192 if (NULL != src->atomtype)
194 dst->atomtype[i] = src->atomtype[i];
196 if (NULL != src->atomtypeB)
198 dst->atomtypeB[i] = src->atomtypeB[i];
201 dst->nres = src->nres;
202 for (i = 0; (i < src->nres); i++)
204 dst->resinfo[i] = src->resinfo[i];
209 void t_atoms_set_resinfo(t_atoms *atoms, int atom_ind, t_symtab *symtab,
210 const char *resname, int resnr, unsigned char ic,
211 int chainnum, char chainid)
215 ri = &atoms->resinfo[atoms->atom[atom_ind].resind];
216 ri->name = put_symtab(symtab, resname);
220 ri->chainnum = chainnum;
221 ri->chainid = chainid;
224 void free_t_atoms(t_atoms *atoms, gmx_bool bFreeNames)
228 if (bFreeNames && atoms->atomname != NULL)
230 for (i = 0; i < atoms->nr; i++)
232 if (atoms->atomname[i] != NULL)
234 sfree(*atoms->atomname[i]);
235 *atoms->atomname[i] = NULL;
239 if (bFreeNames && atoms->resinfo != NULL)
241 for (i = 0; i < atoms->nres; i++)
243 if (atoms->resinfo[i].name != NULL)
245 sfree(*atoms->resinfo[i].name);
246 *atoms->resinfo[i].name = NULL;
250 if (bFreeNames && atoms->atomtype != NULL)
252 for (i = 0; i < atoms->nr; i++)
254 if (atoms->atomtype[i] != NULL)
256 sfree(*atoms->atomtype[i]);
257 *atoms->atomtype[i] = NULL;
261 if (bFreeNames && atoms->atomtypeB != NULL)
263 for (i = 0; i < atoms->nr; i++)
265 if (atoms->atomtypeB[i] != NULL)
267 sfree(*atoms->atomtypeB[i]);
268 *atoms->atomtypeB[i] = NULL;
272 sfree(atoms->atomname);
273 sfree(atoms->atomtype);
274 sfree(atoms->atomtypeB);
275 sfree(atoms->resinfo);
277 sfree(atoms->pdbinfo);
280 atoms->atomname = NULL;
281 atoms->atomtype = NULL;
282 atoms->atomtypeB = NULL;
283 atoms->resinfo = NULL;
285 atoms->pdbinfo = NULL;