def get_contributions(self, limit=20): docs = self.query_contributions( projection={'_id': 1, 'identifier': 1, 'content': 1}, limit=limit) # use URL for all data if not docs: raise Exception('No contributions found for CarrierTransport Explorer!') data = [] columns = ['##'.join(['general', sk]) for sk in ['mp-id', 'cid', 'formula']] keys, subkeys = ['<mₑᶜᵒⁿᵈ>', '<S>', '<σ>', '<S²σ>'], ['n', 'p'] columns += ['##'.join([k, sk]) for k in keys for sk in subkeys] for doc in docs: mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] contrib = mpfile.hdata[mp_id] cid_url = self.get_cid_url(doc) row = [mp_id, cid_url, contrib['extra_data']['pretty_formula']] row += [ contrib['data'].get(k[1:-1], {}).get(sk, {}).get('<ε>', 'n.a. mₑ') for k in keys for sk in subkeys ] data.append((mp_id, row)) return Table.from_items(data, orient='index', columns=columns)
def get_contributions(self, doping): dopings = ['n', 'p'] if doping not in dopings: raise Exception('doping has to be n or p!') docs = self.query_contributions(projection={ '_id': 1, 'mp_cat_id': 1, 'content': 1 }) if not docs: raise Exception('No contributions found for Boltztrap Explorer!') data = [] columns = [ '##'.join(['general', sk]) for sk in ['mp-id', 'cid', 'formula'] ] keys, subkeys = [u'mₑᶜᵒⁿᵈ', u"Seebeck"], [u"e₁", u"e₂", u"e₃"] columns += ['##'.join([k, sk]) for k in keys for sk in subkeys] for doc in docs: mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] contrib = mpfile.hdata[mp_id]['data'] cid_url = self.get_cid_url(doc) row = [mp_id, cid_url, contrib['pretty_formula']] row += [ contrib[k].get(doping, {}).get(sk, '') for k in keys for sk in subkeys ] data.append((mp_id, row)) return Table.from_items(data, orient='index', columns=columns)
def get_contributions(self): docs = self.query_contributions( projection={'_id': 1, 'mp_cat_id': 1, 'content.data': 1} ) if not docs: raise Exception('No contributions found for MpWorkshop2017 Explorer!') data = [] columns = ['mp-id', 'contribution'] for doc in docs: mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] contrib = mpfile.hdata[mp_id]['data'] cid_url = self.get_cid_url(doc) for k in contrib.keys(): if k not in columns: columns.append(k) row = [mp_id, cid_url] for col in columns[2:]: row.append(contrib.get(col, '')) data.append([mp_id, row]) # enforce equal row lengths ncols = len(columns) for entry in data: n = len(entry[1]) if n != ncols: entry[1] += [''] * (ncols - n) return Table.from_items(data, orient='index', columns=columns)
def get_contributions(self): docs = self.query_contributions(projection={ '_id': 1, 'mp_cat_id': 1, 'content': 1 }) if not docs: raise Exception('No contributions found for SLAC MoSe2 Explorer!') import pandas as pd doc = docs[0] # there should be only one for MoSe2 mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] response = {} response['graphs'] = [ plot for key, plot in mpfile.gdata[mp_id].items() if 'pump' in key ] tdata = mpfile.tdata[mp_id] name = tdata.keys()[-1] table = tdata[name] table = table.apply(pd.to_numeric) table.dropna(how='any', inplace=True) response['traces'] = [] for col in table.columns[1:]: response['traces'].append({ 'x': table[table.columns[0]].values, 'y': table[col].values, 'name': col }) return response
def get_contributions(self): data = [] columns = [ 'mp-id', 'contribution', 'formula', 'CIF', 'dISO', 'etaQ', 'QCC', 'B' ] docs = self.query_contributions(projection={ '_id': 1, 'mp_cat_id': 1, 'content': 1 }) if not docs: raise Exception('No contributions found for Dibbs Explorer!') for doc in docs: mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] contrib = mpfile.hdata[mp_id] cid_url = self.get_cid_url(doc) row = [mp_id, cid_url, contrib['formula']] cif_url = '' structures = mpfile.sdata.get(mp_id) if structures: cif_url = '/'.join([ self.preamble.rsplit('/', 1)[0], 'explorer', 'materials', doc['_id'], 'cif', structures.keys()[0] ]) row.append(cif_url) row += [contrib['data'][col] for col in columns[-4:]] data.append((mp_id, row)) return Table.from_items(data, orient='index', columns=columns)
def get_contributions(self): data = [] columns = ['mp-id', 'contribution', 'efermi', 'ehull', 'bandgap'] docs = self.query_contributions(criteria=self.tam_perovskites_query, projection={ '_id': 1, 'mp_cat_id': 1, 'content.efermi': 1, 'content.ehull': 1, 'content.bandgap': 1 }) if not docs: raise Exception( 'No contributions found for TamPerovskites Explorer!') for doc in docs: mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] contrib = mpfile.hdata[mp_id] cid_url = '/'.join([ self.preamble.rsplit('/', 1)[0], 'explorer', 'materials', doc['_id'] ]) row = [ mp_id, cid_url, contrib['efermi'], contrib['ehull'], contrib['bandgap'] ] data.append((mp_id, row)) return DataFrame.from_items(data, orient='index', columns=columns)
def get_contributions(self): projection = {'_id': 1, 'identifier': 1, 'content.data': 1} docs = self.query_contributions(projection=projection) if not docs: raise Exception( 'No contributions found for RedoxThermoCsp Explorer!') data, columns = [], ['identifier', 'contribution'] for doc in docs: mpfile = MPFile.from_contribution(doc) identifier = mpfile.ids[0] contrib = mpfile.hdata[identifier]['data'] cid_url = self.get_cid_url(doc) row = [identifier, cid_url] scope = [] for key, value in contrib.iterate(): level, key = key level_reduction = bool(level < len(scope)) if level_reduction: del scope[level:] if value is None: scope.append(key) else: col = '##'.join(scope + [key]).replace('_', ' ') if col not in columns: columns.append(col) row.append(value) data.append((identifier, row)) return Table.from_items(data, orient='index', columns=columns)
def get_contributions(self, phase=None): data = [] phase_query_key = {'$exists': 1} if phase is None else phase columns = ['mp-id', 'contribution', 'formula'] if phase is None: columns.append('phase') columns += ['dH (formation)', 'dH (hydration)', 'GS?', 'CIF'] for doc in self.query_contributions(criteria={ 'project': { '$in': ['LBNL', 'MIT'] }, 'content.info.Phase': phase_query_key }, projection={ '_id': 1, 'mp_cat_id': 1, 'content': 1 }): mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] info = mpfile.hdata[mp_id]['info'] row = [mp_id, get_short_object_id(doc['_id']), info['Formula']] if phase is None: row.append(info['Phase']) row += [info['dHf'], info['dHh'], info['GS'], 'TODO'] # TODO URLs for mp_id and cid data.append((mp_id, row)) return DataFrame.from_items(data, orient='index', columns=columns)
def get_provenance(self): for doc in self.query_contributions(criteria={ 'project': { '$in': ['LBNL', 'MIT'] }, 'content.Authors': { '$exists': 1 }, 'content.Title': { '$exists': 1 }, 'content.Reference': { '$exists': 1 } }, projection={ '_id': 1, 'mp_cat_id': 1, 'content.Authors': 1, 'content.Reference': 1, 'content.Title': 1 }): mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] return mpfile.hdata[mp_id]
def get_uwsi2_contributions(self): data = [] for doc in self.query_contributions(criteria={ 'project': { '$in': ['LBNL', 'UW-Madison'] }, 'content.figshare_id': { '$exists': 1 } }, projection={ '_id': 1, 'mp_cat_id': 1, 'content': 1 }): mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] table = mpfile.tdata[mp_id]['data_D0_Q'] anums = [self.z[el] for el in table['element']] table.insert(0, 'Z', Series(anums, index=table.index)) table.sort_values('Z', inplace=True) table.reset_index(drop=True, inplace=True) hdata = mpfile.hdata[mp_id] data.append({ 'mp_id': mp_id, 'cid': doc['_id'], 'short_cid': get_short_object_id(doc['_id']), 'formula': hdata['formula'], 'table': table }) return data
def get_contributions(self): data = [] columns = ['mp-id', 'contribution', 'formula', 'CIF', 'dISO', 'etaQ', 'QCC', 'B'] docs = self.query_contributions( projection={'_id': 1, 'mp_cat_id': 1, 'content': 1} ) if not docs: raise Exception('No contributions found for Dibbs Explorer!') for doc in docs: mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] contrib = mpfile.hdata[mp_id] cid_url = self.get_cid_url(doc) row = [mp_id, cid_url, contrib['formula']] cif_url = '' structures = mpfile.sdata.get(mp_id) if structures: cif_url = '/'.join([ self.preamble.rsplit('/', 1)[0], 'explorer', 'materials', doc['_id'], 'cif', structures.keys()[0] ]) row.append(cif_url) row += [contrib['data'][col] for col in columns[-4:]] data.append((mp_id, row)) return Table.from_items(data, orient='index', columns=columns)
def get_contributions(self): docs = self.query_contributions( projection={'_id': 1, 'mp_cat_id': 1, 'content': 1} ) if not docs: raise Exception('No contributions found for SLAC MoSe2 Explorer!') import pandas as pd doc = docs[0] # there should be only one for MoSe2 mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] response = {} response['graphs'] = [ plot for key, plot in mpfile.gdata[mp_id].items() if 'pump' in key ] tdata = mpfile.tdata[mp_id] name = tdata.keys()[-1] table = tdata[name] table = table.apply(pd.to_numeric) table.dropna(how='any', inplace=True) response['traces'] = [] for col in table.columns[1:]: response['traces'].append({ 'x': table[table.columns[0]].values, 'y': table[col].values, 'name': col }) return response
def get_detail_data(self,doping): ''' function to get doping and temperature related to the max values and the three eigenvalues of the effective mass tensor ''' dopings = ['n', 'p'] if doping not in dopings: raise Exception('doping has to be n or p!') docs = self.query_contributions(projection={'_id': 1, 'identifier': 1, 'content': 1}) if not docs: raise Exception('No contributions found for CarrierTransport Explorer!') data = [] columns = ['mp-id', 'cid', 'formula', u'mₑᶜᵒⁿᵈ', u"Sₘₐₓ", u"σₘₐₓ", u"κₑ₋ₘᵢₙ"] for doc in docs: mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] contrib = mpfile.hdata[mp_id]['data'] details = {k:[contrib[k][doping]['temperature'],contrib[k][doping]['doping']] for k in columns[4:]} data.append((mp_id, details)) return data
def get_contributions(self, limit=20): docs = self.query_contributions(projection={ '_id': 1, 'identifier': 1, 'content': 1 }, limit=limit) # use URL for all data if not docs: raise Exception( 'No contributions found for CarrierTransport Explorer!') data = [] columns = [ '##'.join(['general', sk]) for sk in ['mp-id', 'cid', 'formula'] ] keys, subkeys = ['<mₑᶜᵒⁿᵈ>', '<S>', '<σ>', '<S²σ>'], ['n', 'p'] columns += ['##'.join([k, sk]) for k in keys for sk in subkeys] for doc in docs: mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] contrib = mpfile.hdata[mp_id] cid_url = self.get_cid_url(doc) row = [mp_id, cid_url, contrib['extra_data']['pretty_formula']] row += [ contrib['data'].get(k[1:-1], {}).get(sk, {}).get('<ε>', 'n.a. mₑ') for k in keys for sk in subkeys ] data.append((mp_id, row)) return Table.from_items(data, orient='index', columns=columns)
def get_contributions(self): projection = {'_id': 1, 'identifier': 1, 'content': 1} docs = self.query_contributions(projection=projection) if not docs: raise Exception('No contributions found for ALS Beamline Explorer!') data = [] columns = ['formula', 'cid'] keys = RecursiveDict([ ('composition', ['Co', 'Cu', 'Ce']), #('position', ['x', 'y']), ('XAS', ['min', 'max']), ('XMCD', ['min', 'max']) ]) columns += ['##'.join([k, sk]) for k, subkeys in keys.items() for sk in subkeys] for doc in docs: mpfile = MPFile.from_contribution(doc) identifier = mpfile.ids[0] contrib = mpfile.hdata[identifier]['data'] cid_url = self.get_cid_url(doc) row = [identifier, cid_url] row += [contrib[k][sk] for k, subkeys in keys.items() for sk in subkeys] data.append((identifier, row)) return Table.from_items(data, orient='index', columns=columns)
def get_ionic_radii(self): data = [] columns = ['mp-id', 'cid', 'species', 'charge', u'rᵢₒₙ', 'HS/LS', 'CN'] docs = self.query_contributions( criteria={'content.title': 'Ionic Radii'}, projection={'_id': 1, 'mp_cat_id': 1, 'content.data': 1} ) if not docs: raise Exception('No contributions found for DlrVieten Ionic Radii!') for doc in docs: mpfile = MPFile.from_contribution(doc) identifier = mpfile.ids[0] contrib = mpfile.hdata[identifier]['data'] cid_url = '/'.join([ self.preamble.rsplit('/', 1)[0], 'explorer', 'materials', doc['_id'] ]) nrows = sum(1 for v in contrib.values() if isinstance(v, dict)) rows = [[identifier, cid_url] for i in range(nrows)] for col in columns[2:]: for irow, row in enumerate(rows): val = contrib.get(col) if val is None: val = contrib[str(irow)].get(col, '-') row.append(val) for row in rows: data.append((identifier, row)) return Table.from_items(data, orient='index', columns=columns)
def get_contributions(self): data = [] columns = ['identifier', 'contribution', 'composition', 'CIF'] docs = self.query_contributions( criteria={'content.title': {'$ne': 'Ionic Radii'}}, projection={'_id': 1, 'mp_cat_id': 1, 'content': 1} ) if not docs: raise Exception('No contributions found for DlrVieten Explorer!') for doc in docs: mpfile = MPFile.from_contribution(doc) identifier = mpfile.ids[0] contrib = mpfile.hdata[identifier] cid_url = self.get_cid_url(doc) row = [identifier, cid_url, contrib['composition']] cif_url = '' structures = mpfile.sdata.get(identifier) if structures: cif_url = '/'.join([ self.preamble.rsplit('/', 1)[0], 'explorer', 'materials', doc['_id'], 'cif', structures.keys()[0] ]) row.append(cif_url) data.append((identifier, row)) return Table.from_items(data, orient='index', columns=columns)
def get_contributions(self): projection = {'_id': 1, 'mp_cat_id': 1, 'content': 1} docs = self.query_contributions(projection=projection) if not docs: raise Exception('No contributions found for ALS Beamline Explorer!') data = [] columns = ['formula', 'cid'] keys = RecursiveDict([ ('composition', ['Co', 'Cu', 'Ce']), #('position', ['x', 'y']), ('XAS', ['min', 'max']), ('XMCD', ['min', 'max']) ]) columns += ['##'.join([k, sk]) for k, subkeys in keys.items() for sk in subkeys] for doc in docs: mpfile = MPFile.from_contribution(doc) identifier = mpfile.ids[0] contrib = mpfile.hdata[identifier]['data'] cid_url = self.get_cid_url(doc) row = [identifier, cid_url] row += [contrib[k][sk] for k, subkeys in keys.items() for sk in subkeys] data.append((identifier, row)) return Table.from_items(data, orient='index', columns=columns)
def get_ionic_radii(self): data = [] columns = ['mp-id', 'cid', 'species', 'charge', u'rᵢₒₙ', 'HS/LS', 'CN'] docs = self.query_contributions( criteria={'content.title': 'Ionic Radii'}, projection={'_id': 1, 'identifier': 1, 'content.data': 1} ) if not docs: raise Exception('No contributions found for RedoxThermoCsp Ionic Radii!') for doc in docs: mpfile = MPFile.from_contribution(doc) identifier = mpfile.ids[0] contrib = mpfile.hdata[identifier]['data'] cid_url = '/'.join([ self.preamble.rsplit('/', 1)[0], 'explorer', 'materials', doc['_id'] ]) nrows = sum(1 for v in contrib.values() if isinstance(v, dict)) rows = [[identifier, cid_url] for i in range(nrows)] for col in columns[2:]: for irow, row in enumerate(rows): val = contrib.get(col) if val is None: val = contrib[str(irow)].get(col, '-') row.append(val) for row in rows: data.append((identifier, row)) return Table.from_items(data, orient='index', columns=columns)
def get_contributions(self): projection = {'_id': 1, 'identifier': 1, 'content.data': 1} docs = self.query_contributions(projection=projection) if not docs: raise Exception('No contributions found for RedoxThermoCsp Explorer!') data, columns = [], ['identifier', 'contribution'] for doc in docs: mpfile = MPFile.from_contribution(doc) identifier = mpfile.ids[0] contrib = mpfile.hdata[identifier]['data'] cid_url = self.get_cid_url(doc) row = [identifier, cid_url] scope = [] for key, value in contrib.iterate(): level, key = key level_reduction = bool(level < len(scope)) if level_reduction: del scope[level:] if value is None: scope.append(key) else: col = '##'.join(scope + [key]).replace('_', ' ') if col not in columns: columns.append(col) row.append(value) data.append((identifier, row)) return Table.from_items(data, orient='index', columns=columns)
def get_contributions(self): docs = self.query_contributions( projection={'_id': 1, 'mp_cat_id': 1, 'content.data': 1} ) if not docs: raise Exception('No contributions found for SWF Explorer!') data = [] columns = ['formula', 'contribution'] ncols = 9 for doc in docs: mpfile = MPFile.from_contribution(doc) formula = mpfile.ids[0] contrib = mpfile.hdata[formula].get('data') if contrib is None: continue cid_url = self.get_cid_url(doc) for k in contrib.keys(): if k not in columns: columns.append(k) row = [formula, cid_url] for col in columns[2:]: row.append(contrib.get(col, '')) n = len(row) if n < ncols: row += [''] * (ncols - n) data.append((formula, row)) return Table.from_items(data, orient='index', columns=columns)
def get_contributions(self): docs = self.query_contributions( projection={'_id': 1, 'mp_cat_id': 1, 'content': 1} ) if not docs: raise Exception('No contributions found for JarvisDft Explorer!') data, data_jarvis = [], [] general_columns = ['mp-id', 'cid', 'formula'] keys, subkeys = ['NUS', 'JARVIS'], ['id', 'Eₓ', 'CIF'] columns = general_columns + ['##'.join([k, sk]) for k in keys for sk in subkeys] columns_jarvis = general_columns + ['id', 'E', 'ΔE|optB88vdW', 'ΔE|mbj', 'CIF'] for doc in docs: mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] contrib = mpfile.hdata[mp_id]['data'] cid_url = self.get_cid_url(doc) structures = mpfile.sdata.get(mp_id) cif_urls = {} for k in keys: cif_urls[k] = '' name = '{}_{}'.format(contrib['formula'], k) if structures.get(name) is not None: cif_urls[k] = '/'.join([ self.preamble.rsplit('/', 1)[0], 'explorer', 'materials', doc['_id'], 'cif', name ]) row = [mp_id, cid_url, contrib['formula']] for k in keys: for sk in subkeys: if sk == subkeys[-1]: row.append(cif_urls[k]) else: cell = contrib.get(k, {sk: ''})[sk] row.append(cell) data.append((mp_id, row)) row_jarvis = [mp_id, cid_url, contrib['formula']] for k in columns_jarvis[len(general_columns):]: if k == columns_jarvis[-1]: row_jarvis.append(cif_urls[keys[1]]) else: row_jarvis.append(contrib.get(keys[1], {k: ''}).get(k, '')) if row_jarvis[3]: data_jarvis.append((mp_id, row_jarvis)) return [ Table.from_items(data, orient='index', columns=columns), Table.from_items(data_jarvis, orient='index', columns=columns_jarvis) ]
def get_provenance(self): provenance_keys = ['authors', 'abbreviations'] projection = {'_id': 1, 'mp_cat_id': 1} for key in provenance_keys: projection['content.' + key] = 1 docs = self.query_contributions(criteria=self.tam_perovskites_query, projection=projection) if not docs: raise Exception('No contributions found for DTU Explorer!') mpfile = MPFile.from_contribution(docs[0]) mp_id = mpfile.ids[0] return mpfile.hdata[mp_id]
def table(request, db_type=None, mdb=None): try: page = int(request.GET.get('page', '1')) crit = {'project': 'carrier_transport'} search = request.GET.get('q') if search is not None: crit.update({'content.extra_data.pretty_formula': {'$regex': search}}) proj = {'content.data': 1, 'content.extra_data': 1, 'identifier': 1} total_count = mdb.contrib_ad.query_contributions(crit).count() last_id = None if page is not None and page > 1: limit = (page-1) * 20 # TODO page_size from where? ids = [d['_id'] for d in mdb.contrib_ad.query_contributions(crit, limit=limit)] last_id = ids[-1] sort = {'key': request.GET.get('sort'), 'order': request.GET.get('order')} docs, last_id = mdb.contrib_ad.query_paginate(crit, projection=proj, last_id=last_id, sort=sort) if not docs: raise Exception('No contributions found for CarrierTransport Explorer!') items = [] columns = ['##'.join(['general', sk]) for sk in ['mp-id', 'cid', 'formula']] keys, subkeys = {'<mₑᶜᵒⁿᵈ>': '[mₑ]', '<S>': '[μV/K]', '<σ>': '[(Ωms)⁻¹]', '<S²σ>': '[μW/(cmK²s)]'}, ['n', 'p'] columns += ['##'.join([k, ' '.join([sk, keys[k]])]) for k in keys for sk in subkeys] for doc in docs: mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] contrib = mpfile.hdata[mp_id] cid_url = '/'.join([ request.build_absolute_uri(request.path).rsplit('/', 3)[0], 'explorer', 'materials' , unicode(doc['_id']) ]) mp_id_url = 'https://materialsproject.org/materials/{}'.format(mp_id) row = [mp_id_url, cid_url, contrib['extra_data']['pretty_formula']] row += [ contrib['data'].get(k[1:-1], {}).get(sk, {}).get('<ε>', '-').split()[0] for k in keys for sk in subkeys ] items.append(dict((k, v) for k, v in zip(columns, row))) per_page = len(items) total_pages = total_count/per_page if total_pages%per_page: total_pages += 1 response = { 'total_count': total_count, 'total_pages': total_pages, 'page': page, 'last_page': total_pages, 'per_page': per_page, 'last_id': last_id, 'items': items } except Exception as ex: raise ValueError('"REST Error: "{}"'.format(str(ex))) return response
def get_graphs(self): docs = self.query_contributions( projection={'_id': 1, 'mp_cat_id': 1, 'content': 1} ) if not docs: raise Exception('No contributions found for MpWorkshop2017 Explorer!') graphs = {} for doc in docs: mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] graphs[mp_id] = mpfile.gdata[mp_id] return graphs
def get_graphs(self): docs = self.query_contributions( criteria={'project': {'$in': ['LBNL']}, 'content.formula': 'MoSe2'}, projection={'_id': 1, 'mp_cat_id': 1, 'content': 1} ) if not docs: raise Exception('No contributions found for SLAC MoSe2 Explorer!') doc = docs[0] # there should be only one for MoSe2 mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] graphs = mpfile.gdata[mp_id] return graphs
def get_provenance(self): provenance_keys = [ 'title', 'url', 'explanation', 'references', 'authors', 'contributor' ] projection = {'_id': 1, 'mp_cat_id': 1} for key in provenance_keys: projection['content.' + key] = 1 docs = self.query_contributions(criteria=self.dtu_query, projection=projection) if not docs: raise Exception('No contributions found for DTU Explorer!') mpfile = MPFile.from_contribution(docs[0]) mp_id = mpfile.ids[0] return mpfile.hdata[mp_id]
def get_contributions(self, typ): types = ['2d', '3d'] if typ not in types: raise Exception('typ has to be 2d or 3d!') docs = self.query_contributions( criteria={'content.data.{}'.format(typ): { '$exists': 1 }}, projection={ '_id': 1, 'mp_cat_id': 1, 'content': 1 }) if not docs: raise Exception('No contributions found for JarvisDft Explorer!') data = [] columns = [ 'mp-id', 'cid', 'CIF', 'final_energy', 'optB88vDW_bandgap', 'mbj_bandgap', 'bulk_modulus', 'shear_modulus', 'jid' ] for doc in docs: mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] hdata = mpfile.hdata[mp_id] contrib = hdata['data'][typ] cid_url = self.get_cid_url(doc) cif_url = '' structures = mpfile.sdata.get(mp_id) if structures: cif_url = '/'.join([ self.preamble.rsplit('/', 1)[0], 'explorer', 'materials', doc['_id'], 'cif', structures.keys()[0] ]) row = [mp_id, cid_url, cif_url ] + [contrib[k] for k in columns[3:-1]] row.append(hdata['details_url'].format(contrib['jid'])) data.append((mp_id, row)) return Table.from_items(data, orient='index', columns=columns)
def get_contributions(self, bandgap_range=None): projection = { '_id': 1, 'identifier': 1, 'content.formula': 1, 'content.ICSD': 1, 'content.data': 1 } docs = self.query_contributions(projection=projection) if not docs: raise Exception('No contributions found for DTU Explorer!') data = [] columns = ['mp-id', 'cid', 'formula', 'ICSD', 'C'] keys, subkeys = ['ΔE-KS', 'ΔE-QP'], ['indirect', 'direct'] columns += ['##'.join([k, sk]) for k in keys for sk in subkeys] for doc in docs: mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] contrib = mpfile.hdata[mp_id] cid_url = self.get_cid_url(doc) row = [ mp_id, cid_url, contrib['formula'], contrib['ICSD'], contrib['data']['C'] ] row += [contrib['data'][k][sk] for k in keys for sk in subkeys] if bandgap_range: in_filter = True for k, v in bandgap_range.iteritems(): ks = k.split('_') val = contrib['data'][ks[0]][ ks[1]] if len(ks) > 1 else contrib['data'][k] dec = float(val.split()[0]) if dec < v[0] or dec > v[1]: in_filter = False break if in_filter: data.append((mp_id, row)) else: data.append((mp_id, row)) return Table.from_items(data, orient='index', columns=columns)
def get_contributions(self, phase=None): data = [] phase_query_key = {'$exists': 1} if phase is None else phase columns = ['mp-id', 'contribution', 'formula'] if phase is None: columns.append('phase') columns += ['dH (formation)', 'dH (hydration)', 'GS?', 'CIF'] docs = self.query_contributions( criteria={ 'content.doi': '10.1021/jacs.6b11301', 'content.data.Phase': phase_query_key }, projection={ '_id': 1, 'mp_cat_id': 1, 'content.data': 1, 'content.{}'.format(mp_level01_titles[3]): 1 } ) if not docs: raise Exception('No contributions found for MnO2 Phase Selection Explorer!') for doc in docs: mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] contrib = mpfile.hdata[mp_id]['data'] cid_url = '/'.join([ self.preamble.rsplit('/', 1)[0], 'explorer', 'materials', doc['_id'] ]) row = [mp_id, cid_url, contrib['Formula']] if phase is None: row.append(contrib['Phase']) row += [contrib['dHf'], contrib['dHh'], contrib['GS']] cif_url = '' structures = mpfile.sdata.get(mp_id) if structures: cif_url = '/'.join([ self.preamble.rsplit('/', 1)[0], 'explorer', 'materials', doc['_id'], 'cif', structures.keys()[0] ]) row.append(cif_url) data.append((mp_id, row)) return DataFrame.from_items(data, orient='index', columns=columns)
def get_provenance(self): docs = self.query_contributions( criteria={ 'project': {'$in': ['LBNL']}, 'content.authors': {'$exists': 1}, 'content.description': {'$exists': 1}, 'content.reference': {'$exists': 1} }, projection={ '_id': 1, 'mp_cat_id': 1, 'content.authors': 1, 'content.reference': 1, 'content.description': 1 } ) if not docs: raise Exception('No contributions found for SLAC MoSe2 Explorer!') mpfile = MPFile.from_contribution(docs[0]) mp_id = mpfile.ids[0] return mpfile.hdata[mp_id]
def get_contributions(self): docs = self.query_contributions( projection={'_id': 1, 'mp_cat_id': 1, 'content.data': 1, 'content.abbreviations': 1} ) if not docs: raise Exception('No contributions found for PerovskitesDiffusion Explorer!') data, columns = [], None for doc in docs: mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] contrib = mpfile.hdata[mp_id]['data'] cid_url = self.get_cid_url(doc) if columns is None: columns = ['mp-id', 'contribution'] + contrib.keys() row = [mp_id, cid_url] + contrib.values() data.append((mp_id, row)) return Table.from_items(data, orient='index', columns=columns)
def get_contributions(self): data = [] for doc in self.query_contributions( projection={'_id': 1, 'mp_cat_id': 1, 'content': 1} ): mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] table = mpfile.tdata[mp_id][mp_level01_titles[1]+'_D0_Q'] anums = [self.z[el] for el in table['element']] table.insert(0, 'Z', Series(anums, index=table.index)) table.sort_values('Z', inplace=True) table.reset_index(drop=True, inplace=True) hdata = mpfile.hdata[mp_id] data.append({ 'mp_id': mp_id, 'cid': doc['_id'], 'short_cid': get_short_object_id(doc['_id']), 'formula': hdata['formula'], 'table': table }) return data
def get_provenance(self): docs = self.query_contributions( criteria={ 'content.doi': '10.1021/jacs.6b11301', 'content.authors': {'$exists': 1}, 'content.title': {'$exists': 1}, 'content.reference': {'$exists': 1} }, projection={ '_id': 1, 'mp_cat_id': 1, 'content.authors': 1, 'content.reference': 1, 'content.title': 1 } ) if not docs: raise Exception('No contributions found for MnO2 Phase Selection Explorer!') for doc in docs: mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] return mpfile.hdata[mp_id]
def get_all_spectra(self, typ): types = ['XAS', 'XMCD'] if typ not in types: raise Exception('{} not in {}'.format(typ, types)) projection = {'_id': 1, 'mp_cat_id': 1, 'content.Co': 1} docs = self.query_contributions(projection=projection) if not docs: raise Exception('No contributions found for ALS Beamline Explorer!') table = Table() for doc in docs: mpfile = MPFile.from_contribution(doc) identifier = mpfile.ids[0] df = mpfile.tdata[identifier]['Co'] if 'Energy' not in table.columns: table['Energy'] = df['Energy'] table[identifier] = df[typ] return Plot({'x': 'Energy', 'table': typ, 'showlegend': False}, table)
def get_all_spectra(self, typ): types = ['XAS', 'XMCD'] if typ not in types: raise Exception('{} not in {}'.format(typ, types)) projection = {'_id': 1, 'identifier': 1, 'content.Co': 1} docs = self.query_contributions(projection=projection) if not docs: raise Exception('No contributions found for ALS Beamline Explorer!') table = Table() for doc in docs: mpfile = MPFile.from_contribution(doc) identifier = mpfile.ids[0] df = mpfile.tdata[identifier]['Co'] if 'Energy' not in table.columns: table['Energy'] = df['Energy'] table[identifier] = df[typ] return Plot({'x': 'Energy', 'table': typ, 'showlegend': False}, table)
def get_contributions(self): data = [] columns = [ 'mp-id', 'contribution', 'kohn-sham_bandgap(indirect)', 'kohn-sham_bandgap(direct)', 'derivative_discontinuity', 'quasi-particle_bandgap(indirect)', 'quasi-particle_bandgap(direct)' ] docs = self.query_contributions( criteria=self.dtu_query, projection={ '_id': 1, 'mp_cat_id': 1, 'content.kohn-sham_bandgap.indirect': 1, 'content.kohn-sham_bandgap.direct': 1, 'content.derivative_discontinuity': 1, 'content.quasi-particle_bandgap.indirect': 1, 'content.quasi-particle_bandgap.direct': 1 }) if not docs: raise Exception('No contributions found for DTU Explorer!') for doc in docs: mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] contrib = mpfile.hdata[mp_id] cid_url = '/'.join([ self.preamble.rsplit('/', 1)[0], 'explorer', 'materials', doc['_id'] ]) row = [ mp_id, cid_url, contrib['kohn-sham_bandgap']['indirect'], contrib['kohn-sham_bandgap']['direct'], contrib['derivative_discontinuity'], contrib['quasi-particle_bandgap']['indirect'], contrib['quasi-particle_bandgap']['direct'] ] data.append((mp_id, row)) return DataFrame.from_items(data, orient='index', columns=columns)
def get_contributions(self): docs = self.query_contributions( projection={'_id': 1, 'mp_cat_id': 1, 'content.data': 1} ) if not docs: raise Exception('No contributions found for PCFC Explorer!') data = [] columns = ['mp-id', 'cid'] for doc in docs: mpfile = MPFile.from_contribution(doc) mpid = mpfile.ids[0] contrib = mpfile.hdata[mpid]['data'] cid_url = self.get_cid_url(doc) row = [mpid, cid_url] if len(columns) == 2: columns += [k for k in contrib.keys()] for col in columns[2:]: row.append(contrib.get(col, '')) data.append((mpid, row)) return Table.from_items(data, orient='index', columns=columns)
def get_contributions(self, phase=None): data = [] phase_query_key = {'$exists': 1} if phase is None else phase columns = ['mp-id', 'contribution', 'formula'] if phase is None: columns.append('phase') columns += ['ΔH', 'ΔHₕ', 'GS?', 'CIF'] docs = self.query_contributions( criteria={'content.data.Phase': phase_query_key}, projection={ '_id': 1, 'mp_cat_id': 1, 'content.data': 1, 'content.{}'.format(mp_level01_titles[3]): 1 } ) if not docs: raise Exception('No contributions found for MnO2 Phase Selection Explorer!') for doc in docs: mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] contrib = mpfile.hdata[mp_id]['data'] cid_url = self.get_cid_url(doc) row = [mp_id, cid_url, contrib['Formula'].replace(' ', '')] if phase is None: row.append(contrib['Phase']) row += [contrib['ΔH'], contrib['ΔHₕ'], contrib['GS']] cif_url = '' structures = mpfile.sdata.get(mp_id) if structures: cif_url = '/'.join([ self.preamble.rsplit('/', 1)[0], 'explorer', 'materials', doc['_id'], 'cif', structures.keys()[0] ]) row.append(cif_url) data.append((mp_id, row)) return Table.from_items(data, orient='index', columns=columns)
def get_detail_data(self, doping): ''' function to get doping and temperature related to the max values and the three eigenvalues of the effective mass tensor ''' dopings = ['n', 'p'] if doping not in dopings: raise Exception('doping has to be n or p!') docs = self.query_contributions(projection={ '_id': 1, 'identifier': 1, 'content': 1 }) if not docs: raise Exception( 'No contributions found for CarrierTransport Explorer!') data = [] columns = [ 'mp-id', 'cid', 'formula', u'mₑᶜᵒⁿᵈ', u"Sₘₐₓ", u"σₘₐₓ", u"κₑ₋ₘᵢₙ" ] for doc in docs: mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] contrib = mpfile.hdata[mp_id]['data'] details = { k: [ contrib[k][doping]['temperature'], contrib[k][doping]['doping'] ] for k in columns[4:] } data.append((mp_id, details)) return data
def get_contributions(self, host): hosts = self.get_hosts() if host not in hosts: raise Exception('{} not a host: {}'.format(host, hosts)) projection = {'_id': 1, 'mp_cat_id': 1, 'content.D₀_Q': 1} docs = self.query_contributions( criteria={'content.data.formula': host}, projection=projection) if not docs: raise Exception( 'No contributions found for DiluteSoluteDiffusion Explorer!') from pandas import Series mpfile = MPFile.from_contribution(docs[0]) mp_id = mpfile.ids[0] table = mpfile.tdata[mp_id]['D₀_Q'] for col in table.columns: table[col] = table[col].apply(lambda x: clean_value(x)) anums = [self.z[el] for el in table['El.']] table.insert(0, 'Z', Series(anums, index=table.index)) table.sort_values('Z', inplace=True) table.reset_index(drop=True, inplace=True) return table
def get_contributions(self, bandgap_range=None): projection = { '_id': 1, 'mp_cat_id': 1, 'content.formula': 1, 'content.ICSD': 1, 'content.data': 1 } docs = self.query_contributions(projection=projection) if not docs: raise Exception('No contributions found for DTU Explorer!') data = [] columns = ['mp-id', 'cid', 'formula', 'ICSD', 'C'] keys, subkeys = ['ΔE-KS', 'ΔE-QP'], ['indirect', 'direct'] columns += ['##'.join([k, sk]) for k in keys for sk in subkeys] for doc in docs: mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] contrib = mpfile.hdata[mp_id] cid_url = self.get_cid_url(doc) row = [mp_id, cid_url, contrib['formula'], contrib['ICSD'], contrib['data']['C']] row += [contrib['data'][k][sk] for k in keys for sk in subkeys] if bandgap_range: in_filter = True for k, v in bandgap_range.iteritems(): ks = k.split('_') val = contrib['data'][ks[0]][ks[1]] if len(ks) > 1 else contrib['data'][k] dec = float(val.split()[0]) if dec < v[0] or dec > v[1]: in_filter = False break if in_filter: data.append((mp_id, row)) else: data.append((mp_id, row)) return Table.from_items(data, orient='index', columns=columns)
def get_contributions(self): docs = self.query_contributions(projection={ '_id': 1, 'identifier': 1, 'content.data': 1 }) if not docs: raise Exception('No contributions found for PCFC Explorer!') data = [] columns = ['mp-id', 'cid'] for doc in docs: mpfile = MPFile.from_contribution(doc) mpid = mpfile.ids[0] contrib = mpfile.hdata[mpid]['data'] cid_url = self.get_cid_url(doc) row = [mpid, cid_url] if len(columns) == 2: columns += [k for k in contrib.keys()] for col in columns[2:]: row.append(contrib.get(col, '')) data.append((mpid, row)) return Table.from_items(data, orient='index', columns=columns)
def get_contributions(self): projection = {'_id': 1, 'mp_cat_id': 1, 'content': 1} docs = self.query_contributions(projection=projection) if not docs: raise Exception('No contributions found for DTU Explorer!') data = [] columns = [ 'mp-id', 'cid', 'indirect ΔE-KS', 'direct ΔE-KS', 'C', 'indirect ΔE-QP', 'direct ΔE-QP' ] for doc in docs: mpfile = MPFile.from_contribution(doc) mp_id = mpfile.ids[0] contrib = mpfile.hdata[mp_id]['data'] cid_url = self.get_cid_url(doc) row = [ mp_id, cid_url, contrib['ΔE-KS']['indirect'], contrib['ΔE-KS']['direct'], contrib['C'], contrib['ΔE-QP']['indirect'], contrib['ΔE-QP']['direct'] ] data.append((mp_id, row)) return Table.from_items(data, orient='index', columns=columns)