Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ compile_commands.json
.clangd
.idea/
src/interface/stable_29Sep2021.tar.gz
build/
1 change: 1 addition & 0 deletions include/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.h
2 changes: 2 additions & 0 deletions lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.a
*.so
144 changes: 144 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
###################################################################################################
# CMake Build System for n2p2
###################################################################################################

###################################################################################################
# Project & CMake Information
cmake_minimum_required(VERSION 3.16) # Same required version as LAMMPS (no extra dependencies)
project(n2p2 VERSION 2.2.0)
###################################################################################################

###################################################################################################
# Git version info for project
execute_process(COMMAND git describe --tags --always
OUTPUT_VARIABLE GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND git rev-parse HEAD
OUTPUT_VARIABLE GIT_REV OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND git rev-parse --abbrev-ref HEAD
OUTPUT_VARIABLE GIT_BRANCH OUTPUT_STRIP_TRAILING_WHITESPACE)
###################################################################################################

###################################################################################################
# Set C++ Standard
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()
if(CMAKE_CXX_STANDARD LESS 11)
message(FATAL_ERROR "C++ standard must be set to at least 11")
endif()

# Manually append the standard flag to CMAKE_CXX_FLAGS for external Makefile usage
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
#elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
endif()
###################################################################################################

###################################################################################################
# Project Path Variables
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../lib)
set(PROJECT_INCLUDE ${CMAKE_BINARY_DIR}/../include)
set(CMAKE_SHARED_LIBRARY_SUFFIX .so)
###################################################################################################

###################################################################################################
# Document CLI Option Defaults
option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
option(NDEBUG "Disable all C++ asserts (also Eigen debugging)." OFF)

# N2P2 Compile Options
option(N2P2_NO_SF_GROUPS "Disable Symmetry function groups (NOT RECOMMENDED)" OFF)
option(N2P2_FULL_SFD_MEMORY "Store zero symmetry function derivatives" OFF)
option(N2P2_NO_SF_CACHE "Do not use symmetry function cache." OFF)
option(N2P2_NO_ASYM_POLY "Disable asymmetric polynomial symmetry functions." OFF)
option(N2P2_NO_TIME "Build with dummy Stopwatch class." OFF)
option(N2P2_NO_NEIGH_CHECK "Disable check for low number of neighbors." OFF)
option(N2P2_NO_MPI "Compile without MPI support." OFF)

# Which interfaces to build
option(N2P2_IF_LAMMPS "Build LAMMPS interface into libnnpif" ON)
option(N2P2_IF_CABANA "Build CabanaMD interface into libnnpif" ON)

# Eigen Optimization Options
option(EIGEN_DONT_PARALLELIZE "Disable Eigen multi threading." ON)
option(EIGEN_USE_BLAS "Use BLAS together with Eigen." ON)
option(EIGEN_USE_MKL_ALL "Use Intel MKL together with Eigen." OFF)
###################################################################################################

###################################################################################################
# Set N2P2 Preprocessor Options Variable (Used in subdirectory CMakeLists)
if(N2P2_NO_SF_GROUPS)
set(N2P2_PROJECT_OPTIONS "${N2P2_PROJECT_OPTIONS} -DN2P2_NO_SF_GROUPS")
endif(N2P2_NO_SF_GROUPS)

if(N2P2_FULL_SFD_MEMORY)
set(N2P2_PROJECT_OPTIONS "${N2P2_PROJECT_OPTIONS} -DN2P2_FULL_SFD_MEMORY")
endif(N2P2_FULL_SFD_MEMORY)

if(N2P2_NO_SF_CACHE)
set(N2P2_PROJECT_OPTIONS "${N2P2_PROJECT_OPTIONS} -DN2P2_NO_SF_CACHE")
endif(N2P2_NO_SF_CACHE)

if(N2P2_NO_ASYM_POLY)
set(N2P2_PROJECT_OPTIONS "${N2P2_PROJECT_OPTIONS} -DN2P2_NO_ASYM_POLY")
endif(N2P2_NO_ASYM_POLY)

if(N2P2_NO_TIME)
set(N2P2_PROJECT_OPTIONS "${N2P2_PROJECT_OPTIONS} -DN2P2_NO_TIME")
endif(N2P2_NO_TIME)

if(N2P2_NO_NEIGH_CHECK)
set(N2P2_PROJECT_OPTIONS "${N2P2_PROJECT_OPTIONS} -DN2P2_NO_NEIGH_CHECK")
endif(N2P2_NO_NEIGH_CHECK)

if(N2P2_NO_MPI)
set(N2P2_PROJECT_OPTIONS "${N2P2_PROJECT_OPTIONS} -DN2P2_NO_MPI")
else()
set(CMAKE_C_COMPILER "mpicc")
set(CMAKE_CXX_COMPILER "mpicxx")
endif(N2P2_NO_MPI)

if(EIGEN_DONT_PARALLELIZE)
set(EIGEN_PROJECT_OPTIONS "${EIGEN_PROJECT_OPTIONS} -DEIGEN_DONT_PARALLELIZE")
endif(EIGEN_DONT_PARALLELIZE)

if(EIGEN_USE_BLAS)
set(EIGEN_PROJECT_OPTIONS "${EIGEN_PROJECT_OPTIONS} -DEIGEN_USE_BLAS")
endif(EIGEN_USE_BLAS)

if(EIGEN_USE_MKL_ALL)
set(EIGEN_PROJECT_OPTIONS "${EIGEN_PROJECT_OPTIONS} -DEIGEN_USE_MKL_ALL")
endif(EIGEN_USE_MKL_ALL)

set(PROJECT_OPTIONS "${PROJECT_OPTIONS} ${N2P2_PROJECT_OPTIONS} ${EIGEN_PROJECT_OPTIONS}")

if(NDEBUG)
set(PROJECT_OPTIONS "${PROJECT_OPTIONS} -DNDEBUG")
endif(NDEBUG)

if(N2P2_IF_LAMMPS)
list(APPEND INTERFACES "${INTERFACES} LAMMPS")
endif(N2P2_IF_LAMMPS)

if(N2P2_IF_CABANA)
list(APPEND INTERFACES "${INTERFACES} CabanaMD")
endif(N2P2_IF_CABANA)
###################################################################################################

###################################################################################################
find_package(MPI REQUIRED)
find_package(GSL REQUIRED)
find_package(Eigen3 3.4 REQUIRED NO_MODULE)
link_directories(${GSL_LIBRARY_DIRS} ${MPI_LIBRARY_DIRS})
list(GET GSL_LIBRARIES 0 FIRST_GSL_LIBRARY)
get_filename_component(GSL_LIBRARY_DIR "${FIRST_GSL_LIBRARY}" DIRECTORY)

# Go into each subdirectory
add_subdirectory(libnnp)
add_subdirectory(libnnptrain)
add_subdirectory(application)
add_subdirectory(libnnpif)
add_subdirectory(interface)
###################################################################################################
64 changes: 64 additions & 0 deletions src/application/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
###################################################################################################
# CMake Build System for n2p2 executables
###################################################################################################

###################################################################################################
# Specify executables based on dependencies
# APP_CORE require only libnnp
set(APP_CORE
nnp-convert
nnp-cutoff
nnp-dist
nnp-predict
nnp-prune
nnp-select
nnp-symfunc)

# APP_DATASET require libnnp and libnnptrain (Use class Dataset only, not Training)
# NB: These are separated out since they do not require the Eigen library
set(APP_DATASET
nnp-atomenv
nnp-checkf
nnp-comp2
nnp-dataset
nnp-norm
nnp-scaling)

# APP_TRAINING require libnnp and libnnptrain
set(APP_TRAINING
nnp-checkdw
nnp-norm2
nnp-train)

# APP contains all executables
set(APP ${APP_CORE} ${APP_DATASET} ${APP_TRAINING})
###################################################################################################

###################################################################################################
# Specify Build Target for Each APP
foreach(app IN ITEMS ${APP})
add_executable(${app} ${app}.cpp)
endforeach(app IN ITEMS ${APP})

# Set Directory-Wide Project Options
add_compile_options(${PROJECT_OPTIONS})
###################################################################################################

###################################################################################################
# Find Required Package dependencies
include_directories(${MPI_INCLUDE_PATH} ${GSL_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/libnnp ${PROJECT_SOURCE_DIR}/libnnptrain)

# Add Link Dependencies based on requirements
foreach(app IN ITEMS ${APP_CORE})
target_link_libraries(${app} PRIVATE nnp)
endforeach(app IN ITEMS ${APP_CORE})

foreach(app IN ITEMS ${APP_DATASET})
target_link_libraries(${app} PRIVATE ${GSL_LIBRARIES} nnp nnptrain)
endforeach(app IN ITEMS ${APP_DATASET})

foreach(app IN ITEMS ${APP_TRAINING})
target_link_libraries(${app} PRIVATE ${GSL_LIBRARIES} Eigen3::Eigen nnp nnptrain)
endforeach(app IN ITEMS ${APP_TRAINING})

###################################################################################################]]
104 changes: 104 additions & 0 deletions src/interface/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
###################################################################################################
# CMake Build System for n2p2 LAMMPS interface
###################################################################################################

###################################################################################################
# Skip if not building LAMMPS or LAMMPS interface
if(NOT N2P2_IF_LAMMPS )
return()
endif(NOT N2P2_IF_LAMMPS )
###################################################################################################

###################################################################################################
# LAMMPS Specific Options
# Build Internal Version or External (sets name of the lammps package)
option(LAMMPS_INTERNAL
"Build as internal package. Uses name nnp vs. hdnnp to avoid conflict with release version."
OFF)
if(LAMMPS_INTERNAL)
set(LAMMPS_PACKAGE_NAME nnp)
else()
set(LAMMPS_PACKAGE_NAME hdnnp)
endif(LAMMPS_INTERNAL)

# Download & Build own LAMMPS executable
option(BUILD_LAMMPS
"Build minimal LAMMPS executable. (Either Specify DOWNLOAD_LAMMPS=ON or LAMMPS_PATH)" OFF)

if (NOT LAMMPS_PATH)
option(DOWNLOAD_LAMMPS "Download LAMMPS. This supersedes LAMMPS_PATH variable." OFF)
else()
option(DOWNLOAD_LAMMPS "Download LAMMPS. This supersedes LAMMPS_PATH variable." OFF)
endif (NOT LAMMPS_PATH)

# Specify Default LAMMPS Version
if (NOT LAMMPS_VERSION)
set(LAMMPS_VERSION "lammps-29Aug2024")
endif (NOT LAMMPS_VERSION)
###################################################################################################

###################################################################################################
# Configure makefiles and extra cmake file to add N2P2 options to LAMMPS build
message("Creating LAMMPS configuration files.")
configure_file(LAMMPS/Makefile.lammps-extra.config.in ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/Makefile.lammps-extra)
configure_file(LAMMPS/lammps-extra.cmake.config.in ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lammps-extra.cmake)
###################################################################################################

###################################################################################################
# Download LAMMPS if needed
if(DOWNLOAD_LAMMPS)
if (LAMMPS_PATH)
message(WARNING "Specified both LAMMPS_PATH and DOWNLOAD_LAMMPS=ON. Ignoring LAMMPS_PATH.")
endif (LAMMPS_PATH)

message("Downloading LAMMPS to ${CMAKE_BINARY_DIR}/_deps/lammps-nnp-src/")
include(FetchContent)
FetchContent_Declare(lammps-hdnnp
URL https://download.lammps.org/tars/${LAMMPS_VERSION}.tar.gz)
FetchContent_MakeAvailable(lammps-hdnnp)

set(LAMMPS_PATH "${CMAKE_BINARY_DIR}/_deps/lammps-hdnnp-src/")
endif(DOWNLOAD_LAMMPS)
###################################################################################################

if(BUILD_LAMMPS)
###################################################################################################
# Symlink to n2p2 Library from LAMMPS
add_custom_target(link_n2p2 ALL
#COMMAND ${CMAKE_COMMAND} -E make_directory ${LAMMPS_PATH}lib/nnp
COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${LAMMPS_PATH}/lib/hdnnp/liblink
COMMAND ${CMAKE_COMMAND} -E create_symlink ${PROJECT_INCLUDE} ${LAMMPS_PATH}/lib/hdnnp/includelink
COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/Makefile.lammps-extra ${LAMMPS_PATH}/lib/hdnnp/Makefile.lammps
COMMENT "Creating Symlink from LAMMPS to n2p2.")
###################################################################################################

###################################################################################################
# Copy Source Code to LAMMPS
add_custom_target(update_lammps ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/interface/LAMMPS/src/ML-HDNNP/ ${LAMMPS_PATH}src/ML-HDNNP
COMMENT "Updating LAMMPS ML-HDNNP package.")
###################################################################################################

###################################################################################################
# Patch LAMMPS makefile.mpi
add_custom_target(patch_lammps_makefile ALL
COMMAND sed -i.bak "s,^CC .*$$,CC = ${MPI_CXX_COMPILER}," ${LAMMPS_PATH}/src/MAKE/Makefile.mpi
COMMAND sed -i.bak "s,^CCFLAGS .*$$,CCFLAGS = ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_MPI} -I${GSL_INCLUDE_DIRS} -I${EIGEN3_INCLUDE_DIR}," ${LAMMPS_PATH}/src/MAKE/Makefile.mpi
COMMAND sed -i.bak "s,^LINK .*$$,LINK = ${MPI_CXX_COMPILER} ," ${LAMMPS_PATH}/src/MAKE/Makefile.mpi
COMMAND sed -i.bak "s,^LINKFLAGS .*$$,LINKFLAGS = ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_MPI} -L${GSL_LIBRARY_DIR}," ${LAMMPS_PATH}/src/MAKE/Makefile.mpi
COMMENT "Patching LAMMPS makefile.mpi")
###################################################################################################

###################################################################################################
# Build a minimal LAMMPS Executable (uses LAMMPS make build system)
add_custom_target(build_lammps ALL
COMMAND ${CMAKE_COMMAND} -E chdir ${LAMMPS_PATH}/src/ make yes-ml-hdnnp
COMMAND ${CMAKE_COMMAND} -E chdir ${LAMMPS_PATH}/src/ make yes-kspace
COMMAND ${CMAKE_COMMAND} -E chdir ${LAMMPS_PATH}/src/ make yes-molecule
COMMAND ${CMAKE_COMMAND} -E chdir ${LAMMPS_PATH}/src/ make mpi
DEPENDS "${LAMMPS_PATH}/src/ML-HDNNP"
COMMENT "Building minimal LAMMPS Distribution. Version: ${LAMMPS_VERSION}")
install(FILES "${LAMMPS_PATH}/src/lmp_mpi" DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
add_dependencies(build_lammps link_n2p2 update_lammps patch_lammps_makefile nnpif)
###################################################################################################
endif(BUILD_LAMMPS)
5 changes: 5 additions & 0 deletions src/interface/LAMMPS/Makefile.lammps-extra.config.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Settings that the LAMMPS build will import when this package library is used

${LAMMPS_PACKAGE_NAME}_SYSINC = ${N2P2_PROJECT_OPTIONS}
${LAMMPS_PACKAGE_NAME}_SYSLIB = -lnnpif -lnnp -lgsl -lgslcblas
${LAMMPS_PACKAGE_NAME}_SYSPATH =
1 change: 1 addition & 0 deletions src/interface/LAMMPS/lammps-extra.cmake.config.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target_compile_definitions(lammps PRIVATE ${N2P2_PROJECT_OPTIONS})
23 changes: 23 additions & 0 deletions src/libnnp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
###################################################################################################
# CMake Build System for n2p2/libnnp
###################################################################################################

###################################################################################################
# Set Source Files
file(GLOB SRC_FILES "*.cpp")
file(GLOB HDR_FILES "*.h")
###################################################################################################

###################################################################################################
# Specify Build Targets
add_library(nnp ${SRC_FILES})
add_compile_options(${PROJECT_OPTIONS})
configure_file(version.config.h ${CMAKE_CURRENT_SOURCE_DIR}/version.h)
install(FILES ${HDR_FILES} DESTINATION ${PROJECT_INCLUDE}) # Headers copied at install time
###################################################################################################

###################################################################################################
# Find Required Package dependencies
target_link_libraries(nnp PUBLIC MPI::MPI_CXX Eigen3::Eigen)
include_directories(${MPI_INCLUDE_PATH})
###################################################################################################
25 changes: 25 additions & 0 deletions src/libnnp/version.config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// n2p2 - A neural network potential package
// Copyright (C) 2018 Andreas Singraber (University of Vienna)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#ifndef VERSION_H
#define VERSION_H

#define N2P2_VERSION "${PROJECT_VERSION}"
#define N2P2_GIT_VERSION "${GIT_VERSION}"
#define N2P2_GIT_REV "${GIT_REV}"
#define N2P2_GIT_BRANCH "${GIT_BRANCH}"

#endif
Loading