optimade 2.0.5 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "optimade",
3
- "version": "2.0.5",
3
+ "version": "2.1.1",
4
4
  "description": "Aggregating Optimade client for the online materials databases",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -23,14 +23,13 @@
23
23
  "@types/jest": "^26.0.15",
24
24
  "jest": "^26.6.0",
25
25
  "rollup": "^2.47.0",
26
- "rollup-plugin-typescript2": "^0.28.0",
26
+ "rollup-plugin-typescript2": "^0.37.0",
27
27
  "ts-jest": "^26.4.1",
28
28
  "eslint": "^8.16.0",
29
29
  "typescript": "^4.0.3"
30
30
  },
31
31
  "dependencies": {
32
- "isomorphic-unfetch": "^3.1.0",
33
- "node-abort-controller": "^3.0.1"
32
+ "isomorphic-unfetch": "^3.1.0"
34
33
  },
35
34
  "keywords": [
36
35
  "optimade",
@@ -40,4 +39,4 @@
40
39
  "type": "git",
41
40
  "url": "git+https://github.com/tilde-lab/optimade-client"
42
41
  }
43
- }
42
+ }
package/prefetch.js CHANGED
@@ -6,10 +6,6 @@ const fs = require('fs');
6
6
  const path = require('path');
7
7
  const { Optimade } = require('./dist/index');
8
8
 
9
- const { AbortController } = require('node-abort-controller');
10
-
11
- global.AbortController = AbortController;
12
-
13
9
  const optimade = new Optimade({
14
10
  providersUrl: 'https://providers.optimade.org/providers.json'
15
11
  });
@@ -55,19 +51,23 @@ optimade.getProviders().then(async (providers) => {
55
51
  : e.detail
56
52
  : '0';
57
53
  };
54
+ // take care of the pagination for GUIs
58
55
  const nums = detail(res.errors).match(/\d+/g).filter(n => +n < max).map(n => +n);
59
56
  return {
60
57
  [k]: { ...v, attributes: { ...v.attributes, api_version: api, ['query_limits']: !nums.includes(0) ? nums : [10] } }
61
58
  };
62
59
  } catch (error) {
63
- console.log(error);
60
+ console.error(error);
64
61
  }
65
62
  };
66
63
  time = performance.now();
67
64
  return await Object.entries(providers).reduce(async (promise, [k, v], i) => {
68
65
  const provider = await fetchLimits(k, v);
69
66
  const acc = await promise;
70
- console.log(i, provider);
67
+
68
+ console.log(`Provider # ${i}:`);
69
+ console.log(JSON.stringify(provider, null, 4));
70
+
71
71
  return { ...acc, ...provider };
72
72
  }, Promise.resolve({}));
73
73
  }
@@ -80,16 +80,16 @@ optimade.getProviders().then(async (providers) => {
80
80
  console.log({
81
81
  prefetched: Object.keys(providers).length,
82
82
  source: Object.keys(source).length,
83
- alltime: performance.now() - alltime
83
+ time: performance.now() - alltime
84
84
  });
85
85
 
86
86
  fs.writeFile(path.join(__dirname, 'dist/prefetched.json'), JSON.stringify(data), (err) => {
87
87
  if (err) throw err;
88
88
  console.log('The prefetched.json file has been saved!');
89
89
  });
90
- fs.writeFile(path.join(__dirname, 'dist/providers.json'), JSON.stringify(source), (err) => {
90
+ fs.writeFile(path.join(__dirname, 'dist/providers.debug.json'), JSON.stringify(source), (err) => {
91
91
  if (err) throw err;
92
- console.log('The providers.json file has been saved!');
92
+ console.log('The providers.debug.json file has been saved!');
93
93
  });
94
94
  });
95
95
 
package/src/index.ts CHANGED
@@ -114,7 +114,7 @@ export class Optimade {
114
114
  return Optimade.apiVersion(apis);
115
115
  }
116
116
 
117
- async getStructures(providerId: string, filter = '', page = 1, limit: number): Promise<Types.StructuresResponse[] | Types.ResponseError> {
117
+ async getStructures({ providerId, filter, page, limit, offset }: { providerId: string; filter: string; page: number; limit: number; offset: number; }): Promise<Types.StructuresResponse[] | Types.ResponseError> {
118
118
 
119
119
  if (!this.apis[providerId]) { return null; }
120
120
 
@@ -122,12 +122,11 @@ export class Optimade {
122
122
  const provider = this.providers[providerId];
123
123
 
124
124
  const structures: Types.StructuresResponse[] = await allSettled(apis.map(async (api: Types.Api) => {
125
- if (page <= 0) { page = 1; }
126
125
  const pageLimit = limit ? `&page_limit=${limit}` : '';
127
- const pageNumber = page ? `&page_number=${page - 1}` : '';
128
- const pageOffset = limit && page ? `&page_offset=${limit * (page - 1)}` : '';
126
+ const pageNumber = page ? `&page_number=${page}` : '';
127
+ const pageOffset = offset ? `&page_offset=${offset}` : '';
129
128
  const params = filter ? `${pageLimit + pageNumber + pageOffset}` : `?${pageLimit}`;
130
- const url: string = this.wrapUrl(Optimade.apiVersionUrl(api), filter ? `/structures?filter=${filter + params}` : `/structures${params}`);
129
+ const url = this.wrapUrl(Optimade.apiVersionUrl(api), filter ? `/structures?filter=${filter + params}` : `/structures${params}`);
131
130
 
132
131
  try {
133
132
  return await Optimade.getJSON(url, {}, { Origin: 'https://cors.optimade.science', 'X-Requested-With': 'XMLHttpRequest' });
@@ -149,13 +148,13 @@ export class Optimade {
149
148
  }, []);
150
149
  }
151
150
 
152
- getStructuresAll(providerIds: string[], filter = '', page = 1, limit: number, batch = true): Promise<Promise<Types.StructuresResult>[]> | Promise<Types.StructuresResult>[] {
151
+ getStructuresAll({ providers, filter, page, limit, offset, batch = true }: { providers: string[]; filter: string; page: number; limit: number; offset: number; batch?: boolean; }): Promise<Promise<Types.StructuresResult>[]> | Promise<Types.StructuresResult>[] {
153
152
 
154
- const results = providerIds.reduce((structures: Promise<any>[], providerId: string) => {
153
+ const results = providers.reduce((structures: Promise<any>[], providerId: string) => {
155
154
  const provider = this.providers[providerId];
156
155
  if (provider) {
157
156
  structures.push(allSettled([
158
- this.getStructures(providerId, filter, page, limit),
157
+ this.getStructures({ providerId, filter, page, limit, offset }),
159
158
  Promise.resolve(provider)
160
159
  ]));
161
160
  }
@@ -173,7 +172,7 @@ export class Optimade {
173
172
  return !this.isDuplicatedReq(url) ? Optimade.getJSON(url) : null;
174
173
  }
175
174
 
176
- private wrapUrl(url, tail = '') {
175
+ private wrapUrl(url: string, tail = ''): string {
177
176
  url = this.corsProxyUrl ? `${this.corsProxyUrl}/${url.replace('://', '/').replace('//', '/')}` : url;
178
177
  return tail ? url.replace(/\/$/, '') + tail : url;
179
178
  }
@@ -191,7 +190,7 @@ export class Optimade {
191
190
  Object.entries(params).forEach((param: [string, any]) => url.searchParams.append(...param));
192
191
  }
193
192
 
194
- Object.assign(headers, { 'User-Agent': `tilde-lab-optimade-client/${version}` })
193
+ Object.assign(headers, { 'User-Agent': `tilde-lab-optimade-client/${version}` });
195
194
 
196
195
  const res = await fetchWithTimeout(url.toString(), { headers }, timeout);
197
196
 
@@ -225,4 +224,4 @@ export class Optimade {
225
224
  data.find(({ attributes }) => attributes.api_version === meta.api_version) :
226
225
  data;
227
226
  }
228
- }
227
+ }
@@ -1 +0,0 @@
1
- {"2dstructures":{"id":"2dstructures","type":"links","attributes":{"name":"2D Structures","description":"Two-dimensional (2D) materials from high-throughput computational exfoliation of experimentally known compounds.","base_url":"https://aiida.materialscloud.org/2dstructures/optimade","homepage":"https://materialscloud.org/explore/2dstructures","link_type":"child","aggregate":"ok","no_aggregate_reason":null}},"2dtopo":{"id":"2dtopo","type":"links","attributes":{"name":"2D topological insulators","description":"Quantum spin Hall insulator (QSHI) candidates through DFT band structure calculations of a database with 1825 compounds.","base_url":"https://aiida.materialscloud.org/2dtopo/optimade","homepage":"https://materialscloud.org/explore/2dtopo","link_type":"child","aggregate":"ok","no_aggregate_reason":null}},"aflow":{"id":"aflow","type":"links","attributes":{"name":"AFLOW","description":"The AFLOW OPTIMADE endpoint","base_url":"http://aflow.org/API/optimade/","homepage":"http://aflow.org","link_type":"child"}},"cod":{"id":"cod","type":"links","attributes":{"name":"Crystallography Open Database","description":"Open-access collection of crystal structures of organic, inorganic, metal-organics compounds and minerals, excluding biopolymers","base_url":"https://www.crystallography.net/cod/optimade","homepage":"https://www.crystallography.net/cod","link_type":"child"}},"curated-cofs":{"id":"curated-cofs","type":"links","attributes":{"name":"CURATED covalent organic frameworks database","description":"Database of experimentally reported Covalent-Organic Frameworks (COFs), provided with DFT-optimized geometry and DDEC partial charges for molecular simulations.","base_url":"https://aiida.materialscloud.org/curated-cofs/optimade","homepage":"https://materialscloud.org/discover/curated-cofs","link_type":"child","aggregate":"ok","no_aggregate_reason":null}},"jarvis":{"id":"jarvis","type":"links","attributes":{"name":"JARVIS-DFT","description":"JARVIS-DFT is a materials property repository focused on density functional theory (DFT) predictions of material properties, especially for crystalline materials.","base_url":"https://jarvis.nist.gov/optimade/jarvisdft","homepage":"https://jarvis.nist.gov","link_type":"child"}},"li-ion-conductors":{"id":"li-ion-conductors","type":"links","attributes":{"name":"Solid-state Li-ion conductors.","description":"High-throughput computational screening study for solid-state Li-ion conductors.","base_url":"https://aiida.materialscloud.org/li-ion-conductors/optimade","homepage":"https://materialscloud.org/explore/li-ion-conductors","link_type":"child","aggregate":"staging","no_aggregate_reason":null}},"mc3d-structures":{"id":"mc3d-structures","type":"links","attributes":{"name":"Materials Cloud three-dimensional crystals database","description":"Curated set of relaxed three-dimensional crystal structures based on raw CIF data from the experimantal databases MPDS, COD, and ICSD.","base_url":"https://aiida.materialscloud.org/mc3d-structures/optimade","homepage":"https://materialscloud.org/explore/mc3d-structures","link_type":"child","aggregate":"ok","no_aggregate_reason":null}},"mp":{"id":"mp","type":"links","attributes":{"name":"The Materials Project","description":"The Materials Project OPTIMADE endpoint","base_url":"https://optimade.materialsproject.org","homepage":"https://www.materialsproject.org","link_type":"child"}},"mpds":{"id":"mpds","type":"links","attributes":{"name":"Materials Platform for Data Science","description":"A highly curated Pauling File dataset based on ~0.5M publications and backing up Springer Materials, ICDD PDF, ASM APD, MedeA, Pearson Crystal Data, AtomWork Advanced, etc.","base_url":"https://api.mpds.io","homepage":"https://mpds.io","link_type":"child"}},"nmd":{"id":"nmd","type":"links","attributes":{"name":"novel materials discovery (NOMAD)","description":"A FAIR data sharing platform for materials science data","base_url":"https://nomad-lab.eu/prod/rae/optimade/","homepage":"https://nomad-lab.eu","link_type":"child"}},"odbx":{"id":"odbx","type":"links","attributes":{"name":"odbx","description":"The Open Database of Xtals is run by the group of Dr Andrew Morris at the universities of Birmingham and Cambridge and is constructed using the matador library.","base_url":"https://optimade.odbx.science","homepage":"https://odbx.science","link_type":"child","aggregate":"ok","no_aggregate_reason":null}},"omdb_production":{"id":"omdb_production","type":"links","attributes":{"name":"Open Materials Database (omdb) production database","description":"This is the main production version of the Open Materials Database","base_url":"http://optimade.openmaterialsdb.se","homepage":"http://openmaterialsdb.se","link_type":"child"}},"optimade-sample":{"id":"optimade-sample","type":"links","attributes":{"name":"OPTIMADE Sample Database","description":"Database with example structures for OPTIMADE tests.","base_url":"https://aiida.materialscloud.org/optimade-sample/optimade","homepage":"https://materialscloud.org/explore/optimade-sample","link_type":"child","aggregate":"test","no_aggregate_reason":null}},"pyrene-mofs":{"id":"pyrene-mofs","type":"links","attributes":{"name":"Pyrene MOFs","description":"Pyrene Metal Organic Frameworks (MOFs).","base_url":"https://aiida.materialscloud.org/pyrene-mofs/optimade","homepage":"https://materialscloud.org/discover/pyrene-mofs","link_type":"child","aggregate":"ok","no_aggregate_reason":null}},"scdm":{"id":"scdm","type":"links","attributes":{"name":"Automated high-throughput Wannierisation","description":"Validation results of an automated protocol for generating maximally-localized Wannier functions in a high-throughput framework.","base_url":"https://aiida.materialscloud.org/autowannier/optimade","homepage":"https://materialscloud.org/explore/autowannier","link_type":"child","aggregate":"ok","no_aggregate_reason":null}},"sssp":{"id":"sssp","type":"links","attributes":{"name":"Standard solid-state pseudopotentials (SSSP)","description":"It contains data generated from the testing protocol of the standard solid-state pseudopotentials library.\n","base_url":"https://aiida.materialscloud.org/sssplibrary/optimade","homepage":"https://materialscloud.org/explore/sssplibrary","link_type":"child","aggregate":"ok","no_aggregate_reason":null}},"stoceriaitf":{"id":"stoceriaitf","type":"links","attributes":{"name":"SrTiO3-CeO2 interfaces","description":"Refining random structure searching results of SrTiO3-CeO2 interfaces, and exploring how it can affect ionic conduction. Candidate structures of the DFT validation calculations.","base_url":"https://aiida.materialscloud.org/stoceriaitf/optimade","homepage":"https://materialscloud.org/explore/stoceriaitf","link_type":"child","aggregate":"ok","no_aggregate_reason":null}},"tc-applicability":{"id":"tc-applicability","type":"links","attributes":{"name":"Applicability of tail-corrections in the molecular simulations of porous materials","description":"Tail-corrections in molecular simulations for adsorption of gasses in a diverse set of nanoporous crystalline materials (zeolites, Covalent Organic Framworks (COFs), and Metal Organic Frameworks (MOFs)).","base_url":"https://aiida.materialscloud.org/tc-applicability/optimade","homepage":"https://materialscloud.org/explore/tc-applicability","link_type":"child","aggregate":"ok","no_aggregate_reason":null}},"tcod":{"id":"tcod","type":"links","attributes":{"name":"Theoretical Crystallography Open Database","description":"Open-access collection of theoretically calculated or refined crystal structures of organic, inorganic, metal-organic compounds and minerals, excluding biopolymers","base_url":"https://www.crystallography.net/tcod/optimade","homepage":"https://www.crystallography.net/tcod","link_type":"child"}},"tin-antimony-sulfoiodide":{"id":"tin-antimony-sulfoiodide","type":"links","attributes":{"name":"Hidden spontaneous polarisation in the chalcohalide photovoltaic Sn2SbS2I3","description":"Structural, dynamic and electronic characterisation of a novel mixed-metal chalcohalide revealing hidden symmetry breaking and spontaneous polarisation.","base_url":"https://aiida.materialscloud.org/tin-antimony-sulfoiodide/optimade","homepage":"https://materialscloud.org/explore/tin-antimony-sulfoiodide","link_type":"child","aggregate":"ok","no_aggregate_reason":null}},"twodmatpedia":{"id":"twodmatpedia","type":"links","attributes":{"name":"2DMatpedia","description":"2DMatpedia, an open computational database of two-dimensional materials from top-down and bottom-up approaches","base_url":"http://optimade.2dmatpedia.org","homepage":"http://2dmatpedia.org","link_type":"child"}}}