HTPolyNet 2.10.0__py3-none-any.whl → 2.10.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.
@@ -51,6 +51,46 @@ def _yield_bonds_as_df(R: Reaction, TC: TopoCoord, resid_mapper) -> pd.DataFrame
51
51
  'order': bondrec['order'], 'reactantName': R.product})
52
52
  return pd.DataFrame(rows)
53
53
 
54
+ _TRANSROT_STEP_DEG_ = 10.0
55
+ """Angular step of the turn scan in Molecule.transrot."""
56
+
57
+ _TRANSROT_WARN_NM_ = 0.10
58
+ """Closest approach, in nm, below which a template's starting geometry is reported as crowded.
59
+
60
+ Contacts of 1.2-1.5 A between the new piece and the rest are routine before
61
+ minimization; below 1 A they have been seen to stop sqm converging (a TMB ring
62
+ methyl H 0.82 A from a triazine N).
63
+ """
64
+
65
+
66
+ def _rotate_about_axis(xyz, point, axis, theta):
67
+ """Rotates points by theta about the line through point along unit vector axis (Rodrigues).
68
+
69
+ Args:
70
+ xyz (numpy.ndarray): (n, 3) positions
71
+ point (numpy.ndarray): a point on the axis
72
+ axis (numpy.ndarray): unit vector along the axis
73
+ theta (float): angle in radians
74
+
75
+ Returns:
76
+ numpy.ndarray: rotated (n, 3) positions
77
+ """
78
+ if theta == 0.0:
79
+ return xyz.copy()
80
+ k = axis / np.linalg.norm(axis)
81
+ K = np.array([[0, -k[2], k[1]], [k[2], 0, -k[0]], [-k[1], k[0], 0]])
82
+ R = np.eye(3) + np.sin(theta) * K + (1.0 - np.cos(theta)) * (K @ K)
83
+ return (xyz - point) @ R.T + point
84
+
85
+
86
+ def _min_distance(a, b):
87
+ """Smallest distance between any point of a and any point of b; inf if either is empty."""
88
+ if len(a) == 0 or len(b) == 0:
89
+ return np.inf
90
+ diff = a[:, np.newaxis, :] - b[np.newaxis, :, :]
91
+ return float(np.sqrt((diff * diff).sum(axis=2)).min())
92
+
93
+
54
94
  class Molecule:
55
95
  def __init__(self, name='', generator:Reaction=None, origin:str=None):
56
96
  self.name = name
@@ -830,7 +870,16 @@ class Molecule:
830
870
  Rj = TC.get_R(from_idx)
831
871
  logger.debug(f'Ri {at_idx} {Ri} {type(Ri)} {Ri.dtype}')
832
872
  logger.debug(f'Rj {from_idx} {Rj} {type(Rj)} {Rj.dtype}')
833
- overall_maximum = (-1.e9, -1, -1)
873
+ # The two sacrificial H's are made to coincide, which puts at_idx, the H's
874
+ # and from_idx on one line. The moving piece can still turn freely about
875
+ # that line, and that freedom is what clears a crowded site: a third
876
+ # tetramethyl bisphenol on a triazine lands its ortho methyl inside the
877
+ # ring at the unrotated placement. So each H pairing is tried at a
878
+ # range of turns, and the one farthest from the residues that stay put
879
+ # wins. (Measuring against all of TC would include the moving piece's
880
+ # own pre-move positions.)
881
+ fixed = C[~C['resNum'].isin(bresids)]
882
+ overall_maximum = (-1.e9, -1, -1, 0.0)
834
883
  coord_trials = {}
835
884
  for myH, myHnm in myHpartners.items(): # keys are globalIdx's, values are names
836
885
  coord_trials[myH] = {}
@@ -838,17 +887,13 @@ class Molecule:
838
887
  logger.debug(f' Rh {myH} {Rh} {Rh.dtype}')
839
888
  Rih = Ri - Rh
840
889
  Rih *= 1.0 / np.linalg.norm(Rih)
890
+ fixed_xyz = fixed.loc[fixed['globalIdx'] != myH, ['posX', 'posY', 'posZ']].to_numpy(dtype=float)
841
891
  for otH, otHnm in otHpartners.items():
842
892
  logger.debug(f'{self.name}: Considering {myH} {otH}')
843
- coord_trials[myH][otH] = deepcopy(BTC)
844
- # logger.debug(f'\n{coord_trials[myH][otH].Coordinates.A.to_string()}')
845
- Rk = coord_trials[myH][otH].get_R(otH)
846
- logger.debug(f'{self.name}: otH {otH} Rk {Rk} {Rk.dtype}')
893
+ aligned = deepcopy(BTC)
894
+ Rk = aligned.get_R(otH)
847
895
  Rkj = Rk - Rj
848
896
  Rkj *= 1.0 / np.linalg.norm(Rkj)
849
- logger.debug(f'Rkj {Rkj} {Rkj.dtype} Rih {Rih} {Rih.dtype}')
850
- #Rhk=Rh-Rk
851
- #rhk=np.linalg.norm(Rhk)
852
897
  cp = np.cross(Rkj,Rih)
853
898
  c = np.dot(Rkj,Rih)
854
899
  v = np.array([[0,-cp[2],cp[1]],[cp[2],0,-cp[0]],[-cp[1],cp[0],0]])
@@ -856,19 +901,31 @@ class Molecule:
856
901
  I = np.array([[1.,0.,0.],[0.,1.,0.],[0.,0.,1.]])
857
902
  # R is the rotation matrix that will rotate donb to align with accb
858
903
  R = I + v + v2 / (1. + c)
859
- # logger.debug(f'{self.name}: R:\n{R}')
860
- # rotate translate all donor atoms!
861
- coord_trials[myH][otH].rotate(R)
862
- Rk = coord_trials[myH][otH].get_R(otH)
904
+ aligned.rotate(R)
905
+ Rk = aligned.get_R(otH)
863
906
  # overlap the two H atoms by translation
864
- Rik = Rh - Rk
865
- coord_trials[myH][otH].translate(Rik)
866
- minD = TC.minimum_distance(coord_trials[myH][otH], self_excludes=[myH], other_excludes=[otH])
867
- logger.debug(f'{self.name}: minD {minD}')
907
+ aligned.translate(Rh - Rk)
908
+ A = aligned.Coordinates.A
909
+ moving_mask = (A['globalIdx'] != otH).to_numpy()
910
+ xyz = A[['posX', 'posY', 'posZ']].to_numpy(dtype=float)
911
+ best = None
912
+ for theta in np.deg2rad(np.arange(0.0, 360.0, _TRANSROT_STEP_DEG_)):
913
+ trial = _rotate_about_axis(xyz, Rh, Rih, theta)
914
+ minD = _min_distance(trial[moving_mask], fixed_xyz)
915
+ if best is None or minD > best[0]:
916
+ best = (minD, theta, trial)
917
+ minD, theta, trial = best
918
+ A[['posX', 'posY', 'posZ']] = trial
919
+ coord_trials[myH][otH] = aligned
920
+ logger.debug(f'{self.name}: {myH}/{otH} best turn {np.rad2deg(theta):.0f} deg, minD {minD}')
868
921
  if minD > overall_maximum[0]:
869
- overall_maximum = (minD, myH, otH)
922
+ overall_maximum = (minD, myH, otH, theta)
870
923
  logger.debug(f'{self.name}: overall_maximum {overall_maximum}')
871
- minD, myH, otH = overall_maximum
924
+ minD, myH, otH, _ = overall_maximum
925
+ if minD < _TRANSROT_WARN_NM_:
926
+ logger.warning(f'{self.name}: the best placement found for the new bond still leaves two atoms '
927
+ f'{minD*10:.2f} A apart; a semi-empirical charge method (bcc, abcg2) may fail to converge '
928
+ f'on this starting geometry')
872
929
  BTC = coord_trials[myH][otH]
873
930
  TC.overwrite_coords(BTC)
874
931
  TC.swap_atom_names(myH, list(myHighestH.keys())[0])
htpolynet/core/runtime.py CHANGED
@@ -195,6 +195,28 @@ class Runtime:
195
195
  if k not in current:
196
196
  current[k]=v
197
197
 
198
+ def _report_parameterization_summary(self):
199
+ """Logs how many molecule templates were reused and how many were parameterized.
200
+
201
+ Counted after every derived template (symmetry, C=C chain, and
202
+ second-shell) exists, so the numbers cover everything this run needs;
203
+ a job that must not parameterize anything, e.g. one reading a
204
+ pre-filled read-only cache, can check for "0 freshly parameterized".
205
+ """
206
+ n_cached=sum(1 for M in self.molecules.values() if M.origin=='previously parameterized')
207
+ n_new=sum(1 for M in self.molecules.values() if (M.origin or '').startswith('newly parameterized'))
208
+ if not (n_cached or n_new): return
209
+ where=[]
210
+ if pfs._PFS_ and pfs._PFS_.userlibrary:
211
+ where.append(f'{pfs._PFS_.userlibrary.root}')
212
+ if pfs._USER_CACHE_ is not None:
213
+ where.append(f'{pfs._USER_CACHE_.root}')
214
+ logger.info(f'Parameterization summary: {n_cached} of {n_cached+n_new} molecule templates reused from the library '
215
+ f'({" or ".join(where) or "unknown location"}), {n_new} freshly parameterized.')
216
+ if n_cached:
217
+ logger.info(' to force re-parameterization on the next run, use '
218
+ '`htpolynet run --force-parameterization --force-checkin ...`')
219
+
198
220
  def _read_frcmods(self):
199
221
  """Reads the user frcmod file each constituent names, if any.
200
222
 
@@ -357,18 +379,6 @@ class Runtime:
357
379
  logger.debug(f'Generating: {list(self.molecules.keys())}')
358
380
  for mname,M in self.molecules.items():
359
381
  self._generate_molecule(M,force_parameterization=force_parameterization,force_checkin=force_checkin)
360
- n_cached=sum(1 for M in self.molecules.values() if M.origin=='previously parameterized')
361
- n_new=sum(1 for M in self.molecules.values() if M.origin=='newly parameterized')
362
- if n_cached or n_new:
363
- logger.info(
364
- f'Parameterization summary: {n_cached} reused from cache '
365
- f'(~/.htpolynet/molecules/parameterized/), {n_new} freshly parameterized.'
366
- )
367
- if n_cached:
368
- logger.info(
369
- ' to force re-parameterization on the next run, use '
370
- '`htpolynet run --force-parameterization --force-checkin ...`'
371
- )
372
382
  new_reactions,new_molecules=bondchain_expand_reactions(self.molecules)
373
383
  if len(new_molecules)>0:
374
384
  ess='' if len(new_molecules)==1 else 's'
@@ -392,6 +402,7 @@ class Runtime:
392
402
  self.molecules[mname]=M
393
403
  logger.debug(f'Generated {mname}')
394
404
 
405
+ self._report_parameterization_summary()
395
406
  self._check_frcmod_type_conflicts()
396
407
 
397
408
  for M in self.molecules:
@@ -890,7 +890,13 @@ class CureController:
890
890
  # monomer was mid-chain.
891
891
  if fmax<3:
892
892
  if mask is not None:
893
- logger.info('No residue carries three or more cure-reactive sites, so crosslink percolation is not assessed. That is correct for a linear polymer; a system that crosslinks through a multi-residue molecule -- a dimethacrylate, a multi-arm prepolymer -- is outside what this residue-level check can see.')
893
+ logger.info('Crosslink percolation was not assessed: no residue carries three or more '
894
+ 'cure-reactive sites. For a chain polymer that is the answer -- a fully reacted '
895
+ 'difunctional unit is a chain interior, not a junction. But a system that '
896
+ 'crosslinks through a multi-residue molecule, such as a dimethacrylate built from '
897
+ 'a bisphenol and two methacrylates, does percolate through junctions this '
898
+ 'residue-level count cannot see, and there this line means "cannot assess", not '
899
+ '"does not percolate".')
894
900
  return
895
901
  names=adf.loc[adf['resNum']==func.idxmax(),'resName']
896
902
  resname=names.iloc[0] if len(names) else f'residue {func.idxmax()}'
@@ -60,6 +60,56 @@ def insert_molecules(composition,boxSize,outName,inputs_dir='.',**kwargs):
60
60
  logger.debug(l)
61
61
  raise Exception('need bigger box')
62
62
 
63
+ _DYNAMICAL_INTEGRATORS_ = ('md', 'md-vv', 'md-vv-avek', 'sd', 'bd')
64
+ """GROMACS integrators that do dynamics; the rest (steep, cg, l-bfgs, nm, tpi, ...) do not."""
65
+
66
+ _DYNAMICS_ONLY_GPU_TASKS_ = ('pme', 'update', 'bonded')
67
+ """mdrun tasks not forced onto a GPU without a dynamical integrator.
68
+
69
+ GROMACS refuses ``-pme gpu`` and ``-update gpu`` with a minimizer. Whether it
70
+ accepts ``-bonded gpu`` there has not been checked, and a minimization is
71
+ cheap enough that running its bonded work on the CPU costs nothing that matters.
72
+ """
73
+
74
+
75
+ def mdp_integrator(mdp_filename):
76
+ """Returns the integrator an mdp file selects, lower-cased; 'md' if it does not say.
77
+
78
+ Args:
79
+ mdp_filename (str): mdp file name
80
+
81
+ Returns:
82
+ str: integrator name
83
+ """
84
+ value = mdp_to_dict(mdp_filename).get('integrator', 'md')
85
+ return value.split(';')[0].strip().lower() or 'md'
86
+
87
+
88
+ def mdrun_options_for(mdrun_options, integrator):
89
+ """Returns the mdrun options to use with a given integrator.
90
+
91
+ One ``gromacs.mdrun_options`` serves every stage of a build, minimizations
92
+ included. GROMACS stops with a fatal error when ``-pme gpu`` or
93
+ ``-update gpu`` is given with a minimizer, so for a minimizer these, and
94
+ ``-bonded gpu``, become ``auto``. Dynamics gets the options unchanged.
95
+
96
+ Args:
97
+ mdrun_options (dict): options from the configuration
98
+ integrator (str): the mdp's integrator
99
+
100
+ Returns:
101
+ dict: options to pass to mdrun
102
+ """
103
+ if integrator in _DYNAMICAL_INTEGRATORS_:
104
+ return mdrun_options
105
+ adjusted = dict(mdrun_options)
106
+ for task in _DYNAMICS_ONLY_GPU_TASKS_:
107
+ if str(adjusted.get(task, '')).lower() == 'gpu':
108
+ adjusted[task] = 'auto'
109
+ logger.debug(f'integrator {integrator} cannot run {task} on the GPU; passing -{task} auto for this run')
110
+ return adjusted
111
+
112
+
63
113
  def grompp_and_mdrun(gro='',top='',out='',mdp='',boxSize=[],single_molecule=False,**kwargs):
64
114
  """Launcher for grompp and mdrun.
65
115
 
@@ -75,7 +125,7 @@ def grompp_and_mdrun(gro='',top='',out='',mdp='',boxSize=[],single_molecule=Fals
75
125
  quiet=kwargs.get('quiet',True)
76
126
  ignore_codes=kwargs.get('ignore_codes',[-11])
77
127
  maxwarn=kwargs.get('maxwarn',4)
78
- mdrun_options=kwargs.get('mdrun_options',{})
128
+ mdrun_options=dict(kwargs.get('mdrun_options',{}))
79
129
  for option in ['rdd','dds','dlb','npme','nt','ntpmi','ntomp','ntomp_pme','nb','tunepme','pme','pmefft','bonded','update']:
80
130
  if option in kwargs and not option in mdrun_options:
81
131
  mdrun_options[option]=kwargs[option]
@@ -91,6 +141,7 @@ def grompp_and_mdrun(gro='',top='',out='',mdp='',boxSize=[],single_molecule=Fals
91
141
  run(f'{sw.gmx} {sw.gmx_options} editconf -f {gro}.gro -o {gro} -box {box_str}', quiet=quiet)
92
142
  # nsteps=kwargs.get('nsteps',-2)
93
143
  run(f'{sw.gmx} {sw.gmx_options} grompp -f {mdp}.mdp -c {gro}.gro -p {top}.top -o {out}.tpr -maxwarn {maxwarn}', quiet=quiet)
144
+ mdrun_options = mdrun_options_for(mdrun_options, mdp_integrator(f'{mdp}.mdp'))
94
145
  if 'gpu_id' in mdrun_options:
95
146
  unusable = sw.gpu_unusable_reasons()
96
147
  if unusable:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: htpolynet
3
- Version: 2.10.0
3
+ Version: 2.10.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,21 +9,21 @@ 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=RKnsVz_SX7GrCxuL-1rXP9AQ23EcFyiQSYeLiG6CHc4,5191
11
11
  htpolynet/core/coordinates.py,sha256=CGTHkdfw2ikc2ANacA5akRhZ9tOyM2IbELwQ2FVcKRw,23878
12
- htpolynet/core/molecule.py,sha256=MXTdgKXFc7JnCvFhorCaTBQNXrdhKhC9gALtBge4Ff0,52787
12
+ htpolynet/core/molecule.py,sha256=M2IgRZrSqFFLzMvdk4qZLYo1veiWXkEhjN1uX8C4i-w,55359
13
13
  htpolynet/core/paramcache.py,sha256=A99VVqf1SdcdzoW5tEkRnN_GEPMjnw-1yy0J-S6FzJI,5660
14
14
  htpolynet/core/projectfilesystem.py,sha256=2U_EToZxN7yUGWu9BIRABVsYdp1AKkOuManwuFBz89k,20983
15
- htpolynet/core/runtime.py,sha256=DOYay4BcLab2p-Eeti45kWMozEol-8fYsYB5mZQixCY,61529
15
+ htpolynet/core/runtime.py,sha256=FQUHlU0SUPxAqcUnMZHhpLgNu8fa5zRmPy8kv5pv72w,62251
16
16
  htpolynet/core/topocoord.py,sha256=GfxOf04jAMYB6_vgj87kG9lXR0LVXwDHWetG5sv5AIA,109249
17
17
  htpolynet/core/topology.py,sha256=fRp3a-ILNsrjCyIuJrs7p1NYnH4Y6waKLm_CEQK7IUw,60531
18
18
  htpolynet/cure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  htpolynet/cure/chain.py,sha256=-d5BFE5xUKjFdNkxLfSnCnZIRSJCtr7xuxYzNHBeSgU,5344
20
- htpolynet/cure/curecontroller.py,sha256=ulj9wpXRIEH6AAUSS23ssCMYvPKiOOL748fKK0jVjJI,58056
20
+ htpolynet/cure/curecontroller.py,sha256=NObB2l32W2eAf59j_LSHjj_UNEvUQ-dqvs8MWFQ8_pU,58433
21
21
  htpolynet/cure/expandreactions.py,sha256=LDVefyrCZI2QSqrTsrVIPYP6g_w-LiUsYZkN3lUAM74,19977
22
22
  htpolynet/cure/reaction.py,sha256=S-w60HocYknKnGbq1_uwLpKTL5Fte_o7zxwk3FbyQ1I,10557
23
23
  htpolynet/external/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
24
  htpolynet/external/ambertools.py,sha256=NkZ0fP6iqwMnMk2jMD3-EaiGCmutHb1MVFOTFJiQ7WI,6286
25
25
  htpolynet/external/command.py,sha256=KYmWV8P4nuw_ciE16WazviorxjGj5un_z7dL62n0TG0,2480
26
- htpolynet/external/gromacs.py,sha256=KEtHA4TuHaSA_nFXoz2NyrX3JUr9a733-KkOv5BE4Lc,12848
26
+ htpolynet/external/gromacs.py,sha256=vyK-FfodCSgrjELMBWOG7K8pldG2EqoSLJBa_hzC4lk,14795
27
27
  htpolynet/external/slurm.py,sha256=FvnKyNqFXgDe5bdTDB4Kcn9KU4mxq9Gcw675SzU-4w0,4082
28
28
  htpolynet/external/smiles_input.py,sha256=vt-CdEHSqpJ5EA57NqQSCywjpHnTE5wCk2im2oxhM3U,9830
29
29
  htpolynet/external/software.py,sha256=Uzd1vkNnLm8C6By9ryFlbAnVPII30oFHLUOxzxdJJmw,10054
@@ -98,8 +98,8 @@ htpolynet/utils/logsetup.py,sha256=o0mlVXNzqcfua2SAlJPkGSh4lM_bmI10gWwpb9gqYu8,1
98
98
  htpolynet/utils/profiling.py,sha256=su7qpGEz6FXVU4KT2HQDWG82bc1sgsfpDQBbAfPpsHc,7331
99
99
  htpolynet/utils/stringthings.py,sha256=Mr6o55EM8o4YAaVYpjIJj2IxDToNdbPzb-lpQ3w3jFk,1176
100
100
  htpolynet/utils/vmd_viz.py,sha256=Crk3Ln88PKiJ9X7DMMkFEVh2Ru6a1y0RUgj3w6EIgFc,10867
101
- htpolynet-2.10.0.dist-info/METADATA,sha256=tnzImfyZ92r2NecCZeltVxO4wkElSF5ZCgrnQkNauMM,6589
102
- htpolynet-2.10.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
103
- htpolynet-2.10.0.dist-info/entry_points.txt,sha256=G5tx55llJf-IV9dIe7J8myGdyrhCVggCAhKrVNGP_s0,48
104
- htpolynet-2.10.0.dist-info/licenses/LICENSE,sha256=piPSGqJdmTGyzF9HOnjlO2KvgOKT8NHwhCuGYM778tY,1071
105
- htpolynet-2.10.0.dist-info/RECORD,,
101
+ htpolynet-2.10.2.dist-info/METADATA,sha256=M2phMgBpu4Ry-usT-iLjtO6hhBfHhaVtMN5BlhAW6fc,6589
102
+ htpolynet-2.10.2.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
103
+ htpolynet-2.10.2.dist-info/entry_points.txt,sha256=G5tx55llJf-IV9dIe7J8myGdyrhCVggCAhKrVNGP_s0,48
104
+ htpolynet-2.10.2.dist-info/licenses/LICENSE,sha256=piPSGqJdmTGyzF9HOnjlO2KvgOKT8NHwhCuGYM778tY,1071
105
+ htpolynet-2.10.2.dist-info/RECORD,,