r/comp_chem • • Aug 24 '26

Update: the pure-Python DFT code I shared here earlier this year is now published — and has grown quite a bit

About 6 months ago I posted here about PyFock, the Gaussian-basis DFT code I had been building with essentially all of the performance-critical quantum-chemistry parts such as molecular integrals, density fitting, XC evaluation, etc., written directly in Python and just-in-time compiled. This is in contrast to what PySCF/Psi4 do where they utilise ahead-of-time (AOT) compiled C/C++ code for expensive calculations.

That post led to some really useful discussion here, particularly about comparisons with PySCF/GPU4PySCF, ERI performance, JIT compilation, and whether this kind of architecture can remain competitive as the code grows.

So I thought I would come back with an update.

The PyFock paper is now published in The Journal of Physical Chemistry A.

More importantly, PyFock itself has grown quite a bit since I first posted it here.

Some of the things added since then include:

  • Analytical DFT nuclear gradients and forces

  • an ASE calculator, allowing geometry optimizations and other ASE workflows

  • a VQE interface through PennyLane

  • native implementations of XC functionals, including LDA, GGA and meta-GGA functionals, so LibXC is now optional

  • significantly improved electron-repulsion integral evaluation on both CPUs and GPUs

  • continued improvements to the GPU implementation and overall performance

  • ECP support and several other additions to the electronic-structure infrastructure

The original motivation is still the same:

Can the performance-critical algorithms of a Gaussian-basis electronic-structure code remain directly readable and modifiable in Python without sacrificing too much performance?

For me, the interesting part is still the hackability. If you want to change an ERI algorithm, experiment with screening, modify an XC implementation, or try a different GPU strategy, you can modify the actual Python kernel instead of having to work through a separate C/C++ backend.

At this point PyFock is becoming less of a proof-of-concept and more of a small electronic-structure development platform.

It is obviously still nowhere near the feature set or maturity of PySCF, Psi4, TURBOMOLE, etc., and that isn't the claim. The goal is to make the low-level algorithms unusually transparent while keeping the code fast enough to actually experiment with realistic systems.

69 Upvotes

10 comments sorted by

11

u/nano-zan Aug 24 '26

This might be a bit stupid question, but I'll still ask it anyways. What is the purpose of a pure python framework for DFT and is it worth the slow speed python brings compared to c/c++ frameworks?

9

u/FalconX88 Aug 24 '26

According to the paper the idea is that you can more easily change the underlying code since you don't have to fiddle with Fortran or C

https://pubs.acs.org/jpcafh/article/doi/10.1021/acs.jpca.6c03727/5298372/PyFock-A-Just-In-Time-Compiled-Gaussian-Basis-DFT

But I'm missing a comparison to software like ORCA. Sure, comparing it to other python packages makes sense, but with the exception of GPU4PySCF no one is seriously using those.

4

u/manassharma007 Aug 24 '26
  1. "no one is seriously using those" PySCF has 1.7k stars on GitHub and over 4k citations combined on just two of its reference articles. Psi4 also has combined >4k citations on 3 of its reference articles. While I agree that ORCA is significantly more popular than PySCF and Psi4 with over 20k citations on just two of its reference articles, it does not mean that PySCF and Psi4 are not being used seriously.

  2. Comparison would not be one-to-one with ORCA. ORCA employs much more sofisticated ERI calculation algorithms than used by PySCF/PyFock. Since both use the standard density fitting approximation with CS screening, these are comparable to each other at least at the theoretical algorithmic level. The idea was to show that the same algorithm can be implemented at the same speed as in C using just Python with JIT.

6

u/FalconX88 Aug 24 '26

it does not mean that PySCF and Psi4 are not being used seriously.

I'm in this field for 15 years. Not once have a read an article that elucidates a mechanism or predicts reactivity or does a large scale screening or explains stereoselectivity using PySCF. Everyone is using Gaussian, ORCA, Turbomole, Q-Chem,... And so do all the pharma companies. Why? Because PySCF is slow and doesn't have any advantage in use cases like that.

The only large scale deployment of PySCF I know of is in Rowan but they use GPU4PySCF and not the actual CPU DFT methods.

Look, I'm not saying that PySCF isn't an important piece of software, in particular for teaching it's nice since you can run it in a jupyter notebook. But no one is using it for serious DFT work.

Psi4 you find the occasional paper, but still essentially nothing compared to the big software packages.

Comparison would not be one-to-one with ORCA.

I disagree. Both do DFT calculations. If you benchmark for speed you definitely should also compare to the software most people are using right now.

It's very cool work, but the advantage is clearly that you can modify the code easier than in other software, not that you can perform DFT suepr efficiently.

2

u/manassharma007 Aug 24 '26

Well since I'm also a TURBOMOLE developer, I can tell you that sophisticated and well-mature codes like TURBOMOLE utilise techniques like MARI-J approximation which is linear scaling in principle. Therefore, no performance benchmarks are necessary as of course it would be faster as we go to bigger system sizes. The article did not mean to say that PyFock is super fast in absolute terms. But rather that if the same algorithm is implemented using Python and JIT then it can perform just as well as a C/C++ implementation. So why not retain both readability and performance. That's it.

But that being said, I am currently working on improving the GPU code further and also on MARI-J. So hopefully in the near future it would be competitive with ORCA.

1

u/manassharma007 12d ago

Hey, Just published a benchmark comparing the performance of multiple QC programs for the same calculations reported in the PyFock paper.
Also updated PyFock in the mean time and it is faster than ORCA and quite close to TURBOMOLE's performance. Check it out here:
https://www.linkedin.com/posts/manassharma07_dft-programs-performance-comparison-ugcPost-7527647358013317120-Lixc/

4

u/manassharma007 Aug 24 '26

I'm glad you asked this. As you can see from the paper (Open Access, BTW, so anyone can download it), PyFock is not at all slow compared to other codes that use C/C++ as backends for molecular integrals or other compute-intensive operations. This is possible through the just-in-time compilation capabilities provided by Numba (a python library). This means that the development of complex codes no longer needs to be a "two-language problem". Usually, quantum chemistry utilize libcint/libint, which are written in low-level languages and then provide a wrapper on top of those. PyFock, implements all these from scratch in python.

3

u/Historical-Mix6784 Aug 24 '26

This is really cool and also serves as an important test of Numba. 

I’d never had much luck in accelerating my code using JIT and always had to use Cython, but this proves that, if done intelligently JIT can actually be competitive with C backend. 

2

u/FeLoNy111 Aug 24 '26

ASE integration is awesome. My issue with DFT -> ASE workflows has been that things have been pretty consistently fragile, eg VASP has to run in a temporary directory and then ASE is just a file reader. This would seem to solve that general fragility

Nice work!

2

u/Internal-Swordfish-9 Aug 24 '26

Nice work. Have you compared with PySCF? Not sure what extra your code adds compare to PySCF