swiftpol
A Python package for building in silico polymer systems
swiftpol.build
- swiftpol.build.build_polymer(sequence, monomer_list, reaction, terminal='hydroxyl', chain_num=1)[source]
Constructs a polymer from a given sequence of monomers.
- Parameters:
sequence (str) – A string representing the sequence of monomers (e.g., ‘ABAB’).
monomer_list (list) – A list of SMILES strings representing the monomers.
reaction (rdkit.Chem.rdChemReactions.ChemicalReaction) – An RDKit reaction object used to link monomers.
terminal (str, optional) – The terminal group to be added to the polymer. Options are ‘hydroxyl’, ‘carboxyl’, or ‘ester’. Default is ‘hydroxyl’.
chain_number (int, optional) – The number of polymer chains to construct. Default is 1. Input used for ensemble build.
- Returns:
The constructed polymer as an RDKit molecule object.
- Return type:
rdkit.Chem.rdchem.Mol
- swiftpol.build.build_linear_copolymer(sequence, monomer_a_smiles, monomer_b_smiles, reaction=<rdkit.Chem.rdChemReactions.ChemicalReaction object>)[source]
Constructs a linear co-polymer from the provided sequence of monomers.
This function takes a sequence of monomers represented as ‘A’ and ‘B’, and the SMILES strings of two monomers. It constructs a co-polymer based on the sequence, using the provided reaction SMARTS for joining the monomers. The function returns the sanitized polymer and the percentage composition of each monomer in the polymer.
- Parameters:
sequence (str) – A string representing the sequence of monomers. ‘A’ represents monomer_a and ‘B’ represents monomer_b.
monomer_a_smiles (str) – The SMILES string of monomer A.
monomer_b_smiles (str) – The SMILES string of monomer B.
reaction (rdkit.Chem.rdChemReactions.ChemicalReaction, optional) – The reaction SMARTS used for joining the monomers. Defaults to ‘[C:1][HO:2].[HO:3][C:4]>>[C:1][O:2][C:4].[O:3]’, representing a condensation polymerisation.
- Returns:
A tuple containing the following elements: - sanitized_polymer (rdkit.Chem.rdchem.Mol): The constructed and sanitized polymer. - percentage_monomer_a (float): The percentage composition of monomer A in the polymer. - percentage_monomer_b (float): The percentage composition of monomer B in the polymer.
- Return type:
tuple
- swiftpol.build.PDI(chains)[source]
Calculates the Polydispersity Index (PDI), number-average molecular weight (Mn), and weight-average molecular weight (Mw) of a list of chains.
This function takes a list of molecular chains and calculates the PDI, which is the ratio of Mw to Mn. It also calculates Mn, which is the sum of the molecular weights of the chains divided by the number of chains, and Mw, which is the sum of the product of the weight fraction and molecular weight of each chain.
- Parameters:
chains (list) – A list of molecular chains. Each chain is represented as an RDKit molecule object.
- Returns:
A tuple containing the following elements: - PDI (float): The Polydispersity Index, which is the ratio of Mw to Mn. - Mn (float): The number-average molecular weight. - Mw (float): The weight-average molecular weight.
- Return type:
tuple
- swiftpol.build.blockiness_gen(sequence)[source]
Calculate the blockiness and average block length of a co-polymer sequence.
This function calculates the blockiness of a co-polymer sequence by counting the occurrences of ‘BB’ and ‘BA’ or ‘AB’ in the sequence. It also calculates the average block length of ‘A’ and ‘B’ monomers in the sequence.
- Parameters:
sequence (str) – A string representing the co-polymer sequence. ‘A’ represents one type of monomer and ‘B’ represents another type.
- Returns:
A tuple containing the following elements: - blockiness (float): The blockiness of the co-polymer sequence. Calculated as the ratio of ‘BB’ to ‘BA’ or ‘AB’. - block_length_A (float): The average block length of ‘A’ in the sequence. - block_length_B (float): The average block length of ‘B’ in the sequence.
- Return type:
tuple
Notes
If the sequence does not contain both ‘A’ and ‘B’, the function returns a string indicating that the molecule is not a co-polymer.
- swiftpol.build.calculate_box_components(chains, monomers, sequence, salt_concentration=<Quantity(0.0, 'mole / liter')>, residual_monomer=0.0, solvated=True)[source]
Calculates the components required to construct a simulation box for a given set of molecular chains.
This function determines the quantity of each molecule type required, considering the salt concentration and residual monomer concentration. It is adapted from the OpenFF Toolkit Packmol wrapper’s solvate_topology function.
Parameters:
- chainslist
A list of molecular chains to be included in the simulation box.
- sequencestr
A string representing the sequence of the molecular chains. ‘G’ and ‘L’ represent different types of monomers.
- salt_concentrationfloat, optional
The desired salt concentration in the simulation box. Defaults to 0 M.
- residual_monomerfloat, optional
The desired residual monomer concentration in the simulation box. Defaults to 0.00%.
- solvatedbool, optional
Indicates whether the system contains water. Defaults to False.
Returns:
- tuple
A tuple containing the following elements: - molecules (list): A list of molecules to be included in the simulation box. - number_of_copies (list): A list indicating the quantity of each molecule to be included in the simulation box. - topology (openff.toolkit.topology.Topology): The topology of the simulation box. - box_vectors (numpy.ndarray): The vectors defining the dimensions of the simulation box.
Notes:
This function is adapted from the OpenFF Toolkit Packmol wrapper’s solvate_topology function.
swiftpol.build.polymer_system
- class swiftpol.build.polymer_system(monomer_list, reaction, length_target, num_chains, terminals='standard', perc_A_target=100, blockiness_target=1.0, copolymer=False, acceptance=10)[source]
Bases:
object
- __init__(monomer_list, reaction, length_target, num_chains, terminals='standard', perc_A_target=100, blockiness_target=1.0, copolymer=False, acceptance=10)[source]
Initialize the polymer system and build the polymer chains.
Parameters:
monomer_list (list): List of monomers to be used in the polymerization.
reaction (str): The type of reaction to be used for polymerization.
length_target (float): The target length of the polymer chains.
num_chains (int): The number of polymer chains to be generated.
terminals (str, optional): The type of terminal groups to be used. Default is ‘standard’.
perc_A_target (float, optional): The target percentage of monomer A in the copolymer. Default is 100.
blockiness_target (float, optional): The target blockiness of the copolymer. Default is 1.0.
copolymer (bool, optional): Flag to indicate if the system is a copolymer. Default is False.
acceptance = % deviation of blockiness and A percentage from target values. Default is 10%
Attributes:
length_target (float): The target length of the polymer chains.
terminals (str): The type of terminal groups used.
blockiness_target (float): The target blockiness of the copolymer.
A_target (float): The target percentage of monomer A in the copolymer.
chains (list): List of polymer chains as OpenFF Molecule objects.
chain_rdkit (list): List of polymer chains as RDKit molecule objects.
lengths (list): List of lengths of the polymer chains.
perc_A_actual (list): List of actual percentages of monomer A in the polymer chains.
B_block_length (float): The average block length of monomer B in the copolymer.
A_block_length (float): The average block length of monomer A in the copolymer.
blockiness_list (list): List of blockiness values for the polymer chains.
mean_blockiness (float): The mean blockiness of the polymer chains.
mol_weight_average (float): The average molecular weight of the polymer chains.
PDI (float): The polydispersity index of the polymer chains.
Mn (float): The number-average molecular weight of the polymer chains.
Mw (float): The weight-average molecular weight of the polymer chains.
num_chains (int): The number of polymer chains generated.
length_average (float): The average length of the polymer chains.
min_length (float): The minimum length of the polymer chains.
max_length (float): The maximum length of the polymer chains.
- generate_conformers()[source]
Generate conformers for each polymer chain in the system.
This method uses the OpenFF toolkit OpenEye Wrapper to generate conformers for each polymer chain in the system. It first checks if the OpenEye toolkit is licensed and available. If it is, it uses the OpenEyeToolkitWrapper to generate conformers. Otherwise, it falls back to using the RDKitToolkitWrapper. Each chain is processed to generate a single conformer, and unique atom names are assigned to each chain.
- Raises:
ImportError – If neither RDKit nor OpenEye toolkits are available.
- charge_system(charge_scheme)[source]
Assign partial charges to each polymer chain in the system.
This method uses one of AM1-BCC, Espaloma, or OpenFF NAGL to assign partial charges to each polymer chain in the system. It iterates over each chain in the self.chains list and assigns partial charges to the chain.
- Parameters:
charge_scheme (str) – The charge assignment scheme to use. Options are ‘AM1_BCC’, ‘espaloma’, or ‘NAGL’.
- Raises:
ImportError – If the selected toolkit is not available.
swiftpol.parameterize
- swiftpol.parameterize.charge_polymer(polymer, charge_scheme)[source]
Calculate and return the partial charges of a polymer chain based on the specified charge scheme.
- Parameters:
polymer (rdkit.Chem.rdchem.Mol) – A polymer chain for which the charges are to be calculated.
charge_scheme (str) – A string that specifies the charge scheme to be used. It can be either ‘AM1_BCC’, ‘espaloma’, or ‘NAGL’.
- Returns:
The partial charges of the polymer chain according to the specified charge scheme.
- Return type:
numpy.ndarray
- Raises:
AttributeError – If the charge_scheme input is not ‘AM1_BCC’, ‘NAGL’, or ‘espaloma’.
- swiftpol.parameterize.charge_openff_polymer(openff_chain, charge_scheme)[source]
Calculate and return the partial charges of a polymer chain based on the specified charge scheme.
- Parameters:
polymer (rdkit.Chem.rdchem.Mol) – A polymer chain for which the charges are to be calculated.
charge_scheme (str) – A string that specifies the charge scheme to be used. It can be either ‘AM1_BCC’, ‘espaloma’, or ‘NAGL’.
- Returns:
The partial charges of the polymer chain according to the specified charge scheme.
- Return type:
numpy.ndarray
- Raises:
AttributeError – If the charge_scheme input is not ‘AM1_BCC’, ‘NAGL’, or ‘espaloma’.
- swiftpol.parameterize.forcefield_with_charge_handler(molecule, charge_method, forcefield='openff-2.2.0.offxml', ensemble=False)[source]
Create a forcefield with a charge handler for a given molecule and charge method.
The function can handle both individual molecules and ensembles of molecules.
- Parameters:
molecule (rdkit.Chem.rdchem.Mol or list of rdkit.Chem.rdchem.Mol) – An RDKit molecule object or a list of RDKit molecule objects for which the forcefield is to be created.
charge_method (str) – A string that specifies the charge method to be used for the molecule.
forcefield (str, optional) – A string that specifies the forcefield to be used. Default is “openff-2.2.0.offxml”.
ensemble (bool, optional) – A boolean that specifies whether the input molecule is an ensemble of molecules. Default is False.
- Returns:
An OpenFF ForceField object with the specified molecule’s charges added to the LibraryCharges parameter.
- Return type:
openff.toolkit.typing.engines.smirnoff.ForceField
- Raises:
Exception – If the charge method is not supported.