HTPolyNet 1.0.7.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. HTPolyNet/__init__.py +1 -0
  2. HTPolyNet/ambertools.py +94 -0
  3. HTPolyNet/analyze.py +258 -0
  4. HTPolyNet/banner.py +26 -0
  5. HTPolyNet/bondlist.py +206 -0
  6. HTPolyNet/bondtemplate.py +111 -0
  7. HTPolyNet/checkpoint.py +88 -0
  8. HTPolyNet/command.py +42 -0
  9. HTPolyNet/configuration.py +240 -0
  10. HTPolyNet/coordinates.py +1071 -0
  11. HTPolyNet/countTime.py +26 -0
  12. HTPolyNet/curecontroller.py +767 -0
  13. HTPolyNet/dataframetools.py +130 -0
  14. HTPolyNet/driver.py +250 -0
  15. HTPolyNet/expandreactions.py +154 -0
  16. HTPolyNet/gromacs.py +333 -0
  17. HTPolyNet/inputcheck.py +51 -0
  18. HTPolyNet/linkcell.py +322 -0
  19. HTPolyNet/molecule.py +1279 -0
  20. HTPolyNet/plot.py +607 -0
  21. HTPolyNet/postsim.py +444 -0
  22. HTPolyNet/projectfilesystem.py +483 -0
  23. HTPolyNet/reaction.py +282 -0
  24. HTPolyNet/resources/README.md +20 -0
  25. HTPolyNet/resources/__init__.py +0 -0
  26. HTPolyNet/resources/cfg/DGE-PAC-hi.yaml +115 -0
  27. HTPolyNet/resources/cfg/DGE-PAC-lo.yaml +115 -0
  28. HTPolyNet/resources/cfg/FDE-DFDA-hi.yaml +116 -0
  29. HTPolyNet/resources/cfg/FDE-DFDA-lo.yaml +116 -0
  30. HTPolyNet/resources/cfg/GMASTY-hi.yaml +158 -0
  31. HTPolyNet/resources/cfg/GMASTY-lo.yaml +158 -0
  32. HTPolyNet/resources/cfg/README.md +1 -0
  33. HTPolyNet/resources/cfg/STY.yaml +23 -0
  34. HTPolyNet/resources/cfg/pMSTY-hi.yaml +101 -0
  35. HTPolyNet/resources/cfg/pMSTY-lo.yaml +101 -0
  36. HTPolyNet/resources/cfg/pSTY-hi.yaml +101 -0
  37. HTPolyNet/resources/cfg/pSTY-lo.yaml +101 -0
  38. HTPolyNet/resources/example_depot/0-liquid-styrene.tgz +0 -0
  39. HTPolyNet/resources/example_depot/1-polystyrene.tgz +0 -0
  40. HTPolyNet/resources/example_depot/2-polymethylstyrene.tgz +0 -0
  41. HTPolyNet/resources/example_depot/3-bisgma-styrene-thermoset.tgz +0 -0
  42. HTPolyNet/resources/example_depot/4-pacm-dgeba-epoxy-thermoset.tgz +0 -0
  43. HTPolyNet/resources/example_depot/5-dfda-fde-epoxy-thermoset.tgz +0 -0
  44. HTPolyNet/resources/mdp/README.md +1 -0
  45. HTPolyNet/resources/mdp/drag-min.mdp +13 -0
  46. HTPolyNet/resources/mdp/drag-npt.mdp +36 -0
  47. HTPolyNet/resources/mdp/drag-nvt.mdp +31 -0
  48. HTPolyNet/resources/mdp/min.mdp +14 -0
  49. HTPolyNet/resources/mdp/npt.mdp +37 -0
  50. HTPolyNet/resources/mdp/nvt.mdp +29 -0
  51. HTPolyNet/resources/mdp/relax-min.mdp +13 -0
  52. HTPolyNet/resources/mdp/relax-npt.mdp +37 -0
  53. HTPolyNet/resources/mdp/relax-nvt.mdp +31 -0
  54. HTPolyNet/resources/mdp/single-molecule-min.mdp +12 -0
  55. HTPolyNet/resources/mdp/single-molecule-nvt.mdp +25 -0
  56. HTPolyNet/resources/molecules/inputs/DFA.pdb +62 -0
  57. HTPolyNet/resources/molecules/inputs/DGE.mol2 +115 -0
  58. HTPolyNet/resources/molecules/inputs/EMB.mol2 +50 -0
  59. HTPolyNet/resources/molecules/inputs/FDE.pdb +72 -0
  60. HTPolyNet/resources/molecules/inputs/GMA.mol2 +163 -0
  61. HTPolyNet/resources/molecules/inputs/PAC.mol2 +91 -0
  62. HTPolyNet/resources/molecules/inputs/STY.mol2 +44 -0
  63. HTPolyNet/resources/molecules/make-monomers.sh +64 -0
  64. HTPolyNet/resources/molecules/pics/DFA.png +0 -0
  65. HTPolyNet/resources/molecules/pics/DGE.png +0 -0
  66. HTPolyNet/resources/molecules/pics/EMB.png +0 -0
  67. HTPolyNet/resources/molecules/pics/FDE.png +0 -0
  68. HTPolyNet/resources/molecules/pics/GMA.png +0 -0
  69. HTPolyNet/resources/molecules/pics/PAC.png +0 -0
  70. HTPolyNet/resources/molecules/pics/STY.png +0 -0
  71. HTPolyNet/resources/molecules/sample-inputs/DFA.pdb +62 -0
  72. HTPolyNet/resources/molecules/sample-inputs/DGE.mol2 +115 -0
  73. HTPolyNet/resources/molecules/sample-inputs/EMB.mol2 +50 -0
  74. HTPolyNet/resources/molecules/sample-inputs/FDE.pdb +72 -0
  75. HTPolyNet/resources/molecules/sample-inputs/GMA.mol2 +163 -0
  76. HTPolyNet/resources/molecules/sample-inputs/PAC.mol2 +91 -0
  77. HTPolyNet/resources/molecules/sample-inputs/STY.mol2 +44 -0
  78. HTPolyNet/resources/tcl/readbonds.tcl +32 -0
  79. HTPolyNet/resources/tcl/readgrx.tcl +46 -0
  80. HTPolyNet/resources/tcl/render.tcl +74 -0
  81. HTPolyNet/ring.py +155 -0
  82. HTPolyNet/runtime.py +709 -0
  83. HTPolyNet/software.py +106 -0
  84. HTPolyNet/stringthings.py +39 -0
  85. HTPolyNet/topocoord.py +1877 -0
  86. HTPolyNet/topology.py +1288 -0
  87. HTPolyNet/unused_symmetry_stuff.py +291 -0
  88. HTPolyNet/utils.py +405 -0
  89. htpolynet-1.0.7.2.dist-info/METADATA +84 -0
  90. htpolynet-1.0.7.2.dist-info/RECORD +93 -0
  91. htpolynet-1.0.7.2.dist-info/WHEEL +4 -0
  92. htpolynet-1.0.7.2.dist-info/entry_points.txt +2 -0
  93. htpolynet-1.0.7.2.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,111 @@
1
+ """
2
+
3
+ .. module:: bondtemplate
4
+ :synopsis: Manages bond templates (bonds defined by type) and reaction bonds (bonds defined by instances)
5
+
6
+ .. moduleauthor: Cameron F. Abrams, <cfa22@drexel.edu>
7
+
8
+ """
9
+ import logging
10
+ from copy import deepcopy
11
+
12
+ class BondTemplate:
13
+ def __init__(self,names,resnames,intraresidue,order,bystander_resnames,bystander_atomnames,oneaway_resnames,oneaway_atomnames):
14
+ """__init__ create a BondTemplate object
15
+
16
+ :param names: names of atoms in the bond
17
+ :type names: list-like container of two ints
18
+ :param resnames: names of the two residues to which the atoms belong
19
+ :type resnames: list-like container of two strs
20
+ :param intraresidue: True if this is an intraresidue bond
21
+ :type intraresidue: bool
22
+ :param order: bond order (1=single, 2=double, ...)
23
+ :type order: int
24
+ :param bystander_resnames: lists of names of bystander residues (residues also bound to one of the atoms)
25
+ :type bystander_resnames: list of two list-like containers of strs, one for each atom in names
26
+ :param bystander_atomnames: lists of names of atoms in bystander residues
27
+ :type bystander_atomnames: list of two list-like containers of strs (parallel to bystander_resnames)
28
+ :param oneaway_resnames: names of one-away residues (residues bound one bond away from the new interresidue bond; only relevant for C=C free-radical polymerization)
29
+ :type oneaway_resnames: list-like container of strs
30
+ :param oneaway_atomnames: names of atoms in one-away residues
31
+ :type oneaway_atomnames: list-like container of strs
32
+ """
33
+ self.names=names
34
+ self.resnames=resnames
35
+ self.intraresidue=intraresidue
36
+ self.bystander_resnames=bystander_resnames
37
+ self.bystander_atomnames=bystander_atomnames
38
+ self.oneaway_resnames=oneaway_resnames
39
+ self.oneaway_atomnames=oneaway_atomnames
40
+ self.order=order
41
+ def reverse(self):
42
+ """reverse the order of all parallel lists in a BondTemplate object
43
+ """
44
+ self.names=self.names[::-1]
45
+ self.resnames=self.resnames[::-1]
46
+ self.bystander_resnames=self.bystander_resnames[::-1]
47
+ self.bystander_atomnames=self.bystander_atomnames[::-1]
48
+ self.oneaway_resnames=self.oneaway_resnames[::-1]
49
+ self.oneaway_atomnames=self.oneaway_atomnames[::-1]
50
+ def __str__(self):
51
+ return f'BondTemplate {self.names} resnames {self.resnames} intraresidue? {self.intraresidue} order {self.order} bystander-resnames {self.bystander_resnames} bystander-atomnames {self.bystander_atomnames} oneaway-resnames {self.oneaway_resnames} oneaway-atomnames {self.oneaway_atomnames}'
52
+ def __eq__(self,other):
53
+ check=self.names==other.names
54
+ check=check and self.intraresidue==other.intraresidue
55
+ check=check and self.resnames==other.resnames
56
+ check=check and self.bystander_resnames==other.bystander_resnames
57
+ check=check and self.bystander_atomnames==other.bystander_atomnames
58
+ check=check and self.oneaway_resnames==other.oneaway_resnames
59
+ check=check and self.oneaway_atomnames==other.oneaway_atomnames
60
+ return check
61
+ def is_reverse_of(self,other):
62
+ """is_reverse_of return True if self and other are reverse of each other
63
+
64
+ :param other: another BondTemplate object
65
+ :type other: BondTemplate
66
+ :return: True if self and other are reverse copies of each other
67
+ :rtype: bool
68
+ """
69
+ rb=deepcopy(other)
70
+ rb.reverse()
71
+ return self==rb
72
+
73
+ BondTemplateList=list[BondTemplate]
74
+
75
+ class ReactionBond:
76
+ def __init__(self,idx,resids,order,bystanders,bystanders_atomidx,oneaways,oneaways_atomidx):
77
+ """__init__ generate a new ReactionBond object
78
+
79
+ :param idx: indices of two atoms that form the bond
80
+ :type idx: list-like container of two ints
81
+ :param resids: resids of the two atoms that form the bond
82
+ :type resids: list-like container of two ints
83
+ :param order: order of the bond (1=single, 2=double, ...)
84
+ :type order: int
85
+ :param bystanders: two lists of indices of interresidue resids already bound to each atom in idx
86
+ :type bystanders: list of two list-like containers of ints
87
+ :param bystanders_atomidx: two lists of indices of interresidue atoms already bound to each atom in idx
88
+ :type bystanders_atomidx: list of two list-like containers of ints
89
+ :param oneaways: list of one-away resids
90
+ :type oneaways: list of ints
91
+ :param oneaways_atomidx: list of one-away atom indices
92
+ :type oneaways_atomidx: list of ints
93
+ """
94
+ self.idx=idx
95
+ self.resids=resids
96
+ self.bystander_resids=bystanders
97
+ self.bystander_atomidx=bystanders_atomidx
98
+ self.oneaway_resids=oneaways
99
+ self.oneaway_atomidx=oneaways_atomidx
100
+ self.order=order
101
+ def reverse(self):
102
+ self.idx=self.idx[::-1]
103
+ self.resids=self.resids[::-1]
104
+ self.bystander_resids=self.bystander_resids[::-1]
105
+ self.bystander_atomidx=self.bystander_atomidx[::-1]
106
+ self.oneaway_resids=self.oneaway_resids[::-1]
107
+ self.oneaway_atomidx=self.oneaway_atomidx[::-1]
108
+ def __str__(self):
109
+ return f'ReactionBond {self.idx} resids {self.resids} order {self.order} bystander-resids {self.bystander_resids} oneaway-resids {self.oneaway_resids} oneaway-atomidx {self.oneaway_atomidx}'
110
+
111
+ ReactionBondList=list[ReactionBond]
@@ -0,0 +1,88 @@
1
+ """
2
+
3
+ .. module:: checkpoint
4
+ :synopsis: Implements a simple checkpointing scheme using a wrapper
5
+
6
+ .. moduleauthor: Cameron F. Abrams, <cfa22@drexel.edu>
7
+
8
+ """
9
+ import os
10
+ import yaml
11
+ import logging
12
+ import functools
13
+
14
+ logger=logging.getLogger(__name__)
15
+
16
+ class Checkpoint:
17
+ default_filename='checkpoint_state.yaml'
18
+ def __init__(self,input_dict={}):
19
+ self.my_abspath=os.getcwd()
20
+ self.calls:list=input_dict.get('calls',[])
21
+ self.results:dict=input_dict.get('results',{})
22
+ self.narrative:list=input_dict.get('narrative',[])
23
+
24
+ def to_yaml(self):
25
+ with open(self.default_filename,'w') as f:
26
+ f.write(yaml.dump(self))
27
+
28
+ @classmethod
29
+ def from_yaml(cls):
30
+ try:
31
+ with open(cls.default_filename,'r') as f:
32
+ yaml_string=f.read()
33
+ inst=yaml.load(yaml_string,Loader=yaml.Loader)
34
+ # overwrite the absolute path in the file upon reading in
35
+ inst.my_abspath=os.getcwd()
36
+ return inst
37
+ except FileNotFoundError:
38
+ return cls()
39
+
40
+ _CP_=Checkpoint()
41
+
42
+ def enableCheckpoint(method):
43
+ """enableCheckpoint wraps any method so that every call is registered in a history of calls in a written checkpoint file
44
+
45
+ :param method: name of method to be wrapped
46
+ :type method: method
47
+ :return: wrapped method
48
+ :rtype: method
49
+ """
50
+ @functools.wraps(method)
51
+ def wrapper_method(self,*args,**kwargs):
52
+ ''' define working directory as current directory relative to the checkpoint '''
53
+ mywd=os.path.relpath(os.getcwd(),_CP_.my_abspath)
54
+ ''' if the method calling this from the current directory is already in the checkpoint history,
55
+ to not call the method, just return '''
56
+ if len(_CP_.calls)>0 and (method.__name__,mywd) in _CP_.calls:
57
+ logger.info(f'Skipping {method.__name__} in {mywd}')
58
+ return
59
+ ''' call the method, save result '''
60
+ result=method(self,*args,**kwargs)
61
+ ''' register this method call in this directory and its results '''
62
+ _CP_.calls.append((method.__name__,mywd))
63
+ _CP_.results.update(result) # must be a dict
64
+ _CP_.narrative.append(f'Method {method.__name__} called in {os.path.join(_CP_.my_abspath,mywd)} gave result {result}')
65
+ ''' update the written checkpoint file '''
66
+ _write_checkpoint()
67
+ return result
68
+ return wrapper_method
69
+
70
+ def _write_checkpoint():
71
+ """_write_checkpoint writes the checkpoint file in its globally resolved location
72
+ """
73
+ sv=os.getcwd()
74
+ os.chdir(_CP_.my_abspath)
75
+ _CP_.to_yaml()
76
+ os.chdir(sv)
77
+
78
+ def read_checkpoint():
79
+ """read_checkpoint creates a new global Checkpoint object by reading from the default file
80
+
81
+ :return: current results dictionary with any pathnames resolved as absolute
82
+ :rtype: dict
83
+ """
84
+ global _CP_
85
+ _CP_=Checkpoint.from_yaml()
86
+ if len(_CP_.calls)>0:
87
+ lwd=os.path.join(_CP_.my_abspath,_CP_.calls[-1][1])
88
+ return {c:os.path.join(lwd,x) for c,x in _CP_.results.items()}
HTPolyNet/command.py ADDED
@@ -0,0 +1,42 @@
1
+ """
2
+
3
+ .. module:: command
4
+ :synopsis: Custom handling of calls to subprocess.Popen()
5
+
6
+ .. moduleauthor: Cameron F. Abrams, <cfa22@drexel.edu>
7
+
8
+ """
9
+ import logging
10
+ import subprocess
11
+ logger=logging.getLogger(__name__)
12
+
13
+ class Command:
14
+ linelen=55
15
+ def __init__(self,command,**options):
16
+ self.command=command
17
+ self.options=options
18
+ self.c=f'{self.command} '+' '.join([f'-{k} {v}' for k,v in self.options.items()])
19
+
20
+ def run(self,override=(),ignore_codes=[],quiet=True):
21
+ if not quiet:
22
+ logger.debug(f'{self.c}')
23
+ process=subprocess.Popen(self.c,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE,text=True)
24
+ out,err=process.communicate()
25
+ if process.returncode!=0 and not process.returncode in ignore_codes:
26
+ logger.error(f'Returncode: {process.returncode}')
27
+ if len(out)>0:
28
+ logger.error('stdout buffer follows\n'+'*'*self.linelen+'\n'+out+'\n'+'*'*self.linelen)
29
+ if len(err)>0:
30
+ logger.error('stderr buffer follows\n'+'*'*self.linelen+'\n'+err+'\n'+'*'*self.linelen)
31
+ raise subprocess.SubprocessError(f'Command "{self.c}" failed with returncode {process.returncode}')
32
+ else:
33
+ if len(override)==2:
34
+ needle,msg=override
35
+ if needle in out or needle in err:
36
+ logger.error(f'Returncode: {process.returncode}, but another error was detected:')
37
+ logger.error(msg)
38
+ if len(out)>0:
39
+ logger.error('stdout buffer follows\n'+'*'*self.linelen+'\n'+out+'\n'+'*'*self.linelen)
40
+ if len(err)>0:
41
+ logger.error('stderr buffer follows\n'+'*'*self.linelen+'\n'+err+'\n'+'*'*self.linelen)
42
+ return out,err
@@ -0,0 +1,240 @@
1
+ """
2
+
3
+ .. module:: configuration
4
+ :synopsis: Manages reading and parsing of YAML configuration files
5
+
6
+ .. moduleauthor: Cameron F. Abrams, <cfa22@drexel.edu>
7
+
8
+ """
9
+ import json
10
+ import yaml
11
+ import os
12
+ import logging
13
+ from collections import namedtuple
14
+ from HTPolyNet.molecule import Molecule, MoleculeDict, generate_stereo_reactions, generate_symmetry_reactions
15
+ from HTPolyNet.reaction import Reaction, ReactionList, parse_reaction_list, extract_molecule_reactions, reaction_stage
16
+
17
+ logger=logging.getLogger(__name__)
18
+
19
+ class Configuration:
20
+ default_directives = {
21
+ 'Title': 'No title provided',
22
+ 'constituents': {},
23
+ 'reactions':[],
24
+ 'densification':{},
25
+ 'precure':{},
26
+ 'postcure':{},
27
+ 'CURE':{},
28
+ 'ambertools':{},
29
+ 'gromacs':{}
30
+ }
31
+ def __init__(self):
32
+ self.cfgFile = ''
33
+ self.Title = ''
34
+ ''' List of (Molecule, count) '''
35
+ self.constituents = {}
36
+ ''' Dictionary of name:Molecule '''
37
+ self.molecules:MoleculeDict = {}
38
+ ''' List of Reaction instances '''
39
+ self.reactions:ReactionList = []
40
+ ''' all other parameters in cfg file '''
41
+ self.parameters = {}
42
+
43
+ self.molecule_report={}
44
+
45
+ self.initial_composition = []
46
+ ''' raw dict read from JSON/YAML '''
47
+ self.basedict = {}
48
+ self.maxconv=0.0
49
+
50
+ @classmethod
51
+ def read(cls,filename,parse=True,**kwargs):
52
+ """read generates a new Configuration object by reading in the JSON or YAML file indicated by filename
53
+
54
+ :param filename: name of file from which to read new Configuration object
55
+ :type filename: str
56
+ :param parse: if True, parse the input configuration file, defaults to True
57
+ :type parse: bool, optional
58
+ :raises Exception: if extension of filename is not '.json' or '.yaml' or '.yml'
59
+ :return: a new Configuration object
60
+ :rtype: Configuration
61
+ """
62
+ basename,extension=os.path.splitext(filename)
63
+ if extension=='.json':
64
+ return cls._read_json(filename,parse,**kwargs)
65
+ elif extension=='.yaml' or extension=='.yml':
66
+ return cls._read_yaml(filename,parse,**kwargs)
67
+ else:
68
+ raise Exception(f'Unknown config file extension {extension}')
69
+
70
+ @classmethod
71
+ def _read_json(cls,filename,parse=True,**kwargs):
72
+ """_read_json create a new Configuration object by reading from JSON input
73
+
74
+ :param filename: name of JSON file
75
+ :type filename: str
76
+ :param parse: if True, parse the JSON data, defaults to True
77
+ :type parse: bool, optional
78
+ :return: a new Configuration object
79
+ :rtype: Configuration
80
+ """
81
+ inst=cls()
82
+ inst.cfgFile=filename
83
+ with open(filename,'r') as f:
84
+ inst.basedict=json.load(f)
85
+ if parse: inst.parse(**kwargs)
86
+ return inst
87
+
88
+ @classmethod
89
+ def _read_yaml(cls,filename,parse=True,**kwargs):
90
+ """_read_yaml create a new Configuration object by reading from YAML input
91
+
92
+ :param filename: name of YAML file
93
+ :type filename: str
94
+ :param parse: if True, parse the YAML data, defaults to True
95
+ :type parse: bool, optional
96
+ :return: a new Configuration object
97
+ :rtype: Configuration
98
+ """
99
+ inst=cls()
100
+ inst.cfgFile=filename
101
+ with open(filename,'r') as f:
102
+ inst.basedict=yaml.safe_load(f)
103
+ if parse: inst.parse(**kwargs)
104
+ return inst
105
+
106
+ def NewMolecule(self,mol_name,molrec={}):
107
+ """NewMolecule generate and return a new Molecule object with name mol_name and populated via directives in molrec
108
+
109
+ :param mol_name: name of new molecule
110
+ :type mol_name: str
111
+ :param molrec: dictionary of new molecule directives, defaults to {}
112
+ :type molrec: dict, optional
113
+ :return: the new Molecule object
114
+ :rtype: Molecule
115
+ """
116
+ return Molecule.New(mol_name,molrec)
117
+
118
+ def parse(self,**kwargs):
119
+ """parse self.basedict to set Title, initial_composition, and lists of
120
+ reactions and molecules.
121
+ """
122
+ plot_reaction_network=kwargs.get('plot_reaction_network',True)
123
+ assert not self.basedict=={},f'Reading error for config'
124
+ for d in self.basedict.keys():
125
+ if not d in self.default_directives:
126
+ logging.debug(f'Ignoring unknown directive "{d}" in {self.cfgFile}')
127
+
128
+ self.Title=self.basedict.get('Title',self.default_directives['Title'])
129
+ self.parameters=self.basedict
130
+ if not 'ncpu' in self.parameters:
131
+ self.parameters['ncpu']=os.cpu_count()
132
+
133
+ self.constituents=self.basedict.get('constituents',{})
134
+ rlist=self.basedict.get('reactions',[])
135
+
136
+ base_reaction_list=[Reaction(r) for r in rlist]
137
+ self.reactions=parse_reaction_list(base_reaction_list)
138
+ mol_reac_detected=extract_molecule_reactions(self.reactions,plot=plot_reaction_network)
139
+ self.molecule_report['explicit']=len(mol_reac_detected)
140
+ self.molecule_report['implied by stereochemistry']=0
141
+ self.molecule_report['implied by symmetry']=0
142
+ for mname,gen in mol_reac_detected:
143
+ self.molecules[mname]=Molecule.New(mname,gen,self.constituents.get(mname,{}))
144
+ for si,S in self.molecules[mname].stereoisomers.items():
145
+ self.molecules[si]=S
146
+ self.molecule_report['implied by stereochemistry']+=1
147
+
148
+ for mname,M in self.molecules.items():
149
+ M.set_sequence_from_moldict(self.molecules)
150
+ logging.debug(f'{mname} seq: {M.sequence}')
151
+
152
+ self.molecule_report['implied by stereochemistry']+=generate_stereo_reactions(self.reactions,self.molecules)
153
+ self.molecule_report['implied by symmetry']+=generate_symmetry_reactions(self.reactions,self.molecules)
154
+ for R in self.reactions:
155
+ for rnum,rname in R.reactants.items():
156
+ zrecs=[]
157
+ for atnum,atrec in R.atoms.items():
158
+ if atrec['reactant']==rnum:
159
+ cprec=atrec.copy()
160
+ del cprec['reactant']
161
+ zrecs.append(cprec)
162
+ self.molecules[rname].update_zrecs(zrecs,self.molecules)
163
+
164
+ for r in self.reactions:
165
+ logger.debug(f'{str(r)}')
166
+
167
+ for m,M in self.molecules.items():
168
+ R=M.generator
169
+ if not R==None:
170
+ logger.debug(f'{m}: generator: {R.name}')
171
+ else:
172
+ logger.debug(f'{m}: generator: None')
173
+ logger.debug(f'{m}: zrecs: {M.zrecs}')
174
+
175
+ self.initial_composition=[]
176
+ for molecule,mrec in self.constituents.items():
177
+ self.initial_composition.append({'molecule':molecule,'count':mrec.get('count',0)})
178
+
179
+ for molec in self.initial_composition:
180
+ mname=molec['molecule']
181
+ if not mname in self.molecules:
182
+ self.molecules[mname]=Molecule.New(mname,None,self.constituents.get(mname,{}))
183
+ self.molecules[mname].set_sequence_from_moldict(self.molecules)
184
+ logging.debug(f'{mname} seq: {self.molecules[mname].sequence}')
185
+
186
+
187
+ def calculate_maximum_conversion(self):
188
+ """calculate_maximum_conversion calculates the maximum number of polymerization bonds that can form based on specified system composition and reactions
189
+ """
190
+ Atom=namedtuple('Atom',['name','resid','reactantKey','reactantName','z'])
191
+ Bond=namedtuple('Bond',['ai','aj'])
192
+ N={}
193
+ # may have composite molecules
194
+ for item in self.initial_composition:
195
+ molecule_name=item['molecule']
196
+ molecule_count=item.get('count',0)
197
+ if molecule_count:
198
+ for res in self.molecules[molecule_name].sequence:
199
+ if not res in N:
200
+ N[res]=0
201
+ N[res]+=molecule_count
202
+ logger.debug(f'Base residue counts: {N}')
203
+ Bonds=[]
204
+ Atoms=[]
205
+ for R in [x for x in self.reactions if x.stage==reaction_stage.cure]:
206
+ logger.debug(str(R))
207
+ for b in R.bonds:
208
+ A,B=b['atoms']
209
+ a,b=R.atoms[A],R.atoms[B]
210
+ aan,ban=a['atom'],b['atom']
211
+ ari,bri=a['resid'],b['resid']
212
+ arnum,brnum=a['reactant'],b['reactant']
213
+ arn,brn=R.reactants[arnum],R.reactants[brnum]
214
+ if arnum==brnum: continue # this is an intramolecular reaction
215
+ az,bz=a['z'],b['z']
216
+ ia=Atom(aan,ari,arnum,arn,az)
217
+ ib=Atom(ban,bri,brnum,brn,bz)
218
+ logger.debug(f'ia {ia} ib {ib} arn {arn} brn {brn}')
219
+ b=Bond(ia,ib)
220
+ if ia not in Atoms and arn in N:
221
+ Atoms.append(ia)
222
+ if ib not in Atoms and brn in N:
223
+ Atoms.append(ib)
224
+ if b not in Bonds and arn in N and brn in N:
225
+ Bonds.append(b)
226
+ logger.debug(f'atomset: {Atoms}')
227
+ Z=[]
228
+ for a in Atoms:
229
+ Z.append(a.z*N[a.reactantName])
230
+ logger.debug(f'Z: {Z}')
231
+ logger.debug(f'bondset: {Bonds}')
232
+ MaxB=[]
233
+ for B in Bonds:
234
+ az=Z[Atoms.index(B.ai)]
235
+ bz=Z[Atoms.index(B.aj)]
236
+ MaxB.append(min(az,bz))
237
+ Z[Atoms.index(B.ai)]-=MaxB[-1]
238
+ Z[Atoms.index(B.aj)]-=MaxB[-1]
239
+ logger.debug(f'MaxB: {MaxB} {sum(MaxB)}')
240
+ self.maxconv=sum(MaxB)