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,2015,2016, 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.
46 #include "gromacs/topology/symtab.h"
47 #include "gromacs/utility/smalloc.h"
48 #include "gromacs/utility/txtdump.h"
50 const char *ptype_str[eptNR+1] = {
51 "Atom", "Nucleus", "Shell", "Bond", "VSite", NULL
54 void init_atom(t_atoms *at)
66 void init_atomtypes(t_atomtypes *at)
71 at->atomnumber = NULL;
76 void done_atom(t_atoms *at)
87 void done_atomtypes(t_atomtypes *atype)
92 sfree(atype->surftens);
93 sfree(atype->atomnumber);
94 sfree(atype->gb_radius);
98 void add_t_atoms(t_atoms *atoms, int natom_extra, int nres_extra)
104 srenew(atoms->atomname, atoms->nr+natom_extra);
105 srenew(atoms->atom, atoms->nr+natom_extra);
106 if (NULL != atoms->pdbinfo)
108 srenew(atoms->pdbinfo, atoms->nr+natom_extra);
110 if (NULL != atoms->atomtype)
112 srenew(atoms->atomtype, atoms->nr+natom_extra);
114 if (NULL != atoms->atomtypeB)
116 srenew(atoms->atomtypeB, atoms->nr+natom_extra);
118 for (i = atoms->nr; (i < atoms->nr+natom_extra); i++)
120 atoms->atomname[i] = NULL;
121 memset(&atoms->atom[i], 0, sizeof(atoms->atom[i]));
122 if (NULL != atoms->pdbinfo)
124 std::memset(&atoms->pdbinfo[i], 0, sizeof(atoms->pdbinfo[i]));
126 if (NULL != atoms->atomtype)
128 atoms->atomtype[i] = NULL;
130 if (NULL != atoms->atomtypeB)
132 atoms->atomtypeB[i] = NULL;
135 atoms->nr += natom_extra;
139 srenew(atoms->resinfo, atoms->nres+nres_extra);
140 for (i = atoms->nres; (i < atoms->nres+nres_extra); i++)
142 std::memset(&atoms->resinfo[i], 0, sizeof(atoms->resinfo[i]));
144 atoms->nres += nres_extra;
148 void init_t_atoms(t_atoms *atoms, int natoms, gmx_bool bPdbinfo)
152 snew(atoms->atomname, natoms);
153 atoms->atomtype = NULL;
154 atoms->atomtypeB = NULL;
155 snew(atoms->resinfo, natoms);
156 snew(atoms->atom, natoms);
159 snew(atoms->pdbinfo, natoms);
163 atoms->pdbinfo = NULL;
167 void gmx_pdbinfo_init_default(t_pdbinfo *pdbinfo)
169 pdbinfo->type = epdbATOM;
171 pdbinfo->altloc = ' ';
172 pdbinfo->atomnm[0] = '\0';
173 pdbinfo->occup = 1.0;
175 pdbinfo->bAnisotropic = FALSE;
176 std::fill(pdbinfo->uij, pdbinfo->uij+6, 0.0);
179 t_atoms *copy_t_atoms(const t_atoms *src)
185 init_t_atoms(dst, src->nr, (NULL != src->pdbinfo));
187 if (NULL != src->atomname)
189 snew(dst->atomname, src->nr);
191 if (NULL != src->atomtype)
193 snew(dst->atomtype, src->nr);
195 if (NULL != src->atomtypeB)
197 snew(dst->atomtypeB, src->nr);
199 for (i = 0; (i < src->nr); i++)
201 dst->atom[i] = src->atom[i];
202 if (NULL != src->pdbinfo)
204 dst->pdbinfo[i] = src->pdbinfo[i];
206 if (NULL != src->atomname)
208 dst->atomname[i] = src->atomname[i];
210 if (NULL != src->atomtype)
212 dst->atomtype[i] = src->atomtype[i];
214 if (NULL != src->atomtypeB)
216 dst->atomtypeB[i] = src->atomtypeB[i];
219 dst->nres = src->nres;
220 for (i = 0; (i < src->nres); i++)
222 dst->resinfo[i] = src->resinfo[i];
227 void t_atoms_set_resinfo(t_atoms *atoms, int atom_ind, t_symtab *symtab,
228 const char *resname, int resnr, unsigned char ic,
229 int chainnum, char chainid)
233 ri = &atoms->resinfo[atoms->atom[atom_ind].resind];
234 ri->name = put_symtab(symtab, resname);
238 ri->chainnum = chainnum;
239 ri->chainid = chainid;
242 static void pr_atom(FILE *fp, int indent, const char *title, const t_atom *atom, int n)
246 if (available(fp, atom, indent, title))
248 indent = pr_title_n(fp, indent, title, n);
249 for (i = 0; i < n; i++)
251 pr_indent(fp, indent);
252 fprintf(fp, "%s[%6d]={type=%3hu, typeB=%3hu, ptype=%8s, m=%12.5e, "
253 "q=%12.5e, mB=%12.5e, qB=%12.5e, resind=%5d, atomnumber=%3d}\n",
254 title, i, atom[i].type, atom[i].typeB, ptype_str[atom[i].ptype],
255 atom[i].m, atom[i].q, atom[i].mB, atom[i].qB,
256 atom[i].resind, atom[i].atomnumber);
261 static void pr_strings2(FILE *fp, int indent, const char *title,
262 char ***nm, char ***nmB, int n, gmx_bool bShowNumbers)
266 if (available(fp, nm, indent, title))
268 indent = pr_title_n(fp, indent, title, n);
269 for (i = 0; i < n; i++)
271 pr_indent(fp, indent);
272 fprintf(fp, "%s[%d]={name=\"%s\",nameB=\"%s\"}\n",
273 title, bShowNumbers ? i : -1, *(nm[i]), *(nmB[i]));
278 static void pr_resinfo(FILE *fp, int indent, const char *title, const t_resinfo *resinfo, int n,
279 gmx_bool bShowNumbers)
283 if (available(fp, resinfo, indent, title))
285 indent = pr_title_n(fp, indent, title, n);
286 for (i = 0; i < n; i++)
288 pr_indent(fp, indent);
289 fprintf(fp, "%s[%d]={name=\"%s\", nr=%d, ic='%c'}\n",
290 title, bShowNumbers ? i : -1,
291 *(resinfo[i].name), resinfo[i].nr,
292 (resinfo[i].ic == '\0') ? ' ' : resinfo[i].ic);
297 void pr_atoms(FILE *fp, int indent, const char *title, const t_atoms *atoms,
298 gmx_bool bShownumbers)
300 if (available(fp, atoms, indent, title))
302 indent = pr_title(fp, indent, title);
303 pr_atom(fp, indent, "atom", atoms->atom, atoms->nr);
304 pr_strings(fp, indent, "atom", atoms->atomname, atoms->nr, bShownumbers);
305 pr_strings2(fp, indent, "type", atoms->atomtype, atoms->atomtypeB, atoms->nr, bShownumbers);
306 pr_resinfo(fp, indent, "residue", atoms->resinfo, atoms->nres, bShownumbers);
311 void pr_atomtypes(FILE *fp, int indent, const char *title, const t_atomtypes *atomtypes,
312 gmx_bool bShowNumbers)
315 if (available(fp, atomtypes, indent, title))
317 indent = pr_title(fp, indent, title);
318 for (i = 0; i < atomtypes->nr; i++)
320 pr_indent(fp, indent);
322 "atomtype[%3d]={radius=%12.5e, volume=%12.5e, gb_radius=%12.5e, surftens=%12.5e, atomnumber=%4d, S_hct=%12.5e)}\n",
323 bShowNumbers ? i : -1, atomtypes->radius[i], atomtypes->vol[i],
324 atomtypes->gb_radius[i],
325 atomtypes->surftens[i], atomtypes->atomnumber[i], atomtypes->S_hct[i]);