Python wrapper for IBM RXN for Chemistry
Reason this release was yanked:
Broken API compatibility
Project description
Python wrapper for the IBM RXN for Chemistry API
A python wrapper to access the API of the IBM RXN for Chemistry website.
Install
From PYPI:
pip install rxn4chemistry
Or directly from the repo:
pip install git+https://github.com/rxn4chemistry/rxn4chemistry.git
Usage
Create a project
Get your API key from here and build the wrapper:
api_key='API_KEY'
from rxn4chemistry import RXN4ChemistryWrapper
rxn4chemistry_wrapper = RXN4ChemistryWrapper(api_key=api_key)
# NOTE: you can create a project or set an esiting one using:
# rxn4chemistry_wrapper.set_project('PROJECT_ID')
rxn4chemistry_wrapper.create_project('test_wrapper')
print(rxn4chemistry_wrapper.project_id)
Reaction prediction
Running a reaction prediction is as simple as:
response = rxn4chemistry_wrapper.predict_reaction(
'BrBr.c1ccc2cc3ccccc3cc2c1'
)
results = rxn4chemistry_wrapper.get_predict_reaction_results(
response['prediction_id']
)
print(results['response']['payload']['attempts'][0]['smiles'])
Extracting actions from a paragraph describing a recipe
Extract the actions from a recipe:
results = rxn4chemistry_wrapper.paragraph_to_actions(
'To a stirred solution of '
'7-(difluoromethylsulfonyl)-4-fluoro-indan-1-one (110 mg, '
'0.42 mmol) in methanol (4 mL) was added sodium borohydride '
'(24 mg, 0.62 mmol). The reaction mixture was stirred at '
'ambient temperature for 1 hour.'
)
print(results['actions'])
Retrosynthesis prediction
Predict a retrosynthetic pathway given a product:
response = rxn4chemistry_wrapper.predict_automatic_retrosynthesis(
'Brc1c2ccccc2c(Br)c2ccccc12'
)
results = rxn4chemistry_wrapper.get_predict_automatic_retrosynthesis_results(
response['prediction_id']
)
print(results['status'])
# NOTE: upon 'SUCCESS' you can inspect the predicted retrosynthetic paths.
print(results['retrosynthetic_paths'][0])
Create a synthesis and start it on Robot (or Simulator)
# Each retrosynthetic path predicted has a unique sequence_id that can
# be used to create a new synthesis
response = rxn4chemistry_wrapper.create_synthesis_from_sequence(
sequence_id=results['retrosynthetic_paths'][0]['sequence_id']
)
print(response['synthesis_id'])
# get the entire list of actions for the entire synthesis, as well as a tree representation
synthesis_tree, ordered_tree_nodes, ordered_list_of_actions = rxn4chemistry_wrapper.get_synthesis_plan(
synthesis_id=response['synthesis_id']
)
for action in ordered_list_of_actions:
print(action)
synthesis_status_result = rxn4chemistry_wrapper.start_synthesis(
synthesis_id=response['synthesis_id']
)
print(synthesis_status_result['status'])
synthesis_status_result = rxn4chemistry_wrapper.get_synthesis_status(
synthesis_id=response['synthesis_id']
)
print(synthesis_status_result['status'])
# NOTE: upon 'SUCCESS' you can download any analysis reports that are available as pdf
# The pdf contents are returned as text
analysis_actions = rxn4chemistry_wrapper.get_synthesis_actions_with_spectrometer_pdf(
synthesis_id=response['synthesis_id']
)
pdfs = []
for action in analysis_actions:
pdfs.append(
rxn4chemistry_wrapper.get_synthesis_analysis_report_pdf(
**action
)
)
print(pdfs[0])
See here for a more comprehensive example.
Examples
To learn more see the examples.
Documentation
The documentation is hosted here using GitHub pages.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
RXN4Chemistry-0.3.0.tar.gz
(9.9 kB
view hashes)