mosdef-hub / mbuild

A hierarchical, component based molecule builder
https://mbuild.mosdef.org
Other
171 stars 80 forks source link

Plot hierarchy of a compound #1096

Closed chrisiacovella closed 1 year ago

chrisiacovella commented 1 year ago

It would likely be helpful to be able to generate an overview of the hierarchy in a compound. It would likely be good to be able to plot out the full hierarchy, or plot it where identical compounds are condensed together.

For example, something akin to:

test_compound.plot_hierarchy()

Compound, 230 particles, 220 bonds, 10 children
├── [Polymer x 5], 20 particles, 19 bonds, 6 children
│   ├── [CH2 x 4], 3 particles, 2 bonds, 3 children
│   │   ├── [C x 1], 1 particles, 4 bonds, 0 children
│   │   └── [H x 2], 1 particles, 1 bonds, 0 children
│   └── [CH3 x 2], 4 particles, 3 bonds, 4 children
│       ├── [C x 1], 1 particles, 4 bonds, 0 children
│       └── [H x 3], 1 particles, 1 bonds, 0 children
└── [Polymer x 5], 26 particles, 25 bonds, 8 children
    ├── [CH2 x 6], 3 particles, 2 bonds, 3 children
    │   ├── [C x 1], 1 particles, 4 bonds, 0 children
    │   └── [H x 2], 1 particles, 1 bonds, 0 children
    └── [CH3 x 2], 4 particles, 3 bonds, 4 children
        ├── [C x 1], 1 particles, 4 bonds, 0 children
        └── [H x 3], 1 particles, 1 bonds, 0 children

I've already put together code for this and will be submitting a PR soon.