-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample_reactor_polyester.py
More file actions
49 lines (40 loc) · 1.78 KB
/
Copy pathexample_reactor_polyester.py
File metadata and controls
49 lines (40 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Reactor example: step-growth polymerization of a monomer melt.
Builds a melt of ethylene glycol + adipic acid and prepares LAMMPS
``fix bond/react`` inputs so the two monomers polymerize into a polyester
during MD (with water split off as a byproduct).
The reactor:
1. detects the diol + di-carboxylic-acid polyesterification reaction,
2. builds the pre/post reaction molecule templates + map file (typed with
the same force field as the system),
3. writes supplementary force-field parameters for the types the reaction
creates (ester linkage, rehybridized carbonyl, water),
4. writes a ready-to-run ``in.bond_react`` input script.
Run the generated script from the project directory:
cd reactor_out/melt
lmp -in in.bond_react
"""
from AutoPoly import System, Molecule, generate, Reactor
# 1. Build a monomer melt (no pre-built chains; the monomers react in MD)
system = System(out="reactor_out")
eg = Molecule(Count=20, Smiles="OCCO", Name="eg")
adipic = Molecule(Count=20, Smiles="O=C(O)CCCCC(=O)O", Name="adipic")
generate(system, "melt", [eg, adipic], force_field="gaff2")
# 2. Detect the polymerization reactions between the packed monomers
project_dir = system.get_folder_path() + "/melt"
reactor = Reactor(project_dir, monomers=[eg, adipic])
instances = reactor.detect_reactions()
print("Detected reactions:")
for inst in instances:
print(" -", inst.description)
# 3. Build the fix bond/react templates + input script
result = reactor.build(temperature=300.0, nevery=100, rmin=0.0, rmax=3.5)
print("\nBuilt reaction template sets:")
for name in result.reactions:
print(" -", name)
print("\nFiles written:")
for f in result.template_files:
print(" ", f)
print(f"\nRun with: cd {project_dir} && lmp -in in.bond_react")