<jupyter_start><jupyter_text>08_branching Create branched polymers<jupyter_code># set ligning path (optional if installed via pip)
import sys, os
project_path = os.path.abspath(os.path.join(os.getcwd(), '..\..\..'))
print(project_path)
sys.path.insert(0, project_path)

import ligning.characterization as ch
import ligning.monomer as mono
import ligning.polymer as poly
import ligning.utils as ut
from ligning.rules import linkage_ring
import time 
from rdkit import Chem<jupyter_output>c:\Users\yifan\Documents\GitHub\LigninGraphs<jupyter_text>Test on branched polymer<jupyter_code>#%% Constructing a dimmer for testing
m0 = mono.Monomer("S")
polymer = poly.Polymer(m0)
polymer.add_specific_linkage(linkage_type = '4-O-5', monomer_type = 'G')
#%% Test on branched polymer
polymer_0 = poly.Polymer(polymer)
start = time.time()
n_iter = 10
for i in range(n_iter):
    flag = polymer_0.add_specific_linkage(linkage_type ='beta-O-4', monomer_type = 'G', branching_state=True)
    #polymer.add_specific_linkage(linkage_type ='5-5', monomer_type = 'G')

P_mol_0 = ut.graph_to_mol(polymer_0.G)
# Characterize the polymer
ch_p = ch.Characterize(polymer_0)
ch_p.cal_branching()
branching_coeff_0 = ch_p.branching_coeff
assert(branching_coeff_0 == 0.25)
print('The branching coefficient is {}'.format(branching_coeff_0))

#%% Test on drawing functions
ut.draw_atomic_graph(polymer_0.G)
ut.draw_big_graph(polymer_0.bigG)<jupyter_output>Connect a S to a G unit (in polymer) via a 4-O-5 bond
Connect a G to a G unit (in polymer) via a beta-O-4 bond
Connect a G to a G unit (in polymer) via a beta-O-4 bond
The branching coefficient is 0.25<jupyter_text>Test on non-branched polymer<jupyter_code>polymer_1 = poly.Polymer(polymer)
start = time.time()
n_iter = 10
for i in range(n_iter):
    polymer_1.add_specific_linkage(linkage_type ='beta-O-4', monomer_type = 'G', branching_state=False)
    #polymer.add_specific_linkage(linkage_type ='5-5', monomer_type = 'G')

P_mol_1 = ut.graph_to_mol(polymer_1.G)
# Characterize the polymer
ch_p = ch.Characterize(polymer_1)
ch_p.cal_branching()
branching_coeff_1 = ch_p.branching_coeff
assert(branching_coeff_1 == 0)
print('The branching coefficient is {}'.format(branching_coeff_1))

#%% Test on drawing functions
ut.draw_atomic_graph(polymer_1.G)
ut.draw_big_graph(polymer_1.bigG)<jupyter_output>Connect a G to a G unit (in polymer) via a beta-O-4 bond
Connect a G to a G unit (in polymer) via a beta-O-4 bond
Connect a S to a G unit (in polymer) via a beta-O-4 bond
Connect a G to a G unit (in polymer) via a beta-O-4 bond
Connect a G to a G unit (in polymer) via a beta-O-4 bond
Connect a G to a G unit (in polymer) via a beta-O-4 bond
Connect a G to a G unit (in polymer) via a beta-O-4 bond
Connect a G to a G unit (in polymer) via a beta-O-4 bond
Connect a G to a G unit (in polymer) via a beta-O-4 bond
Connect a G to a G unit (in polymer) via a beta-O-4 bond
The branching coefficient is 0.0
{'fraction_non_alphanumeric': 0.10378968931375897, 'fraction_numerical': 0.020484807101399796, 'mean_word_length': 5.15546218487395, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '326914', 'license': 'MIT', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1065, 'n_words': 330, 'path': 'docs/source/examples/08_branching.ipynb', 'repo_name': 'VlachosGroup/LigninGraphs', 'size': '2929'}