API Documentation

IMDClient module

class imdclient.IMDClient.IMDClient(host, port, n_atoms, socket_bufsize=None, multithreaded=True, continue_after_disconnect=None, **kwargs)[source]
Parameters:
  • host (str) – Hostname of the server

  • port (int) – Port number of the server

  • n_atoms (int) – Number of atoms in the simulation

  • socket_bufsize (int, (optional)) – Size of the socket buffer in bytes. Default is to use the system default

  • buffer_size (int (optional)) – IMDFrameBuffer will be filled with as many IMDFrame fit in buffer_size bytes [10MB]

  • timeout (int, optional) – Timeout for the socket in seconds [5]

  • continue_after_disconnect (bool, optional [None]) – If True, the client will attempt to change the simulation engine’s waiting behavior to non-blocking after the client disconnects. If False, the client will attempt to change it to blocking. If None, the client will not attempt to change the simulation engine’s behavior.

  • **kwargs (dict (optional)) – Additional keyword arguments to pass to the BaseIMDProducer and IMDFrameBuffer

get_imdframe()[source]
Returns:

The next frame from the IMD server

Return type:

IMDFrame

Raises:

EOFError – If there are no more frames to read from the stream

get_imdsessioninfo()[source]
Returns:

Information about the IMD session

Return type:

IMDSessionInfo

signal_handler(*args, **kwargs)[source]

Catch SIGINT to allow clean shutdown on CTRL+C.

This also ensures that main thread execution doesn’t get stuck waiting in buf.pop_full_imdframe()

stop()[source]

Stop the client and close the connection

class imdclient.IMDClient.BaseIMDProducer(conn, buffer, sinfo, n_atoms, multithreaded, error_queue, timeout=5, **kwargs)[source]
Parameters:
  • conn (socket.socket) – Connection object to the server

  • buffer (IMDFrameBuffer) – Buffer object to hold IMD frames. If multithreaded is False, this argument is ignored

  • sinfo (IMDSessionInfo) – Information about the IMD session

  • n_atoms (int) – Number of atoms in the simulation

  • multithreaded (bool) – If True, socket interaction will occur in a separate thread & frames will be buffered. Single-threaded, blocking IMDClient should only be used in testing

  • error_queue (queue.Queue) – Queue to hold errors produced by the producer thread

  • timeout (int, optional) – Timeout for the socket in seconds [5]

property daemon

A boolean value indicating whether this thread is a daemon thread.

This must be set before start() is called, otherwise RuntimeError is raised. Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False.

The entire Python program exits when only daemon threads are left.

getName()

Return a string used for identification purposes only.

This method is deprecated, use the name attribute instead.

property ident

Thread identifier of this thread or None if it has not been started.

This is a nonzero integer. See the get_ident() function. Thread identifiers may be recycled when a thread exits and another thread is created. The identifier is available even after the thread has exited.

isDaemon()

Return whether this thread is a daemon.

This method is deprecated, use the daemon attribute instead.

is_alive()

Return whether the thread is alive.

This method returns True just before the run() method starts until just after the run() method terminates. See also the module function enumerate().

join(timeout=None)

Wait until the thread terminates.

This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.

When the timeout argument is present and not None, it should be a floating-point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call is_alive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.

When the timeout argument is not present or None, the operation will block until the thread terminates.

A thread can be join()ed many times.

join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.

property name

A string used for identification purposes only.

It has no semantics. Multiple threads may be given the same name. The initial name is set by the constructor.

property native_id

Native integral thread ID of this thread, or None if it has not been started.

This is a non-negative integer. See the get_native_id() function. This represents the Thread ID as reported by the kernel.

run()[source]

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

setDaemon(daemonic)

Set whether this thread is a daemon.

This method is deprecated, use the .daemon property instead.

setName(name)

Set the name string for this thread.

This method is deprecated, use the name attribute instead.

start()

Start the thread’s activity.

It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.

This method will raise a RuntimeError if called more than once on the same thread object.

class imdclient.IMDClient.IMDProducerV2(conn, buffer, sinfo, n_atoms, multithreaded, error_queue, **kwargs)[source]
property daemon

A boolean value indicating whether this thread is a daemon thread.

This must be set before start() is called, otherwise RuntimeError is raised. Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False.

The entire Python program exits when only daemon threads are left.

getName()

Return a string used for identification purposes only.

This method is deprecated, use the name attribute instead.

property ident

Thread identifier of this thread or None if it has not been started.

This is a nonzero integer. See the get_ident() function. Thread identifiers may be recycled when a thread exits and another thread is created. The identifier is available even after the thread has exited.

isDaemon()

Return whether this thread is a daemon.

This method is deprecated, use the daemon attribute instead.

is_alive()

Return whether the thread is alive.

This method returns True just before the run() method starts until just after the run() method terminates. See also the module function enumerate().

join(timeout=None)

Wait until the thread terminates.

This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.

When the timeout argument is present and not None, it should be a floating-point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call is_alive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.

When the timeout argument is not present or None, the operation will block until the thread terminates.

A thread can be join()ed many times.

join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.

property name

A string used for identification purposes only.

It has no semantics. Multiple threads may be given the same name. The initial name is set by the constructor.

property native_id

Native integral thread ID of this thread, or None if it has not been started.

This is a non-negative integer. See the get_native_id() function. This represents the Thread ID as reported by the kernel.

run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

setDaemon(daemonic)

Set whether this thread is a daemon.

This method is deprecated, use the .daemon property instead.

setName(name)

Set the name string for this thread.

This method is deprecated, use the name attribute instead.

start()

Start the thread’s activity.

It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.

This method will raise a RuntimeError if called more than once on the same thread object.

class imdclient.IMDClient.IMDProducerV3(conn, buffer, sinfo, n_atoms, multithreaded, error_queue, **kwargs)[source]
property daemon

A boolean value indicating whether this thread is a daemon thread.

This must be set before start() is called, otherwise RuntimeError is raised. Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False.

The entire Python program exits when only daemon threads are left.

getName()

Return a string used for identification purposes only.

This method is deprecated, use the name attribute instead.

property ident

Thread identifier of this thread or None if it has not been started.

This is a nonzero integer. See the get_ident() function. Thread identifiers may be recycled when a thread exits and another thread is created. The identifier is available even after the thread has exited.

isDaemon()

Return whether this thread is a daemon.

This method is deprecated, use the daemon attribute instead.

is_alive()

Return whether the thread is alive.

This method returns True just before the run() method starts until just after the run() method terminates. See also the module function enumerate().

join(timeout=None)

Wait until the thread terminates.

This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.

When the timeout argument is present and not None, it should be a floating-point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call is_alive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.

When the timeout argument is not present or None, the operation will block until the thread terminates.

A thread can be join()ed many times.

join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.

property name

A string used for identification purposes only.

It has no semantics. Multiple threads may be given the same name. The initial name is set by the constructor.

property native_id

Native integral thread ID of this thread, or None if it has not been started.

This is a non-negative integer. See the get_native_id() function. This represents the Thread ID as reported by the kernel.

run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

setDaemon(daemonic)

Set whether this thread is a daemon.

This method is deprecated, use the .daemon property instead.

setName(name)

Set the name string for this thread.

This method is deprecated, use the name attribute instead.

start()

Start the thread’s activity.

It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.

This method will raise a RuntimeError if called more than once on the same thread object.

class imdclient.IMDClient.IMDFrameBuffer(imdsinfo, n_atoms, buffer_size=10485760, pause_empty_proportion=0.25, unpause_empty_proportion=0.5, **kwargs)[source]

Acts as interface between producer (IMDProducer) and consumer (IMDClient) threads when IMDClient runs in multithreaded mode

Parameters:
  • imdsinfo (IMDSessionInfo) – Information about the IMD session

  • n_atoms (int) – Number of atoms in the simulation

  • buffer_size (int, optional) – Size of the buffer in bytes [10MB]

  • pause_empty_proportion (float, optional) – Lower threshold proportion of the buffer’s IMDFrames that are empty before the simulation is paused [0.25]

  • unpause_empty_proportion (float, optional) – Proportion of the buffer’s IMDFrames that must be empty before the simulation is unpaused [0.5]

pop_full_imdframe()[source]

Put empty_ts in the empty_q and get the next full timestep

class imdclient.IMDClient.IMDFrame(n_atoms, imdsinfo)[source]