npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rxn-wrapper

v0.0.1-beta.0

Published

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Downloads

5

Readme

rxn-wrapper

License: MIT

A JavaScript wrapper to access the API of the IBM RXN for Chemistry website.

This project it is inspired by rxn4chemistry.

Install

Using npm:

$ npm install rxn-wrapper

Using yarn:

$ yarn add rxn-wrapper

Usage

Initialize the wrapper

The baseUrl is set by default to 'https://rxn.res.ibm.com/rxn/'.

import RXNWrapper from 'rxn-wrapper';

const wrapper = new RXNWrapper({
    apiKey: 'your_apikey',
    // These fields are not required to initialize the wrapper
    // baseUrl: '',
    // projectId: ''
});

Create a project

import RXNWrapper from 'rxn-wrapper';

const wrapper = new RXNWrapper({
    apiKey: 'your_apikey',
});

wrapper.createProject({
    name: 'project_name',
    // These fields are not required
    // invitations: [],
    // select: True
});

Select a project

You can select a project by initializing the wrapper with the projectId property or by setting it programatically. Another way is setting select to True in the creation process.

import RXNWrapper from 'rxn-wrapper';

const wrapper = new RXNWrapper({
    apiKey: 'your_apikey',
});

wrapper.setProjectId('project_id');

Reaction prediction

import RXNWrapper from 'rxn-wrapper';

const wrapper = new RXNWrapper({
    apiKey: 'your_apikey',
    projectId: 'project_id'
});

async function predict() {
    const predictionId = await wrapper.predictReaction({
        reactants: 'BrBr.c1ccc2cc3ccccc3cc2c1'
    });

    setTimeout(
        () => {
            wrapper.getPredictReactionResults(predictionId).then(smiles => {
                console.log(smiles); // BrBr.c1ccc2cc3ccccc3cc2c1>>Brc1c2ccccc2cc2ccccc12
            });
        }, 500
    );
}

predict();

Retrosynthesis prediction

import RXNWrapper from 'rxn-wrapper';

const wrapper = new RXNWrapper({
    apiKey: 'your_apikey',
    projectId: 'project_id'
});

const delay = ms => new Promise(res => setTimeout(res, ms));

async function getStatus(predictionId) {
    await delay(5000);

    const res = await wrapper.getPredictRetrosynthesisResults(predictionId).then(res => {
        if (res.status === 'SUCCESS') return false;
        return true;
    });

    return res;
}

async function predict() {
    const predictionId = await wrapper.predictRetrosynthesis({
        product: 'Brc1c2ccccc2c(Br)c2ccccc12'
    });

    await delay(2000);

    while (await getStatus(predictionId)) {
        console.log('Waiting for results...');
    }

    await delay(2000);

    wrapper.getPredictRetrosynthesisResults(predictionId).then(res => {
        console.log(res);
    });
}

predict();

Extracting actions from a paragraph describing a recipe

import RXNWrapper from 'rxn-wrapper';

const wrapper = new RXNWrapper({
    apiKey: 'your_apikey',
});

wrapper.paragraphToActions([
    '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.'
]).then(res => {
    console.log(res);
    /*
        [
            'MAKESOLUTION with 7-(difluoromethylsulfonyl)-4-fluoro-indan-1-one (110 mg, 0.42 mmol) and methanol (4 mL)',
            'ADD SLN',
            'ADD sodium borohydride (24 mg, 0.62 mmol)',
            'STIR for 1 hour at ambient temperature'
        ]
    */
});

Forward prediction in batch

It is possible to run a batch of forward reaction predictions without linking them to a project:

import RXNWrapper from 'rxn-wrapper';

const wrapper = new RXNWrapper({
    apiKey: 'your_apikey',
});

async function predict() {
    const { taskId, taskStatus } = await wrapper.predictReactionBatch({
        reactants: ['BrBr.c1ccc2cc3ccccc3cc2c1', 'Cl.c1ccc2cc3ccccc3cc2c1']
    });

    setTimeout(
        () => {
            wrapper.getPredictReactionBatchResults(taskId).then(({ result, task, taskStatus }) => {
                console.log(result);
                /*
                    {
                        aiModel: '2020-08-10',
                        predictions: [
                            {
                                attention_weights: null,
                                confidence: 0.9797951373863595,
                                message: 'ok',
                                predict_time: 0.405620813369751,
                                reaction_image: null,
                                smiles: 'BrBr.c1ccc2cc3ccccc3cc2c1>>Brc1c2ccccc2cc2ccccc12',
                                total_time: 0.41137075424194336
                            },
                            {
                                attention_weights: null,
                                confidence: 0.5872236848398613,
                                message: 'ok',
                                predict_time: 0.405620813369751,
                                reaction_image: null,
                                smiles: 'Cl.c1ccc2cc3ccccc3cc2c1>>ClC1c2ccccc2Cc2ccccc21',
                                total_time: 0.41137075424194336
                            }
                        ]
                    }
                */
                console.log(task);
                // { status: 'DONE', task_id: 'task_id' }
            });
        }, 2000
    );
}

predict();

NOTE: the results for batch prediction are not stored permanently in the RXN databases, so it is strongly recommend to save them since they will expire.