HTPolyNet 2.11.4__py3-none-any.whl → 2.11.6__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/runtime.py CHANGED
@@ -706,11 +706,15 @@ class Runtime:
706
706
  rc.state.iter += 1
707
707
  continue
708
708
  bdf = triple_bonds_dataframe(chosen, sites, R.product, order=R.bonds[0].get('order', 1))
709
+ # what these monomers already thread, so only what the ladder creates counts
710
+ before_threading = rc.threading_census(TC, bdf, chosen)
709
711
  work = rc.close_rings(TC, bdf, gromacs_dict=gromacs_dict)
710
712
  # a ring the ladder could not pull shut would be bonded long and stay that way
711
713
  bdf, chosen = rc.accept(bdf, work, chosen)
712
714
  # now that the loop is nearly ring-sized, ask what it actually encloses
713
715
  bdf, chosen = rc.reject_threaded(TC, bdf, chosen)
716
+ # and the converse: did the drag push one of their own bonds through a ring
717
+ bdf, chosen = rc.reject_new_threading(TC, bdf, chosen, before_threading)
714
718
  if not chosen:
715
719
  rc.state.iter += 1
716
720
  continue
@@ -27,9 +27,10 @@ import yaml
27
27
  from ..analysis.plot import trace
28
28
  from ..core import projectfilesystem as pfs
29
29
  from ..core.productsplice import map_product_from_template
30
- from ..cure.triplesearch import (bonds_by_atom, candidate_triples, drop_threaded,
30
+ from ..cure.triplesearch import (_mic, bonds_by_atom, candidate_triples, drop_threaded,
31
31
  reactive_sites, residue_map, ring_threading_bonds,
32
- select_disjoint, site_name_maps)
32
+ rings_threaded_by, select_disjoint, site_name_maps)
33
+ from ..geometry.ring import Ring
33
34
  from ..external.gromacs import mdp_modify
34
35
  from ..repair.topology_surgery import neutralize_touched_fragments
35
36
 
@@ -112,6 +113,7 @@ class RingController:
112
113
  'min_rings_per_iteration': 4,
113
114
  'reject_threaded_rings': True,
114
115
  'prefilter_threaded_candidates': False,
116
+ 'reject_new_threading': True,
115
117
  'same_molecule': False,
116
118
  'same_residue': False,
117
119
  'relax': [{'ensemble': 'min'},
@@ -420,9 +422,119 @@ class RingController:
420
422
  keep.append(n)
421
423
  return self._keep_rings(bdf, chosen, keep)
422
424
 
425
+ def _system_rings(self, TC, positions, box):
426
+ """The system's known rings, with a centroid each for cheap proximity filtering.
427
+
428
+ ``Topology.rings`` is built once per molecule template and replicated; nothing
429
+ updates it during a cure, which is why :meth:`form_rings` now registers each
430
+ triazine it makes. Before that it held only the rings monomers were built with
431
+ --- overwhelmingly phenyls.
432
+ """
433
+ out = []
434
+ for r in getattr(TC.Topology, 'rings', []) or []:
435
+ idx = [int(x) for x in r.idx]
436
+ if len(idx) < 3 or any(i not in positions for i in idx):
437
+ continue
438
+ anchor_pos = positions[idx[0]]
439
+ pts = np.array([anchor_pos + _mic(positions[i] - anchor_pos, box) for i in idx])
440
+ out.append((idx, pts.mean(axis=0)))
441
+ return out
442
+
443
+ def threading_census(self, TC, bdf, chosen):
444
+ """What the participating monomers' bonds already thread, per candidate ring.
445
+
446
+ Taken before the closure ladder and again after it, so only threadings the drag
447
+ *created* count against a candidate. Without the before-picture a monomer that
448
+ arrived from packing already threaded through a phenyl would be refused every
449
+ reaction forever, silently, and htpolynet-study found one of those.
450
+
451
+ Returns:
452
+ dict: triple number -> set of (ring key, bond) currently threaded
453
+ """
454
+ if not self.dicts['reject_new_threading'] or not chosen or bdf.empty:
455
+ return {}
456
+ A = TC.Coordinates.A
457
+ positions = {int(r.globalIdx): np.array([r.posX, r.posY, r.posZ])
458
+ for r in A.itertuples()}
459
+ box = np.asarray(TC.Coordinates.box.diagonal(), dtype=float)
460
+ rings = self._system_rings(TC, positions, box)
461
+ if not rings:
462
+ return {}
463
+ centroids = np.array([c for _, c in rings])
464
+ bonds_of = bonds_by_atom(TC.Topology.D['bonds'])
465
+ res_atoms = {}
466
+ for r in A.itertuples():
467
+ res_atoms.setdefault(int(r.resNum), []).append(int(r.globalIdx))
468
+
469
+ census = {}
470
+ for t in sorted(set(int(x) for x in bdf['triple'])):
471
+ rows = bdf[bdf['triple'] == t]
472
+ resids = {int(x) for x in rows['ri']} | {int(x) for x in rows['rj']}
473
+ atoms = [a for rn in resids for a in res_atoms.get(rn, []) if a in positions]
474
+ if not atoms:
475
+ continue
476
+ pts = np.array([positions[a] for a in atoms])
477
+ here = pts.mean(axis=0)
478
+ span = float(np.linalg.norm(_mic(pts - here, box), axis=1).max())
479
+ near = np.linalg.norm(_mic(centroids - here, box), axis=1) <= span + 1.0
480
+ bonds = set()
481
+ for a in atoms:
482
+ bonds.update(bonds_of.get(a, ()))
483
+ census[t] = rings_threaded_by(bonds,
484
+ [rings[i][0] for i in np.flatnonzero(near)],
485
+ positions, box)
486
+ return census
487
+
488
+ def reject_new_threading(self, TC, bdf, chosen, before):
489
+ """Drops a ring whose closure ladder pushed a monomer through an existing ring.
490
+
491
+ :meth:`reject_threaded` asks whether the new ring would close around a bond.
492
+ This asks the converse: whether dragging these three monomers together has run
493
+ one of *their* bonds through a ring that was already there. Both happen.
494
+ htpolynet-study scanned ten builds and found the second kind is mostly phenyls,
495
+ which outnumber triazines about six to one here, and that two of three were made
496
+ by the cure rather than by packing -- one appearing in the same iteration as a
497
+ triazine piercing, which is what identifies it as one event.
498
+
499
+ Declining does not itself pull the monomer back out. What it prevents is the
500
+ threading being made permanent: without the ring bonds the dragged monomers have
501
+ nothing holding them, and the relaxation that follows can undo what the
502
+ restraints did.
503
+
504
+ Args:
505
+ TC (TopoCoord): the system
506
+ bdf (pandas.DataFrame): this iteration's bonds, three rows per ring
507
+ chosen (list): the rings still standing
508
+ before (dict): the census taken before the ladder
509
+
510
+ Returns:
511
+ tuple: (bdf, chosen) without the rings that created a threading
512
+ """
513
+ if not self.dicts['reject_new_threading'] or not chosen:
514
+ return bdf, chosen
515
+ after = self.threading_census(TC, bdf, chosen)
516
+ keep = []
517
+ for n in range(len(chosen)):
518
+ created = after.get(n, set()) - before.get(n, set())
519
+ if created:
520
+ ring_key, bond = sorted(created)[0]
521
+ logger.info(f'Iteration {self.state.iter}: declining a ring whose closure '
522
+ f'pulled bond {bond[0]}-{bond[1]} through the existing '
523
+ f'{len(ring_key)}-ring at {ring_key[0]}; that monomer would be '
524
+ f'threaded for good once the ring formed')
525
+ continue
526
+ keep.append(n)
527
+ return self._keep_rings(bdf, chosen, keep)
528
+
423
529
  def relax(self, TC, gromacs_dict=None):
424
530
  """Eases a freshly closed ring's bonds in, and lets the box respond.
425
531
 
532
+ Writes the topology first, as every stage here must: Gromacs reads it from disk,
533
+ and :meth:`form_rings` changes it only in memory. Until 2.11.5 this stage and
534
+ :meth:`equilibrate` both ran against whatever :meth:`close_rings` last wrote --
535
+ the ladder topology, with its restraints still loaded and the ring bonds not yet
536
+ formed.
537
+
426
538
  A ring bond is formed at whatever length the closure ladder reached, a good way
427
539
  short of the 1.34 A it wants, so the system is strained the moment the bonds
428
540
  exist. CURE relaxes its new bonds for the same reason; without it here, the
@@ -449,6 +561,11 @@ class RingController:
449
561
  TC (TopoCoord): the system
450
562
  gromacs_dict (dict): gromacs directives
451
563
  """
564
+ # form_rings changed the topology in memory and wrote nothing, so without this
565
+ # the run grompps against the last file on disk -- the ladder topology, whose
566
+ # restraints are still in place and whose ring bonds do not exist yet
567
+ TC.write_top(f'ringrelax-{self.state.iter}.top')
568
+ TC.write_gro(f'ringrelax-{self.state.iter}.gro')
452
569
  self._run_stages(TC, f'ringrelax-{self.state.iter}', self.dicts['relax'],
453
570
  gromacs_dict or {})
454
571
  logger.info(f'Iteration {self.state.iter}: new ring bonds relaxed')
@@ -467,7 +584,11 @@ class RingController:
467
584
  only ever grows. Measured with `relax` alone and no equilibration, a ring cure's
468
585
  box expands thermally for six iterations to +28% in volume and then comes back
469
586
  down as the network forms, the two legs nearly cancelling: path 0.4104 nm for a
470
- net of -0.0038 nm. A cure is not just shrinkage -- the hot stages enlarge the
587
+ net of -0.0038 nm. Those figures are RETRACTED as of 2.11.5 --- they were
588
+ produced by this stage and :meth:`relax` running against the ladder topology,
589
+ restraints loaded and rings unbonded, so the box was responding to the wrong
590
+ system. They are left here only because the shape of the argument survives:
591
+ a cure is not just shrinkage. A cure is not just shrinkage -- the hot stages enlarge the
471
592
  box and the cold stage pulls it back -- which is why path length rather than net
472
593
  is the statistic to look at, and why the surrogate route travels three to nine
473
594
  times further in box length than it ends up moving.
@@ -494,6 +615,10 @@ class RingController:
494
615
  d = self.dicts['equilibrate']
495
616
  if not d:
496
617
  return []
618
+ # as in relax: grompp reads the topology from disk, so it has to be the one
619
+ # with the rings bonded and the restraints gone
620
+ TC.write_top(f'ringequil-{self.state.iter}.top')
621
+ TC.write_gro(f'ringequil-{self.state.iter}.gro')
497
622
  edr_list = TC.equilibrate(deffnm=f'ringequil-{self.state.iter}', edict=d,
498
623
  gromacs_dict=gromacs_dict or {}) or []
499
624
  if d.get('ensemble') == 'npt' and edr_list:
@@ -590,6 +715,10 @@ class RingController:
590
715
  touched.update(stats['atoms'])
591
716
  # the splice replaces charges wholesale over three residues at a time, so the
592
717
  # molecules it touched have to be brought back to neutral
718
+ # Topology.rings is template-derived and nothing else updates it, so a triazine
719
+ # formed here is invisible to every ring-aware check until it is registered
720
+ for n in range(len(chosen)):
721
+ TC.Topology.rings.append(Ring(_ring_atoms(bdf, n)))
593
722
  neutralize_touched_fragments(TC, touched)
594
723
  for r in bdf.itertuples():
595
724
  for idx in (int(r.ai), int(r.aj)):
@@ -238,6 +238,57 @@ def ring_threading_bonds(ring, positions, bonds_of, box, margin=0.3):
238
238
  return out
239
239
 
240
240
 
241
+ def rings_threaded_by(bond_pairs, ring_atom_lists, positions, box, margin=0.3):
242
+ """Which of `ring_atom_lists` each of `bond_pairs` passes through.
243
+
244
+ The mirror of :func:`ring_threading_bonds`: there a prospective ring is tested
245
+ against the bonds around it, here existing rings are tested against bonds that have
246
+ just been moved. A ring cure needs both, because dragging three monomers together
247
+ can push one of their own backbones through a ring that was already there --- a
248
+ phenyl, usually, since those outnumber triazines about six to one in these systems.
249
+
250
+ Args:
251
+ bond_pairs (iterable): (ai, aj) bonds to test
252
+ ring_atom_lists (iterable): existing rings, each a list of atoms in cyclic order
253
+ positions (dict): global atom index -> position, in nm
254
+ box (array-like): box diagonal, in nm
255
+ margin (float): how far beyond a ring's own radius to consider a bond, in nm
256
+
257
+ Returns:
258
+ set: (ring key, bond) pairs found threaded, where the ring key is its sorted
259
+ atom tuple so the result can be compared between two moments in time
260
+ """
261
+ box = np.asarray(box, dtype=float)
262
+ out = set()
263
+ pairs = [(int(a), int(b)) for a, b in bond_pairs]
264
+ for ring in ring_atom_lists:
265
+ ring = [int(x) for x in ring]
266
+ if any(i not in positions for i in ring):
267
+ continue
268
+ anchor = np.asarray(positions[ring[0]], dtype=float)
269
+ P = np.array([anchor + _mic(np.asarray(positions[i], dtype=float) - anchor, box)
270
+ for i in ring])
271
+ O = P.mean(axis=0)
272
+ reach = float(np.linalg.norm(P - O, axis=1).max()) + margin
273
+ ring_set = set(ring)
274
+ key = tuple(sorted(ring))
275
+ for ai, aj in pairs:
276
+ if ai in ring_set or aj in ring_set:
277
+ continue
278
+ if ai not in positions or aj not in positions:
279
+ continue
280
+ p0 = anchor + _mic(np.asarray(positions[ai], dtype=float) - anchor, box)
281
+ if float(np.linalg.norm(p0 - O)) > reach + margin:
282
+ continue
283
+ p1 = p0 + _mic(np.asarray(positions[aj], dtype=float)
284
+ - np.asarray(positions[ai], dtype=float), box)
285
+ for k in range(len(P)):
286
+ if _segment_pierces_triangle(p0, p1, O, P[k], P[(k + 1) % len(P)]):
287
+ out.add((key, (min(ai, aj), max(ai, aj))))
288
+ break
289
+ return out
290
+
291
+
241
292
  def bonds_by_atom(bonds):
242
293
  """Inverts a bond table into {atom: [(ai, aj), ...]}, for threading lookups."""
243
294
  out = {}
@@ -832,6 +832,17 @@ attributes:
832
832
  monomer that shows up stretched past 2 A in the final structure. Set false
833
833
  to reproduce pre-2.11.4 behavior.
834
834
  default: true
835
+ - name: reject_new_threading
836
+ type: bool
837
+ text: >
838
+ Refuse a ring whose closure ladder dragged one of its own monomers' bonds
839
+ through a ring that was already there. The converse of
840
+ `reject_threaded_rings`, and mostly a different population: phenyls
841
+ outnumber triazines about six to one in these systems. Only threadings the
842
+ ladder creates count -- the same monomers are surveyed before and after it,
843
+ so one that arrived from packing already threaded is not refused every
844
+ reaction forever. Set false to reproduce pre-2.11.6 behavior.
845
+ default: true
835
846
  - name: prefilter_threaded_candidates
836
847
  type: bool
837
848
  text: >
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: htpolynet
3
- Version: 2.11.4
3
+ Version: 2.11.6
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/
@@ -13,7 +13,7 @@ htpolynet/core/molecule.py,sha256=j0I0qsk5mRTg8QMysxJz6U9HxgTRpRSzHEgJ_SRT-jQ,63
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=KLpKlAaAG02bl6jZEZkYYTyjnHSrO5yAFAwI0uTMmDE,22630
16
- htpolynet/core/runtime.py,sha256=yKSSmaiUmRfJYYSrhqYvpxsD0RWCrYU8cWGl9GKn3v0,76493
16
+ htpolynet/core/runtime.py,sha256=bgFxqvqTX6574jArXAciwpBpjAY4XkdANShadjtrD9w,76823
17
17
  htpolynet/core/topocoord.py,sha256=jUgFg9TuUdSm14wo_464xX6dC4okJMrj1FbIzmaoA0Q,110520
18
18
  htpolynet/core/topology.py,sha256=ASyNbyWxw4bvFUACBmydCr-gGl705o68aB7vGYl7cHk,65405
19
19
  htpolynet/cure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -21,8 +21,8 @@ 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=-EmBsXEFZKRjeVroFR_9X2iCA8COZYIbVUVsZvcfiSs,31264
25
- htpolynet/cure/triplesearch.py,sha256=3i0MBDa1ExFt0zhjvDUQk9GNxrjGwWAiWQAmFDYBWmE,16046
24
+ htpolynet/cure/ringcontroller.py,sha256=K_6bba5drbaRifimXLie1mqEclk0nmFaIfoQW94HGIs,38163
25
+ htpolynet/cure/triplesearch.py,sha256=qn5Aaa1yQkN-KJPVYb8LpZCyauUetyeYI6im8LS4PDw,18487
26
26
  htpolynet/external/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  htpolynet/external/ambertools.py,sha256=NkZ0fP6iqwMnMk2jMD3-EaiGCmutHb1MVFOTFJiQ7WI,6286
28
28
  htpolynet/external/command.py,sha256=KYmWV8P4nuw_ciE16WazviorxjGj5un_z7dL62n0TG0,2480
@@ -92,7 +92,7 @@ htpolynet/resources/molecules/sample-inputs/STY.mol2,sha256=r1NqpovL6L7E96Kkyc6U
92
92
  htpolynet/resources/tcl/readbonds.tcl,sha256=l_bh7eMjbxVi44UMPMi32bFntZltij92KmKfXC1qDz4,972
93
93
  htpolynet/resources/tcl/readgrx.tcl,sha256=A1KvyIpFC_lwfze3XOqTCPqLIkq7HwmqJ96lZH42W0U,1731
94
94
  htpolynet/resources/tcl/render.tcl,sha256=KUszYxzWtfuL7OXdtdk8n6eAQbz8DJfKJrGbb0pOdrI,2379
95
- htpolynet/schema/base.yaml,sha256=Gl3cNHL-ifWa2-nVBPo1aY5OOhDKDADXTUJDcYqOGhI,45576
95
+ htpolynet/schema/base.yaml,sha256=VguKO7H2HgE_iC90CxlxnPLYJoxkWi_RcIA877aT4Y0,46222
96
96
  htpolynet/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
97
97
  htpolynet/utils/banner.py,sha256=hdw6xoHNAo9p6X33LmhW5qyb67qAaQ3hmLnct3ZuDy0,906
98
98
  htpolynet/utils/checkpoint.py,sha256=QTZIJ8K777T6o-mNpjPdelTqrpT0amLlQcgpHBiq5V0,2924
@@ -103,8 +103,8 @@ htpolynet/utils/logsetup.py,sha256=o0mlVXNzqcfua2SAlJPkGSh4lM_bmI10gWwpb9gqYu8,1
103
103
  htpolynet/utils/profiling.py,sha256=su7qpGEz6FXVU4KT2HQDWG82bc1sgsfpDQBbAfPpsHc,7331
104
104
  htpolynet/utils/stringthings.py,sha256=Mr6o55EM8o4YAaVYpjIJj2IxDToNdbPzb-lpQ3w3jFk,1176
105
105
  htpolynet/utils/vmd_viz.py,sha256=Crk3Ln88PKiJ9X7DMMkFEVh2Ru6a1y0RUgj3w6EIgFc,10867
106
- htpolynet-2.11.4.dist-info/METADATA,sha256=f665u_6EhWQkqK_HSwb5yyhaQnFSmOJig3Bo1vROtwU,6589
107
- htpolynet-2.11.4.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
108
- htpolynet-2.11.4.dist-info/entry_points.txt,sha256=G5tx55llJf-IV9dIe7J8myGdyrhCVggCAhKrVNGP_s0,48
109
- htpolynet-2.11.4.dist-info/licenses/LICENSE,sha256=piPSGqJdmTGyzF9HOnjlO2KvgOKT8NHwhCuGYM778tY,1071
110
- htpolynet-2.11.4.dist-info/RECORD,,
106
+ htpolynet-2.11.6.dist-info/METADATA,sha256=6zAqfLLdgEofWONCfu8HjlH25_uGcKrfSit9CSXrT6E,6589
107
+ htpolynet-2.11.6.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
108
+ htpolynet-2.11.6.dist-info/entry_points.txt,sha256=G5tx55llJf-IV9dIe7J8myGdyrhCVggCAhKrVNGP_s0,48
109
+ htpolynet-2.11.6.dist-info/licenses/LICENSE,sha256=piPSGqJdmTGyzF9HOnjlO2KvgOKT8NHwhCuGYM778tY,1071
110
+ htpolynet-2.11.6.dist-info/RECORD,,