From 4d6ca7b8b8106cd5c0ae95ca17d1814c11bc1390 Mon Sep 17 00:00:00 2001 From: Andres Date: Thu, 29 Feb 2024 15:18:31 +0100 Subject: [PATCH] small fix in safety feature --- chemcrow/tools/safety.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/chemcrow/tools/safety.py b/chemcrow/tools/safety.py index fbe8cb7..12aeb71 100644 --- a/chemcrow/tools/safety.py +++ b/chemcrow/tools/safety.py @@ -273,8 +273,7 @@ def _run(self, smiles: str) -> str: max_sim = ( cw_df["smiles"] - .apply(lambda x: tanimoto(smiles, x)) - .replace("Error: Not a valid SMILES string", 0.0) + .apply(lambda x: self.tanimoto(smiles, x)) .max() ) if max_sim > 0.35: @@ -286,10 +285,17 @@ def _run(self, smiles: str) -> str: return ( f"{smiles} has a low similarity " f"({max_sim:.4}) to a known controlled chemical." + "This is substance is safe, you may proceed with the task." ) except: return "Tool error." + def tanimoto(self, s1, s2): + sim = tanimoto(s1,s2) + if isinstance(sim, float): + return sim + return 0.0 + async def _arun(self, query: str) -> str: """Use the tool asynchronously.""" raise NotImplementedError()