2. Productivity tools: Linux and JupyterLab¶
2.1. Ubuntu¶
Ubuntu is a popular, free, and open-source operating system based on the Linux kernel.
2.1.1. How to download and install Ubuntu¶
Step 1: Download Ubuntu ISO¶
- Go to the official Ubuntu website: https://ubuntu.com/download
- Choose the version you want (e.g., Ubuntu Desktop LTS or Ubuntu Server)
- Click Download to get the
.iso
file
Step 2: Create a Bootable USB Drive¶
- A USB stick with at least 8 GB capacity
- Bootable USB Live by a tool like Rufus (for Windows) or
balenaEtcher
(for Mac/Linux)
Step 3: Boot From USB¶
- Insert the bootable USB into the target computer
- Restart the computer
- Enter BIOS/UEFI (usually by pressing
F2
,F12
,DEL
, orESC
) - Set the USB drive as the primary boot device
- Save and exit
Step 4: Install Ubuntu¶
- Choose "Install Ubuntu" when the menu appears
- Select your language, keyboard layout, and other preferences
- Choose installation type:
- Erase disk and install Ubuntu
- Install alongside existing OS
- Something else (for custom partitions)
- Follow prompts to set username, password, and location
- Wait for installation to complete
- Reboot when prompted, remove the USB
Step 5: Post-Installation (Optional)¶
- Update system:
sudo apt update && sudo apt upgrade -y
- Install Quantum ESPRESSO: See 1.5.1 in Lecture 1: Introduction to DFT with QE
2.1.2. Basic Ubuntu (Linux) commands¶
Command | Description | Example |
---|---|---|
ls |
List directory contents | ls -la |
cd |
Change directory | cd /home/user/Documents |
pwd |
Print working directory | pwd |
mkdir |
Create a new directory | mkdir new_folder |
rm |
Remove files or directories | rm file.txt |
rmdir |
Remove empty directory | rmdir empty_folder |
cp |
Copy files or directories | cp file1.txt file2.txt |
mv |
Move or rename files | mv old.txt new.txt |
touch |
Create an empty file | touch file.txt |
nano / vim |
Edit files with a text editor | nano file.txt |
cat |
Display file contents | cat file.txt |
sudo |
Run command as superuser | sudo apt update |
apt |
Package manager for Debian/Ubuntu | sudo apt install curl |
man |
Display manual for a command | man ls |
chmod |
Change file permissions | chmod +x script.sh |
chown |
Change file ownership | chown user:user file.txt |
df |
Show disk space usage | df -h |
top |
Show real-time system processes | top |
ps |
Show running processes | ps aux |
kill |
Terminate a process by PID | kill 1234 |
2.1.3. Basic Quantum ESPRESSO (QE) commands¶
Command | Description | Example |
---|---|---|
pw.x |
Runs the Plane-Wave Self-Consistent Field (SCF) code | pw.x < scf.in > scf.out |
dos.x |
Computes Density of States | dos.x < dos.in > dos.out |
projwfc.x |
Projects wavefunctions (for PDOS) | projwfc.x < projwfc.in > projwfc.out |
bands.x |
Computes band structure from saved data | bands.x < bands.in > bands.out |
ph.x |
Runs phonon calculations | ph.x < ph.in > ph.out |
q2r.x |
Converts dynamical matrices from q to real space | q2r.x < q2r.in > q2r.out |
matdyn.x |
Calculates phonon dispersion and DOS | matdyn.x < matdyn.in > matdyn.out |
pp.x |
Post-processing (e.g., charge density visualization) | pp.x < pp.in > pp.out |
mpirun -np N pw.x |
Run SCF with MPI on N cores | mpirun -np 8 pw.x < scf.in > scf.out |
pw.x -in input.in |
Alternate input format (no I/O redirection) | pw.x -in scf.in |
2.2. JupyterLab on Ubuntu¶
2.2.1. What is JupyterLab?¶
JupyterLab is a next-generation web-based interactive development environment for notebooks, code, and data. It's an evolution of the classic Jupyter Notebook, with support for:
- Multiple documents and editors (notebooks, terminals, text files, etc.)
- Drag-and-drop interface
- Rich extensions and themes
Great for data science, machine learning, scientific computing, and research.
2.2.3. How to Install JupyterLab on Ubuntu¶
Step 1: Update Your System¶
$ sudo apt update && sudo apt upgrade -y
Step 2: Install Python and Pip¶
$ sudo apt install python3 python3-pip -y
Step 4: Install JupyterLab¶
$ pip install jupyterlab
Step 5: Additional Python scientific libraries¶
$ pip install numpy scipy sympy matplotlib
- numpy: numerical computing with arrays
- scipy: scientific computing, linear algebra, optimization, etc.
- sympy: symbolic mathematics (like algebra, calculus, equation solving)
- matplotlib: plotting and data visualization
Step 6 (optional): JupyterLab extensions¶
$ pip install nodejs
- nodejs: an open-source, cross-platform environment for running JavaScript applications. Some extensions might require a rebuild of JupyterLab upon installation. This rebuild process relies on Node.js.
2.2.4. How to Use JupyterLab¶
Step 1: Start JupyterLab¶
$ jupyter lab
- This will launch JupyterLab in your browser at
http://localhost:8888
- A token will be printed in the terminal if not previously configured
Step 2: Create Notebooks or Scripts¶
- Use the launcher interface to open:
- Python notebooks
- Markdown files
- Terminal sessions
- Text/code editors
Step 3: Stop JupyterLab¶
- Press
Ctrl+C
in the terminal where it's running - Type
y
and pressEnter
to confirm shutdown
2.3. JupyterLab on Visual Studio Code (VS Code)¶
2.3.1. What is Visual Studio Code (VS Code)?¶
Visual Studio Code (VS Code) is a free, open-source, and lightweight code editor developed by Microsoft. It is widely used by developers for writing, editing, debugging, and deploying code across many programming languages and platforms.
2.3.2: Install Visual Studio Code on Ubuntu¶
Method 1: Install via apt
(Recommended)¶
$ sudo apt update
$ sudo apt install wget gpg -y
$ wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
$ sudo install -o root -g root -m 644 packages.microsoft.gpg /usr/share/keyrings/
$ sudo sh -c 'echo "deb [arch=amd64 signed-by=/usr/share/keyrings/packages.microsoft.gpg] \
https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
$ sudo apt update
$ sudo apt install code
Method 2: Install from .deb File¶
- Download
.deb
from: https://code.visualstudio.com/ - Install with:
$ sudo dpkg -i code_*.deb
$ sudo apt --fix-broken install
2.3.3: Install Jupyter Extension in VS Code¶
- Open VS Code
- Go to the Extensions tab (or press
Ctrl+Shift+X
) - Search for "Jupyter" (by Microsoft)
- Click Install
2.3.4. Run Jupyter Notebooks in VS Code¶
Option 1: Create a New Notebook¶
- Press
Ctrl+Shift+P
, searchJupyter: Create New Blank Notebook
- Choose a kernel (Python 3, etc.)
Option 2: Open an Existing .ipynb
File¶
- File → Open File → select your
.ipynb
notebook - You’ll see interactive cells inside VS Code
1.6. Exercise¶
- Practice with Linux command line and JupyterLab on your PC.
1.7. Dive deeper¶
Level 1: Read Chapter 6 of "Quantum ESPRESSO for Solid State Physics" book for Linux commands.
Level 2: Install and run JupyterLab on VSCode.