HTPolyNet 1.0.7.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.
Files changed (93) hide show
  1. HTPolyNet/__init__.py +1 -0
  2. HTPolyNet/ambertools.py +94 -0
  3. HTPolyNet/analyze.py +258 -0
  4. HTPolyNet/banner.py +26 -0
  5. HTPolyNet/bondlist.py +206 -0
  6. HTPolyNet/bondtemplate.py +111 -0
  7. HTPolyNet/checkpoint.py +88 -0
  8. HTPolyNet/command.py +42 -0
  9. HTPolyNet/configuration.py +240 -0
  10. HTPolyNet/coordinates.py +1071 -0
  11. HTPolyNet/countTime.py +26 -0
  12. HTPolyNet/curecontroller.py +767 -0
  13. HTPolyNet/dataframetools.py +130 -0
  14. HTPolyNet/driver.py +250 -0
  15. HTPolyNet/expandreactions.py +154 -0
  16. HTPolyNet/gromacs.py +333 -0
  17. HTPolyNet/inputcheck.py +51 -0
  18. HTPolyNet/linkcell.py +322 -0
  19. HTPolyNet/molecule.py +1279 -0
  20. HTPolyNet/plot.py +607 -0
  21. HTPolyNet/postsim.py +444 -0
  22. HTPolyNet/projectfilesystem.py +483 -0
  23. HTPolyNet/reaction.py +282 -0
  24. HTPolyNet/resources/README.md +20 -0
  25. HTPolyNet/resources/__init__.py +0 -0
  26. HTPolyNet/resources/cfg/DGE-PAC-hi.yaml +115 -0
  27. HTPolyNet/resources/cfg/DGE-PAC-lo.yaml +115 -0
  28. HTPolyNet/resources/cfg/FDE-DFDA-hi.yaml +116 -0
  29. HTPolyNet/resources/cfg/FDE-DFDA-lo.yaml +116 -0
  30. HTPolyNet/resources/cfg/GMASTY-hi.yaml +158 -0
  31. HTPolyNet/resources/cfg/GMASTY-lo.yaml +158 -0
  32. HTPolyNet/resources/cfg/README.md +1 -0
  33. HTPolyNet/resources/cfg/STY.yaml +23 -0
  34. HTPolyNet/resources/cfg/pMSTY-hi.yaml +101 -0
  35. HTPolyNet/resources/cfg/pMSTY-lo.yaml +101 -0
  36. HTPolyNet/resources/cfg/pSTY-hi.yaml +101 -0
  37. HTPolyNet/resources/cfg/pSTY-lo.yaml +101 -0
  38. HTPolyNet/resources/example_depot/0-liquid-styrene.tgz +0 -0
  39. HTPolyNet/resources/example_depot/1-polystyrene.tgz +0 -0
  40. HTPolyNet/resources/example_depot/2-polymethylstyrene.tgz +0 -0
  41. HTPolyNet/resources/example_depot/3-bisgma-styrene-thermoset.tgz +0 -0
  42. HTPolyNet/resources/example_depot/4-pacm-dgeba-epoxy-thermoset.tgz +0 -0
  43. HTPolyNet/resources/example_depot/5-dfda-fde-epoxy-thermoset.tgz +0 -0
  44. HTPolyNet/resources/mdp/README.md +1 -0
  45. HTPolyNet/resources/mdp/drag-min.mdp +13 -0
  46. HTPolyNet/resources/mdp/drag-npt.mdp +36 -0
  47. HTPolyNet/resources/mdp/drag-nvt.mdp +31 -0
  48. HTPolyNet/resources/mdp/min.mdp +14 -0
  49. HTPolyNet/resources/mdp/npt.mdp +37 -0
  50. HTPolyNet/resources/mdp/nvt.mdp +29 -0
  51. HTPolyNet/resources/mdp/relax-min.mdp +13 -0
  52. HTPolyNet/resources/mdp/relax-npt.mdp +37 -0
  53. HTPolyNet/resources/mdp/relax-nvt.mdp +31 -0
  54. HTPolyNet/resources/mdp/single-molecule-min.mdp +12 -0
  55. HTPolyNet/resources/mdp/single-molecule-nvt.mdp +25 -0
  56. HTPolyNet/resources/molecules/inputs/DFA.pdb +62 -0
  57. HTPolyNet/resources/molecules/inputs/DGE.mol2 +115 -0
  58. HTPolyNet/resources/molecules/inputs/EMB.mol2 +50 -0
  59. HTPolyNet/resources/molecules/inputs/FDE.pdb +72 -0
  60. HTPolyNet/resources/molecules/inputs/GMA.mol2 +163 -0
  61. HTPolyNet/resources/molecules/inputs/PAC.mol2 +91 -0
  62. HTPolyNet/resources/molecules/inputs/STY.mol2 +44 -0
  63. HTPolyNet/resources/molecules/make-monomers.sh +64 -0
  64. HTPolyNet/resources/molecules/pics/DFA.png +0 -0
  65. HTPolyNet/resources/molecules/pics/DGE.png +0 -0
  66. HTPolyNet/resources/molecules/pics/EMB.png +0 -0
  67. HTPolyNet/resources/molecules/pics/FDE.png +0 -0
  68. HTPolyNet/resources/molecules/pics/GMA.png +0 -0
  69. HTPolyNet/resources/molecules/pics/PAC.png +0 -0
  70. HTPolyNet/resources/molecules/pics/STY.png +0 -0
  71. HTPolyNet/resources/molecules/sample-inputs/DFA.pdb +62 -0
  72. HTPolyNet/resources/molecules/sample-inputs/DGE.mol2 +115 -0
  73. HTPolyNet/resources/molecules/sample-inputs/EMB.mol2 +50 -0
  74. HTPolyNet/resources/molecules/sample-inputs/FDE.pdb +72 -0
  75. HTPolyNet/resources/molecules/sample-inputs/GMA.mol2 +163 -0
  76. HTPolyNet/resources/molecules/sample-inputs/PAC.mol2 +91 -0
  77. HTPolyNet/resources/molecules/sample-inputs/STY.mol2 +44 -0
  78. HTPolyNet/resources/tcl/readbonds.tcl +32 -0
  79. HTPolyNet/resources/tcl/readgrx.tcl +46 -0
  80. HTPolyNet/resources/tcl/render.tcl +74 -0
  81. HTPolyNet/ring.py +155 -0
  82. HTPolyNet/runtime.py +709 -0
  83. HTPolyNet/software.py +106 -0
  84. HTPolyNet/stringthings.py +39 -0
  85. HTPolyNet/topocoord.py +1877 -0
  86. HTPolyNet/topology.py +1288 -0
  87. HTPolyNet/unused_symmetry_stuff.py +291 -0
  88. HTPolyNet/utils.py +405 -0
  89. htpolynet-1.0.7.2.dist-info/METADATA +84 -0
  90. htpolynet-1.0.7.2.dist-info/RECORD +93 -0
  91. htpolynet-1.0.7.2.dist-info/WHEEL +4 -0
  92. htpolynet-1.0.7.2.dist-info/entry_points.txt +2 -0
  93. htpolynet-1.0.7.2.dist-info/licenses/LICENSE +21 -0
HTPolyNet/linkcell.py ADDED
@@ -0,0 +1,322 @@
1
+ """
2
+
3
+ .. module:: linkcell
4
+ :synopsis: manages the link-cell structure used for searching for pierced rings
5
+
6
+ .. moduleauthor: Cameron F. Abrams, <cfa22@drexel.edu>
7
+
8
+ """
9
+ import numpy as np
10
+ import pandas as pd
11
+ import logging
12
+ from itertools import product
13
+ from multiprocessing import Pool
14
+ from functools import partial
15
+
16
+ logger=logging.getLogger(__name__)
17
+
18
+ class Linkcell:
19
+ """ Handles the link-cell algorithm for searching for bonding partners within a
20
+ cutoff distance from each other
21
+ """
22
+ def __init__(self,box=[],cutoff=None,pbc_wrapper=None):
23
+ """__init__ Constructor for an empty Linkcell object
24
+
25
+ :param box: system box size, defaults to []
26
+ :type box: list, optional
27
+ :param cutoff: cutoff distance, defaults to None
28
+ :type cutoff: float, optional
29
+ :param pbc_wrapper: function used on any 3-D point to wrap it into the central image (provided by HTPolyNet.configuration)
30
+ """
31
+ self.box=box
32
+ self.cutoff=cutoff
33
+ self.pbc_wrapper=pbc_wrapper
34
+
35
+ def create(self,cutoff,box,origin=np.array([0.,0.,0.])):
36
+ """create Creates the link-cell structure in a previously initialized instance
37
+
38
+ :param cutoff: cutoff distance
39
+ :type cutoff: float
40
+ :param box: box size
41
+ :type box: numpy.ndarray
42
+ :param origin: origin, defaults to np.array([0.,0.,0.])
43
+ :type origin: numpy.ndarry, optional
44
+ """
45
+ if box.shape==(3,3):
46
+ box=np.diagonal(box)
47
+ self.cutoff=cutoff
48
+ self.box=box
49
+ self.origin=origin
50
+ # number of cells along x, y, and z directions
51
+ self.ncells=np.floor(self.box/self.cutoff).astype(int)
52
+ # dimensions of one cell
53
+ self.celldim=box/self.ncells
54
+ # 3-d array of lower left corner as a 3-space point, indexed by i,j,k
55
+ # initialized to all zeros, calculated below
56
+ self.cells=np.zeros((*self.ncells,3))
57
+ # 1-d array of (i,j,k) indices indexed by linear cell index (0...ncells-1)
58
+ self.cellndx=np.array(list(product(*[np.arange(x) for x in self.ncells])))
59
+ # 3-d array of lower left corner as a 3-space point, indexed by i,j,k
60
+ for t in self.cellndx:
61
+ i,j,k=t
62
+ self.cells[i,j,k]=self.celldim*np.array([i,j,k])+self.origin
63
+ # set up neighbor lists using linear indices
64
+ self.make_neighborlists()
65
+ logger.debug(f'Linkcell structure: {len(self.cellndx)} cells ({self.ncells}) dim {self.celldim}')
66
+
67
+ def cellndx_of_point(self,R):
68
+ """cellndx_of_point returns the (i,j,k) cell index of point R
69
+
70
+ :param R: a 3-space point
71
+ :type R: numpy.ndarray
72
+ :return: (i,j,k) index of cell
73
+ :rtype: (int,int,int)
74
+ """
75
+ wrapR,bl=self.pbc_wrapper(R)
76
+ C=np.floor(wrapR*np.reciprocal(self.celldim)).astype(int)
77
+ lowdim=(C<np.zeros(3).astype(int)).astype(int) # will never happen if R is wrapped
78
+ hidim=(C>=self.ncells).astype(int) # could happen if exactly there
79
+ if (any(lowdim) or any(hidim)):
80
+ logger.warning(f'Warning: point {R} maps to out-of-bounds-cell {C} ({self.ncells})')
81
+ logger.warning(f'box: {self.box}')
82
+ C+=lowdim
83
+ C-=hidim
84
+ return C
85
+
86
+ def point_in_cellndx(self,R,C):
87
+ """point_in_cellndx returns True if point R is located in cell with (i,j,k) index C
88
+
89
+ :param R: 3-space point
90
+ :type R: numpy.ndarray
91
+ :param C: (i,j,k) cell index
92
+ :type C: (int,int,int)
93
+ :return:
94
+ - True: R in C
95
+ - False: R not in C
96
+ :rtype: boolean
97
+ """
98
+ LL,UU=self.corners_of_cellndx(C)
99
+ wrapR,bl=self.pbc_wrapper(R)
100
+ return all(wrapR<UU) and all(wrapR>=LL)
101
+
102
+ def corners_of_cellndx(self,C):
103
+ """corners_of_cellndx returns the lower-left and upper-right corners of cell with (i,j,k) index C, as an array of 3-space points
104
+
105
+ :param C: (i,j,k) index
106
+ :type C: (int,int,int)
107
+ :return: 2x3 array of lower-left and upper-right corner coordinates
108
+ :rtype: numpy.ndarray
109
+ """
110
+ LL=self.cells[C[0],C[1],C[2]]
111
+ UU=LL+self.celldim
112
+ return np.array([LL,UU])
113
+
114
+ def cellndx_in_structure(self,C):
115
+ """cellndx_in_structure test to see if (i,j,k) index given is within the established linkcell structure
116
+
117
+ :param C: (i,j,k) index
118
+ :type C: (int,int,int)
119
+ :return: - True: C is in the linkcell structure
120
+ - False: C is not in the linkcell structure
121
+ :rtype: boolean
122
+ """
123
+ return all(np.zeros(3)<=C) and all(C<self.ncells)
124
+
125
+ def ldx_of_cellndx(self,C):
126
+ """ldx_of_cellndx return scalar index of cell with (i,j,k)-index C
127
+
128
+ :param C: (i,j,k)-index
129
+ :type C: (int,int,int)
130
+ :return: scalar index of C
131
+ :rtype: int
132
+ """
133
+ nc=self.ncells
134
+ xc=C[0]*nc[1]*nc[2]+C[1]*nc[1]+C[2]
135
+ return xc
136
+
137
+ def cellndx_of_ldx(self,i):
138
+ """cellndx_of_ldx returns (i,j,k)-index of cell with scalar index i
139
+
140
+ :param i: scalar cell index
141
+ :type i: int
142
+ :return: (i,j,k)-index of cell
143
+ :rtype: (int,int,int)
144
+ """
145
+ return self.cellndx[i]
146
+
147
+ def populate_par(self,adf):
148
+ """populate_par populate the linkcell structure by setting the "linkcell_idx" attribute of each atom in the coordinates dataframe adf
149
+
150
+ :param adf: gromacs-format coordinate dataframe
151
+ :type adf: pandas.DataFrame
152
+ :return: modified dataframe
153
+ :rtype: pandas.DataFrame
154
+ """
155
+ sp=adf[['posX','posY','posZ']]
156
+ for i,srow in sp.iterrows():
157
+ ri=srow.values
158
+ C=self.cellndx_of_point(ri)
159
+ idx=self.ldx_of_cellndx(C)
160
+ adf.loc[i,'linkcell_idx']=idx
161
+ return adf
162
+
163
+ def _return_list_lens(self,idx_list,mlists):
164
+ """_return_list_lens returns a list of lengths of lists in list mlists
165
+
166
+ :param idx_list: indicies of mlists that will be tallied
167
+ :type idx_list: list of ints
168
+ :param mlists: list of lists, each a list of integer atom global indices
169
+ :type mlists: list of list of ints
170
+ :return: list of lengths of lists
171
+ :rtype: list of ints
172
+ """
173
+ return [len(mlists[i]) for i in idx_list]
174
+
175
+ def populate(self,Coordinates,ncpu=1):
176
+ """populate Populates linkcell structure
177
+
178
+ :param Coordinates: Coordinates instance from which atom coordinates are taken
179
+ :type Coordinates: Coordinates
180
+ :param ncpu: number of processors to split the operation over, defaults to 1
181
+ :type ncpu: int, optional
182
+ :raises Exception: dies if a point's assigned (i,j,k) cell is outside the cell structure (this would mean the atom's position is outside the periodic box, which is an error. Atom coordinates are always to be held in wrapped configuration, but be careful: gro files unwrap!)
183
+ """
184
+ N=Coordinates.A.shape[0]
185
+ logger.debug(f'Linkcell: assigning cell indices to {N} atoms in {self.box}...')
186
+ Coordinates.set_atomset_attribute('linkcell_idx',-1*np.ones(N).astype(int))
187
+ self.memberlists=[[] for _ in range(self.cellndx.shape[0])]
188
+ ess='s' if ncpu>1 else ''
189
+ logger.debug(f'Linkcell assignment will use {ncpu} processor{ess}')
190
+ p=Pool(processes=ncpu)
191
+ adf_split=np.array_split(Coordinates.A,ncpu)
192
+ result=p.map(partial(self.populate_par),adf_split)
193
+ p.close()
194
+ p.join()
195
+ Coordinates.A=pd.DataFrame()
196
+ for a in result:
197
+ Coordinates.A=pd.concat((Coordinates.A,a))
198
+
199
+ idx_list=Coordinates.A['globalIdx'].to_list()
200
+ for i in idx_list:
201
+ lc_idx=Coordinates.get_atom_attribute('linkcell_idx',{'globalIdx':i})
202
+ try:
203
+ self.memberlists[lc_idx].append(i)
204
+ except:
205
+ logger.debug(f'Linear linkcell index {lc_idx} of atom {i} is out of range.\ncellndx.shape[0] is {self.cellndx.shape[0]}\nThis is a bug.')
206
+ raise Exception
207
+
208
+ idx_list=list(range(len(self.memberlists)))
209
+ p=Pool(processes=ncpu)
210
+ idx_list_split=np.array_split(idx_list,ncpu)
211
+ result=p.map(partial(self._return_list_lens,mlists=self.memberlists),idx_list_split)
212
+ p.close()
213
+ p.join()
214
+ result=np.array([item for sublist in result for item in sublist])
215
+ avg_cell_pop=result.mean()
216
+ min_cell_pop=int(result.min())
217
+ max_cell_pop=int(result.max())
218
+ logger.debug(f'Avg/min/max cell pop: {avg_cell_pop:>8.3f}/{min_cell_pop:>8d}/{max_cell_pop:>8d}')
219
+ # logger.debug(f'Linkcell.populate() ends.')
220
+
221
+ def make_neighborlists(self):
222
+ """make_neighborlists populates the neighborlist member, one element per cell; each element is the list of neighbors of that cell
223
+ """
224
+ self.neighborlists=[[] for _ in range(self.cellndx.shape[0])]
225
+ for C in self.cellndx:
226
+ idx=self.ldx_of_cellndx(C)
227
+ for D in self.neighbors_of_cellndx(C):
228
+ if self.ldx_of_cellndx(D)!=idx:
229
+ self.neighborlists[idx].append(self.ldx_of_cellndx(D))
230
+
231
+ def make_memberlists(self,cdf):
232
+ """make_memberlists populates the memberlists member, one element per cell; each element is the list of atom indices in that cell
233
+
234
+ :param cdf: coordinates data frame
235
+ :type cdf: pd.DataFrame
236
+ """
237
+ self.memberlists=[[] for _ in range(self.cellndx.shape[0])]
238
+ rdf=cdf[cdf['linkcell_idx']!=-1]
239
+ # logger.debug(f'Generated {len(self.memberlists)} empty memberlists.')
240
+ for i,r in rdf.iterrows():
241
+ cidx=r['linkcell_idx']
242
+ idx=r['globalIdx']
243
+ self.memberlists[cidx].append(idx)
244
+ rl=np.array([len(self.memberlists[i]) for i in range(self.cellndx.shape[0])])
245
+ assert int(rl.sum())==rdf.shape[0] # check to make sure all atoms are counted
246
+ avg_cell_pop=rl.mean()
247
+ min_cell_pop=int(rl.min())
248
+ max_cell_pop=int(rl.max())
249
+ logger.debug(f'Avg/min/max cell pop: {avg_cell_pop:>8.3f}/{min_cell_pop:>8d}/{max_cell_pop:>8d}')
250
+
251
+ def neighbors_of_cellndx(self,Ci):
252
+ """neighbors_of_cellndx returns the list of neighbors of cell Ci by their (i,j,k) indices
253
+
254
+ :param Ci: _description_
255
+ :type Ci: _type_
256
+ :return: _description_
257
+ :rtype: _type_
258
+ """
259
+ assert self.cellndx_in_structure(Ci),f'Error: cell {Ci} outside of cell structure {self.ncells}'
260
+ retlist=[]
261
+ dd=np.array([-1,0,1])
262
+ S=list(product(dd,dd,dd))
263
+ S.remove((0,0,0))
264
+ for s in S:
265
+ nCi=Ci+np.array(s)
266
+ for d in range(3):
267
+ if nCi[d]==self.ncells[d]:
268
+ nCi[d]=0
269
+ elif nCi[d]==-1:
270
+ nCi[d]=self.ncells[d]-1
271
+ retlist.append(nCi)
272
+ assert len(retlist)==(len(dd)**3)-1
273
+ return retlist
274
+
275
+ def searchlist_of_ldx(self,i):
276
+ """searchlist_of_ldx returns the list of scalar cell indices of cells that are neighbors of cell with scalar index i
277
+
278
+ :param i: scalar cell index
279
+ :type i: int
280
+ :return: list of scalar indices of neighbor cells
281
+ :rtype: list
282
+ """
283
+ assert i!=-1
284
+ retlist=[]
285
+ C=self.cellndx[i]
286
+ for c in self.neighbors_of_cellndx(C):
287
+ retlist.append(self.ldx_of_cellndx(c))
288
+ assert len(retlist)==27,f'Error: not counting enough neighbor cells'
289
+ return retlist
290
+
291
+ def are_cellndx_neighbors(self,Ci,Cj):
292
+ """are_cellndx_neighbors returns True if cells with (i,j,k) indices Ci and Cj are neighbors
293
+
294
+ :param Ci: cell index
295
+ :type Ci: np.ndarray(3,int)
296
+ :param Cj: cell index
297
+ :type Cj: np.ndarray(3,int)
298
+ :return: True if cells are neighbors, False otherwise
299
+ :rtype: bool
300
+ """
301
+ assert self.cellndx_in_structure(Ci),f'Error: cell {Ci} outside of cell structure {self.ncells}'
302
+ assert self.cellndx_in_structure(Cj),f'Error: cell {Cj} outside of cell structure {self.ncells}'
303
+ dij=Ci-Cj
304
+ low=(dij<-self.ncells/2).astype(int)
305
+ hi=(dij>self.ncells/2).astype(int)
306
+ dij+=(low-hi)*self.ncells
307
+ return all([x in [-1,0,1] for x in dij])
308
+
309
+ def are_ldx_neighbors(self,ildx,jldx):
310
+ """are_ldx_neighbors returns True if cells with scalar indices ildx and jldx are neighbors
311
+
312
+ :param ildx: scalar cell index
313
+ :type ildx: int
314
+ :param jldx: scalar cell index
315
+ :type jldx: int
316
+ :return: True if cells are neighbors, False otherwise
317
+ :rtype: bool
318
+ """
319
+ # should never call this for atoms with unset lc indices
320
+ assert ildx!=-1
321
+ assert jldx!=-1
322
+ return jldx in self.neighborlists[ildx]