moleculekit.viewer.molstar.renderserver module#

A render server: draw images for machines that cannot draw their own.

Rendering needs a browser, and it is far faster with a GPU. Neither is available in a sandbox or on a cluster node, so this serves the drawing half of render() over HTTP: a client turns its Molecule into a structure and a scene description, both plain data, and posts them here. The browser stays on this machine, which is what makes the arrangement worth having, since a GPU render is roughly thirty times faster than a software one on a small container.

Run it on the machine with the GPU:

python -m moleculekit.viewer.molstar.renderserver --port 8080

and point clients at it, either per call with render(..., server=...) or for a whole environment:

export MOLECULEKIT_RENDER_SERVER=http://gpuhost:8080

The service renders whatever it is sent and has no authentication, so bind it to a private interface, which is what the default host does. Do not put it on a public address.

moleculekit.viewer.molstar.renderserver.MAX_REQUEST_BYTES = 268435456#

Refuse bodies larger than this. Structures and volumes arrive base64 encoded, so this allows a very large complex, or a 256-cell grid, while still bounding what one request can cost: the body is read into memory and parsed, and passed on to the browser as JSON again, so a request peaks at several times its own size.

class moleculekit.viewer.molstar.renderserver.RenderHandler(request, client_address, server)#

Bases: BaseHTTPRequestHandler

Serve POST /render and GET /health.

do_GET()#

Answer a health check.

do_POST()#

Render one image and return it as a PNG.

log_message(format, *args)#

Send request logs to the module logger rather than stderr.

server_version = 'moleculekit-render'#
moleculekit.viewer.molstar.renderserver.main()#

Run the render server from the command line.

Return type:

None

moleculekit.viewer.molstar.renderserver.serve(host='127.0.0.1', port=8080)#

Serve renders until interrupted.

The browser is started before the first request and reused, so only the server start pays for it.

Parameters:
  • host (str) – Interface to bind. The default keeps the service on this machine; use an address on a private network to serve other machines.

  • port (int) – Port to listen on.

Raises:

RuntimeError – If no browser can be started, since the service could serve nothing.

Return type:

None