imdclient 0.2.2__tar.gz → 0.2.4__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.2 → imdclient-0.2.4}/CHANGELOG.md +35 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/PKG-INFO +5 -5
- {imdclient-0.2.2 → imdclient-0.2.4}/README.md +1 -1
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/IMDClient.py +62 -29
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/tests/server.py +4 -2
- imdclient-0.2.4/imdclient/tests/test_imdclient.py +408 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient.egg-info/PKG-INFO +5 -5
- {imdclient-0.2.2 → imdclient-0.2.4}/pyproject.toml +3 -3
- imdclient-0.2.2/imdclient/tests/test_imdclient.py +0 -239
- {imdclient-0.2.2 → imdclient-0.2.4}/AUTHORS.md +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/CODE_OF_CONDUCT.md +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/LICENSE +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/MANIFEST.in +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/IMDProtocol.py +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/__init__.py +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/data/__init__.py +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/data/gromacs/md/gromacs_struct.gro +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/data/gromacs/md/gromacs_v3.top +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/data/gromacs/md/gromacs_v3_nst1.mdp +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/data/gromacs/md/gromacs_v3_nst8.mdp +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/data/lammps/md/lammps_topol.data +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/data/lammps/md/lammps_v3_nst_1.in +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/data/lammps/md/lammps_v3_nst_8.in +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/data/namd/md/alanin.params +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/data/namd/md/alanin.pdb +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/data/namd/md/alanin.psf +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/data/namd/md/namd_v3_nst_1.namd +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/data/namd/md/namd_v3_nst_8.namd +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/tests/__init__.py +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/tests/base.py +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/tests/conftest.py +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/tests/datafiles.py +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/tests/docker_testing/docker.md +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/tests/minimalreader.py +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/tests/test_gromacs.py +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/tests/test_lammps.py +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/tests/test_namd.py +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/tests/test_utils.py +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/tests/utils.py +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient/utils.py +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient.egg-info/SOURCES.txt +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient.egg-info/dependency_links.txt +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient.egg-info/requires.txt +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/imdclient.egg-info/top_level.txt +0 -0
- {imdclient-0.2.2 → imdclient-0.2.4}/setup.cfg +0 -0
|
@@ -14,8 +14,43 @@ The rules for this file:
|
|
|
14
14
|
* 79 char width
|
|
15
15
|
* YYYY-MM-DD date format (following ISO 8601)
|
|
16
16
|
* accompany each entry with github issue/PR number (Issue #xyz)
|
|
17
|
+
-------------------------------------------------------------------------------
|
|
17
18
|
-->
|
|
18
19
|
|
|
20
|
+
## [v0.2.4] - UNPUBLISHED
|
|
21
|
+
### Authors
|
|
22
|
+
@orbeckst @amruthesht
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
* support Python 3.11--3.14 following SPEC0 (#124)
|
|
26
|
+
* timeout default value changed to 600s (was 5s) so that stream from a running
|
|
27
|
+
simulation is not prematurely killed with infrequent updates (#111)
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
* improved error propagation and chaining (PR #120)
|
|
31
|
+
* warn if timeout < 1s (overly optimistic) (Issue #111, PR #120)
|
|
32
|
+
|
|
33
|
+
## [v0.2.3] - 2025-11-08
|
|
34
|
+
### Authors
|
|
35
|
+
@ljwoods2
|
|
36
|
+
|
|
37
|
+
### Changed
|
|
38
|
+
|
|
39
|
+
### Added
|
|
40
|
+
|
|
41
|
+
### Fixed
|
|
42
|
+
* Changed signal handler method to accept arbitrary args to prevent
|
|
43
|
+
error being raised in new jupyter version (Issue #116, PR #117)
|
|
44
|
+
* Removed timeout changes during pause/resume for IMDv2 and IMDv3
|
|
45
|
+
(Issue #96, PR #118)
|
|
46
|
+
|
|
47
|
+
### Deprecated
|
|
48
|
+
<!-- Soon-to-be removed features -->
|
|
49
|
+
|
|
50
|
+
### Removed
|
|
51
|
+
<!-- Removed features -->
|
|
52
|
+
|
|
53
|
+
|
|
19
54
|
## [v0.2.2] - 2025-07-20
|
|
20
55
|
### Authors
|
|
21
56
|
@hmacdope
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: imdclient
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Receiver for IMD v2 and v3 data from simulation engines like Gromacs, LAMMPS, and NAMD
|
|
5
|
-
Author-email: Lawson <ljwoods2@asu.edu>
|
|
6
|
-
Maintainer-email: Lawson <ljwoods2@asu.edu>, Amruthesh Thirumalaiswamy <athiru12@asu.edu>
|
|
5
|
+
Author-email: Lawson Woods <ljwoods2@asu.edu>
|
|
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
10
|
Keywords: molecular simulations
|
|
11
|
-
Requires-Python: >=3.
|
|
11
|
+
Requires-Python: >=3.11
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
14
|
License-File: AUTHORS.md
|
|
@@ -52,7 +52,7 @@ IMDClient is bound by a [Code of Conduct](https://github.com/becksteinlab/imdcli
|
|
|
52
52
|
|
|
53
53
|
### Installation
|
|
54
54
|
|
|
55
|
-
IMDClient requires Python 3.
|
|
55
|
+
IMDClient requires Python 3.11 or higher.
|
|
56
56
|
|
|
57
57
|
#### Install via mamba (recommended)
|
|
58
58
|
To install the latest release of IMDClient from conda-forge:
|
|
@@ -25,7 +25,7 @@ IMDClient is bound by a [Code of Conduct](https://github.com/becksteinlab/imdcli
|
|
|
25
25
|
|
|
26
26
|
### Installation
|
|
27
27
|
|
|
28
|
-
IMDClient requires Python 3.
|
|
28
|
+
IMDClient requires Python 3.11 or higher.
|
|
29
29
|
|
|
30
30
|
#### Install via mamba (recommended)
|
|
31
31
|
To install the latest release of IMDClient from conda-forge:
|
|
@@ -54,7 +54,7 @@ class IMDClient:
|
|
|
54
54
|
buffer_size : int (optional)
|
|
55
55
|
:class:`IMDFrameBuffer` will be filled with as many :class:`IMDFrame` fit in `buffer_size` bytes [``10MB``]
|
|
56
56
|
timeout : int, optional
|
|
57
|
-
Timeout for the socket in seconds [``
|
|
57
|
+
Timeout for the socket in seconds [``600``]
|
|
58
58
|
continue_after_disconnect : bool, optional [``None``]
|
|
59
59
|
If True, the client will attempt to change the simulation engine's waiting behavior to
|
|
60
60
|
non-blocking after the client disconnects. If False, the client will attempt to change it
|
|
@@ -74,6 +74,13 @@ class IMDClient:
|
|
|
74
74
|
**kwargs,
|
|
75
75
|
):
|
|
76
76
|
|
|
77
|
+
# Warn if timeout is overly optimistic
|
|
78
|
+
if "timeout" in kwargs and kwargs["timeout"] <= 1:
|
|
79
|
+
logger.warning(
|
|
80
|
+
f"IMDClient: timeout value of {kwargs['timeout']} second(s) is very low and may lead to "
|
|
81
|
+
"premature disconnection by the client. Consider using a higher value (default is 600 seconds)."
|
|
82
|
+
)
|
|
83
|
+
|
|
77
84
|
self._stopped = False
|
|
78
85
|
self._conn = self._connect_to_server(host, port, socket_bufsize)
|
|
79
86
|
self._imdsinfo = self._await_IMD_handshake()
|
|
@@ -147,7 +154,7 @@ class IMDClient:
|
|
|
147
154
|
|
|
148
155
|
self._producer.start()
|
|
149
156
|
|
|
150
|
-
def signal_handler(self):
|
|
157
|
+
def signal_handler(self, *args, **kwargs):
|
|
151
158
|
"""Catch SIGINT to allow clean shutdown on CTRL+C.
|
|
152
159
|
|
|
153
160
|
This also ensures that main thread execution doesn't get stuck
|
|
@@ -165,26 +172,38 @@ class IMDClient:
|
|
|
165
172
|
Raises
|
|
166
173
|
------
|
|
167
174
|
EOFError
|
|
168
|
-
If there are no more frames to read from the stream
|
|
175
|
+
If there are no more frames to read from the stream, or if the
|
|
176
|
+
producer thread stopped due to an error.
|
|
177
|
+
|
|
178
|
+
For API stability, errors raised in the producer thread (including
|
|
179
|
+
:class:`RuntimeError` for mismatches such as incorrect
|
|
180
|
+
atom counts) are raised eventually as ``EOFError``s. The original
|
|
181
|
+
exception message in the case for a multithreaded client is available
|
|
182
|
+
in the error queue.
|
|
169
183
|
"""
|
|
170
184
|
if self._multithreaded:
|
|
171
185
|
try:
|
|
172
186
|
return self._buf.pop_full_imdframe()
|
|
173
|
-
except EOFError:
|
|
187
|
+
except EOFError as e:
|
|
174
188
|
# in this case, consumer is already finished
|
|
175
189
|
# and doesn't need to be notified
|
|
190
|
+
logger.debug(f"IMDClient: Multithreaded connection ended")
|
|
176
191
|
self._disconnect()
|
|
177
192
|
self._stopped = True
|
|
178
193
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
194
|
+
try:
|
|
195
|
+
error = self._error_queue.get_nowait()
|
|
196
|
+
except queue.Empty:
|
|
197
|
+
raise EOFError from e
|
|
198
|
+
else:
|
|
199
|
+
raise EOFError(str(error)) from error
|
|
182
200
|
else:
|
|
183
201
|
try:
|
|
184
202
|
return self._producer._get_imdframe()
|
|
185
|
-
except EOFError:
|
|
203
|
+
except EOFError as e:
|
|
204
|
+
logger.debug(f"IMDClient: Single-threaded connection ended")
|
|
186
205
|
self._disconnect()
|
|
187
|
-
raise EOFError
|
|
206
|
+
raise EOFError from e
|
|
188
207
|
|
|
189
208
|
def get_imdsessioninfo(self):
|
|
190
209
|
"""
|
|
@@ -242,7 +261,9 @@ class IMDClient:
|
|
|
242
261
|
read_into_buf(self._conn, h_buf)
|
|
243
262
|
except (ConnectionError, TimeoutError, Exception) as e:
|
|
244
263
|
logger.debug("IMDClient: No handshake packet received: %s", e)
|
|
245
|
-
raise ConnectionError(
|
|
264
|
+
raise ConnectionError(
|
|
265
|
+
"IMDClient: No handshake packet received"
|
|
266
|
+
) from e
|
|
246
267
|
|
|
247
268
|
header = IMDHeader(h_buf)
|
|
248
269
|
|
|
@@ -363,7 +384,7 @@ class BaseIMDProducer(threading.Thread):
|
|
|
363
384
|
error_queue: queue.Queue
|
|
364
385
|
Queue to hold errors produced by the producer thread
|
|
365
386
|
timeout : int, optional
|
|
366
|
-
Timeout for the socket in seconds [``
|
|
387
|
+
Timeout for the socket in seconds [``600``]
|
|
367
388
|
"""
|
|
368
389
|
|
|
369
390
|
def __init__(
|
|
@@ -374,7 +395,7 @@ class BaseIMDProducer(threading.Thread):
|
|
|
374
395
|
n_atoms,
|
|
375
396
|
multithreaded,
|
|
376
397
|
error_queue,
|
|
377
|
-
timeout=
|
|
398
|
+
timeout=600,
|
|
378
399
|
**kwargs,
|
|
379
400
|
):
|
|
380
401
|
super(BaseIMDProducer, self).__init__(daemon=True)
|
|
@@ -425,7 +446,8 @@ class BaseIMDProducer(threading.Thread):
|
|
|
425
446
|
try:
|
|
426
447
|
self._parse_imdframe()
|
|
427
448
|
except EOFError as e:
|
|
428
|
-
|
|
449
|
+
logger.debug(f"IMDProducer: No more frames to read: {e}")
|
|
450
|
+
raise EOFError from e
|
|
429
451
|
except Exception as e:
|
|
430
452
|
raise RuntimeError("An unexpected error occurred") from e
|
|
431
453
|
|
|
@@ -469,11 +491,13 @@ class BaseIMDProducer(threading.Thread):
|
|
|
469
491
|
self._frame,
|
|
470
492
|
t.elapsed,
|
|
471
493
|
)
|
|
472
|
-
except EOFError:
|
|
494
|
+
except EOFError as e:
|
|
473
495
|
# simulation ended in a way
|
|
474
496
|
# that we expected
|
|
475
497
|
# i.e. consumer stopped or read_into_buf didn't find
|
|
476
498
|
# full token of data
|
|
499
|
+
logger.debug("IMDProducer: %s", e)
|
|
500
|
+
self.error_queue.put(e)
|
|
477
501
|
logger.debug("IMDProducer: Simulation ended normally, cleaning up")
|
|
478
502
|
except Exception as e:
|
|
479
503
|
logger.debug("IMDProducer: An unexpected error occurred: %s", e)
|
|
@@ -484,7 +508,6 @@ class BaseIMDProducer(threading.Thread):
|
|
|
484
508
|
self._buf.notify_producer_finished()
|
|
485
509
|
|
|
486
510
|
def _expect_header(self, expected_type, expected_value=None):
|
|
487
|
-
|
|
488
511
|
header = self._get_header()
|
|
489
512
|
|
|
490
513
|
if header.type != expected_type:
|
|
@@ -515,13 +538,19 @@ class BaseIMDProducer(threading.Thread):
|
|
|
515
538
|
"""Wraps `read_into_buf` call to give uniform error handling which indicates end of stream"""
|
|
516
539
|
try:
|
|
517
540
|
read_into_buf(self._conn, buf)
|
|
518
|
-
except (ConnectionError, TimeoutError, BlockingIOError, Exception):
|
|
519
541
|
# ConnectionError: Server is definitely done sending frames, socket is closed
|
|
520
542
|
# TimeoutError: Server is *likely* done sending frames.
|
|
521
543
|
# BlockingIOError: Occurs when timeout is 0 in place of a TimeoutError. Server is *likely* done sending frames
|
|
522
544
|
# OSError: Occurs when main thread disconnects from the server and closes the socket, but producer thread attempts to read another frame
|
|
523
545
|
# Exception: Something unexpected happened
|
|
524
|
-
|
|
546
|
+
except ConnectionError as e:
|
|
547
|
+
raise EOFError("Server is definitely done sending frames") from e
|
|
548
|
+
except TimeoutError as e:
|
|
549
|
+
raise EOFError("Server is likely done sending frames") from e
|
|
550
|
+
except BlockingIOError as e:
|
|
551
|
+
raise EOFError("Server is likely done sending frames") from e
|
|
552
|
+
except Exception as e:
|
|
553
|
+
raise EOFError("Something unexpected happened") from e
|
|
525
554
|
|
|
526
555
|
|
|
527
556
|
class IMDProducerV2(BaseIMDProducer):
|
|
@@ -591,7 +620,6 @@ class IMDProducerV2(BaseIMDProducer):
|
|
|
591
620
|
raise RuntimeError("IMDProducer: Unexpected packet type or length")
|
|
592
621
|
|
|
593
622
|
def _pause(self):
|
|
594
|
-
self._conn.settimeout(0)
|
|
595
623
|
logger.debug(
|
|
596
624
|
"IMDProducer: Pausing simulation because buffer is almost full"
|
|
597
625
|
)
|
|
@@ -600,14 +628,15 @@ class IMDProducerV2(BaseIMDProducer):
|
|
|
600
628
|
self._conn.sendall(pause)
|
|
601
629
|
except ConnectionResetError as e:
|
|
602
630
|
# Simulation has already ended by the time we paused
|
|
603
|
-
raise EOFError
|
|
631
|
+
raise EOFError(
|
|
632
|
+
"Simulation has already ended by the time we paused"
|
|
633
|
+
) from e
|
|
604
634
|
# Edge case: pause occured in the time between server sends its last frame
|
|
605
635
|
# and closing socket
|
|
606
636
|
# Simulation is not actually paused but is over, but we still want to read remaining data
|
|
607
637
|
# from the socket
|
|
608
638
|
|
|
609
639
|
def _unpause(self):
|
|
610
|
-
self._conn.settimeout(self._timeout)
|
|
611
640
|
logger.debug("IMDProducer: Unpausing simulation, buffer has space")
|
|
612
641
|
unpause = create_header_bytes(IMDHeaderType.IMD_PAUSE, 0)
|
|
613
642
|
try:
|
|
@@ -616,7 +645,9 @@ class IMDProducerV2(BaseIMDProducer):
|
|
|
616
645
|
# Edge case: pause occured in the time between server sends its last frame
|
|
617
646
|
# and closing socket
|
|
618
647
|
# Simulation was never actually paused in this case and is now over
|
|
619
|
-
raise EOFError
|
|
648
|
+
raise EOFError(
|
|
649
|
+
"Simulation was never actually paused as pause was sent after the last frame; simulation is now over"
|
|
650
|
+
) from e
|
|
620
651
|
# Edge case: pause & unpause occured in the time between server sends its last frame and closing socket
|
|
621
652
|
# in this case, the simulation isn't actually unpaused but over
|
|
622
653
|
|
|
@@ -658,7 +689,6 @@ class IMDProducerV3(BaseIMDProducer):
|
|
|
658
689
|
self._forces = bytearray(xvf_bytes)
|
|
659
690
|
|
|
660
691
|
def _pause(self):
|
|
661
|
-
self._conn.settimeout(0)
|
|
662
692
|
logger.debug(
|
|
663
693
|
"IMDProducer: Pausing simulation because buffer is almost full"
|
|
664
694
|
)
|
|
@@ -667,14 +697,15 @@ class IMDProducerV3(BaseIMDProducer):
|
|
|
667
697
|
self._conn.sendall(pause)
|
|
668
698
|
except ConnectionResetError as e:
|
|
669
699
|
# Simulation has already ended by the time we paused
|
|
670
|
-
raise EOFError
|
|
700
|
+
raise EOFError(
|
|
701
|
+
"Simulation has already ended by the time we paused"
|
|
702
|
+
) from e
|
|
671
703
|
# Edge case: pause occured in the time between server sends its last frame
|
|
672
704
|
# and closing socket
|
|
673
705
|
# Simulation is not actually paused but is over, but we still want to read remaining data
|
|
674
706
|
# from the socket
|
|
675
707
|
|
|
676
708
|
def _unpause(self):
|
|
677
|
-
self._conn.settimeout(self._timeout)
|
|
678
709
|
logger.debug("IMDProducer: Unpausing simulation, buffer has space")
|
|
679
710
|
unpause = create_header_bytes(IMDHeaderType.IMD_RESUME, 0)
|
|
680
711
|
try:
|
|
@@ -683,7 +714,9 @@ class IMDProducerV3(BaseIMDProducer):
|
|
|
683
714
|
# Edge case: pause occured in the time between server sends its last frame
|
|
684
715
|
# and closing socket
|
|
685
716
|
# Simulation was never actually paused in this case and is now over
|
|
686
|
-
raise EOFError
|
|
717
|
+
raise EOFError(
|
|
718
|
+
"Simulation was never actually paused as pause was sent after the last frame; simulation is now over"
|
|
719
|
+
) from e
|
|
687
720
|
# Edge case: pause & unpause occured in the time between server sends its last frame and closing socket
|
|
688
721
|
# in this case, the simulation isn't actually unpaused but over
|
|
689
722
|
|
|
@@ -858,9 +891,10 @@ class IMDFrameBuffer:
|
|
|
858
891
|
|
|
859
892
|
if self._consumer_finished:
|
|
860
893
|
logger.debug("IMDProducer: Noticing consumer finished")
|
|
861
|
-
raise EOFError
|
|
894
|
+
raise EOFError("Consumer has finished")
|
|
862
895
|
except Exception as e:
|
|
863
896
|
logger.debug(f"IMDProducer: Error waiting for space in buffer: {e}")
|
|
897
|
+
raise RuntimeError("Error waiting for space in buffer") from e
|
|
864
898
|
|
|
865
899
|
def pop_empty_imdframe(self):
|
|
866
900
|
logger.debug("IMDProducer: Getting empty frame")
|
|
@@ -876,7 +910,7 @@ class IMDFrameBuffer:
|
|
|
876
910
|
|
|
877
911
|
if self._consumer_finished:
|
|
878
912
|
logger.debug("IMDProducer: Noticing consumer finished")
|
|
879
|
-
raise EOFError
|
|
913
|
+
raise EOFError("Consumer has finished")
|
|
880
914
|
|
|
881
915
|
return self._empty_q.get()
|
|
882
916
|
|
|
@@ -911,7 +945,7 @@ class IMDFrameBuffer:
|
|
|
911
945
|
|
|
912
946
|
if self._producer_finished and self._full_q.qsize() == 0:
|
|
913
947
|
logger.debug("IMDFrameBuffer(Consumer): Producer finished")
|
|
914
|
-
raise EOFError
|
|
948
|
+
raise EOFError("Producer has finished")
|
|
915
949
|
|
|
916
950
|
imdf = self._full_q.get()
|
|
917
951
|
|
|
@@ -938,7 +972,6 @@ class IMDFrameBuffer:
|
|
|
938
972
|
|
|
939
973
|
|
|
940
974
|
class IMDFrame:
|
|
941
|
-
|
|
942
975
|
def __init__(self, n_atoms, imdsinfo):
|
|
943
976
|
if imdsinfo.time:
|
|
944
977
|
self.time = 0.0
|
|
@@ -37,7 +37,7 @@ class InThreadIMDServer:
|
|
|
37
37
|
@property
|
|
38
38
|
def port(self):
|
|
39
39
|
"""Get the port the server is bound to.
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
Returns:
|
|
42
42
|
int: The port number, or None if not bound yet.
|
|
43
43
|
"""
|
|
@@ -47,7 +47,9 @@ class InThreadIMDServer:
|
|
|
47
47
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
48
48
|
s.bind((host, 0)) # Bind to port 0 to get a free port
|
|
49
49
|
self._bound_port = s.getsockname()[1] # Store the actual bound port
|
|
50
|
-
logger.debug(
|
|
50
|
+
logger.debug(
|
|
51
|
+
f"InThreadIMDServer: Listening on {host}:{self._bound_port}"
|
|
52
|
+
)
|
|
51
53
|
s.listen(60)
|
|
52
54
|
self.listen_socket = s
|
|
53
55
|
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
"""Test for IMDClient functionality"""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import sys
|
|
5
|
+
import time
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
from numpy.testing import (
|
|
9
|
+
assert_allclose,
|
|
10
|
+
)
|
|
11
|
+
import MDAnalysis as mda
|
|
12
|
+
from MDAnalysisTests.datafiles import (
|
|
13
|
+
COORDINATES_TOPOLOGY,
|
|
14
|
+
COORDINATES_H5MD,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
from imdclient.IMDClient import (
|
|
18
|
+
IMDFrameBuffer,
|
|
19
|
+
imdframe_memsize,
|
|
20
|
+
IMDClient,
|
|
21
|
+
)
|
|
22
|
+
from imdclient.IMDProtocol import IMDHeaderType
|
|
23
|
+
from .utils import (
|
|
24
|
+
create_default_imdsinfo_v3,
|
|
25
|
+
)
|
|
26
|
+
from .server import InThreadIMDServer
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
logger = logging.getLogger("imdclient.IMDClient")
|
|
30
|
+
file_handler = logging.FileHandler("test.log")
|
|
31
|
+
formatter = logging.Formatter(
|
|
32
|
+
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
|
33
|
+
)
|
|
34
|
+
file_handler.setFormatter(formatter)
|
|
35
|
+
logger.addHandler(file_handler)
|
|
36
|
+
logger.setLevel(logging.DEBUG)
|
|
37
|
+
|
|
38
|
+
IMDENERGYKEYS = [
|
|
39
|
+
"step",
|
|
40
|
+
"temperature",
|
|
41
|
+
"total_energy",
|
|
42
|
+
"potential_energy",
|
|
43
|
+
"van_der_walls_energy",
|
|
44
|
+
"coulomb_energy",
|
|
45
|
+
"bonds_energy",
|
|
46
|
+
"angles_energy",
|
|
47
|
+
"dihedrals_energy",
|
|
48
|
+
"improper_dihedrals_energy",
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class TestIMDClientV3:
|
|
53
|
+
|
|
54
|
+
@pytest.fixture
|
|
55
|
+
def universe(self):
|
|
56
|
+
return mda.Universe(COORDINATES_TOPOLOGY, COORDINATES_H5MD)
|
|
57
|
+
|
|
58
|
+
@pytest.fixture
|
|
59
|
+
def imdsinfo(self):
|
|
60
|
+
return create_default_imdsinfo_v3()
|
|
61
|
+
|
|
62
|
+
@pytest.fixture
|
|
63
|
+
def server_client(self, universe, imdsinfo):
|
|
64
|
+
created = []
|
|
65
|
+
|
|
66
|
+
def _server_client(endianness=None, **client_kwargs):
|
|
67
|
+
server = InThreadIMDServer(universe.trajectory)
|
|
68
|
+
if endianness is not None:
|
|
69
|
+
imdsinfo.endianness = endianness
|
|
70
|
+
server.set_imdsessioninfo(imdsinfo)
|
|
71
|
+
|
|
72
|
+
n_atoms = client_kwargs.pop("n_atoms", universe.atoms.n_atoms)
|
|
73
|
+
server.handshake_sequence("localhost", first_frame=False)
|
|
74
|
+
client = IMDClient(
|
|
75
|
+
"localhost",
|
|
76
|
+
server.port,
|
|
77
|
+
n_atoms,
|
|
78
|
+
**client_kwargs,
|
|
79
|
+
)
|
|
80
|
+
server.join_accept_thread()
|
|
81
|
+
created.append((server, client))
|
|
82
|
+
return server, client
|
|
83
|
+
|
|
84
|
+
yield _server_client
|
|
85
|
+
|
|
86
|
+
# Teardown: stop clients and cleanup servers
|
|
87
|
+
for server, client in created:
|
|
88
|
+
try:
|
|
89
|
+
client.stop()
|
|
90
|
+
except Exception:
|
|
91
|
+
pass
|
|
92
|
+
try:
|
|
93
|
+
server.cleanup()
|
|
94
|
+
except Exception:
|
|
95
|
+
pass
|
|
96
|
+
|
|
97
|
+
@pytest.fixture
|
|
98
|
+
def server_client_two_frame_buf(self, server_client, universe, imdsinfo):
|
|
99
|
+
# Calculate the buffer size
|
|
100
|
+
buffer_size = (
|
|
101
|
+
imdframe_memsize(universe.trajectory.n_atoms, imdsinfo) * 2
|
|
102
|
+
)
|
|
103
|
+
timeout = 5 # to speed up no disconnect test
|
|
104
|
+
server, client = server_client(buffer_size=buffer_size, timeout=timeout)
|
|
105
|
+
yield server, client
|
|
106
|
+
|
|
107
|
+
@pytest.fixture(params=["<", ">"])
|
|
108
|
+
def server_client_endianness(self, server_client, request):
|
|
109
|
+
server, client = server_client(endianness=request.param)
|
|
110
|
+
yield server, client
|
|
111
|
+
|
|
112
|
+
@pytest.fixture
|
|
113
|
+
def server_client_incorrect_atoms(self, server_client, universe):
|
|
114
|
+
server, client = server_client(n_atoms=universe.trajectory.n_atoms + 1)
|
|
115
|
+
yield server, client
|
|
116
|
+
|
|
117
|
+
def test_traj_unchanged(self, server_client_endianness, universe):
|
|
118
|
+
server, client = server_client_endianness
|
|
119
|
+
server.send_frames(0, 5)
|
|
120
|
+
for i in range(5):
|
|
121
|
+
imdf = client.get_imdframe()
|
|
122
|
+
assert_allclose(universe.trajectory[i].time, imdf.time)
|
|
123
|
+
assert_allclose(universe.trajectory[i].dt, imdf.dt)
|
|
124
|
+
assert_allclose(universe.trajectory[i].data["step"], imdf.step)
|
|
125
|
+
assert_allclose(universe.trajectory[i].positions, imdf.positions)
|
|
126
|
+
assert_allclose(universe.trajectory[i].velocities, imdf.velocities)
|
|
127
|
+
assert_allclose(universe.trajectory[i].forces, imdf.forces)
|
|
128
|
+
assert_allclose(
|
|
129
|
+
universe.trajectory[i].triclinic_dimensions, imdf.box
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
def test_pause_resume_continue(self, server_client_two_frame_buf):
|
|
133
|
+
server, client = server_client_two_frame_buf
|
|
134
|
+
server.send_frames(0, 2)
|
|
135
|
+
# Client's buffer is filled. client should send pause
|
|
136
|
+
server.expect_packet(IMDHeaderType.IMD_PAUSE)
|
|
137
|
+
# Empty buffer
|
|
138
|
+
client.get_imdframe()
|
|
139
|
+
# only the second call actually frees buffer memory
|
|
140
|
+
client.get_imdframe()
|
|
141
|
+
# client has free memory. should send resume
|
|
142
|
+
server.expect_packet(IMDHeaderType.IMD_RESUME)
|
|
143
|
+
server.send_frame(1)
|
|
144
|
+
client.get_imdframe()
|
|
145
|
+
|
|
146
|
+
def test_pause_resume_disconnect(self, server_client_two_frame_buf):
|
|
147
|
+
"""Client pauses because buffer is full, empties buffer and attempt to resume, but
|
|
148
|
+
finds that simulation has already ended and raises EOF"""
|
|
149
|
+
server, client = server_client_two_frame_buf
|
|
150
|
+
server.send_frames(0, 2)
|
|
151
|
+
server.expect_packet(IMDHeaderType.IMD_PAUSE)
|
|
152
|
+
client.get_imdframe()
|
|
153
|
+
client.get_imdframe()
|
|
154
|
+
# client has free frame. should send resume
|
|
155
|
+
server.expect_packet(IMDHeaderType.IMD_RESUME)
|
|
156
|
+
# simulation is over. client should raise EOF
|
|
157
|
+
server.disconnect()
|
|
158
|
+
with pytest.raises(EOFError):
|
|
159
|
+
client.get_imdframe()
|
|
160
|
+
|
|
161
|
+
def test_pause_resume_no_disconnect(self, server_client_two_frame_buf):
|
|
162
|
+
"""Client pauses because buffer is full, empties buffer and attempt to resume, but
|
|
163
|
+
finds that simulation has already ended (but has not yet disconnected) and raises EOF
|
|
164
|
+
"""
|
|
165
|
+
server, client = server_client_two_frame_buf
|
|
166
|
+
server.send_frames(0, 2)
|
|
167
|
+
server.expect_packet(IMDHeaderType.IMD_PAUSE)
|
|
168
|
+
client.get_imdframe()
|
|
169
|
+
client.get_imdframe()
|
|
170
|
+
# client has free frame. should send resume
|
|
171
|
+
server.expect_packet(IMDHeaderType.IMD_RESUME)
|
|
172
|
+
# simulation is over. client should raise EOF
|
|
173
|
+
with pytest.raises(EOFError):
|
|
174
|
+
client.get_imdframe()
|
|
175
|
+
# server should receive disconnect from client (though it doesn't have to do anything)
|
|
176
|
+
server.expect_packet(IMDHeaderType.IMD_DISCONNECT)
|
|
177
|
+
|
|
178
|
+
@pytest.mark.parametrize("cont", [True, False])
|
|
179
|
+
def test_continue_after_disconnect(self, server_client, cont):
|
|
180
|
+
server, client = server_client(continue_after_disconnect=cont)
|
|
181
|
+
server.expect_packet(
|
|
182
|
+
IMDHeaderType.IMD_WAIT, expected_length=(int)(not cont)
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
@pytest.mark.parametrize("read_error", [TimeoutError, ConnectionError])
|
|
186
|
+
def test_await_IMD_handshake_error_on_read_buf_failure(
|
|
187
|
+
self, server_client, monkeypatch, read_error
|
|
188
|
+
):
|
|
189
|
+
_, client = server_client()
|
|
190
|
+
|
|
191
|
+
def _raise_read_error(sock, buf):
|
|
192
|
+
raise read_error()
|
|
193
|
+
|
|
194
|
+
monkeypatch.setattr(
|
|
195
|
+
sys.modules[client.__class__.__module__],
|
|
196
|
+
"read_into_buf",
|
|
197
|
+
_raise_read_error,
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
with pytest.raises(
|
|
201
|
+
ConnectionError, match="No handshake packet received"
|
|
202
|
+
) as exc_info:
|
|
203
|
+
client._await_IMD_handshake()
|
|
204
|
+
|
|
205
|
+
assert isinstance(exc_info.value.__cause__, read_error)
|
|
206
|
+
|
|
207
|
+
def test_timeout_warning_low_value(self, server_client, caplog):
|
|
208
|
+
"""Test that warning is issued for timeout values <= 1 second"""
|
|
209
|
+
with caplog.at_level(logging.WARNING):
|
|
210
|
+
server, client = server_client(timeout=1)
|
|
211
|
+
|
|
212
|
+
# Check that warning was logged
|
|
213
|
+
assert any(
|
|
214
|
+
"timeout value of 1 second(s) is very low" in record.message
|
|
215
|
+
for record in caplog.records
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
@pytest.mark.parametrize("timeout_val", [2, 10])
|
|
219
|
+
def test_timeout_within_limit(self, server_client, universe, timeout_val):
|
|
220
|
+
"""Test that timeout does not trigger when server responds within timeout period"""
|
|
221
|
+
server, client = server_client(timeout=timeout_val)
|
|
222
|
+
|
|
223
|
+
# Sleep for less than timeout before sending frames
|
|
224
|
+
time.sleep(timeout_val - 1)
|
|
225
|
+
server.send_frame(0)
|
|
226
|
+
|
|
227
|
+
# Should successfully receive frame without timeout
|
|
228
|
+
imdf = client.get_imdframe()
|
|
229
|
+
assert_allclose(universe.trajectory[0].positions, imdf.positions)
|
|
230
|
+
|
|
231
|
+
@pytest.mark.parametrize("timeout_val", [2, 10])
|
|
232
|
+
def test_timeout_when_exceeded(self, server_client, timeout_val):
|
|
233
|
+
"""Test that timeout triggers EOFError when server doesn't respond within timeout period"""
|
|
234
|
+
server, client = server_client(timeout=timeout_val)
|
|
235
|
+
|
|
236
|
+
# Sleep for longer than timeout without sending any frames
|
|
237
|
+
time.sleep(timeout_val + 1)
|
|
238
|
+
|
|
239
|
+
# Client should timeout and raise EOFError when trying to get first frame
|
|
240
|
+
with pytest.raises(EOFError) as exc_info:
|
|
241
|
+
client.get_imdframe()
|
|
242
|
+
|
|
243
|
+
# Verify TimeoutError is somewhere in the exception chain
|
|
244
|
+
exception_chain = []
|
|
245
|
+
current = exc_info.value
|
|
246
|
+
while current is not None:
|
|
247
|
+
exception_chain.append(type(current))
|
|
248
|
+
current = current.__cause__
|
|
249
|
+
|
|
250
|
+
assert TimeoutError in exception_chain
|
|
251
|
+
|
|
252
|
+
def test_incorrect_atom_count(
|
|
253
|
+
self, server_client_incorrect_atoms, universe
|
|
254
|
+
):
|
|
255
|
+
server, client = server_client_incorrect_atoms
|
|
256
|
+
|
|
257
|
+
server.send_frame(0)
|
|
258
|
+
|
|
259
|
+
with pytest.raises(EOFError) as exc_info:
|
|
260
|
+
client.get_imdframe()
|
|
261
|
+
|
|
262
|
+
error_msg = str(exc_info.value)
|
|
263
|
+
assert (
|
|
264
|
+
f"Expected n_atoms value {universe.atoms.n_atoms + 1}" in error_msg
|
|
265
|
+
)
|
|
266
|
+
assert f"got {universe.atoms.n_atoms}" in error_msg
|
|
267
|
+
assert "Ensure you are using the correct topology file" in error_msg
|
|
268
|
+
|
|
269
|
+
def test_single_threaded_client_reads_frame_and_eof(
|
|
270
|
+
self, server_client, universe
|
|
271
|
+
):
|
|
272
|
+
server, client = server_client(multithreaded=False)
|
|
273
|
+
|
|
274
|
+
server.send_frame(0)
|
|
275
|
+
|
|
276
|
+
# Check one frame data by comparing positions
|
|
277
|
+
imdf = client.get_imdframe()
|
|
278
|
+
assert_allclose(universe.trajectory[0].positions, imdf.positions)
|
|
279
|
+
|
|
280
|
+
# diconnect to check EOF handling in singlethreaded code
|
|
281
|
+
server.disconnect()
|
|
282
|
+
|
|
283
|
+
with pytest.raises(EOFError):
|
|
284
|
+
client.get_imdframe()
|
|
285
|
+
|
|
286
|
+
def test_single_threaded_get_imdframe_reraises_eoferror(
|
|
287
|
+
self, server_client, monkeypatch
|
|
288
|
+
):
|
|
289
|
+
_server, client = server_client(multithreaded=False)
|
|
290
|
+
|
|
291
|
+
def _raise_eoferror():
|
|
292
|
+
raise EOFError("test EOF")
|
|
293
|
+
|
|
294
|
+
monkeypatch.setattr(
|
|
295
|
+
client._producer, "_parse_imdframe", _raise_eoferror
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
with pytest.raises(EOFError):
|
|
299
|
+
client._producer._get_imdframe()
|
|
300
|
+
|
|
301
|
+
def test_single_threaded_get_imdframe_wraps_unexpected_errors(
|
|
302
|
+
self, server_client, monkeypatch
|
|
303
|
+
):
|
|
304
|
+
_server, client = server_client(multithreaded=False)
|
|
305
|
+
|
|
306
|
+
def _raise_valueerror():
|
|
307
|
+
raise ValueError("test ValueError")
|
|
308
|
+
|
|
309
|
+
monkeypatch.setattr(
|
|
310
|
+
client._producer,
|
|
311
|
+
"_parse_imdframe",
|
|
312
|
+
_raise_valueerror,
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
with pytest.raises(RuntimeError, match="An unexpected error occurred"):
|
|
316
|
+
client._producer._get_imdframe()
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
class TestIMDClientV3ContextManager:
|
|
320
|
+
@pytest.fixture
|
|
321
|
+
def universe(self):
|
|
322
|
+
return mda.Universe(COORDINATES_TOPOLOGY, COORDINATES_H5MD)
|
|
323
|
+
|
|
324
|
+
@pytest.fixture
|
|
325
|
+
def imdsinfo(self):
|
|
326
|
+
return create_default_imdsinfo_v3()
|
|
327
|
+
|
|
328
|
+
@pytest.fixture
|
|
329
|
+
def server(self, universe, imdsinfo):
|
|
330
|
+
server = InThreadIMDServer(universe.trajectory)
|
|
331
|
+
server.set_imdsessioninfo(imdsinfo)
|
|
332
|
+
yield server
|
|
333
|
+
server.cleanup()
|
|
334
|
+
|
|
335
|
+
def test_context_manager_traj_unchanged(self, server, universe):
|
|
336
|
+
server.handshake_sequence("localhost", first_frame=False)
|
|
337
|
+
|
|
338
|
+
i = 0
|
|
339
|
+
with IMDClient(
|
|
340
|
+
"localhost",
|
|
341
|
+
server.port,
|
|
342
|
+
universe.trajectory.n_atoms,
|
|
343
|
+
) as client:
|
|
344
|
+
server.send_frames(0, 5)
|
|
345
|
+
while i < 5:
|
|
346
|
+
|
|
347
|
+
imdf = client.get_imdframe()
|
|
348
|
+
assert_allclose(universe.trajectory[i].time, imdf.time)
|
|
349
|
+
assert_allclose(universe.trajectory[i].dt, imdf.dt)
|
|
350
|
+
assert_allclose(universe.trajectory[i].data["step"], imdf.step)
|
|
351
|
+
assert_allclose(
|
|
352
|
+
universe.trajectory[i].positions, imdf.positions
|
|
353
|
+
)
|
|
354
|
+
assert_allclose(
|
|
355
|
+
universe.trajectory[i].velocities, imdf.velocities
|
|
356
|
+
)
|
|
357
|
+
assert_allclose(universe.trajectory[i].forces, imdf.forces)
|
|
358
|
+
assert_allclose(
|
|
359
|
+
universe.trajectory[i].triclinic_dimensions, imdf.box
|
|
360
|
+
)
|
|
361
|
+
i += 1
|
|
362
|
+
server.expect_packet(IMDHeaderType.IMD_DISCONNECT)
|
|
363
|
+
assert i == 5
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
class TestIMDFrameBuffer:
|
|
367
|
+
@pytest.fixture
|
|
368
|
+
def imdsinfo(self):
|
|
369
|
+
return create_default_imdsinfo_v3()
|
|
370
|
+
|
|
371
|
+
def test_pop_empty_imdframe_raises_when_consumer_finished(self, imdsinfo):
|
|
372
|
+
buffer_size = imdframe_memsize(1, imdsinfo)
|
|
373
|
+
buffer = IMDFrameBuffer(imdsinfo, n_atoms=1, buffer_size=buffer_size)
|
|
374
|
+
|
|
375
|
+
buffer.pop_empty_imdframe()
|
|
376
|
+
buffer.notify_consumer_finished()
|
|
377
|
+
|
|
378
|
+
with pytest.raises(EOFError, match="Consumer has finished"):
|
|
379
|
+
buffer.pop_empty_imdframe()
|
|
380
|
+
|
|
381
|
+
def test_pop_full_imdframe_raises_when_producer_finished(self, imdsinfo):
|
|
382
|
+
buffer_size = imdframe_memsize(1, imdsinfo)
|
|
383
|
+
buffer = IMDFrameBuffer(imdsinfo, n_atoms=1, buffer_size=buffer_size)
|
|
384
|
+
|
|
385
|
+
buffer.notify_producer_finished()
|
|
386
|
+
|
|
387
|
+
with pytest.raises(EOFError, match="Producer has finished"):
|
|
388
|
+
buffer.pop_full_imdframe()
|
|
389
|
+
|
|
390
|
+
# simple test below to cover Error raising but doesn't test if the Error is raised
|
|
391
|
+
# when consumer finishes while the `wait_for_space()` is running
|
|
392
|
+
# TODO: add threaded test to properly test this scenario
|
|
393
|
+
def test_wait_for_space_raises_when_consumer_finished(self, imdsinfo):
|
|
394
|
+
buffer_size = imdframe_memsize(1, imdsinfo) * 2
|
|
395
|
+
buffer = IMDFrameBuffer(imdsinfo, n_atoms=1, buffer_size=buffer_size)
|
|
396
|
+
|
|
397
|
+
# Drain empty slots so buffer is below unpause threshold
|
|
398
|
+
buffer.pop_empty_imdframe()
|
|
399
|
+
buffer.pop_empty_imdframe()
|
|
400
|
+
buffer.notify_consumer_finished()
|
|
401
|
+
|
|
402
|
+
with pytest.raises(
|
|
403
|
+
RuntimeError, match="Error waiting for space in buffer"
|
|
404
|
+
) as exc_info:
|
|
405
|
+
buffer.wait_for_space()
|
|
406
|
+
|
|
407
|
+
assert isinstance(exc_info.value.__cause__, EOFError)
|
|
408
|
+
assert "Consumer has finished" in str(exc_info.value.__cause__)
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: imdclient
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Receiver for IMD v2 and v3 data from simulation engines like Gromacs, LAMMPS, and NAMD
|
|
5
|
-
Author-email: Lawson <ljwoods2@asu.edu>
|
|
6
|
-
Maintainer-email: Lawson <ljwoods2@asu.edu>, Amruthesh Thirumalaiswamy <athiru12@asu.edu>
|
|
5
|
+
Author-email: Lawson Woods <ljwoods2@asu.edu>
|
|
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
10
|
Keywords: molecular simulations
|
|
11
|
-
Requires-Python: >=3.
|
|
11
|
+
Requires-Python: >=3.11
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
14
|
License-File: AUTHORS.md
|
|
@@ -52,7 +52,7 @@ IMDClient is bound by a [Code of Conduct](https://github.com/becksteinlab/imdcli
|
|
|
52
52
|
|
|
53
53
|
### Installation
|
|
54
54
|
|
|
55
|
-
IMDClient requires Python 3.
|
|
55
|
+
IMDClient requires Python 3.11 or higher.
|
|
56
56
|
|
|
57
57
|
#### Install via mamba (recommended)
|
|
58
58
|
To install the latest release of IMDClient from conda-forge:
|
|
@@ -11,14 +11,14 @@ description = "Receiver for IMD v2 and v3 data from simulation engines like Grom
|
|
|
11
11
|
license = "MIT"
|
|
12
12
|
license-files = ["LICENSE", "AUTHORS.md"]
|
|
13
13
|
authors = [
|
|
14
|
-
{name = "Lawson", email = "ljwoods2@asu.edu"},
|
|
14
|
+
{name = "Lawson Woods", email = "ljwoods2@asu.edu"},
|
|
15
15
|
]
|
|
16
16
|
maintainers = [
|
|
17
|
-
{name = "Lawson", email = "ljwoods2@asu.edu"},
|
|
17
|
+
{name = "Lawson Woods", email = "ljwoods2@asu.edu"},
|
|
18
18
|
{name = "Amruthesh Thirumalaiswamy", email = "athiru12@asu.edu"},
|
|
19
19
|
]
|
|
20
20
|
readme = "README.md"
|
|
21
|
-
requires-python = ">=3.
|
|
21
|
+
requires-python = ">=3.11"
|
|
22
22
|
dependencies = [
|
|
23
23
|
"numpy",
|
|
24
24
|
]
|
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
"""Test for IMDClient functionality"""
|
|
2
|
-
|
|
3
|
-
import logging
|
|
4
|
-
|
|
5
|
-
import pytest
|
|
6
|
-
from numpy.testing import (
|
|
7
|
-
assert_allclose,
|
|
8
|
-
)
|
|
9
|
-
import MDAnalysis as mda
|
|
10
|
-
from MDAnalysisTests.datafiles import (
|
|
11
|
-
COORDINATES_TOPOLOGY,
|
|
12
|
-
COORDINATES_H5MD,
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
from imdclient.IMDClient import imdframe_memsize, IMDClient
|
|
16
|
-
from imdclient.IMDProtocol import IMDHeaderType
|
|
17
|
-
from .utils import (
|
|
18
|
-
create_default_imdsinfo_v3,
|
|
19
|
-
)
|
|
20
|
-
from .server import InThreadIMDServer
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
logger = logging.getLogger("imdclient.IMDClient")
|
|
24
|
-
file_handler = logging.FileHandler("test.log")
|
|
25
|
-
formatter = logging.Formatter(
|
|
26
|
-
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
|
27
|
-
)
|
|
28
|
-
file_handler.setFormatter(formatter)
|
|
29
|
-
logger.addHandler(file_handler)
|
|
30
|
-
logger.setLevel(logging.DEBUG)
|
|
31
|
-
|
|
32
|
-
IMDENERGYKEYS = [
|
|
33
|
-
"step",
|
|
34
|
-
"temperature",
|
|
35
|
-
"total_energy",
|
|
36
|
-
"potential_energy",
|
|
37
|
-
"van_der_walls_energy",
|
|
38
|
-
"coulomb_energy",
|
|
39
|
-
"bonds_energy",
|
|
40
|
-
"angles_energy",
|
|
41
|
-
"dihedrals_energy",
|
|
42
|
-
"improper_dihedrals_energy",
|
|
43
|
-
]
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
class TestIMDClientV3:
|
|
47
|
-
|
|
48
|
-
@pytest.fixture
|
|
49
|
-
def universe(self):
|
|
50
|
-
return mda.Universe(COORDINATES_TOPOLOGY, COORDINATES_H5MD)
|
|
51
|
-
|
|
52
|
-
@pytest.fixture
|
|
53
|
-
def imdsinfo(self):
|
|
54
|
-
return create_default_imdsinfo_v3()
|
|
55
|
-
|
|
56
|
-
@pytest.fixture
|
|
57
|
-
def server_client_two_frame_buf(self, universe, imdsinfo):
|
|
58
|
-
server = InThreadIMDServer(universe.trajectory)
|
|
59
|
-
server.set_imdsessioninfo(imdsinfo)
|
|
60
|
-
server.handshake_sequence("localhost", first_frame=False)
|
|
61
|
-
client = IMDClient(
|
|
62
|
-
f"localhost",
|
|
63
|
-
server.port,
|
|
64
|
-
universe.trajectory.n_atoms,
|
|
65
|
-
buffer_size=imdframe_memsize(universe.trajectory.n_atoms, imdsinfo)
|
|
66
|
-
* 2,
|
|
67
|
-
)
|
|
68
|
-
server.join_accept_thread()
|
|
69
|
-
yield server, client
|
|
70
|
-
client.stop()
|
|
71
|
-
server.cleanup()
|
|
72
|
-
|
|
73
|
-
@pytest.fixture(params=[">", "<"])
|
|
74
|
-
def server_client(self, universe, imdsinfo, request):
|
|
75
|
-
server = InThreadIMDServer(universe.trajectory)
|
|
76
|
-
imdsinfo.endianness = request.param
|
|
77
|
-
server.set_imdsessioninfo(imdsinfo)
|
|
78
|
-
server.handshake_sequence("localhost", first_frame=False)
|
|
79
|
-
client = IMDClient(
|
|
80
|
-
f"localhost",
|
|
81
|
-
server.port,
|
|
82
|
-
universe.atoms.n_atoms,
|
|
83
|
-
)
|
|
84
|
-
server.join_accept_thread()
|
|
85
|
-
yield server, client
|
|
86
|
-
client.stop()
|
|
87
|
-
server.cleanup()
|
|
88
|
-
|
|
89
|
-
@pytest.fixture
|
|
90
|
-
def server_client_incorrect_atoms(self, universe, imdsinfo):
|
|
91
|
-
server = InThreadIMDServer(universe.trajectory)
|
|
92
|
-
server.set_imdsessioninfo(imdsinfo)
|
|
93
|
-
server.handshake_sequence("localhost", first_frame=False)
|
|
94
|
-
client = IMDClient(
|
|
95
|
-
f"localhost",
|
|
96
|
-
server.port,
|
|
97
|
-
universe.atoms.n_atoms + 1,
|
|
98
|
-
)
|
|
99
|
-
server.join_accept_thread()
|
|
100
|
-
yield server, client
|
|
101
|
-
client.stop()
|
|
102
|
-
server.cleanup()
|
|
103
|
-
|
|
104
|
-
def test_traj_unchanged(self, server_client, universe):
|
|
105
|
-
server, client = server_client
|
|
106
|
-
server.send_frames(0, 5)
|
|
107
|
-
for i in range(5):
|
|
108
|
-
imdf = client.get_imdframe()
|
|
109
|
-
assert_allclose(universe.trajectory[i].time, imdf.time)
|
|
110
|
-
assert_allclose(universe.trajectory[i].dt, imdf.dt)
|
|
111
|
-
assert_allclose(universe.trajectory[i].data["step"], imdf.step)
|
|
112
|
-
assert_allclose(universe.trajectory[i].positions, imdf.positions)
|
|
113
|
-
assert_allclose(universe.trajectory[i].velocities, imdf.velocities)
|
|
114
|
-
assert_allclose(universe.trajectory[i].forces, imdf.forces)
|
|
115
|
-
assert_allclose(
|
|
116
|
-
universe.trajectory[i].triclinic_dimensions, imdf.box
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
def test_pause_resume_continue(self, server_client_two_frame_buf):
|
|
120
|
-
server, client = server_client_two_frame_buf
|
|
121
|
-
server.send_frames(0, 2)
|
|
122
|
-
# Client's buffer is filled. client should send pause
|
|
123
|
-
server.expect_packet(IMDHeaderType.IMD_PAUSE)
|
|
124
|
-
# Empty buffer
|
|
125
|
-
client.get_imdframe()
|
|
126
|
-
# only the second call actually frees buffer memory
|
|
127
|
-
client.get_imdframe()
|
|
128
|
-
# client has free memory. should send resume
|
|
129
|
-
server.expect_packet(IMDHeaderType.IMD_RESUME)
|
|
130
|
-
server.send_frame(1)
|
|
131
|
-
client.get_imdframe()
|
|
132
|
-
|
|
133
|
-
def test_pause_resume_disconnect(self, server_client_two_frame_buf):
|
|
134
|
-
"""Client pauses because buffer is full, empties buffer and attempt to resume, but
|
|
135
|
-
finds that simulation has already ended and raises EOF"""
|
|
136
|
-
server, client = server_client_two_frame_buf
|
|
137
|
-
server.send_frames(0, 2)
|
|
138
|
-
server.expect_packet(IMDHeaderType.IMD_PAUSE)
|
|
139
|
-
client.get_imdframe()
|
|
140
|
-
client.get_imdframe()
|
|
141
|
-
# client has free frame. should send resume
|
|
142
|
-
server.expect_packet(IMDHeaderType.IMD_RESUME)
|
|
143
|
-
# simulation is over. client should raise EOF
|
|
144
|
-
server.disconnect()
|
|
145
|
-
with pytest.raises(EOFError):
|
|
146
|
-
client.get_imdframe()
|
|
147
|
-
|
|
148
|
-
def test_pause_resume_no_disconnect(self, server_client_two_frame_buf):
|
|
149
|
-
"""Client pauses because buffer is full, empties buffer and attempt to resume, but
|
|
150
|
-
finds that simulation has already ended (but has not yet disconnected) and raises EOF
|
|
151
|
-
"""
|
|
152
|
-
server, client = server_client_two_frame_buf
|
|
153
|
-
server.send_frames(0, 2)
|
|
154
|
-
server.expect_packet(IMDHeaderType.IMD_PAUSE)
|
|
155
|
-
client.get_imdframe()
|
|
156
|
-
client.get_imdframe()
|
|
157
|
-
# client has free frame. should send resume
|
|
158
|
-
server.expect_packet(IMDHeaderType.IMD_RESUME)
|
|
159
|
-
# simulation is over. client should raise EOF
|
|
160
|
-
with pytest.raises(EOFError):
|
|
161
|
-
client.get_imdframe()
|
|
162
|
-
# server should receive disconnect from client (though it doesn't have to do anything)
|
|
163
|
-
server.expect_packet(IMDHeaderType.IMD_DISCONNECT)
|
|
164
|
-
|
|
165
|
-
@pytest.mark.parametrize("cont", [True, False])
|
|
166
|
-
def test_continue_after_disconnect(self, universe, imdsinfo, cont):
|
|
167
|
-
server = InThreadIMDServer(universe.trajectory)
|
|
168
|
-
server.set_imdsessioninfo(imdsinfo)
|
|
169
|
-
server.handshake_sequence("localhost", first_frame=False)
|
|
170
|
-
client = IMDClient(
|
|
171
|
-
f"localhost",
|
|
172
|
-
server.port,
|
|
173
|
-
universe.trajectory.n_atoms,
|
|
174
|
-
continue_after_disconnect=cont,
|
|
175
|
-
)
|
|
176
|
-
server.join_accept_thread()
|
|
177
|
-
server.expect_packet(
|
|
178
|
-
IMDHeaderType.IMD_WAIT, expected_length=(int)(not cont)
|
|
179
|
-
)
|
|
180
|
-
|
|
181
|
-
def test_incorrect_atom_count(self, server_client_incorrect_atoms, universe):
|
|
182
|
-
server, client = server_client_incorrect_atoms
|
|
183
|
-
|
|
184
|
-
server.send_frame(0)
|
|
185
|
-
|
|
186
|
-
with pytest.raises(EOFError) as exc_info:
|
|
187
|
-
client.get_imdframe()
|
|
188
|
-
|
|
189
|
-
error_msg = str(exc_info.value)
|
|
190
|
-
assert f"Expected n_atoms value {universe.atoms.n_atoms + 1}" in error_msg
|
|
191
|
-
assert f"got {universe.atoms.n_atoms}" in error_msg
|
|
192
|
-
assert "Ensure you are using the correct topology file" in error_msg
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
class TestIMDClientV3ContextManager:
|
|
196
|
-
@pytest.fixture
|
|
197
|
-
def universe(self):
|
|
198
|
-
return mda.Universe(COORDINATES_TOPOLOGY, COORDINATES_H5MD)
|
|
199
|
-
|
|
200
|
-
@pytest.fixture
|
|
201
|
-
def imdsinfo(self):
|
|
202
|
-
return create_default_imdsinfo_v3()
|
|
203
|
-
|
|
204
|
-
@pytest.fixture
|
|
205
|
-
def server(self, universe, imdsinfo):
|
|
206
|
-
server = InThreadIMDServer(universe.trajectory)
|
|
207
|
-
server.set_imdsessioninfo(imdsinfo)
|
|
208
|
-
yield server
|
|
209
|
-
server.cleanup()
|
|
210
|
-
|
|
211
|
-
def test_context_manager_traj_unchanged(self, server, universe):
|
|
212
|
-
server.handshake_sequence("localhost", first_frame=False)
|
|
213
|
-
|
|
214
|
-
i = 0
|
|
215
|
-
with IMDClient(
|
|
216
|
-
"localhost",
|
|
217
|
-
server.port,
|
|
218
|
-
universe.trajectory.n_atoms,
|
|
219
|
-
) as client:
|
|
220
|
-
server.send_frames(0, 5)
|
|
221
|
-
while i < 5:
|
|
222
|
-
|
|
223
|
-
imdf = client.get_imdframe()
|
|
224
|
-
assert_allclose(universe.trajectory[i].time, imdf.time)
|
|
225
|
-
assert_allclose(universe.trajectory[i].dt, imdf.dt)
|
|
226
|
-
assert_allclose(universe.trajectory[i].data["step"], imdf.step)
|
|
227
|
-
assert_allclose(
|
|
228
|
-
universe.trajectory[i].positions, imdf.positions
|
|
229
|
-
)
|
|
230
|
-
assert_allclose(
|
|
231
|
-
universe.trajectory[i].velocities, imdf.velocities
|
|
232
|
-
)
|
|
233
|
-
assert_allclose(universe.trajectory[i].forces, imdf.forces)
|
|
234
|
-
assert_allclose(
|
|
235
|
-
universe.trajectory[i].triclinic_dimensions, imdf.box
|
|
236
|
-
)
|
|
237
|
-
i += 1
|
|
238
|
-
server.expect_packet(IMDHeaderType.IMD_DISCONNECT)
|
|
239
|
-
assert i == 5
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|