Most of my protocols are implemented as classes with protocol and reaction properties. Both properties are calculated from scratch each time they are accessed. However, this limits the flexibility of the python API. It's also a little confusing, because although the object returned by the reaction property is mutable, any changes will not be reflected in the protocol.
It'd be nice to be able to (i) calculate the reaction as usual, (ii) change any aspect of the reaction, (iii) make a protocol with the modified reaction. Really, this just means making the reaction behave more like a normal attribute (e.g. calculated in the constructor or something). To do this, I'd need one method to calculate the reaction, and another to get the reaction (and calculate it if necessary). Basically a typical caching scheme:
class MyProtocol:
def __init__(self):
self._rxn = None
def find_rxn(self):
rxn = stepwise.MasterMix()
self.set_rxn(rxn)
def get_rxn(self):
if self._rxn is None:
self._find_rxn()
return self._rxn
def set_rxn(self, rxn):
self._rxn = rxn
This is a lot of boiler plate, though. Is there any way to cut down on it? And would I want to recalculate on any attribute change?
Most of my protocols are implemented as classes with
protocol
andreaction
properties. Both properties are calculated from scratch each time they are accessed. However, this limits the flexibility of the python API. It's also a little confusing, because although the object returned by thereaction
property is mutable, any changes will not be reflected in the protocol.It'd be nice to be able to (i) calculate the reaction as usual, (ii) change any aspect of the reaction, (iii) make a protocol with the modified reaction. Really, this just means making the reaction behave more like a normal attribute (e.g. calculated in the constructor or something). To do this, I'd need one method to calculate the reaction, and another to get the reaction (and calculate it if necessary). Basically a typical caching scheme:
This is a lot of boiler plate, though. Is there any way to cut down on it? And would I want to recalculate on any attribute change?