31
31
#include "modify.h"
33
33
#include "update.h"
35
36
#include "colvarproxy_lammps.h"
38
static const char colvars_pub[] =
39
"fix colvars command:\n\n"
40
"@Article{fiorin13,\n"
41
" author = {G.~Fiorin and M.{\\,}L.~Klein and J.~H{\\'e}nin},\n"
42
" title = {Using collective variables to drive molecular"
43
" dynamics simulations},\n"
44
" journal = {Mol.~Phys.},\n"
46
" note = {doi: 10.1080/00268976.2013.813594}\n"
37
49
/* re-usable integer hash table code with static linkage. */
39
51
/** hash table top level data structure */
322
328
/* parse optional arguments */
323
329
int argsdone = 4;
324
while (argsdone+1 < narg) {
330
while (argsdone < narg) {
331
// we have keyword/value pairs. check if value is missing
332
if (argsdone+1 == narg)
333
error->all(FLERR,"Missing argument to keyword");
325
335
if (0 == strcmp(arg[argsdone], "input")) {
326
336
inp_name = strdup(arg[argsdone+1]);
327
337
} else if (0 == strcmp(arg[argsdone], "output")) {
328
338
out_name = strdup(arg[argsdone+1]);
329
339
} else if (0 == strcmp(arg[argsdone], "seed")) {
330
rng_seed = atoi(arg[argsdone+1]);
340
rng_seed = force->inumeric(FLERR,arg[argsdone+1]);
331
341
} else if (0 == strcmp(arg[argsdone], "unwrap")) {
332
342
if (0 == strcmp(arg[argsdone+1], "yes")) {
413
404
mask |= MIN_POST_FORCE;
414
405
mask |= POST_FORCE;
415
406
mask |= POST_FORCE_RESPA;
417
407
mask |= END_OF_STEP;
421
411
/* ---------------------------------------------------------------------- */
423
// initial setup of colvars run.
413
// initial checks for colvars run.
425
415
void FixColvars::init()
417
if (atom->tag_enable == 0)
418
error->all(FLERR,"Cannot use fix colvars without atom IDs");
420
if (atom->map_style == 0)
421
error->all(FLERR,"Fix colvars requires an atom map");
423
if ((me == 0) && (update->whichflag == 2))
424
error->warning(FLERR,"Using fix colvars with minimization");
427
426
if (strstr(update->integrate_style,"respa"))
428
427
nlevels_respa = ((Respa *) update->integrate)->nlevels;
436
// collect a list of atom type by atom id for the entire system.
437
// the colvar module requires this information to set masses. :-(
439
int *typemap,*type_buf;
440
int nlocal_max,tag_max,max;
441
const int * const tag = atom->tag;
442
const int * const type = atom->type;
443
int nlocal = atom->nlocal;
446
for (i = 0; i < nlocal; i++) max = MAX(max,tag[i]);
447
MPI_Allreduce(&max,&tag_max,1,MPI_INT,MPI_MAX,world);
448
MPI_Allreduce(&nlocal,&nlocal_max,1,MPI_INT,MPI_MAX,world);
451
typemap = new int[tag_max+1];
452
memset(typemap,0,sizeof(int)*tag_max);
454
type_buf = new int[2*nlocal_max];
457
for (i=0; i<nlocal; ++i)
458
typemap[tag[i]] = type[i];
460
// loop over procs to receive and apply remote data
462
for (i=1; i < comm->nprocs; ++i) {
463
MPI_Irecv(type_buf, 2*nlocal_max, MPI_INT, i, 0, world, &request);
464
MPI_Send(&tmp, 0, MPI_INT, i, 0, world);
465
MPI_Wait(&request, &status);
466
MPI_Get_count(&status, MPI_INT, &ndata);
468
for (int k=0; k<ndata; k+=2)
469
typemap[type_buf[k]] = type_buf[k+1];
473
// copy tag/type data into communication buffer
476
for (i=0; i<nlocal; ++i) {
477
type_buf[nme] = tag[i];
478
type_buf[nme+1] = type[i];
481
/* blocking receive to wait until it is our turn to send data. */
482
MPI_Recv(&tmp, 0, MPI_INT, 0, 0, world, &status);
483
MPI_Rsend(type_buf, nme, MPI_INT, 0, 0, world);
486
// now create and initialize the colvar proxy
431
/* ---------------------------------------------------------------------- */
433
void FixColvars::one_time_init()
437
if (init_flag) return;
440
// create and initialize the colvars proxy
443
if (screen) fputs("colvars: Creating proxy instance\n",screen);
444
if (logfile) fputs("colvars: Creating proxy instance\n",logfile);
491
447
if (strcmp(inp_name,"NULL") == 0) {
509
proxy = new colvarproxy_lammps(lmp,conf_file,inp_name,out_name,
510
rng_seed,t_target,typemap);
466
proxy = new colvarproxy_lammps(lmp,inp_name,out_name,rng_seed,t_target);
467
proxy->init(conf_file);
511
468
coords = proxy->get_coords();
512
469
forces = proxy->get_forces();
513
470
oforce = proxy->get_oforce();
643
627
MPI_Rsend(comm_buf, nme*size_one, MPI_BYTE, 0, 0, world);
646
// clear temporary storage
647
if (me == 0) delete typemap;
651
/* ---------------------------------------------------------------------- */
653
void FixColvars::setup(int vflag)
655
if (strstr(update->integrate_style,"verlet"))
630
// run pre-run setup in colvarproxy
635
if (strstr(update->integrate_style,"verlet") || (update->whichflag == 2))
656
636
post_force(vflag);
658
post_force_respa(vflag,0,0);
638
((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1);
639
post_force_respa(vflag,nlevels_respa-1,0);
640
((Respa *) update->integrate)->copy_f_flevel(nlevels_respa-1);
661
644
/* ---------------------------------------------------------------------- */
923
906
/* ---------------------------------------------------------------------- */
908
void FixColvars::write_restart(FILE *fp)
911
std::string rest_text("");
912
proxy->serialize_status(rest_text);
913
const char *cvm_state = rest_text.c_str();
914
int len = strlen(cvm_state) + 1; // need to include terminating NULL byte.
915
fwrite(&len,sizeof(int),1,fp);
916
fwrite(cvm_state,1,len,fp);
920
/* ---------------------------------------------------------------------- */
922
void FixColvars::restart(char *buf)
927
std::string rest_text(buf);
928
proxy->deserialize_status(rest_text);
932
/* ---------------------------------------------------------------------- */
925
934
double FixColvars::compute_scalar()