Polymer Builder: Amorphous Polymer Cells#

Grow many polymer chains in a periodic box at a target density: homopolymers, blends and chains with a distribution of lengths. Dense melts are grown at a low density and compressed with molecular dynamics. Free link points can be crosslinked to build a polymer network.

Expected duration: This notebook takes a few minutes to run.

Overview#

This example builds amorphous polymer cells: many chains in a periodic box at a given density, as a starting point for molecular dynamics. The polymer builder grows all chains at the same time, one monomer per chain in turn, and checks for overlaps across the periodic boundaries.

Random growth gets stuck well below the density of a real polymer melt, especially for bulky monomers. Dense cells are therefore grown at a lower density and then compressed with a short molecular dynamics run that shrinks the lattice.

import numpy as np
from scm.plams import view
from scm.structures.builder.polymer import *


def density(system):
    """Density in g/cm^3 of a system with an orthorhombic lattice."""
    mass = sum(atom.element.mass for atom in system.atoms)
    return mass * 1.66054 / np.prod(np.diag(system.lattice.vectors))

Chains in a box#

Each Chain describes one kind of chain, either from a link table with a number of monomers, or from a sequence. count is the number of such chains. With density the builder sizes a cubic box for the expected mass. Every chain is put in its own region.

When no placement of a monomer fits, the builder may accept one with a few close contacts, and warns about it. optimize="uff" removes them with a short geometry optimization in AMS.

ethylene = Monomer.from_smiles("[*]CC[*]")
styrene = Monomer.from_smiles("[*]CC([*])c1ccccc1")
monomers = {"E": ethylene, "S": styrene}

chains = [Chain(homopolymer_links(monomers, "E"), 30, count=8)]
polyethylene = build_polymers(monomers, chains, density=0.4, temperature=300, optimize="uff", seed=1)
print(f"{polyethylene.num_atoms} atoms, {polyethylene.num_molecules()} chains, density {density(polyethylene):.2f} g/cm^3")
view(polyethylene, direction="tilt_x", width=400, height=400)
[16.10|16:49:50] JOB polymer_optimization STARTED
[16.10|16:49:50] JOB polymer_optimization RUNNING
[16.10|16:49:54] JOB polymer_optimization FINISHED
[16.10|16:49:54] JOB polymer_optimization SUCCESSFUL
1456 atoms, 8 chains, density 0.40 g/cm^3
image generated from notebook

Chain length distributions#

The number of monomers can be a distribution. Every chain draws its own length, here from a Schulz-Zimm distribution with a number average of 20 monomers and a dispersity of 1.5. Different kinds of chains give a blend.

chains = [
    Chain(sequence=Repeat("E", SchulzZimm(20, 1.5)), count=6),
    Chain(sequence=Repeat("S", 8), count=3),
]
blend = build_polymers(monomers, chains, density=0.4, temperature=300, optimize="uff", seed=2)
lengths = [len(blend.get_atoms_in_region(f"Chain{i}")) for i in range(1, 10)]
print("atoms per chain:", lengths)
view(blend, direction="tilt_x", width=400, height=400)
[16.10|16:50:40] JOB polymer_optimization STARTED
[16.10|16:50:40] Renaming job polymer_optimization to polymer_optimization.002
[16.10|16:50:40] JOB polymer_optimization.002 RUNNING
[16.10|16:50:45] JOB polymer_optimization.002 FINISHED
[16.10|16:50:45] JOB polymer_optimization.002 SUCCESSFUL
atoms per chain: [116, 74, 314, 80, 128, 200, 130, 130, 130]
image generated from notebook

A dense melt#

To reach the density of a melt, growth_density grows the chains in a larger box at a low density first. They are then compressed to density with molecular dynamics that deforms the lattice (here with UFF), and optimized. This runs AMS, which takes a minute or two.

chains = [Chain(sequence=Repeat("S", 12), count=6)]
melt = build_polymers(
    monomers,
    chains,
    density=1.0,
    growth_density=0.4,
    compress_steps=4000,
    optimize="uff",
    temperature=300,
    seed=1,
)
print(f"{melt.num_atoms} atoms, density {density(melt):.2f} g/cm^3")
view(melt, direction="tilt_x", width=400, height=400)
[16.10|16:53:04] JOB polymer_compression_prerelax STARTED
[16.10|16:53:04] JOB polymer_compression_prerelax RUNNING
[16.10|16:53:08] JOB polymer_compression_prerelax FINISHED
[16.10|16:53:08] JOB polymer_compression_prerelax SUCCESSFUL
[16.10|16:53:08] JOB polymer_compression STARTED
... output trimmed ....
[16.10|16:53:44] Renaming job polymer_optimization to polymer_optimization.003
[16.10|16:53:44] JOB polymer_optimization.003 RUNNING
[16.10|16:53:47] JOB polymer_optimization.003 FINISHED
[16.10|16:53:47] JOB polymer_optimization.003 SUCCESSFUL
1164 atoms, density 1.00 g/cm^3
image generated from notebook

Crosslinking#

After the growth, free link points can be bonded to each other. Here the backbone monomer has an extra link point C on the phenyl ring. Pairs of these link points whose atoms are within crosslink_distance and that point at each other are bonded, closest first. The new bonds are strained, so the result is optimized.

crosslinker = {"G": Monomer.from_smiles("[*]CC([*])c1ccc([*])cc1", head="A", tail="B")}
chains = [Chain(homopolymer_links(crosslinker, "G"), 10, count=6)]
crosslinks = [Link(LinkPoint("G", "C"), LinkPoint("G", "C"))]
network = build_polymers(
    crosslinker,
    chains,
    density=0.3,
    crosslinks=crosslinks,
    crosslink_distance=6.0,
    optimize="uff",
    temperature=300,
    seed=2,
)
print(f"6 chains, {network.num_molecules()} molecules after crosslinking")
view(network, direction="tilt_x", width=400, height=400)
[16.10|16:53:51] JOB polymer_optimization STARTED
[16.10|16:53:51] Renaming job polymer_optimization to polymer_optimization.004
[16.10|16:53:51] JOB polymer_optimization.004 RUNNING
[16.10|16:53:56] JOB polymer_optimization.004 FINISHED
[16.10|16:53:56] JOB polymer_optimization.004 SUCCESSFUL
6 chains, 3 molecules after crosslinking
image generated from notebook

See also#

Python Script#

#!/usr/bin/env python
# coding: utf-8

# ## Overview
# 
# This example builds amorphous polymer cells: many chains in a periodic box at a given density, as a starting point
# for molecular dynamics. The polymer builder grows all chains at the same time, one monomer per chain in turn, and
# checks for overlaps across the periodic boundaries.
# 
# Random growth gets stuck well below the density of a real polymer melt, especially for bulky monomers. Dense cells
# are therefore grown at a lower density and then compressed with a short molecular dynamics run that shrinks the
# lattice.

import numpy as np
from scm.plams import view
from scm.structures.builder.polymer import *


def density(system):
    """Density in g/cm^3 of a system with an orthorhombic lattice."""
    mass = sum(atom.element.mass for atom in system.atoms)
    return mass * 1.66054 / np.prod(np.diag(system.lattice.vectors))


# ## Chains in a box
# 
# Each ``Chain`` describes one kind of chain, either from a link table with a number of monomers, or from a sequence.
# ``count`` is the number of such chains. With ``density`` the builder sizes a cubic box for the expected mass. Every
# chain is put in its own region.
# 
# When no placement of a monomer fits, the builder may accept one with a few close contacts, and warns about it.
# ``optimize="uff"`` removes them with a short geometry optimization in AMS.

ethylene = Monomer.from_smiles("[*]CC[*]")
styrene = Monomer.from_smiles("[*]CC([*])c1ccccc1")
monomers = {"E": ethylene, "S": styrene}

chains = [Chain(homopolymer_links(monomers, "E"), 30, count=8)]
polyethylene = build_polymers(monomers, chains, density=0.4, temperature=300, optimize="uff", seed=1)
print(f"{polyethylene.num_atoms} atoms, {polyethylene.num_molecules()} chains, density {density(polyethylene):.2f} g/cm^3")
view(polyethylene, direction="tilt_x", width=400, height=400, picture_path="picture1.png")


# ## Chain length distributions
# 
# The number of monomers can be a distribution. Every chain draws its own length, here from a Schulz-Zimm
# distribution with a number average of 20 monomers and a dispersity of 1.5. Different kinds of chains give a blend.

chains = [
    Chain(sequence=Repeat("E", SchulzZimm(20, 1.5)), count=6),
    Chain(sequence=Repeat("S", 8), count=3),
]
blend = build_polymers(monomers, chains, density=0.4, temperature=300, optimize="uff", seed=2)
lengths = [len(blend.get_atoms_in_region(f"Chain{i}")) for i in range(1, 10)]
print("atoms per chain:", lengths)
view(blend, direction="tilt_x", width=400, height=400, picture_path="picture2.png")


# ## A dense melt
# 
# To reach the density of a melt, ``growth_density`` grows the chains in a larger box at a low density first. They are
# then compressed to ``density`` with molecular dynamics that deforms the lattice (here with UFF), and optimized.
# This runs AMS, which takes a minute or two.

chains = [Chain(sequence=Repeat("S", 12), count=6)]
melt = build_polymers(
    monomers,
    chains,
    density=1.0,
    growth_density=0.4,
    compress_steps=4000,
    optimize="uff",
    temperature=300,
    seed=1,
)
print(f"{melt.num_atoms} atoms, density {density(melt):.2f} g/cm^3")
view(melt, direction="tilt_x", width=400, height=400, picture_path="picture3.png")


# ## Crosslinking
# 
# After the growth, free link points can be bonded to each other. Here the backbone monomer has an extra link point
# ``C`` on the phenyl ring. Pairs of these link points whose atoms are within ``crosslink_distance`` and that point at
# each other are bonded, closest first. The new bonds are strained, so the result is optimized.

crosslinker = {"G": Monomer.from_smiles("[*]CC([*])c1ccc([*])cc1", head="A", tail="B")}
chains = [Chain(homopolymer_links(crosslinker, "G"), 10, count=6)]
crosslinks = [Link(LinkPoint("G", "C"), LinkPoint("G", "C"))]
network = build_polymers(
    crosslinker,
    chains,
    density=0.3,
    crosslinks=crosslinks,
    crosslink_distance=6.0,
    optimize="uff",
    temperature=300,
    seed=2,
)
print(f"6 chains, {network.num_molecules()} molecules after crosslinking")
view(network, direction="tilt_x", width=400, height=400, picture_path="picture4.png")