ligning.polymer

Build lignin polymers

class ligning.polymer.Polymer(M_init: object, verbose: Optional[bool] = True)

Polymer object for lignin growth

add_random_monomer(draw: Optional[bool] = False, branching_state: Optional[bool] = None)

Main body - Add one random monomer and connect the new linkage Rejection free

Parameters
  • branching_state (Optioanl[bool], optional) – likelihood to form a branch by default None, select all Cs if true, select Cs in the chain if false, select Cs at the terminal monomers

  • draw (Optional[bool], optional) – flag to draw the polymer graph, by default False

add_random_ring(draw: Optional[bool] = False, branching_state: Optional[bool] = None)

Add a randome linkage inside a polymer a ring is formed

Parameters
  • branching_state (Optioanl[bool], optional) – likelihood to form a branch by default None, select all Cs if true, select Cs in the chain if false, select Cs at the terminal monomers

  • draw (Optional[bool], optional) – flag to draw the polymer graph, by default False

add_specific_linkage(linkage_type: str, monomer_type: Optional[str] = None, branching_state: Optional[bool] = None, draw: Optional[bool] = False)

Add specific linkage to a polymer with a specific monomer if user defined Otherwise add an extra linkage allowed by the linkage rules

Parameters
  • linkage_type (str) – bond types defined in bond type selection

  • monomer_type (Optional[str], optional) – monomer type, by default None

  • draw (Optional[bool], optional) – flag to draw the polymer graph, by default False

  • branching_state (Optional[bool], optional) – likelihood to form a branch by default None, select all Cs if true, select Cs in the chain if false, select Cs at the terminal monomers

Raises
  • Exception – if input linkage type not defined

  • Exception – if input linkage does not exist

add_specific_monomer(monomer_type: str, linkage_type: Optional[str] = None, branching_state: Optional[bool] = None, draw: Optional[bool] = False)

Add specific linkage to a polymer with a specific monomer if user defined Otherwise add an extra linkage allowed by the linkage rules

Parameters
  • monomer_type (str) – monomer type

  • linkage_type (Optional[str], optional) – linkage types defined in bond type selection, by default None

  • branching_state (Optioanl[bool], optional) – likelihood to form a branch by default None, select all Cs if true, select Cs in the chain if false, select Cs at the terminal monomers

  • draw (Optional[bool], optional) – flag to draw the polymer graph, by default False

add_specific_ring(linkage_type: str, draw: Optional[bool] = False)

Add specific linkage to a polymer with a specific monomer if user defined Otherwise add an extra linkage allowed by the linkage rules

Parameters
  • linkage_type (str) – bond types defined in bond type selection

  • monomer_type (Optional[str], optional) – monomer type, by default None

  • draw (Optional[bool], optional) – flag to draw the polymer graph, by default False

Raises
  • Exception – if input linkage type not defined

  • Exception – if input linkage does not exist

  • Exception – if input monomer is not allowed by the bonding

try_adding_new(linkage_index: Tuple[int, int], C1_index_in_polymer: int, C2_index_in_polymer: int, monomer_new: Optional[Monomer] = None, draw: Optional[bool] = False) bool

Try adding a new monomer or linkage

Parameters
  • linkage_index (Tuple[int, int]) – (C1, C2) index tuple for the linkage

  • C1_index_in_polymer (int) – C1 index in the polymer

  • C2_index_in_polymer (int) – C2 index in the polymer

  • monomer_new (Optional[Monomer], optional) – monomer object for the new monomer, by default None, i.e. forming a ring

  • draw (Optional[bool], optional) – flag to draw the polymer graph, by default False

Returns

new_linkage_flag – a flag if new linkage is formed

Return type

bool

update_units(linkage_index: Tuple[int, int], C1_index_in_polymer: int, C2_index_in_polymer: int)

Update the units dictionary in polymer object

Parameters
  • linkage_index (Tuple[int, int]) – (C1, C2) index tuple for the linkage

  • C1_index_in_polymer (int) – C1 index in the polymer

  • C2_index_in_polymer (int) – C2 index in the polymer

class ligning.polymer.PolymerGraph(G: nxgraph, verbose: Optional[bool] = True)

PolymerGraph object contains all graph operations for a polymer

connect_C1_C2(linkage_index: Tuple[int, int], C1_index_in_polymer: int, C2_index_in_polymer: int) bool

Add a new linkage, connect C1 and C2 in the polymer

Parameters
  • linkage_index (Tuple[int, int]) – (C1, C2) index tuple for the linkage

  • C1_index_in_polymer (int) – C1 index in the polymer

  • C2_index_in_polymer (int) – C2 index in the polymer

Returns

new_linkage_flag – a flag if new linkage is formed

Return type

bool

find_C2_index_in_polymer(C2_index_in_monomer: int) int

Convert C2 index in monomer to its index in the polymer

Parameters

C2_index_in_monomer (int) – C2 index in the monomer

Returns

C2_index_in_polymer – C2 index in the polymer

Return type

int

find_O_index_in_polymer(C_index_in_polymer: int) int

find the oxygen neighboring to the 4th carbon in a graph

Parameters

C_index_in_polymer (int) – the index of 4th carbon

Returns

O_index_in_polymer – the oxygen connected to the 4th carbon

Return type

int

find_available_C1_in_polymer(branching_state: Optional[bool] = None) list

find available C1 node in a polymer

Returns

  • C1_indices_in_polymer (list) – the C1 node indices in the polymer

  • branching_state (Optional[bool], optional) – flag to control whether the new C is branced or not by default None, select all Cs if true, select Cs in the chain if false, select Cs at the terminal monomers

find_available_C2_in_monomer(C1_index_in_polymer: int, ring: Optional[bool] = False) list

find available C2 node in monomer using the linkage selection rules

Parameters

C1_index_in_polymer (int) – C1 indices in polymer

Returns

C2_indices_in_monmer – C2 index in monomer

Return type

list

find_available_monomer_types(bond_index: tuple) list

find available monomer types using monomer selection rules

Parameters

bond_index (tuple) – bonding C index pair, e.g., (4, 5)

Returns

monomer type list – a list monomer available for forming linkages

Return type

list

update_available_C1_in_polymer(C1_index_in_polymer: int) list

update available C1 node in a polymer by delete C1_index_in_polymer from the list

Parameters

C1_index_in_polymer (int) – C1 indices in polymer

Returns

C1_indices_in_polymer – the C1 node indices in the polymer

Return type

list

update_branching_C_in_polymer(C_indices_in_polymer: list, branching_state: Optional[bool] = False) list

update the C indices based on branching

Parameters
  • C_indices_in_polymer (list) – C indices available for bonding

  • branching_state (Optional[bool], optional) – find branching_state or non-branching_state monomers, by default False

Returns

C_available_indices_in_polymer – the C indices in branching_state or non-branching_state monomers

Return type

list