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 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * 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.
44 #include "gmx_fatal.h"
47 void replace_atom(t_topology *top,int inr,char *anm,char *resnm,
48 real q,real m,int type)
52 atoms = &(top->atoms);
54 /* Replace important properties of an atom by other properties */
55 if ((inr < 0) || (inr > atoms->nr))
56 gmx_fatal(FARGS,"Replace_atom: inr (%d) not in %d .. %d",inr,0,atoms->nr);
58 fprintf(debug,"Replacing atom %d ... ",inr);
59 /* Charge, mass and type */
60 atoms->atom[inr].q = atoms->atom[inr].qB = q;
61 atoms->atom[inr].m = atoms->atom[inr].mB = m;
62 atoms->atom[inr].type = atoms->atom[inr].typeB = type;
65 atoms->resinfo[atoms->atom[inr].resind].name = put_symtab(&top->symtab,resnm);
67 atoms->atomname[inr] = put_symtab(&top->symtab,anm);
69 fprintf(debug," done\n");
72 static void delete_from_interactions(t_idef *idef,int inr)
78 /* Delete interactions including atom inr from lists */
79 for(i=0; (i<F_NRE); i++) {
80 nra = interaction_function[i].nratoms;
82 snew(niatoms,idef->il[i].nr);
83 for(j=0; (j<idef->il[i].nr); j+=nra+1) {
85 for(k=0; (k<nra); k++)
86 if (idef->il[i].iatoms[j+k+1] == inr)
89 /* If this does not need to be deleted, then copy it to temp array */
90 for(k=0; (k<nra+1); k++)
91 niatoms[nnr+k] = idef->il[i].iatoms[j+k];
95 /* Copy temp array back */
96 for(j=0; (j<nnr); j++)
97 idef->il[i].iatoms[j] = niatoms[j];
103 static void delete_from_block(t_block *block,int inr)
105 /* Update block data structure */
108 for(i=0; (i<block->nr); i++) {
109 for(j=block->index[i]; (j<block->index[i+1]); j++) {
111 /* This atom has to go */
112 /* Change indices too */
113 for(i1=i+1; (i1<=block->nr); i1++)
120 static void delete_from_blocka(t_blocka *block,int inr)
122 /* Update block data structure */
125 for(i=0; (i<block->nr); i++) {
126 for(j=block->index[i]; (j<block->index[i+1]); j++) {
129 /* This atom has to go */
130 for(j1=j; (j1<block->nra-1); j1++)
131 block->a[j1] = block->a[j1+1];
133 /* Change indices too */
134 for(i1=i+1; (i1<=block->nr); i1++)
141 static void delete_from_atoms(t_atoms *atoms,int inr)
145 /* Shift the atomnames down */
146 for(i=inr; (i<atoms->nr-1); i++)
147 atoms->atomname[i] = atoms->atomname[i+1];
149 /* Shift the atom struct down */
150 for(i=inr; (i<atoms->nr-1); i++)
151 atoms->atom[i] = atoms->atom[i+1];
153 if (atoms->pdbinfo) {
154 /* Shift the pdbatom struct down */
155 for(i=inr; (i<atoms->nr-1); i++)
156 atoms->pdbinfo[i] = atoms->pdbinfo[i+1];
161 void delete_atom(t_topology *top,int inr)
165 if ((inr < 0) || (inr >= top->atoms.nr))
166 gmx_fatal(FARGS,"Delete_atom: inr (%d) not in %d .. %d",inr,0,
169 fprintf(debug,"Deleting atom %d ...",inr);
171 /* First remove bonds etc. */
172 delete_from_interactions(&top->idef,inr);
173 /* Now charge groups etc. */
174 delete_from_block(&(top->cgs),inr);
175 delete_from_block(&(top->mols),inr);
176 delete_from_blocka(&(top->excls),inr);
177 /* Now from the atoms struct */
178 delete_from_atoms(&top->atoms,inr);
180 fprintf(debug," done\n");