Skip to main content

RetroSynthesis API

test

  • retroapi get predict routes given target molecule.

  • supply plausible value for all predicts.

  • predict conditions base on one reaction.

  • add aync support

  • deploy your backend server with torchserve (if api failed)

    install torchserve and other libraries from requirements.txt run download_models.sh run

    torchserve --start --foreground --ncs --model-store=mars --models reaxys=reaxys.mar
    

    test server

     curl http://127.0.0.1:8080/predictions/reaxys \                                                                                                            (base)
                  --header "Content-Type: application/json" \
                  --request POST \
                  --data '{"smiles": ["CC(C)(C)OC(=O)N1CCC(OCCO)CC1"]}'
    

Install

  • using pip
pip install retroapi

Usage

from retroapi import RetroApi, Name2Smiles

token = "" # you may get token first

retro_api = RetroApi(token)

# if you have simles of molecule.
smiles = "COc1cccc(OC(=O)/C=C/c2cc(OC)c(OC)c(OC)c2)c1"

# else:
chemical_name = "4-Hydroxycoumarin"
name2smiles = Name2Smiles()
smiles = name2smiles.get_smiles(chemical_name)

# check if smiles is valid or not
is_valid_smiles = retro_api.validate_smiles(smiles)

if is_valid_smiles:
    routes = retro_api.predict_routes(smiles)
    if routes is not None:
        # work with routes
        pass

# check if chemical is buyable or not
is_buyable = retro_api.check_stock(smiles)

# check reaction conditions

# first you should get product smile
# second you should get reactants smile

products = "COc1cc(C(=O)O)cc(OC)c1OC"
reactants = "C=CC(=O)O.COc1cc(Br)cc(OC)c1OC"

conds = retro_api.process_reaction(product, reactants)
if conds is not None:
    # check reaction condition with plausible
    pass

Async Usage

from retroapi import RetroApi, Name2Smiles


async def foo():
    retro_api = RetroApi(token)

    # if you have simles of molecule.
    smiles = "COc1cccc(OC(=O)/C=C/c2cc(OC)c(OC)c(OC)c2)c1"

    # else:
    chemical_name = "4-Hydroxycoumarin"
    name2smiles = Name2Smiles()
    smiles = await name2smiles.aget_smiles(chemical_name)

    # check if smiles is valid or not
    is_valid_smiles = await retro_api.avalidate_smiles(smiles)

    if is_valid_smiles:
        routes = await retro_api.apredict_routes(smiles)
        if routes is not None:
            # work with routes
            pass

    # check if chemical is buyable or not
    is_buyable = await retro_api.acheck_stock(smiles)

    # check reaction conditions

    # first you should get product smile
    # second you should get reactants smile

    products = "COc1cc(C(=O)O)cc(OC)c1OC"
    reactants = "C=CC(=O)O.COc1cc(Br)cc(OC)c1OC"

    conds = await retro_api.aprocess_reaction(product, reactants)
    if conds is not None:
        # check reaction condition with plausible
        pass

Change log:

2023-12-30 Extract condition recommend code from ASKCOS to notebook for local test.

2023-12-25 Run backend server with torchserve

Add try_times in predict_routes and process_reaction w/ async

routes = await retro_api.apredict_routes(smiles, try_num=20)

Need Token to use this package

It's wrap package for askcos.mit.edu API, so you can get token from website first.

add aync for package

with function name prefix with 'a', for example get_smile -> aget_smile

API Documentation

Class Name2Smiles

  • get_smiles
    • parameter
      • chemical_name: str
    • output
      • smiles: str

Class RetroApi

  • validate_smiles

    • parameter
      • smiles: str
    • output
      • true/false
  • predict_routes

    • parameter
      • smiles: str
    • output
      • routes: list
  • process_reaction

    • parameter
      • product: str

        product smiles

      • reactants: str

        reactants smiles jointed by "." like "C=CC(=O)O.COc1cc(Br)cc(OC)c1OC"

    • output conditions: list

Metadata

Release files for retroapi 0.8.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for retroapi 0.8.10
File Size Uploaded
retroapi-0.8.10.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for retroapi 0.8.10
File Interpreter ABI Platform
retroapi-0.8.10-py3-none-any.whl Python 3 none any Details

Total release size: 12.2 kB

Release files / retroapi-0.8.10.tar.gz

Download URL retroapi-0.8.10.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8658416193df23c1e2f7142441dba3f646ba86569a64094ece74e2ebbcdd95f9
BLAKE2b-256 checksum
How to use checksums
77457a780525f5783c732ea54e34668b6c835af9ff164f89bdc410f776830522
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release files / retroapi-0.8.10-py3-none-any.whl

Download URL retroapi-0.8.10-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6873a0fb5bcff5670f248d8e95459a090aae199956588539daa7205b114b8594
BLAKE2b-256 checksum
How to use checksums
1b2a47ad90a3b27a246c36a2de4a28d7d5bfd8d7577b8da17cc7839144337778
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.8.10 This release

2 release files

0.8.2

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.5.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page