Skip to content

Schemas

polymcsim.schemas

Pydantic schemas for PolyMCsim configuration and validation.

MonomerDef

Bases: BaseModel

Define a type of monomer in the system.

Attributes:

Name Type Description
name str

Unique name for this monomer type.

count int

Number of these monomers to add to the system.

molar_mass float

Molar mass of the monomer unit (g/mol).

sites List[SiteDef]

List of reactive sites on this monomer.

chaingrowth_initiator(name, count, molar_mass, n_sites=1, additional_sites=None, active_site_name='R') classmethod

Create a monomer for chain growth initiator.

chaingrowth_monomer(name, count, molar_mass, additional_sites=None, head_name='R_Head', tail_name='R_Tail') classmethod

Create a monomer for chain growth.

Polymer

Bases: BaseModel

Represents a single polymer chain.

This is a connected component in the simulation graph.

branch_points property

The number of branch points (nodes with degree > 2).

composition property

Return the monomer composition of the polymer as a dictionary.

is_linear property

Checks if the polymer is linear (maximum degree is 2 or less).

molecular_weight property

The total molar mass of this polymer chain (g/mol).

num_monomers property

The number of monomer units in this polymer (degree of polymerization).

get_nodes_by_type()

Return nodes of the polymer graph grouped by monomer type.

ReactionSchema

Bases: BaseModel

Defines the outcome and rate of a reaction between two site types.

chaingrowth_initiation(initiator, monomers, rate=10.0, initiator_site=0, monomer_site=0, monomer_activated_side=1, active_site_type=None) classmethod

Create a reaction schema for chain growth initiation.

SimParams

Bases: BaseModel

Parameters to control the simulation execution.

Attributes:

Name Type Description
name str

Name for this simulation run.

max_time float

Maximum simulation time to run.

max_reactions int

Maximum number of reaction events.

max_conversion float

Maximum fraction of monomers that can be reacted (0.0 to 1.0).

random_seed int

Random seed for reproducible results.

serialize_max_time(max_time)

Serialize inf values as 'inf' string for JSON compatibility.

validate_max_time(v) classmethod

Convert 'inf' string back to float('inf') during validation.

SimulationInput

Bases: BaseModel

Complete input configuration for a PolyMCsim simulation.

Attributes:

Name Type Description
monomers List[MonomerDef]

List of monomer definitions.

reactions Dict[frozenset[str], ReactionSchema]

Dictionary mapping site type pairs to reaction schemas.

params SimParams

Simulation parameters.

serialize_reactions(reactions)

Serialize frozenset keys into strings for JSON compatibility.

validate_reactions(v) classmethod

Validate and convert string keys back to frozensets.

SimulationResult

Bases: BaseModel

Holds the results of a single simulation run.

Attributes:

Name Type Description
graph Graph | None

The final polymer network structure.

metadata Dict[str, Any] | None

A dictionary of metadata about the simulation run.

config 'SimulationInput'

The input configuration that generated this result.

error str | None

An error message if the simulation failed.

get_average_molecular_weights()

Calculate Mn, Mw, and PDI for the polymer mixture.

Returns:

Type Description
Dict[str, float]

A dictionary with keys 'Mn', 'Mw', and 'PDI'. Returns zero values

Dict[str, float]

if no polymers were formed.

get_largest_polymer()

Return the largest polymer chain from the simulation result.

Returns:

Type Description
'Polymer' | None

The largest Polymer object, or None if no polymers were formed.

get_polymers()

Extract individual polymer chains from the main simulation graph.

This method identifies connected components in the simulation graph, filters out unreacted monomers (components with a single node), and returns a list of Polymer objects. The result is cached after the first call.

Returns:

Type Description
List['Polymer']

A list of Polymer objects, sorted from largest to smallest.

get_unreacted_monomer_composition()

Count the number of unreacted monomers of each type.

Returns:

Type Description
Dict[str, int]

A dictionary mapping monomer type to its unreacted count.

get_unreacted_monomers()

Identify monomers that have not participated in any reactions.

An unreacted monomer is represented as an isolated node in the graph (i.e., its degree is 0).

Returns:

Type Description
List[Dict[str, Any]]

A list of dictionaries, where each dictionary contains the

List[Dict[str, Any]]

attributes of an unreacted monomer node (e.g., monomer_type).

summary()

Provide a summary of the simulation results.

Returns:

Type Description
Dict[str, Any]

A dictionary containing key metrics like conversion, number of

Dict[str, Any]

polymers, and average molecular weights.

SiteDef

Bases: BaseModel

Defines a reactive site on a monomer.