4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
34 * Green Red Orange Magenta Azure Cyan Skyblue
42 void replace_atom(t_topology
*top
,int inr
,char *anm
,char *resnm
,
43 real q
,real m
,int type
)
47 atoms
= &(top
->atoms
);
49 /* Replace important properties of an atom by other properties */
50 if ((inr
< 0) || (inr
> atoms
->nr
))
51 fatal_error(0,"Replace_atom: inr (%d) not in %d .. %d",inr
,0,atoms
->nr
);
53 fprintf(debug
,"Replacing atom %d ... ",inr
);
54 /* Charge, mass and type */
55 atoms
->atom
[inr
].q
= atoms
->atom
[inr
].qB
= q
;
56 atoms
->atom
[inr
].m
= atoms
->atom
[inr
].mB
= m
;
57 atoms
->atom
[inr
].type
= atoms
->atom
[inr
].typeB
= type
;
60 atoms
->resname
[atoms
->atom
[inr
].resnr
] = put_symtab(&top
->symtab
,resnm
);
62 atoms
->atomname
[inr
] = put_symtab(&top
->symtab
,anm
);
64 fprintf(debug
," done\n");
67 static void delete_from_interactions(t_idef
*idef
,int inr
)
73 /* Delete interactions including atom inr from lists */
74 for(i
=0; (i
<F_NRE
); i
++) {
75 nra
= interaction_function
[i
].nratoms
;
77 snew(niatoms
,idef
->il
[i
].nr
);
78 for(j
=0; (j
<idef
->il
[i
].nr
); j
+=nra
+1) {
80 for(k
=0; (k
<nra
); k
++)
81 if (idef
->il
[i
].iatoms
[j
+k
+1] == inr
)
84 /* If this does not need to be deleted, then copy it to temp array */
85 for(k
=0; (k
<nra
+1); k
++)
86 niatoms
[nnr
+k
] = idef
->il
[i
].iatoms
[j
+k
];
90 /* Copy temp array back */
91 for(j
=0; (j
<nnr
); j
++)
92 idef
->il
[i
].iatoms
[j
] = niatoms
[j
];
96 /* Reduce multinr if necessary */
97 for(j
=0; (j
<MAXNODES
); j
++)
98 if (idef
->il
[i
].multinr
[j
] >= nnr
)
99 idef
->il
[i
].multinr
[j
] = nnr
;
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
++) {
112 /* This atom has to go */
113 for(j1
=j
; (j1
<block
->nra
-1); j1
++)
114 block
->a
[j1
] = block
->a
[j1
+1];
116 /* Change indices too */
117 for(i1
=i
+1; (i1
<=block
->nr
); i1
++)
124 static void delete_from_atoms(t_atoms
*atoms
,int inr
)
128 /* Delete inr as an exclusion from other atoms */
129 delete_from_block(&(atoms
->excl
),inr
);
130 /* Now delete the exclusions with inr as i atom */
131 ind0
= atoms
->excl
.index
[inr
];
132 nrei
= atoms
->excl
.index
[inr
+1]-ind0
;
133 for(i
=ind0
+nrei
; (i
<atoms
->excl
.nra
); i
++)
134 atoms
->excl
.a
[i
-nrei
] = atoms
->excl
.a
[i
];
135 atoms
->excl
.nra
-= nrei
;
136 for(i
=inr
; (i
<atoms
->excl
.nr
); i
++)
137 atoms
->excl
.index
[i
] = atoms
->excl
.index
[i
+1] - nrei
;
139 assert(atoms
->excl
.index
[atoms
->excl
.nr
] == atoms
->excl
.nra
);
141 /* Shift the atomnames down */
142 for(i
=inr
; (i
<atoms
->nr
-1); i
++)
143 atoms
->atomname
[i
] = atoms
->atomname
[i
+1];
145 /* Shift the atom struct down */
146 for(i
=inr
; (i
<atoms
->nr
-1); i
++)
147 atoms
->atom
[i
] = atoms
->atom
[i
+1];
149 if (atoms
->pdbinfo
) {
150 /* Shift the pdbatom struct down */
151 for(i
=inr
; (i
<atoms
->nr
-1); i
++)
152 atoms
->pdbinfo
[i
] = atoms
->pdbinfo
[i
+1];
157 void delete_atom(t_topology
*top
,int inr
)
161 if ((inr
< 0) || (inr
>= top
->atoms
.nr
))
162 fatal_error(0,"Delete_atom: inr (%d) not in %d .. %d",inr
,0,
165 fprintf(debug
,"Deleting atom %d ...",inr
);
167 /* First remove bonds etc. */
168 delete_from_interactions(&top
->idef
,inr
);
169 /* Now charge groups etc. */
170 for(k
=0; (k
<ebNR
); k
++)
171 delete_from_block(&(top
->blocks
[k
]),inr
);
172 /* Now from the atoms struct */
173 delete_from_atoms(&top
->atoms
,inr
);
175 fprintf(debug
," done\n");