28
$\begingroup$

I just saw I am a beginner in Density Functional Theory. What are some resources that could help me to learn the basics? and it reminded me that few years ago I'd asked How can I calculate the charge distribution of a water molecule? in Chemistry SE.

There is some excellent advice there, but at the time I'd realized I couldn't just install a python package and type "Calculate H2O" so I shelved it at the time. Now there is Materials Modeling SE!

In addition to reading the material recommended in answers to the resources question linked above, I'd like to run an example and getting the electron density of a water molecule still captures my interest.

What would be a simple approach be, and by simple I mean a python package that can be used with an Anaconda Python 3 installation and run without a large number of additional dependencies that might be complicated to install?

The process should be instructive but the results do not have to be particularly accurate; I've chosen the water molecule to get my feet wet and get a better feeling for how these calculates are actually done procedurally.

If there is an OS aspect to this I'd prefer to do this on MacOS but I have access to Windows machines. I know that these can be computationally intensive once one gets going and so I may need to find more hardware resources later on.

$\endgroup$
9
  • 2
    $\begingroup$ Funnily enough, yesterday I was talking to Cody Aldaz and Tyberius as I was debating with myself whether or not I should ask here how to install the Python software MRChem. I ended up making a cheat sheet for how to install it, but it still involves about 15 commands and about 25 minutes (on an old 2011 machine with only 7GB of RAM). $\endgroup$ May 24, 2020 at 4:10
  • 1
    $\begingroup$ Then, this morning I got a Hartree-Fock calculation done for H2O with their simple input file. Right below this input file, they have an input file also for DFT (with the B3LYP functional), however it is unfortunately for the CO2 molecule, so it won't get your feet as wet. $\endgroup$ May 24, 2020 at 4:11
  • 1
    $\begingroup$ I mentioned that it had 7GB of RAM, not because it was a concern for the calculation, nor for the installation. I was just trying to point out that it took 25 minutes to install on an ancient machine, so it might take 10 minutes on a modern machine. The RAM usage was in the megabytes. $\endgroup$ May 24, 2020 at 4:30
  • 2
    $\begingroup$ With 2 answers and 4 upvotes, in only 9 views, this question is guaranteed to become a Hot Network Question so get ready for it tomorrow! $\endgroup$ May 24, 2020 at 4:44
  • 2
    $\begingroup$ @NikeDattani do you need more than 7GB to simulate a water molecule using Python? $\endgroup$
    – Camps
    May 24, 2020 at 15:52

3 Answers 3

16
$\begingroup$

SlowQuant

In your question from 2015, you mentioned PyQuante and PySCF, but I saw no mention of SlowQuant in the question or in the multiple answers. I see that while writing this, someone else answered, with mentions of PyQuante, PySCF, and Psi4 again. Still no mention of SlowQuant.

The author of SlowQuant has described the program this way (emphasis mine):

SlowQuant is a molecular quantum chemistry program written in python. Even the computational demanding parts are written in python, so it lacks speed, thus the name SlowQuant.

Right below that he gives the command for running it on the water molecule (click to get input files):

python SlowQuant.py H2O.csv setting.csv

Dependencies:
- Python 3.5 or above
- numpy 1.13.1
- scipy 0.19.1
- numba 0.34.0
- cython 0.25.2
- gcc 5.4.0

As you can see, even SlowQuant requires the GCC compilers, presumably because it uses Cython which is for turning Python code into faster running C code (maybe this program is not so slow after all?).

$\endgroup$
12
  • $\begingroup$ per this answer I typed gcc -v and got Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 8.0.0 (clang-800.0.42.1) Target: x86_64-apple-darwin15.6.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin Presumably this is good news? update: wow the slowquant install page is quite easy to read! $\endgroup$
    – uhoh
    May 24, 2020 at 4:39
  • 1
    $\begingroup$ I tried this and had trouble because the factorial2 function has been moved in newer scipy packages. In two places I changed 'import scipy.misc as scm' to 'import scipy.special as scm' and it passes tests and runs the example. $\endgroup$
    – Bit Chaser
    May 24, 2020 at 16:59
  • 1
    $\begingroup$ The hot summer has finally broken and the "rainy season" has begun here, so it is literally time to "get my feet wet" and do a water molecule! $\endgroup$
    – uhoh
    Sep 27, 2020 at 13:13
  • 1
    $\begingroup$ It's now January... still high on my to-do list... grr... $\endgroup$
    – uhoh
    Jan 29, 2021 at 1:33
  • 1
    $\begingroup$ tests failed because factorial2 has been moved from scipy.misc to scipy.special. Edited MIpython.py and BasisSet.py and all tests pass and the H2O example runs. Yay! $\endgroup$
    – uhoh
    Mar 11, 2021 at 7:37
16
$\begingroup$

If you're set on using Python here are some options. I haven't used these codes so I can't speak to their ease of use.

PyQyante

PyQuante is a suite of programs that can not only do DFT but also Hartree-Fock, MP2, and more. Certain parts of the code are written in C for speed. A package can be downloaded and then installed with Python, but a newer version, PyQuante2, can simply be installed with conda. It typically only requires Numpy, but some other packages are recommended in certain situations (see the previous install link).

On Windows:

conda install -c rpmuller pyquante2

On Linux/Mac:

conda install -c rpmuller pyquante2_pure

Psi

Psi is also package that includes a lot of quantum chemistry methods beyond DFT. The front end uses Python but underlying code uses C and C++. It can be compiled from source code, but binaries can be installed either by using provided install scripts or by using conda (it's recommended to create a new environment):

conda create --name psi4env python=3.6 psi4 psi4-rt -c psi4/label/dev -c psi4

Psi requires a fairly large number of dependencies but they are taken care of by conda if you install by that route.

PySCF

PySCF is another Python-based suite of programs. Some additional documentation is available here. It can support finite and periodic systems and has a fairly extensive list of features. If you build it yourself, you will require

  • CMake 2.8+
  • Numpy 1.8.0+
  • Scipy 0.10+ (0.12.0+ for python 3.4-3.8)
  • h5py 2.3.0+ (also HDF5 1.8.4+)

But this is made simpler if you just use conda:

conda install -c pyscf pyscf

Other options

If you are interested, it might be worthwhile to look into other codes, and if they are open-source, try compiling them on your Mac. Quantum Espresso should compile pretty easily, I've done it on my Windows PC via Cygwin and Windows Subsystem for Linux (it's also been installed on at least one smartphone and Playstation 3).

$\endgroup$
8
  • 3
    $\begingroup$ I mentioned Python because I'm looking for something that is on the easy side to install, When I see " via Cygwin and Windows Subsystem for Linux" my eyes glaze over because I don't know what those mean. Which one of these options do you think might be good for a non developer to try to install? $\endgroup$
    – uhoh
    May 24, 2020 at 4:28
  • 2
    $\begingroup$ @Kevin, the user wants to model an H2O molecule, so would you agree that Quantum Espresso is out of the question? Likewise, Psi4 and PySCF are heavyweight programs that can do far more than what the user seems to need! Maybe PyQuante is the one to take away from this answer? $\endgroup$ May 24, 2020 at 4:35
  • 4
    $\begingroup$ @uhoh Okay, forget that Cygwin/Linux stuff then, it can always be something to look into later if you're interested. Check SlowQuante from Nike's answer, and/or PyQuante, as a first step. $\endgroup$ May 24, 2020 at 5:04
  • 3
    $\begingroup$ @KevinJ.M. I really liked the format we had going on here. How would you feel about us following that here too? Maybe you can pick one program and give the dependencies? I say this because the asker mentioned in the question that they want something without a lot of dependencies. PySCF needs CMake and HDF5 and Psi4 seems to need even more. $\endgroup$ May 24, 2020 at 5:18
  • 2
    $\begingroup$ @NikeDattani Sure. Just edited the answer. $\endgroup$ May 24, 2020 at 6:38
8
$\begingroup$

Psi4NumPy

First of all, thanks @uhoh for pointing me towards this question.

And as an answer (or rather different P.O.V), I want to suggest taking another look in the direction of PSI4 mainly PSI4NUMPY.

LINK: https://github.com/psi4/psi4numpy

I was recently suggested to this amazing git on my Reddit post.

PSI4NUMPY contains literally a lot of python codes along with a very good explanation.
Psi4, I agree can be a little heavy but if you have Conda installed, it is not that difficult to install and run (as suggested by @Kevin J. M.).

Best of luck!

$\endgroup$
1
  • 3
    $\begingroup$ Thanks for your answer and Welcome to Matter Modeling SE! I will indeed take a look. $\endgroup$
    – uhoh
    Jan 28, 2021 at 14:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .