Skip to content

Commit 9efd430

Browse files
committed
add infrastructure to convert pair style into plugin
1 parent d4113d0 commit 9efd430

File tree

6 files changed

+298
-0
lines changed

6 files changed

+298
-0
lines changed

.gitignore

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
*~
2+
*.o
3+
*.so
4+
*.lo
5+
*.cu_o
6+
*.ptx
7+
*_ptx.h
8+
*.a
9+
*.d
10+
*.x
11+
*.exe
12+
*.sif
13+
*.dll
14+
*.pyc
15+
*.whl
16+
a.out
17+
__pycache__
18+
19+
Obj_*
20+
log.lammps
21+
log.cite
22+
*.bz2
23+
*.gz
24+
*.tar
25+
.*.swp
26+
*.orig
27+
*.rej
28+
vgcore.*
29+
.vagrant
30+
\#*#
31+
.#*
32+
.vscode
33+
34+
.DS_Store
35+
.DS_Store?
36+
._*
37+
.Spotlight-V100
38+
.Trashes
39+
ehthumbs.db
40+
Thumbs.db
41+
.lammps_history
42+
.vs
43+
44+
#cmake
45+
/build*
46+
/CMakeCache.txt
47+
/CMakeFiles/
48+
/Testing
49+
/Makefile
50+
/Testing
51+
/cmake_install.cmake
52+
/lmp
53+
out/Debug
54+
out/RelWithDebInfo
55+
out/Release
56+
out/x86
57+
out/x64

lammps-text-logo-wide.bmp

25.2 KB
Binary file not shown.

lammps.ico

204 KB
Binary file not shown.

pair-aeam/CMakeLists.txt

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
##########################################
2+
# CMake build system for plugin examples.
3+
# The is meant to be used as a template for plugins that are
4+
# distributed independent from the LAMMPS package.
5+
##########################################
6+
7+
cmake_minimum_required(VERSION 3.10)
8+
if(POLICY CMP0077)
9+
cmake_policy(SET CMP0077 NEW)
10+
endif()
11+
12+
project(aeamplugin VERSION 1.0 LANGUAGES CXX)
13+
14+
if(NOT LAMMPS_SOURCE_DIR)
15+
message(FATAL_ERROR "Must set LAMMPS_SOURCE_DIR variable")
16+
endif()
17+
set(CMAKE_MODULE_PATH "${LAMMPS_SOURCE_DIR}/../cmake/Modules")
18+
include(CheckIncludeFileCXX)
19+
include(LAMMPSInterfacePlugin)
20+
21+
##########################
22+
# building the plugins
23+
24+
add_library(aeamplugin MODULE aeamplugin.cpp ${CMAKE_SOURCE_DIR}/pair_aeam.cpp)
25+
target_link_libraries(aeamplugin PRIVATE lammps)
26+
set_target_properties(aeamplugin PROPERTIES PREFIX "" SUFFIX ".so")
27+
28+
# MacOS seems to need this
29+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
30+
set_target_properties(aeamplugin PROPERTIES LINK_FLAGS "-Wl,-undefined,dynamic_lookup")
31+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
32+
# tell CMake to export all symbols to a .dll on Windows with special case for MinGW cross-compilers
33+
set_target_properties(aeamplugin PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
34+
if(CMAKE_CROSSCOMPILING)
35+
set_target_properties(aeamplugin PROPERTIES LINK_FLAGS "-Wl,--export-all-symbols")
36+
endif()
37+
38+
get_lammps_version(${LAMMPS_SOURCE_DIR}/version.h LAMMPS_VERSION)
39+
find_program(MAKENSIS_PATH makensis)
40+
if(MAKENSIS_PATH)
41+
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/../lammps.ico
42+
${CMAKE_SOURCE_DIR}/../lammps-text-logo-wide.bmp ${CMAKE_SOURCE_DIR}/aeamplugin.nsis ${CMAKE_BINARY_DIR})
43+
if(BUILD_MPI)
44+
add_custom_target(package ${MAKENSIS_PATH} -V1 -DVERSION=${LAMMPS_VERSION}-MPI aeamplugin.nsis
45+
DEPENDS aeamplugin
46+
BYPRODUCTS LAMMPS-USER-AEAM-plugin-${LAMMPS_VERSION}-MPI.exe)
47+
else()
48+
add_custom_target(package ${MAKENSIS_PATH} -V1 -DVERSION=${LAMMPS_VERSION} aeamplugin.nsis
49+
COMMAND ${CMAKE_COMMAND} -E echo ${PWD}
50+
DEPENDS aeamplugin lammps.ico lammps-text-logo-wide.bmp aeamplugin.nsis
51+
BYPRODUCTS LAMMPS-USER-AEAM-plugin-${LAMMPS_VERSION}.exe)
52+
endif()
53+
endif()
54+
else()
55+
set_target_properties(aeamplugin PROPERTIES LINK_FLAGS "-rdynamic")
56+
endif()

pair-aeam/aeamplugin.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
#include "lammpsplugin.h"
3+
#include "version.h"
4+
5+
#include "pair_aeam.h"
6+
7+
using namespace LAMMPS_NS;
8+
9+
static Pair *pair_aeam_creator(LAMMPS *lmp)
10+
{
11+
return new PairAEAM(lmp);
12+
}
13+
14+
extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc)
15+
{
16+
lammpsplugin_t plugin;
17+
lammpsplugin_regfunc register_plugin = (lammpsplugin_regfunc) regfunc;
18+
19+
// register pace pair style
20+
plugin.version = LAMMPS_VERSION;
21+
plugin.style = "pair";
22+
plugin.name = "aeam";
23+
plugin.info = "AEAM plugin pair style v1.0";
24+
plugin.author = "Axel Kohlmeyer ([email protected])";
25+
plugin.creator.v1 = (lammpsplugin_factory1 *) &pair_aeam_creator;
26+
plugin.handle = handle;
27+
(*register_plugin)(&plugin, lmp);
28+
}

pair-aeam/aeamplugin.nsis

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
#!Nsis Installer Command Script
2+
#
3+
# The following external defines are recognized:
4+
# ${VERSION} = YYYYMMDD
5+
6+
!include "MUI2.nsh"
7+
!include "FileFunc.nsh"
8+
9+
!define MUI_ICON "lammps.ico"
10+
!define MUI_UNICON "lammps.ico"
11+
!define MUI_HEADERIMAGE
12+
!define MUI_HEADERIMAGE_BITMAP "lammps-text-logo-wide.bmp"
13+
!define MUI_HEADERIMAGE_RIGHT
14+
15+
Unicode true
16+
XPStyle on
17+
18+
!include "LogicLib.nsh"
19+
!addplugindir "envvar/Plugins/x86-unicode"
20+
!include "x64.nsh"
21+
22+
RequestExecutionLevel user
23+
24+
!macro VerifyUserIsAdmin
25+
UserInfo::GetAccountType
26+
pop $0
27+
${If} $0 != "admin"
28+
messageBox mb_iconstop "Administrator rights required!"
29+
setErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
30+
quit
31+
${EndIf}
32+
!macroend
33+
34+
!define PACEPLUGIN "LAMMPS USER-AEAM Plugin ${VERSION}"
35+
OutFile "LAMMPS-USER-AEAM-plugin-${VERSION}.exe"
36+
37+
Name "${PACEPLUGIN}"
38+
InstallDir "$LOCALAPPDATA\${PACEPLUGIN}"
39+
40+
ShowInstDetails show
41+
ShowUninstDetails show
42+
SetCompressor lzma
43+
44+
!define MUI_ABORTWARNING
45+
46+
!insertmacro MUI_PAGE_DIRECTORY
47+
!insertmacro MUI_PAGE_INSTFILES
48+
49+
!insertmacro MUI_UNPAGE_CONFIRM
50+
!insertmacro MUI_UNPAGE_INSTFILES
51+
52+
!insertmacro MUI_LANGUAGE "English"
53+
54+
function .onInit
55+
# Determine if LAMMPS was already installed and check whether it was in 32-bit
56+
# or 64-bit. Then look up path to uninstaller and offer to uninstall or quit
57+
SetRegView 32
58+
ReadRegDWORD $0 HKCU "Software\LAMMPS-USER-AEAM" "Bits"
59+
SetRegView LastUsed
60+
${If} $0 == "32"
61+
SetRegView 32
62+
${ElseIf} $0 == "64"
63+
SetRegView 64
64+
${Else}
65+
SetRegView 64
66+
${EndIf}
67+
ClearErrors
68+
ReadRegStr $R0 HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM" "UninstallString"
69+
SetRegView LastUsed
70+
${If} ${Errors}
71+
DetailPrint "LAMMPS USER-AEAM plugin not (yet) installed"
72+
${Else}
73+
MessageBox MB_YESNO "LAMMPS USER-AEAM plugin ($0 bit) is already installed. Uninstall existing version?" /SD IDYES IDNO Quit
74+
Pop $R1
75+
StrCmp $R1 2 Quit +1
76+
Exec $R0
77+
Quit:
78+
Quit
79+
${EndIf}
80+
setShellVarContext all
81+
functionEnd
82+
83+
Section "${PACEPLUGIN}" SecPaceplugin
84+
SectionIn RO
85+
# Write LAMMPS installation bitness marker. Always use 32-bit registry view
86+
SetRegView 32
87+
IntFmt $0 "0x%08X" 64
88+
WriteRegDWORD HKCU "Software\LAMMPS-USER-AEAM" "Bits" $0
89+
90+
# Switch to "native" registry view
91+
SetRegView 64
92+
SetShellVarContext current
93+
94+
SetOutPath "$INSTDIR"
95+
File lammps.ico
96+
File aeamplugin.so
97+
98+
# Register Application and its uninstaller
99+
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM" \
100+
"DisplayName" "${PACEPLUGIN}"
101+
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM" \
102+
"Publisher" "The LAMMPS and PACE Developers"
103+
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM" \
104+
"URLInfoAbout" "lammps.org"
105+
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM" \
106+
"DisplayIcon" "$INSTDIR\lammps.ico"
107+
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM" \
108+
"DisplayVersion" "${VERSION}"
109+
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM" \
110+
"InstallLocation" "$INSTDIR"
111+
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM" \
112+
"UninstallString" "$\"$INSTDIR\uninstall.exe$\""
113+
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM" \
114+
"QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
115+
116+
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
117+
IntFmt $0 "0x%08X" $0
118+
WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM" \
119+
"EstimatedSize" "$0"
120+
121+
# update path variables
122+
EnVar::SetHKCU
123+
# add to LAMMPS plugin search path
124+
EnVar::AddValue "LAMMPS_PLUGIN_PATH" "$INSTDIR"
125+
126+
WriteUninstaller "$INSTDIR\Uninstall.exe"
127+
SectionEnd
128+
129+
function un.onInit
130+
SetShellVarContext current
131+
functionEnd
132+
133+
Section "Uninstall"
134+
# remove LAMMPS bitness/installation indicator always in 32-bit registry view
135+
SetRegView 32
136+
DeleteRegKey HKCU "Software\LAMMPS-USER-AEAM"
137+
138+
# unregister extension, and uninstall info
139+
SetRegView 64
140+
SetShellVarContext current
141+
# unregister installation
142+
DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM"
143+
144+
# update path variables
145+
EnVar::SetHKCU
146+
# remove entry from LAMMPS plugin search path
147+
EnVar::DeleteValue "LAMMPS_PLUGIN_PATH" "$INSTDIR"
148+
149+
Delete /REBOOTOK "$INSTDIR\aeamplugin.so"
150+
Delete /REBOOTOK "$INSTDIR\Uninstall.exe"
151+
Delete /REBOOTOK "$INSTDIR\lammps.ico"
152+
RMDir /REBOOTOK "$INSTDIR"
153+
SectionEnd
154+
155+
# Local Variables:
156+
# mode: sh
157+
# End:

0 commit comments

Comments
 (0)