Electrolyte for Li-ion batteries


Dear everyone,

I would like to get the electron affinity (EA) and ionization energy (IE) for electrolyte materials of Li-ion batteries. I write this code to get the EA of La-Ti-O based materials but the results are not what I expect (no EA):

from pymatgen import MPRester

if name == “main”:
MAPI_KEY = “mykey”
QUERY = “La-Ti-O” # electron affinities

mpr = MPRester(MAPI_KEY)  

data = mpr.get_data(QUERY)
for EA in data:

I am the beginner and I am not good at coding. Anyone could help, please.
Thank you in advance.


Hi ThuyTran,

Electron affinities for solids require a more computationally intensive calculation than the calculations we currently host on the materials project (the simulation required is the same as that required for the work function). Unfortunately, our currently automation infrastructure doesn’t support the calculation of these properties, so they’re not available in the database. We are hoping to calculate and add them eventually.

You might be interested in our infrastructure for calculating the electron affinities for molecules, which has a short tutorial on the mapidoc repo.


Thank Joseph Montoya! I will read the link. By the way, how to know if the electron affinities and ionization energies for solids are added. Could I get notification?


When follow the link, I get this problem:

"Ensure you have an API key and that you have selected the “jcesr” sandbox on your
# dashboard (https://materialsproject.org/dashboard). If you do not see the "jcesr"
# option and believe you should have access to EG data, please contact us."

I have API key but I can’t see “jcesr” in the sandbox. Please help me. Thanks.


Sorry, that should be updated. Electrolyte genome data (electrolyte molecules and multivalent cathode materials) were released to all users a while ago. You have full access to the data as a “core” sandbox user.


Thank you for your reply. I asked about “jcesr” because I got errors at the “Setup” step and I thought they comes from “jcesr”. Now, they belong to another reason but I can’t figure our. Please help me to take a look at these errors:
After finished input 1, I entered input 2 but I got error: ImportError: cannot import name 'quote_plus’
And when I typed: MAPI_KEY = os.environ[“my API key”], I got another error:
KeyError Traceback (most recent call last)
in ()
----> 1 MAPI_KEY = os.environ[“my key”]

~\Anaconda3\envs\my_pymatgen\lib\os.py in getitem(self, key)
** 667 except KeyError:**
** 668 # raise KeyError with the original key value**
–> 669 raise KeyError(key) from None
** 670 return self.decodevalue(value)**
** 671 **

KeyError: 'my key’


Hi ThuyTran,

It looks like you’re trying to set your API key as a shell environment variable. If you want to have a “universal” API key that’s read from your system, we recommend setting it in your .pmgrc.yaml file. Pymatgen has a command-line interface to do this. Issue the following command from the command line and it should set a default API key for the pymatgen MPRester

pmg config --add PMG_MAPI_KEY "your_api_key_goes_here"


@ThuyTran, I’ve updated the notebook to fix some issues. In particular, the notebook didn’t work for Python 3. Thank you for bringing it to our attention. Try again.


Thank you you both! After “dwinston” modify the code, it work well for me except the final one:

first_result = results[0]
mol_id = first_result[‘task_id’]
print(“ID: {}”.format(mol_id))

# Get all data by default
molecule = get_molecule(mol_id)
print(“There are {} key/value pairs in molecule {}. Have a look around!”.format(len(molecule), mol_id))

# The SVG format provides a two-dimensional “pretty picture” of the molecular structure.
svg_of_molecule = get_molecule(mol_id, fmt=‘svg’)
with open(‘molecule.svg’,‘w’) as f:
** f.write(svg_of_molecule)**
** print(“scalable vector graphic saved”)**

# The XYZ representation provided is the optimized geometry of the molecule in a charge-neutral state.
xyz_of_molecule = get_molecule(mol_id, fmt=‘xyz’)
with open(‘molecule.xyz’,‘w’) as f:
** f.write(xyz_of_molecule)**
** print(“XYZ file saved. Can load into molecule-viewer software.”)**

with the following output error:
ID: mol-64060
There are 29 key/value pairs in molecule mol-64060. Have a look around!

TypeError Traceback (most recent call last)
in ()
10 svg_of_molecule = get_molecule(mol_id, fmt=‘svg’)
11 with open(‘molecule.svg’,‘w’) as f:
—> 12 f.write(svg_of_molecule)
13 print(“scalable vector graphic saved”)

TypeError: write() argument must be str, not bytes

I have changed the two lines:
open(‘molecule.svg’,‘w’) into open(‘molecule.svg’,‘wb’)
and open(‘molecule.xyz’,‘w’) into open(‘molecule.xyz’,‘wb’)

The old error is sold but I got another error:

NameError Traceback (most recent call last)
in ()
----> 1 first_result = results[0]
2 mol_id = first_result[‘task_id’]
3 print(“ID: {}”.format(mol_id))
5 # Get all data by default

NameError: name ‘results’ is not defined

Therefore, in my notebook homepage I saw an empty “molecule.svg” file. I don’t know is this due to Python 3 or not. Please help!