Skip to content

Commit 9dbc4c4

Browse files
committed
Merge pull request #278 from nickvandewiele/props_species_refactor
Add props dictionary attribute to the Species class for storing various user-defined properties.
2 parents 2129769 + c54bfcb commit 9dbc4c4

4 files changed

Lines changed: 15 additions & 4 deletions

File tree

rmgpy/rmg/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ class Species(rmgpy.species.Species):
7676
def __init__(self, index=-1, label='', thermo=None, conformer=None,
7777
molecule=None, transportData=None, molecularWeight=None,
7878
dipoleMoment=None, polarizability=None, Zrot=None,
79-
energyTransferModel=None, reactive=True, coreSizeAtCreation=0):
80-
rmgpy.species.Species.__init__(self, index, label, thermo, conformer, molecule, transportData, molecularWeight, dipoleMoment, polarizability, Zrot, energyTransferModel, reactive)
79+
energyTransferModel=None, reactive=True, props={}, coreSizeAtCreation=0):
80+
rmgpy.species.Species.__init__(self, index, label, thermo, conformer, molecule, transportData, molecularWeight, dipoleMoment, polarizability, Zrot, energyTransferModel, reactive, props)
8181
self.coreSizeAtCreation = coreSizeAtCreation
8282

8383
def __reduce__(self):

rmgpy/species.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ cdef class Species:
4848
cdef public ScalarQuantity _Zrot
4949
cdef public bint reactive
5050
cdef public object energyTransferModel
51+
cdef public dict props
5152

5253
cpdef generateResonanceIsomers(self)
5354

rmgpy/species.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class Species(object):
8484
`Zrot` The rotational relaxation collision number
8585
`energyTransferModel` The collisional energy transfer model to use
8686
`reactive` ``True`` if the species participates in reactions, ``False`` if not
87+
'props' A generic 'properties' dictionary to store user-defined flags
8788
======================= ====================================================
8889
8990
note::
@@ -94,7 +95,7 @@ class Species(object):
9495
def __init__(self, index=-1, label='', thermo=None, conformer=None,
9596
molecule=None, transportData=None, molecularWeight=None,
9697
dipoleMoment=None, polarizability=None, Zrot=None,
97-
energyTransferModel=None, reactive=True):
98+
energyTransferModel=None, reactive=True, props={}):
9899
self.index = index
99100
self.label = label
100101
self.thermo = thermo
@@ -115,6 +116,8 @@ def __init__(self, index=-1, label='', thermo=None, conformer=None,
115116
if mult != m.multiplicity:
116117
raise SpeciesError('Multiplicities of molecules in species {species} do not match.'.format(species=label))
117118

119+
self.props = props
120+
118121

119122
def __repr__(self):
120123
"""

rmgpy/speciesTest.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,14 @@ def testToAdjacencyList(self):
109109
"""
110110
string = self.species.toAdjacencyList()
111111
self.assertTrue(string.startswith(self.species.molecule[0].toAdjacencyList(label=self.species.label,removeH=False)),string)
112-
112+
113+
def testSpeciesProps(self):
114+
'''
115+
Create a test in which a key-value pair is added to the props attribute of Species.
116+
'''
117+
self.species.props['foo'] = 'bar'
118+
self.assertIsInstance(self.species.props, dict)
119+
self.assertEquals(self.species.props['foo'], 'bar')
113120
################################################################################
114121

115122
if __name__ == '__main__':

0 commit comments

Comments
 (0)