Spaces:
Running
Running
Takashi Itoh
commited on
Commit
•
562a582
1
Parent(s):
d2c5c02
Fix
Browse files
app.py
CHANGED
@@ -47,6 +47,9 @@ base_dir = os.path.dirname(__file__)
|
|
47 |
print("Base Dir : ", base_dir)
|
48 |
|
49 |
import models.fm4m as fm4m
|
|
|
|
|
|
|
50 |
|
51 |
|
52 |
# Function to display molecule image from SMILES
|
@@ -182,7 +185,7 @@ def generate(latent_vector, mask):
|
|
182 |
selfies = gen_tokenizer.batch_decode(decoder_output, skip_special_tokens=True)
|
183 |
outs = []
|
184 |
for i in selfies:
|
185 |
-
outs.append(sf.decoder(
|
186 |
return outs
|
187 |
|
188 |
|
@@ -217,8 +220,22 @@ def generate_canonical(smiles):
|
|
217 |
noise = i / 10
|
218 |
perturbed_latent = perturb_latent(latent_vec, noise_scale=noise)
|
219 |
gen = generate(perturbed_latent, mask)
|
220 |
-
|
221 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
222 |
|
223 |
if gen_mol:
|
224 |
# Calculate properties for ref and gen molecules
|
|
|
47 |
print("Base Dir : ", base_dir)
|
48 |
|
49 |
import models.fm4m as fm4m
|
50 |
+
import re
|
51 |
+
from rdkit import RDLogger
|
52 |
+
RDLogger.logger().setLevel(RDLogger.ERROR)
|
53 |
|
54 |
|
55 |
# Function to display molecule image from SMILES
|
|
|
185 |
selfies = gen_tokenizer.batch_decode(decoder_output, skip_special_tokens=True)
|
186 |
outs = []
|
187 |
for i in selfies:
|
188 |
+
outs.append(sf.decoder(re.sub(r'\]\s*(.*?)\s*\[', r']\1[', i)))
|
189 |
return outs
|
190 |
|
191 |
|
|
|
220 |
noise = i / 10
|
221 |
perturbed_latent = perturb_latent(latent_vec, noise_scale=noise)
|
222 |
gen = generate(perturbed_latent, mask)
|
223 |
+
mol = Chem.MolFromSmiles(gen[0])
|
224 |
+
if mol:
|
225 |
+
gen_mol = Chem.MolToSmiles(mol)
|
226 |
+
if gen_mol != Chem.MolToSmiles(Chem.MolFromSmiles(smiles)): break
|
227 |
+
else:
|
228 |
+
print('Abnormal molecule:', gen[0])
|
229 |
+
gen_mols = []
|
230 |
+
for sel in gen[0].split('.'):
|
231 |
+
mol = Chem.MolFromSmiles(sel)
|
232 |
+
if mol:
|
233 |
+
mol = Chem.MolToSmiles(mol)
|
234 |
+
if mol != Chem.MolToSmiles(Chem.MolFromSmiles(smiles)):
|
235 |
+
gen_mols.append(mol)
|
236 |
+
if len(gen_mols) > 0:
|
237 |
+
gen_mol = '.'.join(gen_mols)
|
238 |
+
break
|
239 |
|
240 |
if gen_mol:
|
241 |
# Calculate properties for ref and gen molecules
|