-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspecies_search.py
57 lines (53 loc) · 1.6 KB
/
species_search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'''
File: species_search.py
Project: MINICHEM
File Created: Tuesday, 7th January 2020 1:16:30 pm
Author: John Arul & Parth ([email protected], [email protected])
-----
Last Modified: Tuesday, 7th January 2020 1:16:34 pm
Modified By: John Arul & Parth Patel ([email protected], [email protected])
-----
Copyright: IGCAR - 2020
'''
import re
import itertools
from chem_parse import chemparse
def el(species):
"""
The function takes the input species (list form), and convert
the element of the list which can be compound/element to the element.
INPUT: species (list)
"""
sp_set = set()
temp_list = []
name = []
for i in range(len(species)):
if re.findall('\([L|a|cr|I|III|II]\)', species[i]) != []:
name.append(re.sub('\([L|a|cr|I|III|II]\)', "", species[i]))
# print(name)
else:
name.append(species[i])
# print(name)
for i in name:
# print(re.findall('([A-Z][a-z]*)',i))
temp_list.append(re.findall('([A-Z][a-z]*)', i))
tb = list(itertools.chain.from_iterable(temp_list))
for i in tb:
sp_set.add(i)
return list(sp_set)
def combination_search(species, grt_dict, combination_sp):
"""
Searches the combination of the element in the grt_dict.
For example,
If species is H2O,
Then the combinations in grt_dict might be: OH, H2O2, H, O2 etc.
"""
a = el(species)
for i in grt_dict.keys():
spice = set()
if chemparse(a, i):
spice.add(i)
# print(i)
combination_sp[i] = grt_dict[i]
# print(spice)
return combination_sp