Example #1
0
 def compile(self):
     """compile phase (calculation from MAST DiffusionCoefficient.py)"""
     from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
     from pymatgen.matproj.rest import MPRester
     indirs = glob.glob(os.path.join(self.rootdir, "*CuCu*")) + [
         fn for fn in glob.glob(os.path.join(self.rootdir, "*Cu*"))
         if not fnmatch.fnmatch(fn, "*CuCu*")
     ]
     mp_id, E0, nw = None, None, 5 # five-frequency model
     df = None
     for idx,indir in enumerate(indirs):
         element = os.path.basename(indir).split('_')[2][2:]
         struct = self.find_entry_for_directory(
             os.path.join(indir, 'perfect_stat*'), oszicar=False
         ).structure
         reduced = SpacegroupAnalyzer(struct, symprec=1e-2).get_primitive_standard_structure()
         if idx == 0:
             ENDPOINT = "https://www.materialsproject.org/rest"
             with MPRester(endpoint=ENDPOINT) as m:
                 matches = m.find_structure(reduced)
                 if len(matches) == 1: mp_id = matches[0]
                 else: raise ValueError(
                     "found {} matching structure(s) in MP and hence cannot "
                     "assign structure in {}.".format(len(matches), indir)
                 )
         a = reduced.lattice.abc[0] * math.sqrt(2) * 10**(-8)
         enebarr = np.array([ self.get_barrier(indir, i) for i in range(nw) ], dtype=float)
         if idx == 0: E0 = min(enebarr[~np.isnan(enebarr)])
         else: enebarr[0] = E0 # TODO: is this correct?
         v = np.array([ self.get_attempt_frequency(indir, i) for i in range(nw) ])
         v[0], HVf, kB, f0 = 1.0, 0.4847, 8.6173324e-5, 0.7815 # TODO set v[0] to 1.0? HVf dynamic how?
         t, tempstep, tempend = 0.0, 0.1, 2.0 # default temperature range
         x, y = [], []
         while t < tempend + tempstep:
             v *= np.exp(-enebarr/kB/1e3*t)
             alpha = v[4]/v[0]
             F_num = 10*np.power(alpha,4) + 180.5*np.power(alpha,3)
             F_num += 927*np.power(alpha,2) + 1341*alpha
             F_denom = 2*np.power(alpha,4) + 40.2*np.power(alpha,3)
             F_denom += 254*np.power(alpha,2) + 597*alpha + 435
             FX = 1-(1.0/7.0)*(F_num/F_denom)
             f2 = 1+3.5*FX*(v[3]/v[1])
             f2 /= 1+(v[2]/v[1]) + 3.5*FX*(v[3]/v[1])
             cV = np.exp(-HVf/kB/1e3*t) if t > 0. else 1.
             D = f0*cV*a**2*v[0] * f2/f0 * v[4]/v[0] * v[2]/v[3]
             x.append(t)
             y.append(D)
             t += tempstep
         if df is None: df = DataFrame(np.array(x), columns=['1/T'])
         df.loc[:,element] = Series(np.array(y), index=df.index)
     #  generate (physical) MPFile
     mpfile = MPFile()
     mpfile.add_data_table(mp_id, df, 'data')
     #print mpfile
     mpfile.write_file(os.path.join(self.rootdir, 'output.mpf'))
Example #2
0
    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)
Example #3
0
    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)
Example #4
0
    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)
Example #5
0
    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)
Example #6
0
    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)
Example #7
0
    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):

        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):
        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)
Example #10
0
    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)
Example #11
0
 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]
Example #12
0
    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
Example #13
0
    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_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)
Example #15
0
    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
Example #16
0
class PerovskitesDiffusionRester(MPContribsRester):
    """PerovskitesDiffusion-specific convenience functions to interact with MPContribs REST interface"""
    mpfile = MPFile.from_file(os.path.join(
        os.path.dirname(__file__), '..', 'mpfile_init.txt'
    ))
    query = {'content.doi': mpfile.hdata.general['doi']}
    provenance_keys = [k for k in mpfile.hdata.general.keys() if k != 'google_sheet']

    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_abbreviations(self):
        return self.get_global_hierarchical_data(['abbreviations']).get('abbreviations')
    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)
Example #18
0
    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)
Example #19
0
    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)
Example #20
0
    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)
Example #21
0
    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)
Example #22
0
    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)
Example #23
0
 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
Example #24
0
class MpWorkshop2017Rester(MPContribsRester):
    """MpWorkshop2017-specific convenience functions to interact with MPContribs REST interface"""
    mpfile = MPFile.from_file(os.path.join(
        os.path.dirname(__file__), '..', 'mpfile_init.txt'
    ))

    query = {'content.source': mpfile.hdata.general['source']}
    provenance_keys = [k for k in mpfile.hdata.general.keys() if k != 'google_sheet']

    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_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
Example #25
0
    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 compile(self):
     """compile phase (calculation from MAST DiffusionCoefficient.py)"""
     from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
     from pymatgen.matproj.rest import MPRester
     indirs = glob.glob(os.path.join(self.rootdir, "*CuCu*")) + [
         fn for fn in glob.glob(os.path.join(self.rootdir, "*Cu*"))
         if not fnmatch.fnmatch(fn, "*CuCu*")
     ]
     mp_id, E0, nw = None, None, 5  # five-frequency model
     df = None
     for idx, indir in enumerate(indirs):
         element = os.path.basename(indir).split('_')[2][2:]
         struct = self.find_entry_for_directory(os.path.join(
             indir, 'perfect_stat*'),
                                                oszicar=False).structure
         reduced = SpacegroupAnalyzer(
             struct, symprec=1e-2).get_primitive_standard_structure()
         if idx == 0:
             ENDPOINT = "https://www.materialsproject.org/rest"
             with MPRester(endpoint=ENDPOINT) as m:
                 matches = m.find_structure(reduced)
                 if len(matches) == 1: mp_id = matches[0]
                 else:
                     raise ValueError(
                         "found {} matching structure(s) in MP and hence cannot "
                         "assign structure in {}.".format(
                             len(matches), indir))
         a = reduced.lattice.abc[0] * math.sqrt(2) * 10**(-8)
         enebarr = np.array([self.get_barrier(indir, i) for i in range(nw)],
                            dtype=float)
         if idx == 0: E0 = min(enebarr[~np.isnan(enebarr)])
         else: enebarr[0] = E0  # TODO: is this correct?
         v = np.array(
             [self.get_attempt_frequency(indir, i) for i in range(nw)])
         v[0], HVf, kB, f0 = 1.0, 0.4847, 8.6173324e-5, 0.7815  # TODO set v[0] to 1.0? HVf dynamic how?
         t, tempstep, tempend = 0.0, 0.1, 2.0  # default temperature range
         x, y = [], []
         while t < tempend + tempstep:
             v *= np.exp(-enebarr / kB / 1e3 * t)
             alpha = v[4] / v[0]
             F_num = 10 * np.power(alpha, 4) + 180.5 * np.power(alpha, 3)
             F_num += 927 * np.power(alpha, 2) + 1341 * alpha
             F_denom = 2 * np.power(alpha, 4) + 40.2 * np.power(alpha, 3)
             F_denom += 254 * np.power(alpha, 2) + 597 * alpha + 435
             FX = 1 - (1.0 / 7.0) * (F_num / F_denom)
             f2 = 1 + 3.5 * FX * (v[3] / v[1])
             f2 /= 1 + (v[2] / v[1]) + 3.5 * FX * (v[3] / v[1])
             cV = np.exp(-HVf / kB / 1e3 * t) if t > 0. else 1.
             D = f0 * cV * a**2 * v[0] * f2 / f0 * v[4] / v[0] * v[2] / v[3]
             x.append(t)
             y.append(D)
             t += tempstep
         if df is None: df = DataFrame(np.array(x), columns=['1/T'])
         df.loc[:, element] = Series(np.array(y), index=df.index)
     #  generate (physical) MPFile
     mpfile = MPFile()
     mpfile.add_data_table(mp_id, df, 'data')
     #print mpfile
     mpfile.write_file(os.path.join(self.rootdir, 'output.mpf'))
Example #27
0
    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]
Example #28
0
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(
            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
Example #30
0
    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
Example #31
0
    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]
Example #32
0
class SwfRester(MPContribsRester):
    """SWF-specific convenience functions to interact with MPContribs REST interface"""
    mpfile = MPFile.from_file(
        os.path.join(os.path.dirname(__file__), '..', 'mpfile_init.txt'))
    query = {'content.doi': mpfile.hdata.general['doi']}
    provenance_keys = [
        k for k in mpfile.hdata.general.keys() if k != 'google_sheet'
    ]

    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']

        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, ''))

            data.append([formula, 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)
Example #33
0
    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_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]
Example #36
0
    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, 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_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)
Example #39
0
    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]
Example #40
0
    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)
Example #41
0
 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
Example #42
0
    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)
Example #43
0
    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)
Example #44
0
    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)
Example #45
0
    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)
Example #46
0
def test_get_string():
    mpfile = MPFile.from_file('test_files/test_archieml.txt')
    mpfile_test = MPFile.from_string(mpfile.get_string())
    assert_equal(mpfile.document, mpfile_test.document)
def test_get_string():
    test_file = os.path.join(os.path.dirname(__file__), 'test_archieml.txt')
    mpfile = MPFile.from_file(test_file)
    mpfile_test = MPFile.from_string(mpfile.get_string())
    assert mpfile.document == mpfile_test.document
def run(mpfile, nmax=None, dup_check_test_site=True):

    existing_mpids = {}
    for b in [False, True]:
        with PerovskitesDiffusionRester(test_site=b) as mpr:
            for doc in mpr.query_contributions(
                    projection={'content.data.directory': 1, 'mp_cat_id': 1}
                ):
                key = '_'.join([doc['mp_cat_id'], doc['content']['data']['directory']])
                existing_mpids[key] = doc['_id']
        if not dup_check_test_site:
            break

    general = mpfile.document[mp_level01_titles[0]]
    google_sheet = general.pop('google_sheet') + '/export?format=xlsx'
    contcars_filepath = general.pop('contcars_filepath')
    contcars = tarfile.open(contcars_filepath)

    df = read_excel(google_sheet)
    keys = df.iloc[[0]].to_dict(orient='records')[0]
    abbreviations = RecursiveDict()

    count, skipped, update = 0, 0, 0
    for index, row in df[1:].iterrows():
        mpid = None
        data = RecursiveDict()
        mpfile_single = MPFile()

        for col, value in row.iteritems():
            if col == 'level_0' or col == 'index':
                continue
            key = keys[col]
            if isinstance(key, string_types):
                key = key.strip()
                if not key in abbreviations:
                    abbreviations[key] = col
            else:
                key = col.strip().lower()

            if key == 'pmgmatchid':
                mpid = value.strip()
                if mpid == 'None':
                    mpid = None
                name = '_'.join(data['directory'].split('/')[1:])
                contcar_path = 'bulk_CONTCARs/{}_CONTCAR'.format(
                    data['directory'].replace('/', '_')
                )
                contcar = contcars.extractfile(contcar_path)
                mpid_match = mpfile_single.add_structure(
                    contcar.read(), fmt='poscar',
                    name=name, identifier=mpid
                )
                if not mp_id_pattern.match(mpid_match):
                    print 'skipping', name
                    continue
                mpid = mpid_match
            else:
                data[key] = value

        if mpid is None:
            continue

        mpid_mod = '_'.join([mpid, data['directory']])
        if nmax is not None and mpid_mod in existing_mpids:
            print 'skipping', mpid_mod
            skipped += 1
            continue # skip duplicates

        mpfile_single.add_hierarchical_data({'data': data}, identifier=mpid)

        if mpid_mod in existing_mpids:
            cid = existing_mpids[mpid_mod]
            mpfile_single.insert_id(mpid, cid)
            update += 1

        mpfile.concat(mpfile_single)

        if nmax is not None and count >= nmax-1:
            break
        count += 1

    mpfile.add_hierarchical_data({'abbreviations': abbreviations})

    print len(mpfile.ids), 'mp-ids to submit.'
    if nmax is None and update > 0:
        print update, 'mp-ids to update.'
    if nmax is not None and skipped > 0:
        print skipped, 'duplicates to skip.'
Example #49
0
import argparse, os
from mpcontribs.io.archieml.mpfile import MPFile
from pre_submission import *

parser = argparse.ArgumentParser(
    description="""generate MPFile from directory of related XAS measurements"""
)
parser.add_argument(
    '-i', '--input_mpfile', type=str, metavar="PATH", help="""path to input
    MPFile with shared MetaData and processing instructions for each
    composition""", default="input.txt"
)
parser.add_argument(
    '-o', '--output_mpfile', type=str, metavar="FILENAME", help="""name of
    output MPFile with shared MetaData and processing results for each
    composition (will be created in same directory as `input_mpfile`)""",
    default="output.txt"
)
args = parser.parse_args()

mpfile = MPFile.from_file(args.input_mpfile)
run(mpfile)
work_dir = os.path.dirname(os.path.realpath(args.input_mpfile))
output_mpfile = os.path.join(work_dir, args.output_mpfile)
mpfile.write_file(output_mpfile)
Example #50
0
import sys, json, os
from pympler import asizeof

if __name__ == '__main__':

    if not os.path.exists('martin_lab.json'):
        from mpcontribs.users.martin_lab.pre_submission import run
        from mpcontribs.io.archieml.mpfile import MPFile
        from mpcontribs.rest.adapter import ContributionMongoAdapter
        from mpcontribs.builder import MPContributionsBuilder, export_notebook

        mpfile = MPFile.from_file('MPContribs/mpcontribs/users/martin_lab/mpfile_init.txt')
        run(mpfile)
        cma = ContributionMongoAdapter()
        for mpfile_single in mpfile.split():
            contributor = 'Patrick Huck <*****@*****.**>'
            doc = cma.submit_contribution(mpfile_single, contributor)
            cid = doc['_id']
            print doc.keys()
            mcb = MPContributionsBuilder(doc)
            build_doc = mcb.build(contributor, cid)
            nb = build_doc[-1]
            print nb.keys()
            with open('martin_lab.json', 'w') as f:
                json.dump(nb, f)
            print 'DONE'

    with open('martin_lab.json', 'r') as f:
        nb = json.load(f)
        for idx, cell in enumerate(nb['cells']):
            if idx: # skip first cell