{"id":26356525,"url":"https://github.com/ds4sd/molgrapher","last_synced_at":"2025-03-16T13:31:59.572Z","repository":{"id":189189144,"uuid":"679610551","full_name":"DS4SD/MolGrapher","owner":"DS4SD","description":"MolGrapher: Graph-based Visual Recognition of Chemical Structures","archived":false,"fork":false,"pushed_at":"2025-03-11T08:15:55.000Z","size":1551,"stargazers_count":65,"open_issues_count":2,"forks_count":4,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-11T09:25:38.166Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/2308.12234","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DS4SD.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-17T08:16:36.000Z","updated_at":"2025-03-11T08:15:59.000Z","dependencies_parsed_at":"2023-08-18T18:06:43.234Z","dependency_job_id":"b94a17c9-d064-49c9-aa4e-24c8cde6e752","html_url":"https://github.com/DS4SD/MolGrapher","commit_stats":null,"previous_names":["ds4sd/molgrapher"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DS4SD%2FMolGrapher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DS4SD%2FMolGrapher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DS4SD%2FMolGrapher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DS4SD%2FMolGrapher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DS4SD","download_url":"https://codeload.github.com/DS4SD/MolGrapher/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243875058,"owners_count":20361937,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-16T13:30:54.509Z","updated_at":"2025-03-16T13:31:59.558Z","avatar_url":"https://github.com/DS4SD.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MolGrapher\n\n[![Huggingface](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-USPTO%0A30K-blue)](https://huggingface.co/datasets/ds4sd/USPTO-30K/)\n[![Huggingface](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-MolGrapher%0ASynthetic%0A300K-blue)](https://huggingface.co/datasets/ds4sd/MolGrapher-Synthetic-300K)\n[![arXiv](https://img.shields.io/badge/arXiv-2308.12234-919191.svg)](https://doi.org/10.48550/arXiv.2308.12234)\n[![ICCV](https://img.shields.io/badge/Paper-iccv51070.2023.01791-b31b1b.svg)](https://openaccess.thecvf.com/content/ICCV2023/html/Morin_MolGrapher_Graph-based_Visual_Recognition_of_Chemical_Structures_ICCV_2023_paper.html)\n\nThis is the repository for [MolGrapher: Graph-based Visual Recognition of Chemical Structures](https://openaccess.thecvf.com/content/ICCV2023/html/Morin_MolGrapher_Graph-based_Visual_Recognition_of_Chemical_Structures_ICCV_2023_paper.html).\n\n![MolGrapher](assets/model_architecture.png)\n\n### Citation\n\nIf you find this repository useful, please consider citing:\n```\n@InProceedings{Morin_2023_ICCV,\n    author = {Morin, Lucas and Danelljan, Martin and Agea, Maria Isabel and Nassar, Ahmed and Weber, Valery and Meijer, Ingmar and Staar, Peter and Yu, Fisher},\n    title = {MolGrapher: Graph-based Visual Recognition of Chemical Structures},\n    booktitle = {Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV)},\n    month = {October},\n    year = {2023},\n    pages = {19552-19561}\n}\n```\nLinks: [ICCV](https://openaccess.thecvf.com/content/ICCV2023/html/Morin_MolGrapher_Graph-based_Visual_Recognition_of_Chemical_Structures_ICCV_2023_paper.html), [Arxiv](https://arxiv.org/abs/2308.12234) \n\n### Installation\n\nCreate a virtual environment.\n```\nconda create -n molgrapher python=3.11\nconda activate molgrapher\n```\nInstall [MolGrapher](https://github.com/DS4SD/MolGrapher/) and [MolDepictor](https://github.com/DS4SD/MolDepictor/) for CPU.\n```\npip install -e .[\"cpu\"]\n```\n\nInstall [MolGrapher](https://github.com/DS4SD/MolGrapher/) and [MolDepictor](https://github.com/DS4SD/MolDepictor/) for GPU. (Tested for x86_64, Linux Ubuntu 20.04, CUDA 11.7, CUDNN 8.4)\n```\npip install -e .[\"gpu\"]\n```\nCUDA and CDNN versions can be edited in `setup.py`.\n\nTo install and run MolGrapher using Docker, please refer to [README_DOCKER.md](https://github.com/DS4SD/MolGrapher/blob/main/README_DOCKER.md).\n\n### Model\n\nModels are available on [Hugging Face](https://huggingface.co/ds4sd/MolGrapher).\n```\nwget https://huggingface.co/ds4sd/MolGrapher/resolve/main/models/graph_classifier/gc_gcn_model.ckpt -P ./data/models/graph_classifier/\nwget https://huggingface.co/ds4sd/MolGrapher/resolve/main/models/graph_classifier/gc_no_stereo_model.ckpt -P ./data/models/graph_classifier/\nwget https://huggingface.co/ds4sd/MolGrapher/resolve/main/models/graph_classifier/gc_stereo_model.ckpt -P ./data/models/graph_classifier/\nwget https://huggingface.co/ds4sd/MolGrapher/resolve/main/models/keypoint_detector/kd_model.ckpt -P ./data/models/keypoint_detector/\n```\n\nAfter downloading, the folder `models` from Hugging Face should be placed in: `./data/`.\nModels can be selected by modifying attributes of GraphRecognizer in `./molgrapher/models/graph_recognizer.py` (The steps to follow are detailed in this [issue](https://github.com/DS4SD/MolGrapher/issues/6#issuecomment-2132380848)).\n\n### Inference\n\n#### Script\nYour input images can be placed in the folder: `./data/benchmarks/default/`.\n```\nbash molgrapher/scripts/annotate/run.sh\n```\nOutput predictions are saved in: `./data/predictions/default/`.\n\n#### Python\n```\nfrom molgrapher.models.molgrapher_model import MolgrapherModel\n\nmodel = MolgrapherModel()\nimages_or_paths = [\"./data/benchmarks/default/images/image_0.png\"] \nannotations = model.predict_batch(images_or_paths) \n```\n\n`annotations` is a list of dictionnaries with fields:\n```\n[\n    {\n        'smi': 'O=C(O)C1=CC=C(C2=C(...',                      # MolGrapher SMILES prediction\n        'conf': 0.991,                                        # MolGrapher confidence\n        'file-info': {\n            'filename': '...',                                # Input image filename\n            'image_nbr': 1       \n        }, \n        'abbreviations_ocr': [...],                           # Detected OCR text\n        'abbreviations': [...],                               # Post-processed detected OCR text\n        'annotator': {'program': 'MolGrapher', 'version': '1.0.0'},\n   },\n   ...\n]\n```\n\n### Docling Integration\n[Docling](https://github.com/DS4SD/docling) is a toolkit to extract the content and structure from PDF documents. It recognizes page layout, reading order, table structure, code, formulas, and classify images. \nHere, we combine `docling` and `MolGrapher`: \n- `Docling` segments and classify chemical-structure images from document pages,\n- `MolGrapher` converts images to SMILES.\n\nInstall `docling` in the `molgrapher` environment.\n```\npip install docling\n```\n\nOption 1. Convert a PDF document with `docling` and enrich it with `MolGrapher` annotations. \n\nExample: \n```\nbash molgrapher/scripts/annotate/docling/docling_convert_and_enrich.sh ./data/pdfs/US9259003_page_4.pdf ./data/docling_documents/US9259003_page_4/\n# bash [script] [pdf-path] [docling-document-directory-path]\n```\nOption 2. Enrich an existing `docling` document with `MolGrapher` annotations.\n\nExample: \n```\npython3 molgrapher/scripts/annotate/docling/enrich_docling_document.py --docling-document-directory-path ./data/docling_documents/US9259003_page_4/  \n# python3 [script] --docling-document-directory-path [docling-document-directory-path]\n```\n\nThe `docling` document, enriched with SMILES predictions, will be stored in `[docling-document-directory-path]`.\nFor more information, please refer to [docling](https://github.com/DS4SD/docling).\n\n### USPTO-30K Benchmark\n\nUSPTO-30K is available on [Hugging Face](https://huggingface.co/datasets/ds4sd/USPTO-30K).\n- USPTO-10K contains 10,000 clean molecules, i.e. without any abbreviated groups. \n- USPTO-10K-abb contains 10,000 molecules with superatom groups.\n- USPTO-10K-L contains 10,000 clean molecules with more than 70 atoms. \n\n### Synthetic Dataset\n\nThe synthetic dataset is available on [Hugging Face](https://huggingface.co/datasets/ds4sd/MolGrapher-Synthetic-300K).\nImages and graphs are generated using [MolDepictor](https://github.com/DS4SD/MolDepictor/).\n\n### Training\n\nTo train the keypoint detector:\n```\npython3 ./molgrapher/scripts/train/train_keypoint_detector.py\n```\nTo train the node classifier:\n```\npython3 ./molgrapher/scripts/train/train_graph_classifier.py\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fds4sd%2Fmolgrapher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fds4sd%2Fmolgrapher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fds4sd%2Fmolgrapher/lists"}