From 2ae07ec1cb2aa36e7a477422c7a947e645bee0a7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 4 Feb 2025 17:00:12 -0500 Subject: [PATCH 01/50] sync C++ standard selection with main CMakeLists.txt file --- cmake/Modules/LAMMPSInterfacePlugin.cmake | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/cmake/Modules/LAMMPSInterfacePlugin.cmake b/cmake/Modules/LAMMPSInterfacePlugin.cmake index 151e0a04f7..fcaf604778 100644 --- a/cmake/Modules/LAMMPSInterfacePlugin.cmake +++ b/cmake/Modules/LAMMPSInterfacePlugin.cmake @@ -34,8 +34,26 @@ if(MSVC) add_compile_definitions(_CRT_SECURE_NO_WARNINGS) endif() -# C++11 is required -set(CMAKE_CXX_STANDARD 11) +if(NOT CMAKE_CXX_STANDARD) + if(cxx_std_17 IN_LIST CMAKE_CXX_COMPILE_FEATURES) + set(CMAKE_CXX_STANDARD 17) + else() + set(CMAKE_CXX_STANDARD 11) + endif() +endif() +if(CMAKE_CXX_STANDARD LESS 11) + message(FATAL_ERROR "C++ standard must be set to at least 11") +endif() +if(CMAKE_CXX_STANDARD LESS 17) + message(WARNING "Selecting C++17 standard is preferred over C++${CMAKE_CXX_STANDARD}") +endif() +if(PKG_KOKKOS AND (CMAKE_CXX_STANDARD LESS 17)) + set(CMAKE_CXX_STANDARD 17) +endif() +# turn off C++17 check in lmptype.h +if(LAMMPS_CXX11) + add_compile_definitions(LAMMPS_CXX11) +endif() set(CMAKE_CXX_STANDARD_REQUIRED ON) # Need -restrict with Intel compilers From 97e7baf33f0dddbea9c5dabe8d960eacdb4ea3c2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 5 Feb 2025 23:39:13 -0500 Subject: [PATCH 02/50] get rid of non-standard variable-length arrays in ML-RANN package --- src/ML-RANN/rann_fingerprint_bond.cpp | 54 ++++++++------- src/ML-RANN/rann_fingerprint_bondscreened.cpp | 67 ++++++++++--------- .../rann_fingerprint_bondscreenedspin.cpp | 60 +++++++++-------- src/ML-RANN/rann_fingerprint_bondspin.cpp | 57 ++++++++-------- 4 files changed, 123 insertions(+), 115 deletions(-) diff --git a/src/ML-RANN/rann_fingerprint_bond.cpp b/src/ML-RANN/rann_fingerprint_bond.cpp index acc3318ba0..536859dc8f 100644 --- a/src/ML-RANN/rann_fingerprint_bond.cpp +++ b/src/ML-RANN/rann_fingerprint_bond.cpp @@ -36,6 +36,8 @@ DISTRIBUTION A. Approved for public release; distribution unlimited. OPSEC#4918 using namespace LAMMPS_NS::RANN; +static constexpr double SMALL = 1.0e-12; + Fingerprint_bond::Fingerprint_bond(PairRANN *_pair) : Fingerprint(_pair) { n_body_type = 3; @@ -317,7 +319,8 @@ void Fingerprint_bond::do3bodyfeatureset_singleneighborloop(double * features,do i = ilist[ii]; itype = pair->map[type[i]]; int f = pair->net[itype].dimensions[0]; - double expr[jnum][kmax+12]; + std::vector row(kmax+12, 0.0); + std::vector> expr(jnum, row); int p = kmax; int countmb=((mlength)*(mlength+1))>>1; // calculate interpolation expr, rinvs and dfc, for each neighbor @@ -354,13 +357,13 @@ void Fingerprint_bond::do3bodyfeatureset_singleneighborloop(double * features,do expr[jj][p+1]=dely*rinvs; expr[jj][p+2]=delz*rinvs; //Hack to avoid nan when x y or z component of radial vector is exactly 0. Shouldn't affect accuracy. - if (expr[jj][p]*expr[jj][p]<0.000000000001) { + if (expr[jj][p]*expr[jj][p] < SMALL) { expr[jj][p] = 0.000001; } - if (expr[jj][p+1]*expr[jj][p+1]<0.000000000001) { + if (expr[jj][p+1]*expr[jj][p+1] < SMALL) { expr[jj][p+1] = 0.000001; } - if (expr[jj][p+2]*expr[jj][p+2]<0.000000000001) { + if (expr[jj][p+2]*expr[jj][p+2] < SMALL) { expr[jj][p+2] = 0.000001; } expr[jj][p+3] = -dfc*expr[jj][p]; @@ -377,7 +380,7 @@ void Fingerprint_bond::do3bodyfeatureset_singleneighborloop(double * features,do int kb = kmax; int mb = mlength; count = startingneuron; - double Bb[mb]; + std::vector Bb(mb, 0.0); double dBbx; double dBby; double dBbz; @@ -397,7 +400,7 @@ void Fingerprint_bond::do3bodyfeatureset_singleneighborloop(double * features,do } for (n=0;n Bg(mb, 0.0); ai = n; double y1 = alpha_k[ai]/re; //loop over ktype to get Bg @@ -433,7 +433,7 @@ void Fingerprint_bond::do3bodyfeatureset_singleneighborloop(double * features,do continue; } double yprod = expr[jj][ai]; - double *y4 = &expr[jj][p]; + double *y4 = expr[jj].data() + p; for (a2=0;a2map[type[i]]; int f = pair->net[itype].dimensions[0]; - double expr[jnum][kmax]; - double y[jnum][3]; - double ri[jnum]; - double dfc[jnum]; + std::vector row(kmax, 0.0); + std::vector> expr(jnum, row); + std::vector yrow(3, 0.0); + std::vector> y(jnum, yrow); + std::vector ri(jnum, 0.0); + std::vector dfc(jnum, 0.0); int kb = kmax; int mb = mlength; - double c41[kmax]; - double c51[kmax]; - double c61[kmax]; - double ct[kmax]; + std::vector c41(kmax, 0.0); + std::vector c51(kmax, 0.0); + std::vector c61(kmax, 0.0); + std::vector ct(kmax, 0.0); for (jj = 0; jj < jnum; jj++) { jtype = tn[jj]; if (jtypes != nelements && jtypes != jtype && ktypes != nelements && ktypes != jtype) { diff --git a/src/ML-RANN/rann_fingerprint_bondscreened.cpp b/src/ML-RANN/rann_fingerprint_bondscreened.cpp index 8dcc2e4389..018bbc6df1 100644 --- a/src/ML-RANN/rann_fingerprint_bondscreened.cpp +++ b/src/ML-RANN/rann_fingerprint_bondscreened.cpp @@ -36,6 +36,8 @@ DISTRIBUTION A. Approved for public release; distribution unlimited. OPSEC#4918 using namespace LAMMPS_NS::RANN; +static constexpr double SMALL = 1.0e-12; + Fingerprint_bondscreened::Fingerprint_bondscreened(PairRANN *_pair) : Fingerprint(_pair) { n_body_type = 3; @@ -319,7 +321,8 @@ void Fingerprint_bondscreened::do3bodyfeatureset_singleneighborloop(double * fea i = ilist[ii]; itype = pair->map[type[i]]; int f = pair->net[itype].dimensions[0]; - double expr[jnum][kmax+12]; + std::vector row(kmax+12, 0.0); + std::vector> expr(jnum, row); int p = kmax; int countmb=((mlength)*(mlength+1))>>1; // calculate interpolation expr, rinvs and dfc, for each neighbor @@ -358,13 +361,13 @@ void Fingerprint_bondscreened::do3bodyfeatureset_singleneighborloop(double * fea expr[jj][p+1]=dely*rinvs; expr[jj][p+2]=delz*rinvs; //Hack to avoid nan when x y or z component of radial vector is exactly 0. Shouldn't affect accuracy. - if (expr[jj][p]*expr[jj][p]<0.000000000001) { + if (expr[jj][p]*expr[jj][p] < SMALL) { expr[jj][p] = 0.000001; } - if (expr[jj][p+1]*expr[jj][p+1]<0.000000000001) { + if (expr[jj][p+1]*expr[jj][p+1] < SMALL) { expr[jj][p+1] = 0.000001; } - if (expr[jj][p+2]*expr[jj][p+2]<0.000000000001) { + if (expr[jj][p+2]*expr[jj][p+2] < SMALL) { expr[jj][p+2] = 0.000001; } expr[jj][p+3] = -dfc*expr[jj][p]-dSikx[jj]; @@ -381,20 +384,20 @@ void Fingerprint_bondscreened::do3bodyfeatureset_singleneighborloop(double * fea int kb = kmax; int mb = mlength; count = startingneuron; - double Bb[mb]; + std::vector Bb(mb, 0.0); double dBbx; double dBby; double dBbz; - double dBbx1[mb]; - double dBby1[mb]; - double dBbz1[mb]; + std::vector dBbx1(mb, 0.0); + std::vector dBby1(mb, 0.0); + std::vector dBbz1(mb, 0.0); double yprod; for (mcount=0;mcount Bg(mb, 0.0); ai = n; double y1 = alpha_k[ai]/re; //loop over ktype to get Bg @@ -445,7 +445,7 @@ void Fingerprint_bondscreened::do3bodyfeatureset_singleneighborloop(double * fea continue; } double yprod = expr[jj][ai]; - double *y4 = &expr[jj][p]; + double *y4 = expr[jj].data() + p; for (a2=0;a2map[type[i]]; int f = pair->net[itype].dimensions[0]; - double expr[jnum][kmax]; - double y[jnum][3]; - double ri[jnum]; - double dfc[jnum]; + std::vector row(kmax, 0.0); + std::vector> expr(jnum, row); + std::vector yrow(3, 0.0); + std::vector> y(jnum, yrow); + std::vector ri(jnum, 0.0); + std::vector dfc(jnum, 0.0); int kb = kmax; int mb = mlength; - double Bijk[kb][mb]; - double c41[kmax]; - double c51[kmax]; - double c61[kmax]; - double ct[kmax]; + std::vector brow(mb, 0.0); + std::vector> Bijk(kb, brow); + std::vector c41(kmax, 0.0); + std::vector c51(kmax, 0.0); + std::vector c61(kmax, 0.0); + std::vector ct(kmax, 0.0); for (jj = 0; jj < jnum; jj++) { if (Bij[jj]==false) {continue;} jtype = tn[jj]; diff --git a/src/ML-RANN/rann_fingerprint_bondscreenedspin.cpp b/src/ML-RANN/rann_fingerprint_bondscreenedspin.cpp index cbd3b2a6dc..26fa46b4eb 100644 --- a/src/ML-RANN/rann_fingerprint_bondscreenedspin.cpp +++ b/src/ML-RANN/rann_fingerprint_bondscreenedspin.cpp @@ -35,6 +35,8 @@ DISTRIBUTION A. Approved for public release; distribution unlimited. OPSEC#4918 using namespace LAMMPS_NS::RANN; +static constexpr double SMALL = 1.0e-12; + Fingerprint_bondscreenedspin::Fingerprint_bondscreenedspin(PairRANN *_pair) : Fingerprint(_pair) { n_body_type = 3; @@ -320,7 +322,8 @@ void Fingerprint_bondscreenedspin::do3bodyfeatureset_singleneighborloop(double * i = ilist[ii]; itype = pair->map[type[i]]; int f = pair->net[itype].dimensions[0]; - double expr[jnum][kmax+12]; + std::vector row(kmax+12, 0.0); + std::vector> expr(jnum, row); int p = kmax; int countmb=((mlength)*(mlength+1))>>1; double *si = sim->s[i]; @@ -360,13 +363,13 @@ void Fingerprint_bondscreenedspin::do3bodyfeatureset_singleneighborloop(double * expr[jj][p+1]=dely*rinvs; expr[jj][p+2]=delz*rinvs; //Hack to avoid nan when x y or z component of radial vector is exactly 0. Shouldn't affect accuracy. - if (expr[jj][p]*expr[jj][p]<0.000000000001) { + if (expr[jj][p]*expr[jj][p] < SMALL) { expr[jj][p] = 0.000001; } - if (expr[jj][p+1]*expr[jj][p+1]<0.000000000001) { + if (expr[jj][p+1]*expr[jj][p+1] < SMALL) { expr[jj][p+1] = 0.000001; } - if (expr[jj][p+2]*expr[jj][p+2]<0.000000000001) { + if (expr[jj][p+2]*expr[jj][p+2] < SMALL) { expr[jj][p+2] = 0.000001; } expr[jj][p+3] = -dfc*expr[jj][p]-dSikx[jj]; @@ -383,8 +386,8 @@ void Fingerprint_bondscreenedspin::do3bodyfeatureset_singleneighborloop(double * int kb = kmax; int mb = mlength; count = startingneuron; - double Bb[mb]; - double Bbs[mb]; + std::vector Bb(mb, 0.0); + std::vector Bbs(mb, 0.0); double dBbx; double dBby; double dBbz; @@ -421,7 +424,7 @@ void Fingerprint_bondscreenedspin::do3bodyfeatureset_singleneighborloop(double * double *sj = sim->s[j]; double sp = si[0]*sj[0]+si[1]*sj[1]+si[2]*sj[2]; double yprod = expr[jj][ai]; - double *y4 = &expr[jj][p]; + double *y4 = expr[jj].data() + p; for (a2=0;a2 Bg(mb, 0.0); + std::vector Bgs(mb, 0.0); ai = n; double y1 = alpha_k[ai]/re; //loop over ktype to get Bg @@ -452,7 +451,7 @@ void Fingerprint_bondscreenedspin::do3bodyfeatureset_singleneighborloop(double * double *sj = sim->s[j]; double sp = si[0]*sj[0]+si[1]*sj[1]+si[2]*sj[2]; double yprod = expr[jj][ai]; - double *y4 = &expr[jj][p]; + double *y4 = expr[jj].data() + p; for (a2=0;a2s[j]; double sp = si[0]*sj[0]+si[1]*sj[1]+si[2]*sj[2]; - double *y3 = &expr[jj][p+3]; - double *y4 = &expr[jj][p]; + double *y3 = expr[jj].data() + p + 3; + double *y4 = expr[jj].data() + p; ai = n; yprod = expr[jj][ai]; for (a2=0;a2s[j]; double sp = si[0]*sj[0]+si[1]*sj[1]+si[2]*sj[2]; - double *y3 = &expr[jj][p+3]; - double *y4 = &expr[jj][p]; + double *y3 = expr[jj].data() + p + 3; + double *y4 = expr[jj].data() + p; ai = n; yprod = expr[jj][ai]; for (a2=0;a2s[j]; double sp = si[0]*sj[0]+si[1]*sj[1]+si[2]*sj[2]; - double *y3 = &expr[jj][p+3]; - double *y4 = &expr[jj][p]; + double *y3 = expr[jj].data() + p + 3; + double *y4 = expr[jj].data() + p; ai = n; yprod = expr[jj][ai]; for (a2=0;a2map[type[i]]; int f = pair->net[itype].dimensions[0]; - double expr[jnum][kmax]; - double y[jnum][3]; - double ri[jnum]; - double dfc[jnum]; + std::vector row(kmax, 0.0); + std::vector> expr(jnum, row); + std::vector yrow(3, 0.0); + std::vector> y(jnum, yrow); + std::vector ri(jnum, 0.0); + std::vector dfc(jnum, 0.0); int kb = kmax; int mb = mlength; - double Bijk[kb][mb]; - double c41[kmax]; - double c51[kmax]; - double c61[kmax]; - double ct[kmax]; double *si = sim->s[i]; + std::vector brow(mb, 0.0); + std::vector> Bijk(kb, brow); + std::vector c41(kmax, 0.0); + std::vector c51(kmax, 0.0); + std::vector c61(kmax, 0.0); + std::vector ct(kmax, 0.0); for (jj = 0; jj < jnum; jj++) { if (Bij[jj]==false) {continue;} jtype = tn[jj]; diff --git a/src/ML-RANN/rann_fingerprint_bondspin.cpp b/src/ML-RANN/rann_fingerprint_bondspin.cpp index 1ccdf8ff62..5ecd37b89c 100644 --- a/src/ML-RANN/rann_fingerprint_bondspin.cpp +++ b/src/ML-RANN/rann_fingerprint_bondspin.cpp @@ -35,6 +35,8 @@ DISTRIBUTION A. Approved for public release; distribution unlimited. OPSEC#4918 using namespace LAMMPS_NS::RANN; +static constexpr double SMALL = 1.0e-12; + Fingerprint_bondspin::Fingerprint_bondspin(PairRANN *_pair) : Fingerprint(_pair) { n_body_type = 3; @@ -317,7 +319,8 @@ void Fingerprint_bondspin::do3bodyfeatureset_singleneighborloop(double * feature i = ilist[ii]; itype = pair->map[type[i]]; int f = pair->net[itype].dimensions[0]; - double expr[jnum][kmax+12]; + std::vector row(kmax+12, 0.0); + std::vector> expr(jnum, row); int p = kmax; int countmb=((mlength)*(mlength+1))>>1; double *si = sim->s[i]; @@ -355,13 +358,13 @@ void Fingerprint_bondspin::do3bodyfeatureset_singleneighborloop(double * feature expr[jj][p+1]=dely*rinvs; expr[jj][p+2]=delz*rinvs; //Hack to avoid nan when x y or z component of radial vector is exactly 0. Shouldn't affect accuracy. - if (expr[jj][p]*expr[jj][p]<0.000000000001) { + if (expr[jj][p]*expr[jj][p] < SMALL) { expr[jj][p] = 0.000001; } - if (expr[jj][p+1]*expr[jj][p+1]<0.000000000001) { + if (expr[jj][p+1]*expr[jj][p+1] < SMALL) { expr[jj][p+1] = 0.000001; } - if (expr[jj][p+2]*expr[jj][p+2]<0.000000000001) { + if (expr[jj][p+2]*expr[jj][p+2] < SMALL) { expr[jj][p+2] = 0.000001; } expr[jj][p+3] = -dfc*expr[jj][p]; @@ -378,8 +381,8 @@ void Fingerprint_bondspin::do3bodyfeatureset_singleneighborloop(double * feature int kb = kmax; int mb = mlength; count = startingneuron; - double Bb[mb]; - double Bbs[mb]; + std::vector Bb(mb, 0.0); + std::vector Bbs(mb, 0.0); double dBbx; double dBby; double dBbz; @@ -415,7 +418,7 @@ void Fingerprint_bondspin::do3bodyfeatureset_singleneighborloop(double * feature double *sj = sim->s[j]; double sp = si[0]*sj[0]+si[1]*sj[1]+si[2]*sj[2]; double yprod = expr[jj][ai]; - double *y4 = &expr[jj][p]; + double *y4 = expr[jj].data() + p; for (a2=0;a2 Bg(mb, 0.0); + std::vector Bgs(mb, 0.0); ai = n; double y1 = alpha_k[ai]/re; //loop over ktype to get Bg @@ -445,7 +444,7 @@ void Fingerprint_bondspin::do3bodyfeatureset_singleneighborloop(double * feature double *sj = sim->s[j]; double sp = si[0]*sj[0]+si[1]*sj[1]+si[2]*sj[2]; double yprod = expr[jj][ai]; - double *y4 = &expr[jj][p]; + double *y4 = expr[jj].data() + p; for (a2=0;a2s[j]; double sp = si[0]*sj[0]+si[1]*sj[1]+si[2]*sj[2]; - double *y3 = &expr[jj][p+3]; - double *y4 = &expr[jj][p]; + double *y3 = expr[jj].data() + p + 3; + double *y4 = expr[jj].data() + p; ai = n; yprod = expr[jj][ai]; for (a2=0;a2s[j]; double sp = si[0]*sj[0]+si[1]*sj[1]+si[2]*sj[2]; - double *y3 = &expr[jj][p+3]; - double *y4 = &expr[jj][p]; + double *y3 = expr[jj].data() + p + 3; + double *y4 = expr[jj].data() + p; ai = n; yprod = expr[jj][ai]; for (a2=0;a2s[j]; double sp = si[0]*sj[0]+si[1]*sj[1]+si[2]*sj[2]; - double *y3 = &expr[jj][p+3]; - double *y4 = &expr[jj][p]; + double *y3 = expr[jj].data() + p + 3; + double *y4 = expr[jj].data() + p; ai = n; yprod = expr[jj][ai]; for (a2=0;a2map[type[i]]; int f = pair->net[itype].dimensions[0]; - double expr[jnum][kmax]; - double y[jnum][3]; - double ri[jnum]; - double dfc[jnum]; + std::vector row(kmax, 0.0); + std::vector> expr(jnum, row); + std::vector yrow(3, 0.0); + std::vector> y(jnum, yrow); + std::vector ri(jnum, 0.0); + std::vector dfc(jnum, 0.0); int kb = kmax; int mb = mlength; - double c41[kmax]; - double c51[kmax]; - double c61[kmax]; - double ct[kmax]; + std::vector c41(kmax, 0.0); + std::vector c51(kmax, 0.0); + std::vector c61(kmax, 0.0); + std::vector ct(kmax, 0.0); double *si = sim->s[i]; for (jj = 0; jj < jnum; jj++) { jtype = tn[jj]; From 04cad88b551e7f9ffedcfa272b749f8b9945ee39 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 6 Feb 2025 00:10:17 -0500 Subject: [PATCH 03/50] we can include ML-RANN package now in VLA check --- .github/workflows/check-vla.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-vla.yml b/.github/workflows/check-vla.yml index ab89018a3d..94e367be33 100644 --- a/.github/workflows/check-vla.yml +++ b/.github/workflows/check-vla.yml @@ -77,7 +77,7 @@ jobs: -D PKG_MDI=on \ -D PKG_MANIFOLD=on \ -D PKG_ML-PACE=on \ - -D PKG_ML-RANN=off \ + -D PKG_ML-RANN=on \ -D PKG_MOLFILE=on \ -D PKG_RHEO=on \ -D PKG_PTM=on \ From a547b9a4171da2f1052d9e510c7b61a03c93d3df Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 6 Feb 2025 15:00:54 -0500 Subject: [PATCH 04/50] do not mention rebasing --- .github/release_steps.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/release_steps.md b/.github/release_steps.md index 71388e115a..01b9224114 100644 --- a/.github/release_steps.md +++ b/.github/release_steps.md @@ -28,9 +28,9 @@ Create a 'next\_release' branch off 'develop' and make the following changes: ..versionadded:: or ..versionchanged:: are missing and need to be added -Submit this pull request, rebase if needed. This is the last pull -request merged for the release and should not contain any other -changes. (Exceptions: this document, last minute trivial(!) changes). +Submit this pull request. This is the last pull request merged for the +release and should not contain any other changes. (Exceptions: this +document, last minute trivial(!) changes). This PR shall not be merged before **all** pending tests have completed and cleared. We currently use a mix of automated tests running on From c9f41f9d90ab3cc2d2f5aa1a453450ecf3e77ed9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 6 Feb 2025 17:32:39 -0500 Subject: [PATCH 05/50] explain more steps of the release process related to building packages --- .github/release_steps.md | 178 +++++++++++++++++++--- tools/singularity/README.md | 2 +- tools/singularity/fedora41_musl_mingw.def | 109 +++++++++++++ 3 files changed, 264 insertions(+), 25 deletions(-) create mode 100644 tools/singularity/fedora41_musl_mingw.def diff --git a/.github/release_steps.md b/.github/release_steps.md index 01b9224114..857acfdb85 100644 --- a/.github/release_steps.md +++ b/.github/release_steps.md @@ -35,7 +35,7 @@ document, last minute trivial(!) changes). This PR shall not be merged before **all** pending tests have completed and cleared. We currently use a mix of automated tests running on either Temple's Jenkins cluster or GitHub workflows. Those include time -consuming tests not run on pull requests. If needed, a bugfix pull +consuming tests not run on pull requests. If needed, a bug-fix pull request should be created and merged to clear all tests. ### Create release on GitHub @@ -56,7 +56,7 @@ git pull git checkout release git pull git merge --ff-only develop -git tag -s -m "LAMMPS feature release 19 November 2024" patch_19Nov2024 +git tag -s -m "LAMMPS feature release 4 February 2025" patch_4Feb2025 git push git@github.com:lammps/lammps.git --tags develop release ``` @@ -77,7 +77,7 @@ release page with a summary of all the changes included and references to the pull requests they were merged from or check the existing draft for any necessary changes from pull requests that were merged but are not listed. Then select the applied tag for the release in the "Choose -a tag" dropdown list. Go to the bottom of the list and select the "Set +a tag" drop-down list. Go to the bottom of the list and select the "Set as pre-release" checkbox. The "Set as the latest release" button is reserved for stable releases and updates to them. @@ -87,12 +87,18 @@ you can return to edit the release page and publish it. ### Prepare pre-compiled packages, update packages to GitHub -Build a fully static LAMMPS installation using a musl-libc -cross-compiler, install into a lammps-static folder, and create a -tarball called lammps-linux-x86_64-19Nov2024.tar.gz (or using a -corresponding date with a future release) from the lammps-static folder. A suitable build environment is provided with the -https://download.lammps.org/static/fedora37_musl.sif container image. +https://download.lammps.org/static/fedora41_musl_mingw.sif container +image. The corresponding container build definition file is maintained +in the tools/singularity folder of the LAMMPS source distribution. + +#### Fully portable static Linux x86_64 non-MPI binaries + +The following commands use the Fedora container to build a fully static +LAMMPS installation using a musl-libc cross-compiler, install it into a +`lammps-static` folder, and create a tarball called +`lammps-linux-x86_64-4Feb2025.tar.gz` (or using a corresponding date +with a future release) from the `lammps-static` folder. ``` sh rm -rf release-packages @@ -105,49 +111,173 @@ cmake -S lammps-release/cmake -B build-release -G Ninja -D CMAKE_INSTALL_PREFIX= cmake --build build-release --target all cmake --build build-release --target install /usr/musl/bin/x86_64-linux-musl-strip lammps-static/bin/* -tar -czvvf lammps-linux-x86_64-19Nov2024.tar.gz lammps-static +tar -czvvf ../lammps-linux-x86_64-4Feb2025.tar.gz lammps-static exit # fedora 41 container +cd .. ``` The resulting tar archive can be uploaded to the GitHub release page with: -``` -gh release upload patch_19Nov2024 lammps-linux-x86_64-19Nov2024.tar.gz +``` sh +gh release upload patch_4Feb2025 lammps-linux-x86_64-4Feb2025.tar.gz ``` +#### Linux x86_64 Flatpak bundle with GUI included + Make sure you have the `flatpak` and `flatpak-builder` packages -installed locally (they cannot be used from the container) and build a +installed locally (they require binaries that run with elevated +privileges and thus cannot be used from the container) and build a LAMMPS and LAMMPS-GUI flatpak bundle in the `release-packages` folder with: ``` sh +cd release-packages flatpak --user remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo flatpak-builder --force-clean --verbose --repo=$PWD/flatpak-repo --install-deps-from=flathub --state-dir=$PWD --user --ccache --default-branch=release flatpak-build lammps-release/tools/lammps-gui/org.lammps.lammps-gui.yml -flatpak build-bundle --runtime-repo=https://flathub.org/repo/flathub.flatpakrepo --verbose $PWD/flatpak-repo LAMMPS-Linux-x86_64-GUI-19Nov2024.flatpak org.lammps.lammps-gui release +flatpak build-bundle --runtime-repo=https://flathub.org/repo/flathub.flatpakrepo --verbose $PWD/flatpak-repo ../LAMMPS-Linux-x86_64-GUI-4Feb2025.flatpak org.lammps.lammps-gui release +cd .. ``` The resulting flatpak bundle file can be uploaded to the GitHub release page with: -``` -gh release upload patch_19Nov2024 LAMMPS-Linux-x86_64-GUI-19Nov2024.flatpak +``` sh +gh release upload patch_4Feb2025 LAMMPS-Linux-x86_64-GUI-4Feb2025.flatpak ``` -Also build serial executable packages that also include LAMMPS-GUI for -Linux, macOS, and Windows, and upload them to the GitHub release. +#### LAMMPS Source tarball -Clean up: +The container for the static binary can also be used to prepare the source +tarball including the HTML and PDF manual (this is currently done automatically +when the releases is created and the tarball uploaded to https://download.lammps.org/tars/). +The steps are as follows: + +``` sh +cd release-packages +apptainer shell fedora41_musl_mingw.sif +cd lammps-release +rm -f ../release.tar* +git archive --output=../release.tar --prefix=lammps-4Feb2025/ HEAD +cd doc +make clean-all +make html pdf +tar -rf ../../release.tar --transform 's,^,lammps-4Feb2025/doc/,' html Manual.pdf +gzip -9v ../../release.tar +mv ../../release.tar.gz ../../lammps-src-4Feb2025.tar.gz +exit # fedora41 container +cd .. +``` + +The resulting source tarball can be uploaded to the GitHub release page with: + +``` sh +gh release upload patch_4Feb2025 lammps-src-4Feb2025.tar.gz +``` + +#### Build Windows Installer Packages with MinGW Linux-to-Windows Cross-compiler + +The various Windows installer packages can also be built with +apptainer container image. + +``` sh +cd release-packages +apptainer shell fedora41_musl_mingw.sif +git clone --depth 10 https://github.com/lammps/lammps-packages.git lammps-packages +cd lammps-packages/mingw-cross +ln -sf ../../lammps-release lammps +./buildall.sh release >& mk.log & less +F mk.log +``` + +The installer with the GUI included can be uploaded to the GitHub release page with: + +``` sh +ln -sf LAMMPS-64bit-GUI-4Feb2025.exe LAMMPS-Win10-64bit-GUI-4Feb2025.exe +gh release upload patch_4Feb2025 LAMMPS-Win10-64bit-GUI-4Feb2025.exe +``` + +The symbolic link is used to have a consistent naming scheme for the packages +attached to the GitHub release page. + +#### Clean up: ``` sh cd .. rm -r release-packages ``` -TODO: -- add detailed commands for building GUI packages on Ubuntu 20.04LTS (move to 22.04LTS?), - macOS, and Windows cross-compiler and upload to GitHub -- build all Windows cross-compiled installer packages using lammps-packages repo +#### Build Multi-arch App-bundle for macOS -### Update download website +Building app-bundles for macOS is not as easily automated and portable +as some of the other steps. It requires a machine actually running +macOS. In that machine the Xcode compiler package needs to be +installed. This also includes tools for building and manipulating disk +images. This compiler supports building executables for both, the +x86_64 and the arm64 architectures. This requires building with CMake +and using the CMake settings: + +``` sh +-D CMAKE_OSX_ARCHITECTURES=arm64;x86_64 +-D CMAKE_OSX_DEPLOYMENT_TARGER=11.0 +``` + +This will add the compiler flags `-arch arm64 -arch x86_64 +-mmacosx-version-min=11.0` and thus produce object for both +architectures and support for macOS versions back to version 11 (aka Big +Sur). With these settings the following libraries should be compiled +and installed (e.g. to `$HOME/.local`) as static libraries only: +- libomp taken from the LLVM/Clang source distribution (to support OpenMP) +- jpeg +- zlib +- png +- Qt (for LAMMPS-GUI) + +When configuring LAMMPS the `cmake/presets/clang.cmake` should be used +and as many packages as possible enabled. For LAMMPS-GUI, MPI should be +disabled with `-D BUILD_MPI=OFF` and LAMMPS-GUI enabled with +`-D BUILD_LAMMPS_GUI=ON`. If the CMake configuration is successful, +settings for building a macOS app-bundle are enabled and with `cmake +--build build --target dmg` extra steps will be executed that will build +a macOS application installer image under the name +`LAMMPS_GUI-macOS-multiarch-4Feb2025.dmg` + +The application image can be uploaded to the GitHub release page with: + +``` sh +ln -sf LAMMPS_GUI-macOS-multiarch-4Feb2025.dmg LAMMPS-macOS-multiarch-GUI-4Feb2025.dmg +gh release upload patch_4Feb2025 LAMMPS-macOS-multiarch-GUI-4Feb2025.dmg +``` + +The symbolic link is used to have a consistent naming scheme for the packages +attached to the GitHub release page. + +We are currently building the application images on macOS 12 (aka Monterey). + +#### Build Linux x86_64 binary tarball on Ubuntu 20.04LTS + +While the flatpak Linux version uses portable runtime libraries provided +by the flatpak environment, we also build regular Linux executables that +use a wrapper script and matching shared libraries in a tarball. To be +compatible with many Linux distributions, one has to build this on a +very old Linux distribution, since most Linux system libraries are +usually backward compatible but not forward compatible. This is +currently done on an Ubuntu 20.04LTS system. Once LAMMPS moves to +require CMake 3.20 and C++17, we will have to move to Ubuntu 22.04LTS. +This installation (either on a real or a virtual machine) should have +the packages installed that are indicated in +`tools/singularity/ubuntu20.04.def` plus Qt version 5.x with development +headers, so that LAMMPS-GUI can be compiled. + +Also the building of the binary tarball and setup of the bundled +libraries and wrapper scripts is automated and can executed with `cmake +--build build --target tgz`. This should produce a file +`LAMMPS_GUI-Linux-amd64-4Feb2025.tar.gz` which can be uploaded to the +GitHub release page with: + +``` sh +ln -sf LAMMPS_GUI-Linux-amd64-4Feb2025.tar.gz LAMMPS-Linux-x86_64-GUI-4Feb2025.tar.gz +gh release upload patch_4Feb2025 LAMMPS-Linux-x86_64-GUI-4Feb2025.tar.gz +``` + +### Update download page on LAMMPS website Check out the LAMMPS website repo https://github.com/lammps/lammps-website.git and edit the file @@ -156,7 +286,7 @@ html` and review `html/download.html` Then add and commit to git and push the changes to GitHub. The Temple Jenkis cluster will automatically update https://www.lammps.org/download.html accordingly. -Notify Steve of the release so he can update `src/bug.txt` on the +Also notify Steve of the release so he can update `src/bug.txt` on the website from the available release notes. ## LAMMPS Stable Release diff --git a/tools/singularity/README.md b/tools/singularity/README.md index 4700dac6ec..8f0508b9f0 100644 --- a/tools/singularity/README.md +++ b/tools/singularity/README.md @@ -1,6 +1,6 @@ # Apptainer (aka Singularity) container definitions for compiling/testing LAMMPS -The *.def files in this folder can be used to build container images +The \*.def files in this folder can be used to build container images for [Apptainer](https://apptainer.org) (previously called [Singularity](https://sylabs.io)), suitable for compiling and testing LAMMPS on a variety of OS variants with support for most standard diff --git a/tools/singularity/fedora41_musl_mingw.def b/tools/singularity/fedora41_musl_mingw.def new file mode 100644 index 0000000000..7e15f6590b --- /dev/null +++ b/tools/singularity/fedora41_musl_mingw.def @@ -0,0 +1,109 @@ +BootStrap: docker +From: fedora:41 + +%setup + curl -L -o musl-gcc-f37.tar.gz https://download.lammps.org/static/musl-gcc-f37.tar.gz + cp musl-gcc-f37.tar.gz ${APPTAINER_ROOTFS} + +%post + dnf -y update + dnf -y install vim-enhanced git file make cmake patch which file \ + ninja-build libomp-devel diffutils dos2unix findutils rsync \ + ccache gcc-c++ gcc-gfortran gdb valgrind python3-pyyaml \ + enchant enchant2 python3-enchant python3-virtualenv doxygen latexmk \ + texlive-latex-fonts texlive-pslatex texlive-collection-latexrecommended \ + texlive-latex texlive-latexconfig doxygen-latex texlive-collection-latex \ + texlive-latex-bin texlive-lualatex-math texlive-fncychap texlive-tabulary \ + texlive-framed texlive-wrapfig texlive-upquote texlive-capt-of texlive-pict2e \ + texlive-needspace texlive-titlesec texlive-anysize texlive-dvipng texlive-xindy \ + texlive-fontawesome texlive-ellipse texlive-tex-gyre \ + mingw-filesystem-base mingw32-nsis mingw-binutils-generic \ + mingw64-filesystem mingw64-pkg-config \ + mingw64-crt mingw64-headers mingw64-binutils \ + mingw64-cpp mingw64-gcc mingw64-gcc-gfortran mingw64-gcc-c++ \ + mingw64-curl \ + mingw64-libgomp \ + mingw64-winpthreads \ + mingw64-eigen3 \ + mingw64-fftw \ + mingw64-libjpeg-turbo \ + mingw64-libpng \ + mingw64-python3 \ + mingw64-python3-numpy \ + mingw64-python3-pyyaml \ + mingw64-python3-setuptools \ + mingw64-readline \ + mingw64-termcap \ + mingw64-tcl \ + mingw64-tk \ + mingw64-zlib \ + mingw64-zstd \ + mingw64-qt5-qtdeclarative \ + mingw64-qt5-qmldevtools \ + mingw64-qt5-qmldevtools-devel \ + mingw64-qt5-qttools-tools \ + mingw64-qt5-qtcharts \ + mingw64-qt5-qttools \ + mingw64-qt5-qmake \ + mingw64-qt5-qtbase \ + mingw64-qt5-qtbase-devel \ + mingw64-qt5-qtbase-static \ + + dnf clean all + + # install musl-libc Linux-2-Linux cross-compiler + tar -C /usr/ -xvf /musl-gcc-f37.tar.gz + rm -f /musl-gcc-f37.tar.gz + + # install NSIS EnVar plugin + curl -L -o EnVar_plugin.zip https://nsis.sourceforge.io/mediawiki/images/7/7f/EnVar_plugin.zip + unzip -d /usr/share/nsis EnVar_plugin.zip + rm EnVar_plugin.zip + + # create missing termcap pkgconfig file + cat > /usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig/termcap.pc <$CUSTOM_PROMPT_ENV < Date: Thu, 6 Feb 2025 20:55:23 -0500 Subject: [PATCH 06/50] update copyright year --- tools/lammps-gui/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/lammps-gui/CMakeLists.txt b/tools/lammps-gui/CMakeLists.txt index aee806c81a..b09c6c26d9 100644 --- a/tools/lammps-gui/CMakeLists.txt +++ b/tools/lammps-gui/CMakeLists.txt @@ -279,7 +279,7 @@ if(APPLE) MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE_ICON_FILE lammps.icns - MACOSX_BUNDLE_COPYRIGHT "(c) 2003 - 2024, The LAMMPS Developers" + MACOSX_BUNDLE_COPYRIGHT "(c) 2003 - 2025, The LAMMPS Developers" MACOSX_BUNDLE TRUE ) # additional targets to populate the bundle tree and create the .dmg image file From ab6668031fe47090c50ea6608a65c414f4ec8c62 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 6 Feb 2025 20:55:40 -0500 Subject: [PATCH 07/50] explain some more about transition to C++17 --- doc/src/Build_settings.rst | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/doc/src/Build_settings.rst b/doc/src/Build_settings.rst index e4a53ddee7..53a7a3b761 100644 --- a/doc/src/Build_settings.rst +++ b/doc/src/Build_settings.rst @@ -23,14 +23,15 @@ explains how to do this for building both with CMake and make. .. _cxx11: -C++11 standard compliance -------------------------- +C++11 and C++17 standard compliance +----------------------------------- -A C++11 standard compatible compiler is a requirement for compiling LAMMPS. -LAMMPS version 3 March 2020 is the last version compatible with the previous -C++98 standard for the core code and most packages. Most currently used -C++ compilers are compatible with C++11, but some older ones may need extra -flags to enable C++11 compliance. Example for GNU c++ 4.8.x: +A C++11 standard compatible compiler is currently the minimum +requirement for compiling LAMMPS. LAMMPS version 3 March 2020 is the +last version compatible with the previous C++98 standard for the core +code and most packages. Most currently used C++ compilers are compatible +with C++11, but some older ones may need extra flags to enable C++11 +compliance. Example for GNU c++ 4.8.x: .. code-block:: make @@ -40,6 +41,17 @@ Individual packages may require compliance with a later C++ standard like C++14 or C++17. These requirements will be documented with the :doc:`individual packages `. +.. versionchanged:: 4Feb2025 + +Starting with LAMMPS version 4 February 2025 we are starting a +transition to require the C++17 standard. Most current compilers are +compatible and if the C++17 standard is available by default, LAMMPS +will enable C++17 and will compile normally. If the chosen compiler is +not compatible with C++17, but only supports C++11, then the define +-DLAMMPS_CXX11 is required to fall back to compiling with a C++11 +compiler. After the next stable release of LAMMPS in summer 2025, the +LAMMPS development branch and future releases will require C++17. + ---------- .. _fft: From 1a636acf81a8fcd3cd49f7b5127426045c3b6cd3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 7 Feb 2025 07:34:32 -0500 Subject: [PATCH 08/50] simplify / optimize --- src/REAXFF/fix_reaxff_species.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/REAXFF/fix_reaxff_species.cpp b/src/REAXFF/fix_reaxff_species.cpp index 09c3884c34..5b32ca0528 100644 --- a/src/REAXFF/fix_reaxff_species.cpp +++ b/src/REAXFF/fix_reaxff_species.cpp @@ -965,6 +965,7 @@ void FixReaxFFSpecies::DeleteSpecies(int Nmole, int Nspec) int *mask = atom->mask; double *mass = atom->mass; double *rmass = atom->rmass; + int *type = atom->type; double localmass, totalmass; std::string species_str; @@ -1013,12 +1014,12 @@ void FixReaxFFSpecies::DeleteSpecies(int Nmole, int Nspec) if (!(mask[i] & groupbit)) continue; cid = nint(clusterID[i]); if (cid == m) { - itype = ele2uele[atom->type[i] - 1]; + itype = ele2uele[type[i] - 1]; Name[itype]++; count++; marklist[nmarklist++] = i; if (rmass) localmass += rmass[i]; - else localmass += atom->mass[atom->type[i]]; + else localmass += mass[type[i]]; } } From 61a2db47152aed59cd75cc568e173213446394f7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 7 Feb 2025 19:47:05 -0500 Subject: [PATCH 09/50] revise and expand global README file --- README | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/README b/README index c25506e2c0..6477eb41d3 100644 --- a/README +++ b/README @@ -23,17 +23,20 @@ more information about the code and its uses. The LAMMPS distribution includes the following files and directories: README this file -LICENSE the GNU General Public License (GPL) -bench benchmark problems +LICENSE the GNU General Public License (GPLv2) +CITATION.cff Citation information for LAMMPS in CFF format +bench benchmark inputs cmake CMake build files doc documentation -examples simple test problems -fortran Fortran wrapper for LAMMPS +examples example inputs for many LAMMPS commands +fortran Fortran 2003 module for LAMMPS lib additional provided or external libraries potentials interatomic potential files -python Python wrappers for LAMMPS +python Python module for LAMMPS src source files tools pre- and post-processing tools +unittest test programs for use with CTest +.github Git and GitHub related files and tools Point your browser at any of these files to get started: @@ -42,6 +45,8 @@ https://docs.lammps.org/Intro.html hi-level introduction https://docs.lammps.org/Build.html how to build LAMMPS https://docs.lammps.org/Run_head.html how to run LAMMPS https://docs.lammps.org/Commands_all.html Table of available commands +https://docs.lammps.org/Howto.html Short tutorials and HowTo discussions +https://docs.lammps.org/Errors.html How to interpret and debug errors https://docs.lammps.org/Library.html LAMMPS library interfaces https://docs.lammps.org/Modify.html how to modify and extend LAMMPS https://docs.lammps.org/Developer.html LAMMPS developer info From 6eddb3a33f410d1e8a386e27c83799f1341d541b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 7 Feb 2025 20:50:14 -0500 Subject: [PATCH 10/50] various minor tweaks and reformatting for CMake scripts --- cmake/CMakeLists.txt | 4 +- cmake/Modules/CodeCoverage.cmake | 120 +++++++++++++-------------- cmake/Modules/Documentation.cmake | 6 +- cmake/Modules/Packages/ML-QUIP.cmake | 2 +- cmake/Modules/Packages/PLUMED.cmake | 11 ++- cmake/Modules/Packages/PYTHON.cmake | 2 +- doc/src/Build_settings.rst | 2 +- 7 files changed, 77 insertions(+), 70 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index ff0d69e316..591958f996 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -209,7 +209,7 @@ endif() ######################################################################## # User input options # ######################################################################## -# backward compatibility with CMake before 3.12 and older LAMMPS documentation +# backward compatibility with older LAMMPS documentation if (PYTHON_EXECUTABLE) set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}") endif() @@ -930,7 +930,7 @@ endif() include(Testing) include(CodeCoverage) include(CodingStandard) -find_package(ClangFormat 11.0) +find_package(ClangFormat 11.0 QUIET) if(ClangFormat_FOUND) add_custom_target(format-src diff --git a/cmake/Modules/CodeCoverage.cmake b/cmake/Modules/CodeCoverage.cmake index 21a651e519..885b5cba6d 100644 --- a/cmake/Modules/CodeCoverage.cmake +++ b/cmake/Modules/CodeCoverage.cmake @@ -7,76 +7,76 @@ # For Python coverage the coverage package needs to be installed ############################################################################### if(ENABLE_COVERAGE) - find_program(GCOVR_BINARY gcovr) - find_package_handle_standard_args(GCOVR DEFAULT_MSG GCOVR_BINARY) + find_program(GCOVR_BINARY gcovr) + find_package_handle_standard_args(GCOVR DEFAULT_MSG GCOVR_BINARY) - find_program(COVERAGE_BINARY coverage) - find_package_handle_standard_args(COVERAGE DEFAULT_MSG COVERAGE_BINARY) + find_program(COVERAGE_BINARY coverage) + find_package_handle_standard_args(COVERAGE DEFAULT_MSG COVERAGE_BINARY) - if(GCOVR_FOUND) - get_filename_component(ABSOLUTE_LAMMPS_SOURCE_DIR ${LAMMPS_SOURCE_DIR} ABSOLUTE) + if(GCOVR_FOUND) + get_filename_component(ABSOLUTE_LAMMPS_SOURCE_DIR ${LAMMPS_SOURCE_DIR} ABSOLUTE) - add_custom_target( - gen_coverage_xml - COMMAND ${GCOVR_BINARY} -s -x -r ${ABSOLUTE_LAMMPS_SOURCE_DIR} --object-directory=${CMAKE_BINARY_DIR} -o coverage.xml - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - COMMENT "Generating XML coverage report..." - ) + add_custom_target( + gen_coverage_xml + COMMAND ${GCOVR_BINARY} -s -x -r ${ABSOLUTE_LAMMPS_SOURCE_DIR} --object-directory=${CMAKE_BINARY_DIR} -o coverage.xml + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Generating XML coverage report..." + ) - set(COVERAGE_HTML_DIR ${CMAKE_BINARY_DIR}/coverage_html) + set(COVERAGE_HTML_DIR ${CMAKE_BINARY_DIR}/coverage_html) - add_custom_target(coverage_html_folder - COMMAND ${CMAKE_COMMAND} -E make_directory ${COVERAGE_HTML_DIR}) + add_custom_target(coverage_html_folder + COMMAND ${CMAKE_COMMAND} -E make_directory ${COVERAGE_HTML_DIR}) - add_custom_target( - gen_coverage_html - COMMAND ${GCOVR_BINARY} -s --html --html-details -r ${ABSOLUTE_LAMMPS_SOURCE_DIR} --object-directory=${CMAKE_BINARY_DIR} -o ${COVERAGE_HTML_DIR}/index.html - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - COMMENT "Generating HTML coverage report..." - ) - add_dependencies(gen_coverage_html coverage_html_folder) + add_custom_target( + gen_coverage_html + COMMAND ${GCOVR_BINARY} -s --html --html-details -r ${ABSOLUTE_LAMMPS_SOURCE_DIR} --object-directory=${CMAKE_BINARY_DIR} -o ${COVERAGE_HTML_DIR}/index.html + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Generating HTML coverage report..." + ) + add_dependencies(gen_coverage_html coverage_html_folder) - add_custom_target(clean_coverage_html - ${CMAKE_COMMAND} -E remove_directory ${COVERAGE_HTML_DIR} - COMMENT "Deleting HTML coverage report..." - ) + add_custom_target(clean_coverage_html + ${CMAKE_COMMAND} -E remove_directory ${COVERAGE_HTML_DIR} + COMMENT "Deleting HTML coverage report..." + ) - add_custom_target(reset_coverage - ${CMAKE_COMMAND} -E remove -f */*.gcda */*/*.gcda */*/*/*.gcda - */*/*/*/*.gcda */*/*/*/*/*.gcda */*/*/*/*/*/*.gcda - */*/*/*/*/*/*/*.gcda */*/*/*/*/*/*/*/*.gcda - */*/*/*/*/*/*/*/*/*.gcda */*/*/*/*/*/*/*/*/*/*.gcda - WORKIND_DIRECTORY ${CMAKE_BINARY_DIR} - COMMENT "Deleting coverage data files..." - ) - add_dependencies(reset_coverage clean_coverage_html) - endif() + add_custom_target(reset_coverage + ${CMAKE_COMMAND} -E remove -f */*.gcda */*/*.gcda */*/*/*.gcda + */*/*/*/*.gcda */*/*/*/*/*.gcda */*/*/*/*/*/*.gcda + */*/*/*/*/*/*/*.gcda */*/*/*/*/*/*/*/*.gcda + */*/*/*/*/*/*/*/*/*.gcda */*/*/*/*/*/*/*/*/*/*.gcda + WORKIND_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Deleting coverage data files..." + ) + add_dependencies(reset_coverage clean_coverage_html) + endif() - if(COVERAGE_FOUND) - set(PYTHON_COVERAGE_HTML_DIR ${CMAKE_BINARY_DIR}/python_coverage_html) - configure_file(.coveragerc.in ${CMAKE_BINARY_DIR}/.coveragerc @ONLY) + if(COVERAGE_FOUND) + set(PYTHON_COVERAGE_HTML_DIR ${CMAKE_BINARY_DIR}/python_coverage_html) + configure_file(.coveragerc.in ${CMAKE_BINARY_DIR}/.coveragerc @ONLY) - add_custom_command( - OUTPUT ${CMAKE_BINARY_DIR}/unittest/python/.coverage - COMMAND ${COVERAGE_BINARY} combine - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/unittest/python - COMMENT "Combine Python coverage files..." - ) + add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/unittest/python/.coverage + COMMAND ${COVERAGE_BINARY} combine + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/unittest/python + COMMENT "Combine Python coverage files..." + ) - add_custom_target( - gen_python_coverage_html - COMMAND ${COVERAGE_BINARY} html --rcfile=${CMAKE_BINARY_DIR}/.coveragerc -d ${PYTHON_COVERAGE_HTML_DIR} - DEPENDS ${CMAKE_BINARY_DIR}/unittest/python/.coverage ${CMAKE_BINARY_DIR}/.coveragerc - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/unittest/python - COMMENT "Generating HTML Python coverage report..." - ) + add_custom_target( + gen_python_coverage_html + COMMAND ${COVERAGE_BINARY} html --rcfile=${CMAKE_BINARY_DIR}/.coveragerc -d ${PYTHON_COVERAGE_HTML_DIR} + DEPENDS ${CMAKE_BINARY_DIR}/unittest/python/.coverage ${CMAKE_BINARY_DIR}/.coveragerc + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/unittest/python + COMMENT "Generating HTML Python coverage report..." + ) - add_custom_target( - gen_python_coverage_xml - COMMAND ${COVERAGE_BINARY} xml --rcfile=${CMAKE_BINARY_DIR}/.coveragerc -o ${CMAKE_BINARY_DIR}/python_coverage.xml - DEPENDS ${CMAKE_BINARY_DIR}/unittest/python/.coverage ${CMAKE_BINARY_DIR}/.coveragerc - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/unittest/python - COMMENT "Generating XML Python coverage report..." - ) - endif() + add_custom_target( + gen_python_coverage_xml + COMMAND ${COVERAGE_BINARY} xml --rcfile=${CMAKE_BINARY_DIR}/.coveragerc -o ${CMAKE_BINARY_DIR}/python_coverage.xml + DEPENDS ${CMAKE_BINARY_DIR}/unittest/python/.coverage ${CMAKE_BINARY_DIR}/.coveragerc + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/unittest/python + COMMENT "Generating XML Python coverage report..." + ) + endif() endif() diff --git a/cmake/Modules/Documentation.cmake b/cmake/Modules/Documentation.cmake index dfaf7bdb39..511d54114c 100644 --- a/cmake/Modules/Documentation.cmake +++ b/cmake/Modules/Documentation.cmake @@ -13,7 +13,7 @@ if(BUILD_DOC) endif() find_package(Python3 REQUIRED COMPONENTS Interpreter) if(Python3_VERSION VERSION_LESS 3.8) - message(FATAL_ERROR "Python 3.8 and up is required to build the HTML documentation") + message(FATAL_ERROR "Python 3.8 and up is required to build the LAMMPS HTML documentation") endif() set(VIRTUALENV ${Python3_EXECUTABLE} -m venv) @@ -65,8 +65,8 @@ if(BUILD_DOC) find_package(Sphinx) endif() - set(MATHJAX_URL "https://github.com/mathjax/MathJax/archive/3.1.3.tar.gz" CACHE STRING "URL for MathJax tarball") - set(MATHJAX_MD5 "b81661c6e6ba06278e6ae37b30b0c492" CACHE STRING "MD5 checksum of MathJax tarball") + set(MATHJAX_URL "https://github.com/mathjax/MathJax/archive/3.2.2.tar.gz" CACHE STRING "URL for MathJax tarball") + set(MATHJAX_MD5 "08dd6ef33ca08870220d9aade2a62845" CACHE STRING "MD5 checksum of MathJax tarball") mark_as_advanced(MATHJAX_URL) GetFallbackURL(MATHJAX_URL MATHJAX_FALLBACK) diff --git a/cmake/Modules/Packages/ML-QUIP.cmake b/cmake/Modules/Packages/ML-QUIP.cmake index 9106ff54ef..aad6ee5e34 100644 --- a/cmake/Modules/Packages/ML-QUIP.cmake +++ b/cmake/Modules/Packages/ML-QUIP.cmake @@ -37,7 +37,7 @@ if(DOWNLOAD_QUIP) endforeach() # Fix cmake crashing when MATH_LINKOPTS not set, required for e.g. recent Cray Programming Environment set(temp "${temp} -L/_DUMMY_PATH_\n") - set(temp "${temp}PYTHON=python\nPIP=pip\nEXTRA_LINKOPTS=\n") + set(temp "${temp}PYTHON=${Python_EXECUTABLE}\nPIP=pip\nEXTRA_LINKOPTS=\n") set(temp "${temp}HAVE_CP2K=0\nHAVE_VASP=0\nHAVE_TB=0\nHAVE_PRECON=1\nHAVE_LOTF=0\nHAVE_ONIOM=0\n") set(temp "${temp}HAVE_LOCAL_E_MIX=0\nHAVE_QC=0\nHAVE_GAP=1\nHAVE_DESCRIPTORS_NONCOMMERCIAL=1\n") set(temp "${temp}HAVE_TURBOGAP=0\nHAVE_QR=1\nHAVE_THIRDPARTY=0\nHAVE_FX=0\nHAVE_SCME=0\nHAVE_MTP=0\n") diff --git a/cmake/Modules/Packages/PLUMED.cmake b/cmake/Modules/Packages/PLUMED.cmake index 5e5d110626..1b4845d259 100644 --- a/cmake/Modules/Packages/PLUMED.cmake +++ b/cmake/Modules/Packages/PLUMED.cmake @@ -40,6 +40,13 @@ mark_as_advanced(PLUMED_URL) mark_as_advanced(PLUMED_MD5) GetFallbackURL(PLUMED_URL PLUMED_FALLBACK) +# adjust C++ standard support for self-compiled Plumed2 +if(CMAKE_CXX_STANDARD GREATER 11) + set(PLUMED_CXX_STANDARD 14) +else() + set(PLUMED_CXX_STANDARD 11) +endif() + if((CMAKE_SYSTEM_NAME STREQUAL "Windows") AND (CMAKE_CROSSCOMPILING)) if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") set(CROSS_CONFIGURE mingw64-configure) @@ -55,7 +62,7 @@ if((CMAKE_SYSTEM_NAME STREQUAL "Windows") AND (CMAKE_CROSSCOMPILING)) URL_MD5 ${PLUMED_MD5} BUILD_IN_SOURCE 1 CONFIGURE_COMMAND ${CROSS_CONFIGURE} --disable-shared --disable-bsymbolic - --disable-python --enable-cxx=11 + --disable-python --enable-cxx=${PLUMED_CXX_STANDARD} --enable-modules=-adjmat:+crystallization:-dimred:+drr:+eds:-fisst:+funnel:+logmfd:+manyrestraints:+maze:+opes:+multicolvar:-pamm:-piv:+s2cm:-sasa:-ves ${PLUMED_CONFIG_OMP} ${PLUMED_CONFIG_MPI} @@ -142,7 +149,7 @@ else() CONFIGURE_COMMAND /configure --prefix= ${CONFIGURE_REQUEST_PIC} --enable-modules=all - --enable-cxx=11 + --enable-cxx=${PLUMED_CXX_STANDARD} --disable-python ${PLUMED_CONFIG_MPI} ${PLUMED_CONFIG_OMP} diff --git a/cmake/Modules/Packages/PYTHON.cmake b/cmake/Modules/Packages/PYTHON.cmake index e05edadbf3..0879382ed7 100644 --- a/cmake/Modules/Packages/PYTHON.cmake +++ b/cmake/Modules/Packages/PYTHON.cmake @@ -1,6 +1,6 @@ if(NOT Python_INTERPRETER) - # backward compatibility with CMake before 3.12 and older LAMMPS documentation + # backward compatibility with older LAMMPS documentation if(PYTHON_EXECUTABLE) set(Python_EXECUTABLE ${PYTHON_EXECUTABLE}) endif() diff --git a/doc/src/Build_settings.rst b/doc/src/Build_settings.rst index 53a7a3b761..fb3ebf4b48 100644 --- a/doc/src/Build_settings.rst +++ b/doc/src/Build_settings.rst @@ -8,7 +8,7 @@ Optional build settings LAMMPS can be built with several optional settings. Each subsection explains how to do this for building both with CMake and make. -* `C++11 standard compliance`_ when building all of LAMMPS +* `C++11 and C++17 standard compliance`_ when building all of LAMMPS * `FFT library`_ for use with the :doc:`kspace_style pppm ` command * `Size of LAMMPS integer types and size limits`_ * `Read or write compressed files`_ From b188cdc0444a5167a1329c34af81a51fe71be327 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 7 Feb 2025 20:51:50 -0500 Subject: [PATCH 11/50] add check for Python version. Require minimum of Python 3.6 (Sphinx requires 3.8) --- cmake/CMakeLists.txt | 6 +++ cmake/Modules/CodingStandard.cmake | 67 ++++++++++++++--------------- cmake/Modules/Packages/ML-IAP.cmake | 4 +- 3 files changed, 40 insertions(+), 37 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index ff0d69e316..63dc1a08a4 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -225,6 +225,12 @@ if(DEFINED ENV{VIRTUAL_ENV} AND NOT Python_EXECUTABLE) " Setting Python interpreter to: ${Python_EXECUTABLE}") endif() +find_package(Python COMPONENTS Interpreter QUIET) +# NOTE: RHEL 8.0 and Ubuntu 18.04LTS ship with Python 3.6, Python 3.8 was EOL in 2024 +if(Python_VERSION VERSION_LESS 3.6) + message(FATAL_ERROR "LAMMPS requires Python 3.6 or later") +endif() + set(LAMMPS_MACHINE "" CACHE STRING "Suffix to append to lmp binary (WON'T enable any features automatically") mark_as_advanced(LAMMPS_MACHINE) if(LAMMPS_MACHINE) diff --git a/cmake/Modules/CodingStandard.cmake b/cmake/Modules/CodingStandard.cmake index 94639c7771..4e99c2e39c 100644 --- a/cmake/Modules/CodingStandard.cmake +++ b/cmake/Modules/CodingStandard.cmake @@ -1,40 +1,39 @@ -# use default (or custom) Python executable, if version is sufficient -if(Python_VERSION VERSION_GREATER_EQUAL 3.6) +# use default (or custom) Python executable. +# Python version check is in main CMakeLists.txt file +if(Python_EXECUTABLE) set(Python3_EXECUTABLE ${Python_EXECUTABLE}) endif() find_package(Python3 COMPONENTS Interpreter) if(Python3_EXECUTABLE) - if(Python3_VERSION VERSION_GREATER_EQUAL 3.6) - add_custom_target( - check-whitespace - ${Python3_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/whitespace.py . - WORKING_DIRECTORY ${LAMMPS_DIR} - COMMENT "Check for whitespace errors") - add_custom_target( - check-homepage - ${Python3_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/homepage.py . - WORKING_DIRECTORY ${LAMMPS_DIR} - COMMENT "Check for homepage URL errors") - add_custom_target( - check-permissions - ${Python3_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/permissions.py . - WORKING_DIRECTORY ${LAMMPS_DIR} - COMMENT "Check for permission errors") - add_custom_target( - fix-whitespace - ${Python3_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/whitespace.py -f . - WORKING_DIRECTORY ${LAMMPS_DIR} - COMMENT "Fix whitespace errors") - add_custom_target( - fix-homepage - ${Python3_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/homepage.py -f . - WORKING_DIRECTORY ${LAMMPS_DIR} - COMMENT "Fix homepage URL errors") - add_custom_target( - fix-permissions - ${Python3_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/permissions.py -f . - WORKING_DIRECTORY ${LAMMPS_DIR} - COMMENT "Fix permission errors") - endif() + add_custom_target( + check-whitespace + ${Python3_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/whitespace.py . + WORKING_DIRECTORY ${LAMMPS_DIR} + COMMENT "Check for whitespace errors") + add_custom_target( + check-homepage + ${Python3_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/homepage.py . + WORKING_DIRECTORY ${LAMMPS_DIR} + COMMENT "Check for homepage URL errors") + add_custom_target( + check-permissions + ${Python3_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/permissions.py . + WORKING_DIRECTORY ${LAMMPS_DIR} + COMMENT "Check for permission errors") + add_custom_target( + fix-whitespace + ${Python3_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/whitespace.py -f . + WORKING_DIRECTORY ${LAMMPS_DIR} + COMMENT "Fix whitespace errors") + add_custom_target( + fix-homepage + ${Python3_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/homepage.py -f . + WORKING_DIRECTORY ${LAMMPS_DIR} + COMMENT "Fix homepage URL errors") + add_custom_target( + fix-permissions + ${Python3_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/permissions.py -f . + WORKING_DIRECTORY ${LAMMPS_DIR} + COMMENT "Fix permission errors") endif() diff --git a/cmake/Modules/Packages/ML-IAP.cmake b/cmake/Modules/Packages/ML-IAP.cmake index 91b772efb5..1691af8d95 100644 --- a/cmake/Modules/Packages/ML-IAP.cmake +++ b/cmake/Modules/Packages/ML-IAP.cmake @@ -24,9 +24,7 @@ if(MLIAP_ENABLE_PYTHON) if(NOT PKG_PYTHON) message(FATAL_ERROR "Must enable PYTHON package for including Python support in ML-IAP") endif() - if(Python_VERSION VERSION_LESS 3.6) - message(FATAL_ERROR "Python support in ML-IAP requires Python 3.6 or later") - endif() + # Python version check is in main CMakeLists.txt file set(MLIAP_BINARY_DIR ${CMAKE_BINARY_DIR}/cython) file(GLOB MLIAP_CYTHON_SRC CONFIGURE_DEPENDS ${LAMMPS_SOURCE_DIR}/ML-IAP/*.pyx) From 8a1744c038072e0b7c39bd8eeb5496a0abaaf77c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 7 Feb 2025 21:51:37 -0500 Subject: [PATCH 12/50] Updates to the instructions for building the manual. --- doc/README | 20 ++++++++++++------ doc/src/Build_manual.rst | 45 ++++++++++++++++++++++++++++++---------- 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/doc/README b/doc/README index de956a96bb..f96e0b14da 100644 --- a/doc/README +++ b/doc/README @@ -22,12 +22,12 @@ doxygen-warn.log logfile with warnings from running doxygen and: github-development-workflow.md notes on the LAMMPS development workflow -include-file-conventions.md notes on LAMMPS' include file conventions documentation_conventions.md notes on writing documentation for LAMMPS If you downloaded a LAMMPS tarball from www.lammps.org, then the html folder and the PDF manual should be included. If you downloaded LAMMPS -from GitHub then you either need to build them. +using GitHub then you either need to build them yourself or read the +online version at https://docs.lammps.org/ You can build the HTML and PDF files yourself, by typing "make html" or by "make pdf", respectively. This requires various tools and files. @@ -39,10 +39,10 @@ environment and local folders. Installing prerequisites for the documentation build -To run the HTML documention build toolchain, python 3.x, doxygen, git, -and the venv python module have to be installed if not already available. -Also internet access is initially required to download external files -and tools. +To run the HTML documention build toolchain, python 3.8 or later, +doxygen 1.8.10 or later, git, and the venv python module have to be +installed if not already available. Also internet access is initially +required to download external files and tools. Building the PDF format manual requires in addition a compatible LaTeX installation with support for PDFLaTeX and several add-on LaTeX packages @@ -52,16 +52,24 @@ installed. This includes: - babel - capt-of - cmap +- dvipng +- ellipse - fncychap +- fontawesom - framed - geometry +- gyre - hyperref - hypcap - needspace +- pict2e - times - tabulary +- titlesec - upquote - wrapfig +- xindy + Also the latexmk script is required to run PDFLaTeX and related tools. the required number of times to have self-consistent output and include updated bibliography and indices. diff --git a/doc/src/Build_manual.rst b/doc/src/Build_manual.rst index 4b4bfa5a45..490594af02 100644 --- a/doc/src/Build_manual.rst +++ b/doc/src/Build_manual.rst @@ -116,9 +116,9 @@ environment variable. Prerequisites for HTML ---------------------- -To run the HTML documentation build toolchain, python 3, git, doxygen, -and virtualenv have to be installed locally. Here are instructions for -common setups: +To run the HTML documentation build toolchain, Python 3.8 or later, git, +doxygen, and virtualenv have to be installed locally. Here are +instructions for common setups: .. tabs:: @@ -128,13 +128,7 @@ common setups: sudo apt-get install git doxygen - .. tab:: RHEL or CentOS (Version 7.x) - - .. code-block:: bash - - sudo yum install git doxygen - - .. tab:: Fedora or RHEL/CentOS (8.x or later) + .. tab:: Fedora or RHEL/AlmaLinux/RockyLinux (8.x or later) .. code-block:: bash @@ -154,7 +148,36 @@ Prerequisites for PDF In addition to the tools needed for building the HTML format manual, a working LaTeX installation with support for PDFLaTeX and a selection -of LaTeX styles/packages are required. To run the PDFLaTeX translation +of LaTeX styles/packages are required. Apart from LaTeX packages that +are usually installed by default, the following packages are required: + +.. table_from_list:: + :columns: 11 + + - amsmath + - anysize + - babel + - capt-of + - cmap + - dvipng + - ellipse + - fncychap + - fontawesom + - framed + - geometry + - gyre + - hyperref + - hypcap + - needspace + - pict2e + - times + - tabulary + - titlesec + - upquote + - wrapfig + - xindy + +To run the PDFLaTeX translation the ``latexmk`` script needs to be installed as well. Prerequisites for ePUB and MOBI From 86f7f6da98f8a0573731de612c7e8bbfbd5c1839 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 7 Feb 2025 21:52:17 -0500 Subject: [PATCH 13/50] Add check that Python 3 is required --- src/Makefile | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Makefile b/src/Makefile index 3de8eb85d5..f4eafbf299 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,6 +2,12 @@ SHELL = /bin/bash PYTHON = python +PYTHON_VERSION=$(word 2,$(shell $(PYTHON) -V 2>&1 | tr '.' ' ')) +ifeq ($(PYTHON_VERSION),2) +PYTHON_CHECK=@echo LAMMPS requires Python 3. Try: 'make PYTHON=python3 ...' ; exit 1 +else +PYTHON_CHECK=@echo +endif DYN_LIB = -ldl #.IGNORE: @@ -276,7 +282,7 @@ LIBDIR = $(@:lib-%=%) # List of all targets help: - @echo '' + $(PYTHON_CHECK) @echo 'make clean-all delete all object files' @echo 'make clean-machine delete object files for one machine' @echo 'make mpi-stubs build dummy MPI library in STUBS' @@ -378,6 +384,7 @@ gitversion: # shared = shared compile in Obj_shared_machine .DEFAULT: + $(PYTHON_CHECK) @if [ $@ = "serial" ]; \ then cd STUBS; $(MAKE); cd ..; fi @test -f MAKE/Makefile.$@ -o -f MAKE/OPTIONS/Makefile.$@ -o \ @@ -465,6 +472,7 @@ mpi-stubs: sinclude ../lib/python/Makefile.lammps install-python: + $(PYTHON_CHECK) @rm -rf ../python/build @$(PYTHON) ../python/install.py -p ../python/lammps -l ../src/liblammps.so -w $(PWD) -v $(PWD)/version.h @@ -483,49 +491,59 @@ tar: check: check-whitespace check-permissions check-homepage check-errordocs check-fmtlib check-docs check-version check-whitespace: + $(PYTHON_CHECK) $(PYTHON) ../tools/coding_standard/whitespace.py .. fix-whitespace: + $(PYTHON_CHECK) $(PYTHON) ../tools/coding_standard/whitespace.py .. -f check-permissions: + $(PYTHON_CHECK) $(PYTHON) ../tools/coding_standard/permissions.py .. fix-permissions: + $(PYTHON_CHECK) $(PYTHON) ../tools/coding_standard/permissions.py .. -f check-homepage: + $(PYTHON_CHECK) $(PYTHON) ../tools/coding_standard/homepage.py .. fix-homepage: + $(PYTHON_CHECK) $(PYTHON) ../tools/coding_standard/homepage.py .. -f check-errordocs: + $(PYTHON_CHECK) $(PYTHON) ../tools/coding_standard/errordocs.py .. fix-errordocs: + $(PYTHON_CHECK) $(PYTHON) ../tools/coding_standard/errordocs.py .. -f check-fmtlib: + $(PYTHON_CHECK) $(PYTHON) ../tools/coding_standard/fmtlib.py .. fix-fmtlib: + $(PYTHON_CHECK) $(PYTHON) ../tools/coding_standard/fmtlib.py .. -f check-docs: + $(PYTHON_CHECK) $(MAKE) $(MFLAGS) -C ../doc anchor_check style_check package_check role_check check-version: + $(PYTHON_CHECK) $(PYTHON) ../tools/coding_standard/versiontags.py .. || echo - format-src: clang-format -i --verbose --style=file *.cpp *.h */*.cpp */*.h format-tests: clang-format -i --verbose --style=file ../unittest/*/*.cpp ../unittest/*/*.h - # Package management package: From 599ff11eb0cdcc03320f814fdf15bdee2d8dca23 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 8 Feb 2025 05:05:00 -0500 Subject: [PATCH 14/50] remove compatibility for compiling LAMMPS with Python 2.x and Python 3.5 and older --- lib/python/Makefile.lammps.python2 | 7 ----- ...s.python2.7 => Makefile.lammps.python3.13} | 0 lib/python/README | 27 +++++++++---------- src/KOKKOS/mliap_model_python_kokkos.cpp | 4 +-- src/ML-IAP/mliap_model_python.cpp | 4 +-- src/PYTHON/fix_python_invoke.cpp | 2 +- src/PYTHON/fix_python_move.cpp | 4 +-- src/PYTHON/pair_python.cpp | 4 +-- src/PYTHON/python_compat.h | 21 +++------------ src/PYTHON/python_impl.cpp | 8 +++--- 10 files changed, 29 insertions(+), 52 deletions(-) delete mode 100644 lib/python/Makefile.lammps.python2 rename lib/python/{Makefile.lammps.python2.7 => Makefile.lammps.python3.13} (100%) diff --git a/lib/python/Makefile.lammps.python2 b/lib/python/Makefile.lammps.python2 deleted file mode 100644 index 7b54b4c3df..0000000000 --- a/lib/python/Makefile.lammps.python2 +++ /dev/null @@ -1,7 +0,0 @@ -# Settings that the LAMMPS build will import when this package library is used -# See the README file for more explanation - -python_SYSINC = $(shell which python2-config > /dev/null 2>&1 && python2-config --includes || (which python-config > /dev/null 2>&1 && python-config --includes || :)) -python_SYSLIB = $(shell which python2-config > /dev/null 2>&1 && python2-config --ldflags || (which python-config > /dev/null 2>&1 && python-config --ldflags || :)) -python_SYSPATH = -PYTHON=$(shell which python2 > /dev/null 2>&1 && echo python2 || echo python) diff --git a/lib/python/Makefile.lammps.python2.7 b/lib/python/Makefile.lammps.python3.13 similarity index 100% rename from lib/python/Makefile.lammps.python2.7 rename to lib/python/Makefile.lammps.python3.13 diff --git a/lib/python/README b/lib/python/README index 8de2bc4bd7..c84b291f05 100644 --- a/lib/python/README +++ b/lib/python/README @@ -9,30 +9,29 @@ installation. If needed, you can copy one of the other provided Makefile.lammps.* files to to Makefile.lammps before building LAMMPS itself. -The files Makefile.lammps.python2 and Makefile.lammps.python3 are -similar to the default file, but meant for the case that both, -python 2 and python 3, are installed simultaneously and you want -to prefer one over the other. If neither of these files work, you -may have to create a custom Makefile.lammps file suitable for -the version of Python on your system. To illustrate, these are -example settings from the Makefile.lammps.python2.7 file: +The file Makefile.lammps.python3 is similar to the default file, but +meant for the case that both, python 2 and python 3, are installed +simultaneously. LAMMPS only supports python 3. If neither of these +files work, you may have to create a custom Makefile.lammps file +suitable for the version of Python on your system. To illustrate, these +are example settings from the Makefile.lammps.python3.13 file: -python_SYSINC = -I/usr/local/include/python2.7 -python_SYSLIB = -lpython2.7 -lnsl -ldl -lreadline -ltermcap -lpthread -lutil -lm -python_SYSPATH = -PYTHON=python2.7 +python_SYSINC = -I/usr/local/include/python3.13 +python_SYSLIB = -lpython3.13 -ldl -lm +python_SYSPATH = -L/usr/lib64 +PYTHON=python3.13 python_SYSINC refers to the directory where Python's Python.h file is found. LAMMPS includes this file. python_SYSLIB refers to the libraries needed to link to from an application (LAMMPS in this case) to "embed" Python in the -application. The Python library itself is listed (-lpython2.7) are +application. The Python library itself is listed (-lpython3.13) are are several system libraries needed by Python. python_SYSPATH refers to the path (e.g. -L/usr/local/lib) where the Python library can be found. You may not need this setting if the -path is already included in your LD_LIBRARY_PATH environment variable. +path is already included in your LIBRARY_PATH environment variable. PYTHON is the name of the python interpreter. It is used for installing the LAMMPS python module with "make install-python" @@ -45,7 +44,7 @@ run in embedded mode on your machine. Here is what this Python doc page says about it: -https://docs.python.org/2/extending/embedding.html#compiling-and-linking-under-unix-like-systems +https://docs.python.org/3/extending/embedding.html#compiling-and-linking-under-unix-like-systems "It is not necessarily trivial to find the right flags to pass to your compiler (and linker) in order to embed the Python interpreter into diff --git a/src/KOKKOS/mliap_model_python_kokkos.cpp b/src/KOKKOS/mliap_model_python_kokkos.cpp index 4435a0371a..1b010cc286 100644 --- a/src/KOKKOS/mliap_model_python_kokkos.cpp +++ b/src/KOKKOS/mliap_model_python_kokkos.cpp @@ -68,12 +68,12 @@ MLIAPModelPythonKokkos::MLIAPModelPythonKokkos(LAMMPS *lmp, char *co // Recipe from lammps/src/pair_python.cpp : // add current directory to PYTHONPATH PyObject *py_path = PySys_GetObject((char *) "path"); - PyList_Append(py_path, PY_STRING_FROM_STRING(".")); + PyList_Append(py_path, PyUnicode_FromString(".")); // if LAMMPS_POTENTIALS environment variable is set, add it to PYTHONPATH as well const char *potentials_path = getenv("LAMMPS_POTENTIALS"); if (potentials_path != nullptr) { - PyList_Append(py_path, PY_STRING_FROM_STRING(potentials_path)); + PyList_Append(py_path, PyUnicode_FromString(potentials_path)); } PyGILState_Release(gstate); if (coefffilename) read_coeffs(coefffilename); diff --git a/src/ML-IAP/mliap_model_python.cpp b/src/ML-IAP/mliap_model_python.cpp index c06bbdc121..c1c534401a 100644 --- a/src/ML-IAP/mliap_model_python.cpp +++ b/src/ML-IAP/mliap_model_python.cpp @@ -62,12 +62,12 @@ MLIAPModelPython::MLIAPModelPython(LAMMPS *lmp, char *coefffilename, bool is_chi // Recipe from lammps/src/pair_python.cpp : // add current directory to PYTHONPATH PyObject *py_path = PySys_GetObject((char *) "path"); - PyList_Append(py_path, PY_STRING_FROM_STRING(".")); + PyList_Append(py_path, PyUnicode_FromString(".")); // if LAMMPS_POTENTIALS environment variable is set, add it to PYTHONPATH as well const char *potentials_path = getenv("LAMMPS_POTENTIALS"); if (potentials_path != nullptr) { - PyList_Append(py_path, PY_STRING_FROM_STRING(potentials_path)); + PyList_Append(py_path, PyUnicode_FromString(potentials_path)); } PyGILState_Release(gstate); if (coefffilename) read_coeffs(coefffilename); diff --git a/src/PYTHON/fix_python_invoke.cpp b/src/PYTHON/fix_python_invoke.cpp index 6f27831438..2485371690 100644 --- a/src/PYTHON/fix_python_invoke.cpp +++ b/src/PYTHON/fix_python_invoke.cpp @@ -70,7 +70,7 @@ FixPythonInvoke::FixPythonInvoke(LAMMPS *lmp, int narg, char **arg) : error->all(FLERR,"Could not find Python function"); } - lmpPtr = PY_VOID_POINTER(lmp); + lmpPtr = PyCapsule_New((void *)lmp, nullptr, nullptr); // nvalid = next step on which end_of_step or post_force does something // add nextvalid() to all computes that store invocation times diff --git a/src/PYTHON/fix_python_move.cpp b/src/PYTHON/fix_python_move.cpp index caa1557503..c0be31dee6 100644 --- a/src/PYTHON/fix_python_move.cpp +++ b/src/PYTHON/fix_python_move.cpp @@ -44,7 +44,7 @@ FixPythonMove::FixPythonMove(LAMMPS *lmp, int narg, char **arg) : // add current directory to PYTHONPATH PyObject *py_path = PySys_GetObject((char *)"path"); - PyList_Append(py_path, PY_STRING_FROM_STRING(".")); + PyList_Append(py_path, PyUnicode_FromString(".")); // create integrator instance @@ -73,7 +73,7 @@ FixPythonMove::FixPythonMove(LAMMPS *lmp, int narg, char **arg) : error->all(FLERR,"Could not find integrator class {} in module {}", cls_name, module_name); } - PyObject *ptr = PY_VOID_POINTER(lmp); + PyObject *ptr = PyCapsule_New((void *)lmp, nullptr, nullptr); PyObject *py_move_obj = PyObject_CallFunction(py_move_type, (char *)"O", ptr); Py_CLEAR(ptr); diff --git a/src/PYTHON/pair_python.cpp b/src/PYTHON/pair_python.cpp index 695954604c..0f7baa0104 100644 --- a/src/PYTHON/pair_python.cpp +++ b/src/PYTHON/pair_python.cpp @@ -54,14 +54,14 @@ PairPython::PairPython(LAMMPS *lmp) : Pair(lmp) { PyUtils::GIL lock; PyObject *py_path = PySys_GetObject((char *)"path"); - PyList_Append(py_path, PY_STRING_FROM_STRING(".")); + PyList_Append(py_path, PyUnicode_FromString(".")); // if LAMMPS_POTENTIALS environment variable is set, // add it to PYTHONPATH as well const char *potentials_path = getenv("LAMMPS_POTENTIALS"); if (potentials_path != nullptr) { - PyList_Append(py_path, PY_STRING_FROM_STRING(potentials_path)); + PyList_Append(py_path, PyUnicode_FromString(potentials_path)); } } diff --git a/src/PYTHON/python_compat.h b/src/PYTHON/python_compat.h index d1194056d8..88c0969a59 100644 --- a/src/PYTHON/python_compat.h +++ b/src/PYTHON/python_compat.h @@ -16,22 +16,11 @@ #include -// Wrap API changes between Python 2 and 3 using macros -#if PY_MAJOR_VERSION == 2 -#if defined(_MSC_VER) || defined(__MINGW32__) -#define PY_INT_FROM_LONG(X) PyLong_FromLongLong(X) -#define PY_INT_AS_LONG(X) PyLong_AsLongLong(X) -#define PY_LONG_FROM_STRING(X) std::stoll(X) -#else -#define PY_INT_FROM_LONG(X) PyInt_FromLong(X) -#define PY_INT_AS_LONG(X) PyInt_AsLong(X) -#define PY_LONG_FROM_STRING(X) std::stol(X) +#if PY_VERSION_HEX < 0x030600f0 +#error Python version 3.6 or later is required by LAMMPS #endif -#define PY_STRING_FROM_STRING(X) PyString_FromString(X) -#define PY_VOID_POINTER(X) PyCObject_FromVoidPtr((void *) X, nullptr) -#define PY_STRING_AS_STRING(X) PyString_AsString(X) -#elif PY_MAJOR_VERSION == 3 +// Wrap API differences between platforms using macros #if defined(_MSC_VER) || defined(__MINGW32__) #define PY_INT_FROM_LONG(X) PyLong_FromLongLong(X) #define PY_INT_AS_LONG(X) PyLong_AsLongLong(X) @@ -41,9 +30,5 @@ #define PY_INT_AS_LONG(X) PyLong_AsLong(X) #define PY_LONG_FROM_STRING(X) std::stol(X) #endif -#define PY_STRING_FROM_STRING(X) PyUnicode_FromString(X) -#define PY_VOID_POINTER(X) PyCapsule_New((void *) X, nullptr, nullptr) -#define PY_STRING_AS_STRING(X) PyUnicode_AsUTF8(X) -#endif #endif diff --git a/src/PYTHON/python_impl.cpp b/src/PYTHON/python_impl.cpp index 91e0a7abe5..e4ec8d74d8 100644 --- a/src/PYTHON/python_impl.cpp +++ b/src/PYTHON/python_impl.cpp @@ -361,12 +361,12 @@ void PythonImpl::invoke_function(int ifunc, char *result) if (!str) error->all(FLERR, "Could not evaluate Python function {} input variable: {}", pfuncs[ifunc].name, pfuncs[ifunc].svalue[i]); - pValue = PY_STRING_FROM_STRING(str); + pValue = PyUnicode_FromString(str); } else { - pValue = PY_STRING_FROM_STRING(pfuncs[ifunc].svalue[i]); + pValue = PyUnicode_FromString(pfuncs[ifunc].svalue[i]); } } else if (itype == PTR) { - pValue = PY_VOID_POINTER(lmp); + pValue = PyCapsule_New((void *)lmp, nullptr, nullptr); } else { error->all(FLERR, "Unsupported variable type: {}", itype); } @@ -397,7 +397,7 @@ void PythonImpl::invoke_function(int ifunc, char *result) auto value = fmt::format("{:.15g}", PyFloat_AsDouble(pValue)); strncpy(result, value.c_str(), Variable::VALUELENGTH - 1); } else if (otype == STRING) { - const char *pystr = PY_STRING_AS_STRING(pValue); + const char *pystr = PyUnicode_AsUTF8(pValue); if (pfuncs[ifunc].longstr) strncpy(pfuncs[ifunc].longstr, pystr, pfuncs[ifunc].length_longstr); else From 314d0a0e614c9a1abdd9bcf67fb7226a17f8c7de Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 8 Feb 2025 05:50:10 -0500 Subject: [PATCH 15/50] only support Python version 3.6 or later. Update and correct docs and README --- doc/src/Python_install.rst | 19 ++++----- python/README | 86 ++++++++++++++++++++------------------ python/lammps/__init__.py | 3 ++ python/lammps/core.py | 24 ++--------- 4 files changed, 62 insertions(+), 70 deletions(-) diff --git a/doc/src/Python_install.rst b/doc/src/Python_install.rst index 01610b84f0..1e53a99914 100644 --- a/doc/src/Python_install.rst +++ b/doc/src/Python_install.rst @@ -7,6 +7,10 @@ LAMMPS shared library through the Python `ctypes `_ module. Because of the dynamic loading, it is required that LAMMPS is compiled in :ref:`"shared" mode `. +.. versionchanged:: TBD + +LAMMPS currently only supports Python version 3.6 or later. + Two components are necessary for Python to be able to invoke LAMMPS code: * The LAMMPS Python Package (``lammps``) from the ``python`` folder @@ -136,11 +140,6 @@ folder that the dynamic loader searches or inside of the installed # create virtual environment in folder $HOME/myenv python3 -m venv $HOME/myenv - For Python versions prior 3.3 you can use `virtualenv - `_ - command instead of "python3 -m venv". This step has to be done - only once. - To activate the virtual environment type: .. code-block:: bash @@ -245,14 +244,14 @@ make MPI calls directly from Python in your script, if you desire. We have tested this with `MPI for Python `_ (aka mpi4py) and you will find installation instruction for it below. -Installation of mpi4py (version 3.0.3 as of Sep 2020) can be done as +Installation of mpi4py (version 4.0.1 as of Feb 2025) can be done as follows: - Via ``pip`` into a local user folder with: .. code-block:: bash - pip install --user mpi4py + python3 -m pip install --user mpi4py - Via ``dnf`` into a system folder for RedHat/Fedora systems: @@ -261,20 +260,20 @@ follows: # for use with OpenMPI sudo dnf install python3-mpi4py-openmpi # for use with MPICH - sudo dnf install python3-mpi4py-openmpi + sudo dnf install python3-mpi4py-mpich - Via ``pip`` into a virtual environment (see above): .. code-block:: console $ source $HOME/myenv/activate - (myenv)$ pip install mpi4py + (myenv)$ python -m pip install mpi4py - Via ``pip`` into a system folder (not recommended): .. code-block:: bash - sudo pip install mpi4py + sudo python3 -m pip install mpi4py For more detailed installation instructions and additional options, please see the `mpi4py installation `_ page. diff --git a/python/README b/python/README index 0757a84cd6..97f47b2a36 100644 --- a/python/README +++ b/python/README @@ -1,20 +1,27 @@ -This directory contains Python code which wraps LAMMPS as a library -and allows the LAMMPS library interface to be invoked from Python, -either from a Python script or using Python interactively. +This directory contains the LAMMPS Python module that allows the LAMMPS +C library interface to be invoked from Python, either from a Python +script or using Python interactively. Details on the Python interface to LAMMPS and how to build LAMMPS as a shared library, for use with Python, are given in -doc/Section_python.html and in doc/Section_start.html#start_5. +https://docs.lammps.org/Build_basics.html#exe +and +https://docs.lammps.org/Python_install.html -Basically you need to follow these steps in the src directory: +Basically you need to use the flag -D BUILD_SHARED_LIBS=ON when +configuring LAMMPS with CMake and then in the build folder use the +command % cmake --build . --target install-python + +or for the legacy GNU build system execute these steps in the src folder: % make g++ mode=shlib # build for whatever machine target you wish % make install-python # install into site-packages folder You can replace the last step by a one-time setting of environment -variables in your shell script. Or you can run the python/install.py -script directly to give you more control over where the two relevant -files are installed. See doc/Python_install.html for details. +variables in your shell environment. Or you can run the +python/install.py script directly to give you more control over where +the two relevant files are installed. See +https://docs.lammps.org/Python_install.html for details. You should then be able to launch Python and instantiate an instance of LAMMPS: @@ -24,39 +31,41 @@ of LAMMPS: >>> lmp = lammps() If that gives no errors, you have successfully wrapped LAMMPS with -Python. See doc/Section_python.html#py_7 for tests you can then use -to run LAMMPS both in serial or parallel thru Python. +Python. See https://docs.lammps.org/Python_launch.html for examples how +to run LAMMPS both in serial or parallel from Python. Note that you can also invoke Python code from within a LAMMPS input -script, using the "python" command. See the doc/python.html doc page -for details. The Python code you invoke can also call back to LAMMPS -using the same interface described here for wrapping LAMMPS. +script, using the "python" command. See the +https://docs.lammps.org/python.html doc page for details. The Python +code you invoke can also call back to LAMMPS using the same interface +described here for wrapping LAMMPS. ------------------------------------------------------------------- Once you have successfully wrapped LAMMPS, you can run the Python scripts in the examples sub-directory: -trivial.py read/run a LAMMPS input script thru Python -demo.py invoke various LAMMPS library interface routines -simple.py parallel example, mimicing examples/COUPLE/simple/simple.cpp -split.py parallel example -mc.py Monte Carlo energy relaxation wrapper on LAMMPS -gui.py GUI go/stop/temperature-slider to control LAMMPS -plot.py real-time temperature plot with GnuPlot via Pizza.py -matplotlib_plot.py real-time temperature plot with Matplotlib via Pizza.py -viz_tool.py real-time viz via some viz package -vizplotgui_tool.py combination of viz.py and plot.py and gui.py +trivial.py read/run a LAMMPS input script thru Python +demo.py invoke various LAMMPS library interface routines +simple.py parallel example, mimicing examples/COUPLE/simple/simple.cpp +split.py parallel example +mc.py Monte Carlo energy relaxation wrapper on LAMMPS +gui.py GUI go/stop/temperature-slider to control LAMMPS +plot.py real-time temperature plot with GnuPlot via Pizza.py +matplotlib_plot.py real-time temperature plot with Matplotlib via Pizza.py +viz_.py real-time viz via some viz package +vizplotgui_.py combination of viz.py and plot.py and gui.py -For the viz_tool.py and vizplotgui_tool.py commands, replace "tool" -with "gl" or "atomeye" or "pymol", depending on what visualization -package you have installed. We hope to add a VMD option soon. +For the viz_.py and vizplotgui_.py commands, replace +"" with "gl" or "atomeye" or "pymol", depending on what +visualization package you have installed. We hope to add a VMD option +soon. Note that for GL, you need to be able to run the Pizza.py GL tool, which is included in the pizza sub-directory. See the Pizza.py doc pages for more info: -http://www.sandia.gov/~sjplimp/pizza.html +https://lammps.github.io/pizza/ Note that for AtomEye, you need version 3, and their is a line in the scripts that specifies the path and name of the executable. See @@ -115,17 +124,14 @@ one-processor run, where both Python and LAMMPS will run on single processors. Each running job will read the same input file, and write to same log.lammps file, which isn't too useful. -However, if you have the mpi4py Python package installed and uncomment mpi4py -code in simple.py, then the above commands will invoke 1 instance of a -P-processor run. Both Python and LAMMPS will run on P processors. The job will -read the input file and write a single log.lammps file. - -The split.py script can also be run in parallel. It uses mpi4py -version 2.0.0 (or later), which makes it possible to pass a -communicator when creating the LAMMPS object and thus run multiple -instances of LAMMPS at the same time, each on a different subset of -MPI ranks. Or run LAMMPS on one subset and some other program on the -rest of the MPI ranks, concurrently. See comments in the split.py -script for more details. - +However, if you have the mpi4py Python package installed and uncomment +mpi4py code in simple.py, then the above commands will invoke 1 instance +of a P-processor run. Both Python and LAMMPS will run on P processors. +The job will read the input file and write a single log.lammps file. +The split.py script can also be run in parallel. It uses mpi4py version +2.0.0 (or later), which makes it possible to pass a communicator when +creating the LAMMPS object and thus run multiple instances of LAMMPS at +the same time, each on a different subset of MPI ranks. Or run LAMMPS +on one subset and some other program on the rest of the MPI ranks, +concurrently. See comments in the split.py script for more details. diff --git a/python/lammps/__init__.py b/python/lammps/__init__.py index fc35e45225..0cc658371f 100644 --- a/python/lammps/__init__.py +++ b/python/lammps/__init__.py @@ -23,6 +23,9 @@ def get_version_number(): if __file__.find(join('python', 'lammps', '__init__.py')) > 0: return 0 + if version_info.major < 3 or (version_info.major == 3 and version_info.minor < 6): + raise SystemError('LAMMPS only supports Python version 3.6 or later') + vstring = None if version_info.major == 3 and version_info.minor >= 8: from importlib.metadata import version, PackageNotFoundError diff --git a/python/lammps/core.py b/python/lammps/core.py index 43d142c7de..d8fc3a666e 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -83,8 +83,6 @@ class command_wrapper(object): def _wrap_args(self, x): if callable(x): - if sys.version_info < (3,): - raise Exception("Passing functions or lambdas directly as arguments is only supported in Python 3 or newer") import hashlib import __main__ sha = hashlib.sha256() @@ -105,11 +103,6 @@ class command_wrapper(object): all the arguments, concatinates them to a single string, and executes it using :py:meth:`lammps.command`. - Starting with Python 3.6 it also supports keyword arguments. key=value is - transformed into 'key value'. Note, since these have come last in the - parameter list, only a subset of LAMMPS commands can be used with this - syntax. - LAMMPS commands that accept callback functions (such as fix python/invoke) can be passed functions and lambdas directly. The first argument of such callbacks will be an lammps object constructed from the passed LAMMPS @@ -121,9 +114,6 @@ class command_wrapper(object): def handler(*args, **kwargs): cmd_args = [name] + [str(self._wrap_args(x)) for x in args] - if len(kwargs) > 0 and sys.version_info < (3,6): - raise Exception("Keyword arguments are only supported in Python 3.6 or newer") - # Python 3.6+ maintains ordering of kwarg keys for k in kwargs.keys(): cmd_args.append(k) @@ -530,16 +520,10 @@ class lammps(object): else: # magic to convert ptr to ctypes ptr - if sys.version_info >= (3, 0): - # Python 3 (uses PyCapsule API) - pythonapi.PyCapsule_GetPointer.restype = c_void_p - pythonapi.PyCapsule_GetPointer.argtypes = [py_object, c_char_p] - self.lmp = c_void_p(pythonapi.PyCapsule_GetPointer(ptr, None)) - else: - # Python 2 (uses PyCObject API) - pythonapi.PyCObject_AsVoidPtr.restype = c_void_p - pythonapi.PyCObject_AsVoidPtr.argtypes = [py_object] - self.lmp = c_void_p(pythonapi.PyCObject_AsVoidPtr(ptr)) + # Python 3 (uses PyCapsule API) + pythonapi.PyCapsule_GetPointer.restype = c_void_p + pythonapi.PyCapsule_GetPointer.argtypes = [py_object, c_char_p] + self.lmp = c_void_p(pythonapi.PyCapsule_GetPointer(ptr, None)) # check if library initilialization failed if not self.lmp: From 098bb4b3c8715a013e24904f6936cfb714631944 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 8 Feb 2025 08:55:32 -0500 Subject: [PATCH 16/50] flag development version --- src/version.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/version.h b/src/version.h index d24e7ed8f1..d28810b466 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1,2 @@ #define LAMMPS_VERSION "4 Feb 2025" +#define LAMMPS_UPDATE "Development" From 8791b29aa2a9eb01932c53ffd1185d87dd4c36b6 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 8 Feb 2025 18:05:57 -0500 Subject: [PATCH 17/50] give Region2VMD class access to protected members of region style classes --- src/region.cpp | 2 +- src/region_block.h | 1 + src/region_cone.h | 2 ++ src/region_cylinder.h | 1 + src/region_sphere.h | 3 ++- 5 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/region.cpp b/src/region.cpp index 7399b14adb..2d2c6513c9 100644 --- a/src/region.cpp +++ b/src/region.cpp @@ -375,7 +375,7 @@ void Region::options(int narg, char **arg) openflag = 1; iarg += 2; } else - error->all(FLERR, "Illegal region command argument: {}", arg[iarg]); + error->all(FLERR, iarg, "Unknown region command argument: {}", arg[iarg]); } // error check diff --git a/src/region_block.h b/src/region_block.h index 35ee7fe2f2..c939373a20 100644 --- a/src/region_block.h +++ b/src/region_block.h @@ -26,6 +26,7 @@ namespace LAMMPS_NS { class RegBlock : public Region { friend class FixPour; + friend class Region2VMD; public: RegBlock(class LAMMPS *, int, char **); diff --git a/src/region_cone.h b/src/region_cone.h index 81288d26b8..aeec55c4dc 100644 --- a/src/region_cone.h +++ b/src/region_cone.h @@ -25,6 +25,8 @@ RegionStyle(cone,RegCone); namespace LAMMPS_NS { class RegCone : public Region { + friend class Region2VMD; + public: RegCone(class LAMMPS *, int, char **); ~RegCone() override; diff --git a/src/region_cylinder.h b/src/region_cylinder.h index 816cbda3de..f84f3408bb 100644 --- a/src/region_cylinder.h +++ b/src/region_cylinder.h @@ -26,6 +26,7 @@ namespace LAMMPS_NS { class RegCylinder : public Region { friend class FixPour; + friend class Region2VMD; public: RegCylinder(class LAMMPS *, int, char **); diff --git a/src/region_sphere.h b/src/region_sphere.h index 3053d98edb..735116f4a1 100644 --- a/src/region_sphere.h +++ b/src/region_sphere.h @@ -23,8 +23,9 @@ RegionStyle(sphere,RegSphere); #include "region.h" namespace LAMMPS_NS { - class RegSphere : public Region { + friend class Region2VMD; + public: RegSphere(class LAMMPS *, int, char **); ~RegSphere() override; From 95858bccc66375c316ca45a301a8c6de5f50a83c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 8 Feb 2025 18:06:12 -0500 Subject: [PATCH 18/50] add region2vmd command --- src/EXTRA-COMMAND/region2vmd.cpp | 198 +++++++++++++++++++++++++++++++ src/EXTRA-COMMAND/region2vmd.h | 41 +++++++ 2 files changed, 239 insertions(+) create mode 100644 src/EXTRA-COMMAND/region2vmd.cpp create mode 100644 src/EXTRA-COMMAND/region2vmd.h diff --git a/src/EXTRA-COMMAND/region2vmd.cpp b/src/EXTRA-COMMAND/region2vmd.cpp new file mode 100644 index 0000000000..fa5bd4015d --- /dev/null +++ b/src/EXTRA-COMMAND/region2vmd.cpp @@ -0,0 +1,198 @@ +/* -*- c++ -*-------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- + Contributing author: Axel Kohlmeyer (Temple U) +------------------------------------------------------------------------- */ + +#include "region2vmd.h" + +#include "atom.h" +#include "comm.h" +#include "domain.h" +#include "error.h" +#include "region.h" + +#include "region_block.h" +#include "region_cone.h" +#include "region_cylinder.h" +#include "region_sphere.h" + +#include + +using namespace LAMMPS_NS; + +static constexpr double SMALL = 1.0e-10; + +/* ---------------------------------------------------------------------- */ + +void Region2VMD::command(int narg, char **arg) +{ + FILE *fp = nullptr; + + if (narg < 2) utils::missing_cmd_args(FLERR, "region2vmd", error); + + if (comm->me == 0) { + fp = fopen(arg[0], "w"); + if (fp == nullptr) { + error->one(FLERR, Error::ARGZERO, "Cannot open file {} for writing: {}", arg[0], + utils::getsyserror()); + } else { + utils::logmesg(lmp, "Writing region visualizations to VMD Tcl script file {}:\n", arg[0]); + fputs("# save old top molecule index\nset oldtop [molinfo top]\n", fp); + } + } + + for (int iarg = 1; iarg < narg; ++iarg) { + auto *region = domain->get_region_by_id(arg[iarg]); + if (!region) { + if (fp) fclose(fp); + error->all(FLERR, iarg, "Region {} does not exist", arg[iarg]); + } else { + write_region(fp, region); + } + } + + // done, close file + if (comm->me == 0) { + // reset views and restore previous top molecule + fputs("display resetview\nif {$oldtop >= 0} {mol top $oldtop}\n", fp); + fclose(fp); + } +} + +/* ---------------------------------------------------------------------- + write out one region using VMD graphics primitives + fp is non-NULL only on MPI rank 0 + ---------------------------------------------------------------------- */ + +void Region2VMD::write_region(FILE *fp, Region *region) +{ + if (!fp || !region) return; + + if (region->dynamic_check()) { + utils::logmesg(lmp, "Cannot (yet) handle moving or rotating region {}. Skipping... ", + region->id); + return; + } + + // create a new (empty) VMD molecule to hold the graphics for this specific region. + + utils::logmesg(lmp, " writing region {} ...", region->id); + utils::print(fp, "\n# region {} of style {}\n", region->id, region->style); + fputs("# create new empty VMD molecule to store the graphics primitives\n" + "set gfxmol [mol new]\nmol top $gfxmol\n", + fp); + utils::print(fp, "mol rename $gfxmol {{LAMMPS region {}}}\n", region->id); + fputs("# set color to desired value. Use 'gray' by default\n" + "graphics $gfxmol color gray\n", + fp); + fputs("# set material to desired choice\n" + "graphics $gfxmol material Transparent\n", + fp); + + // translate compatible regions to VMD graphics primitives, skip others. + + const std::string regstyle = region->style; + if (regstyle == "block") { + const auto block = dynamic_cast(region); + if (!block) { + error->one(FLERR, Error::NOLASTLINE, "Region {} is not of style 'block'", region->id); + } else { + + // a block is represented by 12 triangles + + utils::print(fp, + "draw triangle {{{0} {2} {4}}} {{{0} {2} {5}}} {{{0} {3} {4}}}\n" + "draw triangle {{{0} {3} {4}}} {{{0} {3} {5}}} {{{0} {2} {5}}}\n" + "draw triangle {{{0} {2} {4}}} {{{0} {2} {5}}} {{{1} {2} {4}}}\n" + "draw triangle {{{1} {2} {4}}} {{{1} {2} {5}}} {{{0} {2} {5}}}\n" + "draw triangle {{{1} {2} {4}}} {{{1} {2} {5}}} {{{1} {3} {4}}}\n" + "draw triangle {{{1} {3} {4}}} {{{1} {3} {5}}} {{{1} {2} {5}}}\n" + "draw triangle {{{0} {2} {4}}} {{{1} {2} {4}}} {{{1} {3} {4}}}\n" + "draw triangle {{{0} {2} {4}}} {{{0} {3} {4}}} {{{1} {3} {4}}}\n" + "draw triangle {{{0} {2} {5}}} {{{1} {2} {5}}} {{{1} {3} {5}}}\n" + "draw triangle {{{0} {2} {5}}} {{{0} {3} {5}}} {{{1} {3} {5}}}\n" + "draw triangle {{{0} {3} {4}}} {{{0} {3} {5}}} {{{1} {3} {5}}}\n" + "draw triangle {{{0} {3} {4}}} {{{1} {3} {4}}} {{{1} {3} {5}}}\n", + block->xlo, block->xhi, block->ylo, block->yhi, block->zlo, block->zhi); + } + + } else if (regstyle == "cone") { + const auto cone = dynamic_cast(region); + if (!cone) { + error->one(FLERR, Error::NOLASTLINE, "Region {} is not of style 'cone'", region->id); + } else { + + // The VMD cone primitive requires one radius set to zero + if (cone->radiuslo < SMALL) { + // a cone uses a single cone primitive + if (cone->axis == 'x') { + utils::print(fp, "draw cone {{{1} {2} {3}}} {{{0} {2} {3}}} radius {4} resolution 20\n", + cone->lo, cone->hi, cone->c1, cone->c2, cone->radiushi); + } else if (cone->axis == 'y') { + utils::print(fp, "draw cone {{{2} {1} {3}}} {{{2} {0} {3}}} radius {4} resolution 20\n", + cone->lo, cone->hi, cone->c1, cone->c2, cone->radiushi); + } else if (cone->axis == 'z') { + utils::print(fp, "draw cone {{{2} {3} {1}}} {{{2} {3} {0}}} radius {4} resolution 20\n", + cone->lo, cone->hi, cone->c1, cone->c2, cone->radiushi); + } + } else if (cone->radiushi < SMALL) { + // a cone uses a single cone primitive + if (cone->axis == 'x') { + utils::print(fp, "draw cone {{{0} {2} {3}}} {{{1} {2} {3}}} radius {4} resolution 20\n", + cone->lo, cone->hi, cone->c1, cone->c2, cone->radiuslo); + } else if (cone->axis == 'y') { + utils::print(fp, "draw cone {{{2} {0} {3}}} {{{2} {1} {3}}} radius {4} resolution 20\n", + cone->lo, cone->hi, cone->c1, cone->c2, cone->radiuslo); + } else if (cone->axis == 'z') { + utils::print(fp, "draw cone {{{2} {3} {0}}} {{{2} {3} {1}}} radius {4} resolution 20\n", + cone->lo, cone->hi, cone->c1, cone->c2, cone->radiuslo); + } + } else { + utils::logmesg(lmp, + "Cannot (yet) translate a truncated cone to VMD graphics. Skipping...\n"); + } + } + } else if (regstyle == "cylinder") { + const auto cylinder = dynamic_cast(region); + if (!cylinder) { + error->one(FLERR, Error::NOLASTLINE, "Region {} is not of style 'cylinder'", region->id); + } else { + // a cylinder uses a single cylinder primitive + if (cylinder->axis == 'x') { + utils::print(fp, "draw cylinder {{{0} {2} {3}}} {{{1} {2} {3}}} radius {4} resolution 20\n", + cylinder->lo, cylinder->hi, cylinder->c1, cylinder->c2, cylinder->radius); + } else if (cylinder->axis == 'y') { + utils::print(fp, "draw cylinder {{{2} {0} {3}}} {{{2} {1} {3}}} radius {4} resolution 20\n", + cylinder->lo, cylinder->hi, cylinder->c1, cylinder->c2, cylinder->radius); + } else if (cylinder->axis == 'z') { + utils::print(fp, "draw cylinder {{{2} {3} {0}}} {{{2} {3} {1}}} radius {4} resolution 20\n", + cylinder->lo, cylinder->hi, cylinder->c1, cylinder->c2, cylinder->radius); + } + } + } else if (regstyle == "sphere") { + const auto sphere = dynamic_cast(region); + if (!sphere) { + error->one(FLERR, Error::NOLASTLINE, "Region {} is not of style 'sphere'", region->id); + } else { + // a sphere uses a single sphere primitive + utils::print(fp, "draw sphere {{{} {} {}}} radius {} resolution 20\n", sphere->xc, sphere->yc, + sphere->zc, sphere->radius); + } + } else { + utils::logmesg(lmp, + "Cannot (yet) translate region {} of style {} to VMD graphics. Skipping... ", + region->id, region->style); + } + utils::logmesg(lmp, " done\n"); +} diff --git a/src/EXTRA-COMMAND/region2vmd.h b/src/EXTRA-COMMAND/region2vmd.h new file mode 100644 index 0000000000..05352217af --- /dev/null +++ b/src/EXTRA-COMMAND/region2vmd.h @@ -0,0 +1,41 @@ +/* -*- c++ -*----------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef COMMAND_CLASS +// clang-format off +CommandStyle(region2vmd,Region2VMD); +// clang-format on +#else + +#ifndef LMP_REGION2VMD_H +#define LMP_REGION2VMD_H + +#include "command.h" + +namespace LAMMPS_NS { + +class Region; + +class Region2VMD : public Command { + public: + Region2VMD(class LAMMPS *lmp) : Command(lmp) {}; + void command(int, char **) override; + + protected: + void write_region(FILE *, Region *); +}; + +} // namespace LAMMPS_NS + +#endif +#endif From c7db4e9e1969196dfa6a13ff3a9ccb3fd9d83761 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 8 Feb 2025 18:06:32 -0500 Subject: [PATCH 19/50] add docs for region2vmd command --- doc/src/Commands_all.rst | 1 + doc/src/commands_list.rst | 1 + doc/src/region2vmd.rst | 66 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 doc/src/region2vmd.rst diff --git a/doc/src/Commands_all.rst b/doc/src/Commands_all.rst index 58623401f3..bfc9e8538c 100644 --- a/doc/src/Commands_all.rst +++ b/doc/src/Commands_all.rst @@ -140,6 +140,7 @@ additional letter in parenthesis: k = KOKKOS. * :doc:`plugin ` * :doc:`prd ` * :doc:`python ` + * :doc:`region2vmd ` * :doc:`tad ` * :doc:`temper ` * :doc:`temper/grem ` diff --git a/doc/src/commands_list.rst b/doc/src/commands_list.rst index dc5731f579..acfdfd9df0 100644 --- a/doc/src/commands_list.rst +++ b/doc/src/commands_list.rst @@ -82,6 +82,7 @@ Commands read_dump read_restart region + region2vmd replicate rerun reset_atoms diff --git a/doc/src/region2vmd.rst b/doc/src/region2vmd.rst new file mode 100644 index 0000000000..87ad64b65e --- /dev/null +++ b/doc/src/region2vmd.rst @@ -0,0 +1,66 @@ +.. index:: region2vmd + +region2cmd command +================== + +Syntax +"""""" + +.. code-block:: LAMMPS + + region2vmd file args + +* file = name of VMD script file to write +* args = one or more region IDs may be appended + +Examples +"""""""" + +.. code-block:: LAMMPS + + region2vmd regions.vmd box c1 c2 + +Description +""""""""""" + +Write a `VMD `_ Tcl script file with +commands that aim to create a visualization of :doc:`LAMMPS regions +`. There may be multiple region visualizations stored in a +single file. Only a limited amount of region styles and settings are +currently supported. See **Restrictions** below. + +The visualization is implemented by creating a new (and empty) "VMD +molecule" and then using VMD graphics primitives to represent the region +in VMD. Each region will be stored in a separate "VMD molecule" with +the name "LAMMPS region ". + +The created file can be loaded into VMD either from the command line +with the -e flag, or from the command prompt with play