Skip to content

Commit ddff545

Browse files
authored
Merge pull request lammps#4431 from Becksteinlab/imd-v3-integration
Interactive Molecular Dynamics [IMD] Version 3 implementation
2 parents 528770f + be62d7e commit ddff545

8 files changed

Lines changed: 986 additions & 120 deletions

File tree

cmake/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,16 @@ foreach(PKG_WITH_INCL KSPACE PYTHON ML-IAP VORONOI COLVARS ML-HDNNP MDI MOLFILE
605605
endif()
606606
endforeach()
607607

608+
# settings for misc packages and styles
609+
if(PKG_MISC)
610+
option(LAMMPS_ASYNC_IMD "Asynchronous IMD processing" OFF)
611+
mark_as_advanced(LAMMPS_ASYNC_IMD)
612+
if(LAMMPS_ASYNC_IMD)
613+
target_compile_definitions(lammps PRIVATE -DLAMMPS_ASYNC_IMD)
614+
message(STATUS "Using IMD in asynchronous mode")
615+
endif()
616+
endif()
617+
608618
# optionally enable building script wrappers using swig
609619
option(WITH_SWIG "Build scripting language wrappers with SWIG" OFF)
610620
if(WITH_SWIG)

doc/src/Build_extras.rst

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ This is the list of packages that may require additional steps.
4848
* :ref:`LEPTON <lepton>`
4949
* :ref:`MACHDYN <machdyn>`
5050
* :ref:`MDI <mdi>`
51+
* :ref:`MISC <misc>`
5152
* :ref:`ML-HDNNP <ml-hdnnp>`
5253
* :ref:`ML-IAP <mliap>`
5354
* :ref:`ML-PACE <ml-pace>`
@@ -2031,7 +2032,7 @@ TBB and MKL.
20312032
.. _mdi:
20322033

20332034
MDI package
2034-
-----------------------------
2035+
-----------
20352036

20362037
.. tabs::
20372038

@@ -2058,6 +2059,37 @@ MDI package
20582059

20592060
----------
20602061

2062+
.. _misc:
2063+
2064+
MISC package
2065+
------------
2066+
2067+
The :doc:`fix imd <fix_imd>` style in this package can be run either
2068+
synchronously (communication with IMD clients is done in the main
2069+
process) or asynchronously (the fix spawns a separate thread that can
2070+
communicate with IMD clients concurrently to the LAMMPS execution).
2071+
2072+
.. tabs::
2073+
2074+
.. tab:: CMake build
2075+
2076+
.. code-block:: bash
2077+
2078+
-D LAMMPS_ASYNC_IMD=value # Run IMD server asynchronously
2079+
# value = no (default) or yes
2080+
2081+
.. tab:: Traditional make
2082+
2083+
To enable asynchronous mode the ``-DLAMMPS_ASYNC_IMD`` define
2084+
needs to be added to the ``LMP_INC`` variable in the
2085+
``Makefile.machine`` you are using. For example:
2086+
2087+
.. code-block:: make
2088+
2089+
LMP_INC = -DLAMMPS_ASYNC_IMD -DLAMMPS_MEMALIGN=64
2090+
2091+
----------
2092+
20612093
.. _molfile:
20622094

20632095
MOLFILE package

doc/src/Build_package.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ packages:
4949
* :ref:`LEPTON <lepton>`
5050
* :ref:`MACHDYN <machdyn>`
5151
* :ref:`MDI <mdi>`
52+
* :ref:`MISC <misc>`
5253
* :ref:`ML-HDNNP <ml-hdnnp>`
5354
* :ref:`ML-IAP <mliap>`
5455
* :ref:`ML-PACE <ml-pace>`

doc/src/fix_imd.rst

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,29 @@ Syntax
2626
*nowait* arg = *on* or *off*
2727
off = LAMMPS waits to be connected to an IMD client before continuing (default)
2828
on = LAMMPS listens for an IMD client, but continues with the run
29+
*version* arg = *2* or *3*
30+
2 = use IMD protocol version 2 (default)
31+
3 = use IMD protocol version 3.
32+
33+
The following keywords are only supported for IMD protocol version 3.
34+
35+
.. parsed-literal::
36+
37+
*time* arg = *on* or *off*
38+
off = simulation time is not transmitted (default)
39+
on = simulation time is transmitted.
40+
*box* arg = *on* or *off*
41+
off = simulation box data is not transmitted (default)
42+
on = simulation box data is transmitted.
43+
*coordinates* arg = *on* or *off*
44+
off = atomic coordinates are not transmitted (default)
45+
on = atomic coordinates are transmitted.
46+
*velocities* arg = *on* or *off*
47+
off = atomic velocities are not transmitted (default)
48+
on = atomic velocities are transmitted.
49+
*forces* arg = *on* or *off*
50+
off = atomic forces are not transmitted (default)
51+
on = atomic forces are transmitted.
2952
3053
Examples
3154
""""""""
@@ -40,16 +63,19 @@ Description
4063

4164
This fix implements the "Interactive MD" (IMD) protocol which allows
4265
realtime visualization and manipulation of MD simulations through the
43-
IMD protocol, as initially implemented in VMD and NAMD. Specifically
44-
it allows LAMMPS to connect an IMD client, for example the `VMD visualization program <VMD_>`_, so that it can monitor the progress of the
45-
simulation and interactively apply forces to selected atoms.
46-
47-
If LAMMPS is compiled with the pre-processor flag -DLAMMPS_ASYNC_IMD
48-
then fix imd will use POSIX threads to spawn a IMD communication
49-
thread on MPI rank 0 in order to offload data reading and writing
50-
from the main execution thread and potentially lower the inferred
51-
latencies for slow communication links. This feature has only been
52-
tested under linux.
66+
IMD protocol, as initially implemented in VMD and NAMD. Specifically it
67+
allows LAMMPS to connect an IMD client, for example the `VMD
68+
visualization program <VMD_>`_ (currently only supports IMDv2) or the
69+
`Python IMDClient <IMDClient_>`_ (supports both IMDv2 and IMDv3), so
70+
that it can monitor the progress of the simulation and interactively
71+
apply forces to selected atoms.
72+
73+
If LAMMPS is compiled with the pre-processor flag
74+
:ref:`-DLAMMPS_ASYNC_IMD <misc>` then fix imd will use POSIX threads to
75+
spawn an IMD communication thread on MPI rank 0 in order to offload data
76+
exchange with the IMD client from the main execution thread and
77+
potentially lower the inferred latencies for slow communication
78+
links. This feature has only been tested under linux.
5379

5480
The source code for this fix includes code developed by the Theoretical
5581
and Computational Biophysics Group in the Beckman Institute for Advanced
@@ -94,6 +120,15 @@ with different units or as a measure to tweak the forces generated by
94120
the manipulation of the IMD client, this option allows to make
95121
adjustments.
96122

123+
.. versionadded:: TBD
124+
125+
In `IMDv3 <IMDv3_>`_, the IMD protocol has been extended to allow for
126+
the transmission of simulation time, box dimensions, atomic coordinates,
127+
velocities, and forces. The *version* keyword allows to select the
128+
version of the protocol to be used. The *time*, *box*, *coordinates*,
129+
*velocities*, and *forces* keywords allow to select which data is
130+
transmitted to the IMD client. The default is to transmit all data.
131+
97132
To connect VMD to a listening LAMMPS simulation on the same machine
98133
with fix imd enabled, one needs to start VMD and load a coordinate or
99134
topology file that matches the fix group. When the VMD command
@@ -129,6 +164,10 @@ screen output is active.
129164

130165
.. _imdvmd: https://www.ks.uiuc.edu/Research/vmd/imd/
131166

167+
.. _IMDClient: https://github.com/Becksteinlab/imdclient/tree/main/imdclient
168+
169+
.. _IMDv3: https://imdclient.readthedocs.io/en/latest/protocol_v3.html
170+
132171
Restart, fix_modify, output, run start/stop, minimize info
133172
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
134173

@@ -147,14 +186,14 @@ This fix is part of the MISC package. It is only enabled if LAMMPS was
147186
built with that package. See the :doc:`Build package <Build_package>`
148187
page for more info.
149188

150-
When used in combination with VMD, a topology or coordinate file has
151-
to be loaded, which matches (in number and ordering of atoms) the
152-
group the fix is applied to. The fix internally sorts atom IDs by
153-
ascending integer value; in VMD (and thus the IMD protocol) those will
154-
be assigned 0-based consecutive index numbers.
189+
When used in combination with VMD, a topology or coordinate file has to
190+
be loaded, which matches (in number and ordering of atoms) the group the
191+
fix is applied to. The fix internally sorts atom IDs by ascending
192+
integer value; in VMD (and thus the IMD protocol) those will be assigned
193+
0-based consecutive index numbers.
155194

156195
When using multiple active IMD connections at the same time, each
157-
needs to use a different port number.
196+
fix instance needs to use a different port number.
158197

159198
Related commands
160199
""""""""""""""""
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
For use with 'in.deca-ala-solv_imd_v3'.
3+
4+
Tested with imdclient v0.1.4 and MDAnalysis v2.8.0
5+
"""
6+
from imdclient.IMD import IMDReader
7+
import MDAnalysis as mda
8+
9+
u = mda.Universe('data.deca-ala-solv', "imd://localhost:5678", topology_format='DATA')
10+
11+
for ts in u.trajectory:
12+
print(ts.time)
13+
print(ts.velocities)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
units real
3+
neighbor 2.5 bin
4+
neigh_modify delay 1 every 1
5+
6+
atom_style full
7+
bond_style harmonic
8+
angle_style charmm
9+
dihedral_style charmm
10+
improper_style harmonic
11+
12+
pair_style lj/charmm/coul/long 8 10
13+
pair_modify mix arithmetic
14+
special_bonds charmm
15+
read_data data.deca-ala-solv
16+
17+
18+
group peptide id <= 103
19+
fix rigidh all shake 1e-6 100 1000 t 1 2 3 4 5 a 23
20+
21+
thermo 100
22+
thermo_style multi
23+
timestep 2.0
24+
kspace_style pppm 1e-5
25+
26+
fix ensemble all npt temp 300.0 300.0 100.0 iso 1.0 1.0 1000.0 drag 0.2
27+
28+
# IMD setup. Client code available in 'deca-ala-solv_imd_v3.py'
29+
fix comm all imd 5678 unwrap on trate 10 version 3 time on box on coordinates on velocities on forces off
30+
31+
run 5000000

0 commit comments

Comments
 (0)