imdclient 0.1.3__py3-none-any.whl → 0.1.4__py3-none-any.whl

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.
Files changed (33) hide show
  1. imdclient/IMD.py +3 -1
  2. imdclient/IMDClient.py +37 -8
  3. imdclient/IMDProtocol.py +1 -0
  4. imdclient/data/gromacs/md/gromacs_v3_nst1.mdp +3 -3
  5. imdclient/tests/base.py +46 -0
  6. imdclient/tests/conftest.py +0 -39
  7. imdclient/tests/datafiles.py +16 -1
  8. imdclient/tests/hpc_testing/gromacs/README.md +112 -0
  9. imdclient/tests/hpc_testing/gromacs/gmx_gpu_test.mdp +58 -0
  10. imdclient/tests/hpc_testing/gromacs/gmx_gpu_test.top +11764 -0
  11. imdclient/tests/hpc_testing/gromacs/struct.gro +21151 -0
  12. imdclient/tests/hpc_testing/gromacs/validate_gmx.sh +90 -0
  13. imdclient/tests/hpc_testing/lammps/README.md +62 -0
  14. imdclient/tests/hpc_testing/lammps/lammps_v3_nst_1.in +71 -0
  15. imdclient/tests/hpc_testing/lammps/topology_after_min.data +8022 -0
  16. imdclient/tests/hpc_testing/lammps/validate_lmp.sh +66 -0
  17. imdclient/tests/hpc_testing/namd/README.md +73 -0
  18. imdclient/tests/hpc_testing/namd/alanin.params +402 -0
  19. imdclient/tests/hpc_testing/namd/alanin.pdb +77 -0
  20. imdclient/tests/hpc_testing/namd/alanin.psf +206 -0
  21. imdclient/tests/hpc_testing/namd/namd_v3_nst_1.namd +59 -0
  22. imdclient/tests/hpc_testing/namd/validate_namd.sh +71 -0
  23. imdclient/tests/server.py +2 -11
  24. imdclient/tests/test_imdclient.py +18 -0
  25. imdclient/tests/test_imdreader.py +60 -1
  26. imdclient/tests/test_manual.py +221 -65
  27. {imdclient-0.1.3.dist-info → imdclient-0.1.4.dist-info}/METADATA +1 -1
  28. imdclient-0.1.4.dist-info/RECORD +57 -0
  29. imdclient-0.1.3.dist-info/RECORD +0 -42
  30. {imdclient-0.1.3.dist-info → imdclient-0.1.4.dist-info}/AUTHORS.md +0 -0
  31. {imdclient-0.1.3.dist-info → imdclient-0.1.4.dist-info}/LICENSE +0 -0
  32. {imdclient-0.1.3.dist-info → imdclient-0.1.4.dist-info}/WHEEL +0 -0
  33. {imdclient-0.1.3.dist-info → imdclient-0.1.4.dist-info}/top_level.txt +0 -0
imdclient/IMD.py CHANGED
@@ -50,6 +50,7 @@ class IMDReader(StreamReaderBase):
50
50
  ):
51
51
  super(IMDReader, self).__init__(filename, **kwargs)
52
52
 
53
+ self._imdclient = None
53
54
  logger.debug("IMDReader initializing")
54
55
 
55
56
  if n_atoms is None:
@@ -125,6 +126,7 @@ class IMDReader(StreamReaderBase):
125
126
  def close(self):
126
127
  """Gracefully shut down the reader. Stops the producer thread."""
127
128
  logger.debug("IMDReader close() called")
128
- self._imdclient.stop()
129
+ if self._imdclient is not None:
130
+ self._imdclient.stop()
129
131
  # NOTE: removeme after testing
130
132
  logger.debug("IMDReader shut down gracefully.")
imdclient/IMDClient.py CHANGED
@@ -46,6 +46,10 @@ class IMDClient:
46
46
  IMDFramebuffer will be filled with as many :class:`IMDFrame` fit in `buffer_size` bytes [``10MB``]
47
47
  timeout : int, optional
48
48
  Timeout for the socket in seconds [``5``]
49
+ continue_after_disconnect : bool, optional [``None``]
50
+ If True, the client will attempt to change the simulation engine's waiting behavior to
51
+ non-blocking after the client disconnects. If False, the client will attempt to change it
52
+ to blocking. If None, the client will not attempt to change the simulation engine's behavior.
49
53
  **kwargs : dict (optional)
50
54
  Additional keyword arguments to pass to the :class:`BaseIMDProducer` and :class:`IMDFrameBuffer`
51
55
  """
@@ -57,6 +61,7 @@ class IMDClient:
57
61
  n_atoms,
58
62
  socket_bufsize=None,
59
63
  multithreaded=True,
64
+ continue_after_disconnect=None,
60
65
  **kwargs,
61
66
  ):
62
67
 
@@ -64,6 +69,7 @@ class IMDClient:
64
69
  self._conn = self._connect_to_server(host, port, socket_bufsize)
65
70
  self._imdsinfo = self._await_IMD_handshake()
66
71
  self._multithreaded = multithreaded
72
+ self._continue_after_disconnect = continue_after_disconnect
67
73
 
68
74
  if self._multithreaded:
69
75
  self._buf = IMDFrameBuffer(
@@ -201,7 +207,9 @@ class IMDClient:
201
207
  # /proc/sys/net/core/rmem_default
202
208
  # Max (linux):
203
209
  # /proc/sys/net/core/rmem_max
204
- conn.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, socket_bufsize)
210
+ conn.setsockopt(
211
+ socket.SOL_SOCKET, socket.SO_RCVBUF, socket_bufsize
212
+ )
205
213
  try:
206
214
  logger.debug(f"IMDClient: Connecting to {host}:{port}")
207
215
  conn.connect((host, port))
@@ -292,6 +300,17 @@ class IMDClient:
292
300
  self._conn.sendall(go)
293
301
  logger.debug("IMDClient: Sent go packet to server")
294
302
 
303
+ if self._continue_after_disconnect is not None:
304
+ wait_behavior = (int)(not self._continue_after_disconnect)
305
+ wait_packet = create_header_bytes(
306
+ IMDHeaderType.IMD_WAIT, wait_behavior
307
+ )
308
+ self._conn.sendall(wait_packet)
309
+ logger.debug(
310
+ "IMDClient: Attempted to change wait behavior to %s",
311
+ not self._continue_after_disconnect
312
+ )
313
+
295
314
  def _disconnect(self):
296
315
  # MUST disconnect before stopping execution
297
316
  # if simulation already ended, this method will do nothing
@@ -499,7 +518,14 @@ class BaseIMDProducer(threading.Thread):
499
518
 
500
519
  class IMDProducerV2(BaseIMDProducer):
501
520
  def __init__(
502
- self, conn, buffer, sinfo, n_atoms, multithreaded, error_queue, **kwargs
521
+ self,
522
+ conn,
523
+ buffer,
524
+ sinfo,
525
+ n_atoms,
526
+ multithreaded,
527
+ error_queue,
528
+ **kwargs,
503
529
  ):
504
530
  super(IMDProducerV2, self).__init__(
505
531
  conn, buffer, sinfo, n_atoms, multithreaded, error_queue, **kwargs
@@ -713,9 +739,6 @@ class IMDProducerV3(BaseIMDProducer):
713
739
  ).reshape((self._n_atoms, 3)),
714
740
  )
715
741
 
716
- def __del__(self):
717
- logger.debug("IMDProducer: I am being deleted")
718
-
719
742
 
720
743
  class IMDFrameBuffer:
721
744
  """
@@ -762,7 +785,9 @@ class IMDFrameBuffer:
762
785
  raise ValueError("pause_empty_proportion must be between 0 and 1")
763
786
  self._pause_empty_proportion = pause_empty_proportion
764
787
  if unpause_empty_proportion < 0 or unpause_empty_proportion > 1:
765
- raise ValueError("unpause_empty_proportion must be between 0 and 1")
788
+ raise ValueError(
789
+ "unpause_empty_proportion must be between 0 and 1"
790
+ )
766
791
  self._unpause_empty_proportion = unpause_empty_proportion
767
792
 
768
793
  if buffer_size <= 0:
@@ -829,7 +854,9 @@ class IMDFrameBuffer:
829
854
  logger.debug("IMDProducer: Noticing consumer finished")
830
855
  raise EOFError
831
856
  except Exception as e:
832
- logger.debug(f"IMDProducer: Error waiting for space in buffer: {e}")
857
+ logger.debug(
858
+ f"IMDProducer: Error waiting for space in buffer: {e}"
859
+ )
833
860
 
834
861
  def pop_empty_imdframe(self):
835
862
  logger.debug("IMDProducer: Getting empty frame")
@@ -875,7 +902,9 @@ class IMDFrameBuffer:
875
902
  imdf = self._full_q.get()
876
903
  else:
877
904
  with self._full_imdf_avail:
878
- while self._full_q.qsize() == 0 and not self._producer_finished:
905
+ while (
906
+ self._full_q.qsize() == 0 and not self._producer_finished
907
+ ):
879
908
  self._full_imdf_avail.wait()
880
909
 
881
910
  if self._producer_finished and self._full_q.qsize() == 0:
imdclient/IMDProtocol.py CHANGED
@@ -34,6 +34,7 @@ class IMDHeaderType(Enum):
34
34
  IMD_BOX = 13
35
35
  IMD_VELOCITIES = 14
36
36
  IMD_FORCES = 15
37
+ IMD_WAIT = 16
37
38
 
38
39
 
39
40
  def parse_energy_bytes(data, endianness):
@@ -1,5 +1,5 @@
1
1
  title = PRODUCTION IN NPT
2
- ld-seed = 1
2
+ ld-seed = 1
3
3
  ; Run parameters
4
4
  integrator = md ; leap-frog integrator
5
5
  nsteps = 100 ; 1 * 1000 = 1 ps
@@ -7,9 +7,9 @@ dt = 0.001 ; 1 fs
7
7
  ; Output control
8
8
  nstxout = 1 ; save coordinates every 1 fs
9
9
  nstvout = 1 ; save velocities every 1 fs
10
- nstfout = 1
10
+ nstfout = 1 ; save forces every 1 fs
11
11
  nstenergy = 1 ; save energies every 1 fs
12
- nstlog = 10 ; update log file every 1 ps
12
+ nstlog = 10
13
13
  ; Center of mass (COM) motion
14
14
  nstcomm = 10 ; remove COM motion every 10 steps
15
15
  comm-mode = Linear ; remove only COM translation (liquids in PBC)
imdclient/tests/base.py CHANGED
@@ -208,3 +208,49 @@ class IMDv3IntegrationTest:
208
208
  imd_u.trajectory[i - first_frame].forces,
209
209
  atol=1e-03,
210
210
  )
211
+
212
+ def test_continue_after_disconnect(
213
+ self, docker_client, topol, tmp_path, port
214
+ ):
215
+ u = mda.Universe(
216
+ (tmp_path / topol),
217
+ f"imd://localhost:{port}",
218
+ continue_after_disconnect=True,
219
+ # Make sure LAMMPS topol can be read
220
+ # Does nothing if not LAMMPS
221
+ atom_style="id type x y z",
222
+ )
223
+ # Though we disconnect here, the simulation should continue
224
+ u.trajectory.close()
225
+ # Wait for the simulation to finish running
226
+ time.sleep(45)
227
+
228
+ # Now, attempt to reconnect- should fail,
229
+ # since the simulation should have continued
230
+ with pytest.raises(IOError):
231
+ u = mda.Universe(
232
+ (tmp_path / topol),
233
+ f"imd://localhost:{port}",
234
+ atom_style="id type x y z",
235
+ )
236
+
237
+ def test_wait_after_disconnect(self, docker_client, topol, tmp_path, port):
238
+ u = mda.Universe(
239
+ (tmp_path / topol),
240
+ f"imd://localhost:{port}",
241
+ # Could also use None here- just being explicit
242
+ continue_after_disconnect=False,
243
+ # Make sure LAMMPS topol can be read
244
+ # Does nothing if not LAMMPS
245
+ atom_style="id type x y z",
246
+ )
247
+ u.trajectory.close()
248
+ # Give the simulation engine
249
+ # enough time to finish running (though it shouldn't)
250
+ time.sleep(45)
251
+
252
+ u = mda.Universe(
253
+ (tmp_path / topol),
254
+ f"imd://localhost:{port}",
255
+ atom_style="id type x y z",
256
+ )
@@ -1,42 +1,3 @@
1
1
  """
2
2
  Global pytest fixtures
3
3
  """
4
-
5
-
6
- # Command line arguments for 'test_manual.py'
7
- def pytest_addoption(parser):
8
- parser.addoption(
9
- "--topol_path_arg",
10
- action="store",
11
- default=None,
12
- )
13
- parser.addoption(
14
- "--traj_path_arg",
15
- action="store",
16
- default=None,
17
- )
18
- parser.addoption(
19
- "--first_frame_arg", action="store", type=int, default=None
20
- )
21
-
22
-
23
- def pytest_generate_tests(metafunc):
24
- # This is called for every test. Only get/set command line arguments
25
- # if the argument is specified in the list of test "fixturenames".
26
- topol = metafunc.config.option.topol_path_arg
27
- traj = metafunc.config.option.traj_path_arg
28
- first_frame = metafunc.config.option.first_frame_arg
29
-
30
- if all(
31
- arg in metafunc.fixturenames
32
- for arg in ["topol_path_arg", "traj_path_arg", "first_frame_arg"]
33
- ):
34
- if topol is None or traj is None or first_frame is None:
35
- raise ValueError(
36
- "Must pass all three of '--topol_path_arg <path/to/topology>', "
37
- + "'--traj_path_arg <path/to/trajectory>', "
38
- + "'--first_frame_arg <first traj frame to compare to IMD>"
39
- )
40
- metafunc.parametrize("topol_path_arg", [topol])
41
- metafunc.parametrize("traj_path_arg", [traj])
42
- metafunc.parametrize("first_frame_arg", [first_frame])
@@ -8,7 +8,22 @@ Use as ::
8
8
 
9
9
  """
10
10
 
11
- __all__ = ["LAMMPS_IN", "LAMMPS_TOPOL", "GROMACS_TRAJ", "GROMACS_MDP"]
11
+ __all__ = [
12
+ "LAMMPS_TOPOL",
13
+ "LAMMPS_IN_NST_1",
14
+ "LAMMPS_IN_NST_8",
15
+ "GROMACS_TRAJ",
16
+ "GROMACS_MDP",
17
+ "GROMACS_TOP" "LAMMPS_IN_NST_1",
18
+ "GROMACS_GRO",
19
+ "GROMACS_MDP_NST_1",
20
+ "GROMACS_MDP_NST_8",
21
+ "NAMD_TOPOL",
22
+ "NAMD_CONF_NST_1",
23
+ "NAMD_CONF_NST_8",
24
+ "NAMD_PARAMS",
25
+ "NAMD_PSF",
26
+ ]
12
27
 
13
28
  from importlib import resources
14
29
  from pathlib import Path
@@ -0,0 +1,112 @@
1
+ # Manual validation of different compiler options for GROMACS using ASU's SOL
2
+
3
+ ### Running tests
4
+
5
+ To validate all IMDv3 output (time, integration step, dt, box, positions, velocities, and forces)
6
+ against TRR output with a simple sample simulation, first ensure you're using a
7
+ python environment which has the testing requirements of IMDClient installed.
8
+
9
+ If not already installed, do:
10
+ ```bash
11
+ conda env create -n imdclient-test -f devtools/conda-envs/test_env.yaml -y
12
+ conda activate imdclient-test
13
+ ```
14
+
15
+ Equivalently, on ASU's Sol, do:
16
+ ```bash
17
+ module load mamba
18
+ # Only needed for MPI builds
19
+ module load openmpi/4.1.5
20
+ conda env create -n imdclient-test -f devtools/conda-envs/test_env.yaml -y
21
+ source activate imdclient-test
22
+ ```
23
+
24
+ Then, to run the tests, do:
25
+ ```bash
26
+ cd imdclient/tests/hpc_testing/gromacs
27
+ chmod +x validate_gmx.sh
28
+
29
+ ./validate_gmx.sh \
30
+ --gmx_binary /path/to/gmx
31
+ ```
32
+
33
+ Or, for MPI builds,
34
+ ```bash
35
+ ./validate_gmx.sh \
36
+ --gmx_binary /path/to/gmx \
37
+ --mpi
38
+ ```
39
+
40
+ To validate against your own simulation files, see `validate_gmx.sh` for
41
+ command line arguments.
42
+
43
+ ### Compiling on ASU's Sol supercomputer
44
+
45
+ Allocate a GPU node on SOL and clone in https://gitlab.com/ljwoods2/gromacs.git
46
+
47
+ After cloning, do:
48
+ ```bash
49
+ git checkout imd-v3
50
+ module load cmake/3.30.2
51
+ module load gcc-12.1.0-gcc-11.2.0
52
+ moudle load cuda-12.6.1-gcc-12.1.0
53
+ module load openmpi/4.1.5
54
+
55
+ mkdir -p build_gpu
56
+ cd build_gpu
57
+
58
+ cmake .. -DGMX_BUILD_OWN_FFTW=ON -DGMX_GPU=CUDA -DGMX_MPI=ON
59
+ make -j 4
60
+ make install
61
+ source /your/installation/prefix/here/bin/GMXRC
62
+ ```
63
+ <!--
64
+ After GROMACS has been built, change into the directory containing this file.
65
+
66
+ To test on one node, run this in the shell (assuming there are 4 cores available):
67
+ ```bash
68
+ /home/ljwoods2/workspace/gromacs/build_mpi/bin/gmx grompp \
69
+ -f gmx_gpu_test.mdp \
70
+ -c struct.gro \
71
+ -p gmx_gpu_test.top \
72
+ -imd struct_imd.gro \
73
+ -o gmx_gpu_test.tpr \
74
+ -maxwarn 1
75
+
76
+ /home/ljwoods2/workspace/gromacs/build_mpi/bin/gmx mdrun \
77
+ -s gmx_gpu_test.tpr \
78
+ -o gmx_gpu_test.trr \
79
+ -imdwait \
80
+ -ntmpi 2 \
81
+ -ntomp 2
82
+ ```
83
+ To test on multiple nodes, run this in the shell (assuming there are 4 nodes and 16 cores available, with 1 GPU on each node):
84
+
85
+ ```bash
86
+ module load openmpi/4.1.5
87
+
88
+ /home/ljwoods2/workspace/gromacs/build_mpi/bin/mpirun \
89
+ -np 4 \
90
+ gmx_mpi mdrun \
91
+ -s gmx_gpu_test.tpr \
92
+ -o gmx_gpu_test.trr \
93
+ -imdwait \
94
+ -ntomp 4 \
95
+ -gpu_id 0
96
+ ```
97
+
98
+ And in a different shell (from the same directory), run the following commands:
99
+
100
+ ```bash
101
+ module load mamba
102
+ # Environment containing IMDClient
103
+ source activate imdclient-test
104
+
105
+ mkdir tmp_test
106
+
107
+ python imdclient/tests/test_manual.py \
108
+ --topol_arg imdclient/tests/hpc_testing/gromacs/struct.gro \
109
+ --traj_arg imdclient/tests/hpc_testing/gromacs/gmx_gpu_test.trr \
110
+ --first_frame_arg 0 \
111
+ --tmp_path tmp_test
112
+ ``` -->
@@ -0,0 +1,58 @@
1
+ title = PRODUCTION IN NPT
2
+ ld-seed = 1
3
+ ; Run parameters
4
+ integrator = md ; leap-frog integrator
5
+ nsteps = 1000 ; 1 * 1000 = 1 ps
6
+ dt = 0.001 ; 1 fs
7
+ ; Output control
8
+ nstxout = 10 ; save coordinates every 10 fs
9
+ nstvout = 10 ; save velocities every 10 fs
10
+ nstfout = 10
11
+ nstenergy = 10 ; save energies every 10 fs
12
+ nstlog = 10 ; update log file every 10 fs
13
+ ; Center of mass (COM) motion
14
+ nstcomm = 10 ; remove COM motion every 10 steps
15
+ comm-mode = Linear ; remove only COM translation (liquids in PBC)
16
+ ; Bond parameters
17
+ continuation = yes ; first dynamics run
18
+ constraint_algorithm = lincs ; holonomic constraints
19
+ constraints = all-bonds ; all bonds lengths are constrained
20
+ lincs_iter = 1 ; accuracy of LINCS
21
+ lincs_order = 4 ; also related to accuracy
22
+ ; Nonbonded settings
23
+ cutoff-scheme = Verlet ; Buffered neighbor searching
24
+ ns_type = grid ; search neighboring grid cells
25
+ nstlist = 10 ; 10 fs, largely irrelevant with Verlet
26
+ rcoulomb = 1.0 ; short-range electrostatic cutoff (in nm)
27
+ rvdw = 1.0 ; short-range van der Waals cutoff (in nm)
28
+ DispCorr = EnerPres ; account for cut-off vdW scheme
29
+ ; Electrostatics
30
+ coulombtype = PME ; Particle Mesh Ewald for long-range electrostatics
31
+ pme_order = 4 ; cubic interpolation
32
+ fourierspacing = 0.12 ; grid spacing for FFT
33
+ ; Temperature coupling is on
34
+ tcoupl = Nose-Hoover ; good for production, after equilibration
35
+ ; we define separate thermostats for the solute and solvent (need to adapt)
36
+ ; see default groups defined by Gromacs for your system or define your own (make_ndx)
37
+ tc-grps = Protein SOL ; the separate groups for the thermostats
38
+ tau-t = 1.0 1.0 ; time constants for thermostats (ps)
39
+ ref-t = 300 300 ; reference temperature for thermostats (K)
40
+ ; Pressure coupling is off
41
+ pcoupl = Parrinello-Rahman ; good for production, after equilibration
42
+ tau-p = 2.0 ; time constant for barostat (ps)
43
+ compressibility = 4.5e-5 ; compressibility (1/bar) set to water at ~300K
44
+ ref-p = 1.0 ; reference pressure for barostat (bar)
45
+ ; Periodic boundary conditions
46
+ pbc = xyz ; 3-D PBC
47
+ ; Velocity generation
48
+ gen_vel = no
49
+ IMD-group = System
50
+ IMD-nst = 10
51
+ IMD-version = 3
52
+ IMD-time = yes
53
+ IMD-box = yes
54
+ IMD-coords = yes
55
+ IMD-unwrap = no
56
+ IMD-vels = yes
57
+ IMD-forces = yes
58
+ IMD-energies = yes