Help on gist script


#1

Hello,

I am the beginner with API Materials and I am not good at coding. I have just started to learn with MP tutorial videos. I have just follow the website to install Conda and then Pymatgen http://pymatgen.org/installation.html#step-3-install-pymatgen

After finish, I have tried with some examples from Gisthub but I am not sucessful

I am using Python to run this. However, in Python, I only can type one by one command sentence. I don’t know how to run pymatgen in the right way as shown in Tutorial video # 7:
https://www.youtube.com/watch?v=zhLwfuaBNiY&t=0s&index=7&list=PLTjFYVNE7LTjHJwV994iQHS-bIkh3UXKJ (where to type “vi scartch”???, it looks not Python)

Please help me.

Thanks a lot in advance.

Mod edit: post was moved from previous topic since it was unrelated to installation


Problem installing pymatgen on Windows
#2

Hi ThuyTran,

The text you’ve linked comprises a python script, which is a text file that contains a series of python commands to be executed in sequence. You can use any text editor (vi from the video is a text editor) to copy/paste and edit the text you’ve linked and then type python oxidative_stability.py at the command line, which tells the python interpreter that you want to run all of the commands in the script.

If you’re not too keen on using text editors, you might consider using jupyter notebooks instead, which will enable you to type and edit multiple python commands in “cells” and execute them in sequence.

Feel free to follow up with further questions.


#3

Dear Joseph Montoya,

Thank you for your kind reply. I have installed “jupyter notebook” and tried to use it with some simple calculation. It works well.

However, when I copy the following content https://gist.github.com/computron/939af8c774a7737f0d5f69401722454f
into the input file (also change my API key), and press “Shift+Enter” it shows that:

"---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
in ()
----> 1 from pymatgen import Composition, Element, MPRester
** 2 from pymatgen.analysis.phase_diagram import PhaseDiagram**
** 3 **
** 4 if name == “main”:**
** 5 **

ModuleNotFoundError: No module named ‘pymatgen’ "

In other way, If I save the content as “oxidative_stability.py” in jupyter notebook and type " python oxidative_stability.py" command in “Anaconda Prompt”, I got this:

(my_pymatgen) C:\Users\Owner>python oxidative_stability.py
C:\Users\Owner\Anaconda3\envs\my_pymatgen\lib\site-packages\pymatgen\analysis\reaction_calculator.py:336: FutureWarning: rcond parameter will change to the default of machine precision times max(M, N) where M and N are the input matrix dimensions.
To use the future default and silence this warning we advise to pass rcond=None, to keep using the old, explicitly pass rcond=-1.
** coeffs, res, _, s = np.linalg.lstsq(f_mat.T, b)**
FeP2 -8.466709382916667

I know that I did something silly but I don’t know how to get to the right way. Please help me.
Thank you in advance.


#4

Absolutely, we’re happy to help. I believe the output you’ve linked indicates the command-line script is working. (The message you’re seeing, a FutureWarning, is a warning that’s related to some other codes that pymatgen uses that are undergoing a change and want to notify users). The output, “FeP2 -8.466709382916667” is from the last line of the script, print(FORMULA, max_chempot).

For the first problem, it sounds like the Jupyter environment and pymatgen aren’t installed in the same environment. If you’d like to fix it, maybe try clicking “Kernel->Change kernel” and seeing if there’s an option called “my_pymatgen”?. Anaconda enables you to install different environments with a different interpreter and installed packages, but the default jupyter will use the default python interpreter as its programming environment unless specified otherwise.


#5

Thanks for your reply. Yes, you are right. I have tried the second way and practice with some examples from Gisthub then they works well.
However, for the first problem, I have clicked “Kernel->Change kernel” but I only see one option “Python3”, no “my_pymatgen”. I have installed “jupyter notebook” and “pymatgen” via Anaconda. I don’t know how to fix this. If you have any suggestion, please let me know. Thanks a lot.


#6

Hmm… anaconda must not be picking up the extra environment. You’re on windows, correct? If so, maybe try the following:

  1. Open the “Anaconda Prompt” option from the “Start Menu->Anaconda” set of options, which is a command line interface with python.
  2. Type “source activate my_pymatgen” at the prompt to active your environment.
  3. Type “conda install jupyter” and that will install jupyter in your environment.
  4. Type “jupyter notebook”, which should open a browser with the jupyter notebook from the current environment.

Unfortunately, if this doesn’t work, I’m not sure what else to try, so you might have to post your issue to the anaconda forum.


#7

Ya, I am on windows. I have followed your instruction and I can run in jupyter notebook now. Thanks a lot!