Aggregating Optimade client for the online materials databases

Features
- discover all the official Optimade databases recursively
- cache the discovered list (
prefetched.json
) for future and boost the retrieval performance
- query them all, in the browser, at the server, everywhere
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>
<script type="module" src="/path/to/optimade/dist/index.mjs"></script>
Usage
const optimadeClient = new Optimade({
providersUrl: '/path/to/optimade/providers.json'
});
console.log(optimadeClient.providers);
const providersMap = await optimadeClient.getProviders();
const providerIds = Object.keys(providersMap);
const results = await optimadeClient.getStructuresAll(providerIds, YOUR_OPTIMADE_QUERY);
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.
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 e.g. 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.
License
MIT © PaulMaly, Tilde Materials Informatics