imdclient 0.1.3__py3-none-any.whl → 0.2.0b0__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 (48) hide show
  1. imdclient/IMDClient.py +43 -12
  2. imdclient/IMDProtocol.py +1 -0
  3. imdclient/__init__.py +0 -5
  4. imdclient/data/gromacs/md/gromacs_v3_nst1.mdp +3 -3
  5. imdclient/data/namd/md/namd3 +0 -0
  6. imdclient/data/namd/md/namd_v3_nst_1.namd +1 -1
  7. imdclient/tests/base.py +108 -83
  8. imdclient/tests/conftest.py +0 -39
  9. imdclient/tests/datafiles.py +16 -1
  10. imdclient/tests/docker_testing/docker.md +1 -1
  11. imdclient/tests/hpc_testing/gromacs/README.md +112 -0
  12. imdclient/tests/hpc_testing/gromacs/gmx_gpu_test.mdp +58 -0
  13. imdclient/tests/hpc_testing/gromacs/gmx_gpu_test.top +11764 -0
  14. imdclient/tests/hpc_testing/gromacs/struct.gro +21151 -0
  15. imdclient/tests/hpc_testing/gromacs/validate_gmx.sh +90 -0
  16. imdclient/tests/hpc_testing/lammps/README.md +62 -0
  17. imdclient/tests/hpc_testing/lammps/lammps_v3_nst_1.in +71 -0
  18. imdclient/tests/hpc_testing/lammps/topology_after_min.data +8022 -0
  19. imdclient/tests/hpc_testing/lammps/validate_lmp.sh +66 -0
  20. imdclient/tests/hpc_testing/namd/README.md +147 -0
  21. imdclient/tests/hpc_testing/namd/alanin.params +402 -0
  22. imdclient/tests/hpc_testing/namd/alanin.pdb +77 -0
  23. imdclient/tests/hpc_testing/namd/alanin.psf +206 -0
  24. imdclient/tests/hpc_testing/namd/namd_v3_nst_1.namd +59 -0
  25. imdclient/tests/hpc_testing/namd/validate_namd.sh +71 -0
  26. imdclient/tests/minimalreader.py +86 -0
  27. imdclient/tests/server.py +6 -14
  28. imdclient/tests/test_gromacs.py +15 -3
  29. imdclient/tests/test_imdclient.py +26 -7
  30. imdclient/tests/test_lammps.py +22 -19
  31. imdclient/tests/test_manual.py +224 -66
  32. imdclient/tests/test_namd.py +39 -16
  33. imdclient/tests/test_utils.py +31 -0
  34. imdclient/utils.py +50 -17
  35. {imdclient-0.1.3.dist-info → imdclient-0.2.0b0.dist-info}/METADATA +60 -39
  36. imdclient-0.2.0b0.dist-info/RECORD +53 -0
  37. {imdclient-0.1.3.dist-info → imdclient-0.2.0b0.dist-info}/WHEEL +1 -1
  38. {imdclient-0.1.3.dist-info → imdclient-0.2.0b0.dist-info/licenses}/AUTHORS.md +4 -1
  39. {imdclient-0.1.3.dist-info → imdclient-0.2.0b0.dist-info/licenses}/LICENSE +3 -1
  40. imdclient/IMD.py +0 -130
  41. imdclient/backends.py +0 -352
  42. imdclient/results.py +0 -332
  43. imdclient/streamanalysis.py +0 -1056
  44. imdclient/streambase.py +0 -199
  45. imdclient/tests/test_imdreader.py +0 -658
  46. imdclient/tests/test_stream_analysis.py +0 -61
  47. imdclient-0.1.3.dist-info/RECORD +0 -42
  48. {imdclient-0.1.3.dist-info → imdclient-0.2.0b0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,206 @@
1
+ PSF
2
+
3
+ 11 !NTITLE
4
+ REMARKS FILENAME="/usr/people/nonella/xplor/benchmark1/ALANIN.PSF"
5
+ REMARKS PARAM11.PRO ( from PARAM6A )
6
+ REMARKS ===========
7
+ REMARKS PROTEIN PARAMETERS:
8
+ REMARKS PEPTIDE GEOMETRY FROM RAMACHANDRAN ET AL BBA 359:298 (1974)
9
+ REMARKS TORSIONS FROM HAGLER ET AL JACS 98:4600 (1976)
10
+ REMARKS LENNARD-JONES NONBONDED PARAMETERS WITH SPECIAL TREATMENT OF 1:4
11
+ REMARKS CARBON-CARBON INTERACTIONS: JORGENSON ET. AL.
12
+ REMARKS JACS 103:3976-3985 WITH 1-4 RC=1.80/0.1
13
+ REMARKS
14
+ REMARKS DATE:16-Feb-89 11:21:29 created by user: nonella
15
+
16
+ 66 !NATOM
17
+ 1 MAIN 1 ACE CA CH3E 0.000000E+00 15.0350 0
18
+ 2 MAIN 1 ACE C C 0.450000 12.0110 0
19
+ 3 MAIN 1 ACE O O -0.450000 15.9994 0
20
+ 4 MAIN 2 ALA N NH1 -0.350000 14.0067 0
21
+ 5 MAIN 2 ALA H H 0.250000 1.00800 0
22
+ 6 MAIN 2 ALA CA CH1E 0.100000 13.0190 0
23
+ 7 MAIN 2 ALA CB CH3E 0.000000E+00 15.0350 0
24
+ 8 MAIN 2 ALA C C 0.450000 12.0110 0
25
+ 9 MAIN 2 ALA O O -0.450000 15.9994 0
26
+ 10 MAIN 3 ALA N NH1 -0.350000 14.0067 0
27
+ 11 MAIN 3 ALA H H 0.250000 1.00800 0
28
+ 12 MAIN 3 ALA CA CH1E 0.100000 13.0190 0
29
+ 13 MAIN 3 ALA CB CH3E 0.000000E+00 15.0350 0
30
+ 14 MAIN 3 ALA C C 0.450000 12.0110 0
31
+ 15 MAIN 3 ALA O O -0.450000 15.9994 0
32
+ 16 MAIN 4 ALA N NH1 -0.350000 14.0067 0
33
+ 17 MAIN 4 ALA H H 0.250000 1.00800 0
34
+ 18 MAIN 4 ALA CA CH1E 0.100000 13.0190 0
35
+ 19 MAIN 4 ALA CB CH3E 0.000000E+00 15.0350 0
36
+ 20 MAIN 4 ALA C C 0.450000 12.0110 0
37
+ 21 MAIN 4 ALA O O -0.450000 15.9994 0
38
+ 22 MAIN 5 ALA N NH1 -0.350000 14.0067 0
39
+ 23 MAIN 5 ALA H H 0.250000 1.00800 0
40
+ 24 MAIN 5 ALA CA CH1E 0.100000 13.0190 0
41
+ 25 MAIN 5 ALA CB CH3E 0.000000E+00 15.0350 0
42
+ 26 MAIN 5 ALA C C 0.450000 12.0110 0
43
+ 27 MAIN 5 ALA O O -0.450000 15.9994 0
44
+ 28 MAIN 6 ALA N NH1 -0.350000 14.0067 0
45
+ 29 MAIN 6 ALA H H 0.250000 1.00800 0
46
+ 30 MAIN 6 ALA CA CH1E 0.100000 13.0190 0
47
+ 31 MAIN 6 ALA CB CH3E 0.000000E+00 15.0350 0
48
+ 32 MAIN 6 ALA C C 0.450000 12.0110 0
49
+ 33 MAIN 6 ALA O O -0.450000 15.9994 0
50
+ 34 MAIN 7 ALA N NH1 -0.350000 14.0067 0
51
+ 35 MAIN 7 ALA H H 0.250000 1.00800 0
52
+ 36 MAIN 7 ALA CA CH1E 0.100000 13.0190 0
53
+ 37 MAIN 7 ALA CB CH3E 0.000000E+00 15.0350 0
54
+ 38 MAIN 7 ALA C C 0.450000 12.0110 0
55
+ 39 MAIN 7 ALA O O -0.450000 15.9994 0
56
+ 40 MAIN 8 ALA N NH1 -0.350000 14.0067 0
57
+ 41 MAIN 8 ALA H H 0.250000 1.00800 0
58
+ 42 MAIN 8 ALA CA CH1E 0.100000 13.0190 0
59
+ 43 MAIN 8 ALA CB CH3E 0.000000E+00 15.0350 0
60
+ 44 MAIN 8 ALA C C 0.450000 12.0110 0
61
+ 45 MAIN 8 ALA O O -0.450000 15.9994 0
62
+ 46 MAIN 9 ALA N NH1 -0.350000 14.0067 0
63
+ 47 MAIN 9 ALA H H 0.250000 1.00800 0
64
+ 48 MAIN 9 ALA CA CH1E 0.100000 13.0190 0
65
+ 49 MAIN 9 ALA CB CH3E 0.000000E+00 15.0350 0
66
+ 50 MAIN 9 ALA C C 0.450000 12.0110 0
67
+ 51 MAIN 9 ALA O O -0.450000 15.9994 0
68
+ 52 MAIN 10 ALA N NH1 -0.350000 14.0067 0
69
+ 53 MAIN 10 ALA H H 0.250000 1.00800 0
70
+ 54 MAIN 10 ALA CA CH1E 0.100000 13.0190 0
71
+ 55 MAIN 10 ALA CB CH3E 0.000000E+00 15.0350 0
72
+ 56 MAIN 10 ALA C C 0.450000 12.0110 0
73
+ 57 MAIN 10 ALA O O -0.450000 15.9994 0
74
+ 58 MAIN 11 ALA N NH1 -0.350000 14.0067 0
75
+ 59 MAIN 11 ALA H H 0.250000 1.00800 0
76
+ 60 MAIN 11 ALA CA CH1E 0.100000 13.0190 0
77
+ 61 MAIN 11 ALA CB CH3E 0.000000E+00 15.0350 0
78
+ 62 MAIN 11 ALA C C 0.450000 12.0110 0
79
+ 63 MAIN 11 ALA O O -0.450000 15.9994 0
80
+ 64 MAIN 12 CBX N NH1 -0.350000 14.0067 0
81
+ 65 MAIN 12 CBX H H 0.250000 1.00800 0
82
+ 66 MAIN 12 CBX CA CH3E 0.100000 15.0350 0
83
+
84
+ 65 !NBOND: bonds
85
+ 1 2 2 3 4 6 6 8
86
+ 8 9 4 5 6 7 2 4
87
+ 10 12 12 14 14 15 10 11
88
+ 12 13 8 10 16 18 18 20
89
+ 20 21 16 17 18 19 14 16
90
+ 22 24 24 26 26 27 22 23
91
+ 24 25 20 22 28 30 30 32
92
+ 32 33 28 29 30 31 26 28
93
+ 34 36 36 38 38 39 34 35
94
+ 36 37 32 34 40 42 42 44
95
+ 44 45 40 41 42 43 38 40
96
+ 46 48 48 50 50 51 46 47
97
+ 48 49 44 46 52 54 54 56
98
+ 56 57 52 53 54 55 50 52
99
+ 58 60 60 62 62 63 58 59
100
+ 60 61 56 58 64 66 64 65
101
+ 62 64
102
+
103
+ 96 !NTHETA: angles
104
+ 1 2 3 4 6 8 6 4 5
105
+ 4 6 7 6 8 9 8 6 7
106
+ 1 2 4 3 2 4 2 4 6
107
+ 2 4 5 10 12 14 12 10 11
108
+ 10 12 13 12 14 15 14 12 13
109
+ 6 8 10 9 8 10 8 10 12
110
+ 8 10 11 16 18 20 18 16 17
111
+ 16 18 19 18 20 21 20 18 19
112
+ 12 14 16 15 14 16 14 16 18
113
+ 14 16 17 22 24 26 24 22 23
114
+ 22 24 25 24 26 27 26 24 25
115
+ 18 20 22 21 20 22 20 22 24
116
+ 20 22 23 28 30 32 30 28 29
117
+ 28 30 31 30 32 33 32 30 31
118
+ 24 26 28 27 26 28 26 28 30
119
+ 26 28 29 34 36 38 36 34 35
120
+ 34 36 37 36 38 39 38 36 37
121
+ 30 32 34 33 32 34 32 34 36
122
+ 32 34 35 40 42 44 42 40 41
123
+ 40 42 43 42 44 45 44 42 43
124
+ 36 38 40 39 38 40 38 40 42
125
+ 38 40 41 46 48 50 48 46 47
126
+ 46 48 49 48 50 51 50 48 49
127
+ 42 44 46 45 44 46 44 46 48
128
+ 44 46 47 52 54 56 54 52 53
129
+ 52 54 55 54 56 57 56 54 55
130
+ 48 50 52 51 50 52 50 52 54
131
+ 50 52 53 58 60 62 60 58 59
132
+ 58 60 61 60 62 63 62 60 61
133
+ 54 56 58 57 56 58 56 58 60
134
+ 56 58 59 66 64 65 60 62 64
135
+ 63 62 64 62 64 66 62 64 65
136
+
137
+ 31 !NPHI: dihedrals
138
+ 2 4 6 8 1 2 4 6
139
+ 8 10 12 14 4 6 8 10
140
+ 6 8 10 12 14 16 18 20
141
+ 10 12 14 16 12 14 16 18
142
+ 20 22 24 26 16 18 20 22
143
+ 18 20 22 24 26 28 30 32
144
+ 22 24 26 28 24 26 28 30
145
+ 32 34 36 38 28 30 32 34
146
+ 30 32 34 36 38 40 42 44
147
+ 34 36 38 40 36 38 40 42
148
+ 44 46 48 50 40 42 44 46
149
+ 42 44 46 48 50 52 54 56
150
+ 46 48 50 52 48 50 52 54
151
+ 56 58 60 62 52 54 56 58
152
+ 54 56 58 60 58 60 62 64
153
+ 60 62 64 66
154
+
155
+ 32 !NIMPHI: impropers
156
+ 6 4 8 7 2 1 4 3
157
+ 4 2 6 5 12 10 14 13
158
+ 8 6 10 9 10 8 12 11
159
+ 18 16 20 19 14 12 16 15
160
+ 16 14 18 17 24 22 26 25
161
+ 20 18 22 21 22 20 24 23
162
+ 30 28 32 31 26 24 28 27
163
+ 28 26 30 29 36 34 38 37
164
+ 32 30 34 33 34 32 36 35
165
+ 42 40 44 43 38 36 40 39
166
+ 40 38 42 41 48 46 50 49
167
+ 44 42 46 45 46 44 48 47
168
+ 54 52 56 55 50 48 52 51
169
+ 52 50 54 53 60 58 62 61
170
+ 56 54 58 57 58 56 60 59
171
+ 62 60 64 63 64 62 66 65
172
+
173
+ 11 !NDON: donors
174
+ 4 5 10 11 16 17 22 23
175
+ 28 29 34 35 40 41 46 47
176
+ 52 53 58 59 64 65
177
+
178
+ 11 !NACC: acceptors
179
+ 3 2 9 8 15 14 21 20
180
+ 27 26 33 32 39 38 45 44
181
+ 51 50 57 56 63 62
182
+
183
+ 0 !NNB
184
+
185
+ 0 0 0 0 0 0 0 0
186
+ 0 0 0 0 0 0 0 0
187
+ 0 0 0 0 0 0 0 0
188
+ 0 0 0 0 0 0 0 0
189
+ 0 0 0 0 0 0 0 0
190
+ 0 0 0 0 0 0 0 0
191
+ 0 0 0 0 0 0 0 0
192
+ 0 0 0 0 0 0 0 0
193
+ 0 0
194
+
195
+ 33 0 !NGRP
196
+ 0 0 0 1 0 0 3 0 0
197
+ 6 0 0 7 0 0 9 0 0
198
+ 12 0 0 13 0 0 15 0 0
199
+ 18 0 0 19 0 0 21 0 0
200
+ 24 0 0 25 0 0 27 0 0
201
+ 30 0 0 31 0 0 33 0 0
202
+ 36 0 0 37 0 0 39 0 0
203
+ 42 0 0 43 0 0 45 0 0
204
+ 48 0 0 49 0 0 51 0 0
205
+ 54 0 0 55 0 0 57 0 0
206
+ 60 0 0 61 0 0 63 0 0
@@ -0,0 +1,59 @@
1
+ # This is a test namd configuration file
2
+
3
+ timestep 0.5
4
+ numsteps 10
5
+ structure alanin.psf
6
+ parameters alanin.params
7
+ coordinates alanin.pdb
8
+ exclude scaled1-4
9
+ 1-4scaling 0.4
10
+ outputname output[myReplica]
11
+ margin 1.0
12
+ stepspercycle 3
13
+ temperature 0
14
+
15
+ switching on
16
+ switchdist 7.0
17
+ cutoff 8.0
18
+ pairlistdist 9.0
19
+
20
+ # Add box dimensions
21
+ cellBasisVector1 32.76 0.0 0.0
22
+ cellBasisVector2 0.0 31.66 0.0
23
+ cellBasisVector3 0.0 0.0 32.89
24
+
25
+ DCDfile alanin.dcd
26
+ DCDfreq 1
27
+ DCDUnitCell yes
28
+ velDcdFile alanin.vel.dcd
29
+ velDcdFreq 1
30
+ forceDcdFile alanin.force.dcd
31
+ forceDcdFreq 1
32
+ XSTFile alanin.xst
33
+ xstFreq 1
34
+
35
+ #restartname alanin.restart
36
+ #restartfreq 10
37
+
38
+ #langevin on
39
+ #langevinTemp 300.0
40
+ #langevincol O
41
+
42
+ #constraints on
43
+
44
+ #fma on
45
+
46
+ seed 12345
47
+
48
+ IMDon yes
49
+ IMDport 8888
50
+ IMDfreq 1
51
+ IMDwait on
52
+ IMDversion 3
53
+ IMDsendPositions yes
54
+ IMDsendEnergies yes
55
+ IMDsendTime yes
56
+ IMDsendBoxDimensions yes
57
+ IMDsendVelocities yes
58
+ IMDsendForces yes
59
+ IMDwrapPositions yes
@@ -0,0 +1,71 @@
1
+ #!/bin/bash
2
+
3
+ NAMD_BINARY="namd3"
4
+ CONFIG_FILE="namd_v3_nst_1.namd"
5
+ OUTPUT_FILE="namd_output.log"
6
+ TOPOL_PATH="alanin.pdb"
7
+ TRAJ_PATH="alanin.dcd"
8
+ VEL_PATH="alanin.vel.dcd"
9
+ FORCE_PATH="alanin.force.dcd"
10
+
11
+ # Parse args
12
+ while [[ $# -gt 0 ]]; do
13
+ case $1 in
14
+ --namd_binary)
15
+ NAMD_BINARY="$2"
16
+ shift 2
17
+ ;;
18
+ --config_file)
19
+ CONFIG_FILE="$2"
20
+ shift 2
21
+ ;;
22
+ --topol_path)
23
+ TOPOL_PATH="$2"
24
+ shift 2
25
+ ;;
26
+ --traj_path)
27
+ TRAJ_PATH="$2"
28
+ shift 2
29
+ ;;
30
+ --vel_path)
31
+ VEL_PATH="$2"
32
+ shift 2
33
+ ;;
34
+ --force_path)
35
+ FORCE_PATH="$2"
36
+ shift 2
37
+ ;;
38
+ *)
39
+ echo "Unknown argument: $1"
40
+ exit 1
41
+ ;;
42
+ esac
43
+ done
44
+
45
+ # Start the simulation
46
+ $NAMD_BINARY $CONFIG_FILE &> "$OUTPUT_FILE" &
47
+
48
+ # Wait for the simulation to be ready
49
+ await_namd_imd() {
50
+ grep -q "INTERACTIVE MD AWAITING CONNECTION" $OUTPUT_FILE
51
+ }
52
+
53
+ while ! await_namd_imd; do
54
+ echo "Waiting for NAMD IMD readiness in $OUTPUT_FILE..."
55
+ sleep 5
56
+ done
57
+
58
+ # Run the test
59
+
60
+ echo "Running test with the following parameters:"
61
+ echo " Topology file: $TOPOL_PATH"
62
+ echo " Trajectory file: $TRAJ_PATH"
63
+ echo " Velocity file: $VEL_PATH"
64
+ echo " Force file: $FORCE_PATH"
65
+
66
+ python ../../test_manual.py \
67
+ --topol_path "$TOPOL_PATH" \
68
+ --traj_path "$TRAJ_PATH" \
69
+ --vel_path "$VEL_PATH" \
70
+ --force_path "$FORCE_PATH" \
71
+ --first_frame 0
@@ -0,0 +1,86 @@
1
+ import logging
2
+ import copy
3
+
4
+ from MDAnalysis.coordinates import core
5
+
6
+ from imdclient.IMDClient import IMDClient
7
+ from imdclient.utils import parse_host_port
8
+
9
+ logger = logging.getLogger("imdclient.IMDClient")
10
+
11
+
12
+ class MinimalReader:
13
+ """
14
+ Minimal reader for testing purposes
15
+
16
+ Parameters
17
+ ----------
18
+ filename : str
19
+ a string of the form "host:port" where host is the hostname
20
+ or IP address of the listening MD engine server and port
21
+ is the port number.
22
+ n_atoms : int
23
+ number of atoms in the system. defaults to number of atoms
24
+ in the topology. don't set this unless you know what you're doing
25
+ process_stream : bool (optional)
26
+ if True, the reader will process the stream of frames and
27
+ store them in the `trajectory` attribute. defaults to False.
28
+ kwargs : dict (optional)
29
+ keyword arguments passed to the constructed :class:`IMDClient`
30
+ """
31
+
32
+ def __init__(self, filename, n_atoms, process_stream=False, **kwargs):
33
+
34
+ self.imd_frame = None
35
+
36
+ # a trajectory of imd frames
37
+ self.trajectory = []
38
+
39
+ self.n_atoms = n_atoms
40
+
41
+ host, port = parse_host_port(filename)
42
+
43
+ # This starts the simulation
44
+ self._imdclient = IMDClient(host, port, n_atoms, **kwargs)
45
+
46
+ self._frame = -1
47
+
48
+ if process_stream:
49
+ self._process_stream()
50
+
51
+ def _read_next_frame(self):
52
+ try:
53
+ imd_frame = self._imdclient.get_imdframe()
54
+ except EOFError:
55
+ raise
56
+
57
+ self._frame += 1
58
+ self.imd_frame = imd_frame
59
+
60
+ # Modify the box dimensions to be triclinic
61
+ self._modify_box_dimesions()
62
+
63
+ logger.debug(f"MinimalReader: Loaded frame {self._frame}")
64
+
65
+ return self.imd_frame
66
+
67
+ def _modify_box_dimesions(self):
68
+ self.imd_frame.dimensions = core.triclinic_box(*self.imd_frame.box)
69
+
70
+ def _process_stream(self):
71
+ # Process the stream of frames
72
+ while True:
73
+ try:
74
+ self.trajectory.append(copy.deepcopy(self._read_next_frame()))
75
+ # `.copy()` might not be required but adding it to cover any edge cases where a refernce gets passed
76
+ logger.debug(
77
+ f"MinimalReader: Added frame {self._frame} to trajectory"
78
+ )
79
+ except EOFError:
80
+ break
81
+
82
+ def close(self):
83
+ """Gracefully shut down the reader. Stops the producer thread."""
84
+ logger.debug("MinimalReader: close() called")
85
+ if self._imdclient is not None:
86
+ self._imdclient.stop()
imdclient/tests/server.py CHANGED
@@ -1,15 +1,16 @@
1
1
  import socket
2
2
  import struct
3
- import numpy as np
4
3
  import threading
5
- import time
4
+ import logging
5
+
6
+ import numpy as np
7
+
6
8
  from imdclient.IMDProtocol import (
7
9
  IMDHeaderType,
8
10
  create_header_bytes,
9
11
  create_energy_bytes,
10
12
  IMDHEADERSIZE,
11
13
  )
12
- import logging
13
14
  from imdclient.IMDClient import sock_contains_data, read_into_buf, IMDHeader
14
15
 
15
16
  logger = logging.getLogger("imdclient.IMDClient")
@@ -93,7 +94,7 @@ class InThreadIMDServer:
93
94
  positions,
94
95
  wrapped_coords,
95
96
  velocities,
96
- forces
97
+ forces,
97
98
  )
98
99
  logger.debug(f"InThreadIMDServer: Sending session info")
99
100
  self.conn.sendall(sinfo)
@@ -101,14 +102,6 @@ class InThreadIMDServer:
101
102
  def join_accept_thread(self):
102
103
  self.accept_thread.join()
103
104
 
104
- def _expect_go(self):
105
- logger.debug(f"InThreadIMDServer: Waiting for go")
106
- head_buf = bytearray(IMDHEADERSIZE)
107
- read_into_buf(self.conn, head_buf)
108
- header = IMDHeader(head_buf)
109
- if header.type != IMDHeaderType.IMD_GO:
110
- raise ValueError("Expected IMD_GO packet, got something else")
111
-
112
105
  def send_frames(self, start, end):
113
106
  for i in range(start, end):
114
107
  self.send_frame(i)
@@ -126,7 +119,7 @@ class InThreadIMDServer:
126
119
  )
127
120
 
128
121
  self.conn.sendall(time_header + time)
129
-
122
+
130
123
  if self.imdsinfo.energies:
131
124
  energy_header = create_header_bytes(IMDHeaderType.IMD_ENERGIES, 1)
132
125
  energies = create_energy_bytes(
@@ -183,7 +176,6 @@ class InThreadIMDServer:
183
176
 
184
177
  self.conn.sendall(force_header + force)
185
178
 
186
-
187
179
  def expect_packet(self, packet_type, expected_length=None):
188
180
  head_buf = bytearray(IMDHEADERSIZE)
189
181
  read_into_buf(self.conn, head_buf)
@@ -1,6 +1,9 @@
1
- import MDAnalysis as mda
2
- import pytest
3
1
  import logging
2
+ from pathlib import Path
3
+ import re
4
+
5
+ import pytest
6
+
4
7
  from .base import IMDv3IntegrationTest
5
8
  from .datafiles import (
6
9
  GROMACS_GRO,
@@ -8,7 +11,6 @@ from .datafiles import (
8
11
  GROMACS_MDP_NST_1,
9
12
  GROMACS_MDP_NST_8,
10
13
  )
11
- from pathlib import Path
12
14
 
13
15
  logger = logging.getLogger("imdclient.IMDClient")
14
16
  file_handler = logging.FileHandler("gromacs_test.log")
@@ -46,6 +48,16 @@ class TestIMDv3Gromacs(IMDv3IntegrationTest):
46
48
  def topol(self):
47
49
  return Path(GROMACS_GRO).name
48
50
 
51
+ @pytest.fixture()
52
+ def dt(self, mdp):
53
+ pattern = re.compile(r"^\s*dt\s*=\s*(\S+)")
54
+ with open(mdp, "r") as file:
55
+ for line in file:
56
+ match = pattern.match(line)
57
+ if match:
58
+ return float(match.group(1))
59
+ raise ValueError(f"No dt found in {mdp}")
60
+
49
61
  # @pytest.fixture()
50
62
  # def match_string(self):
51
63
  # return "IMD: Will wait until I have a connection and IMD_GO orders."
@@ -1,10 +1,17 @@
1
1
  """Test for IMDClient functionality"""
2
2
 
3
+ import logging
4
+
5
+ import pytest
6
+ from numpy.testing import (
7
+ assert_allclose,
8
+ )
9
+ import MDAnalysis as mda
3
10
  from MDAnalysisTests.datafiles import (
4
11
  COORDINATES_TOPOLOGY,
5
12
  COORDINATES_H5MD,
6
13
  )
7
- import MDAnalysis as mda
14
+
8
15
  from imdclient.IMDClient import imdframe_memsize, IMDClient
9
16
  from imdclient.IMDProtocol import IMDHeaderType
10
17
  from .utils import (
@@ -12,12 +19,6 @@ from .utils import (
12
19
  create_default_imdsinfo_v3,
13
20
  )
14
21
  from .server import InThreadIMDServer
15
- from MDAnalysisTests.coordinates.base import (
16
- assert_allclose,
17
- )
18
- from MDAnalysisTests.coordinates.test_xdr import TRRReference
19
- import logging
20
- import pytest
21
22
 
22
23
 
23
24
  logger = logging.getLogger("imdclient.IMDClient")
@@ -69,6 +70,7 @@ class TestIMDClientV3:
69
70
  buffer_size=imdframe_memsize(universe.trajectory.n_atoms, imdsinfo)
70
71
  * 2,
71
72
  )
73
+ server.join_accept_thread()
72
74
  yield server, client
73
75
  client.stop()
74
76
  server.cleanup()
@@ -84,6 +86,7 @@ class TestIMDClientV3:
84
86
  port,
85
87
  universe.trajectory.n_atoms,
86
88
  )
89
+ server.join_accept_thread()
87
90
  yield server, client
88
91
  client.stop()
89
92
  server.cleanup()
@@ -149,6 +152,22 @@ class TestIMDClientV3:
149
152
  # server should receive disconnect from client (though it doesn't have to do anything)
150
153
  server.expect_packet(IMDHeaderType.IMD_DISCONNECT)
151
154
 
155
+ @pytest.mark.parametrize("cont", [True, False])
156
+ def test_continue_after_disconnect(self, universe, imdsinfo, port, cont):
157
+ server = InThreadIMDServer(universe.trajectory)
158
+ server.set_imdsessioninfo(imdsinfo)
159
+ server.handshake_sequence("localhost", port, first_frame=False)
160
+ client = IMDClient(
161
+ f"localhost",
162
+ port,
163
+ universe.trajectory.n_atoms,
164
+ continue_after_disconnect=cont,
165
+ )
166
+ server.join_accept_thread()
167
+ server.expect_packet(
168
+ IMDHeaderType.IMD_WAIT, expected_length=(int)(not cont)
169
+ )
170
+
152
171
 
153
172
  class TestIMDClientV3ContextManager:
154
173
  @pytest.fixture
@@ -1,7 +1,11 @@
1
- import MDAnalysis as mda
2
- import pytest
3
- from pathlib import Path
4
1
  import logging
2
+ from pathlib import Path
3
+ import re
4
+
5
+ import pytest
6
+ import MDAnalysis as mda
7
+
8
+ from .minimalreader import MinimalReader
5
9
  from .base import IMDv3IntegrationTest
6
10
  from .datafiles import LAMMPS_TOPOL, LAMMPS_IN_NST_1, LAMMPS_IN_NST_8
7
11
 
@@ -48,10 +52,15 @@ class TestIMDv3Lammps(IMDv3IntegrationTest):
48
52
  else:
49
53
  return 0
50
54
 
51
- # Not present in lammps-produced H5MD
52
55
  @pytest.fixture()
53
- def comp_dt(self):
54
- return False
56
+ def dt(self, inp):
57
+ pattern = re.compile(r"^\s*timestep\s*(\S+)")
58
+ with open(inp, "r") as file:
59
+ for line in file:
60
+ match = pattern.match(line)
61
+ if match:
62
+ return float(match.group(1))
63
+ raise ValueError(f"No dt found in {inp}")
55
64
 
56
65
  # This must wait until after imd stream has ended
57
66
  @pytest.fixture()
@@ -66,18 +75,12 @@ class TestIMDv3Lammps(IMDv3IntegrationTest):
66
75
 
67
76
  @pytest.fixture()
68
77
  def imd_u(self, docker_client, topol, tmp_path, port):
69
- u = mda.Universe(
70
- (tmp_path / topol),
71
- f"imd://localhost:{port}",
72
- atom_style="id type x y z",
73
- )
74
- with mda.Writer(
75
- (tmp_path / "imd.trr").as_posix(), u.trajectory.n_atoms
76
- ) as w:
77
- for ts in u.trajectory:
78
- w.write(u.atoms)
79
- yield mda.Universe(
80
- (tmp_path / topol),
81
- (tmp_path / "imd.trr"),
78
+ n_atoms = mda.Universe(
79
+ tmp_path / topol,
82
80
  atom_style="id type x y z",
81
+ convert_units=False,
82
+ ).atoms.n_atoms
83
+ u = MinimalReader(
84
+ f"imd://localhost:{port}", n_atoms=n_atoms, process_stream=True
83
85
  )
86
+ yield u