forked from PatWalters/TS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ts_utils.py
36 lines (31 loc) · 1.4 KB
/
ts_utils.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
from typing import List, Optional
from reagent import Reagent
def create_reagents(filename: str, num_to_select: Optional[int] = None) -> List[Reagent]:
"""
Creates a list of Reagents from a file
:param filename: a smiles file containing the reagents
:param num_to_select: For dev purposes; the number of molecules to return
:return: List of Reagents
"""
reagent_list = []
with open(filename, 'r') as f:
for line in f.readlines():
smiles, reagent_name = line.split()
reagent = Reagent(reagent_name=reagent_name, smiles=smiles)
reagent_list.append(reagent)
if num_to_select is not None and len(reagent_list) > num_to_select:
reagent_list = reagent_list[:num_to_select]
return reagent_list
def read_reagents(reagent_file_list, num_to_select: Optional[int]) -> List[Reagent]:
"""
Read the reagents SMILES files
:param reagent_file_list: a list of filenames containing reagents for the reaction. Each file list contains smiles
strings for a single component of the reaction.
:param num_to_select: select how many reagents to read, mostly a development function
:return: List of Reagents
"""
reagents = []
for reagent_filename in reagent_file_list:
reagent_list = create_reagents(filename=reagent_filename, num_to_select=num_to_select)
reagents.append(reagent_list)
return reagents