|
1
|
|
|
from intelligine.core.exceptions import NoTypeInMolecule, NoCategoryInMolecule |
|
2
|
|
|
from intelligine.simulation.molecule.Molecule import Molecule |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
class MoleculeFlavour(): |
|
6
|
|
|
|
|
7
|
|
|
@classmethod |
|
8
|
|
|
def new_from_raw_data(cls, raw_data): |
|
9
|
|
|
flavour = {} |
|
10
|
|
|
for category in raw_data: |
|
11
|
|
|
molecules_by_category = raw_data[category] |
|
12
|
|
|
for type in molecules_by_category: |
|
13
|
|
|
distance, intensity, cycle_age = molecules_by_category[type] |
|
14
|
|
|
if category not in flavour: |
|
15
|
|
|
flavour[category] = {} |
|
16
|
|
|
flavour[category][type] = Molecule(category, type, distance, intensity, cycle_age) |
|
17
|
|
|
return cls(flavour) |
|
18
|
|
|
|
|
19
|
|
|
def get_raw_data(self): |
|
20
|
|
|
raw_data = {} |
|
21
|
|
|
for category in self._flavour: |
|
22
|
|
|
molecules_by_category = self._flavour[category] |
|
23
|
|
|
for type in molecules_by_category: |
|
24
|
|
|
molecule = molecules_by_category[type] |
|
25
|
|
|
if category not in raw_data: |
|
26
|
|
|
raw_data[category] = {} |
|
27
|
|
|
if molecule.get_intensity() >= 0: |
|
28
|
|
|
raw_data[category][type] = (molecule.get_distance(), |
|
29
|
|
|
molecule.get_intensity(), |
|
30
|
|
|
molecule.get_cycle_age()) |
|
31
|
|
|
return raw_data |
|
32
|
|
|
|
|
33
|
|
|
def __init__(self, flavour): |
|
34
|
|
|
self._flavour = flavour |
|
35
|
|
|
|
|
36
|
|
|
def get_molecule(self, category, type): |
|
37
|
|
|
types = self.get_types(category) |
|
38
|
|
|
if type not in types: |
|
39
|
|
|
raise NoTypeInMolecule() |
|
40
|
|
|
return types[type] |
|
41
|
|
|
|
|
42
|
|
|
def get_molecules(self, category): |
|
43
|
|
|
""" |
|
44
|
|
|
|
|
45
|
|
|
:param category: |
|
46
|
|
|
:return: Molecules dict or empty dict of no molecules |
|
47
|
|
|
""" |
|
48
|
|
|
try: |
|
49
|
|
|
return self.get_types(category).values() |
|
50
|
|
|
except NoCategoryInMolecule: |
|
51
|
|
|
return {} |
|
52
|
|
|
|
|
53
|
|
|
def get_molecules_types(self, category): |
|
54
|
|
|
try: |
|
55
|
|
|
return self.get_types(category).keys() |
|
56
|
|
|
except NoCategoryInMolecule: |
|
57
|
|
|
return {} |
|
58
|
|
|
|
|
59
|
|
|
def get_types(self, category): |
|
60
|
|
|
if category not in self._flavour: |
|
61
|
|
|
raise NoCategoryInMolecule() |
|
62
|
|
|
return self._flavour[category] |
|
63
|
|
|
|
|
64
|
|
|
def set_molecule(self, molecule): |
|
65
|
|
|
category = molecule.get_category() |
|
66
|
|
|
type = molecule.get_type() |
|
67
|
|
|
|
|
68
|
|
|
if category not in self._flavour: |
|
69
|
|
|
self._flavour[category] = {} |
|
70
|
|
|
|
|
71
|
|
|
self._flavour[category][type] = molecule |
|
72
|
|
|
|
|
73
|
|
|
def remove_molecule(self, molecule): |
|
74
|
|
|
category = molecule.get_category() |
|
75
|
|
|
type = molecule.get_type() |
|
76
|
|
|
del(self._flavour[category][type]) |
|
77
|
|
|
|