Python

Looking for resources to become more proficient with Python? Check out the  MolSSI Education Resources for Python ,  Scientific Computing from Scratch , or  Python for Everybody . That said, there are nearly unlimited free resources out there, so use what works well for you!

Set up a Conda Environment

 Conda  is a package manager and environment management system for the Python programming language. I generally recommend using a minimal version called  Miniconda , described below.

To install Miniconda on a Linux machine, run the following:
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod +x Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh
For Mac/Windows, you should download and execute the Miniconda installer found  here .

When asked if you wish to add conda to your  PATH  environment variable and/or to run  conda init  after completion, enter  yes . Ignore the warning.

Once that's done, we will create an environment called  quacc .
conda create --name quacc python=3.11

Activate the environment and install several packages we will regularly use.
conda activate quacc
conda install numpy matplotlib jupyterlab ruff pytest

It is generally best to keep your base conda environment clean and to rely on other environments instead for installing new packages. It is often wise to make a conda environment for each project as a matter of reproducibility and ease of use.

Every now and then, you may need to run  conda clean --all  to remove the cached installers that end up accumulating a lot of space.

Nuking a Conda Environment

More often than one would like, you'll need to destroy your conda environment and start fresh if things just get messy. To do that:
conda env remove --name quacc
Then re-make your Conda environment like before.

Python Code Formatting

For internal consistency in the group, all publicly accessible Python code (and codes we work on collaboratively) should be formatted with  ruff . Ruff is by no means a "perfect" formatter (which is largely a matter of preference). However, there are few things more frustrating in scientific computing than dealing with formatting inconsistencies when you're just trying to get things done. Ruff is fast, uncompromising, and "just works."

To format your code with Ruff, make sure it is installed (e.g.  pip install ruff ). To format code from the command line, run  ruff format . --fix  in the directory of files you want to format. VS Code will also do this automatically on-save if you have the  Ruff  extension installed.

Jupyter Notebooks

Looking for a tutorial on how to use Jupyter Notebooks? See a written setup tutorial  here  and a video walkthrough  here .

To use Jupyter Notebooks on the Princeton HPC clusters, refer to  this guide .

Jupyter Notebooks are a great way to do exploratory data analysis, preparing small scripts, launch workflows on the HPC cluster, and write up tutorials. That said, Jupyter Notebooks are rarely ideal for writing research code. Most programming efforts should be with their own dedicated Python package that you use in editable mode ( pip install -e . ). Jupyter Notebooks make it difficult to adopt good programing practices, like modularity and testing. This isn't to say that you should avoid Jupyter Notebooks, but as they say: with great power comes great responsibility.