Skip to content

Commit 2afb54b

Browse files
committed
fix: Backport changes from LAMMPS repository
1 parent 0d90574 commit 2afb54b

File tree

3 files changed

+31
-30
lines changed

3 files changed

+31
-30
lines changed

lammps/src/COLVARS/colvarproxy_lammps.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,18 @@ class colvarproxy_lammps : public colvarproxy {
8585
cvm::real rand_gaussian() override;
8686

8787
int init_atom(int atom_number) override;
88+
int init_atom(cvm::residue_id const &residue, std::string const &atom_name,
89+
std::string const &segment_id) override
90+
{
91+
return colvarproxy::init_atom(residue, atom_name, segment_id);
92+
}
93+
8894
int check_atom_id(int atom_number) override;
95+
int check_atom_id(cvm::residue_id const &residue, std::string const &atom_name,
96+
std::string const &segment_id) override
97+
{
98+
return colvarproxy::check_atom_id(residue, atom_name, segment_id);
99+
}
89100

90101
inline std::vector<int> *modify_atom_types() { return &atoms_types; }
91102
};

lammps/src/COLVARS/fix_colvars.cpp

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
------------------------------------------------------------------------- */
2828

2929
#include "fix_colvars.h"
30-
#include "inthash.h"
3130

3231
#include "atom.h"
3332
#include "citeme.h"
@@ -61,7 +60,6 @@ struct LAMMPS_NS::commdata {
6160

6261
using namespace LAMMPS_NS;
6362
using namespace FixConst;
64-
using namespace IntHash_NS;
6563

6664
// initialize static class members
6765
int FixColvars::instances = 0;
@@ -122,7 +120,6 @@ FixColvars::FixColvars(LAMMPS *lmp, int narg, char **arg) :
122120
comm_buf = nullptr;
123121
taglist = nullptr;
124122
force_buf = nullptr;
125-
idmap = nullptr;
126123

127124
script_args[0] = reinterpret_cast<unsigned char *>(utils::strdup("fix_modify"));
128125

@@ -227,11 +224,6 @@ FixColvars::~FixColvars()
227224

228225
if (proxy) delete proxy;
229226

230-
if (idmap) {
231-
inthash_destroy(idmap);
232-
delete idmap;
233-
}
234-
235227
if (root2root != MPI_COMM_NULL)
236228
MPI_Comm_free(&root2root);
237229

@@ -349,16 +341,11 @@ void FixColvars::init_taglist()
349341

350342
std::vector<int> const &tl = *(proxy->get_atom_ids());
351343

352-
if (idmap) {
353-
delete idmap;
354-
idmap = nullptr;
355-
}
356-
357-
idmap = new inthash_t;
358-
inthash_init(idmap, num_coords);
344+
idmap.clear();
345+
idmap.reserve(num_coords);
359346
for (int i = 0; i < num_coords; ++i) {
360347
taglist[i] = tl[i];
361-
inthash_insert(idmap, tl[i], i);
348+
idmap[tl[i]] = i;
362349
}
363350
}
364351

@@ -542,10 +529,9 @@ void FixColvars::setup(int vflag)
542529
ndata /= size_one;
543530

544531
for (int k=0; k<ndata; ++k) {
545-
546-
const int j = inthash_lookup(idmap, comm_buf[k].tag);
547-
548-
if (j != HASH_FAIL) {
532+
auto search = idmap.find(comm_buf[k].tag);
533+
if (search != idmap.end()) {
534+
const int j = search->second;
549535

550536
tp[j] = comm_buf[k].type;
551537

@@ -701,8 +687,10 @@ void FixColvars::post_force(int /*vflag*/)
701687
ndata /= size_one;
702688

703689
for (int k=0; k<ndata; ++k) {
704-
const int j = inthash_lookup(idmap, comm_buf[k].tag);
705-
if (j != HASH_FAIL) {
690+
auto search = idmap.find(comm_buf[k].tag);
691+
if (search != idmap.end()) {
692+
const int j = search->second;
693+
706694
cd[j].x = comm_buf[k].x;
707695
cd[j].y = comm_buf[k].y;
708696
cd[j].z = comm_buf[k].z;
@@ -826,8 +814,10 @@ void FixColvars::end_of_step()
826814
const tagint k = atom->map(taglist[i]);
827815
if ((k >= 0) && (k < nlocal)) {
828816

829-
const int j = inthash_lookup(idmap, tag[k]);
830-
if (j != HASH_FAIL) {
817+
auto search = idmap.find(tag[k]);
818+
if (search != idmap.end()) {
819+
const int j = search->second;
820+
831821
of[j].x = f[k][0];
832822
of[j].y = f[k][1];
833823
of[j].z = f[k][2];
@@ -845,8 +835,10 @@ void FixColvars::end_of_step()
845835
ndata /= size_one;
846836

847837
for (int k=0; k<ndata; ++k) {
848-
const int j = inthash_lookup(idmap, comm_buf[k].tag);
849-
if (j != HASH_FAIL) {
838+
auto search = idmap.find(comm_buf[k].tag);
839+
if (search != idmap.end()) {
840+
const int j = search->second;
841+
850842
of[j].x = comm_buf[k].x;
851843
of[j].y = comm_buf[k].y;
852844
of[j].z = comm_buf[k].z;

lammps/src/COLVARS/fix_colvars.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@ FixStyle(colvars,FixColvars);
3535
#define LMP_FIX_COLVARS_H
3636

3737
#include "fix.h"
38+
#include <unordered_map>
3839

3940
// Forward declarations
40-
namespace IntHash_NS {
41-
struct inthash_t;
42-
}
4341
class colvarproxy_lammps;
4442

4543
namespace LAMMPS_NS {
@@ -87,7 +85,7 @@ class FixColvars : public Fix {
8785
/// Arguments passed from fix_modify to the Colvars script interface
8886
unsigned char *script_args[100];
8987

90-
IntHash_NS::inthash_t *idmap; // hash for mapping atom indices to consistent order.
88+
std::unordered_map<int, int> idmap; // for mapping atom indices to consistent order.
9189

9290
int nlevels_respa; // flag to determine respa levels.
9391
int store_forces; // flag to determine whether to store total forces

0 commit comments

Comments
 (0)