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.
- HTPolyNet/__init__.py +1 -0
- HTPolyNet/ambertools.py +94 -0
- HTPolyNet/analyze.py +258 -0
- HTPolyNet/banner.py +26 -0
- HTPolyNet/bondlist.py +206 -0
- HTPolyNet/bondtemplate.py +111 -0
- HTPolyNet/checkpoint.py +88 -0
- HTPolyNet/command.py +42 -0
- HTPolyNet/configuration.py +240 -0
- HTPolyNet/coordinates.py +1071 -0
- HTPolyNet/countTime.py +26 -0
- HTPolyNet/curecontroller.py +767 -0
- HTPolyNet/dataframetools.py +130 -0
- HTPolyNet/driver.py +250 -0
- HTPolyNet/expandreactions.py +154 -0
- HTPolyNet/gromacs.py +333 -0
- HTPolyNet/inputcheck.py +51 -0
- HTPolyNet/linkcell.py +322 -0
- HTPolyNet/molecule.py +1279 -0
- HTPolyNet/plot.py +607 -0
- HTPolyNet/postsim.py +444 -0
- HTPolyNet/projectfilesystem.py +483 -0
- HTPolyNet/reaction.py +282 -0
- HTPolyNet/resources/README.md +20 -0
- HTPolyNet/resources/__init__.py +0 -0
- HTPolyNet/resources/cfg/DGE-PAC-hi.yaml +115 -0
- HTPolyNet/resources/cfg/DGE-PAC-lo.yaml +115 -0
- HTPolyNet/resources/cfg/FDE-DFDA-hi.yaml +116 -0
- HTPolyNet/resources/cfg/FDE-DFDA-lo.yaml +116 -0
- HTPolyNet/resources/cfg/GMASTY-hi.yaml +158 -0
- HTPolyNet/resources/cfg/GMASTY-lo.yaml +158 -0
- HTPolyNet/resources/cfg/README.md +1 -0
- HTPolyNet/resources/cfg/STY.yaml +23 -0
- HTPolyNet/resources/cfg/pMSTY-hi.yaml +101 -0
- HTPolyNet/resources/cfg/pMSTY-lo.yaml +101 -0
- HTPolyNet/resources/cfg/pSTY-hi.yaml +101 -0
- HTPolyNet/resources/cfg/pSTY-lo.yaml +101 -0
- HTPolyNet/resources/example_depot/0-liquid-styrene.tgz +0 -0
- HTPolyNet/resources/example_depot/1-polystyrene.tgz +0 -0
- HTPolyNet/resources/example_depot/2-polymethylstyrene.tgz +0 -0
- HTPolyNet/resources/example_depot/3-bisgma-styrene-thermoset.tgz +0 -0
- HTPolyNet/resources/example_depot/4-pacm-dgeba-epoxy-thermoset.tgz +0 -0
- HTPolyNet/resources/example_depot/5-dfda-fde-epoxy-thermoset.tgz +0 -0
- HTPolyNet/resources/mdp/README.md +1 -0
- HTPolyNet/resources/mdp/drag-min.mdp +13 -0
- HTPolyNet/resources/mdp/drag-npt.mdp +36 -0
- HTPolyNet/resources/mdp/drag-nvt.mdp +31 -0
- HTPolyNet/resources/mdp/min.mdp +14 -0
- HTPolyNet/resources/mdp/npt.mdp +37 -0
- HTPolyNet/resources/mdp/nvt.mdp +29 -0
- HTPolyNet/resources/mdp/relax-min.mdp +13 -0
- HTPolyNet/resources/mdp/relax-npt.mdp +37 -0
- HTPolyNet/resources/mdp/relax-nvt.mdp +31 -0
- HTPolyNet/resources/mdp/single-molecule-min.mdp +12 -0
- HTPolyNet/resources/mdp/single-molecule-nvt.mdp +25 -0
- HTPolyNet/resources/molecules/inputs/DFA.pdb +62 -0
- HTPolyNet/resources/molecules/inputs/DGE.mol2 +115 -0
- HTPolyNet/resources/molecules/inputs/EMB.mol2 +50 -0
- HTPolyNet/resources/molecules/inputs/FDE.pdb +72 -0
- HTPolyNet/resources/molecules/inputs/GMA.mol2 +163 -0
- HTPolyNet/resources/molecules/inputs/PAC.mol2 +91 -0
- HTPolyNet/resources/molecules/inputs/STY.mol2 +44 -0
- HTPolyNet/resources/molecules/make-monomers.sh +64 -0
- HTPolyNet/resources/molecules/pics/DFA.png +0 -0
- HTPolyNet/resources/molecules/pics/DGE.png +0 -0
- HTPolyNet/resources/molecules/pics/EMB.png +0 -0
- HTPolyNet/resources/molecules/pics/FDE.png +0 -0
- HTPolyNet/resources/molecules/pics/GMA.png +0 -0
- HTPolyNet/resources/molecules/pics/PAC.png +0 -0
- HTPolyNet/resources/molecules/pics/STY.png +0 -0
- HTPolyNet/resources/molecules/sample-inputs/DFA.pdb +62 -0
- HTPolyNet/resources/molecules/sample-inputs/DGE.mol2 +115 -0
- HTPolyNet/resources/molecules/sample-inputs/EMB.mol2 +50 -0
- HTPolyNet/resources/molecules/sample-inputs/FDE.pdb +72 -0
- HTPolyNet/resources/molecules/sample-inputs/GMA.mol2 +163 -0
- HTPolyNet/resources/molecules/sample-inputs/PAC.mol2 +91 -0
- HTPolyNet/resources/molecules/sample-inputs/STY.mol2 +44 -0
- HTPolyNet/resources/tcl/readbonds.tcl +32 -0
- HTPolyNet/resources/tcl/readgrx.tcl +46 -0
- HTPolyNet/resources/tcl/render.tcl +74 -0
- HTPolyNet/ring.py +155 -0
- HTPolyNet/runtime.py +709 -0
- HTPolyNet/software.py +106 -0
- HTPolyNet/stringthings.py +39 -0
- HTPolyNet/topocoord.py +1877 -0
- HTPolyNet/topology.py +1288 -0
- HTPolyNet/unused_symmetry_stuff.py +291 -0
- HTPolyNet/utils.py +405 -0
- htpolynet-1.0.7.2.dist-info/METADATA +84 -0
- htpolynet-1.0.7.2.dist-info/RECORD +93 -0
- htpolynet-1.0.7.2.dist-info/WHEEL +4 -0
- htpolynet-1.0.7.2.dist-info/entry_points.txt +2 -0
- htpolynet-1.0.7.2.dist-info/licenses/LICENSE +21 -0
HTPolyNet/postsim.py
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
"""
|
|
2
|
+
|
|
3
|
+
.. module:: postsim
|
|
4
|
+
:synopsis: handles the postsim subcommand
|
|
5
|
+
|
|
6
|
+
.. moduleauthor: Cameron F. Abrams, <cfa22@drexel.edu>
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
import logging
|
|
10
|
+
import shutil
|
|
11
|
+
import numpy as np
|
|
12
|
+
import os
|
|
13
|
+
import json
|
|
14
|
+
import yaml
|
|
15
|
+
import HTPolyNet.projectfilesystem as pfs
|
|
16
|
+
from HTPolyNet.topocoord import TopoCoord
|
|
17
|
+
from HTPolyNet.gromacs import mdp_get, mdp_modify, gmx_energy_trace
|
|
18
|
+
import HTPolyNet.software as software
|
|
19
|
+
from HTPolyNet.configuration import Configuration
|
|
20
|
+
from HTPolyNet.plot import scatter
|
|
21
|
+
|
|
22
|
+
logger=logging.getLogger(__name__)
|
|
23
|
+
|
|
24
|
+
class PostSimMD:
|
|
25
|
+
""" Generic class for handling post-cure md simulations; this one just does simple NPT MD equilibration;
|
|
26
|
+
Classes that inherit from this class should define their own default_params and build_npt
|
|
27
|
+
"""
|
|
28
|
+
default_params={
|
|
29
|
+
'subdir': 'postsim/equilibrate',
|
|
30
|
+
'input_top': 'systems/final-results/final.top',
|
|
31
|
+
'input_gro': 'systems/final-results/final.gro',
|
|
32
|
+
'input_grx': 'systems/final-results/final.grx',
|
|
33
|
+
'gromacs' : {
|
|
34
|
+
'gmx': 'gmx',
|
|
35
|
+
'mdrun': 'gmx mdrun',
|
|
36
|
+
'options': '-quiet -nobackup',
|
|
37
|
+
'mdrun_single_molecule': 'gmx mdrun mdrun'
|
|
38
|
+
},
|
|
39
|
+
'ps': 1000,
|
|
40
|
+
'T': 300,
|
|
41
|
+
'P':1,
|
|
42
|
+
'output_deffnm': 'equilibrate',
|
|
43
|
+
'traces': ['Temperature','Density','Volume'],
|
|
44
|
+
'scatter': ('time(ps)',['Density'],'rho_v_ns.png')
|
|
45
|
+
}
|
|
46
|
+
def __init__(self,indict,strict=True):
|
|
47
|
+
self.params={}
|
|
48
|
+
for p,v in self.default_params.items():
|
|
49
|
+
self.params[p]=indict.get(p,v)
|
|
50
|
+
for p,v in indict.items():
|
|
51
|
+
if not p in self.default_params:
|
|
52
|
+
if strict:
|
|
53
|
+
logger.info(f'Ignoring directive \'{p}\' in yaml input file')
|
|
54
|
+
else:
|
|
55
|
+
self.params[p]=v
|
|
56
|
+
|
|
57
|
+
def do(self,mdp_pfx='npt',**gromacs_dict):
|
|
58
|
+
"""do handles executing the postsim MD simulation
|
|
59
|
+
|
|
60
|
+
:param mdp_pfx: filename prefix for output files, defaults to 'npt'
|
|
61
|
+
:type mdp_pfx: str, optional
|
|
62
|
+
"""
|
|
63
|
+
p=self.params
|
|
64
|
+
logger.info(f'do {p}')
|
|
65
|
+
# if a gromacs dict is passed in, assume this overrides the one read in from the file
|
|
66
|
+
if gromacs_dict:
|
|
67
|
+
software.set_gmx_preferences(gromacs_dict)
|
|
68
|
+
else:
|
|
69
|
+
software.set_gmx_preferences(p['gromacs'])
|
|
70
|
+
logger.info(f'going to {p["subdir"]}')
|
|
71
|
+
pfs.go_to(p['subdir'])
|
|
72
|
+
for input_file in ['input_top','input_gro','input_grx']:
|
|
73
|
+
srcnm=os.path.join(pfs.proj(),p[input_file])
|
|
74
|
+
shutil.copy(srcnm,'.')
|
|
75
|
+
local_top=os.path.basename(p['input_top'])
|
|
76
|
+
local_gro=os.path.basename(p['input_gro'])
|
|
77
|
+
local_grx=os.path.basename(p['input_grx'])
|
|
78
|
+
TC=TopoCoord(topfilename=local_top,grofilename=local_gro,grxfilename=local_grx)
|
|
79
|
+
logger.info(f'{TC.Coordinates.A.shape[0]} atoms {TC.total_mass(units="gromacs"):.2f} amu')
|
|
80
|
+
box=TC.Coordinates.box
|
|
81
|
+
pfs.checkout('mdp/npt.mdp')
|
|
82
|
+
os.rename('npt.mdp',f'{mdp_pfx}.mdp')
|
|
83
|
+
self.build_mdp(f'{mdp_pfx}.mdp',box=box)
|
|
84
|
+
msg=TC.grompp_and_mdrun(out=p['output_deffnm'],mdp=mdp_pfx,quiet=False,mylogger=logger.info,**gromacs_dict)
|
|
85
|
+
df=gmx_energy_trace(p['output_deffnm'],p['traces'])
|
|
86
|
+
use_scatter=p['scatter']
|
|
87
|
+
temp_x=None
|
|
88
|
+
temp_y=None
|
|
89
|
+
scat_file=use_scatter[2]
|
|
90
|
+
for sznm in ['Box-X','Box-Y','Box-Z']:
|
|
91
|
+
if sznm in p['traces']:
|
|
92
|
+
L0=box[0][0] if sznm=='Box-X' else box[1][1] if sznm=='Box-Y' else box[2][2]
|
|
93
|
+
temp_x=f'{sznm}-strain'
|
|
94
|
+
df[temp_x]=df[sznm]/L0-1.0
|
|
95
|
+
for sznm in ['Pres-XX','Pres-YY','Pres-ZZ']:
|
|
96
|
+
if sznm in p['traces']:
|
|
97
|
+
df[f'{sznm}-stress']=df[sznm]*(-1)
|
|
98
|
+
temp_y=[f'{sznm}-stress']
|
|
99
|
+
if temp_x and temp_y:
|
|
100
|
+
use_scatter=(temp_x,temp_y,scat_file)
|
|
101
|
+
df.to_csv(f'{p["output_deffnm"]}.csv',header=True,index=False)
|
|
102
|
+
scatter(df,*use_scatter)
|
|
103
|
+
logger.info(f'Final coordinates in {p["output_deffnm"]}.gro')
|
|
104
|
+
logger.info(f'Traces saved in {p["output_deffnm"]}.csv')
|
|
105
|
+
|
|
106
|
+
def build_mdp(self,mdpname,**kwargs):
|
|
107
|
+
"""build_mdp builds the GROMACS mdp file required for an NPT equilibration
|
|
108
|
+
|
|
109
|
+
:param mdpname: name of mdp file
|
|
110
|
+
:type mdpname: str
|
|
111
|
+
"""
|
|
112
|
+
params=self.params
|
|
113
|
+
timestep=float(mdp_get(mdpname,'dt'))
|
|
114
|
+
duration=params['ps']
|
|
115
|
+
nsteps=int(duration/timestep)
|
|
116
|
+
mod_dict={
|
|
117
|
+
'ref_t':params['T'],
|
|
118
|
+
'ref_p':params['P'],
|
|
119
|
+
'gen-temp':params['T'],
|
|
120
|
+
'gen-vel':'yes',
|
|
121
|
+
'nsteps':nsteps,
|
|
122
|
+
'tcoupl':'v-rescale','tau_t':0.5
|
|
123
|
+
}
|
|
124
|
+
mdp_modify(mdpname,mod_dict)
|
|
125
|
+
|
|
126
|
+
class PostSimAnneal(PostSimMD):
|
|
127
|
+
""" a class to handle temperature annealing MD simulation
|
|
128
|
+
"""
|
|
129
|
+
default_params={
|
|
130
|
+
'subdir':'postsim/anneal',
|
|
131
|
+
'input_top': 'systems/final-results/final.top',
|
|
132
|
+
'input_gro': 'systems/final-results/final.gro',
|
|
133
|
+
'input_grx': 'systems/final-results/final.grx',
|
|
134
|
+
'gromacs' : {
|
|
135
|
+
'gmx': 'gmx',
|
|
136
|
+
'mdrun': 'gmx mdrun',
|
|
137
|
+
'options': '-quiet -nobackup',
|
|
138
|
+
'mdrun_single_molecule': 'gmx mdrun'
|
|
139
|
+
},
|
|
140
|
+
'output_deffnm':'anneal',
|
|
141
|
+
'traces': ['Temperature','Density','Volume'],
|
|
142
|
+
'scatter': ('time(ps)',['Density'],'rho_v_ns.png'),
|
|
143
|
+
'T0': 300,
|
|
144
|
+
'T1': 600,
|
|
145
|
+
'ncycles': 1,
|
|
146
|
+
'T0_to_T1_ps': 1000,
|
|
147
|
+
'T1_ps': 1000,
|
|
148
|
+
'T1_to_T0_ps': 1000,
|
|
149
|
+
'T0_ps': 1000,
|
|
150
|
+
'P':1
|
|
151
|
+
}
|
|
152
|
+
def build_mdp(self,mdpname,**kwargs):
|
|
153
|
+
"""build_mdp builds the GROMACS mdp file required for an annealing MD simulation
|
|
154
|
+
|
|
155
|
+
:param mdpname: name of mdp file
|
|
156
|
+
:type mdpname: str
|
|
157
|
+
"""
|
|
158
|
+
params=self.params
|
|
159
|
+
timestep=float(mdp_get(mdpname,'dt'))
|
|
160
|
+
timeints=[0.0,params['T0_to_T1_ps'],params['T1_ps'],params['T1_to_T0_ps'],params['T0_ps']]
|
|
161
|
+
timepoints=[0.0]
|
|
162
|
+
temppoints=[params['T0'],params['T1'],params['T1'],params['T0'],params['T0']]
|
|
163
|
+
for i in range(1,len(timeints)):
|
|
164
|
+
timepoints.append(timepoints[-1]+timeints[i])
|
|
165
|
+
duration=timepoints[-1]
|
|
166
|
+
nsteps=int(duration/timestep)*params['ncycles']
|
|
167
|
+
mod_dict={
|
|
168
|
+
'ref_t':params['T0'],
|
|
169
|
+
'ref_p':params['P'],
|
|
170
|
+
'gen-temp':params['T0'],
|
|
171
|
+
'gen-vel':'yes',
|
|
172
|
+
'annealing-npoints':len(timepoints),
|
|
173
|
+
'annealing-temp':' '.join([str(x) for x in temppoints]),
|
|
174
|
+
'annealing-time':' '.join([str(x) for x in timepoints]),
|
|
175
|
+
'annealing':'periodic' if params['ncycles']>1 else 'single',
|
|
176
|
+
'nsteps':nsteps,
|
|
177
|
+
'tcoupl':'v-rescale','tau_t':0.5
|
|
178
|
+
}
|
|
179
|
+
mdp_modify(mdpname,mod_dict)
|
|
180
|
+
|
|
181
|
+
class PostSimLadder(PostSimMD):
|
|
182
|
+
""" a class to handle a temperature-ladder MD simulation
|
|
183
|
+
"""
|
|
184
|
+
default_params={
|
|
185
|
+
'subdir':'postsim/ladder',
|
|
186
|
+
'input_top': 'systems/final-results/final.top',
|
|
187
|
+
'input_gro': 'systems/final-results/final.gro',
|
|
188
|
+
'input_grx': 'systems/final-results/final.grx',
|
|
189
|
+
'gromacs' : {
|
|
190
|
+
'gmx': 'gmx',
|
|
191
|
+
'mdrun': 'gmx mdrun',
|
|
192
|
+
'options': '-quiet -nobackup',
|
|
193
|
+
'mdrun_single_molecule': 'gmx mdrun mdrun'
|
|
194
|
+
},
|
|
195
|
+
'output_deffnm':'ladder',
|
|
196
|
+
'traces': ['Temperature','Density','Volume'],
|
|
197
|
+
'scatter': ('time(ps)',['Density'],'rho_v_ns.png'),
|
|
198
|
+
'Tlo':300.0,
|
|
199
|
+
'Thi':600.0,
|
|
200
|
+
'deltaT':5,
|
|
201
|
+
'ps_per_run':1000,
|
|
202
|
+
'ps_per_rise':1000,
|
|
203
|
+
'warmup_ps':5000,
|
|
204
|
+
'P':1
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
def build_mdp(self,mdpname,**kwargs):
|
|
208
|
+
"""build_mdp builds the GROMACS mdp file required for a temperature-ladder MD simulation
|
|
209
|
+
|
|
210
|
+
:param mdpname: name of mdp file
|
|
211
|
+
:type mdpname: str
|
|
212
|
+
"""
|
|
213
|
+
params=self.params
|
|
214
|
+
timestep=float(mdp_get(mdpname,'dt'))
|
|
215
|
+
Tdomain=params['Thi']-params['Tlo']
|
|
216
|
+
nSteps=int(Tdomain/np.abs(params['deltaT']))+1
|
|
217
|
+
T0=params['Tlo'] if params['deltaT']>0.0 else params['Thi']
|
|
218
|
+
T1=params['Thi'] if params['deltaT']>0.0 else params['Tlo']
|
|
219
|
+
Tladder=np.linspace(T0,T1,nSteps)
|
|
220
|
+
timepoints=[0.0,params['warmup_ps']]
|
|
221
|
+
temppoints=[T0,T0]
|
|
222
|
+
for i in range(nSteps):
|
|
223
|
+
cT=Tladder[i]
|
|
224
|
+
timepoints.append(timepoints[-1]+params['ps_per_rise'])
|
|
225
|
+
temppoints.append(cT)
|
|
226
|
+
timepoints.append(timepoints[-1]+params['ps_per_run'])
|
|
227
|
+
temppoints.append(cT)
|
|
228
|
+
duration=timepoints[-1]
|
|
229
|
+
nMDsteps=int(duration/timestep)
|
|
230
|
+
mod_dict={
|
|
231
|
+
'ref_t':T0,
|
|
232
|
+
'ref_p':params['P'],
|
|
233
|
+
'gen-temp':T0,
|
|
234
|
+
'gen-vel':'yes',
|
|
235
|
+
'annealing-npoints':len(timepoints),
|
|
236
|
+
'annealing-temp':' '.join([str(x) for x in temppoints]),
|
|
237
|
+
'annealing-time':' '.join([str(x) for x in timepoints]),
|
|
238
|
+
'annealing':'single',
|
|
239
|
+
'nsteps':nMDsteps,
|
|
240
|
+
'tcoupl':'v-rescale','tau_t':0.5
|
|
241
|
+
}
|
|
242
|
+
mdp_modify(mdpname,mod_dict)
|
|
243
|
+
|
|
244
|
+
class PostSimDeform(PostSimMD):
|
|
245
|
+
""" a class to handle a uniaxial deformation MD simulation
|
|
246
|
+
"""
|
|
247
|
+
default_params={
|
|
248
|
+
'subdir':'postsim/deform-x',
|
|
249
|
+
'input_top': 'systems/final-results/final.top',
|
|
250
|
+
'input_gro': 'postsim/equilibrate/equilibrate.gro',
|
|
251
|
+
'input_grx': 'systems/final-results/final.grx',
|
|
252
|
+
'gromacs' : {
|
|
253
|
+
'gmx': 'gmx',
|
|
254
|
+
'mdrun': 'gmx mdrun',
|
|
255
|
+
'options': '-quiet -nobackup',
|
|
256
|
+
'mdrun_single_molecule': 'gmx mdrun mdrun'
|
|
257
|
+
},
|
|
258
|
+
'output_deffnm':'deform-x',
|
|
259
|
+
'traces': ['Box-X','Pres-XX'],
|
|
260
|
+
'scatter': ('Box-X',['Pres-XX'],'tension_v_xlength.png'),
|
|
261
|
+
'direction':'x',
|
|
262
|
+
'T':300.0,
|
|
263
|
+
'P':1.0,
|
|
264
|
+
'ps':1000,
|
|
265
|
+
'edot': 0.001 # strain rate in ps^-1
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
def build_mdp(self,mdpname,**kwargs):
|
|
269
|
+
"""build_mdp builds the GROMACS mdp file required for a temperature-ladder MD simulation
|
|
270
|
+
|
|
271
|
+
:param mdpname: name of mdp file
|
|
272
|
+
:type mdpname: str
|
|
273
|
+
"""
|
|
274
|
+
params=self.params
|
|
275
|
+
timestep=float(mdp_get(mdpname,'dt'))
|
|
276
|
+
duration=params['ps']
|
|
277
|
+
nsteps=int(duration/timestep)
|
|
278
|
+
box=kwargs.get('box',np.array([[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0]]))
|
|
279
|
+
edot=params.get('edot',0.0)
|
|
280
|
+
direction=params.get('direction','x')
|
|
281
|
+
mod_dict={
|
|
282
|
+
'ref_t':params['T'],
|
|
283
|
+
'ref_p':params['P'],
|
|
284
|
+
'gen-temp':params['T'],
|
|
285
|
+
'gen-vel':'yes',
|
|
286
|
+
'tcoupl':'v-rescale',
|
|
287
|
+
'nsteps': nsteps,
|
|
288
|
+
'rlist': 1.2,
|
|
289
|
+
'rcoulomb': 1.2,
|
|
290
|
+
'rvdw': 1.2,
|
|
291
|
+
'tau_t':0.5,
|
|
292
|
+
'tau_p':1.0,
|
|
293
|
+
'refcoord_scaling': 'com',
|
|
294
|
+
'pcoupltype': 'anisotropic'
|
|
295
|
+
}
|
|
296
|
+
if direction=='x':
|
|
297
|
+
strain_vel=box[0][0]*edot
|
|
298
|
+
mod_dict['ref_p']='0.0 1.0 1.0 0 0 0'
|
|
299
|
+
mod_dict['compressibility']='0.0 4.5e-5 4.5e-5 0 0 0'
|
|
300
|
+
mod_dict['deform']=f'{strain_vel:.3e} 0 0 0 0 0'
|
|
301
|
+
params['output_deffnm'] = 'deform-x'
|
|
302
|
+
params['traces']=['Box-X','Pres-XX']
|
|
303
|
+
params['scatter']=('Box-X',['Pres-XX'],'tension_v_xlength.png')
|
|
304
|
+
elif direction=='y':
|
|
305
|
+
strain_vel=box[1][1]*edot
|
|
306
|
+
mod_dict['ref_p']='1.0 0.0 1.0 0 0 0'
|
|
307
|
+
mod_dict['compressibility']='4.5e-5 0.0 4.5e-5 0 0 0'
|
|
308
|
+
mod_dict['deform']=f'0 {strain_vel:.3e} 0 0 0 0'
|
|
309
|
+
params['output_deffnm'] = 'deform-y'
|
|
310
|
+
params['traces']=['Box-Y','Pres-YY']
|
|
311
|
+
params['scatter']=('Box-Y',['Pres-YY'],'tension_v_ylength.png')
|
|
312
|
+
elif direction=='z':
|
|
313
|
+
strain_vel=box[2][2]*edot
|
|
314
|
+
mod_dict['ref_p']='1.0 1.0 0.0 0 0 0'
|
|
315
|
+
mod_dict['compressibility']='4.5e-5 4.5e-5 0.0 0 0 0'
|
|
316
|
+
mod_dict['deform']=f'0 0 {strain_vel:.3e} 0 0 0'
|
|
317
|
+
params['output_deffnm'] = 'deform-z'
|
|
318
|
+
params['traces']=['Box-Z','Pres-ZZ']
|
|
319
|
+
params['scatter']=('Box-Z',['Pres-ZZ'],'tension_v_zlength.png')
|
|
320
|
+
else:
|
|
321
|
+
logger.error(f'Bad direction for uniaxial strain {direction}')
|
|
322
|
+
|
|
323
|
+
mdp_modify(mdpname,mod_dict)
|
|
324
|
+
|
|
325
|
+
class PostsimConfiguration:
|
|
326
|
+
""" handles reading and parsing a postcure simulation input config file.
|
|
327
|
+
Config file format
|
|
328
|
+
|
|
329
|
+
- { key1: {<paramdict>}}
|
|
330
|
+
- { key2: {<paramdict>}}
|
|
331
|
+
|
|
332
|
+
...
|
|
333
|
+
|
|
334
|
+
The config file is a list of single-element dictionaries, whose single keyword
|
|
335
|
+
indicates the type of MD simulation to be run; simulations are run in the order
|
|
336
|
+
they appear in the config file.
|
|
337
|
+
|
|
338
|
+
Currently allowed simulation types:
|
|
339
|
+
|
|
340
|
+
- 'equilibrate': simple NPT equilibration;
|
|
341
|
+
- 'anneal': simple simulated annealing;
|
|
342
|
+
- 'ladder': temperature ladder;
|
|
343
|
+
- 'deform: constant strain-rate uniaxial deformation;
|
|
344
|
+
|
|
345
|
+
"""
|
|
346
|
+
default_classes={'equilibrate':PostSimMD,'anneal':PostSimAnneal,'ladder':PostSimLadder,'deform':PostSimDeform}
|
|
347
|
+
def __init__(self):
|
|
348
|
+
self.cfgFile=''
|
|
349
|
+
self.baselist=[]
|
|
350
|
+
self.stagelist=[]
|
|
351
|
+
|
|
352
|
+
@classmethod
|
|
353
|
+
def read(cls,filename,parse=True,**kwargs):
|
|
354
|
+
"""read generates a new PostsimConfiguration object by reading in the JSON or YAML file indicated by filename
|
|
355
|
+
|
|
356
|
+
:param filename: name of file from which to read new PostsimConfiguration object
|
|
357
|
+
:type filename: str
|
|
358
|
+
:param parse: if True, parse the input configuration file, defaults to True
|
|
359
|
+
:type parse: bool, optional
|
|
360
|
+
:raises Exception: if extension of filename is not '.json' or '.yaml' or '.yml'
|
|
361
|
+
:return: a new PostsimConfiguration object
|
|
362
|
+
:rtype: PostsimConfiguration
|
|
363
|
+
"""
|
|
364
|
+
basename,extension=os.path.splitext(filename)
|
|
365
|
+
if extension=='.json':
|
|
366
|
+
return cls._read_json(filename,parse,**kwargs)
|
|
367
|
+
elif extension=='.yaml' or extension=='.yml':
|
|
368
|
+
return cls._read_yaml(filename,parse,**kwargs)
|
|
369
|
+
else:
|
|
370
|
+
raise Exception(f'Unknown config file extension {extension}')
|
|
371
|
+
|
|
372
|
+
@classmethod
|
|
373
|
+
def _read_json(cls,filename,parse=True,**kwargs):
|
|
374
|
+
"""_read_json create a new PostsimConfiguration object by reading from JSON input
|
|
375
|
+
|
|
376
|
+
:param filename: name of JSON file
|
|
377
|
+
:type filename: str
|
|
378
|
+
:param parse: if True, parse the JSON data, defaults to True
|
|
379
|
+
:type parse: bool, optional
|
|
380
|
+
:return: a new PostsimConfiguration object
|
|
381
|
+
:rtype: PostsimConfiguration
|
|
382
|
+
"""
|
|
383
|
+
inst=cls()
|
|
384
|
+
inst.cfgFile=filename
|
|
385
|
+
with open(filename,'r') as f:
|
|
386
|
+
inst.baselist=json.load(f)
|
|
387
|
+
assert type(inst.baselist)==list,f'Poorly formatted {filename}'
|
|
388
|
+
if parse: inst.parse(**kwargs)
|
|
389
|
+
return inst
|
|
390
|
+
|
|
391
|
+
@classmethod
|
|
392
|
+
def _read_yaml(cls,filename,parse=True,**kwargs):
|
|
393
|
+
"""_read_yaml create a new PostsimConfiguration object by reading from YAML input
|
|
394
|
+
|
|
395
|
+
:param filename: name of YAML file
|
|
396
|
+
:type filename: str
|
|
397
|
+
:param parse: if True, parse the YAML data, defaults to True
|
|
398
|
+
:type parse: bool, optional
|
|
399
|
+
:return: a new PostsimConfiguration object
|
|
400
|
+
:rtype: PostsimConfiguration
|
|
401
|
+
"""
|
|
402
|
+
inst=cls()
|
|
403
|
+
inst.cfgFile=filename
|
|
404
|
+
with open(filename,'r') as f:
|
|
405
|
+
inst.baselist=yaml.safe_load(f)
|
|
406
|
+
assert type(inst.baselist)==list,f'Poorly formatted {filename}'
|
|
407
|
+
if parse: inst.parse(**kwargs)
|
|
408
|
+
return inst
|
|
409
|
+
|
|
410
|
+
def parse(self,**kwargs):
|
|
411
|
+
"""parse parses a PostsimConfiguration file to build the list of stages to run
|
|
412
|
+
"""
|
|
413
|
+
for p in self.baselist:
|
|
414
|
+
assert len(p)==1,f'Poorly formatted {self.cfgFile}; each stanza may have only one keyword'
|
|
415
|
+
simtype=list(p.keys())[0]
|
|
416
|
+
assert simtype in self.default_classes,f'Simulation type "{simtype}" in {self.cfgFile} not understood.'
|
|
417
|
+
logger.info(f'passing in {p[simtype]}')
|
|
418
|
+
self.stagelist.append(self.default_classes[simtype](p[simtype]))
|
|
419
|
+
|
|
420
|
+
def postsim(args):
|
|
421
|
+
"""postsim handles the postsim subcommand for managing post-cure production MD simulations
|
|
422
|
+
|
|
423
|
+
:param args: command-line arguments
|
|
424
|
+
:type args: argparse.Namespace
|
|
425
|
+
"""
|
|
426
|
+
loglevel_numeric=getattr(logging, args.loglevel.upper())
|
|
427
|
+
logging.basicConfig(format='%(levelname)s> %(message)s',level=loglevel_numeric)
|
|
428
|
+
ess='y' if len(args.proj)==0 else 'ies'
|
|
429
|
+
ogromacs={}
|
|
430
|
+
if args.ocfg:
|
|
431
|
+
ocfg=Configuration.read(args.ocfg,parse=False)
|
|
432
|
+
ogromacs=ocfg.basedict.get('gromacs',{})
|
|
433
|
+
cfg=PostsimConfiguration.read(args.cfg)
|
|
434
|
+
logger.debug(f'{cfg.baselist}')
|
|
435
|
+
logger.info(f'Project director{ess}: {args.proj}')
|
|
436
|
+
software.sw_setup()
|
|
437
|
+
logger.debug(f'ogromacs {ogromacs}')
|
|
438
|
+
for d in args.proj:
|
|
439
|
+
pfs.pfs_setup(root=os.getcwd(),topdirs=['molecules','systems','plots','postsim'],verbose=True,projdir=d,reProject=False,userlibrary=args.lib)
|
|
440
|
+
pfs.go_to('postsim')
|
|
441
|
+
for stage in cfg.stagelist:
|
|
442
|
+
stage.do(mdp_pfx='local',**ogromacs)
|
|
443
|
+
pfs.go_root()
|
|
444
|
+
|