4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Copyright (c) 1991-2001, University of Groningen, The Netherlands
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * If you want to redistribute modifications, please consider that
18 * scientific software is very special. Version control is crucial -
19 * bugs must be traceable. We will be happy to consider code for
20 * inclusion in the official distribution, but derived work must not
21 * be called official GROMACS. Details are found in the README & COPYING
22 * files - if they are missing, get the official version at www.gromacs.org.
24 * To help us fund GROMACS development, we humbly ask that you cite
25 * the papers on the package - you can find them in the top README file.
27 * For more info, check our website at http://www.gromacs.org
30 * Gromacs Runs One Microsecond At Cannonball Speeds
45 static t_correct
*recv_init(FILE *fp
,
46 t_commrec
*cr
,int *seed
,int *natom
,int *nres
,
47 rvec
**xref
,rvec
**xcenter
,bool *bKeep
)
51 gmx_rxs(0,seed
,sizeof(*seed
));
52 gmx_rxs(0,natom
,sizeof(*natom
));
53 gmx_rxs(0,nres
,sizeof(*nres
));
54 gmx_rxs(0,bKeep
,sizeof(*bKeep
));
57 #define cget(nn) gmx_rxs(0,record(c->nn))
78 gmx_rxs(0,*xref
,*natom
*sizeof(**xref
));
80 snew(*xcenter
,*natom
);
81 gmx_rxs(0,*xcenter
,*natom
*sizeof(**xcenter
));
84 /* Get the important input data */
86 gmx_rxs(0,array(c
->d
,c
->ndist
));
88 snew(c
->pepbond
,c
->npep
);
89 gmx_rxs(0,array(c
->pepbond
,c
->npep
));
91 snew(c
->imp
,c
->nimp
+1);
92 gmx_rxs(0,array(c
->imp
,c
->nimp
+1));
94 snew(c
->weight
,*natom
);
95 gmx_rxs(0,array(c
->weight
,*natom
));
97 /* Other arrays can be deduced from these */
98 fprintf(fp
,"Succesfully got input data\n");
104 static void send_init(FILE *fp
,
105 t_commrec
*cr
,t_correct
*c
,int *seed
,int natom
,int nres
,
106 rvec
*xref
,rvec
*xcenter
,bool bKeep
)
110 for(nodeid
=1; (nodeid
< cr
->nnodes
); nodeid
++) {
111 gmx_txs(nodeid
,seed
,sizeof(*seed
));
112 /* Update random seed */
114 gmx_txs(nodeid
,record(natom
));
115 gmx_txs(nodeid
,record(nres
));
116 gmx_txs(nodeid
,record(bKeep
));
118 #define cput(nn) gmx_txs(nodeid,record(c->nn))
138 gmx_txs(nodeid
,array(xref
,natom
));
141 gmx_txs(nodeid
,array(xcenter
,natom
));
143 /* Send the important input data */
144 gmx_txs(nodeid
,array(c
->d
,c
->ndist
));
146 gmx_txs(nodeid
,array(c
->pepbond
,c
->npep
));
148 gmx_txs(nodeid
,array(c
->imp
,c
->nimp
+1));
150 gmx_txs(nodeid
,array(c
->weight
,natom
));
152 /* Other arrays can be deduced from these */
153 fprintf(fp
,"Succesfully sent input data to nodeid %d\n",nodeid
);
158 static bool send_coords(t_commrec
*cr
,int nviol
,int nit
,int k
,
159 int natom
,rvec x
[],matrix box
,bool bKeep
)
164 gmx_tx(0,record(cr
->nodeid
));
167 gmx_rxs(0,record(bDone
));
170 gmx_txs(0,record(nviol
));
171 gmx_txs(0,record(nit
));
172 gmx_txs(0,record(k
));
173 if (bKeep
|| (nviol
== 0)) {
174 gmx_txs(0,record(natom
));
175 gmx_txs(0,array(x
,natom
));
176 gmx_txs(0,array(box
,DIM
));
184 static int recv_coords(t_commrec
*cr
,int *nviol
,int *nit
,int *k
,
185 rvec x
[],matrix box
,bool bKeep
,bool bDone
)
189 /* Check whether there is something from anyone */
192 gmx_rx(MPI_ANY_SOURCE
,record(nodeid
));
195 } while (!mpiio_rx_probe(MPI_ANY_SOURCE
));
199 if ((nodeid
>= cr
->nnodes
) || (nodeid
<= 0))
200 fatal_error(0,"Reading data from nodeid %d",nodeid
);
202 gmx_txs(nodeid
,record(bDone
));
205 gmx_rxs(nodeid
,record(*nviol
));
206 gmx_rxs(nodeid
,record(*nit
));
207 gmx_rxs(nodeid
,record(*k
));
208 if (bKeep
|| (*nviol
== 0)) {
209 gmx_rxs(nodeid
,record(natom
));
210 gmx_rxs(nodeid
,array(x
,natom
));
211 gmx_rxs(nodeid
,array(box
,DIM
));
217 void disco_slave(t_commrec
*cr
,FILE *fp
)
220 int seed
,nit
,natom
,nres
,k
,nviol
;
224 rvec
*x
,*xref
,*xcenter
;
227 c
= recv_init(fp
,cr
,&seed
,&natom
,&nres
,&xref
,&xcenter
,&bKeep
);
236 fprintf(fp
,"Random seed = %d\n",seed
);
240 for(k
=0; (!bDone
); k
++) {
241 /* Generate random box*/
243 rand_box(c
->bBox
,box
,boxsize
,nres
,c
->bCubic
,&seed
);
245 /* Generate random coords */
247 rand_coords(natom
,x
,xref
,c
->weight
,c
->bCenter
,xcenter
,boxsize
,&seed
);
249 /* Now correct the random coords */
251 nviol
= shake_coords(fp
,FALSE
,k
,natom
,xref
,x
,&seed
,box
,c
,&nit
);
254 bDone
= send_coords(cr
,nviol
,nit
,k
,natom
,x
,box
,bKeep
);
258 void disco_master(t_commrec
*cr
,FILE *fp
,char *outfn
,char *keepfn
,t_correct
*c
,
259 bool bVerbose
,t_atoms
*atoms
,
260 rvec xref
[],rvec xcenter
[],
261 int nstruct
,int *seed
,
262 bool bFit
,int nfit
,atom_id fit_ind
[],
263 bool bPrintViol
,char *violfn
,rvec boxsize
)
267 int i
,k
,kk
,nconv
,ntry
,status
,kstatus
,natom
,nres
,nit
;
268 int nvtest
,nodeid
,knodeid
,nviol
;
279 /* Send out the word to my disciples */
281 send_init(fp
,cr
,c
,seed
,natom
,nres
,xref
,xcenter
,(keepfn
!= NULL
));
288 wrbox
[XX
][XX
] = wrbox
[YY
][YY
] = wrbox
[ZZ
][ZZ
] = nres
;
289 status
= open_trx(outfn
,"w");
291 kstatus
= open_trx(keepfn
,"w");
296 for(k
=0; (k
<natom
); k
++)
299 for(k
=0; (k
<nfit
); k
++)
300 w_rls
[fit_ind
[k
]] = 1;
302 snew(nconvdist
,c
->maxnit
+1);
307 for(k
=0; (k
<nstruct
); ) {
308 nodeid
= recv_coords(cr
,&nviol
,&nit
,&knodeid
,x
,box
,
309 (keepfn
!= NULL
),FALSE
);
310 bConverged
= (nviol
== 0);
317 /*nvtest = quick_check(bVerbose ? fp : NULL,natom,x,box,c);*/
319 fprintf(stderr
,"%8s%6s%6s%8s%6s\n",
320 "Struct","CPU","Str","nviol","niter");
321 fprintf(stderr
,"%8d%6d%6d%8d%6d\n",k
,nodeid
,knodeid
,nviol
,nit
);
323 if (bConverged
|| keepfn
) {
324 center_in_box(natom
,x
,wrbox
,x
);
326 do_fit(natom
,w_rls
,xref
,x
);
327 write_trx(bConverged
? status
: kstatus
,
328 natom
,wr_ind
,atoms
,k
,(real
) k
,wrbox
,x
,NULL
);
335 if (bPrintViol
&& 0) {
336 /* Print structure coloured by the violations */
338 snew(atoms
->pdbinfo
,natom
);
339 for(kk
=0; (kk
<natom
); kk
++)
340 atoms
->pdbinfo
[kk
].bfac
= (real
) c
->bViol
[kk
];
341 gp
=ffopen(violfn
,"w");
342 write_pdbfile(gp
,"Structure coloured by violation",atoms
,x
,box
,0,-1);
346 for(k
=1; (k
<cr
->nnodes
); k
++)
347 nodeid
= recv_coords(cr
,&nviol
,&nit
,&knodeid
,x
,box
,(keepfn
!= NULL
),TRUE
);
352 gp
= xvgropen("conv_stat.xvg","Iterations per converged structure",
354 for(i
=0; (i
<c
->maxnit
); i
++)
355 fprintf(gp
,"%10d %10d\n",i
,nconvdist
[i
]);
362 pr_conv_stat(fp
,ntry
,nconv
,tnit
);
363 pr_conv_stat(stderr
,ntry
,nconv
,tnit
);