Skip to content

Commit 8c90c3d

Browse files
Add ZnDraw visualizer (#4967)
Description of changes: - add support for the ZnDraw visualizer
2 parents ba9d2f0 + bab0796 commit 8c90c3d

File tree

6 files changed

+728
-6
lines changed

6 files changed

+728
-6
lines changed

doc/bibliography.bib

+10
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,16 @@ @Article{durlofsky87a
432432
doi = {10.1017/S002211208700171X},
433433
}
434434

435+
@TechReport{elijosius24a,
436+
title = {Zero Shot Molecular Generation via Similarity Kernels},
437+
author = {Elijo{\v s}ius, Rokas and Zills, Fabian and Batatia, Ilyes and Norwood, Sam Walton and Kov{\'a}cs, D{\'a}vid P{\'e}ter and Holm, Christian and Cs{\'a}nyi, G{\'a}bor},
438+
year = {2024},
439+
type = {Preprint},
440+
number = {arXiv:2402.08708},
441+
doi = {10.48550/arXiv.2402.08708},
442+
institution = {arXiv},
443+
}
444+
435445
@Article{ermak78a,
436446
title={{B}rownian dynamics with hydrodynamic interactions},
437447
author={Ermak, Donald L. and McCammon, J. A.},

doc/sphinx/conf.py.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ napoleon_use_param = False
258258

259259
# Suppress warnings for features not compiled in
260260
# https://stackoverflow.com/questions/12206334/sphinx-autosummary-toctree-contains-reference-to-nonexisting-document-warnings
261-
autodoc_mock_imports = ['featuredefs', 'matplotlib', 'OpenGL', 'vtk']
261+
autodoc_mock_imports = ['featuredefs', 'matplotlib', 'OpenGL', 'vtk', 'zndraw', 'znsocket', 'znjson']
262262

263263
# Add custom stylesheets
264264
def setup(app):

doc/sphinx/installation.rst

+6
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ Optionally the ccmake utility can be installed for easier configuration:
128128
129129
sudo apt install cmake-curses-gui
130130
131+
To install the ZnDraw visualizer:
132+
133+
.. code-block:: bash
134+
135+
python3 -m pip install --user -c requirements.txt 'zndraw==0.4.5'
136+
131137
.. _Nvidia GPU acceleration:
132138

133139
Nvidia GPU acceleration

doc/sphinx/visualization.rst

+86-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ to user input. It requires the Python module *PyOpenGL*.
1212
It is not meant to produce high quality renderings, but rather to
1313
debug the simulation setup and equilibration process.
1414

15+
.. _OpenGL visualizer:
16+
17+
OpenGL visualizer
18+
-----------------
19+
1520
.. _General usage:
1621

1722
General usage
18-
-------------
23+
~~~~~~~~~~~~~
1924

2025
The recommended usage is to instantiate the visualizer and pass it the
21-
:class:`espressomd.System() <espressomd.system.System>` object. Then write
26+
:class:`~espressomd.system.System` object. Then write
2227
your integration loop in a separate function, which is started in a
2328
non-blocking thread. Whenever needed, call ``update()`` to synchronize
2429
the renderer with your system. Finally start the blocking visualization
@@ -50,7 +55,7 @@ window with ``start()``. See the following minimal code example::
5055
.. _Setting up the visualizer:
5156

5257
Setting up the visualizer
53-
-------------------------
58+
~~~~~~~~~~~~~~~~~~~~~~~~~
5459

5560
:class:`espressomd.visualization.openGLLive()`
5661

@@ -81,7 +86,6 @@ live plotting (see sample script :file:`/samples/visualization_ljliquid.py`).
8186
default package manager of your operating system. On Ubuntu the required package is called ``libgle3-dev``,
8287
on Fedora ``libgle`` -- just to name two examples.
8388

84-
8589
.. _Running the visualizer:
8690

8791
Running the visualizer
@@ -292,10 +296,88 @@ With the keyword ``drag_enabled`` set to ``True``, the mouse can be used to
292296
exert a force on particles in drag direction (scaled by ``drag_force`` and the
293297
distance of particle and mouse cursor).
294298

299+
.. _ZnDraw:
300+
301+
ZnDraw visualizer
302+
-----------------
303+
304+
|es| supports the ZnDraw visualizer :cite:`elijosius24a` in Jupyter Notebooks.
305+
With ZnDraw [1]_, you can visualize your simulation live in a notebook or
306+
web browser. The visualizer is based on ``THREE.js``.
307+
308+
.. _ZnDraw General usage:
309+
310+
General usage
311+
~~~~~~~~~~~~~
312+
313+
The recommended usage is to instantiate the visualizer :class:`espressomd.zn.Visualizer` and pass it the :class:`~espressomd.system.System` object.
314+
With the initialization you can also assign all particle types a color and radii through a type mapping. There are standard
315+
colors like ``red``, ``black`` etc., but one can also use hex colors like ``#ff0000``. The radii can be set to a float value.
316+
Then write your integration loop in a separate function, and call the update function of the visualizer to capture
317+
the current state of the system and visualize it. Note that the visualizer needs to be started by pressing space.
318+
319+
Example code::
320+
321+
import espressomd
322+
import espressomd.zn
323+
324+
system = espressomd.System(box_l=[10, 10, 10])
325+
system.cell_system.skin = 0.4
326+
system.time_step = 0.001
327+
328+
system.part.add(pos=[1, 1, 1], v=[1, 0, 0])
329+
system.part.add(pos=[9, 9, 9], v=[0, 1, 0])
330+
331+
vis = espressomd.zn.Visualizer(system, colors={0: "red"}, radii={0: 0.5})
332+
333+
for i in range(1000):
334+
system.integrator.run(25)
335+
vis.update()
336+
337+
The visualizer supports further features like bonds, constraints, folding and lattice-Boltzmann solvers. The particle coordinates
338+
can be folded by initalizing the visualizer with the keyword ``folded=True``. The display of bonds can be enabled by setting
339+
``bonds=True``.
340+
341+
Constraints can be drawn using the :meth:`~espressomd.zn.Visualizer.draw_constraints` method.
342+
The method takes a list of all ESPResSo shapes that should be drawn as an argument.
343+
344+
Furthermore the visualizer supports the visualization of the lattice-Boltzmann solver. The lattice-Boltzmann solver can be visualized
345+
by setting the keyword ``vector_field`` to a lattice-Boltzmann solver :class:`~espressomd.zn.LBField` object, which has to be created
346+
before initializing the visualizer and takes in several parameters like the node spacing, node offset and scale. One can also apply a
347+
color map to the vector field by setting the keyword ``arrow_config`` to a dictionary containing the arrow settings.
348+
349+
The arrow config contains a ``colormap`` using a list of 2 HSL-color values from which vector colors are interpolated using their length
350+
as a criterium. The ``normalize`` boolean which normalizes the color to the largest vector. The ``colorrange`` list which is only used when
351+
``normalize`` is false and describes the range to what the colorrange is applied to. ``scale_vector_thickness`` is a boolean and changes
352+
the thickness scaling of the vectors and ``opacity`` is a float value that sets the opacity of the vectors.
353+
354+
An example code snippet containing the :class:`~espressomd.zn.LBField` object::
355+
356+
import espressomd.zn
357+
358+
color = {0: "#00f0f0"}
359+
radii = {0: 0.5}
360+
arrows_config = {'colormap': [[-0.5, 0.9, 0.5], [-0.0, 0.9, 0.5]],
361+
'normalize': True,
362+
'colorrange': [0, 1],
363+
'scale_vector_thickness': True,
364+
'opacity': 1.0}
365+
366+
lbfield = espressomd.zn.LBField(system, step_x=2, step_y=2, step_z=5, scale=1)
367+
vis = espressomd.zn.Visualizer(system, colors=color, radii=radii, folded=True,
368+
vector_field=lbfield)
369+
370+
vis.draw_constraints([wall1, wall2])
371+
295372
.. _Visualization example scripts:
296373

297374
Visualization example scripts
298375
-----------------------------
299376

300377
Various :ref:`Sample Scripts` can be found in :file:`/samples/visualization_*.py`
301378
or in the :ref:`Tutorials` "Visualization" and "Charged Systems".
379+
380+
____
381+
382+
.. [1]
383+
https://github.com/zincware/ZnDraw

maintainer/CI/doc_warnings.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ if [ "${?}" = "0" ]; then
5151
# skip if broken link refers to a standard Python type or to a
5252
# class/function from an imported module other than espressomd
5353
is_standard_type_or_module="false"
54-
grep -Pq '^([a-zA-Z0-9_]+Error|[a-zA-Z0-9_]*Exception|(?!espressomd\.)[a-zA-Z0-9_]+\.[a-zA-Z0-9_\.]+)$' <<< "${reference}"
54+
grep -Pq '^([a-zA-Z0-9_]+Error|[a-zA-Z0-9_]*Exception|ConverterBase|(?!espressomd\.)[a-zA-Z0-9_]+\.[a-zA-Z0-9_\.]+)$' <<< "${reference}"
5555
[ "${?}" = "0" ] && is_standard_type_or_module="true"
5656
# private objects are not documented and cannot be linked
5757
is_private="false"

0 commit comments

Comments
 (0)