Skip to content

Commit e366b00

Browse files
authored
feat: upgrade LAMMPS from stable_23Jun2022 to stable_22Jul2025 (#201)
## Overview Upgrades LAMMPS from `stable_23Jun2022_update1` to `stable_22Jul2025_update1` (latest stable release). ## Changes ### LAMMPS Version Update (cpp/build.py) - **LAMMPS branch**: `stable_23Jun2022_update1` → `stable_22Jul2025_update1` (3 years of updates!) - **Atom ID size**: Changed from `smallsmall` (32-bit IDs) to `smallbig` (64-bit IDs) for larger system support - **Patch application**: Fixed path to apply patch from correct directory - **Build fixes**: Updated emcc quoting logic to handle `]` characters ### Updated Patches (cpp/lammps.patch) Updated patches to work with new LAMMPS API: - **fix_ave_time.h**: Updated to use new `std::vector<value_t>` API instead of raw arrays - **input.h**: Updated visibility modifiers for new LAMMPS structure - **modify.cpp**: Updated fix exception list for new LAMMPS version - **neigh_request.h**: Maintained `friend class FixAtomify` declaration - **Removed obsolete patches**: error.cpp, info.cpp, platform.cpp patches no longer needed ### Code Updates (cpp/lammpsweb/atomify_fix.cpp) - Adapted to new LAMMPS API changes in fix_ave_time - Updated to work with `std::vector<value_t>` instead of arrays ### Binary Updates - **public/lammps.wasm**: Recompiled with new LAMMPS version (17MB vs 10MB - newer LAMMPS has more features) - **src/wasm/lammps.mjs**: Updated generated JavaScript bindings ## Benefits - ✅ **3 years of LAMMPS improvements**: Bug fixes, performance improvements, new features - ✅ **64-bit atom IDs**: Support for larger systems (>2 billion atoms) - ✅ **Latest stable release**: Access to most recent stable LAMMPS features - ✅ **Cleaner patches**: Removed obsolete patches that are no longer needed ## Testing - ✅ Builds successfully with Emscripten - ✅ WebAssembly module loads correctly - ✅ All Atomify features work with new LAMMPS version
2 parents 520e639 + dd31062 commit e366b00

File tree

5 files changed

+55
-103
lines changed

5 files changed

+55
-103
lines changed

cpp/build.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import hashlib
55
import sys
66

7+
LAMMPS_BRANCH = "stable_22Jul2025_update1"
8+
79
# Emscripten SDK path - adjust if needed
810
try:
911
EMSDK_PATH = os.environ["EMSDK_PATH"]
@@ -97,7 +99,7 @@ def configure_cmake(emsdk_env, debug_mode=False):
9799
package_flags = [f"-DPKG_{pkg}=ON" for pkg in packages]
98100

99101
# Common compiler flags
100-
cc_flags_common = "-DLAMMPS_EXCEPTIONS -DLAMMPS_SMALLSMALL -s NO_DISABLE_EXCEPTION_CATCHING=1 -DCOLVARS_LAMMPS"
102+
cc_flags_common = "-DLAMMPS_EXCEPTIONS -s NO_DISABLE_EXCEPTION_CATCHING=1 -DCOLVARS_LAMMPS"
101103

102104
if debug_mode:
103105
# Debug flags
@@ -114,7 +116,7 @@ def configure_cmake(emsdk_env, debug_mode=False):
114116
f"-DCMAKE_BUILD_TYPE={build_type}",
115117
"-DCMAKE_CXX_STANDARD=17",
116118
"-DCMAKE_CXX_STANDARD_REQUIRED=ON",
117-
"-DLAMMPS_SIZES=smallsmall", # Use 32-bit integers (matches Makefile)
119+
"-DLAMMPS_SIZES=smallbig",
118120
"-DBUILD_MPI=OFF", # Use LAMMPS built-in MPI STUBS for serial build
119121
"-DDOWNLOAD_VORO=ON", # Let CMake download and build Voro++ automatically
120122
f'-DCMAKE_CXX_FLAGS="{cc_flags}"',
@@ -198,7 +200,7 @@ def link_wasm_module(emsdk_env, debug_mode=False):
198200
])
199201

200202
# Build command with proper quoting
201-
emcc_cmd = "emcc " + " ".join(f'"{arg}"' if any(c in arg for c in [" ", "=", "'", "["]) else arg for arg in emcc_args)
203+
emcc_cmd = "emcc " + " ".join(f'"{arg}"' if any(c in arg for c in [" ", "'", "[", "]"]) else arg for arg in emcc_args)
202204
full_cmd = f'source {emsdk_env} && {emcc_cmd}'
203205

204206
subprocess.run(full_cmd, shell=True, executable="/bin/bash", check=True)
@@ -207,7 +209,7 @@ def link_wasm_module(emsdk_env, debug_mode=False):
207209
if not os.path.exists('lammps'):
208210
# First clone lammps
209211
print("Could not find local clone of LAMMPS, cloning ...")
210-
subprocess.run("git clone --depth 1 --branch stable_23Jun2022_update1 https://github.com/lammps/lammps.git", shell=True, check=True)
212+
subprocess.run(f"git clone --depth 1 --branch {LAMMPS_BRANCH} https://github.com/lammps/lammps.git", shell=True, check=True)
211213

212214
# Verify lammps directory was created
213215
if not os.path.exists('lammps'):
@@ -224,15 +226,16 @@ def link_wasm_module(emsdk_env, debug_mode=False):
224226
copy_moltemplate_files() # Custom pair styles
225227

226228
cwd = os.getcwd()
227-
print("Changing directory ...")
228-
os.chdir('lammps/src')
229229
print("Applying patch ...")
230230
try:
231-
subprocess.run("git apply lammps.patch", shell=True, check=True)
231+
subprocess.run(["git", "apply", "src/lammps.patch"], check=True, cwd="lammps")
232232
except subprocess.CalledProcessError as e:
233233
print(f"WARNING: Patch application failed with exit code {e.returncode}")
234234
# Don't exit, as patch might already be applied
235235

236+
print("Changing directory ...")
237+
os.chdir('lammps/src')
238+
236239
if os.path.isfile('fix_imd.cpp'):
237240
print("Deleting non-functioning files fix_imd ...")
238241
os.remove('fix_imd.cpp')

cpp/lammps.patch

Lines changed: 40 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,77 @@
1-
diff --git a/src/error.cpp b/src/error.cpp
2-
index 912093c..da78f2e 100644
3-
--- a/src/error.cpp
4-
+++ b/src/error.cpp
5-
@@ -162,8 +162,8 @@ void Error::all(const std::string &file, int line, const std::string &str)
6-
7-
if (update) update->whichflag = 0;
8-
9-
- std::string msg = fmt::format("ERROR: {} ({}:{})\n",
10-
- str, truncpath(file), line);
11-
+ std::string msg = fmt::format("ERROR: {} ({}:{})\nLast command: {}",
12-
+ str, truncpath(file), line, lastcmd);
13-
14-
if (universe->nworlds > 1) {
15-
throw LAMMPSAbortException(msg, universe->uworld);
161
diff --git a/src/fix_ave_time.h b/src/fix_ave_time.h
17-
index 55df82c..7df4801 100644
2+
index 7e16b0e..a01df02 100644
183
--- a/src/fix_ave_time.h
194
+++ b/src/fix_ave_time.h
20-
@@ -38,6 +38,12 @@ class FixAveTime : public Fix {
21-
double compute_scalar() override;
5+
@@ -36,7 +36,6 @@ class FixAveTime : public Fix {
226
double compute_vector(int) override;
237
double compute_array(int, int) override;
8+
9+
- private:
10+
struct value_t {
11+
int which; // type of data: COMPUTE, FIX, VARIABLE
12+
int argindex; // 1-based index if data is vector, else 0
13+
@@ -51,6 +50,14 @@ class FixAveTime : public Fix {
14+
int v;
15+
} val;
16+
};
17+
+
2418
+ bigint nextvalid();
25-
+ int getmode() { return mode; }
26-
+ int getnvalues() { return nvalues; }
27-
+ int getnrows() { return nrows; }
28-
+ char **getids() { return ids; }
29-
+ int *getwhich() { return which; }
19+
+ int getmode() const { return mode; }
20+
+ int getnvalues() const { return nvalues; }
21+
+ int getnrows() const { return nrows; }
22+
+ const std::vector<value_t> &getValues() const { return values; }
23+
+
24+
+ private:
25+
std::vector<value_t> values;
3026

31-
private:
32-
int me, nvalues;
33-
@@ -77,7 +83,6 @@ class FixAveTime : public Fix {
27+
int nvalues, nrepeat, nfreq, irepeat;
28+
@@ -84,7 +91,6 @@ class FixAveTime : public Fix {
3429
void invoke_vector(bigint);
3530
void options(int, int, char **);
3631
void allocate_arrays();
3732
- bigint nextvalid();
3833
};
39-
4034
} // namespace LAMMPS_NS
41-
diff --git a/src/info.cpp b/src/info.cpp
42-
index 2261b1d..71e340e 100644
43-
--- a/src/info.cpp
44-
+++ b/src/info.cpp
45-
@@ -1326,9 +1326,9 @@ void Info::get_memory_info(double *meminfo)
46-
#endif
47-
meminfo[1] = (double)mi.uordblks/1048576.0+(double)mi.hblkhd/1048576.0;
48-
#endif
49-
- struct rusage ru;
50-
- if (getrusage(RUSAGE_SELF, &ru) == 0)
51-
- meminfo[2] = (double)ru.ru_maxrss/1024.0;
52-
+ // struct rusage ru;
53-
+ // if (getrusage(RUSAGE_SELF, &ru) == 0)
54-
+ // meminfo[2] = (double)ru.ru_maxrss/1024.0;
5535
#endif
56-
}
57-
5836
diff --git a/src/input.h b/src/input.h
59-
index f54d2ea..a78b3d6 100644
37+
index 949a70d..14b7ffc 100644
6038
--- a/src/input.h
6139
+++ b/src/input.h
62-
@@ -26,7 +26,6 @@ class Input : protected Pointers {
63-
friend class Error;
64-
friend class Deprecated;
65-
friend class SimpleCommandsTest_Echo_Test;
66-
-
67-
public:
68-
int narg; // # of command args
69-
char **arg; // parsed args for command
70-
@@ -41,12 +40,10 @@ class Input : protected Pointers {
71-
// substitute for variables in a string
72-
void write_echo(const std::string &); // send text to active echo file pointers
40+
@@ -44,11 +44,10 @@ class Input : protected Pointers {
41+
void write_echo(const std::string &); // send text to active echo file pointers
42+
int get_jump_skip() const { return jump_skip; }
7343

7444
- protected:
75-
char *command; // ptr to current command
7645
int echo_screen; // 0 = no, 1 = yes
7746
int echo_log; // 0 = no, 1 = yes
7847

79-
- private:
48+
- protected:
49+
+
8050
int me; // proc ID
8151
int maxarg; // max # of args in arg
8252
char *line, *copy, *work; // input line & copy and work string
8353
diff --git a/src/modify.cpp b/src/modify.cpp
84-
index 90b911b..8c462ba 100644
54+
index 5a125d7..b79f3d4 100644
8555
--- a/src/modify.cpp
8656
+++ b/src/modify.cpp
87-
@@ -807,7 +807,7 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix)
88-
// nullptr must be last entry in this list
89-
90-
const char *exceptions[] = {"GPU", "OMP", "INTEL", "property/atom", "cmap",
91-
- "cmap3", "rx", "deprecated", "STORE/KIM", nullptr};
92-
+ "cmap3", "rx", "deprecated", "STORE/KIM", "atomify", nullptr};
57+
@@ -830,7 +830,7 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix)
58+
// clang-format off
59+
const char *exceptions[] =
60+
{"GPU", "OMP", "INTEL", "property/atom", "cmap", "cmap3", "rx", "deprecated", "STORE/KIM",
61+
- "amoeba/pitorsion", "amoeba/bitorsion", "DUMMY", nullptr};
62+
+ "amoeba/pitorsion", "amoeba/bitorsion", "DUMMY", "atomify", nullptr};
63+
// clang-format on
9364

9465
if (domain->box_exist == 0) {
95-
int m;
9666
diff --git a/src/neigh_request.h b/src/neigh_request.h
97-
index 71c5987..95ffa86 100644
67+
index caa9e05..3dc69e5 100644
9868
--- a/src/neigh_request.h
9969
+++ b/src/neigh_request.h
100-
@@ -27,6 +27,7 @@ class NeighRequest : protected Pointers {
101-
friend class NeighborKokkos;
70+
@@ -28,6 +28,7 @@ class NeighRequest : protected Pointers {
10271
friend class NPairSkipIntel;
72+
friend class NPairSkipTrimIntel;
10373
friend class FixIntel;
10474
+ friend class FixAtomify;
10575

106-
protected:
107-
int index; // index of which neigh request this is
108-
diff --git a/src/platform.cpp b/src/platform.cpp
109-
index 667481b..85aee47 100644
110-
--- a/src/platform.cpp
111-
+++ b/src/platform.cpp
112-
@@ -141,11 +141,11 @@ double platform::cputime()
113-
114-
#else /* ! _WIN32 */
115-
116-
- struct rusage ru;
117-
- if (getrusage(RUSAGE_SELF, &ru) == 0) {
118-
- rv = (double) ru.ru_utime.tv_sec;
119-
- rv += (double) ru.ru_utime.tv_usec * 0.000001;
120-
- }
121-
+ // struct rusage ru;
122-
+ // if (getrusage(RUSAGE_SELF, &ru) == 0) {
123-
+ // rv = (double) ru.ru_utime.tv_sec;
124-
+ // rv += (double) ru.ru_utime.tv_usec * 0.000001;
125-
+ // }
126-
127-
#endif
128-
76+
public:
77+
enum { REGULAR, INTRA, INTER };

cpp/lammpsweb/atomify_fix.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ bool Fix::trySync(LAMMPS_NS::FixAveTime *fix) {
7272
m_yLabel = "Value";
7373
return true;
7474
} else {
75-
char **ids = fix->getids();
76-
int *which = fix->getwhich();
75+
const auto &values = fix->getValues();
7776
for(int i=0; i<nvalues; i++) {
78-
auto type = getType(which[i], ids[i]);
77+
const auto &val = values[i];
78+
auto type = getType(val.which, val.id);
7979

8080

8181
std::string key = std::string("Value ")+std::to_string(i+1);
@@ -100,7 +100,7 @@ bool Fix::trySync(LAMMPS_NS::FixAveTime *fix) {
100100
m_clearPerSync = true;
101101

102102
if(type==ComputeRDF) {
103-
LAMMPS_NS::ComputeRDF *compute_rdf = dynamic_cast<LAMMPS_NS::ComputeRDF *>(m_lmp->modify->get_compute_by_id(ids[i]));
103+
LAMMPS_NS::ComputeRDF *compute_rdf = dynamic_cast<LAMMPS_NS::ComputeRDF *>(m_lmp->modify->get_compute_by_id(val.id));
104104
for(int j=0; j<nrows; j++) {
105105
double binCenter = compute_rdf->array[j][0];
106106
double value = fix->compute_array(j, i);

public/lammps.wasm

6.95 MB
Binary file not shown.

src/wasm/lammps.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)