-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapply.py
41 lines (34 loc) · 1.49 KB
/
apply.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
from moleculeresolver import MoleculeResolver
# if you specify molecule_cache_db_path, you will have a separate cache for
# the found molecules in each folder. If you leave the default, all instances
# of MoleculeResolver will share the same cache
with MoleculeResolver(
available_service_API_keys={"chemeo": "YOUR_CHEMEO_API_KEY"},
molecule_cache_db_path="test.db",
) as mr:
names_to_find = ["2-bromobutane", "ethanol", "methanol", "propane", "butane"]
# search for the names in parallel
all_names = []
all_modes = []
for name in names_to_find:
names = mr.expand_name_heuristically(name)
all_names.append(names)
all_modes.append(["name"])
molecules_found_in_parallel = mr.find_multiple_molecules_parallelized(
all_names, all_modes
)
print("all_found_in_parallel:", all(molecules_found_in_parallel))
# search for the names sequentially
molecules = []
for name in names_to_find:
names = mr.expand_name_heuristically(name)
molecule = mr.find_single_molecule_cross_checked(names, "name")
molecules.append(molecule)
print("all_found:", all(molecules))
# search for CAS numbers
molecules_found_by_CAS = []
CAS_numbers = ["7732-18-5", "78-76-2", "64-17-5", "67-56-1", "74-98-6", "106-97-8"]
for CAS in CAS_numbers:
molecule = mr.find_single_molecule_cross_checked(CAS, "CAS")
molecules_found_by_CAS.append(molecule)
print("all_found_by_CAS:", all(molecules_found_by_CAS))