In [8]:
import h5py
import networkx

In [9]:
h5 = h5py.File('sim0_12345_traj.h5', 'r')
h5['/particles/atoms'].keys()


Out[9]:
[u'box',
 u'id',
 u'image',
 u'mass',
 u'position',
 u'res_id',
 u'species',
 u'state']

In [14]:
cl = h5['/connectivity/chem_bonds_0/value'][-1]
species = h5['/particles/atoms/species/value'][-1]
state = h5['/particles/atoms/state/value'][-1]

In [17]:
h5['/particles/atoms/id/value'][-1]


Out[17]:
array([ 1,  2,  3, ..., -1, -1, -1])

In [31]:
g = networkx.Graph()
b_d = []
a = []
a_star = []
for i, s in enumerate(state):
    if s != -1:
        g.add_node(i+1, state=s, type_id=species[i])
        if species[i] in [1, 2]:
            b_d.append(i+1)
        else:
            a.append(i+1)
            if s == 2:
                a_star.append(i+1)
for b in cl:
    if -1 not in b:
        g.add_edge(b[0], b[1])

In [32]:
g_bd = g.subgraph(b_d)
g_a = g.subgraph(a)
g_a_star = g.subgraph(a_star)

In [37]:
{v for k, v in g_a.degree().items()}


Out[37]:
{0, 1, 2, 3}

In [ ]: