Skip to content

[Bug]: No longer way to obtain charge density from task_id #924

@teddykoker

Description

@teddykoker

Code snippet

# given some task id:
task_id = "mp-1805669"

# used to be able to do this
with MPRester(MP_API_KEY, monty_decode=deserialize) as mpr:
    results = mpr.materials.search(task_ids=[task_id])
    assert len(results) == 1
    chgcar = mpr.charge_density.get_charge_density_from_file_id(results[0].fs_id)

What happened?

There is currently no way to obtain charge density given some task id. MPRester.charge_density no longer exists, and there is no get_charge_density_from_file_id() function within MPRester.

I noticed there is a TODO related to this as well.

A work around is to use the tasks._query_open_data function manually, though I'm not sure this is robust to future API changes. Although I am not 100% sure this is correct, since I don't think the task_id always matches the file path in the key below.

# given some task id:
task_id = "mp-1805669"

with MPRester(MP_API_KEY) as mpr:
    decoder = MontyDecoder().decode
    chgcar = (
        mpr.tasks._query_open_data(
            bucket="materialsproject-parsed",
            key=f"chgcars/{str(task_id)}.json.gz",
            decoder=decoder,
            fields=["data"],
        )[0][0]["data"]
        or {}
    )

Version

0.41.2

Which OS?

  • MacOS
  • Windows
  • Linux

Log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions