예제 #1
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')
예제 #2
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
예제 #3
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)
예제 #4
0
                         ] + ["Hop attempt frequency, v_X [THz]"]
            df_v = df[["Solute element name"] + columns_v]
            df_v.columns = ["Solute"] + ["vₐ [THz]"] + ["vₓ [THz]"]
            mpfile.add_data_table(mpid, df_v, "hop_attempt_frequencies")

    print("DONE")


mpfile = MPFile()
mpfile.max_contribs = 15
run(mpfile)
print(mpfile)

filename = f"{project}.txt"
mpfile.write_file(filename=filename)
mpfile = MPFile.from_file(filename)
print(len(mpfile.ids))

table_names = ["D₀_Q", "hop_activation_barriers", "hop_attempt_frequencies"]

for idx, (identifier, content) in enumerate(mpfile.document.items()):
    # doc = {'identifier': identifier, 'project': project, 'content': {}}
    # doc['content']['data'] = content['data']
    # doc['collaborators'] = [{'name': 'Patrick Huck', 'email': '*****@*****.**'}]
    # r = db.contributions.insert_one(doc)
    # cid = r.inserted_id
    # print(idx, ':', cid)

    # tids = []
    # for name in table_names:
    #    table = mpfile.document[identifier][name]
예제 #5
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
예제 #6
0
import sys, json, os
from pympler import asizeof

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
            obj_size = asizeof.asizeof(cell) / 1024. / 1024.
            if obj_size > 1.:
예제 #7
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)
예제 #8
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)
예제 #9
0
            elif "rev_dB_p3" in name:
                offset = 4.49694000e-10
            elif "fwd_dG_p6" in name:
                offset = -8.90037000e-11
            elif "rev_dG_p6" in name:
                offset = 8.42196000e-10

            temp = name[4:].split("CZnO", 1)[0]
            direction = "fwd" if "fwd" in name else "rev"
            col = ycol.format(temp, direction)
            full_df[col] = (df[ycol] + offset).abs() * 1000.0 / 0.045

    mpfile.add_data_table(identifier, full_df, "JV|dark")


mpfile = MPFile.from_file("mpfile_init.txt")
mpfile.max_contribs = 2
run(mpfile)
print(mpfile)

filename = f"{project}.txt"
mpfile.write_file(filename=filename)
mpfile = MPFile.from_file(filename)
print(len(mpfile.ids))

mpfile.document.pop("_hdata")

for idx, (identifier, content) in enumerate(mpfile.document.items()):
    doc = {"identifier": identifier, "project": project, "content": {}}
    doc["content"]["data"] = content.pop("data")
    doc["collaborators"] = [{"name": "Patrick Huck", "email": "*****@*****.**"}]
예제 #10
0
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
예제 #11
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)
예제 #12
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)