<jupyter_start><jupyter_text>With waterSimulation with water.<jupyter_code>h5 = h5py.File('p_1.0_25699_25699_traj.h5')
h5['/connectivity/'].keys()
cl = h5['/connectivity/chem_bonds_0/value']
st_cl = filter(lambda x: -1 not in x, h5['/connectivity/bonds_0'])
st = filter(lambda x: x != -1, h5['/particles/atoms/state/value'][-1])
sp = filter(lambda x: x != -1, h5['/particles/atoms/species/value'][-1])
sp_t = h5['/particles/atoms/species/value']
id_t = h5['/particles/atoms/id/value']
pid2res_id = {p: p for p in range(1, 1001)}
pid2res_id.update({pid: 1001+(pid-1001)//3 for pid in range(1001, 4001)})
(id_t[0][np.where(sp_t[0]==2)[0]] == id_t[0][np.where(sp_t[0]==2)[0]]).all()
g0 = nx.Graph()
g0.add_nodes_from(range(1, 4001))
g0.add_edges_from(st_cl)
g0.add_edges_from(filter(lambda b: -1 not in b, cl[-1]))
np.average([sg.number_of_nodes() for sg in nx.connected_component_subgraphs(g0)])
from networkx.drawing.nx_agraph import graphviz_layout
def draw_graph(g, **kwargs):
    g_degree = g.degree()
    pos = graphviz_layout(g)
    node_colors = {1: 'r', 2: 'g', 3: 'y', 4: 'b'}
    
    nx.draw_networkx(g, pos, node_size=500, font_size=12, alpha=0.5, labels=g_degree,
                     node_color=[node_colors[g_degree[x]] for x in g.nodes()], **kwargs)
    plt.xticks([])
    plt.yticks([])
g160 = sorted([(sg.number_of_nodes(), sg) for sg in nx.connected_component_subgraphs(g0)])[-1][1]
dd = g160.degree().values()
{d: dd.count(d) for d in set(dd)}
cg160 = nx.Graph()
for b in g160.edges():
    r1, r2 = map(pid2res_id.get, b)
    if r1 != r2:
        cg160.add_edge(r1, r2)
draw_graph(sorted([(sg.number_of_nodes(), sg) for sg in nx.connected_component_subgraphs(g0)])[-1][1])
cg160.number_of_nodes()
cr_pn = []
last_cr = -1
static_b = {tuple(sorted(map(pid2res_id.get, b))) for b in st_cl}
static_b = filter(lambda b: b[0] != b[1], static_b)
for t_cl in h5['/connectivity/chem_bonds_0/value']:
    s_cl = filter(lambda x: -1 not in x, t_cl)
    if len(s_cl) != last_cr:
        g = nx.Graph()
        g.add_nodes_from(range(1, 2001))
        g.add_edges_from(static_b)
        g.add_edges_from({tuple(sorted(map(pid2res_id.get, b))) for b in s_cl})
        cr_pn.append([len(s_cl), np.average([sg.number_of_nodes() for sg in nx.connected_component_subgraphs(g)])])
        last_cr = len(s_cl)
cr_pn = np.array(cr_pn)
def theory_pn(p):
    return 1.0/(1.0-p)
plt.plot(cr_pn[:, 0]/2000.0, cr_pn[:, 1], label='sim')
plt.plot(cr_pn[:, 0]/2000.0, map(theory_pn, cr_pn[:, 0]/2000.0), label='theory')
plt.legend(loc=0)
def px(p):
    def pp(x):
        return (1.0-p)*(p**(x-1))
    return pp
x = np.arange(1, 10, 0.1)
plt.plot(x, map(px(0.001), x))
plt.plot(x, map(px(0.01), x))
plt.plot(x, map(px(0.1), x))
plt.plot(x, map(px(0.5), x))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20144144144144144, 'fraction_numerical': 0.061621621621621624, 'mean_word_length': 4.37984496124031, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '251794', 'license': 'Unlicense', 'n_tokens_mistral': 1326, 'n_tokens_neox': 1233, 'n_words': 229, 'path': 'paper/analysis/scan_p_1000/with_water/Untitled.ipynb', 'repo_name': 'jkrajniak/paper-cg-md-simulations-of-polymerization-with-forward-and-backward-reactions', 'size': '2775'}