PathTree Example¶
PathTree Visualization Example¶
from openpathsampling.storage import Storage
from openpathsampling.visualize import PathTreeBuilder
from IPython.display import SVG
First load a previously generated trajectory storage object
TODO: Change example directory at some point
storage = Storage('trajectory.nc')
Then create a simple tree builder object. The TreeBuilder knows about the way things should be arranged and what to display. It contains a TreeRenderer() object that is in charge of generating the actual SVG output. The renderer knows about zoom levels and scaling, etc.
tree = PathTreeBuilder(storage)
Load a set of samples that belong to a specific ensemble (in this case ensemble with ID 4)
samples = tree.construct_heritage(storage, storage.sample.load(10))
Finally set some options
- show rejected paths
- show state bars below the snapshot boxes, here for StateA in black
- use a transformed orderparameter, here use psi angles and convert to degrees
and then create the set of drawing commands for this setting from the list of samples
tree.rejected = True
tree.states = [('StateA','black')]
tree.op = storage.cv.load('psi').get_transformed_view(lambda x : int(x / 3.141592653 * 180))
tree.from_samples(samples)
Last, tweak the output to be a little bigger, increase a fontsize and output the SVG to the ipython notebook
view = tree.renderer
view.zoom = 1.1
view.font_size = 0.35
SVG(view.to_svg())
Or more similar to the old style
tree.rejected = True
tree.states = []
tree.op = None
tree.from_samples(samples)
view = tree.renderer
view.zoom = 1.1
view.horizontal_gap = -0.01
view.scale_y = 15
view.font_size = 0.8
view.font_family = 'Times'
SVG(view.to_svg())
Let's save the last tree as a pdf (using wkhtmltopdf, which can be downloaded from wkhtmltopdf.org)
#! skip
view.save_pdf('mypathtree.pdf')
!open mypathtree.pdf
(visualization.ipynb; visualization_evaluated.ipynb; visualization.py)