Skip to content

Commit

Permalink
Fixing pytest error: Adding a session to the compound identifier func…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
Abellegese authored Oct 24, 2024
1 parent 44c171a commit 9110816
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ersilia/utils/identifiers/compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@ def is_key_header(self, h):

def _is_smiles(self, text):
if self.Chem is None:
return self._pubchem_smiles_to_inchikey(text) is not None
return asyncio.run(self._pubchem_smiles_to_inchikey_sync(text))
else:
mol = self.Chem.MolFromSmiles(text)
return mol is not None

async def _pubchem_smiles_to_inchikey_sync(self, text):
semaphore = asyncio.Semaphore(self.concurrency_limit)
async with semaphore:
async with aiohttp.ClientSession() as session:
return await self._pubchem_smiles_to_inchikey(session, text)

@staticmethod
def _is_inchikey(text):
Expand Down Expand Up @@ -227,4 +233,4 @@ async def fetch_inchikeys():
def validate_smiles(self, smiles):
return smiles.strip() != "" and Chem.MolFromSmiles(smiles) is not None

Identifier = CompoundIdentifier
Identifier = CompoundIdentifier

0 comments on commit 9110816

Please sign in to comment.