Beispiel #1
0
def test_mpds():
    from mpds_client import MPDSDataRetrieval
    key = os.getenv('MPDS_KEY')
    client = MPDSDataRetrieval(api_key=key)
    query_dict = dict(formulae="MgO", sgs=225, classes="binary")
    # insert props: atomic structure to query. Might check if it's already set to smth
    query_dict['props'] = 'atomic structure'
    answer = client.get_data(query_dict, fields={'S': [
        'phase',
    ]})
    assert len(set(_[0] for _ in answer)) == 1
Beispiel #2
0
    def get_geometry(self):
        """ Getting geometry from MPDS database
        """
        key = os.getenv('MPDS_KEY')
        client = MPDSDataRetrieval(api_key=key, verbose=False)
        query_dict = self.inputs.mpds_query.get_dict()

        # Add direct structures submitting support: FIXME
        assert query_dict or self.inputs.struct_in
        if not query_dict:
            return self.inputs.struct_in

        # insert props: atomic structure to query. Might check if it's already set to smth
        query_dict['props'] = 'atomic structure'
        try:
            answer = client.get_data(
                query_dict,
                fields={'S': [
                    'cell_abc',
                    'sg_n',
                    'basis_noneq',
                    'els_noneq'
                ]}
            )
        except APIError as ex:
            if ex.code == 429:
                self.logger.warning("Too many parallel MPDS requests, chilling")
                time.sleep(random.choice([2 * 2**m for m in range(5)]))
                return self.get_geometry()
            else: raise

        structs = [client.compile_crystal(line, flavor='ase') for line in answer]
        structs = list(filter(None, structs))
        if not structs:
            raise APIError('No crystal structures returned')
        minimal_struct = min([len(s) for s in structs])

        # get structures with minimal number of atoms and find the one with median cell vectors
        cells = np.array([s.get_cell().reshape(9) for s in structs if len(s) == minimal_struct])
        median_cell = np.median(cells, axis=0)
        median_idx = int(np.argmin(np.sum((cells - median_cell) ** 2, axis=1) ** 0.5))
        return get_data_class('structure')(ase=structs[median_idx])
Beispiel #3
0
def get_phases():
    key = os.getenv('MPDS_KEY', None)
    if key is None:
        raise EnvironmentError(
            'Environment variable MPDS_KEY not set, aborting')

    cols = ['phase', 'chemical_formula', 'sg_n']
    client = MPDSDataRetrieval(api_key=key)

    for formula in get_formulae():
        formula.update({'props': 'atomic structure'})
        data = client.get_data(formula, fields={'S': cols})
        data_df = pd.DataFrame(data=data,
                               columns=cols).dropna(axis=0,
                                                    how="all",
                                                    subset=["phase"])

        for _, phase in data_df.drop_duplicates().iterrows():
            yield {
                'phase': phase['phase'],
                'formulae': phase['chemical_formula'],
                'sgs': int(phase['sg_n'])
            }
Beispiel #4
0
import requests
from mpds_client import MPDSDataRetrieval, MPDSDataTypes

from etransport_raw import analyze_raw # this is given in the supplied file "etransport_raw.py"

# the raw data on the MPDS are in 7z format
# so we need the latest dev version of pylzma
# pip install git+https://github.com/fancycode/pylzma
# then py7zlib is available

from py7zlib import Archive7z


mpds_api = MPDSDataRetrieval(dtype=MPDSDataTypes.AB_INITIO)

for entry in mpds_api.get_data({'props': 'electrical conductivity'}, fields={}):

    archive_url = entry['sample']['measurement'][0]['raw_data'] # this is the raw data archive location

    p = requests.get(archive_url)
    if p.status_code != 200:
        logging.critical('ARCHIVE %s IS UNAVAILABLE' % archive_url)
        continue

    print('Analyzing the raw data for %s' % entry['sample']['material']['entry'])

    archive = Archive7z(io.BytesIO(p.content))
    for virtual_path in archive.files:

        if virtual_path.filename != 'TRANSPORT/SIGMA.DAT':
            continue
Beispiel #5
0
            for m, neighbor in enumerate(ase_obj):
                if neighbor.symbol == elB:
                    dist = round(ase_obj.get_distance(n, m),
                                 2)  # NB occurrence <-> rounding
                    if dist < limit:
                        lengths.append(dist)
    return lengths


client = MPDSDataRetrieval()

answer = client.get_data({
    "elements": "U-O",
    "props": "atomic structure"
},
                         fields={
                             'S': [
                                 'phase_id', 'entry', 'chemical_formula',
                                 'cell_abc', 'sg_n', 'basis_noneq', 'els_noneq'
                             ]
                         })

lengths = []

for item in answer:
    crystal = MPDSDataRetrieval.compile_crystal(item, 'ase')
    if not crystal: continue
    lengths.extend(calculate_lengths(crystal, 'U', 'O'))

dfrm = pd.DataFrame(sorted(lengths), columns=['length'])
dfrm['occurrence'] = dfrm.groupby('length')['length'].transform('count')
dfrm.drop_duplicates('length', inplace=True)
Beispiel #6
0
#excel sheet
df.to_excel(writer,'Sheet1',index=False)
#saving the excel file
writer.save()
print(Tc) 
'''

#Extracting the isothermal bulk modulus data in a similar manner
Bulk_Mod = []
for x in range(len(name)):
    Bulk_M = []
    try:
        time.sleep(1)
        ans = client.get_data({
            "formulae": name[x],
            'classes': 'peer-reviewed',
            "props": "isothermal bulk modulus"
        })
        for i in ans:
            if i[4] == 'isothermal bulk modulus' and i[2] == spacegroup[x]:
                Bulk_M.append(
                    i[6]
                )  #Appending all the Bulk Moduli values for that compound
    except:
        Bulk_M.append("NAN")
    Bulk_Mod.append(
        Bulk_M[:]
    )  #Creating a list of lists which contain all different given Bulk moduli values for a particular compound

#Saving it in a given excel sheet
df = pd.DataFrame({'Bulk Modulus': Bulk_Mod})
Beispiel #7
0
        raise RuntimeError('Chemical element symbols should be given.')
    elements = sorted([ela, elb])
    print("Elements: %s" % elements)

    api_client = MPDSDataRetrieval()

    plt.xlabel('Composition')
    plt.ylabel('Temperature')
    plt.annotate(ela, xy=(-0.05, -0.1), xycoords='axes fraction')
    plt.annotate(elb, xy=(1.05, -0.1), xycoords='axes fraction')
    ymin, ymax = 500, 700

    for pd in api_client.get_data(
        {
            "props": "phase diagram",
            "classes": "binary",
            "elements": "-".join(elements)
        },
            fields={}):  # fields={} means all fields
        # Consider only full-composition diagrams
        if pd['comp_range'] != [0, 100]:
            continue

        # Consider only a relatively large temperature range
        if pd['temp'][1] - pd['temp'][0] < 300:
            continue

        print("*" * 50, pd['entry'], "*" * 50)
        done_liquidus = False
        if pd['temp'][0] < ymin: ymin = pd['temp'][0]
        if pd['temp'][1] > ymax: ymax = pd['temp'][1]
Beispiel #8
0
import numpy as np
from mpds_client import MPDSDataRetrieval, MPDSDataTypes

mpds_api = MPDSDataRetrieval(
    dtype=MPDSDataTypes.MACHINE_LEARNING)  # NB MPDSDataTypes.ALL

phase_for_formula = {}
phase_for_val_a, phase_for_val_b = {}, {}

for deck in mpds_api.get_data(
    {
        'props': 'temperature for congruent melting',
        'classes': 'oxide'
    },
        fields={
            'P': [
                'sample.material.phase_id', 'sample.material.chemical_formula',
                'sample.measurement[0].property.scalar'
            ]
        }):
    if deck[2] > (1800 + 273):
        phase_for_formula[deck[0]] = deck[1]
        phase_for_val_a.setdefault(deck[0], []).append(
            deck[2])  # why list? each phase might have > 1 value

for deck in mpds_api.get_data(
    {'props': 'linear thermal expansion coefficient'},
        phases=phase_for_val_a.keys(),
        fields={
            'P': [