Giter Site home page Giter Site logo

tilde-lab / optimade-client Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 1.0 533 KB

Isomorphic TypeScript / JavaScript client to aggregate all the official Optimade providers

Home Page: https://optimade.science

License: MIT License

JavaScript 25.30% TypeScript 74.70%
materials materials-science materials-informatics materials-design materials-genome materials-platform materials-discoveries materials-discovery chemoinformatics optimade

optimade-client's Introduction

Aggregating Optimade client for the online materials databases

NPM version NPM downloads GitHub issues DOI

Features

  • discovers all the official Optimade databases recursively
  • caches the discovered list (prefetched.json) for future and boosts the retrieval performance
  • queries them all, in the browser, at the server, everywhere
  • provides pagination, with the minimized number of pages

Install

npm i optimade --save
yarn add optimade

CDN: UNPKG | jsDelivr (available as window.optimade)

If you are not using ES6 or CDN, add to your HTML just before closing the body tag:

<script src="/path/to/optimade/dist/index.js"></script>
<!-- OR -->
<script type="module" src="/path/to/optimade/dist/index.mjs"></script>

Usage

The code is generally isomorphic, however one should additionally take care of downloading the cache or setting the CORS policy for the browsers. Concerning the CORS, the Optimade class constructor accepts the corsProxyUrl parameter, pointing to a running cors-anywhere proxy instance. This will be valid until all the Optimade providers are supplying the header Access-Control-Allow-Origin $http_origin in their responses. For the server-side environment this is not required.

Discovery and querying

const optimadeClient = new Optimade({
  providersUrl: "https://providers.optimade.org/providers.json",
});

console.log(optimadeClient.providers); // { [id: string]: Provider }[]

const providersMap = await optimadeClient.getProviders(); // { [id: string]: Provider }[]

const providerIds = Object.keys(providersMap); // string[]

const results = await optimadeClient.getStructuresAll({
  providers: Provider[],
  filter: YOUR_OPTIMADE_QUERY,
}); // [StructuresResponse[], Provider][]

Importing depends on your environment. See also the examples folder. The .html examples are suited for the browser environment, the .js examples are suited for the server environment.

Pagination

import prefetched from 'optimade/dist/prefetched.json';

const optimadeClient = new Optimade({
  providersUrl: "https://providers.optimade.org/providers.json",
});

optimadeClient.providers = prefetched.providers;
optimadeClient.apis = prefetched.apis;

const results = await optimadeClient.getStructuresAll({
  providers: Provider[],
  filter: YOUR_OPTIMADE_QUERY,
  page: number,
  limit: number,
  offset: number,
  batch: true
}); // [StructuresResponse[], Provider][]

See also the demo folder.

License

MIT © Pavel Malyshev and Alexander Volkov, Tilde Materials Informatics

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.