-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample_peo_all_forcefields.py
More file actions
122 lines (99 loc) · 3.18 KB
/
Copy pathexample_peo_all_forcefields.py
File metadata and controls
122 lines (99 loc) · 3.18 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python3
"""
PEO Force Field Test Example
Tests all supported force fields with polyethylene oxide (PEO):
- OPLS-AA: Standard force field for vinyl polymers
- GAFF: General Amber Force Field
- GAFF2: Extended GAFF
- L-OPLS: Long-chain optimized OPLS
- DREIDING: Generic force field (requires external charges)
- COMPASS: Class2 force field (requires LAMMPS CLASS2 package)
Configuration:
- Monomer: Ethylene oxide (-CH2-CH2-O-)
- Chain length: 10 monomers
- Number of chains: 10
Requires: pip install -e . (from the AutoPoly repo root)
"""
from AutoPoly import System, Polymer, generate
# Force fields to test
FORCE_FIELDS = ["oplsaa", "gaff", "gaff2", "lopls", "dreiding", "compass"]
# PEO configuration
PEO_CONFIG = {
"first_smiles": "CCO[*]",
"middle_smiles": "[*]CCO[*]",
"last_smiles": "[*]CCO",
"chain_num": 10,
"dop": 10,
"topology": "linear",
"tacticity": "atactic"
}
def build_sequence(config):
"""Build complement SMILES sequence."""
dop = config["dop"]
if dop == 1:
return ["CCO"] # Single monomer, no wildcards
elif dop == 2:
return [config["first_smiles"], config["last_smiles"]]
else:
return (
[config["first_smiles"]] +
[config["middle_smiles"]] * (dop - 2) +
[config["last_smiles"]]
)
def test_force_field(force_field, output_base="peo_test"):
"""Test PEO with a specific force field."""
output_name = f"{output_base}_{force_field}"
print(f"\n{'='*60}")
print(f"Testing {force_field.upper()} force field")
print(f"{'='*60}")
try:
# Create system
system = System(out=output_name)
# Build sequence
sequence = build_sequence(PEO_CONFIG)
print(f"Sequence length: {len(sequence)} monomers")
# Create polymer
polymer = Polymer(
chain_num=PEO_CONFIG["chain_num"],
sequence=sequence,
topology=PEO_CONFIG["topology"],
tacticity=PEO_CONFIG["tacticity"]
)
# Run generation
generate(
system,
f"peo_{force_field}",
[polymer],
force_field=force_field,
)
print(f"SUCCESS: {force_field} completed")
return True
except Exception as e:
print(f"FAILED: {force_field} - {e}")
import traceback
traceback.print_exc()
return False
def main():
"""Run all force field tests."""
print("PEO Force Field Comparison Test")
print("================================")
print(f"Configuration:")
print(f" - Chains: {PEO_CONFIG['chain_num']}")
print(f" - DOP: {PEO_CONFIG['dop']}")
print(f" - Topology: {PEO_CONFIG['topology']}")
print(f" - Tacticity: {PEO_CONFIG['tacticity']}")
results = {}
for ff in FORCE_FIELDS:
results[ff] = test_force_field(ff)
# Summary
print(f"\n{'='*60}")
print("SUMMARY")
print(f"{'='*60}")
for ff, success in results.items():
status = "PASS" if success else "FAIL"
print(f" {ff:12s}: {status}")
passed = sum(results.values())
total = len(results)
print(f"\nTotal: {passed}/{total} passed")
if __name__ == "__main__":
main()