pymatgen-analysis-diffusion icon indicating copy to clipboard operation
pymatgen-analysis-diffusion copied to clipboard

[Bug]: analyzer.get_msd_plot failed

Open AlexHeustc opened this issue 1 year ago • 1 comments

Email (Optional)

[email protected]

Version

v2023.8.15

Which OS(es) are you using?

  • [ ] MacOS
  • [ ] Windows
  • [X] Linux

What happened?

The function "get_msd_plot()" is incompatible with the function "pretty_plot" in pymatgen

Code snippet

analyzer.get_msd_plot()

Log output

TypeError                                 Traceback (most recent call last)
Cell In[10], line 1
----> 1 analyzer.get_msd_plot(plt=None)

File ~/soft/anaconda3/envs/pymatgen/lib/python3.11/site-packages/pymatgen/analysis/diffusion/analyzer.py:561, in DiffusionAnalyzer.get_msd_plot(self, plt, mode)
    548 """
    549 Get the plot of the smoothed msd vs time graph. Useful for
    550 checking convergence. This can be written to an image file.
   (...)
    557         time will be plotted.
    558 """
    559 from pymatgen.util.plotting import pretty_plot
--> 561 plt = pretty_plot(12, 8, plt=plt)
    562 if np.max(self.dt) > 100000:
    563     plot_dt = self.dt / 1000

TypeError: pretty_plot() got an unexpected keyword argument 'plt'

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

AlexHeustc avatar Nov 21 '23 03:11 AlexHeustc

This issue has been resolved in previous issue. To avoid this problem, you can install the patched version by running pip install “pip install git+https://github.com/materialsvirtuallab/pymatgen-analysis-diffusion.git”. However, there still be other new issues even with this solution. For example, I encountered the following problem:

  File "/home/lws/Desktop/SSE/analysis.py", line 17, in <module>
    analyzers[temp].get_msd_plot() 
  File "/home/lws/anaconda3/envs/deepmd/lib/python3.10/site-packages/pymatgen/analysis/diffusion/analyzer.py", line 590, in get_msd_plot
    plt.xlabel(f"Timestep ({unit})")
AttributeError: 'Axes' object has no attribute 'xlabel'. Did you mean: '_label'?

To avoid the issue mentioned, you can replace lines 590-596 in pymatgen/analysis/diffusion/analyzer.py with the following content:

        plt.set_xlabel(f"Timestep ({unit})")
        if mode == "mscd":
            plt.set_ylabel("MSCD ($\\AA^2$)")
        else:
            plt.set_ylabel("MSD ($\\AA^2$)")
        plt.figure.tight_layout()
        return plt.figure

Hope this helps.

LiangWenshuo1118 avatar Dec 01 '23 06:12 LiangWenshuo1118

hello @LiangWenshuo1118

Could you please provide a fix for get_arrhenius_plot too?

okibrisli avatar Jun 23 '24 17:06 okibrisli