<jupyter_start><jupyter_text>In this notebook we simulate rounded cubes using the [DEM component](https://hoomd-blue.readthedocs.io/en/stable/module-dem-pair.htmlhoomd.dem.pair.WCA) of HOOMD-Blue. We visualize the shapes using the povray backend and color them by the distance to their nearest neighbor.<jupyter_code>import flowws
import gtar
from hoomd_flowws.Init import Init
from hoomd_flowws.DEMInteraction import DEMInteraction
from hoomd_flowws.Run import Run
from hoomd_flowws.ShapeDefinition import ShapeDefinition

import json
import plato, plato.draw.povray as draw
import freud
import numpy as np
import IPython
import ipywidgets
shape = dict(type='cube', modifications=[dict(type='scale', factor=2), dict(type='round', radius=.5)])

storage = flowws.DirectoryStorage()
stages = [
    ShapeDefinition(shape_arguments=[shape]),
    Init(number=128),
    DEMInteraction(type='wca'),
    Run(steps=1e3, integrator='langevin'),
    Run(steps=1e5, integrator='langevin', compress_to=.8, dump_period=1e4),
]

flowws.Workflow(stages, storage).run();
num_frames = 0

def get_frame(frame=-1):
    global num_frames
    with gtar.GTAR('dump.sqlite', 'r') as traj:
        (posRec, quatRec, boxRec), frames = traj.framesWithRecordsNamed(['position', 'orientation', 'box'])

        for (_, type_shapes) in traj.recordsNamed('type_shapes.json'):
            type_shapes = json.loads(type_shapes)

        num_frames = len(frames)
        positions = traj.getRecord(posRec, frames[frame])
        orientations = traj.getRecord(quatRec, frames[frame])
        box = traj.getRecord(boxRec, frames[frame])

    shapedef = type_shapes[0]
    return positions, orientations, box, shapedef
def update(scene, frame=-1):
    (positions, orientations, box, shapedef) = get_frame(frame)
    # get nearest-neighbor distance, rescaled to go from 0-1, as cval
    fbox = freud.box.Box.from_box(box)
    nn = freud.locality.AABBQuery(fbox, positions)
    nlist = nn.query(positions, dict(exclude_ii=True, num_neighbors=1)).toNeighborList(True)
    cval = nlist.distances.copy()
    cval -= np.min(cval)
    cval /= np.max(cval)

    colors = plato.cmap.cubehelix(.25 + .5*cval, s=1)

    for prim in scene:
        prim.positions = positions
        prim.orientations = orientations
        prim.colors = colors
        prim.vertices = shapedef['vertices']
        prim.radius = shapedef['rounding_radius']

prim = draw.ConvexSpheropolyhedra()
features = dict(ambient_light=.4)
scene = draw.Scene(prim, features=features, zoom=1.3)
update(scene)

target = '../../gallery/flowws_cubes_povray.png'
scene.save(target)
IPython.display.Image(filename=target)
import plato.draw.vispy as interactive

live_scene = scene.convert(interactive)
live_scene.show()

@ipywidgets.interact(frame=(0, num_frames - 1))
def plot(frame=0):
    update(live_scene, frame)
    live_scene.render()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12192587461032213, 'fraction_numerical': 0.010045029442327675, 'mean_word_length': 4.500952380952381, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '190814', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1006, 'n_tokens_neox': 970, 'n_words': 208, 'path': 'flowws/rounded_cubes/Rounded Cubes.ipynb', 'repo_name': 'glotzerlab/plato-gallery', 'size': '2887'}