5.3.5. Week 3 Hands-On: File Transfer (scp/WinSCP), vi, and More Jupyter/Python#


5.3.5.1. Overview#

Today you will practice three skills you will use repeatedly in computational chemistry workflows:

  1. Transferring files to/from the HPC system (pete.hpc.okstate.edu) using scp (and WinSCP for Windows users)

  2. A crash course in vi (the editor you will see on HPC systems)

  3. A few advanced Jupyter/Python habits (functions, re-running cells safely, and simple organization)

End-of-class deliverable: a small set of files in your HPC directory plus brief evidence pasted into this notebook.


5.3.5.2. Learning Goals#

By the end of this session, you should be able to:

  • Use scp to copy files to and from pete.hpc.okstate.edu

  • Explain the difference between a local machine path and a remote path

  • Use vi to create and edit a text file (insert mode, save, quit, search)

  • Write a simple Python function in a notebook and use it to compute values repeatedly

  • Keep a notebook reproducible (restart kernel, run-all, avoid hidden state)

5.3.5.3. 0. Setup: Your Working Directory on Pete#

For this activity, work in the directory:

/projects/tia001/$USER/week3

Create it if it does not exist:

mkdir -p /projects/tia001/$USER/week3
cd /projects/tia001/$USER/week3
pwd

Note: $USER expands to your username on the HPC system.

# Run these in a TERMINAL on pete (or a Jupyter terminal)
mkdir -p /projects/tia001/$USER/weekX
cd /projects/tia001/$USER/weekX
pwd
ls -la
  Cell In[1], line 2
    mkdir -p /projects/tia001/$USER/weekX
                              ^
SyntaxError: invalid syntax

5.3.5.4. 1. Transferring Files with scp (Mac/Linux)#

5.3.5.4.1. 1.1 Key idea: scp syntax#

scp [options] SOURCE DESTINATION
  • Local paths look like: ./file.txt, /Users/you/Documents/file.txt

  • Remote paths look like: username@pete.hpc.okstate.edu:/path/on/pete/

5.3.5.4.2. 1.2 Copy a file to Pete#

From your local computer terminal:

scp local_file.txt YOURUSERNAME@pete.hpc.okstate.edu:/projects/tia001/YOURUSERNAME/week3/

5.3.5.4.3. 1.3 Copy a file from Pete back to your local computer#

scp YOURUSERNAME@pete.hpc.okstate.edu:/projects/tia001/YOURUSERNAME/week3/remote_file.txt .

The final . means “copy into the current local directory”.

5.3.5.4.4. 1.4 Copy an entire directory (recursive)#

scp -r myfolder YOURUSERNAME@pete.hpc.okstate.edu:/projects/tia001/YOURUSERNAME/week3/

5.3.5.4.5. 1.5 Common options#

  • -r recursive (directories)

  • -p preserve timestamps

  • -v verbose (debug)

  • -C compression (sometimes helpful)

5.3.5.4.6. 1.6 Quick sanity checks#

On Pete:

ls -l /projects/tia001/$USER/week3

Locally:

ls -l

5.3.5.5. 2. Windows Users: WinSCP (GUI File Transfer)#

If you are on Windows, the easiest path is often WinSCP:

  • File protocol: SFTP (recommended)

  • Host name: pete.hpc.okstate.edu

  • User name: your Pete username

  • Password: your Pete password (or Duo/2FA flow if required)

5.3.5.5.1. What to do in WinSCP#

  1. Connect to pete.hpc.okstate.edu

  2. Navigate to: /projects/tia001/<your_username>/week3/

  3. Drag-and-drop files between your local machine and the remote directory

5.3.5.5.2. Equivalent to scp#

  • Upload: drag local → remote

  • Download: drag remote → local

If you prefer a terminal on Windows, you can use PowerShell with scp (OpenSSH), or WSL.

5.3.5.6. 3. Mini-Task: Transfer a File (Everyone)#

5.3.5.6.1. Goal#

Create a small file locally, transfer it to Pete, and verify it arrived.

5.3.5.6.1.1. Step A (local machine)#

Create a file called hello_local.txt with a short message (one line).

5.3.5.6.1.2. Step B (transfer)#

Use scp (or WinSCP) to place it into:

/projects/tia001/$USER/week3/

5.3.5.6.1.3. Step C (verify on Pete)#

On Pete, run:

cd /projects/tia001/$USER/week3
ls -l hello_local.txt
cat hello_local.txt

You will paste the output of these verification commands into the assignment section at the end.

# Run on pete after transfer:
cd /projects/tia001/$USER/weekX
ls -l hello_local.txt
cat hello_local.txt

5.3.5.7. 4. vi Crash Course (HPC Essential)#

5.3.5.7.1. 4.1 Two modes you must know#

  • Normal mode: navigation + commands (default)

  • Insert mode: typing text (press i to enter)

5.3.5.7.2. 4.2 Minimal survival commands#

  • i : enter insert mode

  • Esc : back to normal mode

  • :w : write/save

  • :q : quit

  • :wq : save and quit

  • :q! : quit without saving

  • /text : search forward for text

  • n : next match

  • gg : go to top of file

  • G : go to bottom

  • dd : delete a line

  • yy : copy (yank) a line

  • p : paste below

5.3.5.7.3. 4.3 Practice file on Pete#

On Pete, create and edit:

vi vi_practice.txt

Put the following (exactly except replace the <> entries with the proper text) as the first three lines, then add 2–3 additional lines of your choice:

  1. NAME: <your name>

  2. USERNAME: <your username>

  3. TODAY: <YYYY-MM-DD>

Save and quit.

Verify:

cat vi_practice.txt
# Run on pete:
cd /projects/tia001/$USER/weekX
vi vi_practice.txt

# After saving:
cat vi_practice.txt

5.3.5.8. 5. Jupyter/Python Power-Ups (If Time)#

5.3.5.8.1. 5.1 Avoid hidden state#

A notebook can silently depend on the order you ran cells.

Good habit:

  1. Restart kernel

  2. Run all cells from the top

5.3.5.8.2. 5.2 Writing functions (reusable code)#

A function packages a calculation you can reuse many times.

Example: compute \(\sqrt{x^2 + 1}\).

Run the cell below.

import math

def f(x: float) -> float:
    """Compute sqrt(x^2 + 1)."""
    return math.sqrt(x**2 + 1)

for x in [0, 1, 2, 3, 4]:
    print(x, f(x))

5.3.5.8.3. 5.3 A tiny workflow example#

Compute a table of values and save it as a text file on Pete.

Run the cell below (it writes values.txt into your current working directory).

import numpy as np

xs = np.linspace(0, 4, 9)
vals = [(float(x), f(float(x))) for x in xs]

with open("values.txt", "w", encoding="utf-8") as fp:
    fp.write("# x  sqrt(x^2+1)\n")
    for x, y in vals:
        fp.write(f"{x:8.3f}  {y:12.6f}\n")

print("Wrote values.txt with", len(vals), "rows")

5.3.6. End-of-Class Assignment (Due at End of Session)#

Complete the tasks below. Paste requested outputs into this notebook (in the cells provided).

All files should be in:

/projects/tia001/$USER/week3

5.3.6.1. Task A (File Transfer Evidence)#

Paste the output of these commands run on Pete:

cd /projects/tia001/$USER/week3
ls -l hello_local.txt
cat hello_local.txt

You should see the file you created locally and transferred to Pete.

# Paste Task A output here (or run in a pete terminal and paste)

5.3.6.2. Task B (vi Evidence)#

Paste the output of:

cd /projects/tia001/$USER/week3
cat vi_practice.txt

Your file must include the three required lines (NAME/USERNAME/TODAY).

# Paste Task B output here

5.3.6.3. Task C (Functions + Reproducibility)#

In the code cell below:

  1. Write a function energy(n, L) that returns the particle-in-a-box energy [ E_n = \frac{n^2\pi^2}{2L^2} ] in units where \(\hbar=m=1\).

  2. Use your function to print E_n for n = 1..5 with L = 1.0.

  3. Restart your kernel and Run All to confirm everything still works.

(We will spot-check that your notebook runs from top to bottom.)

import math

def energy(n: int, L: float) -> float:
    # YOUR CODE HERE
    raise NotImplementedError

# Print energies for n=1..5 at L=1.0

5.3.6.4. Wrap-up Reflection (2–3 sentences, Markdown)#

  • What part of today’s workflow felt most unfamiliar?

  • What is one step you will use next week when running calculations?

(Write your response below.)

Write your reflection here.