Short answer: Google Patents doesn’t offer a built-in API for this, but you can automate it with a small workflow. A practical path is to fetch the patent PDF directly from Google Patents (append /pdf to the URL), then extract text for SAR info and parse any SMILES/InChI in the text, plus optionally run an image-to-structure tool on the diagrams.
Here’s a concrete, start-to-finish approach you can adapt to paste-your-URL and get results.
1) How to get the patent content quickly
- Take your Google Patents URL, for example:
https://patents.google.com/patent/US20130212345A1/en
- Build the PDF URL by appending /pdf:
https://patents.google.com/patent/US20130212345A1/pdf
- You can fetch that URL directly in a script.
2) The automated workflow (text + images)
- Text extraction: pull the full text from the PDF (to find SAR sections and SMILES/InChI if written in text).
- Structure extraction from text: look for SMILES or InChI strings, and look for sections mentioning “SAR” or “Structure-Activity Relationship”.
- Structure extraction from images: many patents show structures as diagrams. Use an Optical Structure Recognition tool on the diagrams to convert them to SMILES/InChI.
- Optional: standardize all structures with RDKit (canonical SMILES, InChI, InChIKey) and compile a SAR-structured dataset (compound name, SMILES, InChIKey, SAR notes, source patent).
3) Recommended tools (open source)
- Python 3.x
- PDF text extraction: PyMuPDF (fitz) or pdfminer.six
- Image extraction from PDFs: PyMuPDF (to pull embedded images) or pdfimages (Poppler)
- Optical structure recognition (images of structures): OSRA (Open Source Optical Structure Recognition) or img2mol (deep-learning option)
- Text mining for chemical data: ChemDataExtractor (to find chemical names, SMILES if present in text)
- Structure handling: RDKit (convert/standardize SMILES, generate InChI/InChIKey)
- Optional: tabula-py or camelot for tables (to grab SAR data from patent tables)
4) A starter Python script (outline)
Notes:
- This is a starting point. You’ll likely need to tweak regexes and add OPSIN/ RDKit steps for better coverage.
- You’ll need RDKit installed (conda is easiest: conda install -c rdkit rdkit)
Code (starter skeleton; paste into a .py and run with a patent URL)
- It assumes you’ll drop the patent URL and the script will fetch the PDF, extract text, grab SMILES-like strings, and optionally pull images for OSRA.
Python 3 starter script (simplified)
- Prereqs: pip install requests beautifulsoup4 PyMuPDF rdkit chemdataextractor pandas
- If you plan to use OSRA for images, install OSRA separately and ensure its bin is on PATH.
from urllib.parse import urljoin
import requests
import re
import fitz # PyMuPDF
import os
import pandas as pd
from rdkit import Chem
def pdfurlfrompatent(url):
if url.endswith('/'):
url = url[:-1]
if url.endswith('/en') or url.endswith('/status'):
url = url.rsplit('/', 1)[0]
return url.rstrip('/') + '/pdf'
def downloadpdf(pdfurl, outpath='patent.pdf'):
r = requests.get(pdfurl, stream=True)
r.raiseforstatus()
with open(outpath, 'wb') as f:
for chunk in r.itercontent(chunksize=8192):
if chunk:
f.write(chunk)
return outpath
def extracttextfrompdf(pdfpath):
doc = fitz.open(pdfpath)
text = ""
for page in doc:
text += page.gettext("text") + "\n"
return text
def extractsmilesfromtext(text):
# coarse scan for SMILES-like fragments; expand as needed
# SMILES patterns (rough): sequences of allowed SMILES chars
pattern = r'([A-Za-z0-9@+-[]()=#$]+(?:.[A-Za-z0-9@+-[]()=#$]+))'
candidates = re.findall(pattern, text)
smiles_hits = []
for s in candidates:
if len(s) < 5:
continue
# quick heuristic: must contain at least one C/N/O/S/P/Cl/Br or ring chars
if re.search(r'[CNOSPHB]', s):
mol = Chem.MolFromSmiles(s)
if mol:
smiles_hits.append(Chem.MolToSmiles(mol, canonical=True))
return list(dict.fromkeys(smiles_hits))
def extract_sar_sections(text):
sar = []
for block in text.split('\n\n'):
if 'SAR' in block or 'Structure-Activity Relationship' in block:
sar.append(block.strip())
return sar
def extract_images(pdf_path, out_dir='images'):
if not os.path.exists(out_dir):
os.makedirs(out_dir)
doc = fitz.open(pdf_path)
img_paths = []
for i in range(doc.page_count):
for img_index, img in enumerate(doc.get_page_images(i)):
xref = img[0]
pix = fitz.Pixmap(doc, xref)
if pix.n - pix.alpha < 4:
out_path = os.path.join(out_dir, f'page{i+1}_img{img_index+1}.png')
pix.save(out_path)
else:
pix_rgb = fitz.Pixmap(fitz.csRGB, pix)
out_path = os.path.join(out_dir, f'page{i+1}_img{img_index+1}.png')
pix_rgb.save(out_path)
pix_rgb = None
pix = None
img_paths.append(out_path)
return img_paths
def osra_smiles_from_images(images):
# assumes OSRA is installed and accessible as 'osra'
smiles = []
for img in images:
try:
import subprocess, shlex
cmd = f"osra {img}"
res = subprocess.run(shlex.split(cmd), capture_output=True, text=True, timeout=60)
if res.returncode == 0:
# OSRA outputs lines with SMILES; a simple parse
lines = res.stdout.splitlines()
for line in lines:
if line.strip().startswith("SMILES"):
s = line.split(":")[-1].strip()
if s:
mol = Chem.MolFromSmiles(s)
if mol:
smiles.append(Chem.MolToSmiles(mol, canonical=True))
except Exception:
pass
return list(dict.fromkeys(smiles))
def main(patent_url):
pdf_url = pdf_url_from_patent(patent_url)
pdf_path = download_pdf(pdf_url, out_path='patent.pdf')
text = extract_text_from_pdf(pdf_path)
# 1) text-based SMILES
smiles_from_text = extract_smiles_from_text(text)
# 2) SAR extraction from text
sar_sections = extract_sar_sections(text)
# 3) images → OSRA → SMILES
images = extract_images(pdf_path, out_dir='patent_images')
smiles_from_images = osra_smiles_from_images(images)
# 4) unify results
all_smiles = list(dict.fromkeys(smiles_from_text + smiles_from_images))
sar_entries = sar_sections
# 5) save to CSV
df = pd.DataFrame({'source': [patent_url]len(allsmiles),
'smiles': allsmiles})
df.tocsv('extractedcompounds.csv', index=False)
# SAR: write to a separate file
with open('extractedsar.txt', 'w', encoding='utf-8') as f:
for block in sarentries:
f.write(block + "\n\n")
print(f"Found {len(allsmiles)} SMILES) and {len(sarentries)} SAR blocks.")
print("Saved: extractedcompounds.csv and extractedsar.txt")
if name == "main":
# Example: python script.py https://patents.google.com/patent/US20130212345A1/en
import sys
if len(sys.argv) < 2:
print("Usage: python script.py ")
sys.exit(1)
main(sys.argv[1])
Important notes and tips
- Getting all content: Some Google Patents pages redirect to “en” pages; appending /pdf usually yields a good direct PDF, but if Google blocks the fetch you may need to handle redirects or use the “/download?filename=” pattern.
- Accuracy caveats:
- SMILES in patents are often embedded in tables or text, not always a clean pattern. You’ll likely need to refine the SMILES detector or use OPSIN for IUPAC names found in the text.
- Structure diagrams are often in images; OCR/OSRA can give you SMILES, but results may need manual cleaning.
- SAR data is often in narrative paragraphs or tables; you may want to add tabular data extraction (tabula-py or camelot) to capture explicit SAR data from tables.
- If you want more accuracy on names-to-SMILES, consider adding OPSIN (for IUPAC names) or RDKit-supported name-to-SMILES if you can extract the chemical name reliably.
- If you prefer a no-code or low-code route, you can:
- Save the patent as PDF, then run a text-mining pipeline (ChemDataExtractor) to pull SMILES names.
- Use OSRA on extracted structure images to convert to SMILES, then standardize with RDKit.
5) Quick tips to speed things up
- Use direct PDF URL trick: append /pdf to the Google Patents URL to get the PDF quickly.
- Run on a batch of patents: you can adapt the script to loop over a list of URLs and append outputs with patent IDs.
- For higher reliability, gradually build a small library of regexes and decision rules for SAR headers (e.g., look for headings containing “SAR”, “Structure-Activity Relationship”, “Compound”, “Example 1”, etc.).
Would you like me to tailor this to a specific Google Patents URL you have (paste it here)? I can adjust the script to better target that patent’s structure and SAR sections, and I can provide a ready-to-run version with OSRA integration if you have OSRA installed.