4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
27 * GRowing Old MAkes el Chrono Sweat
29 static char *SRCID_g_dist_c
= "$Id$";
47 int main(int argc
,char *argv
[])
49 static char *desc
[] = {
50 "g_dist can calculate the distance between the centers of mass of two",
51 "groups of atoms as a function of time.[PAR]",
52 "Or when [TT]-dist[tt] is set, print all the atoms in group 2 that are",
53 "closer than a certain distance to the center of mass of group 1."
58 rvec
*x
=NULL
,*v
=NULL
,dx
;
63 int g
,d
,i
,j
,res
,teller
=0;
66 int ngrps
; /* the number of index groups */
67 atom_id
**index
,max
; /* the index for the atom numbers */
68 int *isize
; /* the size of each group */
69 char **grpname
; /* the name of each group */
77 static t_pargs pa
[] = {
78 { "-dist", FALSE
, etREAL
, {&cut
},
79 "Print all atoms in group 2 closer than dist to the center of mass of group 1" },
84 { efTRX
, "-f", NULL
, ffREAD
},
85 { efTPX
, NULL
, NULL
, ffREAD
},
86 { efNDX
, NULL
, NULL
, ffOPTRD
},
87 { efXVG
, NULL
, "dist", ffOPTWR
},
89 #define NFILE asize(fnm)
92 CopyRight(stdout
,argv
[0]);
94 parse_common_args(&argc
,argv
,PCA_CAN_TIME
,TRUE
,
95 NFILE
,fnm
,NPA
,pa
,asize(desc
),desc
,0,NULL
);
97 bCutoff
=opt2parg_bSet("-dist",NPA
,pa
);
100 top
=read_top(ftp2fn(efTPX
,NFILE
,fnm
));
102 /* read index files */
108 get_index(&top
->atoms
,ftp2fn(efNDX
,NFILE
,fnm
),ngrps
,isize
,index
,grpname
);
113 for(g
=0;(g
<ngrps
);g
++) {
115 for(i
=0;(i
<isize
[g
]);i
++) {
118 if (index
[g
][i
] >= top
->atoms
.nr
)
119 fatal_error(0,"Atom number %d, item %d of group %d, is larger than number of atoms in the topolgy (%d)\n",index
[g
][i
]+1,i
+1,g
+1,top
->atoms
.nr
+1);
120 mass
[g
]+=top
->atoms
.atom
[index
[g
][i
]].m
;
124 natoms
=read_first_x(&status
,ftp2fn(efTRX
,NFILE
,fnm
),&t
,&x
,box
);
127 fatal_error(0,"Atom number %d in an index group is larger than number of atoms in the trajectory (%d)\n",(int)max
+1,natoms
);
130 /* open output file */
131 fp
= xvgropen(ftp2fn(efXVG
,NFILE
,fnm
),
132 "Distance","Time (ps)","Distance (nm)");
137 /* initialisation for correct distance calculations */
139 /* make molecules whole again */
140 rm_pbc(&top
->idef
,natoms
,box
,x
,x
);
142 /* calculate center of masses */
143 for(g
=0;(g
<ngrps
);g
++) {
144 for(d
=0;(d
<DIM
);d
++) {
146 for(i
=0;(i
<isize
[g
]);i
++) {
147 com
[g
][d
] += x
[index
[g
][i
]][d
] * top
->atoms
.atom
[index
[g
][i
]].m
;
149 com
[g
][d
] /= mass
[g
];
154 /* write to output */
155 fprintf(fp
,"%8.3f ",t
);
156 for(g
=0;(g
<ngrps
/2);g
++) {
157 pbc_dx(com
[2*g
],com
[2*g
+1],dx
);
158 fprintf(fp
,"%10.5f %10.5f %10.5f %10.5f",
159 norm(dx
),dx
[XX
],dx
[YY
],dx
[ZZ
]);
163 for(i
=0;(i
<isize
[1]);i
++) {
165 pbc_dx(x
[j
],com
[0],dx
);
168 res
=top
->atoms
.atom
[j
].resnr
;
169 fprintf(stdout
,"\rt: %g %d %s %d %s %g (nm)\n",
170 t
,res
+1,*top
->atoms
.resname
[res
],
171 j
+1,*top
->atoms
.atomname
[j
],sqrt(dist2
));
177 } while (read_next_x(status
,&t
,natoms
,x
,box
));