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/gromacs.py
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
"""
|
|
2
|
+
|
|
3
|
+
.. module:: gromacs
|
|
4
|
+
:synopsis: methods for handling the gmx suite of executables
|
|
5
|
+
|
|
6
|
+
.. moduleauthor: Cameron F. Abrams, <cfa22@drexel.edu>
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
import logging
|
|
10
|
+
import os
|
|
11
|
+
import pandas as pd
|
|
12
|
+
import numpy as np
|
|
13
|
+
from itertools import product
|
|
14
|
+
from collections import namedtuple
|
|
15
|
+
from HTPolyNet.command import Command
|
|
16
|
+
import HTPolyNet.software as sw
|
|
17
|
+
logger=logging.getLogger(__name__)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def insert_molecules(composition,boxSize,outName,inputs_dir='.',**kwargs):
|
|
21
|
+
"""insert_molecules launcher for gmx insert-molecules
|
|
22
|
+
|
|
23
|
+
:param composition: dictionary of molecule_name:count
|
|
24
|
+
:type composition: dict
|
|
25
|
+
:param boxSize: size of box as 3 floats or 1 float (if cubic box)
|
|
26
|
+
:type boxSize: list(3,float) or float
|
|
27
|
+
:param outName: basename of output files
|
|
28
|
+
:type outName: str
|
|
29
|
+
:param inputs_dir: directory to search for input structures, defaults to '.'
|
|
30
|
+
:type inputs_dir: str, optional
|
|
31
|
+
:raises Exception: if gmx-insert molecules fails to insert the requested number of molecules
|
|
32
|
+
"""
|
|
33
|
+
if type(boxSize)==int:
|
|
34
|
+
boxSize=float(boxSize)
|
|
35
|
+
if type(boxSize)==float:
|
|
36
|
+
boxSize=[boxSize]*3
|
|
37
|
+
box=' '.join([f'{x:.8f}' for x in boxSize])
|
|
38
|
+
scale=kwargs.get('scale',0.4) # our default vdw radius scaling
|
|
39
|
+
for name,num in composition.items(): # composition determines order
|
|
40
|
+
ci=os.path.join(inputs_dir,f'{name}.gro')
|
|
41
|
+
if os.path.isfile(f'{outName}.gro'):
|
|
42
|
+
logger.debug(f'gmx insert-molecules inserts into existing {outName}.gro')
|
|
43
|
+
''' final gro file exists; we must insert into it '''
|
|
44
|
+
c=Command(f'{sw.gmx} {sw.gmx_options} insert-molecules',f=f'{outName}.gro',ci=ci,nmol=num,o=outName,box=box,scale=scale)
|
|
45
|
+
else:
|
|
46
|
+
''' no final gro file yet; make it '''
|
|
47
|
+
c=Command(f'{sw.gmx} {sw.gmx_options} insert-molecules',ci=ci,nmol=num,o=outName,box=box,scale=scale)
|
|
48
|
+
out,err=c.run()
|
|
49
|
+
out+=err
|
|
50
|
+
# logger.debug(f'Output of "{sw.gmx} insert-molecules"')
|
|
51
|
+
# for ln in out.split('\n'):
|
|
52
|
+
# logger.debug(ln)
|
|
53
|
+
if 'Added' in out:
|
|
54
|
+
outlines=out.split('\n')
|
|
55
|
+
for ol in outlines:
|
|
56
|
+
if 'Added' in ol:
|
|
57
|
+
tokens=ol.split()
|
|
58
|
+
numadded=int(tokens[1])
|
|
59
|
+
break
|
|
60
|
+
if numadded!=num:
|
|
61
|
+
msg=f'{sw.gmx} insert-molecules did not add enough {name}.\nOnly {numadded} out of {num} were placed.\nIncrease your initial boxsize or lower your initial density.'
|
|
62
|
+
for l in msg.split('\n'):
|
|
63
|
+
logger.debug(l)
|
|
64
|
+
raise Exception('need bigger box')
|
|
65
|
+
|
|
66
|
+
def grompp_and_mdrun(gro='',top='',out='',mdp='',boxSize=[],single_molecule=False,**kwargs):
|
|
67
|
+
"""grompp_and_mdrun launcher for grompp and mdrun
|
|
68
|
+
|
|
69
|
+
:param gro: input gro file, defaults to ''
|
|
70
|
+
:type gro: str, optional
|
|
71
|
+
:param top: input top file, defaults to ''
|
|
72
|
+
:type top: str, optional
|
|
73
|
+
:param out: output file basename, defaults to ''
|
|
74
|
+
:type out: str, optional
|
|
75
|
+
:param mdp: input mdp file, defaults to ''
|
|
76
|
+
:type mdp: str, optional
|
|
77
|
+
:param boxSize: explicit box size, defaults to []
|
|
78
|
+
:type boxSize: list, optional
|
|
79
|
+
:param single_molecule: if true, a single-molecule system is simulated, defaults to False
|
|
80
|
+
:type single_molecule: bool, optional
|
|
81
|
+
"""
|
|
82
|
+
logger.debug(kwargs)
|
|
83
|
+
quiet=kwargs.get('quiet',True)
|
|
84
|
+
ignore_codes=kwargs.get('ignore_codes',[-11])
|
|
85
|
+
maxwarn=kwargs.get('maxwarn',4)
|
|
86
|
+
mdrun_options=kwargs.get('mdrun_options',{})
|
|
87
|
+
for option in ['rdd','dds','dlb','npme','nt','ntpmi','ntomp','ntomp_pme','nb','tunepme','pme','pmefft','bonded','update']:
|
|
88
|
+
if option in kwargs and not option in mdrun_options:
|
|
89
|
+
mdrun_options[option]=kwargs[option]
|
|
90
|
+
|
|
91
|
+
#tunepme=kwargs.get('tunepme','yes')
|
|
92
|
+
if gro=='' or top=='' or out=='' or mdp=='':
|
|
93
|
+
raise Exception('grompp_and_mdrun requires gro, top, out, and mdp filename prefixes.')
|
|
94
|
+
infiles=[f'{gro}.gro',f'{top}.top',f'{mdp}.mdp']
|
|
95
|
+
assert all([os.path.exists(x) for x in infiles])
|
|
96
|
+
if len(boxSize)>0:
|
|
97
|
+
logger.debug(f'Resizing to {boxSize}')
|
|
98
|
+
c=Command(f'{sw.gmx} {sw.gmx_options} editconf',f=f'{gro}.gro',o=gro,
|
|
99
|
+
box=' '.join([f'{x:.8f}' for x in boxSize]))
|
|
100
|
+
c.run(quiet=quiet)
|
|
101
|
+
# nsteps=kwargs.get('nsteps',-2)
|
|
102
|
+
c=Command(f'{sw.gmx} {sw.gmx_options} grompp',f=f'{mdp}.mdp',c=f'{gro}.gro',p=f'{top}.top',o=f'{out}.tpr',maxwarn=maxwarn)
|
|
103
|
+
c.run(quiet=quiet)
|
|
104
|
+
if single_molecule:
|
|
105
|
+
c=Command(f'{sw.mdrun_single_molecule}',deffnm=out,**mdrun_options)
|
|
106
|
+
else:
|
|
107
|
+
c=Command(f'{sw.mdrun}',deffnm=out,**mdrun_options)
|
|
108
|
+
c.run(quiet=quiet,ignore_codes=ignore_codes)
|
|
109
|
+
if os.path.exists(f'{out}.gro'):
|
|
110
|
+
pass
|
|
111
|
+
# logger.info(f'grompp_and_mdrun completed. Check {gro}.gro.')
|
|
112
|
+
else:
|
|
113
|
+
logger.error(f'{sw.mdrun} ended prematurely; {out}.gro not found.')
|
|
114
|
+
raise Exception(f'{sw.mdrun} ended prematurely; {out}.gro not found.')
|
|
115
|
+
|
|
116
|
+
def get_energy_menu(edr,**kwargs):
|
|
117
|
+
"""get_energy_menu gets the menu provided by 'gmx energy' when applied to a particular edr file
|
|
118
|
+
|
|
119
|
+
:param edr: name of edr file
|
|
120
|
+
:type edr: str
|
|
121
|
+
:return: menu dictionary
|
|
122
|
+
:rtype: dict
|
|
123
|
+
"""
|
|
124
|
+
assert os.path.exists(edr+'.edr'),f'Error: {edr} not found'
|
|
125
|
+
with open('_menugetter_','w') as f:
|
|
126
|
+
f.write('\n')
|
|
127
|
+
c=Command(f'{sw.gmx} {sw.gmx_options} energy -f {edr}.edr -o {edr}-out.xvg -xvg none < _menugetter_ > _menu_ 2>&1')
|
|
128
|
+
c.run(ignore_codes=[1,2])
|
|
129
|
+
with open('_menu_','r') as f:
|
|
130
|
+
lines=f.read().split('\n')
|
|
131
|
+
topline=lines.index('End your selection with an empty line or a zero.')
|
|
132
|
+
botline=topline
|
|
133
|
+
while len(lines[botline])>0:
|
|
134
|
+
botline+=1
|
|
135
|
+
menulines=lines[topline+2:botline]
|
|
136
|
+
m=''.join(menulines)
|
|
137
|
+
n=' '.join(m.split()).split()
|
|
138
|
+
num,label=n[::2],n[1::2]
|
|
139
|
+
menu={l:n for l,n in zip(label,num)}
|
|
140
|
+
os.remove('_menu_')
|
|
141
|
+
os.remove('_menugetter_')
|
|
142
|
+
return menu
|
|
143
|
+
|
|
144
|
+
def gmx_energy_trace(edr,names=[],report_averages=False,keep_files=False,**kwargs):
|
|
145
|
+
"""Generate traces of data in edr file
|
|
146
|
+
|
|
147
|
+
:param edr: name of edr file
|
|
148
|
+
:type edr: str
|
|
149
|
+
:param names: list of data names, defaults to []
|
|
150
|
+
:type names: list
|
|
151
|
+
:param report_averages: flag to indicate if averages of all data are to be computed here, default False
|
|
152
|
+
:type report_averages: bool, optional
|
|
153
|
+
:param keep_files: flag indicating caller would like to keep the raw input and output files for gmx energy, default False
|
|
154
|
+
:type keep_files: bool
|
|
155
|
+
:return: dataframe of traces
|
|
156
|
+
:rtype: pandas DataFrame
|
|
157
|
+
"""
|
|
158
|
+
assert os.path.exists(edr+'.edr'),f'Error: {edr}.edr not found'
|
|
159
|
+
assert len(names)>0,f'Nothing to plot'
|
|
160
|
+
xshift=kwargs.get('xshift',0)
|
|
161
|
+
menu=get_energy_menu(edr)
|
|
162
|
+
if not any([i in menu for i in names]):
|
|
163
|
+
logger.debug(f'None of {names} in menu {menu}')
|
|
164
|
+
return pd.DataFrame()
|
|
165
|
+
logger.debug(f'report_averages? {report_averages} {names}')
|
|
166
|
+
namvals=[]
|
|
167
|
+
with open(f'{edr}-gmx.in','w') as f:
|
|
168
|
+
for i in names:
|
|
169
|
+
if i in menu:
|
|
170
|
+
f.write(f'{menu[i]}\n')
|
|
171
|
+
namvals.append((i,int(menu[i])))
|
|
172
|
+
f.write('\n')
|
|
173
|
+
namvals.sort(key=lambda x: x[1])
|
|
174
|
+
c=Command(f'{sw.gmx} {sw.gmx_options} energy -f {edr}.edr -o {edr}-out.xvg -xvg none < {edr}-gmx.in')
|
|
175
|
+
c.run()
|
|
176
|
+
colnames=[x[0] for x in namvals]
|
|
177
|
+
colnames.insert(0,'time(ps)')
|
|
178
|
+
data=pd.read_csv(f'{edr}-out.xvg',sep='\s+',header=None,names=colnames)
|
|
179
|
+
data.iloc[:,0]+=xshift
|
|
180
|
+
ndata=data.shape[0]
|
|
181
|
+
if report_averages:
|
|
182
|
+
for i in names:
|
|
183
|
+
data[f'Running-average-{i}']=data[i].expanding(1).mean()
|
|
184
|
+
data[f'Rolling-10-average-{i}']=data[i].rolling(window=ndata//10).mean()
|
|
185
|
+
for ln in data.iloc[-1][[i,f'Running-average-{i}',f'Rolling-10-average-{i}']].to_string(float_format='{:.2f}'.format).split('\n'):
|
|
186
|
+
logger.info(f'{ln}')
|
|
187
|
+
if not keep_files:
|
|
188
|
+
os.remove(f'{edr}-out.xvg')
|
|
189
|
+
os.remove(f'{edr}-gmx.in')
|
|
190
|
+
return data
|
|
191
|
+
|
|
192
|
+
# make a bunch of 3-character filename prefixes so parallel invocations don't collide
|
|
193
|
+
_abc='abcdefghijklmnopqrstuwxyz'
|
|
194
|
+
_fnames=[''.join(i) for i in product(_abc,_abc,_abc)]
|
|
195
|
+
def gromacs_distance(idf,gro,new_column_name='r',pfx='tmp',force_recalculate=False,keep_files=False):
|
|
196
|
+
"""Use 'gmx distance' to measure interatomic distances
|
|
197
|
+
|
|
198
|
+
:param idf: dataframe of atom indexes in pairs ['ai','aj']
|
|
199
|
+
:type idf: pandas DataFrame
|
|
200
|
+
:param gro: name of gromacs input file for 'gmx distance' to use
|
|
201
|
+
:type gro: str
|
|
202
|
+
:param new_column_name: name of column in idf where distances are stored, default 'r'
|
|
203
|
+
:type new_column_name: str, optional
|
|
204
|
+
:param force_recalculate: flag to force calculation of distances even if a distance column exists in idf, default False
|
|
205
|
+
:type force_recalculate: boolean, optional
|
|
206
|
+
:param keep_files: flag indicating caller would like to keep the raw input and output files for gmx energy default False
|
|
207
|
+
:type keep_files: bool, optional
|
|
208
|
+
:return: list of distances parallel to idf columns
|
|
209
|
+
:rtype: numpy.ndarray
|
|
210
|
+
"""
|
|
211
|
+
if type(idf)==tuple: # this is being called in parallel
|
|
212
|
+
i,idf=idf # unpack index and actual data frame
|
|
213
|
+
pfx=_fnames[i]
|
|
214
|
+
logger.debug(f'packet {i} using fname {pfx}; dataframe size {idf.shape[0]}')
|
|
215
|
+
npair=idf.shape[0]
|
|
216
|
+
# logger.debug(f'idf dtype {idf["ai"].dtype}')
|
|
217
|
+
if npair==0 or ('r' in idf and not force_recalculate):
|
|
218
|
+
return idf
|
|
219
|
+
''' create the index file '''
|
|
220
|
+
with open(f'{pfx}.ndx','w') as f:
|
|
221
|
+
f.write('[ bonds-1 ]\n')
|
|
222
|
+
idf[['ai','aj']].to_csv(f,sep=' ',header=False,index=False)
|
|
223
|
+
# logger.debug('wrote tmp.ndx')
|
|
224
|
+
''' create the user-input file '''
|
|
225
|
+
with open (f'{pfx}.in','w') as f:
|
|
226
|
+
f.write('0\n\n')
|
|
227
|
+
c=Command(f'{sw.gmx} {sw.gmx_options} distance -f {gro} -n {pfx}.ndx -oall {pfx}.xvg -xvg none < {pfx}.in')
|
|
228
|
+
c.run()
|
|
229
|
+
''' read the xvg file that 'gmx distance' creates '''
|
|
230
|
+
with open (f'{pfx}.xvg','r') as f:
|
|
231
|
+
datastr=f.read().split()
|
|
232
|
+
datastr=datastr[1:]
|
|
233
|
+
# logger.debug(f'0 {datastr[0]} - {len(datastr)-1} {datastr[-1]}')
|
|
234
|
+
data=np.array([float(x) for x in datastr])
|
|
235
|
+
nd=len(data)
|
|
236
|
+
''' clean up '''
|
|
237
|
+
os.remove(f'{pfx}.ndx')
|
|
238
|
+
os.remove(f'{pfx}.in')
|
|
239
|
+
os.remove(f'{pfx}.xvg')
|
|
240
|
+
''' add the lengths back to the input dataframe '''
|
|
241
|
+
idf[new_column_name]=data
|
|
242
|
+
assert npair==nd
|
|
243
|
+
return idf
|
|
244
|
+
|
|
245
|
+
def mdp_to_dict(mdp_filename):
|
|
246
|
+
with open(mdp_filename,'r') as f:
|
|
247
|
+
lines=f.read().split('\n')
|
|
248
|
+
all_dict={}
|
|
249
|
+
for l in lines:
|
|
250
|
+
if len(l)>0:
|
|
251
|
+
if '=' in l:
|
|
252
|
+
k,v=l.split('=')
|
|
253
|
+
k=k.strip()
|
|
254
|
+
v=v.strip()
|
|
255
|
+
all_dict[k]=v
|
|
256
|
+
else:
|
|
257
|
+
logger.debug(f'line {l} in {mdp_filename} skipped')
|
|
258
|
+
return all_dict
|
|
259
|
+
|
|
260
|
+
def mdp_get(mdp_filename,key):
|
|
261
|
+
all_dict=mdp_to_dict(mdp_filename)
|
|
262
|
+
return all_dict.get(key,'NOT FOUND!')
|
|
263
|
+
|
|
264
|
+
def mdp_modify(mdp_filename,opt_dict,new_filename=None,add_if_missing=True):
|
|
265
|
+
"""Modify a gromacs mdp file
|
|
266
|
+
|
|
267
|
+
:param mdp_filename: name of mdp file to modify; overwritten if new_filename==None
|
|
268
|
+
:type mdp_filename: str
|
|
269
|
+
:param opt_dict: keyword:value dictionary of mdp options
|
|
270
|
+
:type opt_dict: dict
|
|
271
|
+
:param new_filename: name of outputile, defaults to None
|
|
272
|
+
:type new_filename: str, optional
|
|
273
|
+
:param add_if_missing: Flag indicating whether to insert key:value into mdp file if not already there, defaults to True
|
|
274
|
+
:type add_if_missing: bool, optional
|
|
275
|
+
"""
|
|
276
|
+
all_dict=mdp_to_dict(mdp_filename)
|
|
277
|
+
# logger.debug(f'mdp_modify: all_dict: {all_dict}')
|
|
278
|
+
for k,v in opt_dict.items():
|
|
279
|
+
if not k in all_dict:
|
|
280
|
+
if add_if_missing:
|
|
281
|
+
logger.debug(f'adding {k} = {v} to {mdp_filename}')
|
|
282
|
+
all_dict[k]=v
|
|
283
|
+
else:
|
|
284
|
+
all_dict[k]=v
|
|
285
|
+
if new_filename:
|
|
286
|
+
with open(new_filename,'w') as f:
|
|
287
|
+
for k,v in all_dict.items():
|
|
288
|
+
f.write(f'{k} = {v}\n')
|
|
289
|
+
# logger.debug(f'wrote {new_filename}.')
|
|
290
|
+
else:
|
|
291
|
+
with open(mdp_filename,'w') as f:
|
|
292
|
+
for k,v in all_dict.items():
|
|
293
|
+
f.write(f'{k} = {v}\n')
|
|
294
|
+
# logger.debug(f'wrote {mdp_filename}.')
|
|
295
|
+
|
|
296
|
+
def gmx_traj_info(trr):
|
|
297
|
+
Result=namedtuple('gmx_check','nframes time')
|
|
298
|
+
c=Command(f'{sw.gmx} {sw.gmx_options} check -f {trr}')
|
|
299
|
+
out,err=c.run()
|
|
300
|
+
out+=err
|
|
301
|
+
for l in out.split('\n'):
|
|
302
|
+
tok=l.split()
|
|
303
|
+
if len(tok)==0:
|
|
304
|
+
continue
|
|
305
|
+
if tok[0]=='Step':
|
|
306
|
+
# print(tok)
|
|
307
|
+
nframes=int(tok[1])
|
|
308
|
+
ts_ps=float(tok[2])
|
|
309
|
+
break
|
|
310
|
+
result=Result(nframes,(nframes-1)*ts_ps)
|
|
311
|
+
return result
|
|
312
|
+
|
|
313
|
+
def gmx_command(name,options={},console_in=''):
|
|
314
|
+
optstring=''
|
|
315
|
+
for a,v in options.items():
|
|
316
|
+
optstring+=f'-{a} {v} '
|
|
317
|
+
cmdstr=f'{sw.gmx} {sw.gmx_options} {name} {optstring}'
|
|
318
|
+
if console_in:
|
|
319
|
+
cmdstr+=f' < {console_in}'
|
|
320
|
+
c=Command(cmdstr)
|
|
321
|
+
out,err=c.run()
|
|
322
|
+
out+=err
|
|
323
|
+
return out
|
|
324
|
+
|
|
325
|
+
def gro_from_trr(pfx,nzero=2,b=0,outpfx=''):
|
|
326
|
+
if not outpfx:
|
|
327
|
+
outpfx=pfx
|
|
328
|
+
with open('tmp.in','w') as f:
|
|
329
|
+
f.write('0\n')
|
|
330
|
+
c=Command(f'{sw.gmx} {sw.gmx_options} trjconv -f {pfx}.trr -s {pfx}.tpr -o {outpfx}.gro -sep -nzero {nzero} -b {b} < tmp.in')
|
|
331
|
+
out,err=c.run()
|
|
332
|
+
os.remove('tmp.in')
|
|
333
|
+
out+=err
|
HTPolyNet/inputcheck.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""
|
|
2
|
+
|
|
3
|
+
.. module:: inputcheck
|
|
4
|
+
:synopsis: manages the inputcheck subcommand
|
|
5
|
+
|
|
6
|
+
.. moduleauthor: Cameron F. Abrams, <cfa22@drexel.edu>
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
from HTPolyNet.topocoord import TopoCoord
|
|
10
|
+
from HTPolyNet.configuration import Configuration
|
|
11
|
+
from HTPolyNet.coordinates import Coordinates
|
|
12
|
+
from HTPolyNet.command import Command
|
|
13
|
+
import os
|
|
14
|
+
|
|
15
|
+
def input_check(args):
|
|
16
|
+
"""input_check manages in the input-check subcommand
|
|
17
|
+
|
|
18
|
+
:param args: parsed arguments
|
|
19
|
+
:type args: argparse.Namespace
|
|
20
|
+
"""
|
|
21
|
+
lib='./lib/molecules'
|
|
22
|
+
C=Configuration.read(args.config,plot_reaction_network=False)
|
|
23
|
+
icdict={x['molecule']:x['count'] for x in C.initial_composition}
|
|
24
|
+
natoms=0
|
|
25
|
+
tmass=0.0
|
|
26
|
+
mmass={}
|
|
27
|
+
for mname,M in C.molecules.items():
|
|
28
|
+
matoms=0
|
|
29
|
+
mmass[mname]=0.0
|
|
30
|
+
if os.path.exists(os.path.join(lib,'parameterized',f'{mname}.top')):
|
|
31
|
+
M.TopoCoord=TopoCoord(grofilename=os.path.join(lib,'parameterized',f'{mname}.gro'),topfilename=os.path.join(lib,'parameterized',f'{mname}.top'))
|
|
32
|
+
matoms=M.TopoCoord.Coordinates.A.shape[0]
|
|
33
|
+
mmass[mname]=M.TopoCoord.Topology.total_mass()
|
|
34
|
+
elif os.path.exists(os.path.join(lib,'inputs',f'{mname}.mol2')):
|
|
35
|
+
c=Coordinates.read_mol2(os.path.join(lib,'inputs',f'{mname}.mol2'))
|
|
36
|
+
matoms=c.A.shape[0]
|
|
37
|
+
elif os.path.exists(os.path.join(lib,'inputs',f'{mname}.pdb')):
|
|
38
|
+
# print(os.path.join(lib,f"{mname}.{fmt}"))
|
|
39
|
+
out,err=Command(f'grep -c ^ATOM {os.path.join(lib,"inputs",f"{mname}.pdb")}').run(ignore_codes=[1])
|
|
40
|
+
matoms=int(out)
|
|
41
|
+
out,err=Command(f'grep -c ^HETATM {os.path.join(lib,"inputs",f"{mname}.pdb")}').run(ignore_codes=[1])
|
|
42
|
+
matoms+=int(out)
|
|
43
|
+
if matoms>0 and mname in icdict:
|
|
44
|
+
natoms+=icdict[mname]*matoms
|
|
45
|
+
tmass+=icdict[mname]*mmass[mname]
|
|
46
|
+
print(f'Molecule {mname}: {matoms} atoms, {icdict[mname]} molecules')
|
|
47
|
+
print(f'{args.config}: {natoms} atoms in initial system.')
|
|
48
|
+
if tmass>0.0:
|
|
49
|
+
for mname in icdict:
|
|
50
|
+
wtpct=100.0*icdict[mname]*mmass[mname]/tmass
|
|
51
|
+
print(f'Molecule {mname}: {wtpct:0.2f} wt-%')
|