A complete guide to turning an old Android phone into a remote DFT compute server with job submission, monitoring, and remote access.
This guide walks through setting up a complete DFT job submission system on an Android phone using Termux. The phone acts as a compute server โ you submit jobs from your laptop, the phone runs them, and you download the results.
Download and install these apps from f-droid.org:
Important: Do not install Termux from the Play Store โ it is outdated. Always use the F-Droid version.
Go to Settings โ Apps โ Termux โ Battery โ Unrestricted
Do the same for Termux:Boot. This prevents Android from killing the server.
# Update packages
pkg update && pkg upgrade -y
# Install SSH server
pkg install openssh -y
# Set a password
passwd
# Start SSH server
sshd
๐ป From Laptop
# Connect to phone (default port 8022)
ssh -p 8022 192.168.1.46
Find your phone's IP by running ifconfig in Termux or checking your router's connected devices.
# Install dependencies
pkg install redis python -y
pip install flask rq
# Start Redis
redis-server --daemonize yes
# Test Redis
redis-cli ping
# Should return: PONG
# Create project directory
mkdir ~/jobserver && cd ~/jobserver
# Create tasks.py
cat > tasks.py << 'EOF'
import time, subprocess
def sleep_job(seconds):
time.sleep(seconds)
return f"Slept {seconds}s"
def run_script(script_path, args=None):
cmd = ["bash", script_path] + (args or [])
result = subprocess.run(cmd, capture_output=True, text=True)
return {"stdout": result.stdout, "stderr": result.stderr, "code": result.returncode}
def run_qe(input_file, output_file=None):
if output_file is None:
output_file = input_file.replace('.in', '.out')
pw = '/data/data/com.termux/files/home/q-e/bin/pw.x'
result = subprocess.run(
[pw, '-i', input_file],
stdout=open(output_file, 'w'),
stderr=subprocess.PIPE,
text=True
)
return {
"output_file": output_file,
"returncode": result.returncode,
"stderr": result.stderr
}
EOF
# Create server.py using Python
python3 -c "
content = '''from flask import Flask, request, jsonify, send_file
from rq import Queue
from rq.job import Job
from redis import Redis
import tasks, os
app = Flask(__name__)
conn = Redis()
q = Queue(connection=conn)
UPLOAD_DIR = \"/data/data/com.termux/files/home/qe_jobs\"
os.makedirs(UPLOAD_DIR, exist_ok=True)
@app.route(\"/upload\", methods=[\"POST\"])
def upload():
if \"file\" not in request.files:
return jsonify({\"error\": \"no file provided\"}), 400
f = request.files[\"file\"]
path = os.path.join(UPLOAD_DIR, f.filename)
f.save(path)
return jsonify({\"path\": path, \"message\": \"uploaded successfully\"})
@app.route(\"/submit\", methods=[\"POST\"])
def submit():
data = request.json
job_type = data.get(\"type\")
if job_type == \"qe\":
job = q.enqueue(tasks.run_qe, data[\"input\"], data.get(\"output\"), job_timeout=3600)
elif job_type == \"sleep\":
job = q.enqueue(tasks.sleep_job, data[\"seconds\"])
else:
return jsonify({\"error\": \"unknown job type\"}), 400
return jsonify({\"job_id\": job.id, \"status\": str(job.get_status())})
@app.route(\"/status/\", methods=[\"GET\"])
def status(job_id):
job = Job.fetch(job_id, connection=conn)
return jsonify({\"id\": job.id, \"status\": str(job.get_status()), \"result\": job.result})
@app.route(\"/jobs\", methods=[\"GET\"])
def list_jobs():
queued = [j.id for j in q.get_jobs()]
return jsonify({\"queued\": queued, \"length\": len(q)})
@app.route(\"/download\", methods=[\"GET\"])
def download():
path = request.args.get(\"path\")
if not path:
return jsonify({\"error\": \"no path provided\"}), 400
try:
return send_file(path, as_attachment=True)
except Exception as e:
return jsonify({\"error\": str(e)}), 404
if __name__ == \"__main__\":
app.run(host=\"0.0.0.0\", port=5000)
'''
open('/data/data/com.termux/files/home/jobserver/server.py', 'w').write(content)
print('done')
"
# Install tmux for managing multiple processes
pkg install tmux -y
tmux new -s jobserver
# In tmux - split panes with Ctrl+B then %
# Left pane: start RQ worker
cd ~/jobserver && rq worker
# Right pane: start Flask (Ctrl+B then right arrow)
cd ~/jobserver && python server.py
| Method | Endpoint | Description |
|---|---|---|
| POST | /upload | Upload input file to phone |
| POST | /submit | Submit a job to the queue |
| GET | /status/<job_id> | Check job status |
| GET | /jobs | List queued jobs |
| GET | /download?path=... | Download output file |
Compilation takes 30โ60 minutes. Keep the phone plugged in and make sure Termux stays active.
# Install build dependencies
pkg install cmake make clang flang openblas fftw patchelf llvm -y
# Install missing library fix
pkg install libandroid-complex-math -y
ln -s /data/data/com.termux/files/usr/lib/libandroid-complex-math.so \
/data/data/com.termux/files/usr/lib/libandroid-complex-math.a
# Create symlinks for missing tools
ln -s /data/data/com.termux/files/usr/bin/llvm-ar \
/data/data/com.termux/files/usr/bin/ar
ln -s /data/data/com.termux/files/usr/bin/flang \
/data/data/com.termux/files/usr/bin/gfortran
# Clone Quantum Espresso
cd ~ && git clone https://github.com/QEF/q-e.git
cd ~/q-e
# Configure with flang
./configure F77=flang FC=flang
# Fix make.inc (remove duplicate compiler entries)
grep "^MPIF90\|^F90\|^LD" make.inc
# Ensure these are all set to 'flang' with no duplicates:
# MPIF90 = flang
# F90 = flang
# LD = flang
# Fix lapack make.inc
sed -i 's/FORTRAN = gfortran/FORTRAN = flang/' ~/q-e/install/make_lapack.inc
sed -i 's/OPTS = -O3 -g/OPTS =/' ~/q-e/install/make_lapack.inc
sed -i 's/LOADOPTS = -g/LOADOPTS =/' ~/q-e/install/make_lapack.inc
# Build pw.x with all cores
make pw -j6 2>&1 | tail -20
# Verify binary exists
ls ~/q-e/bin/pw.x
# Download Silicon pseudopotential
mkdir -p ~/pseudo ~/out ~/qe_jobs
wget https://pseudopotentials.quantum-espresso.org/upf_files/Si.pbe-n-rrkjus_psl.1.0.0.UPF \
-P ~/pseudo/
Test your installation: ~/q-e/bin/pw.x -i ~/si_vcrelax.in > ~/si_vcrelax.out 2>&1
Save this as submit.py on your laptop:
import requests, sys, time, os
PHONE_URL = "http://100.83.65.14:5000" # Your phone's Tailscale IP
def upload_and_submit(input_file):
print(f"Uploading {input_file}...")
with open(input_file, 'rb') as f:
r = requests.post(f"{PHONE_URL}/upload", files={"file": f})
remote_path = r.json()["path"]
print(f"Uploaded to: {remote_path}")
r = requests.post(f"{PHONE_URL}/submit", json={
"type": "qe", "input": remote_path
})
job_id = r.json()["job_id"]
print(f"Job ID: {job_id}")
while True:
r = requests.get(f"{PHONE_URL}/status/{job_id}")
status = r.json()["status"]
print(f"Status: {status}")
if "FINISHED" in status:
return job_id, r.json()["result"]["output_file"]
elif "FAILED" in status:
sys.exit("Job failed!")
time.sleep(5)
def download_output(output_file):
local_file = os.path.basename(output_file)
r = requests.get(f"{PHONE_URL}/download", params={"path": output_file})
open(local_file, 'wb').write(r.content)
print(f"Saved to {local_file}")
if __name__ == "__main__":
job_id, output = upload_and_submit(sys.argv[1])
download_output(output)
print("Done!")
# Usage
python3 submit.py my_calculation.in
Install Termux:Boot from F-Droid, open it once, then create the boot script:
๐ฑ On Phone (via SSH)mkdir -p ~/.termux/boot
cat > ~/.termux/boot/start_server.sh << 'EOF'
#!/data/data/com.termux/files/usr/bin/bash
termux-wake-lock
sleep 10
pkill -f "redis-server"
pkill -f "rq worker"
pkill -f "python server.py"
sleep 2
redis-server --daemonize yes
sleep 2
cd /data/data/com.termux/files/home/jobserver
rq worker &
sleep 2
python server.py &
EOF
chmod +x ~/.termux/boot/start_server.sh
The sleep 10 gives Android time to fully boot before starting services. After phone restart, the server will be available in ~15 seconds.
Tailscale creates a secure VPN mesh so you can access your phone from anywhere without port forwarding.
๐ป On Laptop# Install Tailscale
curl -fsSL https://tailscale.com/install.sh | sh
sudo tailscale up
# Visit the URL shown to authenticate
# Get your laptop's Tailscale IP
tailscale ip
๐ฑ On Phone
Install Tailscale from the Play Store and log in with the same account.
๐ป On Laptop โ Test Remote Access# Replace with your phone's Tailscale IP (shown in Tailscale app)
curl http://100.83.65.14:5000/jobs
# Should return: {"length":0,"queued":[]}
Once connected, update PHONE_URL in submit.py to your phone's Tailscale IP. You can now submit jobs from anywhere in the world!
| Item | Path |
|---|---|
| QE Binary | ~/q-e/bin/pw.x |
| Pseudopotentials | ~/pseudo/ |
| Job inputs | ~/qe_jobs/ |
| Job server | ~/jobserver/ |
| Boot script | ~/.termux/boot/start_server.sh |
# Check server status
curl http://<PHONE_IP>:5000/jobs
# Upload input file
curl -X POST http://<PHONE_IP>:5000/upload -F "[email protected]"
# Submit QE job
curl -X POST http://<PHONE_IP>:5000/submit \
-H "Content-Type: application/json" \
-d '{"type": "qe", "input": "/path/to/input.in"}'
# Check job status
curl http://<PHONE_IP>:5000/status/<job_id>
# Download output
curl "http://<PHONE_IP>:5000/download?path=/path/to/output.out" -o output.out
&CONTROL
calculation = 'vc-relax'
prefix = 'silicon'
outdir = '/data/data/com.termux/files/home/out'
pseudo_dir = '/data/data/com.termux/files/home/pseudo'
/
&SYSTEM
ibrav = 2
celldm(1) = 10.2
nat = 2
ntyp = 1
ecutwfc = 30.0
ecutrho = 120.0
/
&ELECTRONS
conv_thr = 1.0e-8
/
&IONS
ion_dynamics = 'bfgs'
/
&CELL
cell_dynamics = 'bfgs'
/
ATOMIC_SPECIES
Si 28.086 Si.pbe-n-rrkjus_psl.1.0.0.UPF
ATOMIC_POSITIONS {alat}
Si 0.00 0.00 0.00
Si 0.25 0.25 0.25
K_POINTS {automatic}
4 4 4 0 0 0