PathTree Example

visualization

PathTree Visualization Example

In [1]:
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

In [2]:
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.

In [3]:
tree = PathTreeBuilder(storage)

Load a set of samples that belong to a specific ensemble (in this case ensemble with ID 4)

In [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

In [5]:
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

In [6]:
view = tree.renderer
view.zoom = 1.1
view.font_size = 0.35
SVG(view.to_svg())
Out[6]:
-31-24-23-27-332b2b-31-263b-31-254b-36-29-24-245b-35-29-24-236b-31-25-23

Or more similar to the old style

In [7]:
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())
Out[7]:
2b2b3b4b5b6b

Let's save the last tree as a pdf (using wkhtmltopdf, which can be downloaded from wkhtmltopdf.org)

In [8]:
#! skip
view.save_pdf('mypathtree.pdf')
!open mypathtree.pdf

(visualization.ipynb; visualization_evaluated.ipynb; visualization.py)