Synapse.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. class Synapse(object):
  2. """
  3. This Class is representing a Synapse with its name, and a dict of Neurons and a dict of signals
  4. .. note:: must be defined in the brain.yml
  5. """
  6. def __init__(self, name=None, neurons=None, signals=None):
  7. self.name = name
  8. self.neurons = neurons
  9. self.signals = signals
  10. def serialize(self):
  11. """
  12. This method allows to serialize in a proper way this object
  13. :return: A dict of name, neurons, signals
  14. :rtype: Dict
  15. """
  16. return {
  17. 'name': self.name,
  18. 'neurons': [e.serialize() for e in self.neurons],
  19. 'signals': [e.serialize() for e in self.signals]
  20. }
  21. def __str__(self):
  22. return_val = "Synapse name: %s" % self.name
  23. return_val += "\nneurons:"
  24. for el in self.neurons:
  25. return_val += str(el)
  26. return_val += "\nsignals:"
  27. for el in self.signals:
  28. return_val += str(el)
  29. return return_val
  30. def __eq__(self, other):
  31. """
  32. This is used to compare 2 objects
  33. :param other:
  34. :return:
  35. """
  36. return self.__dict__ == other.__dict__