In [ ]:
from mpcontribs.client import Client
client = Client('your-api-key-here')

Define project information and create project:


In [ ]:
info = {
    'project': 'qsgw_band_structures',  # primary key
    'owner': 'walter.lambrecht@case.edu',
    'title': 'QSGW Band Structure',
    'long_title': 'QSGW Sand Structures for Nitrides',
    'authors': 'W.R.L. Lambrecht, S. Lyu, A.P. Jaroenjittichai',
    'description': '''
    Band structure calculations were performed with the QSGW (quasiparticle
    self-consistent GW) approach [Codes, PRB, PRL]. The band structures use
    the 0.8Σ approximation, meaning 0.8 of the self-energy is included [PRM].
    For effective mass tensors and full band structure, see [DMREF]. In the
    Pna2_1 structure the valence band maximum (VBM) is split into 3 levels 
    with a₁, b₁ and b₂ symmetry as described in
    <a href="https://doi.org/10.1103/PhysRevB.84.165204">PRB84 165205</a>.
    In some cases (ZnSiN2) a 4th level with symmetry a₂ falls between these.
    ''',
    'urls': {
       'DMREF': 'https://sites.google.com/a/case.edu/dmref/',
       'CODE': 'https://www.questaal.org/',
       'PRB': 'https://doi.org/10.1103/PhysRevB.76.165106',
       'PRL': 'https://doi.org/10.1103/PhysRevLett.96.226402',
       'PRM': 'https://doi.org/10.1103/PhysRevMaterials.2.013807'
    }
}
# only execute once and wait for approval (or already entered in online form)
# client.projects.create_entry(project=info).result()

Get and update project information (if needed):


In [ ]:
client.projects.get_entry(pk=info['project']).result()

In [ ]:
# client.projects.update_entry(
#     pk=info['project'], project={'description': info['description']}
# ).result()

Create and work with contributions:


In [ ]:
contributions = [
    {
        'project': info['project'],
        'identifier': 'mp-1020712', # ZnSiN2
        'data': {
            'reference': 'https://doi.org/10.1103/PhysRevB.84.165204',
            'ΔE|Γ': {
                'indirect': '5.70 eV',
                'direct': '5.92 eV'
            },
            'VBM|Γ': {
                'b₁': '0',
                'a₂': '-20 meV',
                'b₂': '-40 meV',
                'a₁': '-180 meV'
            }
        }
    }, {
        'project': info['project'],
        'identifier': 'mp-2979', # ZnGeN2
        'data': {
            'reference': 'https://doi.org/10.1103/PhysRevB.84.165204',
            'ΔE|Γ': {'direct': '3.60 eV'},
            'VBM|Γ': {
                'b₁': '0',
                'b₂': '-28 meV',
                'a₁': '-129 meV'
            }
        }
    }, {
        'project': info['project'],
        'identifier': 'mp-1029469', # ZnSnN2
        'data': {
            'reference': 'https://doi.org/10.1103/PhysRevB.91.205207',
            'ΔE|Γ': {'direct': '1.82 eV'},
            'VBM|Γ': {
                'b₁': '0',
                'b₂': '-188 meV',
                'a₁': '-176 meV'
            }
        }
    }, {
        'project': info['project'],
        'identifier': 'mp-3677', # MgSiN2
        'data': {
            'reference': 'https://doi.org/10.1103/PhysRevB.94.125201',
            'ΔE|Γ': {
                'indirect': '6.08 eV',
                'direct': '6.53 eV',
                'direct|3x4x4': '6.30 eV'
            }
        }
    }, {
        'project': info['project'],
        'identifier': 'mp-7798', # MgGeN2
        'data': {
            'reference': 'https://doi.org/10.1016/j.ssc.2019.113664',
            'ΔE|Γ': {'direct': '4.11 eV'},
            'VBM|Γ': {
                'b₁': '0',
                'b₂': '-82 meV',
                'a₁': '-238 meV'
            }
        }
    }, {
        'project': info['project'],
        'identifier': 'mp-1029791', # MgSnN2
        'data': {
            'reference': 'https://doi.org/10.1016/j.ssc.2019.113664',
            'ΔE|Γ': {'direct': '2.28 eV'},
            'VBM|Γ': {
                'b₁': '0',
                'b₂': '-116 meV',
                'a₁': '-144 meV'
            }
        }
    }
]

In [ ]:
for contrib in contributions:
    print(client.contributions.create_entry(contribution=contrib).result())

In [ ]:
contribs = client.contributions.get_entries(
    project=info['project']
).result()['data']
len(contribs)

In [ ]:
client.contributions.get_entries(identifier='mp-2979').result()

Delete contributions or make all public:


In [ ]:
for contrib in contribs:
    client.contributions.delete_entry(pk=contrib['id']).result()

In [ ]:
client.contributions.update_entries(
    project=info['project'], contributions={'is_public': True}
).result()

IGNORE Administrative stuff:


In [ ]:
project = 'redox_thermo_csp' # TODO also adjust landingpage app
client.projects.get_entry(pk=project, _fields=['columns']).result()

In [ ]:
has_more, page, per_page = True, 1, 99
while has_more:
    contributions = client.contributions.get_entries(
        project=project, per_page=per_page, page=page, formula='TODO'
    ).result()
    cids = [c['id'] for c in contributions['data']]
    if not cids:
        break
    updated = client.contributions.update_entries(
        id__in=cids, contributions={
            'formula': 'TODO', 'data': {'formula': None}
        }
    ).result()
    has_more = contributions['has_more']
    print(page, contributions['total_count'], updated['count'], has_more)
    page += 1