Interactivity
In [1]:
Copied!
import bubblebox as bb
help(bb.showcase.double_harmonic_chain)
import bubblebox as bb
help(bb.showcase.double_harmonic_chain)
Help on function double_harmonic_chain in module bubblebox.showcase: double_harmonic_chain(n_bubbles=200, size=(10, 10, 10), charge=20.0, force_params=array([4., 1.])) # Harmonic Chain Generates a double-layered structure of n_bubbles connected to their neighbors with harmonic potentials, and repelling all others with a coulomb potential Auhor: Audun Skau Hansen 2022 ## Keyword arguuments | Argument | Description | Default | | ----------- | ----------- | --- | | n_bubbles | number of bubbles | 120 | | size | size of simulation box | (10,10,10) | | charge | repulsive charge | 20.0 |
In [2]:
Copied!
m = bb.showcase.double_harmonic_chain(80)
m.view()
m = bb.showcase.double_harmonic_chain(80)
m.view()
Out[2]:
MDView(bg_color=[1.0, 1.0, 1.0], box=[10, 10, 10], colors=[[0.4993901038167592, 0.5549452882456589, 0.91639324…
In [3]:
Copied!
# relax geometry interactively
for i in range(1000):
for j in range(5):
m.advance()
m.vel_ *= 0.99
m.update_view()
# relax geometry interactively
for i in range(1000):
for j in range(5):
m.advance()
m.vel_ *= 0.99
m.update_view()
In [8]:
Copied!
import evince as ev
m.pos *= 2
bonds = ev.spotlight.extract_bonds(m)
mv = ev.SpotlightView(m, realism = False, bonds = bonds, dof = True, focus = 5, aperture = 0.001, max_blur = 0.001)
mv
import evince as ev
m.pos *= 2
bonds = ev.spotlight.extract_bonds(m)
mv = ev.SpotlightView(m, realism = False, bonds = bonds, dof = True, focus = 5, aperture = 0.001, max_blur = 0.001)
mv
Out[8]:
SpotlightView(aperture=0.001, bg_color=[1.0, 1.0, 1.0], bonds=[[0, 1], [0, 40], [1, 2], [1, 41], [2, 3], [2, 4…
Manual update¶
What happens here is that the mdbox
-instance above (that is m
) has a model and a view. The view is rendered to screen in the line m.view()
, which explicitly returns the view to the cell-output in Jupyter.
In the cell below, we manually change the list of positions m.view().pos
-list and observe that the view updates the positions:
In [9]:
Copied!
mv.save("harmonic_chain.html")
mv.save("harmonic_chain.html")
In [ ]:
Copied!