02_polymer_chainΒΆ
Create monomers and linear polymer chains
Install the package from pip (skip this step if the package is already installed)
[1]:
! pip install ligning
Requirement already satisfied: ligning in /opt/anaconda3/lib/python3.8/site-packages (0.1.1)
Requirement already satisfied: numpy>=1.19.2 in /opt/anaconda3/lib/python3.8/site-packages (from ligning) (1.20.3)
Requirement already satisfied: pysmiles>=1.0.1 in /opt/anaconda3/lib/python3.8/site-packages (from ligning) (1.0.1)
Requirement already satisfied: pytest>=6.2.3 in /opt/anaconda3/lib/python3.8/site-packages (from ligning) (6.2.5)
Requirement already satisfied: openpyxl>=3.0.7 in /opt/anaconda3/lib/python3.8/site-packages (from ligning) (3.0.9)
Requirement already satisfied: rdkit-pypi>=2021.9.2.1 in /opt/anaconda3/lib/python3.8/site-packages (from ligning) (2022.3.2.1)
Requirement already satisfied: networkx>=2.5 in /opt/anaconda3/lib/python3.8/site-packages (from ligning) (2.8.3)
Requirement already satisfied: matplotlib>=3.1.1 in /opt/anaconda3/lib/python3.8/site-packages (from ligning) (3.2.2)
Requirement already satisfied: scipy>=1.3.1 in /opt/anaconda3/lib/python3.8/site-packages (from ligning) (1.5.0)
Requirement already satisfied: pandas>=0.25.1 in /opt/anaconda3/lib/python3.8/site-packages (from ligning) (1.0.5)
Requirement already satisfied: python-dateutil>=2.1 in /opt/anaconda3/lib/python3.8/site-packages (from matplotlib>=3.1.1->ligning) (2.8.1)
Requirement already satisfied: kiwisolver>=1.0.1 in /opt/anaconda3/lib/python3.8/site-packages (from matplotlib>=3.1.1->ligning) (1.2.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /opt/anaconda3/lib/python3.8/site-packages (from matplotlib>=3.1.1->ligning) (2.4.7)
Requirement already satisfied: cycler>=0.10 in /opt/anaconda3/lib/python3.8/site-packages (from matplotlib>=3.1.1->ligning) (0.10.0)
Requirement already satisfied: six in /opt/anaconda3/lib/python3.8/site-packages (from cycler>=0.10->matplotlib>=3.1.1->ligning) (1.15.0)
Requirement already satisfied: et-xmlfile in /opt/anaconda3/lib/python3.8/site-packages (from openpyxl>=3.0.7->ligning) (1.0.1)
Requirement already satisfied: pytz>=2017.2 in /opt/anaconda3/lib/python3.8/site-packages (from pandas>=0.25.1->ligning) (2020.1)
Requirement already satisfied: pbr in /opt/anaconda3/lib/python3.8/site-packages (from pysmiles>=1.0.1->ligning) (5.6.0)
Requirement already satisfied: attrs>=19.2.0 in /opt/anaconda3/lib/python3.8/site-packages (from pytest>=6.2.3->ligning) (19.3.0)
Requirement already satisfied: iniconfig in /opt/anaconda3/lib/python3.8/site-packages (from pytest>=6.2.3->ligning) (1.1.1)
Requirement already satisfied: packaging in /opt/anaconda3/lib/python3.8/site-packages (from pytest>=6.2.3->ligning) (20.4)
Requirement already satisfied: pluggy<2.0,>=0.12 in /opt/anaconda3/lib/python3.8/site-packages (from pytest>=6.2.3->ligning) (0.13.1)
Requirement already satisfied: py>=1.8.2 in /opt/anaconda3/lib/python3.8/site-packages (from pytest>=6.2.3->ligning) (1.9.0)
Requirement already satisfied: toml in /opt/anaconda3/lib/python3.8/site-packages (from pytest>=6.2.3->ligning) (0.10.1)
Requirement already satisfied: Pillow in /opt/anaconda3/lib/python3.8/site-packages (from rdkit-pypi>=2021.9.2.1->ligning) (7.2.0)
[4]:
# 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
c:\Users\yifan\Documents\GitHub\LigninGraphs
Constructing a polymer chain
Starting from a G monomer, visualize it in the graph format
[5]:
P0 = mono.Monomer("G")
P0_G = P0.create()
ut.draw_graph(P0_G)
polymer = poly.Polymer(P0)
Add a G monomer with a linkage
[6]:
polymer.add_specific_linkage(linkage_type = 'beta-O-4', monomer_type = 'G')
P1_G = polymer.G
ut.draw_graph(P1_G)
Connect a G to a G unit (in polymer) via a beta-O-4 bond
Add n random monomers with beta-O-4 bonds and time the speed
[7]:
start = time.time()
n_iter = 100
for i in range(n_iter):
polymer.add_specific_linkage(linkage_type ='beta-O-4', monomer_type = 'G')
n_iter = 10
for i in range(n_iter):
polymer.add_specific_linkage(linkage_type ='beta-beta', monomer_type = 'G')
# get the molecular in mol format
n_monomer = n_iter + 2
P_mol = ut.graph_to_mol(polymer.G)
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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-beta bond
c:\Users\yifan\Documents\GitHub\LigninGraphs\ligning\polymer.py:544: UserWarning: No more bonding atoms available
warnings.warn("No more bonding atoms available")
Characterize the polymer
[8]:
ch1 = ch.CharacterizeGraph(polymer.G)
print("\nCharaterizing the polymer...\n")
ch1.cal_all()
# Calculate and print the polymer properties using the graphs and big graphs
ch2 = ch.Characterize(polymer)
print("\nCharaterizing the polymer...\n")
ch2.cal_all()
Charaterizing the polymer...
{ 'G': <networkx.classes.graph.Graph object at 0x000002243E8FCC08>,
'MW': None,
'Mol': None,
'OCH3_count': 103.0,
'OH_count': 103.0,
'linkages_count': { '4-O-5': 0.0,
'5-5': 0.0,
'alpha-O-4': 0.0,
'beta-1': 0.0,
'beta-5': 0.0,
'beta-O-4': 101.0,
'beta-beta': 1.0},
'metrics': None,
'mol': None,
'monomer_count': 103.0,
'mtype_count': {'G': 103.0, 'H': 0.0, 'S': 0.0},
'smiles': None}
Charaterizing the polymer...
{ 'G': <networkx.classes.graph.Graph object at 0x000002243E8FCC08>,
'MW': None,
'Mol': None,
'OCH3_count': 103.0,
'OH_count': 103.0,
'bigG': <networkx.classes.graph.Graph object at 0x000002243E93B148>,
'branching_coeff': 0.0,
'connections_count': {1: 2, 2: 101},
'linkages_count': { '4-O-5': 0,
'5-5': 0,
'alpha-O-4': 0,
'beta-1': 0,
'beta-5': 0,
'beta-O-4': 101,
'beta-beta': 1},
'metrics': None,
'mol': None,
'monomer_count': 103,
'mtype_count': {'G': 103, 'H': 0, 'S': 0},
'n_branched': 0,
'smiles': None}