<jupyter_start><jupyter_text>Ideal Living Polymerization 1. Simulation<jupyter_code>import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt

# Number of polymer chains (Feel free to change the value, but keep it > or = 100).
NPoly = 10000  
# Different targeted degree of polymerization (Feel free to add or to delete numbers, or to change the values).
DP_Targ = np.array([1, 5, 10, 20, 30, 100])  
# Number of monomers.
NMon = NPoly*DP_Targ.max()  
# Each monomer goes to one polymer chain randomly.
polym = np.random.randint(1, NPoly, NMon)  

mpl.rcParams['figure.figsize'] = (12.0, 4.0*len(DP_Targ))
# Calculate the degree of polymerization of each chain.
DP = np.zeros((len(DP_Targ), NPoly))  
plt.subplots(len(DP_Targ), 2)
k = 0
index = np.arange(1, 100)
while k < len(DP_Targ):
    for i in polym[0:NPoly*DP_Targ[k]]:
        DP[k, i-1] = DP[k, i-1] + 1            
    plt.subplot(len(DP_Targ), 2, 2*k+1)
    plt.bar(index,DP[k, 0:99], 0.5, alpha=0.65,color='b')  
    plt.xlabel('Polymer Chains')
    plt.ylabel('DP')
    plt.title('Targeted DP = %r' %DP_Targ[k])
    plt.subplot(len(DP_Targ), 2, 2*(k+1))
    plt.hist(DP[k], 200, density=1, facecolor='green', alpha=0.65)  
    plt.xlabel('DP')
    plt.ylabel('Fraction')
    plt.title('Targeted DP = %r' %DP_Targ[k])
    k = k + 1
# Display 100 polymer chains to illustrate the deviation of chain lengths (left side).
# Display the chain length distribution (right side).
plt.tight_layout()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14484126984126985, 'fraction_numerical': 0.04034391534391534, 'mean_word_length': 3.9444444444444446, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '634203', 'license': 'CC0-1.0', 'n_tokens_mistral': 640, 'n_tokens_neox': 571, 'n_words': 161, 'path': 'OVESET/Ideal_Living_Polymerization.ipynb', 'repo_name': 'fishdream/Physical-Chemistry', 'size': '1512'}