HTPolyNet 2.11.0__py3-none-any.whl → 2.11.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- htpolynet/core/molecule.py +12 -1
- htpolynet/core/runtime.py +6 -1
- htpolynet/core/topocoord.py +5 -0
- htpolynet/core/topology.py +77 -0
- htpolynet/cure/ringcontroller.py +98 -7
- htpolynet/geometry/templategeom.py +267 -0
- htpolynet/schema/base.yaml +7 -0
- {htpolynet-2.11.0.dist-info → htpolynet-2.11.2.dist-info}/METADATA +1 -1
- {htpolynet-2.11.0.dist-info → htpolynet-2.11.2.dist-info}/RECORD +12 -11
- {htpolynet-2.11.0.dist-info → htpolynet-2.11.2.dist-info}/WHEEL +0 -0
- {htpolynet-2.11.0.dist-info → htpolynet-2.11.2.dist-info}/entry_points.txt +0 -0
- {htpolynet-2.11.0.dist-info → htpolynet-2.11.2.dist-info}/licenses/LICENSE +0 -0
htpolynet/core/molecule.py
CHANGED
|
@@ -18,11 +18,13 @@ from ..core.bondtemplate import BondTemplate, BondTemplateList, ReactionBond, Re
|
|
|
18
18
|
from ..core.topocoord import TopoCoord
|
|
19
19
|
from ..cure.chain import ChainManager
|
|
20
20
|
from ..cure.reaction import (Reaction, ReactionList, consumes_sacrificial_h, reaction_stage,
|
|
21
|
-
spanning_and_closing_bonds)
|
|
21
|
+
spanning_and_closing_bonds, is_ring_closing)
|
|
22
22
|
from ..external.ambertools import GAFFParameterize
|
|
23
23
|
from ..external.command import run
|
|
24
24
|
from ..external.gromacs import mdp_modify,gro_from_trr
|
|
25
25
|
from ..geometry.matrix4 import Matrix4
|
|
26
|
+
from ..geometry.templategeom import (check_ring_closed,
|
|
27
|
+
relax_geometry as relax_template_geometry)
|
|
26
28
|
from ..geometry.placement import min_distance, place_group, rotate_about_axis
|
|
27
29
|
from ..io.gro import GRX_ATTRIBUTES
|
|
28
30
|
|
|
@@ -510,6 +512,15 @@ class Molecule:
|
|
|
510
512
|
# logger.debug(f'Using override input molecules/inputs/{self.name}.{isf} as a generator')
|
|
511
513
|
# pfs.checkout(f'molecules/inputs/{self.name}.{isf}')
|
|
512
514
|
# else:
|
|
515
|
+
# A ring closure leaves the template's coordinates describing its reactants
|
|
516
|
+
# rather than its product: the closure ladder cannot beat the reactants' own
|
|
517
|
+
# sp parameters, so the ring bonds are recorded but still ~0.22 nm long.
|
|
518
|
+
# Charges are computed from the geometry, so this has to be put right before
|
|
519
|
+
# antechamber sees it -- see geometry.templategeom.
|
|
520
|
+
if is_ring_closing(R):
|
|
521
|
+
self.TopoCoord.Topology.rebalance_mol2_bond_orders()
|
|
522
|
+
relax_template_geometry(self.TopoCoord, name=self.name)
|
|
523
|
+
check_ring_closed(self.TopoCoord, self.name)
|
|
513
524
|
self.TopoCoord.write_mol2(filename=f'{self.name}.mol2', molname=self.name)
|
|
514
525
|
if not do_parameterization:
|
|
515
526
|
self.TopoCoord.write_gro(f'{self.name}.gro', grotitle=self.name)
|
htpolynet/core/runtime.py
CHANGED
|
@@ -701,7 +701,12 @@ class Runtime:
|
|
|
701
701
|
rc.state.iter += 1
|
|
702
702
|
continue
|
|
703
703
|
bdf = triple_bonds_dataframe(chosen, sites, R.product, order=R.bonds[0].get('order', 1))
|
|
704
|
-
rc.close_rings(TC, bdf, gromacs_dict=gromacs_dict)
|
|
704
|
+
work = rc.close_rings(TC, bdf, gromacs_dict=gromacs_dict)
|
|
705
|
+
# a ring the ladder could not pull shut would be bonded long and stay that way
|
|
706
|
+
bdf, chosen = rc.accept(bdf, work, chosen)
|
|
707
|
+
if not chosen:
|
|
708
|
+
rc.state.iter += 1
|
|
709
|
+
continue
|
|
705
710
|
rc.form_rings(TC, bdf, sites, chosen, template, template_resids,
|
|
706
711
|
name_translations=name_translations, atom_names=arm)
|
|
707
712
|
rc.relax(TC, gromacs_dict=gromacs_dict)
|
htpolynet/core/topocoord.py
CHANGED
|
@@ -1307,6 +1307,11 @@ class TopoCoord:
|
|
|
1307
1307
|
# htpolynet-study 2026-09-21: that is the sole reason no cured cyanate-ester
|
|
1308
1308
|
# network in 96 cells contains an intramolecular 14-ring, while carrying a
|
|
1309
1309
|
# cycle rank of ~430 on ~938 junctions. Do not "fix" the staleness.
|
|
1310
|
+
# Nor is gelling the whole of it: counting edges and vertices on the
|
|
1311
|
+
# monomer-junction graph, an acyclic network requires a conversion below
|
|
1312
|
+
# 3/4, so above that every further bond MUST close a cycle. A cure that
|
|
1313
|
+
# refused cycle-closing bonds could not reach the conversions this
|
|
1314
|
+
# chemistry is run at (0.97-0.99) at all.
|
|
1310
1315
|
assert i_resNum!=j_resNum,f'shortcircuit test error {i}-{j} both in residue {i_resNum}?'
|
|
1311
1316
|
i_neighbors=self.Topology.bondlist.partners_of(i)
|
|
1312
1317
|
j_neighbors=self.Topology.bondlist.partners_of(j)
|
htpolynet/core/topology.py
CHANGED
|
@@ -209,6 +209,23 @@ def select_topology_type_option(options, typename='dihedraltypes', rule='stiffes
|
|
|
209
209
|
return sorted_options[0]
|
|
210
210
|
return []
|
|
211
211
|
|
|
212
|
+
|
|
213
|
+
def _element_of(name, gafftype):
|
|
214
|
+
"""Best guess at an atom's element from its GAFF type, falling back to its name.
|
|
215
|
+
|
|
216
|
+
GAFF types are lowercase element-led (``ca``, ``nb``, ``os``, ``hc``), with the
|
|
217
|
+
two-letter halogens the only ambiguity worth handling.
|
|
218
|
+
"""
|
|
219
|
+
for src in (str(gafftype), str(name)):
|
|
220
|
+
t = src.strip().upper()
|
|
221
|
+
if not t:
|
|
222
|
+
continue
|
|
223
|
+
if t[:2] in ('CL', 'BR'):
|
|
224
|
+
return t[:2]
|
|
225
|
+
if t[0].isalpha():
|
|
226
|
+
return t[0]
|
|
227
|
+
return ''
|
|
228
|
+
|
|
212
229
|
class Topology:
|
|
213
230
|
""" Class for handling gromacs topology data
|
|
214
231
|
"""
|
|
@@ -649,6 +666,66 @@ class Topology:
|
|
|
649
666
|
to_drop.append(d[(d.ai == ai) & (d.aj == aj)].index.values[0])
|
|
650
667
|
self.D['bonds'] = self.D['bonds'].drop(to_drop)
|
|
651
668
|
|
|
669
|
+
def rebalance_mol2_bond_orders(self, atoms=None):
|
|
670
|
+
"""Restores valence after an addition bond, by reducing a multiple bond.
|
|
671
|
+
|
|
672
|
+
A condensation reaction removes a hydrogen from each atom it bonds, so valence
|
|
673
|
+
takes care of itself. An addition removes nothing: ``add_bonds`` records the new
|
|
674
|
+
mol2 bond at order 1 and leaves every existing bond alone, so an atom that already
|
|
675
|
+
carried a multiple bond ends up over-valent. A cyclotrimerization does exactly
|
|
676
|
+
this -- the cyanate carbon keeps its C#N, gains the ring bond, and still carries
|
|
677
|
+
its ester oxygen, for a valence of five.
|
|
678
|
+
|
|
679
|
+
The mol2 bond orders are what antechamber perceives the molecule from, so an
|
|
680
|
+
impossible valence there is not cosmetic. Reducing the shared triple bond fixes
|
|
681
|
+
both of its atoms at once, which is why a bond over-valent at BOTH ends is chosen
|
|
682
|
+
first.
|
|
683
|
+
|
|
684
|
+
Args:
|
|
685
|
+
atoms (iterable): restrict the repair to these atom numbers, normally the ones
|
|
686
|
+
a reaction just bonded; None considers every atom
|
|
687
|
+
|
|
688
|
+
Returns:
|
|
689
|
+
int: how many bond orders were reduced
|
|
690
|
+
"""
|
|
691
|
+
mb = self.D.get('mol2_bonds')
|
|
692
|
+
if mb is None or mb.empty:
|
|
693
|
+
return 0
|
|
694
|
+
at = self.D['atoms']
|
|
695
|
+
element = {int(r.nr): _element_of(r.atom, r.type) for r in at.itertuples()}
|
|
696
|
+
limit = {'H': 1, 'C': 4, 'N': 3, 'O': 2, 'F': 1, 'CL': 1, 'BR': 1, 'I': 1}
|
|
697
|
+
order_of = {'1': 1.0, '2': 2.0, '3': 3.0, 'ar': 1.5, 'am': 1.0}
|
|
698
|
+
watch = None if atoms is None else {int(a) for a in atoms}
|
|
699
|
+
reduced = 0
|
|
700
|
+
for _ in range(4 * mb.shape[0]): # each pass reduces one order; bounded
|
|
701
|
+
val = {}
|
|
702
|
+
for r in mb.itertuples():
|
|
703
|
+
o = order_of.get(str(r.order), 1.0)
|
|
704
|
+
val[int(r.ai)] = val.get(int(r.ai), 0.0) + o
|
|
705
|
+
val[int(r.aj)] = val.get(int(r.aj), 0.0) + o
|
|
706
|
+
over = {a: v - limit[element[a]] for a, v in val.items()
|
|
707
|
+
if element.get(a) in limit and v > limit[element[a]] + 0.01
|
|
708
|
+
and (watch is None or a in watch)}
|
|
709
|
+
if not over:
|
|
710
|
+
break
|
|
711
|
+
# a bond over-valent at both ends repairs two atoms at once
|
|
712
|
+
cand = [(i, r) for i, r in enumerate(mb.itertuples())
|
|
713
|
+
if order_of.get(str(r.order), 1.0) >= 2.0
|
|
714
|
+
and (int(r.ai) in over or int(r.aj) in over)]
|
|
715
|
+
if not cand:
|
|
716
|
+
break
|
|
717
|
+
cand.sort(key=lambda x: (-(int(x[1].ai) in over) - (int(x[1].aj) in over),
|
|
718
|
+
-order_of.get(str(x[1].order), 1.0)))
|
|
719
|
+
i, row = cand[0]
|
|
720
|
+
newo = int(order_of[str(row.order)] - 1)
|
|
721
|
+
mb.iat[i, mb.columns.get_loc('order')] = str(newo)
|
|
722
|
+
logger.debug(f'valence repair: bond {row.ai}-{row.aj} order '
|
|
723
|
+
f'{row.order} -> {newo}')
|
|
724
|
+
reduced += 1
|
|
725
|
+
if reduced:
|
|
726
|
+
logger.info(f'Reduced {reduced} bond order(s) to keep valence after an addition')
|
|
727
|
+
return reduced
|
|
728
|
+
|
|
652
729
|
def add_bonds(self, pairs=[]):
|
|
653
730
|
"""Adds bonds indicated in list pairs to the topology.
|
|
654
731
|
|
htpolynet/cure/ringcontroller.py
CHANGED
|
@@ -33,6 +33,21 @@ from ..repair.topology_surgery import neutralize_touched_fragments
|
|
|
33
33
|
logger = logging.getLogger(__name__)
|
|
34
34
|
|
|
35
35
|
|
|
36
|
+
def _triple_key(donors):
|
|
37
|
+
"""A ring's identity, in terms that survive from one iteration to the next.
|
|
38
|
+
|
|
39
|
+
A triple is held as row numbers into the site table, and that table is rebuilt
|
|
40
|
+
every iteration and shrinks as groups react, so those numbers name a different
|
|
41
|
+
ring next time. The three donor atoms do not move: one per group, unique to it,
|
|
42
|
+
and fixed for the life of the system.
|
|
43
|
+
|
|
44
|
+
The two ring orientations deliberately share a key. :func:`candidate_triples`
|
|
45
|
+
scores both and keeps the better one, so the orientation that was declined is the
|
|
46
|
+
better one, and the other would have farther to go.
|
|
47
|
+
"""
|
|
48
|
+
return frozenset(int(d) for d in donors)
|
|
49
|
+
|
|
50
|
+
|
|
36
51
|
class RingCureState:
|
|
37
52
|
"""How far a ring cure has got, and enough to resume it."""
|
|
38
53
|
|
|
@@ -81,7 +96,7 @@ class RingController:
|
|
|
81
96
|
'same_residue': False,
|
|
82
97
|
'relax': [{'ensemble': 'min'},
|
|
83
98
|
{'ensemble': 'nvt', 'temperature': 300, 'nsteps': 2000}],
|
|
84
|
-
'closure': {'nstages': 8, 'target': 0.15, 'kb': 300000.0,
|
|
99
|
+
'closure': {'nstages': 8, 'target': 0.15, 'kb': 300000.0, 'max_accept': 0.30,
|
|
85
100
|
'equilibration': [{'ensemble': 'min'},
|
|
86
101
|
{'ensemble': 'nvt', 'temperature': 600, 'nsteps': 1000}]},
|
|
87
102
|
}
|
|
@@ -93,6 +108,7 @@ class RingController:
|
|
|
93
108
|
self.dicts = d
|
|
94
109
|
self.state = state or RingCureState()
|
|
95
110
|
self.rings_df = None
|
|
111
|
+
self.declined = set()
|
|
96
112
|
|
|
97
113
|
# ---- what the loop decides, all of it testable without MD ----
|
|
98
114
|
|
|
@@ -172,16 +188,49 @@ class RingController:
|
|
|
172
188
|
cands = candidate_triples(sites, positions, self.radius, box,
|
|
173
189
|
same_molecule=self.dicts['same_molecule'],
|
|
174
190
|
same_residue=self.dicts['same_residue'])
|
|
175
|
-
|
|
191
|
+
allowed = self._drop_declined(cands, sites)
|
|
192
|
+
chosen = select_disjoint(allowed, max_triples=self.dicts['max_rings_per_iteration'])
|
|
193
|
+
passed = len(cands) - len(allowed)
|
|
176
194
|
logger.info(f'Iteration {self.state.iter}: {len(sites)} unreacted group(s), '
|
|
177
|
-
f'{len(cands)} candidate ring(s) within {self.radius:.3f} nm
|
|
178
|
-
f'{
|
|
195
|
+
f'{len(cands)} candidate ring(s) within {self.radius:.3f} nm'
|
|
196
|
+
+ (f' ({passed} passed over as already failed)' if passed else '')
|
|
197
|
+
+ f', {len(chosen)} accepted')
|
|
179
198
|
if len(chosen) >= floor or self.radius >= self.dicts['max_radius']:
|
|
199
|
+
if not chosen and cands and self.declined:
|
|
200
|
+
# the memory is now the only thing keeping this iteration idle, and
|
|
201
|
+
# the groups have moved since they were declined; try them again
|
|
202
|
+
logger.info(f'Iteration {self.state.iter}: every ring in reach has '
|
|
203
|
+
f'failed before; forgetting {len(self.declined)} of them '
|
|
204
|
+
f'and offering them again')
|
|
205
|
+
self.declined.clear()
|
|
206
|
+
chosen = select_disjoint(cands,
|
|
207
|
+
max_triples=self.dicts['max_rings_per_iteration'])
|
|
180
208
|
return sites, chosen
|
|
181
209
|
self.state.radius_index += 1
|
|
182
210
|
logger.info(f'Radius increased to {self.radius:.3f} nm '
|
|
183
211
|
f'({len(chosen)}/{floor} ring(s) so far)')
|
|
184
212
|
|
|
213
|
+
def _drop_declined(self, cands, sites):
|
|
214
|
+
"""Passes over the triples this cure has already failed to pull shut.
|
|
215
|
+
|
|
216
|
+
A declined ring leaves its three groups unreacted by design, and the next search
|
|
217
|
+
offers them again -- so a rigid endgame proposes the same triples, runs the same
|
|
218
|
+
closure ladder, and declines them again. Measured at conversion 0.97 with 24
|
|
219
|
+
groups left: nine iterations running, 77 declines, about 67 s apiece, before one
|
|
220
|
+
triple finally closed and the cure finished at 0.971.
|
|
221
|
+
|
|
222
|
+
A preference, not a prohibition, because the geometry between one decline and the
|
|
223
|
+
next search is not identical -- the inter-iteration relaxation moves the groups,
|
|
224
|
+
which is how that cure escaped. Skipping a triple saves a ladder that would
|
|
225
|
+
almost certainly fail; refusing it outright would have ended that cure three
|
|
226
|
+
iterations early. :meth:`search` therefore lifts the whole memory rather than
|
|
227
|
+
come back empty-handed.
|
|
228
|
+
"""
|
|
229
|
+
if not self.declined:
|
|
230
|
+
return cands
|
|
231
|
+
return [c for c in cands
|
|
232
|
+
if _triple_key(sites.at[a, 'donor'] for a in c[1]) not in self.declined]
|
|
233
|
+
|
|
185
234
|
def record(self, chosen):
|
|
186
235
|
"""Counts the rings formed and the groups they consumed."""
|
|
187
236
|
self.state.rings += len(chosen)
|
|
@@ -229,11 +278,53 @@ class RingController:
|
|
|
229
278
|
TC.add_length_attribute(work, attr_name='final_distance')
|
|
230
279
|
worst = work['final_distance'].max()
|
|
231
280
|
logger.info(f'Rings closed to at most {worst:.3f} nm (target {c["target"]:.3f})')
|
|
232
|
-
if worst > 2.0 * c['target']:
|
|
233
|
-
logger.warning(f'A ring-closing pair is still {worst:.3f} nm apart; its bond will be '
|
|
234
|
-
f'formed long and relaxed, which may strain the network')
|
|
235
281
|
return work
|
|
236
282
|
|
|
283
|
+
def accept(self, bdf, work, chosen):
|
|
284
|
+
"""Drops any ring the closure ladder could not actually pull shut.
|
|
285
|
+
|
|
286
|
+
Late in a cure the matrix is rigid enough that a ring sometimes stops well short
|
|
287
|
+
-- one batch at conversion 0.95 ended 0.327 nm apart against a target of 0.150.
|
|
288
|
+
Forming the bond anyway leaves it long: two ring bonds survived relaxation and a
|
|
289
|
+
500 K anneal still 2.6 A apart, strained but stable, which is a defect the
|
|
290
|
+
network then carries for good.
|
|
291
|
+
|
|
292
|
+
Declining costs almost nothing. The groups stay unreacted and are offered again
|
|
293
|
+
next iteration, by which time the neighbourhood has moved; only if they can never
|
|
294
|
+
close does the cure lose them, which is the right outcome.
|
|
295
|
+
|
|
296
|
+
The combination itself is recorded for :meth:`_drop_declined`, which prefers not
|
|
297
|
+
to spend another ladder on it while any untried ring is in reach. That is what
|
|
298
|
+
a rigid endgame otherwise does: nine iterations running, 77 declines, the same
|
|
299
|
+
few triples every time.
|
|
300
|
+
|
|
301
|
+
Args:
|
|
302
|
+
bdf (pandas.DataFrame): this iteration's bonds, three rows per ring
|
|
303
|
+
work (pandas.DataFrame): the same pairs with their final distances
|
|
304
|
+
chosen (list): the rings the search accepted
|
|
305
|
+
|
|
306
|
+
Returns:
|
|
307
|
+
tuple: (bdf, chosen) keeping only the rings that closed
|
|
308
|
+
"""
|
|
309
|
+
limit = self.dicts['closure']['max_accept']
|
|
310
|
+
if not limit:
|
|
311
|
+
return bdf, chosen
|
|
312
|
+
worst = work['final_distance'].to_numpy().reshape(-1, 3).max(axis=1)
|
|
313
|
+
keep = [n for n in range(len(chosen)) if worst[n] <= limit]
|
|
314
|
+
if len(keep) == len(chosen):
|
|
315
|
+
return bdf, chosen
|
|
316
|
+
for n in range(len(chosen)):
|
|
317
|
+
if n not in keep:
|
|
318
|
+
self.declined.add(_triple_key(bdf[bdf['triple'] == n]['ai']))
|
|
319
|
+
logger.info(f'Iteration {self.state.iter}: declining a ring still '
|
|
320
|
+
f'{worst[n]:.3f} nm from closing (limit {limit:.3f} nm); its '
|
|
321
|
+
f'groups stay unreacted, and this combination waits until '
|
|
322
|
+
f'nothing untried is in reach')
|
|
323
|
+
renumber = {old: new for new, old in enumerate(keep)}
|
|
324
|
+
bdf = bdf[bdf['triple'].isin(keep)].copy()
|
|
325
|
+
bdf['triple'] = [renumber[t] for t in bdf['triple']]
|
|
326
|
+
return bdf.reset_index(drop=True), [chosen[n] for n in keep]
|
|
327
|
+
|
|
237
328
|
def relax(self, TC, gromacs_dict=None):
|
|
238
329
|
"""Eases a freshly closed ring's bonds in before anything else runs.
|
|
239
330
|
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"""Makes a freshly assembled product template a plausible molecule before it is parameterized.
|
|
2
|
+
|
|
3
|
+
A template built by bonding reactants together inherits its geometry from how those
|
|
4
|
+
reactants were placed, not from the chemistry of the product. For a condensation that
|
|
5
|
+
is close enough: one new bond, formed between atoms that were already adjacent, and the
|
|
6
|
+
minimization after parameterization tidies the rest.
|
|
7
|
+
|
|
8
|
+
A ring closure is not close enough. Three cyanate groups pulled toward each other close
|
|
9
|
+
to about 0.22 nm and no further -- the restraint ladder is fighting each group's own
|
|
10
|
+
C#N, whose sp parameters hold it linear, and no force constant wins that. The bonds are
|
|
11
|
+
recorded, so the connectivity says triazine, but the coordinates still say three
|
|
12
|
+
cyanates 2.2 A apart.
|
|
13
|
+
|
|
14
|
+
That matters because charges are computed from the geometry. antechamber repairs the
|
|
15
|
+
connectivity it is given -- it perceives the ring as aromatic and assigns `ca`/`nb`
|
|
16
|
+
correctly -- but AM1-BCC takes Mulliken charges from a semiempirical calculation on the
|
|
17
|
+
coordinates, and on those coordinates the calculation sees three separate cyanates.
|
|
18
|
+
Measured on a methyl cyanate trimer: each ring carbon comes out at +0.699 against
|
|
19
|
+
+0.909 for the same molecule properly embedded, 0.21 e low on every ring carbon, with
|
|
20
|
+
the deficit smeared over the rest of the molecule so the net charge still checks out.
|
|
21
|
+
htpolynet-study measured 0.2113 e on a bisphenol A dicyanate trimer independently.
|
|
22
|
+
|
|
23
|
+
Correcting the bond orders alone does not fix it -- that arm of the experiment was
|
|
24
|
+
bit-identical to the unfixed one, because the QM step does not read bond orders. The
|
|
25
|
+
geometry has to be right before antechamber sees it, which is what this module does.
|
|
26
|
+
|
|
27
|
+
Author: Cameron F. Abrams <cfa22@drexel.edu>
|
|
28
|
+
"""
|
|
29
|
+
import logging
|
|
30
|
+
|
|
31
|
+
import numpy as np
|
|
32
|
+
|
|
33
|
+
logger = logging.getLogger(__name__)
|
|
34
|
+
|
|
35
|
+
_ORDER_ = {'1': 1.0, '2': 2.0, '3': 3.0, 'ar': 1.5, 'am': 1.0}
|
|
36
|
+
"""mol2 bond order strings as numbers."""
|
|
37
|
+
|
|
38
|
+
_MAX_PLAUSIBLE_ = {1.0: 0.20, 1.5: 0.18, 2.0: 0.18, 3.0: 0.16}
|
|
39
|
+
"""Longest believable length, in nm, for a bond of each order between light elements.
|
|
40
|
+
|
|
41
|
+
Generous: the longest ordinary single bond here is C-S at about 0.182 nm, and the point
|
|
42
|
+
is to catch a bond that is not a bond at all, not to police a strained one.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _has_mol2_bonds(TC):
|
|
47
|
+
"""True when a TopoCoord carries the bond orders these checks read.
|
|
48
|
+
|
|
49
|
+
A monomer reaches parameterization with its structure still in a file rather than
|
|
50
|
+
loaded, and a system-scale TopoCoord never carries mol2 bonds at all, so both simply
|
|
51
|
+
have nothing to check here.
|
|
52
|
+
"""
|
|
53
|
+
top = getattr(TC, 'Topology', None)
|
|
54
|
+
D = getattr(top, 'D', None) if top is not None else None
|
|
55
|
+
if not D or 'atoms' not in D:
|
|
56
|
+
return False
|
|
57
|
+
mb = D.get('mol2_bonds')
|
|
58
|
+
if mb is None or mb.empty:
|
|
59
|
+
return False
|
|
60
|
+
A = getattr(getattr(TC, 'Coordinates', None), 'A', None)
|
|
61
|
+
return A is not None and not A.empty
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _rdkit_mol(TC):
|
|
65
|
+
"""Builds an RDKit molecule from a TopoCoord's elements, mol2 bonds and coordinates.
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
tuple: (mol, index_map) where index_map takes an htpolynet atom number to an
|
|
69
|
+
RDKit atom index, or (None, None) if the molecule cannot be sanitized
|
|
70
|
+
"""
|
|
71
|
+
from rdkit import Chem
|
|
72
|
+
from rdkit.Chem import AllChem # noqa: F401 (registers conformer machinery)
|
|
73
|
+
from rdkit.Geometry import Point3D
|
|
74
|
+
|
|
75
|
+
from ..core.topology import _element_of
|
|
76
|
+
|
|
77
|
+
if not _has_mol2_bonds(TC):
|
|
78
|
+
return None, None
|
|
79
|
+
at = TC.Topology.D['atoms']
|
|
80
|
+
mb = TC.Topology.D['mol2_bonds']
|
|
81
|
+
A = TC.Coordinates.A.set_index('globalIdx')
|
|
82
|
+
|
|
83
|
+
bt = {1.0: Chem.BondType.SINGLE, 1.5: Chem.BondType.AROMATIC,
|
|
84
|
+
2.0: Chem.BondType.DOUBLE, 3.0: Chem.BondType.TRIPLE}
|
|
85
|
+
rw = Chem.RWMol()
|
|
86
|
+
index_map = {}
|
|
87
|
+
for r in at.itertuples():
|
|
88
|
+
e = _element_of(r.atom, r.type)
|
|
89
|
+
e = e.capitalize() if len(e) == 2 else e
|
|
90
|
+
index_map[int(r.nr)] = rw.AddAtom(Chem.Atom(e))
|
|
91
|
+
for r in mb.itertuples():
|
|
92
|
+
rw.AddBond(index_map[int(r.ai)], index_map[int(r.aj)],
|
|
93
|
+
bt[_ORDER_.get(str(r.order), 1.0)])
|
|
94
|
+
mol = rw.GetMol()
|
|
95
|
+
try:
|
|
96
|
+
Chem.SanitizeMol(mol)
|
|
97
|
+
except Exception as e:
|
|
98
|
+
logger.debug(f'RDKit could not sanitize the template: {e}')
|
|
99
|
+
return None, None
|
|
100
|
+
|
|
101
|
+
conf = Chem.Conformer(mol.GetNumAtoms())
|
|
102
|
+
for nr, idx in index_map.items():
|
|
103
|
+
p = A.loc[nr]
|
|
104
|
+
# htpolynet holds coordinates in nm; RDKit force fields want Angstrom
|
|
105
|
+
conf.SetAtomPosition(idx, Point3D(float(p.posX) * 10.0, float(p.posY) * 10.0,
|
|
106
|
+
float(p.posZ) * 10.0))
|
|
107
|
+
mol.AddConformer(conf, assignId=True)
|
|
108
|
+
return mol, index_map
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _minimize(mol, maxIters):
|
|
112
|
+
"""Runs MMFF if it has parameters for this molecule, UFF otherwise.
|
|
113
|
+
|
|
114
|
+
Returns:
|
|
115
|
+
tuple: (succeeded, energy before, energy after)
|
|
116
|
+
"""
|
|
117
|
+
from rdkit.Chem import AllChem
|
|
118
|
+
try:
|
|
119
|
+
props = AllChem.MMFFGetMoleculeProperties(mol)
|
|
120
|
+
ff = (AllChem.MMFFGetMoleculeForceField(mol, props) if props is not None
|
|
121
|
+
else AllChem.UFFGetMoleculeForceField(mol))
|
|
122
|
+
if ff is None:
|
|
123
|
+
return False, 0.0, 0.0
|
|
124
|
+
before = ff.CalcEnergy()
|
|
125
|
+
ff.Minimize(maxIts=maxIters)
|
|
126
|
+
return True, before, ff.CalcEnergy()
|
|
127
|
+
except Exception as e:
|
|
128
|
+
logger.debug(f'force-field minimization failed: {e}')
|
|
129
|
+
return False, 0.0, 0.0
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def relax_geometry(TC, name='', maxIters=5000):
|
|
133
|
+
"""Relaxes a template's coordinates against its own connectivity, in place.
|
|
134
|
+
|
|
135
|
+
Tries first from the coordinates the template already has, so a product keeps the
|
|
136
|
+
arrangement its reactants were placed in and only the bonds that were never closed
|
|
137
|
+
actually move. If that minimization cannot get going -- a bond recorded across 2.2 A
|
|
138
|
+
can leave the starting geometry strained enough that the line search fails on its
|
|
139
|
+
first step -- it falls back to embedding the molecule from scratch. A fresh embed
|
|
140
|
+
discards the reactants' arrangement, which is a real loss but a much smaller one than
|
|
141
|
+
parameterizing an open ring: the template's geometry is a starting point that gets
|
|
142
|
+
minimized again under GAFF, while its charges are computed once and kept.
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
TC (TopoCoord): the template
|
|
146
|
+
name (str): the molecule's name, for logging
|
|
147
|
+
maxIters (int): force-field iteration cap
|
|
148
|
+
|
|
149
|
+
Returns:
|
|
150
|
+
bool: True if the coordinates were updated
|
|
151
|
+
"""
|
|
152
|
+
from rdkit.Chem import AllChem
|
|
153
|
+
|
|
154
|
+
mol, index_map = _rdkit_mol(TC)
|
|
155
|
+
if mol is None:
|
|
156
|
+
logger.warning(f'{name}: template geometry left as built; RDKit could not read it. '
|
|
157
|
+
f'If this product closes a ring, its charges would be computed on an '
|
|
158
|
+
f'open ring.')
|
|
159
|
+
return False
|
|
160
|
+
|
|
161
|
+
ok, before, after = _minimize(mol, maxIters)
|
|
162
|
+
how = 'relaxed against its own bonds'
|
|
163
|
+
if not ok:
|
|
164
|
+
logger.debug(f'{name}: minimizing from the built geometry failed; re-embedding')
|
|
165
|
+
mol.RemoveAllConformers()
|
|
166
|
+
if AllChem.EmbedMolecule(mol, randomSeed=0xC0FFEE) != 0:
|
|
167
|
+
logger.warning(f'{name}: template geometry left as built; RDKit could neither '
|
|
168
|
+
f'minimize nor embed it.')
|
|
169
|
+
return False
|
|
170
|
+
ok, before, after = _minimize(mol, maxIters)
|
|
171
|
+
how = 're-embedded and relaxed'
|
|
172
|
+
if not ok:
|
|
173
|
+
logger.warning(f'{name}: template geometry left as built; no force field would '
|
|
174
|
+
f'run on it.')
|
|
175
|
+
return False
|
|
176
|
+
|
|
177
|
+
conf = mol.GetConformer()
|
|
178
|
+
A = TC.Coordinates.A
|
|
179
|
+
pos = {nr: conf.GetAtomPosition(idx) for nr, idx in index_map.items()}
|
|
180
|
+
for col, comp in (('posX', 'x'), ('posY', 'y'), ('posZ', 'z')):
|
|
181
|
+
A[col] = [getattr(pos[int(g)], comp) / 10.0 if int(g) in pos else v
|
|
182
|
+
for g, v in zip(A['globalIdx'], A[col])]
|
|
183
|
+
logger.info(f'{name}: template geometry {how} ({before:.1f} -> {after:.1f} kcal/mol)')
|
|
184
|
+
return True
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def geometry_complaints(TC):
|
|
188
|
+
"""Finds what would make a template a bad thing to hand to a charge calculation.
|
|
189
|
+
|
|
190
|
+
Two checks, because they fail independently: an atom whose recorded bond orders
|
|
191
|
+
exceed what its element can carry, and a bond whose length is not credible for its
|
|
192
|
+
order. The second is what catches a ring that never closed -- an aromatic C-N
|
|
193
|
+
recorded at 2.2 A is unmistakable -- and it catches it whether or not the orders
|
|
194
|
+
were ever repaired.
|
|
195
|
+
|
|
196
|
+
Args:
|
|
197
|
+
TC (TopoCoord): the template
|
|
198
|
+
|
|
199
|
+
Returns:
|
|
200
|
+
list: human-readable complaints, empty when the template is fit to parameterize
|
|
201
|
+
"""
|
|
202
|
+
from ..core.topology import _element_of
|
|
203
|
+
|
|
204
|
+
out = []
|
|
205
|
+
if not _has_mol2_bonds(TC):
|
|
206
|
+
return out
|
|
207
|
+
mb = TC.Topology.D['mol2_bonds']
|
|
208
|
+
at = TC.Topology.D['atoms']
|
|
209
|
+
element = {int(r.nr): _element_of(r.atom, r.type) for r in at.itertuples()}
|
|
210
|
+
name = {int(r.nr): r.atom for r in at.itertuples()}
|
|
211
|
+
limit = {'H': 1, 'C': 4, 'N': 3, 'O': 2, 'F': 1, 'CL': 1, 'BR': 1, 'I': 1}
|
|
212
|
+
|
|
213
|
+
val = {}
|
|
214
|
+
for r in mb.itertuples():
|
|
215
|
+
o = _ORDER_.get(str(r.order), 1.0)
|
|
216
|
+
val[int(r.ai)] = val.get(int(r.ai), 0.0) + o
|
|
217
|
+
val[int(r.aj)] = val.get(int(r.aj), 0.0) + o
|
|
218
|
+
for a, v in sorted(val.items()):
|
|
219
|
+
e = element.get(a)
|
|
220
|
+
if e in limit and v > limit[e] + 0.01:
|
|
221
|
+
out.append(f'atom {a} ({name[a]}, {e}) has bond orders summing to {v:g}, '
|
|
222
|
+
f'more than {e} can carry')
|
|
223
|
+
|
|
224
|
+
A = TC.Coordinates.A.set_index('globalIdx')
|
|
225
|
+
for r in mb.itertuples():
|
|
226
|
+
i, j = int(r.ai), int(r.aj)
|
|
227
|
+
if i not in A.index or j not in A.index:
|
|
228
|
+
continue
|
|
229
|
+
d = float(np.linalg.norm(A.loc[i, ['posX', 'posY', 'posZ']].to_numpy(dtype=float)
|
|
230
|
+
- A.loc[j, ['posX', 'posY', 'posZ']].to_numpy(dtype=float)))
|
|
231
|
+
o = _ORDER_.get(str(r.order), 1.0)
|
|
232
|
+
if d > _MAX_PLAUSIBLE_.get(o, 0.20):
|
|
233
|
+
out.append(f'bond {name[i]}({i})-{name[j]}({j}) is recorded at order '
|
|
234
|
+
f'{r.order} but is {d * 10:.2f} A long')
|
|
235
|
+
return out
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def check_ring_closed(TC, name):
|
|
239
|
+
"""Refuses to parameterize a ring-closing product whose ring is still open.
|
|
240
|
+
|
|
241
|
+
Scope matters here. EVERY htpolynet template reaches antechamber with its new bonds
|
|
242
|
+
about 2.2 A long -- a styrene dimer as much as a triazine -- because the bond is
|
|
243
|
+
recorded before anything relaxes it. For a single new bond that has always been
|
|
244
|
+
fine in practice, and this check deliberately says nothing about it: changing how
|
|
245
|
+
those are parameterized would move the charges of every template htpolynet has ever
|
|
246
|
+
built, which is not a thing to do blind. See ROADMAP.md.
|
|
247
|
+
|
|
248
|
+
What is not fine is a ring, because its charges were measured wrong: 0.21 e low on
|
|
249
|
+
every ring carbon, twice, on two different monomers. So after
|
|
250
|
+
:func:`relax_geometry` has had its turn, a ring that is still open means the repair
|
|
251
|
+
did not work and the charges would be silently wrong again.
|
|
252
|
+
|
|
253
|
+
Note that antechamber echoes its input coordinates into its output, so this must be
|
|
254
|
+
checked on what we hand it. Its output geometry is not evidence of anything.
|
|
255
|
+
|
|
256
|
+
Raises:
|
|
257
|
+
RuntimeError: listing every complaint, because they usually share one cause
|
|
258
|
+
"""
|
|
259
|
+
complaints = geometry_complaints(TC)
|
|
260
|
+
if not complaints:
|
|
261
|
+
return
|
|
262
|
+
raise RuntimeError(
|
|
263
|
+
f'{name} closes a ring, but after relaxation it is still not a plausible '
|
|
264
|
+
f'molecule, so its charges would be wrong and it will not be parameterized:\n '
|
|
265
|
+
+ '\n '.join(complaints) +
|
|
266
|
+
f'\nCharges are computed from the geometry, not from the bond orders, and a ring '
|
|
267
|
+
f'left open is charged as the separate groups it still looks like.')
|
htpolynet/schema/base.yaml
CHANGED
|
@@ -543,6 +543,13 @@ attributes:
|
|
|
543
543
|
Minimum amount in nm by which the target distance is decreased
|
|
544
544
|
per stage; with `limit`, this sets the stage count.
|
|
545
545
|
default: 0.0
|
|
546
|
+
- name: max_accept
|
|
547
|
+
type: float
|
|
548
|
+
text: >
|
|
549
|
+
Refuse to form a ring whose pairs are still further apart than this after
|
|
550
|
+
the closure ladder, in nm. The groups stay unreacted and are offered
|
|
551
|
+
again next iteration. 0 accepts any ring.
|
|
552
|
+
default: 0.30
|
|
546
553
|
- name: nstages
|
|
547
554
|
type: int
|
|
548
555
|
text: Explicit stage count, as an alternative to deriving one from `increment`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: htpolynet
|
|
3
|
-
Version: 2.11.
|
|
3
|
+
Version: 2.11.2
|
|
4
4
|
Summary: Automated MD System Builder for Amorphous Network Polymers
|
|
5
5
|
Project-URL: Source, https://github.com/cameronabrams/htpolynet
|
|
6
6
|
Project-URL: Documentation, https://htpolynet.readthedocs.io/
|
|
@@ -9,19 +9,19 @@ htpolynet/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
9
9
|
htpolynet/core/bondtemplate.py,sha256=_1vYMugonDuogysu15IsbpthvxYb6uJKC5ao7pQcWvg,9969
|
|
10
10
|
htpolynet/core/configuration.py,sha256=j-74qPF_bqZrt9fBivGj-jX85kkVHNkSHM13ewE2ut0,5279
|
|
11
11
|
htpolynet/core/coordinates.py,sha256=CGTHkdfw2ikc2ANacA5akRhZ9tOyM2IbELwQ2FVcKRw,23878
|
|
12
|
-
htpolynet/core/molecule.py,sha256=
|
|
12
|
+
htpolynet/core/molecule.py,sha256=j0I0qsk5mRTg8QMysxJz6U9HxgTRpRSzHEgJ_SRT-jQ,63012
|
|
13
13
|
htpolynet/core/paramcache.py,sha256=37S88gRXZ5_xAdWyUE-Q3Etxc5HMv8L_RHrykkq9YAs,6966
|
|
14
14
|
htpolynet/core/productsplice.py,sha256=asFVCW8G_rcMIizvO2Sh98MpOsFqzP1kIX1JySei_p8,12816
|
|
15
15
|
htpolynet/core/projectfilesystem.py,sha256=2U_EToZxN7yUGWu9BIRABVsYdp1AKkOuManwuFBz89k,20983
|
|
16
|
-
htpolynet/core/runtime.py,sha256=
|
|
17
|
-
htpolynet/core/topocoord.py,sha256=
|
|
18
|
-
htpolynet/core/topology.py,sha256=
|
|
16
|
+
htpolynet/core/runtime.py,sha256=yBDfo0-ExUKFmfycWNi-ldnV249yR_j_dkUCkZG0sx8,72385
|
|
17
|
+
htpolynet/core/topocoord.py,sha256=jUgFg9TuUdSm14wo_464xX6dC4okJMrj1FbIzmaoA0Q,110520
|
|
18
|
+
htpolynet/core/topology.py,sha256=ASyNbyWxw4bvFUACBmydCr-gGl705o68aB7vGYl7cHk,65405
|
|
19
19
|
htpolynet/cure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
20
|
htpolynet/cure/chain.py,sha256=-d5BFE5xUKjFdNkxLfSnCnZIRSJCtr7xuxYzNHBeSgU,5344
|
|
21
21
|
htpolynet/cure/curecontroller.py,sha256=eTJc1JqrD7w6XLg4pL5ACHXo5N1oJ6P5pVdzMONxiBU,59756
|
|
22
22
|
htpolynet/cure/expandreactions.py,sha256=eN35-SQrzjoo8ftZVLJkiAKxpA_FigERTwZ8jtoxDng,20682
|
|
23
23
|
htpolynet/cure/reaction.py,sha256=_kRJ1JzT_fjLIAF6j9lH_Sft41KD1kVQuWPmXdHia-M,13446
|
|
24
|
-
htpolynet/cure/ringcontroller.py,sha256=
|
|
24
|
+
htpolynet/cure/ringcontroller.py,sha256=T104pX6qUwjzRgOmROuQnxiV6Eu3xSSZim2XBsFwNaY,19962
|
|
25
25
|
htpolynet/cure/triplesearch.py,sha256=54Dl0RU_LHcwCDa4-0AiRH08eIEA8bTacrA1TDhs5I8,10605
|
|
26
26
|
htpolynet/external/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
27
27
|
htpolynet/external/ambertools.py,sha256=NkZ0fP6iqwMnMk2jMD3-EaiGCmutHb1MVFOTFJiQ7WI,6286
|
|
@@ -37,6 +37,7 @@ htpolynet/geometry/linkcell.py,sha256=11AWNugo9QruaVldMBhK23CuU3F-imkbbUvBX2r1kh
|
|
|
37
37
|
htpolynet/geometry/matrix4.py,sha256=hXVz9VGXT_0nJ-hI7xk4YZmeq4mntYqPrlJYdD1KFl4,3780
|
|
38
38
|
htpolynet/geometry/placement.py,sha256=oSg4uFC8oOIm3UpTdGbD3PhgjdPDIvI3QgsVIcazHuk,3968
|
|
39
39
|
htpolynet/geometry/ring.py,sha256=dpMajpPRRYTywpMsnwoyXVMNGfWZUZxS1SAx3Qh8E2I,9638
|
|
40
|
+
htpolynet/geometry/templategeom.py,sha256=NO6RXL9_iYnPL6QOFPA9UeSDAaGUgxlbJuN8wnNw9p0,11702
|
|
40
41
|
htpolynet/io/__init__.py,sha256=nX1-mb5tNRK_FTH1NP55ESWBSmiY_yBBU-43NMgzeA4,160
|
|
41
42
|
htpolynet/io/gro.py,sha256=QGsAIlTIJlMRxtv_Juo0wdpbICAzyfQvSzzaMWrlMmA,7141
|
|
42
43
|
htpolynet/io/mol2.py,sha256=5aU3HmQ5DS0LBF7tBPCNYKzBScwj8V3xfEUcFIrsevk,7314
|
|
@@ -91,7 +92,7 @@ htpolynet/resources/molecules/sample-inputs/STY.mol2,sha256=r1NqpovL6L7E96Kkyc6U
|
|
|
91
92
|
htpolynet/resources/tcl/readbonds.tcl,sha256=l_bh7eMjbxVi44UMPMi32bFntZltij92KmKfXC1qDz4,972
|
|
92
93
|
htpolynet/resources/tcl/readgrx.tcl,sha256=A1KvyIpFC_lwfze3XOqTCPqLIkq7HwmqJ96lZH42W0U,1731
|
|
93
94
|
htpolynet/resources/tcl/render.tcl,sha256=KUszYxzWtfuL7OXdtdk8n6eAQbz8DJfKJrGbb0pOdrI,2379
|
|
94
|
-
htpolynet/schema/base.yaml,sha256=
|
|
95
|
+
htpolynet/schema/base.yaml,sha256=rIAWZDJuiZLIpnVU5DZCv40Z7KmQ5cx8o5RJyOY2i20,40385
|
|
95
96
|
htpolynet/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
96
97
|
htpolynet/utils/banner.py,sha256=hdw6xoHNAo9p6X33LmhW5qyb67qAaQ3hmLnct3ZuDy0,906
|
|
97
98
|
htpolynet/utils/checkpoint.py,sha256=QTZIJ8K777T6o-mNpjPdelTqrpT0amLlQcgpHBiq5V0,2924
|
|
@@ -102,8 +103,8 @@ htpolynet/utils/logsetup.py,sha256=o0mlVXNzqcfua2SAlJPkGSh4lM_bmI10gWwpb9gqYu8,1
|
|
|
102
103
|
htpolynet/utils/profiling.py,sha256=su7qpGEz6FXVU4KT2HQDWG82bc1sgsfpDQBbAfPpsHc,7331
|
|
103
104
|
htpolynet/utils/stringthings.py,sha256=Mr6o55EM8o4YAaVYpjIJj2IxDToNdbPzb-lpQ3w3jFk,1176
|
|
104
105
|
htpolynet/utils/vmd_viz.py,sha256=Crk3Ln88PKiJ9X7DMMkFEVh2Ru6a1y0RUgj3w6EIgFc,10867
|
|
105
|
-
htpolynet-2.11.
|
|
106
|
-
htpolynet-2.11.
|
|
107
|
-
htpolynet-2.11.
|
|
108
|
-
htpolynet-2.11.
|
|
109
|
-
htpolynet-2.11.
|
|
106
|
+
htpolynet-2.11.2.dist-info/METADATA,sha256=OC5RW8dmoa0N3Ud9ZbTkPDqJnNPvX0PpA1fESIu-wes,6589
|
|
107
|
+
htpolynet-2.11.2.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
108
|
+
htpolynet-2.11.2.dist-info/entry_points.txt,sha256=G5tx55llJf-IV9dIe7J8myGdyrhCVggCAhKrVNGP_s0,48
|
|
109
|
+
htpolynet-2.11.2.dist-info/licenses/LICENSE,sha256=piPSGqJdmTGyzF9HOnjlO2KvgOKT8NHwhCuGYM778tY,1071
|
|
110
|
+
htpolynet-2.11.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|