diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 42e6d12ffb..12b713f15c 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -220,6 +220,7 @@ if(BUILD_OMP) endif() if (((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9.0)) OR + (CMAKE_CXX_COMPILER_ID STREQUAL "PGI") OR ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0)) OR ((CMAKE_CXX_COMPILER_ID STREQUAL "Intel") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.0))) # GCC 9.x and later plus Clang 10.x and later implement strict OpenMP 4.0 semantics for consts. @@ -372,7 +373,7 @@ else() set(CUDA_REQUEST_PIC) endif() -foreach(PKG_WITH_INCL KSPACE PYTHON VORONOI USER-COLVARS USER-MOLFILE USER-NETCDF USER-PLUMED USER-QMMM +foreach(PKG_WITH_INCL KSPACE PYTHON MLIAP VORONOI USER-COLVARS USER-MOLFILE USER-NETCDF USER-PLUMED USER-QMMM USER-QUIP USER-SCAFACOS USER-SMD USER-VTK KIM LATTE MESSAGE MSCG COMPRESS) if(PKG_${PKG_WITH_INCL}) include(Packages/${PKG_WITH_INCL}) @@ -661,7 +662,7 @@ if(BUILD_SHARED_LIBS) add_custom_target( install-python ${Python_EXECUTABLE} install.py -v ${LAMMPS_SOURCE_DIR}/version.h - -m ${LAMMPS_PYTHON_DIR}/lammps.py + -p ${LAMMPS_PYTHON_DIR}/lammps -l ${CMAKE_BINARY_DIR}/liblammps${CMAKE_SHARED_LIBRARY_SUFFIX} WORKING_DIRECTORY ${LAMMPS_PYTHON_DIR} COMMENT "Installing LAMMPS Python module") @@ -691,11 +692,8 @@ if(BUILD_SHARED_LIBS OR PKG_PYTHON) find_package(Python COMPONENTS Interpreter) endif() if (Python_EXECUTABLE) - execute_process(COMMAND ${Python_EXECUTABLE} - -c "import distutils.sysconfig as cg; print(cg.get_python_lib(1,0,prefix='${CMAKE_INSTALL_PREFIX}'))" - OUTPUT_VARIABLE PYTHON_DEFAULT_INSTDIR OUTPUT_STRIP_TRAILING_WHITESPACE) - set(PYTHON_INSTDIR ${PYTHON_DEFAULT_INSTDIR} CACHE PATH "Installation folder for LAMMPS Python module") - install(FILES ${LAMMPS_PYTHON_DIR}/lammps.py DESTINATION ${PYTHON_INSTDIR}) + file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/python) + install(CODE "execute_process(COMMAND ${Python_EXECUTABLE} setup.py build -b ${CMAKE_BINARY_DIR}/python install --prefix=${CMAKE_INSTALL_PREFIX} --root=\$ENV{DESTDIR}/ WORKING_DIRECTORY ${LAMMPS_PYTHON_DIR})") endif() endif() diff --git a/cmake/Modules/FindCythonize.cmake b/cmake/Modules/FindCythonize.cmake new file mode 100644 index 0000000000..9a37904ea7 --- /dev/null +++ b/cmake/Modules/FindCythonize.cmake @@ -0,0 +1,30 @@ +# Find the Cythonize tool. +# +# This code sets the following variables: +# +# Cythonize_EXECUTABLE +# +# adapted from https://github.com/cmarshall108/cython-cmake-example/blob/master/cmake/FindCython.cmake +#============================================================================= + +if(CMAKE_VERSION VERSION_LESS 3.12) + find_package(PythonInterp 3.6 QUIET) # Deprecated since version 3.12 + if(PYTHONINTERP_FOUND) + set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE}) + endif() +else() + find_package(Python3 3.6 COMPONENTS Interpreter QUIET) +endif() + +# Use the Cython executable that lives next to the Python executable +# if it is a local installation. +if(Python3_EXECUTABLE) + get_filename_component(_python_path ${Python3_EXECUTABLE} PATH) + find_program(Cythonize_EXECUTABLE + NAMES cythonize3 cythonize cythonize.bat + HINTS ${_python_path}) +endif() + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Cythonize REQUIRED_VARS Cythonize_EXECUTABLE) +mark_as_advanced(Cythonize_EXECUTABLE) diff --git a/cmake/Modules/LAMMPSUtils.cmake b/cmake/Modules/LAMMPSUtils.cmake index 339ba867bd..37275843fa 100644 --- a/cmake/Modules/LAMMPSUtils.cmake +++ b/cmake/Modules/LAMMPSUtils.cmake @@ -50,6 +50,7 @@ function(check_for_autogen_files source_dir) file(GLOB SRC_AUTOGEN_FILES ${source_dir}/style_*.h) file(GLOB SRC_AUTOGEN_PACKAGES ${source_dir}/packages_*.h) list(APPEND SRC_AUTOGEN_FILES ${SRC_AUTOGEN_PACKAGES} ${source_dir}/lmpinstalledpkgs.h ${source_dir}/lmpgitversion.h) + list(APPEND SRC_AUTOGEN_FILES ${SRC_AUTOGEN_PACKAGES} ${source_dir}/mliap_model_python_couple.h ${source_dir}/mliap_model_python_couple.cpp) foreach(_SRC ${SRC_AUTOGEN_FILES}) get_filename_component(FILENAME "${_SRC}" NAME) if(EXISTS ${source_dir}/${FILENAME}) diff --git a/cmake/Modules/Packages/KIM.cmake b/cmake/Modules/Packages/KIM.cmake index 42b7bb884d..83a96d02b8 100644 --- a/cmake/Modules/Packages/KIM.cmake +++ b/cmake/Modules/Packages/KIM.cmake @@ -19,6 +19,8 @@ if(CURL_FOUND) target_compile_definitions(lammps PRIVATE -DLMP_NO_SSL_CHECK) endif() endif() +set(KIM_EXTRA_UNITTESTS OFF CACHE STRING "Set extra unit tests verbose mode on/off. If on, extra tests are included.") +mark_as_advanced(KIM_EXTRA_UNITTESTS) find_package(PkgConfig QUIET) set(DOWNLOAD_KIM_DEFAULT ON) if(PKG_CONFIG_FOUND) @@ -34,8 +36,8 @@ if(DOWNLOAD_KIM) enable_language(C) enable_language(Fortran) ExternalProject_Add(kim_build - URL https://s3.openkim.org/kim-api/kim-api-2.2.0.txz - URL_MD5 e7f944e1593cffd7444679a660607f6c + URL https://s3.openkim.org/kim-api/kim-api-2.2.1.txz + URL_MD5 ae1ddda2ef7017ea07934e519d023dca BINARY_DIR build CMAKE_ARGS ${CMAKE_REQUEST_PIC} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} diff --git a/cmake/Modules/Packages/MLIAP.cmake b/cmake/Modules/Packages/MLIAP.cmake new file mode 100644 index 0000000000..d3f601a1e1 --- /dev/null +++ b/cmake/Modules/Packages/MLIAP.cmake @@ -0,0 +1,31 @@ +# if PYTHON package is included we may also include Python support in MLIAP +set(MLIAP_ENABLE_PYTHON_DEFAULT OFF) +if(PKG_PYTHON) + find_package(Cythonize) + if(Cythonize_FOUND) + set(MLIAP_ENABLE_PYTHON_DEFAULT ON) + endif() +endif() + +option(MLIAP_ENABLE_PYTHON "Build MLIAP package with Python support" ${MLIAP_ENABLE_PYTHON_DEFAULT}) + +if(MLIAP_ENABLE_PYTHON) + find_package(Cythonize REQUIRED) + if(NOT PKG_PYTHON) + message(FATAL_ERROR "Must enable PYTHON package for including Python support in MLIAP") + endif() + + set(MLIAP_BINARY_DIR ${CMAKE_BINARY_DIR}/cython) + set(MLIAP_CYTHON_SRC ${LAMMPS_SOURCE_DIR}/MLIAP/mliap_model_python_couple.pyx) + get_filename_component(MLIAP_CYTHON_BASE ${MLIAP_CYTHON_SRC} NAME_WE) + file(MAKE_DIRECTORY ${MLIAP_BINARY_DIR}) + add_custom_command(OUTPUT ${MLIAP_BINARY_DIR}/${MLIAP_CYTHON_BASE}.cpp ${MLIAP_BINARY_DIR}/${MLIAP_CYTHON_BASE}.h + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${MLIAP_CYTHON_SRC} ${MLIAP_BINARY_DIR}/${MLIAP_CYTHON_BASE}.pyx + COMMAND ${Cythonize_EXECUTABLE} -3 ${MLIAP_BINARY_DIR}/${MLIAP_CYTHON_BASE}.pyx + WORKING_DIRECTORY ${MLIAP_BINARY_DIR} + MAIN_DEPENDENCY ${MLIAP_CYTHON_SRC} + COMMENT "Generating C++ sources with cythonize...") + target_compile_definitions(lammps PRIVATE -DMLIAP_PYTHON) + target_sources(lammps PRIVATE ${MLIAP_BINARY_DIR}/${MLIAP_CYTHON_BASE}.cpp) + target_include_directories(lammps PRIVATE ${MLIAP_BINARY_DIR}) +endif() diff --git a/cmake/Modules/Packages/USER-PLUMED.cmake b/cmake/Modules/Packages/USER-PLUMED.cmake index 74add65cdc..53abf5771a 100644 --- a/cmake/Modules/Packages/USER-PLUMED.cmake +++ b/cmake/Modules/Packages/USER-PLUMED.cmake @@ -55,8 +55,8 @@ if(DOWNLOAD_PLUMED) endif() include(ExternalProject) ExternalProject_Add(plumed_build - URL https://github.com/plumed/plumed2/releases/download/v2.6.1/plumed-src-2.6.1.tgz - URL_MD5 89a9a450fc6025299fe16af235957163 + URL https://github.com/plumed/plumed2/releases/download/v2.7.0/plumed-src-2.7.0.tgz + URL_MD5 95f29dd0c067577f11972ff90dfc7d12 BUILD_IN_SOURCE 1 CONFIGURE_COMMAND /configure --prefix= ${CONFIGURE_REQUEST_PIC} diff --git a/cmake/presets/pgi.cmake b/cmake/presets/pgi.cmake new file mode 100644 index 0000000000..b34cb05331 --- /dev/null +++ b/cmake/presets/pgi.cmake @@ -0,0 +1,16 @@ +# preset that will enable clang/clang++ with support for MPI and OpenMP (on Linux boxes) + +set(CMAKE_CXX_COMPILER "pgc++" CACHE STRING "" FORCE) +set(CMAKE_C_COMPILER "pgcc" CACHE STRING "" FORCE) +set(CMAKE_Fortran_COMPILER "pgfortran" CACHE STRING "" FORCE) +set(MPI_CXX "pgc++" CACHE STRING "" FORCE) +set(MPI_CXX_COMPILER "mpicxx" CACHE STRING "" FORCE) +unset(HAVE_OMP_H_INCLUDE CACHE) + +set(OpenMP_C "pgcc" CACHE STRING "" FORCE) +set(OpenMP_C_FLAGS "-mp" CACHE STRING "" FORCE) +set(OpenMP_C_LIB_NAMES "omp" CACHE STRING "" FORCE) +set(OpenMP_CXX "pgc++" CACHE STRING "" FORCE) +set(OpenMP_CXX_FLAGS "-mp" CACHE STRING "" FORCE) +set(OpenMP_CXX_LIB_NAMES "omp" CACHE STRING "" FORCE) +set(OpenMP_omp_LIBRARY "libomp.so" CACHE PATH "" FORCE) diff --git a/doc/Makefile b/doc/Makefile index 59700f03aa..041c7a372a 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -229,7 +229,7 @@ $(VENV): $(VIRTUALENV) -p $(PYTHON) $(VENV); \ . $(VENV)/bin/activate; \ pip install --upgrade pip; \ - pip install --use-feature=2020-resolver -r $(BUILDDIR)/utils/requirements.txt; \ + pip install -r $(BUILDDIR)/utils/requirements.txt; \ deactivate;\ ) diff --git a/doc/lammps.1 b/doc/lammps.1 index 5fc4795ba7..299f8538b0 100644 --- a/doc/lammps.1 +++ b/doc/lammps.1 @@ -1,4 +1,4 @@ -.TH LAMMPS "30 November 2020" "2020-10-29" +.TH LAMMPS "24 December 2020" "2020-12-24" .SH NAME .B LAMMPS \- Molecular Dynamics Simulator. diff --git a/doc/src/Build_basics.rst b/doc/src/Build_basics.rst index 8f40d3e5ba..cb6bd9f6aa 100644 --- a/doc/src/Build_basics.rst +++ b/doc/src/Build_basics.rst @@ -236,12 +236,15 @@ LAMMPS. cmake ../cmake -DCMAKE_C_COMPILER=icc -DCMAKE_CXX_COMPILER=icpc -DCMAKE_Fortran_COMPILER=ifort # Building with LLVM/Clang Compilers: cmake ../cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_Fortran_COMPILER=flang + # Building with PGI/Nvidia Compilers: + cmake ../cmake -DCMAKE_C_COMPILER=pgcc -DCMAKE_CXX_COMPILER=pgc++ -DCMAKE_Fortran_COMPILER=pgfortran For compiling with the Clang/LLVM compilers a CMake preset is provided that can be loaded with `-C ../cmake/presets/clang.cmake`. Similarly, `-C ../cmake/presets/intel.cmake` should switch the compiler - toolchain to the Intel compilers. + toolchain to the Intel compilers and `-C ../cmake/presets/pgi.cmake` + should switch the compiler to the PGI compilers. In addition you can set ``CMAKE_TUNE_FLAGS`` to specifically add compiler flags to tune for optimal performance on given hosts. By diff --git a/doc/src/Build_extras.rst b/doc/src/Build_extras.rst index 5ef29fbca1..78165f0150 100644 --- a/doc/src/Build_extras.rst +++ b/doc/src/Build_extras.rst @@ -37,6 +37,7 @@ This is the list of packages that may require additional steps. * :ref:`KOKKOS ` * :ref:`LATTE ` * :ref:`MESSAGE ` + * :ref:`MLIAP ` * :ref:`MSCG ` * :ref:`OPT ` * :ref:`POEMS ` @@ -282,6 +283,7 @@ minutes to hours) to build. Of course you only need to do that once.) -D DOWNLOAD_KIM=value # download OpenKIM API v2 for build, value = no (default) or yes -D LMP_DEBUG_CURL=value # set libcurl verbose mode on/off, value = off (default) or on -D LMP_NO_SSL_CHECK=value # tell libcurl to not verify the peer, value = no (default) or yes + -D KIM_EXTRA_UNITTESTS=value # enables extra unit tests, value = no (default) or yes If ``DOWNLOAD_KIM`` is set to *yes* (or *on*), the KIM API library will be downloaded and built inside the CMake build directory. If @@ -290,6 +292,11 @@ minutes to hours) to build. Of course you only need to do that once.) ``PKG_CONFIG_PATH`` environment variable so that libkim-api can be found, or run the command ``source kim-api-activate``. + Extra unit tests can only be available if they are explicitly requested + (``KIM_EXTRA_UNITTESTS`` is set to *yes* (or *on*)) and the prerequisites + are met. See :ref:`KIM Extra unit tests ` for + more details on this. + .. tab:: Traditional make You can download and build the KIM library manually if you prefer; @@ -338,6 +345,38 @@ specify your own CA cert path by setting the environment variable ``CURL_CA_BUNDLE`` to the path of your choice. A call to the KIM web query would get this value from the environment variable. +.. _kim_extra_unittests: + +KIM Extra unit tests (CMake only) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +During development, testing, or debugging, if +:doc:`unit testing ` is enabled in LAMMPS, one can also +enable extra tests on :doc:`KIM commands ` by setting the +``KIM_EXTRA_UNITTESTS`` to *yes* (or *on*). + +Enabling the extra unit tests have some requirements, + +* It requires to have internet access. +* It requires to have libcurl installed with the matching development headers + and the curl-config tool. +* It requires to build LAMMPS with the PYTHON package installed and linked to + Python 3.6 or later. See the :ref:`PYTHON package build info ` for + more details on this. +* It requires to have ``kim-property`` Python package installed, which can be + easily done using *pip* as ``pip install kim-property``, or from the + *conda-forge* channel as ``conda install kim-property`` if LAMMPS is built in + Conda. More detailed information is available at: + `kim-property installation `_. +* It is also necessary to install + ``EAM_Dynamo_Mendelev_2007_Zr__MO_848899341753_000``, and + ``EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005`` KIM models. + See `Obtaining KIM Models `_ + to learn how to install a pre-build binary of the OpenKIM Repository of + Models or see + `Installing KIM Models `_ + to learn how to install the specific KIM models. + ---------- .. _kokkos: @@ -732,6 +771,54 @@ be installed on your system. ---------- +.. _mliap: + +MLIAP package +--------------------------- + +Building the MLIAP package requires including the :ref:`SNAP ` +package. There will be an error message if this requirement is not satisfied. +Using the *mliappy* model also requires enabling Python support, which +in turn requires the :ref:`PYTHON ` +package **and** requires you have the `cython `_ software +installed and with it a working ``cythonize`` command. This feature requires +compiling LAMMPS with Python version 3.6 or later. + +.. tabs:: + + .. tab:: CMake build + + .. code-block:: bash + + -D MLIAP_ENABLE_PYTHON=value # enable mliappy model (default is autodetect) + + Without this setting, CMake will check whether it can find a + suitable Python version and the ``cythonize`` command and choose + the default accordingly. During the build procedure the provided + .pyx file(s) will be automatically translated to C++ code and compiled. + Please do **not** run ``cythonize`` manually in the ``src/MLIAP`` folder, + as that can lead to compilation errors if Python support is not enabled. + If you did by accident, please remove the generated .cpp and .h files. + + .. tab:: Traditional make + + The build uses the ``lib/python/Makefile.mliap_python`` file in the + compile/link process to add a rule to update the files generated by + the ``cythonize`` command in case the corresponding .pyx file(s) were + modified. You may need to modify ``lib/python/Makefile.lammps`` + if the LAMMPS build fails. + To manually enforce building MLIAP with Python support enabled, + you can add + ``-DMLIAP_PYTHON`` to the ``LMP_INC`` variable in your machine makefile. + You may have to manually run the ``cythonize`` command on .pyx file(s) + in the ``src`` folder, if this is not automatically done during + installing the MLIAP package. Please do **not** run ``cythonize`` + in the ``src/MLIAP`` folder, as that can lead to compilation errors + if Python support is not enabled. + If you did by accident, please remove the generated .cpp and .h files. + +---------- + .. _mscg: MSCG package diff --git a/doc/src/Build_package.rst b/doc/src/Build_package.rst index 18d9ab5f19..63312d7aa8 100644 --- a/doc/src/Build_package.rst +++ b/doc/src/Build_package.rst @@ -1,4 +1,5 @@ Include packages in build + ========================= In LAMMPS, a package is a group of files that enable a specific set of @@ -160,6 +161,7 @@ one of them as a starting point and customize it to your needs. cmake -C ../cmake/presets/clang.cmake [OPTIONS] ../cmake # change settings to use the Clang compilers by default cmake -C ../cmake/presets/gcc.cmake [OPTIONS] ../cmake # change settings to use the GNU compilers by default cmake -C ../cmake/presets/intel.cmake [OPTIONS] ../cmake # change settings to use the Intel compilers by default + cmake -C ../cmake/presets/pgi.cmake [OPTIONS] ../cmake # change settings to use the PGI compilers by default cmake -C ../cmake/presets/all_on.cmake [OPTIONS] ../cmake # enable all packages cmake -C ../cmake/presets/all_off.cmake [OPTIONS] ../cmake # disable all packages mingw64-cmake -C ../cmake/presets/mingw-cross.cmake [OPTIONS] ../cmake # compile with MinGW cross compilers diff --git a/doc/src/Commands_fix.rst b/doc/src/Commands_fix.rst index d1bc20c9ca..26dcc1101c 100644 --- a/doc/src/Commands_fix.rst +++ b/doc/src/Commands_fix.rst @@ -221,6 +221,8 @@ OPT. * :doc:`temp/rescale ` * :doc:`temp/rescale/eff ` * :doc:`tfmc ` + * :doc:`tgnpt/drude ` + * :doc:`tgnvt/drude ` * :doc:`thermal/conductivity ` * :doc:`ti/spring ` * :doc:`tmd ` diff --git a/doc/src/Developer.rst b/doc/src/Developer.rst index a895369a28..3a0c03b7ea 100644 --- a/doc/src/Developer.rst +++ b/doc/src/Developer.rst @@ -13,6 +13,7 @@ of time and requests from the LAMMPS user community. Developer_org Developer_flow Developer_write + Developer_notes Developer_unittest Classes Developer_utils diff --git a/doc/src/Developer_notes.rst b/doc/src/Developer_notes.rst new file mode 100644 index 0000000000..87ef97ea7b --- /dev/null +++ b/doc/src/Developer_notes.rst @@ -0,0 +1,105 @@ +Notes for Developers and Code Maintainers +----------------------------------------- + +This section documents how a few large sections of code with LAMMPS +work at a conceptual level. Comments on code in source files +typically document what a variable stores, what a small section of +code does, or what a function does or its input/outputs. The topics +on this page are intended to document code at a higher level. + +KSpace PPPM FFT grids +^^^^^^^^^^^^^^^^^^^^^ + +The various :doc:`KSpace PPPM ` styles in LAMMPS use +FFTs to solve Poisson's equation. This subsection describes: + +* how FFT grids are defined +* how they are decomposed across processors +* how they are indexed by each processor +* how particle charge and electric field values are mapped to/from + the grid + +An FFT grid cell is a 3d volume; grid points are corners of a grid +cell and the code stores values assigned to grid points in vectors or +3d arrays. A global 3d FFT grid has points indexed 0 to N-1 inclusive +in each dimension. + +Each processor owns two subsets of the grid, each subset is +brick-shaped. Depending on how it is used, these subsets are +allocated as a 1d vector or 3d array. Either way, the ordering of +values within contiguous memory x fastest, then y, z slowest. + +For the ``3d decomposition`` of the grid, the global grid is +partitioned into bricks that correspond to the sub-domains of the +simulation box that each processor owns. Often, this is a regular 3d +array (Px by Py by Pz) of bricks, where P = number of processors = +Px * Py * Pz. More generally it can be a tiled decomposition, where +each processor owns a brick and the union of all the bricks is the +global grid. Tiled decompositions are produced by load balancing with +the RCB algorithm; see the :doc:`balance rcb ` command. + +For the ``FFT decompostion`` of the grid, each processor owns a brick +that spans the entire x dimension of the grid while the y and z +dimensions are partitioned as a regular 2d array (P1 by P2), where P = +P1 * P2. + +The following indices store the inclusive bounds of the brick a +processor owns, within the global grid: + +.. parsed-literal:: + + nxlo_in,nxhi_in,nylo_in,nyhi_in,nzlo_in,nzhi_in = 3d decomposition brick + nxlo_fft,nxhi_fft,nylo_fft,nyhi_fft,nzlo_fft,nzhi_fft = FFT decomposition brick + nxlo_out,nxhi_out,nylo_out,nyhi_out,nzlo_out,nzhi_out = 3d decomposition brick + ghost cells + +The ``in`` and ``fft`` indices are from 0 to N-1 inclusive in each +dimension, where N is the grid size. + +The ``out`` indices index an array which stores the ``in`` subset of +the grid plus ghost cells that surround it. These indices can thus be +< 0 or >= N. + +The number of ghost cells a processor owns in each of the 6 directions +is a function of: + +.. parsed-literal:: + + neighbor skin distance (since atoms can move outside a proc subdomain) + qdist = offset or charge from atom due to TIP4P fictitious charge + order = mapping stencil size + shift = factor used when order is an even number (see below) + +Here is an explanation of how the PPPM variables ``order``, +``nlower`` / ``nupper``, ``shift``, and ``OFFSET`` work. They are the +relevant variables that determine how atom charge is mapped to grid +points and how field values are mapped from grid points to atoms: + +.. parsed-literal:: + + order = # of nearby grid points in each dim that atom charge/field are mapped to/from + nlower,nupper = extent of stencil around the grid point an atom is assigned to + OFFSET = large integer added/subtracted when mapping to avoid int(-0.75) = 0 when -1 is the desired result + +The particle_map() method assigns each atom to a grid point. + +If order is even, say 4: + +.. parsed-literal:: + + atom is assigned to grid point to its left (in each dim) + shift = OFFSET + nlower = -1, nupper = 2, which are offsets from assigned grid point + window of mapping grid pts is thus 2 grid points to left of atom, 2 to right + +If order is odd, say 5: + +.. parsed-literal:: + + atom is assigned to left/right grid pt it is closest to (in each dim) + shift = OFFSET + 0.5 + nlower = 2, nupper = 2 + if point is in left half of cell, then window of affected grid pts is 3 grid points to left of atom, 2 to right + if point is in right half of cell, then window of affected grid pts is 2 grid points to left of atom, 3 to right + +These settings apply to each dimension, so that if order = 5, an +atom's charge is mapped to 125 grid points that surround the atom. diff --git a/doc/src/Howto_drude.rst b/doc/src/Howto_drude.rst index c866340e77..7c1022b784 100644 --- a/doc/src/Howto_drude.rst +++ b/doc/src/Howto_drude.rst @@ -42,10 +42,11 @@ screening. It may be necessary to use the *extra/special/per/atom* keyword of the :doc:`read_data ` command. If using :doc:`fix shake `, make sure no Drude particle is in this fix group. -There are two ways to thermostat the Drude particles at a low +There are three ways to thermostat the Drude particles at a low temperature: use either :doc:`fix langevin/drude ` for a Langevin thermostat, or :doc:`fix drude/transform/\* ` for a Nose-Hoover -thermostat. The former requires use of the command :doc:`comm_modify vel yes `. The latter requires two separate integration +thermostat, or :doc:`fix tgnvt/drude ` for a temperature-grouped Nose-Hoover thermostat. +The first and third require use of the command :doc:`comm_modify vel yes `. The second requires two separate integration fixes like *nvt* or *npt*\ . The correct temperatures of the reduced degrees of freedom can be calculated using the :doc:`compute temp/drude `. This requires also to use the command *comm_modify vel yes*. diff --git a/doc/src/Howto_drude2.rst b/doc/src/Howto_drude2.rst index b0b910a832..d95f5c02aa 100644 --- a/doc/src/Howto_drude2.rst +++ b/doc/src/Howto_drude2.rst @@ -221,6 +221,14 @@ modification of forces but no position/velocity updates), the fix fix NVE all nve +To avoid the flying ice cube artifact, where the atoms progressively freeze and the +center of mass of the whole system drifts faster and faster, the *fix momentum* +can be used. For instance: + +.. code-block:: LAMMPS + + fix MOMENTUM all momentum 100 linear 1 1 1 + Finally, do not forget to update the atom type elements if you use them in a *dump_modify ... element ...* command, by adding the element type of the DPs. Here for instance @@ -376,14 +384,7 @@ For our phenol example, the groups would be defined as Note that with the fixes *drude/transform*\ , it is not required to specify *comm_modify vel yes* because the fixes do it anyway (several -times and for the forces also). To avoid the flying ice cube artifact -:ref:`(Lamoureux and Roux) `, where the atoms progressively freeze and the -center of mass of the whole system drifts faster and faster, the *fix -momentum* can be used. For instance: - -.. code-block:: LAMMPS - - fix MOMENTUM all momentum 100 linear 1 1 1 +times and for the forces also). It is a bit more tricky to run a NPT simulation with Nose-Hoover barostat and thermostat. First, the volume should be integrated only @@ -404,6 +405,31 @@ instructions for thermostatting and barostatting will look like fix NVT DRUDES nvt temp 1. 1. 20 fix INVERSE all drude/transform/inverse +Another option for thermalizing the Drude model is to use the +temperature-grouped Nose-Hoover (TGNH) thermostat proposed by :ref:`(Son) `. +This is implemented as :doc:`fix tgnvt/drude ` and :doc:`fix tgnpt/drude `. +It separates the kinetic energy into three contributions: +the molecular center of mass (COM) motion, the motion of atoms or atom-Drude pairs relative to molecular COMs, +and the relative motion of atom-Drude pairs. +An independent Nose-Hoover chain is applied to each type of motion. +When TGNH is used, the temperatures of molecular, atomic and Drude motion can be printed out with :doc:`thermo_style` command. + +NVT simulation with TGNH thermostat + +.. code-block:: LAMMPS + + comm_modify vel yes + fix TGNVT all tgnvt/drude temp 300. 300. 100 1. 20 + thermo_style custom f_TGNVT[1] f_TGNVT[2] f_TGNVT[3] + +NPT simulation with TGNH thermostat + +.. code-block:: LAMMPS + + comm_modify vel yes + fix TGNPT all tgnpt/drude temp 300. 300. 100 1. 20 iso 1. 1. 500 + thermo_style custom f_TGNPT[1] f_TGNPT[2] f_TGNPT[3] + ---------- **Rigid bodies** @@ -480,3 +506,7 @@ NPT ensemble using Nose-Hoover thermostat: **(SWM4-NDP)** Lamoureux, Harder, Vorobyov, Roux, MacKerell, Chem Phys Let, 418, 245-249 (2006) + +.. _TGNH-Son: + +**(Son)** Son, McDaniel, Cui and Yethiraj, J Phys Chem Lett, 10, 7523 (2019). diff --git a/doc/src/Howto_pylammps.rst b/doc/src/Howto_pylammps.rst index 89119e89af..e6d3d7b91d 100644 --- a/doc/src/Howto_pylammps.rst +++ b/doc/src/Howto_pylammps.rst @@ -9,8 +9,8 @@ Overview ``PyLammps`` is a Python wrapper class for LAMMPS which can be created on its own or use an existing lammps Python object. It creates a simpler, more "pythonic" interface to common LAMMPS functionality, in contrast to -the ``lammps.py`` wrapper for the C-style LAMMPS library interface which -is written using `Python ctypes `_. The ``lammps.py`` wrapper +the ``lammps`` wrapper for the C-style LAMMPS library interface which +is written using `Python ctypes `_. The ``lammps`` wrapper is discussed on the :doc:`Python_head` doc page. Unlike the flat ``ctypes`` interface, PyLammps exposes a discoverable diff --git a/doc/src/Packages_details.rst b/doc/src/Packages_details.rst index 2b2cb90aff..e044adfcb3 100644 --- a/doc/src/Packages_details.rst +++ b/doc/src/Packages_details.rst @@ -662,19 +662,31 @@ MLIAP package **Contents:** -A general interface for machine-learning interatomic potentials. +A general interface for machine-learning interatomic potentials, including PyTorch. **Install:** -To use this package, also the :ref:`SNAP package ` needs to be installed. +To use this package, also the :ref:`SNAP package ` package needs +to be installed. To make the *mliappy* model available, also the +:ref:`PYTHON package ` package needs to be installed, the version of +Python must be 3.6 or later, and the `cython `_ software +must be installed. -**Author:** Aidan Thompson (Sandia). +**Author:** Aidan Thompson (Sandia), Nicholas Lubbers (LANL). **Supporting info:** * src/MLIAP: filenames -> commands +* src/MLIAP/README * :doc:`pair_style mliap ` -* examples/mliap +* :doc:`compute_style mliap ` +* examples/mliap (see README) + +When built with the *mliappy* model this package includes an extension for +coupling with Python models, including PyTorch. In this case, the Python +interpreter linked to LAMMPS will need the ``cython`` and ``numpy`` modules +installed. The provided examples build models with PyTorch, which would +therefore also needs to be installed to run those examples. ---------- diff --git a/doc/src/Python_ext.rst b/doc/src/Python_ext.rst index 6b6d1ab715..8966ffcb2a 100644 --- a/doc/src/Python_ext.rst +++ b/doc/src/Python_ext.rst @@ -9,7 +9,7 @@ This means you can extend the Python wrapper by following these steps: * Add a new interface function to ``src/library.cpp`` and ``src/library.h``. * Rebuild LAMMPS as a shared library. -* Add a wrapper method to ``python/lammps.py`` for this interface +* Add a wrapper method to ``python/lammps/core.py`` for this interface function. * Define the corresponding ``argtypes`` list and ``restype`` in the ``lammps.__init__()`` function. diff --git a/doc/src/Python_install.rst b/doc/src/Python_install.rst index 88d32895a3..c12644bf4a 100644 --- a/doc/src/Python_install.rst +++ b/doc/src/Python_install.rst @@ -8,9 +8,9 @@ module. Because of the dynamic loading, it is required that LAMMPS is compiled in :ref:`"shared" mode `. It is also recommended to compile LAMMPS with :ref:`C++ exceptions ` enabled. -Two files are necessary for Python to be able to invoke LAMMPS code: +Two components are necessary for Python to be able to invoke LAMMPS code: -* The LAMMPS Python Module (``lammps.py``) from the ``python`` folder +* The LAMMPS Python Package (``lammps``) from the ``python`` folder * The LAMMPS Shared Library (``liblammps.so``, ``liblammps.dylib`` or ``liblammps.dll``) from the folder where you compiled LAMMPS. @@ -25,10 +25,10 @@ Installing the LAMMPS Python Module and Shared Library ====================================================== Making LAMMPS usable within Python and vice versa requires putting the -LAMMPS Python module file (``lammps.py``) into a location where the +LAMMPS Python package (``lammps``) into a location where the Python interpreter can find it and installing the LAMMPS shared library -into a folder that the dynamic loader searches or into the same folder -where the ``lammps.py`` file is. There are multiple ways to achieve +into a folder that the dynamic loader searches or inside of the installed +``lammps`` package folder. There are multiple ways to achieve this. #. Do a full LAMMPS installation of libraries, executables, selected @@ -36,13 +36,13 @@ this. available via CMake), which can also be either system-wide or into user specific folders. -#. Install both files into a Python ``site-packages`` folder, either +#. Install both components into a Python ``site-packages`` folder, either system-wide or in the corresponding user-specific folder. This way no additional environment variables need to be set, but the shared library is otherwise not accessible. -#. Do an installation into a virtual environment. This can either be - an installation of the python module only or a full installation. +#. Do an installation into a virtual environment. This can either be an + installation of the Python package only or a full installation of LAMMPS. #. Leave the files where they are in the source/development tree and adjust some environment variables. @@ -81,19 +81,19 @@ this. This leads to an installation to the following locations: - +------------------------+-----------------------------------------------------------+-------------------------------------------------------------+ - | File | Location | Notes | - +========================+===========================================================+=============================================================+ - | LAMMPS Python Module | * ``$HOME/.local/lib/pythonX.Y/site-packages/`` (32bit) | ``X.Y`` depends on the installed Python version | - | | * ``$HOME/.local/lib64/pythonX.Y/site-packages/`` (64bit) | | - +------------------------+-----------------------------------------------------------+-------------------------------------------------------------+ - | LAMMPS shared library | * ``$HOME/.local/lib/`` (32bit) | | - | | * ``$HOME/.local/lib64/`` (64bit) | | - +------------------------+-----------------------------------------------------------+-------------------------------------------------------------+ - | LAMMPS executable | * ``$HOME/.local/bin/`` | | - +------------------------+-----------------------------------------------------------+-------------------------------------------------------------+ - | LAMMPS potential files | * ``$HOME/.local/share/lammps/potentials/`` | Set ``LAMMPS_POTENTIALS`` environment variable to this path | - +------------------------+-----------------------------------------------------------+-------------------------------------------------------------+ + +------------------------+-----------------------------------------------------------------+-------------------------------------------------------------+ + | File | Location | Notes | + +========================+=================================================================+=============================================================+ + | LAMMPS Python package | * ``$HOME/.local/lib/pythonX.Y/site-packages/lammps`` (32bit) | ``X.Y`` depends on the installed Python version | + | | * ``$HOME/.local/lib64/pythonX.Y/site-packages/lammps`` (64bit) | | + +------------------------+-----------------------------------------------------------------+-------------------------------------------------------------+ + | LAMMPS shared library | * ``$HOME/.local/lib/`` (32bit) | Set shared loader environment variable to this path | + | | * ``$HOME/.local/lib64/`` (64bit) | (see below for more info on this) | + +------------------------+-----------------------------------------------------------------+-------------------------------------------------------------+ + | LAMMPS executable | * ``$HOME/.local/bin/`` | | + +------------------------+-----------------------------------------------------------------+-------------------------------------------------------------+ + | LAMMPS potential files | * ``$HOME/.local/share/lammps/potentials/`` | Set ``LAMMPS_POTENTIALS`` environment variable to this path | + +------------------------+-----------------------------------------------------------------+-------------------------------------------------------------+ For a system-wide installation you need to set ``CMAKE_INSTALL_PREFIX`` to a system folder like ``/usr`` (or @@ -102,19 +102,19 @@ this. privilege, e.g. by using ``sudo cmake --install .``. The installation folders will then by changed to: - +------------------------+---------------------------------------------------+-------------------------------------------------------------+ - | File | Location | Notes | - +========================+===================================================+=============================================================+ - | LAMMPS Python Module | * ``/usr/lib/pythonX.Y/site-packages/`` (32bit) | ``X.Y`` depends on the installed Python version | - | | * ``/usr/lib64/pythonX.Y/site-packages/`` (64bit) | | - +------------------------+---------------------------------------------------+-------------------------------------------------------------+ - | LAMMPS shared library | * ``/usr/lib/`` (32bit) | | - | | * ``/usr/lib64/`` (64bit) | | - +------------------------+---------------------------------------------------+-------------------------------------------------------------+ - | LAMMPS executable | * ``/usr/bin/`` | | - +------------------------+---------------------------------------------------+-------------------------------------------------------------+ - | LAMMPS potential files | * ``/usr/share/lammps/potentials/`` | | - +------------------------+---------------------------------------------------+-------------------------------------------------------------+ + +------------------------+---------------------------------------------------------+-------------------------------------------------------------+ + | File | Location | Notes | + +========================+=========================================================+=============================================================+ + | LAMMPS Python package | * ``/usr/lib/pythonX.Y/site-packages/lammps`` (32bit) | ``X.Y`` depends on the installed Python version | + | | * ``/usr/lib64/pythonX.Y/site-packages/lammps`` (64bit) | | + +------------------------+---------------------------------------------------------+-------------------------------------------------------------+ + | LAMMPS shared library | * ``/usr/lib/`` (32bit) | | + | | * ``/usr/lib64/`` (64bit) | | + +------------------------+---------------------------------------------------------+-------------------------------------------------------------+ + | LAMMPS executable | * ``/usr/bin/`` | | + +------------------------+---------------------------------------------------------+-------------------------------------------------------------+ + | LAMMPS potential files | * ``/usr/share/lammps/potentials/`` | | + +------------------------+---------------------------------------------------------+-------------------------------------------------------------+ To be able to use the "user" installation you have to ensure that the folder containing the LAMMPS shared library is either included @@ -146,7 +146,7 @@ this. necessary due to files installed in system folders that are loaded automatically when a login shell is started. - .. tab:: Python module only + .. tab:: Python package only Compile LAMMPS with either :doc:`CMake ` or the :doc:`traditional make ` procedure in :ref:`shared @@ -157,37 +157,37 @@ this. make install-python - This will try to install (only) the shared library and the python - module into a system folder and if that fails (due to missing + This will try to install (only) the shared library and the Python + package into a system folder and if that fails (due to missing write permissions) will instead do the installation to a user folder under ``$HOME/.local``. For a system-wide installation you would have to gain superuser privilege, e.g. though ``sudo`` - +------------------------+-----------------------------------------------------------+-------------------------------------------------------------+ - | File | Location | Notes | - +========================+===========================================================+=============================================================+ - | LAMMPS Python Module | * ``$HOME/.local/lib/pythonX.Y/site-packages/`` (32bit) | ``X.Y`` depends on the installed Python version | - | | * ``$HOME/.local/lib64/pythonX.Y/site-packages/`` (64bit) | | - +------------------------+-----------------------------------------------------------+-------------------------------------------------------------+ - | LAMMPS shared library | * ``$HOME/.local/lib/pythonX.Y/site-packages/`` (32bit) | ``X.Y`` depends on the installed Python version | - | | * ``$HOME/.local/lib64/pythonX.Y/site-packages/`` (64bit) | | - +------------------------+-----------------------------------------------------------+-------------------------------------------------------------+ + +------------------------+-----------------------------------------------------------------+-------------------------------------------------------------+ + | File | Location | Notes | + +========================+=================================================================+=============================================================+ + | LAMMPS Python package | * ``$HOME/.local/lib/pythonX.Y/site-packages/lammps`` (32bit) | ``X.Y`` depends on the installed Python version | + | | * ``$HOME/.local/lib64/pythonX.Y/site-packages/lammps`` (64bit) | | + +------------------------+-----------------------------------------------------------------+-------------------------------------------------------------+ + | LAMMPS shared library | * ``$HOME/.local/lib/pythonX.Y/site-packages/lammps`` (32bit) | ``X.Y`` depends on the installed Python version | + | | * ``$HOME/.local/lib64/pythonX.Y/site-packages/lammps`` (64bit) | | + +------------------------+-----------------------------------------------------------------+-------------------------------------------------------------+ For a system-wide installation those folders would then become. - +------------------------+---------------------------------------------------+-------------------------------------------------------------+ - | File | Location | Notes | - +========================+===================================================+=============================================================+ - | LAMMPS Python Module | * ``/usr/lib/pythonX.Y/site-packages/`` (32bit) | ``X.Y`` depends on the installed Python version | - | | * ``/usr/lib64/pythonX.Y/site-packages/`` (64bit) | | - +------------------------+---------------------------------------------------+-------------------------------------------------------------+ - | LAMMPS shared library | * ``/usr/lib/pythonX.Y/site-packages/`` (32bit) | ``X.Y`` depends on the installed Python version | - | | * ``/usr/lib64/pythonX.Y/site-packages/`` (64bit) | | - +------------------------+---------------------------------------------------+-------------------------------------------------------------+ + +------------------------+---------------------------------------------------------+-------------------------------------------------------------+ + | File | Location | Notes | + +========================+=========================================================+=============================================================+ + | LAMMPS Python package | * ``/usr/lib/pythonX.Y/site-packages/lammps`` (32bit) | ``X.Y`` depends on the installed Python version | + | | * ``/usr/lib64/pythonX.Y/site-packages/lammps`` (64bit) | | + +------------------------+---------------------------------------------------------+-------------------------------------------------------------+ + | LAMMPS shared library | * ``/usr/lib/pythonX.Y/site-packages/lammps`` (32bit) | ``X.Y`` depends on the installed Python version | + | | * ``/usr/lib64/pythonX.Y/site-packages/lammps`` (64bit) | | + +------------------------+---------------------------------------------------------+-------------------------------------------------------------+ No environment variables need to be set for those, as those folders are searched by default by Python or the LAMMPS Python - module. + package. For the traditional make process you can override the python version to version x.y when calling ``make`` with @@ -199,9 +199,9 @@ this. .. code-block:: bash - $ python install.py -m -l -v [-d ] + $ python install.py -p -l -v [-d ] - * The ``-m`` flag points to the ``lammps.py`` python module file to be installed, + * The ``-p`` flag points to the ``lammps`` Python package folder to be installed, * the ``-l`` flag points to the LAMMPS shared library file to be installed, * the ``-v`` flag points to the ``version.h`` file in the LAMMPS source * and the optional ``-d`` flag to a custom (legacy) installation folder @@ -249,38 +249,38 @@ this. When using CMake to build LAMMPS, you need to set ``CMAKE_INSTALL_PREFIX`` to the value of the ``$VIRTUAL_ENV`` environment variable during the configuration step. For the - traditional make procedure, not additional steps are needed. - After compiling LAMMPS you can do a "Python module only" + traditional make procedure, no additional steps are needed. + After compiling LAMMPS you can do a "Python package only" installation with ``make install-python`` and the LAMMPS Python - module and the shared library file are installed into the + package and the shared library file are installed into the following locations: - +------------------------+-----------------------------------------------------------+-------------------------------------------------------------+ - | File | Location | Notes | - +========================+===========================================================+=============================================================+ - | LAMMPS Python Module | * ``$VIRTUAL_ENV/lib/pythonX.Y/site-packages/`` (32bit) | ``X.Y`` depends on the installed Python version | - | | * ``$VIRTUAL_ENV/lib64/pythonX.Y/site-packages/`` (64bit) | | - +------------------------+-----------------------------------------------------------+-------------------------------------------------------------+ - | LAMMPS shared library | * ``$VIRTUAL_ENV/lib/pythonX.Y/site-packages/`` (32bit) | ``X.Y`` depends on the installed Python version | - | | * ``$VIRTUAL_ENV/lib64/pythonX.Y/site-packages/`` (64bit) | | - +------------------------+-----------------------------------------------------------+-------------------------------------------------------------+ + +------------------------+-----------------------------------------------------------------+-------------------------------------------------------------+ + | File | Location | Notes | + +========================+=================================================================+=============================================================+ + | LAMMPS Python Module | * ``$VIRTUAL_ENV/lib/pythonX.Y/site-packages/lammps`` (32bit) | ``X.Y`` depends on the installed Python version | + | | * ``$VIRTUAL_ENV/lib64/pythonX.Y/site-packages/lammps`` (64bit) | | + +------------------------+-----------------------------------------------------------------+-------------------------------------------------------------+ + | LAMMPS shared library | * ``$VIRTUAL_ENV/lib/pythonX.Y/site-packages/lammps`` (32bit) | ``X.Y`` depends on the installed Python version | + | | * ``$VIRTUAL_ENV/lib64/pythonX.Y/site-packages/lammps`` (64bit) | | + +------------------------+-----------------------------------------------------------------+-------------------------------------------------------------+ If you do a full installation (CMake only) with "install", this leads to the following installation locations: - +------------------------+-----------------------------------------------------------+-------------------------------------------------------------+ - | File | Location | Notes | - +========================+===========================================================+=============================================================+ - | LAMMPS Python Module | * ``$VIRTUAL_ENV/lib/pythonX.Y/site-packages/`` (32bit) | ``X.Y`` depends on the installed Python version | - | | * ``$VIRTUAL_ENV/lib64/pythonX.Y/site-packages/`` (64bit) | | - +------------------------+-----------------------------------------------------------+-------------------------------------------------------------+ - | LAMMPS shared library | * ``$VIRTUAL_ENV/lib/`` (32bit) | | - | | * ``$VIRTUAL_ENV/lib64/`` (64bit) | | - +------------------------+-----------------------------------------------------------+-------------------------------------------------------------+ - | LAMMPS executable | * ``$VIRTUAL_ENV/bin/`` | | - +------------------------+-----------------------------------------------------------+-------------------------------------------------------------+ - | LAMMPS potential files | * ``$VIRTUAL_ENV/share/lammps/potentials/`` | | - +------------------------+-----------------------------------------------------------+-------------------------------------------------------------+ + +------------------------+-----------------------------------------------------------------+-------------------------------------------------------------+ + | File | Location | Notes | + +========================+=================================================================+=============================================================+ + | LAMMPS Python Module | * ``$VIRTUAL_ENV/lib/pythonX.Y/site-packages/lammps`` (32bit) | ``X.Y`` depends on the installed Python version | + | | * ``$VIRTUAL_ENV/lib64/pythonX.Y/site-packages/lammps`` (64bit) | | + +------------------------+-----------------------------------------------------------------+-------------------------------------------------------------+ + | LAMMPS shared library | * ``$VIRTUAL_ENV/lib/`` (32bit) | Set shared loader environment variable to this path | + | | * ``$VIRTUAL_ENV/lib64/`` (64bit) | (see below for more info on this) | + +------------------------+-----------------------------------------------------------------+-------------------------------------------------------------+ + | LAMMPS executable | * ``$VIRTUAL_ENV/bin/`` | | + +------------------------+-----------------------------------------------------------------+-------------------------------------------------------------+ + | LAMMPS potential files | * ``$VIRTUAL_ENV/share/lammps/potentials/`` | Set ``LAMMPS_POTENTIALS`` environment variable to this path | + +------------------------+-----------------------------------------------------------------+-------------------------------------------------------------+ In that case you need to modify the ``$HOME/myenv/bin/activate`` script in a similar fashion you need to update your @@ -296,15 +296,15 @@ this. echo 'export LD_LIBRARY_PATH=$VIRTUAL_ENV/lib:$LD_LIBRARY_PATH' >> $HOME/myenv/bin/activate # MacOS - echo 'export DYLD_LIBRARY_PATH=$VIRTUAL_ENV/lib:$LD_LIBRARY_PATH' >> $HOME/myenv/bin/activate + echo 'export DYLD_LIBRARY_PATH=$VIRTUAL_ENV/lib:$DYLD_LIBRARY_PATH' >> $HOME/myenv/bin/activate .. tab:: In place usage You can also :doc:`compile LAMMPS ` as usual in :ref:`"shared" mode ` leave the shared library and Python - module files inside the source/compilation folders. Instead of + package inside the source/compilation folders. Instead of copying the files where they can be found, you need to set the environment - variables ``PYTHONPATH`` (for the Python module) and + variables ``PYTHONPATH`` (for the Python package) and ``LD_LIBRARY_PATH`` (or ``DYLD_LIBRARY_PATH`` on MacOS For Bourne shells (bash, ksh and similar) the commands are: @@ -325,6 +325,10 @@ this. You can make those changes permanent by editing your ``$HOME/.bashrc`` or ``$HOME/.login`` files, respectively. + .. note:: + + The ``PYTHONPATH`` needs to point to the parent folder that contains the ``lammps`` package! + To verify if LAMMPS can be successfully started from Python, start the Python interpreter, load the ``lammps`` Python module and create a @@ -346,7 +350,7 @@ output similar to the following: .. note:: Unless you opted for "In place use", you will have to rerun the installation - any time you recompile LAMMPS to ensure the latest Python module and shared + any time you recompile LAMMPS to ensure the latest Python package and shared library are installed and used. .. note:: diff --git a/doc/src/Python_module.rst b/doc/src/Python_module.rst index 04bc3f2c5b..8b4fbe1c2e 100644 --- a/doc/src/Python_module.rst +++ b/doc/src/Python_module.rst @@ -3,12 +3,12 @@ The ``lammps`` Python module .. py:module:: lammps -The LAMMPS Python interface is implemented as a module called -:py:mod:`lammps` in the ``lammps.py`` file in the ``python`` folder of -the LAMMPS source code distribution. After compilation of LAMMPS, the -module can be installed into a Python system folder or a user folder -with ``make install-python``. Components of the module can then loaded -into a Python session with the ``import`` command. +The LAMMPS Python interface is implemented as a module called :py:mod:`lammps` +which is defined in the ``lammps`` package in the ``python`` folder of the +LAMMPS source code distribution. After compilation of LAMMPS, the module can +be installed into a Python system folder or a user folder with ``make +install-python``. Components of the module can then loaded into a Python +session with the ``import`` command. There are multiple Python interface classes in the :py:mod:`lammps` module: @@ -44,7 +44,7 @@ functions. Below is a detailed documentation of the API. .. autoclass:: lammps.lammps :members: -.. autoclass:: lammps.numpy_wrapper +.. autoclass:: lammps.numpy::numpy_wrapper :members: ---------- @@ -117,8 +117,8 @@ Style Constants to request from computes or fixes. See :cpp:enum:`_LMP_STYLE_CONST` for the equivalent constants in the C library interface. Used in :py:func:`lammps.extract_compute`, :py:func:`lammps.extract_fix`, and their NumPy variants - :py:func:`lammps.numpy.extract_compute() ` and - :py:func:`lammps.numpy.extract_fix() `. + :py:func:`lammps.numpy.extract_compute() ` and + :py:func:`lammps.numpy.extract_fix() `. .. _py_type_constants: @@ -132,8 +132,8 @@ Type Constants to request from computes or fixes. See :cpp:enum:`_LMP_TYPE_CONST` for the equivalent constants in the C library interface. Used in :py:func:`lammps.extract_compute`, :py:func:`lammps.extract_fix`, and their NumPy variants - :py:func:`lammps.numpy.extract_compute() ` and - :py:func:`lammps.numpy.extract_fix() `. + :py:func:`lammps.numpy.extract_compute() ` and + :py:func:`lammps.numpy.extract_fix() `. .. _py_vartype_constants: @@ -153,6 +153,6 @@ Classes representing internal objects :members: :no-undoc-members: -.. autoclass:: lammps.NumPyNeighList +.. autoclass:: lammps.numpy::NumPyNeighList :members: :no-undoc-members: diff --git a/doc/src/Python_overview.rst b/doc/src/Python_overview.rst index a90ea171d5..2dfc193f8d 100644 --- a/doc/src/Python_overview.rst +++ b/doc/src/Python_overview.rst @@ -2,9 +2,9 @@ Overview ======== The LAMMPS distribution includes a ``python`` directory with the Python -code needed to run LAMMPS from Python. The ``python/lammps.py`` -contains :doc:`the "lammps" Python ` that wraps the -LAMMPS C-library interface. This file makes it is possible to do the +code needed to run LAMMPS from Python. The ``python/lammps`` package +contains :doc:`the "lammps" Python module ` that wraps the +LAMMPS C-library interface. This module makes it is possible to do the following either from a Python script, or interactively from a Python prompt: @@ -20,8 +20,8 @@ have a version of Python that extends Python to enable multiple instances of Python to read what you type. To do all of this, you must build LAMMPS in :ref:`"shared" mode ` -and make certain that your Python interpreter can find the ``lammps.py`` -file and the LAMMPS shared library file. +and make certain that your Python interpreter can find the ``lammps`` +Python package and the LAMMPS shared library file. .. _ctypes: https://docs.python.org/3/library/ctypes.html diff --git a/doc/src/Python_trouble.rst b/doc/src/Python_trouble.rst index 3ef7dacf34..b94a043a6a 100644 --- a/doc/src/Python_trouble.rst +++ b/doc/src/Python_trouble.rst @@ -33,7 +33,7 @@ the constructor call as follows (see :ref:`python_create_lammps` for more detail >>> lmp = lammps(name='mpi') You can also test the load directly in Python as follows, without -first importing from the lammps.py file: +first importing from the ``lammps`` module: .. code-block:: python diff --git a/doc/src/balance.rst b/doc/src/balance.rst index 7af8a86e9a..07ea82eeba 100644 --- a/doc/src/balance.rst +++ b/doc/src/balance.rst @@ -288,7 +288,7 @@ adjacent planes are closer together than the neighbor skin distance (as specified by the :doc`neigh_modify ` command), then the plane positions are shifted to separate them by at least this amount. This is to prevent particles being lost when dynamics are run -with processor subdomains that are too narrow in one or more +with processor sub-domains that are too narrow in one or more dimensions. Once the re-balancing is complete and final processor sub-domains diff --git a/doc/src/comm_modify.rst b/doc/src/comm_modify.rst index 9a2ae60f1e..864c544fed 100644 --- a/doc/src/comm_modify.rst +++ b/doc/src/comm_modify.rst @@ -84,13 +84,15 @@ information is available, then also a heuristic based on that bond length is computed. It is used as communication cutoff, if there is no pair style present and no *comm_modify cutoff* command used. Otherwise a warning is printed, if this bond based estimate is larger than the -communication cutoff used. A +communication cutoff used. The *cutoff/multi* option is equivalent to *cutoff*\ , but applies to communication mode *multi* instead. Since in this case the communication cutoffs are determined per atom type, a type specifier is needed and cutoff for one or multiple types can be extended. Also ranges of types -using the usual asterisk notation can be given. +using the usual asterisk notation can be given. For granular pair styles, +the default cutoff is set to the sum of the current maximum atomic radii +for each type. These are simulation scenarios in which it may be useful or even necessary to set a ghost cutoff > neighbor cutoff: diff --git a/doc/src/compute_mliap.rst b/doc/src/compute_mliap.rst index fcc336e682..579086ad4a 100644 --- a/doc/src/compute_mliap.rst +++ b/doc/src/compute_mliap.rst @@ -18,7 +18,7 @@ Syntax .. parsed-literal:: *model* values = style - style = *linear* or *quadratic* + style = *linear* or *quadratic* or *mliappy* *descriptor* values = style filename style = *sna* filename = name of file containing descriptor definitions @@ -56,13 +56,15 @@ and it is also straightforward to add new descriptor styles. The compute *mliap* command must be followed by two keywords *model* and *descriptor* in either order. -The *model* keyword is followed by a model style, currently limited to -either *linear* or *quadratic*. +The *model* keyword is followed by the model style (*linear*, *quadratic* or *mliappy*). +The *mliappy* model is only available +if lammps is built with MLIAPPY package. The *descriptor* keyword is followed by a descriptor style, and additional arguments. -Currently the only descriptor style is *sna*, indicating the bispectrum component -descriptors used by the Spectral Neighbor Analysis Potential (SNAP) potentials of -:doc:`pair_style snap `. +The compute currently supports just one descriptor style, but it is +is straightforward to add new descriptor styles. +The SNAP descriptor style *sna* is the same as that used by :doc:`pair_style snap `, +including the linear, quadratic, and chem variants. A single additional argument specifies the descriptor filename containing the parameters and setting used by the SNAP descriptor. The descriptor filename usually ends in the *.mliap.descriptor* extension. @@ -162,9 +164,10 @@ potentials, see the examples in `FitSNAP `_. Restrictions """""""""""" -This compute is part of the MLIAP package. It is only enabled if -LAMMPS was built with that package. In addition, building LAMMPS with the MLIAP package +This compute is part of the MLIAP package. It is only enabled if LAMMPS +was built with that package. In addition, building LAMMPS with the MLIAP package requires building LAMMPS with the SNAP package. +The *mliappy* model requires building LAMMPS with the PYTHON package. See the :doc:`Build package ` doc page for more info. Related commands diff --git a/doc/src/fix.rst b/doc/src/fix.rst index 37ddbbeb3e..2e516faa4e 100644 --- a/doc/src/fix.rst +++ b/doc/src/fix.rst @@ -364,6 +364,8 @@ accelerated styles exist. * :doc:`temp/rescale ` - temperature control by velocity rescaling * :doc:`temp/rescale/eff ` - temperature control by velocity rescaling in the electron force field model * :doc:`tfmc ` - perform force-bias Monte Carlo with time-stamped method +* :doc:`tgnvt/drude ` - NVT time integration for Drude polarizable model via temperature-grouped Nose-Hoover +* :doc:`tgnpt/drude ` - NPT time integration for Drude polarizable model via temperature-grouped Nose-Hoover * :doc:`thermal/conductivity ` - Muller-Plathe kinetic energy exchange for thermal conductivity calculation * :doc:`ti/spring ` - * :doc:`tmd ` - guide a group of atoms to a new configuration diff --git a/doc/src/fix_bond_react.rst b/doc/src/fix_bond_react.rst index 16bd4ecb71..38f061e05f 100644 --- a/doc/src/fix_bond_react.rst +++ b/doc/src/fix_bond_react.rst @@ -457,6 +457,23 @@ example, the molecule fragment could consist of only the backbone atoms of a polymer chain. This constraint can be used to enforce a specific relative position and orientation between reacting molecules. +By default, all constraints must be satisfied for the reaction to +occur. In other words, constraints are evaluated as a series of +logical values using the logical AND operator "&&". More complex logic +can be achieved by explicitly adding the logical AND operator "&&" or +the logical OR operator "||" after a given constraint command. If a +logical operator is specified after a constraint, it must be placed +after all constraint parameters, on the same line as the constraint +(one per line). Similarly, parentheses can be used to group +constraints. The expression that results from concatenating all +constraints should be a valid logical expression that can be read by +the :doc:`variable ` command after converting each +constraint to a logical value. Because exactly one constraint is +allowed per line, having a valid logical expression implies that left +parentheses "(" should only appear before a constraint, and right +parentheses ")" should only appear after a constraint and before any +logical operator. + Once a reaction site has been successfully identified, data structures within LAMMPS that store bond topology are updated to reflect the post-reacted molecule template. All force fields with fixed bonds, @@ -599,8 +616,8 @@ reset_mol_ids = yes, custom_charges = no, molecule = off .. _Gissinger: -**(Gissinger)** Gissinger, Jensen and Wise, Polymer, 128, 211 (2017). +**(Gissinger)** Gissinger, Jensen and Wise, Polymer, 128, 211-217 (2017). .. _Gissinger2020: -**(Gissinger)** Gissinger, Jensen and Wise, Macromolecules (2020, in press). +**(Gissinger)** Gissinger, Jensen and Wise, Macromolecules, 53, 22, 9953–9961 (2020). diff --git a/doc/src/fix_drude.rst b/doc/src/fix_drude.rst index b3b04832d2..385a847749 100644 --- a/doc/src/fix_drude.rst +++ b/doc/src/fix_drude.rst @@ -41,12 +41,12 @@ Restrictions """""""""""" This fix should be invoked before any other commands that implement -the Drude oscillator model, such as :doc:`fix langevin/drude `, :doc:`fix drude/transform `, :doc:`compute temp/drude `, :doc:`pair_style thole `. +the Drude oscillator model, such as :doc:`fix langevin/drude `, :doc:`fix tgnvt/drude `, :doc:`fix drude/transform `, :doc:`compute temp/drude `, :doc:`pair_style thole `. Related commands """""""""""""""" -:doc:`fix langevin/drude `, :doc:`fix drude/transform `, :doc:`compute temp/drude `, :doc:`pair_style thole ` +:doc:`fix langevin/drude `, :doc:`fix tgnvt/drude `, :doc:`fix drude/transform `, :doc:`compute temp/drude `, :doc:`pair_style thole ` Default """"""" diff --git a/doc/src/fix_temp_csvr.rst b/doc/src/fix_temp_csvr.rst index 8faa6035cf..440a264ed5 100644 --- a/doc/src/fix_temp_csvr.rst +++ b/doc/src/fix_temp_csvr.rst @@ -124,6 +124,19 @@ temperature is calculated taking the bias into account, bias is removed from each atom, thermostatting is performed on the remaining thermal degrees of freedom, and the bias is added back in. +An important feature of these thermostats is that they have an +associated effective energy that is a constant of motion. +The effective energy is the total energy (kinetic + potential) plus +the accumulated kinetic energy changes due to the thermostat. The +latter quantity is the global scalar computed by these fixes. This +feature is useful to check the integration of the equations of motion +against discretization errors. In other words, the conservation of +the effective energy can be used to choose an appropriate integration +:doc:`timestep `. This is similar to the usual paradigm of +checking the conservation of the total energy in the microcanonical +ensemble. + + ---------- Restart, fix_modify, output, run start/stop, minimize info diff --git a/doc/src/fix_tgnh_drude.rst b/doc/src/fix_tgnh_drude.rst new file mode 100644 index 0000000000..92781cd9e8 --- /dev/null +++ b/doc/src/fix_tgnh_drude.rst @@ -0,0 +1,305 @@ +.. index:: fix tgnvt/drude +.. index:: fix tgnpt/drude + +fix tgnvt/drude command +======================= + +fix tgnpt/drude command +======================= + + +Syntax +"""""" + +.. parsed-literal:: + + fix ID group-ID style_name keyword values ... + +* ID, group-ID are documented in :doc:`fix ` command +* style_name = *tgnvt/drude* or *tgnpt/drude* +* one or more keyword/values pairs may be appended + + .. parsed-literal:: + + keyword = *temp* *iso* or *aniso* or *tri* or *x* or *y* or *z* or *xy* or *yz* or *xz* or *couple* or *tchain* or *pchain* or *mtk* or *tloop* or *ploop* or *nreset* or *scalexy* or *scaleyz* or *scalexz* or *flip* or *fixedpoint* + *temp* values = Tstart Tstop Tdamp Tdrude Tdamp_drude + Tstart, Tstop = external temperature at start/end of run (temperature units) + Tdamp = temperature damping parameter (time units) + Tdrude = desired temperature of Drude oscillators (temperature units) + Tdamp_drude = temperature damping parameter for Drude oscillators (time units) + *iso* or *aniso* or *tri* values = Pstart Pstop Pdamp + Pstart,Pstop = scalar external pressure at start/end of run (pressure units) + Pdamp = pressure damping parameter (time units) + *x* or *y* or *z* or *xy* or *yz* or *xz* values = Pstart Pstop Pdamp + Pstart,Pstop = external stress tensor component at start/end of run (pressure units) + Pdamp = stress damping parameter (time units) + *couple* = *none* or *xyz* or *xy* or *yz* or *xz* + *tchain* value = N + N = length of thermostat chain (1 = single thermostat) + *pchain* value = N + N length of thermostat chain on barostat (0 = no thermostat) + *mtk* value = *yes* or *no* = add in MTK adjustment term or not + *tloop* value = M + M = number of sub-cycles to perform on thermostat + *ploop* value = M + M = number of sub-cycles to perform on barostat thermostat + *nreset* value = reset reference cell every this many timesteps + *scalexy* value = *yes* or *no* = scale xy with ly + *scaleyz* value = *yes* or *no* = scale yz with lz + *scalexz* value = *yes* or *no* = scale xz with lz + *flip* value = *yes* or *no* = allow or disallow box flips when it becomes highly skewed + *fixedpoint* values = x y z + x,y,z = perform barostat dilation/contraction around this point (distance units) + +Examples +"""""""" + +.. code-block:: LAMMPS + + comm_modify vel yes + fix 1 all tgnvt/drude temp 300.0 300.0 100.0 1.0 20.0 + fix 1 water tgnpt/drude temp 300.0 300.0 100.0 1.0 20.0 iso 0.0 0.0 1000.0 + fix 2 jello tgnpt/drude temp 300.0 300.0 100.0 1.0 20.0 tri 5.0 5.0 1000.0 + fix 2 ice tgnpt/drude temp 250.0 250.0 100.0 1.0 20.0 x 1.0 1.0 0.5 y 2.0 2.0 0.5 z 3.0 3.0 0.5 yz 0.1 0.1 0.5 xz 0.2 0.2 0.5 xy 0.3 0.3 0.5 nreset 1000 + +Description +""""""""""" + +These commands are variants of the Nose-Hoover fix styles :doc:`fix nvt +` and :doc:`fix npt ` for thermalized Drude polarizable +models. They apply temperature-grouped Nose-Hoover thermostat (TGNH) +proposed by :ref:`(Son) `. When there are fast vibrational +modes with frequencies close to Drude oscillators (e.g. double bonds or +out-of-plane torsions), this thermostat can provide better kinetic +energy equipartitioning. + +The difference between TGNH and the original Nose-Hoover thermostat is that, +TGNH separates the kinetic energy of the group into three contributions: +molecular center of mass (COM) motion, +motion of COM of atom-Drude pairs or non-polarizable atoms relative to molecular COM, +and relative motion of atom-Drude pairs. +An independent Nose-Hoover chain is applied to each type of motion. +The temperatures for these three types of motion are denoted as +molecular translational temperature (:math:`T_\mathrm{M}`), real atomic temperature (:math:`T_\mathrm{R}`) and Drude temperature (:math:`T_\mathrm{D}`), +which are defined in terms of their associated degrees of freedom (DOF): + +.. math:: + + T_\mathrm{M}=\frac{\Sigma_{i}^{N_\mathrm{mol}} M_i V_i^2}{3 \left ( N_\mathrm{mol} - \frac{N_\mathrm{mol}}{N_\mathrm{mol,sys}} \right ) k_\mathrm{B}} + +.. math:: + + T_\mathrm{R}=\frac{\Sigma_{i}^{N_\mathrm{real}} m_i (v_i-v_{M,i})^2}{(N_\mathrm{DOF} - 3 N_\mathrm{mol} + 3 \frac{N_\mathrm{mol}}{N_\mathrm{mol,sys}} - 3 N_\mathrm{drude}) k_\mathrm{B}} + +.. math:: + + T_\mathrm{D}=\frac{\Sigma_{i}^{N_\mathrm{drude}} m_i^{\prime} v_i^{\prime 2}}{3 N_\mathrm{drude} k_\mathrm{B}} + +Here :math:`N_\mathrm{mol}` and :math:`N_\mathrm{mol,sys}` are the numbers of molecules in the group and in the whole system, respectively. +:math:`N_\mathrm{real}` is the number of atom-Drude pairs and non-polarizable atoms in the group. +:math:`N_\mathrm{drude}` is the number of Drude particles in the group. +:math:`N_\mathrm{DOF}` is the DOF of the group. +:math:`M_i` and :math:`V_i` are the mass and the COM velocity of the i-th molecule. +:math:`m_i` is the mass of the i-th atom-Drude pair or non-polarizable atom. +:math:`v_i` is the velocity of COM of i-th atom-Drude pair or non-polarizable atom. +:math:`v_{M,i}` is the COM velocity of the molecule the i-th atom-Drude pair or non-polarizable atom belongs to. +:math:`m_i^\prime` and :math:`v_i^\prime` are the reduced mass and the relative velocity of the i-th atom-Drude pair. + +.. note:: + + These fixes require that each atom knows whether it is a Drude particle or + not. You must therefore use the :doc:`fix drude ` command to + specify the Drude status of each atom type. + + Because the TGNH thermostat thermostats the molecular COM motion, + all atoms belonging to the same molecule must be in the same group. + That is, these fixes can not be applied to a subset of a molecule. + + For this fix to act correctly, ghost atoms need to know their velocity. + You must use the :doc:`comm_modify ` command to enable this. + + These fixes assume that the translational DOF of the whole system is removed. + It is therefore recommended to invoke :doc:`fix momentum ` command so that the :math:`T_\mathrm{M}` is calculated correctly. + +---------- + +The thermostat parameters are specified using the *temp* keyword. +The thermostat is applied to only the translational DOF +for the particles. The translational DOF can also have +a bias velocity removed before thermostatting takes place; see the +description below. The desired temperature for molecular and real atomic motion is a +ramped value during the run from *Tstart* to *Tstop*\ . The *Tdamp* +parameter is specified in time units and determines how rapidly the +temperature is relaxed. For example, a value of 10.0 means to relax +the temperature in a timespan of (roughly) 10 time units (e.g. :math:`\tau` +or fs or ps - see the :doc:`units ` command). +The parameter *Tdrude* is the desired temperature for Drude motion at each timestep. +Similar to *Tdamp*, the *Tdamp_drude* parameter determines the relaxation speed for Drude motion. +Fix group are the only ones whose velocities and positions are updated +by the velocity/position update portion of the integration. +Other thermostat-related keywords are *tchain*\ and *tloop*\ , +which are detailed in :doc:`fix nvt `. + +.. note:: + + A Nose-Hoover thermostat will not work well for arbitrary values + of *Tdamp*\ . If *Tdamp* is too small, the temperature can fluctuate + wildly; if it is too large, the temperature will take a very long time + to equilibrate. A good choice for many models is a *Tdamp* of around + 100 timesteps. A smaller *Tdamp_drude* value would be required + to maintain Drude motion at low temperature. + +.. code-block:: LAMMPS + + fix 1 all nvt temp 300.0 300.0 $(100.0*dt) 1.0 $(20.0*dt) + +---------- + +The barostat parameters for fix style *tgnpt/drude* is specified +using one or more of the *iso*\ , *aniso*\ , *tri*\ , *x*\ , *y*\ , *z*\ , *xy*\ , +*xz*\ , *yz*\ , and *couple* keywords. These keywords give you the +ability to specify all 6 components of an external stress tensor, and +to couple various of these components together so that the dimensions +they represent are varied together during a constant-pressure +simulation. Other barostat-related keywords are *pchain*\ , *mtk*\ , *ploop*\ , +*nreset*\ , *scalexy*\ , *scaleyz*\ , *scalexz*\ , *flip*\ and *fixedpoint*. +The meaning of barostat parameters are detailed in :doc:`fix npt `. + +Regardless of what atoms are in the fix group (the only atoms which +are time integrated), a global pressure or stress tensor is computed +for all atoms. Similarly, when the size of the simulation box is +changed, all atoms are re-scaled to new positions. + +.. note:: + + Unlike the :doc:`fix temp/berendsen ` command + which performs thermostatting but NO time integration, these fixes + perform thermostatting/barostatting AND time integration. Thus you + should not use any other time integration fix, such as :doc:`fix nve ` on atoms to which this fix is applied. + Likewise, these fixes should not be used on atoms that also + have their temperature controlled by another fix - e.g. by :doc:`fix langevin/drude ` command. + +See the :doc:`Howto thermostat ` and :doc:`Howto barostat ` doc pages for a discussion of different +ways to compute temperature and perform thermostatting and +barostatting. + +---------- + +Like other fixes that perform thermostatting, these fixes can +be used with :doc:`compute commands ` that calculate a +temperature after removing a "bias" from the atom velocities. +This is not done by default, but only if the :doc:`fix_modify ` command +is used to assign a temperature compute to this fix that includes such +a bias term. See the doc pages for individual :doc:`compute commands ` to determine which ones include a bias. In +this case, the thermostat works in the following manner: the current +temperature is calculated taking the bias into account, bias is +removed from each atom, thermostatting is performed on the remaining +thermal DOF, and the bias is added back in. + +.. note:: + + However, not all temperature compute commands are valid to be used with these fixes. + Precisely, only temperature compute that does not modify the DOF of the group can be used. + E.g. :doc:`compute temp/ramp ` and :doc:`compute viscosity/cos ` + compute the kinetic energy after remove a velocity gradient without affecting the DOF of the group, + then they can be invoked in this way. + In contrast, :doc:`compute temp/partial ` may remove the DOF at one or more dimensions, + therefore it cannot be used with these fixes. + +---------- + +Restart, fix_modify, output, run start/stop, minimize info +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +These fixes writes the state of all the thermostat and barostat +variables to :doc:`binary restart files `. See the +:doc:`read_restart ` command for info on how to re-specify +a fix in an input script that reads a restart file, so that the +operation of the fix continues in an uninterrupted fashion. + +The :doc:`fix_modify ` *temp* and *press* options are +supported by these fixes. You can use them to assign a +:doc:`compute ` you have defined to this fix which will be used +in its thermostatting or barostatting procedure, as described above. +If you do this, note that the kinetic energy derived from the compute +temperature should be consistent with the virial term computed using +all atoms for the pressure. LAMMPS will warn you if you choose to +compute temperature on a subset of atoms. + +.. note:: + + If both the *temp* and *press* keywords are used in a single + thermo_modify command (or in two separate commands), then the order in + which the keywords are specified is important. Note that a :doc:`pressure compute ` defines its own temperature compute as + an argument when it is specified. The *temp* keyword will override + this (for the pressure compute being used by fix npt), but only if the + *temp* keyword comes after the *press* keyword. If the *temp* keyword + comes before the *press* keyword, then the new pressure compute + specified by the *press* keyword will be unaffected by the *temp* + setting. + +The :doc:`fix_modify ` *energy* option is supported by these +fixes to add the energy change induced by Nose/Hoover thermostatting +and barostatting to the system's potential energy as part of +:doc:`thermodynamic output `. + +These fixes compute a global scalar and a global vector of quantities, +which can be accessed by various :doc:`output commands `. +The scalar value calculated by these fixes is "extensive"; the vector +values are "intensive". +The scalar is the cumulative energy change due to the fix. +The vector stores the three temperatures :math:`T_\mathrm{M}`, :math:`T_\mathrm{R}` and :math:`T_\mathrm{D}`. + +These fixes can ramp their external temperature and pressure over +multiple runs, using the *start* and *stop* keywords of the +:doc:`run ` command. See the :doc:`run ` command for details of +how to do this. + +These fixes are not invoked during :doc:`energy minimization `. + +---------- + +Restrictions +"""""""""""" + +These fixes are only available when LAMMPS was built with the USER-DRUDE package. +These fixes cannot be used with dynamic groups as defined by the :doc:`group ` command. +These fixes cannot be used in 2D simulations. + +*X*\ , *y*\ , *z* cannot be barostatted if the associated dimension is not +periodic. *Xy*\ , *xz*\ , and *yz* can only be barostatted if the +simulation domain is triclinic and the second dimension in the keyword +(\ *y* dimension in *xy*\ ) is periodic. The :doc:`create_box `, +:doc:`read data `, and :doc:`read_restart ` +commands specify whether the simulation box is orthogonal or +non-orthogonal (triclinic) and explain the meaning of the xy,xz,yz +tilt factors. + +For the *temp* keyword, the final *Tstop* cannot be 0.0 since it would +make the external T = 0.0 at some timestep during the simulation which +is not allowed in the Nose/Hoover formulation. + +The *scaleyz yes*\ , *scalexz yes*\ , and *scalexy yes* options +can only be used if the second dimension in the keyword is periodic, +and if the tilt factor is not coupled to the barostat via keywords +*tri*\ , *yz*\ , *xz*\ , and *xy*\ . + +Related commands +"""""""""""""""" + +:doc:`fix drude `, :doc:`fix nvt `, :doc:`fix_npt `, +:doc:`fix_modify ` + +Default +""""""" + +The keyword defaults are tchain = 3, pchain = 3, mtk = yes, tloop = 1, +ploop = 1, nreset = 0, couple = none, +flip = yes, scaleyz = scalexz = scalexy = yes if periodic in second +dimension and not coupled to barostat, otherwise no. + +---------- + +.. _tgnh-Son: + +**(Son)** Son, McDaniel, Cui and Yethiraj, J Phys Chem Lett, 10, 7523 (2019). diff --git a/doc/src/lattice.rst b/doc/src/lattice.rst index e937541864..b87ddaaf70 100644 --- a/doc/src/lattice.rst +++ b/doc/src/lattice.rst @@ -254,9 +254,9 @@ in commands that use the spacings should be decipherable. Example commands for generating a Wurtzite crystal. The lattice constants approximate those of CdSe. The :math:`\sqrt{3}\times 1` orthorhombic supercell is used -with the x, y, and z directions oriented -along :math:`[\bar{1}\bar{2}30]`, -:math:`[10\bar{1}0]`, and :math:`[0001]`, respectively. +with the x, y, and z directions oriented +along :math:`[\bar{1}\bar{2}30]`, +:math:`[10\bar{1}0]`, and :math:`[0001]`, respectively. .. code-block:: LAMMPS diff --git a/doc/src/neighbor.rst b/doc/src/neighbor.rst index 1bb591587c..98ee0d0b6a 100644 --- a/doc/src/neighbor.rst +++ b/doc/src/neighbor.rst @@ -49,7 +49,9 @@ sometimes be faster. Either style should give the same answers. The *multi* style is a modified binning algorithm that is useful for systems with a wide range of cutoff distances, e.g. due to different -size particles. For the *bin* style, the bin size is set to 1/2 of +size particles. For granular pair styles, cutoffs are set to the +sum of the maximum atomic radii for each atom type. +For the *bin* style, the bin size is set to 1/2 of the largest cutoff distance between any pair of atom types and a single set of bins is defined to search over for all atom types. This can be inefficient if one pair of types has a very long cutoff, but @@ -57,8 +59,10 @@ other type pairs have a much shorter cutoff. For style *multi* the bin size is set to 1/2 of the shortest cutoff distance and multiple sets of bins are defined to search over for different atom types. This imposes some extra setup overhead, but the searches themselves -may be much faster for the short-cutoff cases. See the :doc:`comm_modify mode multi ` command for a communication option -that may also be beneficial for simulations of this kind. +may be much faster for the short-cutoff cases. +See the :doc:`comm_modify mode multi ` command for a +communication option that may also be beneficial for simulations of +this kind. The :doc:`neigh_modify ` command has additional options that control how often neighbor lists are built and which pairs are diff --git a/doc/src/package.rst b/doc/src/package.rst index 725536310a..339a1c7ca7 100644 --- a/doc/src/package.rst +++ b/doc/src/package.rst @@ -18,13 +18,16 @@ Syntax *gpu* args = Ngpu keyword value ... Ngpu = # of GPUs per node zero or more keyword/value pairs may be appended - keywords = *neigh* or *newton* or *binsize* or *split* or *gpuID* or *tpa* or *device* or *blocksize* + keywords = *neigh* or *newton* or *pair/only* or *binsize* or *split* or *gpuID* or *tpa* or *device* or *blocksize* *neigh* value = *yes* or *no* yes = neighbor list build on GPU (default) no = neighbor list build on CPU *newton* = *off* or *on* off = set Newton pairwise flag off (default and required) on = set Newton pairwise flag on (currently not allowed) + *pair/only* = *off* or *on* + off = apply "gpu" suffix to all available styles in the GPU package (default) + on - apply "gpu" suffix only pair styles *binsize* value = size size = bin size for neighbor list construction (distance units) *split* = fraction @@ -65,7 +68,7 @@ Syntax *no_affinity* values = none *kokkos* args = keyword value ... zero or more keyword/value pairs may be appended - keywords = *neigh* or *neigh/qeq* or *neigh/thread* or *newton* or *binsize* or *comm* or *comm/exchange* or *comm/forward* or *comm/reverse* or *cuda/aware* + keywords = *neigh* or *neigh/qeq* or *neigh/thread* or *newton* or *binsize* or *comm* or *comm/exchange* or *comm/forward* or *comm/reverse* or *cuda/aware* or *pair/only* *neigh* value = *full* or *half* full = full neighbor list half = half neighbor list built in thread-safe manner @@ -91,6 +94,9 @@ Syntax *cuda/aware* = *off* or *on* off = do not use CUDA-aware MPI on = use CUDA-aware MPI (default) + *pair/only* = *off* or *on* + off = use device acceleration (e.g. GPU) for all available styles in the KOKKOS package (default) + on = use device acceleration only for pair styles (and host acceleration for others) *omp* args = Nthreads keyword value ... Nthread = # of OpenMP threads to associate with each MPI process zero or more keyword/value pairs may be appended @@ -194,6 +200,14 @@ for compatibility with the package command for other accelerator styles. Note that the newton setting for bonded interactions is not affected by this keyword. +The *pair/only* keyword can change how any "gpu" suffix is applied. +By default a suffix is applied to all styles for which an accelerated +variant is available. However, that is not always the most effective +way to use an accelerator. With *pair/only* set to *on* the suffix +will only by applied to supported pair styles, which tend to be the +most effective in using an accelerator and their operation can be +overlapped with all other computations on the CPU. + The *binsize* keyword sets the size of bins used to bin atoms in neighbor list builds performed on the GPU, if *neigh* = *yes* is set. If *binsize* is set to 0.0 (the default), then bins = the size of the @@ -534,12 +548,20 @@ available (currently only possible with OpenMPI v2.0.0 or later), then the *cuda/aware* keyword is automatically set to *off* by default. When the *cuda/aware* keyword is set to *off* while any of the *comm* keywords are set to *device*\ , the value for these *comm* keywords will -be automatically changed to *host*\ . This setting has no effect if not +be automatically changed to *no*\ . This setting has no effect if not running on GPUs or if using only one MPI rank. CUDA-aware MPI is available for OpenMPI 1.8 (or later versions), Mvapich2 1.9 (or later) when the "MV2_USE_CUDA" environment variable is set to "1", CrayMPI, and IBM Spectrum MPI when the "-gpu" flag is used. +The *pair/only* keyword can change how the KOKKOS suffix "kk" is applied +when using an accelerator device. By default device acceleration is +always used for all available styles. With *pair/only* set to *on* the +suffix setting will choose device acceleration only for pair styles and +run all other force computations concurrently on the host CPU. +The *comm* flags will also automatically be changed to *no*\ . This can +result in better performance for certain configurations and system sizes. + ---------- The *omp* style invokes settings associated with the use of the diff --git a/doc/src/pair_meam_spline.rst b/doc/src/pair_meam_spline.rst index b5c94385fa..6bedb9b4fb 100644 --- a/doc/src/pair_meam_spline.rst +++ b/doc/src/pair_meam_spline.rst @@ -20,7 +20,7 @@ Examples pair_style meam/spline pair_coeff * * Ti.meam.spline Ti - pair_coeff * * Ti.meam.spline Ti Ti Ti + pair_coeff * * Ti.meam.spline Ti O Description """"""""""" @@ -84,23 +84,22 @@ where N is the number of LAMMPS atom types: See the :doc:`pair_coeff ` doc page for alternate ways to specify the path for the potential file. -As an example, imagine the Ti.meam.spline file has values for Ti (old style). If -your LAMMPS simulation has 3 atoms types and they are all to be -treated with this potentials, you would use the following pair_coeff -command: +As an example, imagine the Ti.meam.spline file has values for Ti (old style). +In that case your LAMMPS simulation may only have one atom type which has +to be mapped to the Ti element as follows: .. code-block:: LAMMPS - pair_coeff * * Ti.meam.spline Ti Ti Ti + pair_coeff * * Ti.meam.spline Ti -The first 2 arguments must be \* \* so as to span all LAMMPS atom types. -The three Ti arguments map LAMMPS atom types 1,2,3 to the Ti element -in the potential file. If a mapping value is specified as NULL, the -mapping is not performed. This can be used when a *meam/spline* -potential is used as part of the *hybrid* pair style. The NULL values -are placeholders for atom types that will be used with other -potentials. The old-style potential maps any non-NULL species named -on the command line to that single type. +The first 2 arguments must be \* \* and there may be only one element +following or NULL. Systems where there would be multiple atom types +assigned to the same element are **not** supported by this pair style +due to limitations in its implementation. If a mapping value is +specified as NULL, the mapping is not performed. This can be used when +a *meam/spline* potential is used as part of the *hybrid* pair style. +The NULL values are placeholders for atom types that will be used with +other potentials. An example with a two component spline (new style) is TiO.meam.spline, where the command @@ -143,6 +142,8 @@ Restrictions This pair style requires the :doc:`newton ` setting to be "on" for pair interactions. +This pair style does not support mapping multiple atom types to the same element. + This pair style is only enabled if LAMMPS was built with the USER-MISC package. See the :doc:`Build package ` doc page for more info. diff --git a/doc/src/pair_mliap.rst b/doc/src/pair_mliap.rst index 09295cd8be..af0cc9e855 100644 --- a/doc/src/pair_mliap.rst +++ b/doc/src/pair_mliap.rst @@ -16,7 +16,7 @@ Syntax .. parsed-literal:: *model* values = style filename - style = *linear* or *quadratic* + style = *linear* or *quadratic* or *mliappy* filename = name of file containing model definitions *descriptor* values = style filename style = *sna* @@ -40,12 +40,15 @@ definitions of the interatomic potential functional form (*model*) and the geometric quantities that characterize the atomic positions (*descriptor*). By defining *model* and *descriptor* separately, it is possible to use many different models with a given descriptor, -or many different descriptors with a given model. Currently, the pair_style -supports just two models, *linear* and *quadratic*, -and one descriptor, *sna*, the SNAP descriptor used by :doc:`pair_style snap `, including the linear, quadratic, -and chem variants. Work is currently underway to extend -the interface to handle neural network energy models, -and it is also straightforward to add new descriptor styles. +or many different descriptors with a given model. The +pair style currently supports just one descriptor style, but it is +is straightforward to add new descriptor styles. +The SNAP descriptor style *sna* is the same as that used by :doc:`pair_style snap `, +including the linear, quadratic, and chem variants. +The available models are *linear*, *quadratic*, and *mliappy*. +The *mliappy* style can be used to couple python models, +e.g. PyTorch neural network energy models, and requires building +LAMMPS with the PYTHON package (see below). In order to train a model, it is useful to know the gradient or derivative of energy, force, and stress w.r.t. model parameters. This information can be accessed using the related :doc:`compute mliap ` command. @@ -59,9 +62,8 @@ that specify the mapping of MLIAP element names to LAMMPS atom types, where N is the number of LAMMPS atom types. -The *model* keyword is followed by a model style, currently limited to -either *linear* or *quadratic*. In both cases, -this is followed by a single argument specifying the model filename containing the +The *model* keyword is followed by the model style. This is followed +by a single argument specifying the model filename containing the parameters for a set of elements. The model filename usually ends in the *.mliap.model* extension. It may contain parameters for many elements. The only requirement is that it @@ -82,6 +84,16 @@ for the :doc:`pair_style snap ` coefficient file. Specifically, the line containing the element weight and radius is omitted, since these are handled by the *descriptor*. +Notes on mliappy models: +When the *model* keyword is *mliappy*, the filename should end in '.pt', +'.pth' for pytorch models, or be a pickle file. To load a model from +memory (i.e. an existing python object), specify the filename as +"LATER", and then call `lammps.mliap.load_model(model)` from python +before using the pair style. When using lammps via the library mode, you will need to call +`lammps.mliappy.activate_mliappy(lmp)` on the active lammps object +before the pair style is defined. This call locates and loads the mliap-specific +python module that is built into lammps. + The *descriptor* keyword is followed by a descriptor style, and additional arguments. Currently the only descriptor style is *sna*, indicating the bispectrum component descriptors used by the Spectral Neighbor Analysis Potential (SNAP) potentials of @@ -138,11 +150,13 @@ This pair style can only be used via the *pair* keyword of the Restrictions """""""""""" -This style is part of the MLIAP package. It is only enabled if LAMMPS +This pair style is part of the MLIAP package. It is only enabled if LAMMPS was built with that package. In addition, building LAMMPS with the MLIAP package requires building LAMMPS with the SNAP package. +The *mliappy* model requires building LAMMPS with the PYTHON package. See the :doc:`Build package ` doc page for more info. + Related commands """""""""""""""" diff --git a/doc/src/python.rst b/doc/src/python.rst index f38e756232..a4c3d7097c 100644 --- a/doc/src/python.rst +++ b/doc/src/python.rst @@ -323,8 +323,8 @@ Python function is as follows: The function definition must include a variable (lmpptr in this case) which corresponds to SELF in the python command. The first line of the -function imports the Python module lammps.py in the python directory of -the distribution. The second line creates a Python object "lmp" which +function imports the :doc:`"lammps" Python module `. +The second line creates a Python object ``lmp`` which wraps the instance of LAMMPS that called the function. The "ptr=lmpptr" argument is what makes that happen. The third line invokes the command() function in the LAMMPS library interface. It takes a single @@ -502,18 +502,16 @@ Python library on your system. Settings to enable this are in the lib/python/Makefile.lammps file. See the lib/python/README file for information on those settings. -If you use Python code which calls back to LAMMPS, via the SELF input -argument explained above, there is an extra step required when -building LAMMPS. LAMMPS must also be built as a shared library and -your Python function must be able to load the Python module in -python/lammps.py that wraps the LAMMPS library interface. These are -the same steps required to use Python by itself to wrap LAMMPS. -Details on these steps are explained on the :doc:`Python ` -doc page. Note that it is important that the stand-alone LAMMPS -executable and the LAMMPS shared library be consistent (built from the -same source code files) in order for this to work. If the two have -been built at different times using different source files, problems -may occur. +If you use Python code which calls back to LAMMPS, via the SELF input argument +explained above, there is an extra step required when building LAMMPS. LAMMPS +must also be built as a shared library and your Python function must be able to +load the :doc:`"lammps" Python module ` that wraps the LAMMPS +library interface. These are the same steps required to use Python by itself +to wrap LAMMPS. Details on these steps are explained on the :doc:`Python +` doc page. Note that it is important that the stand-alone LAMMPS +executable and the LAMMPS shared library be consistent (built from the same +source code files) in order for this to work. If the two have been built at +different times using different source files, problems may occur. Related commands """""""""""""""" diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index 2fb7939676..7d5a9eb480 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -534,6 +534,7 @@ cuda Cuda CUDA CuH +Cui cuFFT Cummins Curk @@ -558,6 +559,7 @@ Cygwin cylindrically Cyrot cyrstals +cython Daivis Dammak dampflag @@ -870,6 +872,7 @@ equilibrating equilibration Equilibria equilization +equipartitioning Ercolessi Erdmann eradius @@ -3074,9 +3077,11 @@ tex tfac tfmc tfMC -th +tgnpt +tgnvt Thakkar Thaokar +th thb thei Theodorou @@ -3482,6 +3487,7 @@ Yc ycm Yeh yellowgreen +Yethiraj yflag yhi yi diff --git a/examples/COUPLE/python/example.py b/examples/COUPLE/python/example.py index ea268fe1ca..5ddb9fb587 100644 --- a/examples/COUPLE/python/example.py +++ b/examples/COUPLE/python/example.py @@ -1,4 +1,4 @@ -# this example requires the LAMMPS Python package (lammps.py) to be installed +# this example requires the LAMMPS Python package (python/lammps) to be installed # and LAMMPS to be loadable as shared library in LD_LIBRARY_PATH import lammps diff --git a/examples/USER/drude/README b/examples/USER/drude/README index a305999e89..1a9593ed37 100644 --- a/examples/USER/drude/README +++ b/examples/USER/drude/README @@ -1,8 +1,8 @@ Example simulations of polarizable systems using Drude oscillators ================================================================== -Each example comes in two versions for demonstrating the use of -Nosé-Hoover or Langevin thermostats. +Each example comes in several versions for demonstrating the use of +Langevin, Nosé-Hoover and temperature-grouped Nosé-Hoover thermostats. * `butane` -- simulation in NVT ensemble with Thole damping diff --git a/examples/USER/drude/butane/in.butane.tgnh b/examples/USER/drude/butane/in.butane.tgnh new file mode 100644 index 0000000000..79b9d2dfc5 --- /dev/null +++ b/examples/USER/drude/butane/in.butane.tgnh @@ -0,0 +1,57 @@ +# 250 butane system for drude polarizability example (Langevin) + +units real +boundary p p p + +atom_style full +bond_style harmonic +angle_style harmonic +dihedral_style opls +special_bonds lj/coul 0.0 0.0 0.5 + +pair_style hybrid/overlay lj/cut/coul/long 8.0 8.0 thole 2.089 8.0 +pair_modify mix geometric tail yes +kspace_style pppm 1.0e-4 + +read_data data.butane + +comm_modify vel yes + +group gBUTANE molecule 1:250 +group gCORES type 1 2 3 +group gDRUDES type 4 5 + +pair_coeff 1 1 lj/cut/coul/long 0.065997 3.500000 # C3H C3H +pair_coeff 1 2 lj/cut/coul/long 0.065997 3.500000 # C3H C2H +pair_coeff 1 3 lj/cut/coul/long 0.044496 2.958040 # C3H H +pair_coeff 2 2 lj/cut/coul/long 0.065997 3.500000 # C2H C2H +pair_coeff 2 3 lj/cut/coul/long 0.044496 2.958040 # C2H H +pair_coeff 3 3 lj/cut/coul/long 0.029999 2.500000 # H H +pair_coeff * 4*5 lj/cut/coul/long 0.000000 0.000000 # No lj for drudes +pair_coeff 1 * thole 1.368000 +pair_coeff 2 * thole 1.368000 +pair_coeff 4 * thole 1.368000 +pair_coeff 5 * thole 1.368000 + +neighbor 2.0 bin + +variable vTEMP equal 260.0 +variable vTEMP_D equal 1.0 +variable vPRESS equal 1.0 + +velocity gCORES create ${vTEMP} 12345 +velocity gDRUDES create ${vTEMP_D} 12345 + +fix fDRUDE all drude C C N D D + +fix fSHAKE gCORES shake 0.0001 20 0 b 2 4 + +fix fNVT all tgnvt/drude temp ${vTEMP} ${vTEMP} 100.0 ${vTEMP_D} 20.0 + +compute cTEMP all temp/drude + +thermo_style custom step cpu etotal ke temp pe ebond eangle edihed eimp evdwl ecoul elong press vol c_cTEMP[1] c_cTEMP[2] f_fNVT[1] f_fNVT[2] f_fNVT[3] +thermo 50 + +timestep 0.5 +run 2000 diff --git a/examples/USER/drude/butane/log.12Nov20.butane.tgnh.g++.1 b/examples/USER/drude/butane/log.12Nov20.butane.tgnh.g++.1 new file mode 100644 index 0000000000..7d64a2e939 --- /dev/null +++ b/examples/USER/drude/butane/log.12Nov20.butane.tgnh.g++.1 @@ -0,0 +1,203 @@ +LAMMPS (29 Oct 2020) +OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:94) + using 1 OpenMP thread(s) per MPI task +# 250 butane system for drude polarizability example (Langevin) + +units real +boundary p p p + +atom_style full +bond_style harmonic +angle_style harmonic +dihedral_style opls +special_bonds lj/coul 0.0 0.0 0.5 + +pair_style hybrid/overlay lj/cut/coul/long 8.0 8.0 thole 2.089 8.0 +pair_modify mix geometric tail yes +kspace_style pppm 1.0e-4 + +read_data data.butane +Reading data file ... + orthogonal box = (-19.099988 -19.099913 -19.099998) to (19.099998 19.099999 19.099987) + 1 by 1 by 1 MPI processor grid + reading atoms ... + 4500 atoms + scanning bonds ... + 5 = max bonds/atom + scanning angles ... + 6 = max angles/atom + scanning dihedrals ... + 9 = max dihedrals/atom + reading bonds ... + 4250 bonds + reading angles ... + 6000 angles + reading dihedrals ... + 6750 dihedrals +Finding 1-2 1-3 1-4 neighbors ... + special bond factors lj: 0.0 0.0 0.5 + special bond factors coul: 0.0 0.0 0.5 + 5 = max # of 1-2 neighbors + 8 = max # of 1-3 neighbors + 12 = max # of 1-4 neighbors + 17 = max # of special neighbors + special bonds CPU = 0.005 seconds + read_data CPU = 0.107 seconds + +comm_modify vel yes + +group gBUTANE molecule 1:250 +4500 atoms in group gBUTANE +group gCORES type 1 2 3 +3500 atoms in group gCORES +group gDRUDES type 4 5 +1000 atoms in group gDRUDES + +pair_coeff 1 1 lj/cut/coul/long 0.065997 3.500000 # C3H C3H +pair_coeff 1 2 lj/cut/coul/long 0.065997 3.500000 # C3H C2H +pair_coeff 1 3 lj/cut/coul/long 0.044496 2.958040 # C3H H +pair_coeff 2 2 lj/cut/coul/long 0.065997 3.500000 # C2H C2H +pair_coeff 2 3 lj/cut/coul/long 0.044496 2.958040 # C2H H +pair_coeff 3 3 lj/cut/coul/long 0.029999 2.500000 # H H +pair_coeff * 4*5 lj/cut/coul/long 0.000000 0.000000 # No lj for drudes +pair_coeff 1 * thole 1.368000 +pair_coeff 2 * thole 1.368000 +pair_coeff 4 * thole 1.368000 +pair_coeff 5 * thole 1.368000 + +neighbor 2.0 bin + +variable vTEMP equal 260.0 +variable vTEMP_D equal 1.0 +variable vPRESS equal 1.0 + +velocity gCORES create ${vTEMP} 12345 +velocity gCORES create 260 12345 +velocity gDRUDES create ${vTEMP_D} 12345 +velocity gDRUDES create 1 12345 + +fix fDRUDE all drude C C N D D + +fix fSHAKE gCORES shake 0.0001 20 0 b 2 4 + 0 = # of size 2 clusters + 500 = # of size 3 clusters + 500 = # of size 4 clusters + 0 = # of frozen angles + find clusters CPU = 0.002 seconds + +fix fNVT all tgnvt/drude temp ${vTEMP} ${vTEMP} 100.0 ${vTEMP_D} 20.0 +fix fNVT all tgnvt/drude temp 260 ${vTEMP} 100.0 ${vTEMP_D} 20.0 +fix fNVT all tgnvt/drude temp 260 260 100.0 ${vTEMP_D} 20.0 +fix fNVT all tgnvt/drude temp 260 260 100.0 1 20.0 + +compute cTEMP all temp/drude + +thermo_style custom step cpu etotal ke temp pe ebond eangle edihed eimp evdwl ecoul elong press vol c_cTEMP[1] c_cTEMP[2] f_fNVT[1] f_fNVT[2] f_fNVT[3] +thermo 50 + +timestep 0.5 +run 2000 +PPPM initialization ... + using 12-bit tables for long-range coulomb (src/kspace.cpp:328) + G vector (1/distance) = 0.36786669 + grid = 36 36 36 + stencil order = 5 + estimated absolute RMS force accuracy = 0.031353958 + estimated relative force accuracy = 9.4421513e-05 + using double precision FFTW3 + 3d grid and FFT values/proc = 79507 46656 +Rebuild special list taking Drude particles into account +Old max number of 1-2 to 1-4 neighbors: 17 +New max number of 1-2 to 1-4 neighbors: 17 (+0) +Neighbor list info ... + update every 1 steps, delay 10 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 10 + ghost atom cutoff = 10 + binsize = 5, bins = 8 8 8 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair lj/cut/coul/long, perpetual + attributes: half, newton on + pair build: half/bin/newton + stencil: half/bin/3d/newton + bin: standard + (2) pair thole, perpetual, skip from (1) + attributes: half, newton on + pair build: skip + stencil: none + bin: none +TGNHC thermostat for Drude model + DOFs of molecules, atoms and dipoles: 747.0 7250.0 3000.0 +Per MPI rank memory allocation (min/avg/max) = 26.74 | 26.74 | 26.74 Mbytes +Step CPU TotEng KinEng Temp PotEng E_bond E_angle E_dihed E_impro E_vdwl E_coul E_long Press Volume c_cTEMP[1] c_cTEMP[2] f_fNVT[1] f_fNVT[2] f_fNVT[3] + 0 0 6535.5187 2714.74 248.45112 3820.7787 3724.3278 140.75328 1.4735401 0 -518.77975 595169.42 -594696.41 4439.7916 55742.797 334.61375 18.435655 235.53872 344.96036 18.435655 + 50 3.1687763 2088.2827 1463.7181 133.95847 624.56452 190.24602 660.52157 113.41252 0 -767.94561 595300.94 -594872.61 2824.2625 55742.797 183.94884 0.5168738 309.18564 171.12124 0.5168738 + 100 6.392197 2119.741 1619.097 148.17863 500.64399 180.00042 696.41212 164.28885 0 -972.75524 595305.17 -594872.47 1212.6136 55742.797 203.63725 0.14080733 399.49069 183.54186 0.14080733 + 150 9.5800587 2141.3837 1671.6283 152.98627 469.75531 135.1638 703.8743 168.6738 0 -966.11416 595300.45 -594872.29 4391.1694 55742.797 210.25781 0.10918071 418.15558 188.92417 0.10918071 + 200 12.853705 2171.9506 1663.8326 152.27281 508.11794 189.68939 718.42616 166.2915 0 -990.53041 595295.36 -594871.12 2071.4055 55742.797 209.24314 0.19965091 435.49843 186.01763 0.19965091 + 250 16.067977 2208.7064 1678.7069 153.6341 529.99951 152.56393 831.36872 167.05009 0 -1047.6813 595297.24 -594870.54 1092.2375 55742.797 210.84693 0.91289443 438.53468 187.47449 0.91289443 + 300 19.290601 2251.9246 1764.9742 161.52921 486.95043 145.17235 805.81497 155.39025 0 -1045.9572 595297.21 -594870.68 2438.7801 55742.797 220.85043 3.177778 427.70756 199.6284 3.177778 + 350 22.523101 2270.9632 1684.9306 154.20368 586.03264 186.29543 828.98436 164.45539 0 -1016.9035 595293.56 -594870.36 2804.0926 55742.797 211.53678 1.1611927 408.91355 191.2877 1.1611927 + 400 25.747934 2299.236 1742.1505 159.44041 557.0855 171.75438 844.97783 181.89643 0 -1068.3059 595296.85 -594870.09 346.86959 55742.797 219.02792 0.38093991 392.66374 201.22808 0.38093991 + 450 28.921993 2335.9622 1666.2461 152.49369 669.71602 137.8956 986.46039 179.59582 0 -1060.189 595295.82 -594869.86 -125.83593 55742.797 209.50259 0.31748182 376.15783 192.41804 0.31748182 + 500 32.312988 2377.923 1744.8977 159.69183 633.02533 192.86619 865.11335 173.23166 0 -1020.1061 595291.45 -594869.53 3306.7537 55742.797 219.29509 0.59010722 361.05703 204.77946 0.59010722 + 550 36.691992 2428.1816 1631.766 149.33809 796.41562 183.75276 1043.9175 175.64604 0 -1030.3844 595293.08 -594869.6 1566.0362 55742.797 204.67411 1.6260367 344.40559 190.36165 1.6260367 + 600 41.042781 2475.0304 1615.769 147.87406 859.26146 195.35951 1102.8743 185.82441 0 -1049.7179 595293.93 -594869 751.07631 55742.797 202.5711 1.8674049 324.5681 190.08503 1.8674049 + 650 45.328915 2516.5445 1706.6033 156.18716 809.94113 177.34479 1029.3219 186.91492 0 -1005.4619 595290.9 -594869.08 2456.1336 55742.797 214.42466 0.73094758 306.66872 205.00907 0.73094758 + 700 49.764606 2566.0671 1658.8261 151.81461 907.24102 186.97528 1088.6916 184.51371 0 -976.01174 595292.41 -594869.33 403.91053 55742.797 208.52534 0.43420426 292.04619 200.0061 0.43420426 + 750 54.232008 2621.7889 1798.1047 164.5613 823.68424 181.39689 1029.9425 187.40871 0 -1005.4402 595300.06 -594869.68 93.345406 55742.797 226.01979 0.50741755 278.62961 220.69269 0.50741755 + 800 58.691111 2682.2116 1697.0698 155.31465 985.14182 215.09199 1113.1134 201.785 0 -975.13212 595300.04 -594869.76 -978.97822 55742.797 213.08116 1.115316 269.45572 207.36081 1.115316 + 850 63.191067 2745.8302 1887.0667 172.70304 858.76349 213.25376 980.55106 184.54859 0 -948.21117 595298.22 -594869.6 -1842.9661 55742.797 236.69142 1.8946563 265.28903 233.84282 1.8946563 + 900 68.297608 2799.3194 1855.1338 169.78056 944.1856 201.04167 1103.4608 183.6645 0 -978.27382 595303.89 -594869.59 -1771.6573 55742.797 232.95614 1.1425454 262.10904 230.04879 1.1425454 + 950 72.791466 2852.8885 1809.5899 165.61241 1043.2986 249.1926 1129.6516 191.5705 0 -961.04118 595303.8 -594869.88 -2342.8998 55742.797 227.44427 0.56184866 253.71617 224.83147 0.56184866 + 1000 77.035667 2910.6565 1900.2429 173.90892 1010.4136 196.79043 1117.444 178.94619 0 -911.75161 595298.72 -594869.74 -30.451099 55742.797 238.87602 0.48940683 245.53211 238.28906 0.48940683 + 1050 81.411119 2970.473 1950.8452 178.54 1019.6278 226.17987 1113.3407 186.50456 0 -935.79287 595298.24 -594868.85 -835.03656 55742.797 245.11923 0.81684119 243.27893 245.41028 0.81684119 + 1100 85.352255 3032.1777 1913.2921 175.10317 1118.8856 252.39337 1183.7624 209.49478 0 -958.58165 595300.89 -594869.07 -2339.7573 55742.797 240.10633 1.5863163 244.29251 239.77436 1.5863163 + 1150 88.542324 3088.7233 2015.1572 184.4258 1073.5661 215.84757 1132.2268 209.14846 0 -912.58909 595297.76 -594868.83 53.404069 55742.797 252.92982 1.5639609 247.6541 253.57807 1.5639609 + 1200 92.122601 3137.9447 1895.1546 173.44324 1242.7901 238.97673 1266.308 207.46165 0 -898.18367 595297.09 -594868.86 -940.55827 55742.797 238.13441 0.75999751 245.44164 237.48006 0.75999751 + 1250 95.311451 3187.5696 2117.7204 193.81231 1069.8492 181.35781 1173.5116 216.10446 0 -933.15422 595300.81 -594868.78 -1638.23 55742.797 266.21428 0.54658889 243.60628 268.65384 0.54658889 + 1300 98.511654 3238.1405 2050.9414 187.70074 1187.1991 249.20898 1196.3016 223.50078 0 -909.6591 595296.3 -594868.46 -1547.4617 55742.797 257.76705 0.6695258 252.14097 258.4534 0.6695258 + 1350 101.52721 3288.0387 2035.6917 186.3051 1252.347 218.31874 1254.421 222.85512 0 -868.43705 595293.49 -594868.3 390.90212 55742.797 255.64252 1.2189872 257.21253 255.58654 1.2189872 + 1400 104.52829 3334.0324 2200.7086 201.40733 1133.3238 203.591 1213.1272 225.86605 0 -936.79465 595295.53 -594868 1372.2474 55742.797 276.25415 1.6144005 265.70225 277.45567 1.6144005 + 1450 107.57536 3365.7397 2053.535 187.9381 1312.2047 229.27407 1349.3993 233.25524 0 -924.22271 595292.17 -594867.67 -836.52213 55742.797 257.94919 1.053914 270.4816 256.76466 1.053914 + 1500 110.67807 3391.6801 2142.1349 196.04671 1249.5452 216.36803 1271.289 236.65847 0 -894.899 595287.51 -594867.38 1789.6923 55742.797 269.25236 0.63559736 274.68538 268.80398 0.63559736 + 1550 113.65872 3411.9839 2115.0942 193.57196 1296.8897 192.92659 1363.4027 230.98652 0 -914.70137 595291.47 -594867.19 2191.6084 55742.797 265.85125 0.63359087 272.59399 265.26653 0.63359087 + 1600 116.66477 3424.9783 2002.6546 183.28156 1422.3237 261.62038 1419.7862 242.17905 0 -928.05995 595294.38 -594867.58 -1278.1217 55742.797 251.58666 0.95135757 265.94171 250.2117 0.95135757 + 1650 119.69122 3429.9661 2102.8573 192.45205 1327.1088 253.88883 1296.8164 239.01537 0 -888.25345 595293.11 -594867.47 948.16575 55742.797 263.99864 1.4686915 261.93718 264.32028 1.4686915 + 1700 122.69838 3421.465 2141.4791 195.98669 1279.9859 181.31236 1326.081 226.54243 0 -878.86521 595292.19 -594867.28 241.93125 55742.797 268.9293 1.2770595 262.79349 269.67278 1.2770595 + 1750 125.70436 3402.5396 2090.1999 191.29365 1312.3397 263.74025 1296.4274 228.60032 0 -905.54661 595296.37 -594867.25 -1707.3557 55742.797 262.65583 0.80319616 257.84463 263.26023 0.80319616 + 1800 128.64288 3381.1607 2133.1735 195.22657 1247.9872 234.93738 1242.035 231.34689 0 -887.78079 595295.05 -594867.6 -6.7713651 55742.797 268.11425 0.66416955 258.06107 269.26102 0.66416955 + 1850 131.64553 3358.3375 2097.2908 191.9426 1261.0467 207.32514 1269.9582 225.83462 0 -867.84477 595293.05 -594867.28 1032.3077 55742.797 263.55741 0.77783532 261.21918 263.90739 0.77783532 + 1900 134.66459 3335.0634 2130.3209 194.96549 1204.7425 244.28549 1208.9691 209.87044 0 -885.54671 595293.8 -594866.63 -302.54262 55742.797 267.53309 1.2569444 256.95232 268.73397 1.2569444 + 1950 137.77487 3309.5009 2065.148 189.00092 1244.3529 244.25407 1240.7976 222.92873 0 -891.58467 595294.86 -594866.9 -2000.0789 55742.797 259.29344 1.3652015 254.19331 259.92622 1.3652015 + 2000 140.88126 3284.0767 2005.7474 183.56462 1278.3292 226.17277 1236.5565 225.16671 0 -837.57878 595295.52 -594867.51 942.09961 55742.797 251.97128 0.96329477 250.4516 252.23212 0.96329477 +Loop time of 140.882 on 1 procs for 2000 steps with 4500 atoms + +Performance: 0.613 ns/day, 39.134 hours/ns, 14.196 timesteps/s +100.0% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 90.189 | 90.189 | 90.189 | 0.0 | 64.02 +Bond | 5.0432 | 5.0432 | 5.0432 | 0.0 | 3.58 +Kspace | 39.478 | 39.478 | 39.478 | 0.0 | 28.02 +Neigh | 2.4322 | 2.4322 | 2.4322 | 0.0 | 1.73 +Comm | 0.62876 | 0.62876 | 0.62876 | 0.0 | 0.45 +Output | 0.021652 | 0.021652 | 0.021652 | 0.0 | 0.02 +Modify | 2.9918 | 2.9918 | 2.9918 | 0.0 | 2.12 +Other | | 0.09631 | | | 0.07 + +Nlocal: 4500.00 ave 4500 max 4500 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 9440.00 ave 9440 max 9440 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 811251.0 ave 811251 max 811251 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 811251 +Ave neighs/atom = 180.27800 +Ave special neighs/atom = 13.333333 +Neighbor list builds = 31 +Dangerous builds = 0 +Total wall time: 0:02:21 diff --git a/examples/USER/drude/butane/log.12Nov20.butane.tgnh.g++.4 b/examples/USER/drude/butane/log.12Nov20.butane.tgnh.g++.4 new file mode 100644 index 0000000000..5cadbab3d2 --- /dev/null +++ b/examples/USER/drude/butane/log.12Nov20.butane.tgnh.g++.4 @@ -0,0 +1,203 @@ +LAMMPS (29 Oct 2020) +OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:94) + using 1 OpenMP thread(s) per MPI task +# 250 butane system for drude polarizability example (Langevin) + +units real +boundary p p p + +atom_style full +bond_style harmonic +angle_style harmonic +dihedral_style opls +special_bonds lj/coul 0.0 0.0 0.5 + +pair_style hybrid/overlay lj/cut/coul/long 8.0 8.0 thole 2.089 8.0 +pair_modify mix geometric tail yes +kspace_style pppm 1.0e-4 + +read_data data.butane +Reading data file ... + orthogonal box = (-19.099988 -19.099913 -19.099998) to (19.099998 19.099999 19.099987) + 2 by 1 by 2 MPI processor grid + reading atoms ... + 4500 atoms + scanning bonds ... + 5 = max bonds/atom + scanning angles ... + 6 = max angles/atom + scanning dihedrals ... + 9 = max dihedrals/atom + reading bonds ... + 4250 bonds + reading angles ... + 6000 angles + reading dihedrals ... + 6750 dihedrals +Finding 1-2 1-3 1-4 neighbors ... + special bond factors lj: 0.0 0.0 0.5 + special bond factors coul: 0.0 0.0 0.5 + 5 = max # of 1-2 neighbors + 8 = max # of 1-3 neighbors + 12 = max # of 1-4 neighbors + 17 = max # of special neighbors + special bonds CPU = 0.002 seconds + read_data CPU = 0.135 seconds + +comm_modify vel yes + +group gBUTANE molecule 1:250 +4500 atoms in group gBUTANE +group gCORES type 1 2 3 +3500 atoms in group gCORES +group gDRUDES type 4 5 +1000 atoms in group gDRUDES + +pair_coeff 1 1 lj/cut/coul/long 0.065997 3.500000 # C3H C3H +pair_coeff 1 2 lj/cut/coul/long 0.065997 3.500000 # C3H C2H +pair_coeff 1 3 lj/cut/coul/long 0.044496 2.958040 # C3H H +pair_coeff 2 2 lj/cut/coul/long 0.065997 3.500000 # C2H C2H +pair_coeff 2 3 lj/cut/coul/long 0.044496 2.958040 # C2H H +pair_coeff 3 3 lj/cut/coul/long 0.029999 2.500000 # H H +pair_coeff * 4*5 lj/cut/coul/long 0.000000 0.000000 # No lj for drudes +pair_coeff 1 * thole 1.368000 +pair_coeff 2 * thole 1.368000 +pair_coeff 4 * thole 1.368000 +pair_coeff 5 * thole 1.368000 + +neighbor 2.0 bin + +variable vTEMP equal 260.0 +variable vTEMP_D equal 1.0 +variable vPRESS equal 1.0 + +velocity gCORES create ${vTEMP} 12345 +velocity gCORES create 260 12345 +velocity gDRUDES create ${vTEMP_D} 12345 +velocity gDRUDES create 1 12345 + +fix fDRUDE all drude C C N D D + +fix fSHAKE gCORES shake 0.0001 20 0 b 2 4 + 0 = # of size 2 clusters + 500 = # of size 3 clusters + 500 = # of size 4 clusters + 0 = # of frozen angles + find clusters CPU = 0.003 seconds + +fix fNVT all tgnvt/drude temp ${vTEMP} ${vTEMP} 100.0 ${vTEMP_D} 20.0 +fix fNVT all tgnvt/drude temp 260 ${vTEMP} 100.0 ${vTEMP_D} 20.0 +fix fNVT all tgnvt/drude temp 260 260 100.0 ${vTEMP_D} 20.0 +fix fNVT all tgnvt/drude temp 260 260 100.0 1 20.0 + +compute cTEMP all temp/drude + +thermo_style custom step cpu etotal ke temp pe ebond eangle edihed eimp evdwl ecoul elong press vol c_cTEMP[1] c_cTEMP[2] f_fNVT[1] f_fNVT[2] f_fNVT[3] +thermo 50 + +timestep 0.5 +run 2000 +PPPM initialization ... + using 12-bit tables for long-range coulomb (src/kspace.cpp:328) + G vector (1/distance) = 0.36786669 + grid = 36 36 36 + stencil order = 5 + estimated absolute RMS force accuracy = 0.031353958 + estimated relative force accuracy = 9.4421513e-05 + using double precision FFTW3 + 3d grid and FFT values/proc = 26875 11664 +Rebuild special list taking Drude particles into account +Old max number of 1-2 to 1-4 neighbors: 17 +New max number of 1-2 to 1-4 neighbors: 17 (+0) +Neighbor list info ... + update every 1 steps, delay 10 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 10 + ghost atom cutoff = 10 + binsize = 5, bins = 8 8 8 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair lj/cut/coul/long, perpetual + attributes: half, newton on + pair build: half/bin/newton + stencil: half/bin/3d/newton + bin: standard + (2) pair thole, perpetual, skip from (1) + attributes: half, newton on + pair build: skip + stencil: none + bin: none +TGNHC thermostat for Drude model + DOFs of molecules, atoms and dipoles: 747.0 7250.0 3000.0 +Per MPI rank memory allocation (min/avg/max) = 17.33 | 17.61 | 17.71 Mbytes +Step CPU TotEng KinEng Temp PotEng E_bond E_angle E_dihed E_impro E_vdwl E_coul E_long Press Volume c_cTEMP[1] c_cTEMP[2] f_fNVT[1] f_fNVT[2] f_fNVT[3] + 0 0 6535.5187 2714.74 248.45112 3820.7787 3724.3278 140.75328 1.4735401 0 -518.77975 595169.42 -594696.41 4439.7916 55742.797 334.61375 18.435655 235.53872 344.96036 18.435655 + 50 1.2808116 2088.3442 1463.7416 133.96062 624.60259 190.28732 660.54143 113.40785 0 -767.95454 595300.93 -594872.61 2824.0523 55742.797 183.9497 0.52468068 309.23594 171.11764 0.52468068 + 100 2.5584104 2119.7471 1619.1466 148.18318 500.60051 180.0129 696.37693 164.27736 0 -972.76956 595305.17 -594872.47 1212.1148 55742.797 203.64285 0.14251823 399.52878 183.54411 0.14251823 + 150 3.8010236 2141.3696 1671.6877 152.99171 469.68182 135.1764 703.84494 168.6598 0 -966.14516 595300.44 -594872.29 4390.752 55742.797 210.26485 0.11034179 418.18146 188.92927 0.11034179 + 200 5.1283429 2171.9547 1663.9057 152.2795 508.04901 189.69207 718.41361 166.26728 0 -990.56316 595295.36 -594871.12 2071.2788 55742.797 209.25133 0.20233224 435.53114 186.0233 0.20233224 + 250 6.4042978 2208.7763 1678.8339 153.64571 529.94239 152.60724 831.35366 166.99449 0 -1047.7147 595297.24 -594870.54 1092.02 55742.797 210.85827 0.9252592 438.54342 187.4861 0.9252592 + 300 7.6759895 2251.8197 1764.844 161.5173 486.97577 145.12518 805.82891 155.36767 0 -1045.8941 595297.22 -594870.68 2440.3181 55742.797 220.83898 3.1684561 427.70245 199.61611 3.1684561 + 350 8.9352416 2270.8953 1684.8322 154.19468 586.06305 186.26267 828.9806 164.47014 0 -1016.8664 595293.58 -594870.36 2805.0915 55742.797 211.52748 1.151954 408.90784 191.27829 1.151954 + 400 10.226474 2299.1993 1742.2608 159.4505 556.93851 171.73982 844.94626 181.87018 0 -1068.3641 595296.84 -594870.09 346.42411 55742.797 219.04152 0.38166821 392.61871 201.24772 0.38166821 + 450 11.460384 2335.947 1666.1971 152.4892 669.74994 137.90858 986.43107 179.60302 0 -1060.1348 595295.81 -594869.87 -124.88535 55742.797 209.49545 0.32005879 376.11474 192.41461 0.32005879 + 500 12.727526 2377.9345 1744.9374 159.69546 632.99715 192.8966 865.02273 173.24203 0 -1020.0569 595291.42 -594869.52 3307.6909 55742.797 219.29743 0.59718599 361.06132 204.78161 0.59718599 + 550 14.002285 2428.2193 1631.8271 149.34369 796.3922 183.78402 1043.8511 175.66575 0 -1030.3885 595293.08 -594869.6 1565.6449 55742.797 204.6776 1.6372397 344.46071 190.35982 1.6372397 + 600 15.309195 2474.8599 1615.6237 147.86076 859.23616 195.26628 1102.8384 185.89393 0 -1049.6659 595293.91 -594869.01 751.15809 55742.797 202.55856 1.8521167 324.58977 190.06895 1.8521167 + 650 16.528946 2516.5107 1706.7483 156.20043 809.76241 177.33665 1029.1545 186.8922 0 -1005.4741 595290.93 -594869.08 2457.4736 55742.797 214.44458 0.72647262 306.69821 205.02801 0.72647262 + 700 17.788857 2566.0306 1658.7538 151.808 907.27687 187.0133 1088.6084 184.61388 0 -976.00491 595292.38 -594869.33 403.14977 55742.797 208.51586 0.43547213 292.00328 200.00013 0.43547213 + 750 19.056136 2621.8108 1798.0665 164.5578 823.74429 181.38067 1030.1211 187.24746 0 -1005.3911 595300.06 -594869.68 92.552993 55742.797 226.01327 0.51200863 278.52415 220.69636 0.51200863 + 800 20.328816 2682.2638 1697.1503 155.32202 985.11349 215.11037 1113.1057 201.61206 0 -974.97574 595300.02 -594869.76 -976.02218 55742.797 213.08709 1.1265124 269.37146 207.37604 1.1265124 + 850 21.675028 2745.7956 1887.1133 172.70731 858.68222 213.20281 980.38605 184.58101 0 -948.10772 595298.22 -594869.6 -1838.829 55742.797 236.69968 1.8882632 265.22854 233.85817 1.8882632 + 900 22.973234 2799.2121 1855.3963 169.80459 943.81573 200.99559 1103.2167 183.64073 0 -978.26954 595303.83 -594869.59 -1773.6417 55742.797 232.99302 1.1323134 262.06588 230.09392 1.1323134 + 950 24.248459 2852.9103 1809.6345 165.6165 1043.2758 249.23659 1129.5155 191.54177 0 -960.95833 595303.82 -594869.88 -2343.6579 55742.797 227.45041 0.56047502 253.63589 224.84652 0.56047502 + 1000 25.536354 2910.7011 1900.5669 173.93856 1010.1343 196.76213 1117.2835 179.06956 0 -911.9529 595298.71 -594869.74 -33.375682 55742.797 238.91568 0.49230975 245.54917 238.33106 0.49230975 + 1050 27.032801 2970.593 1950.7545 178.53171 1019.8385 226.09391 1113.2803 186.61907 0 -935.59614 595298.29 -594868.85 -832.86686 55742.797 245.10467 0.82528071 243.25364 245.39681 0.82528071 + 1100 28.276849 3032.248 1914.0097 175.16884 1118.2383 252.4222 1183.4081 209.13741 0 -958.53105 595300.88 -594869.07 -2341.1239 55742.797 240.19374 1.5939531 244.2841 239.87168 1.5939531 + 1150 29.492505 3088.6987 2014.6006 184.37485 1074.0982 215.76487 1132.4575 209.01044 0 -912.08646 595297.78 -594868.83 59.335425 55742.797 252.86479 1.5506297 247.67435 253.50422 1.5506297 + 1200 30.792128 3137.976 1895.5574 173.4801 1242.4187 239.01663 1266.2435 206.94828 0 -898.01399 595297.09 -594868.87 -935.85119 55742.797 238.18675 0.75585601 245.80184 237.50082 0.75585601 + 1250 32.351654 3187.6007 2118.7576 193.90723 1068.8431 181.27841 1173.4284 215.72666 0 -933.61935 595300.82 -594868.79 -1641.4966 55742.797 266.34429 0.54783845 244.09536 268.74691 0.54783845 + 1300 34.279555 3238.1339 2050.9128 187.69812 1187.2212 249.09831 1195.8579 223.95802 0 -909.52255 595296.29 -594868.46 -1548.7665 55742.797 257.76137 0.67507496 252.48992 258.41118 0.67507496 + 1350 36.142639 3287.8996 2035.6486 186.30115 1252.251 218.35091 1254.3488 223.36318 0 -868.93347 595293.43 -594868.31 385.64561 55742.797 255.63367 1.2281317 257.51447 255.54567 1.2281317 + 1400 37.680265 3333.7702 2200.7264 201.40895 1133.0439 203.40304 1213.391 225.99045 0 -937.20521 595295.47 -594868.01 1368.2351 55742.797 276.25818 1.6096154 265.82263 277.44771 1.6096154 + 1450 38.930719 3365.4323 2053.468 187.93197 1311.9643 229.10608 1350.1009 232.99574 0 -924.67313 595292.11 -594867.67 -844.05749 55742.797 257.94445 1.0440927 270.14303 256.79431 1.0440927 + 1500 40.161434 3391.3707 2141.7727 196.01356 1249.598 216.2106 1271.1542 236.52415 0 -894.39832 595287.52 -594867.41 1800.4964 55742.797 269.20769 0.63415006 273.93125 268.83182 0.63415006 + 1550 41.331434 3411.6894 2114.0335 193.47488 1297.6559 192.9656 1363.167 231.27359 0 -913.98645 595291.45 -594867.21 2209.1641 55742.797 265.71649 0.63741948 271.92193 265.18682 0.63741948 + 1600 42.514856 3424.7938 2003.2634 183.33728 1421.5305 261.67378 1419.189 241.66354 0 -927.77417 595294.37 -594867.6 -1282.8296 55742.797 251.6594 0.96160577 265.79668 250.30691 0.96160577 + 1650 43.712954 3429.9764 2104.4785 192.60041 1325.4979 253.75783 1296.7732 237.25083 0 -887.95744 595293.15 -594867.48 966.66903 55742.797 264.20211 1.4699573 262.83185 264.45262 1.4699573 + 1700 44.988869 3421.4427 2141.3199 195.97211 1280.1228 180.56711 1326.1422 227.27194 0 -878.75929 595292.2 -594867.3 269.33339 55742.797 268.91342 1.2659937 264.28353 269.50173 1.2659937 + 1750 46.32512 3402.6047 2089.4689 191.22675 1313.1357 263.71155 1295.9383 229.85515 0 -905.40883 595296.3 -594867.26 -1711.6299 55742.797 262.56648 0.79625261 258.49733 263.09439 0.79625261 + 1800 47.626741 3381.3633 2132.4465 195.16003 1248.9167 234.45582 1241.8128 232.64927 0 -887.43322 595295.06 -594867.63 6.1750563 55742.797 268.02308 0.66339407 257.61935 269.20593 0.66339407 + 1850 48.859097 3358.9769 2090.1997 191.29363 1268.7772 207.84877 1271.8504 229.08032 0 -865.66614 595292.95 -594867.29 1046.4693 55742.797 262.66189 0.78698303 260.47063 262.99635 0.78698303 + 1900 50.086851 3336.417 2129.6659 194.90555 1206.7511 244.28118 1211.1819 208.93923 0 -884.87319 595293.88 -594866.65 -289.20276 55742.797 267.44697 1.2668343 256.868 268.64764 1.2668343 + 1950 51.245913 3311.0369 2068.2384 189.28375 1242.7985 243.85893 1242.1317 220.07989 0 -891.04779 595294.68 -594866.91 -1991.6618 55742.797 259.6859 1.3553911 254.54251 260.3233 1.3553911 + 2000 52.444694 3285.8337 2003.2382 183.33497 1282.5955 227.01654 1237.0479 227.77755 0 -837.34967 595295.6 -594867.49 937.91227 55742.797 251.65869 0.95505158 250.48617 251.88363 0.95505158 +Loop time of 52.4449 on 4 procs for 2000 steps with 4500 atoms + +Performance: 1.647 ns/day, 14.568 hours/ns, 38.135 timesteps/s +98.1% CPU use with 4 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 26.398 | 27.961 | 29.034 | 18.3 | 53.31 +Bond | 1.3959 | 1.5762 | 1.7169 | 9.5 | 3.01 +Kspace | 17.592 | 18.436 | 19.757 | 18.9 | 35.15 +Neigh | 0.8492 | 0.85015 | 0.85101 | 0.1 | 1.62 +Comm | 1.311 | 1.6626 | 2.0789 | 22.0 | 3.17 +Output | 0.010571 | 0.011494 | 0.013821 | 1.3 | 0.02 +Modify | 1.8078 | 1.8237 | 1.8372 | 0.8 | 3.48 +Other | | 0.1236 | | | 0.24 + +Nlocal: 1125.00 ave 1220 max 1043 min +Histogram: 1 0 1 0 0 0 1 0 0 1 +Nghost: 5813.50 ave 5907 max 5699 min +Histogram: 1 0 0 1 0 0 0 0 1 1 +Neighs: 202807.0 ave 217353 max 190808 min +Histogram: 1 1 0 0 0 0 1 0 0 1 + +Total # of neighbors = 811227 +Ave neighs/atom = 180.27267 +Ave special neighs/atom = 13.333333 +Neighbor list builds = 31 +Dangerous builds = 0 +Total wall time: 0:00:52 diff --git a/examples/USER/drude/ethanol/in.ethanol.tgnh b/examples/USER/drude/ethanol/in.ethanol.tgnh new file mode 100644 index 0000000000..8d476da68a --- /dev/null +++ b/examples/USER/drude/ethanol/in.ethanol.tgnh @@ -0,0 +1,79 @@ +units real +boundary p p p + +atom_style full +bond_style harmonic +angle_style harmonic +dihedral_style opls +special_bonds lj/coul 0.0 0.0 0.5 + +pair_style hybrid/overlay lj/cut/coul/long 8.0 8.0 thole 2.600 8.0 +kspace_style pppm 1.0e-4 + +comm_modify vel yes +read_data data.ethanol + +pair_coeff 1 1 lj/cut/coul/long 0.065997 3.500000 # C3H C3H +pair_coeff 1 2 lj/cut/coul/long 0.065997 3.500000 # C3H CTO +pair_coeff 1 3 lj/cut/coul/long 0.044496 2.958040 # C3H H +pair_coeff 1 4 lj/cut/coul/long 0.105921 3.304542 # C3H OH +pair_coeff 1 5 lj/cut/coul/long 0.000000 0.000000 # C3H HO +pair_coeff 2 2 lj/cut/coul/long 0.065997 3.500000 # CTO CTO +pair_coeff 2 3 lj/cut/coul/long 0.044496 2.958040 # CTO H +pair_coeff 2 4 lj/cut/coul/long 0.105921 3.304542 # CTO OH +pair_coeff 2 5 lj/cut/coul/long 0.000000 0.000000 # CTO HO +pair_coeff 3 3 lj/cut/coul/long 0.029999 2.500000 # H H +pair_coeff 3 4 lj/cut/coul/long 0.071413 2.792848 # H OH +pair_coeff 3 5 lj/cut/coul/long 0.000000 0.000000 # H HO +pair_coeff 4 4 lj/cut/coul/long 0.169996 3.120000 # OH OH +pair_coeff 4 5 lj/cut/coul/long 0.000000 0.000000 # OH HO +pair_coeff 5 5 lj/cut/coul/long 0.000000 0.000000 # HO HO +pair_coeff * 6*8 lj/cut/coul/long 0.000000 0.000000 # No lj for drudes +pair_coeff 1 1 thole 2.051000 +pair_coeff 1 2 thole 1.580265 +pair_coeff 1 4 thole 1.416087 +pair_coeff 1 6 thole 2.051000 +pair_coeff 1 7 thole 1.580265 +pair_coeff 1 8 thole 1.416087 +pair_coeff 2 2 thole 1.217570 +pair_coeff 2 4 thole 1.091074 +pair_coeff 2 6 thole 1.580265 +pair_coeff 2 7 thole 1.217570 +pair_coeff 2 8 thole 1.091074 +pair_coeff 4 4 thole 0.977720 +pair_coeff 4 6 thole 1.416087 +pair_coeff 4 7 thole 1.091074 +pair_coeff 4 8 thole 0.977720 +pair_coeff 6 6 thole 2.051000 +pair_coeff 6 7 thole 1.580265 +pair_coeff 6 8 thole 1.416087 +pair_coeff 7 7 thole 1.217570 +pair_coeff 7 8 thole 1.091074 +pair_coeff 8 8 thole 0.977720 + +group gETHANOL molecule 1:250 +group gATOMS type 1 2 3 4 5 +group gDRUDES type 6 7 8 + +neighbor 2.0 bin + +variable vTEMP equal 300.0 +variable vTEMP_D equal 1.0 +variable vPRESS equal 1.0 + +velocity gATOMS create ${vTEMP} 12345 +velocity gDRUDES create ${vTEMP_D} 12345 + +fix fDRUDE all drude C C N C N D D D + +fix fSHAKE gATOMS shake 0.0001 20 0 b 2 3 5 + +fix fNPT all tgnpt/drude temp ${vTEMP} ${vTEMP} 100.0 ${vTEMP_D} 20.0 iso ${vPRESS} ${vPRESS} 1000 + +compute cTEMP all temp/drude + +thermo_style custom step cpu etotal ke temp pe ebond eangle edihed eimp evdwl ecoul elong press vol c_cTEMP[1] c_cTEMP[2] f_fNPT[1] f_fNPT[2] f_fNPT[3] +thermo 20 + +timestep 0.5 +run 2000 diff --git a/examples/USER/drude/ethanol/log.12Nov20.ethanol.tgnh.g++.1 b/examples/USER/drude/ethanol/log.12Nov20.ethanol.tgnh.g++.1 new file mode 100644 index 0000000000..d6c39edb32 --- /dev/null +++ b/examples/USER/drude/ethanol/log.12Nov20.ethanol.tgnh.g++.1 @@ -0,0 +1,287 @@ +LAMMPS (29 Oct 2020) +OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:94) + using 1 OpenMP thread(s) per MPI task +units real +boundary p p p + +atom_style full +bond_style harmonic +angle_style harmonic +dihedral_style opls +special_bonds lj/coul 0.0 0.0 0.5 + +pair_style hybrid/overlay lj/cut/coul/long 8.0 8.0 thole 2.600 8.0 +kspace_style pppm 1.0e-4 + +comm_modify vel yes +read_data data.ethanol +Reading data file ... + orthogonal box = (-14.013845 -14.027809 -14.018882) to (14.016930 14.017730 14.085730) + 1 by 1 by 1 MPI processor grid + reading atoms ... + 3000 atoms + scanning bonds ... + 5 = max bonds/atom + scanning angles ... + 6 = max angles/atom + scanning dihedrals ... + 9 = max dihedrals/atom + reading bonds ... + 2750 bonds + reading angles ... + 3250 angles + reading dihedrals ... + 3000 dihedrals +Finding 1-2 1-3 1-4 neighbors ... + special bond factors lj: 0.0 0.0 0.5 + special bond factors coul: 0.0 0.0 0.5 + 5 = max # of 1-2 neighbors + 6 = max # of 1-3 neighbors + 10 = max # of 1-4 neighbors + 11 = max # of special neighbors + special bonds CPU = 0.003 seconds + read_data CPU = 0.062 seconds + +pair_coeff 1 1 lj/cut/coul/long 0.065997 3.500000 # C3H C3H +pair_coeff 1 2 lj/cut/coul/long 0.065997 3.500000 # C3H CTO +pair_coeff 1 3 lj/cut/coul/long 0.044496 2.958040 # C3H H +pair_coeff 1 4 lj/cut/coul/long 0.105921 3.304542 # C3H OH +pair_coeff 1 5 lj/cut/coul/long 0.000000 0.000000 # C3H HO +pair_coeff 2 2 lj/cut/coul/long 0.065997 3.500000 # CTO CTO +pair_coeff 2 3 lj/cut/coul/long 0.044496 2.958040 # CTO H +pair_coeff 2 4 lj/cut/coul/long 0.105921 3.304542 # CTO OH +pair_coeff 2 5 lj/cut/coul/long 0.000000 0.000000 # CTO HO +pair_coeff 3 3 lj/cut/coul/long 0.029999 2.500000 # H H +pair_coeff 3 4 lj/cut/coul/long 0.071413 2.792848 # H OH +pair_coeff 3 5 lj/cut/coul/long 0.000000 0.000000 # H HO +pair_coeff 4 4 lj/cut/coul/long 0.169996 3.120000 # OH OH +pair_coeff 4 5 lj/cut/coul/long 0.000000 0.000000 # OH HO +pair_coeff 5 5 lj/cut/coul/long 0.000000 0.000000 # HO HO +pair_coeff * 6*8 lj/cut/coul/long 0.000000 0.000000 # No lj for drudes +pair_coeff 1 1 thole 2.051000 +pair_coeff 1 2 thole 1.580265 +pair_coeff 1 4 thole 1.416087 +pair_coeff 1 6 thole 2.051000 +pair_coeff 1 7 thole 1.580265 +pair_coeff 1 8 thole 1.416087 +pair_coeff 2 2 thole 1.217570 +pair_coeff 2 4 thole 1.091074 +pair_coeff 2 6 thole 1.580265 +pair_coeff 2 7 thole 1.217570 +pair_coeff 2 8 thole 1.091074 +pair_coeff 4 4 thole 0.977720 +pair_coeff 4 6 thole 1.416087 +pair_coeff 4 7 thole 1.091074 +pair_coeff 4 8 thole 0.977720 +pair_coeff 6 6 thole 2.051000 +pair_coeff 6 7 thole 1.580265 +pair_coeff 6 8 thole 1.416087 +pair_coeff 7 7 thole 1.217570 +pair_coeff 7 8 thole 1.091074 +pair_coeff 8 8 thole 0.977720 + +group gETHANOL molecule 1:250 +3000 atoms in group gETHANOL +group gATOMS type 1 2 3 4 5 +2250 atoms in group gATOMS +group gDRUDES type 6 7 8 +750 atoms in group gDRUDES + +neighbor 2.0 bin + +variable vTEMP equal 300.0 +variable vTEMP_D equal 1.0 +variable vPRESS equal 1.0 + +velocity gATOMS create ${vTEMP} 12345 +velocity gATOMS create 300 12345 +velocity gDRUDES create ${vTEMP_D} 12345 +velocity gDRUDES create 1 12345 + +fix fDRUDE all drude C C N C N D D D + +fix fSHAKE gATOMS shake 0.0001 20 0 b 2 3 5 + 250 = # of size 2 clusters + 250 = # of size 3 clusters + 250 = # of size 4 clusters + 0 = # of frozen angles + find clusters CPU = 0.001 seconds + +fix fNPT all tgnpt/drude temp ${vTEMP} ${vTEMP} 100.0 ${vTEMP_D} 20.0 iso ${vPRESS} ${vPRESS} 1000 +fix fNPT all tgnpt/drude temp 300 ${vTEMP} 100.0 ${vTEMP_D} 20.0 iso ${vPRESS} ${vPRESS} 1000 +fix fNPT all tgnpt/drude temp 300 300 100.0 ${vTEMP_D} 20.0 iso ${vPRESS} ${vPRESS} 1000 +fix fNPT all tgnpt/drude temp 300 300 100.0 1 20.0 iso ${vPRESS} ${vPRESS} 1000 +fix fNPT all tgnpt/drude temp 300 300 100.0 1 20.0 iso 1 ${vPRESS} 1000 +fix fNPT all tgnpt/drude temp 300 300 100.0 1 20.0 iso 1 1 1000 + +compute cTEMP all temp/drude + +thermo_style custom step cpu etotal ke temp pe ebond eangle edihed eimp evdwl ecoul elong press vol c_cTEMP[1] c_cTEMP[2] f_fNPT[1] f_fNPT[2] f_fNPT[3] +thermo 20 + +timestep 0.5 +run 2000 +PPPM initialization ... + using 12-bit tables for long-range coulomb (src/kspace.cpp:328) + G vector (1/distance) = 0.37973843 + grid = 30 30 30 + stencil order = 5 + estimated absolute RMS force accuracy = 0.028997858 + estimated relative force accuracy = 8.7326188e-05 + using double precision FFTW3 + 3d grid and FFT values/proc = 50653 27000 +Rebuild special list taking Drude particles into account +Old max number of 1-2 to 1-4 neighbors: 11 +New max number of 1-2 to 1-4 neighbors: 11 (+0) +Neighbor list info ... + update every 1 steps, delay 10 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 10 + ghost atom cutoff = 10 + binsize = 5, bins = 6 6 6 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair lj/cut/coul/long, perpetual + attributes: half, newton on + pair build: half/bin/newton + stencil: half/bin/3d/newton + bin: standard + (2) pair thole, perpetual, skip from (1) + attributes: half, newton on + pair build: skip + stencil: none + bin: none +TGNHC thermostat for Drude model + DOFs of molecules, atoms and dipoles: 747.0 4500.0 2250.0 +Per MPI rank memory allocation (min/avg/max) = 22.99 | 22.99 | 22.99 Mbytes +Step CPU TotEng KinEng Temp PotEng E_bond E_angle E_dihed E_impro E_vdwl E_coul E_long Press Volume c_cTEMP[1] c_cTEMP[2] f_fNPT[1] f_fNPT[2] f_fNPT[3] + 0 0 13868.828 2013.3852 270.28772 11855.443 3145.896 51.880809 0.00019113234 0 8481.5109 514734.14 -514557.98 170210.19 22094.109 381.62759 10.134301 291.07893 396.91308 10.134301 + 20 1.299002 9802.0013 5175.0939 694.7326 4626.9074 1138.6388 2334.7257 132.32135 0 1890.1205 514082.52 -514951.42 83148.665 22175.038 987.97886 9.5650257 2458.1912 744.58226 9.5650257 + 40 2.6585262 9235.2784 5579.5869 749.03392 3655.6915 905.50827 1897.9797 277.48003 0 1696.6242 513843.84 -514965.74 60300.581 22359.787 1068.9505 1.5632512 2851.9591 773.68368 1.5632512 + 60 4.0767848 8671.8892 5504.7567 738.98831 3167.1326 829.06537 2052.5827 330.50295 0 997.94126 513948.25 -514991.2 48878.532 22600.438 1054.9063 0.8609188 3046.3154 725.0357 0.8609188 + 80 5.4198065 8041.4551 5718.4601 767.67701 2322.9951 733.58679 1714.9273 332.16847 0 607.45721 513906.05 -514971.19 46156.9 22855.703 1095.9536 0.67476425 2911.1504 795.36156 0.67476425 + 100 6.8445274 7424.1846 5485.2445 736.36888 1938.9402 725.61122 1556.2473 334.28427 0 311.33112 513993.29 -514981.82 35649.376 23094.997 1051.3109 0.5222695 2722.3778 774.61471 0.5222695 + 120 8.1987147 6864.2981 5106.0869 685.46872 1758.2112 639.80517 1608.9702 330.7119 0 225.63755 513930.12 -514977.04 28592.139 23302.575 978.67156 0.41481306 2531.1524 721.61219 0.41481306 + 140 9.6125531 6355.2419 4782.2344 641.99302 1573.0074 692.8178 1572.2236 329.75157 0 62.526757 513879.29 -514963.61 24166.914 23482.684 916.61358 0.35571984 2382.5955 673.87165 0.35571984 + 160 10.981043 5871.6552 4610.4861 618.9366 1261.169 680.52384 1414.3474 329.28182 0 -159.78058 513987.52 -514990.72 27542.211 23647.419 883.68752 0.35918951 2123.8994 678.40147 0.35918951 + 180 12.332621 5435.5691 4279.3184 574.47885 1156.2507 684.91656 1423.9511 309.44801 0 -233.41405 513945.61 -514974.26 18688.318 23808.753 820.22155 0.31322062 1867.6728 646.89147 0.31322062 + 200 13.684023 5063.6933 3974.692 533.58416 1089.0012 610.82746 1398.9423 299.55778 0 -238.71277 514006.42 -514988.03 14346.596 23962.516 761.81108 0.34323344 1649.6269 614.94153 0.34323344 + 220 15.025737 4729.6345 3862.1044 518.46979 867.53006 589.15408 1361.5835 291.68077 0 -382.15023 514000.76 -514993.5 14084.228 24106.002 740.21384 0.37572015 1480.8499 617.76172 0.37572015 + 240 16.361954 4425.17 3701.2817 496.88008 723.88831 584.37459 1295.507 282.13297 0 -468.19466 514014.29 -514984.22 13175.309 24240.893 709.36164 0.42725973 1335.0379 605.97228 0.42725973 + 260 17.686205 4147.8236 3444.1814 462.36555 703.6422 561.69812 1304.6664 277.46507 0 -505.18688 514062.51 -514997.51 9960.5444 24367.441 660.03654 0.51674844 1202.6787 570.39815 0.51663293 + 280 19.001433 3906.0499 3263.3789 438.09363 642.67099 612.03629 1258.9736 278.79088 0 -503.36734 513978.2 -514981.97 5911.2321 24482.777 625.29586 0.70431199 1076.194 550.86363 0.70431199 + 300 20.239475 3688.6521 3138.7761 421.36628 549.87595 589.66541 1229.0183 274.52568 0 -529.41366 513980.02 -514993.93 8818.9035 24585 601.19081 1.2138917 967.42544 540.79666 1.2138917 + 320 21.55208 3484.9768 3041.6682 408.32999 443.30859 581.36133 1221.761 276.40415 0 -581.91733 513938.29 -514992.59 9181.7725 24679.377 582.27807 1.9067083 865.20562 535.70028 1.9067083 + 340 22.866527 3301.111 2892.7326 388.33607 408.3784 575.39496 1150.6761 289.75308 0 -522.13929 513897.14 -514982.44 7705.6777 24768.367 553.48144 2.4790842 782.86323 515.77305 2.4790842 + 360 24.169391 3134.601 2727.1786 366.11121 407.42236 560.04836 1167.7896 290.8151 0 -534.37256 513917.26 -514994.12 5173.1603 24851.201 521.90957 2.0935593 720.9275 489.22054 2.0935593 + 380 25.499891 2978.9742 2626.4574 352.58985 352.51679 565.92745 1159.8532 276.01665 0 -574.15206 513906.53 -514981.66 5406.7601 24926.52 502.85217 1.5076664 663.92569 476.44959 1.5078823 + 400 26.749513 2830.4515 2571.0905 345.15709 259.36106 608.49648 1122.7921 254.35509 0 -631.46578 513898.27 -514993.09 6598.5441 24996.189 492.43661 1.0446762 619.49263 471.67242 1.0443567 + 420 28.295841 2690.9016 2510.0923 336.96837 180.80925 579.44132 1054.4508 246.41333 0 -619.58628 513907.01 -514986.92 3344.148 25062.431 480.89086 0.69994647 565.8201 467.11319 0.69994647 + 440 29.740652 2568.0899 2415.0979 324.2158 152.99201 549.56174 1062.4133 248.3112 0 -625.52103 513895.56 -514977.34 1508.2507 25122.432 462.77313 0.4830629 522.5615 453.15678 0.4830629 + 460 31.033999 2452.8301 2374.2562 318.73299 78.573926 560.62424 1025.2699 241.11159 0 -664.87807 513904.81 -514988.36 2645.1623 25175.119 454.98091 0.39620035 489.058 449.62743 0.39620035 + 480 32.287371 2343.6513 2309.9229 310.09654 33.728418 543.67605 1036.735 236.6691 0 -646.19525 513846.07 -514983.23 4840.3297 25223.454 442.64176 0.41089885 466.91678 438.90721 0.41089885 + 500 33.575452 2237.0869 2186.7578 293.56219 50.329153 569.29753 1077.789 237.78011 0 -644.2024 513802.59 -514992.93 3147.641 25270.717 419.03821 0.39338041 448.26725 414.46511 0.39352695 + 520 34.882586 2139.9267 2184.6613 293.28075 -44.734618 598.44589 949.76187 230.75426 0 -639.80829 513811.79 -514995.68 89.417432 25315.104 418.62009 0.43123772 424.93066 417.85161 0.43123772 + 540 36.099168 2047.6906 2096.7059 281.47314 -49.015331 603.23512 994.03336 236.23878 0 -642.85411 513760.61 -515000.28 2488.0247 25353.845 401.6824 0.6095642 402.80198 401.76434 0.6095642 + 560 37.392444 1959.8223 2108.0902 283.00143 -148.26783 556.77844 933.83445 228.23222 0 -640.71325 513772.73 -514999.13 3943.0471 25390.643 403.78476 0.79631768 387.29154 406.79182 0.79631768 + 580 38.599277 1877.9441 2032.3004 272.827 -154.35632 567.35925 915.88654 217.432 0 -638.21268 513777.18 -514994 990.21765 25427.432 389.08915 1.184871 380.81536 390.72199 1.184871 + 600 39.880662 1802.0089 2025.4302 271.90471 -223.42134 546.62696 900.79592 214.83879 0 -668.01506 513782.41 -515000.08 13.167029 25461.023 387.51997 1.7732181 375.29493 389.80736 1.773544 + 620 41.151704 1729.2181 1934.4658 259.69315 -205.24769 550.82063 913.19495 217.45935 0 -675.32746 513791.35 -515002.74 241.52954 25490.189 369.99117 1.9848435 365.94576 370.90937 1.9848435 + 640 42.367107 1658.2621 1869.4172 250.96067 -211.15505 560.62227 911.72129 213.95368 0 -665.21833 513766.85 -514999.08 3632.223 25516.498 357.58414 1.8379694 353.567 358.48938 1.8379694 + 660 43.641386 1588.4137 1852.2333 248.65382 -263.8196 577.15612 856.06817 203.8208 0 -643.32076 513743.58 -515001.12 1748.9053 25544.141 354.40947 1.5590879 342.18406 356.67449 1.5598187 + 680 44.916294 1522.8833 1803.3756 242.0949 -280.4923 569.2594 868.20962 207.92742 0 -667.28233 513741.85 -515000.45 -707.71197 25570.844 345.28497 0.99527257 329.41069 348.14899 0.99572941 + 700 46.126721 1461.9096 1769.8128 237.58924 -307.90315 542.7914 861.81473 203.22264 0 -674.68634 513754.76 -514995.8 1167.0096 25593.851 338.95839 0.74443058 320.56652 342.23742 0.74427874 + 720 47.342692 1403.7901 1774.9009 238.2723 -371.11079 533.63282 871.2916 186.94204 0 -661.24368 513696.56 -514998.29 1734.2343 25615.595 339.99734 0.59618884 315.31635 344.32074 0.59612251 + 740 48.606886 1347.7019 1788.1767 240.05451 -440.47482 551.44173 832.07818 173.00046 0 -679.31011 513685.34 -515003.03 1108.3607 25637.321 342.57548 0.51883795 311.99896 347.87957 0.51883795 + 760 49.886167 1294.2014 1732.3399 232.55868 -438.13849 563.187 825.18662 175.50788 0 -672.34818 513677.51 -515007.18 -2118.7763 25657.738 331.88911 0.47758368 305.31362 336.52173 0.47757969 + 780 51.181176 1243.7936 1720.77 231.00547 -476.9764 565.28094 800.5385 187.89263 0 -663.7818 513643.08 -515009.99 142.9942 25673.523 329.66915 0.48221433 293.10673 335.95739 0.48257178 + 800 52.501053 1195.7584 1713.4482 230.02255 -517.6898 575.29743 793.40588 182.96177 0 -652.3437 513594.18 -515011.19 2569.2035 25687.829 328.22734 0.57136512 282.06342 336.10937 0.57136512 + 820 53.730285 1149.3704 1688.6401 226.69218 -539.26966 566.02535 783.51259 170.42752 0 -645.21365 513596.56 -515010.58 158.43243 25703.753 323.41372 0.70633792 274.90722 331.6814 0.70633792 + 840 55.059346 1107.3402 1626.7277 218.38072 -519.38749 557.00463 817.13283 161.18356 0 -661.6802 513616.64 -515009.67 -859.99932 25718.477 311.42538 0.98533165 274.36623 317.78482 0.98533165 + 860 56.26804 1067.0989 1619.5401 217.41582 -552.44114 567.51474 819.44456 157.01002 0 -653.65749 513563.92 -515006.67 -110.22037 25730.521 309.90587 1.3158099 279.28284 315.1959 1.3158099 + 880 57.552129 1028.7737 1622.6482 217.83307 -593.87455 579.7559 769.38822 163.25737 0 -641.48094 513545.77 -515010.56 2044.3918 25741.489 310.33341 1.7085038 277.85767 315.93127 1.7085038 + 900 58.752011 990.85148 1635.8709 219.60816 -645.01941 590.07687 741.99946 160.20976 0 -648.65733 513521.95 -515010.6 -616.21441 25753.742 312.82551 1.8081896 279.97773 318.48679 1.8081896 + 920 60.02342 953.65737 1657.228 222.47525 -703.57061 574.2732 734.42873 151.5283 0 -657.51865 513506.29 -515012.57 -2391.2196 25763.907 316.97803 1.6721323 286.84832 322.1911 1.6717714 + 940 61.246864 917.3708 1532.2653 205.69958 -614.89448 576.8991 775.3663 162.78532 0 -639.35069 513524.45 -515015.04 564.89367 25770.107 293.21271 1.2280076 293.75433 293.31884 1.2282942 + 960 62.520232 883.18364 1537.9463 206.46223 -654.76268 563.51425 761.32405 161.47799 0 -631.38061 513503.44 -515013.14 1374.3226 25776.278 294.40866 0.9786147 300.31219 293.62423 0.97818807 + 980 63.72859 851.43088 1538.0246 206.47273 -686.59368 565.62724 756.61795 152.08723 0 -645.22417 513500.66 -515016.36 -203.76984 25783.711 294.53876 0.71003563 300.78246 293.69924 0.71029723 + 1000 65.325249 822.29342 1546.1186 207.55932 -723.82514 573.24707 705.27714 145.40402 0 -627.3824 513491.87 -515012.24 -1482.5195 25790.098 296.12917 0.61958842 301.40343 295.45106 0.61958842 + 1020 67.066265 795.41337 1551.6368 208.30012 -756.22343 597.40466 700.03219 143.14559 0 -631.02663 513445.32 -515011.1 748.62224 25794.159 297.21498 0.5543604 297.93873 297.29299 0.5543604 + 1040 68.784411 769.92029 1548.9081 207.9338 -778.9878 581.53993 723.87795 137.61133 0 -624.63041 513420.31 -515017.7 1356.2174 25798.811 296.7141 0.50251818 294.64447 297.25547 0.50251818 + 1060 70.531164 745.98628 1514.0024 203.24787 -768.0161 590.02417 718.13714 148.25485 0 -620.67061 513412.77 -515016.53 -984.90789 25804.672 289.98962 0.57944566 296.06714 289.17408 0.57944566 + 1080 72.339286 724.41988 1468.7378 197.17131 -744.31795 587.12574 750.82761 166.43289 0 -611.54088 513376.94 -515014.1 -1369.9774 25808.741 281.26901 0.68044534 297.86474 278.70146 0.68043227 + 1100 74.081078 705.1492 1475.7507 198.11275 -770.60147 596.03939 703.74275 166.87407 0 -604.94878 513382.71 -515015.02 322.11458 25810.632 282.54351 0.84350846 304.3263 279.11613 0.84359917 + 1120 75.92559 688.04772 1517.3948 203.70329 -829.34708 589.83314 688.24666 158.8665 0 -610.41803 513358.01 -515013.88 1171.4548 25812.799 290.41298 1.1090646 307.74167 287.73002 1.1090646 + 1140 77.724149 672.36504 1512.4831 203.04391 -840.11804 611.8019 686.11567 154.1589 0 -600.4798 513325.18 -515016.9 -1129.2791 25816.098 289.32063 1.4608372 307.70226 286.46216 1.4608372 + 1160 79.533442 657.64948 1524.9394 204.71611 -867.2899 614.09367 686.86805 145.77079 0 -587.50349 513287.47 -515013.99 -1405.9783 25817.666 291.61223 1.6855491 302.37391 290.02089 1.6855106 + 1180 81.243201 643.07936 1483.2148 199.11478 -840.13545 607.70554 729.46823 145.73396 0 -581.12793 513268.2 -515010.11 951.82863 25817.313 283.62844 1.6507547 296.31179 281.7127 1.6507678 + 1200 83.124235 628.84892 1508.103 202.45591 -879.25413 610.27958 699.47204 146.65751 0 -581.22705 513258.98 -515013.42 845.8635 25818.085 288.47775 1.4683346 288.26595 288.70552 1.4687429 + 1220 84.861868 615.48595 1506.3938 202.22645 -890.90781 640.61601 705.74981 149.24915 0 -568.44006 513197.45 -515015.53 -989.87699 25819.897 288.2897 1.1425522 284.47457 289.11499 1.1433225 + 1240 86.657973 603.46611 1521.8 204.29466 -918.3339 627.93094 681.9999 147.50604 0 -563.03024 513206.69 -515019.43 -1294.0886 25820.275 291.33208 0.93495852 284.52005 292.65658 0.93566845 + 1260 88.527368 592.83025 1550.0222 208.08336 -957.19193 638.74876 684.27892 144.10419 0 -567.28292 513161.98 -515019.02 366.82518 25818.88 296.84123 0.70423253 289.40784 298.27306 0.70423253 + 1280 90.26083 583.62238 1500.3203 201.41111 -916.69791 658.39007 717.40575 149.49357 0 -560.74831 513138.12 -515019.36 468.99306 25817.909 287.36089 0.59306602 294.54267 286.36029 0.59306602 + 1300 92.13165 575.42151 1519.3082 203.96014 -943.88664 655.72041 704.25181 141.32573 0 -550.47558 513125.5 -515020.21 -1022.3924 25817.559 291.00356 0.58689962 300.73954 289.58167 0.58691655 + 1320 93.894194 568.3477 1518.4074 203.83922 -950.05966 670.96379 726.82052 139.93925 0 -527.97883 513058.34 -515018.15 -972.06273 25815.822 290.83615 0.57457637 307.54777 288.256 0.57459152 + 1340 95.719114 562.07892 1523.1375 204.47422 -961.05857 677.25051 688.02873 138.64793 0 -528.35304 513081.3 -515017.94 1058.9949 25813.039 291.70253 0.66885112 312.02785 288.52311 0.66873042 + 1360 97.524416 556.93389 1560.3959 209.47598 -1003.462 665.73523 686.80959 139.77318 0 -523.04289 513045.29 -515018.03 937.16072 25811.796 298.7948 0.7861094 312.82634 296.66456 0.78666076 + 1380 99.357452 553.33396 1516.3062 203.55714 -962.97224 678.04454 713.74957 137.42774 0 -517.91272 513044.03 -515018.31 -292.99291 25811.915 290.25807 0.98357958 308.02329 287.50255 0.98357958 + 1400 101.09848 550.59887 1532.5676 205.74016 -981.9687 668.87709 700.85053 135.12927 0 -539.20798 513074.89 -515022.51 -1158.8487 25811.561 293.25245 1.2705054 302.5546 291.90379 1.2705054 + 1420 102.92972 548.73321 1476.7658 198.24903 -928.03261 677.96546 739.35433 145.56163 0 -552.34431 513084.77 -515023.34 9.5625031 25809.75 282.48418 1.436009 300.29464 279.71597 1.436009 + 1440 104.66752 547.12666 1527.8761 205.11036 -980.74947 650.61377 711.8671 147.59824 0 -556.66671 513090.53 -515024.69 1019.1836 25808.157 292.23402 1.5483375 300.12772 291.11848 1.5483375 + 1460 106.50314 545.65053 1490.3999 200.07935 -944.74941 670.75445 719.7737 150.18449 0 -549.39105 513087.25 -515023.32 -1319.4425 25807.672 285.07809 1.4821899 301.34029 282.56847 1.4823299 + 1480 108.28741 544.77516 1526.097 204.87152 -981.32183 652.3433 696.79415 149.20209 0 -556.6563 513098.18 -515021.18 -742.16174 25805.656 292.01497 1.2636175 302.51451 290.4664 1.2639932 + 1500 110.12511 545.19541 1545.583 207.48742 -1000.3876 645.73389 715.44716 136.9985 0 -567.26011 513090.87 -515022.18 -400.28471 25802.486 295.86865 0.987897 302.34922 294.99013 0.987897 + 1520 111.89057 546.1418 1523.2045 204.48322 -977.06274 643.78664 737.65713 128.87884 0 -556.6123 513087.83 -515018.61 382.6378 25799.004 291.65193 0.81691637 299.79434 290.49472 0.81691637 + 1540 113.68915 548.12322 1532.5317 205.73534 -984.40845 662.00085 713.14115 141.83628 0 -546.54637 513065.85 -515020.69 -558.02865 25796.128 293.49257 0.69415483 292.07299 293.92389 0.69415483 + 1560 115.74426 551.58749 1524.0291 204.59391 -972.44159 662.89347 709.62799 163.91089 0 -538.91833 513050.59 -515020.55 -1648.6737 25792.534 291.9015 0.60340834 283.91962 293.42109 0.60340834 + 1580 118.02455 556.31359 1557.1932 209.04604 -1000.8797 650.22504 703.18471 164.34921 0 -547.76291 513048.79 -515019.67 218.40066 25787.071 298.26162 0.59762744 279.75915 301.53187 0.59762744 + 1600 119.98362 561.8489 1536.2864 206.2394 -974.4375 650.4012 725.52549 152.37926 0 -524.6233 513039.24 -515017.36 724.91327 25782.038 294.23674 0.63726972 276.89513 297.31161 0.63726972 + 1620 121.24569 568.29298 1516.8518 203.6304 -948.55886 669.43634 758.17152 141.59579 0 -508.64869 513005.84 -515014.95 305.45057 25778.393 290.46698 0.74019001 276.01771 293.0592 0.74019001 + 1640 122.52086 575.42679 1531.3719 205.57965 -955.94515 683.26836 731.47049 143.09022 0 -504.62735 513005.89 -515015.04 -1258.1839 25775.243 293.18351 0.89655264 276.95868 296.07228 0.89655264 + 1660 123.85319 583.33428 1520.971 204.18338 -937.63676 670.138 752.36615 158.20486 0 -497.10065 512993.63 -515014.87 990.4476 25771.018 291.11283 1.0757415 276.8874 293.66833 1.0757415 + 1680 125.13263 591.99646 1532.4661 205.72654 -940.46967 689.25478 743.16987 168.03522 0 -502.0189 512975.1 -515014.01 1349.4251 25768.301 293.2049 1.3360644 279.26444 295.71449 1.3360644 + 1700 126.41729 600.72595 1576.928 211.69534 -976.20204 698.82384 728.20266 164.32429 0 -509.63109 512960.78 -515018.71 -714.74537 25767.499 301.65964 1.4963853 288.03969 304.12166 1.4963853 + 1720 127.8002 608.72776 1572.2293 211.06457 -963.50155 686.50487 751.5254 162.66596 0 -520.30848 512974.4 -515018.29 -1233.7505 25765.895 300.75432 1.507047 296.46478 301.66689 1.507047 + 1740 129.05369 615.86972 1571.5987 210.97992 -955.72903 672.03255 760.03518 170.57691 0 -531.78859 512987.74 -515014.32 -5.6954413 25762.646 300.66959 1.422713 303.78613 300.35269 1.422713 + 1760 130.46587 622.55796 1579.5377 212.04568 -956.97974 706.80226 734.80437 178.63803 0 -529.02192 512966.71 -515014.91 1439.5408 25759.728 302.30266 1.1633531 310.55359 301.13515 1.1641118 + 1780 131.77476 628.52662 1584.4407 212.70388 -955.91404 676.79766 773.29727 172.22703 0 -534.56221 512976.35 -515020.03 -1144.3707 25758.632 303.36936 0.86750014 314.93649 301.6529 0.86760316 + 1800 133.12003 634.21603 1614.4896 216.73781 -980.27353 677.17437 758.17735 157.86038 0 -522.96761 512972.14 -515022.66 -952.36111 25756.246 309.15671 0.80472277 318.00054 307.89448 0.80488217 + 1820 134.41588 639.49479 1633.2745 219.2596 -993.77971 706.25176 736.76382 153.75695 0 -523.32693 512955.21 -515022.44 534.27821 25752.618 312.8094 0.68438418 326.33448 310.77281 0.68437053 + 1840 135.69809 643.87101 1634.8429 219.47015 -990.97185 701.84421 766.76216 151.35177 0 -502.94871 512911.91 -515019.89 654.67154 25749.912 313.13395 0.62866073 330.35595 310.48258 0.62856511 + 1860 137.01849 646.9769 1624.5262 218.08519 -977.54933 717.81093 788.02881 151.94179 0 -495.90915 512881.92 -515021.34 -1064.2782 25748.146 311.14125 0.66359764 330.55161 308.12656 0.66359764 + 1880 138.29577 648.32991 1639.5616 220.10361 -991.23166 726.93665 759.79041 159.81907 0 -493.81895 512873.87 -515017.83 -1411.6366 25744.916 313.99078 0.74007658 329.3198 311.65549 0.74007658 + 1900 139.67366 648.89417 1644.4291 220.75706 -995.53493 724.72865 762.39029 163.96612 0 -495.61342 512866.53 -515017.54 1351.1833 25740.228 314.85836 0.89300573 324.54001 313.46241 0.89316115 + 1920 140.93714 648.51479 1660.4204 222.90381 -1011.9056 683.6849 759.17365 164.85228 0 -494.26512 512891.03 -515016.38 401.57284 25737.361 317.86954 1.0199045 319.35529 317.83552 1.0202343 + 1940 142.29997 646.69169 1612.2108 216.43189 -965.51908 714.97385 778.57354 175.15205 0 -508.7717 512893.53 -515018.97 -1076.6986 25735.181 308.53939 1.2258299 312.47436 308.09188 1.2258299 + 1960 143.5485 643.66804 1612.4723 216.467 -968.80423 729.94319 778.86473 177.62474 0 -483.88964 512849.44 -515020.79 -696.10678 25731.708 308.50602 1.4206534 300.71602 310.00483 1.4206534 + 1980 144.89715 639.49991 1600.0251 214.79602 -960.52514 725.68053 773.8468 176.16615 0 -469.86188 512851.09 -515017.45 822.18174 25727.586 306.08335 1.5058554 291.63271 308.68799 1.505066 + 2000 146.15013 633.86554 1648.9263 221.36078 -1015.0607 703.29388 761.03433 170.08933 0 -468.34451 512835.81 -515016.94 763.74636 25724.778 315.51687 1.3681009 284.57812 320.86295 1.3683497 +Loop time of 146.15 on 1 procs for 2000 steps with 3000 atoms + +Performance: 0.591 ns/day, 40.597 hours/ns, 13.685 timesteps/s +100.0% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 92.462 | 92.462 | 92.462 | 0.0 | 63.26 +Bond | 2.9377 | 2.9377 | 2.9377 | 0.0 | 2.01 +Kspace | 28.493 | 28.493 | 28.493 | 0.0 | 19.50 +Neigh | 4.3811 | 4.3811 | 4.3811 | 0.0 | 3.00 +Comm | 0.86167 | 0.86167 | 0.86167 | 0.0 | 0.59 +Output | 0.040132 | 0.040132 | 0.040132 | 0.0 | 0.03 +Modify | 16.886 | 16.886 | 16.886 | 0.0 | 11.55 +Other | | 0.08886 | | | 0.06 + +Nlocal: 3000.00 ave 3000 max 3000 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 10696.0 ave 10696 max 10696 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 737603.0 ave 737603 max 737603 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 737603 +Ave neighs/atom = 245.86767 +Ave special neighs/atom = 10.500000 +Neighbor list builds = 59 +Dangerous builds = 0 +Total wall time: 0:02:26 diff --git a/examples/USER/drude/ethanol/log.12Nov20.ethanol.tgnh.g++.4 b/examples/USER/drude/ethanol/log.12Nov20.ethanol.tgnh.g++.4 new file mode 100644 index 0000000000..d8b7046fbc --- /dev/null +++ b/examples/USER/drude/ethanol/log.12Nov20.ethanol.tgnh.g++.4 @@ -0,0 +1,287 @@ +LAMMPS (29 Oct 2020) +OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:94) + using 1 OpenMP thread(s) per MPI task +units real +boundary p p p + +atom_style full +bond_style harmonic +angle_style harmonic +dihedral_style opls +special_bonds lj/coul 0.0 0.0 0.5 + +pair_style hybrid/overlay lj/cut/coul/long 8.0 8.0 thole 2.600 8.0 +kspace_style pppm 1.0e-4 + +comm_modify vel yes +read_data data.ethanol +Reading data file ... + orthogonal box = (-14.013845 -14.027809 -14.018882) to (14.016930 14.017730 14.085730) + 1 by 2 by 2 MPI processor grid + reading atoms ... + 3000 atoms + scanning bonds ... + 5 = max bonds/atom + scanning angles ... + 6 = max angles/atom + scanning dihedrals ... + 9 = max dihedrals/atom + reading bonds ... + 2750 bonds + reading angles ... + 3250 angles + reading dihedrals ... + 3000 dihedrals +Finding 1-2 1-3 1-4 neighbors ... + special bond factors lj: 0.0 0.0 0.5 + special bond factors coul: 0.0 0.0 0.5 + 5 = max # of 1-2 neighbors + 6 = max # of 1-3 neighbors + 10 = max # of 1-4 neighbors + 11 = max # of special neighbors + special bonds CPU = 0.003 seconds + read_data CPU = 0.115 seconds + +pair_coeff 1 1 lj/cut/coul/long 0.065997 3.500000 # C3H C3H +pair_coeff 1 2 lj/cut/coul/long 0.065997 3.500000 # C3H CTO +pair_coeff 1 3 lj/cut/coul/long 0.044496 2.958040 # C3H H +pair_coeff 1 4 lj/cut/coul/long 0.105921 3.304542 # C3H OH +pair_coeff 1 5 lj/cut/coul/long 0.000000 0.000000 # C3H HO +pair_coeff 2 2 lj/cut/coul/long 0.065997 3.500000 # CTO CTO +pair_coeff 2 3 lj/cut/coul/long 0.044496 2.958040 # CTO H +pair_coeff 2 4 lj/cut/coul/long 0.105921 3.304542 # CTO OH +pair_coeff 2 5 lj/cut/coul/long 0.000000 0.000000 # CTO HO +pair_coeff 3 3 lj/cut/coul/long 0.029999 2.500000 # H H +pair_coeff 3 4 lj/cut/coul/long 0.071413 2.792848 # H OH +pair_coeff 3 5 lj/cut/coul/long 0.000000 0.000000 # H HO +pair_coeff 4 4 lj/cut/coul/long 0.169996 3.120000 # OH OH +pair_coeff 4 5 lj/cut/coul/long 0.000000 0.000000 # OH HO +pair_coeff 5 5 lj/cut/coul/long 0.000000 0.000000 # HO HO +pair_coeff * 6*8 lj/cut/coul/long 0.000000 0.000000 # No lj for drudes +pair_coeff 1 1 thole 2.051000 +pair_coeff 1 2 thole 1.580265 +pair_coeff 1 4 thole 1.416087 +pair_coeff 1 6 thole 2.051000 +pair_coeff 1 7 thole 1.580265 +pair_coeff 1 8 thole 1.416087 +pair_coeff 2 2 thole 1.217570 +pair_coeff 2 4 thole 1.091074 +pair_coeff 2 6 thole 1.580265 +pair_coeff 2 7 thole 1.217570 +pair_coeff 2 8 thole 1.091074 +pair_coeff 4 4 thole 0.977720 +pair_coeff 4 6 thole 1.416087 +pair_coeff 4 7 thole 1.091074 +pair_coeff 4 8 thole 0.977720 +pair_coeff 6 6 thole 2.051000 +pair_coeff 6 7 thole 1.580265 +pair_coeff 6 8 thole 1.416087 +pair_coeff 7 7 thole 1.217570 +pair_coeff 7 8 thole 1.091074 +pair_coeff 8 8 thole 0.977720 + +group gETHANOL molecule 1:250 +3000 atoms in group gETHANOL +group gATOMS type 1 2 3 4 5 +2250 atoms in group gATOMS +group gDRUDES type 6 7 8 +750 atoms in group gDRUDES + +neighbor 2.0 bin + +variable vTEMP equal 300.0 +variable vTEMP_D equal 1.0 +variable vPRESS equal 1.0 + +velocity gATOMS create ${vTEMP} 12345 +velocity gATOMS create 300 12345 +velocity gDRUDES create ${vTEMP_D} 12345 +velocity gDRUDES create 1 12345 + +fix fDRUDE all drude C C N C N D D D + +fix fSHAKE gATOMS shake 0.0001 20 0 b 2 3 5 + 250 = # of size 2 clusters + 250 = # of size 3 clusters + 250 = # of size 4 clusters + 0 = # of frozen angles + find clusters CPU = 0.001 seconds + +fix fNPT all tgnpt/drude temp ${vTEMP} ${vTEMP} 100.0 ${vTEMP_D} 20.0 iso ${vPRESS} ${vPRESS} 1000 +fix fNPT all tgnpt/drude temp 300 ${vTEMP} 100.0 ${vTEMP_D} 20.0 iso ${vPRESS} ${vPRESS} 1000 +fix fNPT all tgnpt/drude temp 300 300 100.0 ${vTEMP_D} 20.0 iso ${vPRESS} ${vPRESS} 1000 +fix fNPT all tgnpt/drude temp 300 300 100.0 1 20.0 iso ${vPRESS} ${vPRESS} 1000 +fix fNPT all tgnpt/drude temp 300 300 100.0 1 20.0 iso 1 ${vPRESS} 1000 +fix fNPT all tgnpt/drude temp 300 300 100.0 1 20.0 iso 1 1 1000 + +compute cTEMP all temp/drude + +thermo_style custom step cpu etotal ke temp pe ebond eangle edihed eimp evdwl ecoul elong press vol c_cTEMP[1] c_cTEMP[2] f_fNPT[1] f_fNPT[2] f_fNPT[3] +thermo 20 + +timestep 0.5 +run 2000 +PPPM initialization ... + using 12-bit tables for long-range coulomb (src/kspace.cpp:328) + G vector (1/distance) = 0.37973843 + grid = 30 30 30 + stencil order = 5 + estimated absolute RMS force accuracy = 0.028997858 + estimated relative force accuracy = 8.7326188e-05 + using double precision FFTW3 + 3d grid and FFT values/proc = 17908 7200 +Rebuild special list taking Drude particles into account +Old max number of 1-2 to 1-4 neighbors: 11 +New max number of 1-2 to 1-4 neighbors: 11 (+0) +Neighbor list info ... + update every 1 steps, delay 10 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 10 + ghost atom cutoff = 10 + binsize = 5, bins = 6 6 6 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair lj/cut/coul/long, perpetual + attributes: half, newton on + pair build: half/bin/newton + stencil: half/bin/3d/newton + bin: standard + (2) pair thole, perpetual, skip from (1) + attributes: half, newton on + pair build: skip + stencil: none + bin: none +TGNHC thermostat for Drude model + DOFs of molecules, atoms and dipoles: 747.0 4500.0 2250.0 +Per MPI rank memory allocation (min/avg/max) = 16.30 | 16.32 | 16.34 Mbytes +Step CPU TotEng KinEng Temp PotEng E_bond E_angle E_dihed E_impro E_vdwl E_coul E_long Press Volume c_cTEMP[1] c_cTEMP[2] f_fNPT[1] f_fNPT[2] f_fNPT[3] + 0 0 13868.828 2013.3852 270.28772 11855.443 3145.896 51.880809 0.00019113234 0 8481.5109 514734.14 -514557.98 170210.19 22094.109 381.62759 10.134301 291.07893 396.91308 10.134301 + 20 0.5489804 9803.4819 5175.7976 694.82706 4627.6843 1139.1179 2334.7381 132.32214 0 1890.1377 514082.74 -514951.37 83147.098 22175.037 987.97841 9.8830686 2458.1459 744.58371 9.8830686 + 40 1.1305859 9235.5604 5579.723 749.0522 3655.8374 905.64066 1897.9743 277.47993 0 1696.6152 513843.93 -514965.8 60300.791 22359.784 1068.9531 1.6180875 2851.9045 773.69577 1.6180875 + 60 1.7763265 8672.0018 5504.7529 738.98781 3167.2488 829.16747 2052.5807 330.50296 0 997.97233 513948.23 -514991.2 48877.822 22600.434 1054.8974 0.8814188 3046.2785 725.0302 0.8814188 + 80 2.3974232 8041.5241 5718.5668 767.69134 2322.9573 733.63486 1714.8909 332.16188 0 607.44872 513906.01 -514971.19 46157.199 22855.699 1095.9682 0.68487797 2911.1669 795.37545 0.68487797 + 100 3.0302813 7424.2386 5485.3388 736.38155 1938.8999 725.65842 1556.2309 334.30067 0 311.29882 513993.24 -514981.83 35648.625 23094.994 1051.3251 0.52778467 2722.3899 774.63067 0.52778467 + 120 3.6273007 6864.3426 5106.0771 685.46741 1758.2655 639.83956 1608.9962 330.73079 0 225.62345 513930.12 -514977.04 28591.458 23302.572 978.66797 0.41866327 2531.1648 721.6052 0.41866327 + 140 4.196656 6355.3019 4782.0272 641.9652 1573.2747 692.74007 1572.242 329.76251 0 62.485696 513879.64 -514963.6 24167.635 23482.68 916.57384 0.35834425 2382.631 673.81858 0.35834425 + 160 4.779717 5871.7118 4610.7111 618.9668 1261.0006 680.57069 1414.3177 329.24321 0 -159.81123 513987.38 -514990.7 27541.231 23647.415 883.72945 0.36200572 2123.9268 678.44584 0.36200572 + 180 5.338641 5435.6217 4279.7314 574.5343 1155.8903 684.86021 1423.9782 309.42239 0 -233.49805 513945.42 -514974.29 18687.102 23808.747 820.29876 0.31648848 1867.6601 646.98347 0.31648848 + 200 5.9102262 5063.7313 3974.8766 533.60893 1088.8548 610.8373 1399.1355 299.45065 0 -238.66713 514006.14 -514988.04 14346.964 23962.508 761.84531 0.34591369 1649.624 614.98194 0.34591369 + 220 6.4670983 4729.6679 3862.1203 518.47192 867.54758 589.19356 1361.7383 291.57325 0 -382.16606 514000.72 -514993.51 14083.524 24105.992 740.21525 0.37963928 1480.8429 617.76448 0.37963928 + 240 7.0337756 4425.2126 3701.4126 496.89765 723.79998 584.3439 1295.3888 282.13205 0 -468.28082 514014.44 -514984.22 13173.086 24240.879 709.38377 0.43418988 1335.0115 606.00249 0.43418988 + 260 7.6151553 4147.9089 3443.8677 462.32342 704.04123 561.65864 1304.8745 277.43914 0 -505.26328 514062.78 -514997.45 9958.5179 24367.421 659.97189 0.52765671 1202.5793 570.33937 0.52753359 + 280 8.1803862 3906.1678 3262.9801 438.0401 643.18765 611.98615 1259.2636 278.89902 0 -503.31011 513978.3 -514981.95 5914.4091 24482.749 625.21285 0.7191852 1076.0582 550.78956 0.7191852 + 300 8.7043311 3688.7789 3139.2097 421.42449 549.56918 589.70836 1228.8579 274.66549 0 -529.44562 513979.71 -514993.93 8820.6294 24584.968 601.2678 1.2327257 967.30569 540.9051 1.2327257 + 320 9.2828722 3485.0301 3041.6251 408.32421 443.40492 581.268 1221.8962 276.57911 0 -581.90861 513938.2 -514992.63 9180.621 24679.345 582.26671 1.9139563 865.07721 535.70848 1.9139563 + 340 9.8440863 3301.0782 2892.3054 388.27872 408.77286 575.63973 1150.7154 289.94072 0 -522.07034 513896.97 -514982.42 7703.8271 24768.334 553.40856 2.4558958 782.77492 515.70254 2.4558958 + 360 10.398275 3134.468 2727.432 366.14522 407.03603 560.03929 1167.6565 290.68699 0 -534.30813 513917.05 -514994.09 5177.6501 24851.165 521.97249 2.0603668 720.8089 489.31359 2.0603668 + 380 10.971208 2978.8927 2626.9512 352.65614 351.94143 566.26677 1159.7933 275.53948 0 -574.10697 513905.99 -514981.54 5406.9463 24926.487 502.95796 1.4831172 663.80755 476.59194 1.4833313 + 400 11.487591 2830.3779 2572.5528 345.3534 257.82518 609.13682 1122.447 253.59547 0 -631.51589 513897.17 -514993.01 6594.5632 24996.158 492.72116 1.0347263 619.38728 472.02151 1.0352452 + 420 12.147771 2690.8114 2511.4485 337.15043 179.36289 580.62912 1054.4972 245.98614 0 -619.15187 513904.39 -514986.98 3340.3887 25062.398 481.15102 0.69884987 565.60536 467.45245 0.69884987 + 440 12.683915 2567.8386 2417.1223 324.48758 150.71626 550.84021 1061.6154 248.79898 0 -625.11745 513892.15 -514977.57 1516.8529 25122.396 463.15967 0.48668891 522.23117 453.66261 0.48668891 + 460 13.219765 2452.4983 2377.8819 319.21973 74.616329 562.85065 1024.1437 240.77499 0 -664.71238 513899.97 -514988.41 2625.4899 25175.085 455.6735 0.40127583 488.72927 450.48999 0.40127583 + 480 13.734817 2343.3317 2306.9816 309.70169 36.35008 544.98865 1036.7003 239.14437 0 -646.5969 513844.75 -514982.63 4826.9949 25223.402 442.07562 0.41558073 466.54905 438.30802 0.41558073 + 500 14.2704 2236.968 2183.0006 293.0578 53.967445 569.68824 1077.5153 241.06612 0 -644.36418 513802.58 -514992.52 3137.1149 25270.633 418.31485 0.39923526 447.67208 413.72065 0.39935381 + 520 14.830149 2139.9757 2184.3136 293.23408 -44.337922 598.68848 949.68592 231.65813 0 -640.55841 513811.34 -514995.15 74.532539 25314.977 418.54937 0.44074429 424.27621 417.87775 0.44074429 + 540 15.342945 2047.7713 2097.3453 281.55898 -49.574068 603.65225 992.19405 234.95516 0 -644.08949 513763.2 -514999.49 2503.1827 25353.667 401.80131 0.61813129 402.19428 402.00395 0.61813129 + 560 15.876281 1959.9733 2106.7002 282.81483 -146.72689 554.39132 933.09924 226.68229 0 -642.41154 513779.76 -514998.25 3929.9055 25390.434 403.5098 0.81842484 386.57171 406.59055 0.81842484 + 580 16.38257 1878.3658 2030.0966 272.53115 -151.7308 563.56362 914.74758 216.22925 0 -639.68928 513785.76 -514992.34 1013.3048 25427.188 388.65548 1.2108332 381.10541 390.16777 1.2108332 + 600 16.920685 1802.551 2017.1476 270.7928 -214.59656 542.55586 900.05624 215.01335 0 -670.18556 513796.03 -514998.07 18.493782 25460.775 385.93337 1.7700661 377.13463 387.65116 1.7700661 + 620 17.474131 1730.0309 1927.5545 258.76534 -197.52353 548.09305 912.68313 219.66229 0 -677.86412 513801.32 -515001.42 211.58879 25489.947 368.6727 1.9725715 368.40356 368.96285 1.9725715 + 640 17.983631 1659.1463 1874.5489 251.64958 -215.40256 560.91381 910.47755 215.67628 0 -668.88025 513765.74 -514999.33 3576.6139 25516.217 358.58525 1.8035012 356.22593 359.21531 1.8035012 + 660 18.557287 1589.2837 1850.4075 248.40872 -261.12386 578.2925 854.48492 205.27001 0 -645.94735 513747.59 -515000.82 1704.7835 25543.749 354.0776 1.5147284 344.22319 355.94967 1.5157289 + 680 19.099188 1523.7572 1809.2809 242.88766 -285.52371 571.10597 870.42753 209.32749 0 -670.04285 513734.83 -515001.17 -730.02178 25570.285 346.40935 1.010892 331.62309 349.09523 1.010892 + 700 19.606934 1462.426 1781.0971 239.10411 -318.67111 547.9598 858.22372 204.5839 0 -674.26004 513742.06 -514997.24 1193.1019 25593.123 341.12225 0.74301975 322.22823 344.48583 0.74301975 + 720 20.138988 1403.965 1772.7176 237.9792 -368.75257 537.38813 872.15383 187.31368 0 -658.83726 513691.57 -514998.34 1717.9835 25614.736 339.57934 0.59520661 315.58412 343.78893 0.59520661 + 740 20.654731 1347.9142 1778.2063 238.71603 -430.29207 554.12065 833.24568 175.13397 0 -676.57227 513685.79 -515002.01 1164.2855 25636.35 340.66194 0.52336173 311.70411 345.69611 0.52336173 + 760 21.20085 1294.8201 1727.5363 231.91382 -432.71627 562.83637 826.41881 177.39944 0 -670.89859 513677.68 -515006.15 -2179.3296 25656.719 330.96325 0.48927201 305.61756 335.39128 0.48927201 + 780 21.736798 1244.1479 1729.459 232.17193 -485.31103 563.29093 800.45744 179.65918 0 -660.60078 513641.9 -515010.01 140.35372 25672.399 331.32725 0.49993893 293.14787 337.88591 0.49993893 + 800 22.313875 1195.9276 1716.8118 230.47411 -520.8842 572.20526 790.59915 174.22123 0 -646.04585 513597.21 -515009.08 2706.2932 25686.61 328.8596 0.60065349 282.54175 336.7676 0.60065349 + 820 22.880819 1149.3267 1681.646 225.75325 -532.31925 564.24784 783.06404 168.40012 0 -638.53799 513598.2 -515007.69 291.5994 25702.646 322.07401 0.70343079 279.53588 329.34955 0.70332477 + 840 23.400356 1107.2877 1640.6002 220.24304 -533.31252 558.56409 815.12167 157.71519 0 -653.87313 513597.92 -515008.76 -762.24777 25717.669 314.07832 1.0007715 278.89623 320.12842 1.0010942 + 860 23.930137 1066.5896 1621.3757 217.66224 -554.78609 569.30332 821.05893 152.83409 0 -645.45431 513552.23 -515004.75 100.50325 25730.157 310.25167 1.3271389 283.08497 314.96823 1.3271389 + 880 24.425549 1027.6567 1624.8454 218.12803 -597.18868 587.96681 765.45362 159.91238 0 -628.42404 513525.88 -515007.98 2270.6911 25741.827 310.74777 1.7225758 280.31191 316.00736 1.7225758 + 900 24.945527 989.67183 1619.7368 217.44223 -630.06494 605.34666 753.15286 166.12808 0 -637.67643 513491.85 -515008.87 -504.34781 25755.03 309.75098 1.7673447 280.95321 314.73839 1.7673447 + 920 25.481976 952.75609 1646.0573 220.97563 -693.30118 586.10824 737.80362 161.44982 0 -645.91448 513480.65 -515013.4 -2245.0436 25766.26 314.83888 1.6620102 286.24272 319.79545 1.6618169 + 940 26.009417 916.27341 1558.2262 209.18472 -641.95282 584.88671 784.61327 161.29551 0 -636.55462 513482.98 -515019.17 351.20595 25773.56 298.17626 1.2572795 293.25423 299.19214 1.2573671 + 960 26.54868 881.26579 1570.5631 210.84088 -689.29727 567.48803 757.85558 154.89763 0 -628.37927 513476.62 -515017.78 1224.7198 25780.472 300.67272 0.95167357 297.40913 301.41483 0.95167357 + 980 27.082306 848.00567 1563.3504 209.87262 -715.34478 576.51161 766.15302 148.2325 0 -637.27495 513450.83 -515019.79 -304.57224 25788.336 299.38564 0.72910884 295.89994 300.16415 0.72910884 + 1000 27.619404 817.47747 1553.8221 208.59349 -736.34466 586.86696 709.60783 150.55877 0 -608.57994 513440.8 -515015.6 -1422.5332 25794.968 297.60262 0.62762006 294.24682 298.35812 0.62773318 + 1020 28.12313 789.1786 1563.9655 209.95519 -774.78691 608.04057 694.03517 152.80101 0 -605.61567 513386.72 -515010.76 1005.4938 25799.349 299.58342 0.54306229 290.32557 301.31971 0.54293571 + 1040 28.647646 762.65087 1534.0005 205.93252 -771.3496 587.61838 735.74998 150.09823 0 -603.04152 513371.63 -515013.4 1470.8094 25804.634 293.84005 0.54036941 291.28531 294.46003 0.54036941 + 1060 29.166844 737.77923 1518.4576 203.84597 -780.67842 594.18573 720.72071 149.63679 0 -601.17736 513365.82 -515009.86 -729.10372 25811.329 290.84548 0.57532052 295.86391 290.20631 0.57532052 + 1080 29.694185 715.33941 1497.4861 201.03063 -782.14665 601.83156 732.61956 157.72044 0 -593.12281 513331.09 -515012.29 -1329.475 25816.507 286.76945 0.70534246 298.86373 284.95298 0.70534246 + 1100 30.187888 694.69953 1511.5454 202.91803 -816.84589 616.66719 703.13897 158.99611 0 -577.76244 513295.95 -515013.83 324.57282 25819.509 289.39998 0.85625823 302.74025 287.37843 0.85625823 + 1120 30.72232 675.80012 1511.985 202.97705 -836.18488 604.64779 695.06693 153.9432 0 -584.60486 513304.31 -515009.54 1125.7488 25822.677 289.3669 1.1300709 304.44007 287.0563 1.1300629 + 1140 31.225571 658.36551 1521.8389 204.29988 -863.47335 629.12728 674.88861 150.24405 0 -590.89933 513286.66 -515013.49 -980.39731 25826.849 291.15043 1.376207 307.33908 288.65717 1.3761333 + 1160 31.744542 641.31431 1531.9582 205.65836 -890.64389 626.42495 680.62653 148.56061 0 -577.09298 513242.55 -515011.72 -1275.5851 25829.398 292.96469 1.6693561 303.6583 291.38487 1.6693561 + 1180 32.314241 624.85166 1471.4431 197.53448 -846.59145 617.3346 711.86666 153.07391 0 -572.06725 513251.25 -515008.05 1129.9547 25830.175 281.38976 1.6087801 294.57721 279.38824 1.6087801 + 1200 32.836834 609.19491 1498.3739 201.14982 -889.17902 629.25511 684.67985 160.94667 0 -569.8543 513217.89 -515012.1 714.83828 25832.193 286.64705 1.3880783 283.02115 287.44058 1.3888122 + 1220 33.330996 594.74278 1478.8355 198.52688 -884.09277 636.92004 698.39685 160.32561 0 -562.35565 513195.99 -515013.37 -758.81758 25835.054 283.01514 1.1229017 278.46407 283.95841 1.1229296 + 1240 33.860993 582.31866 1493.1918 200.45414 -910.87313 618.74977 681.25809 152.31533 0 -562.54483 513217.1 -515017.75 -1008.5931 25836.703 285.8671 0.88995954 281.0699 286.85402 0.88995954 + 1260 34.359886 571.65412 1485.3064 199.39557 -913.6523 627.02685 698.36302 149.47819 0 -579.83549 513207.17 -515015.85 -191.59975 25836.765 284.43438 0.70581205 287.41841 284.12865 0.70581205 + 1280 34.886036 563.01807 1489.0976 199.90452 -926.07957 639.7656 697.32018 156.99221 0 -585.76217 513181.62 -515016.02 169.07813 25836.47 285.20229 0.61087596 293.46017 284.02179 0.61087596 + 1300 35.37543 555.84411 1527.2006 205.01966 -971.35646 641.09274 662.1865 159.13537 0 -579.97157 513161.92 -515015.72 -1463.4981 25836.182 292.51734 0.58590366 295.34409 292.24276 0.58590366 + 1320 35.905183 550.05933 1490.5448 200.09879 -940.48543 625.52991 696.21744 165.64927 0 -566.29494 513152.4 -515013.99 -1001.3282 25833.961 285.49188 0.58134778 295.28397 284.05681 0.58136859 + 1340 36.400304 545.82552 1477.3653 198.3295 -931.53974 649.76738 698.13673 166.18782 0 -561.79356 513131.65 -515015.49 256.39573 25830.414 282.92884 0.6685389 293.55866 281.35291 0.66910289 + 1360 36.922034 543.45958 1491.565 200.23575 -948.10541 625.58496 716.94864 163.71131 0 -571.55519 513134.22 -515017.02 297.35038 25827.363 285.59777 0.79202277 296.88495 283.9144 0.79202277 + 1380 37.451357 542.88076 1508.4282 202.49956 -965.54741 646.84583 717.12486 157.01613 0 -570.9963 513101.79 -515017.33 -727.70264 25824.817 288.73715 1.0078391 299.43294 287.15417 1.0078391 + 1400 37.973437 543.25917 1541.9768 207.00331 -998.71768 642.88473 676.64442 147.18972 0 -575.45961 513127.78 -515017.75 -1351.9224 25821.311 295.05395 1.2758201 298.33888 294.70535 1.2758201 + 1420 38.477087 544.25328 1494.226 200.59298 -949.97275 637.44698 691.08413 146.44269 0 -570.05548 513163.4 -515018.29 -270.25101 25816.213 285.82275 1.45608 293.72434 284.70163 1.45608 + 1440 39.004978 546.23983 1496.1396 200.84988 -949.89981 631.74619 738.457 152.80933 0 -573.9543 513118.44 -515017.39 211.73327 25811.001 286.12443 1.60978 287.34634 286.11175 1.60978 + 1460 39.506582 548.84457 1466.6766 196.8946 -917.83206 633.37692 721.14643 162.99807 0 -556.88904 513139.89 -515018.35 -423.45238 25806.343 280.53109 1.4808771 287.46457 279.56727 1.4808771 + 1480 40.013021 551.95616 1529.776 205.3654 -977.81982 643.3714 687.91646 168.45052 0 -559.19128 513096.53 -515014.9 -1060.0608 25801.347 292.71931 1.2657554 295.62549 292.43217 1.2657554 + 1500 40.538129 555.97974 1537.2966 206.37501 -981.31688 625.22061 717.66026 158.35427 0 -572.42591 513106.71 -515016.83 -521.38973 25795.193 294.26369 1.0278009 305.22402 292.64051 1.0278009 + 1520 41.025889 561.04463 1546.2574 207.57796 -985.21278 635.77714 721.02166 143.98506 0 -562.3667 513090.07 -515013.7 480.66458 25788.679 296.07983 0.80049966 308.03207 294.29295 0.80049966 + 1540 41.55805 566.68767 1533.2704 205.83452 -966.58278 654.42171 733.05018 143.06827 0 -536.78594 513051.91 -515012.25 -13.266306 25783.154 293.62787 0.70845158 300.7356 292.64315 0.70845158 + 1560 42.081834 573.47741 1545.9514 207.53687 -972.47397 667.35837 705.11749 148.50883 0 -511.03863 513035.3 -515017.72 -1128.9314 25777.865 296.082 0.65411382 299.13367 295.77283 0.65411382 + 1580 42.665773 580.84578 1594.8648 214.10328 -1014.0191 665.14281 711.19644 150.09976 0 -528.59268 513008.73 -515020.6 202.40236 25771.588 305.48503 0.59346496 305.13087 305.74762 0.59346496 + 1600 43.198806 587.93053 1593.0533 213.8601 -1005.1228 667.00914 717.18229 154.08514 0 -518.43498 512998.02 -515022.99 1129.067 25765.95 305.11474 0.64754135 305.66863 305.22598 0.64754135 + 1620 43.714818 594.73059 1540.0228 206.74099 -945.29217 676.98346 739.79112 155.99494 0 -494.24155 512994.51 -515018.33 526.11962 25762.249 294.90314 0.75499506 297.8325 294.6134 0.75499506 + 1640 44.259458 602.01816 1574.0462 211.30848 -972.02805 663.3896 727.17417 151.24073 0 -494.0956 513000.57 -515020.3 -575.47503 25759.514 301.37613 0.86690808 296.74738 302.34638 0.86686227 + 1660 44.764134 609.8688 1585.4465 212.83891 -975.57766 664.90151 754.20462 143.39975 0 -512.60013 512995.21 -515020.69 120.01767 25756.288 303.44799 1.1375937 302.29356 303.8427 1.1375483 + 1680 45.295079 617.0121 1599.4294 214.71606 -982.41735 673.71348 740.31978 139.29744 0 -523.39592 513004.17 -515016.52 1018.995 25753.537 306.06349 1.2857605 306.24911 306.23701 1.2851446 + 1700 45.797194 622.7816 1587.5062 213.11542 -964.72461 681.14985 737.5354 142.64373 0 -527.89471 513016.69 -515014.85 -762.54382 25752.152 303.67113 1.5346092 313.56414 302.2316 1.5344941 + 1720 46.320299 627.3514 1607.6889 215.82486 -980.33755 664.85413 752.47086 151.63477 0 -558.53514 513025.83 -515016.59 -1533.2781 25749.855 307.5455 1.5204255 324.85436 304.8785 1.5204255 + 1740 46.830115 630.51695 1598.6908 214.6169 -968.17382 653.58364 747.05167 160.79211 0 -580.54509 513063.86 -515012.91 -682.94257 25745.444 305.87278 1.3989272 333.2609 301.5297 1.3989272 + 1760 47.394788 632.38111 1593.237 213.88475 -960.85589 650.78705 764.11644 167.2889 0 -573.51639 513045.53 -515015.07 563.26755 25740.336 304.94629 1.1225547 334.94227 300.17035 1.1225547 + 1780 47.922889 633.30997 1598.6499 214.61141 -965.33996 653.54119 765.83593 164.00427 0 -562.23222 513033.51 -515020 -1327.8381 25735.912 306.08499 0.88668411 334.15679 301.62884 0.88668411 + 1800 48.463113 633.70382 1649.9701 221.50091 -1016.2663 659.96781 745.28779 159.23213 0 -549.62971 512990.43 -515021.55 -1220.9829 25730.022 315.99137 0.72802345 326.79654 314.40852 0.72802345 + 1820 48.984029 633.58292 1659.156 222.73407 -1025.573 665.57877 731.85128 149.46328 0 -533.84488 512983.77 -515022.39 259.29033 25722.788 317.77089 0.68459607 313.70692 318.65732 0.68459607 + 1840 49.535432 632.84896 1602.3796 215.1121 -969.53059 677.68273 790.85762 153.52845 0 -510.95603 512938.27 -515018.91 271.83168 25716.16 306.91304 0.62307528 301.73642 307.97704 0.62193772 + 1860 50.131212 631.44034 1614.3342 216.71695 -982.89384 704.07775 755.95641 164.4832 0 -496.35082 512910.85 -515021.91 193.91175 25710.384 309.1988 0.63700741 295.94067 311.60525 0.63654587 + 1880 50.855644 629.18958 1597.9323 214.51508 -968.74275 705.91154 777.10222 163.27419 0 -490.72673 512895.73 -515020.04 -974.53867 25705.004 306.00767 0.74633313 296.65573 307.7641 0.74633313 + 1900 51.442767 625.97644 1641.4591 220.35835 -1015.4827 686.52567 770.03702 156.74058 0 -497.98541 512884.62 -515015.42 634.14021 25698.897 314.30703 0.85093529 303.58173 316.29697 0.85093529 + 1920 52.143124 621.81199 1629.0055 218.68651 -1007.1935 697.66793 744.88149 154.37261 0 -496.80305 512905.46 -515012.77 706.77423 25693.859 311.83949 1.0371868 309.16955 312.48998 1.0372355 + 1940 52.903306 616.46004 1627.6423 218.50351 -1011.1823 701.93564 779.10792 151.5545 0 -486.4562 512854.72 -515012.04 -356.74685 25690.093 311.50393 1.2116518 310.99764 311.79486 1.2113866 + 1960 53.626542 609.78344 1638.9504 220.02157 -1029.167 696.4213 776.28011 154.35764 0 -474.71134 512832.29 -515013.81 -303.73538 25686.165 313.59711 1.3852662 315.5116 313.48837 1.3852662 + 1980 54.31028 600.96661 1637.173 219.78295 -1036.2064 718.42192 759.0789 153.6092 0 -472.50282 512815.84 -515010.66 -151.6766 25681.92 313.21609 1.4792586 321.24113 312.09275 1.4792586 + 2000 54.986641 589.81965 1648.0734 221.24629 -1058.2538 690.75922 747.98481 160.84305 0 -487.54224 512840.7 -515011 980.73982 25677.907 315.36457 1.3399431 321.77651 314.51049 1.3399431 +Loop time of 54.9868 on 4 procs for 2000 steps with 3000 atoms + +Performance: 1.571 ns/day, 15.274 hours/ns, 36.372 timesteps/s +98.8% CPU use with 4 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 27.901 | 28.34 | 29.027 | 7.9 | 51.54 +Bond | 0.92918 | 0.94546 | 0.97217 | 1.7 | 1.72 +Kspace | 14.647 | 15.356 | 15.836 | 11.2 | 27.93 +Neigh | 1.6543 | 1.6584 | 1.6622 | 0.2 | 3.02 +Comm | 1.5279 | 1.6227 | 1.7184 | 5.6 | 2.95 +Output | 0.022354 | 0.027337 | 0.040941 | 4.8 | 0.05 +Modify | 5.7813 | 6.226 | 6.5243 | 12.2 | 11.32 +Other | | 0.8108 | | | 1.47 + +Nlocal: 750.000 ave 763 max 736 min +Histogram: 1 0 0 0 1 0 1 0 0 1 +Nghost: 6184.00 ave 6204 max 6165 min +Histogram: 1 0 0 1 0 0 1 0 0 1 +Neighs: 185088.0 ave 189615 max 180533 min +Histogram: 2 0 0 0 0 0 0 0 0 2 + +Total # of neighbors = 740354 +Ave neighs/atom = 246.78467 +Ave special neighs/atom = 10.500000 +Neighbor list builds = 63 +Dangerous builds = 0 +Total wall time: 0:00:55 diff --git a/examples/mliap/README b/examples/mliap/README new file mode 100644 index 0000000000..af848e42ba --- /dev/null +++ b/examples/mliap/README @@ -0,0 +1,103 @@ +This directory contains multiple examples of +machine-learning potentials defined using the +MLIAP package in LAMMPS. The input files +are described below. + +in.mliap.snap.Ta06A +------------------- +Run linear SNAP, equivalent to examples/snap/in.snap.Ta06A + +in.mliap.snap.WBe.PRB2019 +------------------------- +Run linear SNAP, equivalent to examples/snap/in.snap.WBe.PRB2019 + +in.mliap.snap.quadratic +----------------------- +Run quadratic SNAP + +in.mliap.snap.chem +------------------ +Run EME-SNAP, equivalent to examples/snap/in.snap.InP.JCPA2020 + +in.mliap.snap.compute +--------------------- +Generate the A matrix, the gradients (w.r.t. coefficients) +of total potential energy, forces, and stress tensor for +linear SNAP, equivalent to in.snap.compute + +in.mliap.quadratic.compute +-------------------------- +Generate the A matrix, the gradients (w.r.t. coefficients) +of total potential energy, forces, and stress tensor for +for quadratic SNAP, equivalent to in.snap.compute.quadratic + +in.mliap.pytorch.Ta06A +----------------------- +This reproduces the output of in.mliap.snap.Ta06A above, +but using the Python coupling to PyTorch. + +This example can be run in two different ways: + +1: Running a LAMMPS executable: in.mliap.pytorch.Ta06A + +First run ``python convert_mliap_Ta06A.py``. It creates +a PyTorch energy model that replicates the +SNAP Ta06A potential and saves it in the file +"Ta06A.mliap.pytorch.model.pt". + +You can then run the example as follows + +`lmp -in in.mliap.pytorch.Ta06A -echo both` + +The resultant log.lammps output should be identical to that generated +by in.mliap.snap.Ta06A. + +If this fails, see the instructions for building the MLIAP package +with Python support enabled. Also, confirm that the +LAMMPS Python embedded Python interpreter is +working by running ../examples/in.python. + +2: Running a Python script: mliap_pytorch_Ta06A.py + +Before testing this, ensure that the previous method +(running a LAMMPS executable) works. + +You can run the example in serial: + +`python mliap_pytorch_Ta06A.py` + +or in parallel: + +`mpirun -np 4 python mliap_pytorch_Ta06A.py` + +The resultant log.lammps output should be identical to that generated +by in.mliap.snap.Ta06A and in.mliap.pytorch.Ta06A. + +Not all Python installations support this mode of operation. +It requires that the Python interpreter be initialized. If not, +the script will exit with an error message. + +in.mliap.pytorch.relu1hidden +---------------------------- +This example demonstrates a simple neural network potential +using PyTorch and SNAP descriptors. + +`lmp -in in.mliap.pytorch.relu1hidden -echo both` + +It was trained on just the energy component (no forces) of +the data used in the original SNAP Ta06A potential for +tantalum (Thompson, Swiler, Trott, Foiles, Tucker, +J Comp Phys, 285, 316 (2015).). Because of the very small amount +of energy training data, it uses just 1 hidden layer with +a ReLU activation function. It is not expected to be +very accurate for forces. + +NOTE: Unlike the previous example, this example uses +a pre-built PyTorch file `Ta06A.mliap.pytorch.model.pt`. +It is read using `torch.load`, +which implicitly uses the Python `pickle` module. +This is known to be insecure. It is possible to construct malicious +pickle data that will execute arbitrary code during unpickling. Never +load data that could have come from an untrusted source, or that +could have been tampered with. Only load data you trust. + diff --git a/examples/mliap/Ta06A.mliap.pytorch b/examples/mliap/Ta06A.mliap.pytorch new file mode 100644 index 0000000000..5489688a82 --- /dev/null +++ b/examples/mliap/Ta06A.mliap.pytorch @@ -0,0 +1,18 @@ +# DATE: 2014-09-05 UNITS: metal CONTRIBUTOR: Aidan Thompson athomps@sandia.gov CITATION: Thompson, Swiler, Trott, Foiles and Tucker, arxiv.org, 1409.3880 (2014) + +# Definition of SNAP potential Ta_Cand06A +# Assumes 1 LAMMPS atom type + +variable zblcutinner equal 4 +variable zblcutouter equal 4.8 +variable zblz equal 73 + +# Specify hybrid with SNAP, ZBL + +pair_style hybrid/overlay & +zbl ${zblcutinner} ${zblcutouter} & +mliap model mliappy Ta06A.mliap.pytorch.model.pt & +descriptor sna Ta06A.mliap.descriptor +pair_coeff 1 1 zbl ${zblz} ${zblz} +pair_coeff * * mliap Ta + diff --git a/examples/mliap/convert_mliap_Ta06A.py b/examples/mliap/convert_mliap_Ta06A.py new file mode 100644 index 0000000000..8a7466743f --- /dev/null +++ b/examples/mliap/convert_mliap_Ta06A.py @@ -0,0 +1,26 @@ +import sys +import numpy as np +import torch + +# torch.nn.modules useful for defining a MLIAPPY model. +from lammps.mliap.pytorch import TorchWrapper, IgnoreElems + +# Read coefficients +coeffs = np.genfromtxt("Ta06A.mliap.model",skip_header=6) + +# Write coefficients to a pytorch linear model +bias = coeffs[0] +weights = coeffs[1:] +lin = torch.nn.Linear(weights.shape[0],1) +lin.to(torch.float64) +with torch.autograd.no_grad(): + lin.weight.set_(torch.from_numpy(weights).unsqueeze(0)) + lin.bias.set_(torch.as_tensor(bias,dtype=torch.float64).unsqueeze(0)) + +# Wrap the pytorch model for usage with mliappy coupling. +model = IgnoreElems(lin) # The linear module does not use the types. +n_descriptors = lin.weight.shape[1] +n_elements = 1 +linked_model = TorchWrapper(model,n_descriptors=n_descriptors,n_elements=n_elements) + +torch.save(linked_model,"Ta06A.mliap.pytorch.model.pt") diff --git a/examples/mliap/in.mliap.pytorch.Ta06A b/examples/mliap/in.mliap.pytorch.Ta06A new file mode 100644 index 0000000000..59cdcc8c81 --- /dev/null +++ b/examples/mliap/in.mliap.pytorch.Ta06A @@ -0,0 +1,53 @@ +# Demonstrate MLIAP/PyTorch interface to linear SNAP potential + +# Initialize simulation + +variable nsteps index 100 +variable nrep equal 4 +variable a equal 3.316 +units metal + +# generate the box and atom positions using a BCC lattice + +variable nx equal ${nrep} +variable ny equal ${nrep} +variable nz equal ${nrep} + +boundary p p p + +lattice bcc $a +region box block 0 ${nx} 0 ${ny} 0 ${nz} +create_box 1 box +create_atoms 1 box + +mass 1 180.88 + +# choose potential + +include Ta06A.mliap.pytorch + +# Setup output + +compute eatom all pe/atom +compute energy all reduce sum c_eatom + +compute satom all stress/atom NULL +compute str all reduce sum c_satom[1] c_satom[2] c_satom[3] +variable press equal (c_str[1]+c_str[2]+c_str[3])/(3*vol) + +thermo_style custom step temp epair c_energy etotal press v_press +thermo 10 +thermo_modify norm yes + +# Set up NVE run + +timestep 0.5e-3 +neighbor 1.0 bin +neigh_modify once no every 1 delay 0 check yes + +# Run MD + +velocity all create 300.0 4928459 loop geom +fix 1 all nve +run ${nsteps} + diff --git a/examples/mliap/in.mliap.pytorch.relu1hidden b/examples/mliap/in.mliap.pytorch.relu1hidden new file mode 100644 index 0000000000..f19ffb608d --- /dev/null +++ b/examples/mliap/in.mliap.pytorch.relu1hidden @@ -0,0 +1,53 @@ +# Demonstrate MLIAP interface to linear SNAP potential + +# Initialize simulation + +variable nsteps index 100 +variable nrep equal 4 +variable a equal 3.316 +units metal + +# generate the box and atom positions using a BCC lattice + +variable nx equal ${nrep} +variable ny equal ${nrep} +variable nz equal ${nrep} + +boundary p p p + +lattice bcc $a +region box block 0 ${nx} 0 ${ny} 0 ${nz} +create_box 1 box +create_atoms 1 box + +mass 1 180.88 + +# choose potential + +include relu1hidden.mliap.pytorch + +# Setup output + +compute eatom all pe/atom +compute energy all reduce sum c_eatom + +compute satom all stress/atom NULL +compute str all reduce sum c_satom[1] c_satom[2] c_satom[3] +variable press equal (c_str[1]+c_str[2]+c_str[3])/(3*vol) + +thermo_style custom step temp epair c_energy etotal press v_press +thermo 10 +thermo_modify norm yes + +# Set up NVE run + +timestep 0.5e-3 +neighbor 1.0 bin +neigh_modify once no every 1 delay 0 check yes + +# Run MD + +velocity all create 300.0 4928459 loop geom +fix 1 all nve +run ${nsteps} + diff --git a/examples/mliap/in.mliap.snap.Ta06A b/examples/mliap/in.mliap.snap.Ta06A index 3d94d5c9fc..7b9b5b47d1 100644 --- a/examples/mliap/in.mliap.snap.Ta06A +++ b/examples/mliap/in.mliap.snap.Ta06A @@ -1,4 +1,4 @@ -# Demonstrate MLIAP interface to kinear SNAP potential +# Demonstrate MLIAP interface to linear SNAP potential # Initialize simulation diff --git a/examples/mliap/log.04Dec20.mliap.pytorch.Ta06A.g++.1 b/examples/mliap/log.04Dec20.mliap.pytorch.Ta06A.g++.1 new file mode 100644 index 0000000000..f56a79650e --- /dev/null +++ b/examples/mliap/log.04Dec20.mliap.pytorch.Ta06A.g++.1 @@ -0,0 +1,157 @@ +LAMMPS (30 Nov 2020) + using 48 OpenMP thread(s) per MPI task +# Demonstrate MLIAP/PyTorch interface to linear SNAP potential + +# Initialize simulation + +variable nsteps index 100 +variable nrep equal 4 +variable a equal 3.316 +units metal + +# generate the box and atom positions using a BCC lattice + +variable nx equal ${nrep} +variable nx equal 4 +variable ny equal ${nrep} +variable ny equal 4 +variable nz equal ${nrep} +variable nz equal 4 + +boundary p p p + +lattice bcc $a +lattice bcc 3.316 +Lattice spacing in x,y,z = 3.3160000 3.3160000 3.3160000 +region box block 0 ${nx} 0 ${ny} 0 ${nz} +region box block 0 4 0 ${ny} 0 ${nz} +region box block 0 4 0 4 0 ${nz} +region box block 0 4 0 4 0 4 +create_box 1 box +Created orthogonal box = (0.0000000 0.0000000 0.0000000) to (13.264000 13.264000 13.264000) + 1 by 1 by 1 MPI processor grid +create_atoms 1 box +Created 128 atoms + create_atoms CPU = 0.002 seconds + +mass 1 180.88 + +# choose potential + +include Ta06A.mliap.pytorch +# DATE: 2014-09-05 UNITS: metal CONTRIBUTOR: Aidan Thompson athomps@sandia.gov CITATION: Thompson, Swiler, Trott, Foiles and Tucker, arxiv.org, 1409.3880 (2014) + +# Definition of SNAP potential Ta_Cand06A +# Assumes 1 LAMMPS atom type + +variable zblcutinner equal 4 +variable zblcutouter equal 4.8 +variable zblz equal 73 + +# Specify hybrid with SNAP, ZBL + +pair_style hybrid/overlay zbl ${zblcutinner} ${zblcutouter} mliap model mliappy Ta06A.mliap.pytorch.model.pkl descriptor sna Ta06A.mliap.descriptor +pair_style hybrid/overlay zbl 4 ${zblcutouter} mliap model mliappy Ta06A.mliap.pytorch.model.pkl descriptor sna Ta06A.mliap.descriptor +pair_style hybrid/overlay zbl 4 4.8 mliap model mliappy Ta06A.mliap.pytorch.model.pkl descriptor sna Ta06A.mliap.descriptor +Loading python model complete. +Reading potential file Ta06A.mliap.descriptor with DATE: 2014-09-05 +SNAP keyword rcutfac 4.67637 +SNAP keyword twojmax 6 +SNAP keyword nelems 1 +SNAP keyword elems Ta +SNAP keyword radelems 0.5 +SNAP keyword welems 1 +SNAP keyword rfac0 0.99363 +SNAP keyword rmin0 0 +SNAP keyword bzeroflag 0 +pair_coeff 1 1 zbl ${zblz} ${zblz} +pair_coeff 1 1 zbl 73 ${zblz} +pair_coeff 1 1 zbl 73 73 +pair_coeff * * mliap Ta + + +# Setup output + +compute eatom all pe/atom +compute energy all reduce sum c_eatom + +compute satom all stress/atom NULL +compute str all reduce sum c_satom[1] c_satom[2] c_satom[3] +variable press equal (c_str[1]+c_str[2]+c_str[3])/(3*vol) + +thermo_style custom step temp epair c_energy etotal press v_press +thermo 10 +thermo_modify norm yes + +# Set up NVE run + +timestep 0.5e-3 +neighbor 1.0 bin +neigh_modify once no every 1 delay 0 check yes + +# Run MD + +velocity all create 300.0 4928459 loop geom +fix 1 all nve +run ${nsteps} +run 100 +Neighbor list info ... + update every 1 steps, delay 0 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 5.8 + ghost atom cutoff = 5.8 + binsize = 2.9, bins = 5 5 5 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair zbl, perpetual, half/full from (2) + attributes: half, newton on + pair build: halffull/newton + stencil: none + bin: none + (2) pair mliap, perpetual + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard +Per MPI rank memory allocation (min/avg/max) = 159.8 | 159.8 | 159.8 Mbytes +Step Temp E_pair c_energy TotEng Press v_press + 0 300 -11.85157 -11.85157 -11.813095 2717.1661 -2717.1661 + 10 296.01467 -11.851059 -11.851059 -11.813095 2697.4796 -2697.4796 + 20 284.53666 -11.849587 -11.849587 -11.813095 2289.1527 -2289.1527 + 30 266.51577 -11.847275 -11.847275 -11.813095 1851.7131 -1851.7131 + 40 243.05007 -11.844266 -11.844266 -11.813095 1570.684 -1570.684 + 50 215.51032 -11.840734 -11.840734 -11.813094 1468.1899 -1468.1899 + 60 185.48331 -11.836883 -11.836883 -11.813094 1524.8757 -1524.8757 + 70 154.6736 -11.832931 -11.832931 -11.813094 1698.3351 -1698.3351 + 80 124.79303 -11.829099 -11.829099 -11.813094 1947.0715 -1947.0715 + 90 97.448054 -11.825592 -11.825592 -11.813094 2231.9563 -2231.9563 + 100 74.035418 -11.822589 -11.822589 -11.813094 2515.8526 -2515.8526 +Loop time of 2.00236 on 48 procs for 100 steps with 128 atoms + +Performance: 2.157 ns/day, 11.124 hours/ns, 49.941 timesteps/s +288.8% CPU use with 1 MPI tasks x 48 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 1.9998 | 1.9998 | 1.9998 | 0.0 | 99.87 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0.0011814 | 0.0011814 | 0.0011814 | 0.0 | 0.06 +Output | 0.00059724 | 0.00059724 | 0.00059724 | 0.0 | 0.03 +Modify | 0.00047352 | 0.00047352 | 0.00047352 | 0.0 | 0.02 +Other | | 0.0003468 | | | 0.02 + +Nlocal: 128.000 ave 128 max 128 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 727.000 ave 727 max 727 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 3712.00 ave 3712 max 3712 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +FullNghs: 7424.00 ave 7424 max 7424 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 7424 +Ave neighs/atom = 58.000000 +Neighbor list builds = 0 +Dangerous builds = 0 + +Total wall time: 0:00:03 diff --git a/examples/mliap/log.04Dec20.mliap.pytorch.Ta06A.g++.4 b/examples/mliap/log.04Dec20.mliap.pytorch.Ta06A.g++.4 new file mode 100644 index 0000000000..7f1bc818d1 --- /dev/null +++ b/examples/mliap/log.04Dec20.mliap.pytorch.Ta06A.g++.4 @@ -0,0 +1,157 @@ +LAMMPS (30 Nov 2020) + using 48 OpenMP thread(s) per MPI task +# Demonstrate MLIAP/PyTorch interface to linear SNAP potential + +# Initialize simulation + +variable nsteps index 100 +variable nrep equal 4 +variable a equal 3.316 +units metal + +# generate the box and atom positions using a BCC lattice + +variable nx equal ${nrep} +variable nx equal 4 +variable ny equal ${nrep} +variable ny equal 4 +variable nz equal ${nrep} +variable nz equal 4 + +boundary p p p + +lattice bcc $a +lattice bcc 3.316 +Lattice spacing in x,y,z = 3.3160000 3.3160000 3.3160000 +region box block 0 ${nx} 0 ${ny} 0 ${nz} +region box block 0 4 0 ${ny} 0 ${nz} +region box block 0 4 0 4 0 ${nz} +region box block 0 4 0 4 0 4 +create_box 1 box +Created orthogonal box = (0.0000000 0.0000000 0.0000000) to (13.264000 13.264000 13.264000) + 1 by 2 by 2 MPI processor grid +create_atoms 1 box +Created 128 atoms + create_atoms CPU = 0.002 seconds + +mass 1 180.88 + +# choose potential + +include Ta06A.mliap.pytorch +# DATE: 2014-09-05 UNITS: metal CONTRIBUTOR: Aidan Thompson athomps@sandia.gov CITATION: Thompson, Swiler, Trott, Foiles and Tucker, arxiv.org, 1409.3880 (2014) + +# Definition of SNAP potential Ta_Cand06A +# Assumes 1 LAMMPS atom type + +variable zblcutinner equal 4 +variable zblcutouter equal 4.8 +variable zblz equal 73 + +# Specify hybrid with SNAP, ZBL + +pair_style hybrid/overlay zbl ${zblcutinner} ${zblcutouter} mliap model mliappy Ta06A.mliap.pytorch.model.pkl descriptor sna Ta06A.mliap.descriptor +pair_style hybrid/overlay zbl 4 ${zblcutouter} mliap model mliappy Ta06A.mliap.pytorch.model.pkl descriptor sna Ta06A.mliap.descriptor +pair_style hybrid/overlay zbl 4 4.8 mliap model mliappy Ta06A.mliap.pytorch.model.pkl descriptor sna Ta06A.mliap.descriptor +Loading python model complete. +Reading potential file Ta06A.mliap.descriptor with DATE: 2014-09-05 +SNAP keyword rcutfac 4.67637 +SNAP keyword twojmax 6 +SNAP keyword nelems 1 +SNAP keyword elems Ta +SNAP keyword radelems 0.5 +SNAP keyword welems 1 +SNAP keyword rfac0 0.99363 +SNAP keyword rmin0 0 +SNAP keyword bzeroflag 0 +pair_coeff 1 1 zbl ${zblz} ${zblz} +pair_coeff 1 1 zbl 73 ${zblz} +pair_coeff 1 1 zbl 73 73 +pair_coeff * * mliap Ta + + +# Setup output + +compute eatom all pe/atom +compute energy all reduce sum c_eatom + +compute satom all stress/atom NULL +compute str all reduce sum c_satom[1] c_satom[2] c_satom[3] +variable press equal (c_str[1]+c_str[2]+c_str[3])/(3*vol) + +thermo_style custom step temp epair c_energy etotal press v_press +thermo 10 +thermo_modify norm yes + +# Set up NVE run + +timestep 0.5e-3 +neighbor 1.0 bin +neigh_modify once no every 1 delay 0 check yes + +# Run MD + +velocity all create 300.0 4928459 loop geom +fix 1 all nve +run ${nsteps} +run 100 +Neighbor list info ... + update every 1 steps, delay 0 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 5.8 + ghost atom cutoff = 5.8 + binsize = 2.9, bins = 5 5 5 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair zbl, perpetual, half/full from (2) + attributes: half, newton on + pair build: halffull/newton + stencil: none + bin: none + (2) pair mliap, perpetual + attributes: full, newton on + pair build: full/bin/atomonly + stencil: full/bin/3d + bin: standard +Per MPI rank memory allocation (min/avg/max) = 159.7 | 159.7 | 159.7 Mbytes +Step Temp E_pair c_energy TotEng Press v_press + 0 300 -11.85157 -11.85157 -11.813095 2717.1661 -2717.1661 + 10 296.01467 -11.851059 -11.851059 -11.813095 2697.4796 -2697.4796 + 20 284.53666 -11.849587 -11.849587 -11.813095 2289.1527 -2289.1527 + 30 266.51577 -11.847275 -11.847275 -11.813095 1851.7131 -1851.7131 + 40 243.05007 -11.844266 -11.844266 -11.813095 1570.684 -1570.684 + 50 215.51032 -11.840734 -11.840734 -11.813094 1468.1899 -1468.1899 + 60 185.48331 -11.836883 -11.836883 -11.813094 1524.8757 -1524.8757 + 70 154.6736 -11.832931 -11.832931 -11.813094 1698.3351 -1698.3351 + 80 124.79303 -11.829099 -11.829099 -11.813094 1947.0715 -1947.0715 + 90 97.448054 -11.825592 -11.825592 -11.813094 2231.9563 -2231.9563 + 100 74.035418 -11.822589 -11.822589 -11.813094 2515.8526 -2515.8526 +Loop time of 0.562802 on 192 procs for 100 steps with 128 atoms + +Performance: 7.676 ns/day, 3.127 hours/ns, 177.682 timesteps/s +99.7% CPU use with 4 MPI tasks x 48 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 0.53583 | 0.54622 | 0.55401 | 0.9 | 97.05 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0.0071442 | 0.01491 | 0.025289 | 5.4 | 2.65 +Output | 0.00092525 | 0.00095771 | 0.0010166 | 0.0 | 0.17 +Modify | 0.00014479 | 0.00015043 | 0.00015893 | 0.0 | 0.03 +Other | | 0.0005624 | | | 0.10 + +Nlocal: 32.0000 ave 32 max 32 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +Nghost: 431.000 ave 431 max 431 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +Neighs: 928.000 ave 928 max 928 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +FullNghs: 1856.00 ave 1856 max 1856 min +Histogram: 4 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 7424 +Ave neighs/atom = 58.000000 +Neighbor list builds = 0 +Dangerous builds = 0 + +Total wall time: 0:00:02 diff --git a/examples/mliap/mliap_pytorch_Ta06A.py b/examples/mliap/mliap_pytorch_Ta06A.py new file mode 100644 index 0000000000..c4387e21a3 --- /dev/null +++ b/examples/mliap/mliap_pytorch_Ta06A.py @@ -0,0 +1,104 @@ +# Demonstrate how to load a model from the python side. +# This is essentially the same as in.mliap.pytorch.Ta06A +# except that python is the driving program, and lammps +# is in library mode. + +before_loading =\ +"""# Demonstrate MLIAP/PyTorch interface to linear SNAP potential + +# Initialize simulation + +variable nsteps index 100 +variable nrep equal 4 +variable a equal 3.316 +units metal + +# generate the box and atom positions using a BCC lattice + +variable nx equal ${nrep} +variable ny equal ${nrep} +variable nz equal ${nrep} + +boundary p p p + +lattice bcc $a +region box block 0 ${nx} 0 ${ny} 0 ${nz} +create_box 1 box +create_atoms 1 box + +mass 1 180.88 + +# choose potential + +# DATE: 2014-09-05 UNITS: metal CONTRIBUTOR: Aidan Thompson athomps@sandia.gov CITATION: Thompson, Swiler, Trott, Foiles and Tucker, arxiv.org, 1409.3880 (2014) + +# Definition of SNAP potential Ta_Cand06A +# Assumes 1 LAMMPS atom type + +variable zblcutinner equal 4 +variable zblcutouter equal 4.8 +variable zblz equal 73 + +# Specify hybrid with SNAP, ZBL + +pair_style hybrid/overlay & +zbl ${zblcutinner} ${zblcutouter} & +mliap model mliappy LATER & +descriptor sna Ta06A.mliap.descriptor +pair_coeff 1 1 zbl ${zblz} ${zblz} +pair_coeff * * mliap Ta +""" +after_loading =\ +""" + +# Setup output + +compute eatom all pe/atom +compute energy all reduce sum c_eatom + +compute satom all stress/atom NULL +compute str all reduce sum c_satom[1] c_satom[2] c_satom[3] +variable press equal (c_str[1]+c_str[2]+c_str[3])/(3*vol) + +thermo_style custom step temp epair c_energy etotal press v_press +thermo 10 +thermo_modify norm yes + +# Set up NVE run + +timestep 0.5e-3 +neighbor 1.0 bin +neigh_modify once no every 1 delay 0 check yes + +# Run MD + +velocity all create 300.0 4928459 loop geom +fix 1 all nve +run ${nsteps} +""" + +import lammps + +lmp = lammps.lammps(cmdargs=['-echo','both']) + +# Before defining the pair style, one must do the following: +import lammps.mliap +lammps.mliap.activate_mliappy(lmp) +# Otherwise, when running lammps in library mode, +# you will get an error: +# "ERROR: Loading MLIAPPY coupling module failure." + +# Setup the simulation and declare an empty model +# by specifying model filename as "LATER" +lmp.commands_string(before_loading) + +# Define the model however you like. In this example +# we load it from disk: +import torch +model = torch.load('Ta06A.mliap.pytorch.model.pt') + +# Connect the PyTorch model to the mliap pair style. +lammps.mliap.load_model(model) + +# run the simulation with the mliap pair style +lmp.commands_string(after_loading) diff --git a/examples/mliap/relu1hidden.mliap.pytorch b/examples/mliap/relu1hidden.mliap.pytorch new file mode 100644 index 0000000000..32ac4c85a3 --- /dev/null +++ b/examples/mliap/relu1hidden.mliap.pytorch @@ -0,0 +1,18 @@ +# DATE: 2014-09-05 UNITS: metal CONTRIBUTOR: Aidan Thompson athomps@sandia.gov CITATION: Thompson, Swiler, Trott, Foiles and Tucker, arxiv.org, 1409.3880 (2014) + +# Definition of SNAP potential Ta_Cand06A +# Assumes 1 LAMMPS atom type + +variable zblcutinner equal 4 +variable zblcutouter equal 4.8 +variable zblz equal 73 + +# Specify hybrid with SNAP, ZBL + +pair_style hybrid/overlay & +zbl ${zblcutinner} ${zblcutouter} & +mliap model mliappy relu1hidden.mliap.pytorch.model.pt & +descriptor sna Ta06A.mliap.descriptor +pair_coeff 1 1 zbl ${zblz} ${zblz} +pair_coeff * * mliap Ta + diff --git a/examples/mliap/relu1hidden.mliap.pytorch.model.pt b/examples/mliap/relu1hidden.mliap.pytorch.model.pt new file mode 100644 index 0000000000..ecc04341a7 Binary files /dev/null and b/examples/mliap/relu1hidden.mliap.pytorch.model.pt differ diff --git a/lib/kim/Install.py b/lib/kim/Install.py index 3ebcb8e237..ae4b356ba9 100644 --- a/lib/kim/Install.py +++ b/lib/kim/Install.py @@ -18,13 +18,14 @@ parser = ArgumentParser(prog='Install.py', # settings thisdir = fullpath('.') -version = "2.2.0" +version = "2.2.1" # known checksums for different KIM-API versions. used to validate the download. checksums = { \ '2.1.2' : '6ac52e14ef52967fc7858220b208cba5', \ '2.1.3' : '6ee829a1bbba5f8b9874c88c4c4ebff8', \ '2.2.0' : 'e7f944e1593cffd7444679a660607f6c', \ + '2.2.1' : 'ae1ddda2ef7017ea07934e519d023dca', \ } diff --git a/lib/plumed/Install.py b/lib/plumed/Install.py index 33bb40c9d9..c11d5bfee9 100644 --- a/lib/plumed/Install.py +++ b/lib/plumed/Install.py @@ -17,7 +17,7 @@ parser = ArgumentParser(prog='Install.py', # settings -version = "2.6.1" +version = "2.7.0" mode = "static" # help message @@ -49,6 +49,7 @@ checksums = { \ '2.5.4' : 'f31b7d16a4be2e30aa7d5c19c3d37853', \ '2.6.0' : '204d2edae58d9b10ba3ad460cad64191', \ '2.6.1' : '89a9a450fc6025299fe16af235957163', \ + '2.7.0' : '95f29dd0c067577f11972ff90dfc7d12', \ } # parse and process arguments diff --git a/lib/python/Makefile.lammps b/lib/python/Makefile.lammps index 4289674e99..e4afa70456 100644 --- a/lib/python/Makefile.lammps +++ b/lib/python/Makefile.lammps @@ -2,6 +2,6 @@ # See the README file for more explanation python_SYSINC = $(shell which python-config > /dev/null 2>&1 && python-config --includes || :) -python_SYSLIB = $(shell which python-config > /dev/null 2>&1 && python-config --ldflags || :) +python_SYSLIB = $(shell which python-config > /dev/null 2>&1 && python-config --ldflags --embed > /dev/null 2>&1 && python-config --ldflags --embed || (which python-config > /dev/null 2>&1 && python-config --ldflags || :) ) python_SYSPATH = PYTHON=python diff --git a/lib/python/Makefile.lammps.python3 b/lib/python/Makefile.lammps.python3 index 5c43b45ff6..d37e822327 100644 --- a/lib/python/Makefile.lammps.python3 +++ b/lib/python/Makefile.lammps.python3 @@ -2,6 +2,6 @@ # See the README file for more explanation python_SYSINC = $(shell which python3-config > /dev/null 2>&1 && python3-config --includes || (which python-config > /dev/null 2>&1 && python-config --includes || :)) -python_SYSLIB = $(shell which python3-config > /dev/null 2>&1 && python3-config --ldflags || (which python-config > /dev/null 2>&1 && python-config --ldflags || :)) +python_SYSLIB = $(shell which python3-config > /dev/null 2>&1 && python3-config --ldflags --embed > /dev/null 2>&1 && python3-config --ldflags --embed || (which python3-config > /dev/null 2>&1 && python3-config --ldflags || (which python-config > /dev/null 2>&1 && python-config --ldflags || :) ) ) python_SYSPATH = PYTHON=$(shell which python3 > /dev/null 2>&1 && echo python3 || echo python) diff --git a/lib/python/Makefile.mliap_python b/lib/python/Makefile.mliap_python new file mode 100644 index 0000000000..00483a4a6a --- /dev/null +++ b/lib/python/Makefile.mliap_python @@ -0,0 +1,3 @@ + +../mliap_model_python_couple.cpp: ../mliap_model_python_couple.pyx + cythonize -3 ../mliap_model_python_couple.cpp diff --git a/python/install.py b/python/install.py index 7f7062103a..6765c33925 100644 --- a/python/install.py +++ b/python/install.py @@ -1,42 +1,42 @@ #!/usr/bin/env python """ -Installer script to install the LAMMPS python module and the corresponding +Installer script to install the LAMMPS python package and the corresponding shared library into either the system-wide site-packages tree, or - failing that - into the corresponding user tree. Called from the 'install-python' build target in the conventional and CMake based build systems """ -# copy LAMMPS shared library and lammps.py to system dirs +# copy LAMMPS shared library and lammps package to system dirs from __future__ import print_function import sys,os,shutil from argparse import ArgumentParser parser = ArgumentParser(prog='install.py', - description='LAMMPS python module installer script') + description='LAMMPS python package installer script') -parser.add_argument("-m", "--module", required=True, - help="path to the source of the LAMMPS Python module") +parser.add_argument("-p", "--package", required=True, + help="path to the LAMMPS Python package") parser.add_argument("-l", "--lib", required=True, help="path to the compiled LAMMPS shared library") parser.add_argument("-v", "--version", required=True, help="path to the LAMMPS version.h header file") parser.add_argument("-d","--dir", - help="Legacy custom installation folder selection for module and library") + help="Legacy custom installation folder selection for package and library") args = parser.parse_args() # validate arguments and make paths absolute -if args.module: - if not os.path.exists(args.module): - print( "ERROR: LAMMPS module file %s does not exist" % args.module) +if args.package: + if not os.path.exists(args.package): + print( "ERROR: LAMMPS package %s does not exist" % args.package) parser.print_help() sys.exit(1) else: - args.module = os.path.abspath(args.module) + args.package = os.path.abspath(args.package) if args.lib: if not os.path.exists(args.lib): @@ -66,9 +66,9 @@ if args.dir: # without any special processing or additional steps to that folder if args.dir: - print("Copying LAMMPS Python module to custom folder %s" % args.dir) + print("Copying LAMMPS Python package to custom folder %s" % args.dir) try: - shutil.copyfile(args.module, os.path.join(args.dir,'lammps.py')) + shutil.copytree(args.package, os.path.join(args.dir,'lammps')) except shutil.Error: pass # fail silently @@ -81,32 +81,40 @@ if args.dir: sys.exit() # extract version string from header -fp = open(args.version,'r') -txt=fp.read().split('"')[1].split() -verstr=txt[0]+txt[1]+txt[2] -fp.close() +def get_lammps_version(header): + with open(header, 'r') as f: + line = f.readline() + start_pos = line.find('"')+1 + end_pos = line.find('"', start_pos) + return "".join(line[start_pos:end_pos].split()) -print("Installing LAMMPS Python module version %s into site-packages folder" % verstr) +verstr = get_lammps_version(args.version) -# we need to switch to the folder of the python module -os.chdir(os.path.dirname(args.module)) +print("Installing LAMMPS Python package version %s into site-packages folder" % verstr) + +# we need to switch to the folder of the python package +os.chdir(os.path.dirname(args.package)) from distutils.core import setup from distutils.sysconfig import get_python_lib import site -tryuser=False +#Arguments common to global or user install -- everything but data_files +setup_kwargs= dict(name="lammps", + version=verstr, + author="Steve Plimpton", + author_email="sjplimp@sandia.gov", + url="https://lammps.sandia.gov", + description="LAMMPS Molecular Dynamics Python package", + license="GPL", + packages=["lammps","lammps.mliap"], + ) + +tryuser=False try: sys.argv = ["setup.py","install"] # as if had run "python setup.py install" - setup(name = "lammps", - version = verstr, - author = "Steve Plimpton", - author_email = "sjplimp@sandia.gov", - url = "https://lammps.sandia.gov", - description = "LAMMPS Molecular Dynamics Python module", - license = "GPL", - py_modules = ["lammps"], - data_files = [(get_python_lib(), [args.lib])]) + setup_kwargs['data_files']=[(os.path.join(get_python_lib(), 'lammps'), [args.lib])] + setup(**setup_kwargs) except: tryuser=True print ("Installation into global site-packages folder failed.\nTrying user folder %s now." % site.USER_SITE) @@ -114,14 +122,7 @@ except: if tryuser: try: sys.argv = ["setup.py","install","--user"] # as if had run "python setup.py install --user" - setup(name = "lammps", - version = verstr, - author = "Steve Plimpton", - author_email = "sjplimp@sandia.gov", - url = "https://lammps.sandia.gov", - description = "LAMMPS Molecular Dynamics Python module", - license = "GPL", - py_modules = ["lammps"], - data_files = [(site.USER_SITE, [args.lib])]) + setup_kwargs['data_files']=[(os.path.join(site.USER_SITE, 'lammps'), [args.lib])] + setup(**setup_kwargs) except: print("Installation into user site package folder failed.") diff --git a/python/lammps/__init__.py b/python/lammps/__init__.py new file mode 100644 index 0000000000..b1c8306617 --- /dev/null +++ b/python/lammps/__init__.py @@ -0,0 +1,4 @@ +from .constants import * +from .core import * +from .data import * +from .pylammps import * diff --git a/python/lammps/constants.py b/python/lammps/constants.py new file mode 100644 index 0000000000..e5504691fe --- /dev/null +++ b/python/lammps/constants.py @@ -0,0 +1,49 @@ +# ---------------------------------------------------------------------- +# LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator +# http://lammps.sandia.gov, Sandia National Laboratories +# Steve Plimpton, sjplimp@sandia.gov +# +# 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. +# ------------------------------------------------------------------------- + +from ctypes import c_int, c_int32, c_int64 + +# various symbolic constants to be used +# in certain calls to select data formats +LAMMPS_AUTODETECT = None +LAMMPS_INT = 0 +LAMMPS_INT_2D = 1 +LAMMPS_DOUBLE = 2 +LAMMPS_DOUBLE_2D = 3 +LAMMPS_INT64 = 4 +LAMMPS_INT64_2D = 5 +LAMMPS_STRING = 6 + +# these must be kept in sync with the enums in library.h +LMP_STYLE_GLOBAL = 0 +LMP_STYLE_ATOM = 1 +LMP_STYLE_LOCAL = 2 + +LMP_TYPE_SCALAR = 0 +LMP_TYPE_VECTOR = 1 +LMP_TYPE_ARRAY = 2 +LMP_SIZE_VECTOR = 3 +LMP_SIZE_ROWS = 4 +LMP_SIZE_COLS = 5 + +LMP_VAR_EQUAL = 0 +LMP_VAR_ATOM = 1 + +# ------------------------------------------------------------------------- + +def get_ctypes_int(size): + if size == 4: + return c_int32 + elif size == 8: + return c_int64 + return c_int diff --git a/python/lammps.py b/python/lammps/core.py similarity index 59% rename from python/lammps.py rename to python/lammps/core.py index b74e111dc6..c0cbaac533 100644 --- a/python/lammps.py +++ b/python/lammps/core.py @@ -10,62 +10,23 @@ # # See the README file in the top-level LAMMPS directory. # ------------------------------------------------------------------------- -# Python wrappers for the LAMMPS library via ctypes +# Python wrapper for the LAMMPS library via ctypes # for python2/3 compatibility from __future__ import print_function -# imports for simple LAMMPS python wrapper module "lammps" - -import sys,traceback,types +import os +import sys +import traceback +import types import warnings from ctypes import * from os.path import dirname,abspath,join from inspect import getsourcefile -# imports for advanced LAMMPS python wrapper modules "PyLammps" and "IPyLammps" - -from collections import namedtuple -import os -import select -import re -import sys - -# various symbolic constants to be used -# in certain calls to select data formats -LAMMPS_AUTODETECT = None -LAMMPS_INT = 0 -LAMMPS_INT_2D = 1 -LAMMPS_DOUBLE = 2 -LAMMPS_DOUBLE_2D = 3 -LAMMPS_INT64 = 4 -LAMMPS_INT64_2D = 5 -LAMMPS_STRING = 6 - -# these must be kept in sync with the enums in library.h -LMP_STYLE_GLOBAL = 0 -LMP_STYLE_ATOM = 1 -LMP_STYLE_LOCAL = 2 - -LMP_TYPE_SCALAR = 0 -LMP_TYPE_VECTOR = 1 -LMP_TYPE_ARRAY = 2 -LMP_SIZE_VECTOR = 3 -LMP_SIZE_ROWS = 4 -LMP_SIZE_COLS = 5 - -LMP_VAR_EQUAL = 0 -LMP_VAR_ATOM = 1 - -# ------------------------------------------------------------------------- - -def get_ctypes_int(size): - if size == 4: - return c_int32 - elif size == 8: - return c_int64 - return c_int +from .constants import * +from .data import * # ------------------------------------------------------------------------- @@ -78,94 +39,6 @@ class MPIAbortException(Exception): # ------------------------------------------------------------------------- -class NeighList: - """This is a wrapper class that exposes the contents of a neighbor list. - - It can be used like a regular Python list. Each element is a tuple of: - - * the atom local index - * its number of neighbors - * and a pointer to an c_int array containing local atom indices of its - neighbors - - Internally it uses the lower-level LAMMPS C-library interface. - - :param lmp: reference to instance of :py:class:`lammps` - :type lmp: lammps - :param idx: neighbor list index - :type idx: int - """ - def __init__(self, lmp, idx): - self.lmp = lmp - self.idx = idx - - def __str__(self): - return "Neighbor List ({} atoms)".format(self.size) - - def __repr__(self): - return self.__str__() - - @property - def size(self): - """ - :return: number of elements in neighbor list - """ - return self.lmp.get_neighlist_size(self.idx) - - def get(self, element): - """ - :return: tuple with atom local index, numpy array of neighbor local atom indices - :rtype: (int, int, ctypes.POINTER(c_int)) - """ - iatom, numneigh, neighbors = self.lmp.get_neighlist_element_neighbors(self.idx, element) - return iatom, numneigh, neighbors - - # the methods below implement the iterator interface, so NeighList can be used like a regular Python list - - def __getitem__(self, element): - return self.get(element) - - def __len__(self): - return self.size - - def __iter__(self): - inum = self.size - - for ii in range(inum): - yield self.get(ii) - -# ------------------------------------------------------------------------- - -class NumPyNeighList(NeighList): - """This is a wrapper class that exposes the contents of a neighbor list. - - It can be used like a regular Python list. Each element is a tuple of: - - * the atom local index - * a NumPy array containing the local atom indices of its neighbors - - Internally it uses the lower-level LAMMPS C-library interface. - - :param lmp: reference to instance of :py:class:`lammps` - :type lmp: lammps - :param idx: neighbor list index - :type idx: int - """ - def __init__(self, lmp, idx): - super(NumPyNeighList, self).__init__(lmp, idx) - - def get(self, element): - """ - :return: tuple with atom local index, numpy array of neighbor local atom indices - :rtype: (int, numpy.array) - """ - iatom, neighbors = self.lmp.numpy.get_neighlist_element_neighbors(self.idx, element) - return iatom, neighbors - - -# ------------------------------------------------------------------------- -# ------------------------------------------------------------------------- - class lammps(object): """Create an instance of the LAMMPS Python class. @@ -204,7 +77,7 @@ class lammps(object): modpath = dirname(abspath(getsourcefile(lambda:0))) # for windows installers the shared library is in a different folder - winpath = abspath(os.path.join(modpath,'..','bin')) + winpath = abspath(os.path.join(modpath,'..','..','bin')) self.lib = None self.lmp = None @@ -222,7 +95,7 @@ class lammps(object): # load liblammps.so unless name is given # if name = "g++", load liblammps_g++.so # try loading the LAMMPS shared object from the location - # of lammps.py with an absolute path, + # of the lammps package with an absolute path, # so that LD_LIBRARY_PATH does not need to be set for regular install # fall back to loading with a relative path, # typically requires LD_LIBRARY_PATH to be set appropriately @@ -446,7 +319,7 @@ class lammps(object): narg = 0 cargs = None if cmdargs: - cmdargs.insert(0,"lammps.py") + cmdargs.insert(0,"lammps") narg = len(cmdargs) for i in range(narg): if type(cmdargs[i]) is str: @@ -468,7 +341,7 @@ class lammps(object): self.comm = self.MPI.COMM_WORLD self.opened = 1 if cmdargs: - cmdargs.insert(0,"lammps.py") + cmdargs.insert(0,"lammps") narg = len(cmdargs) for i in range(narg): if type(cmdargs[i]) is str: @@ -528,6 +401,7 @@ class lammps(object): :rtype: numpy_wrapper """ if not self._numpy: + from .numpy import numpy_wrapper self._numpy = numpy_wrapper(self) return self._numpy @@ -1796,1131 +1670,3 @@ class lammps(object): computeid = computeid.encode() idx = self.lib.lammps_find_compute_neighlist(self.lmp, computeid, request) return idx - -# ------------------------------------------------------------------------- - -class numpy_wrapper: - """lammps API NumPy Wrapper - - This is a wrapper class that provides additional methods on top of an - existing :py:class:`lammps` instance. The methods transform raw ctypes - pointers into NumPy arrays, which give direct access to the - original data while protecting against out-of-bounds accesses. - - There is no need to explicitly instantiate this class. Each instance - of :py:class:`lammps` has a :py:attr:`numpy ` property - that returns an instance. - - :param lmp: instance of the :py:class:`lammps` class - :type lmp: lammps - """ - def __init__(self, lmp): - self.lmp = lmp - - # ------------------------------------------------------------------------- - - def _ctype_to_numpy_int(self, ctype_int): - import numpy as np - if ctype_int == c_int32: - return np.int32 - elif ctype_int == c_int64: - return np.int64 - return np.intc - - # ------------------------------------------------------------------------- - - def extract_atom(self, name, dtype=LAMMPS_AUTODETECT, nelem=LAMMPS_AUTODETECT, dim=LAMMPS_AUTODETECT): - """Retrieve per-atom properties from LAMMPS as NumPy arrays - - This is a wrapper around the :py:meth:`lammps.extract_atom()` method. - It behaves the same as the original method, but returns NumPy arrays - instead of ``ctypes`` pointers. - - .. note:: - - While the returned arrays of per-atom data are dimensioned - for the range [0:nmax] - as is the underlying storage - - the data is usually only valid for the range of [0:nlocal], - unless the property of interest is also updated for ghost - atoms. In some cases, this depends on a LAMMPS setting, see - for example :doc:`comm_modify vel yes `. - - :param name: name of the property - :type name: string - :param dtype: type of the returned data (see :ref:`py_datatype_constants`) - :type dtype: int, optional - :param nelem: number of elements in array - :type nelem: int, optional - :param dim: dimension of each element - :type dim: int, optional - :return: requested data as NumPy array with direct access to C data or None - :rtype: numpy.array or NoneType - """ - if dtype == LAMMPS_AUTODETECT: - dtype = self.lmp.extract_atom_datatype(name) - - if nelem == LAMMPS_AUTODETECT: - if name == "mass": - nelem = self.lmp.extract_global("ntypes") + 1 - else: - nelem = self.lmp.extract_global("nlocal") - if dim == LAMMPS_AUTODETECT: - if dtype in (LAMMPS_INT_2D, LAMMPS_DOUBLE_2D, LAMMPS_INT64_2D): - # TODO add other fields - if name in ("x", "v", "f", "angmom", "torque", "csforce", "vforce"): - dim = 3 - else: - dim = 2 - else: - dim = 1 - - raw_ptr = self.lmp.extract_atom(name, dtype) - - if dtype in (LAMMPS_DOUBLE, LAMMPS_DOUBLE_2D): - return self.darray(raw_ptr, nelem, dim) - elif dtype in (LAMMPS_INT, LAMMPS_INT_2D): - return self.iarray(c_int32, raw_ptr, nelem, dim) - elif dtype in (LAMMPS_INT64, LAMMPS_INT64_2D): - return self.iarray(c_int64, raw_ptr, nelem, dim) - return raw_ptr - - # ------------------------------------------------------------------------- - - def extract_atom_iarray(self, name, nelem, dim=1): - warnings.warn("deprecated, use extract_atom instead", DeprecationWarning) - - if name in ['id', 'molecule']: - c_int_type = self.lmp.c_tagint - elif name in ['image']: - c_int_type = self.lmp.c_imageint - else: - c_int_type = c_int - - if dim == 1: - raw_ptr = self.lmp.extract_atom(name, LAMMPS_INT) - else: - raw_ptr = self.lmp.extract_atom(name, LAMMPS_INT_2D) - - return self.iarray(c_int_type, raw_ptr, nelem, dim) - - # ------------------------------------------------------------------------- - - def extract_atom_darray(self, name, nelem, dim=1): - warnings.warn("deprecated, use extract_atom instead", DeprecationWarning) - - if dim == 1: - raw_ptr = self.lmp.extract_atom(name, LAMMPS_DOUBLE) - else: - raw_ptr = self.lmp.extract_atom(name, LAMMPS_DOUBLE_2D) - - return self.darray(raw_ptr, nelem, dim) - - # ------------------------------------------------------------------------- - - def extract_compute(self, cid, style, type): - """Retrieve data from a LAMMPS compute - - This is a wrapper around the - :py:meth:`lammps.extract_compute() ` method. - It behaves the same as the original method, but returns NumPy arrays - instead of ``ctypes`` pointers. - - :param id: compute ID - :type id: string - :param style: style of the data retrieve (global, atom, or local), see :ref:`py_style_constants` - :type style: int - :param type: type of the returned data (scalar, vector, or array), see :ref:`py_type_constants` - :type type: int - :return: requested data either as float, as NumPy array with direct access to C data, or None - :rtype: float, numpy.array, or NoneType - """ - value = self.lmp.extract_compute(cid, style, type) - - if style in (LMP_STYLE_GLOBAL, LMP_STYLE_LOCAL): - if type == LMP_TYPE_VECTOR: - nrows = self.lmp.extract_compute(cid, style, LMP_SIZE_VECTOR) - return self.darray(value, nrows) - elif type == LMP_TYPE_ARRAY: - nrows = self.lmp.extract_compute(cid, style, LMP_SIZE_ROWS) - ncols = self.lmp.extract_compute(cid, style, LMP_SIZE_COLS) - return self.darray(value, nrows, ncols) - elif style == LMP_STYLE_ATOM: - if type == LMP_TYPE_VECTOR: - nlocal = self.lmp.extract_global("nlocal") - return self.darray(value, nlocal) - elif type == LMP_TYPE_ARRAY: - nlocal = self.lmp.extract_global("nlocal") - ncols = self.lmp.extract_compute(cid, style, LMP_SIZE_COLS) - return self.darray(value, nlocal, ncols) - return value - - # ------------------------------------------------------------------------- - - def extract_fix(self, fid, style, type, nrow=0, ncol=0): - """Retrieve data from a LAMMPS fix - - This is a wrapper around the :py:meth:`lammps.extract_fix() ` method. - It behaves the same as the original method, but returns NumPy arrays - instead of ``ctypes`` pointers. - - :param id: fix ID - :type id: string - :param style: style of the data retrieve (global, atom, or local), see :ref:`py_style_constants` - :type style: int - :param type: type or size of the returned data (scalar, vector, or array), see :ref:`py_type_constants` - :type type: int - :param nrow: index of global vector element or row index of global array element - :type nrow: int - :param ncol: column index of global array element - :type ncol: int - :return: requested data - :rtype: integer or double value, pointer to 1d or 2d double array or None - - """ - value = self.lmp.extract_fix(fid, style, type, nrow, ncol) - if style == LMP_STYLE_ATOM: - if type == LMP_TYPE_VECTOR: - nlocal = self.lmp.extract_global("nlocal") - return self.darray(value, nlocal) - elif type == LMP_TYPE_ARRAY: - nlocal = self.lmp.extract_global("nlocal") - ncols = self.lmp.extract_fix(fid, style, LMP_SIZE_COLS, 0, 0) - return self.darray(value, nlocal, ncols) - elif style == LMP_STYLE_LOCAL: - if type == LMP_TYPE_VECTOR: - nrows = self.lmp.extract_fix(fid, style, LMP_SIZE_ROWS, 0, 0) - return self.darray(value, nrows) - elif type == LMP_TYPE_ARRAY: - nrows = self.lmp.extract_fix(fid, style, LMP_SIZE_ROWS, 0, 0) - ncols = self.lmp.extract_fix(fid, style, LMP_SIZE_COLS, 0, 0) - return self.darray(value, nrows, ncols) - return value - - # ------------------------------------------------------------------------- - - def extract_variable(self, name, group=None, vartype=LMP_VAR_EQUAL): - """ Evaluate a LAMMPS variable and return its data - - This function is a wrapper around the function - :py:meth:`lammps.extract_variable() ` - method. It behaves the same as the original method, but returns NumPy arrays - instead of ``ctypes`` pointers. - - :param name: name of the variable to execute - :type name: string - :param group: name of group for atom-style variable (ignored for equal-style variables) - :type group: string - :param vartype: type of variable, see :ref:`py_vartype_constants` - :type vartype: int - :return: the requested data or None - :rtype: c_double, numpy.array, or NoneType - """ - import numpy as np - value = self.lmp.extract_variable(name, group, vartype) - if vartype == LMP_VAR_ATOM: - return np.ctypeslib.as_array(value) - return value - - # ------------------------------------------------------------------------- - - def get_neighlist(self, idx): - """Returns an instance of :class:`NumPyNeighList` which wraps access to the neighbor list with the given index - - :param idx: index of neighbor list - :type idx: int - :return: an instance of :class:`NumPyNeighList` wrapping access to neighbor list data - :rtype: NumPyNeighList - """ - if idx < 0: - return None - return NumPyNeighList(self.lmp, idx) - - # ------------------------------------------------------------------------- - - def get_neighlist_element_neighbors(self, idx, element): - """Return data of neighbor list entry - - This function is a wrapper around the function - :py:meth:`lammps.get_neighlist_element_neighbors() ` - method. It behaves the same as the original method, but returns a NumPy array containing the neighbors - instead of a ``ctypes`` pointer. - - :param element: neighbor list index - :type element: int - :param element: neighbor list element index - :type element: int - :return: tuple with atom local index and numpy array of neighbor local atom indices - :rtype: (int, numpy.array) - """ - iatom, numneigh, c_neighbors = self.lmp.get_neighlist_element_neighbors(idx, element) - neighbors = self.iarray(c_int, c_neighbors, numneigh, 1) - return iatom, neighbors - - # ------------------------------------------------------------------------- - - def iarray(self, c_int_type, raw_ptr, nelem, dim=1): - import numpy as np - np_int_type = self._ctype_to_numpy_int(c_int_type) - - if dim == 1: - ptr = cast(raw_ptr, POINTER(c_int_type * nelem)) - else: - ptr = cast(raw_ptr[0], POINTER(c_int_type * nelem * dim)) - - a = np.frombuffer(ptr.contents, dtype=np_int_type) - a.shape = (nelem, dim) - return a - - # ------------------------------------------------------------------------- - - def darray(self, raw_ptr, nelem, dim=1): - import numpy as np - if dim == 1: - ptr = cast(raw_ptr, POINTER(c_double * nelem)) - else: - ptr = cast(raw_ptr[0], POINTER(c_double * nelem * dim)) - - a = np.frombuffer(ptr.contents) - a.shape = (nelem, dim) - return a - - -# ------------------------------------------------------------------------- -# ------------------------------------------------------------------------- -# ------------------------------------------------------------------------- - -################################################################################ -# Alternative Python Wrapper -# Written by Richard Berger -################################################################################ - -class OutputCapture(object): - """ Utility class to capture LAMMPS library output """ - - def __init__(self): - self.stdout_pipe_read, self.stdout_pipe_write = os.pipe() - self.stdout_fd = 1 - - def __enter__(self): - self.stdout = os.dup(self.stdout_fd) - os.dup2(self.stdout_pipe_write, self.stdout_fd) - return self - - def __exit__(self, type, value, tracebac): - os.dup2(self.stdout, self.stdout_fd) - os.close(self.stdout) - os.close(self.stdout_pipe_read) - os.close(self.stdout_pipe_write) - - # check if we have more to read from the pipe - def more_data(self, pipe): - r, _, _ = select.select([pipe], [], [], 0) - return bool(r) - - # read the whole pipe - def read_pipe(self, pipe): - out = "" - while self.more_data(pipe): - out += os.read(pipe, 1024).decode() - return out - - @property - def output(self): - return self.read_pipe(self.stdout_pipe_read) - -# ------------------------------------------------------------------------- - -class Variable(object): - def __init__(self, pylammps_instance, name, style, definition): - self._pylmp = pylammps_instance - self.name = name - self.style = style - self.definition = definition.split() - - @property - def value(self): - if self.style == 'atom': - return list(self._pylmp.lmp.extract_variable(self.name, "all", 1)) - else: - value = self._pylmp.lmp_print('"${%s}"' % self.name).strip() - try: - return float(value) - except ValueError: - return value - -# ------------------------------------------------------------------------- - -class AtomList(object): - """ - A dynamic list of atoms that returns either an :py:class:`Atom` or - :py:class:`Atom2D` instance for each atom. Instances are only allocated - when accessed. - - :ivar natoms: total number of atoms - :ivar dimensions: number of dimensions in system - """ - def __init__(self, pylammps_instance): - self._pylmp = pylammps_instance - self.natoms = self._pylmp.system.natoms - self.dimensions = self._pylmp.system.dimensions - self._loaded = {} - - def __getitem__(self, index): - """ - Return Atom with given local index - - :param index: Local index of atom - :type index: int - :rtype: Atom or Atom2D - """ - if index not in self._loaded: - if self.dimensions == 2: - atom = Atom2D(self._pylmp, index + 1) - else: - atom = Atom(self._pylmp, index + 1) - self._loaded[index] = atom - return self._loaded[index] - - def __len__(self): - return self.natoms - - -# ------------------------------------------------------------------------- - -class Atom(object): - """ - A wrapper class then represents a single atom inside of LAMMPS - - It provides access to properties of the atom and allows you to change some of them. - """ - def __init__(self, pylammps_instance, index): - self._pylmp = pylammps_instance - self.index = index - - @property - def id(self): - """ - Return the atom ID - - :type: int - """ - return int(self._pylmp.eval("id[%d]" % self.index)) - - @property - def type(self): - """ - Return the atom type - - :type: int - """ - return int(self._pylmp.eval("type[%d]" % self.index)) - - @property - def mol(self): - """ - Return the atom molecule index - - :type: int - """ - return self._pylmp.eval("mol[%d]" % self.index) - - @property - def mass(self): - """ - Return the atom mass - - :type: float - """ - return self._pylmp.eval("mass[%d]" % self.index) - - @property - def position(self): - """ - :getter: Return position of atom - :setter: Set position of atom - :type: tuple (float, float, float) - """ - return (self._pylmp.eval("x[%d]" % self.index), - self._pylmp.eval("y[%d]" % self.index), - self._pylmp.eval("z[%d]" % self.index)) - - @position.setter - def position(self, value): - """ - :getter: Return velocity of atom - :setter: Set velocity of atom - :type: tuple (float, float, float) - """ - self._pylmp.set("atom", self.index, "x", value[0]) - self._pylmp.set("atom", self.index, "y", value[1]) - self._pylmp.set("atom", self.index, "z", value[2]) - - @property - def velocity(self): - return (self._pylmp.eval("vx[%d]" % self.index), - self._pylmp.eval("vy[%d]" % self.index), - self._pylmp.eval("vz[%d]" % self.index)) - - @velocity.setter - def velocity(self, value): - self._pylmp.set("atom", self.index, "vx", value[0]) - self._pylmp.set("atom", self.index, "vy", value[1]) - self._pylmp.set("atom", self.index, "vz", value[2]) - - @property - def force(self): - """ - Return the total force acting on the atom - - :type: tuple (float, float, float) - """ - return (self._pylmp.eval("fx[%d]" % self.index), - self._pylmp.eval("fy[%d]" % self.index), - self._pylmp.eval("fz[%d]" % self.index)) - - @property - def charge(self): - """ - Return the atom charge - - :type: float - """ - return self._pylmp.eval("q[%d]" % self.index) - -# ------------------------------------------------------------------------- - -class Atom2D(Atom): - """ - A wrapper class then represents a single 2D atom inside of LAMMPS - - Inherits all properties from the :py:class:`Atom` class, but returns 2D versions - of position, velocity, and force. - - It provides access to properties of the atom and allows you to change some of them. - """ - def __init__(self, pylammps_instance, index): - super(Atom2D, self).__init__(pylammps_instance, index) - - @property - def position(self): - """ - :getter: Return position of atom - :setter: Set position of atom - :type: tuple (float, float) - """ - return (self._pylmp.eval("x[%d]" % self.index), - self._pylmp.eval("y[%d]" % self.index)) - - @position.setter - def position(self, value): - self._pylmp.set("atom", self.index, "x", value[0]) - self._pylmp.set("atom", self.index, "y", value[1]) - - @property - def velocity(self): - """ - :getter: Return velocity of atom - :setter: Set velocity of atom - :type: tuple (float, float) - """ - return (self._pylmp.eval("vx[%d]" % self.index), - self._pylmp.eval("vy[%d]" % self.index)) - - @velocity.setter - def velocity(self, value): - self._pylmp.set("atom", self.index, "vx", value[0]) - self._pylmp.set("atom", self.index, "vy", value[1]) - - @property - def force(self): - """ - Return the total force acting on the atom - - :type: tuple (float, float) - """ - return (self._pylmp.eval("fx[%d]" % self.index), - self._pylmp.eval("fy[%d]" % self.index)) - -# ------------------------------------------------------------------------- - -class variable_set: - def __init__(self, name, variable_dict): - self._name = name - array_pattern = re.compile(r"(?P.+)\[(?P[0-9]+)\]") - - for key, value in variable_dict.items(): - m = array_pattern.match(key) - if m: - g = m.groupdict() - varname = g['arr'] - idx = int(g['index']) - if varname not in self.__dict__: - self.__dict__[varname] = {} - self.__dict__[varname][idx] = value - else: - self.__dict__[key] = value - - def __str__(self): - return "{}({})".format(self._name, ','.join(["{}={}".format(k, self.__dict__[k]) for k in self.__dict__.keys() if not k.startswith('_')])) - - def __repr__(self): - return self.__str__() - -# ------------------------------------------------------------------------- - -def get_thermo_data(output): - """ traverse output of runs and extract thermo data columns """ - if isinstance(output, str): - lines = output.splitlines() - else: - lines = output - - runs = [] - columns = [] - in_run = False - current_run = {} - - for line in lines: - if line.startswith("Per MPI rank memory allocation"): - in_run = True - elif in_run and len(columns) == 0: - # first line after memory usage are column names - columns = line.split() - - current_run = {} - - for col in columns: - current_run[col] = [] - - elif line.startswith("Loop time of "): - in_run = False - columns = None - thermo_data = variable_set('ThermoData', current_run) - r = {'thermo' : thermo_data } - runs.append(namedtuple('Run', list(r.keys()))(*list(r.values()))) - elif in_run and len(columns) > 0: - items = line.split() - # Convert thermo output and store it. - # It must have the same number of columns and - # all of them must be convertible to floats. - # Otherwise we ignore the line - if len(items) == len(columns): - try: - values = [float(x) for x in items] - for i, col in enumerate(columns): - current_run[col].append(values[i]) - except ValueError: - pass - - return runs - -# ------------------------------------------------------------------------- -# ------------------------------------------------------------------------- - -class PyLammps(object): - """ - This is a Python wrapper class around the lower-level - :py:class:`lammps` class, exposing a more Python-like, - object-oriented interface for prototyping system inside of IPython and - Jupyter notebooks. - - It either creates its own instance of :py:class:`lammps` or can be - initialized with an existing instance. The arguments are the same of the - lower-level interface. The original interface can still be accessed via - :py:attr:`PyLammps.lmp`. - - :param name: "machine" name of the shared LAMMPS library ("mpi" loads ``liblammps_mpi.so``, "" loads ``liblammps.so``) - :type name: string - :param cmdargs: list of command line arguments to be passed to the :cpp:func:`lammps_open` function. The executable name is automatically added. - :type cmdargs: list - :param ptr: pointer to a LAMMPS C++ class instance when called from an embedded Python interpreter. None means load symbols from shared library. - :type ptr: pointer - :param comm: MPI communicator (as provided by `mpi4py `_). ``None`` means use ``MPI_COMM_WORLD`` implicitly. - :type comm: MPI_Comm - - :ivar lmp: instance of original LAMMPS Python interface - :vartype lmp: :py:class:`lammps` - - :ivar runs: list of completed runs, each storing the thermo output - :vartype run: list - """ - - def __init__(self, name="", cmdargs=None, ptr=None, comm=None): - self.has_echo = False - - if cmdargs: - if '-echo' in cmdargs: - idx = cmdargs.index('-echo') - # ensures that echo line is ignored during output capture - self.has_echo = idx+1 < len(cmdargs) and cmdargs[idx+1] in ('screen', 'both') - - if ptr: - if isinstance(ptr,PyLammps): - self.lmp = ptr.lmp - elif isinstance(ptr,lammps): - self.lmp = ptr - else: - self.lmp = lammps(name=name,cmdargs=cmdargs,ptr=ptr,comm=comm) - else: - self.lmp = lammps(name=name,cmdargs=cmdargs,ptr=None,comm=comm) - print("LAMMPS output is captured by PyLammps wrapper") - self._cmd_history = [] - self.runs = [] - - def __del__(self): - if self.lmp: self.lmp.close() - self.lmp = None - - def close(self): - """Explicitly delete a LAMMPS instance - - This is a wrapper around the :py:meth:`lammps.close` of the Python interface. - """ - if self.lmp: self.lmp.close() - self.lmp = None - - def version(self): - """Return a numerical representation of the LAMMPS version in use. - - This is a wrapper around the :py:meth:`lammps.version` function of the Python interface. - - :return: version number - :rtype: int - """ - return self.lmp.version() - - def file(self, file): - """Read LAMMPS commands from a file. - - This is a wrapper around the :py:meth:`lammps.file` function of the Python interface. - - :param path: Name of the file/path with LAMMPS commands - :type path: string - """ - self.lmp.file(file) - - def write_script(self, filepath): - """ - Write LAMMPS script file containing all commands executed up until now - - :param filepath: path to script file that should be written - :type filepath: string - """ - with open(filepath, "w") as f: - for cmd in self._cmd_history: - print(cmd, file=f) - - def command(self, cmd): - """ - Execute LAMMPS command - - All commands executed will be stored in a command history which can be - written to a file using :py:meth:`PyLammps.write_script()` - - :param cmd: command string that should be executed - :type: cmd: string - """ - self.lmp.command(cmd) - self._cmd_history.append(cmd) - - def run(self, *args, **kwargs): - """ - Execute LAMMPS run command with given arguments - - All thermo output during the run is captured and saved as new entry in - :py:attr:`PyLammps.runs`. The latest run can be retrieved by - :py:attr:`PyLammps.last_run`. - """ - output = self.__getattr__('run')(*args, **kwargs) - - comm = self.lmp.get_mpi_comm() - if comm: - output = self.lmp.comm.bcast(output, root=0) - - self.runs += get_thermo_data(output) - return output - - @property - def last_run(self): - """ - Return data produced of last completed run command - - :getter: Returns an object containing information about the last run command - :type: dict - """ - if len(self.runs) > 0: - return self.runs[-1] - return None - - @property - def atoms(self): - """ - All atoms of this LAMMPS instance - - :getter: Returns a list of atoms currently in the system - :type: AtomList - """ - return AtomList(self) - - @property - def system(self): - """ - The system state of this LAMMPS instance - - :getter: Returns an object with properties storing the current system state - :type: namedtuple - """ - output = self.info("system") - d = self._parse_info_system(output) - return namedtuple('System', d.keys())(*d.values()) - - @property - def communication(self): - """ - The communication state of this LAMMPS instance - - :getter: Returns an object with properties storing the current communication state - :type: namedtuple - """ - output = self.info("communication") - d = self._parse_info_communication(output) - return namedtuple('Communication', d.keys())(*d.values()) - - @property - def computes(self): - """ - The list of active computes of this LAMMPS instance - - :getter: Returns a list of computes that are currently active in this LAMMPS instance - :type: list - """ - output = self.info("computes") - return self._parse_element_list(output) - - @property - def dumps(self): - """ - The list of active dumps of this LAMMPS instance - - :getter: Returns a list of dumps that are currently active in this LAMMPS instance - :type: list - """ - output = self.info("dumps") - return self._parse_element_list(output) - - @property - def fixes(self): - """ - The list of active fixes of this LAMMPS instance - - :getter: Returns a list of fixes that are currently active in this LAMMPS instance - :type: list - """ - output = self.info("fixes") - return self._parse_element_list(output) - - @property - def groups(self): - """ - The list of active atom groups of this LAMMPS instance - - :getter: Returns a list of atom groups that are currently active in this LAMMPS instance - :type: list - """ - output = self.info("groups") - return self._parse_groups(output) - - @property - def variables(self): - """ - Returns a dictionary of all variables defined in the current LAMMPS instance - - :getter: Returns a dictionary of all variables that are defined in this LAMMPS instance - :type: dict - """ - output = self.info("variables") - vars = {} - for v in self._parse_element_list(output): - vars[v['name']] = Variable(self, v['name'], v['style'], v['def']) - return vars - - def eval(self, expr): - """ - Evaluate expression - - :param expr: the expression string that should be evaluated inside of LAMMPS - :type expr: string - - :return: the value of the evaluated expression - :rtype: float if numeric, string otherwise - """ - value = self.lmp_print('"$(%s)"' % expr).strip() - try: - return float(value) - except ValueError: - return value - - def _split_values(self, line): - return [x.strip() for x in line.split(',')] - - def _get_pair(self, value): - return [x.strip() for x in value.split('=')] - - def _parse_info_system(self, output): - lines = output[6:-2] - system = {} - - for line in lines: - if line.startswith("Units"): - system['units'] = self._get_pair(line)[1] - elif line.startswith("Atom style"): - system['atom_style'] = self._get_pair(line)[1] - elif line.startswith("Atom map"): - system['atom_map'] = self._get_pair(line)[1] - elif line.startswith("Atoms"): - parts = self._split_values(line) - system['natoms'] = int(self._get_pair(parts[0])[1]) - system['ntypes'] = int(self._get_pair(parts[1])[1]) - system['style'] = self._get_pair(parts[2])[1] - elif line.startswith("Kspace style"): - system['kspace_style'] = self._get_pair(line)[1] - elif line.startswith("Dimensions"): - system['dimensions'] = int(self._get_pair(line)[1]) - elif line.startswith("Orthogonal box"): - system['orthogonal_box'] = [float(x) for x in self._get_pair(line)[1].split('x')] - elif line.startswith("Boundaries"): - system['boundaries'] = self._get_pair(line)[1] - elif line.startswith("xlo"): - keys, values = [self._split_values(x) for x in self._get_pair(line)] - for key, value in zip(keys, values): - system[key] = float(value) - elif line.startswith("ylo"): - keys, values = [self._split_values(x) for x in self._get_pair(line)] - for key, value in zip(keys, values): - system[key] = float(value) - elif line.startswith("zlo"): - keys, values = [self._split_values(x) for x in self._get_pair(line)] - for key, value in zip(keys, values): - system[key] = float(value) - elif line.startswith("Molecule type"): - system['molecule_type'] = self._get_pair(line)[1] - elif line.startswith("Bonds"): - parts = self._split_values(line) - system['nbonds'] = int(self._get_pair(parts[0])[1]) - system['nbondtypes'] = int(self._get_pair(parts[1])[1]) - system['bond_style'] = self._get_pair(parts[2])[1] - elif line.startswith("Angles"): - parts = self._split_values(line) - system['nangles'] = int(self._get_pair(parts[0])[1]) - system['nangletypes'] = int(self._get_pair(parts[1])[1]) - system['angle_style'] = self._get_pair(parts[2])[1] - elif line.startswith("Dihedrals"): - parts = self._split_values(line) - system['ndihedrals'] = int(self._get_pair(parts[0])[1]) - system['ndihedraltypes'] = int(self._get_pair(parts[1])[1]) - system['dihedral_style'] = self._get_pair(parts[2])[1] - elif line.startswith("Impropers"): - parts = self._split_values(line) - system['nimpropers'] = int(self._get_pair(parts[0])[1]) - system['nimpropertypes'] = int(self._get_pair(parts[1])[1]) - system['improper_style'] = self._get_pair(parts[2])[1] - - return system - - def _parse_info_communication(self, output): - lines = output[6:-3] - comm = {} - - for line in lines: - if line.startswith("MPI library"): - comm['mpi_version'] = line.split(':')[1].strip() - elif line.startswith("Comm style"): - parts = self._split_values(line) - comm['comm_style'] = self._get_pair(parts[0])[1] - comm['comm_layout'] = self._get_pair(parts[1])[1] - elif line.startswith("Processor grid"): - comm['proc_grid'] = [int(x) for x in self._get_pair(line)[1].split('x')] - elif line.startswith("Communicate velocities for ghost atoms"): - comm['ghost_velocity'] = (self._get_pair(line)[1] == "yes") - elif line.startswith("Nprocs"): - parts = self._split_values(line) - comm['nprocs'] = int(self._get_pair(parts[0])[1]) - comm['nthreads'] = int(self._get_pair(parts[1])[1]) - return comm - - def _parse_element_list(self, output): - lines = output[6:-3] - elements = [] - - for line in lines: - element_info = self._split_values(line.split(':')[1].strip()) - element = {'name': element_info[0]} - for key, value in [self._get_pair(x) for x in element_info[1:]]: - element[key] = value - elements.append(element) - return elements - - def _parse_groups(self, output): - lines = output[6:-3] - groups = [] - group_pattern = re.compile(r"(?P.+) \((?P.+)\)") - - for line in lines: - m = group_pattern.match(line.split(':')[1].strip()) - group = {'name': m.group('name'), 'type': m.group('type')} - groups.append(group) - return groups - - def lmp_print(self, s): - """ needed for Python2 compatibility, since print is a reserved keyword """ - return self.__getattr__("print")(s) - - def __dir__(self): - return ['angle_coeff', 'angle_style', 'atom_modify', 'atom_style', 'atom_style', - 'bond_coeff', 'bond_style', 'boundary', 'change_box', 'communicate', 'compute', - 'create_atoms', 'create_box', 'delete_atoms', 'delete_bonds', 'dielectric', - 'dihedral_coeff', 'dihedral_style', 'dimension', 'dump', 'fix', 'fix_modify', - 'group', 'improper_coeff', 'improper_style', 'include', 'kspace_modify', - 'kspace_style', 'lattice', 'mass', 'minimize', 'min_style', 'neighbor', - 'neigh_modify', 'newton', 'nthreads', 'pair_coeff', 'pair_modify', - 'pair_style', 'processors', 'read', 'read_data', 'read_restart', 'region', - 'replicate', 'reset_timestep', 'restart', 'run', 'run_style', 'thermo', - 'thermo_modify', 'thermo_style', 'timestep', 'undump', 'unfix', 'units', - 'variable', 'velocity', 'write_restart'] - - def __getattr__(self, name): - """ - This method is where the Python 'magic' happens. If a method is not - defined by the class PyLammps, it assumes it is a LAMMPS command. It takes - all the arguments, concatinates them to a single string, and executes it using - :py:meth:`lammps.PyLammps.command()`. - - :param verbose: Print output of command - :type verbose: bool - :return: line or list of lines of output, None if no output - :rtype: list or string - """ - def handler(*args, **kwargs): - cmd_args = [name] + [str(x) for x in args] - - with OutputCapture() as capture: - cmd = ' '.join(cmd_args) - self.command(cmd) - output = capture.output - - if 'verbose' in kwargs and kwargs['verbose']: - print(output) - - lines = output.splitlines() - - if self.has_echo: - lines = lines[1:] - - if len(lines) > 1: - return lines - elif len(lines) == 1: - return lines[0] - return None - - return handler - - -class IPyLammps(PyLammps): - """ - IPython wrapper for LAMMPS which adds embedded graphics capabilities to PyLammmps interface - - It either creates its own instance of :py:class:`lammps` or can be - initialized with an existing instance. The arguments are the same of the - lower-level interface. The original interface can still be accessed via - :py:attr:`PyLammps.lmp`. - - :param name: "machine" name of the shared LAMMPS library ("mpi" loads ``liblammps_mpi.so``, "" loads ``liblammps.so``) - :type name: string - :param cmdargs: list of command line arguments to be passed to the :cpp:func:`lammps_open` function. The executable name is automatically added. - :type cmdargs: list - :param ptr: pointer to a LAMMPS C++ class instance when called from an embedded Python interpreter. None means load symbols from shared library. - :type ptr: pointer - :param comm: MPI communicator (as provided by `mpi4py `_). ``None`` means use ``MPI_COMM_WORLD`` implicitly. - :type comm: MPI_Comm - """ - - def __init__(self,name="",cmdargs=None,ptr=None,comm=None): - super(IPyLammps, self).__init__(name=name,cmdargs=cmdargs,ptr=ptr,comm=comm) - - def image(self, filename="snapshot.png", group="all", color="type", diameter="type", - size=None, view=None, center=None, up=None, zoom=1.0, background_color="white"): - """ Generate image using write_dump command and display it - - See :doc:`dump image ` for more information. - - :param filename: Name of the image file that should be generated. The extension determines whether it is PNG or JPEG - :type filename: string - :param group: the group of atoms write_image should use - :type group: string - :param color: name of property used to determine color - :type color: string - :param diameter: name of property used to determine atom diameter - :type diameter: string - :param size: dimensions of image - :type size: tuple (width, height) - :param view: view parameters - :type view: tuple (theta, phi) - :param center: center parameters - :type center: tuple (flag, center_x, center_y, center_z) - :param up: vector pointing to up direction - :type up: tuple (up_x, up_y, up_z) - :param zoom: zoom factor - :type zoom: float - :param background_color: background color of scene - :type background_color: string - - :return: Image instance used to display image in notebook - :rtype: :py:class:`IPython.core.display.Image` - """ - cmd_args = [group, "image", filename, color, diameter] - - if size: - width = size[0] - height = size[1] - cmd_args += ["size", width, height] - - if view: - theta = view[0] - phi = view[1] - cmd_args += ["view", theta, phi] - - if center: - flag = center[0] - Cx = center[1] - Cy = center[2] - Cz = center[3] - cmd_args += ["center", flag, Cx, Cy, Cz] - - if up: - Ux = up[0] - Uy = up[1] - Uz = up[2] - cmd_args += ["up", Ux, Uy, Uz] - - if zoom: - cmd_args += ["zoom", zoom] - - cmd_args.append("modify backcolor " + background_color) - - self.write_dump(*cmd_args) - from IPython.core.display import Image - return Image(filename) - - def video(self, filename): - """ - Load video from file - - Can be used to visualize videos from :doc:`dump movie `. - - :param filename: Path to video file - :type filename: string - :return: HTML Video Tag used by notebook to embed a video - :rtype: :py:class:`IPython.display.HTML` - """ - from IPython.display import HTML - return HTML("") diff --git a/python/lammps/data.py b/python/lammps/data.py new file mode 100644 index 0000000000..2cf100ed82 --- /dev/null +++ b/python/lammps/data.py @@ -0,0 +1,73 @@ +# ---------------------------------------------------------------------- +# LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator +# http://lammps.sandia.gov, Sandia National Laboratories +# Steve Plimpton, sjplimp@sandia.gov +# +# 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. +# ------------------------------------------------------------------------- + +################################################################################ +# LAMMPS data structures +# Written by Richard Berger +################################################################################ + +class NeighList: + """This is a wrapper class that exposes the contents of a neighbor list. + + It can be used like a regular Python list. Each element is a tuple of: + + * the atom local index + * its number of neighbors + * and a pointer to an c_int array containing local atom indices of its + neighbors + + Internally it uses the lower-level LAMMPS C-library interface. + + :param lmp: reference to instance of :py:class:`lammps` + :type lmp: lammps + :param idx: neighbor list index + :type idx: int + """ + def __init__(self, lmp, idx): + self.lmp = lmp + self.idx = idx + + def __str__(self): + return "Neighbor List ({} atoms)".format(self.size) + + def __repr__(self): + return self.__str__() + + @property + def size(self): + """ + :return: number of elements in neighbor list + """ + return self.lmp.get_neighlist_size(self.idx) + + def get(self, element): + """ + :return: tuple with atom local index, numpy array of neighbor local atom indices + :rtype: (int, int, ctypes.POINTER(c_int)) + """ + iatom, numneigh, neighbors = self.lmp.get_neighlist_element_neighbors(self.idx, element) + return iatom, numneigh, neighbors + + # the methods below implement the iterator interface, so NeighList can be used like a regular Python list + + def __getitem__(self, element): + return self.get(element) + + def __len__(self): + return self.size + + def __iter__(self): + inum = self.size + + for ii in range(inum): + yield self.get(ii) diff --git a/python/lammps/mliap/__init__.py b/python/lammps/mliap/__init__.py new file mode 100644 index 0000000000..0d63cc810b --- /dev/null +++ b/python/lammps/mliap/__init__.py @@ -0,0 +1,13 @@ + +# Check compatiblity of this build with the python shared library. +# If this fails, lammps will segfault because its library will +# try to improperly start up a new interpreter. +import sysconfig +import ctypes +library = sysconfig.get_config_vars('INSTSONAME')[0] +pylib = ctypes.CDLL(library) +if not pylib.Py_IsInitialized(): + raise RuntimeError("This interpreter is not compatible with python-based mliap for LAMMPS.") +del sysconfig, ctypes, library, pylib + +from .loader import load_model, activate_mliappy diff --git a/python/lammps/mliap/loader.py b/python/lammps/mliap/loader.py new file mode 100644 index 0000000000..b875d8d834 --- /dev/null +++ b/python/lammps/mliap/loader.py @@ -0,0 +1,52 @@ +# ---------------------------------------------------------------------- +# LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator +# http://lammps.sandia.gov, Sandia National Laboratories +# Steve Plimpton, sjplimp@sandia.gov +# +# 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: Nicholas Lubbers (LANL) +# ------------------------------------------------------------------------- + + +import sys +import importlib.util +import importlib.machinery + +def activate_mliappy(lmp): + try: + # Begin Importlib magic to find the embedded python module + # This is needed because the filename for liblammps does not + # match the spec for normal python modules, wherein + # file names match with PyInit function names. + # Also, python normally doesn't look for extensions besides '.so' + # We fix both of these problems by providing an explict + # path to the extension module 'mliap_model_python_couple' in + + path = lmp.lib._name + loader = importlib.machinery.ExtensionFileLoader('mliap_model_python_couple', path) + spec = importlib.util.spec_from_loader('mliap_model_python_couple', loader) + module = importlib.util.module_from_spec(spec) + sys.modules['mliap_model_python_couple'] = module + spec.loader.exec_module(module) + # End Importlib magic to find the embedded python module + + except Exception as ee: + raise ImportError("Could not load MLIAP python coupling module.") from ee + +def load_model(model): + try: + import mliap_model_python_couple + except ImportError as ie: + raise ImportError("MLIAP python module must be activated before loading\n" + "the pair style. Call lammps.mliap.activate_mliappy(lmp)." + ) from ie + mliap_model_python_couple.load_from_python(model) + diff --git a/python/lammps/mliap/pytorch.py b/python/lammps/mliap/pytorch.py new file mode 100644 index 0000000000..aa2cf1c97c --- /dev/null +++ b/python/lammps/mliap/pytorch.py @@ -0,0 +1,65 @@ +# ---------------------------------------------------------------------- +# LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator +# http://lammps.sandia.gov, Sandia National Laboratories +# Steve Plimpton, sjplimp@sandia.gov +# +# 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: Nicholas Lubbers (LANL) +# ------------------------------------------------------------------------- + +import numpy as np +import torch + +def calc_n_params(model): + return sum(p.nelement() for p in model.parameters()) + +class TorchWrapper(torch.nn.Module): + def __init__(self, model,n_descriptors,n_elements,n_params=None,device=None,dtype=torch.float64): + super().__init__() + + self.model = model + self.device = device + self.dtype = dtype + + # Put model on device and convert to dtype + self.to(self.dtype) + self.to(self.device) + + if n_params is None: + n_params = calc_n_params(model) + + self.n_params = n_params + self.n_descriptors = n_descriptors + self.n_elements = n_elements + + def forward(self, elems, bispectrum, beta, energy): + + bispectrum = torch.from_numpy(bispectrum).to(dtype=self.dtype, device=self.device).requires_grad_(True) + elems = torch.from_numpy(elems).to(dtype=torch.long, device=self.device) - 1 + + with torch.autograd.enable_grad(): + + energy_nn = self.model(bispectrum, elems) + if energy_nn.ndim > 1: + energy_nn = energy_nn.flatten() + + beta_nn = torch.autograd.grad(energy_nn.sum(), bispectrum)[0] + + beta[:] = beta_nn.detach().cpu().numpy().astype(np.float64) + energy[:] = energy_nn.detach().cpu().numpy().astype(np.float64) + +class IgnoreElems(torch.nn.Module): + def __init__(self,subnet): + super().__init__() + self.subnet = subnet + + def forward(self,bispectrum,elems): + return self.subnet(bispectrum) diff --git a/python/lammps/numpy.py b/python/lammps/numpy.py new file mode 100644 index 0000000000..ce64d68c90 --- /dev/null +++ b/python/lammps/numpy.py @@ -0,0 +1,338 @@ +# ---------------------------------------------------------------------- +# LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator +# http://lammps.sandia.gov, Sandia National Laboratories +# Steve Plimpton, sjplimp@sandia.gov +# +# 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. +# ------------------------------------------------------------------------- + +################################################################################ +# NumPy additions +# Written by Richard Berger +################################################################################ + +import warnings +from ctypes import POINTER, c_double, c_int, c_int32, c_int64, cast + + +from .constants import * +from .data import NeighList + + +class numpy_wrapper: + """lammps API NumPy Wrapper + + This is a wrapper class that provides additional methods on top of an + existing :py:class:`lammps` instance. The methods transform raw ctypes + pointers into NumPy arrays, which give direct access to the + original data while protecting against out-of-bounds accesses. + + There is no need to explicitly instantiate this class. Each instance + of :py:class:`lammps` has a :py:attr:`numpy ` property + that returns an instance. + + :param lmp: instance of the :py:class:`lammps` class + :type lmp: lammps + """ + def __init__(self, lmp): + self.lmp = lmp + + # ------------------------------------------------------------------------- + + def _ctype_to_numpy_int(self, ctype_int): + import numpy as np + if ctype_int == c_int32: + return np.int32 + elif ctype_int == c_int64: + return np.int64 + return np.intc + + # ------------------------------------------------------------------------- + + def extract_atom(self, name, dtype=LAMMPS_AUTODETECT, nelem=LAMMPS_AUTODETECT, dim=LAMMPS_AUTODETECT): + """Retrieve per-atom properties from LAMMPS as NumPy arrays + + This is a wrapper around the :py:meth:`lammps.extract_atom()` method. + It behaves the same as the original method, but returns NumPy arrays + instead of ``ctypes`` pointers. + + .. note:: + + While the returned arrays of per-atom data are dimensioned + for the range [0:nmax] - as is the underlying storage - + the data is usually only valid for the range of [0:nlocal], + unless the property of interest is also updated for ghost + atoms. In some cases, this depends on a LAMMPS setting, see + for example :doc:`comm_modify vel yes `. + + :param name: name of the property + :type name: string + :param dtype: type of the returned data (see :ref:`py_datatype_constants`) + :type dtype: int, optional + :param nelem: number of elements in array + :type nelem: int, optional + :param dim: dimension of each element + :type dim: int, optional + :return: requested data as NumPy array with direct access to C data or None + :rtype: numpy.array or NoneType + """ + if dtype == LAMMPS_AUTODETECT: + dtype = self.lmp.extract_atom_datatype(name) + + if nelem == LAMMPS_AUTODETECT: + if name == "mass": + nelem = self.lmp.extract_global("ntypes") + 1 + else: + nelem = self.lmp.extract_global("nlocal") + if dim == LAMMPS_AUTODETECT: + if dtype in (LAMMPS_INT_2D, LAMMPS_DOUBLE_2D, LAMMPS_INT64_2D): + # TODO add other fields + if name in ("x", "v", "f", "angmom", "torque", "csforce", "vforce"): + dim = 3 + else: + dim = 2 + else: + dim = 1 + + raw_ptr = self.lmp.extract_atom(name, dtype) + + if dtype in (LAMMPS_DOUBLE, LAMMPS_DOUBLE_2D): + return self.darray(raw_ptr, nelem, dim) + elif dtype in (LAMMPS_INT, LAMMPS_INT_2D): + return self.iarray(c_int32, raw_ptr, nelem, dim) + elif dtype in (LAMMPS_INT64, LAMMPS_INT64_2D): + return self.iarray(c_int64, raw_ptr, nelem, dim) + return raw_ptr + + # ------------------------------------------------------------------------- + + def extract_atom_iarray(self, name, nelem, dim=1): + warnings.warn("deprecated, use extract_atom instead", DeprecationWarning) + + if name in ['id', 'molecule']: + c_int_type = self.lmp.c_tagint + elif name in ['image']: + c_int_type = self.lmp.c_imageint + else: + c_int_type = c_int + + if dim == 1: + raw_ptr = self.lmp.extract_atom(name, LAMMPS_INT) + else: + raw_ptr = self.lmp.extract_atom(name, LAMMPS_INT_2D) + + return self.iarray(c_int_type, raw_ptr, nelem, dim) + + # ------------------------------------------------------------------------- + + def extract_atom_darray(self, name, nelem, dim=1): + warnings.warn("deprecated, use extract_atom instead", DeprecationWarning) + + if dim == 1: + raw_ptr = self.lmp.extract_atom(name, LAMMPS_DOUBLE) + else: + raw_ptr = self.lmp.extract_atom(name, LAMMPS_DOUBLE_2D) + + return self.darray(raw_ptr, nelem, dim) + + # ------------------------------------------------------------------------- + + def extract_compute(self, cid, style, type): + """Retrieve data from a LAMMPS compute + + This is a wrapper around the + :py:meth:`lammps.extract_compute() ` method. + It behaves the same as the original method, but returns NumPy arrays + instead of ``ctypes`` pointers. + + :param id: compute ID + :type id: string + :param style: style of the data retrieve (global, atom, or local), see :ref:`py_style_constants` + :type style: int + :param type: type of the returned data (scalar, vector, or array), see :ref:`py_type_constants` + :type type: int + :return: requested data either as float, as NumPy array with direct access to C data, or None + :rtype: float, numpy.array, or NoneType + """ + value = self.lmp.extract_compute(cid, style, type) + + if style in (LMP_STYLE_GLOBAL, LMP_STYLE_LOCAL): + if type == LMP_TYPE_VECTOR: + nrows = self.lmp.extract_compute(cid, style, LMP_SIZE_VECTOR) + return self.darray(value, nrows) + elif type == LMP_TYPE_ARRAY: + nrows = self.lmp.extract_compute(cid, style, LMP_SIZE_ROWS) + ncols = self.lmp.extract_compute(cid, style, LMP_SIZE_COLS) + return self.darray(value, nrows, ncols) + elif style == LMP_STYLE_ATOM: + if type == LMP_TYPE_VECTOR: + nlocal = self.lmp.extract_global("nlocal") + return self.darray(value, nlocal) + elif type == LMP_TYPE_ARRAY: + nlocal = self.lmp.extract_global("nlocal") + ncols = self.lmp.extract_compute(cid, style, LMP_SIZE_COLS) + return self.darray(value, nlocal, ncols) + return value + + # ------------------------------------------------------------------------- + + def extract_fix(self, fid, style, type, nrow=0, ncol=0): + """Retrieve data from a LAMMPS fix + + This is a wrapper around the :py:meth:`lammps.extract_fix() ` method. + It behaves the same as the original method, but returns NumPy arrays + instead of ``ctypes`` pointers. + + :param id: fix ID + :type id: string + :param style: style of the data retrieve (global, atom, or local), see :ref:`py_style_constants` + :type style: int + :param type: type or size of the returned data (scalar, vector, or array), see :ref:`py_type_constants` + :type type: int + :param nrow: index of global vector element or row index of global array element + :type nrow: int + :param ncol: column index of global array element + :type ncol: int + :return: requested data + :rtype: integer or double value, pointer to 1d or 2d double array or None + + """ + value = self.lmp.extract_fix(fid, style, type, nrow, ncol) + if style == LMP_STYLE_ATOM: + if type == LMP_TYPE_VECTOR: + nlocal = self.lmp.extract_global("nlocal") + return self.darray(value, nlocal) + elif type == LMP_TYPE_ARRAY: + nlocal = self.lmp.extract_global("nlocal") + ncols = self.lmp.extract_fix(fid, style, LMP_SIZE_COLS, 0, 0) + return self.darray(value, nlocal, ncols) + elif style == LMP_STYLE_LOCAL: + if type == LMP_TYPE_VECTOR: + nrows = self.lmp.extract_fix(fid, style, LMP_SIZE_ROWS, 0, 0) + return self.darray(value, nrows) + elif type == LMP_TYPE_ARRAY: + nrows = self.lmp.extract_fix(fid, style, LMP_SIZE_ROWS, 0, 0) + ncols = self.lmp.extract_fix(fid, style, LMP_SIZE_COLS, 0, 0) + return self.darray(value, nrows, ncols) + return value + + # ------------------------------------------------------------------------- + + def extract_variable(self, name, group=None, vartype=LMP_VAR_EQUAL): + """ Evaluate a LAMMPS variable and return its data + + This function is a wrapper around the function + :py:meth:`lammps.extract_variable() ` + method. It behaves the same as the original method, but returns NumPy arrays + instead of ``ctypes`` pointers. + + :param name: name of the variable to execute + :type name: string + :param group: name of group for atom-style variable (ignored for equal-style variables) + :type group: string + :param vartype: type of variable, see :ref:`py_vartype_constants` + :type vartype: int + :return: the requested data or None + :rtype: c_double, numpy.array, or NoneType + """ + import numpy as np + value = self.lmp.extract_variable(name, group, vartype) + if vartype == LMP_VAR_ATOM: + return np.ctypeslib.as_array(value) + return value + + # ------------------------------------------------------------------------- + + def get_neighlist(self, idx): + """Returns an instance of :class:`NumPyNeighList` which wraps access to the neighbor list with the given index + + :param idx: index of neighbor list + :type idx: int + :return: an instance of :class:`NumPyNeighList` wrapping access to neighbor list data + :rtype: NumPyNeighList + """ + if idx < 0: + return None + return NumPyNeighList(self.lmp, idx) + + # ------------------------------------------------------------------------- + + def get_neighlist_element_neighbors(self, idx, element): + """Return data of neighbor list entry + + This function is a wrapper around the function + :py:meth:`lammps.get_neighlist_element_neighbors() ` + method. It behaves the same as the original method, but returns a NumPy array containing the neighbors + instead of a ``ctypes`` pointer. + + :param element: neighbor list index + :type element: int + :param element: neighbor list element index + :type element: int + :return: tuple with atom local index and numpy array of neighbor local atom indices + :rtype: (int, numpy.array) + """ + iatom, numneigh, c_neighbors = self.lmp.get_neighlist_element_neighbors(idx, element) + neighbors = self.iarray(c_int, c_neighbors, numneigh, 1) + return iatom, neighbors + + # ------------------------------------------------------------------------- + + def iarray(self, c_int_type, raw_ptr, nelem, dim=1): + import numpy as np + np_int_type = self._ctype_to_numpy_int(c_int_type) + + if dim == 1: + ptr = cast(raw_ptr, POINTER(c_int_type * nelem)) + else: + ptr = cast(raw_ptr[0], POINTER(c_int_type * nelem * dim)) + + a = np.frombuffer(ptr.contents, dtype=np_int_type) + a.shape = (nelem, dim) + return a + + # ------------------------------------------------------------------------- + + def darray(self, raw_ptr, nelem, dim=1): + import numpy as np + if dim == 1: + ptr = cast(raw_ptr, POINTER(c_double * nelem)) + else: + ptr = cast(raw_ptr[0], POINTER(c_double * nelem * dim)) + + a = np.frombuffer(ptr.contents) + a.shape = (nelem, dim) + return a + +# ------------------------------------------------------------------------- + +class NumPyNeighList(NeighList): + """This is a wrapper class that exposes the contents of a neighbor list. + + It can be used like a regular Python list. Each element is a tuple of: + + * the atom local index + * a NumPy array containing the local atom indices of its neighbors + + Internally it uses the lower-level LAMMPS C-library interface. + + :param lmp: reference to instance of :py:class:`lammps` + :type lmp: lammps + :param idx: neighbor list index + :type idx: int + """ + def __init__(self, lmp, idx): + super(NumPyNeighList, self).__init__(lmp, idx) + + def get(self, element): + """ + :return: tuple with atom local index, numpy array of neighbor local atom indices + :rtype: (int, numpy.array) + """ + iatom, neighbors = self.lmp.numpy.get_neighlist_element_neighbors(self.idx, element) + return iatom, neighbors diff --git a/python/lammps/pylammps.py b/python/lammps/pylammps.py new file mode 100644 index 0000000000..1ec45d43b5 --- /dev/null +++ b/python/lammps/pylammps.py @@ -0,0 +1,861 @@ +# ---------------------------------------------------------------------- +# LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator +# http://lammps.sandia.gov, Sandia National Laboratories +# Steve Plimpton, sjplimp@sandia.gov +# +# 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. +# ------------------------------------------------------------------------- + +################################################################################ +# Alternative Python Wrapper +# Written by Richard Berger +################################################################################ + +# for python2/3 compatibility + +from __future__ import print_function + +import os +import re +import select +import sys +from collections import namedtuple + +from .core import lammps + + +class OutputCapture(object): + """ Utility class to capture LAMMPS library output """ + + def __init__(self): + self.stdout_pipe_read, self.stdout_pipe_write = os.pipe() + self.stdout_fd = 1 + + def __enter__(self): + self.stdout = os.dup(self.stdout_fd) + os.dup2(self.stdout_pipe_write, self.stdout_fd) + return self + + def __exit__(self, type, value, tracebac): + os.dup2(self.stdout, self.stdout_fd) + os.close(self.stdout) + os.close(self.stdout_pipe_read) + os.close(self.stdout_pipe_write) + + # check if we have more to read from the pipe + def more_data(self, pipe): + r, _, _ = select.select([pipe], [], [], 0) + return bool(r) + + # read the whole pipe + def read_pipe(self, pipe): + out = "" + while self.more_data(pipe): + out += os.read(pipe, 1024).decode() + return out + + @property + def output(self): + return self.read_pipe(self.stdout_pipe_read) + +# ------------------------------------------------------------------------- + +class Variable(object): + def __init__(self, pylammps_instance, name, style, definition): + self._pylmp = pylammps_instance + self.name = name + self.style = style + self.definition = definition.split() + + @property + def value(self): + if self.style == 'atom': + return list(self._pylmp.lmp.extract_variable(self.name, "all", 1)) + else: + value = self._pylmp.lmp_print('"${%s}"' % self.name).strip() + try: + return float(value) + except ValueError: + return value + +# ------------------------------------------------------------------------- + +class AtomList(object): + """ + A dynamic list of atoms that returns either an :py:class:`Atom` or + :py:class:`Atom2D` instance for each atom. Instances are only allocated + when accessed. + + :ivar natoms: total number of atoms + :ivar dimensions: number of dimensions in system + """ + def __init__(self, pylammps_instance): + self._pylmp = pylammps_instance + self.natoms = self._pylmp.system.natoms + self.dimensions = self._pylmp.system.dimensions + self._loaded = {} + + def __getitem__(self, index): + """ + Return Atom with given local index + + :param index: Local index of atom + :type index: int + :rtype: Atom or Atom2D + """ + if index not in self._loaded: + if self.dimensions == 2: + atom = Atom2D(self._pylmp, index + 1) + else: + atom = Atom(self._pylmp, index + 1) + self._loaded[index] = atom + return self._loaded[index] + + def __len__(self): + return self.natoms + + +# ------------------------------------------------------------------------- + +class Atom(object): + """ + A wrapper class then represents a single atom inside of LAMMPS + + It provides access to properties of the atom and allows you to change some of them. + """ + def __init__(self, pylammps_instance, index): + self._pylmp = pylammps_instance + self.index = index + + @property + def id(self): + """ + Return the atom ID + + :type: int + """ + return int(self._pylmp.eval("id[%d]" % self.index)) + + @property + def type(self): + """ + Return the atom type + + :type: int + """ + return int(self._pylmp.eval("type[%d]" % self.index)) + + @property + def mol(self): + """ + Return the atom molecule index + + :type: int + """ + return self._pylmp.eval("mol[%d]" % self.index) + + @property + def mass(self): + """ + Return the atom mass + + :type: float + """ + return self._pylmp.eval("mass[%d]" % self.index) + + @property + def position(self): + """ + :getter: Return position of atom + :setter: Set position of atom + :type: tuple (float, float, float) + """ + return (self._pylmp.eval("x[%d]" % self.index), + self._pylmp.eval("y[%d]" % self.index), + self._pylmp.eval("z[%d]" % self.index)) + + @position.setter + def position(self, value): + """ + :getter: Return velocity of atom + :setter: Set velocity of atom + :type: tuple (float, float, float) + """ + self._pylmp.set("atom", self.index, "x", value[0]) + self._pylmp.set("atom", self.index, "y", value[1]) + self._pylmp.set("atom", self.index, "z", value[2]) + + @property + def velocity(self): + return (self._pylmp.eval("vx[%d]" % self.index), + self._pylmp.eval("vy[%d]" % self.index), + self._pylmp.eval("vz[%d]" % self.index)) + + @velocity.setter + def velocity(self, value): + self._pylmp.set("atom", self.index, "vx", value[0]) + self._pylmp.set("atom", self.index, "vy", value[1]) + self._pylmp.set("atom", self.index, "vz", value[2]) + + @property + def force(self): + """ + Return the total force acting on the atom + + :type: tuple (float, float, float) + """ + return (self._pylmp.eval("fx[%d]" % self.index), + self._pylmp.eval("fy[%d]" % self.index), + self._pylmp.eval("fz[%d]" % self.index)) + + @property + def charge(self): + """ + Return the atom charge + + :type: float + """ + return self._pylmp.eval("q[%d]" % self.index) + +# ------------------------------------------------------------------------- + +class Atom2D(Atom): + """ + A wrapper class then represents a single 2D atom inside of LAMMPS + + Inherits all properties from the :py:class:`Atom` class, but returns 2D versions + of position, velocity, and force. + + It provides access to properties of the atom and allows you to change some of them. + """ + def __init__(self, pylammps_instance, index): + super(Atom2D, self).__init__(pylammps_instance, index) + + @property + def position(self): + """ + :getter: Return position of atom + :setter: Set position of atom + :type: tuple (float, float) + """ + return (self._pylmp.eval("x[%d]" % self.index), + self._pylmp.eval("y[%d]" % self.index)) + + @position.setter + def position(self, value): + self._pylmp.set("atom", self.index, "x", value[0]) + self._pylmp.set("atom", self.index, "y", value[1]) + + @property + def velocity(self): + """ + :getter: Return velocity of atom + :setter: Set velocity of atom + :type: tuple (float, float) + """ + return (self._pylmp.eval("vx[%d]" % self.index), + self._pylmp.eval("vy[%d]" % self.index)) + + @velocity.setter + def velocity(self, value): + self._pylmp.set("atom", self.index, "vx", value[0]) + self._pylmp.set("atom", self.index, "vy", value[1]) + + @property + def force(self): + """ + Return the total force acting on the atom + + :type: tuple (float, float) + """ + return (self._pylmp.eval("fx[%d]" % self.index), + self._pylmp.eval("fy[%d]" % self.index)) + +# ------------------------------------------------------------------------- + +class variable_set: + def __init__(self, name, variable_dict): + self._name = name + array_pattern = re.compile(r"(?P.+)\[(?P[0-9]+)\]") + + for key, value in variable_dict.items(): + m = array_pattern.match(key) + if m: + g = m.groupdict() + varname = g['arr'] + idx = int(g['index']) + if varname not in self.__dict__: + self.__dict__[varname] = {} + self.__dict__[varname][idx] = value + else: + self.__dict__[key] = value + + def __str__(self): + return "{}({})".format(self._name, ','.join(["{}={}".format(k, self.__dict__[k]) for k in self.__dict__.keys() if not k.startswith('_')])) + + def __repr__(self): + return self.__str__() + +# ------------------------------------------------------------------------- + +def get_thermo_data(output): + """ traverse output of runs and extract thermo data columns """ + if isinstance(output, str): + lines = output.splitlines() + else: + lines = output + + runs = [] + columns = [] + in_run = False + current_run = {} + + for line in lines: + if line.startswith("Per MPI rank memory allocation"): + in_run = True + elif in_run and len(columns) == 0: + # first line after memory usage are column names + columns = line.split() + + current_run = {} + + for col in columns: + current_run[col] = [] + + elif line.startswith("Loop time of "): + in_run = False + columns = None + thermo_data = variable_set('ThermoData', current_run) + r = {'thermo' : thermo_data } + runs.append(namedtuple('Run', list(r.keys()))(*list(r.values()))) + elif in_run and len(columns) > 0: + items = line.split() + # Convert thermo output and store it. + # It must have the same number of columns and + # all of them must be convertible to floats. + # Otherwise we ignore the line + if len(items) == len(columns): + try: + values = [float(x) for x in items] + for i, col in enumerate(columns): + current_run[col].append(values[i]) + except ValueError: + pass + + return runs + +# ------------------------------------------------------------------------- +# ------------------------------------------------------------------------- + +class PyLammps(object): + """ + This is a Python wrapper class around the lower-level + :py:class:`lammps` class, exposing a more Python-like, + object-oriented interface for prototyping system inside of IPython and + Jupyter notebooks. + + It either creates its own instance of :py:class:`lammps` or can be + initialized with an existing instance. The arguments are the same of the + lower-level interface. The original interface can still be accessed via + :py:attr:`PyLammps.lmp`. + + :param name: "machine" name of the shared LAMMPS library ("mpi" loads ``liblammps_mpi.so``, "" loads ``liblammps.so``) + :type name: string + :param cmdargs: list of command line arguments to be passed to the :cpp:func:`lammps_open` function. The executable name is automatically added. + :type cmdargs: list + :param ptr: pointer to a LAMMPS C++ class instance when called from an embedded Python interpreter. None means load symbols from shared library. + :type ptr: pointer + :param comm: MPI communicator (as provided by `mpi4py `_). ``None`` means use ``MPI_COMM_WORLD`` implicitly. + :type comm: MPI_Comm + + :ivar lmp: instance of original LAMMPS Python interface + :vartype lmp: :py:class:`lammps` + + :ivar runs: list of completed runs, each storing the thermo output + :vartype run: list + """ + + def __init__(self, name="", cmdargs=None, ptr=None, comm=None): + self.has_echo = False + + if cmdargs: + if '-echo' in cmdargs: + idx = cmdargs.index('-echo') + # ensures that echo line is ignored during output capture + self.has_echo = idx+1 < len(cmdargs) and cmdargs[idx+1] in ('screen', 'both') + + if ptr: + if isinstance(ptr,PyLammps): + self.lmp = ptr.lmp + elif isinstance(ptr,lammps): + self.lmp = ptr + else: + self.lmp = lammps(name=name,cmdargs=cmdargs,ptr=ptr,comm=comm) + else: + self.lmp = lammps(name=name,cmdargs=cmdargs,ptr=None,comm=comm) + print("LAMMPS output is captured by PyLammps wrapper") + self._cmd_history = [] + self.runs = [] + + def __del__(self): + if self.lmp: self.lmp.close() + self.lmp = None + + def close(self): + """Explicitly delete a LAMMPS instance + + This is a wrapper around the :py:meth:`lammps.close` of the Python interface. + """ + if self.lmp: self.lmp.close() + self.lmp = None + + def version(self): + """Return a numerical representation of the LAMMPS version in use. + + This is a wrapper around the :py:meth:`lammps.version` function of the Python interface. + + :return: version number + :rtype: int + """ + return self.lmp.version() + + def file(self, file): + """Read LAMMPS commands from a file. + + This is a wrapper around the :py:meth:`lammps.file` function of the Python interface. + + :param path: Name of the file/path with LAMMPS commands + :type path: string + """ + self.lmp.file(file) + + def write_script(self, filepath): + """ + Write LAMMPS script file containing all commands executed up until now + + :param filepath: path to script file that should be written + :type filepath: string + """ + with open(filepath, "w") as f: + for cmd in self._cmd_history: + print(cmd, file=f) + + def command(self, cmd): + """ + Execute LAMMPS command + + All commands executed will be stored in a command history which can be + written to a file using :py:meth:`PyLammps.write_script()` + + :param cmd: command string that should be executed + :type: cmd: string + """ + self.lmp.command(cmd) + self._cmd_history.append(cmd) + + def run(self, *args, **kwargs): + """ + Execute LAMMPS run command with given arguments + + All thermo output during the run is captured and saved as new entry in + :py:attr:`PyLammps.runs`. The latest run can be retrieved by + :py:attr:`PyLammps.last_run`. + """ + output = self.__getattr__('run')(*args, **kwargs) + + comm = self.lmp.get_mpi_comm() + if comm: + output = self.lmp.comm.bcast(output, root=0) + + self.runs += get_thermo_data(output) + return output + + @property + def last_run(self): + """ + Return data produced of last completed run command + + :getter: Returns an object containing information about the last run command + :type: dict + """ + if len(self.runs) > 0: + return self.runs[-1] + return None + + @property + def atoms(self): + """ + All atoms of this LAMMPS instance + + :getter: Returns a list of atoms currently in the system + :type: AtomList + """ + return AtomList(self) + + @property + def system(self): + """ + The system state of this LAMMPS instance + + :getter: Returns an object with properties storing the current system state + :type: namedtuple + """ + output = self.info("system") + d = self._parse_info_system(output) + return namedtuple('System', d.keys())(*d.values()) + + @property + def communication(self): + """ + The communication state of this LAMMPS instance + + :getter: Returns an object with properties storing the current communication state + :type: namedtuple + """ + output = self.info("communication") + d = self._parse_info_communication(output) + return namedtuple('Communication', d.keys())(*d.values()) + + @property + def computes(self): + """ + The list of active computes of this LAMMPS instance + + :getter: Returns a list of computes that are currently active in this LAMMPS instance + :type: list + """ + output = self.info("computes") + return self._parse_element_list(output) + + @property + def dumps(self): + """ + The list of active dumps of this LAMMPS instance + + :getter: Returns a list of dumps that are currently active in this LAMMPS instance + :type: list + """ + output = self.info("dumps") + return self._parse_element_list(output) + + @property + def fixes(self): + """ + The list of active fixes of this LAMMPS instance + + :getter: Returns a list of fixes that are currently active in this LAMMPS instance + :type: list + """ + output = self.info("fixes") + return self._parse_element_list(output) + + @property + def groups(self): + """ + The list of active atom groups of this LAMMPS instance + + :getter: Returns a list of atom groups that are currently active in this LAMMPS instance + :type: list + """ + output = self.info("groups") + return self._parse_groups(output) + + @property + def variables(self): + """ + Returns a dictionary of all variables defined in the current LAMMPS instance + + :getter: Returns a dictionary of all variables that are defined in this LAMMPS instance + :type: dict + """ + output = self.info("variables") + vars = {} + for v in self._parse_element_list(output): + vars[v['name']] = Variable(self, v['name'], v['style'], v['def']) + return vars + + def eval(self, expr): + """ + Evaluate expression + + :param expr: the expression string that should be evaluated inside of LAMMPS + :type expr: string + + :return: the value of the evaluated expression + :rtype: float if numeric, string otherwise + """ + value = self.lmp_print('"$(%s)"' % expr).strip() + try: + return float(value) + except ValueError: + return value + + def _split_values(self, line): + return [x.strip() for x in line.split(',')] + + def _get_pair(self, value): + return [x.strip() for x in value.split('=')] + + def _parse_info_system(self, output): + lines = output[6:-2] + system = {} + + for line in lines: + if line.startswith("Units"): + system['units'] = self._get_pair(line)[1] + elif line.startswith("Atom style"): + system['atom_style'] = self._get_pair(line)[1] + elif line.startswith("Atom map"): + system['atom_map'] = self._get_pair(line)[1] + elif line.startswith("Atoms"): + parts = self._split_values(line) + system['natoms'] = int(self._get_pair(parts[0])[1]) + system['ntypes'] = int(self._get_pair(parts[1])[1]) + system['style'] = self._get_pair(parts[2])[1] + elif line.startswith("Kspace style"): + system['kspace_style'] = self._get_pair(line)[1] + elif line.startswith("Dimensions"): + system['dimensions'] = int(self._get_pair(line)[1]) + elif line.startswith("Orthogonal box"): + system['orthogonal_box'] = [float(x) for x in self._get_pair(line)[1].split('x')] + elif line.startswith("Boundaries"): + system['boundaries'] = self._get_pair(line)[1] + elif line.startswith("xlo"): + keys, values = [self._split_values(x) for x in self._get_pair(line)] + for key, value in zip(keys, values): + system[key] = float(value) + elif line.startswith("ylo"): + keys, values = [self._split_values(x) for x in self._get_pair(line)] + for key, value in zip(keys, values): + system[key] = float(value) + elif line.startswith("zlo"): + keys, values = [self._split_values(x) for x in self._get_pair(line)] + for key, value in zip(keys, values): + system[key] = float(value) + elif line.startswith("Molecule type"): + system['molecule_type'] = self._get_pair(line)[1] + elif line.startswith("Bonds"): + parts = self._split_values(line) + system['nbonds'] = int(self._get_pair(parts[0])[1]) + system['nbondtypes'] = int(self._get_pair(parts[1])[1]) + system['bond_style'] = self._get_pair(parts[2])[1] + elif line.startswith("Angles"): + parts = self._split_values(line) + system['nangles'] = int(self._get_pair(parts[0])[1]) + system['nangletypes'] = int(self._get_pair(parts[1])[1]) + system['angle_style'] = self._get_pair(parts[2])[1] + elif line.startswith("Dihedrals"): + parts = self._split_values(line) + system['ndihedrals'] = int(self._get_pair(parts[0])[1]) + system['ndihedraltypes'] = int(self._get_pair(parts[1])[1]) + system['dihedral_style'] = self._get_pair(parts[2])[1] + elif line.startswith("Impropers"): + parts = self._split_values(line) + system['nimpropers'] = int(self._get_pair(parts[0])[1]) + system['nimpropertypes'] = int(self._get_pair(parts[1])[1]) + system['improper_style'] = self._get_pair(parts[2])[1] + + return system + + def _parse_info_communication(self, output): + lines = output[6:-3] + comm = {} + + for line in lines: + if line.startswith("MPI library"): + comm['mpi_version'] = line.split(':')[1].strip() + elif line.startswith("Comm style"): + parts = self._split_values(line) + comm['comm_style'] = self._get_pair(parts[0])[1] + comm['comm_layout'] = self._get_pair(parts[1])[1] + elif line.startswith("Processor grid"): + comm['proc_grid'] = [int(x) for x in self._get_pair(line)[1].split('x')] + elif line.startswith("Communicate velocities for ghost atoms"): + comm['ghost_velocity'] = (self._get_pair(line)[1] == "yes") + elif line.startswith("Nprocs"): + parts = self._split_values(line) + comm['nprocs'] = int(self._get_pair(parts[0])[1]) + comm['nthreads'] = int(self._get_pair(parts[1])[1]) + return comm + + def _parse_element_list(self, output): + lines = output[6:-3] + elements = [] + + for line in lines: + element_info = self._split_values(line.split(':')[1].strip()) + element = {'name': element_info[0]} + for key, value in [self._get_pair(x) for x in element_info[1:]]: + element[key] = value + elements.append(element) + return elements + + def _parse_groups(self, output): + lines = output[6:-3] + groups = [] + group_pattern = re.compile(r"(?P.+) \((?P.+)\)") + + for line in lines: + m = group_pattern.match(line.split(':')[1].strip()) + group = {'name': m.group('name'), 'type': m.group('type')} + groups.append(group) + return groups + + def lmp_print(self, s): + """ needed for Python2 compatibility, since print is a reserved keyword """ + return self.__getattr__("print")(s) + + def __dir__(self): + return ['angle_coeff', 'angle_style', 'atom_modify', 'atom_style', 'atom_style', + 'bond_coeff', 'bond_style', 'boundary', 'change_box', 'communicate', 'compute', + 'create_atoms', 'create_box', 'delete_atoms', 'delete_bonds', 'dielectric', + 'dihedral_coeff', 'dihedral_style', 'dimension', 'dump', 'fix', 'fix_modify', + 'group', 'improper_coeff', 'improper_style', 'include', 'kspace_modify', + 'kspace_style', 'lattice', 'mass', 'minimize', 'min_style', 'neighbor', + 'neigh_modify', 'newton', 'nthreads', 'pair_coeff', 'pair_modify', + 'pair_style', 'processors', 'read', 'read_data', 'read_restart', 'region', + 'replicate', 'reset_timestep', 'restart', 'run', 'run_style', 'thermo', + 'thermo_modify', 'thermo_style', 'timestep', 'undump', 'unfix', 'units', + 'variable', 'velocity', 'write_restart'] + + def __getattr__(self, name): + """ + This method is where the Python 'magic' happens. If a method is not + defined by the class PyLammps, it assumes it is a LAMMPS command. It takes + all the arguments, concatinates them to a single string, and executes it using + :py:meth:`lammps.PyLammps.command()`. + + :param verbose: Print output of command + :type verbose: bool + :return: line or list of lines of output, None if no output + :rtype: list or string + """ + def handler(*args, **kwargs): + cmd_args = [name] + [str(x) for x in args] + + with OutputCapture() as capture: + cmd = ' '.join(cmd_args) + self.command(cmd) + output = capture.output + + if 'verbose' in kwargs and kwargs['verbose']: + print(output) + + lines = output.splitlines() + + if self.has_echo: + lines = lines[1:] + + if len(lines) > 1: + return lines + elif len(lines) == 1: + return lines[0] + return None + + return handler + + +class IPyLammps(PyLammps): + """ + IPython wrapper for LAMMPS which adds embedded graphics capabilities to PyLammmps interface + + It either creates its own instance of :py:class:`lammps` or can be + initialized with an existing instance. The arguments are the same of the + lower-level interface. The original interface can still be accessed via + :py:attr:`PyLammps.lmp`. + + :param name: "machine" name of the shared LAMMPS library ("mpi" loads ``liblammps_mpi.so``, "" loads ``liblammps.so``) + :type name: string + :param cmdargs: list of command line arguments to be passed to the :cpp:func:`lammps_open` function. The executable name is automatically added. + :type cmdargs: list + :param ptr: pointer to a LAMMPS C++ class instance when called from an embedded Python interpreter. None means load symbols from shared library. + :type ptr: pointer + :param comm: MPI communicator (as provided by `mpi4py `_). ``None`` means use ``MPI_COMM_WORLD`` implicitly. + :type comm: MPI_Comm + """ + + def __init__(self,name="",cmdargs=None,ptr=None,comm=None): + super(IPyLammps, self).__init__(name=name,cmdargs=cmdargs,ptr=ptr,comm=comm) + + def image(self, filename="snapshot.png", group="all", color="type", diameter="type", + size=None, view=None, center=None, up=None, zoom=1.0, background_color="white"): + """ Generate image using write_dump command and display it + + See :doc:`dump image ` for more information. + + :param filename: Name of the image file that should be generated. The extension determines whether it is PNG or JPEG + :type filename: string + :param group: the group of atoms write_image should use + :type group: string + :param color: name of property used to determine color + :type color: string + :param diameter: name of property used to determine atom diameter + :type diameter: string + :param size: dimensions of image + :type size: tuple (width, height) + :param view: view parameters + :type view: tuple (theta, phi) + :param center: center parameters + :type center: tuple (flag, center_x, center_y, center_z) + :param up: vector pointing to up direction + :type up: tuple (up_x, up_y, up_z) + :param zoom: zoom factor + :type zoom: float + :param background_color: background color of scene + :type background_color: string + + :return: Image instance used to display image in notebook + :rtype: :py:class:`IPython.core.display.Image` + """ + cmd_args = [group, "image", filename, color, diameter] + + if size: + width = size[0] + height = size[1] + cmd_args += ["size", width, height] + + if view: + theta = view[0] + phi = view[1] + cmd_args += ["view", theta, phi] + + if center: + flag = center[0] + Cx = center[1] + Cy = center[2] + Cz = center[3] + cmd_args += ["center", flag, Cx, Cy, Cz] + + if up: + Ux = up[0] + Uy = up[1] + Uz = up[2] + cmd_args += ["up", Ux, Uy, Uz] + + if zoom: + cmd_args += ["zoom", zoom] + + cmd_args.append("modify backcolor " + background_color) + + self.write_dump(*cmd_args) + from IPython.core.display import Image + return Image(filename) + + def video(self, filename): + """ + Load video from file + + Can be used to visualize videos from :doc:`dump movie `. + + :param filename: Path to video file + :type filename: string + :return: HTML Video Tag used by notebook to embed a video + :rtype: :py:class:`IPython.display.HTML` + """ + from IPython.display import HTML + return HTML("") diff --git a/python/setup.py b/python/setup.py new file mode 100644 index 0000000000..aff0b14671 --- /dev/null +++ b/python/setup.py @@ -0,0 +1,26 @@ +# this only installs the LAMMPS python package +# it assumes the LAMMPS shared library is already installed +from distutils.core import setup +import os + +LAMMPS_PYTHON_DIR = os.path.dirname(os.path.realpath(__file__)) +LAMMPS_DIR = os.path.dirname(LAMMPS_PYTHON_DIR) +LAMMPS_SOURCE_DIR = os.path.join(LAMMPS_DIR, 'src') + +def get_lammps_version(): + with open(os.path.join(LAMMPS_SOURCE_DIR, 'version.h'), 'r') as f: + line = f.readline() + start_pos = line.find('"')+1 + end_pos = line.find('"', start_pos) + return "".join(line[start_pos:end_pos].split()) + +setup( + name = "lammps", + version = get_lammps_version(), + author = "Steve Plimpton", + author_email = "sjplimp@sandia.gov", + url = "https://lammps.sandia.gov", + description = "LAMMPS Molecular Dynamics Python package", + license = "GPL", + packages=["lammps","lammps.mliap"], +) diff --git a/src/COMPRESS/zstd_file_writer.cpp b/src/COMPRESS/zstd_file_writer.cpp index e99dbf0181..2631faa4ad 100644 --- a/src/COMPRESS/zstd_file_writer.cpp +++ b/src/COMPRESS/zstd_file_writer.cpp @@ -79,7 +79,7 @@ size_t ZstdFileWriter::write(const void * buffer, size_t length) do { ZSTD_outBuffer output = { out_buffer, out_buffer_size, 0 }; - size_t const remaining = ZSTD_compressStream2(cctx, &output, &input, mode); + ZSTD_compressStream2(cctx, &output, &input, mode); fwrite(out_buffer, sizeof(char), output.pos, fp); } while(input.pos < input.size); diff --git a/src/Depend.sh b/src/Depend.sh index e629ca9197..f77d435fc5 100755 --- a/src/Depend.sh +++ b/src/Depend.sh @@ -106,6 +106,10 @@ if (test $1 = "PERI") then depend USER-OMP fi +if (test $1 = "PYTHON") then + depend MLIAP +fi + if (test $1 = "RIGID") then depend KOKKOS depend USER-OMP @@ -114,6 +118,7 @@ fi if (test $1 = "SNAP") then depend KOKKOS + depend MLIAP fi if (test $1 = "USER-CGSDK") then diff --git a/src/GPU/fix_gpu.cpp b/src/GPU/fix_gpu.cpp index 5774d1ea50..8f88dfd61d 100644 --- a/src/GPU/fix_gpu.cpp +++ b/src/GPU/fix_gpu.cpp @@ -120,6 +120,7 @@ FixGPU::FixGPU(LAMMPS *lmp, int narg, char **arg) : double binsize = 0.0; char *opencl_flags = nullptr; int block_pair = -1; + int pair_only_flag = 0; int iarg = 4; while (iarg < narg) { @@ -169,6 +170,12 @@ FixGPU::FixGPU(LAMMPS *lmp, int narg, char **arg) : if (iarg+2 > narg) error->all(FLERR,"Illegal package gpu command"); block_pair = utils::inumeric(FLERR,arg[iarg+1],false,lmp); iarg += 2; + } else if (strcmp(arg[iarg],"pair/only") == 0) { + if (iarg+2 > narg) error->all(FLERR,"Illegal package gpu command"); + if (strcmp(arg[iarg+1],"off") == 0) pair_only_flag = 0; + else if (strcmp(arg[iarg+1],"on") == 0) pair_only_flag = 1; + else error->all(FLERR,"Illegal package gpu command"); + iarg += 2; } else error->all(FLERR,"Illegal package gpu command"); } @@ -186,6 +193,16 @@ FixGPU::FixGPU(LAMMPS *lmp, int narg, char **arg) : if (force->newton_pair || force->newton_bond) force->newton = 1; else force->newton = 0; + if (pair_only_flag) { + lmp->suffixp = lmp->suffix; + lmp->suffix = nullptr; + } else { + if (lmp->suffixp) { + lmp->suffix = lmp->suffixp; + lmp->suffixp = nullptr; + } + } + // pass params to GPU library // change binsize default (0.0) to -1.0 used by GPU lib diff --git a/src/GPU/pair_lj_cubic_gpu.cpp b/src/GPU/pair_lj_cubic_gpu.cpp index a669d52a19..35062a5d71 100644 --- a/src/GPU/pair_lj_cubic_gpu.cpp +++ b/src/GPU/pair_lj_cubic_gpu.cpp @@ -16,10 +16,11 @@ ------------------------------------------------------------------------- */ #include "pair_lj_cubic_gpu.h" + #include #include - #include + #include "atom.h" #include "atom_vec.h" #include "comm.h" @@ -36,6 +37,8 @@ #include "gpu_extra.h" #include "suffix.h" +#include "pair_lj_cubic_const.h" + using namespace LAMMPS_NS; using namespace PairLJCubicConstants; diff --git a/src/KIM/kim_interactions.cpp b/src/KIM/kim_interactions.cpp index 5eb01d7ced..afb1391606 100644 --- a/src/KIM/kim_interactions.cpp +++ b/src/KIM/kim_interactions.cpp @@ -291,10 +291,10 @@ void KimInteractions::KIM_SET_TYPE_PARAMETERS(const std::string &input_line) con MPI_Bcast(&n,1,MPI_INT,0,world); MPI_Bcast(line,n,MPI_CHAR,0,world); - if (ptr = strchr(line,'#')) *ptr = '\0'; - if (strspn(line," \t\n\r") == strlen(line)) continue; + auto trimmed = utils::trim_comment(line); + if (trimmed.find_first_not_of(" \t\n\r") == std::string::npos) continue; - words = utils::split_words(line); + words = utils::split_words(trimmed); if (key == "pair") { for (int ia = 0; ia < atom->ntypes; ++ia) { for (int ib = ia; ib < atom->ntypes; ++ib) diff --git a/src/KIM/pair_kim.cpp b/src/KIM/pair_kim.cpp index 7ff067dcac..ee6f5f98a5 100644 --- a/src/KIM/pair_kim.cpp +++ b/src/KIM/pair_kim.cpp @@ -890,7 +890,7 @@ void PairKIM::set_argument_pointers() KIM_SUPPORT_STATUS_notSupported)) { if (KIM_SupportStatus_Equal(kim_model_support_for_energy, KIM_SUPPORT_STATUS_required) - || (eflag_global == 1)) { + || (eflag_global != 0)) { kimerror = kimerror || KIM_ComputeArguments_SetArgumentPointerDouble( pargs,KIM_COMPUTE_ARGUMENT_NAME_partialEnergy,&(eng_vdwl)); @@ -905,7 +905,7 @@ void PairKIM::set_argument_pointers() // Set KIM pointer appropriately for particalEnergy if (KIM_SupportStatus_Equal(kim_model_support_for_particleEnergy, KIM_SUPPORT_STATUS_required) - && (eflag_atom != 1)) { + && (eflag_atom == 0)) { // reallocate per-atom energy array if necessary if (atom->nmax > maxeatom) { maxeatom = atom->nmax; @@ -916,13 +916,13 @@ void PairKIM::set_argument_pointers() if (KIM_SupportStatus_Equal(kim_model_support_for_particleEnergy, KIM_SUPPORT_STATUS_optional) - && (eflag_atom != 1)) { + && (eflag_atom == 0)) { kimerror = kimerror || KIM_ComputeArguments_SetArgumentPointerDouble( pargs, KIM_COMPUTE_ARGUMENT_NAME_partialParticleEnergy, static_cast(nullptr)); } else if (KIM_SupportStatus_NotEqual(kim_model_support_for_particleEnergy, - KIM_SUPPORT_STATUS_notSupported)) { + KIM_SUPPORT_STATUS_notSupported)) { kimerror = kimerror || KIM_ComputeArguments_SetArgumentPointerDouble( pargs, KIM_COMPUTE_ARGUMENT_NAME_partialParticleEnergy, eatom); } @@ -940,9 +940,9 @@ void PairKIM::set_argument_pointers() } // Set KIM pointer appropriately for particleVirial - if ((vflag_atom == 0) && - KIM_SupportStatus_Equal(kim_model_support_for_particleVirial, - KIM_SUPPORT_STATUS_required)) { + if (KIM_SupportStatus_Equal(kim_model_support_for_particleVirial, + KIM_SUPPORT_STATUS_required) + && (vflag_atom == 0)) { // reallocate per-atom virial array if necessary if (atom->nmax > maxvatom) { maxvatom = atom->nmax; @@ -951,9 +951,9 @@ void PairKIM::set_argument_pointers() } } - if ((vflag_atom == 0) && - KIM_SupportStatus_Equal(kim_model_support_for_particleVirial, - KIM_SUPPORT_STATUS_optional)) { + if (KIM_SupportStatus_Equal(kim_model_support_for_particleVirial, + KIM_SUPPORT_STATUS_optional) + && (vflag_atom == 0)) { kimerror = kimerror || KIM_ComputeArguments_SetArgumentPointerDouble( pargs, KIM_COMPUTE_ARGUMENT_NAME_partialParticleVirial, diff --git a/src/KOKKOS/atom_vec_angle_kokkos.cpp b/src/KOKKOS/atom_vec_angle_kokkos.cpp index 827929f1a4..b15fc2965b 100644 --- a/src/KOKKOS/atom_vec_angle_kokkos.cpp +++ b/src/KOKKOS/atom_vec_angle_kokkos.cpp @@ -24,8 +24,6 @@ using namespace LAMMPS_NS; -#define DELTA 10 - /* ---------------------------------------------------------------------- */ AtomVecAngleKokkos::AtomVecAngleKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) @@ -59,6 +57,7 @@ AtomVecAngleKokkos::AtomVecAngleKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) void AtomVecAngleKokkos::grow(int n) { + auto DELTA = LMP_KOKKOS_AV_DELTA; int step = MAX(DELTA,nmax*0.01); if (n == 0) nmax += step; else nmax = n; diff --git a/src/KOKKOS/atom_vec_atomic_kokkos.cpp b/src/KOKKOS/atom_vec_atomic_kokkos.cpp index b25cefae34..013b55c959 100644 --- a/src/KOKKOS/atom_vec_atomic_kokkos.cpp +++ b/src/KOKKOS/atom_vec_atomic_kokkos.cpp @@ -24,8 +24,6 @@ using namespace LAMMPS_NS; -#define DELTA 10 - /* ---------------------------------------------------------------------- */ AtomVecAtomicKokkos::AtomVecAtomicKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) @@ -55,6 +53,7 @@ AtomVecAtomicKokkos::AtomVecAtomicKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) void AtomVecAtomicKokkos::grow(int n) { + auto DELTA = LMP_KOKKOS_AV_DELTA; int step = MAX(DELTA,nmax*0.01); if (n == 0) nmax += step; else nmax = n; diff --git a/src/KOKKOS/atom_vec_bond_kokkos.cpp b/src/KOKKOS/atom_vec_bond_kokkos.cpp index 8908ad9b29..91d7dbef63 100644 --- a/src/KOKKOS/atom_vec_bond_kokkos.cpp +++ b/src/KOKKOS/atom_vec_bond_kokkos.cpp @@ -24,8 +24,6 @@ using namespace LAMMPS_NS; -#define DELTA 10 - /* ---------------------------------------------------------------------- */ AtomVecBondKokkos::AtomVecBondKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) @@ -58,6 +56,7 @@ AtomVecBondKokkos::AtomVecBondKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) void AtomVecBondKokkos::grow(int n) { + auto DELTA = LMP_KOKKOS_AV_DELTA; int step = MAX(DELTA,nmax*0.01); if (n == 0) nmax += step; else nmax = n; diff --git a/src/KOKKOS/atom_vec_charge_kokkos.cpp b/src/KOKKOS/atom_vec_charge_kokkos.cpp index 6dd3880c20..698703371f 100644 --- a/src/KOKKOS/atom_vec_charge_kokkos.cpp +++ b/src/KOKKOS/atom_vec_charge_kokkos.cpp @@ -24,8 +24,6 @@ using namespace LAMMPS_NS; -#define DELTA 10 - /* ---------------------------------------------------------------------- */ AtomVecChargeKokkos::AtomVecChargeKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) @@ -58,6 +56,7 @@ AtomVecChargeKokkos::AtomVecChargeKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) void AtomVecChargeKokkos::grow(int n) { + auto DELTA = LMP_KOKKOS_AV_DELTA; int step = MAX(DELTA,nmax*0.01); if (n == 0) nmax += step; else nmax = n; diff --git a/src/KOKKOS/atom_vec_dpd_kokkos.cpp b/src/KOKKOS/atom_vec_dpd_kokkos.cpp index cd4bb76d05..8a733f66e4 100644 --- a/src/KOKKOS/atom_vec_dpd_kokkos.cpp +++ b/src/KOKKOS/atom_vec_dpd_kokkos.cpp @@ -24,8 +24,6 @@ using namespace LAMMPS_NS; -#define DELTA 10 - /* ---------------------------------------------------------------------- */ AtomVecDPDKokkos::AtomVecDPDKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) @@ -60,6 +58,7 @@ AtomVecDPDKokkos::AtomVecDPDKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) void AtomVecDPDKokkos::grow(int n) { + auto DELTA = LMP_KOKKOS_AV_DELTA; int step = MAX(DELTA,nmax*0.01); if (n == 0) nmax += step; else nmax = n; diff --git a/src/KOKKOS/atom_vec_full_kokkos.cpp b/src/KOKKOS/atom_vec_full_kokkos.cpp index 032b36ff4a..2c85e4129b 100644 --- a/src/KOKKOS/atom_vec_full_kokkos.cpp +++ b/src/KOKKOS/atom_vec_full_kokkos.cpp @@ -24,8 +24,6 @@ using namespace LAMMPS_NS; -#define DELTA 10 - /* ---------------------------------------------------------------------- */ AtomVecFullKokkos::AtomVecFullKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) @@ -58,6 +56,7 @@ AtomVecFullKokkos::AtomVecFullKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) void AtomVecFullKokkos::grow(int n) { + auto DELTA = LMP_KOKKOS_AV_DELTA; int step = MAX(DELTA,nmax*0.01); if (n == 0) nmax += step; else nmax = n; diff --git a/src/KOKKOS/atom_vec_kokkos.cpp b/src/KOKKOS/atom_vec_kokkos.cpp index e6caa59859..35ed9160d2 100644 --- a/src/KOKKOS/atom_vec_kokkos.cpp +++ b/src/KOKKOS/atom_vec_kokkos.cpp @@ -16,6 +16,7 @@ #include "atom_kokkos.h" #include "atom_masks.h" #include "comm_kokkos.h" +#include "error.h" #include "domain.h" using namespace LAMMPS_NS; @@ -32,6 +33,22 @@ AtomVecKokkos::AtomVecKokkos(LAMMPS *lmp) : AtomVec(lmp) no_border_vel_flag = 1; } +/* ---------------------------------------------------------------------- + roundup N so it is a multiple of DELTA + error if N exceeds 32-bit int, since will be used as arg to grow() + overload needed because Kokkos uses a smaller DELTA than in atom_vec.cpp + and an exponential instead of a linear growth +------------------------------------------------------------------------- */ + +bigint AtomVecKokkos::roundup(bigint n) +{ + auto DELTA = LMP_KOKKOS_AV_DELTA; + if (n % DELTA) n = n/DELTA * DELTA + DELTA; + if (n > MAXSMALLINT) + error->one(FLERR,"Too many atoms created on one or more procs"); + return n; +} + /* ---------------------------------------------------------------------- */ template diff --git a/src/KOKKOS/atom_vec_kokkos.h b/src/KOKKOS/atom_vec_kokkos.h index 09f02f61e2..9fbf172535 100644 --- a/src/KOKKOS/atom_vec_kokkos.h +++ b/src/KOKKOS/atom_vec_kokkos.h @@ -36,6 +36,7 @@ class AtomVecKokkos : public AtomVec { public: AtomVecKokkos(class LAMMPS *); virtual ~AtomVecKokkos() {} + bigint roundup(bigint); virtual int pack_comm(int, int *, double *, int, int *); virtual int pack_comm_vel(int, int *, double *, int, int *); virtual void unpack_comm(int, int, double *); diff --git a/src/KOKKOS/atom_vec_molecular_kokkos.cpp b/src/KOKKOS/atom_vec_molecular_kokkos.cpp index f54005e87a..20a748191c 100644 --- a/src/KOKKOS/atom_vec_molecular_kokkos.cpp +++ b/src/KOKKOS/atom_vec_molecular_kokkos.cpp @@ -24,8 +24,6 @@ using namespace LAMMPS_NS; -#define DELTA 10 - /* ---------------------------------------------------------------------- */ AtomVecMolecularKokkos::AtomVecMolecularKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) @@ -58,6 +56,7 @@ AtomVecMolecularKokkos::AtomVecMolecularKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) void AtomVecMolecularKokkos::grow(int n) { + auto DELTA = LMP_KOKKOS_AV_DELTA; int step = MAX(DELTA,nmax*0.01); if (n == 0) nmax += step; else nmax = n; diff --git a/src/KOKKOS/atom_vec_sphere_kokkos.cpp b/src/KOKKOS/atom_vec_sphere_kokkos.cpp index f5973c9ab9..22d10e4632 100644 --- a/src/KOKKOS/atom_vec_sphere_kokkos.cpp +++ b/src/KOKKOS/atom_vec_sphere_kokkos.cpp @@ -30,8 +30,6 @@ using namespace LAMMPS_NS; using namespace MathConst; -#define DELTA 10 - /* ---------------------------------------------------------------------- */ AtomVecSphereKokkos::AtomVecSphereKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) @@ -91,6 +89,7 @@ void AtomVecSphereKokkos::init() void AtomVecSphereKokkos::grow(int n) { + auto DELTA = LMP_KOKKOS_AV_DELTA; int step = MAX(DELTA,nmax*0.01); if (n == 0) nmax += step; else nmax = n; diff --git a/src/KOKKOS/compute_orientorder_atom_kokkos.cpp b/src/KOKKOS/compute_orientorder_atom_kokkos.cpp index 1323e589d3..3703769e90 100644 --- a/src/KOKKOS/compute_orientorder_atom_kokkos.cpp +++ b/src/KOKKOS/compute_orientorder_atom_kokkos.cpp @@ -21,6 +21,7 @@ #include "atom_masks.h" #include "kokkos.h" #include "math_const.h" +#include "math_special.h" #include "memory_kokkos.h" #include "neigh_list.h" #include "neigh_request.h" @@ -32,6 +33,7 @@ using namespace LAMMPS_NS; using namespace MathConst; +using namespace MathSpecial; using namespace std; #ifdef DBL_EPSILON diff --git a/src/KOKKOS/kokkos.cpp b/src/KOKKOS/kokkos.cpp index 64455fef4f..ff1b736bf0 100644 --- a/src/KOKKOS/kokkos.cpp +++ b/src/KOKKOS/kokkos.cpp @@ -301,6 +301,7 @@ KokkosLMP::~KokkosLMP() void KokkosLMP::accelerator(int narg, char **arg) { + int pair_only_flag = 0; int iarg = 0; while (iarg < narg) { if (strcmp(arg[iarg],"neigh") == 0) { @@ -390,6 +391,12 @@ void KokkosLMP::accelerator(int narg, char **arg) else if (strcmp(arg[iarg+1],"on") == 0) gpu_aware_flag = 1; else error->all(FLERR,"Illegal package kokkos command"); iarg += 2; + } else if (strcmp(arg[iarg],"pair/only") == 0) { + if (iarg+2 > narg) error->all(FLERR,"Illegal package kokkos command"); + if (strcmp(arg[iarg+1],"off") == 0) pair_only_flag = 0; + else if (strcmp(arg[iarg+1],"on") == 0) pair_only_flag = 1; + else error->all(FLERR,"Illegal package kokkos command"); + iarg += 2; } else if (strcmp(arg[iarg],"neigh/thread") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal package kokkos command"); if (strcmp(arg[iarg+1],"off") == 0) neigh_thread = 0; @@ -402,39 +409,52 @@ void KokkosLMP::accelerator(int narg, char **arg) #ifdef LMP_KOKKOS_GPU + if (pair_only_flag) { + lmp->suffixp = lmp->suffix; + lmp->suffix = new char[7]; + strcpy(lmp->suffix,"kk/host"); + } else { + // restore settings to regular suffix use, if previously, pair/only was used + if (lmp->suffixp) { + delete[] lmp->suffix; + lmp->suffix = lmp->suffixp; + lmp->suffixp = nullptr; + } + } + int nmpi = 0; MPI_Comm_size(world,&nmpi); - // if "cuda/aware off" and "comm device", change to "comm host" + // if "cuda/aware off" or "pair/only on", and "comm device", change to "comm no" - if (!gpu_aware_flag && nmpi > 1) { + if ((!gpu_aware_flag && nmpi > 1) || pair_only_flag) { if (exchange_comm_classic == 0 && exchange_comm_on_host == 0) { - exchange_comm_on_host = 1; + exchange_comm_classic = 1; exchange_comm_changed = 1; } if (forward_comm_classic == 0 && forward_comm_on_host == 0) { - forward_comm_on_host = 1; + forward_comm_classic = 1; forward_comm_changed = 1; } if (reverse_comm_classic == 0 && reverse_comm_on_host == 0) { - reverse_comm_on_host = 1; + reverse_comm_classic = 1; reverse_comm_changed = 1; } } - // if "cuda/aware on" and comm flags were changed previously, change them back + // if "cuda/aware on" and "pair/only off", and comm flags were changed previously, change them back - if (gpu_aware_flag) { + if (gpu_aware_flag && !pair_only_flag) { if (exchange_comm_changed) { - exchange_comm_on_host = 0; + exchange_comm_classic = 0; exchange_comm_changed = 0; } if (forward_comm_changed) { - forward_comm_on_host = 0; + forward_comm_classic = 0; forward_comm_changed = 0; } if (reverse_comm_changed) { - reverse_comm_on_host = 0; + reverse_comm_classic = 0; reverse_comm_changed = 0; } } diff --git a/src/KOKKOS/kokkos_type.h b/src/KOKKOS/kokkos_type.h index 580b22d35f..72513d2b17 100644 --- a/src/KOKKOS/kokkos_type.h +++ b/src/KOKKOS/kokkos_type.h @@ -15,6 +15,7 @@ #define LMP_LMPTYPE_KOKKOS_H #include "pointers.h" +#include "lmptype.h" #include #include @@ -40,7 +41,7 @@ enum{FULL=1u,HALFTHREAD=2u,HALF=4u}; #endif #define MAX_TYPES_STACKPARAMS 12 -#define NeighClusterSize 8 +static constexpr LAMMPS_NS::bigint LMP_KOKKOS_AV_DELTA = 10; namespace Kokkos { using NoInit = ViewAllocateWithoutInitializing; diff --git a/src/KOKKOS/pair_zbl_kokkos.cpp b/src/KOKKOS/pair_zbl_kokkos.cpp index 2cbe65dcf7..4e7e67a074 100644 --- a/src/KOKKOS/pair_zbl_kokkos.cpp +++ b/src/KOKKOS/pair_zbl_kokkos.cpp @@ -30,6 +30,8 @@ #include "atom_masks.h" #include "kokkos.h" +#include "pair_zbl_const.h" + // From J.F. Zeigler, J. P. Biersack and U. Littmark, // "The Stopping and Range of Ions in Matter" volume 1, Pergamon, 1985. diff --git a/src/MANYBODY/pair_comb.h b/src/MANYBODY/pair_comb.h index 7a3d279033..f809dfaf0e 100644 --- a/src/MANYBODY/pair_comb.h +++ b/src/MANYBODY/pair_comb.h @@ -38,7 +38,7 @@ class PairComb : public Pair { virtual double yasu_char(double *, int &); double enegtot; - static const int NPARAMS_PER_LINE = 49; + static constexpr int NPARAMS_PER_LINE = 49; protected: struct Param { diff --git a/src/MANYBODY/pair_comb3.h b/src/MANYBODY/pair_comb3.h index 567859127b..b1c216fee6 100644 --- a/src/MANYBODY/pair_comb3.h +++ b/src/MANYBODY/pair_comb3.h @@ -37,7 +37,7 @@ class PairComb3 : public Pair { virtual double combqeq(double *, int &); double enegtot; - static const int NPARAMS_PER_LINE = 74; + static constexpr int NPARAMS_PER_LINE = 74; protected: // general potential parameters diff --git a/src/MANYBODY/pair_gw.h b/src/MANYBODY/pair_gw.h index 77ff5c0399..2dbf3dcf84 100644 --- a/src/MANYBODY/pair_gw.h +++ b/src/MANYBODY/pair_gw.h @@ -34,7 +34,7 @@ class PairGW : public Pair { void init_style(); double init_one(int, int); - static const int NPARAMS_PER_LINE = 17; + static constexpr int NPARAMS_PER_LINE = 17; protected: struct Param { diff --git a/src/MANYBODY/pair_gw_zbl.h b/src/MANYBODY/pair_gw_zbl.h index 95129c4eb8..de344e94f7 100644 --- a/src/MANYBODY/pair_gw_zbl.h +++ b/src/MANYBODY/pair_gw_zbl.h @@ -29,7 +29,7 @@ class PairGWZBL : public PairGW { PairGWZBL(class LAMMPS *); ~PairGWZBL() {} - static const int NPARAMS_PER_LINE = 21; + static constexpr int NPARAMS_PER_LINE = 21; private: double global_a_0; // Bohr radius for Coulomb repulsion diff --git a/src/MANYBODY/pair_nb3b_harmonic.h b/src/MANYBODY/pair_nb3b_harmonic.h index 0267b6d0e2..b68974e15f 100644 --- a/src/MANYBODY/pair_nb3b_harmonic.h +++ b/src/MANYBODY/pair_nb3b_harmonic.h @@ -34,7 +34,7 @@ class PairNb3bHarmonic : public Pair { double init_one(int, int); void init_style(); - static const int NPARAMS_PER_LINE = 6; + static constexpr int NPARAMS_PER_LINE = 6; protected: struct Param { diff --git a/src/MANYBODY/pair_sw.h b/src/MANYBODY/pair_sw.h index 441b1c0303..4fdc538430 100644 --- a/src/MANYBODY/pair_sw.h +++ b/src/MANYBODY/pair_sw.h @@ -34,7 +34,7 @@ class PairSW : public Pair { virtual double init_one(int, int); virtual void init_style(); - static const int NPARAMS_PER_LINE = 14; + static constexpr int NPARAMS_PER_LINE = 14; struct Param { double epsilon,sigma; diff --git a/src/MANYBODY/pair_tersoff.h b/src/MANYBODY/pair_tersoff.h index 1fa4e0c608..db891027eb 100644 --- a/src/MANYBODY/pair_tersoff.h +++ b/src/MANYBODY/pair_tersoff.h @@ -34,7 +34,7 @@ class PairTersoff : public Pair { virtual void init_style(); double init_one(int, int); - static const int NPARAMS_PER_LINE = 17; + static constexpr int NPARAMS_PER_LINE = 17; protected: diff --git a/src/MANYBODY/pair_tersoff_mod.h b/src/MANYBODY/pair_tersoff_mod.h index 1e3cee2bcf..7b5a32fbd1 100644 --- a/src/MANYBODY/pair_tersoff_mod.h +++ b/src/MANYBODY/pair_tersoff_mod.h @@ -30,7 +30,7 @@ class PairTersoffMOD : public PairTersoff { PairTersoffMOD(class LAMMPS *); ~PairTersoffMOD() {} - static const int NPARAMS_PER_LINE = 20; + static constexpr int NPARAMS_PER_LINE = 20; protected: virtual void read_file(char *); diff --git a/src/MANYBODY/pair_tersoff_mod_c.h b/src/MANYBODY/pair_tersoff_mod_c.h index bad5f988be..4949cb76db 100644 --- a/src/MANYBODY/pair_tersoff_mod_c.h +++ b/src/MANYBODY/pair_tersoff_mod_c.h @@ -29,7 +29,7 @@ class PairTersoffMODC : public PairTersoffMOD { PairTersoffMODC(class LAMMPS *lmp) : PairTersoffMOD(lmp) {}; ~PairTersoffMODC() {} - static const int NPARAMS_PER_LINE = 21; + static constexpr int NPARAMS_PER_LINE = 21; protected: void read_file(char *); diff --git a/src/MANYBODY/pair_tersoff_zbl.h b/src/MANYBODY/pair_tersoff_zbl.h index be3f496b62..42483b7d89 100644 --- a/src/MANYBODY/pair_tersoff_zbl.h +++ b/src/MANYBODY/pair_tersoff_zbl.h @@ -29,7 +29,7 @@ class PairTersoffZBL : public PairTersoff { PairTersoffZBL(class LAMMPS *); ~PairTersoffZBL() {} - static const int NPARAMS_PER_LINE = 21; + static constexpr int NPARAMS_PER_LINE = 21; protected: double global_a_0; // Bohr radius for Coulomb repulsion diff --git a/src/MANYBODY/pair_vashishta.h b/src/MANYBODY/pair_vashishta.h index bd250d328a..19a8e01cd9 100644 --- a/src/MANYBODY/pair_vashishta.h +++ b/src/MANYBODY/pair_vashishta.h @@ -34,7 +34,7 @@ class PairVashishta : public Pair { double init_one(int, int); void init_style(); - static const int NPARAMS_PER_LINE = 17; + static constexpr int NPARAMS_PER_LINE = 17; struct Param { double bigb,gamma,r0,bigc,costheta; diff --git a/src/MLIAP/Install.sh b/src/MLIAP/Install.sh new file mode 100755 index 0000000000..e6ba4042a9 --- /dev/null +++ b/src/MLIAP/Install.sh @@ -0,0 +1,67 @@ +# Install/unInstall package files in LAMMPS +# mode = 0/1/2 for uninstall/install/update + +mode=$1 + +# arg1 = file, arg2 = file it depends on + +# enforce using portable C locale +LC_ALL=C +export LC_ALL + +action () { + if (test $mode = 0) then + rm -f ../$1 + elif (! cmp -s $1 ../$1) then + if (test -z "$2" || test -e ../$2) then + cp $1 .. + if (test $mode = 2) then + echo " updating src/$1" + fi + fi + elif (test -n "$2") then + if (test ! -e ../$2) then + rm -f ../$1 + fi + fi +} + +# enforce package dependency +if (test $1 = 1 || test $1 = 2) then + if (test ! -e ../sna.h) then + echo "Must install SNAP package to use MLIAP package" + exit 1 + fi +fi + +# all package files with no dependencies + +for file in *.cpp *.h *.pyx; do + test -f ${file} && action $file +done + +# edit 2 Makefile.package files to include/exclude package info + +if (test $1 = 1) then + if (test "$(type cythonize 2> /dev/null)" != "" && test -e ../python_impl.cpp) then + if (test -e ../Makefile.package) then + sed -i -e 's|^PKG_INC =[ \t]*|&-DMLIAP_PYTHON |' ../Makefile.package + fi + if (test -e ../Makefile.package.settings) then + sed -i -e '/^include.*python.*mliap_python.*$/d' ../Makefile.package.settings + # multiline form needed for BSD sed on Macs + sed -i -e '4 i \ +include ..\/..\/lib\/python\/Makefile.mliap_python +' ../Makefile.package.settings + fi + cythonize -3 ../mliap_model_python_couple.pyx + fi + +elif (test $1 = 0) then + + if (test -e ../Makefile.package) then + sed -i -e 's/[^ \t]*-DMLIAP_PYTHON[^ \t]* //g' ../Makefile.package + fi + rm -f ../mliap_model_python_couple.cpp ../mliap_model_python_couple.h + sed -i -e '/^include.*python.*mliap_python.*$/d' ../Makefile.package.settings +fi diff --git a/src/MLIAP/README b/src/MLIAP/README index 18ce3297e6..59eb5e34b3 100644 --- a/src/MLIAP/README +++ b/src/MLIAP/README @@ -8,12 +8,15 @@ definitions of the interatomic potential functional form (*model*) and the geometric quantities that characterize the atomic positions (*descriptor*). By defining *model* and *descriptor* separately, it is possible to use many different models with a given descriptor, -or many different descriptors with a given model. Currently, the pair_style -supports just two models, *linear* and *quadratic*, -and one descriptor, *sna*, the SNAP descriptor, including the -linear, quadratic, and chem variants. Work is currently underway to extend -the interface to handle neural network energy models, -and it is also straightforward to add new descriptor styles. +or many different descriptors with a given model. The pair_style +supports the following models: *linear*, *quadratic*, and +*mliappy* (general Python interface to things like PyTorch, see below +for build instructions). +It currently supports only one class of descriptors, +*sna*, the SNAP descriptors, including the +linear, quadratic, and chem variants. +It is straightforward to add new descriptor and model +styles. The mliap compute style provides gradients of the energy, force, and stress tensor w.r.t. model parameters. @@ -27,4 +30,28 @@ reference potential. To see how this command can be used within a Python workflow to train machine-learning interatomic -potentials, see the examples in FitSNAP https://github.com/FitSNAP/FitSNAP>. +potentials, see the examples in FitSNAP https://github.com/FitSNAP/FitSNAP. + +*Additional instructions for building MLIAP with Python support enabled* + +The *mliappy* energy model requires that the MLIAP package +be compiled with Python support enabled. +This extension, written by Nick Lubbers (LANL), +provides a coupling to PyTorch and other Python modules. +This should be automatically +enabled by default if the prerequisite software is installed. It can be +enforced during CMake configuration by setting the variable +MLIAP_ENABLE_PYTHON=yes or for conventional build by adding -DMLIAP_PYTHON +to the LMP_INC variable in your makefile and running the cythonize script +on the .pyx file(s) copied to the src folder. + +This requires to also install the PYTHON package and have the cython +(https://cython.org) software installed. During configuration/compilation +the cythonize script will be used to convert the provided .pyx file(s) +to C++ code. Please do not run the cythonize script in the src/MLIAP folder. +If you have done so by accident, you need to delete the generated .cpp and .h +file(s) in the src/MLIAP folder or there may be problems during compilation. + +More information on building LAMMPS with this package is here: + +https://lammps.sandia.gov/doc/Build_extras.html#mliap diff --git a/src/MLIAP/compute_mliap.cpp b/src/MLIAP/compute_mliap.cpp index 34d086462f..0842e421c0 100644 --- a/src/MLIAP/compute_mliap.cpp +++ b/src/MLIAP/compute_mliap.cpp @@ -11,12 +11,20 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- + Contributing author: Aidan Thompson (SNL) +------------------------------------------------------------------------- */ + #include #include "mliap_data.h" #include "mliap_model_linear.h" #include "mliap_model_quadratic.h" #include "mliap_descriptor_snap.h" +#ifdef MLIAP_PYTHON +#include "mliap_model_python.h" +#endif + #include "compute_mliap.h" #include "atom.h" #include "update.h" @@ -65,7 +73,14 @@ ComputeMLIAP::ComputeMLIAP(LAMMPS *lmp, int narg, char **arg) : } else if (strcmp(arg[iarg+1],"quadratic") == 0) { model = new MLIAPModelQuadratic(lmp); iarg += 2; - } else error->all(FLERR,"Illegal compute mliap command"); + } +#ifdef MLIAP_PYTHON + else if (strcmp(arg[iarg+1],"mliappy") == 0) { + model = new MLIAPModelPython(lmp); + iarg += 2; + } +#endif + else error->all(FLERR,"Illegal compute mliap command"); modelflag = 1; } else if (strcmp(arg[iarg],"descriptor") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal compute mliap command"); diff --git a/src/MLIAP/mliap_data.cpp b/src/MLIAP/mliap_data.cpp index e6502d001a..c310f0efc7 100644 --- a/src/MLIAP/mliap_data.cpp +++ b/src/MLIAP/mliap_data.cpp @@ -11,6 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- + Contributing author: Aidan Thompson (SNL) +------------------------------------------------------------------------- */ + #include "mliap_data.h" #include "atom.h" @@ -25,7 +29,8 @@ MLIAPData::MLIAPData(LAMMPS *lmp, int gradgradflag_in, int *map_in, class MLIAPModel* model_in, class MLIAPDescriptor* descriptor_in, class PairMLIAP* pairmliap_in) : - Pointers(lmp), gradforce(nullptr), betas(nullptr), descriptors(nullptr), gamma(nullptr), + Pointers(lmp), gradforce(nullptr), betas(nullptr), + descriptors(nullptr), eatoms(nullptr), gamma(nullptr), gamma_row_index(nullptr), gamma_col_index(nullptr), egradient(nullptr), numneighs(nullptr), iatoms(nullptr), ielems(nullptr), jatoms(nullptr), jelems(nullptr), rij(nullptr), graddesc(nullptr), model(nullptr), descriptor(nullptr), list(nullptr) @@ -64,6 +69,7 @@ MLIAPData::~MLIAPData() { memory->destroy(betas); memory->destroy(descriptors); + memory->destroy(eatoms); memory->destroy(gamma_row_index); memory->destroy(gamma_col_index); memory->destroy(gamma); @@ -133,6 +139,7 @@ void MLIAPData::generate_neighdata(NeighList* list_in, int eflag_in, int vflag_i if (natoms_max < natoms) { memory->grow(betas,natoms,ndescriptors,"MLIAPData:betas"); memory->grow(descriptors,natoms,ndescriptors,"MLIAPData:descriptors"); + memory->grow(eatoms,natoms,"MLIAPData:eatoms"); natoms_max = natoms; } @@ -267,6 +274,7 @@ double MLIAPData::memory_usage() bytes += natoms*ndescriptors*sizeof(int); // betas bytes += natoms*ndescriptors*sizeof(int); // descriptors + bytes += natoms*sizeof(double); // eatoms bytes += natomneigh_max*sizeof(int); // iatoms bytes += natomneigh_max*sizeof(int); // ielems diff --git a/src/MLIAP/mliap_data.h b/src/MLIAP/mliap_data.h index ffac9ccd4c..7fb60bd723 100644 --- a/src/MLIAP/mliap_data.h +++ b/src/MLIAP/mliap_data.h @@ -34,8 +34,10 @@ class MLIAPData : protected Pointers { int yoffset, zoffset; int ndims_force, ndims_virial; double **gradforce; - double** betas; // betas for all atoms in list + double** betas; // betas for all atoms in list double** descriptors; // descriptors for all atoms in list + double* eatoms; // energies for all atoms in list + double energy; // energy int ndescriptors; // number of descriptors int nparams; // number of model parameters per element int nelements; // number of elements diff --git a/src/MLIAP/mliap_descriptor.cpp b/src/MLIAP/mliap_descriptor.cpp index b3e0cebd2e..ac168dc94b 100644 --- a/src/MLIAP/mliap_descriptor.cpp +++ b/src/MLIAP/mliap_descriptor.cpp @@ -11,6 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- + Contributing author: Aidan Thompson (SNL) +------------------------------------------------------------------------- */ + #include "mliap_descriptor.h" using namespace LAMMPS_NS; diff --git a/src/MLIAP/mliap_descriptor_snap.cpp b/src/MLIAP/mliap_descriptor_snap.cpp index cfbc51cb5c..2cb88de6b4 100644 --- a/src/MLIAP/mliap_descriptor_snap.cpp +++ b/src/MLIAP/mliap_descriptor_snap.cpp @@ -11,6 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- + Contributing author: Aidan Thompson (SNL) +------------------------------------------------------------------------- */ + #include "mliap_descriptor_snap.h" #include "atom.h" diff --git a/src/MLIAP/mliap_model.cpp b/src/MLIAP/mliap_model.cpp index 04b2ac663a..aa198e6085 100644 --- a/src/MLIAP/mliap_model.cpp +++ b/src/MLIAP/mliap_model.cpp @@ -11,6 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- + Contributing author: Aidan Thompson (SNL) +------------------------------------------------------------------------- */ + #include "mliap_model.h" #include "comm.h" @@ -28,13 +32,9 @@ using namespace LAMMPS_NS; MLIAPModel::MLIAPModel(LAMMPS* lmp, char* coefffilename) : Pointers(lmp) { - coeffelem = nullptr; - if (coefffilename) read_coeffs(coefffilename); - else { - nparams = 0; - nelements = 0; - ndescriptors = 0; - } + nparams = 0; + nelements = 0; + ndescriptors = 0; nonlinearflag = 0; } @@ -42,9 +42,9 @@ MLIAPModel::MLIAPModel(LAMMPS* lmp, char* coefffilename) : Pointers(lmp) MLIAPModel::~MLIAPModel() { - memory->destroy(coeffelem); } + /* ---------------------------------------------------------------------- placeholder ------------------------------------------------------------------------- */ @@ -73,7 +73,22 @@ void MLIAPModel::set_ndescriptors(int ndescriptors_in) /* ---------------------------------------------------------------------- */ -void MLIAPModel::read_coeffs(char *coefffilename) + +MLIAPModelSimple::MLIAPModelSimple(LAMMPS* lmp, char* coefffilename) : MLIAPModel(lmp, coefffilename) +{ + coeffelem = nullptr; + if (coefffilename) read_coeffs(coefffilename); +} + +/* ---------------------------------------------------------------------- */ + +MLIAPModelSimple::~MLIAPModelSimple() +{ + memory->destroy(coeffelem); +} + + +void MLIAPModelSimple::read_coeffs(char *coefffilename) { // open coefficient file on proc 0 @@ -165,7 +180,7 @@ void MLIAPModel::read_coeffs(char *coefffilename) memory usage ------------------------------------------------------------------------- */ -double MLIAPModel::memory_usage() +double MLIAPModelSimple::memory_usage() { double bytes = 0; diff --git a/src/MLIAP/mliap_model.h b/src/MLIAP/mliap_model.h index b2f7312897..96cfff0a3d 100644 --- a/src/MLIAP/mliap_model.h +++ b/src/MLIAP/mliap_model.h @@ -30,15 +30,26 @@ public: virtual void compute_gradgrads(class MLIAPData*)=0; virtual void compute_force_gradients(class MLIAPData*)=0; virtual void init(); - virtual double memory_usage(); + virtual double memory_usage()=0; int nelements; // # of unique elements - int nonlinearflag; // 1 if gradient() requires escriptors + int nonlinearflag; // 1 if gradient() requires descriptors int ndescriptors; // number of descriptors int nparams; // number of parameters per element protected: - void read_coeffs(char *); + virtual void read_coeffs(char *)=0; +}; + +class MLIAPModelSimple : public MLIAPModel { +public: + MLIAPModelSimple(LAMMPS*, char*); + ~MLIAPModelSimple(); + virtual double memory_usage(); + +protected: double **coeffelem; // element coefficients + virtual void read_coeffs(char *); + }; } diff --git a/src/MLIAP/mliap_model_linear.cpp b/src/MLIAP/mliap_model_linear.cpp index b3224284e5..3c8f9aa39a 100644 --- a/src/MLIAP/mliap_model_linear.cpp +++ b/src/MLIAP/mliap_model_linear.cpp @@ -11,6 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- + Contributing author: Aidan Thompson (SNL) +------------------------------------------------------------------------- */ + #include "mliap_model_linear.h" #include "pair_mliap.h" #include "mliap_data.h" @@ -21,7 +25,7 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ MLIAPModelLinear::MLIAPModelLinear(LAMMPS* lmp, char* coefffilename) : - MLIAPModel(lmp, coefffilename) + MLIAPModelSimple(lmp, coefffilename) { if (nparams > 0) ndescriptors = nparams - 1; } @@ -51,8 +55,9 @@ int MLIAPModelLinear::get_nparams() void MLIAPModelLinear::compute_gradients(MLIAPData* data) { + data->energy = 0.0; + for (int ii = 0; ii < data->natoms; ii++) { - const int i = data->iatoms[ii]; const int ielem = data->ielems[ii]; double* coeffi = coeffelem[ielem]; @@ -74,7 +79,8 @@ void MLIAPModelLinear::compute_gradients(MLIAPData* data) for (int icoeff = 0; icoeff < data->ndescriptors; icoeff++) etmp += coeffi[icoeff+1]*data->descriptors[ii][icoeff]; - data->pairmliap->e_tally(i,etmp); + data->energy += etmp; + data->eatoms[ii] = etmp; } } } diff --git a/src/MLIAP/mliap_model_linear.h b/src/MLIAP/mliap_model_linear.h index 326407faa8..89c69d3537 100644 --- a/src/MLIAP/mliap_model_linear.h +++ b/src/MLIAP/mliap_model_linear.h @@ -18,7 +18,7 @@ namespace LAMMPS_NS { -class MLIAPModelLinear : public MLIAPModel { +class MLIAPModelLinear : public MLIAPModelSimple { public: MLIAPModelLinear(LAMMPS*, char* = nullptr); ~MLIAPModelLinear(); diff --git a/src/MLIAP/mliap_model_python.cpp b/src/MLIAP/mliap_model_python.cpp new file mode 100644 index 0000000000..e47356390f --- /dev/null +++ b/src/MLIAP/mliap_model_python.cpp @@ -0,0 +1,202 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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: Nicholas Lubbers (LANL) +------------------------------------------------------------------------- */ + +#ifdef MLIAP_PYTHON + +#include +#include "mliap_model_python.h" +#include "mliap_model_python_couple.h" +#include "pair_mliap.h" +#include "mliap_data.h" +#include "error.h" +#include "utils.h" +#include "lmppython.h" +#include "python_compat.h" + + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +MLIAPModelPython::MLIAPModelPython(LAMMPS* lmp, char* coefffilename) : + MLIAPModel(lmp, coefffilename) +{ + model_loaded = 0; + python->init(); + PyGILState_STATE gstate = PyGILState_Ensure(); + + PyObject * pyMain = PyImport_AddModule("__main__"); + + if (!pyMain) { + PyGILState_Release(gstate); + error->all(FLERR,"Could not initialize embedded Python"); + } + + PyObject* coupling_module = PyImport_ImportModule("mliap_model_python_couple"); + + if (!coupling_module) { + PyErr_Print(); + PyErr_Clear(); + PyGILState_Release(gstate); + error->all(FLERR,"Loading MLIAPPY coupling module failure."); + } + // 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(".")); + + // if LAMMPS_POTENTIALS environment variable is set, add it to PYTHONPATH as well + const char * potentials_path = getenv("LAMMPS_POTENTIALS"); + if (potentials_path != NULL) { + PyList_Append(py_path, PY_STRING_FROM_STRING(potentials_path)); + } + PyGILState_Release(gstate); + + if (coefffilename) read_coeffs(coefffilename); + + nonlinearflag=1; +} + +/* ---------------------------------------------------------------------- */ + +MLIAPModelPython::~MLIAPModelPython(){ + MLIAPPY_unload_model(this); +} + +/* ---------------------------------------------------------------------- + get number of parameters + ---------------------------------------------------------------------- */ + + +int MLIAPModelPython::get_nparams() +{ + return nparams; +} + +void MLIAPModelPython::read_coeffs(char * fname) +{ + PyGILState_STATE gstate = PyGILState_Ensure(); + + int loaded = MLIAPPY_load_model(this, fname); + if (PyErr_Occurred()) { + PyErr_Print(); + PyErr_Clear(); + PyGILState_Release(gstate); + error->all(FLERR,"Loading python model failure."); + } + PyGILState_Release(gstate); + + if (loaded) { + this->connect_param_counts(); + } + else { + utils::logmesg(lmp,"Loading python model deferred.\n"); + } +} + +// Finalize loading of the model. +void MLIAPModelPython::connect_param_counts() +{ + PyGILState_STATE gstate = PyGILState_Ensure(); + nelements = MLIAPPY_nelements(this); + nparams = MLIAPPY_nparams(this); + ndescriptors = MLIAPPY_ndescriptors(this); + + if (PyErr_Occurred()) { + PyErr_Print(); + PyErr_Clear(); + PyGILState_Release(gstate); + error->all(FLERR,"Loading python model failure."); + } + PyGILState_Release(gstate); + model_loaded = 1; + utils::logmesg(lmp,"Loading python model complete.\n"); + +} + + +/* ---------------------------------------------------------------------- + Calculate model gradients w.r.t descriptors + for each atom beta_i = dE(B_i)/dB_i + ---------------------------------------------------------------------- */ + +void MLIAPModelPython::compute_gradients(MLIAPData* data) +{ + if (not model_loaded) { + error->all(FLERR,"Model not loaded."); + } + + PyGILState_STATE gstate = PyGILState_Ensure(); + MLIAPPY_compute_gradients(this, data); + if (PyErr_Occurred()) { + PyErr_Print(); + PyErr_Clear(); + PyGILState_Release(gstate); + error->all(FLERR,"Running python model failure."); + } + PyGILState_Release(gstate); + +} + +/* ---------------------------------------------------------------------- + Calculate model double gradients w.r.t descriptors and parameters + for each atom energy gamma_lk = d2E(B)/dB_k/dsigma_l, + where sigma_l is a parameter, B_k a descriptor, + and atom subscript i is omitted + + gamma is in CSR format: + nnz = number of non-zero values + gamma_row_index[inz] = l indices, 0 <= l < nparams + gamma_col_indexiinz] = k indices, 0 <= k < ndescriptors + gamma[i][inz] = non-zero values, 0 <= inz < nnz + + egradient is derivative of energy w.r.t. parameters + ---------------------------------------------------------------------- */ + +void MLIAPModelPython::compute_gradgrads(class MLIAPData* data) +{ + error->all(FLERR,"compute_gradgrads not implemented"); +} + +/* ---------------------------------------------------------------------- + calculate gradients of forces w.r.t. parameters + egradient is derivative of energy w.r.t. parameters + ---------------------------------------------------------------------- */ + +void MLIAPModelPython::compute_force_gradients(class MLIAPData* data) +{ + error->all(FLERR,"compute_force_gradients not implemented"); +} + +/* ---------------------------------------------------------------------- + count the number of non-zero entries in gamma matrix + ---------------------------------------------------------------------- */ + +int MLIAPModelPython::get_gamma_nnz(class MLIAPData* data) +{ + // todo: get_gamma_nnz + return 0; +} + + +double MLIAPModelPython::memory_usage() +{ + // todo: get approximate memory usage in coupling code. + return 0; +} + +#endif diff --git a/src/MLIAP/mliap_model_python.h b/src/MLIAP/mliap_model_python.h new file mode 100644 index 0000000000..57110f36e2 --- /dev/null +++ b/src/MLIAP/mliap_model_python.h @@ -0,0 +1,47 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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. +------------------------------------------------------------------------- */ + +#ifndef LMP_MLIAP_MODEL_PYTHON_H +#define LMP_MLIAP_MODEL_PYTHON_H + +#include "mliap_model.h" + +namespace LAMMPS_NS { + + +class MLIAPModelPython : public MLIAPModel { +public: + MLIAPModelPython(LAMMPS*, char* = NULL); + ~MLIAPModelPython(); + virtual int get_nparams(); + virtual int get_gamma_nnz(class MLIAPData*); + virtual void compute_gradients(class MLIAPData*); + virtual void compute_gradgrads(class MLIAPData*); + virtual void compute_force_gradients(class MLIAPData*); + virtual double memory_usage(); + void connect_param_counts(); // If possible convert this to protected/private and + // and figure out how to declare cython fn + // load_from_python as a friend. + int model_loaded; + +protected: + virtual void read_coeffs(char *); + +private: + +}; + +} + +#endif + diff --git a/src/MLIAP/mliap_model_python_couple.pyx b/src/MLIAP/mliap_model_python_couple.pyx new file mode 100644 index 0000000000..1f04964ef6 --- /dev/null +++ b/src/MLIAP/mliap_model_python_couple.pyx @@ -0,0 +1,120 @@ +# cython: language_level=3 +# distutils: language = c++ + +cimport cython + +import pickle + +# For converting C arrays to numpy arrays +import numpy as np + +# For converting void * to integer for tracking object identity +from libc.stdint cimport uintptr_t + +from libcpp.string cimport string + + +cdef extern from "mliap_data.h" namespace "LAMMPS_NS": + cdef cppclass MLIAPData: + # Array shapes + int natoms + int ndescriptors + + # Input data + int * ielems # types for all atoms in list + double ** descriptors # descriptors for all atoms in list + + # Output data to write to + double ** betas # betas for all atoms in list + double * eatoms # energy for all atoms in list + double energy + +cdef extern from "mliap_model_python.h" namespace "LAMMPS_NS": + cdef cppclass MLIAPModelPython: + void connect_param_counts() + + +class MLIAPPYModelNotLinked(Exception): pass + + +LOADED_MODELS = {} + +cdef object c_id(MLIAPModelPython * c_model): + """ + Use python-style id of object to keep track of identity. + Note, this is probably not a perfect general strategy but it should work fine with LAMMPS pair styles. + """ + return int( c_model) + +cdef object retrieve(MLIAPModelPython * c_model) with gil: + try: + model = LOADED_MODELS[c_id(c_model)] + except KeyError as ke: + raise KeyError("Model has not been loaded.") from ke + if model is None: + raise MLIAPPYModelNotLinked("Model not linked, connect the model from the python side.") + return model + +cdef public int MLIAPPY_load_model(MLIAPModelPython * c_model, char* fname) with gil: + str_fname = fname.decode('utf-8') # Python 3 only; not Python 2 not supported. + if str_fname == "LATER": + model = None + returnval = 0 + else: + if str_fname.endswith(".pt") or str_fname.endswith('.pth'): + import torch + model = torch.load(str_fname) + else: + with open(str_fname,'rb') as pfile: + model = pickle.load(pfile) + returnval = 1 + LOADED_MODELS[c_id(c_model)] = model + return returnval + +def load_from_python(model): + unloaded_models = [k for k, v in LOADED_MODELS.items() if v is None] + num_models = len(unloaded_models) + cdef MLIAPModelPython * lmp_model + + if num_models == 0: + raise ValueError("No model in the waiting area.") + elif num_models > 1: + raise ValueError("Model is amibguous, more than one model in waiting area.") + else: + c_id = unloaded_models[0] + LOADED_MODELS[c_id]=model + lmp_model = c_id + lmp_model.connect_param_counts() + + +cdef public void MLIAPPY_unload_model(MLIAPModelPython * c_model) with gil: + del LOADED_MODELS[c_id(c_model)] + +cdef public int MLIAPPY_nparams(MLIAPModelPython * c_model) with gil: + return int(retrieve(c_model).n_params) + +cdef public int MLIAPPY_nelements(MLIAPModelPython * c_model) with gil: + return int(retrieve(c_model).n_elements) + +cdef public int MLIAPPY_ndescriptors(MLIAPModelPython * c_model) with gil: + return int(retrieve(c_model).n_descriptors) + +cdef public void MLIAPPY_compute_gradients(MLIAPModelPython * c_model, MLIAPData * data) with gil: + model = retrieve(c_model) + + n_d = data.ndescriptors + n_a = data.natoms + + # Make numpy arrays from pointers + beta_np = np.asarray( &data.betas[0][0]) + desc_np = np.asarray( &data.descriptors[0][0]) + elem_np = np.asarray( &data.ielems[0]) + en_np = np.asarray( &data.eatoms[0]) + + # Invoke python model on numpy arrays. + model(elem_np,desc_np,beta_np,en_np) + + # Get the total energy from the atom energy. + energy = np.sum(en_np) + data.energy = energy + return diff --git a/src/MLIAP/mliap_model_quadratic.cpp b/src/MLIAP/mliap_model_quadratic.cpp index 481417078a..915ec30435 100644 --- a/src/MLIAP/mliap_model_quadratic.cpp +++ b/src/MLIAP/mliap_model_quadratic.cpp @@ -11,6 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- + Contributing author: Aidan Thompson (SNL) +------------------------------------------------------------------------- */ + #include "mliap_model_quadratic.h" #include "pair_mliap.h" #include "mliap_data.h" @@ -22,8 +26,9 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ MLIAPModelQuadratic::MLIAPModelQuadratic(LAMMPS* lmp, char* coefffilename) : - MLIAPModel(lmp, coefffilename) + MLIAPModelSimple(lmp, coefffilename) { + if (coefffilename) read_coeffs(coefffilename); if (nparams > 0) ndescriptors = sqrt(2*nparams)-1; nonlinearflag = 1; } @@ -52,8 +57,9 @@ int MLIAPModelQuadratic::get_nparams() void MLIAPModelQuadratic::compute_gradients(MLIAPData* data) { + data->energy = 0.0; + for (int ii = 0; ii < data->natoms; ii++) { - const int i = data->iatoms[ii]; const int ielem = data->ielems[ii]; double* coeffi = coeffelem[ielem]; @@ -99,7 +105,8 @@ void MLIAPModelQuadratic::compute_gradients(MLIAPData* data) etmp += coeffi[k++]*bveci*bvecj; } } - data->pairmliap->e_tally(i,etmp); + data->energy += etmp; + data->eatoms[ii] = etmp; } } } diff --git a/src/MLIAP/mliap_model_quadratic.h b/src/MLIAP/mliap_model_quadratic.h index b41df18a07..28f1732f9b 100644 --- a/src/MLIAP/mliap_model_quadratic.h +++ b/src/MLIAP/mliap_model_quadratic.h @@ -18,7 +18,7 @@ namespace LAMMPS_NS { -class MLIAPModelQuadratic : public MLIAPModel { +class MLIAPModelQuadratic : public MLIAPModelSimple { public: MLIAPModelQuadratic(LAMMPS*, char* = nullptr); ~MLIAPModelQuadratic(); diff --git a/src/MLIAP/pair_mliap.cpp b/src/MLIAP/pair_mliap.cpp index a422271f19..0c6f3903f6 100644 --- a/src/MLIAP/pair_mliap.cpp +++ b/src/MLIAP/pair_mliap.cpp @@ -11,12 +11,19 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- + Contributing author: Aidan Thompson (SNL) +------------------------------------------------------------------------- */ + #include "pair_mliap.h" #include "mliap_data.h" #include "mliap_model_linear.h" #include "mliap_model_quadratic.h" #include "mliap_descriptor_snap.h" +#ifdef MLIAP_PYTHON +#include "mliap_model_python.h" +#endif #include "atom.h" #include "error.h" @@ -27,6 +34,7 @@ #include #include +#include "error.h" using namespace LAMMPS_NS; @@ -65,6 +73,17 @@ PairMLIAP::~PairMLIAP() void PairMLIAP::compute(int eflag, int vflag) { + + // consistency checks + + if (data->ndescriptors != model->ndescriptors) { + error->all(FLERR,"Incompatible model and descriptor descriptor count"); + }; + + if (data->nelements != model->nelements) { + error->all(FLERR,"Incompatible model and descriptor element count"); + }; + ev_init(eflag,vflag); data->generate_neighdata(list, eflag, vflag); @@ -78,6 +97,8 @@ void PairMLIAP::compute(int eflag, int vflag) model->compute_gradients(data); + e_tally(data); + // calculate force contributions beta_i*dB_i/dR_j descriptor->compute_forces(data); @@ -107,6 +128,7 @@ void PairMLIAP::allocate() void PairMLIAP::settings(int narg, char ** arg) { + if (narg < 4) error->all(FLERR,"Illegal pair_style command"); @@ -130,6 +152,12 @@ void PairMLIAP::settings(int narg, char ** arg) if (iarg+3 > narg) error->all(FLERR,"Illegal pair_style mliap command"); model = new MLIAPModelQuadratic(lmp,arg[iarg+2]); iarg += 3; +#ifdef MLIAP_PYTHON + } else if (strcmp(arg[iarg+1],"mliappy") == 0) { + if (iarg+3 > narg) error->all(FLERR,"Illegal pair_style mliap command"); + model = new MLIAPModelPython(lmp,arg[iarg+2]); + iarg += 3; +#endif } else error->all(FLERR,"Illegal pair_style mliap command"); modelflag = 1; } else if (strcmp(arg[iarg],"descriptor") == 0) { @@ -211,22 +239,21 @@ void PairMLIAP::coeff(int narg, char **arg) data = new MLIAPData(lmp, gradgradflag, map, model, descriptor, this); data->init(); - // consistency checks - if (data->ndescriptors != model->ndescriptors) - error->all(FLERR,"Incompatible model and descriptor definitions"); - if (data->nelements != model->nelements) - error->all(FLERR,"Incompatible model and descriptor definitions"); } /* ---------------------------------------------------------------------- - add energy of atom i to global and per-atom energy + add energies to eng_vdwl and per-atom energy ------------------------------------------------------------------------- */ -void PairMLIAP::e_tally(int i, double ei) +void PairMLIAP::e_tally(MLIAPData* data) { - if (eflag_global) eng_vdwl += ei; - if (eflag_atom) eatom[i] += ei; + if (eflag_global) eng_vdwl += data->energy; + if (eflag_atom) + for (int ii = 0; ii < data->natoms; ii++) { + const int i = data->iatoms[ii]; + eatom[i] += data->eatoms[ii]; + } } /* ---------------------------------------------------------------------- diff --git a/src/MLIAP/pair_mliap.h b/src/MLIAP/pair_mliap.h index 61acbbb278..c31634e923 100644 --- a/src/MLIAP/pair_mliap.h +++ b/src/MLIAP/pair_mliap.h @@ -31,7 +31,7 @@ public: virtual void compute(int, int); void settings(int, char **); virtual void coeff(int, char **); - void e_tally(int, double); + void e_tally(class MLIAPData*); void v_tally(int, int, double*, double*); virtual void init_style(); virtual double init_one(int, int); diff --git a/src/Makefile b/src/Makefile index 149dedd35b..7a5e1aa728 100644 --- a/src/Makefile +++ b/src/Makefile @@ -278,7 +278,7 @@ mpi-stubs: sinclude ../lib/python/Makefile.lammps install-python: @$(PYTHON) ../python/install.py -v ../src/version.h \ - -m ../python/lammps.py -l ../src/liblammps.so + -p ../python/lammps -l ../src/liblammps.so # Create a tarball of src dir and packages diff --git a/src/PYTHON/python_impl.cpp b/src/PYTHON/python_impl.cpp index 22bf8e77fb..42b1135ceb 100644 --- a/src/PYTHON/python_impl.cpp +++ b/src/PYTHON/python_impl.cpp @@ -26,6 +26,14 @@ #include #include // IWYU pragma: export +#ifdef MLIAP_PYTHON +#include "mliap_model_python.h" +// The above should somehow really be included in the next file. +// We could get around this with cython --capi-reexport-cincludes +// However, that exposes -too many- headers. +#include "mliap_model_python_couple.h" +#endif + using namespace LAMMPS_NS; enum{NONE,INT,DOUBLE,STRING,PTR}; @@ -47,13 +55,27 @@ PythonImpl::PythonImpl(LAMMPS *lmp) : Pointers(lmp) nfunc = 0; pfuncs = nullptr; - // one-time initialization of Python interpreter // pyMain stores pointer to main module external_interpreter = Py_IsInitialized(); +#ifdef MLIAP_PYTHON + // Inform python intialization scheme of the mliappy module. + // This -must- happen before python is initialized. + int err = PyImport_AppendInittab("mliap_model_python_couple", PyInit_mliap_model_python_couple); + if (err) error->all(FLERR,"Could not register MLIAPPY embedded python module."); +#endif + Py_Initialize(); - PyEval_InitThreads(); + + // only needed for Python 2.x and Python 3 < 3.7 + // With Python 3.7 this function is now called by Py_Initialize() + // Deprecated since version 3.9, will be removed in version 3.11 +#if PY_MAJOR_VERSION < 3 || PY_MINOR_VERSION < 7 + if(!PyEval_ThreadsInitialized()) { + PyEval_InitThreads(); + } +#endif PyGILState_STATE gstate = PyGILState_Ensure(); diff --git a/src/Purge.list b/src/Purge.list index 0251f923be..2853ce2a7c 100644 --- a/src/Purge.list +++ b/src/Purge.list @@ -49,6 +49,8 @@ packages_ntopo.h # other auto-generated files lmpinstalledpkgs.h lmpgitversion.h +mliap_model_python_couple.cpp +mliap_model_python_couple.h # removed on 9 Sep 2020 mergesort.h # renamed on 8 May 2020 diff --git a/src/REPLICA/tad.cpp b/src/REPLICA/tad.cpp index b2a4851d27..0fc611b307 100644 --- a/src/REPLICA/tad.cpp +++ b/src/REPLICA/tad.cpp @@ -554,7 +554,10 @@ void TAD::log_event(int ievent) timer->barrier_start(); modify->addstep_compute_all(update->ntimestep); update->integrate->setup_minimal(1); + // must reset whichflag so that computes won't fail. + update->whichflag = 1; output->write_dump(update->ntimestep); + update->whichflag = 0; timer->barrier_stop(); time_output += timer->get_wall(Timer::TOTAL); } diff --git a/src/RIGID/fix_shake.cpp b/src/RIGID/fix_shake.cpp index 98700403b6..61ba36ea2b 100644 --- a/src/RIGID/fix_shake.cpp +++ b/src/RIGID/fix_shake.cpp @@ -2542,13 +2542,13 @@ void FixShake::stats() const auto bcnt = b_count_all[i]/2; if (bcnt) mesg += fmt::format("{:>6d} {:<9.6} {:<11.6} {:>8d}\n",i, - b_ave_all[i]/bcnt,b_max_all[i]-b_min_all[i],bcnt); + b_ave_all[i]/bcnt/2.0,b_max_all[i]-b_min_all[i],bcnt); } for (i = 1; i < na; i++) { const auto acnt = a_count_all[i]/3; if (acnt) mesg += fmt::format("{:>6d} {:<9.6} {:<11.6} {:>8d}\n",i, - a_ave_all[i]/acnt,a_max_all[i]-a_min_all[i],acnt); + a_ave_all[i]/acnt/3.0,a_max_all[i]-a_min_all[i],acnt); } utils::logmesg(lmp,mesg); } diff --git a/src/RIGID/rigid_const.h b/src/RIGID/rigid_const.h index 3aae988197..b345a6b9dc 100644 --- a/src/RIGID/rigid_const.h +++ b/src/RIGID/rigid_const.h @@ -33,21 +33,21 @@ namespace LAMMPS_NS { TORQUE = 1<<8 }; - static const double TOLERANCE = 1.0e-6; - static const double EPSILON = 1.0e-7; - static const double BIG = 1.0e20; + static constexpr double TOLERANCE = 1.0e-6; + static constexpr double EPSILON = 1.0e-7; + static constexpr double BIG = 1.0e20; // moment of inertia prefactor for sphere - static const double SINERTIA = 0.4; + static constexpr double SINERTIA = 0.4; // moment of inertia prefactor for ellipsoid - static const double EINERTIA = 0.2; + static constexpr double EINERTIA = 0.2; // moment of inertia prefactor for line segment - static const double LINERTIA = 1.0/12.0; + static constexpr double LINERTIA = 1.0/12.0; - static const int MAXLINE = 1024; - static const int CHUNK = 1024; - static const int DELTA_BODY = 10000; - static const int ATTRIBUTE_PERBODY = 20; + static constexpr int MAXLINE = 1024; + static constexpr int CHUNK = 1024; + static constexpr int DELTA_BODY = 10000; + static constexpr int ATTRIBUTE_PERBODY = 20; } } diff --git a/src/SNAP/sna.cpp b/src/SNAP/sna.cpp index 6d4197b59b..3c7a40c0dc 100644 --- a/src/SNAP/sna.cpp +++ b/src/SNAP/sna.cpp @@ -18,6 +18,7 @@ #include "sna.h" #include #include "math_const.h" +#include "math_special.h" #include "memory.h" #include "error.h" #include "comm.h" @@ -25,6 +26,7 @@ using namespace std; using namespace LAMMPS_NS; using namespace MathConst; +using namespace MathSpecial; /* ---------------------------------------------------------------------- @@ -1363,196 +1365,6 @@ void SNA::destroy_twojmax_arrays() } -/* ---------------------------------------------------------------------- - factorial n, wrapper for precomputed table -------------------------------------------------------------------------- */ - -double SNA::factorial(int n) -{ - if (n < 0 || n > nmaxfactorial) { - char str[128]; - sprintf(str, "Invalid argument to factorial %d", n); - error->all(FLERR, str); - } - - return nfac_table[n]; -} - -/* ---------------------------------------------------------------------- - factorial n table, size SNA::nmaxfactorial+1 -------------------------------------------------------------------------- */ - -const double SNA::nfac_table[] = { - 1, - 1, - 2, - 6, - 24, - 120, - 720, - 5040, - 40320, - 362880, - 3628800, - 39916800, - 479001600, - 6227020800, - 87178291200, - 1307674368000, - 20922789888000, - 355687428096000, - 6.402373705728e+15, - 1.21645100408832e+17, - 2.43290200817664e+18, - 5.10909421717094e+19, - 1.12400072777761e+21, - 2.5852016738885e+22, - 6.20448401733239e+23, - 1.5511210043331e+25, - 4.03291461126606e+26, - 1.08888694504184e+28, - 3.04888344611714e+29, - 8.8417619937397e+30, - 2.65252859812191e+32, - 8.22283865417792e+33, - 2.63130836933694e+35, - 8.68331761881189e+36, - 2.95232799039604e+38, - 1.03331479663861e+40, - 3.71993326789901e+41, - 1.37637530912263e+43, - 5.23022617466601e+44, - 2.03978820811974e+46, - 8.15915283247898e+47, - 3.34525266131638e+49, - 1.40500611775288e+51, - 6.04152630633738e+52, - 2.65827157478845e+54, - 1.1962222086548e+56, - 5.50262215981209e+57, - 2.58623241511168e+59, - 1.24139155925361e+61, - 6.08281864034268e+62, - 3.04140932017134e+64, - 1.55111875328738e+66, - 8.06581751709439e+67, - 4.27488328406003e+69, - 2.30843697339241e+71, - 1.26964033536583e+73, - 7.10998587804863e+74, - 4.05269195048772e+76, - 2.35056133128288e+78, - 1.3868311854569e+80, - 8.32098711274139e+81, - 5.07580213877225e+83, - 3.14699732603879e+85, - 1.98260831540444e+87, - 1.26886932185884e+89, - 8.24765059208247e+90, - 5.44344939077443e+92, - 3.64711109181887e+94, - 2.48003554243683e+96, - 1.71122452428141e+98, - 1.19785716699699e+100, - 8.50478588567862e+101, - 6.12344583768861e+103, - 4.47011546151268e+105, - 3.30788544151939e+107, - 2.48091408113954e+109, - 1.88549470166605e+111, - 1.45183092028286e+113, - 1.13242811782063e+115, - 8.94618213078297e+116, - 7.15694570462638e+118, - 5.79712602074737e+120, - 4.75364333701284e+122, - 3.94552396972066e+124, - 3.31424013456535e+126, - 2.81710411438055e+128, - 2.42270953836727e+130, - 2.10775729837953e+132, - 1.85482642257398e+134, - 1.65079551609085e+136, - 1.48571596448176e+138, - 1.3520015276784e+140, - 1.24384140546413e+142, - 1.15677250708164e+144, - 1.08736615665674e+146, - 1.03299784882391e+148, - 9.91677934870949e+149, - 9.61927596824821e+151, - 9.42689044888324e+153, - 9.33262154439441e+155, - 9.33262154439441e+157, - 9.42594775983835e+159, - 9.61446671503512e+161, - 9.90290071648618e+163, - 1.02990167451456e+166, - 1.08139675824029e+168, - 1.14628056373471e+170, - 1.22652020319614e+172, - 1.32464181945183e+174, - 1.44385958320249e+176, - 1.58824554152274e+178, - 1.76295255109024e+180, - 1.97450685722107e+182, - 2.23119274865981e+184, - 2.54355973347219e+186, - 2.92509369349301e+188, - 3.3931086844519e+190, - 3.96993716080872e+192, - 4.68452584975429e+194, - 5.5745857612076e+196, - 6.68950291344912e+198, - 8.09429852527344e+200, - 9.8750442008336e+202, - 1.21463043670253e+205, - 1.50614174151114e+207, - 1.88267717688893e+209, - 2.37217324288005e+211, - 3.01266001845766e+213, - 3.8562048236258e+215, - 4.97450422247729e+217, - 6.46685548922047e+219, - 8.47158069087882e+221, - 1.118248651196e+224, - 1.48727070609069e+226, - 1.99294274616152e+228, - 2.69047270731805e+230, - 3.65904288195255e+232, - 5.01288874827499e+234, - 6.91778647261949e+236, - 9.61572319694109e+238, - 1.34620124757175e+241, - 1.89814375907617e+243, - 2.69536413788816e+245, - 3.85437071718007e+247, - 5.5502938327393e+249, - 8.04792605747199e+251, - 1.17499720439091e+254, - 1.72724589045464e+256, - 2.55632391787286e+258, - 3.80892263763057e+260, - 5.71338395644585e+262, - 8.62720977423323e+264, - 1.31133588568345e+267, - 2.00634390509568e+269, - 3.08976961384735e+271, - 4.78914290146339e+273, - 7.47106292628289e+275, - 1.17295687942641e+278, - 1.85327186949373e+280, - 2.94670227249504e+282, - 4.71472363599206e+284, - 7.59070505394721e+286, - 1.22969421873945e+289, - 2.0044015765453e+291, - 3.28721858553429e+293, - 5.42391066613159e+295, - 9.00369170577843e+297, - 1.503616514865e+300, // nmaxfactorial = 167 -}; - /* ---------------------------------------------------------------------- the function delta given by VMK Eq. 8.2(1) ------------------------------------------------------------------------- */ diff --git a/src/SNAP/sna.h b/src/SNAP/sna.h index 30c4aa6bbc..746b55fb70 100644 --- a/src/SNAP/sna.h +++ b/src/SNAP/sna.h @@ -100,10 +100,6 @@ private: double** dulist_r, ** dulist_i; int elem_duarray; // element of j in derivative - static const int nmaxfactorial = 167; - static const double nfac_table[]; - double factorial(int); - void create_twojmax_arrays(); void destroy_twojmax_arrays(); void init_clebsch_gordan(); diff --git a/src/USER-DRUDE/fix_tgnh_drude.cpp b/src/USER-DRUDE/fix_tgnh_drude.cpp new file mode 100644 index 0000000000..e2122e6792 --- /dev/null +++ b/src/USER-DRUDE/fix_tgnh_drude.cpp @@ -0,0 +1,2363 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://lammps.sandia.gov/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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 authors: Mark Stevens (SNL), Aidan Thompson (SNL), Zheng Gong (ENS Lyon) +---------------------------------------------------------------------------------------- */ + +#include "fix_tgnh_drude.h" +#include +#include +#include "atom.h" +#include "force.h" +#include "group.h" +#include "comm.h" +#include "neighbor.h" +#include "irregular.h" +#include "modify.h" +#include "fix_deform.h" +#include "compute.h" +#include "kspace.h" +#include "update.h" +#include "respa.h" +#include "domain.h" +#include "memory.h" +#include "error.h" + +using namespace LAMMPS_NS; +using namespace FixConst; + +#define DELTAFLIP 0.1 +#define TILTMAX 1.5 + +enum{NOBIAS,BIAS}; +enum{NONE,XYZ,XY,YZ,XZ}; +enum{ISO,ANISO,TRICLINIC}; + +/* ---------------------------------------------------------------------- + NVT,NPH,NPT integrators for improved Nose-Hoover equations of motion + ---------------------------------------------------------------------- */ + +FixTGNHDrude::FixTGNHDrude(LAMMPS *lmp, int narg, char **arg) : + Fix(lmp, narg, arg), + rfix(nullptr), irregular(nullptr), id_temp(nullptr), id_press(nullptr), + etamol(nullptr), etamol_dot(nullptr), etamol_dotdot(nullptr), etamol_mass(nullptr), + etaint(nullptr), etaint_dot(nullptr), etaint_dotdot(nullptr), etaint_mass(nullptr), + etadrude(nullptr), etadrude_dot(nullptr), etadrude_dotdot(nullptr), etadrude_mass(nullptr), + etap(nullptr), etap_dot(nullptr), etap_dotdot(nullptr), etap_mass(nullptr) +{ + if (narg < 4) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + + restart_global = 1; + dynamic_group_allow = 0; + time_integrate = 1; + scalar_flag = 1; + vector_flag = 1; + global_freq = 1; + extscalar = 1; + extvector = 0; + + // default values + + pcouple = NONE; + mtchain = mpchain = 3; + nc_tchain = nc_pchain = 1; + mtk_flag = 1; + deviatoric_flag = 0; + nreset_h0 = 0; + flipflag = 1; + + tcomputeflag = 0; + pcomputeflag = 0; + id_temp = nullptr; + id_press = nullptr; + + // turn on tilt factor scaling, whenever applicable + + dimension = domain->dimension; + + scaleyz = scalexz = scalexy = 0; + if (domain->yperiodic && domain->xy != 0.0) scalexy = 1; + if (domain->zperiodic && dimension == 3) { + if (domain->yz != 0.0) scaleyz = 1; + if (domain->xz != 0.0) scalexz = 1; + } + + // set fixed-point to default = center of cell + + fixedpoint[0] = 0.5*(domain->boxlo[0]+domain->boxhi[0]); + fixedpoint[1] = 0.5*(domain->boxlo[1]+domain->boxhi[1]); + fixedpoint[2] = 0.5*(domain->boxlo[2]+domain->boxhi[2]); + + tstat_flag = 0; + double t_period = 0.0, tdrude_period = 0.0; + + double p_period[6]; + for (int i = 0; i < 6; i++) { + p_start[i] = p_stop[i] = p_period[i] = p_target[i] = 0.0; + p_flag[i] = 0; + } + + // process keywords + + int iarg = 3; + + while (iarg < narg) { + if (strcmp(arg[iarg],"temp") == 0) { + if (iarg+4 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + tstat_flag = 1; + t_start = utils::numeric(FLERR,arg[iarg+1],false,lmp); + t_target = t_start; + t_stop = utils::numeric(FLERR,arg[iarg+2],false,lmp); + t_period = utils::numeric(FLERR,arg[iarg+3],false,lmp); + if (t_start <= 0.0 || t_stop <= 0.0) + error->all(FLERR, + "Target temperature for fix nvt/npt/nph cannot be 0.0"); + tdrude_target = utils::numeric(FLERR,arg[iarg+4],false,lmp); + tdrude_period = utils::numeric(FLERR,arg[iarg+5],false,lmp); + iarg += 6; + + } else if (strcmp(arg[iarg],"iso") == 0) { + if (iarg+4 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + pcouple = XYZ; + p_start[0] = p_start[1] = p_start[2] = utils::numeric(FLERR,arg[iarg+1],false,lmp); + p_stop[0] = p_stop[1] = p_stop[2] = utils::numeric(FLERR,arg[iarg+2],false,lmp); + p_period[0] = p_period[1] = p_period[2] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + p_flag[0] = p_flag[1] = p_flag[2] = 1; + if (dimension == 2) { + p_start[2] = p_stop[2] = p_period[2] = 0.0; + p_flag[2] = 0; + } + iarg += 4; + } else if (strcmp(arg[iarg],"aniso") == 0) { + if (iarg+4 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + pcouple = NONE; + p_start[0] = p_start[1] = p_start[2] = utils::numeric(FLERR,arg[iarg+1],false,lmp); + p_stop[0] = p_stop[1] = p_stop[2] = utils::numeric(FLERR,arg[iarg+2],false,lmp); + p_period[0] = p_period[1] = p_period[2] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + p_flag[0] = p_flag[1] = p_flag[2] = 1; + if (dimension == 2) { + p_start[2] = p_stop[2] = p_period[2] = 0.0; + p_flag[2] = 0; + } + iarg += 4; + } else if (strcmp(arg[iarg],"tri") == 0) { + if (iarg+4 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + pcouple = NONE; + scalexy = scalexz = scaleyz = 0; + p_start[0] = p_start[1] = p_start[2] = utils::numeric(FLERR,arg[iarg+1],false,lmp); + p_stop[0] = p_stop[1] = p_stop[2] = utils::numeric(FLERR,arg[iarg+2],false,lmp); + p_period[0] = p_period[1] = p_period[2] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + p_flag[0] = p_flag[1] = p_flag[2] = 1; + p_start[3] = p_start[4] = p_start[5] = 0.0; + p_stop[3] = p_stop[4] = p_stop[5] = 0.0; + p_period[3] = p_period[4] = p_period[5] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + p_flag[3] = p_flag[4] = p_flag[5] = 1; + if (dimension == 2) { + p_start[2] = p_stop[2] = p_period[2] = 0.0; + p_flag[2] = 0; + p_start[3] = p_stop[3] = p_period[3] = 0.0; + p_flag[3] = 0; + p_start[4] = p_stop[4] = p_period[4] = 0.0; + p_flag[4] = 0; + } + iarg += 4; + } else if (strcmp(arg[iarg],"x") == 0) { + if (iarg+4 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + p_start[0] = utils::numeric(FLERR,arg[iarg+1],false,lmp); + p_stop[0] = utils::numeric(FLERR,arg[iarg+2],false,lmp); + p_period[0] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + p_flag[0] = 1; + deviatoric_flag = 1; + iarg += 4; + } else if (strcmp(arg[iarg],"y") == 0) { + if (iarg+4 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + p_start[1] = utils::numeric(FLERR,arg[iarg+1],false,lmp); + p_stop[1] = utils::numeric(FLERR,arg[iarg+2],false,lmp); + p_period[1] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + p_flag[1] = 1; + deviatoric_flag = 1; + iarg += 4; + } else if (strcmp(arg[iarg],"z") == 0) { + if (iarg+4 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + p_start[2] = utils::numeric(FLERR,arg[iarg+1],false,lmp); + p_stop[2] = utils::numeric(FLERR,arg[iarg+2],false,lmp); + p_period[2] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + p_flag[2] = 1; + deviatoric_flag = 1; + iarg += 4; + if (dimension == 2) + error->all(FLERR,"Invalid fix nvt/npt/nph command for a 2d simulation"); + + } else if (strcmp(arg[iarg],"yz") == 0) { + if (iarg+4 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + p_start[3] = utils::numeric(FLERR,arg[iarg+1],false,lmp); + p_stop[3] = utils::numeric(FLERR,arg[iarg+2],false,lmp); + p_period[3] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + p_flag[3] = 1; + deviatoric_flag = 1; + scaleyz = 0; + iarg += 4; + if (dimension == 2) + error->all(FLERR,"Invalid fix nvt/npt/nph command for a 2d simulation"); + } else if (strcmp(arg[iarg],"xz") == 0) { + if (iarg+4 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + p_start[4] = utils::numeric(FLERR,arg[iarg+1],false,lmp); + p_stop[4] = utils::numeric(FLERR,arg[iarg+2],false,lmp); + p_period[4] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + p_flag[4] = 1; + deviatoric_flag = 1; + scalexz = 0; + iarg += 4; + if (dimension == 2) + error->all(FLERR,"Invalid fix nvt/npt/nph command for a 2d simulation"); + } else if (strcmp(arg[iarg],"xy") == 0) { + if (iarg+4 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + p_start[5] = utils::numeric(FLERR,arg[iarg+1],false,lmp); + p_stop[5] = utils::numeric(FLERR,arg[iarg+2],false,lmp); + p_period[5] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + p_flag[5] = 1; + deviatoric_flag = 1; + scalexy = 0; + iarg += 4; + + } else if (strcmp(arg[iarg],"couple") == 0) { + if (iarg+2 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + if (strcmp(arg[iarg+1],"xyz") == 0) pcouple = XYZ; + else if (strcmp(arg[iarg+1],"xy") == 0) pcouple = XY; + else if (strcmp(arg[iarg+1],"yz") == 0) pcouple = YZ; + else if (strcmp(arg[iarg+1],"xz") == 0) pcouple = XZ; + else if (strcmp(arg[iarg+1],"none") == 0) pcouple = NONE; + else error->all(FLERR,"Illegal fix nvt/npt/nph command"); + iarg += 2; + } else if (strcmp(arg[iarg],"tchain") == 0) { + if (iarg+2 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + mtchain = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + if (mtchain < 1) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + iarg += 2; + } else if (strcmp(arg[iarg],"pchain") == 0) { + if (iarg+2 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + mpchain = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + if (mpchain < 0) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + iarg += 2; + } else if (strcmp(arg[iarg],"mtk") == 0) { + if (iarg+2 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + if (strcmp(arg[iarg+1],"yes") == 0) mtk_flag = 1; + else if (strcmp(arg[iarg+1],"no") == 0) mtk_flag = 0; + else error->all(FLERR,"Illegal fix nvt/npt/nph command"); + iarg += 2; + } else if (strcmp(arg[iarg],"tloop") == 0) { + if (iarg+2 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + nc_tchain = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + if (nc_tchain < 0) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + iarg += 2; + } else if (strcmp(arg[iarg],"ploop") == 0) { + if (iarg+2 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + nc_pchain = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + if (nc_pchain < 0) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + iarg += 2; + } else if (strcmp(arg[iarg],"nreset") == 0) { + if (iarg+2 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + nreset_h0 = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + if (nreset_h0 < 0) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + iarg += 2; + } else if (strcmp(arg[iarg],"scalexy") == 0) { + if (iarg+2 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + if (strcmp(arg[iarg+1],"yes") == 0) scalexy = 1; + else if (strcmp(arg[iarg+1],"no") == 0) scalexy = 0; + else error->all(FLERR,"Illegal fix nvt/npt/nph command"); + iarg += 2; + } else if (strcmp(arg[iarg],"scalexz") == 0) { + if (iarg+2 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + if (strcmp(arg[iarg+1],"yes") == 0) scalexz = 1; + else if (strcmp(arg[iarg+1],"no") == 0) scalexz = 0; + else error->all(FLERR,"Illegal fix nvt/npt/nph command"); + iarg += 2; + } else if (strcmp(arg[iarg],"scaleyz") == 0) { + if (iarg+2 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + if (strcmp(arg[iarg+1],"yes") == 0) scaleyz = 1; + else if (strcmp(arg[iarg+1],"no") == 0) scaleyz = 0; + else error->all(FLERR,"Illegal fix nvt/npt/nph command"); + iarg += 2; + } else if (strcmp(arg[iarg],"flip") == 0) { + if (iarg+2 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + if (strcmp(arg[iarg+1],"yes") == 0) flipflag = 1; + else if (strcmp(arg[iarg+1],"no") == 0) flipflag = 0; + else error->all(FLERR,"Illegal fix nvt/npt/nph command"); + iarg += 2; + } else if (strcmp(arg[iarg],"fixedpoint") == 0) { + if (iarg+4 > narg) error->all(FLERR,"Illegal fix nvt/npt/nph command"); + fixedpoint[0] = utils::numeric(FLERR,arg[iarg+1],false,lmp); + fixedpoint[1] = utils::numeric(FLERR,arg[iarg+2],false,lmp); + fixedpoint[2] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + iarg += 4; + } else error->all(FLERR,"Illegal fix nvt/npt/nph command"); + } + + // error checks + + if (dimension == 2 && (p_flag[2] || p_flag[3] || p_flag[4])) + error->all(FLERR,"Invalid fix nvt/npt/nph command for a 2d simulation"); + if (dimension == 2 && (pcouple == YZ || pcouple == XZ)) + error->all(FLERR,"Invalid fix nvt/npt/nph command for a 2d simulation"); + if (dimension == 2 && (scalexz == 1 || scaleyz == 1 )) + error->all(FLERR,"Invalid fix nvt/npt/nph command for a 2d simulation"); + + if (pcouple == XYZ && (p_flag[0] == 0 || p_flag[1] == 0)) + error->all(FLERR,"Invalid fix nvt/npt/nph command pressure settings"); + if (pcouple == XYZ && dimension == 3 && p_flag[2] == 0) + error->all(FLERR,"Invalid fix nvt/npt/nph command pressure settings"); + if (pcouple == XY && (p_flag[0] == 0 || p_flag[1] == 0)) + error->all(FLERR,"Invalid fix nvt/npt/nph command pressure settings"); + if (pcouple == YZ && (p_flag[1] == 0 || p_flag[2] == 0)) + error->all(FLERR,"Invalid fix nvt/npt/nph command pressure settings"); + if (pcouple == XZ && (p_flag[0] == 0 || p_flag[2] == 0)) + error->all(FLERR,"Invalid fix nvt/npt/nph command pressure settings"); + + // require periodicity in tensile dimension + + if (p_flag[0] && domain->xperiodic == 0) + error->all(FLERR,"Cannot use fix nvt/npt/nph on a non-periodic dimension"); + if (p_flag[1] && domain->yperiodic == 0) + error->all(FLERR,"Cannot use fix nvt/npt/nph on a non-periodic dimension"); + if (p_flag[2] && domain->zperiodic == 0) + error->all(FLERR,"Cannot use fix nvt/npt/nph on a non-periodic dimension"); + + // require periodicity in 2nd dim of off-diagonal tilt component + + if (p_flag[3] && domain->zperiodic == 0) + error->all(FLERR, + "Cannot use fix nvt/npt/nph on a 2nd non-periodic dimension"); + if (p_flag[4] && domain->zperiodic == 0) + error->all(FLERR, + "Cannot use fix nvt/npt/nph on a 2nd non-periodic dimension"); + if (p_flag[5] && domain->yperiodic == 0) + error->all(FLERR, + "Cannot use fix nvt/npt/nph on a 2nd non-periodic dimension"); + + if (scaleyz == 1 && domain->zperiodic == 0) + error->all(FLERR,"Cannot use fix nvt/npt/nph " + "with yz scaling when z is non-periodic dimension"); + if (scalexz == 1 && domain->zperiodic == 0) + error->all(FLERR,"Cannot use fix nvt/npt/nph " + "with xz scaling when z is non-periodic dimension"); + if (scalexy == 1 && domain->yperiodic == 0) + error->all(FLERR,"Cannot use fix nvt/npt/nph " + "with xy scaling when y is non-periodic dimension"); + + if (p_flag[3] && scaleyz == 1) + error->all(FLERR,"Cannot use fix nvt/npt/nph with " + "both yz dynamics and yz scaling"); + if (p_flag[4] && scalexz == 1) + error->all(FLERR,"Cannot use fix nvt/npt/nph with " + "both xz dynamics and xz scaling"); + if (p_flag[5] && scalexy == 1) + error->all(FLERR,"Cannot use fix nvt/npt/nph with " + "both xy dynamics and xy scaling"); + + if (!domain->triclinic && (p_flag[3] || p_flag[4] || p_flag[5])) + error->all(FLERR,"Can not specify Pxy/Pxz/Pyz in " + "fix nvt/npt/nph with non-triclinic box"); + + if (pcouple == XYZ && dimension == 3 && + (p_start[0] != p_start[1] || p_start[0] != p_start[2] || + p_stop[0] != p_stop[1] || p_stop[0] != p_stop[2] || + p_period[0] != p_period[1] || p_period[0] != p_period[2])) + error->all(FLERR,"Invalid fix nvt/npt/nph pressure settings"); + if (pcouple == XYZ && dimension == 2 && + (p_start[0] != p_start[1] || p_stop[0] != p_stop[1] || + p_period[0] != p_period[1])) + error->all(FLERR,"Invalid fix nvt/npt/nph pressure settings"); + if (pcouple == XY && + (p_start[0] != p_start[1] || p_stop[0] != p_stop[1] || + p_period[0] != p_period[1])) + error->all(FLERR,"Invalid fix nvt/npt/nph pressure settings"); + if (pcouple == YZ && + (p_start[1] != p_start[2] || p_stop[1] != p_stop[2] || + p_period[1] != p_period[2])) + error->all(FLERR,"Invalid fix nvt/npt/nph pressure settings"); + if (pcouple == XZ && + (p_start[0] != p_start[2] || p_stop[0] != p_stop[2] || + p_period[0] != p_period[2])) + error->all(FLERR,"Invalid fix nvt/npt/nph pressure settings"); + + if ((tstat_flag && t_period <= 0.0) || + (p_flag[0] && p_period[0] <= 0.0) || + (p_flag[1] && p_period[1] <= 0.0) || + (p_flag[2] && p_period[2] <= 0.0) || + (p_flag[3] && p_period[3] <= 0.0) || + (p_flag[4] && p_period[4] <= 0.0) || + (p_flag[5] && p_period[5] <= 0.0)) + error->all(FLERR,"Fix nvt/npt/nph damping parameters must be > 0.0"); + + // set pstat_flag and box change and restart_pbc variables + + pre_exchange_flag = 0; + pstat_flag = 0; + pstyle = ISO; + + for (int i = 0; i < 6; i++) + if (p_flag[i]) pstat_flag = 1; + + if (pstat_flag) { + if (p_flag[0]) box_change |= BOX_CHANGE_X; + if (p_flag[1]) box_change |= BOX_CHANGE_Y; + if (p_flag[2]) box_change |= BOX_CHANGE_Z; + if (p_flag[3]) box_change |= BOX_CHANGE_YZ; + if (p_flag[4]) box_change |= BOX_CHANGE_XZ; + if (p_flag[5]) box_change |= BOX_CHANGE_XY; + no_change_box = 1; + + // pstyle = TRICLINIC if any off-diagonal term is controlled -> 6 dof + // else pstyle = ISO if XYZ coupling or XY coupling in 2d -> 1 dof + // else pstyle = ANISO -> 3 dof + + if (p_flag[3] || p_flag[4] || p_flag[5]) pstyle = TRICLINIC; + else if (pcouple == XYZ || (dimension == 2 && pcouple == XY)) pstyle = ISO; + else pstyle = ANISO; + + // pre_exchange only required if flips can occur due to shape changes + + if (flipflag && (p_flag[3] || p_flag[4] || p_flag[5])) + pre_exchange_flag = pre_exchange_migrate = 1; + if (flipflag && (domain->yz != 0.0 || domain->xz != 0.0 || domain->xy != 0.0)) + pre_exchange_flag = pre_exchange_migrate = 1; + } + + // convert input periods to frequencies + + t_freq = tdrude_freq = 0.0; + p_freq[0] = p_freq[1] = p_freq[2] = p_freq[3] = p_freq[4] = p_freq[5] = 0.0; + + if (tstat_flag) { + t_freq = 1.0 / t_period; + tdrude_freq = 1.0 / tdrude_period; + } + if (p_flag[0]) p_freq[0] = 1.0 / p_period[0]; + if (p_flag[1]) p_freq[1] = 1.0 / p_period[1]; + if (p_flag[2]) p_freq[2] = 1.0 / p_period[2]; + if (p_flag[3]) p_freq[3] = 1.0 / p_period[3]; + if (p_flag[4]) p_freq[4] = 1.0 / p_period[4]; + if (p_flag[5]) p_freq[5] = 1.0 / p_period[5]; + + // Nose/Hoover temp and pressure init + + size_vector = 3; + + if (tstat_flag) { + int ich; + + etaint = new double[mtchain]; + // add one extra dummy thermostat for eta_dot, set to zero + etaint_dot = new double[mtchain+1]; + etaint_dot[mtchain] = 0.0; + etaint_dotdot = new double[mtchain]; + for (ich = 0; ich < mtchain; ich++) { + etaint[ich] = etaint_dot[ich] = etaint_dotdot[ich] = 0.0; + } + etaint_mass = new double[mtchain]; + + etamol = new double[mtchain]; + // add one extra dummy thermostat for eta_dot, set to zero + etamol_dot = new double[mtchain+1]; + etamol_dot[mtchain] = 0.0; + etamol_dotdot = new double[mtchain]; + for (ich = 0; ich < mtchain; ich++) { + etamol[ich] = etamol_dot[ich] = etamol_dotdot[ich] = 0.0; + } + etamol_mass = new double[mtchain]; + + etadrude = new double[mtchain]; + // add one extra dummy thermostat for eta_dot, set to zero + etadrude_dot = new double[mtchain+1]; + etadrude_dot[mtchain] = 0.0; + etadrude_dotdot = new double[mtchain]; + for (ich = 0; ich < mtchain; ich++) { + etadrude[ich] = etadrude_dot[ich] = etadrude_dotdot[ich] = 0.0; + } + etadrude_mass = new double[mtchain]; + } + + if (pstat_flag) { + omega[0] = omega[1] = omega[2] = 0.0; + omega_dot[0] = omega_dot[1] = omega_dot[2] = 0.0; + omega_mass[0] = omega_mass[1] = omega_mass[2] = 0.0; + omega[3] = omega[4] = omega[5] = 0.0; + omega_dot[3] = omega_dot[4] = omega_dot[5] = 0.0; + omega_mass[3] = omega_mass[4] = omega_mass[5] = 0.0; + + if (mpchain) { + int ich; + etap = new double[mpchain]; + + // add one extra dummy thermostat, set to zero + + etap_dot = new double[mpchain+1]; + etap_dot[mpchain] = 0.0; + etap_dotdot = new double[mpchain]; + for (ich = 0; ich < mpchain; ich++) { + etap[ich] = etap_dot[ich] = + etap_dotdot[ich] = 0.0; + } + etap_mass = new double[mpchain]; + } + } + + nrigid = 0; + rfix = nullptr; + + if (pre_exchange_flag) irregular = new Irregular(lmp); + else irregular = nullptr; + + // initialize vol0,t0 to zero to signal uninitialized + // values then assigned in init(), if necessary + + vol0 = t0 = 0.0; + + // find fix drude + int ifix; + for (ifix = 0; ifix < modify->nfix; ifix++) + if (strcmp(modify->fix[ifix]->style,"drude") == 0) break; + if (ifix == modify->nfix) error->all(FLERR, "fix tgnh/drude requires fix drude"); + fix_drude = (FixDrude *) modify->fix[ifix]; + + // make sure ghost atoms have velocity + if (!comm->ghost_velocity) + error->all(FLERR,"fix tgnh/drude requires ghost velocities. Use comm_modify vel yes"); +} + +/* ---------------------------------------------------------------------- */ + +FixTGNHDrude::~FixTGNHDrude() +{ + if (copymode) return; + + delete [] rfix; + + delete irregular; + + // delete temperature and pressure if fix created them + + if (tcomputeflag) modify->delete_compute(id_temp); + delete [] id_temp; + + if (tstat_flag) { + delete [] etaint; + delete [] etaint_dot; + delete [] etaint_dotdot; + delete [] etaint_mass; + delete [] etamol; + delete [] etamol_dot; + delete [] etamol_dotdot; + delete [] etamol_mass; + delete [] etadrude; + delete [] etadrude_dot; + delete [] etadrude_dotdot; + delete [] etadrude_mass; + } + + if (pstat_flag) { + if (pcomputeflag) modify->delete_compute(id_press); + delete [] id_press; + if (mpchain) { + delete [] etap; + delete [] etap_dot; + delete [] etap_dotdot; + delete [] etap_mass; + } + } +} + +/* ---------------------------------------------------------------------- */ + +int FixTGNHDrude::setmask() +{ + int mask = 0; + mask |= INITIAL_INTEGRATE; + mask |= FINAL_INTEGRATE; + mask |= THERMO_ENERGY; + mask |= INITIAL_INTEGRATE_RESPA; + mask |= FINAL_INTEGRATE_RESPA; + if (pre_exchange_flag) mask |= PRE_EXCHANGE; + return mask; +} + +/* ---------------------------------------------------------------------- */ + +void FixTGNHDrude::init() +{ + // ensure no conflict with fix deform + + if (pstat_flag) + for (int i = 0; i < modify->nfix; i++) + if (strcmp(modify->fix[i]->style,"deform") == 0) { + int *dimflag = ((FixDeform *) modify->fix[i])->dimflag; + if ((p_flag[0] && dimflag[0]) || (p_flag[1] && dimflag[1]) || + (p_flag[2] && dimflag[2]) || (p_flag[3] && dimflag[3]) || + (p_flag[4] && dimflag[4]) || (p_flag[5] && dimflag[5])) + error->all(FLERR,"Cannot use fix npt and fix deform on " + "same component of stress tensor"); + } + + // set temperature and pressure ptrs + + int icompute = modify->find_compute(id_temp); + if (icompute < 0) + error->all(FLERR,"Temperature ID for fix nvt/npt does not exist"); + temperature = modify->compute[icompute]; + + if (temperature->tempbias) which = BIAS; + else which = NOBIAS; + + if (pstat_flag) { + icompute = modify->find_compute(id_press); + if (icompute < 0) + error->all(FLERR,"Pressure ID for fix npt/nph does not exist"); + pressure = modify->compute[icompute]; + } + + // set timesteps and frequencies + + dtv = update->dt; + dtf = 0.5 * update->dt * force->ftm2v; + dthalf = 0.5 * update->dt; + dt4 = 0.25 * update->dt; + dt8 = 0.125 * update->dt; + dto = dthalf; + + p_freq_max = 0.0; + if (pstat_flag) { + p_freq_max = MAX(p_freq[0],p_freq[1]); + p_freq_max = MAX(p_freq_max,p_freq[2]); + if (pstyle == TRICLINIC) { + p_freq_max = MAX(p_freq_max,p_freq[3]); + p_freq_max = MAX(p_freq_max,p_freq[4]); + p_freq_max = MAX(p_freq_max,p_freq[5]); + } + } + + // tally the number of dimensions that are barostatted + // set initial volume and reference cell, if not already done + + if (pstat_flag) { + pdim = p_flag[0] + p_flag[1] + p_flag[2]; + if (vol0 == 0.0) { + if (dimension == 3) vol0 = domain->xprd * domain->yprd * domain->zprd; + else vol0 = domain->xprd * domain->yprd; + h0_inv[0] = domain->h_inv[0]; + h0_inv[1] = domain->h_inv[1]; + h0_inv[2] = domain->h_inv[2]; + h0_inv[3] = domain->h_inv[3]; + h0_inv[4] = domain->h_inv[4]; + h0_inv[5] = domain->h_inv[5]; + } + } + + boltz = force->boltz; + nktv2p = force->nktv2p; + + if (force->kspace) kspace_flag = 1; + else kspace_flag = 0; + + if (strstr(update->integrate_style,"respa")) { + nlevels_respa = ((Respa *) update->integrate)->nlevels; + step_respa = ((Respa *) update->integrate)->step; + dto = 0.5*step_respa[0]; + } + + // detect if any rigid fixes exist so rigid bodies move when box is remapped + // rfix[] = indices to each fix rigid + + delete [] rfix; + nrigid = 0; + rfix = nullptr; + + for (int i = 0; i < modify->nfix; i++) + if (modify->fix[i]->rigid_flag) nrigid++; + if (nrigid) { + rfix = new int[nrigid]; + nrigid = 0; + for (int i = 0; i < modify->nfix; i++) + if (modify->fix[i]->rigid_flag) rfix[nrigid++] = i; + } +} + +/* ---------------------------------------------------------------------- + compute T,P before integrator starts +------------------------------------------------------------------------- */ + +void FixTGNHDrude::setup_mol_mass_dof() { + double *mass = atom->mass; + int *mask = atom->mask; + tagint *molecule = atom->molecule; + int *type = atom->type; + int *drudetype = fix_drude->drudetype; + int n_drude, n_drude_tmp = 0; + tagint id_mol = 0, n_mol_in_group = 0; + + for (int i = 0; i < atom->nlocal; i++) { + // molecule id starts from 1. max(id_mol) equals to the number of molecules in the system + id_mol = std::max(id_mol, molecule[i]); + if (mask[i] & groupbit) { + if (drudetype[type[i]] == DRUDE_TYPE) + n_drude_tmp++; + } + } + MPI_Allreduce(&n_drude_tmp, &n_drude, 1, MPI_LMP_TAGINT, MPI_SUM, world); + MPI_Allreduce(&id_mol, &n_mol, 1, MPI_LMP_TAGINT, MPI_MAX, world); + + // use flag_mol to determine the number of molecules in the fix group + int *flag_mol = new int[n_mol + 1]; + int *flag_mol_tmp = new int[n_mol + 1]; + memset(flag_mol_tmp, 0, sizeof(int) * (n_mol + 1)); + for (int i = 0; i < atom->nlocal; i++) { + if (mask[i] & groupbit) { + flag_mol_tmp[molecule[i]] = 1; + } + } + MPI_Allreduce(flag_mol_tmp, flag_mol, n_mol + 1, MPI_INT, MPI_SUM, world); + for (int i = 1; i < n_mol + 1; i++) { + if (flag_mol[i]) + n_mol_in_group++; + } + delete[] flag_mol; + delete[] flag_mol_tmp; + + // length of v_mol set to n_mol+1, so that the subscript start from 1, we can call v_mol[n_mol] + memory->create(v_mol, n_mol + 1, 3, "fix_tgnh_drude::v_mol"); + memory->create(v_mol_tmp, n_mol + 1, 3, "fix_tgnh_drude::v_mol_tmp"); + memory->create(mass_mol, n_mol + 1, "fix_tgnh_drude::mass_mol"); + + double *mass_tmp = new double[n_mol + 1]; + memset(mass_tmp, 0, sizeof(double) * (n_mol + 1)); + for (int i = 0; i < atom->nlocal; i++) { + id_mol = molecule[i]; + mass_tmp[id_mol] += mass[type[i]]; + } + MPI_Allreduce(mass_tmp, mass_mol, n_mol + 1, MPI_DOUBLE, MPI_SUM, world); + delete[] mass_tmp; + + // DOFs + t_current = temperature->compute_scalar(); + tdof = temperature->dof; + // remove DOFs of COM translational motion based on the number of molecules in the group + dof_mol = 3.0 * n_mol_in_group - 3.0 * n_mol_in_group / n_mol; + dof_drude = 3.0 * n_drude; + dof_int = tdof - dof_mol - dof_drude; + + if (comm->me == 0) { + if (screen) { + fprintf(screen, "TGNHC thermostat for Drude model\n"); + fprintf(screen, " DOFs of molecules, atoms and dipoles: %.1f %.1f %.1f\n", + dof_mol, dof_int, dof_drude); + } + if (logfile) { + fprintf(logfile, "TGNHC thermostat for Drude model\n"); + fprintf(logfile, " DOFs of molecules, atoms and dipoles: %.1f %.1f %.1f\n", + dof_mol, dof_int, dof_drude); + } + } + if (dof_mol <=0 or dof_int <=0 or dof_drude <=0) + error->all(FLERR, "TGNHC thermostat requires DOFs of molecules, atoms and dipoles larger than 0"); +} + +void FixTGNHDrude::setup(int /*vflag*/) +{ + setup_mol_mass_dof(); + // t_target is needed by NVT and NPT in compute_scalar() + // If no thermostat or using fix nphug, + // t_target must be defined by other means. + + if (tstat_flag && strstr(style,"nphug") == nullptr) { + compute_temp_target(); + } else if (pstat_flag) { + + // t0 = reference temperature for masses + // cannot be done in init() b/c temperature cannot be called there + // is b/c Modify::init() inits computes after fixes due to dof dependence + // guesstimate a unit-dependent t0 if actual T = 0.0 + // if it was read in from a restart file, leave it be + + if (t0 == 0.0) { + t0 = temperature->compute_scalar(); + if (t0 == 0.0) { + if (strcmp(update->unit_style,"lj") == 0) t0 = 1.0; + else t0 = 300.0; + } + } + t_target = t0; + } + + if (pstat_flag) compute_press_target(); + + if (pstat_flag) { + if (pstyle == ISO) pressure->compute_scalar(); + else pressure->compute_vector(); + couple(); + pressure->addstep(update->ntimestep+1); + } + + // masses and initial forces on thermostat variables + + if (tstat_flag) { + etaint_mass[0] = ke2int_target / (t_freq * t_freq); + etamol_mass[0] = ke2mol_target / (t_freq * t_freq); + etadrude_mass[0] = ke2drude_target / (tdrude_freq * tdrude_freq); + for (int ich = 1; ich < mtchain; ich++) { + etaint_mass[ich] = boltz * t_target / (t_freq * t_freq); + etamol_mass[ich] = boltz * t_target / (t_freq * t_freq); + etadrude_mass[ich] = boltz * tdrude_target / (tdrude_freq * tdrude_freq); + + etaint_dotdot[ich] = (etaint_mass[ich - 1] * etaint_dot[ich - 1] * etaint_dot[ich - 1] - + boltz * t_target) / etaint_mass[ich]; + etamol_dotdot[ich] = (etamol_mass[ich - 1] * etamol_dot[ich - 1] * etamol_dot[ich - 1] - + boltz * t_target) / etamol_mass[ich]; + etadrude_dotdot[ich] = (etadrude_mass[ich - 1] * etadrude_dot[ich - 1] * etadrude_dot[ich - 1] - + boltz * tdrude_target) / etadrude_mass[ich]; + } + } + + // masses and initial forces on barostat variables + + if (pstat_flag) { + double kt = boltz * t_target; + double nkt = (atom->natoms + 1) * kt; + + for (int i = 0; i < 3; i++) + if (p_flag[i]) + omega_mass[i] = nkt/(p_freq[i]*p_freq[i]); + + if (pstyle == TRICLINIC) { + for (int i = 3; i < 6; i++) + if (p_flag[i]) omega_mass[i] = nkt/(p_freq[i]*p_freq[i]); + } + + // masses and initial forces on barostat thermostat variables + + if (mpchain) { + etap_mass[0] = boltz * t_target / (p_freq_max*p_freq_max); + for (int ich = 1; ich < mpchain; ich++) + etap_mass[ich] = boltz * t_target / (p_freq_max*p_freq_max); + for (int ich = 1; ich < mpchain; ich++) + etap_dotdot[ich] = + (etap_mass[ich-1]*etap_dot[ich-1]*etap_dot[ich-1] - + boltz * t_target) / etap_mass[ich]; + } + } +} + +/* ---------------------------------------------------------------------- + 1st half of Verlet update +------------------------------------------------------------------------- */ + +void FixTGNHDrude::initial_integrate(int /*vflag*/) +{ + // update eta_press_dot + + if (pstat_flag && mpchain) nhc_press_integrate(); + + // update eta_dot + + if (tstat_flag) { + compute_temp_target(); + nhc_temp_integrate(); + } + + // need to recompute pressure to account for change in KE + // t_current is up-to-date, but compute_temperature is not + // compute appropriately coupled elements of mvv_current + + if (pstat_flag) { + if (pstyle == ISO) { + temperature->compute_scalar(); + pressure->compute_scalar(); + } else { + temperature->compute_vector(); + pressure->compute_vector(); + } + couple(); + pressure->addstep(update->ntimestep+1); + } + + if (pstat_flag) { + compute_press_target(); + nh_omega_dot(); + nh_v_press(); + } + + nve_v(); + + // remap simulation box by 1/2 step + + if (pstat_flag) remap(); + + nve_x(); + + // remap simulation box by 1/2 step + // redo KSpace coeffs since volume has changed + + if (pstat_flag) { + remap(); + if (kspace_flag) force->kspace->setup(); + } +} + +/* ---------------------------------------------------------------------- + 2nd half of Verlet update +------------------------------------------------------------------------- */ + +void FixTGNHDrude::final_integrate() +{ + nve_v(); + + // re-compute temp before nh_v_press() + // only needed for temperature computes with BIAS on reneighboring steps: + // b/c some biases store per-atom values (e.g. temp/profile) + // per-atom values are invalid if reneigh/comm occurred + // since temp->compute() in initial_integrate() + + if (which == BIAS && neighbor->ago == 0) + t_current = temperature->compute_scalar(); + + if (pstat_flag) nh_v_press(); + + // compute new T,P after velocities rescaled by nh_v_press() + // compute appropriately coupled elements of mvv_current + + t_current = temperature->compute_scalar(); + tdof = temperature->dof; + + // need to recompute pressure to account for change in KE + // t_current is up-to-date, but compute_temperature is not + // compute appropriately coupled elements of mvv_current + + if (pstat_flag) { + if (pstyle == ISO) pressure->compute_scalar(); + else { + temperature->compute_vector(); + pressure->compute_vector(); + } + couple(); + pressure->addstep(update->ntimestep+1); + } + + if (pstat_flag) nh_omega_dot(); + + // update eta_dot + // update eta_press_dot + + if (tstat_flag) nhc_temp_integrate(); + if (pstat_flag && mpchain) nhc_press_integrate(); +} + +/* ---------------------------------------------------------------------- */ + +void FixTGNHDrude::initial_integrate_respa(int /*vflag*/, int ilevel, int /*iloop*/) +{ + // set timesteps by level + + dtv = step_respa[ilevel]; + dtf = 0.5 * step_respa[ilevel] * force->ftm2v; + dthalf = 0.5 * step_respa[ilevel]; + + // outermost level - update eta_dot and omega_dot, apply to v + // all other levels - NVE update of v + // x,v updates only performed for atoms in group + + if (ilevel == nlevels_respa-1) { + + // update eta_press_dot + + if (pstat_flag && mpchain) nhc_press_integrate(); + + // update eta_dot + + if (tstat_flag) { + compute_temp_target(); + nhc_temp_integrate(); + } + + // recompute pressure to account for change in KE + // t_current is up-to-date, but compute_temperature is not + // compute appropriately coupled elements of mvv_current + + if (pstat_flag) { + if (pstyle == ISO) { + temperature->compute_scalar(); + pressure->compute_scalar(); + } else { + temperature->compute_vector(); + pressure->compute_vector(); + } + couple(); + pressure->addstep(update->ntimestep+1); + } + + if (pstat_flag) { + compute_press_target(); + nh_omega_dot(); + nh_v_press(); + } + + nve_v(); + + } else nve_v(); + + // innermost level - also update x only for atoms in group + // if barostat, perform 1/2 step remap before and after + + if (ilevel == 0) { + if (pstat_flag) remap(); + nve_x(); + if (pstat_flag) remap(); + } + + // if barostat, redo KSpace coeffs at outermost level, + // since volume has changed + + if (ilevel == nlevels_respa-1 && kspace_flag && pstat_flag) + force->kspace->setup(); +} + +/* ---------------------------------------------------------------------- */ + +void FixTGNHDrude::final_integrate_respa(int ilevel, int /*iloop*/) +{ + // set timesteps by level + + dtf = 0.5 * step_respa[ilevel] * force->ftm2v; + dthalf = 0.5 * step_respa[ilevel]; + + // outermost level - update eta_dot and omega_dot, apply via final_integrate + // all other levels - NVE update of v + + if (ilevel == nlevels_respa-1) final_integrate(); + else nve_v(); +} + +/* ---------------------------------------------------------------------- */ + +void FixTGNHDrude::couple() +{ + double *tensor = pressure->vector; + + if (pstyle == ISO) + p_current[0] = p_current[1] = p_current[2] = pressure->scalar; + else if (pcouple == XYZ) { + double ave = 1.0/3.0 * (tensor[0] + tensor[1] + tensor[2]); + p_current[0] = p_current[1] = p_current[2] = ave; + } else if (pcouple == XY) { + double ave = 0.5 * (tensor[0] + tensor[1]); + p_current[0] = p_current[1] = ave; + p_current[2] = tensor[2]; + } else if (pcouple == YZ) { + double ave = 0.5 * (tensor[1] + tensor[2]); + p_current[1] = p_current[2] = ave; + p_current[0] = tensor[0]; + } else if (pcouple == XZ) { + double ave = 0.5 * (tensor[0] + tensor[2]); + p_current[0] = p_current[2] = ave; + p_current[1] = tensor[1]; + } else { + p_current[0] = tensor[0]; + p_current[1] = tensor[1]; + p_current[2] = tensor[2]; + } + + if (!std::isfinite(p_current[0]) || !std::isfinite(p_current[1]) || !std::isfinite(p_current[2])) + error->all(FLERR,"Non-numeric pressure - simulation unstable"); + + // switch order from xy-xz-yz to Voigt + + if (pstyle == TRICLINIC) { + p_current[3] = tensor[5]; + p_current[4] = tensor[4]; + p_current[5] = tensor[3]; + + if (!std::isfinite(p_current[3]) || !std::isfinite(p_current[4]) || !std::isfinite(p_current[5])) + error->all(FLERR,"Non-numeric pressure - simulation unstable"); + } +} + +/* ---------------------------------------------------------------------- + change box size + remap all atoms or dilate group atoms depending on allremap flag + if rigid bodies exist, scale rigid body centers-of-mass +------------------------------------------------------------------------- */ + +void FixTGNHDrude::remap() +{ + int i; + double oldlo,oldhi; + double expfac; + + double **x = atom->x; + int *mask = atom->mask; + int nlocal = atom->nlocal; + double *h = domain->h; + + // omega is not used, except for book-keeping + + for (int i = 0; i < 6; i++) omega[i] += dto*omega_dot[i]; + + // convert pertinent atoms and rigid bodies to lamda coords + + domain->x2lamda(nlocal); + + if (nrigid) + for (i = 0; i < nrigid; i++) + modify->fix[rfix[i]]->deform(0); + + // reset global and local box to new size/shape + + // this operation corresponds to applying the + // translate and scale operations + // corresponding to the solution of the following ODE: + // + // h_dot = omega_dot * h + // + // where h_dot, omega_dot and h are all upper-triangular + // 3x3 tensors. In Voigt notation, the elements of the + // RHS product tensor are: + // h_dot = [0*0, 1*1, 2*2, 1*3+3*2, 0*4+5*3+4*2, 0*5+5*1] + // + // Ordering of operations preserves time symmetry. + + double dto2 = dto/2.0; + double dto4 = dto/4.0; + double dto8 = dto/8.0; + + // off-diagonal components, first half + + if (pstyle == TRICLINIC) { + + if (p_flag[4]) { + expfac = exp(dto8*omega_dot[0]); + h[4] *= expfac; + h[4] += dto4*(omega_dot[5]*h[3]+omega_dot[4]*h[2]); + h[4] *= expfac; + } + + if (p_flag[3]) { + expfac = exp(dto4*omega_dot[1]); + h[3] *= expfac; + h[3] += dto2*(omega_dot[3]*h[2]); + h[3] *= expfac; + } + + if (p_flag[5]) { + expfac = exp(dto4*omega_dot[0]); + h[5] *= expfac; + h[5] += dto2*(omega_dot[5]*h[1]); + h[5] *= expfac; + } + + if (p_flag[4]) { + expfac = exp(dto8*omega_dot[0]); + h[4] *= expfac; + h[4] += dto4*(omega_dot[5]*h[3]+omega_dot[4]*h[2]); + h[4] *= expfac; + } + } + + // scale diagonal components + // scale tilt factors with cell, if set + + if (p_flag[0]) { + oldlo = domain->boxlo[0]; + oldhi = domain->boxhi[0]; + expfac = exp(dto*omega_dot[0]); + domain->boxlo[0] = (oldlo-fixedpoint[0])*expfac + fixedpoint[0]; + domain->boxhi[0] = (oldhi-fixedpoint[0])*expfac + fixedpoint[0]; + } + + if (p_flag[1]) { + oldlo = domain->boxlo[1]; + oldhi = domain->boxhi[1]; + expfac = exp(dto*omega_dot[1]); + domain->boxlo[1] = (oldlo-fixedpoint[1])*expfac + fixedpoint[1]; + domain->boxhi[1] = (oldhi-fixedpoint[1])*expfac + fixedpoint[1]; + if (scalexy) h[5] *= expfac; + } + + if (p_flag[2]) { + oldlo = domain->boxlo[2]; + oldhi = domain->boxhi[2]; + expfac = exp(dto*omega_dot[2]); + domain->boxlo[2] = (oldlo-fixedpoint[2])*expfac + fixedpoint[2]; + domain->boxhi[2] = (oldhi-fixedpoint[2])*expfac + fixedpoint[2]; + if (scalexz) h[4] *= expfac; + if (scaleyz) h[3] *= expfac; + } + + // off-diagonal components, second half + + if (pstyle == TRICLINIC) { + + if (p_flag[4]) { + expfac = exp(dto8*omega_dot[0]); + h[4] *= expfac; + h[4] += dto4*(omega_dot[5]*h[3]+omega_dot[4]*h[2]); + h[4] *= expfac; + } + + if (p_flag[3]) { + expfac = exp(dto4*omega_dot[1]); + h[3] *= expfac; + h[3] += dto2*(omega_dot[3]*h[2]); + h[3] *= expfac; + } + + if (p_flag[5]) { + expfac = exp(dto4*omega_dot[0]); + h[5] *= expfac; + h[5] += dto2*(omega_dot[5]*h[1]); + h[5] *= expfac; + } + + if (p_flag[4]) { + expfac = exp(dto8*omega_dot[0]); + h[4] *= expfac; + h[4] += dto4*(omega_dot[5]*h[3]+omega_dot[4]*h[2]); + h[4] *= expfac; + } + + } + + domain->yz = h[3]; + domain->xz = h[4]; + domain->xy = h[5]; + + // tilt factor to cell length ratio can not exceed TILTMAX in one step + + if (domain->yz < -TILTMAX*domain->yprd || + domain->yz > TILTMAX*domain->yprd || + domain->xz < -TILTMAX*domain->xprd || + domain->xz > TILTMAX*domain->xprd || + domain->xy < -TILTMAX*domain->xprd || + domain->xy > TILTMAX*domain->xprd) + error->all(FLERR,"Fix npt/nph has tilted box too far in one step - " + "periodic cell is too far from equilibrium state"); + + domain->set_global_box(); + domain->set_local_box(); + + // convert pertinent atoms and rigid bodies back to box coords + + domain->lamda2x(nlocal); + + if (nrigid) + for (i = 0; i < nrigid; i++) + modify->fix[rfix[i]]->deform(1); +} + +/* ---------------------------------------------------------------------- + pack entire state of Fix into one write +------------------------------------------------------------------------- */ + +void FixTGNHDrude::write_restart(FILE *fp) +{ + int nsize = size_restart_global(); + + double *list; + memory->create(list,nsize,"nh:list"); + + pack_restart_data(list); + + if (comm->me == 0) { + int size = nsize * sizeof(double); + fwrite(&size,sizeof(int),1,fp); + fwrite(list,sizeof(double),nsize,fp); + } + + memory->destroy(list); +} + +/* ---------------------------------------------------------------------- + calculate the number of data to be packed +------------------------------------------------------------------------- */ + +int FixTGNHDrude::size_restart_global() +{ + int nsize = 2; + if (tstat_flag) nsize += 1 + 6*mtchain; + if (pstat_flag) { + nsize += 16 + 2*mpchain; + if (deviatoric_flag) nsize += 6; + } + + return nsize; +} + +/* ---------------------------------------------------------------------- + pack restart data +------------------------------------------------------------------------- */ + +int FixTGNHDrude::pack_restart_data(double *list) +{ + int n = 0; + + list[n++] = tstat_flag; + if (tstat_flag) { + list[n++] = mtchain; + for (int ich = 0; ich < mtchain; ich++){ + list[n++] = etamol[ich]; + list[n++] = etaint[ich]; + list[n++] = etadrude[ich]; + } + for (int ich = 0; ich < mtchain; ich++) { + list[n++] = etamol_dot[ich]; + list[n++] = etaint_dot[ich]; + list[n++] = etadrude_dot[ich]; + } + } + + list[n++] = pstat_flag; + if (pstat_flag) { + list[n++] = omega[0]; + list[n++] = omega[1]; + list[n++] = omega[2]; + list[n++] = omega[3]; + list[n++] = omega[4]; + list[n++] = omega[5]; + list[n++] = omega_dot[0]; + list[n++] = omega_dot[1]; + list[n++] = omega_dot[2]; + list[n++] = omega_dot[3]; + list[n++] = omega_dot[4]; + list[n++] = omega_dot[5]; + list[n++] = vol0; + list[n++] = t0; + list[n++] = mpchain; + if (mpchain) { + for (int ich = 0; ich < mpchain; ich++) + list[n++] = etap[ich]; + for (int ich = 0; ich < mpchain; ich++) + list[n++] = etap_dot[ich]; + } + + list[n++] = deviatoric_flag; + if (deviatoric_flag) { + list[n++] = h0_inv[0]; + list[n++] = h0_inv[1]; + list[n++] = h0_inv[2]; + list[n++] = h0_inv[3]; + list[n++] = h0_inv[4]; + list[n++] = h0_inv[5]; + } + } + + return n; +} + +/* ---------------------------------------------------------------------- + use state info from restart file to restart the Fix +------------------------------------------------------------------------- */ + +void FixTGNHDrude::restart(char *buf) +{ + int n = 0; + double *list = (double *) buf; + int flag = static_cast (list[n++]); + if (flag) { + int m = static_cast (list[n++]); + if (tstat_flag && m == mtchain) { + for (int ich = 0; ich < mtchain; ich++){ + etamol[ich] = list[n++]; + etaint[ich] = list[n++]; + etadrude[ich] = list[n++]; + } + for (int ich = 0; ich < mtchain; ich++){ + etamol_dot[ich] = list[n++]; + etaint_dot[ich] = list[n++]; + etadrude_dot[ich] = list[n++]; + } + } else n += 2*m; + } + flag = static_cast (list[n++]); + if (flag) { + omega[0] = list[n++]; + omega[1] = list[n++]; + omega[2] = list[n++]; + omega[3] = list[n++]; + omega[4] = list[n++]; + omega[5] = list[n++]; + omega_dot[0] = list[n++]; + omega_dot[1] = list[n++]; + omega_dot[2] = list[n++]; + omega_dot[3] = list[n++]; + omega_dot[4] = list[n++]; + omega_dot[5] = list[n++]; + vol0 = list[n++]; + t0 = list[n++]; + int m = static_cast (list[n++]); + if (pstat_flag && m == mpchain) { + for (int ich = 0; ich < mpchain; ich++) + etap[ich] = list[n++]; + for (int ich = 0; ich < mpchain; ich++) + etap_dot[ich] = list[n++]; + } else n+=2*m; + flag = static_cast (list[n++]); + if (flag) { + h0_inv[0] = list[n++]; + h0_inv[1] = list[n++]; + h0_inv[2] = list[n++]; + h0_inv[3] = list[n++]; + h0_inv[4] = list[n++]; + h0_inv[5] = list[n++]; + } + } +} + +/* ---------------------------------------------------------------------- */ + +int FixTGNHDrude::modify_param(int narg, char **arg) +{ + if (strcmp(arg[0],"temp") == 0) { + if (narg < 2) error->all(FLERR,"Illegal fix_modify command"); + if (tcomputeflag) { + modify->delete_compute(id_temp); + tcomputeflag = 0; + } + delete [] id_temp; + int n = strlen(arg[1]) + 1; + id_temp = new char[n]; + strcpy(id_temp,arg[1]); + + int icompute = modify->find_compute(arg[1]); + if (icompute < 0) + error->all(FLERR,"Could not find fix_modify temperature ID"); + temperature = modify->compute[icompute]; + + if (temperature->tempflag == 0) + error->all(FLERR, + "Fix_modify temperature ID does not compute temperature"); + if (temperature->igroup != 0 && comm->me == 0) + error->warning(FLERR,"Temperature for fix modify is not for group all"); + + // reset id_temp of pressure to new temperature ID + + if (pstat_flag) { + icompute = modify->find_compute(id_press); + if (icompute < 0) + error->all(FLERR,"Pressure ID for fix modify does not exist"); + modify->compute[icompute]->reset_extra_compute_fix(id_temp); + } + + return 2; + + } else if (strcmp(arg[0],"press") == 0) { + if (narg < 2) error->all(FLERR,"Illegal fix_modify command"); + if (!pstat_flag) error->all(FLERR,"Illegal fix_modify command"); + if (pcomputeflag) { + modify->delete_compute(id_press); + pcomputeflag = 0; + } + delete [] id_press; + int n = strlen(arg[1]) + 1; + id_press = new char[n]; + strcpy(id_press,arg[1]); + + int icompute = modify->find_compute(arg[1]); + if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); + pressure = modify->compute[icompute]; + + if (pressure->pressflag == 0) + error->all(FLERR,"Fix_modify pressure ID does not compute pressure"); + return 2; + } + + return 0; +} + +/* ---------------------------------------------------------------------- */ + +double FixTGNHDrude::compute_scalar() +{ + int i; + double volume; + double energy; + double kt = boltz * t_target; + double kt_drude = boltz * tdrude_target; + double lkt_press = 0.0; + int ich; + if (dimension == 3) volume = domain->xprd * domain->yprd * domain->zprd; + else volume = domain->xprd * domain->yprd; + + energy = 0.0; + + // thermostat chain energy is equivalent to Eq. (2) in + // Martyna, Tuckerman, Tobias, Klein, Mol Phys, 87, 1117 + // Sum(0.5*p_eta_k^2/Q_k,k=1,M) + L*k*T*eta_1 + Sum(k*T*eta_k,k=2,M), + // where L = tdof + // M = mtchain + // p_eta_k = Q_k*eta_dot[k-1] + // Q_1 = L*k*T/t_freq^2 + // Q_k = k*T/t_freq^2, k > 1 + + if (tstat_flag) { + energy += ke2mol_target * etamol[0] + 0.5 * etamol_mass[0] * etamol_dot[0] * etamol_dot[0]; + energy += ke2int_target * etaint[0] + 0.5 * etaint_mass[0] * etaint_dot[0] * etaint_dot[0]; + energy += ke2drude_target * etadrude[0] + 0.5 * etadrude_mass[0] * etadrude_dot[0] * etadrude_dot[0]; + for (ich = 1; ich < mtchain; ich++){ + energy += kt * etamol[ich] + 0.5*etamol_mass[ich]*etamol_dot[ich]*etamol_dot[ich]; + energy += kt * etaint[ich] + 0.5*etaint_mass[ich]*etaint_dot[ich]*etaint_dot[ich]; + energy += kt_drude * etadrude[ich] + 0.5*etadrude_mass[ich]*etadrude_dot[ich]*etadrude_dot[ich]; + } + } + + // barostat energy is equivalent to Eq. (8) in + // Martyna, Tuckerman, Tobias, Klein, Mol Phys, 87, 1117 + // Sum(0.5*p_omega^2/W + P*V), + // where N = natoms + // p_omega = W*omega_dot + // W = N*k*T/p_freq^2 + // sum is over barostatted dimensions + + if (pstat_flag) { + for (i = 0; i < 3; i++) { + if (p_flag[i]) { + energy += 0.5*omega_dot[i]*omega_dot[i]*omega_mass[i] + + p_hydro*(volume-vol0) / (pdim*nktv2p); + lkt_press += kt; + } + } + + if (pstyle == TRICLINIC) { + for (i = 3; i < 6; i++) { + if (p_flag[i]) { + energy += 0.5*omega_dot[i]*omega_dot[i]*omega_mass[i]; + lkt_press += kt; + } + } + } + + // extra contributions from thermostat chain for barostat + + if (mpchain) { + energy += lkt_press * etap[0] + 0.5*etap_mass[0]*etap_dot[0]*etap_dot[0]; + for (ich = 1; ich < mpchain; ich++) + energy += kt * etap[ich] + + 0.5*etap_mass[ich]*etap_dot[ich]*etap_dot[ich]; + } + + // extra contribution from strain energy + + if (deviatoric_flag) energy += compute_strain_energy(); + } + + return energy; +} + +/* ---------------------------------------------------------------------- */ + +double FixTGNHDrude::compute_vector(int n) +{ + if (!temp_computed_end_of_step) + compute_temp_mol_int_drude(true); + switch (n){ + case 0: + return t_mol; + case 1: + return t_int; + case 2: + return t_drude; + default: + return 0.0; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixTGNHDrude::reset_target(double t_new) +{ + t_target = t_start = t_stop = t_new; +} + +/* ---------------------------------------------------------------------- */ + +void FixTGNHDrude::reset_dt() +{ + dtv = update->dt; + dtf = 0.5 * update->dt * force->ftm2v; + dthalf = 0.5 * update->dt; + dt4 = 0.25 * update->dt; + dt8 = 0.125 * update->dt; + dto = dthalf; + + // If using respa, then remap is performed in innermost level + + if (strstr(update->integrate_style,"respa")) + dto = 0.5*step_respa[0]; +} + +void FixTGNHDrude::compute_temp_mol_int_drude(bool end_of_step) { + double **v = atom->v; + double *mass = atom->mass; + tagint *molecule = atom->molecule; + int *type = atom->type; + int *mask = atom->mask; + int *drudetype = fix_drude->drudetype; + tagint *drudeid = fix_drude->drudeid; + int imol, ci, di; + double mass_com, mass_reduced, mass_core, mass_drude; + double vint, vcom, vrel; + // use array instead of two numbers to save MPI_Allreduce() + double ke2_int_drude_tmp[2] = {0.0, 0.0}; + double ke2_int_drude[2]; + + memset(*v_mol_tmp, 0, sizeof(double) * (n_mol + 1) * 3); // the length of v_mol is n_mol+1 + + /** + * If there are velocity bias, need to remove them before calculate kinetic energies + */ + for (int i = 0; i < atom->nlocal; i++) { + if (mask[i] & groupbit) { + if (which == BIAS) + temperature->remove_bias(i, v[i]); + + imol = molecule[i]; + for (int k = 0; k < 3; k++) + v_mol_tmp[imol][k] += v[i][k] * mass[type[i]]; + + if (which == BIAS) + temperature->restore_bias(i, v[i]); + } + } + MPI_Allreduce(*v_mol_tmp, *v_mol, (n_mol + 1) * 3, MPI_DOUBLE, MPI_SUM, world); + + ke2mol = 0; + for (int i = 1; i < n_mol + 1; i++) { + for (int k = 0; k < 3; k++) { + v_mol[i][k] /= mass_mol[i]; + ke2mol += mass_mol[i] * (v_mol[i][k] * v_mol[i][k]); + } + } + ke2mol *= force->mvv2e; + t_mol = ke2mol / dof_mol / boltz; + + /** + * Have to call remove_bias at the innermost loop, because drude atom may be a ghost + */ + for (int i = 0; i < atom->nlocal; i++) { + if (mask[i] & groupbit) { + imol = molecule[i]; + if (drudetype[type[i]] == NOPOL_TYPE) { + if (which == BIAS) + temperature->remove_bias(i, v[i]); + for (int k = 0; k < 3; k++) { + vint = v[i][k] - v_mol[imol][k]; + ke2_int_drude_tmp[0] += mass[type[i]] * vint * vint; + } + if (which == BIAS) + temperature->restore_bias(i, v[i]); + } else if (drudetype[type[i]] == CORE_TYPE) { + /** + * have to use closet_image() + * even though all images have the same velocity and it's sort of read-only + * but the bias velocity may depends on it's position like in compute vis/pp + */ + ci = i; + di = domain->closest_image(i, atom->map(drudeid[i])); + if (which == BIAS) { + temperature->remove_bias(ci, v[ci]); + temperature->remove_bias(di, v[di]); + } + mass_core = mass[type[ci]]; + mass_drude = mass[type[di]]; + mass_com = mass_core + mass_drude; + mass_reduced = mass_core * mass_drude / mass_com; + for (int k = 0; k < 3; k++) { + vcom = (mass_core * v[ci][k] + mass_drude * v[di][k]) / mass_com; + vint = vcom - v_mol[imol][k]; + ke2_int_drude_tmp[0] += mass_com * vint * vint; + vrel = v[di][k] - v[ci][k]; + ke2_int_drude_tmp[1] += mass_reduced * vrel * vrel; + } + if (which == BIAS) { + temperature->restore_bias(ci, v[ci]); + temperature->restore_bias(di, v[di]); + } + } + } + } + MPI_Allreduce(ke2_int_drude_tmp, ke2_int_drude, 2, MPI_DOUBLE, MPI_SUM, world); + ke2int = ke2_int_drude[0] * force->mvv2e; + ke2drude = ke2_int_drude[1] * force->mvv2e; + t_int = ke2int / dof_int / boltz; + t_drude = ke2drude / dof_drude / boltz; + + temp_computed_end_of_step = end_of_step; +} + +/* ---------------------------------------------------------------------- + perform half-step update of chain thermostat variables +------------------------------------------------------------------------- */ + +void FixTGNHDrude::nhc_temp_integrate() +{ + compute_temp_mol_int_drude(false); + + // update masses of thermostat in case target temperature changes + etamol_mass[0] = ke2mol_target / (t_freq*t_freq); + etaint_mass[0] = ke2int_target / (t_freq*t_freq); + for (int ich = 1; ich < mtchain; ich++){ + etamol_mass[ich] = boltz * t_target / (t_freq*t_freq); + etaint_mass[ich] = boltz * t_target / (t_freq*t_freq); + } + + // thermostat for molecular COM + factor_eta_mol = propagate(etamol, etamol_dot, etamol_dotdot, etamol_mass, + ke2mol, ke2mol_target, t_target); + factor_eta_int = propagate(etaint, etaint_dot, etaint_dotdot, etaint_mass, + ke2int, ke2int_target, t_target); + factor_eta_drude = propagate(etadrude, etadrude_dot, etadrude_dotdot, etadrude_mass, + ke2drude, ke2drude_target, tdrude_target); + + nh_v_temp(); +} + +double FixTGNHDrude::propagate(double *eta, double *eta_dot, double *eta_dotdot, const double *eta_mass, + const double &ke2, const double &ke2_target, const double &tt) const { + int ich; + double expfac; + double ncfac = 1.0 / nc_tchain; + double factor_eta = 1.0; + + eta_dotdot[0] = (ke2 - ke2_target) / eta_mass[0]; + for (int iloop = 0; iloop < nc_tchain; iloop++) { + for (ich = mtchain - 1; ich > 0; ich--) { + expfac = exp(-ncfac * dt8 * eta_dot[ich + 1]); + eta_dot[ich] *= expfac; + eta_dot[ich] += eta_dotdot[ich] * ncfac * dt4; + eta_dot[ich] *= expfac; + } + expfac = exp(-ncfac * dt8 * eta_dot[1]); + eta_dot[0] *= expfac; + eta_dot[0] += eta_dotdot[0] * ncfac * dt4; + eta_dot[0] *= expfac; + factor_eta *= exp(-ncfac * dthalf * eta_dot[0]); + + for (ich = 0; ich < mtchain; ich++) + eta[ich] += ncfac * dthalf * eta_dot[ich]; + + eta_dotdot[0] = (ke2 * factor_eta * factor_eta - ke2_target) / eta_mass[0]; + eta_dot[0] *= expfac; + eta_dot[0] += eta_dotdot[0] * ncfac * dt4; + eta_dot[0] *= expfac; + for (ich = 1; ich < mtchain; ich++) { + expfac = exp(-ncfac * dt8 * eta_dot[ich + 1]); + eta_dot[ich] *= expfac; + eta_dotdot[ich] = (eta_mass[ich - 1] * eta_dot[ich - 1] * eta_dot[ich - 1] + - boltz * tt) / eta_mass[ich]; + eta_dot[ich] += eta_dotdot[ich] * ncfac * dt4; + eta_dot[ich] *= expfac; + } + } + return factor_eta; +} + +/* ---------------------------------------------------------------------- + perform half-step update of chain thermostat variables for barostat + scale barostat velocities +------------------------------------------------------------------------- */ + +void FixTGNHDrude::nhc_press_integrate() +{ + int ich,i,pdof; + double expfac,factor_etap,kecurrent; + double kt = boltz * t_target; + double lkt_press; + + // Update masses, to preserve initial freq, if t_target changed + double nkt = (atom->natoms + 1) * kt; + for (int i = 0; i < 3; i++) + if (p_flag[i]) + omega_mass[i] = nkt / (p_freq[i] * p_freq[i]); + if (pstyle == TRICLINIC) { + for (int i = 3; i < 6; i++) + if (p_flag[i]) omega_mass[i] = nkt / (p_freq[i] * p_freq[i]); + } + if (mpchain) { + etap_mass[0] = kt / (p_freq_max * p_freq_max); + for (int ich = 1; ich < mpchain; ich++) + etap_mass[ich] = kt / (p_freq_max * p_freq_max); + for (int ich = 1; ich < mpchain; ich++) + etap_dotdot[ich] = (etap_mass[ich - 1] * etap_dot[ich - 1] * etap_dot[ich - 1] + - kt) / etap_mass[ich]; + } + + kecurrent = 0.0; + pdof = 0; + for (i = 0; i < 3; i++) + if (p_flag[i]) { + kecurrent += omega_mass[i]*omega_dot[i]*omega_dot[i]; + pdof++; + } + + if (pstyle == TRICLINIC) { + for (i = 3; i < 6; i++) + if (p_flag[i]) { + kecurrent += omega_mass[i]*omega_dot[i]*omega_dot[i]; + pdof++; + } + } + + if (pstyle == ISO) lkt_press = kt; + else lkt_press = pdof * kt; + etap_dotdot[0] = (kecurrent - lkt_press)/etap_mass[0]; + + double ncfac = 1.0/nc_pchain; + for (int iloop = 0; iloop < nc_pchain; iloop++) { + + for (ich = mpchain-1; ich > 0; ich--) { + expfac = exp(-ncfac*dt8*etap_dot[ich+1]); + etap_dot[ich] *= expfac; + etap_dot[ich] += etap_dotdot[ich] * ncfac*dt4; + etap_dot[ich] *= expfac; + } + + expfac = exp(-ncfac*dt8*etap_dot[1]); + etap_dot[0] *= expfac; + etap_dot[0] += etap_dotdot[0] * ncfac*dt4; + etap_dot[0] *= expfac; + + for (ich = 0; ich < mpchain; ich++) + etap[ich] += ncfac*dthalf*etap_dot[ich]; + + factor_etap = exp(-ncfac*dthalf*etap_dot[0]); + for (i = 0; i < 3; i++) + if (p_flag[i]) omega_dot[i] *= factor_etap; + + if (pstyle == TRICLINIC) { + for (i = 3; i < 6; i++) + if (p_flag[i]) omega_dot[i] *= factor_etap; + } + + kecurrent = 0.0; + for (i = 0; i < 3; i++) + if (p_flag[i]) kecurrent += omega_mass[i]*omega_dot[i]*omega_dot[i]; + + if (pstyle == TRICLINIC) { + for (i = 3; i < 6; i++) + if (p_flag[i]) kecurrent += omega_mass[i]*omega_dot[i]*omega_dot[i]; + } + + etap_dotdot[0] = (kecurrent - lkt_press)/etap_mass[0]; + + etap_dot[0] *= expfac; + etap_dot[0] += etap_dotdot[0] * ncfac*dt4; + etap_dot[0] *= expfac; + + for (ich = 1; ich < mpchain; ich++) { + expfac = exp(-ncfac*dt8*etap_dot[ich+1]); + etap_dot[ich] *= expfac; + etap_dotdot[ich] = + (etap_mass[ich-1]*etap_dot[ich-1]*etap_dot[ich-1] - kt) / etap_mass[ich]; + etap_dot[ich] += etap_dotdot[ich] * ncfac*dt4; + etap_dot[ich] *= expfac; + } + } +} + +/* ---------------------------------------------------------------------- + perform half-step barostat scaling of velocities +-----------------------------------------------------------------------*/ + +void FixTGNHDrude::nh_v_press() +{ + double factor[3]; + double **v = atom->v; + int *mask = atom->mask; + int nlocal = atom->nlocal; + if (igroup == atom->firstgroup) nlocal = atom->nfirst; + + factor[0] = exp(-dt4*(omega_dot[0]+mtk_term2)); + factor[1] = exp(-dt4*(omega_dot[1]+mtk_term2)); + factor[2] = exp(-dt4*(omega_dot[2]+mtk_term2)); + + if (which == NOBIAS) { + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) { + v[i][0] *= factor[0]; + v[i][1] *= factor[1]; + v[i][2] *= factor[2]; + if (pstyle == TRICLINIC) { + v[i][0] += -dthalf*(v[i][1]*omega_dot[5] + v[i][2]*omega_dot[4]); + v[i][1] += -dthalf*v[i][2]*omega_dot[3]; + } + v[i][0] *= factor[0]; + v[i][1] *= factor[1]; + v[i][2] *= factor[2]; + } + } + } else if (which == BIAS) { + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) { + temperature->remove_bias(i,v[i]); + v[i][0] *= factor[0]; + v[i][1] *= factor[1]; + v[i][2] *= factor[2]; + if (pstyle == TRICLINIC) { + v[i][0] += -dthalf*(v[i][1]*omega_dot[5] + v[i][2]*omega_dot[4]); + v[i][1] += -dthalf*v[i][2]*omega_dot[3]; + } + v[i][0] *= factor[0]; + v[i][1] *= factor[1]; + v[i][2] *= factor[2]; + temperature->restore_bias(i,v[i]); + } + } + } +} + +/* ---------------------------------------------------------------------- + perform half-step update of velocities +-----------------------------------------------------------------------*/ + +void FixTGNHDrude::nve_v() +{ + double dtfm; + double **v = atom->v; + double **f = atom->f; + double *rmass = atom->rmass; + double *mass = atom->mass; + int *type = atom->type; + int *mask = atom->mask; + int nlocal = atom->nlocal; + if (igroup == atom->firstgroup) nlocal = atom->nfirst; + + if (rmass) { + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) { + dtfm = dtf / rmass[i]; + v[i][0] += dtfm*f[i][0]; + v[i][1] += dtfm*f[i][1]; + v[i][2] += dtfm*f[i][2]; + } + } + } else { + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) { + dtfm = dtf / mass[type[i]]; + v[i][0] += dtfm*f[i][0]; + v[i][1] += dtfm*f[i][1]; + v[i][2] += dtfm*f[i][2]; + } + } + } +} + +/* ---------------------------------------------------------------------- + perform full-step update of positions +-----------------------------------------------------------------------*/ + +void FixTGNHDrude::nve_x() +{ + double **x = atom->x; + double **v = atom->v; + int *mask = atom->mask; + int nlocal = atom->nlocal; + if (igroup == atom->firstgroup) nlocal = atom->nfirst; + + // x update by full step only for atoms in group + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) { + x[i][0] += dtv * v[i][0]; + x[i][1] += dtv * v[i][1]; + x[i][2] += dtv * v[i][2]; + } + } +} + +/* ---------------------------------------------------------------------- + perform half-step thermostat scaling of velocities +-----------------------------------------------------------------------*/ + +void FixTGNHDrude::nh_v_temp() +{ + double **v = atom->v; + double *mass = atom->mass; + int *mask = atom->mask; + int *type = atom->type; + tagint *molecule = atom->molecule; + int *drudetype = fix_drude->drudetype; + tagint *drudeid = fix_drude->drudeid; + + int imol, i, j, ci, di, itype; + double mass_com, mass_core, mass_drude; + double vint, vcom, vrel; + + /** + * If there are velocity bias, need to remove them before scale velocity + * Have to call remove_bias at the innermost loop, because drude atom may be a ghost + */ + for (i = 0; i < atom->nlocal; i++) { + if (mask[i] & groupbit) { + imol = molecule[i]; + itype = drudetype[type[i]]; + if (itype == NOPOL_TYPE) { + if (which == BIAS) + temperature->remove_bias(i, v[i]); + for (int k = 0; k < 3; k++) { + vint = v[i][k] - v_mol[imol][k]; + vint *= factor_eta_int; + v[i][k] = v_mol[imol][k] * factor_eta_mol + vint; + } + if (which == BIAS) + temperature->restore_bias(i, v[i]); + } else { + // have to use closest_image() because we are manipulating the velocity + j = domain->closest_image(i, atom->map(drudeid[i])); + if (itype == DRUDE_TYPE && j < atom->nlocal) continue; + if (itype == CORE_TYPE) { + ci = i; + di = j; + } else { + ci = j; + di = i; + } + if (which == BIAS) { + temperature->remove_bias(ci, v[ci]); + temperature->remove_bias(di, v[di]); + } + mass_core = mass[type[ci]]; + mass_drude = mass[type[di]]; + mass_com = mass_core + mass_drude; + for (int k = 0; k < 3; k++) { + vcom = (mass_core * v[ci][k] + mass_drude * v[di][k]) / mass_com; + vint = vcom - v_mol[imol][k]; + vrel = v[di][k] - v[ci][k]; + vint *= factor_eta_int; + vrel *= factor_eta_drude; + v[ci][k] = v_mol[imol][k] * factor_eta_mol + vint - vrel * mass_drude / mass_com; + v[di][k] = v_mol[imol][k] * factor_eta_mol + vint + vrel * mass_core / mass_com; + } + if (which == BIAS) { + temperature->restore_bias(ci, v[ci]); + temperature->restore_bias(di, v[di]); + } + } + } + } +} + +/* ---------------------------------------------------------------------- + compute sigma tensor + needed whenever p_target or h0_inv changes +-----------------------------------------------------------------------*/ + +void FixTGNHDrude::compute_sigma() +{ + // if nreset_h0 > 0, reset vol0 and h0_inv + // every nreset_h0 timesteps + + if (nreset_h0 > 0) { + int delta = update->ntimestep - update->beginstep; + if (delta % nreset_h0 == 0) { + if (dimension == 3) vol0 = domain->xprd * domain->yprd * domain->zprd; + else vol0 = domain->xprd * domain->yprd; + h0_inv[0] = domain->h_inv[0]; + h0_inv[1] = domain->h_inv[1]; + h0_inv[2] = domain->h_inv[2]; + h0_inv[3] = domain->h_inv[3]; + h0_inv[4] = domain->h_inv[4]; + h0_inv[5] = domain->h_inv[5]; + } + } + + // generate upper-triangular half of + // sigma = vol0*h0inv*(p_target-p_hydro)*h0inv^t + // units of sigma are are PV/L^2 e.g. atm.A + // + // [ 0 5 4 ] [ 0 5 4 ] [ 0 5 4 ] [ 0 - - ] + // [ 5 1 3 ] = [ - 1 3 ] [ 5 1 3 ] [ 5 1 - ] + // [ 4 3 2 ] [ - - 2 ] [ 4 3 2 ] [ 4 3 2 ] + + sigma[0] = + vol0*(h0_inv[0]*((p_target[0]-p_hydro)*h0_inv[0] + + p_target[5]*h0_inv[5]+p_target[4]*h0_inv[4]) + + h0_inv[5]*(p_target[5]*h0_inv[0] + + (p_target[1]-p_hydro)*h0_inv[5]+p_target[3]*h0_inv[4]) + + h0_inv[4]*(p_target[4]*h0_inv[0]+p_target[3]*h0_inv[5] + + (p_target[2]-p_hydro)*h0_inv[4])); + sigma[1] = + vol0*(h0_inv[1]*((p_target[1]-p_hydro)*h0_inv[1] + + p_target[3]*h0_inv[3]) + + h0_inv[3]*(p_target[3]*h0_inv[1] + + (p_target[2]-p_hydro)*h0_inv[3])); + sigma[2] = + vol0*(h0_inv[2]*((p_target[2]-p_hydro)*h0_inv[2])); + sigma[3] = + vol0*(h0_inv[1]*(p_target[3]*h0_inv[2]) + + h0_inv[3]*((p_target[2]-p_hydro)*h0_inv[2])); + sigma[4] = + vol0*(h0_inv[0]*(p_target[4]*h0_inv[2]) + + h0_inv[5]*(p_target[3]*h0_inv[2]) + + h0_inv[4]*((p_target[2]-p_hydro)*h0_inv[2])); + sigma[5] = + vol0*(h0_inv[0]*(p_target[5]*h0_inv[1]+p_target[4]*h0_inv[3]) + + h0_inv[5]*((p_target[1]-p_hydro)*h0_inv[1]+p_target[3]*h0_inv[3]) + + h0_inv[4]*(p_target[3]*h0_inv[1]+(p_target[2]-p_hydro)*h0_inv[3])); +} + +/* ---------------------------------------------------------------------- + compute strain energy +-----------------------------------------------------------------------*/ + +double FixTGNHDrude::compute_strain_energy() +{ + // compute strain energy = 0.5*Tr(sigma*h*h^t) in energy units + + double* h = domain->h; + double d0,d1,d2; + + d0 = + sigma[0]*(h[0]*h[0]+h[5]*h[5]+h[4]*h[4]) + + sigma[5]*( h[1]*h[5]+h[3]*h[4]) + + sigma[4]*( h[2]*h[4]); + d1 = + sigma[5]*( h[5]*h[1]+h[4]*h[3]) + + sigma[1]*( h[1]*h[1]+h[3]*h[3]) + + sigma[3]*( h[2]*h[3]); + d2 = + sigma[4]*( h[4]*h[2]) + + sigma[3]*( h[3]*h[2]) + + sigma[2]*( h[2]*h[2]); + + double energy = 0.5*(d0+d1+d2)/nktv2p; + return energy; +} + +/* ---------------------------------------------------------------------- + compute deviatoric barostat force = h*sigma*h^t +-----------------------------------------------------------------------*/ + +void FixTGNHDrude::compute_deviatoric() +{ + // generate upper-triangular part of h*sigma*h^t + // units of fdev are are PV, e.g. atm*A^3 + // [ 0 5 4 ] [ 0 5 4 ] [ 0 5 4 ] [ 0 - - ] + // [ 5 1 3 ] = [ - 1 3 ] [ 5 1 3 ] [ 5 1 - ] + // [ 4 3 2 ] [ - - 2 ] [ 4 3 2 ] [ 4 3 2 ] + + double* h = domain->h; + + fdev[0] = + h[0]*(sigma[0]*h[0]+sigma[5]*h[5]+sigma[4]*h[4]) + + h[5]*(sigma[5]*h[0]+sigma[1]*h[5]+sigma[3]*h[4]) + + h[4]*(sigma[4]*h[0]+sigma[3]*h[5]+sigma[2]*h[4]); + fdev[1] = + h[1]*( sigma[1]*h[1]+sigma[3]*h[3]) + + h[3]*( sigma[3]*h[1]+sigma[2]*h[3]); + fdev[2] = + h[2]*( sigma[2]*h[2]); + fdev[3] = + h[1]*( sigma[3]*h[2]) + + h[3]*( sigma[2]*h[2]); + fdev[4] = + h[0]*( sigma[4]*h[2]) + + h[5]*( sigma[3]*h[2]) + + h[4]*( sigma[2]*h[2]); + fdev[5] = + h[0]*( sigma[5]*h[1]+sigma[4]*h[3]) + + h[5]*( sigma[1]*h[1]+sigma[3]*h[3]) + + h[4]*( sigma[3]*h[1]+sigma[2]*h[3]); +} + +/* ---------------------------------------------------------------------- + compute target temperature and kinetic energy +-----------------------------------------------------------------------*/ + +void FixTGNHDrude::compute_temp_target() +{ + double delta = update->ntimestep - update->beginstep; + if (delta != 0.0) delta /= update->endstep - update->beginstep; + + t_target = t_start + delta * (t_stop-t_start); + ke2mol_target = dof_mol * boltz * t_target; + ke2int_target = dof_int * boltz * t_target; + ke2drude_target = dof_drude * boltz * tdrude_target; +} + +/* ---------------------------------------------------------------------- + compute hydrostatic target pressure +-----------------------------------------------------------------------*/ + +void FixTGNHDrude::compute_press_target() +{ + double delta = update->ntimestep - update->beginstep; + if (delta != 0.0) delta /= update->endstep - update->beginstep; + + p_hydro = 0.0; + for (int i = 0; i < 3; i++) + if (p_flag[i]) { + p_target[i] = p_start[i] + delta * (p_stop[i]-p_start[i]); + p_hydro += p_target[i]; + } + if (pdim > 0) p_hydro /= pdim; + + if (pstyle == TRICLINIC) + for (int i = 3; i < 6; i++) + p_target[i] = p_start[i] + delta * (p_stop[i]-p_start[i]); + + // if deviatoric, recompute sigma each time p_target changes + + if (deviatoric_flag) compute_sigma(); +} + +/* ---------------------------------------------------------------------- + update omega_dot, omega +-----------------------------------------------------------------------*/ + +void FixTGNHDrude::nh_omega_dot() +{ + double f_omega,volume; + + if (dimension == 3) volume = domain->xprd*domain->yprd*domain->zprd; + else volume = domain->xprd*domain->yprd; + + if (deviatoric_flag) compute_deviatoric(); + + mtk_term1 = 0.0; + if (mtk_flag) { + if (pstyle == ISO) { + mtk_term1 = tdof * boltz * t_current; + mtk_term1 /= pdim * atom->natoms; + } else { + double *mvv_current = temperature->vector; + for (int i = 0; i < 3; i++) + if (p_flag[i]) + mtk_term1 += mvv_current[i]; + mtk_term1 /= pdim * atom->natoms; + } + } + + for (int i = 0; i < 3; i++) + if (p_flag[i]) { + f_omega = (p_current[i]-p_hydro)*volume / + (omega_mass[i] * nktv2p) + mtk_term1 / omega_mass[i]; + if (deviatoric_flag) f_omega -= fdev[i]/(omega_mass[i] * nktv2p); + omega_dot[i] += f_omega*dthalf; + } + + mtk_term2 = 0.0; + if (mtk_flag) { + for (int i = 0; i < 3; i++) + if (p_flag[i]) + mtk_term2 += omega_dot[i]; + if (pdim > 0) mtk_term2 /= pdim * atom->natoms; + } + + if (pstyle == TRICLINIC) { + for (int i = 3; i < 6; i++) { + if (p_flag[i]) { + f_omega = p_current[i]*volume/(omega_mass[i] * nktv2p); + if (deviatoric_flag) + f_omega -= fdev[i]/(omega_mass[i] * nktv2p); + omega_dot[i] += f_omega*dthalf; + } + } + } +} + +/* ---------------------------------------------------------------------- + if any tilt ratios exceed limits, set flip = 1 and compute new tilt values + do not flip in x or y if non-periodic (can tilt but not flip) + this is b/c the box length would be changed (dramatically) by flip + if yz tilt exceeded, adjust C vector by one B vector + if xz tilt exceeded, adjust C vector by one A vector + if xy tilt exceeded, adjust B vector by one A vector + check yz first since it may change xz, then xz check comes after + if any flip occurs, create new box in domain + image_flip() adjusts image flags due to box shape change induced by flip + remap() puts atoms outside the new box back into the new box + perform irregular on atoms in lamda coords to migrate atoms to new procs + important that image_flip comes before remap, since remap may change + image flags to new values, making eqs in doc of Domain:image_flip incorrect +------------------------------------------------------------------------- */ + +void FixTGNHDrude::pre_exchange() +{ + double xprd = domain->xprd; + double yprd = domain->yprd; + + // flip is only triggered when tilt exceeds 0.5 by DELTAFLIP + // this avoids immediate re-flipping due to tilt oscillations + + double xtiltmax = (0.5+DELTAFLIP)*xprd; + double ytiltmax = (0.5+DELTAFLIP)*yprd; + + int flipxy,flipxz,flipyz; + flipxy = flipxz = flipyz = 0; + + if (domain->yperiodic) { + if (domain->yz < -ytiltmax) { + domain->yz += yprd; + domain->xz += domain->xy; + flipyz = 1; + } else if (domain->yz >= ytiltmax) { + domain->yz -= yprd; + domain->xz -= domain->xy; + flipyz = -1; + } + } + + if (domain->xperiodic) { + if (domain->xz < -xtiltmax) { + domain->xz += xprd; + flipxz = 1; + } else if (domain->xz >= xtiltmax) { + domain->xz -= xprd; + flipxz = -1; + } + if (domain->xy < -xtiltmax) { + domain->xy += xprd; + flipxy = 1; + } else if (domain->xy >= xtiltmax) { + domain->xy -= xprd; + flipxy = -1; + } + } + + int flip = 0; + if (flipxy || flipxz || flipyz) flip = 1; + + if (flip) { + domain->set_global_box(); + domain->set_local_box(); + + domain->image_flip(flipxy,flipxz,flipyz); + + double **x = atom->x; + imageint *image = atom->image; + int nlocal = atom->nlocal; + for (int i = 0; i < nlocal; i++) domain->remap(x[i],image[i]); + + domain->x2lamda(atom->nlocal); + irregular->migrate_atoms(); + domain->lamda2x(atom->nlocal); + } +} + +/* ---------------------------------------------------------------------- + memory usage of Irregular +------------------------------------------------------------------------- */ + +double FixTGNHDrude::memory_usage() +{ + double bytes = 0.0; + if (irregular) bytes += irregular->memory_usage(); + return bytes; +} diff --git a/src/USER-DRUDE/fix_tgnh_drude.h b/src/USER-DRUDE/fix_tgnh_drude.h new file mode 100644 index 0000000000..4d29bb90e7 --- /dev/null +++ b/src/USER-DRUDE/fix_tgnh_drude.h @@ -0,0 +1,295 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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. +------------------------------------------------------------------------- */ + +#ifndef LMP_FIX_TGNH_DRUDE_H +#define LMP_FIX_TGNH_DRUDE_H + +#include "fix.h" +#include "fix_drude.h" + +namespace LAMMPS_NS { + +class FixTGNHDrude : public Fix { + public: + FixTGNHDrude(class LAMMPS *, int, char **); + virtual ~FixTGNHDrude(); + int setmask(); + virtual void init(); + virtual void setup(int); + virtual void initial_integrate(int); + virtual void final_integrate(); + void initial_integrate_respa(int, int, int); + void final_integrate_respa(int, int); + virtual void pre_exchange(); + double compute_scalar(); + virtual double compute_vector(int); + void write_restart(FILE *); + virtual int pack_restart_data(double *); // pack restart data + virtual void restart(char *); + int modify_param(int, char **); + void reset_target(double); + void reset_dt(); + double memory_usage(); + + protected: + int dimension,which; + double dtv,dtf,dthalf,dt4,dt8,dto; + double boltz,nktv2p,tdof; + double vol0; // reference volume + double t0; // reference temperature + // used for barostat mass + double t_start,t_stop; + double t_current,t_target; + double t_freq; + + int tstat_flag; // 1 if control T + int pstat_flag; // 1 if control P + + int pstyle,pcouple; + int p_flag[6]; // 1 if control P on this dim, 0 if not + double p_start[6],p_stop[6]; + double p_freq[6],p_target[6]; + double omega[6],omega_dot[6]; + double omega_mass[6]; + double p_current[6]; + int kspace_flag; // 1 if KSpace invoked, 0 if not + int nrigid; // number of rigid fixes + int *rfix; // indices of rigid fixes + class Irregular *irregular; // for migrating atoms after box flips + + int nlevels_respa; + double *step_respa; + + char *id_temp,*id_press; + class Compute *temperature,*pressure; + int tcomputeflag,pcomputeflag; // 1 = compute was created by fix + // 0 = created externally + + double *etamol; + double *etamol_dot; // chain thermostat for motion of whole molecules + double *etamol_dotdot; + double *etamol_mass; + + double *etaint; + double *etaint_dot; // chain thermostat for internal DOFs + double *etaint_dotdot; + double *etaint_mass; + + double *etadrude; + double *etadrude_dot; // chain thermostat for Drude relative motions + double *etadrude_dotdot; + double *etadrude_mass; + + double *etap; // chain thermostat for barostat + double *etap_dot; + double *etap_dotdot; + double *etap_mass; + + int mtchain; // length of chain + int mpchain; // length of chain + + int mtk_flag; // 0 if using Hoover barostat + int pdim; // number of barostatted dims + double p_freq_max; // maximum barostat frequency + + double p_hydro; // hydrostatic target pressure + + int nc_tchain,nc_pchain; + double sigma[6]; // scaled target stress + double fdev[6]; // deviatoric force on barostat + int deviatoric_flag; // 0 if target stress tensor is hydrostatic + double h0_inv[6]; // h_inv of reference (zero strain) box + int nreset_h0; // interval for resetting h0 + + double mtk_term1,mtk_term2; // Martyna-Tobias-Klein corrections + + int scaleyz; // 1 if yz scaled with lz + int scalexz; // 1 if xz scaled with lz + int scalexy; // 1 if xy scaled with ly + int flipflag; // 1 if box flips are invoked as needed + + int pre_exchange_flag; // set if pre_exchange needed for box flips + + double fixedpoint[3]; // location of dilation fixed-point + + void couple(); + virtual void remap(); + void nhc_temp_integrate(); + void nhc_press_integrate(); + + virtual void nve_x(); // may be overwritten by child classes + virtual void nve_v(); + virtual void nh_v_press(); + virtual void nh_v_temp(); + virtual void compute_temp_target(); + virtual int size_restart_global(); + + void compute_sigma(); + void compute_deviatoric(); + double compute_strain_energy(); + void compute_press_target(); + void nh_omega_dot(); + + + class FixDrude * fix_drude; + int n_mol; // number of molecules in the system + double *mass_mol; + double dof_mol, dof_int, dof_drude; // DOFs of different modes in the fix group + void setup_mol_mass_dof(); + double **v_mol, **v_mol_tmp; + void compute_temp_mol_int_drude(bool); // calculate the temperatures of three sets of DOFs + bool temp_computed_end_of_step = false; + double tdrude_target, tdrude_freq; + double t_mol, t_int, t_drude; + double ke2mol, ke2int, ke2drude; + double ke2mol_target, ke2int_target, ke2drude_target; + double factor_eta_mol, factor_eta_int, factor_eta_drude; + double propagate(double *, double *, double *, const double *, const double &, const double &, const double &) const; +}; + +} + +#endif + +/* ERROR/WARNING messages: + +E: Illegal ... command + +Self-explanatory. Check the input script syntax and compare to the +documentation for the command. You can use -echo screen as a +command-line option when running LAMMPS to see the offending line. + +E: Target temperature for fix nvt/npt/nph cannot be 0.0 + +Self-explanatory. + +E: Invalid fix nvt/npt/nph command for a 2d simulation + +Cannot control z dimension in a 2d model. + +E: Fix nvt/npt/nph dilate group ID does not exist + +Self-explanatory. + +E: Invalid fix nvt/npt/nph command pressure settings + +If multiple dimensions are coupled, those dimensions must be +specified. + +E: Cannot use fix nvt/npt/nph on a non-periodic dimension + +When specifying a diagonal pressure component, the dimension must be +periodic. + +E: Cannot use fix nvt/npt/nph on a 2nd non-periodic dimension + +When specifying an off-diagonal pressure component, the 2nd of the two +dimensions must be periodic. E.g. if the xy component is specified, +then the y dimension must be periodic. + +E: Cannot use fix nvt/npt/nph with yz scaling when z is non-periodic dimension + +The 2nd dimension in the barostatted tilt factor must be periodic. + +E: Cannot use fix nvt/npt/nph with xz scaling when z is non-periodic dimension + +The 2nd dimension in the barostatted tilt factor must be periodic. + +E: Cannot use fix nvt/npt/nph with xy scaling when y is non-periodic dimension + +The 2nd dimension in the barostatted tilt factor must be periodic. + +E: Cannot use fix nvt/npt/nph with both yz dynamics and yz scaling + +Self-explanatory. + +E: Cannot use fix nvt/npt/nph with both xz dynamics and xz scaling + +Self-explanatory. + +E: Cannot use fix nvt/npt/nph with both xy dynamics and xy scaling + +Self-explanatory. + +E: Can not specify Pxy/Pxz/Pyz in fix nvt/npt/nph with non-triclinic box + +Only triclinic boxes can be used with off-diagonal pressure components. +See the region prism command for details. + +E: Invalid fix nvt/npt/nph pressure settings + +Settings for coupled dimensions must be the same. + +E: Using update dipole flag requires atom style sphere + +Self-explanatory. + +E: Using update dipole flag requires atom attribute mu + +Self-explanatory. + +E: Fix nvt/npt/nph damping parameters must be > 0.0 + +Self-explanatory. + +E: Cannot use fix npt and fix deform on same component of stress tensor + +This would be changing the same box dimension twice. + +E: Temperature ID for fix nvt/npt does not exist + +Self-explanatory. + +E: Pressure ID for fix npt/nph does not exist + +Self-explanatory. + +E: Non-numeric pressure - simulation unstable + +UNDOCUMENTED + +E: Fix npt/nph has tilted box too far in one step - periodic cell is too far from equilibrium state + +Self-explanatory. The change in the box tilt is too extreme +on a short timescale. + +E: Could not find fix_modify temperature ID + +The compute ID for computing temperature does not exist. + +E: Fix_modify temperature ID does not compute temperature + +The compute ID assigned to the fix must compute temperature. + +W: Temperature for fix modify is not for group all + +The temperature compute is being used with a pressure calculation +which does operate on group all, so this may be inconsistent. + +E: Pressure ID for fix modify does not exist + +Self-explanatory. + +E: Could not find fix_modify pressure ID + +The compute ID for computing pressure does not exist. + +E: Fix_modify pressure ID does not compute pressure + +The compute ID assigned to the fix must compute pressure. + +U: The dlm flag must be used with update dipole + +Self-explanatory. + +*/ diff --git a/src/USER-DRUDE/fix_tgnpt_drude.cpp b/src/USER-DRUDE/fix_tgnpt_drude.cpp new file mode 100644 index 0000000000..987af367c3 --- /dev/null +++ b/src/USER-DRUDE/fix_tgnpt_drude.cpp @@ -0,0 +1,57 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://lammps.sandia.gov/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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. +------------------------------------------------------------------------- */ + +#include "fix_tgnpt_drude.h" +#include + +#include "modify.h" +#include "error.h" + +using namespace LAMMPS_NS; +using namespace FixConst; + +/* ---------------------------------------------------------------------- */ + +FixTGNPTDrude::FixTGNPTDrude(LAMMPS *lmp, int narg, char **arg) : + FixTGNHDrude(lmp, narg, arg) +{ + if (!tstat_flag) + error->all(FLERR,"Temperature control must be used with fix npt"); + if (!pstat_flag) + error->all(FLERR,"Pressure control must be used with fix npt"); + + // create a new compute temp style + // id = fix-ID + temp + // compute group = all since pressure is always global (group all) + // and thus its KE/temperature contribution should use group all + + std::string tcmd = id + std::string("_temp"); + id_temp = new char[tcmd.size()+1]; + strcpy(id_temp, tcmd.c_str()); + + tcmd += " all temp"; + modify->add_compute(tcmd); + tcomputeflag = 1; + + // create a new compute pressure style + // id = fix-ID + press, compute group = all + // pass id_temp as 4th arg to pressure constructor + + std::string pcmd = id + std::string("_press"); + id_press = new char[pcmd.size()+1]; + strcpy(id_press, pcmd.c_str()); + + pcmd += " all pressure " + std::string(id_temp); + modify->add_compute(pcmd); + pcomputeflag = 1; +} diff --git a/src/USER-DRUDE/fix_tgnpt_drude.h b/src/USER-DRUDE/fix_tgnpt_drude.h new file mode 100644 index 0000000000..afb55ae0d7 --- /dev/null +++ b/src/USER-DRUDE/fix_tgnpt_drude.h @@ -0,0 +1,48 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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 FIX_CLASS + +FixStyle(tgnpt/drude,FixTGNPTDrude) + +#else + +#ifndef LMP_FIX_TGNPT_DRUDE_H +#define LMP_FIX_TGNPT_DRUDE_H + +#include "fix_tgnh_drude.h" + +namespace LAMMPS_NS { + +class FixTGNPTDrude : public FixTGNHDrude { + public: + FixTGNPTDrude(class LAMMPS *, int, char **); + ~FixTGNPTDrude() {} +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +E: Temperature control must be used with fix npt + +Self-explanatory. + +E: Pressure control must be used with fix npt + +Self-explanatory. + +*/ diff --git a/src/USER-DRUDE/fix_tgnvt_drude.cpp b/src/USER-DRUDE/fix_tgnvt_drude.cpp new file mode 100644 index 0000000000..bd6809aaed --- /dev/null +++ b/src/USER-DRUDE/fix_tgnvt_drude.cpp @@ -0,0 +1,44 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://lammps.sandia.gov/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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. +------------------------------------------------------------------------- */ + +#include "fix_tgnvt_drude.h" +#include + +#include "group.h" +#include "modify.h" +#include "error.h" + +using namespace LAMMPS_NS; +using namespace FixConst; + +/* ---------------------------------------------------------------------- */ + +FixTGNVTDrude::FixTGNVTDrude(LAMMPS *lmp, int narg, char **arg) : + FixTGNHDrude(lmp, narg, arg) +{ + if (!tstat_flag) + error->all(FLERR,"Temperature control must be used with fix nvt"); + if (pstat_flag) + error->all(FLERR,"Pressure control can not be used with fix nvt"); + + // create a new compute temp style + // id = fix-ID + temp + + std::string tcmd = id + std::string("_temp"); + id_temp = new char[tcmd.size()+1]; + strcpy(id_temp, tcmd.c_str()); + + tcmd += fmt::format(" {} temp", group->names[igroup]); + modify->add_compute(tcmd); + tcomputeflag = 1; +} diff --git a/src/USER-DRUDE/fix_tgnvt_drude.h b/src/USER-DRUDE/fix_tgnvt_drude.h new file mode 100644 index 0000000000..64f2e52e9c --- /dev/null +++ b/src/USER-DRUDE/fix_tgnvt_drude.h @@ -0,0 +1,48 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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 FIX_CLASS + +FixStyle(tgnvt/drude,FixTGNVTDrude) + +#else + +#ifndef LMP_FIX_TGNVT_DRUDE_H +#define LMP_FIX_TGNVT_DRUDE_H + +#include "fix_tgnh_drude.h" + +namespace LAMMPS_NS { + +class FixTGNVTDrude: public FixTGNHDrude { + public: + FixTGNVTDrude(class LAMMPS *, int, char **); + ~FixTGNVTDrude() {} +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +E: Temperature control must be used with fix nvt + +Self-explanatory. + +E: Pressure control can not be used with fix nvt + +Self-explanatory. + +*/ diff --git a/src/USER-MESONT/pair_mesocnt.cpp b/src/USER-MESONT/pair_mesocnt.cpp index 39a97321a7..f460e3aebb 100644 --- a/src/USER-MESONT/pair_mesocnt.cpp +++ b/src/USER-MESONT/pair_mesocnt.cpp @@ -546,7 +546,7 @@ void PairMesoCNT::bond_neigh() if (i2 > nlocal-1 && false) numneigh2 = 0; else numneigh2 = numneigh[i2]; - int numneigh_max_local = numneigh1 + numneigh1; + int numneigh_max_local = numneigh1 + numneigh2; if (numneigh_max_local > numneigh_max) numneigh_max = numneigh_max_local; } if (numneigh_max > reduced_neigh_size) { diff --git a/src/USER-MESONT/pair_mesont_tpm.cpp b/src/USER-MESONT/pair_mesont_tpm.cpp index 1271ebddb6..2a18bd64c9 100644 --- a/src/USER-MESONT/pair_mesont_tpm.cpp +++ b/src/USER-MESONT/pair_mesont_tpm.cpp @@ -510,33 +510,28 @@ void PairMESONTTPM::compute(int eflag, int vflag) { buckling[idx] = b_sort[i]; } if (eflag_global) { - eng_vdwl = 0.0; energy_s = 0.0; - energy_b = 0.0; energy_t = 0.0; + energy_s = energy_b = energy_t = 0.0; for (int i = 0; i < nall; i++) { - int idx = ntlist.get_idx(i); energy_s += u_ts_sort[i]; energy_b += u_tb_sort[i]; energy_t += u_tt_sort[i]; } - eng_vdwl = energy_s + energy_b + energy_t; + eng_vdwl += energy_s + energy_b + energy_t; } if (eflag_atom) { - for (int i = 0; i < ntot; i++) { - eatom[i] = 0.0; eatom_s[i] = 0.0; - eatom_b[i] = 0.0; eatom_t[i] = 0.0; - } + for (int i = 0; i < ntot; i++) + eatom_s[i] = eatom_b[i] = eatom_t[i] = 0.0; + for (int i = 0; i < nall; i++) { int idx = ntlist.get_idx(i); - eatom_s[idx] = u_ts_sort[i]; - eatom_b[idx] = u_tb_sort[i]; - eatom_t[idx] = u_tt_sort[i]; - eatom[idx] = u_ts_sort[i] + u_tb_sort[i] + u_tt_sort[i]; + eatom_s[idx] += u_ts_sort[i]; + eatom_b[idx] += u_tb_sort[i]; + eatom_t[idx] += u_tt_sort[i]; + eatom[idx] += u_ts_sort[i] + u_tb_sort[i] + u_tt_sort[i]; } } if (vflag_global) { - for (int i = 0; i < 6; i++) virial[i] = 0.0; for (int i = 0; i < nall; i++) { - int idx = ntlist.get_idx(i); virial[0] += s_sort[9*i+0]; //xx virial[1] += s_sort[9*i+4]; //yy virial[2] += s_sort[9*i+8]; //zz @@ -546,16 +541,14 @@ void PairMESONTTPM::compute(int eflag, int vflag) { } } if (vflag_atom) { - for (int i = 0; i < ntot; i++) - for (int j = 0; j < 6; j++) vatom[i][j] = 0.0; for (int i = 0; i < nall; i++) { int idx = ntlist.get_idx(i); - vatom[idx][0] = s_sort[9*i+0]; //xx - vatom[idx][1] = s_sort[9*i+4]; //yy - vatom[idx][2] = s_sort[9*i+8]; //zz - vatom[idx][3] = s_sort[9*i+1]; //xy - vatom[idx][4] = s_sort[9*i+2]; //xz - vatom[idx][5] = s_sort[9*i+5]; //yz + vatom[idx][0] += s_sort[9*i+0]; //xx + vatom[idx][1] += s_sort[9*i+4]; //yy + vatom[idx][2] += s_sort[9*i+8]; //zz + vatom[idx][3] += s_sort[9*i+1]; //xy + vatom[idx][4] += s_sort[9*i+2]; //xz + vatom[idx][5] += s_sort[9*i+5]; //yz } } diff --git a/src/USER-MISC/angle_gaussian.cpp b/src/USER-MISC/angle_gaussian.cpp index 640be38433..554b19cfb5 100644 --- a/src/USER-MISC/angle_gaussian.cpp +++ b/src/USER-MISC/angle_gaussian.cpp @@ -62,7 +62,7 @@ void AngleGaussian::compute(int eflag, int vflag) int i1,i2,i3,n,type; double delx1,dely1,delz1,delx2,dely2,delz2; double eangle,f1[3],f3[3]; - double dtheta,tk; + double dtheta; double rsq1,rsq2,r1,r2,c,s,a,a11,a12,a22; double prefactor, exponent, g_i, sum_g_i, sum_numerator; @@ -331,7 +331,6 @@ double AngleGaussian::single(int type, int i1, int i2, int i3) double theta = acos(c) ; double sum_g_i = 0.0; - double sum_numerator = 0.0; for (int i = 0; i < nterms[type]; i++) { double dtheta = theta - theta0[type][i]; double prefactor = (alpha[type][i]/(width[type][i]*sqrt(MY_PI2))); diff --git a/src/USER-MISC/dihedral_quadratic.cpp b/src/USER-MISC/dihedral_quadratic.cpp index bfe13d13d1..ef5711215c 100644 --- a/src/USER-MISC/dihedral_quadratic.cpp +++ b/src/USER-MISC/dihedral_quadratic.cpp @@ -195,6 +195,8 @@ void DihedralQuadratic::compute(int eflag, int vflag) siinv = 1.0/si; double dphi = phi-phi0[type]; + if (dphi > MY_PI) dphi -= 2*MY_PI; + else if (dphi < -MY_PI) dphi += 2*MY_PI; p = k[type]*dphi; pd = - 2.0 * p * siinv; p = p * dphi; diff --git a/src/USER-MISC/fix_electron_stopping_fit.cpp b/src/USER-MISC/fix_electron_stopping_fit.cpp index e6fa0f2b9b..2d9034aaef 100644 --- a/src/USER-MISC/fix_electron_stopping_fit.cpp +++ b/src/USER-MISC/fix_electron_stopping_fit.cpp @@ -62,9 +62,9 @@ static const char cite_fix_electron_stopping_fit_c[] = // --------------------------------------------------------------------- FixElectronStoppingFit::FixElectronStoppingFit(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp,narg,arg), energy_coh_in(nullptr), drag_fac_in_1(nullptr), - drag_fac_in_2(nullptr), drag_fac_1(nullptr), drag_fac_2(nullptr), - v_min_sq(nullptr), v_max_sq(nullptr) + Fix(lmp,narg,arg), energy_coh_in(nullptr), v_min_sq(nullptr), v_max_sq(nullptr), + drag_fac_in_1(nullptr), drag_fac_in_2(nullptr), + drag_fac_1(nullptr), drag_fac_2(nullptr) { if (lmp->citeme) lmp->citeme->add(cite_fix_electron_stopping_fit_c); @@ -151,7 +151,7 @@ void FixElectronStoppingFit::setup(int vflag) // --------------------------------------------------------------------- -void FixElectronStoppingFit::post_force(int vflag) +void FixElectronStoppingFit::post_force(int /*vflag*/) { double **v = atom->v; double **f = atom->f; @@ -192,7 +192,7 @@ void FixElectronStoppingFit::post_force(int vflag) // --------------------------------------------------------------------- -void FixElectronStoppingFit::post_force_respa(int vflag, int ilevel, int iloop) +void FixElectronStoppingFit::post_force_respa(int vflag, int ilevel, int /*iloop*/) { if (ilevel == nlevels_respa-1) post_force(vflag); }; diff --git a/src/USER-MISC/pair_edip.cpp b/src/USER-MISC/pair_edip.cpp index b29f499de8..12390ba69d 100644 --- a/src/USER-MISC/pair_edip.cpp +++ b/src/USER-MISC/pair_edip.cpp @@ -46,7 +46,7 @@ using namespace LAMMPS_NS; // max number of interaction per atom for f(Z) environment potential -#define leadDimInteractionList 64 +static constexpr int leadDimInteractionList = 64; /* ---------------------------------------------------------------------- */ diff --git a/src/USER-MISC/pair_edip_multi.cpp b/src/USER-MISC/pair_edip_multi.cpp index 811f80abfc..9d36db7041 100644 --- a/src/USER-MISC/pair_edip_multi.cpp +++ b/src/USER-MISC/pair_edip_multi.cpp @@ -32,13 +32,11 @@ #include "error.h" #include "citeme.h" - using namespace LAMMPS_NS; #define MAXLINE 1024 #define DELTA 4 - static const char cite_pair_edip[] = "@article{cjiang2012\n" " author = {Jian, Chao and Morgan, Dane, and Szlufarska, Izabella},\n" @@ -56,7 +54,9 @@ static const char cite_pair_edip[] = " year = {2010},\n" "}\n\n"; +// max number of interaction per atom for f(Z) environment potential +static constexpr int leadDimInteractionList = 64; /* ---------------------------------------------------------------------- */ @@ -94,7 +94,6 @@ PairEDIPMulti::~PairEDIPMulti() memory->destroy(cutsq); delete [] map; -//XXX deallocateGrids(); deallocatePreLoops(); } } diff --git a/src/USER-MISC/pair_edip_multi.h b/src/USER-MISC/pair_edip_multi.h index 26433a66fa..5120ece5d2 100644 --- a/src/USER-MISC/pair_edip_multi.h +++ b/src/USER-MISC/pair_edip_multi.h @@ -36,17 +36,17 @@ class PairEDIPMulti : public Pair { protected: struct Param { - double A, B;//coefficients for pair interaction I-J - double cutoffA;//cut-off distance for pair interaction I-J - double cutoffC;//lower cut-off distance for calculating Z_I - double alpha;//coefficient for calculating Z_I - double beta;//attractive term for pair I-J - double sigma;//cut-off coefficient for pair I-J - double rho;//pair I-J - double gamma;//coefficient for three-body interaction I-J-K - double eta, lambda;//coefficients for function h(l,Z) - double mu, Q0;//coefficients for function Q(Z) - double u1, u2, u3, u4;//coefficients for function tau(Z) + double A, B; // coefficients for pair interaction I-J + double cutoffA; // cut-off distance for pair interaction I-J + double cutoffC; // lower cut-off distance for calculating Z_I + double alpha; // coefficient for calculating Z_I + double beta; // attractive term for pair I-J + double sigma; // cut-off coefficient for pair I-J + double rho; // pair I-J + double gamma; // coefficient for three-body interaction I-J-K + double eta, lambda; // coefficients for function h(l,Z) + double mu, Q0; // coefficients for function Q(Z) + double u1, u2, u3, u4; // coefficients for function tau(Z) double cutsq; int ielement,jelement,kelement; }; @@ -62,10 +62,6 @@ class PairEDIPMulti : public Pair { int maxparam; // max # of parameter sets Param *params; // parameter set for an I-J-K interaction - // max number of interaction per atom for f(Z) environment potential - - static const int leadDimInteractionList = 64; - void allocate(); void allocatePreLoops(void); void deallocatePreLoops(void); diff --git a/src/USER-MISC/pair_tersoff_table.h b/src/USER-MISC/pair_tersoff_table.h index faa704191c..d63a5be5a6 100644 --- a/src/USER-MISC/pair_tersoff_table.h +++ b/src/USER-MISC/pair_tersoff_table.h @@ -43,7 +43,7 @@ class PairTersoffTable : public Pair { void init_style(); double init_one(int, int); - static const int NPARAMS_PER_LINE = 17; + static constexpr int NPARAMS_PER_LINE = 17; protected: struct Param { diff --git a/src/USER-NETCDF/dump_netcdf_mpiio.cpp b/src/USER-NETCDF/dump_netcdf_mpiio.cpp index 5b83ab58ee..2067e14c22 100644 --- a/src/USER-NETCDF/dump_netcdf_mpiio.cpp +++ b/src/USER-NETCDF/dump_netcdf_mpiio.cpp @@ -292,7 +292,7 @@ void DumpNetCDFMPIIO::openfile() if (singlefile_opened) return; singlefile_opened = 1; - NCERRX( ncmpi_open(MPI_COMM_WORLD, filecurrent, NC_WRITE, MPI_INFO_NULL, + NCERRX( ncmpi_open(world, filecurrent, NC_WRITE, MPI_INFO_NULL, &ncid), filecurrent ); // dimensions @@ -372,7 +372,7 @@ void DumpNetCDFMPIIO::openfile() if (singlefile_opened) return; singlefile_opened = 1; - NCERRX( ncmpi_create(MPI_COMM_WORLD, filecurrent, NC_64BIT_DATA, + NCERRX( ncmpi_create(world, filecurrent, NC_64BIT_DATA, MPI_INFO_NULL, &ncid), filecurrent ); // dimensions @@ -748,7 +748,7 @@ void DumpNetCDFMPIIO::write() nme = count(); int *block_sizes = new int[comm->nprocs]; - MPI_Allgather(&nme, 1, MPI_INT, block_sizes, 1, MPI_INT, MPI_COMM_WORLD); + MPI_Allgather(&nme, 1, MPI_INT, block_sizes, 1, MPI_INT, world); blocki = 0; for (int i = 0; i < comm->me; i++) blocki += block_sizes[i]; delete [] block_sizes; diff --git a/src/USER-OMP/dihedral_quadratic_omp.cpp b/src/USER-OMP/dihedral_quadratic_omp.cpp index 2e25258b13..d183500182 100644 --- a/src/USER-OMP/dihedral_quadratic_omp.cpp +++ b/src/USER-OMP/dihedral_quadratic_omp.cpp @@ -23,11 +23,13 @@ #include "neighbor.h" #include "force.h" #include "update.h" +#include "math_const.h" #include "error.h" #include "suffix.h" using namespace LAMMPS_NS; +using namespace MathConst; #define TOLERANCE 0.05 #define SMALL 0.001 @@ -218,6 +220,8 @@ void DihedralQuadraticOMP::eval(int nfrom, int nto, ThrData * const thr) siinv = 1.0/si; double dphi = phi-phi0[type]; + if (dphi > MY_PI) dphi -= 2*MY_PI; + else if (dphi < -MY_PI) dphi += 2*MY_PI; p = k[type]*dphi; pd = - 2.0 * p * siinv; p = p * dphi; diff --git a/src/USER-OMP/npair_half_size_multi_newtoff_omp.cpp b/src/USER-OMP/npair_half_size_multi_newtoff_omp.cpp new file mode 100644 index 0000000000..33722eb9d3 --- /dev/null +++ b/src/USER-OMP/npair_half_size_multi_newtoff_omp.cpp @@ -0,0 +1,126 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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. +------------------------------------------------------------------------- */ + +#include "omp_compat.h" +#include "npair_half_size_multi_newtoff_omp.h" +#include "npair_omp.h" +#include "neigh_list.h" +#include "atom.h" +#include "atom_vec.h" +#include "my_page.h" +#include "error.h" + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +NPairHalfSizeMultiNewtoffOmp::NPairHalfSizeMultiNewtoffOmp(LAMMPS *lmp) : + NPair(lmp) {} + +/* ---------------------------------------------------------------------- + size particles + binned neighbor list construction with partial Newton's 3rd law + each owned atom i checks own bin and other bins in stencil + multi-type stencil is itype dependent and is distance checked + pair stored once if i,j are both owned and i < j + pair stored by me if j is ghost (also stored by proc owning j) +------------------------------------------------------------------------- */ + +void NPairHalfSizeMultiNewtoffOmp::build(NeighList *list) +{ + const int nlocal = (includegroup) ? atom->nfirst : atom->nlocal; + const int history = list->history; + const int mask_history = 3 << SBBITS; + + NPAIR_OMP_INIT; +#if defined(_OPENMP) +#pragma omp parallel LMP_DEFAULT_NONE LMP_SHARED(list) +#endif + NPAIR_OMP_SETUP(nlocal); + + int i,j,k,m,n,itype,jtype,ibin,ns; + double xtmp,ytmp,ztmp,delx,dely,delz,rsq; + double radi,radsum,cutdistsq; + int *neighptr,*s; + double *cutsq,*distsq; + + double **x = atom->x; + double *radius = atom->radius; + int *type = atom->type; + int *mask = atom->mask; + tagint *molecule = atom->molecule; + + int *ilist = list->ilist; + int *numneigh = list->numneigh; + int **firstneigh = list->firstneigh; + + // each thread has its own page allocator + MyPage &ipage = list->ipage[tid]; + ipage.reset(); + + for (i = ifrom; i < ito; i++) { + + n = 0; + neighptr = ipage.vget(); + + itype = type[i]; + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + radi = radius[i]; + + // loop over all atoms in other bins in stencil including self + // only store pair if i < j + // skip if i,j neighbor cutoff is less than bin distance + // stores own/own pairs only once + // stores own/ghost pairs on both procs + + ibin = atom2bin[i]; + s = stencil_multi[itype]; + distsq = distsq_multi[itype]; + cutsq = cutneighsq[itype]; + ns = nstencil_multi[itype]; + for (k = 0; k < ns; k++) { + for (j = binhead[ibin+s[k]]; j >= 0; j = bins[j]) { + if (j <= i) continue; + jtype = type[j]; + if (cutsq[jtype] < distsq[k]) continue; + + if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue; + + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + radsum = radi + radius[j]; + cutdistsq = (radsum+skin) * (radsum+skin); + + if (rsq <= cutdistsq) { + if (history && rsq < radsum*radsum) + neighptr[n++] = j ^ mask_history; + else + neighptr[n++] = j; + } + } + } + + ilist[i] = i; + firstneigh[i] = neighptr; + numneigh[i] = n; + ipage.vgot(n); + if (ipage.status()) + error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); + } + NPAIR_OMP_CLOSE; + list->inum = nlocal; +} diff --git a/src/USER-OMP/npair_half_size_multi_newtoff_omp.h b/src/USER-OMP/npair_half_size_multi_newtoff_omp.h new file mode 100644 index 0000000000..dd883d7f3c --- /dev/null +++ b/src/USER-OMP/npair_half_size_multi_newtoff_omp.h @@ -0,0 +1,44 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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 NPAIR_CLASS + +NPairStyle(half/size/multi/newtoff/omp, + NPairHalfSizeMultiNewtoffOmp, + NP_HALF | NP_SIZE | NP_MULTI | NP_NEWTOFF | NP_OMP | + NP_ORTHO | NP_TRI) + +#else + +#ifndef LMP_NPAIR_HALF_SIZE_MULTI_NEWTOFF_OMP_H +#define LMP_NPAIR_HALF_SIZE_MULTI_NEWTOFF_OMP_H + +#include "npair.h" + +namespace LAMMPS_NS { + +class NPairHalfSizeMultiNewtoffOmp : public NPair { + public: + NPairHalfSizeMultiNewtoffOmp(class LAMMPS *); + ~NPairHalfSizeMultiNewtoffOmp() {} + void build(class NeighList *); +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +*/ diff --git a/src/USER-OMP/npair_half_size_multi_newton_omp.cpp b/src/USER-OMP/npair_half_size_multi_newton_omp.cpp new file mode 100644 index 0000000000..0be87457e3 --- /dev/null +++ b/src/USER-OMP/npair_half_size_multi_newton_omp.cpp @@ -0,0 +1,151 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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. +------------------------------------------------------------------------- */ + +#include "omp_compat.h" +#include "npair_half_size_multi_newton_omp.h" +#include "npair_omp.h" +#include "neigh_list.h" +#include "atom.h" +#include "atom_vec.h" +#include "my_page.h" +#include "error.h" + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +NPairHalfSizeMultiNewtonOmp::NPairHalfSizeMultiNewtonOmp(LAMMPS *lmp) : + NPair(lmp) {} + +/* ---------------------------------------------------------------------- + size particles + binned neighbor list construction with full Newton's 3rd law + each owned atom i checks its own bin and other bins in Newton stencil + multi-type stencil is itype dependent and is distance checked + every pair stored exactly once by some processor +------------------------------------------------------------------------- */ + +void NPairHalfSizeMultiNewtonOmp::build(NeighList *list) +{ + const int nlocal = (includegroup) ? atom->nfirst : atom->nlocal; + const int history = list->history; + const int mask_history = 3 << SBBITS; + + NPAIR_OMP_INIT; +#if defined(_OPENMP) +#pragma omp parallel LMP_DEFAULT_NONE LMP_SHARED(list) +#endif + NPAIR_OMP_SETUP(nlocal); + + int i,j,k,m,n,itype,jtype,ibin,ns; + double xtmp,ytmp,ztmp,delx,dely,delz,rsq; + double radi,radsum,cutdistsq; + int *neighptr,*s; + double *cutsq,*distsq; + + double **x = atom->x; + double *radius = atom->radius; + int *type = atom->type; + int *mask = atom->mask; + tagint *molecule = atom->molecule; + + int *ilist = list->ilist; + int *numneigh = list->numneigh; + int **firstneigh = list->firstneigh; + + // each thread has its own page allocator + MyPage &ipage = list->ipage[tid]; + ipage.reset(); + + for (i = ifrom; i < ito; i++) { + + n = 0; + neighptr = ipage.vget(); + + itype = type[i]; + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + radi = radius[i]; + + // loop over rest of atoms in i's bin, ghosts are at end of linked list + // if j is owned atom, store it, since j is beyond i in linked list + // if j is ghost, only store if j coords are "above and to the right" of i + + for (j = bins[i]; j >= 0; j = bins[j]) { + if (j >= nlocal) { + if (x[j][2] < ztmp) continue; + if (x[j][2] == ztmp) { + if (x[j][1] < ytmp) continue; + if (x[j][1] == ytmp && x[j][0] < xtmp) continue; + } + } + + jtype = type[j]; + if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue; + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + radsum = radi + radius[j]; + cutdistsq = (radsum+skin) * (radsum+skin); + + if (rsq <= cutdistsq) { + if (history && rsq < radsum*radsum) + neighptr[n++] = j ^ mask_history; + else + neighptr[n++] = j; + } + } + + // loop over all atoms in other bins in stencil, store every pair + // skip if i,j neighbor cutoff is less than bin distance + + ibin = atom2bin[i]; + s = stencil_multi[itype]; + distsq = distsq_multi[itype]; + cutsq = cutneighsq[itype]; + ns = nstencil_multi[itype]; + for (k = 0; k < ns; k++) { + for (j = binhead[ibin+s[k]]; j >= 0; j = bins[j]) { + jtype = type[j]; + if (cutsq[jtype] < distsq[k]) continue; + + if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue; + + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + radsum = radi + radius[j]; + cutdistsq = (radsum+skin) * (radsum+skin); + + if (rsq <= cutdistsq) { + if (history && rsq < radsum*radsum) + neighptr[n++] = j ^ mask_history; + else + neighptr[n++] = j; + } + } + } + + ilist[i] = i; + firstneigh[i] = neighptr; + numneigh[i] = n; + ipage.vgot(n); + if (ipage.status()) + error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); + } + NPAIR_OMP_CLOSE; + list->inum = nlocal; +} diff --git a/src/USER-OMP/npair_half_size_multi_newton_omp.h b/src/USER-OMP/npair_half_size_multi_newton_omp.h new file mode 100644 index 0000000000..03d712145f --- /dev/null +++ b/src/USER-OMP/npair_half_size_multi_newton_omp.h @@ -0,0 +1,43 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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 NPAIR_CLASS + +NPairStyle(half/size/multi/newton/omp, + NPairHalfSizeMultiNewtonOmp, + NP_HALF | NP_SIZE | NP_MULTI | NP_NEWTON | NP_OMP | NP_ORTHO) + +#else + +#ifndef LMP_NPAIR_HALF_SIZE_MULTI_NEWTON_OMP_H +#define LMP_NPAIR_HALF_SIZE_MULTI_NEWTON_OMP_H + +#include "npair.h" + +namespace LAMMPS_NS { + +class NPairHalfSizeMultiNewtonOmp : public NPair { + public: + NPairHalfSizeMultiNewtonOmp(class LAMMPS *); + ~NPairHalfSizeMultiNewtonOmp() {} + void build(class NeighList *); +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +*/ diff --git a/src/USER-OMP/npair_half_size_multi_newton_tri_omp.cpp b/src/USER-OMP/npair_half_size_multi_newton_tri_omp.cpp new file mode 100644 index 0000000000..ef26a5f2bd --- /dev/null +++ b/src/USER-OMP/npair_half_size_multi_newton_tri_omp.cpp @@ -0,0 +1,134 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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. +------------------------------------------------------------------------- */ + +#include "omp_compat.h" +#include "npair_half_size_multi_newton_tri_omp.h" +#include "npair_omp.h" +#include "neigh_list.h" +#include "atom.h" +#include "atom_vec.h" +#include "my_page.h" +#include "error.h" + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +NPairHalfSizeMultiNewtonTriOmp::NPairHalfSizeMultiNewtonTriOmp(LAMMPS *lmp) : + NPair(lmp) {} + +/* ---------------------------------------------------------------------- + size particles + binned neighbor list construction with Newton's 3rd law for triclinic + each owned atom i checks its own bin and other bins in triclinic stencil + multi-type stencil is itype dependent and is distance checked + every pair stored exactly once by some processor +------------------------------------------------------------------------- */ + +void NPairHalfSizeMultiNewtonTriOmp::build(NeighList *list) +{ + const int nlocal = (includegroup) ? atom->nfirst : atom->nlocal; + const int history = list->history; + const int mask_history = 3 << SBBITS; + + NPAIR_OMP_INIT; +#if defined(_OPENMP) +#pragma omp parallel LMP_DEFAULT_NONE LMP_SHARED(list) +#endif + NPAIR_OMP_SETUP(nlocal); + + int i,j,k,m,n,itype,jtype,ibin,ns; + double xtmp,ytmp,ztmp,delx,dely,delz,rsq; + double radi,radsum,cutdistsq; + int *neighptr,*s; + double *cutsq,*distsq; + + double **x = atom->x; + double *radius = atom->radius; + int *type = atom->type; + int *mask = atom->mask; + tagint *molecule = atom->molecule; + + int *ilist = list->ilist; + int *numneigh = list->numneigh; + int **firstneigh = list->firstneigh; + + // each thread has its own page allocator + MyPage &ipage = list->ipage[tid]; + ipage.reset(); + + for (i = ifrom; i < ito; i++) { + + n = 0; + neighptr = ipage.vget(); + + itype = type[i]; + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + radi = radius[i]; + + // loop over all atoms in bins, including self, in stencil + // skip if i,j neighbor cutoff is less than bin distance + // bins below self are excluded from stencil + // pairs for atoms j "below" i are excluded + // below = lower z or (equal z and lower y) or (equal zy and lower x) + // (equal zyx and j <= i) + // latter excludes self-self interaction but allows superposed atoms + + ibin = atom2bin[i]; + s = stencil_multi[itype]; + distsq = distsq_multi[itype]; + cutsq = cutneighsq[itype]; + ns = nstencil_multi[itype]; + for (k = 0; k < ns; k++) { + for (j = binhead[ibin+s[k]]; j >= 0; j = bins[j]) { + jtype = type[j]; + if (cutsq[jtype] < distsq[k]) continue; + if (x[j][2] < ztmp) continue; + if (x[j][2] == ztmp) { + if (x[j][1] < ytmp) continue; + if (x[j][1] == ytmp) { + if (x[j][0] < xtmp) continue; + if (x[j][0] == xtmp && j <= i) continue; + } + } + + if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue; + + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + radsum = radi + radius[j]; + cutdistsq = (radsum+skin) * (radsum+skin); + + if (rsq <= cutdistsq) { + if (history && rsq < radsum*radsum) + neighptr[n++] = j ^ mask_history; + else + neighptr[n++] = j; + } + } + } + + ilist[i] = i; + firstneigh[i] = neighptr; + numneigh[i] = n; + ipage.vgot(n); + if (ipage.status()) + error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); + } + NPAIR_OMP_CLOSE; + list->inum = nlocal; +} diff --git a/src/USER-OMP/npair_half_size_multi_newton_tri_omp.h b/src/USER-OMP/npair_half_size_multi_newton_tri_omp.h new file mode 100644 index 0000000000..6e936c8da4 --- /dev/null +++ b/src/USER-OMP/npair_half_size_multi_newton_tri_omp.h @@ -0,0 +1,43 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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 NPAIR_CLASS + +NPairStyle(half/size/multi/newton/tri/omp, + NPairHalfSizeMultiNewtonTriOmp, + NP_HALF | NP_SIZE | NP_MULTI | NP_NEWTON | NP_TRI | NP_OMP) + +#else + +#ifndef LMP_NPAIR_HALF_SIZE_MULTI_NEWTON_TRI_OMP_H +#define LMP_NPAIR_HALF_SIZE_MULTI_NEWTON_TRI_OMP_H + +#include "npair.h" + +namespace LAMMPS_NS { + +class NPairHalfSizeMultiNewtonTriOmp : public NPair { + public: + NPairHalfSizeMultiNewtonTriOmp(class LAMMPS *); + ~NPairHalfSizeMultiNewtonTriOmp() {} + void build(class NeighList *); +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +*/ diff --git a/src/USER-OMP/pair_edip_omp.cpp b/src/USER-OMP/pair_edip_omp.cpp index 2eb8384113..106d038743 100644 --- a/src/USER-OMP/pair_edip_omp.cpp +++ b/src/USER-OMP/pair_edip_omp.cpp @@ -28,7 +28,7 @@ using namespace LAMMPS_NS; // max number of interaction per atom for f(Z) environment potential -#define leadDimInteractionList 64 +static constexpr int leadDimInteractionList = 64; /* ---------------------------------------------------------------------- */ diff --git a/src/USER-OMP/pair_lj_cubic_omp.cpp b/src/USER-OMP/pair_lj_cubic_omp.cpp index 872574a3b2..e96b3d0a79 100644 --- a/src/USER-OMP/pair_lj_cubic_omp.cpp +++ b/src/USER-OMP/pair_lj_cubic_omp.cpp @@ -23,6 +23,8 @@ #include #include "omp_compat.h" +#include "pair_lj_cubic_const.h" + using namespace LAMMPS_NS; using namespace PairLJCubicConstants; diff --git a/src/USER-OMP/pair_zbl_omp.cpp b/src/USER-OMP/pair_zbl_omp.cpp index 993e75f499..6794789f25 100644 --- a/src/USER-OMP/pair_zbl_omp.cpp +++ b/src/USER-OMP/pair_zbl_omp.cpp @@ -24,7 +24,6 @@ #include "omp_compat.h" using namespace LAMMPS_NS; -using namespace PairZBLConstants; /* ---------------------------------------------------------------------- */ diff --git a/src/USER-PLUMED/fix_plumed.cpp b/src/USER-PLUMED/fix_plumed.cpp index b1397b8eeb..1fc19a7724 100644 --- a/src/USER-PLUMED/fix_plumed.cpp +++ b/src/USER-PLUMED/fix_plumed.cpp @@ -76,11 +76,11 @@ FixPlumed::FixPlumed(LAMMPS *lmp, int narg, char **arg) : // Check API version - int api_version; + int api_version=0; p->cmd("getApiVersion",&api_version); - if ((api_version < 5) || (api_version > 7)) + if ((api_version < 5) || (api_version > 8)) error->all(FLERR,"Incompatible API version for PLUMED in fix plumed. " - "Only Plumed 2.4.x, 2.5.x, and 2.6.x are tested and supported."); + "Only Plumed 2.4.x, 2.5.x, 2.6.x, 2.7.x are tested and supported."); #if !defined(MPI_STUBS) // If the -partition option is activated then enable diff --git a/src/USER-REACTION/fix_bond_react.cpp b/src/USER-REACTION/fix_bond_react.cpp index 29a99db75f..2bfc7714be 100644 --- a/src/USER-REACTION/fix_bond_react.cpp +++ b/src/USER-REACTION/fix_bond_react.cpp @@ -82,6 +82,9 @@ enum{ACCEPT,REJECT,PROCEED,CONTINUE,GUESSFAIL,RESTORE}; // types of available reaction constraints enum{DISTANCE,ANGLE,DIHEDRAL,ARRHENIUS,RMSD}; +// ID type used by constraint +enum{ATOM,FRAG}; + // keyword values that accept variables as input enum{NEVERY,RMIN,RMAX,PROB}; @@ -115,7 +118,6 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : global_freq = 1; extvector = 0; rxnID = 0; - nconstraints = 0; narrhenius = 0; status = PROCEED; @@ -206,7 +208,9 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : memory->create(stabilize_steps_flag,nreacts,"bond/react:stabilize_steps_flag"); memory->create(custom_charges_fragid,nreacts,"bond/react:custom_charges_fragid"); memory->create(molecule_keyword,nreacts,"bond/react:molecule_keyword"); - memory->create(constraints,1,MAXCONARGS,"bond/react:constraints"); + memory->create(nconstraints,nreacts,"bond/react:nconstraints"); + memory->create(constraintstr,nreacts,MAXLINE,"bond/react:constraintstr"); + memory->create(constraints,0,nreacts,"bond/react:constraints"); memory->create(var_flag,NUMVARVALS,nreacts,"bond/react:var_flag"); memory->create(var_id,NUMVARVALS,nreacts,"bond/react:var_id"); memory->create(iatomtype,nreacts,"bond/react:iatomtype"); @@ -227,6 +231,7 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : stabilize_steps_flag[i] = 0; custom_charges_fragid[i] = -1; molecule_keyword[i] = OFF; + nconstraints[i] = 0; // set default limit duration to 60 timesteps limit_duration[i] = 60; reaction_count[i] = 0; @@ -440,9 +445,11 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : rrhandom = new class RanMars*[narrhenius]; int tmp = 0; - for (int i = 0; i < nconstraints; i++) { - if (constraints[i][1] == ARRHENIUS) { - rrhandom[tmp++] = new RanMars(lmp,(int) constraints[i][6] + me); + for (int i = 0; i < nreacts; i++) { + for (int j = 0; j < nconstraints[i]; j++) { + if (constraints[j][i].type == ARRHENIUS) { + rrhandom[tmp++] = new RanMars(lmp,(int) constraints[j][i].par[4] + me); + } } } @@ -562,6 +569,9 @@ FixBondReact::~FixBondReact() memory->destroy(stabilize_steps_flag); memory->destroy(custom_charges_fragid); memory->destroy(molecule_keyword); + memory->destroy(constraints); + memory->destroy(nconstraints); + // need to delete rxn_name and constraintstr memory->destroy(iatomtype); memory->destroy(jatomtype); @@ -761,15 +771,15 @@ void FixBondReact::post_constructor() void FixBondReact::init() { - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; - // check cutoff for iatomtype,jatomtype - for (int i = 0; i < nreacts; i++) { - if (closeneigh[i] == -1) // indicates will search for non-bonded bonding atoms - if (force->pair == nullptr || cutsq[i][1] > force->pair->cutsq[iatomtype[i]][jatomtype[i]]) - error->all(FLERR,"Bond/react: Fix bond/react cutoff is longer than pairwise cutoff"); - } + // check cutoff for iatomtype,jatomtype + for (int i = 0; i < nreacts; i++) { + if (closeneigh[i] == -1) // indicates will search for non-bonded bonding atoms + if (force->pair == nullptr || cutsq[i][1] > force->pair->cutsq[iatomtype[i]][jatomtype[i]]) + error->all(FLERR,"Bond/react: Fix bond/react cutoff is longer than pairwise cutoff"); + } // need a half neighbor list, built every Nevery steps int irequest = neighbor->request(this,instance_me); @@ -1068,10 +1078,11 @@ void FixBondReact::far_partner() continue; } - if (molecule_keyword[rxnID] == INTER) + if (molecule_keyword[rxnID] == INTER) { if (atom->molecule[i] == atom->molecule[j]) continue; - else if (molecule_keyword[rxnID] == INTRA) + } else if (molecule_keyword[rxnID] == INTRA) { if (atom->molecule[i] != atom->molecule[j]) continue; + } jtype = type[j]; possible = 0; @@ -1152,10 +1163,11 @@ void FixBondReact::close_partner() if (i_limit_tags[i2] != 0) continue; if (itype != iatomtype[rxnID] || jtype != jatomtype[rxnID]) continue; - if (molecule_keyword[rxnID] == INTER) + if (molecule_keyword[rxnID] == INTER) { if (atom->molecule[i1] == atom->molecule[i2]) continue; - else if (molecule_keyword[rxnID] == INTRA) + } else if (molecule_keyword[rxnID] == INTRA) { if (atom->molecule[i1] != atom->molecule[i2]) continue; + } delx = x[i1][0] - x[i2][0]; dely = x[i1][1] - x[i2][1]; @@ -1793,163 +1805,178 @@ int FixBondReact::check_constraints() tagint atom1,atom2; double **x = atom->x; - for (int i = 0; i < nconstraints; i++) { - if (constraints[i][0] == rxnID) { - if (constraints[i][1] == DISTANCE) { - get_IDcoords((int) constraints[i][2], (int) constraints[i][3], x1); - get_IDcoords((int) constraints[i][4], (int) constraints[i][5], x2); - delx = x1[0] - x2[0]; - dely = x1[1] - x2[1]; - delz = x1[2] - x2[2]; - domain->minimum_image(delx,dely,delz); // ghost location fix - rsq = delx*delx + dely*dely + delz*delz; - if (rsq < constraints[i][6] || rsq > constraints[i][7]) return 0; - } else if (constraints[i][1] == ANGLE) { - get_IDcoords((int) constraints[i][2], (int) constraints[i][3], x1); - get_IDcoords((int) constraints[i][4], (int) constraints[i][5], x2); - get_IDcoords((int) constraints[i][6], (int) constraints[i][7], x3); + int *satisfied; + memory->create(satisfied,nconstraints[rxnID],"bond/react:satisfied"); + for (int i = 0; i < nconstraints[rxnID]; i++) + satisfied[i] = 1; - // 1st bond - delx1 = x1[0] - x2[0]; - dely1 = x1[1] - x2[1]; - delz1 = x1[2] - x2[2]; - domain->minimum_image(delx1,dely1,delz1); // ghost location fix - rsq1 = delx1*delx1 + dely1*dely1 + delz1*delz1; - r1 = sqrt(rsq1); + for (int i = 0; i < nconstraints[rxnID]; i++) { + if (constraints[i][rxnID].type == DISTANCE) { + get_IDcoords(constraints[i][rxnID].idtype[0], constraints[i][rxnID].id[0], x1); + get_IDcoords(constraints[i][rxnID].idtype[1], constraints[i][rxnID].id[1], x2); + delx = x1[0] - x2[0]; + dely = x1[1] - x2[1]; + delz = x1[2] - x2[2]; + domain->minimum_image(delx,dely,delz); // ghost location fix + rsq = delx*delx + dely*dely + delz*delz; + if (rsq < constraints[i][rxnID].par[0] || rsq > constraints[i][rxnID].par[1]) satisfied[i] = 0; + } else if (constraints[i][rxnID].type == ANGLE) { + get_IDcoords(constraints[i][rxnID].idtype[0], constraints[i][rxnID].id[0], x1); + get_IDcoords(constraints[i][rxnID].idtype[1], constraints[i][rxnID].id[1], x2); + get_IDcoords(constraints[i][rxnID].idtype[2], constraints[i][rxnID].id[2], x3); - // 2nd bond - delx2 = x3[0] - x2[0]; - dely2 = x3[1] - x2[1]; - delz2 = x3[2] - x2[2]; - domain->minimum_image(delx2,dely2,delz2); // ghost location fix - rsq2 = delx2*delx2 + dely2*dely2 + delz2*delz2; - r2 = sqrt(rsq2); + // 1st bond + delx1 = x1[0] - x2[0]; + dely1 = x1[1] - x2[1]; + delz1 = x1[2] - x2[2]; + domain->minimum_image(delx1,dely1,delz1); // ghost location fix + rsq1 = delx1*delx1 + dely1*dely1 + delz1*delz1; + r1 = sqrt(rsq1); - // angle (cos and sin) - c = delx1*delx2 + dely1*dely2 + delz1*delz2; - c /= r1*r2; - if (c > 1.0) c = 1.0; - if (c < -1.0) c = -1.0; - if (acos(c) < constraints[i][8] || acos(c) > constraints[i][9]) return 0; - } else if (constraints[i][1] == DIHEDRAL) { - // phi calculation from dihedral style harmonic - get_IDcoords((int) constraints[i][2], (int) constraints[i][3], x1); - get_IDcoords((int) constraints[i][4], (int) constraints[i][5], x2); - get_IDcoords((int) constraints[i][6], (int) constraints[i][7], x3); - get_IDcoords((int) constraints[i][8], (int) constraints[i][9], x4); + // 2nd bond + delx2 = x3[0] - x2[0]; + dely2 = x3[1] - x2[1]; + delz2 = x3[2] - x2[2]; + domain->minimum_image(delx2,dely2,delz2); // ghost location fix + rsq2 = delx2*delx2 + dely2*dely2 + delz2*delz2; + r2 = sqrt(rsq2); - vb1x = x1[0] - x2[0]; - vb1y = x1[1] - x2[1]; - vb1z = x1[2] - x2[2]; - domain->minimum_image(vb1x,vb1y,vb1z); + // angle (cos and sin) + c = delx1*delx2 + dely1*dely2 + delz1*delz2; + c /= r1*r2; + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + if (acos(c) < constraints[i][rxnID].par[0] || acos(c) > constraints[i][rxnID].par[1]) satisfied[i] = 0; + } else if (constraints[i][rxnID].type == DIHEDRAL) { + // phi calculation from dihedral style harmonic + get_IDcoords(constraints[i][rxnID].idtype[0], constraints[i][rxnID].id[0], x1); + get_IDcoords(constraints[i][rxnID].idtype[1], constraints[i][rxnID].id[1], x2); + get_IDcoords(constraints[i][rxnID].idtype[2], constraints[i][rxnID].id[2], x3); + get_IDcoords(constraints[i][rxnID].idtype[3], constraints[i][rxnID].id[3], x4); - vb2x = x3[0] - x2[0]; - vb2y = x3[1] - x2[1]; - vb2z = x3[2] - x2[2]; - domain->minimum_image(vb2x,vb2y,vb2z); + vb1x = x1[0] - x2[0]; + vb1y = x1[1] - x2[1]; + vb1z = x1[2] - x2[2]; + domain->minimum_image(vb1x,vb1y,vb1z); - vb2xm = -vb2x; - vb2ym = -vb2y; - vb2zm = -vb2z; - domain->minimum_image(vb2xm,vb2ym,vb2zm); + vb2x = x3[0] - x2[0]; + vb2y = x3[1] - x2[1]; + vb2z = x3[2] - x2[2]; + domain->minimum_image(vb2x,vb2y,vb2z); - vb3x = x4[0] - x3[0]; - vb3y = x4[1] - x3[1]; - vb3z = x4[2] - x3[2]; - domain->minimum_image(vb3x,vb3y,vb3z); + vb2xm = -vb2x; + vb2ym = -vb2y; + vb2zm = -vb2z; + domain->minimum_image(vb2xm,vb2ym,vb2zm); - ax = vb1y*vb2zm - vb1z*vb2ym; - ay = vb1z*vb2xm - vb1x*vb2zm; - az = vb1x*vb2ym - vb1y*vb2xm; - bx = vb3y*vb2zm - vb3z*vb2ym; - by = vb3z*vb2xm - vb3x*vb2zm; - bz = vb3x*vb2ym - vb3y*vb2xm; + vb3x = x4[0] - x3[0]; + vb3y = x4[1] - x3[1]; + vb3z = x4[2] - x3[2]; + domain->minimum_image(vb3x,vb3y,vb3z); - rasq = ax*ax + ay*ay + az*az; - rbsq = bx*bx + by*by + bz*bz; - rgsq = vb2xm*vb2xm + vb2ym*vb2ym + vb2zm*vb2zm; - rg = sqrt(rgsq); + ax = vb1y*vb2zm - vb1z*vb2ym; + ay = vb1z*vb2xm - vb1x*vb2zm; + az = vb1x*vb2ym - vb1y*vb2xm; + bx = vb3y*vb2zm - vb3z*vb2ym; + by = vb3z*vb2xm - vb3x*vb2zm; + bz = vb3x*vb2ym - vb3y*vb2xm; - ra2inv = rb2inv = 0.0; - if (rasq > 0) ra2inv = 1.0/rasq; - if (rbsq > 0) rb2inv = 1.0/rbsq; - rabinv = sqrt(ra2inv*rb2inv); + rasq = ax*ax + ay*ay + az*az; + rbsq = bx*bx + by*by + bz*bz; + rgsq = vb2xm*vb2xm + vb2ym*vb2ym + vb2zm*vb2zm; + rg = sqrt(rgsq); - c = (ax*bx + ay*by + az*bz)*rabinv; - s = rg*rabinv*(ax*vb3x + ay*vb3y + az*vb3z); + ra2inv = rb2inv = 0.0; + if (rasq > 0) ra2inv = 1.0/rasq; + if (rbsq > 0) rb2inv = 1.0/rbsq; + rabinv = sqrt(ra2inv*rb2inv); - if (c > 1.0) c = 1.0; - if (c < -1.0) c = -1.0; - phi = atan2(s,c); + c = (ax*bx + ay*by + az*bz)*rabinv; + s = rg*rabinv*(ax*vb3x + ay*vb3y + az*vb3z); - ANDgate = 0; - if (constraints[i][10] < constraints[i][11]) { - if (phi > constraints[i][10] && phi < constraints[i][11]) ANDgate = 1; - } else { - if (phi > constraints[i][10] || phi < constraints[i][11]) ANDgate = 1; - } - if (constraints[i][12] < constraints[i][13]) { - if (phi > constraints[i][12] && phi < constraints[i][13]) ANDgate = 1; - } else { - if (phi > constraints[i][12] || phi < constraints[i][13]) ANDgate = 1; - } - if (ANDgate != 1) return 0; - } else if (constraints[i][1] == ARRHENIUS) { - t = get_temperature(); - prrhob = constraints[i][3]*pow(t,constraints[i][4])* - exp(-constraints[i][5]/(force->boltz*t)); - if (prrhob < rrhandom[(int) constraints[i][2]]->uniform()) return 0; - } else if (constraints[i][1] == RMSD) { - // call superpose - int iatom; - int iref = -1; // choose first atom as reference - int n2superpose = 0; - double **xfrozen; // coordinates for the "frozen" target molecule - double **xmobile; // coordinates for the "mobile" molecule - int ifragment = constraints[i][3]; - if (ifragment >= 0) { - for (int j = 0; j < onemol->natoms; j++) - if (onemol->fragmentmask[ifragment][j]) n2superpose++; - memory->create(xfrozen,n2superpose,3,"bond/react:xfrozen"); - memory->create(xmobile,n2superpose,3,"bond/react:xmobile"); - int myincr = 0; - for (int j = 0; j < onemol->natoms; j++) { - if (onemol->fragmentmask[ifragment][j]) { - iatom = atom->map(glove[j][1]); - if (iref == -1) iref = iatom; - iatom = domain->closest_image(iref,iatom); - for (int k = 0; k < 3; k++) { - xfrozen[myincr][k] = x[iatom][k]; - xmobile[myincr][k] = onemol->x[j][k]; - } - myincr++; - } - } - } else { - int iatom; - int iref = -1; // choose first atom as reference - n2superpose = onemol->natoms; - memory->create(xfrozen,n2superpose,3,"bond/react:xfrozen"); - memory->create(xmobile,n2superpose,3,"bond/react:xmobile"); - for (int j = 0; j < n2superpose; j++) { + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + phi = atan2(s,c); + + ANDgate = 0; + if (constraints[i][rxnID].par[0] < constraints[i][rxnID].par[1]) { + if (phi > constraints[i][rxnID].par[0] && phi < constraints[i][rxnID].par[1]) ANDgate = 1; + } else { + if (phi > constraints[i][rxnID].par[0] || phi < constraints[i][rxnID].par[1]) ANDgate = 1; + } + if (constraints[i][rxnID].par[2] < constraints[i][rxnID].par[3]) { + if (phi > constraints[i][rxnID].par[2] && phi < constraints[i][rxnID].par[3]) ANDgate = 1; + } else { + if (phi > constraints[i][rxnID].par[2] || phi < constraints[i][rxnID].par[3]) ANDgate = 1; + } + if (ANDgate != 1) satisfied[i] = 0; + } else if (constraints[i][rxnID].type == ARRHENIUS) { + t = get_temperature(); + prrhob = constraints[i][rxnID].par[1]*pow(t,constraints[i][rxnID].par[2])* + exp(-constraints[i][rxnID].par[3]/(force->boltz*t)); + if (prrhob < rrhandom[(int) constraints[i][rxnID].par[0]]->uniform()) satisfied[i] = 0; + } else if (constraints[i][rxnID].type == RMSD) { + // call superpose + int iatom; + int iref = -1; // choose first atom as reference + int n2superpose = 0; + double **xfrozen; // coordinates for the "frozen" target molecule + double **xmobile; // coordinates for the "mobile" molecule + int ifragment = constraints[i][rxnID].id[0]; + if (ifragment >= 0) { + for (int j = 0; j < onemol->natoms; j++) + if (onemol->fragmentmask[ifragment][j]) n2superpose++; + memory->create(xfrozen,n2superpose,3,"bond/react:xfrozen"); + memory->create(xmobile,n2superpose,3,"bond/react:xmobile"); + int myincr = 0; + for (int j = 0; j < onemol->natoms; j++) { + if (onemol->fragmentmask[ifragment][j]) { iatom = atom->map(glove[j][1]); if (iref == -1) iref = iatom; iatom = domain->closest_image(iref,iatom); for (int k = 0; k < 3; k++) { - xfrozen[j][k] = x[iatom][k]; - xmobile[j][k] = onemol->x[j][k]; + xfrozen[myincr][k] = x[iatom][k]; + xmobile[myincr][k] = onemol->x[j][k]; } + myincr++; + } + } + } else { + int iatom; + int iref = -1; // choose first atom as reference + n2superpose = onemol->natoms; + memory->create(xfrozen,n2superpose,3,"bond/react:xfrozen"); + memory->create(xmobile,n2superpose,3,"bond/react:xmobile"); + for (int j = 0; j < n2superpose; j++) { + iatom = atom->map(glove[j][1]); + if (iref == -1) iref = iatom; + iatom = domain->closest_image(iref,iatom); + for (int k = 0; k < 3; k++) { + xfrozen[j][k] = x[iatom][k]; + xmobile[j][k] = onemol->x[j][k]; } } - Superpose3D superposer(n2superpose); - double rmsd = superposer.Superpose(xfrozen, xmobile); - if (rmsd > constraints[i][2]) return 0; - memory->destroy(xfrozen); - memory->destroy(xmobile); } + Superpose3D superposer(n2superpose); + double rmsd = superposer.Superpose(xfrozen, xmobile); + memory->destroy(xfrozen); + memory->destroy(xmobile); + if (rmsd > constraints[i][rxnID].par[0]) satisfied[i] = 0; } } + if (nconstraints[rxnID] > 0) { + char evalstr[MAXLINE],*ptr,valstr; + strcpy(evalstr,constraintstr[rxnID]); + for (int i = 0; i < nconstraints[rxnID]; i++) { + sprintf(&valstr,"%d", satisfied[i]); + ptr = strchr(evalstr,'C'); + *ptr = valstr; + } + double verdict = input->variable->evaluate_boolean(evalstr); + if (verdict == 0.0) return 0; + } + // let's also check chirality within 'check_constraint' for (int i = 0; i < onemol->natoms; i++) { if (chiral_atoms[i][0][rxnID] == 1) { @@ -1973,6 +2000,7 @@ int FixBondReact::check_constraints() } } + memory->destroy(satisfied); return 1; } @@ -1985,7 +2013,7 @@ fragment: given pre-reacted molID (onemol) and fragID, void FixBondReact::get_IDcoords(int mode, int myID, double *center) { double **x = atom->x; - if (mode == 1) { + if (mode == ATOM) { int iatom = atom->map(glove[myID-1][1]); for (int i = 0; i < 3; i++) center[i] = x[iatom][i]; @@ -3214,8 +3242,8 @@ void FixBondReact::read(int myrxn) else if (strstr(line,"deleteIDs")) sscanf(line,"%d",&ndelete); else if (strstr(line,"chiralIDs")) sscanf(line,"%d",&nchiral); else if (strstr(line,"constraints")) { - sscanf(line,"%d",&nconstr); - memory->grow(constraints,nconstraints+nconstr,MAXCONARGS,"bond/react:constraints"); + sscanf(line,"%d",&nconstraints[myrxn]); + memory->grow(constraints,nconstraints[myrxn],nreacts,"bond/react:constraints"); } else break; } @@ -3250,7 +3278,7 @@ void FixBondReact::read(int myrxn) } else if (strcmp(keyword,"ChiralIDs") == 0) { ChiralCenters(line, myrxn); } else if (strcmp(keyword,"Constraints") == 0) { - Constraints(line, myrxn); + ReadConstraints(line, myrxn); } else error->one(FLERR,"Bond/react: Unknown section in map file"); parse_keyword(1,line,keyword); @@ -3348,69 +3376,89 @@ void FixBondReact::ChiralCenters(char *line, int myrxn) } } -void FixBondReact::Constraints(char *line, int myrxn) +void FixBondReact::ReadConstraints(char *line, int myrxn) { double tmp[MAXCONARGS]; - char **strargs; + char **strargs,*ptr; memory->create(strargs,MAXCONARGS,MAXLINE,"bond/react:strargs"); char *constraint_type = new char[MAXLINE]; - for (int i = 0; i < nconstr; i++) { + strcpy(constraintstr[myrxn],"("); // string for boolean constraint logic + for (int i = 0; i < nconstraints[myrxn]; i++) { readline(line); + if (ptr = strrchr(line,'(')) { // reverse char search + strncat(constraintstr[myrxn],line,ptr-line+1); + line = ptr + 1; + } + // 'C' indicates where to sub in next constraint + strcat(constraintstr[myrxn],"C"); + if (ptr = strchr(line,')')) { + strncat(constraintstr[myrxn],ptr,strrchr(line,')')-ptr+1); + } + if (ptr = strstr(line,"&&")) { + strcat(constraintstr[myrxn],"&&"); + *ptr = '\0'; + } else if (ptr = strstr(line,"||")) { + strcat(constraintstr[myrxn],"||"); + *ptr = '\0'; + } else if (i+1 < nconstraints[myrxn]){ + strcat(constraintstr[myrxn],"&&"); + } + if (ptr = strchr(line,')')) + *ptr = '\0'; sscanf(line,"%s",constraint_type); - constraints[nconstraints][0] = myrxn; if (strcmp(constraint_type,"distance") == 0) { - constraints[nconstraints][1] = DISTANCE; + constraints[i][myrxn].type = DISTANCE; sscanf(line,"%*s %s %s %lg %lg",strargs[0],strargs[1],&tmp[0],&tmp[1]); - readID(strargs[0], nconstraints, 2, 3); - readID(strargs[1], nconstraints, 4, 5); + readID(strargs[0], i, myrxn, 0); + readID(strargs[1], i, myrxn, 1); // cutoffs - constraints[nconstraints][6] = tmp[0]*tmp[0]; // using square of distance - constraints[nconstraints][7] = tmp[1]*tmp[1]; + constraints[i][myrxn].par[0] = tmp[0]*tmp[0]; // using square of distance + constraints[i][myrxn].par[1] = tmp[1]*tmp[1]; } else if (strcmp(constraint_type,"angle") == 0) { - constraints[nconstraints][1] = ANGLE; + constraints[i][myrxn].type = ANGLE; sscanf(line,"%*s %s %s %s %lg %lg",strargs[0],strargs[1],strargs[2],&tmp[0],&tmp[1]); - readID(strargs[0], nconstraints, 2, 3); - readID(strargs[1], nconstraints, 4, 5); - readID(strargs[2], nconstraints, 6, 7); - constraints[nconstraints][8] = tmp[0]/180.0 * MY_PI; - constraints[nconstraints][9] = tmp[1]/180.0 * MY_PI; + readID(strargs[0], i, myrxn, 0); + readID(strargs[1], i, myrxn, 1); + readID(strargs[2], i, myrxn, 2); + constraints[i][myrxn].par[0] = tmp[0]/180.0 * MY_PI; + constraints[i][myrxn].par[1] = tmp[1]/180.0 * MY_PI; } else if (strcmp(constraint_type,"dihedral") == 0) { - constraints[nconstraints][1] = DIHEDRAL; + constraints[i][myrxn].type = DIHEDRAL; tmp[2] = 181.0; // impossible range tmp[3] = 182.0; sscanf(line,"%*s %s %s %s %s %lg %lg %lg %lg",strargs[0],strargs[1], strargs[2],strargs[3],&tmp[0],&tmp[1],&tmp[2],&tmp[3]); - readID(strargs[0], nconstraints, 2, 3); - readID(strargs[1], nconstraints, 4, 5); - readID(strargs[2], nconstraints, 6, 7); - readID(strargs[3], nconstraints, 8, 9); - constraints[nconstraints][10] = tmp[0]/180.0 * MY_PI; - constraints[nconstraints][11] = tmp[1]/180.0 * MY_PI; - constraints[nconstraints][12] = tmp[2]/180.0 * MY_PI; - constraints[nconstraints][13] = tmp[3]/180.0 * MY_PI; + readID(strargs[0], i, myrxn, 0); + readID(strargs[1], i, myrxn, 1); + readID(strargs[2], i, myrxn, 2); + readID(strargs[3], i, myrxn, 3); + constraints[i][myrxn].par[0] = tmp[0]/180.0 * MY_PI; + constraints[i][myrxn].par[1] = tmp[1]/180.0 * MY_PI; + constraints[i][myrxn].par[2] = tmp[2]/180.0 * MY_PI; + constraints[i][myrxn].par[3] = tmp[3]/180.0 * MY_PI; } else if (strcmp(constraint_type,"arrhenius") == 0) { - constraints[nconstraints][1] = ARRHENIUS; - constraints[nconstraints][2] = narrhenius++; + constraints[i][myrxn].type = ARRHENIUS; + constraints[i][myrxn].par[0] = narrhenius++; sscanf(line,"%*s %lg %lg %lg %lg",&tmp[0],&tmp[1],&tmp[2],&tmp[3]); - constraints[nconstraints][3] = tmp[0]; - constraints[nconstraints][4] = tmp[1]; - constraints[nconstraints][5] = tmp[2]; - constraints[nconstraints][6] = tmp[3]; + constraints[i][myrxn].par[1] = tmp[0]; + constraints[i][myrxn].par[2] = tmp[1]; + constraints[i][myrxn].par[3] = tmp[2]; + constraints[i][myrxn].par[4] = tmp[3]; } else if (strcmp(constraint_type,"rmsd") == 0) { - constraints[nconstraints][1] = RMSD; + constraints[i][myrxn].type = RMSD; strcpy(strargs[0],"0"); sscanf(line,"%*s %lg %s",&tmp[0],strargs[0]); - constraints[nconstraints][2] = tmp[0]; // RMSDmax - constraints[nconstraints][3] = -1; // optional molecule fragment + constraints[i][myrxn].par[0] = tmp[0]; // RMSDmax + constraints[i][myrxn].id[0] = -1; // optional molecule fragment if (isalpha(strargs[0][0])) { int ifragment = onemol->findfragment(strargs[0]); if (ifragment < 0) error->one(FLERR,"Bond/react: Molecule fragment does not exist"); - else constraints[nconstraints][3] = ifragment; + else constraints[i][myrxn].id[0] = ifragment; } } else error->one(FLERR,"Bond/react: Illegal constraint type in 'Constraints' section of map file"); - nconstraints++; } + strcat(constraintstr[myrxn],")"); // close boolean constraint logic string delete [] constraint_type; memory->destroy(strargs); } @@ -3420,18 +3468,18 @@ if ID starts with character, assume it is a pre-reaction molecule fragment ID otherwise, it is a pre-reaction atom ID ---------------------------------------------------------------------- */ -void FixBondReact::readID(char *strarg, int iconstr, int mode, int myID) +void FixBondReact::readID(char *strarg, int iconstr, int myrxn, int i) { if (isalpha(strarg[0])) { - constraints[iconstr][mode] = 0; // fragment vs. atom ID flag + constraints[iconstr][myrxn].idtype[i] = FRAG; // fragment vs. atom ID flag int ifragment = onemol->findfragment(strarg); if (ifragment < 0) error->one(FLERR,"Bond/react: Molecule fragment does not exist"); - constraints[iconstr][myID] = ifragment; + constraints[iconstr][myrxn].id[i] = ifragment; } else { - constraints[iconstr][mode] = 1; // fragment vs. atom ID flag + constraints[iconstr][myrxn].idtype[i] = ATOM; // fragment vs. atom ID flag int iatom = atoi(strarg); if (iatom > onemol->natoms) error->one(FLERR,"Bond/react: Invalid template atom ID in map file"); - constraints[iconstr][myID] = iatom; + constraints[iconstr][myrxn].id[i] = iatom; } } diff --git a/src/USER-REACTION/fix_bond_react.h b/src/USER-REACTION/fix_bond_react.h index 6105859136..a66f57c2bc 100644 --- a/src/USER-REACTION/fix_bond_react.h +++ b/src/USER-REACTION/fix_bond_react.h @@ -31,7 +31,9 @@ namespace LAMMPS_NS { class FixBondReact : public Fix { public: - enum {MAXLINE=256}; + enum {MAXLINE=256}; // max length of line read from files + enum {MAXCONIDS=4}; // max # of IDs used by any constraint + enum {MAXCONPAR=4}; // max # of constraint parameters FixBondReact(class LAMMPS *, int, char **); ~FixBondReact(); @@ -66,9 +68,9 @@ class FixBondReact : public Fix { int *stabilize_steps_flag; int *custom_charges_fragid; int *molecule_keyword; - int nconstraints; + int *nconstraints; + char **constraintstr; int narrhenius; - double **constraints; int **var_flag,**var_id; // for keyword values with variable inputs int status; int *groupbits; @@ -114,7 +116,7 @@ class FixBondReact : public Fix { int *ibonding,*jbonding; int *closeneigh; // indicates if bonding atoms of a rxn are 1-2, 1-3, or 1-4 neighbors - int nedge,nequivalent,ndelete,nchiral,nconstr; // # edge, equivalent atoms in mapping file + int nedge,nequivalent,ndelete,nchiral; // # edge, equivalent atoms in mapping file int attempted_rxn; // there was an attempt! int *local_rxn_count; int *ghostly_rxn_count; @@ -155,7 +157,7 @@ class FixBondReact : public Fix { void DeleteAtoms(char *, int); void CustomCharges(int, int); void ChiralCenters(char *, int); - void Constraints(char *, int); + void ReadConstraints(char *, int); void readID(char *, int, int, int); void make_a_guess (); @@ -195,6 +197,14 @@ class FixBondReact : public Fix { }; Set *set; + struct Constraint { + int type; + int id[MAXCONIDS]; + int idtype[MAXCONIDS]; + double par[MAXCONPAR]; + }; + Constraint **constraints; + // DEBUG void print_bb(); diff --git a/src/USER-REAXC/reaxc_ffield.cpp b/src/USER-REAXC/reaxc_ffield.cpp index e4826e78c3..5181415a9f 100644 --- a/src/USER-REAXC/reaxc_ffield.cpp +++ b/src/USER-REAXC/reaxc_ffield.cpp @@ -44,10 +44,7 @@ char Read_Force_Field( FILE *fp, reax_interaction *reax, int lgflag = control->lgflag; int errorflag = 1; double val; - MPI_Comm comm; - int me; - comm = MPI_COMM_WORLD; - MPI_Comm_rank(comm, &me); + int me = control->me; s = (char*) malloc(sizeof(char)*MAX_LINE); tmp = (char**) malloc(sizeof(char*)*MAX_TOKENS); diff --git a/src/USER-SMTBQ/pair_smtbq.cpp b/src/USER-SMTBQ/pair_smtbq.cpp index 94647cb552..aedf90da07 100644 --- a/src/USER-SMTBQ/pair_smtbq.cpp +++ b/src/USER-SMTBQ/pair_smtbq.cpp @@ -72,17 +72,6 @@ using namespace MathSpecial; #define PGDELTA 1 #define MAXNEIGH 24 -/* ------------------------------------------------------------------------------------ - - Calculates the factorial of an integer n via recursion. - - ------------------------------------------------------------------------------------ */ -static double factorial(int n) -{ - if (n <= 1) return 1.0; - else return static_cast(n)*factorial(n-1); -} - /* ---------------------------------------------------------------------- */ PairSMTBQ::PairSMTBQ(LAMMPS *lmp) : Pair(lmp) diff --git a/src/atom_vec.cpp b/src/atom_vec.cpp index e464d31b77..4406ac5f23 100644 --- a/src/atom_vec.cpp +++ b/src/atom_vec.cpp @@ -29,9 +29,6 @@ using namespace LAMMPS_NS; using namespace MathConst; -#define DELTA 16384 -#define DELTA_BONUS 8192 - /* ---------------------------------------------------------------------- */ AtomVec::AtomVec(LAMMPS *lmp) : Pointers(lmp) @@ -188,6 +185,8 @@ void AtomVec::init() error->all(FLERR,"KOKKOS package requires a kokkos enabled atom_style"); } +static constexpr bigint DELTA=16384; + /* ---------------------------------------------------------------------- roundup N so it is a multiple of DELTA error if N exceeds 32-bit int, since will be used as arg to grow() @@ -211,6 +210,8 @@ void AtomVec::grow_nmax() nmax += DELTA; } +static constexpr bigint DELTA_BONUS=8192; + /* ---------------------------------------------------------------------- grow nmax_bonus so it is a multiple of DELTA_BONUS ------------------------------------------------------------------------- */ diff --git a/src/atom_vec_hybrid.cpp b/src/atom_vec_hybrid.cpp index 885299982b..8679b7383d 100644 --- a/src/atom_vec_hybrid.cpp +++ b/src/atom_vec_hybrid.cpp @@ -154,9 +154,9 @@ void AtomVecHybrid::process_args(int narg, char **arg) } if (mass_pertype && mass_peratom && comm->me == 0) - error->warning(FLERR, - "Atom_style hybrid defines both pertype and peratom masses " - "- both must be set, only peratom masses will be used"); + error->warning(FLERR, "Atom style hybrid defines both, per-type " + "and per-atom masses; both must be set, but only " + "per-atom masses will be used"); // free allstyles created by build_styles() @@ -216,8 +216,8 @@ void AtomVecHybrid::process_args(int narg, char **arg) char *dup = (char *) dupfield[idup]; ptr = strstr(concat_grow,dup); if ((ptr && strstr(ptr+1,dup)) && (comm->me == 0)) - error->warning(FLERR,fmt::format("Peratom {} is in multiple sub-styles " - "- must be used consistently",dup)); + error->warning(FLERR,fmt::format("Per-atom {} is used in multiple sub-" + "styles; must be used consistently",dup)); } delete [] concat_grow; diff --git a/src/balance.cpp b/src/balance.cpp index c47412cc9e..6294e023b3 100644 --- a/src/balance.cpp +++ b/src/balance.cpp @@ -924,66 +924,66 @@ int Balance::shift() i = 0; while (i < np) { if (split[i+1] - split[i] < close) { - j = i+1; + j = i+1; - // I,J = set of consecutive splits that are collectively too close - // if can expand set and not become too close to splits I-1 or J+1, do it - // else add split I-1 or J+1 to set and try again - // delta = size of expanded split set that will satisy criterion + // I,J = set of consecutive splits that are collectively too close + // if can expand set and not become too close to splits I-1 or J+1, do it + // else add split I-1 or J+1 to set and try again + // delta = size of expanded split set that will satisy criterion - while (1) { - delta = (j-i) * close; - midpt = 0.5 * (split[i]+split[j]); - start = midpt - 0.5*delta; - stop = midpt + 0.5*delta; + while (1) { + delta = (j-i) * close; + midpt = 0.5 * (split[i]+split[j]); + start = midpt - 0.5*delta; + stop = midpt + 0.5*delta; - if (i > 0) lbound = split[i-1] + close; - else lbound = 0.0; - if (j < np) ubound = split[j+1] - close; - else ubound = 1.0; + if (i > 0) lbound = split[i-1] + close; + else lbound = 0.0; + if (j < np) ubound = split[j+1] - close; + else ubound = 1.0; - // start/stop are within bounds, reset the splits + // start/stop are within bounds, reset the splits - if (start >= lbound && stop <= ubound) break; + if (start >= lbound && stop <= ubound) break; - // try a shift to either bound, reset the splits if delta fits - // these tests change start/stop + // try a shift to either bound, reset the splits if delta fits + // these tests change start/stop - if (start < lbound) { - start = lbound; - stop = start + delta; - if (stop <= ubound) break; - } else if (stop > ubound) { - stop = ubound; - start = stop - delta; - if (start >= lbound) break; - } + if (start < lbound) { + start = lbound; + stop = start + delta; + if (stop <= ubound) break; + } else if (stop > ubound) { + stop = ubound; + start = stop - delta; + if (start >= lbound) break; + } - // delta does not fit between lbound and ubound - // exit if can't expand set, else expand set - // if can expand in either direction, - // pick new split closest to current midpt of set + // delta does not fit between lbound and ubound + // exit if can't expand set, else expand set + // if can expand in either direction, + // pick new split closest to current midpt of set - if (i == 0 && j == np) { - start = 0.0; stop = 1.0; - break; - } - if (i == 0) j++; - else if (j == np) i--; - else if (midpt-lbound < ubound-midpt) i--; - else j++; - } + if (i == 0 && j == np) { + start = 0.0; stop = 1.0; + break; + } + if (i == 0) j++; + else if (j == np) i--; + else if (midpt-lbound < ubound-midpt) i--; + else j++; + } - // reset all splits between I,J inclusive to be equi-spaced + // reset all splits between I,J inclusive to be equi-spaced - spacing = (stop-start) / (j-i); - for (m = i; m <= j; m++) - split[m] = start + (m-i)*spacing; + spacing = (stop-start) / (j-i); + for (m = i; m <= j; m++) + split[m] = start + (m-i)*spacing; if (j == np) split[np] = 1.0; - // continue testing beyond the J split + // continue testing beyond the J split - i = j+1; + i = j+1; } else i++; } diff --git a/src/compute_orientorder_atom.cpp b/src/compute_orientorder_atom.cpp index db8a2f404b..b334654e82 100644 --- a/src/compute_orientorder_atom.cpp +++ b/src/compute_orientorder_atom.cpp @@ -23,6 +23,7 @@ #include "error.h" #include "force.h" #include "math_const.h" +#include "math_special.h" #include "memory.h" #include "modify.h" #include "neigh_list.h" @@ -36,6 +37,8 @@ using namespace LAMMPS_NS; using namespace MathConst; +using namespace MathSpecial; + #ifdef DBL_EPSILON #define MY_EPSILON (10.0*DBL_EPSILON) @@ -708,191 +711,3 @@ void ComputeOrientOrderAtom::init_clebsch_gordan() } } } - -/* ---------------------------------------------------------------------- - factorial n, wrapper for precomputed table -------------------------------------------------------------------------- */ - -double ComputeOrientOrderAtom::factorial(int n) -{ - if (n < 0 || n > nmaxfactorial) - error->all(FLERR,fmt::format("Invalid argument to factorial {}", n)); - - return nfac_table[n]; -} - -/* ---------------------------------------------------------------------- - factorial n table, size SNA::nmaxfactorial+1 -------------------------------------------------------------------------- */ - -const double ComputeOrientOrderAtom::nfac_table[] = { - 1, - 1, - 2, - 6, - 24, - 120, - 720, - 5040, - 40320, - 362880, - 3628800, - 39916800, - 479001600, - 6227020800, - 87178291200, - 1307674368000, - 20922789888000, - 355687428096000, - 6.402373705728e+15, - 1.21645100408832e+17, - 2.43290200817664e+18, - 5.10909421717094e+19, - 1.12400072777761e+21, - 2.5852016738885e+22, - 6.20448401733239e+23, - 1.5511210043331e+25, - 4.03291461126606e+26, - 1.08888694504184e+28, - 3.04888344611714e+29, - 8.8417619937397e+30, - 2.65252859812191e+32, - 8.22283865417792e+33, - 2.63130836933694e+35, - 8.68331761881189e+36, - 2.95232799039604e+38, - 1.03331479663861e+40, - 3.71993326789901e+41, - 1.37637530912263e+43, - 5.23022617466601e+44, - 2.03978820811974e+46, - 8.15915283247898e+47, - 3.34525266131638e+49, - 1.40500611775288e+51, - 6.04152630633738e+52, - 2.65827157478845e+54, - 1.1962222086548e+56, - 5.50262215981209e+57, - 2.58623241511168e+59, - 1.24139155925361e+61, - 6.08281864034268e+62, - 3.04140932017134e+64, - 1.55111875328738e+66, - 8.06581751709439e+67, - 4.27488328406003e+69, - 2.30843697339241e+71, - 1.26964033536583e+73, - 7.10998587804863e+74, - 4.05269195048772e+76, - 2.35056133128288e+78, - 1.3868311854569e+80, - 8.32098711274139e+81, - 5.07580213877225e+83, - 3.14699732603879e+85, - 1.98260831540444e+87, - 1.26886932185884e+89, - 8.24765059208247e+90, - 5.44344939077443e+92, - 3.64711109181887e+94, - 2.48003554243683e+96, - 1.71122452428141e+98, - 1.19785716699699e+100, - 8.50478588567862e+101, - 6.12344583768861e+103, - 4.47011546151268e+105, - 3.30788544151939e+107, - 2.48091408113954e+109, - 1.88549470166605e+111, - 1.45183092028286e+113, - 1.13242811782063e+115, - 8.94618213078297e+116, - 7.15694570462638e+118, - 5.79712602074737e+120, - 4.75364333701284e+122, - 3.94552396972066e+124, - 3.31424013456535e+126, - 2.81710411438055e+128, - 2.42270953836727e+130, - 2.10775729837953e+132, - 1.85482642257398e+134, - 1.65079551609085e+136, - 1.48571596448176e+138, - 1.3520015276784e+140, - 1.24384140546413e+142, - 1.15677250708164e+144, - 1.08736615665674e+146, - 1.03299784882391e+148, - 9.91677934870949e+149, - 9.61927596824821e+151, - 9.42689044888324e+153, - 9.33262154439441e+155, - 9.33262154439441e+157, - 9.42594775983835e+159, - 9.61446671503512e+161, - 9.90290071648618e+163, - 1.02990167451456e+166, - 1.08139675824029e+168, - 1.14628056373471e+170, - 1.22652020319614e+172, - 1.32464181945183e+174, - 1.44385958320249e+176, - 1.58824554152274e+178, - 1.76295255109024e+180, - 1.97450685722107e+182, - 2.23119274865981e+184, - 2.54355973347219e+186, - 2.92509369349301e+188, - 3.3931086844519e+190, - 3.96993716080872e+192, - 4.68452584975429e+194, - 5.5745857612076e+196, - 6.68950291344912e+198, - 8.09429852527344e+200, - 9.8750442008336e+202, - 1.21463043670253e+205, - 1.50614174151114e+207, - 1.88267717688893e+209, - 2.37217324288005e+211, - 3.01266001845766e+213, - 3.8562048236258e+215, - 4.97450422247729e+217, - 6.46685548922047e+219, - 8.47158069087882e+221, - 1.118248651196e+224, - 1.48727070609069e+226, - 1.99294274616152e+228, - 2.69047270731805e+230, - 3.65904288195255e+232, - 5.01288874827499e+234, - 6.91778647261949e+236, - 9.61572319694109e+238, - 1.34620124757175e+241, - 1.89814375907617e+243, - 2.69536413788816e+245, - 3.85437071718007e+247, - 5.5502938327393e+249, - 8.04792605747199e+251, - 1.17499720439091e+254, - 1.72724589045464e+256, - 2.55632391787286e+258, - 3.80892263763057e+260, - 5.71338395644585e+262, - 8.62720977423323e+264, - 1.31133588568345e+267, - 2.00634390509568e+269, - 3.08976961384735e+271, - 4.78914290146339e+273, - 7.47106292628289e+275, - 1.17295687942641e+278, - 1.85327186949373e+280, - 2.94670227249504e+282, - 4.71472363599206e+284, - 7.59070505394721e+286, - 1.22969421873945e+289, - 2.0044015765453e+291, - 3.28721858553429e+293, - 5.42391066613159e+295, - 9.00369170577843e+297, - 1.503616514865e+300, // nmaxfactorial = 167 -}; - diff --git a/src/compute_orientorder_atom.h b/src/compute_orientorder_atom.h index 4e5084bfcd..4fc122c5c8 100644 --- a/src/compute_orientorder_atom.h +++ b/src/compute_orientorder_atom.h @@ -56,9 +56,6 @@ class ComputeOrientOrderAtom : public Compute { double polar_prefactor(int, int, double); double associated_legendre(int, int, double); - static const int nmaxfactorial = 167; - static const double nfac_table[]; - double factorial(int); virtual void init_clebsch_gordan(); double *cglist; // Clebsch-Gordan coeffs int idxcg_max; diff --git a/src/fix.h b/src/fix.h index 75c644e87f..ec951e3bb2 100644 --- a/src/fix.h +++ b/src/fix.h @@ -251,31 +251,32 @@ class Fix : protected Pointers { }; namespace FixConst { - static const int INITIAL_INTEGRATE = 1<<0; - static const int POST_INTEGRATE = 1<<1; - static const int PRE_EXCHANGE = 1<<2; - static const int PRE_NEIGHBOR = 1<<3; - static const int POST_NEIGHBOR = 1<<4; - static const int PRE_FORCE = 1<<5; - static const int PRE_REVERSE = 1<<6; - static const int POST_FORCE = 1<<7; - static const int FINAL_INTEGRATE = 1<<8; - static const int END_OF_STEP = 1<<9; - static const int POST_RUN = 1<<10; - static const int THERMO_ENERGY = 1<<11; - static const int INITIAL_INTEGRATE_RESPA = 1<<12; - static const int POST_INTEGRATE_RESPA = 1<<13; - static const int PRE_FORCE_RESPA = 1<<14; - static const int POST_FORCE_RESPA = 1<<15; - static const int FINAL_INTEGRATE_RESPA = 1<<16; - static const int MIN_PRE_EXCHANGE = 1<<17; - static const int MIN_PRE_NEIGHBOR = 1<<18; - static const int MIN_POST_NEIGHBOR = 1<<19; - static const int MIN_PRE_FORCE = 1<<20; - static const int MIN_PRE_REVERSE = 1<<21; - static const int MIN_POST_FORCE = 1<<22; - static const int MIN_ENERGY = 1<<23; - static const int FIX_CONST_LAST = 1<<24; + enum { + INITIAL_INTEGRATE = 1<<0, + POST_INTEGRATE = 1<<1, + PRE_EXCHANGE = 1<<2, + PRE_NEIGHBOR = 1<<3, + POST_NEIGHBOR = 1<<4, + PRE_FORCE = 1<<5, + PRE_REVERSE = 1<<6, + POST_FORCE = 1<<7, + FINAL_INTEGRATE = 1<<8, + END_OF_STEP = 1<<9, + POST_RUN = 1<<10, + THERMO_ENERGY = 1<<11, + INITIAL_INTEGRATE_RESPA = 1<<12, + POST_INTEGRATE_RESPA = 1<<13, + PRE_FORCE_RESPA = 1<<14, + POST_FORCE_RESPA = 1<<15, + FINAL_INTEGRATE_RESPA = 1<<16, + MIN_PRE_EXCHANGE = 1<<17, + MIN_PRE_NEIGHBOR = 1<<18, + MIN_POST_NEIGHBOR = 1<<19, + MIN_PRE_FORCE = 1<<20, + MIN_PRE_REVERSE = 1<<21, + MIN_POST_FORCE = 1<<22, + MIN_ENERGY = 1<<23 + }; } } diff --git a/src/fix_temp_csld.cpp b/src/fix_temp_csld.cpp index f01de7c2fa..3b522c185f 100644 --- a/src/fix_temp_csld.cpp +++ b/src/fix_temp_csld.cpp @@ -305,16 +305,17 @@ double FixTempCSLD::compute_scalar() void FixTempCSLD::write_restart(FILE *fp) { - int nsize = (98+2+3)*comm->nprocs+2; // pRNG state per proc + nprocs + energy + const int PRNGSIZE = 98+2+3; + int nsize = PRNGSIZE*comm->nprocs+2; // pRNG state per proc + nprocs + energy double *list = nullptr; if (comm->me == 0) { list = new double[nsize]; list[0] = energy; list[1] = comm->nprocs; } - double state[103]; + double state[PRNGSIZE]; random->get_state(state); - MPI_Gather(state,103,MPI_DOUBLE,list+2,103*comm->nprocs,MPI_DOUBLE,0,world); + MPI_Gather(state,PRNGSIZE,MPI_DOUBLE,list+2,PRNGSIZE,MPI_DOUBLE,0,world); if (comm->me == 0) { int size = nsize * sizeof(double); diff --git a/src/fix_temp_csvr.cpp b/src/fix_temp_csvr.cpp index 0130631172..674c436e9d 100644 --- a/src/fix_temp_csvr.cpp +++ b/src/fix_temp_csvr.cpp @@ -338,16 +338,17 @@ double FixTempCSVR::compute_scalar() void FixTempCSVR::write_restart(FILE *fp) { - int nsize = (98+2+3)*comm->nprocs+2; // pRNG state per proc + nprocs + energy + const int PRNGSIZE = 98+2+3; + int nsize = PRNGSIZE*comm->nprocs+2; // pRNG state per proc + nprocs + energy double *list = nullptr; if (comm->me == 0) { list = new double[nsize]; list[0] = energy; list[1] = comm->nprocs; } - double state[103]; + double state[PRNGSIZE]; random->get_state(state); - MPI_Gather(state,103,MPI_DOUBLE,list+2,103*comm->nprocs,MPI_DOUBLE,0,world); + MPI_Gather(state,PRNGSIZE,MPI_DOUBLE,list+2,PRNGSIZE,MPI_DOUBLE,0,world); if (comm->me == 0) { int size = nsize * sizeof(double); diff --git a/src/fmt/os.h b/src/fmt/os.h index d44ea0c904..823173c8e3 100644 --- a/src/fmt/os.h +++ b/src/fmt/os.h @@ -375,7 +375,11 @@ struct ostream_params { }; } // namespace detail +#if defined(__PGI) +static detail::buffer_size buffer_size; +#else static constexpr detail::buffer_size buffer_size; +#endif // A fast output stream which is not thread-safe. class ostream final : private detail::buffer { diff --git a/src/force.cpp b/src/force.cpp index d271d1207e..1f03206f31 100644 --- a/src/force.cpp +++ b/src/force.cpp @@ -245,13 +245,22 @@ void Force::create_pair(const std::string &style, int trysuffix) /* ---------------------------------------------------------------------- generate a pair class if trysuffix = 1, try first with suffix1/2 appended - return sflag = 0 for no suffix added, 1 or 2 for suffix1/2 added + return sflag = 0 for no suffix added, 1 or 2 or 3 for suffix1/2/p added + special case: if suffixp exists only try suffixp, not suffix ------------------------------------------------------------------------- */ Pair *Force::new_pair(const std::string &style, int trysuffix, int &sflag) { if (trysuffix && lmp->suffix_enable) { - if (lmp->suffix) { + if (lmp->suffixp) { + sflag = 3; + std::string estyle = style + "/" + lmp->suffixp; + if (pair_map->find(estyle) != pair_map->end()) { + PairCreator &pair_creator = (*pair_map)[estyle]; + return pair_creator(lmp); + } + } + if (lmp->suffix && !lmp->suffixp) { sflag = 1; std::string estyle = style + "/" + lmp->suffix; if (pair_map->find(estyle) != pair_map->end()) { @@ -727,7 +736,7 @@ KSpace *Force::kspace_match(const std::string &word, int exact) /* ---------------------------------------------------------------------- store style name in str allocated here if sflag = 0, no suffix - if sflag = 1/2, append suffix or suffix2 to style + if sflag = 1/2/3, append suffix or suffix2 or suffixp to style ------------------------------------------------------------------------- */ void Force::store_style(char *&str, const std::string &style, int sflag) @@ -736,6 +745,7 @@ void Force::store_style(char *&str, const std::string &style, int sflag) if (sflag == 1) estyle += std::string("/") + lmp->suffix; else if (sflag == 2) estyle += std::string("/") + lmp->suffix2; + else if (sflag == 3) estyle += std::string("/") + lmp->suffixp; str = new char[estyle.size()+1]; strcpy(str,estyle.c_str()); diff --git a/src/info.cpp b/src/info.cpp index 63ea4dccce..085e4e65ea 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -1179,6 +1179,8 @@ std::string Info::get_compiler_info() std::string buf; #if __clang__ buf = fmt::format("Clang C++ {}", __VERSION__); +#elif __PGI + buf = fmt::format("PGI C++ {}.{}",__PGIC__,__PGIC_MINOR__); #elif __INTEL_COMPILER double version = static_cast(__INTEL_COMPILER)*0.01; buf = fmt::format("Intel C++ {:.2f}.{} / {}", version, diff --git a/src/input.cpp b/src/input.cpp index abdc3775ce..457cf74b1a 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1715,7 +1715,10 @@ void Input::pair_style() int match = 0; if (style == force->pair_style) match = 1; if (!match && lmp->suffix_enable) { - if (lmp->suffix) + if (lmp->suffixp) + if (style + "/" + lmp->suffixp == force->pair_style) match = 1; + + if (lmp->suffix && !lmp->suffixp) if (style + "/" + lmp->suffix == force->pair_style) match = 1; if (lmp->suffix2) diff --git a/src/lammps.cpp b/src/lammps.cpp index 102d2f18cf..69baec5557 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -173,7 +173,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : int citeflag = 1; int helpflag = 0; - suffix = suffix2 = nullptr; + suffix = suffix2 = suffixp = nullptr; suffix_enable = 0; if (arg) exename = arg[0]; else exename = nullptr; @@ -714,6 +714,7 @@ LAMMPS::~LAMMPS() delete kokkos; delete [] suffix; delete [] suffix2; + delete [] suffixp; // free the MPI comm created by -mpi command-line arg processed in constructor // it was passed to universe as if original universe world diff --git a/src/lammps.h b/src/lammps.h index 0d9442ffb9..49d55d4e37 100644 --- a/src/lammps.h +++ b/src/lammps.h @@ -51,7 +51,7 @@ class LAMMPS { double initclock; // wall clock at instantiation - char *suffix,*suffix2; // suffixes to add to input script style names + char *suffix,*suffix2,*suffixp;// suffixes to add to input script style names int suffix_enable; // 1 if suffixes are enabled, 0 if disabled char *exename; // pointer to argv[0] char ***packargs; // arguments for cmdline package commands diff --git a/src/library.h b/src/library.h index 7806903e49..14be4064ea 100644 --- a/src/library.h +++ b/src/library.h @@ -42,7 +42,7 @@ /** Data type constants for extracting data from atoms, computes and fixes * - * Must be kept in sync with the equivalent constants in lammps.py */ + * Must be kept in sync with the equivalent constants in lammps/constants.py */ enum _LMP_DATATYPE_CONST { LAMMPS_INT = 0, /*!< 32-bit integer (array) */ @@ -56,7 +56,7 @@ enum _LMP_DATATYPE_CONST { /** Style constants for extracting data from computes and fixes. * - * Must be kept in sync with the equivalent constants in lammps.py */ + * Must be kept in sync with the equivalent constants in lammps/constants.py */ enum _LMP_STYLE_CONST { LMP_STYLE_GLOBAL=0, /*!< return global data */ @@ -66,7 +66,7 @@ enum _LMP_STYLE_CONST { /** Type and size constants for extracting data from computes and fixes. * - * Must be kept in sync with the equivalent constants in lammps.py */ + * Must be kept in sync with the equivalent constants in lammps/constants.py */ enum _LMP_TYPE_CONST { LMP_TYPE_SCALAR=0, /*!< return scalar */ diff --git a/src/lmptype.h b/src/lmptype.h index e5dba94be0..264b93a329 100644 --- a/src/lmptype.h +++ b/src/lmptype.h @@ -268,6 +268,8 @@ The typecasts prevent compiler warnings about possible truncation issues. # define _noopt __attribute__((optnone)) #elif defined(__INTEL_COMPILER) # define _noopt +#elif defined(__PGI) +# define _noopt #elif defined(__GNUC__) # if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) # if defined(_FORTIFY_SOURCE) && (_FORTIFY_SOURCE > 0) diff --git a/src/math_const.h b/src/math_const.h index fefb442f68..53a485bf99 100644 --- a/src/math_const.h +++ b/src/math_const.h @@ -17,18 +17,18 @@ namespace LAMMPS_NS { namespace MathConst { - static const double THIRD = 1.0/3.0; - static const double TWOTHIRDS = 2.0/3.0; - static const double MY_PI = 3.14159265358979323846; // pi - static const double MY_2PI = 6.28318530717958647692; // 2pi - static const double MY_3PI = 9.42477796076937971538; // 3pi - static const double MY_4PI = 12.56637061435917295384; // 4pi - static const double MY_PI2 = 1.57079632679489661923; // pi/2 - static const double MY_PI4 = 0.78539816339744830962; // pi/4 - static const double MY_PIS = 1.77245385090551602729; // sqrt(pi) - static const double MY_ISPI4 = 1.12837916709551257389; // 1/sqrt(pi/4) - static const double MY_SQRT2 = 1.41421356237309504880; // sqrt(2) - static const double MY_CBRT2 = 1.25992104989487316476; // 2*(1/3) + static constexpr double THIRD = 1.0/3.0; + static constexpr double TWOTHIRDS = 2.0/3.0; + static constexpr double MY_PI = 3.14159265358979323846; // pi + static constexpr double MY_2PI = 6.28318530717958647692; // 2pi + static constexpr double MY_3PI = 9.42477796076937971538; // 3pi + static constexpr double MY_4PI = 12.56637061435917295384; // 4pi + static constexpr double MY_PI2 = 1.57079632679489661923; // pi/2 + static constexpr double MY_PI4 = 0.78539816339744830962; // pi/4 + static constexpr double MY_PIS = 1.77245385090551602729; // sqrt(pi) + static constexpr double MY_ISPI4 = 1.12837916709551257389; // 1/sqrt(pi/4) + static constexpr double MY_SQRT2 = 1.41421356237309504880; // sqrt(2) + static constexpr double MY_CBRT2 = 1.25992104989487316476; // 2*(1/3) } } diff --git a/src/math_special.cpp b/src/math_special.cpp index 5ec0fc3f61..243d5a05f3 100644 --- a/src/math_special.cpp +++ b/src/math_special.cpp @@ -1,9 +1,203 @@ #include "math_special.h" + #include #include // IWYU pragma: keep +#include + +#include "error.h" using namespace LAMMPS_NS; +static constexpr int nmaxfactorial = 167; + +/* ---------------------------------------------------------------------- + factorial n table, size nmaxfactorial+1 +------------------------------------------------------------------------- */ + +static const double nfac_table[] = { + 1, + 1, + 2, + 6, + 24, + 120, + 720, + 5040, + 40320, + 362880, + 3628800, + 39916800, + 479001600, + 6227020800, + 87178291200, + 1307674368000, + 20922789888000, + 355687428096000, + 6.402373705728e+15, + 1.21645100408832e+17, + 2.43290200817664e+18, + 5.10909421717094e+19, + 1.12400072777761e+21, + 2.5852016738885e+22, + 6.20448401733239e+23, + 1.5511210043331e+25, + 4.03291461126606e+26, + 1.08888694504184e+28, + 3.04888344611714e+29, + 8.8417619937397e+30, + 2.65252859812191e+32, + 8.22283865417792e+33, + 2.63130836933694e+35, + 8.68331761881189e+36, + 2.95232799039604e+38, + 1.03331479663861e+40, + 3.71993326789901e+41, + 1.37637530912263e+43, + 5.23022617466601e+44, + 2.03978820811974e+46, + 8.15915283247898e+47, + 3.34525266131638e+49, + 1.40500611775288e+51, + 6.04152630633738e+52, + 2.65827157478845e+54, + 1.1962222086548e+56, + 5.50262215981209e+57, + 2.58623241511168e+59, + 1.24139155925361e+61, + 6.08281864034268e+62, + 3.04140932017134e+64, + 1.55111875328738e+66, + 8.06581751709439e+67, + 4.27488328406003e+69, + 2.30843697339241e+71, + 1.26964033536583e+73, + 7.10998587804863e+74, + 4.05269195048772e+76, + 2.35056133128288e+78, + 1.3868311854569e+80, + 8.32098711274139e+81, + 5.07580213877225e+83, + 3.14699732603879e+85, + 1.98260831540444e+87, + 1.26886932185884e+89, + 8.24765059208247e+90, + 5.44344939077443e+92, + 3.64711109181887e+94, + 2.48003554243683e+96, + 1.71122452428141e+98, + 1.19785716699699e+100, + 8.50478588567862e+101, + 6.12344583768861e+103, + 4.47011546151268e+105, + 3.30788544151939e+107, + 2.48091408113954e+109, + 1.88549470166605e+111, + 1.45183092028286e+113, + 1.13242811782063e+115, + 8.94618213078297e+116, + 7.15694570462638e+118, + 5.79712602074737e+120, + 4.75364333701284e+122, + 3.94552396972066e+124, + 3.31424013456535e+126, + 2.81710411438055e+128, + 2.42270953836727e+130, + 2.10775729837953e+132, + 1.85482642257398e+134, + 1.65079551609085e+136, + 1.48571596448176e+138, + 1.3520015276784e+140, + 1.24384140546413e+142, + 1.15677250708164e+144, + 1.08736615665674e+146, + 1.03299784882391e+148, + 9.91677934870949e+149, + 9.61927596824821e+151, + 9.42689044888324e+153, + 9.33262154439441e+155, + 9.33262154439441e+157, + 9.42594775983835e+159, + 9.61446671503512e+161, + 9.90290071648618e+163, + 1.02990167451456e+166, + 1.08139675824029e+168, + 1.14628056373471e+170, + 1.22652020319614e+172, + 1.32464181945183e+174, + 1.44385958320249e+176, + 1.58824554152274e+178, + 1.76295255109024e+180, + 1.97450685722107e+182, + 2.23119274865981e+184, + 2.54355973347219e+186, + 2.92509369349301e+188, + 3.3931086844519e+190, + 3.96993716080872e+192, + 4.68452584975429e+194, + 5.5745857612076e+196, + 6.68950291344912e+198, + 8.09429852527344e+200, + 9.8750442008336e+202, + 1.21463043670253e+205, + 1.50614174151114e+207, + 1.88267717688893e+209, + 2.37217324288005e+211, + 3.01266001845766e+213, + 3.8562048236258e+215, + 4.97450422247729e+217, + 6.46685548922047e+219, + 8.47158069087882e+221, + 1.118248651196e+224, + 1.48727070609069e+226, + 1.99294274616152e+228, + 2.69047270731805e+230, + 3.65904288195255e+232, + 5.01288874827499e+234, + 6.91778647261949e+236, + 9.61572319694109e+238, + 1.34620124757175e+241, + 1.89814375907617e+243, + 2.69536413788816e+245, + 3.85437071718007e+247, + 5.5502938327393e+249, + 8.04792605747199e+251, + 1.17499720439091e+254, + 1.72724589045464e+256, + 2.55632391787286e+258, + 3.80892263763057e+260, + 5.71338395644585e+262, + 8.62720977423323e+264, + 1.31133588568345e+267, + 2.00634390509568e+269, + 3.08976961384735e+271, + 4.78914290146339e+273, + 7.47106292628289e+275, + 1.17295687942641e+278, + 1.85327186949373e+280, + 2.94670227249504e+282, + 4.71472363599206e+284, + 7.59070505394721e+286, + 1.22969421873945e+289, + 2.0044015765453e+291, + 3.28721858553429e+293, + 5.42391066613159e+295, + 9.00369170577843e+297, + 1.503616514865e+300, // nmaxfactorial = 167 +}; + +/* ---------------------------------------------------------------------- + factorial n vial lookup from precomputed table +------------------------------------------------------------------------- */ + +double MathSpecial::factorial(const int n) +{ + if (n < 0 || n > nmaxfactorial) + return std::numeric_limits::quiet_NaN(); + + return nfac_table[n]; +} + + /* Library libcerf: * Compute complex error functions, based on a new implementation of * Faddeeva's w_of_z. Also provide Dawson and Voigt functions. diff --git a/src/math_special.h b/src/math_special.h index 1e7b10d9fd..59517a2f76 100644 --- a/src/math_special.h +++ b/src/math_special.h @@ -20,6 +20,10 @@ namespace LAMMPS_NS { namespace MathSpecial { + // tabulated factorial function + + extern double factorial(const int); + // support function for scaled error function complement extern double erfcx_y100(const double y100); diff --git a/src/neighbor.cpp b/src/neighbor.cpp index 949e0387ea..7761aae721 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -2162,12 +2162,15 @@ void Neighbor::build_one(class NeighList *mylist, int preflag) // if this is copy list and parent is occasional list, // or this is halffull and parent is occasional list, + // or this is skip list and parent is occasional list, // insure parent is current if (mylist->listcopy && mylist->listcopy->occasional) build_one(mylist->listcopy,preflag); if (mylist->listfull && mylist->listfull->occasional) build_one(mylist->listfull,preflag); + if (mylist->listskip && mylist->listskip->occasional) + build_one(mylist->listskip,preflag); // create stencil if hasn't been created since last setup_bins() call diff --git a/src/neighbor.h b/src/neighbor.h index 9ee2af9c75..b9b40bcf1a 100644 --- a/src/neighbor.h +++ b/src/neighbor.h @@ -235,49 +235,55 @@ class Neighbor : protected Pointers { }; namespace NeighConst { - static const int NB_INTEL = 1<<0; - static const int NB_KOKKOS_DEVICE = 1<<1; - static const int NB_KOKKOS_HOST = 1<<2; - static const int NB_SSA = 1<<3; + enum { + NB_INTEL = 1<<0, + NB_KOKKOS_DEVICE = 1<<1, + NB_KOKKOS_HOST = 1<<2, + NB_SSA = 1<<3 + }; - static const int NS_BIN = 1<<0; - static const int NS_MULTI = 1<<1; - static const int NS_HALF = 1<<2; - static const int NS_FULL = 1<<3; - static const int NS_2D = 1<<4; - static const int NS_3D = 1<<5; - static const int NS_NEWTON = 1<<6; - static const int NS_NEWTOFF = 1<<7; - static const int NS_ORTHO = 1<<8; - static const int NS_TRI = 1<<9; - static const int NS_GHOST = 1<<10; - static const int NS_SSA = 1<<11; + enum { + NS_BIN = 1<<0, + NS_MULTI = 1<<1, + NS_HALF = 1<<2, + NS_FULL = 1<<3, + NS_2D = 1<<4, + NS_3D = 1<<5, + NS_NEWTON = 1<<6, + NS_NEWTOFF = 1<<7, + NS_ORTHO = 1<<8, + NS_TRI = 1<<9, + NS_GHOST = 1<<10, + NS_SSA = 1<<11 + }; - static const int NP_NSQ = 1<<0; - static const int NP_BIN = 1<<1; - static const int NP_MULTI = 1<<2; - static const int NP_HALF = 1<<3; - static const int NP_FULL = 1<<4; - static const int NP_ORTHO = 1<<5; - static const int NP_TRI = 1<<6; - static const int NP_ATOMONLY = 1<<7; - static const int NP_MOLONLY = 1<<8; - static const int NP_NEWTON = 1<<9; - static const int NP_NEWTOFF = 1<<10; - static const int NP_GHOST = 1<<11; - static const int NP_SIZE = 1<<12; - static const int NP_ONESIDE = 1<<13; - static const int NP_RESPA = 1<<14; - static const int NP_BOND = 1<<15; - static const int NP_OMP = 1<<16; - static const int NP_INTEL = 1<<17; - static const int NP_KOKKOS_DEVICE = 1<<18; - static const int NP_KOKKOS_HOST = 1<<19; - static const int NP_SSA = 1<<20; - static const int NP_COPY = 1<<21; - static const int NP_SKIP = 1<<22; - static const int NP_HALF_FULL = 1<<23; - static const int NP_OFF2ON = 1<<24; + enum { + NP_NSQ = 1<<0, + NP_BIN = 1<<1, + NP_MULTI = 1<<2, + NP_HALF = 1<<3, + NP_FULL = 1<<4, + NP_ORTHO = 1<<5, + NP_TRI = 1<<6, + NP_ATOMONLY = 1<<7, + NP_MOLONLY = 1<<8, + NP_NEWTON = 1<<9, + NP_NEWTOFF = 1<<10, + NP_GHOST = 1<<11, + NP_SIZE = 1<<12, + NP_ONESIDE = 1<<13, + NP_RESPA = 1<<14, + NP_BOND = 1<<15, + NP_OMP = 1<<16, + NP_INTEL = 1<<17, + NP_KOKKOS_DEVICE = 1<<18, + NP_KOKKOS_HOST = 1<<19, + NP_SSA = 1<<20, + NP_COPY = 1<<21, + NP_SKIP = 1<<22, + NP_HALF_FULL = 1<<23, + NP_OFF2ON = 1<<24 + }; } } diff --git a/src/npair_half_size_multi_newtoff.cpp b/src/npair_half_size_multi_newtoff.cpp new file mode 100644 index 0000000000..813a642b96 --- /dev/null +++ b/src/npair_half_size_multi_newtoff.cpp @@ -0,0 +1,117 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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. +------------------------------------------------------------------------- */ + +#include "npair_half_size_multi_newtoff.h" +#include "neigh_list.h" +#include "atom.h" +#include "atom_vec.h" +#include "my_page.h" +#include "error.h" + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +NPairHalfSizeMultiNewtoff::NPairHalfSizeMultiNewtoff(LAMMPS *lmp) : NPair(lmp) {} + +/* ---------------------------------------------------------------------- + size particles + binned neighbor list construction with partial Newton's 3rd law + each owned atom i checks own bin and other bins in stencil + multi-type stencil is itype dependent and is distance checked + pair stored once if i,j are both owned and i < j + pair stored by me if j is ghost (also stored by proc owning j) +------------------------------------------------------------------------- */ + +void NPairHalfSizeMultiNewtoff::build(NeighList *list) +{ + int i,j,k,m,n,itype,jtype,ibin,ns; + double xtmp,ytmp,ztmp,delx,dely,delz,rsq; + double radi,radsum,cutdistsq; + int *neighptr,*s; + double *cutsq,*distsq; + + double **x = atom->x; + double *radius = atom->radius; + int *type = atom->type; + int *mask = atom->mask; + tagint *molecule = atom->molecule; + int nlocal = atom->nlocal; + if (includegroup) nlocal = atom->nfirst; + + int history = list->history; + int *ilist = list->ilist; + int *numneigh = list->numneigh; + int **firstneigh = list->firstneigh; + MyPage *ipage = list->ipage; + + int mask_history = 3 << SBBITS; + + int inum = 0; + ipage->reset(); + + for (i = 0; i < nlocal; i++) { + n = 0; + neighptr = ipage->vget(); + + itype = type[i]; + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + radi = radius[i]; + + // loop over all atoms in other bins in stencil including self + // only store pair if i < j + // skip if i,j neighbor cutoff is less than bin distance + // stores own/own pairs only once + // stores own/ghost pairs on both procs + + ibin = atom2bin[i]; + s = stencil_multi[itype]; + distsq = distsq_multi[itype]; + cutsq = cutneighsq[itype]; + ns = nstencil_multi[itype]; + for (k = 0; k < ns; k++) { + for (j = binhead[ibin+s[k]]; j >= 0; j = bins[j]) { + if (j <= i) continue; + jtype = type[j]; + if (cutsq[jtype] < distsq[k]) continue; + + if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue; + + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + radsum = radi + radius[j]; + cutdistsq = (radsum+skin) * (radsum+skin); + + if (rsq <= cutdistsq) { + if (history && rsq < radsum*radsum) + neighptr[n++] = j ^ mask_history; + else + neighptr[n++] = j; + } + } + } + + ilist[inum++] = i; + firstneigh[i] = neighptr; + numneigh[i] = n; + ipage->vgot(n); + if (ipage->status()) + error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); + } + + list->inum = inum; +} diff --git a/src/npair_half_size_multi_newtoff.h b/src/npair_half_size_multi_newtoff.h new file mode 100644 index 0000000000..f255f9a17d --- /dev/null +++ b/src/npair_half_size_multi_newtoff.h @@ -0,0 +1,46 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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 NPAIR_CLASS + +NPairStyle(half/size/multi/newtoff, + NPairHalfSizeMultiNewtoff, + NP_HALF | NP_SIZE | NP_MULTI | NP_NEWTOFF | NP_ORTHO | NP_TRI) + +#else + +#ifndef LMP_NPAIR_HALF_SIZE_MULTI_NEWTOFF_H +#define LMP_NPAIR_HALF_SIZE_MULTI_NEWTOFF_H + +#include "npair.h" + +namespace LAMMPS_NS { + +class NPairHalfSizeMultiNewtoff : public NPair { + public: + NPairHalfSizeMultiNewtoff(class LAMMPS *); + ~NPairHalfSizeMultiNewtoff() {} + void build(class NeighList *); +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +E: Neighbor list overflow, boost neigh_modify one + +UNDOCUMENTED +*/ diff --git a/src/npair_half_size_multi_newton.cpp b/src/npair_half_size_multi_newton.cpp new file mode 100644 index 0000000000..943965ab63 --- /dev/null +++ b/src/npair_half_size_multi_newton.cpp @@ -0,0 +1,143 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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. +------------------------------------------------------------------------- */ + +#include "npair_half_size_multi_newton.h" +#include "neigh_list.h" +#include "atom.h" +#include "atom_vec.h" +#include "my_page.h" +#include "error.h" + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +NPairHalfSizeMultiNewton::NPairHalfSizeMultiNewton(LAMMPS *lmp) : NPair(lmp) {} + +/* ---------------------------------------------------------------------- + size particles + binned neighbor list construction with full Newton's 3rd law + each owned atom i checks its own bin and other bins in Newton stencil + multi-type stencil is itype dependent and is distance checked + every pair stored exactly once by some processor +------------------------------------------------------------------------- */ + +void NPairHalfSizeMultiNewton::build(NeighList *list) +{ + int i,j,k,m,n,itype,jtype,ibin,ns; + double xtmp,ytmp,ztmp,delx,dely,delz,rsq; + double radi,radsum,cutdistsq; + int *neighptr,*s; + double *cutsq,*distsq; + + double **x = atom->x; + double *radius = atom->radius; + int *type = atom->type; + int *mask = atom->mask; + tagint *molecule = atom->molecule; + int nlocal = atom->nlocal; + if (includegroup) nlocal = atom->nfirst; + + int history = list->history; + int *ilist = list->ilist; + int *numneigh = list->numneigh; + int **firstneigh = list->firstneigh; + MyPage *ipage = list->ipage; + + int mask_history = 3 << SBBITS; + + int inum = 0; + ipage->reset(); + + for (i = 0; i < nlocal; i++) { + n = 0; + neighptr = ipage->vget(); + + itype = type[i]; + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + radi = radius[i]; + + // loop over rest of atoms in i's bin, ghosts are at end of linked list + // if j is owned atom, store it, since j is beyond i in linked list + // if j is ghost, only store if j coords are "above and to the right" of i + + for (j = bins[i]; j >= 0; j = bins[j]) { + if (j >= nlocal) { + if (x[j][2] < ztmp) continue; + if (x[j][2] == ztmp) { + if (x[j][1] < ytmp) continue; + if (x[j][1] == ytmp && x[j][0] < xtmp) continue; + } + } + + jtype = type[j]; + if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue; + + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + radsum = radi + radius[j]; + cutdistsq = (radsum+skin) * (radsum+skin); + + if (rsq <= cutdistsq) { + if (history && rsq < radsum*radsum) + neighptr[n++] = j ^ mask_history; + else + neighptr[n++] = j; + } + } + + // loop over all atoms in other bins in stencil, store every pair + // skip if i,j neighbor cutoff is less than bin distance + + ibin = atom2bin[i]; + s = stencil_multi[itype]; + distsq = distsq_multi[itype]; + cutsq = cutneighsq[itype]; + ns = nstencil_multi[itype]; + for (k = 0; k < ns; k++) { + for (j = binhead[ibin+s[k]]; j >= 0; j = bins[j]) { + jtype = type[j]; + if (cutsq[jtype] < distsq[k]) continue; + + if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue; + + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + radsum = radi + radius[j]; + cutdistsq = (radsum+skin) * (radsum+skin); + + if (rsq <= cutdistsq) { + if (history && rsq < radsum*radsum) + neighptr[n++] = j ^ mask_history; + else + neighptr[n++] = j; + } + } + } + + ilist[inum++] = i; + firstneigh[i] = neighptr; + numneigh[i] = n; + ipage->vgot(n); + if (ipage->status()) + error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); + } + + list->inum = inum; +} diff --git a/src/npair_half_size_multi_newton.h b/src/npair_half_size_multi_newton.h new file mode 100644 index 0000000000..3e3d6f4180 --- /dev/null +++ b/src/npair_half_size_multi_newton.h @@ -0,0 +1,46 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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 NPAIR_CLASS + +NPairStyle(half/size/multi/newton, + NPairHalfSizeMultiNewton, + NP_HALF | NP_SIZE | NP_MULTI | NP_NEWTON | NP_ORTHO) + +#else + +#ifndef LMP_NPAIR_HALF_SIZE_MULTI_NEWTON_H +#define LMP_NPAIR_HALF_SIZE_MULTI_NEWTON_H + +#include "npair.h" + +namespace LAMMPS_NS { + +class NPairHalfSizeMultiNewton : public NPair { + public: + NPairHalfSizeMultiNewton(class LAMMPS *); + ~NPairHalfSizeMultiNewton() {} + void build(class NeighList *); +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +E: Neighbor list overflow, boost neigh_modify one + +UNDOCUMENTED +*/ diff --git a/src/npair_half_size_multi_newton_tri.cpp b/src/npair_half_size_multi_newton_tri.cpp new file mode 100644 index 0000000000..e59a3f088a --- /dev/null +++ b/src/npair_half_size_multi_newton_tri.cpp @@ -0,0 +1,125 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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. +------------------------------------------------------------------------- */ + +#include "npair_half_size_multi_newton_tri.h" +#include "neigh_list.h" +#include "atom.h" +#include "atom_vec.h" +#include "my_page.h" +#include "error.h" + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +NPairHalfSizeMultiNewtonTri::NPairHalfSizeMultiNewtonTri(LAMMPS *lmp) : NPair(lmp) {} + +/* ---------------------------------------------------------------------- + binned neighbor list construction with Newton's 3rd law for triclinic + each owned atom i checks its own bin and other bins in triclinic stencil + multi-type stencil is itype dependent and is distance checked + every pair stored exactly once by some processor +------------------------------------------------------------------------- */ + +void NPairHalfSizeMultiNewtonTri::build(NeighList *list) +{ + int i,j,k,m,n,itype,jtype,ibin,ns; + double xtmp,ytmp,ztmp,delx,dely,delz,rsq; + double radi,radsum,cutdistsq; + int *neighptr,*s; + double *cutsq,*distsq; + + double **x = atom->x; + double *radius = atom->radius; + int *type = atom->type; + int *mask = atom->mask; + tagint *molecule = atom->molecule; + int nlocal = atom->nlocal; + if (includegroup) nlocal = atom->nfirst; + + int history = list->history; + int *ilist = list->ilist; + int *numneigh = list->numneigh; + int **firstneigh = list->firstneigh; + MyPage *ipage = list->ipage; + + int mask_history = 3 << SBBITS; + + int inum = 0; + ipage->reset(); + + for (i = 0; i < nlocal; i++) { + n = 0; + neighptr = ipage->vget(); + + itype = type[i]; + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + radi = radius[i]; + + + // loop over all atoms in bins, including self, in stencil + // skip if i,j neighbor cutoff is less than bin distance + // bins below self are excluded from stencil + // pairs for atoms j "below" i are excluded + // below = lower z or (equal z and lower y) or (equal zy and lower x) + // (equal zyx and j <= i) + // latter excludes self-self interaction but allows superposed atoms + + ibin = atom2bin[i]; + s = stencil_multi[itype]; + distsq = distsq_multi[itype]; + cutsq = cutneighsq[itype]; + ns = nstencil_multi[itype]; + for (k = 0; k < ns; k++) { + for (j = binhead[ibin+s[k]]; j >= 0; j = bins[j]) { + jtype = type[j]; + if (cutsq[jtype] < distsq[k]) continue; + if (x[j][2] < ztmp) continue; + if (x[j][2] == ztmp) { + if (x[j][1] < ytmp) continue; + if (x[j][1] == ytmp) { + if (x[j][0] < xtmp) continue; + if (x[j][0] == xtmp && j <= i) continue; + } + } + + if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue; + + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + radsum = radi + radius[j]; + cutdistsq = (radsum+skin) * (radsum+skin); + + if (rsq <= cutdistsq) { + if (history && rsq < radsum*radsum) + neighptr[n++] = j ^ mask_history; + else + neighptr[n++] = j; + } + } + } + + ilist[inum++] = i; + firstneigh[i] = neighptr; + numneigh[i] = n; + ipage->vgot(n); + if (ipage->status()) + error->one(FLERR,"Neighbor list overflow, boost neigh_modify one"); + } + + list->inum = inum; +} diff --git a/src/npair_half_size_multi_newton_tri.h b/src/npair_half_size_multi_newton_tri.h new file mode 100644 index 0000000000..6afe8201a7 --- /dev/null +++ b/src/npair_half_size_multi_newton_tri.h @@ -0,0 +1,46 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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 NPAIR_CLASS + +NPairStyle(half/size/multi/newton/tri, + NPairHalfSizeMultiNewtonTri, + NP_HALF | NP_SIZE | NP_MULTI | NP_NEWTON | NP_TRI) + +#else + +#ifndef LMP_NPAIR_HALF_SIZE_MULTI_NEWTON_TRI_H +#define LMP_NPAIR_HALF_SIZE_MULTI_NEWTON_TRI_H + +#include "npair.h" + +namespace LAMMPS_NS { + +class NPairHalfSizeMultiNewtonTri : public NPair { + public: + NPairHalfSizeMultiNewtonTri(class LAMMPS *); + ~NPairHalfSizeMultiNewtonTri() {} + void build(class NeighList *); +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +E: Neighbor list overflow, boost neigh_modify one + +UNDOCUMENTED +*/ diff --git a/src/pair_coul_streitz.h b/src/pair_coul_streitz.h index d5a4a2de5c..2f62846212 100644 --- a/src/pair_coul_streitz.h +++ b/src/pair_coul_streitz.h @@ -36,7 +36,7 @@ class PairCoulStreitz : public Pair { double memory_usage(); virtual void *extract(const char *, int &); - static const int NPARAMS_PER_LINE = 6; + static constexpr int NPARAMS_PER_LINE = 6; protected: struct Param { diff --git a/src/pair_lj_cubic.cpp b/src/pair_lj_cubic.cpp index 7fe4757358..c5f1f5b257 100644 --- a/src/pair_lj_cubic.cpp +++ b/src/pair_lj_cubic.cpp @@ -26,6 +26,7 @@ #include "memory.h" #include "error.h" +#include "pair_lj_cubic_const.h" using namespace LAMMPS_NS; using namespace PairLJCubicConstants; diff --git a/src/pair_lj_cubic.h b/src/pair_lj_cubic.h index d0af06c0a0..4b5edf7e97 100644 --- a/src/pair_lj_cubic.h +++ b/src/pair_lj_cubic.h @@ -46,20 +46,6 @@ class PairLJCubic : public Pair { void allocate(); }; - -namespace PairLJCubicConstants { - - // LJ quantities scaled by epsilon and rmin = sigma*2^1/6 - - static const double RT6TWO = 1.1224621; // 2^1/6 - static const double SS = 1.1086834; // inflection point (13/7)^1/6 - static const double PHIS = -0.7869823; // energy at s - static const double DPHIDS = 2.6899009; // gradient at s - static const double A3 = 27.93357; // cubic coefficient - static const double SM = 1.5475375; // cubic cutoff = s*67/48 - -} - } #endif diff --git a/src/pair_lj_cubic_const.h b/src/pair_lj_cubic_const.h new file mode 100644 index 0000000000..5fc773ac3c --- /dev/null +++ b/src/pair_lj_cubic_const.h @@ -0,0 +1,48 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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. +------------------------------------------------------------------------- */ + +#ifndef LMP_PAIR_LJ_CUBIC_CONST_H +#define LMP_PAIR_LJ_CUBIC_CONST_H + +namespace LAMMPS_NS { +namespace PairLJCubicConstants { + + // LJ quantities scaled by epsilon and rmin = sigma*2^1/6 + + static constexpr double RT6TWO = 1.1224620483093730; // 2^1/6 + static constexpr double SS = 1.1086834179687215; // inflection point (13/7)^1/6 + static constexpr double PHIS = -0.7869822485207097; // energy at s + static constexpr double DPHIDS = 2.6899008972047196; // gradient at s + static constexpr double A3 = 27.9335700460986445; // cubic coefficient + static constexpr double SM = 1.5475372709146737; // cubic cutoff = s*67/48} +} +} +#endif + +// python script to compute the constants +// +// sixth = 1.0/6.0 +// rmin = pow(2.0,sixth) +// rs = pow(26.0/7.0,sixth) +// ss = rs/rmin +// pow6 = pow(1.0/rs,6.0) +// phis = 4.0*pow6*(pow6-1.0) +// dpds = -24.0*pow6*(2.0*pow6-1.0)/rs*rmin +// a3 = 8.0*pow(dpds,3)/(9.0*phis*phis) +// sm = 67.0/48.0*ss +// print("static constexpr double RT6TWO = %19.16f; // 2^1/6" % rmin) +// print("static constexpr double SS = %19.16f; // inflection point (13/7)^1/6" % ss) +// print("static constexpr double PHIS = %19.16f; // energy at s" % phis) +// print("static constexpr double DPHIDS = %19.16f; // gradient at s" % dpds) +// print("static constexpr double A3 = %19.16f; // cubic coefficient" % a3) +// print("static constexpr double SM = %19.16f; // cubic cutoff = s*67/48" % sm) diff --git a/src/pair_zbl.cpp b/src/pair_zbl.cpp index 6dff702d2c..80b623ff35 100644 --- a/src/pair_zbl.cpp +++ b/src/pair_zbl.cpp @@ -16,15 +16,18 @@ ------------------------------------------------------------------------- */ #include "pair_zbl.h" + #include + #include "atom.h" #include "comm.h" +#include "error.h" #include "force.h" +#include "memory.h" #include "neighbor.h" #include "neigh_list.h" -#include "memory.h" -#include "error.h" +#include "pair_zbl_const.h" // From J.F. Zeigler, J. P. Biersack and U. Littmark, // "The Stopping and Range of Ions in Matter" volume 1, Pergamon, 1985. diff --git a/src/pair_zbl.h b/src/pair_zbl.h index 55a5dc5fa4..6a16bc7419 100644 --- a/src/pair_zbl.h +++ b/src/pair_zbl.h @@ -54,23 +54,6 @@ class PairZBL : public Pair { double d2zbldr2(double, int, int); void set_coeff(int, int, double, double); }; - -namespace PairZBLConstants { - - // ZBL constants - - static const double pzbl = 0.23; - static const double a0 = 0.46850; - static const double c1 = 0.02817; - static const double c2 = 0.28022; - static const double c3 = 0.50986; - static const double c4 = 0.18175; - static const double d1 = 0.20162; - static const double d2 = 0.40290; - static const double d3 = 0.94229; - static const double d4 = 3.19980; -} - } #endif diff --git a/src/pair_zbl_const.h b/src/pair_zbl_const.h new file mode 100644 index 0000000000..385657693f --- /dev/null +++ b/src/pair_zbl_const.h @@ -0,0 +1,34 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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. +------------------------------------------------------------------------- */ + +#ifndef LMP_PAIR_ZBL_CONST_H +#define LMP_PAIR_ZBL_CONST_H + +namespace LAMMPS_NS { +namespace PairZBLConstants { + + // ZBL constants + + static constexpr double pzbl = 0.23; + static constexpr double a0 = 0.46850; + static constexpr double c1 = 0.02817; + static constexpr double c2 = 0.28022; + static constexpr double c3 = 0.50986; + static constexpr double c4 = 0.18175; + static constexpr double d1 = 0.20162; + static constexpr double d2 = 0.40290; + static constexpr double d3 = 0.94229; + static constexpr double d4 = 3.19980; +} +} +#endif diff --git a/src/text_file_reader.h b/src/text_file_reader.h index 0b90304911..0da21e4581 100644 --- a/src/text_file_reader.h +++ b/src/text_file_reader.h @@ -27,7 +27,7 @@ namespace LAMMPS_NS class TextFileReader { std::string filename; std::string filetype; - static const int MAXLINE = 1024; + static constexpr int MAXLINE = 1024; char line[MAXLINE]; FILE *fp; diff --git a/src/universe.cpp b/src/universe.cpp index 3f58c4a074..a7fa8fc2e2 100644 --- a/src/universe.cpp +++ b/src/universe.cpp @@ -185,7 +185,7 @@ void Universe::add_world(char *str) nper = atoi(part.c_str()); } else { n = atoi(part.substr(0,found).c_str()); - nper = atoi(part.substr(found-1).c_str());\ + nper = atoi(part.substr(found+1).c_str()); } } diff --git a/src/version.h b/src/version.h index 379d627653..f812b62821 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define LAMMPS_VERSION "30 Nov 2020" +#define LAMMPS_VERSION "24 Dec 2020" diff --git a/unittest/c-library/test_library_mpi.cpp b/unittest/c-library/test_library_mpi.cpp index cf33ed13b5..7502da767a 100644 --- a/unittest/c-library/test_library_mpi.cpp +++ b/unittest/c-library/test_library_mpi.cpp @@ -173,7 +173,7 @@ TEST(MPI, multi_partition) MPI_Comm_size(MPI_COMM_WORLD, &nprocs); MPI_Comm_rank(MPI_COMM_WORLD, &me); - const char *args[] = {"LAMMPS_test", "-log", "none", "-partition", "2x2", + const char *args[] = {"LAMMPS_test", "-log", "none", "-partition", "4x1", "-echo", "screen", "-nocite", "-in", "none"}; char **argv = (char **)args; int argc = sizeof(args) / sizeof(char *); @@ -183,19 +183,15 @@ TEST(MPI, multi_partition) lammps_command(lmp, "atom_style atomic"); lammps_command(lmp, "region box block 0 2 0 2 0 2"); lammps_command(lmp, "create_box 1 box"); - lammps_command(lmp, "variable partition universe 1 2"); + lammps_command(lmp, "variable partition universe 1 2 3 4"); EXPECT_EQ(lammps_extract_setting(lmp, "universe_size"), nprocs); EXPECT_EQ(lammps_extract_setting(lmp, "universe_rank"), me); - EXPECT_EQ(lammps_extract_setting(lmp, "world_size"), nprocs / 2); - EXPECT_EQ(lammps_extract_setting(lmp, "world_rank"), me % 2); + EXPECT_EQ(lammps_extract_setting(lmp, "world_size"), 1); + EXPECT_EQ(lammps_extract_setting(lmp, "world_rank"), 0); char *part_id = (char *)lammps_extract_variable(lmp, "partition", nullptr); - if (me < 2) { - ASSERT_THAT(part_id, StrEq("1")); - } else { - ASSERT_THAT(part_id, StrEq("2")); - } + ASSERT_THAT(part_id, StrEq(std::to_string(me+1))); lammps_close(lmp); }; diff --git a/unittest/commands/CMakeLists.txt b/unittest/commands/CMakeLists.txt index e9cdf78ab7..7a804820cb 100644 --- a/unittest/commands/CMakeLists.txt +++ b/unittest/commands/CMakeLists.txt @@ -8,6 +8,13 @@ target_link_libraries(test_lattice_region PRIVATE lammps GTest::GMock GTest::GTe add_test(NAME LatticeRegion COMMAND test_lattice_region WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_executable(test_kim_commands test_kim_commands.cpp) +if(KIM_EXTRA_UNITTESTS) + if(CURL_FOUND) + target_compile_definitions(test_kim_commands PRIVATE -DKIM_EXTRA_UNITTESTS) + else() + message(FATAL_ERROR "CURL not found. Enabling KIM extra unit tests requires to have libcurl installed.") + endif() +endif() target_link_libraries(test_kim_commands PRIVATE lammps GTest::GMock GTest::GTest) add_test(NAME KimCommands COMMAND test_kim_commands WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/unittest/commands/test_kim_commands.cpp b/unittest/commands/test_kim_commands.cpp index 42e8a441bd..4e16e28783 100644 --- a/unittest/commands/test_kim_commands.cpp +++ b/unittest/commands/test_kim_commands.cpp @@ -326,7 +326,8 @@ TEST_F(KimCommandsTest, kim_property) "3 >= 3.6 support.*", lmp->input->one("kim_property");); } else { - TEST_FAILURE(".*ERROR: Invalid kim_property command.*", lmp->input->one("kim_property");); + TEST_FAILURE(".*ERROR: Invalid kim_property command.*", + lmp->input->one("kim_property");); TEST_FAILURE(".*ERROR: Invalid kim_property command.*", lmp->input->one("kim_property create");); TEST_FAILURE(".*ERROR: Incorrect arguments in kim_property command.\n" @@ -334,6 +335,29 @@ TEST_F(KimCommandsTest, kim_property) "is mandatory.*", lmp->input->one("kim_property unknown 1 atomic-mass");); } +#if defined(KIM_EXTRA_UNITTESTS) + TEST_FAILURE(".*ERROR: Invalid 'kim_property create' command.*", + lmp->input->one("kim_property create 1");); + TEST_FAILURE(".*ERROR: Invalid 'kim_property destroy' command.*", + lmp->input->one("kim_property destroy 1 cohesive-potential-energy-cubic-crystal");); + TEST_FAILURE(".*ERROR: Invalid 'kim_property modify' command.*", + lmp->input->one("kim_property modify 1 key short-name");); + TEST_FAILURE(".*ERROR: There is no property instance to modify the content.*", + lmp->input->one("kim_property modify 1 key short-name source-value 1 fcc");); + TEST_FAILURE(".*ERROR: Invalid 'kim_property remove' command.*", + lmp->input->one("kim_property remove 1 key");); + TEST_FAILURE(".*ERROR: There is no property instance to remove the content.*", + lmp->input->one("kim_property remove 1 key short-name");); + TEST_FAILURE(".*ERROR: There is no property instance to dump the content.*", + lmp->input->one("kim_property dump results.edn");); + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("kim_init LennardJones612_UniversalShifted__MO_959249795837_003 real"); + lmp->input->one("kim_property create 1 cohesive-potential-energy-cubic-crystal"); + lmp->input->one("kim_property modify 1 key short-name source-value 1 fcc"); + lmp->input->one("kim_property destroy 1"); + if (!verbose) ::testing::internal::GetCapturedStdout(); +#endif } TEST_F(KimCommandsTest, kim_query) @@ -420,48 +444,50 @@ TEST_F(KimCommandsTest, kim_query) "units=[\"angstrom\"]"; TEST_FAILURE(".*ERROR: OpenKIM query failed:.*", lmp->input->one(squery);); - // if (!verbose) ::testing::internal::CaptureStdout(); - // lmp->input->one("clear"); - // lmp->input->one("kim_init EAM_Dynamo_Mendelev_2007_Zr__MO_848899341753_000 metal"); +#if defined(KIM_EXTRA_UNITTESTS) + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("kim_init EAM_Dynamo_Mendelev_2007_Zr__MO_848899341753_000 metal"); - // squery = "kim_query latconst split get_lattice_constant_hexagonal "; - // squery += "crystal=[\"hcp\"] species=[\"Zr\"] units=[\"angstrom\"]"; - // lmp->input->one(squery); - // if (!verbose) ::testing::internal::GetCapturedStdout(); + squery = "kim_query latconst split get_lattice_constant_hexagonal "; + squery += "crystal=[\"hcp\"] species=[\"Zr\"] units=[\"angstrom\"]"; + lmp->input->one(squery); + if (!verbose) ::testing::internal::GetCapturedStdout(); - // ASSERT_TRUE((std::string(lmp->input->variable->retrieve("latconst_1")) == - // std::string("3.234055244384789"))); - // ASSERT_TRUE((std::string(lmp->input->variable->retrieve("latconst_2")) == - // std::string("5.167650199630013"))); + ASSERT_TRUE((std::string(lmp->input->variable->retrieve("latconst_1")) == + std::string("3.234055244384789"))); + ASSERT_TRUE((std::string(lmp->input->variable->retrieve("latconst_2")) == + std::string("5.167650199630013"))); - // if (!verbose) ::testing::internal::CaptureStdout(); - // lmp->input->one("clear"); - // lmp->input->one("kim_init EAM_Dynamo_Mendelev_2007_Zr__MO_848899341753_000 metal"); + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("kim_init EAM_Dynamo_Mendelev_2007_Zr__MO_848899341753_000 metal"); - // squery = "kim_query latconst list get_lattice_constant_hexagonal "; - // squery += "crystal=[hcp] species=[Zr] units=[angstrom]"; - // lmp->input->one(squery); - // if (!verbose) ::testing::internal::GetCapturedStdout(); + squery = "kim_query latconst list get_lattice_constant_hexagonal "; + squery += "crystal=[hcp] species=[Zr] units=[angstrom]"; + lmp->input->one(squery); + if (!verbose) ::testing::internal::GetCapturedStdout(); - // ASSERT_TRUE((std::string(lmp->input->variable->retrieve("latconst")) == - // std::string("3.234055244384789 5.167650199630013"))); + ASSERT_TRUE((std::string(lmp->input->variable->retrieve("latconst")) == + std::string("3.234055244384789 5.167650199630013"))); - // squery = "kim_query latconst list get_lattice_constant_hexagonal "; - // squery += "crystal=[bcc] species=[Zr] units=[angstrom]"; - // TEST_FAILURE(".*ERROR: OpenKIM query failed:.*", lmp->input->one(squery);); + squery = "kim_query latconst list get_lattice_constant_hexagonal "; + squery += "crystal=[bcc] species=[Zr] units=[angstrom]"; + TEST_FAILURE(".*ERROR: OpenKIM query failed:.*", lmp->input->one(squery);); - // if (!verbose) ::testing::internal::CaptureStdout(); - // lmp->input->one("clear"); - // lmp->input->one("kim_init EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005 metal"); + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("kim_init EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005 metal"); - // squery = "kim_query alpha get_linear_thermal_expansion_coefficient_cubic "; - // squery += "crystal=[fcc] species=[Al] units=[1/K] temperature=[293.15] "; - // squery += "temperature_units=[K]"; - // lmp->input->one(squery); - // if (!verbose) ::testing::internal::GetCapturedStdout(); + squery = "kim_query alpha get_linear_thermal_expansion_coefficient_cubic "; + squery += "crystal=[fcc] species=[Al] units=[1/K] temperature=[293.15] "; + squery += "temperature_units=[K]"; + lmp->input->one(squery); + if (!verbose) ::testing::internal::GetCapturedStdout(); - // ASSERT_TRUE((std::string(lmp->input->variable->retrieve("alpha")) == - // std::string("1.654960564704273e-05"))); + ASSERT_TRUE((std::string(lmp->input->variable->retrieve("alpha")) == + std::string("1.654960564704273e-05"))); +#endif } } // namespace LAMMPS_NS diff --git a/unittest/force-styles/tests/angle-harmonic.yaml b/unittest/force-styles/tests/angle-harmonic.yaml index a419c131f1..6d9cf67210 100644 --- a/unittest/force-styles/tests/angle-harmonic.yaml +++ b/unittest/force-styles/tests/angle-harmonic.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:34 202 -epsilon: 2.5e-13 +epsilon: 5e-13 prerequisites: ! | atom full angle harmonic diff --git a/unittest/force-styles/tests/angle-table_linear.yaml b/unittest/force-styles/tests/angle-table_linear.yaml index 2c5410f646..7dc66d9edf 100644 --- a/unittest/force-styles/tests/angle-table_linear.yaml +++ b/unittest/force-styles/tests/angle-table_linear.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:35 202 -epsilon: 2.5e-13 +epsilon: 5e-13 prerequisites: ! | atom full angle table diff --git a/unittest/force-styles/tests/angle-table_spline.yaml b/unittest/force-styles/tests/angle-table_spline.yaml index 42d8f58900..10edec26fd 100644 --- a/unittest/force-styles/tests/angle-table_spline.yaml +++ b/unittest/force-styles/tests/angle-table_spline.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:35 202 -epsilon: 2.5e-13 +epsilon: 5e-13 prerequisites: ! | atom full angle table diff --git a/unittest/force-styles/tests/atomic-pair-hybrid-eam.yaml b/unittest/force-styles/tests/atomic-pair-hybrid-eam.yaml index 6647cc39a5..b3569a7e74 100644 --- a/unittest/force-styles/tests/atomic-pair-hybrid-eam.yaml +++ b/unittest/force-styles/tests/atomic-pair-hybrid-eam.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:23 202 -epsilon: 5e-12 +epsilon: 1e-11 prerequisites: ! | pair eam/fs pre_commands: ! "" diff --git a/unittest/force-styles/tests/fix-timestep-addforce_const.yaml b/unittest/force-styles/tests/fix-timestep-addforce_const.yaml index 13f4644815..39bbfcf280 100644 --- a/unittest/force-styles/tests/fix-timestep-addforce_const.yaml +++ b/unittest/force-styles/tests/fix-timestep-addforce_const.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:39 202 -epsilon: 5e-12 +epsilon: 9e-12 prerequisites: ! | atom full fix addforce diff --git a/unittest/force-styles/tests/fix-timestep-addforce_variable.yaml b/unittest/force-styles/tests/fix-timestep-addforce_variable.yaml index 112b6d89c1..421051601a 100644 --- a/unittest/force-styles/tests/fix-timestep-addforce_variable.yaml +++ b/unittest/force-styles/tests/fix-timestep-addforce_variable.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:39 202 -epsilon: 5e-12 +epsilon: 2e-11 prerequisites: ! | atom full fix addforce diff --git a/unittest/force-styles/tests/fix-timestep-aveforce_const.yaml b/unittest/force-styles/tests/fix-timestep-aveforce_const.yaml index bb8ec69e3e..18dd4cf4b2 100644 --- a/unittest/force-styles/tests/fix-timestep-aveforce_const.yaml +++ b/unittest/force-styles/tests/fix-timestep-aveforce_const.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:40 202 -epsilon: 5e-12 +epsilon: 2e-11 prerequisites: ! | atom full fix aveforce diff --git a/unittest/force-styles/tests/fix-timestep-aveforce_variable.yaml b/unittest/force-styles/tests/fix-timestep-aveforce_variable.yaml index 3f7832acfe..41299b2ec8 100644 --- a/unittest/force-styles/tests/fix-timestep-aveforce_variable.yaml +++ b/unittest/force-styles/tests/fix-timestep-aveforce_variable.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:40 202 -epsilon: 2e-11 +epsilon: 2.5e-11 prerequisites: ! | atom full fix aveforce diff --git a/unittest/force-styles/tests/fix-timestep-drag.yaml b/unittest/force-styles/tests/fix-timestep-drag.yaml index 9b5791f55b..bb4908f55e 100644 --- a/unittest/force-styles/tests/fix-timestep-drag.yaml +++ b/unittest/force-styles/tests/fix-timestep-drag.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:40 202 -epsilon: 1e-14 +epsilon: 5e-14 prerequisites: ! | atom full fix drag diff --git a/unittest/force-styles/tests/fix-timestep-heat.yaml b/unittest/force-styles/tests/fix-timestep-heat.yaml index bfd51fb2a9..a7197528f5 100644 --- a/unittest/force-styles/tests/fix-timestep-heat.yaml +++ b/unittest/force-styles/tests/fix-timestep-heat.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:40 202 -epsilon: 1e-14 +epsilon: 2e-14 prerequisites: ! | atom full fix heat diff --git a/unittest/force-styles/tests/fix-timestep-momentum.yaml b/unittest/force-styles/tests/fix-timestep-momentum.yaml index eb5f4e0235..884c71785d 100644 --- a/unittest/force-styles/tests/fix-timestep-momentum.yaml +++ b/unittest/force-styles/tests/fix-timestep-momentum.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:40 202 -epsilon: 2e-14 +epsilon: 4e-14 prerequisites: ! | atom full fix momentum diff --git a/unittest/force-styles/tests/fix-timestep-npt_aniso.yaml b/unittest/force-styles/tests/fix-timestep-npt_aniso.yaml index 3f71f8d87b..b086a1b95e 100644 --- a/unittest/force-styles/tests/fix-timestep-npt_aniso.yaml +++ b/unittest/force-styles/tests/fix-timestep-npt_aniso.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:40 202 -epsilon: 2e-12 +epsilon: 4e-11 prerequisites: ! | atom full fix npt diff --git a/unittest/force-styles/tests/fix-timestep-npt_iso.yaml b/unittest/force-styles/tests/fix-timestep-npt_iso.yaml index 365b01c29e..8dec2a1bec 100644 --- a/unittest/force-styles/tests/fix-timestep-npt_iso.yaml +++ b/unittest/force-styles/tests/fix-timestep-npt_iso.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:40 202 -epsilon: 5e-13 +epsilon: 2e-12 prerequisites: ! | atom full fix npt diff --git a/unittest/force-styles/tests/fix-timestep-nve.yaml b/unittest/force-styles/tests/fix-timestep-nve.yaml index 8626163bd3..5d2efa1373 100644 --- a/unittest/force-styles/tests/fix-timestep-nve.yaml +++ b/unittest/force-styles/tests/fix-timestep-nve.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:40 202 -epsilon: 1e-14 +epsilon: 2e-14 prerequisites: ! | atom full fix nve diff --git a/unittest/force-styles/tests/fix-timestep-nve_limit.yaml b/unittest/force-styles/tests/fix-timestep-nve_limit.yaml index 56f9873ddd..bc6a16704f 100644 --- a/unittest/force-styles/tests/fix-timestep-nve_limit.yaml +++ b/unittest/force-styles/tests/fix-timestep-nve_limit.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:41 202 -epsilon: 1e-14 +epsilon: 2e-14 prerequisites: ! | atom full fix nve/limit diff --git a/unittest/force-styles/tests/fix-timestep-nve_noforce.yaml b/unittest/force-styles/tests/fix-timestep-nve_noforce.yaml index 7bb02e7873..17e9923d45 100644 --- a/unittest/force-styles/tests/fix-timestep-nve_noforce.yaml +++ b/unittest/force-styles/tests/fix-timestep-nve_noforce.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:41 202 -epsilon: 1e-14 +epsilon: 2e-14 prerequisites: ! | atom full fix nve/noforce diff --git a/unittest/force-styles/tests/fix-timestep-nvt.yaml b/unittest/force-styles/tests/fix-timestep-nvt.yaml index 58eeee64d0..6a4ead99c1 100644 --- a/unittest/force-styles/tests/fix-timestep-nvt.yaml +++ b/unittest/force-styles/tests/fix-timestep-nvt.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:41 202 -epsilon: 5e-14 +epsilon: 2e-13 prerequisites: ! | atom full fix nvt diff --git a/unittest/force-styles/tests/fix-timestep-oneway.yaml b/unittest/force-styles/tests/fix-timestep-oneway.yaml index 4fcef41f5b..01131a3803 100644 --- a/unittest/force-styles/tests/fix-timestep-oneway.yaml +++ b/unittest/force-styles/tests/fix-timestep-oneway.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:41 202 -epsilon: 2e-14 +epsilon: 4e-14 prerequisites: ! | atom full fix oneway diff --git a/unittest/force-styles/tests/fix-timestep-press_berendsen_iso.yaml b/unittest/force-styles/tests/fix-timestep-press_berendsen_iso.yaml index 975d31692e..5bbf178dc3 100644 --- a/unittest/force-styles/tests/fix-timestep-press_berendsen_iso.yaml +++ b/unittest/force-styles/tests/fix-timestep-press_berendsen_iso.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:41 202 -epsilon: 2e-13 +epsilon: 2e-12 prerequisites: ! | atom full fix press/berendsen diff --git a/unittest/force-styles/tests/fix-timestep-rattle_bond.yaml b/unittest/force-styles/tests/fix-timestep-rattle_bond.yaml index 8f771d84b3..cad83187c6 100644 --- a/unittest/force-styles/tests/fix-timestep-rattle_bond.yaml +++ b/unittest/force-styles/tests/fix-timestep-rattle_bond.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:41 202 -epsilon: 9e-12 +epsilon: 1e-10 prerequisites: ! | atom full fix rattle diff --git a/unittest/force-styles/tests/fix-timestep-rigid_nph_small.yaml b/unittest/force-styles/tests/fix-timestep-rigid_nph_small.yaml index 5019d8fbe5..11d6870a42 100644 --- a/unittest/force-styles/tests/fix-timestep-rigid_nph_small.yaml +++ b/unittest/force-styles/tests/fix-timestep-rigid_nph_small.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 22:36:55 202 -epsilon: 5e-13 +epsilon: 6.5e-13 prerequisites: ! | atom full fix rigid/nph/small diff --git a/unittest/force-styles/tests/fix-timestep-setforce_const.yaml b/unittest/force-styles/tests/fix-timestep-setforce_const.yaml index b932718f71..4ff222aff6 100644 --- a/unittest/force-styles/tests/fix-timestep-setforce_const.yaml +++ b/unittest/force-styles/tests/fix-timestep-setforce_const.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:42 202 -epsilon: 5e-12 +epsilon: 2e-11 prerequisites: ! | atom full fix setforce diff --git a/unittest/force-styles/tests/fix-timestep-setforce_variable.yaml b/unittest/force-styles/tests/fix-timestep-setforce_variable.yaml index 5c01ca714f..960368a081 100644 --- a/unittest/force-styles/tests/fix-timestep-setforce_variable.yaml +++ b/unittest/force-styles/tests/fix-timestep-setforce_variable.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:42 202 -epsilon: 5e-12 +epsilon: 1e-11 prerequisites: ! | atom full fix setforce diff --git a/unittest/force-styles/tests/fix-timestep-shake_angle.yaml b/unittest/force-styles/tests/fix-timestep-shake_angle.yaml index e2cc5cb36f..1cc3dfe429 100644 --- a/unittest/force-styles/tests/fix-timestep-shake_angle.yaml +++ b/unittest/force-styles/tests/fix-timestep-shake_angle.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:42 202 -epsilon: 2e-12 +epsilon: 3e-10 prerequisites: ! | atom full fix shake diff --git a/unittest/force-styles/tests/fix-timestep-shake_bond.yaml b/unittest/force-styles/tests/fix-timestep-shake_bond.yaml index 70e70215cc..afbba6c6d7 100644 --- a/unittest/force-styles/tests/fix-timestep-shake_bond.yaml +++ b/unittest/force-styles/tests/fix-timestep-shake_bond.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:42 202 -epsilon: 2e-12 +epsilon: 3.5e-11 prerequisites: ! | atom full fix shake diff --git a/unittest/force-styles/tests/fix-timestep-spring_chunk.yaml b/unittest/force-styles/tests/fix-timestep-spring_chunk.yaml index c151352548..66a9ff9449 100644 --- a/unittest/force-styles/tests/fix-timestep-spring_chunk.yaml +++ b/unittest/force-styles/tests/fix-timestep-spring_chunk.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:42 202 -epsilon: 2e-14 +epsilon: 1e-11 prerequisites: ! | atom full fix spring/chunk diff --git a/unittest/force-styles/tests/fix-timestep-spring_self.yaml b/unittest/force-styles/tests/fix-timestep-spring_self.yaml index 0e8e85516b..96755572bf 100644 --- a/unittest/force-styles/tests/fix-timestep-spring_self.yaml +++ b/unittest/force-styles/tests/fix-timestep-spring_self.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:43 202 -epsilon: 2e-14 +epsilon: 5e-14 prerequisites: ! | atom full fix spring/self diff --git a/unittest/force-styles/tests/fix-timestep-temp_berendsen.yaml b/unittest/force-styles/tests/fix-timestep-temp_berendsen.yaml index 8b05abe90f..7975b61a13 100644 --- a/unittest/force-styles/tests/fix-timestep-temp_berendsen.yaml +++ b/unittest/force-styles/tests/fix-timestep-temp_berendsen.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:43 202 -epsilon: 1e-14 +epsilon: 2e-14 prerequisites: ! | atom full fix temp/berendsen diff --git a/unittest/force-styles/tests/fix-timestep-temp_csld.yaml b/unittest/force-styles/tests/fix-timestep-temp_csld.yaml index 63940d626c..ef6535888d 100644 --- a/unittest/force-styles/tests/fix-timestep-temp_csld.yaml +++ b/unittest/force-styles/tests/fix-timestep-temp_csld.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:43 202 -epsilon: 1e-14 +epsilon: 2e-14 prerequisites: ! | atom full fix temp/csld diff --git a/unittest/force-styles/tests/fix-timestep-temp_csvr.yaml b/unittest/force-styles/tests/fix-timestep-temp_csvr.yaml index 02592f100c..d4f77f596c 100644 --- a/unittest/force-styles/tests/fix-timestep-temp_csvr.yaml +++ b/unittest/force-styles/tests/fix-timestep-temp_csvr.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:43 202 -epsilon: 1e-14 +epsilon: 2e-14 prerequisites: ! | atom full fix temp/csvr diff --git a/unittest/force-styles/tests/fix-timestep-wall_harmonic_const.yaml b/unittest/force-styles/tests/fix-timestep-wall_harmonic_const.yaml index 2cb8904632..e1de14d018 100644 --- a/unittest/force-styles/tests/fix-timestep-wall_harmonic_const.yaml +++ b/unittest/force-styles/tests/fix-timestep-wall_harmonic_const.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:43 202 -epsilon: 2e-14 +epsilon: 3e-14 prerequisites: ! | atom full fix wall/harmonic diff --git a/unittest/force-styles/tests/fix-timestep-wall_lj1043_const.yaml b/unittest/force-styles/tests/fix-timestep-wall_lj1043_const.yaml index db63a76786..e8be8b41a2 100644 --- a/unittest/force-styles/tests/fix-timestep-wall_lj1043_const.yaml +++ b/unittest/force-styles/tests/fix-timestep-wall_lj1043_const.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:43 202 -epsilon: 1e-14 +epsilon: 5e-14 prerequisites: ! | atom full fix wall/lj1043 diff --git a/unittest/force-styles/tests/fix-timestep-wall_lj126_const.yaml b/unittest/force-styles/tests/fix-timestep-wall_lj126_const.yaml index 71b1498ac5..e65b582c09 100644 --- a/unittest/force-styles/tests/fix-timestep-wall_lj126_const.yaml +++ b/unittest/force-styles/tests/fix-timestep-wall_lj126_const.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:43 202 -epsilon: 1e-14 +epsilon: 2e-14 prerequisites: ! | atom full fix wall/lj126 diff --git a/unittest/force-styles/tests/fix-timestep-wall_lj93_const.yaml b/unittest/force-styles/tests/fix-timestep-wall_lj93_const.yaml index 7fa620fae3..d1c27927a2 100644 --- a/unittest/force-styles/tests/fix-timestep-wall_lj93_const.yaml +++ b/unittest/force-styles/tests/fix-timestep-wall_lj93_const.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:43 202 -epsilon: 1e-14 +epsilon: 2e-14 prerequisites: ! | atom full fix wall/lj93 diff --git a/unittest/force-styles/tests/fix-timestep-wall_morse_const.yaml b/unittest/force-styles/tests/fix-timestep-wall_morse_const.yaml index 65f82f8a80..2b935dbf14 100644 --- a/unittest/force-styles/tests/fix-timestep-wall_morse_const.yaml +++ b/unittest/force-styles/tests/fix-timestep-wall_morse_const.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:43 202 -epsilon: 1e-14 +epsilon: 4e-14 prerequisites: ! | atom full fix wall/morse diff --git a/unittest/force-styles/tests/kspace-pppm_tip4p_ad.yaml b/unittest/force-styles/tests/kspace-pppm_tip4p_ad.yaml index 7aebfdd2fb..e2a644a7b2 100644 --- a/unittest/force-styles/tests/kspace-pppm_tip4p_ad.yaml +++ b/unittest/force-styles/tests/kspace-pppm_tip4p_ad.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:39 202 -epsilon: 2e-13 +epsilon: 3e-13 prerequisites: ! | atom full pair tip4p/long diff --git a/unittest/force-styles/tests/kspace-pppm_tip4p_slab.yaml b/unittest/force-styles/tests/kspace-pppm_tip4p_slab.yaml index 69dcdfaf32..b64d7db0f6 100644 --- a/unittest/force-styles/tests/kspace-pppm_tip4p_slab.yaml +++ b/unittest/force-styles/tests/kspace-pppm_tip4p_slab.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:39 202 -epsilon: 2e-13 +epsilon: 5e-13 prerequisites: ! | atom full pair tip4p/long diff --git a/unittest/force-styles/tests/manybody-pair-polymorphic_sw.yaml b/unittest/force-styles/tests/manybody-pair-polymorphic_sw.yaml index 02200151c9..18a2e85c7c 100644 --- a/unittest/force-styles/tests/manybody-pair-polymorphic_sw.yaml +++ b/unittest/force-styles/tests/manybody-pair-polymorphic_sw.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:31 202 -epsilon: 1e-12 +epsilon: 4e-12 prerequisites: ! | pair polymorphic pre_commands: ! | diff --git a/unittest/force-styles/tests/mol-pair-buck.yaml b/unittest/force-styles/tests/mol-pair-buck.yaml index 16866bba3e..6600c63b4f 100644 --- a/unittest/force-styles/tests/mol-pair-buck.yaml +++ b/unittest/force-styles/tests/mol-pair-buck.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:11 202 -epsilon: 5e-14 +epsilon: 6e-14 prerequisites: ! | atom full pair buck diff --git a/unittest/force-styles/tests/mol-pair-buck_coul_long.yaml b/unittest/force-styles/tests/mol-pair-buck_coul_long.yaml index 75b2c40fbd..07606715b8 100644 --- a/unittest/force-styles/tests/mol-pair-buck_coul_long.yaml +++ b/unittest/force-styles/tests/mol-pair-buck_coul_long.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:11 202 -epsilon: 5e-14 +epsilon: 4e-13 prerequisites: ! | atom full pair buck/coul/long diff --git a/unittest/force-styles/tests/mol-pair-buck_coul_msm.yaml b/unittest/force-styles/tests/mol-pair-buck_coul_msm.yaml index 70a34e3726..ca38b6369d 100644 --- a/unittest/force-styles/tests/mol-pair-buck_coul_msm.yaml +++ b/unittest/force-styles/tests/mol-pair-buck_coul_msm.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:11 202 -epsilon: 5e-14 +epsilon: 2e-13 prerequisites: ! | atom full pair buck/coul/msm diff --git a/unittest/force-styles/tests/mol-pair-buck_coul_msm_table.yaml b/unittest/force-styles/tests/mol-pair-buck_coul_msm_table.yaml index b78affb564..24a23bb444 100644 --- a/unittest/force-styles/tests/mol-pair-buck_coul_msm_table.yaml +++ b/unittest/force-styles/tests/mol-pair-buck_coul_msm_table.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:11 202 -epsilon: 5e-14 +epsilon: 2e-13 prerequisites: ! | atom full pair buck/coul/msm diff --git a/unittest/force-styles/tests/mol-pair-lj_charmm_coul_charmm.yaml b/unittest/force-styles/tests/mol-pair-lj_charmm_coul_charmm.yaml index 6c91f1a9a1..d20b8e2e87 100644 --- a/unittest/force-styles/tests/mol-pair-lj_charmm_coul_charmm.yaml +++ b/unittest/force-styles/tests/mol-pair-lj_charmm_coul_charmm.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:14 202 -epsilon: 5e-14 +epsilon: 7e-14 prerequisites: ! | atom full pair lj/charmm/coul/charmm diff --git a/unittest/force-styles/tests/mol-pair-lj_cubic.yaml b/unittest/force-styles/tests/mol-pair-lj_cubic.yaml index ad7f0666ca..6d23998ad5 100644 --- a/unittest/force-styles/tests/mol-pair-lj_cubic.yaml +++ b/unittest/force-styles/tests/mol-pair-lj_cubic.yaml @@ -1,7 +1,7 @@ --- -lammps_version: 24 Aug 2020 -date_generated: Tue Sep 15 09:44:15 202 -epsilon: 2e-13 +lammps_version: 30 Nov 2020 +date_generated: Fri Dec 18 22:30:42 202 +epsilon: 1e-13 prerequisites: ! | atom full pair lj/cubic @@ -19,72 +19,72 @@ pair_coeff: ! | 5 5 0.015 3.1 extract: ! "" natoms: 29 -init_vdwl: 166.005266308562 +init_vdwl: 166.005266338502 init_coul: 0 init_stress: ! |2- - 4.5860676757908186e+02 4.8091912919212928e+02 1.0767204080701006e+03 -2.1005546139122362e+02 -2.9491286717936713e+00 1.6145675857120941e+02 + 4.5860676760613336e+02 4.8091912923656065e+02 1.0767204080957010e+03 -2.1005546139899724e+02 -2.9491286649299440e+00 1.6145675855773089e+02 init_forces: ! |2 - 1 9.1849370411551270e+00 7.6268937957720553e+01 6.1726872441625311e+01 - 2 2.2858712118514426e+01 1.8809274242266209e+01 -2.6905829837199740e+01 - 3 -3.2016987482543328e+01 -9.4135849525427091e+01 -3.4799279593035926e+01 - 4 -5.5341015869901478e-01 1.5206999898436971e-01 -3.9418368928369890e-01 - 5 -1.8042057425348118e-01 -3.0459951056385326e-01 8.7068483241007189e-01 - 6 -2.0038994438822397e+02 2.3344446299945159e+02 2.8487343926572851e+02 - 7 8.0909912172413883e+00 -7.8410849891085633e+01 -4.3214084684451740e+02 - 8 4.7943581255133857e+01 -2.1287511456246008e+01 1.4094503445180061e+02 - 9 1.1447552368270737e+01 1.2328709806786962e+01 5.0656476982000299e+01 - 10 1.3071496571967870e+02 -1.4589264560693914e+02 -4.4748155922123622e+01 - 11 -1.6551880116149281e-01 -4.1534332040572380e-01 -6.8284765241715795e-01 - 12 1.7721533626133388e+00 6.3456329073685158e-01 -8.2372301448028962e-01 - 13 5.6789360334118277e-01 -2.2634410312439054e-01 -9.7536738055328392e-03 - 14 -2.4337021468262635e-01 4.6659433642728905e-02 -6.1110664501270184e-01 - 15 -2.1936997101927893e-02 5.9238263972968364e-01 2.1493099548264527e-01 - 16 1.1121534968449923e+02 -7.8056927924992834e+01 -2.9249212971206231e+02 - 17 -1.1020604609843586e+02 7.6481296254913858e+01 2.9430701446263464e+02 - 18 -1.6570656719723909e-02 -2.7996966177077785e-02 2.6456326954440619e-02 - 19 7.4243353115058947e-04 6.3524893127716046e-04 1.8675586277048476e-04 - 20 -7.4243353115058947e-04 -6.3524893127716046e-04 -1.8675586277048476e-04 + 1 9.1849370400954342e+00 7.6268937960282486e+01 6.1726872440953251e+01 + 2 2.2858712118557477e+01 1.8809274242339992e+01 -2.6905829837209875e+01 + 3 -3.2016987482586380e+01 -9.4135849525500873e+01 -3.4799279593025787e+01 + 4 -5.5341015917141478e-01 1.5206999930354809e-01 -3.9418368927471259e-01 + 5 -1.8042057490785210e-01 -3.0459951013385317e-01 8.7068483295449139e-01 + 6 -2.0038994438983289e+02 2.3344446299845976e+02 2.8487343926562755e+02 + 7 8.0909912152126484e+00 -7.8410849888970290e+01 -4.3214084684693944e+02 + 8 4.7943581253518161e+01 -2.1287511458762772e+01 1.4094503445043824e+02 + 9 1.1447552368334570e+01 1.2328709806695397e+01 5.0656476981938759e+01 + 10 1.3071496571895125e+02 -1.4589264560750766e+02 -4.4748155921681018e+01 + 11 -1.6551880130741767e-01 -4.1534332035668403e-01 -6.8284765271893910e-01 + 12 1.7721533633976141e+00 6.3456328808910523e-01 -8.2372301296999062e-01 + 13 5.6789360517170440e-01 -2.2634410322310763e-01 -9.7536744156455080e-03 + 14 -2.4337021462140446e-01 4.6659433737428486e-02 -6.1110664517858926e-01 + 15 -2.1936996885396808e-02 5.9238264018028652e-01 2.1493099542010694e-01 + 16 1.1121534968641315e+02 -7.8056927926703892e+01 -2.9249212971001145e+02 + 17 -1.1020604609471918e+02 7.6481296251709367e+01 2.9430701446464468e+02 + 18 -1.6570656172995385e-02 -2.7996961634495443e-02 2.6456324093123054e-02 + 19 7.4243314752471426e-04 6.3524860303507949e-04 1.8675576627109685e-04 + 20 -7.4243314752471426e-04 -6.3524860303507949e-04 -1.8675576627109685e-04 21 -1.1415041486189516e+01 -1.3016363071591645e+01 3.6007276733401099e+01 - 22 -1.7227422089792942e+01 -4.1746638094950628e+00 -2.7029162034499002e+01 - 23 2.8642463575982458e+01 1.7191026881086707e+01 -8.9781146989020968e+00 - 24 5.8150644491939154e+00 -3.3774314134628064e+01 1.7867788752379695e+01 - 25 -2.3666545027773044e+01 3.8106021846559952e+00 -1.9896269873584632e+01 - 26 1.7843812244577855e+01 2.9960339884741117e+01 2.0167430316952100e+00 - 27 8.2825859209946024e+00 -3.6194570066818969e+01 1.4492694351988913e+01 - 28 -2.8773892796642542e+01 1.2366374307374247e+01 -1.9468877181285176e+01 - 29 2.0497044211022661e+01 2.3831279505404666e+01 4.9748677441078746e+00 -run_vdwl: 164.176727313193 + 22 -1.7227422090167991e+01 -4.1746638096674396e+00 -2.7029162034658786e+01 + 23 2.8642463576357507e+01 1.7191026881259084e+01 -8.9781146987423170e+00 + 24 5.8150644495067958e+00 -3.3774314132751599e+01 1.7867788754173183e+01 + 25 -2.3666545028156815e+01 3.8106021844353424e+00 -1.9896269873795571e+01 + 26 1.7843812244961626e+01 2.9960339884961773e+01 2.0167430319061479e+00 + 27 8.2825859198612442e+00 -3.6194570067428131e+01 1.4492694352248694e+01 + 28 -2.8773892797077618e+01 1.2366374307246014e+01 -1.9468877181493664e+01 + 29 2.0497044211457737e+01 2.3831279505532898e+01 4.9748677443163629e+00 +run_vdwl: 164.176727343123 run_coul: 0 run_stress: ! |2- - 4.5696669905868288e+02 4.7904134871830234e+02 1.0582153129928076e+03 -2.0794233475912671e+02 -2.0206236780739086e+00 1.5948889983617320e+02 + 4.5696669908578690e+02 4.7904134876274537e+02 1.0582153130184231e+03 -2.0794233476691440e+02 -2.0206236712071677e+00 1.5948889982266843e+02 run_forces: ! |2 - 1 9.2483453892728740e+00 7.5945844239974676e+01 6.1367289784738311e+01 - 2 2.2732852134554197e+01 1.8737493288759875e+01 -2.6669600068587577e+01 - 3 -3.1964986246503269e+01 -9.3734416340601200e+01 -3.4671255449722295e+01 - 4 -5.5001585694065913e-01 1.5070776418957152e-01 -3.9275226164990551e-01 - 5 -1.7969915375876547e-01 -3.0362292678324765e-01 8.6793365916706400e-01 - 6 -1.9796806590003533e+02 2.2990162655369829e+02 2.7501790745035373e+02 - 7 7.9109888171861886e+00 -7.6524641847864288e+01 -4.2032627555539375e+02 - 8 4.5992175211879918e+01 -1.9873148355500923e+01 1.3922798515578887e+02 - 9 1.1403303962503362e+01 1.2231165268449960e+01 5.0409090529604853e+01 - 10 1.3047784096912977e+02 -1.4556513307073578e+02 -4.4756481385998420e+01 - 11 -1.6346238349194633e-01 -4.0922088697872150e-01 -6.7303941060221573e-01 - 12 1.7689668574627495e+00 6.3166692380469824e-01 -8.3233385524693426e-01 - 13 5.6480104331071312e-01 -2.2395151872256039e-01 -9.5790993973179691e-03 - 14 -2.4030540495346994e-01 4.5179188229734012e-02 -6.0304369153488313e-01 - 15 -2.3220111317111478e-02 5.9408611078423390e-01 2.1676726911830960e-01 - 16 1.0963039832302356e+02 -7.7096357855469549e+01 -2.8842624961188653e+02 - 17 -1.0862142117090467e+02 7.5521002117836630e+01 2.9024023117219969e+02 - 18 -1.6565212275867415e-02 -2.7990268691876326e-02 2.6458602067006932e-02 - 19 7.1473709241289744e-04 6.1248437925700357e-04 1.7889258733572757e-04 - 20 -7.1473709241289744e-04 -6.1248437925700357e-04 -1.7889258733572757e-04 - 21 -1.1536904971247665e+01 -1.3021625993962397e+01 3.6108894191673429e+01 - 22 -1.7333879764643559e+01 -4.2314763344327275e+00 -2.7103019136756011e+01 - 23 2.8870784735891224e+01 1.7253102328395126e+01 -9.0058750549174214e+00 - 24 6.1437425316795213e+00 -3.4297207023632204e+01 1.8296742414004438e+01 - 25 -2.4276461284621075e+01 3.8560435260643189e+00 -2.0415720860228767e+01 - 26 1.8125049871956215e+01 3.0437790982988908e+01 2.1072387594169975e+00 - 27 8.4078124309265192e+00 -3.6323119973255714e+01 1.4505938075037919e+01 - 28 -2.8937319168272772e+01 1.2421253477627801e+01 -1.9540501416079319e+01 - 29 2.0535244350189391e+01 2.3904950625827414e+01 5.0332497948309163e+00 + 1 9.2483453882111135e+00 7.5945844242532630e+01 6.1367289784064468e+01 + 2 2.2732852134599622e+01 1.8737493288836678e+01 -2.6669600068598680e+01 + 3 -3.1964986246546172e+01 -9.3734416340673434e+01 -3.4671255449709932e+01 + 4 -5.5001585741105219e-01 1.5070776450703974e-01 -3.9275226164162935e-01 + 5 -1.7969915441332354e-01 -3.0362292635308630e-01 8.6793365971015668e-01 + 6 -1.9796806590165264e+02 2.2990162655270728e+02 2.7501790745023669e+02 + 7 7.9109888151537930e+00 -7.6524641845739424e+01 -4.2032627555780203e+02 + 8 4.5992175210254615e+01 -1.9873148358014198e+01 1.3922798515443196e+02 + 9 1.1403303962567387e+01 1.2231165268357689e+01 5.0409090529541324e+01 + 10 1.3047784096840681e+02 -1.4556513307130629e+02 -4.4756481385556341e+01 + 11 -1.6346238363922402e-01 -4.0922088693014880e-01 -6.7303941090576869e-01 + 12 1.7689668582530251e+00 6.3166692115802814e-01 -8.3233385373913271e-01 + 13 5.6480104514758445e-01 -2.2395151881989347e-01 -9.5791000096411370e-03 + 14 -2.4030540489083232e-01 4.5179188324553629e-02 -6.0304369170302041e-01 + 15 -2.3220111102749796e-02 5.9408611123108124e-01 2.1676726905655996e-01 + 16 1.0963039832494319e+02 -7.7096357857185083e+01 -2.8842624960984045e+02 + 17 -1.0862142116718823e+02 7.5521002114629724e+01 2.9024023117422536e+02 + 18 -1.6565211729771653e-02 -2.7990264151000276e-02 2.6458599205916818e-02 + 19 7.1473670261989000e-04 6.1248404522910675e-04 1.7889248977386897e-04 + 20 -7.1473670261989000e-04 -6.1248404522910675e-04 -1.7889248977386897e-04 + 21 -1.1536904971247079e+01 -1.3021625993961788e+01 3.6108894191671638e+01 + 22 -1.7333879765020438e+01 -4.2314763346057394e+00 -2.7103019136915339e+01 + 23 2.8870784736267517e+01 1.7253102328567529e+01 -9.0058750547563005e+00 + 24 6.1437425319896413e+00 -3.4297207021755547e+01 1.8296742415795482e+01 + 25 -2.4276461285000558e+01 3.8560435258438814e+00 -2.0415720860437396e+01 + 26 1.8125049872338021e+01 3.0437790983209180e+01 2.1072387596271578e+00 + 27 8.4078124297937791e+00 -3.6323119973862774e+01 1.4505938075297303e+01 + 28 -2.8937319168706676e+01 1.2421253477499173e+01 -1.9540501416287395e+01 + 29 2.0535244350622666e+01 2.3904950625953887e+01 5.0332497950390769e+00 ... diff --git a/unittest/force-styles/tests/mol-pair-lj_cut_coul_cut.yaml b/unittest/force-styles/tests/mol-pair-lj_cut_coul_cut.yaml index 9140d352d6..d34748446f 100644 --- a/unittest/force-styles/tests/mol-pair-lj_cut_coul_cut.yaml +++ b/unittest/force-styles/tests/mol-pair-lj_cut_coul_cut.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:15 202 -epsilon: 5e-14 +epsilon: 1e-13 prerequisites: ! | atom full pair lj/cut/coul/cut diff --git a/unittest/force-styles/tests/mol-pair-lj_cut_coul_dsf.yaml b/unittest/force-styles/tests/mol-pair-lj_cut_coul_dsf.yaml index 7560b3a2d0..e830d17236 100644 --- a/unittest/force-styles/tests/mol-pair-lj_cut_coul_dsf.yaml +++ b/unittest/force-styles/tests/mol-pair-lj_cut_coul_dsf.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:15 202 -epsilon: 5e-14 +epsilon: 8e-14 prerequisites: ! | atom full pair lj/cut/coul/dsf diff --git a/unittest/force-styles/tests/mol-pair-lj_cut_coul_msm.yaml b/unittest/force-styles/tests/mol-pair-lj_cut_coul_msm.yaml index d150f9ee7c..a861ce9a34 100644 --- a/unittest/force-styles/tests/mol-pair-lj_cut_coul_msm.yaml +++ b/unittest/force-styles/tests/mol-pair-lj_cut_coul_msm.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:16 202 -epsilon: 5e-14 +epsilon: 7e-14 prerequisites: ! | atom full pair lj/cut/coul/msm diff --git a/unittest/force-styles/tests/mol-pair-lj_expand.yaml b/unittest/force-styles/tests/mol-pair-lj_expand.yaml index 4732d26d9c..cc94bc7213 100644 --- a/unittest/force-styles/tests/mol-pair-lj_expand.yaml +++ b/unittest/force-styles/tests/mol-pair-lj_expand.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:16 202 -epsilon: 5e-14 +epsilon: 1e-13 prerequisites: ! | atom full pair lj/expand diff --git a/unittest/force-styles/tests/mol-pair-tip4p_cut.yaml b/unittest/force-styles/tests/mol-pair-tip4p_cut.yaml index f5e302e7ce..aeaa129089 100644 --- a/unittest/force-styles/tests/mol-pair-tip4p_cut.yaml +++ b/unittest/force-styles/tests/mol-pair-tip4p_cut.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:20 202 -epsilon: 1e-14 +epsilon: 5e-14 prerequisites: ! | atom full pair tip4p/cut diff --git a/unittest/force-styles/tests/mol-pair-tip4p_long.yaml b/unittest/force-styles/tests/mol-pair-tip4p_long.yaml index f80d4587b3..16e07643fb 100644 --- a/unittest/force-styles/tests/mol-pair-tip4p_long.yaml +++ b/unittest/force-styles/tests/mol-pair-tip4p_long.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:20 202 -epsilon: 1e-13 +epsilon: 2.5e-13 prerequisites: ! | atom full pair tip4p/long diff --git a/unittest/formats/test_atom_styles.cpp b/unittest/formats/test_atom_styles.cpp index cb3f7d79a4..b9957c6732 100644 --- a/unittest/formats/test_atom_styles.cpp +++ b/unittest/formats/test_atom_styles.cpp @@ -32,7 +32,7 @@ #include #if !defined(_FORTIFY_SOURCE) || (_FORTIFY_SOURCE == 0) -#if defined(__INTEL_COMPILER) +#if defined(__INTEL_COMPILER) || (__PGI) #define _do_nothing #elif defined(__clang__) #pragma clang optimize off diff --git a/unittest/fortran/test_fortran_commands.f90 b/unittest/fortran/test_fortran_commands.f90 index 748bc5774a..b5cffe698f 100644 --- a/unittest/fortran/test_fortran_commands.f90 +++ b/unittest/fortran/test_fortran_commands.f90 @@ -1,12 +1,12 @@ MODULE keepcmds USE liblammps TYPE(LAMMPS) :: lmp - CHARACTER(len=*), DIMENSION(*), PARAMETER :: demo_input = & + CHARACTER(len=40), DIMENSION(3), PARAMETER :: demo_input = & [ CHARACTER(len=40) :: & 'region box block 0 $x 0 2 0 2', & 'create_box 1 box', & 'create_atoms 1 single 1.0 1.0 ${zpos}' ] - CHARACTER(len=*), DIMENSION(*), PARAMETER :: cont_input = & + CHARACTER(len=40), DIMENSION(2), PARAMETER :: cont_input = & [ CHARACTER(len=40) :: & 'create_atoms 1 single &', & ' 0.2 0.1 0.1' ] @@ -19,7 +19,7 @@ FUNCTION f_lammps_with_args() BIND(C, name="f_lammps_with_args") IMPLICIT NONE TYPE(c_ptr) :: f_lammps_with_args - CHARACTER(len=*), DIMENSION(*), PARAMETER :: args = & + CHARACTER(len=12), DIMENSION(12), PARAMETER :: args = & [ CHARACTER(len=12) :: 'liblammps', '-log', 'none', & '-echo','screen','-nocite','-var','zpos','1.5','-var','x','2'] diff --git a/unittest/fortran/test_fortran_create.f90 b/unittest/fortran/test_fortran_create.f90 index 694646e9bd..e1df7502cb 100644 --- a/unittest/fortran/test_fortran_create.f90 +++ b/unittest/fortran/test_fortran_create.f90 @@ -22,7 +22,7 @@ FUNCTION f_lammps_no_mpi_with_args() BIND(C, name="f_lammps_no_mpi_with_args") IMPLICIT NONE TYPE(c_ptr) :: f_lammps_no_mpi_with_args - CHARACTER(len=*), DIMENSION(*), PARAMETER :: args = & + CHARACTER(len=12), DIMENSION(4), PARAMETER :: args = & [ CHARACTER(len=12) :: 'liblammps', '-log', 'none', '-nocite' ] lmp = lammps(args) @@ -54,7 +54,7 @@ FUNCTION f_lammps_open_with_args() BIND(C, name="f_lammps_open_with_args") TYPE(c_ptr) :: f_lammps_open_with_args INTEGER :: color, key, ierr - CHARACTER(len=*), DIMENSION(*), PARAMETER :: args = & + CHARACTER(len=12), DIMENSION(4), PARAMETER :: args = & [ CHARACTER(len=12) :: 'liblammps', '-log', 'none', '-nocite' ] color = 2 @@ -73,7 +73,7 @@ SUBROUTINE f_lammps_close() BIND(C, name="f_lammps_close") CALL lmp%close() lmp%handle = c_null_ptr END SUBROUTINE f_lammps_close - + FUNCTION f_lammps_get_comm() BIND(C, name="f_lammps_get_comm") USE liblammps USE keepcreate, ONLY: mycomm @@ -82,5 +82,3 @@ FUNCTION f_lammps_get_comm() BIND(C, name="f_lammps_get_comm") f_lammps_get_comm = mycomm END FUNCTION f_lammps_get_comm - - diff --git a/unittest/python/CMakeLists.txt b/unittest/python/CMakeLists.txt index 47fdbbfb2d..640edf2733 100644 --- a/unittest/python/CMakeLists.txt +++ b/unittest/python/CMakeLists.txt @@ -44,7 +44,7 @@ if (Python_EXECUTABLE) find_package_handle_standard_args(COVERAGE DEFAULT_MSG COVERAGE_BINARY) if(COVERAGE_FOUND) - set(PYTHON_TEST_RUNNER ${Python_EXECUTABLE} -u ${COVERAGE_BINARY} run --parallel-mode --include=${LAMMPS_PYTHON_DIR}/lammps.py --omit=${LAMMPS_PYTHON_DIR}/install.py) + set(PYTHON_TEST_RUNNER ${Python_EXECUTABLE} -u ${COVERAGE_BINARY} run --parallel-mode --include=${LAMMPS_PYTHON_DIR}/lammps/*.py --omit=${LAMMPS_PYTHON_DIR}/install.py) else() set(PYTHON_TEST_RUNNER ${Python_EXECUTABLE} -u) endif() @@ -57,10 +57,13 @@ if (Python_EXECUTABLE) WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) set_tests_properties(PythonOpen PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}") - add_test(NAME PythonCommands - COMMAND ${PYTHON_TEST_RUNNER} ${CMAKE_CURRENT_SOURCE_DIR}/python-commands.py -v - WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) - set_tests_properties(PythonCommands PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}") + # some of the tests in this file will fail without exceptions enabled + if(LAMMPS_EXCEPTIONS) + add_test(NAME PythonCommands + COMMAND ${PYTHON_TEST_RUNNER} ${CMAKE_CURRENT_SOURCE_DIR}/python-commands.py -v + WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) + set_tests_properties(PythonCommands PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}") + endif() add_test(NAME PythonNumpy COMMAND ${PYTHON_TEST_RUNNER} ${CMAKE_CURRENT_SOURCE_DIR}/python-numpy.py -v