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
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""
|
|
2
|
+
|
|
3
|
+
.. module:: dataframetools
|
|
4
|
+
:synopsis: Some convenient tools for handling pandas dataframes in the context of htpolynet coordinates
|
|
5
|
+
|
|
6
|
+
.. moduleauthor: Cameron F. Abrams, <cfa22@drexel.edu>
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
import pandas as pd
|
|
10
|
+
import logging
|
|
11
|
+
|
|
12
|
+
logger=logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
def get_row_attribute(df:pd.DataFrame,name,attributes):
|
|
15
|
+
"""get_row_attribute returns a scalar value of attribute "name" in row
|
|
16
|
+
expected to be uniquely defined by attributes dict
|
|
17
|
+
|
|
18
|
+
:param df: dataframe to search
|
|
19
|
+
:type df: pandas.DataFrame
|
|
20
|
+
:param name: name of attribute whose value you want
|
|
21
|
+
:type name: str
|
|
22
|
+
:param attributes: dictionary of attribute:value pairs that defines target set or row
|
|
23
|
+
:type attributes: dict
|
|
24
|
+
:return: value of attribute name
|
|
25
|
+
:rtype: scalar
|
|
26
|
+
"""
|
|
27
|
+
ga={k:v for k,v in attributes.items() if k in df}
|
|
28
|
+
assert len(ga)>0,f'Cannot find row with attributes {attributes}'
|
|
29
|
+
if type(name)==list:
|
|
30
|
+
name_in_df=all([n in df for n in name])
|
|
31
|
+
else:
|
|
32
|
+
name_in_df= name in df
|
|
33
|
+
assert name_in_df,f'Attribute(s) {name} not found'
|
|
34
|
+
c=[df[k] for k in ga]
|
|
35
|
+
V=list(ga.values())
|
|
36
|
+
l=[True]*df.shape[0]
|
|
37
|
+
for i in range(len(c)):
|
|
38
|
+
l = (l) & (c[i]==V[i])
|
|
39
|
+
return df[list(l)][name].values[0]
|
|
40
|
+
|
|
41
|
+
def get_row_as_string(df:pd.DataFrame,attributes):
|
|
42
|
+
"""get_row_as_string returns a scalar value of attribute "name" in row
|
|
43
|
+
expected to be uniquely defined by attributes dict
|
|
44
|
+
|
|
45
|
+
:param df: a pandas dataframe
|
|
46
|
+
:type df: pd.DataFrame
|
|
47
|
+
:param attributes: dictionary of column names (keys) and values that specify set of rows to be returned
|
|
48
|
+
:type attributes: dict(str,obj)
|
|
49
|
+
:return: selected dataframe converted to a string
|
|
50
|
+
:rtype: str
|
|
51
|
+
"""
|
|
52
|
+
ga={k:v for k,v in attributes.items() if k in df}
|
|
53
|
+
c=[df[k] for k in ga]
|
|
54
|
+
V=list(ga.values())
|
|
55
|
+
l=[True]*df.shape[0]
|
|
56
|
+
for i in range(len(c)):
|
|
57
|
+
l = (l) & (c[i]==V[i])
|
|
58
|
+
return df[list(l)].to_string()
|
|
59
|
+
|
|
60
|
+
def get_rows_w_attribute(df:pd.DataFrame,name,attributes:dict):
|
|
61
|
+
''' '''
|
|
62
|
+
"""get_rows_w_attribute returns a series of values of attribute "name" from
|
|
63
|
+
all rows matching attributes dict
|
|
64
|
+
|
|
65
|
+
:return: list of values from selected rows
|
|
66
|
+
:rtype: whatever pd.dataframe.values type is?
|
|
67
|
+
"""
|
|
68
|
+
ga={k:v for k,v in attributes.items() if k in df}
|
|
69
|
+
assert len(ga)>0,f'Cannot find any rows with attributes {attributes}'
|
|
70
|
+
if type(name)==list:
|
|
71
|
+
name_in_df=all([n in df for n in name])
|
|
72
|
+
else:
|
|
73
|
+
name_in_df= name in df
|
|
74
|
+
assert name_in_df,f'Attribute(s) {name} not found'
|
|
75
|
+
c=[df[k] for k in ga]
|
|
76
|
+
V=list(ga.values())
|
|
77
|
+
l=[True]*df.shape[0]
|
|
78
|
+
for i in range(len(c)):
|
|
79
|
+
l = (l) & (c[i]==V[i])
|
|
80
|
+
return df[list(l)][name].values
|
|
81
|
+
|
|
82
|
+
def set_row_attribute(df:pd.DataFrame,name,value,attributes):
|
|
83
|
+
"""set_row_attribute set value of attribute name to value in all rows matching attributes dict
|
|
84
|
+
|
|
85
|
+
:param df: a pandas dataframe
|
|
86
|
+
:type df: pd.DataFrame
|
|
87
|
+
:param name: name of attribute whose value is to be set
|
|
88
|
+
:type name: str
|
|
89
|
+
:param value: value the attribute is to be set to
|
|
90
|
+
:type value: scalar
|
|
91
|
+
:param attributes: dictionary of attribute:value pairs that specify the atoms whose attribute is to be set
|
|
92
|
+
:type attributes: dict
|
|
93
|
+
"""
|
|
94
|
+
ga={k:v for k,v in attributes.items() if k in df}
|
|
95
|
+
exla={k:v for k,v in attributes.items() if not k in df}
|
|
96
|
+
if len(exla)>0:
|
|
97
|
+
logger.warning(f'Caller attempts to use unrecognized attributes to refer to row: {exla}')
|
|
98
|
+
if name in df and len(ga)>0:
|
|
99
|
+
c=[df[k] for k in ga]
|
|
100
|
+
V=list(ga.values())
|
|
101
|
+
l=[True]*df.shape[0]
|
|
102
|
+
for i in range(len(c)):
|
|
103
|
+
l = (l) & (c[i]==V[i])
|
|
104
|
+
cidx=[c==name for c in df.columns]
|
|
105
|
+
df.loc[list(l),cidx]=value
|
|
106
|
+
|
|
107
|
+
def set_rows_attributes_from_dict(df:pd.DataFrame,valdict,attributes):
|
|
108
|
+
"""set_rows_attributes_from_dict set values of attributes in valdict dict of all rows
|
|
109
|
+
matching attributes dict
|
|
110
|
+
|
|
111
|
+
:param df: a pandas dataframe
|
|
112
|
+
:type df: pd.DataFrame
|
|
113
|
+
:param valdict: dictionary of attribute:value pairs to set
|
|
114
|
+
:type valdict: dict
|
|
115
|
+
:param attributes: dictionary of attribute:value pairs that specify the atoms whose attribute is to be set
|
|
116
|
+
:type attributes: dict
|
|
117
|
+
"""
|
|
118
|
+
ga={k:v for k,v in attributes.items() if k in df}
|
|
119
|
+
exla={k:v for k,v in attributes.items() if not k in df}
|
|
120
|
+
if len(exla)>0:
|
|
121
|
+
logger.warning(f'using unknown attributes to refer to atom: {exla}')
|
|
122
|
+
if all([x in df for x in valdict]) and len(ga)>0:
|
|
123
|
+
c=[df[k] for k in ga]
|
|
124
|
+
V=list(ga.values())
|
|
125
|
+
l=[True]*df.shape[0]
|
|
126
|
+
for i in range(len(c)):
|
|
127
|
+
l = (l) & (c[i]==V[i])
|
|
128
|
+
for k,v in valdict.items():
|
|
129
|
+
cidx=[c==k for c in df.columns]
|
|
130
|
+
df.loc[list(l),cidx]=v
|
HTPolyNet/driver.py
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"""
|
|
2
|
+
|
|
3
|
+
.. module:: driver
|
|
4
|
+
:synopsis: manages the HTPolyNet application, provides the command-line interface entry point
|
|
5
|
+
|
|
6
|
+
.. moduleauthor: Cameron F. Abrams, <cfa22@drexel.edu>
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
import logging
|
|
10
|
+
import os
|
|
11
|
+
import argparse as ap
|
|
12
|
+
import textwrap
|
|
13
|
+
import shutil
|
|
14
|
+
import glob
|
|
15
|
+
from .banner import banner, banner_message
|
|
16
|
+
from .runtime import Runtime,logrotate
|
|
17
|
+
from .command import Command
|
|
18
|
+
import HTPolyNet.projectfilesystem as pfs
|
|
19
|
+
import HTPolyNet.software as software
|
|
20
|
+
from .plot import plots
|
|
21
|
+
from .stringthings import my_logger
|
|
22
|
+
from .inputcheck import input_check
|
|
23
|
+
from .postsim import postsim
|
|
24
|
+
from .analyze import analyze
|
|
25
|
+
|
|
26
|
+
logger=logging.getLogger(__name__)
|
|
27
|
+
|
|
28
|
+
def info(args):
|
|
29
|
+
"""info handles the info subcommmand
|
|
30
|
+
|
|
31
|
+
:param args: parsed arguments
|
|
32
|
+
:type args: argparse.Namespace
|
|
33
|
+
"""
|
|
34
|
+
print('This is some information on your installed version of HTPolyNet')
|
|
35
|
+
l=pfs.lib_setup()
|
|
36
|
+
software.sw_setup()
|
|
37
|
+
print(l.info())
|
|
38
|
+
print(software.to_string())
|
|
39
|
+
possibles=l.get_example_names()
|
|
40
|
+
print('Available examples using htpolynet fetch-example')
|
|
41
|
+
for p in possibles:
|
|
42
|
+
if p[0].isdecimal():
|
|
43
|
+
print(f' {p}')
|
|
44
|
+
|
|
45
|
+
def run(args):
|
|
46
|
+
"""run handles the run subcommand
|
|
47
|
+
|
|
48
|
+
:param args: parsed arguments
|
|
49
|
+
:type args: argparse.Namespace
|
|
50
|
+
"""
|
|
51
|
+
logrotate(args.diag)
|
|
52
|
+
''' set up logger with all debug+-level messages going to the diagnostic log file and info to console '''
|
|
53
|
+
loglevel_numeric=getattr(logging, args.loglevel.upper())
|
|
54
|
+
logging.basicConfig(filename=args.diag,filemode='w',format='%(asctime)s %(name)s.%(funcName)s %(levelname)s> %(message)s',level=loglevel_numeric)
|
|
55
|
+
console=logging.StreamHandler()
|
|
56
|
+
console.setLevel(logging.INFO)
|
|
57
|
+
formatter=logging.Formatter('%(levelname)s> %(message)s')
|
|
58
|
+
console.setFormatter(formatter)
|
|
59
|
+
logging.getLogger('').addHandler(console)
|
|
60
|
+
if not args.no_banner: banner(logger.info)
|
|
61
|
+
my_logger('HTPolyNet runtime begins',logger.info)
|
|
62
|
+
userlib=args.lib if os.path.exists(args.lib) else None
|
|
63
|
+
software.sw_setup()
|
|
64
|
+
pfs.pfs_setup(root=os.getcwd(),topdirs=['molecules','systems','plots'],verbose=True,projdir=args.proj,reProject=args.restart,userlibrary=userlib)
|
|
65
|
+
a=Runtime(cfgfile=args.config,restart=args.restart)
|
|
66
|
+
a.do_workflow(force_checkin=args.force_checkin,force_parameterization=args.force_parameterization)
|
|
67
|
+
my_logger('HTPolyNet runtime ends',logger.info)
|
|
68
|
+
|
|
69
|
+
def parameterize(args):
|
|
70
|
+
"""parameterize handles the parameterize subcommand
|
|
71
|
+
|
|
72
|
+
:param args: parsed arguments
|
|
73
|
+
:type args: argparse.Namespace
|
|
74
|
+
"""
|
|
75
|
+
logrotate(args.diag)
|
|
76
|
+
''' set up logger with all debug+-level messages going to the diagnostic log file and info to console '''
|
|
77
|
+
loglevel_numeric=getattr(logging, args.loglevel.upper())
|
|
78
|
+
logging.basicConfig(filename=args.diag,filemode='w',format='%(asctime)s %(name)s.%(funcName)s %(levelname)s> %(message)s',level=loglevel_numeric)
|
|
79
|
+
console=logging.StreamHandler()
|
|
80
|
+
console.setLevel(logging.INFO)
|
|
81
|
+
formatter=logging.Formatter('%(levelname)s> %(message)s')
|
|
82
|
+
console.setFormatter(formatter)
|
|
83
|
+
logging.getLogger('').addHandler(console)
|
|
84
|
+
if not args.no_banner: banner(logger.info)
|
|
85
|
+
my_logger('HTPolyNet parameterization begins',logger.info)
|
|
86
|
+
userlib=args.lib
|
|
87
|
+
if not os.path.exists(args.lib):
|
|
88
|
+
userlib=None
|
|
89
|
+
software.sw_setup()
|
|
90
|
+
pfs.pfs_setup(root=os.getcwd(),topdirs=['molecules','systems','plots'],verbose=True,projdir=args.proj,reProject=args.restart,userlibrary=userlib)
|
|
91
|
+
a=Runtime(cfgfile=args.config,restart=args.restart)
|
|
92
|
+
a.generate_molecules(force_checkin=args.force_checkin,force_parameterization=args.force_parameterization)
|
|
93
|
+
my_logger('HTPolynet parameterization ends',logger.info)
|
|
94
|
+
|
|
95
|
+
def fetch_example(args):
|
|
96
|
+
"""fetch_example handles the fetch-example subcommand
|
|
97
|
+
|
|
98
|
+
:param args: parsed arguments
|
|
99
|
+
:type args: argparse.Namespace
|
|
100
|
+
"""
|
|
101
|
+
l=pfs.system()
|
|
102
|
+
nm=args.n
|
|
103
|
+
kp=args.k
|
|
104
|
+
possibles=l.get_example_names()
|
|
105
|
+
if nm.isdecimal():
|
|
106
|
+
fullname=[x for x in possibles if x.startswith(nm)][0]
|
|
107
|
+
else:
|
|
108
|
+
if nm=='all':
|
|
109
|
+
for fullname in possibles:
|
|
110
|
+
shutil.copy(os.path.join(l.get_example_depot_location(),f'{fullname}.tgz'),'.')
|
|
111
|
+
os.system(f'tar zxf {fullname}.tgz')
|
|
112
|
+
if not kp:
|
|
113
|
+
os.remove(f'{fullname}.tgz')
|
|
114
|
+
return
|
|
115
|
+
fullname=nm
|
|
116
|
+
fullpath=os.path.join(l.get_example_depot_location(),f'{fullname}.tgz')
|
|
117
|
+
assert os.path.exists(fullpath),f'{fullpath}: not found.'
|
|
118
|
+
shutil.copy(fullpath,'.')
|
|
119
|
+
os.system(f'tar zxf {fullname}.tgz')
|
|
120
|
+
if not kp:
|
|
121
|
+
os.remove(f'{fullname}.tgz')
|
|
122
|
+
|
|
123
|
+
def pack_example(args):
|
|
124
|
+
l=pfs.system()
|
|
125
|
+
requires=['README.md','run.sh','lib/molecules']
|
|
126
|
+
for r in requires:
|
|
127
|
+
assert os.path.exists(r),f'{r}: not found.'
|
|
128
|
+
ls=glob.glob('*.yaml')+glob.glob('*.yml')
|
|
129
|
+
assert len(ls)>0,f'No yaml config file found.'
|
|
130
|
+
bn=os.path.basename(os.getcwd())
|
|
131
|
+
inspectname=bn.split('-')
|
|
132
|
+
if len(inspectname)>0:
|
|
133
|
+
firstfield=inspectname[0]
|
|
134
|
+
if firstfield.isdigit():
|
|
135
|
+
existing_n=int(firstfield)
|
|
136
|
+
use_n=False
|
|
137
|
+
else:
|
|
138
|
+
use_n=True
|
|
139
|
+
n=args.n
|
|
140
|
+
existing_examples=l.get_example_names()
|
|
141
|
+
numbers=[int(x.split('-')[0]) for x in existing_examples]
|
|
142
|
+
assert not n in numbers,f'Choose an index other than {n}; an example with this index already exists.'
|
|
143
|
+
if not use_n:
|
|
144
|
+
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.'
|
|
145
|
+
if n==-1:
|
|
146
|
+
n=str(max(numbers)+1)
|
|
147
|
+
if use_n:
|
|
148
|
+
newname=f'{n}-{os.path.basename(os.getcwd())}'
|
|
149
|
+
else:
|
|
150
|
+
newname=f'{os.path.basename(os.getcwd())}'
|
|
151
|
+
depot_location=l.get_example_depot_location()
|
|
152
|
+
os.chdir('..')
|
|
153
|
+
c=Command(f'tar --exclude="*/*/*/*/*" -zvcf {depot_location}/{newname}.tgz {bn}/README.md {bn}/run.sh {bn}/*.yaml {bn}/lib/molecules/')
|
|
154
|
+
o,e=c.run()
|
|
155
|
+
print(o)
|
|
156
|
+
print(e)
|
|
157
|
+
|
|
158
|
+
def cli():
|
|
159
|
+
"""cli Command-line interface
|
|
160
|
+
"""
|
|
161
|
+
l=pfs.lib_setup()
|
|
162
|
+
example_names=l.get_example_names()
|
|
163
|
+
example_ids=[x.split('-')[0] for x in example_names]
|
|
164
|
+
# declare subcommands and their handlers
|
|
165
|
+
commands={}
|
|
166
|
+
commands['run']=run
|
|
167
|
+
commands['parameterize']=parameterize
|
|
168
|
+
commands['info']=info
|
|
169
|
+
commands['plots']=plots
|
|
170
|
+
commands['fetch-example']=fetch_example
|
|
171
|
+
commands['input-check']=input_check
|
|
172
|
+
commands['postsim']=postsim
|
|
173
|
+
commands['analyze']=analyze
|
|
174
|
+
commands['pack-example']=pack_example
|
|
175
|
+
# declare subcommand helpstrings
|
|
176
|
+
helps={}
|
|
177
|
+
helps['run']='build a system using instructions in the config file and any required molecular structure inputs'
|
|
178
|
+
helps['parameterize']='parameterize monomers and oligomer templates using instructions in the config file'
|
|
179
|
+
helps['info']='print some information to the console'
|
|
180
|
+
helps['plots']='generate some plots that summarize aspects of the current completed build'
|
|
181
|
+
helps['fetch-example']='fetch and unpack example(s) from HTPolyNet.HTPolyNet.resources: '+', '.join([f'"{x}"' for x in l.get_example_names()])
|
|
182
|
+
helps['pack-example']='pack current directory as a tarball to the resources/example_depot'
|
|
183
|
+
helps['input-check']='reports number of atoms that would be in initial system based on config'
|
|
184
|
+
helps['postsim']='perform specified postcure MD simulations on final results in one or more project directory'
|
|
185
|
+
helps['analyze']='perform \'gmx <command>\' style analyses specified in the cfg file'
|
|
186
|
+
parser=ap.ArgumentParser(description=textwrap.dedent(banner_message),formatter_class=ap.RawDescriptionHelpFormatter)
|
|
187
|
+
# Subparsers, one per subcommand
|
|
188
|
+
subparsers=parser.add_subparsers()
|
|
189
|
+
subparsers.required=True
|
|
190
|
+
command_parsers={}
|
|
191
|
+
for k in commands:
|
|
192
|
+
command_parsers[k]=subparsers.add_parser(k,help=helps[k])
|
|
193
|
+
command_parsers[k].set_defaults(func=commands[k])
|
|
194
|
+
######## run ########
|
|
195
|
+
command_parsers['run'].add_argument('config',type=str,default=None,help='input configuration file in YAML format')
|
|
196
|
+
command_parsers['run'].add_argument('-lib',type=str,default='lib',help='local user library of molecular structures and parameterizations')
|
|
197
|
+
command_parsers['run'].add_argument('-proj',type=str,default='next',help='project directory; "next" (default) generates next directory. Anything other than "next": if it exists, "-restart" must be included as a parameter; if not, it is created as a new project')
|
|
198
|
+
command_parsers['run'].add_argument('-diag',type=str,default='htpolynet_runtime_diagnostics.log',help='diagnostic log file')
|
|
199
|
+
command_parsers['run'].add_argument('-restart',default=False,action='store_true',help='restart in latest proj dir')
|
|
200
|
+
command_parsers['run'].add_argument('--no-banner',default=False,action='store_true',help='turn off the banner')
|
|
201
|
+
command_parsers['run'].add_argument('--force-parameterization',default=False,action='store_true',help='force GAFF parameterization of any input mol2 structures')
|
|
202
|
+
command_parsers['run'].add_argument('--force-checkin',default=False,action='store_true',help='force check-in of any generated parameter files to the system library')
|
|
203
|
+
command_parsers['run'].add_argument('--loglevel',type=str,default='debug',help='Log level for messages written to diagnostic log (debug|info)')
|
|
204
|
+
######## parameterize ########
|
|
205
|
+
command_parsers['parameterize'].add_argument('config',type=str,default=None,help='input configuration file in YAML format')
|
|
206
|
+
command_parsers['parameterize'].add_argument('-lib',type=str,default='lib',help='local user library of molecular structures and parameterizations')
|
|
207
|
+
command_parsers['parameterize'].add_argument('-proj',type=str,default='next',help='project directory; "next" (default) generates next directory. Anything other than "next": if it exists, "-restart" must be included as a parameter; if not, it is created as a new project')
|
|
208
|
+
command_parsers['parameterize'].add_argument('-diag',type=str,default='htpolynet_runtime_diagnostics.log',help='diagnostic log file')
|
|
209
|
+
command_parsers['parameterize'].add_argument('-restart',default=False,action='store_true',help='restart in latest proj dir')
|
|
210
|
+
command_parsers['parameterize'].add_argument('--force-parameterization',default=False,action='store_true',help='force GAFF parameterization of any input mol2 structures')
|
|
211
|
+
command_parsers['parameterize'].add_argument('--force-checkin',default=False,action='store_true',help='force check-in of any generated parameter files to the system library')
|
|
212
|
+
command_parsers['parameterize'].add_argument('--no-banner',default=False,action='store_true',help='turn off the banner')
|
|
213
|
+
command_parsers['parameterize'].add_argument('--loglevel',type=str,default='debug',help='Log level for messages written to diagnostic log (debug|info)')
|
|
214
|
+
######## plots ########
|
|
215
|
+
command_parsers['plots'].add_argument('source',type=str,choices=['diag','build','post'],default='build',help='source of data to plot')
|
|
216
|
+
command_parsers['plots'].add_argument('--diags',type=str,default=[],nargs='+',help='names of diagnostic log files (1 or more)')
|
|
217
|
+
command_parsers['plots'].add_argument('--proj',nargs='+',type=str,default=[],help='name of project director[y/ies]')
|
|
218
|
+
command_parsers['plots'].add_argument('--cfg',type=str,nargs='+',default=[],help='name input config files')
|
|
219
|
+
command_parsers['plots'].add_argument('--buildplot',type=str,nargs='+',default=['t'],choices=['t','g','n','c'],help='type of build plot to generate: t: traces (select using --traces); g: 2-D graph representations iteration by iteration; n: homo-N between crosslinks; c: cluster-size distributions')
|
|
220
|
+
command_parsers['plots'].add_argument('--traces',type=str,nargs='+',default=['t','d','p'],choices=['t','d','p'],help='type of traces to plot from build: t: temperature; d: density; p: potential energy')
|
|
221
|
+
command_parsers['plots'].add_argument('--n_points',type=int,nargs=2,default=[10,20],help='number of [cold-side,hot-side] data points in the Tg analysis to fit lines to')
|
|
222
|
+
|
|
223
|
+
command_parsers['plots'].add_argument('--plotfile',type=str,default='',help='name of plot file to generate')
|
|
224
|
+
command_parsers['plots'].add_argument('--no-banner',default=False,action='store_true',help='turn off the banner')
|
|
225
|
+
command_parsers['plots'].add_argument('--loglevel',type=str,default='info',help='Log level for messages written to diagnostic log (debug|info)')
|
|
226
|
+
######## fetch-example ########
|
|
227
|
+
command_parsers['fetch-example'].add_argument('-n',type=str,choices=example_ids+['all'],help='number of example tarball to unpack from '+', '.join(example_names))
|
|
228
|
+
command_parsers['fetch-example'].add_argument('-k',default=False,action='store_true',help='keep tarballs')
|
|
229
|
+
######## pack-example
|
|
230
|
+
command_parsers['pack-example'].add_argument('-n',type=int,default=-1,help='desired index (integer) for this example')
|
|
231
|
+
######## input-check ########
|
|
232
|
+
command_parsers['input-check'].add_argument('config',type=str,default=None,help='input configuration file in YAML format')
|
|
233
|
+
command_parsers['input-check'].add_argument('-lib',type=str,default='lib',help='local user library of molecular structures and parameterizations')
|
|
234
|
+
######## postsim ########
|
|
235
|
+
command_parsers['postsim'].add_argument('-proj',type=str,default='',nargs='+',help='name of project directory')
|
|
236
|
+
command_parsers['postsim'].add_argument('-lib',type=str,default='lib',help='local user library of molecular structures and parameterizations')
|
|
237
|
+
command_parsers['postsim'].add_argument('-ocfg',type=str,default='',help='original HTPolyNet config file used to generate project(s)')
|
|
238
|
+
command_parsers['postsim'].add_argument('-cfg',type=str,default='',help='config file for specifying the MD simulations to perform')
|
|
239
|
+
command_parsers['postsim'].add_argument('--no-banner',default=False,action='store_true',help='turn off the banner')
|
|
240
|
+
command_parsers['postsim'].add_argument('--loglevel',type=str,default='info',help='Log level for messages written to diagnostic log (debug|info)')
|
|
241
|
+
|
|
242
|
+
######## analyze ########
|
|
243
|
+
command_parsers['analyze'].add_argument('-proj',type=str,default='',nargs='+',help='name of project directory')
|
|
244
|
+
command_parsers['analyze'].add_argument('-lib',type=str,default='lib',help='local user library of molecular structures and parameterizations')
|
|
245
|
+
command_parsers['analyze'].add_argument('-ocfg',type=str,default='',help='original HTPolyNet config file used to generate project(s)')
|
|
246
|
+
command_parsers['analyze'].add_argument('-cfg',type=str,default='',help='config file for specifying the analyses to perform')
|
|
247
|
+
command_parsers['analyze'].add_argument('--no-banner',default=False,action='store_true',help='turn off the banner')
|
|
248
|
+
command_parsers['analyze'].add_argument('--loglevel',type=str,default='info',help='Log level for messages written to diagnostic log (debug|info)')
|
|
249
|
+
args=parser.parse_args()
|
|
250
|
+
args.func(args)
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"""
|
|
2
|
+
|
|
3
|
+
.. module:: expandreactions
|
|
4
|
+
:synopsis: handles expansion of reactions based on chains
|
|
5
|
+
|
|
6
|
+
.. moduleauthor: Cameron F. Abrams, <cfa22@drexel.edu>
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
from itertools import product
|
|
10
|
+
import logging
|
|
11
|
+
from HTPolyNet.molecule import Molecule, MoleculeList, MoleculeDict
|
|
12
|
+
from HTPolyNet.reaction import reaction_stage, Reaction, ReactionList
|
|
13
|
+
|
|
14
|
+
logger=logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
def chain_expand_reactions(molecules:MoleculeDict):
|
|
17
|
+
"""chain_expand_reactions handles generation of new reactions and molecular templates implied by any C-C chaining
|
|
18
|
+
|
|
19
|
+
Note
|
|
20
|
+
----
|
|
21
|
+
must be called after all grx attributes are set for all molecules
|
|
22
|
+
|
|
23
|
+
:param molecules: dictionary of molecular templates constructed from explicit declarations
|
|
24
|
+
:type molecules: MoleculeDict
|
|
25
|
+
:return: the list of new reactions and dictionary of new molecules
|
|
26
|
+
:rtype: tuple(ReactionList,MoleculeDict)
|
|
27
|
+
"""
|
|
28
|
+
extra_reactions:ReactionList=[]
|
|
29
|
+
extra_molecules:MoleculeDict={}
|
|
30
|
+
monomers:MoleculeList=[]
|
|
31
|
+
dimer_lefts:MoleculeList=[]
|
|
32
|
+
dimer_rights:MoleculeList=[]
|
|
33
|
+
for mname,M in molecules.items():
|
|
34
|
+
if len(M.sequence)==1 and len(M.TopoCoord.idx_lists['chain'])>0 and M.generator==None and M.parentname==M.name:
|
|
35
|
+
monomers.append(M)
|
|
36
|
+
elif len(M.sequence)==2:
|
|
37
|
+
A=molecules[M.sequence[0]]
|
|
38
|
+
if len(A.TopoCoord.idx_lists['chain'])>0:
|
|
39
|
+
dimer_lefts.append(M)
|
|
40
|
+
A=molecules[M.sequence[1]]
|
|
41
|
+
if len(A.TopoCoord.idx_lists['chain'])>0:
|
|
42
|
+
dimer_rights.append(M)
|
|
43
|
+
for mon in monomers:
|
|
44
|
+
cnms=[]
|
|
45
|
+
for c in mon.TopoCoord.idx_lists['chain']:
|
|
46
|
+
cnms.append([mon.TopoCoord.get_gro_attribute_by_attributes('atomName',{'globalIdx':x}) for x in c])
|
|
47
|
+
logger.debug(f'Monomer {mon.name} has {len(mon.TopoCoord.idx_lists["chain"])} 2-chains: {mon.TopoCoord.idx_lists["chain"]} {cnms}')
|
|
48
|
+
|
|
49
|
+
for dim in dimer_lefts:
|
|
50
|
+
logger.debug(f'Dimer_left {dim.name} has sequence {dim.sequence}')
|
|
51
|
+
logger.debug(f'-> chains: {dim.TopoCoord.idx_lists["chain"]}')
|
|
52
|
+
for cl in dim.TopoCoord.idx_lists['chain']:
|
|
53
|
+
nl=[dim.TopoCoord.get_gro_attribute_by_attributes('atomName',{'globalIdx':x}) for x in cl]
|
|
54
|
+
logger.debug(f' -> {nl}')
|
|
55
|
+
for dim in dimer_rights:
|
|
56
|
+
logger.debug(f'Dimer_right {dim.name} has sequence {dim.sequence}')
|
|
57
|
+
logger.debug(f'-> chains: {dim.TopoCoord.idx_lists["chain"]}')
|
|
58
|
+
for cl in dim.TopoCoord.idx_lists['chain']:
|
|
59
|
+
nl=[dim.TopoCoord.get_gro_attribute_by_attributes('atomName',{'globalIdx':x}) for x in cl]
|
|
60
|
+
logger.debug(f' -> {nl}')
|
|
61
|
+
|
|
62
|
+
# monomer head attacks dimer tail
|
|
63
|
+
MD=product(monomers,dimer_lefts)
|
|
64
|
+
for m,d in MD:
|
|
65
|
+
for mb in m.TopoCoord.idx_lists['chain']:
|
|
66
|
+
h_idx=mb[0]
|
|
67
|
+
h_name=m.TopoCoord.get_gro_attribute_by_attributes('atomName',{'globalIdx':h_idx})
|
|
68
|
+
# by definition, the dimer must have one chain of length 4
|
|
69
|
+
D4=[]
|
|
70
|
+
for dc in d.TopoCoord.idx_lists['chain']:
|
|
71
|
+
if len(dc)==4:
|
|
72
|
+
D4.append(dc)
|
|
73
|
+
for DC in D4:
|
|
74
|
+
t_idx=DC[-1]
|
|
75
|
+
t_name=d.TopoCoord.get_gro_attribute_by_attributes('atomName',{'globalIdx':t_idx})
|
|
76
|
+
new_mname=f'{m.name}~{h_name}={t_name}~{d.name}'
|
|
77
|
+
'''construct reaction'''
|
|
78
|
+
R=Reaction()
|
|
79
|
+
R.reactants={1:m.name, 2:d.name}
|
|
80
|
+
R.atoms={'A':{'reactant':1,'resid':1,'atom':h_name,'z':1},
|
|
81
|
+
'B':{'reactant':2,'resid':1,'atom':t_name,'z':1}}
|
|
82
|
+
R.bonds=[{'atoms':['A','B'],'order':1}]
|
|
83
|
+
R.stage=reaction_stage.param
|
|
84
|
+
R.name=new_mname.lower()
|
|
85
|
+
R.product=new_mname
|
|
86
|
+
newP=Molecule.New(R.product,R).set_sequence_from_moldict(molecules)
|
|
87
|
+
newP.set_origin('unparameterized')
|
|
88
|
+
extra_molecules[R.product]=newP
|
|
89
|
+
logger.debug(f'monomer atom {m.name}_{h_name} will attack dimer atom {d.name}[{d.sequence[0]}1_{t_name}] -> {new_mname}:')
|
|
90
|
+
for ln in str(R).split('\n'):
|
|
91
|
+
logger.debug(ln)
|
|
92
|
+
extra_reactions.append(R)
|
|
93
|
+
# dimer head attacks monomer tail
|
|
94
|
+
MD=product(monomers,dimer_rights)
|
|
95
|
+
for m,d in MD:
|
|
96
|
+
for mb in m.TopoCoord.idx_lists['chain']:
|
|
97
|
+
assert len(mb)==2,f'monomer {m.name} has a chain that is not length-2 -- this is IMPOSSIBLE'
|
|
98
|
+
t_idx=mb[-1]
|
|
99
|
+
t_name=m.TopoCoord.get_gro_attribute_by_attributes('atomName',{'globalIdx':t_idx})
|
|
100
|
+
D4=[]
|
|
101
|
+
for dc in d.TopoCoord.idx_lists['chain']:
|
|
102
|
+
if len(dc)==4:
|
|
103
|
+
D4.append(dc)
|
|
104
|
+
for DC in D4:
|
|
105
|
+
h_idx=DC[0]
|
|
106
|
+
h_name=d.TopoCoord.get_gro_attribute_by_attributes('atomName',{'globalIdx':h_idx})
|
|
107
|
+
new_mname=f'{d.name}~{h_name}={t_name}~{m.name}'
|
|
108
|
+
'''construct reaction'''
|
|
109
|
+
R=Reaction()
|
|
110
|
+
R.reactants={1:d.name, 2:m.name}
|
|
111
|
+
R.atoms={'A':{'reactant':1,'resid':2,'atom':h_name,'z':1},
|
|
112
|
+
'B':{'reactant':2,'resid':1,'atom':t_name,'z':1}}
|
|
113
|
+
R.bonds=[{'atoms':['A','B'],'order':1}]
|
|
114
|
+
R.stage=reaction_stage.param
|
|
115
|
+
new_rxnname=new_mname.lower()
|
|
116
|
+
R.name=new_rxnname
|
|
117
|
+
R.product=new_mname
|
|
118
|
+
newP=Molecule.New(R.product,R).set_sequence_from_moldict(molecules)
|
|
119
|
+
newP.set_origin('unparameterized')
|
|
120
|
+
extra_molecules[R.product]=newP
|
|
121
|
+
logger.debug(f'dimer atom {d.name}[{d.sequence[1]}2_{h_name}] will attack monomer atom {m.name}_{t_name}-> {new_mname}:')
|
|
122
|
+
for ln in str(R).split('\n'):
|
|
123
|
+
logger.debug(ln)
|
|
124
|
+
extra_reactions.append(R)
|
|
125
|
+
|
|
126
|
+
DD=product(dimer_rights,dimer_lefts)
|
|
127
|
+
for dr,dl in DD:
|
|
128
|
+
''' head of dr attacks tail of dl '''
|
|
129
|
+
for cr,cl in product(dr.TopoCoord.idx_lists['chain'],dl.TopoCoord.idx_lists['chain']):
|
|
130
|
+
if len(cr)==4 and len(cl)==4:
|
|
131
|
+
h_idx=cr[0]
|
|
132
|
+
h_name=dr.TopoCoord.get_gro_attribute_by_attributes('atomName',{'globalIdx':h_idx})
|
|
133
|
+
t_idx=cl[-1]
|
|
134
|
+
t_name=dl.TopoCoord.get_gro_attribute_by_attributes('atomName',{'globalIdx':t_idx})
|
|
135
|
+
new_mname=f'{dr.name}~{h_name}={t_name}~{dl.name}'
|
|
136
|
+
'''construct reaction'''
|
|
137
|
+
R=Reaction()
|
|
138
|
+
R.reactants={1:dr.name, 2:dl.name}
|
|
139
|
+
R.atoms={'A':{'reactant':1,'resid':2,'atom':h_name,'z':1},
|
|
140
|
+
'B':{'reactant':2,'resid':1,'atom':t_name,'z':1}}
|
|
141
|
+
R.bonds=[{'atoms':['A','B'],'order':1}]
|
|
142
|
+
R.stage=reaction_stage.param
|
|
143
|
+
R.product=new_mname
|
|
144
|
+
R.name=R.product.lower()
|
|
145
|
+
# newP=Molecule(name=R.product,generator=R)
|
|
146
|
+
newP=Molecule.New(R.product,R).set_sequence_from_moldict(molecules)
|
|
147
|
+
newP.set_origin('unparameterized')
|
|
148
|
+
extra_molecules[R.product]=newP
|
|
149
|
+
logger.debug(f'dimer atom {dr.name}-{dr.sequence[1]}2_{h_name} will attack dimer atom {dl.name}-{dl.sequence[0]}1_{t_name} -> {new_mname}:')
|
|
150
|
+
for ln in str(R).split('\n'):
|
|
151
|
+
logger.debug(ln)
|
|
152
|
+
extra_reactions.append(R)
|
|
153
|
+
|
|
154
|
+
return extra_reactions, extra_molecules
|