Repository: materialsproject/pymatgen

Issue #2377: Empty `.pmgrc.yaml` file produces error with `yaml.safe_load` (or `yaml.load`) and `update`
Created: 2022-01-25T05:09:52Z
The bug in #2373 seems to produce an empty .pmgrc.yaml configuration file for me
Traceback (most recent call last):
  File "/usr/local/bin/pmg", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/dist-packages/pymatgen/cli/pmg.py", line 440, in main
    return args.func(args)
  File "/usr/local/lib/python3.7/dist-packages/pymatgen/cli/pmg_config.py", line 218, in configure_pmg
    add_config_var(args)
  File "/usr/local/lib/python3.7/dist-packages/pymatgen/cli/pmg_config.py", line 203, in add_config_var
    dumpfn(d, SETTINGS_FILE, default_flow_style=False)
  File "/usr/local/lib/python3.7/dist-packages/monty/serialization.py", line 119, in dumpfn
    yaml.dump(obj, fp, *args, **kwargs)
TypeError: dump() got an unexpected keyword argument 'default_flow_style'
After using the fallback of export PMG_MAPI_KEY={MP_API_KEY}, an error is later produced when trying to load the empty config file:
from pymatgen.core import Composition
/usr/local/lib/python3.7/dist-packages/pymatgen/core/__init__.py in <module>()
     59 
     60 
---> 61 SETTINGS = _load_pmg_settings()
     62 locals().update(SETTINGS)

/usr/local/lib/python3.7/dist-packages/pymatgen/core/__init__.py in _load_pmg_settings()
     49         with open(SETTINGS_FILE) as f:
     50             d_yml = yaml.safe_load(f)
---> 51         d.update(d_yml)
     52     except OSError:
     53         # If there are any errors, default to using environment variables

TypeError: 'NoneType' object is not iterable
The workaround is to delete the empty file, and only use the export command above or use the latest changes (which I'm sure will go into a new release soon), or to make the empty file read:
PMG_MAPI_KEY: <my-api-key>

pymatgen version is 2022.0.17.

Duplicate issue #2378: pmg command becomes not to work
Created: 2022-01-25T07:35:10Z
Dear all,
I installed pymatgen through conda. Installation of pymatgen was OK.
However, after setting up the location of POTCAR files according to the instruction in the official web page, pmg command become not t work anymore. In the the setting up of the POTCAR files, I run these command.

pmg config -p <EXTRACTED_VASP_POTCAR> <MY_PSP>
pmg config --add PMG_VASP_PSP_DIR <MY_PSP>
pmg config --add PMG_DEFAULT_FUNCTIONAL PBE_52

The following error messages appear when pmg command with any option is run.
###############################
Traceback (most recent call last):
File "/home/kuwabara/anaconda3/envs/pymatgen/bin/pmg", line 7, in 
from pymatgen.cli.pmg import main
File "/home/kuwabara/anaconda3/envs/pymatgen/lib/python3.10/site-packages/pymatgen/cli/pmg.py", line 15, in 
from pymatgen.core import SETTINGS
File "/home/kuwabara/anaconda3/envs/pymatgen/lib/python3.10/site-packages/pymatgen/core/init.py", line 54, in 
SETTINGS = _load_pmg_settings()
File "/home/kuwabara/anaconda3/envs/pymatgen/lib/python3.10/site-packages/pymatgen/core/init.py", line 44, in _load_pmg_settings
d.update(d_yml)
TypeError: 'NoneType' object is not iterable
###############################
I uninstalled pymatgen and reinstall. The problem is not resolved.

OS: Ubuntu 20.04.3 LTS (on WSL2, Windows10)
pymatgen 2022.1.24
python 3.10.2

Closing comment (2022-01-26T02:30:48Z): Dear shyuep,
Thank you for your comment.
I reset the locations of potcar files like
pmg config -p ~/POT_GGA_PAW_PBE_52 ~/vasp_potentials
pmg config --add PMG_VASP_PSP_DIR ~/vasp_potentials
My settings and pmg command works after that.
In my case, empty .pmgrc.yaml was created and it caused my trouble. I found that a similar situation was already reported in #2377. My pmg command recovered after deleting the .pmgrc.yaml file.
Thank you again for your help.