Merge pull request #2434 from akohlmey/swig-wrappers

Provide an interface file for creating script wrappers for LAMMPS with SWIG
This commit is contained in:
Axel Kohlmeyer
2020-10-21 12:56:11 -04:00
committed by GitHub
31 changed files with 1037 additions and 75 deletions

View File

@ -379,6 +379,13 @@ foreach(PKG_WITH_INCL KSPACE PYTHON VORONOI USER-COLVARS USER-MOLFILE USER-NETCD
endif() endif()
endforeach() endforeach()
# optionally enable building script wrappers using swig
option(WITH_SWIG "Build scripting language wrappers with SWIG" OFF)
if(WITH_SWIG)
get_filename_component(LAMMPS_SWIG_DIR ${LAMMPS_SOURCE_DIR}/../tools/swig ABSOLUTE)
add_subdirectory(${LAMMPS_SWIG_DIR} swig)
endif()
set(CMAKE_TUNE_FLAGS "${CMAKE_TUNE_DEFAULT}" CACHE STRING "Compiler and machine specific optimization flags (compilation only)") set(CMAKE_TUNE_FLAGS "${CMAKE_TUNE_DEFAULT}" CACHE STRING "Compiler and machine specific optimization flags (compilation only)")
separate_arguments(CMAKE_TUNE_FLAGS) separate_arguments(CMAKE_TUNE_FLAGS)
foreach(_FLAG ${CMAKE_TUNE_FLAGS}) foreach(_FLAG ${CMAKE_TUNE_FLAGS})

View File

@ -23,7 +23,7 @@ set(DOWNLOAD_VORO ON CACHE BOOL "" FORCE)
set(DOWNLOAD_EIGEN3 ON CACHE BOOL "" FORCE) set(DOWNLOAD_EIGEN3 ON CACHE BOOL "" FORCE)
set(LAMMPS_MEMALIGN "0" CACHE STRING "" FORCE) set(LAMMPS_MEMALIGN "0" CACHE STRING "" FORCE)
set(CMAKE_TUNE_FLAGS "-Wno-missing-include-dirs" CACHE STRING "" FORCE) set(CMAKE_TUNE_FLAGS "-Wno-missing-include-dirs" CACHE STRING "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-stdcall-fixup" CACHE STRING "" FORCE) set(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-stdcall-fixup,--as-needed,-lssp" CACHE STRING "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--enable-stdcall-fixup" CACHE STRING "" FORCE) set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--enable-stdcall-fixup,--as-needed,-lssp" CACHE STRING "" FORCE)
set(BUILD_TOOLS ON CACHE BOOL "" FORCE) set(BUILD_TOOLS ON CACHE BOOL "" FORCE)
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/lammps-installer") set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/lammps-installer")

View File

@ -53,5 +53,5 @@ in two stages: the callback function is registered with the pair style
and then called from the Pair::ev_tally() function, which is called for and then called from the Pair::ev_tally() function, which is called for
each pair after force and energy has been computed for this pair. Then each pair after force and energy has been computed for this pair. Then
the tallied values are retrieved with the standard compute_scalar or the tallied values are retrieved with the standard compute_scalar or
compute_vector or compute_peratom methods. The USER-TALLY package compute_vector or compute_peratom methods. The :doc:`compute styles in the USER-TALLY package <compute_tally>`
provides *examples*\ _compute_tally.html for utilizing this mechanism. provide *examples* for utilizing this mechanism.

View File

@ -21,7 +21,7 @@ distribution.
+------------------------+--------------------------------------------------------------------+ +------------------------+--------------------------------------------------------------------+
| ``gui.py`` | GUI go/stop/temperature-slider to control LAMMPS | | ``gui.py`` | GUI go/stop/temperature-slider to control LAMMPS |
+------------------------+--------------------------------------------------------------------+ +------------------------+--------------------------------------------------------------------+
| ``plot.py`` | real-time temperature plot with GnuPlot via Pizza.py | | ``plot.py`` | real-time temperature plot with GnuPlot via Pizza.py |
+------------------------+--------------------------------------------------------------------+ +------------------------+--------------------------------------------------------------------+
| ``viz_TOOL.py`` | real-time viz via some viz package | | ``viz_TOOL.py`` | real-time viz via some viz package |
+------------------------+--------------------------------------------------------------------+ +------------------------+--------------------------------------------------------------------+

View File

@ -94,6 +94,7 @@ Miscellaneous tools
* :ref:`kate <kate>` * :ref:`kate <kate>`
* :ref:`LAMMPS shell <lammps_shell>` * :ref:`LAMMPS shell <lammps_shell>`
* :ref:`singularity <singularity_tool>` * :ref:`singularity <singularity_tool>`
* :ref:`SWIG interface <swig>`
* :ref:`vim <vim>` * :ref:`vim <vim>`
---------- ----------
@ -559,6 +560,8 @@ More details about this are in the `readline documentation <https://tiswww.cwru.
LAMMPS Shell tips and tricks LAMMPS Shell tips and tricks
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Below are some suggestions for how to use and customize the LAMMPS shell.
Enable tilde expansion Enable tilde expansion
"""""""""""""""""""""" """"""""""""""""""""""
@ -591,8 +594,8 @@ command line like this:
xterm -title "LAMMPS Shell" -e /path/to/lammps-shell -i in.file.lmp xterm -title "LAMMPS Shell" -e /path/to/lammps-shell -i in.file.lmp
Use history create input file Use history to create an input file
""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""
When experimenting with commands to interactively to figure out a When experimenting with commands to interactively to figure out a
suitable choice of settings or simply the correct syntax, you may want suitable choice of settings or simply the correct syntax, you may want
@ -876,6 +879,123 @@ For more details please see the README.md file in that folder.
---------- ----------
.. _swig:
SWIG interface
--------------
The `SWIG tool <http://swig.org>`_ offers a mostly automated way to
incorporate compiled code modules into scripting languages. It
processes the function prototypes in C and generates wrappers for a wide
variety of scripting languages from it. Thus it can also be applied to
the :doc:`C language library interface <Library>` of LAMMPS so that
build a wrapper that allows to call LAMMPS from programming languages
like: C#/Mono, Lua, Java, JavaScript, Perl, Python, R, Ruby, Tcl, and
more.
What is included
^^^^^^^^^^^^^^^^
We provide here an "interface file", ``lammps.i``, that has the content
of the ``library.h`` file adapted so SWIG can process it. That will
create wrappers for all the functions that are present in the LAMMPS C
library interface. Please note that not all kinds of C functions can be
automatically translated, so you would have to add custom functions to
be able to utilize those where the automatic translation does not work.
A few functions for converting pointers and accessing arrays are
predefined. We provide the file here on an "as is" basis to help people
getting started, but not as a fully tested and supported feature of the
LAMMPS distribution. Any contributions to complete this are, of course,
welcome. Please also note, that for the case of creating a Python wrapper,
a fully supported :doc:`Ctypes based lammps module <Python_module>`
already exists. That module is designed to be object oriented while
SWIG will generate a 1:1 translation of the functions in the interface file.
Building the wrapper
^^^^^^^^^^^^^^^^^^^^
When using CMake, the build steps for building a wrapper
module are integrated for the languages: Java, Lua,
Perl5, Python, Ruby, and Tcl. These require that the
LAMMPS library is build as a shared library and all
necessary development headers and libraries are present.
.. code-block:: bash
-D WITH_SWIG=on # to enable building any SWIG wrapper
-D BUILD_SWIG_JAVA=on # to enable building the Java wrapper
-D BUILD_SWIG_LUA=on # to enable building the Lua wrapper
-D BUILD_SWIG_PERL5=on # to enable building the Perl 5.x wrapper
-D BUILD_SWIG_PYTHON=on # to enable building the Python wrapper
-D BUILD_SWIG_RUBY=on # to enable building the Ruby wrapper
-D BUILD_SWIG_TCL=on # to enable building the Tcl wrapper
Manual building allows a little more flexibility. E.g. one can choose
the name of the module and build and use a dynamically loaded object
for Tcl with:
.. code-block:: bash
$ swig -tcl -module tcllammps lammps.i
$ gcc -fPIC -shared $(pkgconf --cflags tcl) -o tcllammps.so \
lammps_wrap.c -L ../src/ -llammps
$ tclsh
Or one can build an extended Tcl shell command with the wrapped
functions included with:
.. code-block:: bash
$ swig -tcl -module tcllmps lammps_shell.i
$ gcc -o tcllmpsh lammps_wrap.c -Xlinker -export-dynamic \
-DHAVE_CONFIG_H $(pkgconf --cflags tcl) \
$(pkgconf --libs tcl) -L ../src -llammps
In both cases it is assumed that the LAMMPS library was compiled
as a shared library in the ``src`` folder. Otherwise the last
part of the commands needs to be adjusted.
Utility functions
^^^^^^^^^^^^^^^^^
Definitions for several utility functions required to manage and access
data passed or returned as pointers are included in the ``lammps.i``
file. So most of the functionality of the library interface should be
accessible. What works and what does not depends a bit on the
individual language for which the wrappers are built and how well SWIG
supports those. The `SWIG documentation <http://swig.org/doc.html>`_
has very detailed instructions and recommendations.
Usage examples
^^^^^^^^^^^^^^
The ``tools/swig`` folder has multiple shell scripts, ``run_<name>_example.sh``
that will create a small example script and demonstrate how to load
the wrapper and run LAMMPS through it in the corresponding programming
language.
For illustration purposes below is a part of the Tcl example script.
.. code-block:: tcl
% load ./tcllammps.so
% set lmp [lammps_open_no_mpi 0 NULL NULL]
% lammps_command $lmp "units real"
% lammps_command $lmp "lattice fcc 2.5"
% lammps_command $lmp "region box block -5 5 -5 5 -5 5"
% lammps_command $lmp "create_box 1 box"
% lammps_command $lmp "create_atoms 1 box"
%
% set dt [doublep_value [voidp_to_doublep [lammps_extract_global $lmp dt]]]
% puts "LAMMPS version $ver"
% puts [format "Number of created atoms: %g" [lammps_get_natoms $lmp]]
% puts "Current size of timestep: $dt"
% puts "LAMMPS version: [lammps_version $lmp]"
% lammps_close $lmp
----------
.. _vim: .. _vim:
vim tool vim tool

View File

@ -24,8 +24,8 @@ Description
""""""""""" """""""""""
Define a computation that extracts the angle energy calculated by each Define a computation that extracts the angle energy calculated by each
of the angle sub-styles used in the "angle_style of the angle sub-styles used in the doc:`angle_style hybrid <angle_hybrid>`
hybrid" angle_hybrid.html command. These values are made accessible command. These values are made accessible
for output or further processing by other commands. The group for output or further processing by other commands. The group
specified for this command is ignored. specified for this command is ignored.

View File

@ -222,9 +222,9 @@ Default
""""""" """""""
The default keyword values specific to this fix are exy = xyz, strain The default keyword values specific to this fix are exy = xyz, strain
= 0 0. The remaining defaults are the same as for *fix = 0 0. The remaining defaults are the same as for :doc:`fix npt <fix_nh>`
npt*\ _fix_nh.html except tchain = 1. The reason for this change is except tchain = 1. The reason for this change is given in
given in :doc:`fix nvt/sllod <fix_nvt_sllod>`. :doc:`fix nvt/sllod <fix_nvt_sllod>`.
---------- ----------

View File

@ -345,9 +345,9 @@ given by
\rho_{\alpha\beta} (r_{ij})\right) + \rho_{\alpha\beta} (r_{ij})\right) +
\frac{1}{2} \sum_{j \neq i} \phi_{\alpha\beta} (r_{ij}) \frac{1}{2} \sum_{j \neq i} \phi_{\alpha\beta} (r_{ij})
where :math:`\rho_{\alpha\beta}` refers to the density contributed where :math:`\rho_{\alpha\beta}` refers to the density contributed
by a neighbor atom J of element :math:`\beta` at the site of atom I by a neighbor atom J of element :math:`\beta` at the site of atom I
of element :math:`\alpha`. of element :math:`\alpha`.
This has the same form as the EAM formula above, except that rho is This has the same form as the EAM formula above, except that rho is
now a functional specific to the elements of both atoms I and J, now a functional specific to the elements of both atoms I and J,
so that different elements can contribute differently to the total so that different elements can contribute differently to the total
@ -408,7 +408,7 @@ each with the following format:
The units of these quantities in line 1 are the same as for *setfl* The units of these quantities in line 1 are the same as for *setfl*
files. Note that the rho(r) arrays in Finnis/Sinclair can be files. Note that the rho(r) arrays in Finnis/Sinclair can be
asymmetric (:math:`\rho_{\alpha\beta} (r) \neq \rho_{\beta\alpha} (r)` ) asymmetric (:math:`\rho_{\alpha\beta} (r) \neq \rho_{\beta\alpha} (r)` )
so there are Nelements\^2 of them listed in the file. so there are Nelements\^2 of them listed in the file.
Following the Nelements sections, Nr values for each pair potential Following the Nelements sections, Nr values for each pair potential

View File

@ -1713,6 +1713,7 @@ lsfftw
ltbbmalloc ltbbmalloc
lubricateU lubricateU
lucy lucy
Lua
Luding Luding
Lussetti Lussetti
Lustig Lustig
@ -3035,6 +3036,7 @@ taubi
tb tb
tchain tchain
Tchain Tchain
Tcl
Tcom Tcom
tcsh tcsh
tdamp tdamp

View File

@ -11,11 +11,11 @@ library.
See these sections of the LAMMPS manual for details: See these sections of the LAMMPS manual for details:
Build LAMMPS as a library (doc/Build_basics.html) Build LAMMPS as a library (doc/html/Build_basics.html)
Link LAMMPS as a library to another code (doc/Build_link.html) Link LAMMPS as a library to another code (doc/html/Build_link.html)
Coupling LAMMPS to other codes (doc/Howto_couple.html) Coupling LAMMPS to other codes (doc/html/Howto_couple.html)
Using LAMMPS in client/server mode (doc/Howto_client_server.html) Using LAMMPS in client/server mode (doc/html/Howto_client_server.html)
Library interface to LAMMPS (doc/Howto_library.html) Library interface to LAMMPS (doc/html/Howto_library.html)
The library interface to LAMMPS is in src/library.cpp. Routines can The library interface to LAMMPS is in src/library.cpp. Routines can
be easily added to this file so an external program can perform the be easily added to this file so an external program can perform the
@ -25,23 +25,23 @@ LAMMPS tasks desired.
These are the sub-directories included in this directory: These are the sub-directories included in this directory:
simple simple example of driver code calling LAMMPS as a lib simple simple example of driver code calling LAMMPS as a lib
multiple example of driver code calling multiple instances of LAMMPS multiple example of driver code calling multiple instances of LAMMPS
plugin example for loading LAMMPS at runtime from a shared library plugin example for loading LAMMPS at runtime from a shared library
lammps_mc client/server coupling of Monte Carlo client lammps_mc client/server coupling of Monte Carlo client
with LAMMPS server for energy evaluation with LAMMPS server for energy evaluation
lammps_nwchem client/server coupling of LAMMPS client with lammps_nwchem client/server coupling of LAMMPS client with
NWChem quantum DFT as server for quantum forces NWChem quantum DFT as server for quantum forces
lammps_quest MD with quantum forces, coupling to Quest DFT code lammps_quest MD with quantum forces, coupling to Quest DFT code
lammps_spparks grain-growth Monte Carlo with strain via MD, lammps_spparks grain-growth Monte Carlo with strain via MD,
coupling to SPPARKS kinetic MC code coupling to SPPARKS kinetic MC code
lammps_vasp client/server coupling of LAMMPS client with lammps_vasp client/server coupling of LAMMPS client with
VASP quantum DFT as server for quantum forces VASP quantum DFT as server for quantum forces
library collection of useful inter-code communication routines library collection of useful inter-code communication routines
fortran a simple wrapper on the LAMMPS library API that fortran a simple wrapper on the LAMMPS library API that
can be called from Fortran can be called from Fortran
fortran2 a more sophisticated wrapper on the LAMMPS library API that fortran2 a more sophisticated wrapper on the LAMMPS library API that
can be called from Fortran can be called from Fortran
fortran_dftb wrapper written by Nir Goldman (LLNL), as an fortran_dftb wrapper written by Nir Goldman (LLNL), as an
extension to fortran2, used for calling LAMMPS extension to fortran2, used for calling LAMMPS
from Fortran DFTB+ tight-binding code from Fortran DFTB+ tight-binding code

View File

@ -1,8 +1,8 @@
Sample Monte Carlo (MC) wrapper on LAMMPS via client/server coupling Sample Monte Carlo (MC) wrapper on LAMMPS via client/server coupling
See the MESSAGE package (doc/Section_messages.html#MESSAGE) See the MESSAGE package documentation Build_extras.html#message
and Section_howto.html#howto10 for more details on how and Build_extras.html#message for more details on how client/server
client/server coupling works in LAMMPS. coupling works in LAMMPS.
In this dir, the mc.cpp/h files are a standalone "client" MC code. It In this dir, the mc.cpp/h files are a standalone "client" MC code. It
should be run on a single processor, though it could become a parallel should be run on a single processor, though it could become a parallel
@ -94,18 +94,18 @@ background.
File mode of messaging: File mode of messaging:
% mpirun -np 1 mc in.mc file tmp.couple % mpirun -np 1 mc in.mc file tmp.couple
% mpirun -np 1 lmp_mpi -v mode file < in.mc.server % mpirun -np 1 lmp_mpi -v mode file -in in.mc.server
% mpirun -np 1 mc in.mc file tmp.couple % mpirun -np 1 mc in.mc file tmp.couple
% mpirun -np 4 lmp_mpi -v mode file < in.mc.server % mpirun -np 4 lmp_mpi -v mode file -in in.mc.server
ZMQ mode of messaging: ZMQ mode of messaging:
% mpirun -np 1 mc in.mc zmq localhost:5555 % mpirun -np 1 mc in.mc zmq localhost:5555
% mpirun -np 1 lmp_mpi -v mode zmq < in.mc.server % mpirun -np 1 lmp_mpi -v mode zmq -in in.mc.server
% mpirun -np 1 mc in.mc zmq localhost:5555 % mpirun -np 1 mc in.mc zmq localhost:5555
% mpirun -np 4 lmp_mpi -v mode zmq < in.mc.server % mpirun -np 4 lmp_mpi -v mode zmq -in in.mc.server
-------------- --------------

View File

@ -1,7 +1,7 @@
Sample LAMMPS MD wrapper on NWChem via client/server coupling Sample LAMMPS MD wrapper on NWChem via client/server coupling
See the MESSAGE package (doc/Section_messages.html#MESSAGE) and See the MESSAGE package documentation Build_extras.html#message
Section_howto.html#howto10 for more details on how client/server and Build_extras.html#message for more details on how client/server
coupling works in LAMMPS. coupling works in LAMMPS.
In this dir, the nwchem_wrap.py is a wrapper on the NWChem electronic In this dir, the nwchem_wrap.py is a wrapper on the NWChem electronic
@ -182,16 +182,16 @@ background.
File mode of messaging: File mode of messaging:
% mpirun -np 1 lmp_mpi -v mode file < in.client.W % mpirun -np 1 lmp_mpi -v mode file -in in.client.W
% python nwchem_wrap.py file pw w.nw % python nwchem_wrap.py file pw w.nw
% mpirun -np 2 lmp_mpi -v mode file < in.client.h2o % mpirun -np 2 lmp_mpi -v mode file -in in.client.h2o
% python nwchem_wrap.py file ao h2o.nw % python nwchem_wrap.py file ao h2o.nw
ZMQ mode of messaging: ZMQ mode of messaging:
% mpirun -np 1 lmp_mpi -v mode zmq < in.client.W % mpirun -np 1 lmp_mpi -v mode zmq -in in.client.W
% python nwchem_wrap.py zmq pw w.nw % python nwchem_wrap.py zmq pw w.nw
% mpirun -np 2 lmp_mpi -v mode zmq < in.client.h2o % mpirun -np 2 lmp_mpi -v mode zmq -in in.client.h2o
% python nwchem_wrap.py zmq ao h2o.nw % python nwchem_wrap.py zmq ao h2o.nw

View File

@ -16,11 +16,11 @@ Lennard-Jones sigma between particles of different types that is
larger than the sigma between particles of the same type (interior to larger than the sigma between particles of the same type (interior to
grains). grains).
lmpspk.cpp main program lmpspk.cpp main program
it links LAMMPS and SPPARKS as libraries it links LAMMPS and SPPARKS as libraries
in.spparks SPPARKS input script, without the run command in.spparks SPPARKS input script, without the run command
lmppath.h contains path to LAMMPS home directory lmppath.h contains path to LAMMPS home directory
spkpath.h contains path to SPPARKS home directory spkpath.h contains path to SPPARKS home directory
After editing the Makefile, lmppath.h, and spkpath.h to make them After editing the Makefile, lmppath.h, and spkpath.h to make them
suitable for your box, type: suitable for your box, type:

View File

@ -1,8 +1,8 @@
Sample LAMMPS MD wrapper on VASP quantum DFT via client/server Sample LAMMPS MD wrapper on VASP quantum DFT via client/server
coupling coupling
See the MESSAGE package (doc/Section_messages.html#MESSAGE) and See the MESSAGE package documentation Build_extras.html#message
Section_howto.html#howto10 for more details on how client/server and Build_extras.html#message for more details on how client/server
coupling works in LAMMPS. coupling works in LAMMPS.
In this dir, the vasp_wrap.py is a wrapper on the VASP quantum DFT In this dir, the vasp_wrap.py is a wrapper on the VASP quantum DFT
@ -134,16 +134,16 @@ background.
File mode of messaging: File mode of messaging:
% mpirun -np 1 lmp_mpi -v mode file < in.client.W % mpirun -np 1 lmp_mpi -v mode file -in in.client.W
% python vasp_wrap.py file POSCAR_W % python vasp_wrap.py file POSCAR_W
% mpirun -np 2 lmp_mpi -v mode file < in.client.W % mpirun -np 2 lmp_mpi -v mode file -in in.client.W
% python vasp_wrap.py file POSCAR_W % python vasp_wrap.py file POSCAR_W
ZMQ mode of messaging: ZMQ mode of messaging:
% mpirun -np 1 lmp_mpi -v mode zmq < in.client.W % mpirun -np 1 lmp_mpi -v mode zmq -in in.client.W
% python vasp_wrap.py zmq POSCAR_W % python vasp_wrap.py zmq POSCAR_W
% mpirun -np 2 lmp_mpi -v mode zmq < in.client.W % mpirun -np 2 lmp_mpi -v mode zmq -in in.client.W
% python vasp_wrap.py zmq POSCAR_W % python vasp_wrap.py zmq POSCAR_W

View File

@ -179,7 +179,7 @@ the same simulation in different unit systems.
The USER directory contains subdirectories of user-provided example The USER directory contains subdirectories of user-provided example
scripts for ser packages. See the README files in those directories scripts for ser packages. See the README files in those directories
for more info. See the doc/Section_start.html file for more info for more info. See the doc/html/Build_package.html file for more info
about installing and building user packages. about installing and building user packages.
The VISCOSITY directory has example scripts for computing the The VISCOSITY directory has example scripts for computing the

View File

@ -36,7 +36,7 @@ In a separate terminal, then, you should run LAMMPS compiled to provide
fix_ipi functionalities. fix_ipi functionalities.
```bash ```bash
$LAMMPS < in.graphene $LAMMPS -in in.graphene
``` ```
You can run multiple instances of LAMMPS if you want to exploit the You can run multiple instances of LAMMPS if you want to exploit the

View File

@ -11,9 +11,8 @@ LAMMPS as the server, e.g. a quantum code computing quantum forces, so
that ab initio MD could be performed. See an example of the latter in that ab initio MD could be performed. See an example of the latter in
examples/COUPLE/lammps_vasp. examples/COUPLE/lammps_vasp.
See the doc pages for the "MESSAGE package" See the MESSAGE package documentation Build_extras.html#message
(Package_details.html#PKG-MESSAGE) and "Howto client/server" and Build_extras.html#message for more details on how client/server
(Howto_client_server.html) for more details on how client/server
coupling works in LAMMPS. coupling works in LAMMPS.
-------------- --------------
@ -30,7 +29,7 @@ You can also run the in.message scripts with an NPT integrator
instead of NVE, if you comment/uncomment the correct lines. instead of NVE, if you comment/uncomment the correct lines.
The client and server script define a "mode" variable The client and server script define a "mode" variable
which can be set to file, zmq, mpi/one, or mpi/two, which can be set to file, zmq, mpi/one, or mpi/two,
as illustrated below. as illustrated below.
-------------- --------------
@ -38,8 +37,8 @@ as illustrated below.
To run this problem in the traditional way (no client/server coupling) To run this problem in the traditional way (no client/server coupling)
do one of these: do one of these:
% lmp_serial < in.message % lmp_serial -in in.message
% mpirun -np 4 lmp_mpi < in.message % mpirun -np 4 lmp_mpi -in in.message
Or run with in.message.tilt. Or run with in.message.tilt.
@ -87,14 +86,14 @@ runs listed below.
File or ZMQ or mpi/two modes of messaging: File or ZMQ or mpi/two modes of messaging:
% mpirun -np 1 lmp_mpi -v mode file -log log.client < in.message.client & % mpirun -np 1 lmp_mpi -v mode file -log log.client -in in.message.client &
% mpirun -np 2 lmp_mpi -v mode file -log log.server < in.message.server % mpirun -np 2 lmp_mpi -v mode file -log log.server -in in.message.server
% mpirun -np 4 lmp_mpi -v mode zmq -log log.client < in.message.client & % mpirun -np 4 lmp_mpi -v mode zmq -log log.client -in in.message.client &
% mpirun -np 1 lmp_mpi -v mode zmq -log log.server < in.message.server % mpirun -np 1 lmp_mpi -v mode zmq -log log.server -in in.message.server
% mpirun -np 2 lmp_mpi -v mode mpitwo -log log.client < in.message.client & % mpirun -np 2 lmp_mpi -v mode mpitwo -log log.client -in in.message.client &
% mpirun -np 4 lmp_mpi -v mode mpitwo -log log.server < in.message.server % mpirun -np 4 lmp_mpi -v mode mpitwo -log log.server -in in.message.server
Or run with in.message.tilt.client/server. Or run with in.message.tilt.client/server.
Don't run the tilt files with the "file" mode; they run too slow. Don't run the tilt files with the "file" mode; they run too slow.

View File

@ -1,8 +0,0 @@
If you get bogus, large energies on timestep 0 when you run this
example in.peptide, you likely have a machine/compiler problem with
the pair_style "long" potentials which use Coulombic tabling by
default.
See the "Additional build tips" sub-section of the manual in
Section_start.html in the "Making LAMMPS" section for details and
suggestions on how to work around this issue.

View File

@ -6,7 +6,7 @@ More information about each feature can be found by reading its doc
page in the LAMMPS doc directory. The doc page which lists all LAMMPS page in the LAMMPS doc directory. The doc page which lists all LAMMPS
input script commands is as follows: input script commands is as follows:
doc/Section_commands.html, subsection 3.5 doc/Commands_all.html
User-contributed features are listed at the bottom of the fix, User-contributed features are listed at the bottom of the fix,
compute, pair, etc sections. compute, pair, etc sections.

View File

@ -46,6 +46,7 @@ replica tool to reorder LAMMPS replica trajectories according to
singularity Singularity container descriptions suitable for LAMMPS development singularity Singularity container descriptions suitable for LAMMPS development
smd convert Smooth Mach Dynamics triangles to VTK smd convert Smooth Mach Dynamics triangles to VTK
spin perform a cubic polynomial interpolation of a GNEB MEP spin perform a cubic polynomial interpolation of a GNEB MEP
swig SWIG generated script language wrappers for the LAMMPS C library interface
valgrind suppression files for use with valgrind's memcheck tool valgrind suppression files for use with valgrind's memcheck tool
vim add-ons to VIM editor for editing LAMMPS input scripts vim add-ons to VIM editor for editing LAMMPS input scripts
xmgrace a collection of scripts to generate xmgrace plots xmgrace a collection of scripts to generate xmgrace plots

100
tools/swig/CMakeLists.txt Normal file
View File

@ -0,0 +1,100 @@
# CMake configuration for generating script language interfaces with SWIG
# set minimum CMake version required and switch to new policies for SWIG
cmake_minimum_required(VERSION 3.14)
if(POLICY CMP0078)
cmake_policy(SET CMP0078 NEW)
endif()
if(POLICY CMP0086)
cmake_policy(SET CMP0086 NEW)
endif()
enable_language(C)
# some of the find_package() scripts trigger developer warnings
# even though they are bundled with CMake; Suppress them
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS TRUE)
if(NOT BUILD_SHARED_LIBS)
message(FATAL_ERROR "Option BUILD_SHARED_LIBS must be enabled to use SWIG wrappers")
endif()
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
option(BUILD_SWIG_JAVA "Build Java JNI wrapper with SWIG" OFF)
option(BUILD_SWIG_LUA "Build Lua wrapper with SWIG" OFF)
option(BUILD_SWIG_PERL5 "Build Perl5 wrapper with SWIG" OFF)
option(BUILD_SWIG_PYTHON "Build Python wrapper with SWIG" OFF)
option(BUILD_SWIG_RUBY "Build Ruby wrapper with SWIG" OFF)
option(BUILD_SWIG_TCL "Build Tcl wrapper with SWIG" OFF)
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
pllammps.pm __pycache__ log.lammps
example.class example.java example.lua example.pl example.py example.rb example.tcl example.tcllmp
javalammps.class javalammpsJNI.class javalammps.java javalammpsJNI.java
_LMP_DATATYPE_CONST.class _LMP_STYLE_CONST.class _LMP_TYPE_CONST.class
_LMP_DATATYPE_CONST.java _LMP_STYLE_CONST.java _LMP_TYPE_CONST.java
SWIGTYPE_p_double.class SWIGTYPE_p_int.class SWIGTYPE_p_p_char.class SWIGTYPE_p_p_double.class
SWIGTYPE_p_p_int.class SWIGTYPE_p_p_void.class SWIGTYPE_p_void.class
SWIGTYPE_p_double.java SWIGTYPE_p_int.java SWIGTYPE_p_p_char.java SWIGTYPE_p_p_double.java
SWIGTYPE_p_p_int.java SWIGTYPE_p_p_void.java SWIGTYPE_p_void.java)
if(BUILD_SWIG_JAVA)
set_property(SOURCE lammps.i PROPERTY SWIG_MODULE_NAME javalammps)
swig_add_library(javalammps TYPE MODULE LANGUAGE java SOURCES lammps.i)
find_package(JNI REQUIRED)
target_include_directories(javalammps PRIVATE ${JNI_INCLUDE_DIRS})
swig_link_libraries(javalammps PRIVATE lammps ${JNI_LIBRARIES})
configure_file(run_java_example.sh run_java_example.sh COPYONLY)
endif()
if(BUILD_SWIG_LUA)
set_property(SOURCE lammps.i PROPERTY SWIG_MODULE_NAME lualammps)
swig_add_library(lualammps TYPE MODULE LANGUAGE lua SOURCES lammps.i)
find_package(Lua REQUIRED)
target_include_directories(lualammps PRIVATE ${LUA_INCLUDE_PATH})
swig_link_libraries(lualammps PRIVATE lammps ${LUA_LIBRARY})
configure_file(run_lua_example.sh run_lua_example.sh COPYONLY)
endif()
if(BUILD_SWIG_PERL5)
set_property(SOURCE lammps.i PROPERTY SWIG_MODULE_NAME pllammps)
swig_add_library(pllammps TYPE MODULE LANGUAGE perl5 SOURCES lammps.i)
find_package(PerlLibs REQUIRED 5.0)
target_compile_definitions(pllammps PRIVATE _LARGEFILE64_SOURCE)
target_include_directories(pllammps PRIVATE ${PERL_INCLUDE_PATH})
swig_link_libraries(pllammps PRIVATE lammps ${PERL_LIBRARY})
configure_file(run_perl_example.sh run_perl_example.sh COPYONLY)
endif()
if(BUILD_SWIG_PYTHON)
set_property(SOURCE lammps.i PROPERTY SWIG_MODULE_NAME pylammps)
swig_add_library(pylammps TYPE MODULE LANGUAGE python SOURCES lammps.i)
find_package(Python REQUIRED COMPONENTS Development)
swig_link_libraries(pylammps PRIVATE lammps Python::Python)
configure_file(run_python_example.sh run_python_example.sh COPYONLY)
endif()
if(BUILD_SWIG_RUBY)
set_property(SOURCE lammps.i PROPERTY SWIG_MODULE_NAME rubylammps)
swig_add_library(rubylammps TYPE MODULE LANGUAGE ruby SOURCES lammps.i)
find_package(Ruby REQUIRED)
target_include_directories(rubylammps PRIVATE ${RUBY_INCLUDE_DIRS})
swig_link_libraries(rubylammps PRIVATE lammps ${RUBY_LIBRARY})
configure_file(run_ruby_example.sh run_ruby_example.sh COPYONLY)
endif()
if(BUILD_SWIG_TCL)
set_property(SOURCE lammps.i PROPERTY SWIG_MODULE_NAME tcllammps)
swig_add_library(tcllammps TYPE MODULE LANGUAGE tcl SOURCES lammps.i)
find_package(TCL REQUIRED)
target_include_directories(tcllammps PRIVATE ${TCL_INCLUDE_PATH})
swig_link_libraries(tcllammps PRIVATE lammps ${TCL_LIBRARY})
configure_file(run_tcl_example.sh run_tcl_example.sh COPYONLY)
set_property(SOURCE lammps_shell.i PROPERTY SWIG_MODULE_NAME tcllmpsh)
swig_add_library(libtcllmpsh TYPE STATIC LANGUAGE tcl SOURCES lammps_shell.i)
add_executable(tcllmpsh tcldummy.c)
target_include_directories(tcllmpsh PRIVATE ${TCL_INCLUDE_PATH})
target_link_libraries(tcllmpsh PRIVATE libtcllmpsh lammps ${TCL_LIBRARY})
endif()

36
tools/swig/README Normal file
View File

@ -0,0 +1,36 @@
SWIG generated script library wrappers
The SWIG tool ( http://swig.org ) offers a mostly automated way to
incorporate compiled code modules into scripting languages. It
processes the function prototypes in C and generates wrappers for a wide
variety of scripting languages from it.
We provide here an "interface file", "lammps.i", that has the content of
the "library.h" file adapted so SWIG can process it. Please note that
not all kinds of C functions can be automatically translated, so you
would have to add custom functions to be able to utilize them. A few
functions for converting pointers and accessing arrays are predefined.
We provide the files here on an "as is" basis to help people getting
started, but not as a fully tested and supported feature of the
distribution. Any contributions to complete this are, of course,
welcome.
In the case of Python, a fully supported and complete wrapper already
exists in the "lammps" module in the "python" folder. This wrapper is
based on Ctypes and is object oriented while SWIG will generate a 1:1
translation of the functions in the interface file.
When using the CMake build system, steps for building wrapper modules
are integrated for the languages: Java, Lua, Perl5, Python, Ruby, and
Tcl and can be selected during the configuration step. These require
that the LAMMPS library is build as a shared library and all necessary
development headers and libraries of the selected script languages are
present. To demonstrate the resulting wrappers, several example shell
scripts (run_*_example.sh) are provided that contain commands to create
an example script file and to demonstrate the use of the wrapped library
functions in the respective programming language.
For details on how to build and adjust wrappers for individual
languages please refer to the SWIG documentation at http://swig.org/doc.html
This functionality has been tested on Fedora 32 with SWIG 4.0.1.

255
tools/swig/lammps.i Normal file
View File

@ -0,0 +1,255 @@
%include "cpointer.i"
%include "carrays.i"
%include "cdata.i"
%include "cstring.i"
%pointer_functions(int, int_p);
%pointer_functions(int, int64_p);
%pointer_functions(double, double_p);
%array_functions(char, char_1d);
%array_functions(int, int_1d);
%array_functions(double, double_1d);
%pointer_cast(void *, int *, void_p_to_int_p);
%pointer_cast(void *, int **, void_p_to_int2d_p);
%pointer_cast(void *, int *, void_p_to_int64_p);
%pointer_cast(void *, int **, void_p_to_int64_2d_p);
%pointer_cast(void *, double *, void_p_to_double_p);
%pointer_cast(void *, double **, void_p_to_double_2d_p);
%cstring_output_maxsize(char *buffer, int buf_size);
%{
enum _LMP_DATATYPE_CONST {
LAMMPS_INT = 0, /*!< 32-bit integer (array) */
LAMMPS_INT_2D = 1, /*!< two-dimensional 32-bit integer array */
LAMMPS_DOUBLE = 2, /*!< 64-bit double (array) */
LAMMPS_DOUBLE_2D = 3, /*!< two-dimensional 64-bit double array */
LAMMPS_INT64 = 4, /*!< 64-bit integer (array) */
LAMMPS_INT64_2D = 5, /*!< two-dimensional 64-bit integer array */
LAMMPS_STRING = 6 /*!< C-String */
};
/** Style constants for extracting data from computes and fixes.
*
* Must be kept in sync with the equivalent constants in lammps.py */
enum _LMP_STYLE_CONST {
LMP_STYLE_GLOBAL=0, /*!< return global data */
LMP_STYLE_ATOM =1, /*!< return per-atom data */
LMP_STYLE_LOCAL =2 /*!< return local data */
};
/** Type and size constants for extracting data from computes and fixes.
*
* Must be kept in sync with the equivalent constants in lammps.py */
enum _LMP_TYPE_CONST {
LMP_TYPE_SCALAR=0, /*!< return scalar */
LMP_TYPE_VECTOR=1, /*!< return vector */
LMP_TYPE_ARRAY =2, /*!< return array */
LMP_SIZE_VECTOR=3, /*!< return length of vector */
LMP_SIZE_ROWS =4, /*!< return number of rows */
LMP_SIZE_COLS =5 /*!< return number of columns */
};
/*
extern void *lammps_open(int argc, char **argv, MPI_Comm comm, void **ptr);
*/
extern void *lammps_open_no_mpi(int argc, char **argv, void **ptr);
extern void *lammps_open_fortran(int argc, char **argv, int f_comm);
extern void lammps_close(void *handle);
extern void lammps_mpi_init();
extern void lammps_mpi_finalize();
extern void lammps_free(void *ptr);
extern void lammps_file(void *handle, const char *file);
extern char *lammps_command(void *handle, const char *cmd);
extern void lammps_commands_list(void *handle, int ncmd, const char **cmds);
extern void lammps_commands_string(void *handle, const char *str);
extern int lammps_version(void *handle);
extern void lammps_get_os_info(char *buffer, int buf_size);
extern void lammps_memory_usage(void *handle, double *meminfo);
extern int lammps_get_mpi_comm(void *handle);
extern double lammps_get_natoms(void *handle);
extern double lammps_get_thermo(void *handle, const char *keyword);
extern void lammps_extract_box(void *handle, double *boxlo, double *boxhi,
double *xy, double *yz, double *xz,
int *pflags, int *boxflag);
extern void lammps_reset_box(void *handle, double *boxlo, double *boxhi,
double xy, double yz, double xz);
extern int lammps_extract_setting(void *handle, const char *keyword);
extern void *lammps_extract_global(void *handle, const char *name);
extern void *lammps_extract_atom(void *handle, const char *name);
extern int lammps_extract_global_datatype(void *handle, const char *name);
extern int lammps_extract_atom_datatype(void *handle, const char *name);
extern int lammps_create_atoms(void *handle, int n, int *id, int *type,
double *x, double *v, int *image, int bexpand);
/*
extern int lammps_create_atoms(void *handle, int n, int64_t *id, int *type, */
extern void *lammps_extract_compute(void *handle, char *id, int, int);
extern void *lammps_extract_fix(void *handle, char *, int, int, int, int);
extern void *lammps_extract_variable(void *handle, char *, char *);
extern int lammps_set_variable(void *, char *, char *);
extern void lammps_gather(void *, char *, int, int, void *);
extern void lammps_gather_concat(void *, char *, int, int, void *);
extern void lammps_gather_subset(void *, char *, int, int, int, int *, void *);
extern void lammps_scatter(void *, char *, int, int, void *);
extern void lammps_scatter_subset(void *, char *, int, int, int, int *, void *);
extern void lammps_gather_atoms(void *, char *, int, int, void *);
extern void lammps_gather_atoms_concat(void *, char *, int, int, void *);
extern void lammps_gather_atoms_subset(void *, char *, int, int, int, int *, void *);
extern void lammps_scatter_atoms(void *, char *, int, int, void *);
extern void lammps_scatter_atoms_subset(void *, char *, int, int, int, int *, void *);
extern int lammps_config_has_mpi_support();
extern int lammps_config_has_package(const char *);
extern int lammps_config_package_count();
extern int lammps_config_package_name(int, char *, int);
extern int lammps_config_has_gzip_support();
extern int lammps_config_has_png_support();
extern int lammps_config_has_jpeg_support();
extern int lammps_config_has_ffmpeg_support();
extern int lammps_config_has_exceptions();
extern int lammps_has_style(void *, const char *, const char *);
extern int lammps_style_count(void *, const char *);
extern int lammps_style_name(void *, const char *, int, char *buffer, int buf_size);
extern int lammps_has_id(void *, const char *, const char *);
extern int lammps_id_count(void *, const char *);
extern int lammps_id_name(void *, const char *, int, char *buffer, int buf_size);
extern int lammps_find_pair_neighlist(void*, char *, int, int, int);
extern int lammps_find_fix_neighlist(void*, char *, int);
extern int lammps_find_compute_neighlist(void*, char *, int);
extern int lammps_neighlist_num_elements(void*, int);
extern void lammps_neighlist_element_neighbors(void *, int, int, int *, int *, int ** );
/*
extern int lammps_encode_image_flags(int ix, int iy, int iz);
extern void lammps_decode_image_flags(int image, int *flags);
extern int64_t lammps_encode_image_flags(int ix, int iy, int iz);
extern void lammps_decode_image_flags(int64_t image, int *flags);
extern void lammps_set_fix_external_callback(void *, char *, FixExternalFnPtr, void*);
extern void lammps_set_fix_external_callback(void *, char *, FixExternalFnPtr, void*);
extern void lammps_set_fix_external_callback(void *, char *, FixExternalFnPtr, void*);
extern void lammps_fix_external_set_energy_global(void *, char *, double);
extern void lammps_fix_external_set_virial_global(void *, char *, double *);
*/
extern int lammps_is_running(void *handle);
extern void lammps_force_timeout(void *handle);
extern int lammps_has_error(void *handle);
extern int lammps_get_last_error_message(void *handle, char *buffer, int buf_size);
%}
enum _LMP_DATATYPE_CONST {
LAMMPS_INT = 0, /*!< 32-bit integer (array) */
LAMMPS_INT_2D = 1, /*!< two-dimensional 32-bit integer array */
LAMMPS_DOUBLE = 2, /*!< 64-bit double (array) */
LAMMPS_DOUBLE_2D = 3, /*!< two-dimensional 64-bit double array */
LAMMPS_INT64 = 4, /*!< 64-bit integer (array) */
LAMMPS_INT64_2D = 5, /*!< two-dimensional 64-bit integer array */
LAMMPS_STRING = 6 /*!< C-String */
};
/** Style constants for extracting data from computes and fixes.
*
* Must be kept in sync with the equivalent constants in lammps.py */
enum _LMP_STYLE_CONST {
LMP_STYLE_GLOBAL=0, /*!< return global data */
LMP_STYLE_ATOM =1, /*!< return per-atom data */
LMP_STYLE_LOCAL =2 /*!< return local data */
};
/** Type and size constants for extracting data from computes and fixes.
*
* Must be kept in sync with the equivalent constants in lammps.py */
enum _LMP_TYPE_CONST {
LMP_TYPE_SCALAR=0, /*!< return scalar */
LMP_TYPE_VECTOR=1, /*!< return vector */
LMP_TYPE_ARRAY =2, /*!< return array */
LMP_SIZE_VECTOR=3, /*!< return length of vector */
LMP_SIZE_ROWS =4, /*!< return number of rows */
LMP_SIZE_COLS =5 /*!< return number of columns */
};
/* extern void *lammps_open(int argc, char **argv, MPI_Comm comm, void **ptr); */
extern void *lammps_open_no_mpi(int argc, char **argv, void **ptr);
extern void *lammps_open_fortran(int argc, char **argv, int f_comm);
extern void lammps_close(void *handle);
extern void lammps_mpi_init();
extern void lammps_mpi_finalize();
extern void lammps_free(void *ptr);
extern void lammps_file(void *handle, const char *file);
extern char *lammps_command(void *handle, const char *cmd);
extern void lammps_commands_list(void *handle, int ncmd, const char **cmds);
extern void lammps_commands_string(void *handle, const char *str);
extern int lammps_version(void *handle);
extern void lammps_get_os_info(char *buffer, int buf_size);
extern void lammps_memory_usage(void *handle, double *meminfo);
extern int lammps_get_mpi_comm(void *handle);
extern double lammps_get_natoms(void *handle);
extern double lammps_get_thermo(void *handle, const char *keyword);
extern void lammps_extract_box(void *handle, double *boxlo, double *boxhi,
double *xy, double *yz, double *xz,
int *pflags, int *boxflag);
extern void lammps_reset_box(void *handle, double *boxlo, double *boxhi,
double xy, double yz, double xz);
extern int lammps_extract_setting(void *handle, const char *keyword);
extern void *lammps_extract_global(void *handle, const char *name);
extern void *lammps_extract_atom(void *handle, const char *name);
extern int lammps_extract_global_datatype(void *handle, const char *name);
extern int lammps_extract_atom_datatype(void *handle, const char *name);
extern int lammps_create_atoms(void *handle, int n, int *id, int *type,
double *x, double *v, int *image, int bexpand);
/*
extern int lammps_create_atoms(void *handle, int n, int64_t *id, int *type, */
extern void *lammps_extract_compute(void *handle, char *id, int, int);
extern void *lammps_extract_fix(void *handle, char *, int, int, int, int);
extern void *lammps_extract_variable(void *handle, char *, char *);
extern int lammps_set_variable(void *, char *, char *);
extern void lammps_gather(void *, char *, int, int, void *);
extern void lammps_gather_concat(void *, char *, int, int, void *);
extern void lammps_gather_subset(void *, char *, int, int, int, int *, void *);
extern void lammps_scatter(void *, char *, int, int, void *);
extern void lammps_scatter_subset(void *, char *, int, int, int, int *, void *);
extern void lammps_gather_atoms(void *, char *, int, int, void *);
extern void lammps_gather_atoms_concat(void *, char *, int, int, void *);
extern void lammps_gather_atoms_subset(void *, char *, int, int, int, int *, void *);
extern void lammps_scatter_atoms(void *, char *, int, int, void *);
extern void lammps_scatter_atoms_subset(void *, char *, int, int, int, int *, void *);
extern int lammps_config_has_mpi_support();
extern int lammps_config_has_package(const char *);
extern int lammps_config_package_count();
extern int lammps_config_package_name(int, char *, int);
extern int lammps_config_has_gzip_support();
extern int lammps_config_has_png_support();
extern int lammps_config_has_jpeg_support();
extern int lammps_config_has_ffmpeg_support();
extern int lammps_config_has_exceptions();
extern int lammps_has_style(void *, const char *, const char *);
extern int lammps_style_count(void *, const char *);
extern int lammps_style_name(void *, const char *, int, char *buffer, int buf_size);
extern int lammps_has_id(void *, const char *, const char *);
extern int lammps_id_count(void *, const char *);
extern int lammps_id_name(void *, const char *, int, char *buffer, int buf_size);
extern int lammps_find_pair_neighlist(void*, char *, int, int, int);
extern int lammps_find_fix_neighlist(void*, char *, int);
extern int lammps_find_compute_neighlist(void*, char *, int);
extern int lammps_neighlist_num_elements(void*, int);
extern void lammps_neighlist_element_neighbors(void *, int, int, int *, int *, int ** );
/*
extern int lammps_encode_image_flags(int ix, int iy, int iz);
extern void lammps_decode_image_flags(int image, int *flags);
extern int64_t lammps_encode_image_flags(int ix, int iy, int iz);
extern void lammps_decode_image_flags(int64_t image, int *flags);
extern void lammps_set_fix_external_callback(void *, char *, FixExternalFnPtr, void*);
extern void lammps_set_fix_external_callback(void *, char *, FixExternalFnPtr, void*);
extern void lammps_set_fix_external_callback(void *, char *, FixExternalFnPtr, void*);
extern void lammps_fix_external_set_energy_global(void *, char *, double);
extern void lammps_fix_external_set_virial_global(void *, char *, double *);
*/
extern int lammps_is_running(void *handle);
extern void lammps_force_timeout(void *handle);
extern int lammps_has_error(void *handle);
extern int lammps_get_last_error_message(void *handle, char *buffer, int buf_size);

View File

@ -0,0 +1,2 @@
%include "tclsh.i"
%include "lammps.i"

63
tools/swig/run_java_example.sh Executable file
View File

@ -0,0 +1,63 @@
#!/bin/sh
if [ ! -f libjavalammps.so ]
then \
echo "Need to compile 'libjavalammps.so' first for this script to work"
exit 1
fi
cat > example.java <<EOF
public class example {
static {
System.loadLibrary("javalammps");
}
public static void main(String argv[]) {
SWIGTYPE_p_void lmp = javalammps.lammps_open_no_mpi(0, null, null);
int ver = javalammps.lammps_version(lmp);
int npair_styles = javalammps.lammps_style_count(lmp, "pair");
System.out.println("LAMMPS includes " + npair_styles + " pair styles");
javalammps.lammps_command(lmp, "units real");
javalammps.lammps_command(lmp, "lattice fcc 2.5");
javalammps.lammps_command(lmp, "region box block -5 5 -5 5 -5 5");
javalammps.lammps_command(lmp, "create_box 1 box");
javalammps.lammps_command(lmp, "create_atoms 1 box");
SWIGTYPE_p_double boxlo_p = javalammps.new_double_1d(3);
SWIGTYPE_p_double boxhi_p = javalammps.new_double_1d(3);
SWIGTYPE_p_double xy_p = javalammps.new_double_p();
SWIGTYPE_p_double yz_p = javalammps.new_double_p();
SWIGTYPE_p_double xz_p = javalammps.new_double_p();
SWIGTYPE_p_int pflags_p = javalammps.new_int_1d(3);
SWIGTYPE_p_int boxflag_p = javalammps.new_int_p();
javalammps.lammps_extract_box(lmp, boxlo_p, boxhi_p, xy_p, yz_p, xz_p, pflags_p, boxflag_p);
System.out.println("boxlo: " + javalammps.double_1d_getitem(boxlo_p, 0) + " " + javalammps.double_1d_getitem(boxlo_p, 1) + " " + javalammps.double_1d_getitem(boxlo_p, 2));
System.out.println("boxhi: " + javalammps.double_1d_getitem(boxhi_p, 0) + " " + javalammps.double_1d_getitem(boxhi_p, 1) + " " + javalammps.double_1d_getitem(boxhi_p, 2));
System.out.println("xy/yz/xz: " + javalammps.double_p_value(xy_p) + " " + javalammps.double_p_value(yz_p) + " " + javalammps.double_p_value(xz_p));
System.out.println("periodicity: " + javalammps.int_1d_getitem(pflags_p, 0) + " " + javalammps.int_1d_getitem(pflags_p, 1) + " " + javalammps.int_1d_getitem(pflags_p, 2));
System.out.println("boxflag: " + javalammps.int_p_value(boxflag_p));
javalammps.delete_double_1d(boxlo_p);
javalammps.delete_double_1d(boxhi_p);
javalammps.delete_int_1d(pflags_p);
javalammps.delete_double_p(xy_p);
javalammps.delete_double_p(yz_p);
javalammps.delete_double_p(xz_p);
javalammps.delete_int_p(boxflag_p);
System.out.println("LAMMPS version " + ver);
System.out.println("Number of created atoms: " + javalammps.lammps_get_natoms(lmp));
javalammps.lammps_close(lmp);
}
}
EOF
CLASSPATH=${PWD}:${CLASSPATH-${PWD}}
LD_LIBRARY_PATH=${PWD}:${LD_LIBARARY_PATH-${PWD}}
export CLASSPATH LD_LIBRARY_PATH
javac *.java
java example

65
tools/swig/run_lua_example.sh Executable file
View File

@ -0,0 +1,65 @@
#!/bin/sh
if [ ! -f lualammps.so ]
then \
echo "Need to compile 'lualammps.so' first for this script to work"
exit 1
fi
cat > example.lua <<EOF
require("lualammps")
-- Lua does not seem to support %cstring_output_maxsize so this
-- currently does not work and complains about a missing argument.
--
-- osinfo = lualammps.lammps_get_os_info(512)
-- print(osinfo)
lmp = lualammps.lammps_open_no_mpi(0,nil,nil)
ver = lualammps.lammps_version(lmp)
npair_styles = lualammps.lammps_style_count(lmp, "pair")
print("LAMMPS includes ", npair_styles, " pair styles")
-- this also does not work (see above)
-- for i = 0, 10, 1 do
-- res = lualammps.lammps_style_name(lmp, 'pair', i, 128)
-- print("Pair style ",i, ': ', res[1])
-- end
lualammps.lammps_command(lmp, "units real")
lualammps.lammps_command(lmp, "lattice fcc 2.5")
lualammps.lammps_command(lmp, "region box block -5 5 -5 5 -5 5")
lualammps.lammps_command(lmp, "create_box 1 box")
lualammps.lammps_command(lmp, "create_atoms 1 box")
boxlo_p = lualammps.new_double_1d(3)
boxhi_p = lualammps.new_double_1d(3)
xy_p = lualammps.new_double_p()
yz_p = lualammps.new_double_p()
xz_p = lualammps.new_double_p()
pflags_p = lualammps.new_int_1d(3)
boxflag_p = lualammps.new_int_p()
lualammps.lammps_extract_box(lmp, boxlo_p, boxhi_p, xy_p, yz_p, xz_p, pflags_p, boxflag_p)
print('boxlo: ', lualammps.double_1d_getitem(boxlo_p, 0), ' ', lualammps.double_1d_getitem(boxlo_p, 1), ' ', lualammps.double_1d_getitem(boxlo_p, 2))
print('boxhi: ', lualammps.double_1d_getitem(boxhi_p, 0), ' ', lualammps.double_1d_getitem(boxhi_p, 1), ' ', lualammps.double_1d_getitem(boxhi_p, 2))
print('xy/yz/xz: ', lualammps.double_p_value(xy_p), ' ', lualammps.double_p_value(yz_p), ' ', lualammps.double_p_value(xz_p))
print('periodicity: ', lualammps.int_1d_getitem(pflags_p, 0), ' ', lualammps.int_1d_getitem(pflags_p, 1), ' ', lualammps.int_1d_getitem(pflags_p, 2))
print('boxflag: ', lualammps.int_p_value(boxflag_p))
lualammps.delete_double_1d(boxlo_p)
lualammps.delete_double_1d(boxhi_p)
lualammps.delete_int_1d(pflags_p)
lualammps.delete_double_p(xy_p)
lualammps.delete_double_p(yz_p)
lualammps.delete_double_p(xz_p)
lualammps.delete_int_p(boxflag_p)
print("LAMMPS version ", ver)
print("Number of created atoms: ", lualammps.lammps_get_natoms(lmp))
print("Current size of timestep: ", lualammps.double_p_value(lualammps.void_p_to_double_p(lualammps.lammps_extract_global(lmp,"dt"))))
lualammps.lammps_close(lmp)
EOF
lua example.lua

66
tools/swig/run_perl_example.sh Executable file
View File

@ -0,0 +1,66 @@
#!/bin/sh
if [ ! -f pllammps.so ]
then \
echo "Need to compile 'pllammps.so' first for this script to work"
exit 1
fi
cat > example.pl <<EOF
use pllammps;
\$osinfo = pllammps::lammps_get_os_info(512);
print("\$osinfo\n");
\$lmp = pllammps::lammps_open_no_mpi(0,undef,undef);
\$ver = pllammps::lammps_version(\$lmp);
\$npair_styles = pllammps::lammps_style_count(\$lmp, "pair");
print("LAMMPS includes \$npair_styles pair styles\n");
for (my \$i=0; \$i < 10; ++\$i) {
@res = pllammps::lammps_style_name(\$lmp, "pair", \$i, 128);
if (\$res[0] == 1) {
print("Style \$i: \$res[1]\n");
}
}
pllammps::lammps_command(\$lmp, "units real");
pllammps::lammps_command(\$lmp, "lattice fcc 2.5");
pllammps::lammps_command(\$lmp, "region box block -5 5 -5 5 -5 5");
pllammps::lammps_command(\$lmp, "create_box 1 box");
pllammps::lammps_command(\$lmp, "create_atoms 1 box");
\$boxlo_p = pllammps::new_double_1d(3);
\$boxhi_p = pllammps::new_double_1d(3);
\$xy_p = pllammps::new_double_p();
\$yz_p = pllammps::new_double_p();
\$xz_p = pllammps::new_double_p();
\$pflags_p = pllammps::new_int_1d(3);
\$boxflag_p = pllammps::new_int_p();
pllammps::lammps_extract_box(\$lmp, \$boxlo_p, \$boxhi_p, \$xy_p, \$yz_p, \$xz_p, \$pflags_p, \$boxflag_p);
printf "boxlo: %g %g %g\n", pllammps::double_1d_getitem(\$boxlo_p, 0), pllammps::double_1d_getitem(\$boxlo_p, 1), pllammps::double_1d_getitem(\$boxlo_p, 2);
printf "boxhi: %g %g %g\n", pllammps::double_1d_getitem(\$boxhi_p, 0), pllammps::double_1d_getitem(\$boxhi_p, 1), pllammps::double_1d_getitem(\$boxhi_p, 2);
printf "xy/yz/xz: %g %g %g\n", pllammps::double_p_value(\$xy_p), pllammps::double_p_value(\$yz_p), pllammps::double_p_value(\$xz_p);
printf "periodicity: %d %d %d\n", pllammps::int_1d_getitem(\$pflags_p, 0), pllammps::int_1d_getitem(\$pflags_p, 1), pllammps::int_1d_getitem(\$pflags_p, 2);
printf "boxflag: %d\n", pllammps::int_p_value(\$boxflag_p);
pllammps::delete_double_1d(\$boxlo_p);
pllammps::delete_double_1d(\$boxhi_p);
pllammps::delete_int_1d(\$pflags_p);
pllammps::delete_double_p(\$xy_p);
pllammps::delete_double_p(\$yz_p);
pllammps::delete_double_p(\$xz_p);
pllammps::delete_int_p(\$boxflag_p);
print "LAMMPS version ", \$ver, "\n";
print "Number of created atoms: ", pllammps::lammps_get_natoms(\$lmp), "\n";
print "Current size of timestep: ", pllammps::double_p_value(pllammps::void_p_to_double_p(pllammps::lammps_extract_global(\$lmp,"dt"))), "\n";
pllammps::lammps_close(\$lmp)
EOF
PERL5LIB=${PWD}:${PERL5LIB-${PWD}}
export PERL5LIB
perl example.pl

View File

@ -0,0 +1,63 @@
#!/bin/sh
if [ ! -f _pylammps.so ]
then \
echo "Need to compile '_pylammps.so' first for this script to work"
exit 1
fi
cat > example.py <<EOF
from pylammps import *
osinfo = lammps_get_os_info(512)
print(osinfo)
lmp = lammps_open_no_mpi(0,None,None)
ver = lammps_version(lmp)
npair_styles = lammps_style_count(lmp, 'pair')
print("LAMMPS includes %d pair styles" % npair_styles)
for i in range(10):
found, style = lammps_style_name(lmp, 'pair', i, 128)
if found == 1: print("Style %d: " % i, style)
lammps_command(lmp, "units real")
lammps_command(lmp, "lattice fcc 2.5")
lammps_command(lmp, "region box block -5 5 -5 5 -5 5")
lammps_command(lmp, "create_box 1 box")
lammps_command(lmp, "create_atoms 1 box")
boxlo_p = new_double_1d(3)
boxhi_p = new_double_1d(3)
xy_p = new_double_p()
yz_p = new_double_p()
xz_p = new_double_p()
pflags_p = new_int_1d(3)
boxflag_p = new_int_p()
lammps_extract_box(lmp, boxlo_p, boxhi_p, xy_p, yz_p, xz_p, pflags_p, boxflag_p)
print("boxlo: %g %g %g" % (double_1d_getitem(boxlo_p, 0), double_1d_getitem(boxlo_p, 1), double_1d_getitem(boxlo_p, 2)))
print("boxhi: %g %g %g" % (double_1d_getitem(boxhi_p, 0), double_1d_getitem(boxhi_p, 1), double_1d_getitem(boxhi_p, 2)))
print("xy/yz/xz: %g %g %g" % (double_p_value(xy_p), double_p_value(yz_p), double_p_value(xz_p)))
print("periodicity: %d %d %d" % (int_1d_getitem(pflags_p, 0), int_1d_getitem(pflags_p, 1), int_1d_getitem(pflags_p, 2)))
print("boxflag: %d" % int_p_value(boxflag_p))
delete_double_1d(boxlo_p)
delete_double_1d(boxhi_p)
delete_int_1d(pflags_p)
delete_double_p(xy_p)
delete_double_p(yz_p)
delete_double_p(xz_p)
delete_int_p(boxflag_p)
print("LAMMPS version ",ver)
print("Number of created atoms: %g" % lammps_get_natoms(lmp))
print("Current size of timestep: %g" % double_p_value(void_p_to_double_p(lammps_extract_global(lmp,'dt'))))
lammps_close(lmp)
EOF
PYTHONPATH=${PWD}:${PYTHONPATH-${PWD}}
export PYTHONPATH
python example.py

63
tools/swig/run_ruby_example.sh Executable file
View File

@ -0,0 +1,63 @@
#!/bin/sh
if [ ! -f rubylammps.so ]
then \
echo "Need to compile 'rubylammps.so' first for this script to work"
exit 1
fi
cat > example.rb <<EOF
require 'rubylammps'
osinfo = Rubylammps.lammps_get_os_info(512)
puts osinfo
lmp = Rubylammps.lammps_open_no_mpi(0,nil,nil)
ver = Rubylammps.lammps_version(lmp)
npair_styles = Rubylammps.lammps_style_count(lmp, 'pair')
puts "LAMMPS includes #{npair_styles} pair styles"
(0..9).each { |i|
res = Rubylammps.lammps_style_name(lmp, 'pair', i, 128)
if res[0] == 1
puts "Pair style #{i}: #{res[1]}\n"
end
}
Rubylammps.lammps_command(lmp, 'units real')
Rubylammps.lammps_command(lmp, 'lattice fcc 2.5')
Rubylammps.lammps_command(lmp, 'region box block -5 5 -5 5 -5 5')
Rubylammps.lammps_command(lmp, 'create_box 1 box')
Rubylammps.lammps_command(lmp, 'create_atoms 1 box')
boxlo_p = Rubylammps.new_double_1d(3)
boxhi_p = Rubylammps.new_double_1d(3)
xy_p = Rubylammps.new_double_p()
yz_p = Rubylammps.new_double_p()
xz_p = Rubylammps.new_double_p()
pflags_p = Rubylammps.new_int_1d(3)
boxflag_p = Rubylammps.new_int_p()
Rubylammps.lammps_extract_box(lmp, boxlo_p, boxhi_p, xy_p, yz_p, xz_p, pflags_p, boxflag_p)
print('boxlo: ', Rubylammps.double_1d_getitem(boxlo_p, 0), ' ', Rubylammps.double_1d_getitem(boxlo_p, 1), ' ', Rubylammps.double_1d_getitem(boxlo_p, 2), "\n")
print('boxhi: ', Rubylammps.double_1d_getitem(boxhi_p, 0), ' ', Rubylammps.double_1d_getitem(boxhi_p, 1), ' ', Rubylammps.double_1d_getitem(boxhi_p, 2), "\n")
print('xy/yz/xz: ', Rubylammps.double_p_value(xy_p), ' ', Rubylammps.double_p_value(yz_p), ' ', Rubylammps.double_p_value(xz_p), "\n")
print('periodicity: ', Rubylammps.int_1d_getitem(pflags_p, 0), ' ', Rubylammps.int_1d_getitem(pflags_p, 1), ' ', Rubylammps.int_1d_getitem(pflags_p, 2), "\n")
print('boxflag: ', Rubylammps.int_p_value(boxflag_p), "\n")
Rubylammps.delete_double_1d(boxlo_p)
Rubylammps.delete_double_1d(boxhi_p)
Rubylammps.delete_int_1d(pflags_p)
Rubylammps.delete_double_p(xy_p)
Rubylammps.delete_double_p(yz_p)
Rubylammps.delete_double_p(xz_p)
Rubylammps.delete_int_p(boxflag_p)
puts "LAMMPS version #{ver}"
print('Number of created atoms: ', Rubylammps.lammps_get_natoms(lmp), "\n")
print('Current size of timestep: ', Rubylammps.double_p_value(Rubylammps.void_p_to_double_p(Rubylammps.lammps_extract_global(lmp,'dt'))), "\n")
Rubylammps.lammps_close(lmp)
EOF
export RUBYLIB=${PWD}:${RUBYLIB-${PWD}}
ruby example.rb

123
tools/swig/run_tcl_example.sh Executable file
View File

@ -0,0 +1,123 @@
#!/bin/sh
if [ ! -f tcllammps.so ]
then \
echo "Need to compile 'tcllammps.so' first for this script to work"
exit 1
fi
cat > example.tcl <<EOF
load ./tcllammps.so
set osinfo [lammps_get_os_info 512]
puts "[lindex \$osinfo 0] [lindex \$osinfo 1]"
set lmp [lammps_open_no_mpi 0 NULL NULL ]
set ver [lammps_version \$lmp]
set npair_styles [lammps_style_count \$lmp "pair"]
puts "LAMMPS includes \$npair_styles pair styles"
for {set i 0} {\$i < 10} {incr i} {
set style [lammps_style_name \$lmp "pair" \$i 128]
if {[lindex \$style 0]} {puts "Style \$i: [lindex \$style 1]"}
}
lammps_command \$lmp "units real"
lammps_command \$lmp "lattice fcc 2.5"
lammps_command \$lmp "region box block -5 5 -5 5 -5 5"
lammps_command \$lmp "create_box 1 box"
lammps_command \$lmp "create_atoms 1 box"
set boxlo_p [new_double_1d 3]
set boxhi_p [new_double_1d 3]
set xy_p [new_double_p]
set yz_p [new_double_p]
set xz_p [new_double_p]
set pflags_p [new_int_1d 3]
set boxflag_p [new_int_p]
lammps_extract_box \$lmp \$boxlo_p \$boxhi_p \$xy_p \$yz_p \$xz_p \$pflags_p \$boxflag_p
puts [format "boxlo: %g %g %g" [double_1d_getitem \$boxlo_p 0] [double_1d_getitem \$boxlo_p 1] [double_1d_getitem \$boxlo_p 2]]
puts [format "boxhi: %g %g %g" [double_1d_getitem \$boxhi_p 0] [double_1d_getitem \$boxhi_p 1] [double_1d_getitem \$boxhi_p 2]]
puts [format "xy/yz/xz: %g %g %g" [double_p_value \$xy_p] [double_p_value \$yz_p] [double_p_value \$xz_p]]
puts [format "periodicity: %d %d %d" [int_1d_getitem \$pflags_p 0] [int_1d_getitem \$pflags_p 1] [int_1d_getitem \$pflags_p 2]]
puts [format "boxflag: %d" [int_p_value \$boxflag_p]]
delete_double_1d \$boxlo_p
delete_double_1d \$boxhi_p
delete_int_1d \$pflags_p
delete_double_p \$xy_p
delete_double_p \$yz_p
delete_double_p \$xz_p
delete_int_p \$boxflag_p
set dt [double_p_value [void_p_to_double_p [lammps_extract_global \$lmp dt]]]
puts "LAMMPS version \$ver"
puts [format "Number of created atoms: %g" [lammps_get_natoms \$lmp]]
puts "Current size of timestep: \$dt"
lammps_close \$lmp
EOF
tclsh example.tcl
# now try again with static extended shell
echo '====================================================================='
if [ ! -f tcllmpsh ]
then \
echo "Need to compile 'tcllmpsh' first for this script to work"
exit 1
fi
cat > example.tcllmp <<EOF
set osinfo [lammps_get_os_info 512]
puts "[lindex \$osinfo 0] [lindex \$osinfo 1]"
set lmp [lammps_open_no_mpi 0 NULL NULL ]
set ver [lammps_version \$lmp]
set npair_styles [lammps_style_count \$lmp "pair"]
puts "LAMMPS includes \$npair_styles pair styles"
for {set i 0} {\$i < 10} {incr i} {
set style [lammps_style_name \$lmp "pair" \$i 128]
if {[lindex \$style 0]} {puts "Style \$i: [lindex \$style 1]"}
}
lammps_command \$lmp "units real"
lammps_command \$lmp "lattice fcc 2.5"
lammps_command \$lmp "region box block -5 5 -5 5 -5 5"
lammps_command \$lmp "create_box 1 box"
lammps_command \$lmp "create_atoms 1 box"
set boxlo_p [new_double_1d 3]
set boxhi_p [new_double_1d 3]
set xy_p [new_double_p]
set yz_p [new_double_p]
set xz_p [new_double_p]
set pflags_p [new_int_1d 3]
set boxflag_p [new_int_p]
lammps_extract_box \$lmp \$boxlo_p \$boxhi_p \$xy_p \$yz_p \$xz_p \$pflags_p \$boxflag_p
puts [format "boxlo: %g %g %g" [double_1d_getitem \$boxlo_p 0] [double_1d_getitem \$boxlo_p 1] [double_1d_getitem \$boxlo_p 2]]
puts [format "boxhi: %g %g %g" [double_1d_getitem \$boxhi_p 0] [double_1d_getitem \$boxhi_p 1] [double_1d_getitem \$boxhi_p 2]]
puts [format "xy/yz/xz: %g %g %g" [double_p_value \$xy_p] [double_p_value \$yz_p] [double_p_value \$xz_p]]
puts [format "periodicity: %d %d %d" [int_1d_getitem \$pflags_p 0] [int_1d_getitem \$pflags_p 1] [int_1d_getitem \$pflags_p 2]]
puts [format "boxflag: %d" [int_p_value \$boxflag_p]]
delete_double_1d \$boxlo_p
delete_double_1d \$boxhi_p
delete_int_1d \$pflags_p
delete_double_p \$xy_p
delete_double_p \$yz_p
delete_double_p \$xz_p
delete_int_p \$boxflag_p
set dt [double_p_value [void_p_to_double_p [lammps_extract_global \$lmp dt]]]
puts "LAMMPS version \$ver"
puts [format "Number of created atoms: %g" [lammps_get_natoms \$lmp]]
puts "Current size of timestep: \$dt"
lammps_close \$lmp
EOF
${PWD}/tcllmpsh example.tcllmp

5
tools/swig/tcldummy.c Normal file
View File

@ -0,0 +1,5 @@
int i_am_a_dummy_function()
{
return 0;
}