HTPolyNet 2.0.0__py3-none-any.whl → 2.1.0__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/cli.py +29 -219
- htpolynet/core/bondtemplate.py +67 -0
- htpolynet/core/configuration.py +2 -0
- htpolynet/core/molecule.py +27 -10
- htpolynet/core/projectfilesystem.py +22 -7
- htpolynet/core/runtime.py +231 -34
- htpolynet/core/topocoord.py +60 -73
- htpolynet/core/topology.py +74 -3
- htpolynet/cure/chain.py +18 -6
- htpolynet/cure/curecontroller.py +16 -14
- htpolynet/cure/expandreactions.py +1 -1
- htpolynet/cure/reaction.py +1 -0
- htpolynet/external/ambertools.py +6 -1
- htpolynet/external/command.py +5 -0
- htpolynet/external/smiles_input.py +259 -0
- htpolynet/external/software.py +37 -4
- htpolynet/profiling.py +218 -0
- htpolynet/repair/__init__.py +39 -0
- htpolynet/repair/cyanate_cap.py +409 -0
- htpolynet/repair/topology_surgery.py +256 -0
- htpolynet/resources/example_depot/0-liquid-styrene.yaml +81 -0
- htpolynet/resources/example_depot/{1-polystyrene.sh → 1-polystyrene.yaml} +14 -49
- htpolynet/resources/example_depot/{2-bisgma-styrene-thermoset.sh → 2-bisgma-styrene-thermoset.yaml} +23 -76
- htpolynet/resources/example_depot/{3-pacm-dgeba-epoxy-thermoset.sh → 3-pacm-dgeba-epoxy-thermoset.yaml} +17 -67
- htpolynet/resources/example_depot/4-dfda-fde-epoxy-thermoset.yaml +191 -0
- htpolynet/resources/example_depot/5-htpb-ipdi.yaml +363 -0
- htpolynet/resources/example_depot/6-cyanate-ester.yaml +238 -0
- htpolynet/utils/inputcheck.py +2 -0
- htpolynet/utils/vmd_viz.py +288 -0
- {htpolynet-2.0.0.dist-info → htpolynet-2.1.0.dist-info}/METADATA +21 -1
- {htpolynet-2.0.0.dist-info → htpolynet-2.1.0.dist-info}/RECORD +34 -43
- htpolynet/resources/cfg/DGE-PAC-hi.yaml +0 -115
- htpolynet/resources/cfg/DGE-PAC-lo.yaml +0 -115
- htpolynet/resources/cfg/FDE-DFDA-hi.yaml +0 -116
- htpolynet/resources/cfg/FDE-DFDA-lo.yaml +0 -116
- htpolynet/resources/cfg/GMASTY-hi.yaml +0 -158
- htpolynet/resources/cfg/GMASTY-lo.yaml +0 -158
- htpolynet/resources/cfg/README.md +0 -1
- htpolynet/resources/cfg/STY.yaml +0 -23
- htpolynet/resources/cfg/pMSTY-hi.yaml +0 -101
- htpolynet/resources/cfg/pMSTY-lo.yaml +0 -101
- htpolynet/resources/cfg/pSTY-hi.yaml +0 -101
- htpolynet/resources/cfg/pSTY-lo.yaml +0 -101
- htpolynet/resources/example_depot/0-liquid-styrene.sh +0 -134
- htpolynet/resources/example_depot/0-liquid-styrene.tgz +0 -0
- htpolynet/resources/example_depot/1-polystyrene.tgz +0 -0
- htpolynet/resources/example_depot/2-bisgma-styrene-thermoset.tgz +0 -0
- htpolynet/resources/example_depot/3-pacm-dgeba-epoxy-thermoset.tgz +0 -0
- htpolynet/resources/example_depot/4-dfda-fde-epoxy-thermoset.sh +0 -216
- htpolynet/resources/example_depot/4-dfda-fde-epoxy-thermoset.tgz +0 -0
- {htpolynet-2.0.0.dist-info → htpolynet-2.1.0.dist-info}/WHEEL +0 -0
- {htpolynet-2.0.0.dist-info → htpolynet-2.1.0.dist-info}/entry_points.txt +0 -0
- {htpolynet-2.0.0.dist-info → htpolynet-2.1.0.dist-info}/licenses/LICENSE +0 -0
htpolynet/cli.py
CHANGED
|
@@ -3,18 +3,13 @@
|
|
|
3
3
|
Author: Cameron F. Abrams <cfa22@drexel.edu>
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
|
-
import glob
|
|
7
|
-
import json
|
|
8
6
|
import logging
|
|
9
7
|
import os
|
|
10
|
-
import tarfile
|
|
11
8
|
import textwrap
|
|
12
9
|
|
|
13
10
|
import argparse as ap
|
|
14
11
|
import yaml
|
|
15
12
|
|
|
16
|
-
from importlib.metadata import distribution
|
|
17
|
-
|
|
18
13
|
from .analysis.analyze import analyze
|
|
19
14
|
from .analysis.plot import plots
|
|
20
15
|
from .analysis.postsim import postsim
|
|
@@ -26,21 +21,11 @@ from .utils.banner import banner_message
|
|
|
26
21
|
from .utils.inputcheck import input_check
|
|
27
22
|
from .utils.logsetup import setup_logging
|
|
28
23
|
from .utils.stringthings import my_logger
|
|
24
|
+
from .utils.vmd_viz import make_viz
|
|
29
25
|
|
|
30
26
|
logger = logging.getLogger(__name__)
|
|
31
27
|
|
|
32
28
|
|
|
33
|
-
def _is_editable_install():
|
|
34
|
-
"""Returns True if htpolynet was installed in editable mode (pip install -e .)."""
|
|
35
|
-
try:
|
|
36
|
-
direct_url = distribution('htpolynet').read_text('direct_url.json')
|
|
37
|
-
if direct_url:
|
|
38
|
-
return json.loads(direct_url).get('dir_info', {}).get('editable', False)
|
|
39
|
-
except Exception:
|
|
40
|
-
pass
|
|
41
|
-
return False
|
|
42
|
-
|
|
43
|
-
|
|
44
29
|
def info(args: ap.Namespace):
|
|
45
30
|
"""Handles the info subcommand.
|
|
46
31
|
|
|
@@ -74,7 +59,21 @@ def run(args: ap.Namespace):
|
|
|
74
59
|
"""
|
|
75
60
|
setup_logging(args.loglevel, diag=args.diag, no_banner=args.no_banner)
|
|
76
61
|
my_logger('htpolynet runtime begins', logger.info)
|
|
77
|
-
|
|
62
|
+
if args.restart:
|
|
63
|
+
logger.warning(
|
|
64
|
+
'Restart (-restart) is experimental and currently broken at the '
|
|
65
|
+
'cure stage: pre-cure stages skip correctly, but the first '
|
|
66
|
+
'topology update of the resumed cure iteration fails with an '
|
|
67
|
+
'internal "temp_idx ... already claimed" assertion (insufficient '
|
|
68
|
+
'in-memory state reconstruction). Re-running from scratch is the '
|
|
69
|
+
'safe path.'
|
|
70
|
+
)
|
|
71
|
+
# Ensure the user-library directory tree exists so pfs.exists() / pfs.checkout()
|
|
72
|
+
# can find any monomer inputs we generate from SMILES. Without this, the
|
|
73
|
+
# generated mol2 files would land in projPath/lib/... where pfs does not look.
|
|
74
|
+
os.makedirs(os.path.join(args.lib, pfs.Dirs.molecules_inputs), exist_ok=True)
|
|
75
|
+
os.makedirs(os.path.join(args.lib, pfs.Dirs.molecules_parameterized), exist_ok=True)
|
|
76
|
+
userlib = args.lib
|
|
78
77
|
software.sw_setup()
|
|
79
78
|
my_logger(software.to_string(), logger.info)
|
|
80
79
|
pfs.pfs_setup(root=os.getcwd(), topdirs=pfs.Dirs.run_topdirs, verbose=True, projdir=args.proj, reProject=args.restart, userlibrary=userlib)
|
|
@@ -85,33 +84,20 @@ def run(args: ap.Namespace):
|
|
|
85
84
|
a.do_workflow(force_checkin=args.force_checkin, force_parameterization=args.force_parameterization)
|
|
86
85
|
my_logger('htpolynet runtime ends', logger.info)
|
|
87
86
|
|
|
88
|
-
def _unpack_example(fullpath):
|
|
89
|
-
"""Extracts a single example tarball into the current directory.
|
|
90
|
-
|
|
91
|
-
Args:
|
|
92
|
-
fullpath (str): absolute path to the .tgz file in the system library
|
|
93
|
-
"""
|
|
94
|
-
with tarfile.open(fullpath) as tf:
|
|
95
|
-
tf.extractall('.')
|
|
96
|
-
|
|
97
87
|
def _fetch_one(depot, fullname):
|
|
98
|
-
"""Fetches one example by name
|
|
88
|
+
"""Fetches one example by name (always a self-contained .yaml).
|
|
99
89
|
|
|
100
90
|
Args:
|
|
101
91
|
depot (str): path to the example depot directory
|
|
102
92
|
fullname (str): example name without extension
|
|
103
93
|
"""
|
|
104
94
|
import shutil
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if os.path.exists(sh_path):
|
|
108
|
-
dest = os.path.basename(sh_path)
|
|
109
|
-
shutil.copy(sh_path, dest)
|
|
110
|
-
print(f'Fetched {dest} (run with: bash {dest})')
|
|
111
|
-
elif os.path.exists(tgz_path):
|
|
112
|
-
_unpack_example(tgz_path)
|
|
113
|
-
else:
|
|
95
|
+
yaml_path = os.path.join(depot, f'{fullname}.yaml')
|
|
96
|
+
if not os.path.exists(yaml_path):
|
|
114
97
|
raise FileNotFoundError(f'No example found for {fullname}')
|
|
98
|
+
dest = os.path.basename(yaml_path)
|
|
99
|
+
shutil.copy(yaml_path, dest)
|
|
100
|
+
print(f'Fetched {dest} (run with: htpolynet run {dest})')
|
|
115
101
|
|
|
116
102
|
def fetch_example(args):
|
|
117
103
|
"""Handles the fetch-example subcommand.
|
|
@@ -132,185 +118,13 @@ def fetch_example(args):
|
|
|
132
118
|
fullname = args.n
|
|
133
119
|
_fetch_one(depot, fullname)
|
|
134
120
|
|
|
135
|
-
def pack_example(args):
|
|
136
|
-
l = pfs.system()
|
|
137
|
-
requires = ['README.md', 'run.sh', 'lib/molecules']
|
|
138
|
-
for r in requires:
|
|
139
|
-
assert os.path.exists(r), f'{r}: not found.'
|
|
140
|
-
ls = glob.glob('*.yaml') + glob.glob('*.yml')
|
|
141
|
-
assert len(ls)>0, f'No yaml config file found.'
|
|
142
|
-
bn = os.path.basename(os.getcwd())
|
|
143
|
-
inspectname = bn.split('-')
|
|
144
|
-
if len(inspectname) > 0:
|
|
145
|
-
firstfield = inspectname[0]
|
|
146
|
-
if firstfield.isdigit():
|
|
147
|
-
existing_n = int(firstfield)
|
|
148
|
-
use_n = False
|
|
149
|
-
else:
|
|
150
|
-
use_n = True
|
|
151
|
-
n = args.n
|
|
152
|
-
overwrite = args.overwrite
|
|
153
|
-
existing_examples = l.get_example_names()
|
|
154
|
-
numbers = [int(x.split('-')[0]) for x in existing_examples]
|
|
155
|
-
if not overwrite:
|
|
156
|
-
assert not n in numbers, f'Choose an index other than {n}; an example with this index already exists.'
|
|
157
|
-
if not use_n:
|
|
158
|
-
assert not existing_n in numbers, f'Choose an index other than {n}; an example with this index already exists. To do this, rename the directory.'
|
|
159
|
-
if n == -1:
|
|
160
|
-
n = str(max(numbers) + 1)
|
|
161
|
-
if use_n:
|
|
162
|
-
newname = f'{n}-{os.path.basename(os.getcwd())}'
|
|
163
|
-
else:
|
|
164
|
-
newname = f'{os.path.basename(os.getcwd())}'
|
|
165
|
-
depot_location = l.get_example_depot_location()
|
|
166
|
-
outpath = os.path.join(depot_location, f'{newname}.tgz')
|
|
167
|
-
if overwrite and os.path.exists(outpath):
|
|
168
|
-
logger.debug(f'Warning: overwriting example {outpath}')
|
|
169
|
-
|
|
170
|
-
def _shallow(tarinfo):
|
|
171
|
-
# mirror --exclude="*/*/*/*/*": omit paths deeper than 4 components
|
|
172
|
-
from pathlib import Path
|
|
173
|
-
return tarinfo if len(Path(tarinfo.name).parts) <= 4 else None
|
|
174
|
-
|
|
175
|
-
with tarfile.open(outpath, 'w:gz') as tf:
|
|
176
|
-
for fname in ['README.md', 'run.sh'] + ls:
|
|
177
|
-
tf.add(fname, arcname=f'{bn}/{fname}', recursive=False)
|
|
178
|
-
tf.add('lib/molecules', arcname=f'{bn}/lib/molecules', filter=_shallow)
|
|
179
|
-
logger.debug(f'Packed {outpath} -- consider a pull request!')
|
|
180
|
-
|
|
181
|
-
def pack_example_sh(args):
|
|
182
|
-
"""Generates a self-contained bash setup script for the current example directory.
|
|
183
|
-
|
|
184
|
-
Scans the current directory for YAML configs and lib/molecules/inputs/ files,
|
|
185
|
-
embeds them as heredocs, and writes the resulting .sh script to the example depot.
|
|
186
|
-
|
|
187
|
-
Args:
|
|
188
|
-
args (argparse.Namespace): parsed arguments
|
|
189
|
-
"""
|
|
190
|
-
import textwrap as _tw
|
|
191
|
-
|
|
192
|
-
l = pfs.system()
|
|
193
|
-
yamls = sorted(glob.glob('*.yaml') + glob.glob('*.yml'))
|
|
194
|
-
assert yamls, 'No YAML config file found in the current directory.'
|
|
195
|
-
inputs_dir = 'lib/molecules/inputs'
|
|
196
|
-
assert os.path.isdir(inputs_dir), f'{inputs_dir}: not found.'
|
|
197
|
-
|
|
198
|
-
# Collect text-format monomer input files (mol2, pdb); skip binaries like png
|
|
199
|
-
input_files = sorted(
|
|
200
|
-
f for f in glob.glob(os.path.join(inputs_dir, '*'))
|
|
201
|
-
if os.path.splitext(f)[1].lower() in ('.mol2', '.pdb')
|
|
202
|
-
)
|
|
203
|
-
|
|
204
|
-
bn = os.path.basename(os.getcwd())
|
|
205
|
-
inspectname = bn.split('-')
|
|
206
|
-
firstfield = inspectname[0] if inspectname else ''
|
|
207
|
-
use_n = not firstfield.isdigit()
|
|
208
|
-
existing_n = int(firstfield) if not use_n else None
|
|
209
|
-
|
|
210
|
-
n = args.n
|
|
211
|
-
overwrite = args.overwrite
|
|
212
|
-
existing_examples = l.get_example_names()
|
|
213
|
-
numbers = [int(x.split('-')[0]) for x in existing_examples]
|
|
214
|
-
if not overwrite:
|
|
215
|
-
if n != -1:
|
|
216
|
-
assert n not in numbers, f'Index {n} already exists; use --overwrite or choose another.'
|
|
217
|
-
if not use_n:
|
|
218
|
-
assert existing_n not in numbers, (
|
|
219
|
-
f'Index {existing_n} (from directory name) already exists; '
|
|
220
|
-
f'use --overwrite or rename the directory.'
|
|
221
|
-
)
|
|
222
|
-
if n == -1:
|
|
223
|
-
n = max(numbers) + 1 if numbers else 0
|
|
224
|
-
newname = f'{n}-{bn}' if use_n else bn
|
|
225
|
-
display_n = n if use_n else existing_n
|
|
226
|
-
|
|
227
|
-
depot_location = l.get_example_depot_location()
|
|
228
|
-
outpath = os.path.join(depot_location, f'{newname}.sh')
|
|
229
|
-
if overwrite and os.path.exists(outpath):
|
|
230
|
-
logger.debug(f'Warning: overwriting {outpath}')
|
|
231
|
-
|
|
232
|
-
# Determine the primary config (first yaml alphabetically) for the --run line
|
|
233
|
-
primary_yaml = yamls[0]
|
|
234
|
-
|
|
235
|
-
lines = [
|
|
236
|
-
'#!/bin/bash',
|
|
237
|
-
f'# htpolynet -- Example {display_n} -- {bn}',
|
|
238
|
-
'#',
|
|
239
|
-
f'# Writes all input files into ./{newname}/ and optionally launches the build.',
|
|
240
|
-
'#',
|
|
241
|
-
'# Usage:',
|
|
242
|
-
f'# bash {newname}.sh # set up directory only',
|
|
243
|
-
f'# bash {newname}.sh --run # set up and launch htpolynet',
|
|
244
|
-
'#',
|
|
245
|
-
'# Generated by: htpolynet pack-example-sh',
|
|
246
|
-
'#',
|
|
247
|
-
'# Cameron F. Abrams — cfa22@drexel.edu',
|
|
248
|
-
'',
|
|
249
|
-
'set -euo pipefail',
|
|
250
|
-
'',
|
|
251
|
-
f'EXDIR="{newname}"',
|
|
252
|
-
'if [ -d "$EXDIR" ]; then',
|
|
253
|
-
' echo "Error: directory \'$EXDIR\' already exists. Remove it first." >&2',
|
|
254
|
-
' exit 1',
|
|
255
|
-
'fi',
|
|
256
|
-
'',
|
|
257
|
-
'mkdir -p "$EXDIR/lib/molecules/inputs" "$EXDIR/lib/molecules/parameterized"',
|
|
258
|
-
'cd "$EXDIR"',
|
|
259
|
-
'',
|
|
260
|
-
]
|
|
261
|
-
|
|
262
|
-
# Embed each monomer input file as a heredoc
|
|
263
|
-
if input_files:
|
|
264
|
-
lines.append('# ---------------------------------------------------------------------------')
|
|
265
|
-
lines.append('# Monomer input files')
|
|
266
|
-
lines.append('# ---------------------------------------------------------------------------')
|
|
267
|
-
for fpath in input_files:
|
|
268
|
-
dest = os.path.join('lib/molecules/inputs', os.path.basename(fpath))
|
|
269
|
-
token = f'HTPOLYNET_{os.path.basename(fpath).replace(".", "_").upper()}_EOF'
|
|
270
|
-
lines.append(f"cat > {dest} << '{token}'")
|
|
271
|
-
with open(fpath) as fh:
|
|
272
|
-
lines.append(fh.read().rstrip())
|
|
273
|
-
lines.append(token)
|
|
274
|
-
lines.append('')
|
|
275
|
-
|
|
276
|
-
# Embed each YAML config as a heredoc
|
|
277
|
-
lines.append('# ---------------------------------------------------------------------------')
|
|
278
|
-
lines.append('# Configuration file(s)')
|
|
279
|
-
lines.append('# ---------------------------------------------------------------------------')
|
|
280
|
-
for yaml_file in yamls:
|
|
281
|
-
token = f'HTPOLYNET_{yaml_file.replace(".", "_").upper()}_EOF'
|
|
282
|
-
lines.append(f"cat > {yaml_file} << '{token}'")
|
|
283
|
-
with open(yaml_file) as fh:
|
|
284
|
-
lines.append(fh.read().rstrip())
|
|
285
|
-
lines.append(token)
|
|
286
|
-
lines.append('')
|
|
287
|
-
|
|
288
|
-
# --run launcher
|
|
289
|
-
lines += [
|
|
290
|
-
'# ---------------------------------------------------------------------------',
|
|
291
|
-
'# Optionally launch the build',
|
|
292
|
-
'# ---------------------------------------------------------------------------',
|
|
293
|
-
'if [[ "${1:-}" == "--run" ]]; then',
|
|
294
|
-
f' htpolynet run -diag diagnostics.log {primary_yaml} &> console.log',
|
|
295
|
-
'else',
|
|
296
|
-
' echo "Setup complete. To run:"',
|
|
297
|
-
f' echo " cd $EXDIR && htpolynet run -diag diagnostics.log {primary_yaml}"',
|
|
298
|
-
'fi',
|
|
299
|
-
]
|
|
300
|
-
|
|
301
|
-
script = '\n'.join(lines) + '\n'
|
|
302
|
-
with open(outpath, 'w') as fh:
|
|
303
|
-
fh.write(script)
|
|
304
|
-
logger.debug(f'Wrote {outpath} -- consider a pull request!')
|
|
305
|
-
print(f'Wrote {outpath}')
|
|
306
|
-
|
|
307
121
|
|
|
308
122
|
def _add_run_options(p, loglevel='debug'):
|
|
309
123
|
"""Adds run options (no positional config) shared by run and gen-slurm-script."""
|
|
310
124
|
p.add_argument('-lib',type=str,default='lib',help='local user library of molecular structures and parameterizations')
|
|
311
125
|
p.add_argument('-proj',type=str,default='next',help='project directory; "next" generates the next available; otherwise creates or resumes (with -restart) a named directory')
|
|
312
126
|
p.add_argument('-diag',type=str,default='htpolynet_runtime_diagnostics.log',help='diagnostic log file')
|
|
313
|
-
p.add_argument('-restart',default=False,action='store_true',help='restart in latest proj dir')
|
|
127
|
+
p.add_argument('-restart',default=False,action='store_true',help='restart in latest proj dir (EXPERIMENTAL: broken at the cure stage; see usage docs)')
|
|
314
128
|
p.add_argument('--no-banner',default=False,action='store_true',help='suppress the startup banner')
|
|
315
129
|
p.add_argument('--force-parameterization',default=False,action='store_true',help='force GAFF parameterization of any input mol2 structures')
|
|
316
130
|
p.add_argument('--force-checkin',default=False,action='store_true',help='force check-in of generated parameter files to the system library')
|
|
@@ -442,10 +256,8 @@ def cli():
|
|
|
442
256
|
('postsim', postsim, 'perform specified post-cure MD simulations on final results in one or more project directories'),
|
|
443
257
|
('analyze', analyze, "perform 'gmx <command>' style analyses specified in the config file"),
|
|
444
258
|
('gen-slurm-script', gen_slurm_script, 'generate a SLURM submission script for running htpolynet on a cluster'),
|
|
259
|
+
('make-viz', make_viz, 'regenerate VMD viz files (.viz.psf + .viz.tcl) from an existing gromacs top + gro pair'),
|
|
445
260
|
]
|
|
446
|
-
if _is_editable_install():
|
|
447
|
-
subcommands.append(('pack-example', pack_example, '(dev) pack current directory as a tarball into resources/example_depot'))
|
|
448
|
-
subcommands.append(('pack-example-sh', pack_example_sh, '(dev) generate a self-contained bash setup script from the current example directory'))
|
|
449
261
|
|
|
450
262
|
parser = ap.ArgumentParser(description=textwrap.dedent(banner_message),formatter_class=ap.RawDescriptionHelpFormatter)
|
|
451
263
|
subparsers = parser.add_subparsers()
|
|
@@ -474,15 +286,13 @@ def cli():
|
|
|
474
286
|
cp['input-check'].add_argument('config', type=str, default=None, help='input configuration file in YAML format')
|
|
475
287
|
cp['input-check'].add_argument('-lib', type=str, default='lib', help='local user library of molecular structures and parameterizations')
|
|
476
288
|
|
|
289
|
+
cp['make-viz'].add_argument('-top', type=str, default='final.top', help='input gromacs topology file (default: final.top)')
|
|
290
|
+
cp['make-viz'].add_argument('-gro', type=str, default='final.gro', help='input gromacs coordinate file (default: final.gro)')
|
|
291
|
+
cp['make-viz'].add_argument('-grx', type=str, default=None, help='input htpolynet .grx (default: auto-detect <gro-stem>.grx; needed for the constituent-selection macros)')
|
|
292
|
+
cp['make-viz'].add_argument('-prefix', type=str, default=None, help='output basename; the .viz.psf, .viz.tcl, and .viz.macros.tcl are written next to the input gro (default: stem of -gro)')
|
|
293
|
+
|
|
477
294
|
_add_analysis_args(cp['postsim'])
|
|
478
295
|
_add_analysis_args(cp['analyze'])
|
|
479
296
|
|
|
480
|
-
if 'pack-example' in cp:
|
|
481
|
-
cp['pack-example'].add_argument('-n', type=int, default=-1, help='desired index for this example (default: next available)')
|
|
482
|
-
cp['pack-example'].add_argument('--overwrite', default=False, action='store_true', help='overwrite any existing example with this index in the depot')
|
|
483
|
-
if 'pack-example-sh' in cp:
|
|
484
|
-
cp['pack-example-sh'].add_argument('-n', type=int, default=-1, help='desired index for this example (default: next available)')
|
|
485
|
-
cp['pack-example-sh'].add_argument('--overwrite', default=False, action='store_true', help='overwrite any existing example with this index in the depot')
|
|
486
|
-
|
|
487
297
|
args = parser.parse_args()
|
|
488
298
|
args.func(args)
|
htpolynet/core/bondtemplate.py
CHANGED
|
@@ -72,6 +72,73 @@ class BondTemplate:
|
|
|
72
72
|
rb.reverse()
|
|
73
73
|
return self == rb
|
|
74
74
|
|
|
75
|
+
def bystander_count(self):
|
|
76
|
+
"""Total number of bystander (resname, atomname) pairs across both sides.
|
|
77
|
+
|
|
78
|
+
Used by find_template's best-match selection: more bystanders = more
|
|
79
|
+
specific template, which should win when multiple templates can match
|
|
80
|
+
an instance under subset semantics.
|
|
81
|
+
"""
|
|
82
|
+
return sum(len(s) for s in self.bystander_resnames)
|
|
83
|
+
|
|
84
|
+
def matches(self, other):
|
|
85
|
+
"""Return True if `self` (a parameterization-stage template) is a
|
|
86
|
+
valid description of `other` (an as-found system bond instance).
|
|
87
|
+
|
|
88
|
+
Strict equality on:
|
|
89
|
+
- atom names (``names``)
|
|
90
|
+
- residue names (``resnames``) and ``intraresidue`` flag
|
|
91
|
+
- one-away context (``oneaway_resnames`` / ``oneaway_atomnames``) —
|
|
92
|
+
chain-extension templates use these to discriminate dimer- vs
|
|
93
|
+
trimer- vs tetramer-context bonds, so the match has to be exact.
|
|
94
|
+
|
|
95
|
+
Subset semantics on bystanders:
|
|
96
|
+
- paired ``(bystander_resname, bystander_atomname)`` items are
|
|
97
|
+
treated as a multiset on each side; every item the template
|
|
98
|
+
declares must appear in the instance, but the instance may
|
|
99
|
+
carry additional bystanders the template does not mention.
|
|
100
|
+
|
|
101
|
+
Rationale: a small-fragment parameterization template (e.g. the
|
|
102
|
+
CY-CY cyanate dimer) carries no inter-residue context at the
|
|
103
|
+
cure-reactive atom because the fragment is a single residue.
|
|
104
|
+
The system-instance bond, formed inside an assembled monomer
|
|
105
|
+
(e.g. BCY = BPA + 2 CY), naturally picks up the BPA-O ester
|
|
106
|
+
bystander at the same atom. That extra structural context does
|
|
107
|
+
not change the local chemistry of the bond template, so the
|
|
108
|
+
template should still match. Exact bystander equality would
|
|
109
|
+
force the cure reactant to mirror every inter-residue partner
|
|
110
|
+
the instance carries, which forecloses the small-fragment idiom.
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
other (BondTemplate): the instance bond to test for compatibility
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
bool: True if self can serve as a template for other
|
|
117
|
+
"""
|
|
118
|
+
if self.names != other.names: return False
|
|
119
|
+
if self.intraresidue != other.intraresidue: return False
|
|
120
|
+
if self.resnames != other.resnames: return False
|
|
121
|
+
if self.oneaway_resnames != other.oneaway_resnames: return False
|
|
122
|
+
if self.oneaway_atomnames != other.oneaway_atomnames: return False
|
|
123
|
+
for side in (0, 1):
|
|
124
|
+
t_pairs = list(zip(self.bystander_resnames[side],
|
|
125
|
+
self.bystander_atomnames[side]))
|
|
126
|
+
i_pairs = list(zip(other.bystander_resnames[side],
|
|
127
|
+
other.bystander_atomnames[side]))
|
|
128
|
+
remaining = list(i_pairs)
|
|
129
|
+
for tp in t_pairs:
|
|
130
|
+
if tp in remaining:
|
|
131
|
+
remaining.remove(tp)
|
|
132
|
+
else:
|
|
133
|
+
return False
|
|
134
|
+
return True
|
|
135
|
+
|
|
136
|
+
def matches_reverse_of(self, other):
|
|
137
|
+
"""Like ``matches`` but tries the reversed orientation of ``other``."""
|
|
138
|
+
rb = deepcopy(other)
|
|
139
|
+
rb.reverse()
|
|
140
|
+
return self.matches(rb)
|
|
141
|
+
|
|
75
142
|
|
|
76
143
|
BondTemplateList = list[BondTemplate]
|
|
77
144
|
|
htpolynet/core/configuration.py
CHANGED
|
@@ -29,6 +29,7 @@ class Configuration:
|
|
|
29
29
|
self.gromacs = {}
|
|
30
30
|
self.densification = {}
|
|
31
31
|
self.precure = {}
|
|
32
|
+
self.postcure_repair = [] # list of postcure topology-repair specs
|
|
32
33
|
self.postcure = {}
|
|
33
34
|
self.cure = {}
|
|
34
35
|
self.gaff = {}
|
|
@@ -72,6 +73,7 @@ class Configuration:
|
|
|
72
73
|
self.gromacs = self.basedict.get('gromacs', {})
|
|
73
74
|
self.densification = self.basedict.get('densification', {})
|
|
74
75
|
self.precure = self.basedict.get('precure', {})
|
|
76
|
+
self.postcure_repair = self.basedict.get('postcure_repair', [])
|
|
75
77
|
self.postcure = self.basedict.get('postcure', {})
|
|
76
78
|
self.cure = self.basedict.get('CURE', {})
|
|
77
79
|
self.gaff = self.basedict.get('GAFF', {})
|
htpolynet/core/molecule.py
CHANGED
|
@@ -362,7 +362,7 @@ class Molecule:
|
|
|
362
362
|
do_parameterization = False
|
|
363
363
|
if self.generator:
|
|
364
364
|
R = self.generator
|
|
365
|
-
if R.stage in [reaction_stage.cure, reaction_stage.param, reaction_stage.cap]: do_parameterization = True
|
|
365
|
+
if R.stage in [reaction_stage.cure, reaction_stage.param, reaction_stage.cap, reaction_stage.repair]: do_parameterization = True
|
|
366
366
|
self.TopoCoord = TopoCoord()
|
|
367
367
|
logger.debug(f'Using reaction {R.name} ({str(R.stage)}) to generate {self.name} parent {self.parentname}')
|
|
368
368
|
isf = 'mol2'
|
|
@@ -548,16 +548,29 @@ class Molecule:
|
|
|
548
548
|
inst_resids = [inst_resids[ij[x]] for x in [0, 1]]
|
|
549
549
|
inst_bystander_resids = [bystanders[ij[x]] for x in [0, 1]]
|
|
550
550
|
inst_oneaway_resids = [oneaways[ij[x]] for x in [0, 1]]
|
|
551
|
-
|
|
552
|
-
|
|
551
|
+
# Bystander counts on each side may legitimately differ when the
|
|
552
|
+
# template (a small parameterization fragment) carries fewer
|
|
553
|
+
# bystanders than the in-system instance — e.g. cyanate-ester cure,
|
|
554
|
+
# where the CY+CY dimer template has no BPA bystander but every
|
|
555
|
+
# BCY-embedded instance does (find_template's subset semantics
|
|
556
|
+
# let the small-fragment template match in this case). Allow
|
|
557
|
+
# the template to be the shorter list on each side; the extra
|
|
558
|
+
# instance bystanders are residues outside the template and don't
|
|
559
|
+
# need to be mapped here. When both lists carry chain context
|
|
560
|
+
# the counts agree as before.
|
|
561
|
+
# Pair region-by-region so that a length difference on one side
|
|
562
|
+
# doesn't shift alignment of the other side's bystanders or the
|
|
563
|
+
# oneaways. Within each region zip naturally truncates the longer
|
|
564
|
+
# (always the instance) list.
|
|
553
565
|
instdf = otherTC.Coordinates.A
|
|
554
566
|
tempdf = self.TopoCoord.Coordinates.A
|
|
555
567
|
inst2temp = {}
|
|
556
568
|
temp2inst = {}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
569
|
+
resid_pairs = list(zip(inst_resids, temp_resids))
|
|
570
|
+
resid_pairs.extend(zip(inst_bystander_resids[0], temp_bystander_resids[0]))
|
|
571
|
+
resid_pairs.extend(zip(inst_bystander_resids[1], temp_bystander_resids[1]))
|
|
572
|
+
resid_pairs.extend(zip(inst_oneaway_resids, temp_oneaway_resids))
|
|
573
|
+
for inst, temp in resid_pairs:
|
|
561
574
|
if inst and temp: # None's in the bystander lists and oneaways lists should be ignored
|
|
562
575
|
logger.debug(f'map inst resid {inst} to template resid {temp}')
|
|
563
576
|
idf = instdf[instdf['resNum'] == inst][['globalIdx','atomName']].copy()
|
|
@@ -753,7 +766,7 @@ class Molecule:
|
|
|
753
766
|
resid_sets = TC.get_resid_sets([r.ai, r.aj])
|
|
754
767
|
hxi, hxj = self.transrot(r.ai, r.ri, r.aj, r.rj, connected_resids=resid_sets[1])
|
|
755
768
|
explicit_sacrificial_Hs[i] = [hxi, hxj]
|
|
756
|
-
if stage in [reaction_stage.cure, reaction_stage.param, reaction_stage.cap]:
|
|
769
|
+
if stage in [reaction_stage.cure, reaction_stage.param, reaction_stage.cap, reaction_stage.repair]:
|
|
757
770
|
template_source = 'ambertools'
|
|
758
771
|
else:
|
|
759
772
|
template_source = 'internal' # signals that a template molecule should be identified to parameterize this bond
|
|
@@ -965,6 +978,12 @@ class Molecule:
|
|
|
965
978
|
gronames.append(f'{si}')
|
|
966
979
|
for gro in gronames:
|
|
967
980
|
pfx = f'{gro}-C'
|
|
981
|
+
fmt = r'{A}{B:0'+str(nd) + r'd}' # the trjconv command in gro_from_trr must generate these files
|
|
982
|
+
cfnl = [fmt.format(A=pfx,B=x) for x in range(self.nconformers)]
|
|
983
|
+
if all(os.path.exists(f'{mname}.gro') for mname in cfnl):
|
|
984
|
+
logger.info(f'Reusing {self.nconformers} existing conformer gro files for {gro}')
|
|
985
|
+
self.conformers.extend(cfnl)
|
|
986
|
+
continue
|
|
968
987
|
if generator['name'] == 'obabel':
|
|
969
988
|
compfile = f'{gro}-obabel-confs.gro'
|
|
970
989
|
run(f'obabel -igro {gro}.gro -O {compfile} --conformer --nconf {self.nconformers} --writeconformers')
|
|
@@ -980,8 +999,6 @@ class Molecule:
|
|
|
980
999
|
TC.vacuum_simulate(outname=f'{compfile}', nsamples=cd['count'], params=params)
|
|
981
1000
|
gro_from_trr(compfile, nzero=nd, outpfx=pfx, b=begin_at)
|
|
982
1001
|
# os.remove(f'{gro}-confs.gro')
|
|
983
|
-
fmt = r'{A}{B:0'+str(nd) + r'd}' # the trjconv command in gro_from_trr must generate these files
|
|
984
|
-
cfnl = [fmt.format(A=pfx,B=x) for x in range(self.nconformers)]
|
|
985
1002
|
for mname in cfnl:
|
|
986
1003
|
assert os.path.exists(f'{mname}.gro'), f'Error: Conformer coordinates file {mname}.gro not found'
|
|
987
1004
|
logger.debug(f'Conformer coordinate filenames {cfnl}')
|
|
@@ -16,6 +16,19 @@ _CACHE_ENV_VAR = 'HTPOLYNET_CACHE'
|
|
|
16
16
|
_CACHE_DEFAULT = Path.home() / '.htpolynet'
|
|
17
17
|
|
|
18
18
|
|
|
19
|
+
def _safe_copyfile(src, dst):
|
|
20
|
+
"""Like ``shutil.copyfile`` but a no-op when src and dst resolve to the
|
|
21
|
+
same path. This arises on restart, when the search path for a checkout
|
|
22
|
+
includes ``projPath`` and the cwd is already inside ``projPath`` (so the
|
|
23
|
+
source we find IS the destination)."""
|
|
24
|
+
try:
|
|
25
|
+
if os.path.abspath(src) == os.path.abspath(dst):
|
|
26
|
+
return
|
|
27
|
+
except Exception:
|
|
28
|
+
pass
|
|
29
|
+
shutil.copyfile(src, dst)
|
|
30
|
+
|
|
31
|
+
|
|
19
32
|
class SystemLibrary:
|
|
20
33
|
"""Read-only access to bundled package resources via importlib.resources."""
|
|
21
34
|
|
|
@@ -61,8 +74,9 @@ class SystemLibrary:
|
|
|
61
74
|
def get_example_names(self):
|
|
62
75
|
"""Returns sorted list of example names available in the depot.
|
|
63
76
|
|
|
64
|
-
Recognises
|
|
65
|
-
names (without extension) in
|
|
77
|
+
Recognises self-contained .yaml configs, legacy .sh scripts, and
|
|
78
|
+
legacy .tgz tarballs; returns unique names (without extension) in
|
|
79
|
+
numeric-prefix order.
|
|
66
80
|
|
|
67
81
|
Returns:
|
|
68
82
|
list: example names without extension
|
|
@@ -70,7 +84,7 @@ class SystemLibrary:
|
|
|
70
84
|
depot = self._root.joinpath('example_depot')
|
|
71
85
|
names = set()
|
|
72
86
|
for f in depot.iterdir():
|
|
73
|
-
if f.name.endswith('.
|
|
87
|
+
if f.name.endswith(('.yaml', '.tgz', '.sh')):
|
|
74
88
|
names.add(f.stem)
|
|
75
89
|
return sorted(names)
|
|
76
90
|
|
|
@@ -140,7 +154,7 @@ class UserCache:
|
|
|
140
154
|
"""
|
|
141
155
|
src = self.root / filename
|
|
142
156
|
if src.exists():
|
|
143
|
-
|
|
157
|
+
_safe_copyfile(src, os.path.basename(filename))
|
|
144
158
|
return True
|
|
145
159
|
return False
|
|
146
160
|
|
|
@@ -161,7 +175,7 @@ class UserCache:
|
|
|
161
175
|
dest = self.root / filename
|
|
162
176
|
dest.parent.mkdir(parents=True, exist_ok=True)
|
|
163
177
|
if not dest.exists() or overwrite:
|
|
164
|
-
|
|
178
|
+
_safe_copyfile(src, dest)
|
|
165
179
|
return True
|
|
166
180
|
|
|
167
181
|
def get_molecule_names(self):
|
|
@@ -220,7 +234,7 @@ class UserLibrary:
|
|
|
220
234
|
"""
|
|
221
235
|
src = self.root / filename
|
|
222
236
|
if src.exists():
|
|
223
|
-
|
|
237
|
+
_safe_copyfile(src, os.path.basename(filename))
|
|
224
238
|
return True
|
|
225
239
|
all_paths = list(searchpath)
|
|
226
240
|
if altpath:
|
|
@@ -228,7 +242,7 @@ class UserLibrary:
|
|
|
228
242
|
for p in all_paths:
|
|
229
243
|
candidate = Path(p) / filename
|
|
230
244
|
if candidate.exists():
|
|
231
|
-
|
|
245
|
+
_safe_copyfile(candidate, os.path.basename(filename))
|
|
232
246
|
return True
|
|
233
247
|
return False
|
|
234
248
|
|
|
@@ -265,6 +279,7 @@ class Dirs:
|
|
|
265
279
|
systems_precure = 'systems/precure'
|
|
266
280
|
systems_postcure = 'systems/postcure'
|
|
267
281
|
systems_capping = 'systems/capping'
|
|
282
|
+
systems_repair = 'systems/repair'
|
|
268
283
|
systems_final = 'systems/final-results'
|
|
269
284
|
|
|
270
285
|
# standard topdirs lists for pfs_setup
|