Move symtab.* to topology/
[gromacs.git] / src / gromacs / gmxana / edittop.c
blob824ea489765f5ecac8de2d7b8c61b78042157e1b
1 /*
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 #ifdef HAVE_CONFIG_H
38 #include <config.h>
39 #endif
41 #include "gromacs/legacyheaders/typedefs.h"
42 #include "gromacs/topology/symtab.h"
43 #include "gromacs/utility/smalloc.h"
44 #include "gromacs/utility/fatalerror.h"
46 void replace_atom(t_topology *top, int inr, char *anm, char *resnm,
47 real q, real m, int type)
49 t_atoms *atoms;
51 atoms = &(top->atoms);
53 /* Replace important properties of an atom by other properties */
54 if ((inr < 0) || (inr > atoms->nr))
56 gmx_fatal(FARGS, "Replace_atom: inr (%d) not in %d .. %d", inr, 0, atoms->nr);
58 if (debug)
60 fprintf(debug, "Replacing atom %d ... ", inr);
62 /* Charge, mass and type */
63 atoms->atom[inr].q = atoms->atom[inr].qB = q;
64 atoms->atom[inr].m = atoms->atom[inr].mB = m;
65 atoms->atom[inr].type = atoms->atom[inr].typeB = type;
67 /* Residue name */
68 atoms->resinfo[atoms->atom[inr].resind].name = put_symtab(&top->symtab, resnm);
69 /* Atom name */
70 atoms->atomname[inr] = put_symtab(&top->symtab, anm);
71 if (debug)
73 fprintf(debug, " done\n");
77 static void delete_from_interactions(t_idef *idef, int inr)
79 int i, j, k, nra, nnr;
80 t_iatom *niatoms;
81 gmx_bool bDel;
83 /* Delete interactions including atom inr from lists */
84 for (i = 0; (i < F_NRE); i++)
86 nra = interaction_function[i].nratoms;
87 nnr = 0;
88 snew(niatoms, idef->il[i].nr);
89 for (j = 0; (j < idef->il[i].nr); j += nra+1)
91 bDel = FALSE;
92 for (k = 0; (k < nra); k++)
94 if (idef->il[i].iatoms[j+k+1] == inr)
96 bDel = TRUE;
99 if (!bDel)
101 /* If this does not need to be deleted, then copy it to temp array */
102 for (k = 0; (k < nra+1); k++)
104 niatoms[nnr+k] = idef->il[i].iatoms[j+k];
106 nnr += nra+1;
109 /* Copy temp array back */
110 for (j = 0; (j < nnr); j++)
112 idef->il[i].iatoms[j] = niatoms[j];
114 idef->il[i].nr = nnr;
115 /* cppcheck-suppress uninitvar Fixed in cppcheck 1.65 */
116 sfree(niatoms);
120 static void delete_from_block(t_block *block, int inr)
122 /* Update block data structure */
123 int i, i1, j1, j, k;
125 for (i = 0; (i < block->nr); i++)
127 for (j = block->index[i]; (j < block->index[i+1]); j++)
129 if (j == inr)
131 /* This atom has to go */
132 /* Change indices too */
133 for (i1 = i+1; (i1 <= block->nr); i1++)
135 block->index[i1]--;
142 static void delete_from_blocka(t_blocka *block, int inr)
144 /* Update block data structure */
145 int i, i1, j1, j, k;
147 for (i = 0; (i < block->nr); i++)
149 for (j = block->index[i]; (j < block->index[i+1]); j++)
151 k = block->a[j];
152 if (k == inr)
154 /* This atom has to go */
155 for (j1 = j; (j1 < block->nra-1); j1++)
157 block->a[j1] = block->a[j1+1];
159 block->nra--;
160 /* Change indices too */
161 for (i1 = i+1; (i1 <= block->nr); i1++)
163 block->index[i1]--;
170 static void delete_from_atoms(t_atoms *atoms, int inr)
172 int i;
174 /* Shift the atomnames down */
175 for (i = inr; (i < atoms->nr-1); i++)
177 atoms->atomname[i] = atoms->atomname[i+1];
180 /* Shift the atom struct down */
181 for (i = inr; (i < atoms->nr-1); i++)
183 atoms->atom[i] = atoms->atom[i+1];
186 if (atoms->pdbinfo)
188 /* Shift the pdbatom struct down */
189 for (i = inr; (i < atoms->nr-1); i++)
191 atoms->pdbinfo[i] = atoms->pdbinfo[i+1];
194 atoms->nr--;
197 void delete_atom(t_topology *top, int inr)
199 int k;
201 if ((inr < 0) || (inr >= top->atoms.nr))
203 gmx_fatal(FARGS, "Delete_atom: inr (%d) not in %d .. %d", inr, 0,
204 top->atoms.nr);
206 if (debug)
208 fprintf(debug, "Deleting atom %d ...", inr);
211 /* First remove bonds etc. */
212 delete_from_interactions(&top->idef, inr);
213 /* Now charge groups etc. */
214 delete_from_block(&(top->cgs), inr);
215 delete_from_block(&(top->mols), inr);
216 delete_from_blocka(&(top->excls), inr);
217 /* Now from the atoms struct */
218 delete_from_atoms(&top->atoms, inr);
219 if (debug)
221 fprintf(debug, " done\n");