From bda07301693ae242d089a234b9f34a2ff0316fd9 Mon Sep 17 00:00:00 2001 From: Max Veit Date: Mon, 7 Nov 2016 14:59:25 +0000 Subject: [PATCH 1/7] Modified the quip/lammps interface to pass lammps atom ids --- src/USER-QUIP/pair_quip.cpp | 3 ++- src/USER-QUIP/pair_quip.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/USER-QUIP/pair_quip.cpp b/src/USER-QUIP/pair_quip.cpp index e8b23c761f..0ad8066027 100644 --- a/src/USER-QUIP/pair_quip.cpp +++ b/src/USER-QUIP/pair_quip.cpp @@ -66,6 +66,7 @@ void PairQUIP::compute(int eflag, int vflag) int nghost = atom->nghost; int ntotal = nlocal + nghost; int *type = atom->type; + tagint *tag = atom->tag; double **x = atom->x; double **f = atom->f; @@ -124,7 +125,7 @@ void PairQUIP::compute(int eflag, int vflag) lattice[8] = domain->zprd; quip_lammps_wrapper - (&nlocal,&nghost,atomic_numbers, + (&nlocal,&nghost,atomic_numbers,tag, &inum,&sum_num_neigh,ilist, quip_num_neigh,quip_neigh,lattice, quip_potential,&n_quip_potential,&x[0][0], diff --git a/src/USER-QUIP/pair_quip.h b/src/USER-QUIP/pair_quip.h index f86df015ea..985a43fd7e 100644 --- a/src/USER-QUIP/pair_quip.h +++ b/src/USER-QUIP/pair_quip.h @@ -24,7 +24,7 @@ PairStyle(quip,PairQUIP) extern "C" { - void quip_lammps_wrapper(int*, int*, int*, + void quip_lammps_wrapper(int*, int*, int*, int*, int*, int*, int*, int*, int*, double*, int*, int*, double*, From 085cbee1163d6cd6bd787718fb2152f37fd049c0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 18 Jul 2017 11:14:59 -0400 Subject: [PATCH 2/7] protect LAMMPS from calling incompatible QUIP library with -DLAMMPS_BIGBIG --- src/USER-QUIP/pair_quip.cpp | 11 +++++++++++ src/USER-QUIP/pair_quip.h | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/src/USER-QUIP/pair_quip.cpp b/src/USER-QUIP/pair_quip.cpp index 0ad8066027..ccd71235e7 100644 --- a/src/USER-QUIP/pair_quip.cpp +++ b/src/USER-QUIP/pair_quip.cpp @@ -124,12 +124,23 @@ void PairQUIP::compute(int eflag, int vflag) lattice[7] = domain->yz; lattice[8] = domain->zprd; +#if defined(LAMMPS_BIGBIG) + error->all(FLERR,"Pair style quip does not support -DLAMMPS_BIGBIG"); + // quip_lammps_longint_wrapper( + // (&nlocal,&nghost,atomic_numbers,tag, + // &inum,&sum_num_neigh,ilist, + // quip_num_neigh,quip_neigh,lattice, + // quip_potential,&n_quip_potential,&x[0][0], + // &quip_energy,quip_local_e,quip_virial,quip_local_virial,quip_force); +#else quip_lammps_wrapper (&nlocal,&nghost,atomic_numbers,tag, &inum,&sum_num_neigh,ilist, quip_num_neigh,quip_neigh,lattice, quip_potential,&n_quip_potential,&x[0][0], &quip_energy,quip_local_e,quip_virial,quip_local_virial,quip_force); +#endif + iquip = 0; for (ii = 0; ii < ntotal; ii++) { for( jj = 0; jj < 3; jj++ ) { diff --git a/src/USER-QUIP/pair_quip.h b/src/USER-QUIP/pair_quip.h index 985a43fd7e..c785792410 100644 --- a/src/USER-QUIP/pair_quip.h +++ b/src/USER-QUIP/pair_quip.h @@ -29,6 +29,11 @@ extern "C" int*, int*, double*, int*, int*, double*, double*, double*, double*, double*, double*); + // void quip_lammps_longint_wrapper(int*, int*, int*, int64_t*, + // int*, int*, int*, + // int*, int*, double*, + // int*, int*, double*, + // double*, double*, double*, double*, double*); void quip_lammps_potential_initialise(int*, int*, double*, char*, int*, char*, int*); } From 02572a4099a6dfc6dc7ddae2c908446a54a491b3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 18 Jul 2017 14:41:38 -0400 Subject: [PATCH 3/7] add workaround that allows pair style quip to work with -DLAMMPS_BIGBIG, assuming tags are still only 32-bit signed integer --- src/USER-QUIP/pair_quip.cpp | 47 +++++++++++++++++++++++-------------- src/USER-QUIP/pair_quip.h | 5 ---- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/USER-QUIP/pair_quip.cpp b/src/USER-QUIP/pair_quip.cpp index ccd71235e7..fa946641a5 100644 --- a/src/USER-QUIP/pair_quip.cpp +++ b/src/USER-QUIP/pair_quip.cpp @@ -125,26 +125,37 @@ void PairQUIP::compute(int eflag, int vflag) lattice[8] = domain->zprd; #if defined(LAMMPS_BIGBIG) - error->all(FLERR,"Pair style quip does not support -DLAMMPS_BIGBIG"); - // quip_lammps_longint_wrapper( - // (&nlocal,&nghost,atomic_numbers,tag, - // &inum,&sum_num_neigh,ilist, - // quip_num_neigh,quip_neigh,lattice, - // quip_potential,&n_quip_potential,&x[0][0], - // &quip_energy,quip_local_e,quip_virial,quip_local_virial,quip_force); + int *tmptag = new int[ntotal]; + int tmplarge = 0, toolarge = 0; + for (ii = 0; ii < ntotal; ++ii) { + tmptag[ii] = tag[ii]; + if (tag[ii] > MAXSMALLINT) tmplarge=1; + } + MPI_Allreduce(&tmplarge,&toolarge,1,MPI_INT,MPI_MAX,comm); + if (toolarge > 0) + error->all(FLERR,"Pair style quip does not support 64-bit atom IDs"); + + quip_lammps_wrapper(&nlocal,&nghost,atomic_numbers,tmptag, + &inum,&sum_num_neigh,ilist, + quip_num_neigh,quip_neigh,lattice, + quip_potential,&n_quip_potential,&x[0][0], + &quip_energy,quip_local_e,quip_virial, + quip_local_virial,quip_force); + + delete[] tmptag; #else - quip_lammps_wrapper - (&nlocal,&nghost,atomic_numbers,tag, - &inum,&sum_num_neigh,ilist, - quip_num_neigh,quip_neigh,lattice, - quip_potential,&n_quip_potential,&x[0][0], - &quip_energy,quip_local_e,quip_virial,quip_local_virial,quip_force); + quip_lammps_wrapper(&nlocal,&nghost,atomic_numbers,tag, + &inum,&sum_num_neigh,ilist, + quip_num_neigh,quip_neigh,lattice, + quip_potential,&n_quip_potential,&x[0][0], + &quip_energy,quip_local_e,quip_virial, + quip_local_virial,quip_force); #endif iquip = 0; for (ii = 0; ii < ntotal; ii++) { for( jj = 0; jj < 3; jj++ ) { - f[ii][jj] = quip_force[iquip]; + f[ii][jj] += quip_force[iquip]; iquip++; } } @@ -175,11 +186,11 @@ void PairQUIP::compute(int eflag, int vflag) vatom[ii][1] += quip_local_virial[iatom+4]; vatom[ii][2] += quip_local_virial[iatom+8]; vatom[ii][3] += (quip_local_virial[iatom+3] + - quip_local_virial[iatom+1])*0.5; + quip_local_virial[iatom+1])*0.5; vatom[ii][4] += (quip_local_virial[iatom+2] + - quip_local_virial[iatom+6])*0.5; + quip_local_virial[iatom+6])*0.5; vatom[ii][5] += (quip_local_virial[iatom+5] + - quip_local_virial[iatom+7])*0.5; + quip_local_virial[iatom+7])*0.5; iatom += 9; } } @@ -202,6 +213,8 @@ void PairQUIP::compute(int eflag, int vflag) void PairQUIP::settings(int narg, char **arg) { if (narg != 0) error->all(FLERR,"Illegal pair_style command"); + if (strncmp(force->pair->style,"hybrid",6) == 0) + error->all(FLERR,"Pair style quip is not compatible with hybrid styles"); } /* ---------------------------------------------------------------------- diff --git a/src/USER-QUIP/pair_quip.h b/src/USER-QUIP/pair_quip.h index c785792410..985a43fd7e 100644 --- a/src/USER-QUIP/pair_quip.h +++ b/src/USER-QUIP/pair_quip.h @@ -29,11 +29,6 @@ extern "C" int*, int*, double*, int*, int*, double*, double*, double*, double*, double*, double*); - // void quip_lammps_longint_wrapper(int*, int*, int*, int64_t*, - // int*, int*, int*, - // int*, int*, double*, - // int*, int*, double*, - // double*, double*, double*, double*, double*); void quip_lammps_potential_initialise(int*, int*, double*, char*, int*, char*, int*); } From f96b9e0dcf555319b94e4397f103cf197cd4c988 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 18 Jul 2017 15:48:18 -0400 Subject: [PATCH 4/7] add various checks and improvements to identify incompatible uses and warn or exit with error message --- src/USER-QUIP/pair_quip.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/USER-QUIP/pair_quip.cpp b/src/USER-QUIP/pair_quip.cpp index fa946641a5..7e178c7a64 100644 --- a/src/USER-QUIP/pair_quip.cpp +++ b/src/USER-QUIP/pair_quip.cpp @@ -42,6 +42,7 @@ PairQUIP::PairQUIP(LAMMPS *lmp) : Pair(lmp) single_enable = 0; one_coeff = 1; no_virial_fdotr_compute = 1; + manybody_flag = 1; } PairQUIP::~PairQUIP() @@ -99,7 +100,7 @@ void PairQUIP::compute(int eflag, int vflag) jnum = numneigh[i]; for (jj = 0; jj < jnum; jj++) { - quip_neigh[iquip] = jlist[jj]+1; + quip_neigh[iquip] = (jlist[jj] & NEIGHMASK) + 1; iquip++; } } @@ -131,7 +132,7 @@ void PairQUIP::compute(int eflag, int vflag) tmptag[ii] = tag[ii]; if (tag[ii] > MAXSMALLINT) tmplarge=1; } - MPI_Allreduce(&tmplarge,&toolarge,1,MPI_INT,MPI_MAX,comm); + MPI_Allreduce(&tmplarge,&toolarge,1,MPI_INT,MPI_MAX,world); if (toolarge > 0) error->all(FLERR,"Pair style quip does not support 64-bit atom IDs"); @@ -213,7 +214,7 @@ void PairQUIP::compute(int eflag, int vflag) void PairQUIP::settings(int narg, char **arg) { if (narg != 0) error->all(FLERR,"Illegal pair_style command"); - if (strncmp(force->pair->style,"hybrid",6) == 0) + if (strncmp(force->pair_style,"hybrid",6) == 0) error->all(FLERR,"Pair style quip is not compatible with hybrid styles"); } From 17aff29fe2e70bbb68d44b0b92ecb105124bdd86 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 18 Jul 2017 15:48:31 -0400 Subject: [PATCH 5/7] fix off-by-one bug when copying strings --- src/USER-QUIP/pair_quip.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/USER-QUIP/pair_quip.cpp b/src/USER-QUIP/pair_quip.cpp index 7e178c7a64..c6ab8b259b 100644 --- a/src/USER-QUIP/pair_quip.cpp +++ b/src/USER-QUIP/pair_quip.cpp @@ -255,11 +255,11 @@ void PairQUIP::coeff(int narg, char **arg) error->all(FLERR,"Incorrect args for pair coefficients"); n_quip_file = strlen(arg[2]); - quip_file = new char[n_quip_file]; + quip_file = new char[n_quip_file+1]; strcpy(quip_file,arg[2]); n_quip_string = strlen(arg[3]); - quip_string = new char[n_quip_string]; + quip_string = new char[n_quip_string+1]; strcpy(quip_string,arg[3]); for (int i = 4; i < narg; i++) { From fcf9607a666616f53cd2d03445e76fb619dae85c Mon Sep 17 00:00:00 2001 From: Max Veit Date: Wed, 19 Jul 2017 17:47:21 +0100 Subject: [PATCH 6/7] Update USER_QUIP docs to clarify use of "special_bonds" --- doc/src/pair_quip.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/src/pair_quip.txt b/doc/src/pair_quip.txt index 12dcd244e2..fbc87d61ac 100644 --- a/doc/src/pair_quip.txt +++ b/doc/src/pair_quip.txt @@ -80,6 +80,14 @@ LAMMPS"_Section_start.html#start_3 section for more info. QUIP potentials are parametrized in electron-volts and Angstroms and therefore should be used with LAMMPS metal "units"_units.html. +QUIP potentials are generally not designed to work with the scaling +factors set by the "special_bonds"_special_bonds.html command. The +recommended setting in molecular systems is to include all +interactions, i.e. to use {special_bonds lj 1.0 1.0 1.0}. The only +exception to this rule is if you know that your QUIP potential needs +to exclude bonded, 1-3, or 1-4 interactions and does not already do +this exclusion within QUIP. + [Related commands:] "pair_coeff"_pair_coeff.html From 52a1c54d500e8255eab06290beaaf99ed225f9ca Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 19 Jul 2017 13:17:35 -0400 Subject: [PATCH 7/7] support QUIP wrapper API version query, relax hybrid restriction to allow hybrid/overlay, update docs --- doc/src/pair_quip.txt | 16 ++++++++++++---- src/USER-QUIP/pair_quip.cpp | 10 ++++++++-- src/USER-QUIP/pair_quip.h | 5 +++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/doc/src/pair_quip.txt b/doc/src/pair_quip.txt index fbc87d61ac..9436b0c4ed 100644 --- a/doc/src/pair_quip.txt +++ b/doc/src/pair_quip.txt @@ -83,10 +83,18 @@ therefore should be used with LAMMPS metal "units"_units.html. QUIP potentials are generally not designed to work with the scaling factors set by the "special_bonds"_special_bonds.html command. The recommended setting in molecular systems is to include all -interactions, i.e. to use {special_bonds lj 1.0 1.0 1.0}. The only -exception to this rule is if you know that your QUIP potential needs -to exclude bonded, 1-3, or 1-4 interactions and does not already do -this exclusion within QUIP. +interactions, i.e. to use {special_bonds lj/coul 1.0 1.0 1.0}. Scaling +factors > 0.0 will be ignored and treated as 1.0. The only exception +to this rule is if you know that your QUIP potential needs to exclude +bonded, 1-3, or 1-4 interactions and does not already do this exclusion +within QUIP. Then a factor 0.0 needs to be used which will remove such +pairs from the neighbor list. This needs to be very carefully tested, +because it may remove pairs from the neighbor list that are still +required. + +Pair style {quip} cannot be used with pair style {hybrid}, only +with {hybrid/overlay} and only the {quip} substyle is applied to +all atom types. [Related commands:] diff --git a/src/USER-QUIP/pair_quip.cpp b/src/USER-QUIP/pair_quip.cpp index c6ab8b259b..6bbbcdb8e6 100644 --- a/src/USER-QUIP/pair_quip.cpp +++ b/src/USER-QUIP/pair_quip.cpp @@ -214,8 +214,14 @@ void PairQUIP::compute(int eflag, int vflag) void PairQUIP::settings(int narg, char **arg) { if (narg != 0) error->all(FLERR,"Illegal pair_style command"); - if (strncmp(force->pair_style,"hybrid",6) == 0) - error->all(FLERR,"Pair style quip is not compatible with hybrid styles"); + if (strcmp(force->pair_style,"hybrid") == 0) + error->all(FLERR,"Pair style quip is only compatible with hybrid/overlay"); + + // check if linked to the correct QUIP library API version + // as of 2017-07-19 this is API_VERSION 1 + if (quip_lammps_api_version() != 1) + error->all(FLERR,"QUIP LAMMPS wrapper API version is not compatible " + "with this version of LAMMPS"); } /* ---------------------------------------------------------------------- diff --git a/src/USER-QUIP/pair_quip.h b/src/USER-QUIP/pair_quip.h index 985a43fd7e..debdc2cb83 100644 --- a/src/USER-QUIP/pair_quip.h +++ b/src/USER-QUIP/pair_quip.h @@ -24,12 +24,13 @@ PairStyle(quip,PairQUIP) extern "C" { - void quip_lammps_wrapper(int*, int*, int*, int*, + int quip_lammps_api_version(); + void quip_lammps_wrapper(int*, int*, int*, int*, int*, int*, int*, int*, int*, double*, int*, int*, double*, double*, double*, double*, double*, double*); - void quip_lammps_potential_initialise(int*, int*, double*, char*, int*, char*, int*); + void quip_lammps_potential_initialise(int*, int*, double*, char*, int*, char*, int*); } namespace LAMMPS_NS {