HTPolyNet 2.10.1__py3-none-any.whl → 2.10.3__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])
@@ -18,6 +18,7 @@ libraries keep working rather than silently re-parameterizing wholesale.
18
18
  Author: Cameron F. Abrams <cfa22@drexel.edu>
19
19
  """
20
20
  import hashlib
21
+ import re
21
22
  import json
22
23
  import logging
23
24
  import os
@@ -34,6 +35,15 @@ _KEY_FIELDS = (
34
35
  )
35
36
  """Fields that determine the parameters, with human-readable labels."""
36
37
 
38
+ VERSION_FIELD = 'ambertools_version'
39
+ """Record field holding the AmberTools version that produced the parameters.
40
+
41
+ The same directives give different numbers under different AmberTools
42
+ releases, and htpolynet's CPU and CUDA images have not always shipped the same
43
+ one. Compared only when both the record and the current run know it, so
44
+ records written before it existed, or runs that cannot tell, still match.
45
+ """
46
+
37
47
  FRCMOD_FIELD = 'frcmod'
38
48
  """Record field holding a digest of the user frcmod files loaded after parmchk2's.
39
49
 
@@ -59,7 +69,19 @@ def frcmod_digest(frcmods):
59
69
  return h.hexdigest()[:16]
60
70
 
61
71
 
62
- def build_key(ambertools=None):
72
+ def ambertools_version():
73
+ """Returns the AmberTools version of the running installation, or None if unknown.
74
+
75
+ Returns:
76
+ str or None: version string, e.g. '26.0'
77
+ """
78
+ from ..external import software
79
+ v = software.versions.get('ambertools', '')
80
+ m = re.search(r'ver\.\s*([0-9][0-9A-Za-z.\-]*)', v or '')
81
+ return m.group(1) if m else None
82
+
83
+
84
+ def build_key(ambertools=None, version='detect'):
63
85
  """Returns the provenance record describing a parameterization run under
64
86
  the given AmberTools directives.
65
87
 
@@ -68,6 +90,8 @@ def build_key(ambertools=None):
68
90
 
69
91
  Args:
70
92
  ambertools (dict, optional): ambertools configuration directives
93
+ version (str, optional): AmberTools version to record; 'detect' (the default) asks the
94
+ running installation, and None records none
71
95
 
72
96
  Returns:
73
97
  dict: provenance record
@@ -79,6 +103,10 @@ def build_key(ambertools=None):
79
103
  digest = frcmod_digest(ambertools.get(FRCMOD_FIELD))
80
104
  if digest:
81
105
  key[FRCMOD_FIELD] = digest
106
+ if version == 'detect':
107
+ version = ambertools_version()
108
+ if version:
109
+ key[VERSION_FIELD] = version
82
110
  return key
83
111
 
84
112
 
@@ -158,6 +186,9 @@ def describe_mismatch(stored, requested):
158
186
  continue
159
187
  if stored[field] != requested.get(field):
160
188
  diffs.append(f'{label} {stored[field]!r} cached, {requested.get(field)!r} requested')
189
+ stored_v, requested_v = stored.get(VERSION_FIELD), requested.get(VERSION_FIELD)
190
+ if stored_v and requested_v and stored_v != requested_v:
191
+ diffs.append(f'AmberTools {stored_v} cached, {requested_v} running')
161
192
  # unlike the fields above, an absent frcmod digest is a statement: none was loaded
162
193
  if stored.get(FRCMOD_FIELD) != requested.get(FRCMOD_FIELD):
163
194
  diffs.append(f'user frcmod {stored.get(FRCMOD_FIELD) or "none"} cached, '
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: htpolynet
3
- Version: 2.10.1
3
+ Version: 2.10.3
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,8 +9,8 @@ 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
13
- htpolynet/core/paramcache.py,sha256=A99VVqf1SdcdzoW5tEkRnN_GEPMjnw-1yy0J-S6FzJI,5660
12
+ htpolynet/core/molecule.py,sha256=M2IgRZrSqFFLzMvdk4qZLYo1veiWXkEhjN1uX8C4i-w,55359
13
+ htpolynet/core/paramcache.py,sha256=37S88gRXZ5_xAdWyUE-Q3Etxc5HMv8L_RHrykkq9YAs,6966
14
14
  htpolynet/core/projectfilesystem.py,sha256=2U_EToZxN7yUGWu9BIRABVsYdp1AKkOuManwuFBz89k,20983
15
15
  htpolynet/core/runtime.py,sha256=FQUHlU0SUPxAqcUnMZHhpLgNu8fa5zRmPy8kv5pv72w,62251
16
16
  htpolynet/core/topocoord.py,sha256=GfxOf04jAMYB6_vgj87kG9lXR0LVXwDHWetG5sv5AIA,109249
@@ -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.1.dist-info/METADATA,sha256=t_ogJTLM8JzzOFhYqZpwQqLaRMFwKQhrvIHxXBZEhuk,6589
102
- htpolynet-2.10.1.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
103
- htpolynet-2.10.1.dist-info/entry_points.txt,sha256=G5tx55llJf-IV9dIe7J8myGdyrhCVggCAhKrVNGP_s0,48
104
- htpolynet-2.10.1.dist-info/licenses/LICENSE,sha256=piPSGqJdmTGyzF9HOnjlO2KvgOKT8NHwhCuGYM778tY,1071
105
- htpolynet-2.10.1.dist-info/RECORD,,
101
+ htpolynet-2.10.3.dist-info/METADATA,sha256=dI_QAlcWsLtR57W9jXTcJN7sPOQ6xjmQFcsMc2qgmrw,6589
102
+ htpolynet-2.10.3.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
103
+ htpolynet-2.10.3.dist-info/entry_points.txt,sha256=G5tx55llJf-IV9dIe7J8myGdyrhCVggCAhKrVNGP_s0,48
104
+ htpolynet-2.10.3.dist-info/licenses/LICENSE,sha256=piPSGqJdmTGyzF9HOnjlO2KvgOKT8NHwhCuGYM778tY,1071
105
+ htpolynet-2.10.3.dist-info/RECORD,,