1

When I manually searched the pubchem web page using the keyword "1-(2-Hydroxyphenyl)-2-phenyl ethanone", I got the following results.

enter image description here

Although no compounds exactly matched the above keywords, four compounds were found that partially matched the keywords.

But if I search using the following code, no compounds are found.

import requests
prolog = "https://pubchem.ncbi.nlm.nih.gov/rest/pug"
a = requests.get(prolog + "/compound/name/1-(2-Hydroxyphenyl)-2-phenyl ethanone/json").json()
print(a)

output :

{'Fault': {'Code': 'PUGREST.NotFound', 'Message': 'No CID found', 'Details': ['No CID found that matches the given name']}}

Another example, using methane as a keyword

enter image description here

There is one "BEST MATCH" (compound 297) and other 444027 related compounds. But the above python code only gives me one result (compound 297)

Therefore, I presume that the above code will only get the BEST MATCH result. How can I get other related results by name please? (or the first few of the relevant compounds)

arron
  • 73
  • 5

1 Answers1

0

Pubchem has a python API called pubchempy

It can be installed using pip: pip install pubchempy.

Using the API we can get similar compounds like this:

name = '1-(2-Hydroxyphenyl)-2-phenylethanone'

matches = pcp.get_compounds(name, 'name')
if matches:
  best_match = matches[0]
  similar_compounds = pcp.get_compounds(best_match.isomeric_smiles, 'smiles', searchtype='similarity',listkey_count=4)
  
  for c in similar_compounds:
    print(c.iupac_name)

This outputs:

1-(2-hydroxyphenyl)ethanone
1-(2-hydroxy-5-methylphenyl)ethanone
(4-hydroxyphenyl)-phenylmethanone
1-(2,5-dihydroxyphenyl)ethanone

Note: If you do not mention the listkey_count=4 argument, it might take a very long time to make the search and may even return a 504: PUGREST.Timeout.

Vandan Revanur
  • 459
  • 6
  • 17