Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
IMDv3 prep
Browse files Browse the repository at this point in the history
  • Loading branch information
ljwoods2 committed Jun 16, 2024
1 parent 2ee0751 commit 25375c9
Show file tree
Hide file tree
Showing 4 changed files with 501 additions and 286 deletions.
15 changes: 7 additions & 8 deletions docs/source/protocol_proposed.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ The suggested changes to the protocol are as follows:
<val> (bit) (imdpull: true or false)
<val> (bit) (imdwait: true or false)
<val> (bit) (imdterm: true or false)
<val> (bit) (wrapped positions: true or false)
<val> (bit) (energies included: true or false)
<val> (bit) (dimensions included: true or false)
<val> (bit) (positions included: true or false)
<val> (bit) (velocities included: true or false)
<val> (bit) (forces included: true or false)
<val> (7 bits) (unused)
<val> (bit) (wrapped positions: true or false. if positions rate is 0, this is a placeholder value)
<val> (int32) (energies rate: number of steps that elapse between steps that contain energy data. 0 means never)
<val> (int32) (dimensions rate: number of steps that elapse between steps that contain dimension data. 0 means never)
<val> (int32) (positions rate: number of steps that elapse between steps that contain position data. 0 means never)
<val> (int32) (velocities rate: number of steps that elapse between steps that contain velocity data. 0 means never)
<val> (int32) (forces rate: number of steps that elapse between steps that contain force data. 0 means never)
"wrapped positions" will be a new ``.mdp`` setting which specifies whether the atoms' positions
should be adjusted to fit within the simulation box before sending. This is useful for visualization purposes.
Expand Down
38 changes: 37 additions & 1 deletion imdreader/IMDProtocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import struct
import logging
from enum import Enum, auto
from typing import Union
from dataclasses import dataclass
import abc
import threading

"""
IMD Packets have an 8 byte header and a variable length payload
Expand All @@ -17,7 +21,8 @@
"""
IMDHEADERSIZE = 8
IMDENERGYPACKETLENGTH = 40
IMDVERSION = 2
IMDBOXPACKETLENGTH = 36
IMDVERSIONS = {2, 3}


class IMDType(Enum):
Expand All @@ -31,6 +36,11 @@ class IMDType(Enum):
IMD_PAUSE = 7
IMD_TRATE = 8
IMD_IOERROR = 9
# New in IMD v3
IMD_BOX = 10
IMD_VELS = 11
IMD_FORCES = 12
IMD_EOS = 13


class IMDHeader:
Expand All @@ -41,6 +51,32 @@ def __init__(self, msg_type: IMDType, length: int):
self.length = length


@dataclass
class IMDSessionInfo:
"""Convenience class to represent the session information of an IMD connection
'<' represents little endian and '>' represents big endian
Data should be loaded into and out of buffers in the order of the fields in this class
if present in the session for that step, i.e.
1. energies,
2. dimensions,
etc.
"""

version: int
endianness: str
imdterm: Union[bool, None]
imdwait: Union[bool, None]
imdpull: Union[bool, None]
wrapped_coords: bool
energies: int
dimensions: int
positions: int
velocities: int
forces: int


def create_header_bytes(msg_type: IMDType, length: int):
# NOTE: add error checking for invalid packet msg_type here
type = msg_type.value
Expand Down
Loading

0 comments on commit 25375c9

Please sign in to comment.