imdclient 0.2.4__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {imdclient-0.2.4 → imdclient-0.3.0}/CHANGELOG.md +39 -1
- imdclient-0.3.0/MANIFEST.in +2 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/PKG-INFO +6 -2
- {imdclient-0.2.4 → imdclient-0.3.0}/README.md +3 -1
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/IMDClient.py +299 -42
- imdclient-0.3.0/imdclient/IMDProtocol.py +467 -0
- imdclient-0.3.0/imdclient/data/gromacs/md/gromacs_v2_nst1.mdp +50 -0
- imdclient-0.3.0/imdclient/data/gromacs/md/gromacs_v2_nst8.mdp +50 -0
- imdclient-0.3.0/imdclient/data/lammps/md/lammps_v2_nst_1.in +71 -0
- imdclient-0.3.0/imdclient/data/lammps/md/lammps_v2_nst_8.in +71 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/data/lammps/md/lammps_v3_nst_1.in +1 -1
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/data/lammps/md/lammps_v3_nst_8.in +1 -1
- imdclient-0.3.0/imdclient/data/namd/md/namd_v2_nst_1.namd +51 -0
- imdclient-0.3.0/imdclient/data/namd/md/namd_v2_nst_8.namd +51 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/tests/base.py +146 -14
- imdclient-0.3.0/imdclient/tests/datafiles.py +85 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/tests/minimalreader.py +32 -2
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/tests/server.py +7 -1
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/tests/test_gromacs.py +30 -17
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/tests/test_imdclient.py +274 -47
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/tests/test_lammps.py +46 -18
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/tests/test_namd.py +37 -16
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/tests/utils.py +2 -2
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient.egg-info/PKG-INFO +6 -2
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient.egg-info/SOURCES.txt +6 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient.egg-info/requires.txt +1 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/pyproject.toml +10 -4
- imdclient-0.2.4/MANIFEST.in +0 -6
- imdclient-0.2.4/imdclient/IMDProtocol.py +0 -165
- imdclient-0.2.4/imdclient/tests/datafiles.py +0 -57
- {imdclient-0.2.4 → imdclient-0.3.0}/AUTHORS.md +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/CODE_OF_CONDUCT.md +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/LICENSE +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/__init__.py +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/data/__init__.py +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/data/gromacs/md/gromacs_struct.gro +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/data/gromacs/md/gromacs_v3.top +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/data/gromacs/md/gromacs_v3_nst1.mdp +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/data/gromacs/md/gromacs_v3_nst8.mdp +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/data/lammps/md/lammps_topol.data +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/data/namd/md/alanin.params +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/data/namd/md/alanin.pdb +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/data/namd/md/alanin.psf +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/data/namd/md/namd_v3_nst_1.namd +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/data/namd/md/namd_v3_nst_8.namd +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/tests/__init__.py +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/tests/conftest.py +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/tests/docker_testing/docker.md +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/tests/test_utils.py +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient/utils.py +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient.egg-info/dependency_links.txt +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/imdclient.egg-info/top_level.txt +0 -0
- {imdclient-0.2.4 → imdclient-0.3.0}/setup.cfg +0 -0
|
@@ -17,7 +17,44 @@ The rules for this file:
|
|
|
17
17
|
-------------------------------------------------------------------------------
|
|
18
18
|
-->
|
|
19
19
|
|
|
20
|
-
## [v0.
|
|
20
|
+
## [v0.3.0] - 2026-12-04
|
|
21
|
+
### Authors
|
|
22
|
+
@ljwoods2 @amruthesht @orbeckst
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
* IMDv2 streaming support in :class:`~imdclient.IMDClient.IMDClient` (alongside
|
|
26
|
+
existing IMDv3) (#140, PR #141)
|
|
27
|
+
* ``transmission_rate`` keyword: send ``IMD_TRATE`` after handshake on IMDv2
|
|
28
|
+
(needed for GROMACS v2 frame interval; optional on LAMMPS/NAMD where
|
|
29
|
+
transmission rate is set in the input deck) (#143, PR #141)
|
|
30
|
+
* Docker integration tests for IMDv2 with GROMACS, LAMMPS, and NAMD compatible
|
|
31
|
+
with imdv2-only builds (#140, PR #141)
|
|
32
|
+
* IMDv2 usage page (``usage_v2``) (PR #141)
|
|
33
|
+
* imdclient logo and theme colors (PR #159)
|
|
34
|
+
* Added citation for the JCTC paper
|
|
35
|
+
(DOI 10.1021/acs.jctc.6c01055) in ``CITATION.cff``, the README,
|
|
36
|
+
and the documentation (Issue #154, PR #165)
|
|
37
|
+
|
|
38
|
+
### Changed
|
|
39
|
+
* ``continue_after_disconnect`` raises :class:`ValueError` for IMDv2
|
|
40
|
+
connections (IMDv3-only feature) (PR #141)
|
|
41
|
+
* energy key "van_der_walls_energy" now correctly named "van_der_waals_energy"
|
|
42
|
+
(#161)
|
|
43
|
+
* API documentation for :class:`~imdclient.IMDClient.IMDFrame`, IMD
|
|
44
|
+
packet types, source-install instructions, and some
|
|
45
|
+
:class:`~imdclient.IMDClient.IMDClient` parameters (PR #162)
|
|
46
|
+
* Tests now also install the h5py package (not installed by the MDAnalysis PyPI
|
|
47
|
+
package by default but needed to run imdclient tests) (PR #167)
|
|
48
|
+
|
|
49
|
+
### Fixed
|
|
50
|
+
* NAMD integration tests: convert force DCD reference from kcal/(mol·Å) to
|
|
51
|
+
kJ/(mol·Å) to match IMDv3 streamed units (PR #141)
|
|
52
|
+
* Simulation container logs captured in engine integration tests when engines
|
|
53
|
+
fail to start (PR #141)
|
|
54
|
+
* `IMDServer.disconnect` call now properly sends EOF to client in all cases (PR
|
|
55
|
+
#149, see also MDAnalysis/mdanalysis#5442)
|
|
56
|
+
|
|
57
|
+
## [v0.2.4] - 2026-07-13
|
|
21
58
|
### Authors
|
|
22
59
|
@orbeckst @amruthesht
|
|
23
60
|
|
|
@@ -30,6 +67,7 @@ The rules for this file:
|
|
|
30
67
|
* improved error propagation and chaining (PR #120)
|
|
31
68
|
* warn if timeout < 1s (overly optimistic) (Issue #111, PR #120)
|
|
32
69
|
|
|
70
|
+
|
|
33
71
|
## [v0.2.3] - 2025-11-08
|
|
34
72
|
### Authors
|
|
35
73
|
@ljwoods2
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: imdclient
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Receiver for IMD v2 and v3 data from simulation engines like Gromacs, LAMMPS, and NAMD
|
|
5
5
|
Author-email: Lawson Woods <ljwoods2@asu.edu>
|
|
6
6
|
Maintainer-email: Lawson Woods <ljwoods2@asu.edu>, Amruthesh Thirumalaiswamy <athiru12@asu.edu>
|
|
7
7
|
License-Expression: MIT
|
|
8
8
|
Project-URL: source, https://github.com/becksteinlab/imdclient
|
|
9
9
|
Project-URL: documentation, https://imdclient.readthedocs.io
|
|
10
|
+
Project-URL: paper, https://doi.org/10.1021/acs.jctc.6c01055
|
|
10
11
|
Keywords: molecular simulations
|
|
11
12
|
Requires-Python: >=3.11
|
|
12
13
|
Description-Content-Type: text/markdown
|
|
@@ -19,6 +20,7 @@ Requires-Dist: pytest-xdist>=2.5; extra == "test"
|
|
|
19
20
|
Requires-Dist: pytest-cov>=3.0; extra == "test"
|
|
20
21
|
Requires-Dist: MDAnalysis; extra == "test"
|
|
21
22
|
Requires-Dist: MDAnalysisTests; extra == "test"
|
|
23
|
+
Requires-Dist: h5py; extra == "test"
|
|
22
24
|
Requires-Dist: docker-py; extra == "test"
|
|
23
25
|
Provides-Extra: doc
|
|
24
26
|
Requires-Dist: sphinx; extra == "doc"
|
|
@@ -145,4 +147,6 @@ Copyright (c) 2024-2025, imdclient [AUTHORS](https://github.com/Becksteinlab/imd
|
|
|
145
147
|
Project based on the
|
|
146
148
|
[MDAnalysis Cookiecutter](https://github.com/MDAnalysis/cookiecutter-mda) version 0.1.
|
|
147
149
|
|
|
148
|
-
**If you use IMDClient in your research, please cite
|
|
150
|
+
**If you use IMDClient in your research, please cite:**
|
|
151
|
+
|
|
152
|
+
A. Thirumalaiswamy, L. J. Woods, H. Cho, H. MacDermott-Opeskin, J. Clark, I. Alibay, Y. Zhuang, O. Beckstein, and M. Heyden. Streaming molecular dynamics simulation data for on-the-fly processing and analysis. *Journal of Chemical Theory and Computation* **2026**, *22* (18), 9260–9273. [doi:10.1021/acs.jctc.6c01055](https://doi.org/10.1021/acs.jctc.6c01055)
|
|
@@ -118,4 +118,6 @@ Copyright (c) 2024-2025, imdclient [AUTHORS](https://github.com/Becksteinlab/imd
|
|
|
118
118
|
Project based on the
|
|
119
119
|
[MDAnalysis Cookiecutter](https://github.com/MDAnalysis/cookiecutter-mda) version 0.1.
|
|
120
120
|
|
|
121
|
-
**If you use IMDClient in your research, please cite
|
|
121
|
+
**If you use IMDClient in your research, please cite:**
|
|
122
|
+
|
|
123
|
+
A. Thirumalaiswamy, L. J. Woods, H. Cho, H. MacDermott-Opeskin, J. Clark, I. Alibay, Y. Zhuang, O. Beckstein, and M. Heyden. Streaming molecular dynamics simulation data for on-the-fly processing and analysis. *Journal of Chemical Theory and Computation* **2026**, *22* (18), 9260–9273. [doi:10.1021/acs.jctc.6c01055](https://doi.org/10.1021/acs.jctc.6c01055)
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
"""
|
|
2
|
-
IMDClient module
|
|
1
|
+
"""IMDClient module
|
|
3
2
|
================
|
|
4
3
|
|
|
4
|
+
The :mod:`IMDClient` module contains the classes for managing IMD
|
|
5
|
+
connections. A user should only need :class:`IMDClient` and understand the data
|
|
6
|
+
format of :class:`IMDFrame`. The producer and buffer classes read the socket;
|
|
7
|
+
typical use does not construct them directly.
|
|
8
|
+
|
|
5
9
|
.. autoclass:: IMDClient
|
|
6
10
|
:members:
|
|
7
11
|
|
|
12
|
+
.. autoclass:: IMDFrame
|
|
13
|
+
:members:
|
|
14
|
+
|
|
8
15
|
.. autoclass:: BaseIMDProducer
|
|
9
16
|
:members:
|
|
10
17
|
:inherited-members:
|
|
@@ -20,8 +27,6 @@ IMDClient module
|
|
|
20
27
|
.. autoclass:: IMDFrameBuffer
|
|
21
28
|
:members:
|
|
22
29
|
|
|
23
|
-
.. autoclass:: IMDFrame
|
|
24
|
-
:members:
|
|
25
30
|
"""
|
|
26
31
|
|
|
27
32
|
import socket
|
|
@@ -41,6 +46,18 @@ logger = logging.getLogger(__name__)
|
|
|
41
46
|
|
|
42
47
|
class IMDClient:
|
|
43
48
|
"""
|
|
49
|
+
Class to manage an IMDv3 or IMDv2 connection.
|
|
50
|
+
|
|
51
|
+
When the class is instantiated, a connection to the MD engine at the given
|
|
52
|
+
`host` and `port` is established, the handshake is exchanged, and the go
|
|
53
|
+
command is issued to the MD engine. The format of the stream (v2 or v3) is
|
|
54
|
+
detected from the handshake. Other parameters can be used to configure how
|
|
55
|
+
interruptions to the connection are handled.
|
|
56
|
+
|
|
57
|
+
Repeated calls to :meth:`get_imdframe` read the trajectory data from the
|
|
58
|
+
stream, frame by frame at intervals configured by the transmission rate.
|
|
59
|
+
|
|
60
|
+
|
|
44
61
|
Parameters
|
|
45
62
|
----------
|
|
46
63
|
host : str
|
|
@@ -50,17 +67,57 @@ class IMDClient:
|
|
|
50
67
|
n_atoms : int
|
|
51
68
|
Number of atoms in the simulation
|
|
52
69
|
socket_bufsize : int, (optional)
|
|
53
|
-
Size of the socket buffer in bytes. Default is to use the system
|
|
54
|
-
|
|
55
|
-
|
|
70
|
+
Size of the socket buffer in bytes. Default is to use the system
|
|
71
|
+
default.
|
|
72
|
+
multithreaded : bool, optional [``True``]
|
|
73
|
+
When ``True``, two threads are used. The calling thread and an
|
|
74
|
+
additional background thread share an :class:`IMDFrameBuffer`. The
|
|
75
|
+
background thread reads the socket and stores frames in that buffer
|
|
76
|
+
for later use, and can pause or resume the simulation. When
|
|
77
|
+
``False``, only the calling thread is used and no buffer is created.
|
|
78
|
+
:meth:`get_imdframe` reads each frame directly from the socket, and
|
|
79
|
+
no pause or resume packet is sent.
|
|
80
|
+
buffer_size : int, optional
|
|
81
|
+
:class:`IMDFrameBuffer` will be filled with as many
|
|
82
|
+
:class:`IMDFrame` objects as fit in `buffer_size` bytes [``10MB``]
|
|
56
83
|
timeout : int, optional
|
|
57
84
|
Timeout for the socket in seconds [``600``]
|
|
58
85
|
continue_after_disconnect : bool, optional [``None``]
|
|
59
|
-
If True, the client will attempt to change the simulation engine's
|
|
60
|
-
non-blocking after the client disconnects. If
|
|
61
|
-
|
|
86
|
+
If True, the client will attempt to change the simulation engine's
|
|
87
|
+
waiting behavior to non-blocking after the client disconnects. If
|
|
88
|
+
False, the client will attempt to change it to blocking. If None, the
|
|
89
|
+
client will not attempt to change the simulation engine's behavior.
|
|
90
|
+
Only supported for IMDv3; must be ``None`` for IMDv2 connections.
|
|
91
|
+
transmission_rate : int, optional [``None``]
|
|
92
|
+
IMD :ref:`transmission rate <transmission-rate>` to send after the go
|
|
93
|
+
packet (for IMDv2 only). The transmission rate is the number of
|
|
94
|
+
integration steps between each IMD frame; see :doc:`protocol_v3` for
|
|
95
|
+
more details.
|
|
96
|
+
|
|
97
|
+
If ``None``, no ``IMD_TRATE`` packet is sent. IMDv2 in LAMMPS and NAMD
|
|
98
|
+
allow setting the rate in the simulation input file instead.
|
|
99
|
+
GROMACS IMDv2 ignores ``IMD-nst`` in the ``*.mdp`` file; the engine
|
|
100
|
+
starts with a default rate of 1 until the client sends ``IMD_TRATE``.
|
|
101
|
+
|
|
102
|
+
.. versionadded:: 0.3.0
|
|
62
103
|
**kwargs : dict (optional)
|
|
63
|
-
Additional keyword arguments to pass to the :class:`BaseIMDProducer`
|
|
104
|
+
Additional keyword arguments to pass to the :class:`BaseIMDProducer`
|
|
105
|
+
and :class:`IMDFrameBuffer`
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
.. warning::
|
|
110
|
+
|
|
111
|
+
When using GROMACS with IMDv2, users should set `transmission_rate`
|
|
112
|
+
explicitly. Otherwise the GROMACS default of 1 will be chosen. This
|
|
113
|
+
default setting will send every integrator time step and may impact
|
|
114
|
+
performance substantially.
|
|
115
|
+
|
|
116
|
+
.. versionadded:: 0.3.0
|
|
117
|
+
Added ``transmission_rate`` parameter to set the IMDv2 transmission
|
|
118
|
+
rate from the client (via an ``IMD_TRATE`` packet) after the go packet
|
|
119
|
+
is sent.
|
|
120
|
+
|
|
64
121
|
"""
|
|
65
122
|
|
|
66
123
|
def __init__(
|
|
@@ -71,6 +128,7 @@ class IMDClient:
|
|
|
71
128
|
socket_bufsize=None,
|
|
72
129
|
multithreaded=True,
|
|
73
130
|
continue_after_disconnect=None,
|
|
131
|
+
transmission_rate=None,
|
|
74
132
|
**kwargs,
|
|
75
133
|
):
|
|
76
134
|
|
|
@@ -87,6 +145,15 @@ class IMDClient:
|
|
|
87
145
|
self._multithreaded = multithreaded
|
|
88
146
|
self._continue_after_disconnect = continue_after_disconnect
|
|
89
147
|
|
|
148
|
+
if (
|
|
149
|
+
self._imdsinfo.version == 2
|
|
150
|
+
and self._continue_after_disconnect is not None
|
|
151
|
+
):
|
|
152
|
+
self._conn.close()
|
|
153
|
+
raise ValueError(
|
|
154
|
+
"IMDClient: continue_after_disconnect is only supported for IMDv3"
|
|
155
|
+
)
|
|
156
|
+
|
|
90
157
|
if self._multithreaded:
|
|
91
158
|
self._buf = IMDFrameBuffer(
|
|
92
159
|
self._imdsinfo,
|
|
@@ -120,6 +187,16 @@ class IMDClient:
|
|
|
120
187
|
|
|
121
188
|
self._go()
|
|
122
189
|
|
|
190
|
+
if transmission_rate is not None:
|
|
191
|
+
if self._imdsinfo.version == 2:
|
|
192
|
+
self._trate(transmission_rate)
|
|
193
|
+
elif self._imdsinfo.version == 3:
|
|
194
|
+
logger.warning(
|
|
195
|
+
"IMDClient: transmission_rate=%s was provided but is ignored for "
|
|
196
|
+
"IMDv3 and not automatically sent/set on the server.",
|
|
197
|
+
transmission_rate,
|
|
198
|
+
)
|
|
199
|
+
|
|
123
200
|
if self._multithreaded:
|
|
124
201
|
# Disconnect MUST occur. This covers typical cases (Python, IPython interpreter)
|
|
125
202
|
signal.signal(signal.SIGINT, self.signal_handler)
|
|
@@ -155,7 +232,8 @@ class IMDClient:
|
|
|
155
232
|
self._producer.start()
|
|
156
233
|
|
|
157
234
|
def signal_handler(self, *args, **kwargs):
|
|
158
|
-
"""
|
|
235
|
+
"""
|
|
236
|
+
Catch SIGINT to allow clean shutdown on CTRL+C.
|
|
159
237
|
|
|
160
238
|
This also ensures that main thread execution doesn't get stuck
|
|
161
239
|
waiting in ``buf.pop_full_imdframe()``"""
|
|
@@ -164,11 +242,14 @@ class IMDClient:
|
|
|
164
242
|
logger.debug("Shutdown success")
|
|
165
243
|
|
|
166
244
|
def get_imdframe(self):
|
|
167
|
-
"""
|
|
245
|
+
"""Method to read the next trajectory frame from the stream.
|
|
246
|
+
|
|
168
247
|
Returns
|
|
169
248
|
-------
|
|
170
249
|
IMDFrame
|
|
171
|
-
The next frame from the IMD server
|
|
250
|
+
The next frame from the IMD server; see :class:`IMDFrame` for
|
|
251
|
+
details of the data structure and how to use it.
|
|
252
|
+
|
|
172
253
|
Raises
|
|
173
254
|
------
|
|
174
255
|
EOFError
|
|
@@ -177,9 +258,10 @@ class IMDClient:
|
|
|
177
258
|
|
|
178
259
|
For API stability, errors raised in the producer thread (including
|
|
179
260
|
:class:`RuntimeError` for mismatches such as incorrect
|
|
180
|
-
atom counts) are raised eventually as
|
|
261
|
+
atom counts) are raised eventually as :exc:`EOFError`. The original
|
|
181
262
|
exception message in the case for a multithreaded client is available
|
|
182
263
|
in the error queue.
|
|
264
|
+
|
|
183
265
|
"""
|
|
184
266
|
if self._multithreaded:
|
|
185
267
|
try:
|
|
@@ -207,6 +289,8 @@ class IMDClient:
|
|
|
207
289
|
|
|
208
290
|
def get_imdsessioninfo(self):
|
|
209
291
|
"""
|
|
292
|
+
Get the session info data structure.
|
|
293
|
+
|
|
210
294
|
Returns
|
|
211
295
|
-------
|
|
212
296
|
IMDSessionInfo
|
|
@@ -248,8 +332,11 @@ class IMDClient:
|
|
|
248
332
|
|
|
249
333
|
def _await_IMD_handshake(self) -> IMDSessionInfo:
|
|
250
334
|
"""
|
|
251
|
-
Wait for the server to send
|
|
252
|
-
|
|
335
|
+
Wait for the server to send
|
|
336
|
+
:attr:`~imdclient.IMDProtocol.IMDHeaderType.IMD_HANDSHAKE`, then
|
|
337
|
+
determine IMD session information (including
|
|
338
|
+
:attr:`~imdclient.IMDProtocol.IMDHeaderType.IMD_SESSIONINFO` for
|
|
339
|
+
IMDv3).
|
|
253
340
|
"""
|
|
254
341
|
end = ">"
|
|
255
342
|
ver = None
|
|
@@ -293,13 +380,13 @@ class IMDClient:
|
|
|
293
380
|
sinfo = IMDSessionInfo(
|
|
294
381
|
version=ver,
|
|
295
382
|
endianness=end,
|
|
296
|
-
wrapped_coords=False,
|
|
297
383
|
time=False,
|
|
298
384
|
energies=True,
|
|
299
385
|
box=False,
|
|
300
386
|
positions=True,
|
|
301
387
|
velocities=False,
|
|
302
388
|
forces=False,
|
|
389
|
+
wrapped_coords=False,
|
|
303
390
|
)
|
|
304
391
|
|
|
305
392
|
elif ver == 3:
|
|
@@ -320,16 +407,32 @@ class IMDClient:
|
|
|
320
407
|
|
|
321
408
|
return sinfo
|
|
322
409
|
|
|
410
|
+
def _trate(self, rate):
|
|
411
|
+
"""
|
|
412
|
+
Send a trate packet to the server to set transmission rate.
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
.. versionadded:: 0.3.0
|
|
416
|
+
"""
|
|
417
|
+
trate = create_header_bytes(IMDHeaderType.IMD_TRATE, rate)
|
|
418
|
+
self._conn.sendall(trate)
|
|
419
|
+
logger.debug("IMDClient: Sent transmission rate %s", rate)
|
|
420
|
+
|
|
323
421
|
def _go(self):
|
|
324
422
|
"""
|
|
325
|
-
Send
|
|
326
|
-
and begin receiving data.
|
|
423
|
+
Send an :attr:`~imdclient.IMDProtocol.IMDHeaderType.IMD_GO` packet to
|
|
424
|
+
start the simulation and begin receiving data. When
|
|
425
|
+
``continue_after_disconnect`` is set, also sends
|
|
426
|
+
:attr:`~imdclient.IMDProtocol.IMDHeaderType.IMD_WAIT`.
|
|
327
427
|
"""
|
|
328
428
|
go = create_header_bytes(IMDHeaderType.IMD_GO, 0)
|
|
329
429
|
self._conn.sendall(go)
|
|
330
430
|
logger.debug("IMDClient: Sent go packet to server")
|
|
331
431
|
|
|
332
|
-
if
|
|
432
|
+
if (
|
|
433
|
+
self._continue_after_disconnect is not None
|
|
434
|
+
and self._imdsinfo.version == 3
|
|
435
|
+
):
|
|
333
436
|
wait_behavior = (int)(not self._continue_after_disconnect)
|
|
334
437
|
wait_packet = create_header_bytes(
|
|
335
438
|
IMDHeaderType.IMD_WAIT, wait_behavior
|
|
@@ -364,7 +467,11 @@ class IMDClient:
|
|
|
364
467
|
|
|
365
468
|
|
|
366
469
|
class BaseIMDProducer(threading.Thread):
|
|
367
|
-
"""
|
|
470
|
+
"""Base class for a threaded IMD stream data reader.
|
|
471
|
+
|
|
472
|
+
The producer reads frame data from the IMD stream and pushes it into the
|
|
473
|
+
:class:`IMDFrameBuffer` from where :class:`IMDClient` makes it available to
|
|
474
|
+
the user.
|
|
368
475
|
|
|
369
476
|
Parameters
|
|
370
477
|
----------
|
|
@@ -385,6 +492,7 @@ class BaseIMDProducer(threading.Thread):
|
|
|
385
492
|
Queue to hold errors produced by the producer thread
|
|
386
493
|
timeout : int, optional
|
|
387
494
|
Timeout for the socket in seconds [``600``]
|
|
495
|
+
|
|
388
496
|
"""
|
|
389
497
|
|
|
390
498
|
def __init__(
|
|
@@ -554,6 +662,13 @@ class BaseIMDProducer(threading.Thread):
|
|
|
554
662
|
|
|
555
663
|
|
|
556
664
|
class IMDProducerV2(BaseIMDProducer):
|
|
665
|
+
"""Threaded IMDv2 producer.
|
|
666
|
+
|
|
667
|
+
SeeAlso
|
|
668
|
+
-------
|
|
669
|
+
:class:`BaseIMDProducer`
|
|
670
|
+
|
|
671
|
+
"""
|
|
557
672
|
def __init__(
|
|
558
673
|
self,
|
|
559
674
|
conn,
|
|
@@ -579,9 +694,20 @@ class IMDProducerV2(BaseIMDProducer):
|
|
|
579
694
|
# Even if they are sent, energies might not be sent every frame
|
|
580
695
|
# cache the last energies received
|
|
581
696
|
|
|
582
|
-
#
|
|
697
|
+
# Consume any leading energy packets first, then handle positions.
|
|
698
|
+
# NOTE:
|
|
699
|
+
# IMDv3 implementations define a fixed per-frame packet order, but IMDv2
|
|
700
|
+
# implementations in simulation engines do not enforce ordering between
|
|
701
|
+
# packet types. Under stream connectivity issues, or in rare parallel
|
|
702
|
+
# execution cases in some engines (e.g. NAMD), an extra energy
|
|
703
|
+
# packet can slip through before the coordinate packet. We keep
|
|
704
|
+
# the last energy values seen and also warn when the leading energy packet
|
|
705
|
+
# count is more than 1, since energies may then be out of sync with the
|
|
706
|
+
# coordinates that follow. This behavior i.e. possible multiple consecutive
|
|
707
|
+
# IMD_ENERGIES packets before coordinates is an IMDv2-only exception.
|
|
583
708
|
header = self._get_header()
|
|
584
|
-
|
|
709
|
+
leading_energies = 0
|
|
710
|
+
while header.type == IMDHeaderType.IMD_ENERGIES and header.length == 1:
|
|
585
711
|
self._imdsinfo.energies = True
|
|
586
712
|
self._read(self._energies)
|
|
587
713
|
self._imdf.energies.update(
|
|
@@ -589,20 +715,22 @@ class IMDProducerV2(BaseIMDProducer):
|
|
|
589
715
|
)
|
|
590
716
|
self._prev_energies = self._imdf.energies
|
|
591
717
|
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
)
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
self._positions, dtype=f"{self._imdsinfo.endianness}f"
|
|
600
|
-
).reshape((self._n_atoms, 3)),
|
|
718
|
+
leading_energies += 1
|
|
719
|
+
|
|
720
|
+
header = self._get_header()
|
|
721
|
+
|
|
722
|
+
if leading_energies == 0 or leading_energies > 1:
|
|
723
|
+
logger.warning(
|
|
724
|
+
f"IMDProducer: Received {leading_energies} leading IMDv2 energy packets before coordinates, energy values may be out of sync with coordinates"
|
|
601
725
|
)
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
726
|
+
|
|
727
|
+
if header.type == IMDHeaderType.IMD_FCOORDS:
|
|
728
|
+
# check if the number of atoms is correct
|
|
729
|
+
if header.length != self._n_atoms:
|
|
730
|
+
raise RuntimeError(
|
|
731
|
+
f"IMDProducer: Expected n_atoms value {self._n_atoms}, got {header.length}. "
|
|
732
|
+
+ "Ensure you are using the correct topology file."
|
|
733
|
+
)
|
|
606
734
|
# If we received positions but no energies
|
|
607
735
|
# use the last energies received
|
|
608
736
|
if self._prev_energies is not None:
|
|
@@ -617,7 +745,9 @@ class IMDProducerV2(BaseIMDProducer):
|
|
|
617
745
|
).reshape((self._n_atoms, 3)),
|
|
618
746
|
)
|
|
619
747
|
else:
|
|
620
|
-
raise RuntimeError(
|
|
748
|
+
raise RuntimeError(
|
|
749
|
+
f"IMDProducer: Unexpected packet type {header.type.name}"
|
|
750
|
+
)
|
|
621
751
|
|
|
622
752
|
def _pause(self):
|
|
623
753
|
logger.debug(
|
|
@@ -653,6 +783,12 @@ class IMDProducerV2(BaseIMDProducer):
|
|
|
653
783
|
|
|
654
784
|
|
|
655
785
|
class IMDProducerV3(BaseIMDProducer):
|
|
786
|
+
"""Threaded IMDv3 producer.
|
|
787
|
+
|
|
788
|
+
SeeAlso
|
|
789
|
+
-------
|
|
790
|
+
:class:`BaseIMDProducer`
|
|
791
|
+
"""
|
|
656
792
|
def __init__(
|
|
657
793
|
self,
|
|
658
794
|
conn,
|
|
@@ -782,9 +918,10 @@ class IMDProducerV3(BaseIMDProducer):
|
|
|
782
918
|
|
|
783
919
|
|
|
784
920
|
class IMDFrameBuffer:
|
|
785
|
-
"""
|
|
786
|
-
|
|
787
|
-
|
|
921
|
+
"""Buffer for IMD frames
|
|
922
|
+
|
|
923
|
+
Acts as interface between producer (:class:`IMDProducer`) and consumer
|
|
924
|
+
(:class:`IMDClient`) threads when IMDClient runs in multithreaded mode.
|
|
788
925
|
|
|
789
926
|
Parameters
|
|
790
927
|
----------
|
|
@@ -800,6 +937,7 @@ class IMDFrameBuffer:
|
|
|
800
937
|
unpause_empty_proportion : float, optional
|
|
801
938
|
Proportion of the buffer's IMDFrames that must be empty
|
|
802
939
|
before the simulation is unpaused [``0.5``]
|
|
940
|
+
|
|
803
941
|
"""
|
|
804
942
|
|
|
805
943
|
def __init__(
|
|
@@ -972,6 +1110,125 @@ class IMDFrameBuffer:
|
|
|
972
1110
|
|
|
973
1111
|
|
|
974
1112
|
class IMDFrame:
|
|
1113
|
+
"""One simulation frame received over an IMD connection.
|
|
1114
|
+
|
|
1115
|
+
:class:`IMDFrame` is the value returned by
|
|
1116
|
+
:meth:`IMDClient.get_imdframe`. Which attributes are present depends on the
|
|
1117
|
+
negotiated :class:`~imdclient.IMDProtocol.IMDSessionInfo`: fields that the
|
|
1118
|
+
engine did not offer for the session are set to ``None``. Available array
|
|
1119
|
+
attributes are pre-allocated and then filled in-place each frame.
|
|
1120
|
+
|
|
1121
|
+
Typical consumer loop for extracting the streamed data into ``frame``::
|
|
1122
|
+
|
|
1123
|
+
client = IMDClient(host, port, n_atoms=n_atoms)
|
|
1124
|
+
while True:
|
|
1125
|
+
try:
|
|
1126
|
+
frame = client.get_imdframe()
|
|
1127
|
+
except EOFError:
|
|
1128
|
+
break
|
|
1129
|
+
# use frame.time, frame.positions, frame.energies, ...
|
|
1130
|
+
|
|
1131
|
+
.. rubric:: Frame reuse
|
|
1132
|
+
|
|
1133
|
+
In the default multithreaded mode, frame objects are pooled by
|
|
1134
|
+
:class:`IMDFrameBuffer`. The next :meth:`~IMDClient.get_imdframe` call
|
|
1135
|
+
returns the previous frame to the free slots; do not use it after that.
|
|
1136
|
+
The producer overwrites it only when that slot is needed for new data,
|
|
1137
|
+
after slots that were already free.
|
|
1138
|
+
|
|
1139
|
+
With ``multithreaded=False`` there is no buffer. Each call fills the same
|
|
1140
|
+
:class:`IMDFrame` in place, so the previous contents are gone after the
|
|
1141
|
+
next call. Copy any data you need to keep
|
|
1142
|
+
(e.g. ``frame.positions.copy()``).
|
|
1143
|
+
|
|
1144
|
+
.. rubric:: Units
|
|
1145
|
+
|
|
1146
|
+
MD engines send payloads in fixed units (see :doc:`protocol_v3`):
|
|
1147
|
+
|
|
1148
|
+
=========== =====================
|
|
1149
|
+
Quantity Unit
|
|
1150
|
+
=========== =====================
|
|
1151
|
+
Length Å
|
|
1152
|
+
Velocity Å/ps
|
|
1153
|
+
Force kJ mol⁻¹ Å⁻¹
|
|
1154
|
+
Time ps
|
|
1155
|
+
Energy kJ/mol
|
|
1156
|
+
Temperature K (absolute)
|
|
1157
|
+
=========== =====================
|
|
1158
|
+
|
|
1159
|
+
.. attention::
|
|
1160
|
+
IMDv2 engines may use engine-native units for *Energy*; interpret those
|
|
1161
|
+
values accordingly.
|
|
1162
|
+
|
|
1163
|
+
.. rubric:: Integration step
|
|
1164
|
+
|
|
1165
|
+
Prefer :attr:`step` from the time packet (64-bit) over ``energies["step"]``
|
|
1166
|
+
(32-bit, carried for IMDv2 compatibility). See the energies packet notes in
|
|
1167
|
+
:doc:`protocol_v3` for more details.
|
|
1168
|
+
|
|
1169
|
+
Parameters
|
|
1170
|
+
----------
|
|
1171
|
+
n_atoms : int
|
|
1172
|
+
Number of atoms expected in coordinate / velocity / force arrays.
|
|
1173
|
+
Must match the topology used with the live simulation.
|
|
1174
|
+
imdsinfo : IMDSessionInfo
|
|
1175
|
+
Session flags from the handshake that decide which attributes are
|
|
1176
|
+
allocated versus left as ``None``.
|
|
1177
|
+
|
|
1178
|
+
Attributes
|
|
1179
|
+
----------
|
|
1180
|
+
time : float or None
|
|
1181
|
+
Current simulation time in ps (IMDv3). ``None`` if the session has no
|
|
1182
|
+
time packets (typical for IMDv2).
|
|
1183
|
+
dt : float or None
|
|
1184
|
+
Integrator time step in ps (IMDv3). ``None`` if time packets are
|
|
1185
|
+
absent.
|
|
1186
|
+
step : int or float or None
|
|
1187
|
+
Current integration step from the time packet (IMDv3, 64-bit when
|
|
1188
|
+
transmitted). ``None`` if time packets are absent.
|
|
1189
|
+
Initialized to ``0.0`` before the first frame is parsed.
|
|
1190
|
+
energies : dict or None
|
|
1191
|
+
Energy block for this frame, or ``None`` if the session does not send
|
|
1192
|
+
energies. After parsing, keys are:
|
|
1193
|
+
|
|
1194
|
+
* ``step`` (*int*): integration step (int32 when transmitted; prefer
|
|
1195
|
+
:attr:`step` for IMDv3 analysis)
|
|
1196
|
+
* ``temperature`` (*float*): absolute temperature
|
|
1197
|
+
* ``total_energy`` (*float*): total energy
|
|
1198
|
+
* ``potential_energy`` (*float*): potential energy
|
|
1199
|
+
* ``van_der_waals_energy`` (*float*): van der Waals energy.
|
|
1200
|
+
* ``coulomb_energy`` (*float*): Coulomb / electrostatic energy
|
|
1201
|
+
* ``bonds_energy`` (*float*): bond energy
|
|
1202
|
+
* ``angles_energy`` (*float*): angle energy
|
|
1203
|
+
* ``dihedrals_energy`` (*float*): dihedral energy
|
|
1204
|
+
* ``improper_dihedrals_energy`` (*float*): improper dihedral energy
|
|
1205
|
+
|
|
1206
|
+
Under IMDv2, energies may be omitted on some frames; the producer then
|
|
1207
|
+
reuses the last received block when possible, or sets :attr:`energies`
|
|
1208
|
+
to ``None`` if none has been seen yet.
|
|
1209
|
+
box : ndarray or None
|
|
1210
|
+
Triclinic box vectors as a ``(3, 3)`` ``float32`` array, or ``None``
|
|
1211
|
+
if box packets are not part of the session. Layout matches the IMDv3
|
|
1212
|
+
box packet (three cell vectors).
|
|
1213
|
+
positions : ndarray or None
|
|
1214
|
+
Atomic coordinates as ``(n_atoms, 3)`` ``float32``, or ``None`` if
|
|
1215
|
+
coordinates are not sent. Values are in Å. Whether
|
|
1216
|
+
coordinates are wrapped is indicated by the session's
|
|
1217
|
+
``wrapped_coords`` flag from :meth:`IMDClient.get_imdsessioninfo`.
|
|
1218
|
+
velocities : ndarray or None
|
|
1219
|
+
Atomic velocities as ``(n_atoms, 3)`` ``float32``, or ``None`` if not
|
|
1220
|
+
sent. IMDv3 unit: Å/ps.
|
|
1221
|
+
forces : ndarray or None
|
|
1222
|
+
Atomic forces as ``(n_atoms, 3)`` ``float32``, or ``None`` if not
|
|
1223
|
+
sent. IMDv3 unit: kJ mol⁻¹ Å⁻¹.
|
|
1224
|
+
|
|
1225
|
+
See Also
|
|
1226
|
+
--------
|
|
1227
|
+
IMDClient.get_imdframe : Obtain the next frame from a live connection.
|
|
1228
|
+
IMDClient.get_imdsessioninfo : Inspect which fields the session provides.
|
|
1229
|
+
IMDFrameBuffer : Multithreaded frame pool that recycles these objects.
|
|
1230
|
+
"""
|
|
1231
|
+
|
|
975
1232
|
def __init__(self, n_atoms, imdsinfo):
|
|
976
1233
|
if imdsinfo.time:
|
|
977
1234
|
self.time = 0.0
|
|
@@ -987,7 +1244,7 @@ class IMDFrame:
|
|
|
987
1244
|
"temperature": 0.0,
|
|
988
1245
|
"total_energy": 0.0,
|
|
989
1246
|
"potential_energy": 0.0,
|
|
990
|
-
"
|
|
1247
|
+
"van_der_waals_energy": 0.0,
|
|
991
1248
|
"coulomb_energy": 0.0,
|
|
992
1249
|
"bonds_energy": 0.0,
|
|
993
1250
|
"angles_energy": 0.0,
|