In [ ]:
from mpcontribs.client import Client
from pymatgen import Structure, MPRester
In [ ]:
project = 'esters'
client = Client('your-api-key-here')
mpr = MPRester()
Retrieve and update project info
In [ ]:
client.projects.get_entry(pk=project, _fields=['_all']).result()
In [ ]:
client.projects.update_entry(pk=project, project={'long_title': 'Improved c-axis parameter for BiSe'}).result()
Create contribution
In [ ]:
# clear out first (includes structure(s))
deleted = client.contributions.delete_entries(project=project).result()
print(deleted['count'], 'contribution(s) deleted')
is_public = True
structure = Structure.from_file('CONTCAR')
mpids = mpr.find_structure(structure)
contrib = {'project': project, 'identifier': mpids[0], 'is_public': is_public}
created = client.contributions.create_entries(contributions=[contrib]).result()
cid = created['data'][0]['id']
print('contribution', cid, 'created')
comp = structure.composition.reduced_formula
sdct = {'contribution': cid, 'is_public': is_public, 'label': '2019/05/21', 'name': comp}
sdct.update(structure.as_dict())
created = client.structures.create_entries(structures=[sdct]).result()
sid = created['data'][0]['id']
print('structure', sid, 'created')