← API reference
Quantum chemistry

PySCF API

Electronic structure calculations with PySCF and GPU4PySCF

Run PySCF Python scripts or build a Hartree–Fock or DFT calculation from molecular coordinates. Compute energies, gradients, optimized structures and harmonic frequencies.

Input method

Set input_mode to choose how inputs are supplied. Only fields for the selected method are used.

Send a Python script in pyscf_input for text mode or its UTF-8 contents in pyscf_input_file for upload mode. Scripts choose the GPU by calling to_gpu().

{"input_mode": "text", "pyscf_input": "from pyscf import gto, scf\nmol = gto.M(atom='H 0 0 0; H 0 0 0.74', basis='sto-3g')\nprint(scf.RHF(mol).kernel())"}

Parameter jobs return result.energy_hartree, the compute device and the final geometry. All modes return printed output and links to generated files in pyscf_files.

Example presets

Send {"preset": "water_energy"} to load an example and its bundled inputs. Add other request fields to override its settings. The schema includes all presets under tool.presets.

presetDescription
water_energyA density-fitted RHF/cc-pVDZ single point on water. Source ↗
water_gpu_gradientDensity-fitted B3LYP nuclear gradient using GPU4PySCF. Source ↗
h2_pythonRun a minimal PySCF script and print its total energy. Source ↗
Request body

Fields

The same names the web form posts. See the field type table for what each kind means over HTTP.

Name Type Required Default Description
pyscf_input string textarea yes text — Python script A Python script using PySCF or GPU4PySCF. Printed output and files written in the working directory are saved. Use pyscf.tools.molden.from_scf to export molecular orbitals. up to 200000 characters.
pyscf_input_file string file yes upload — Python script file Choose a UTF-8 Python script. up to 200000 characters, file types .py.
coordinates string textarea yes parameters O 0.0000 0.0000 0.0000 H 0.0000 -0.7570 0.5870 H 0.0000 0.7570 0.5870 Molecular geometry Element and Cartesian x, y, z coordinates, one atom per line. up to 100000 characters.
unit string select yes parameters Angstrom Coordinate units Length unit for the input geometry. One of: Angstrom, Bohr.
charge number number yes parameters 0 Molecular charge Total charge in elementary charges. minimum -50, maximum 50, step 1.
spin number number yes parameters 0 Spin (2S) Number of alpha electrons minus beta electrons. Use 0 for a singlet or 1 for a doublet. minimum 0, maximum 100, step 1.
calculation string select yes parameters energy Calculation Frequencies are evaluated at the supplied geometry. One of: energy, gradient, optimize, frequency.
method string select yes parameters RHF Method Use an unrestricted method for an open shell. One of: RHF, UHF, RKS, UKS.
basis string combobox yes parameters cc-pvdz Basis set PySCF basis name, such as sto-3g, cc-pVDZ or def2-TZVP. up to 200 characters. Common values: sto-3g, 3-21g, 6-31g, 6-31g*, 6-31g**, 6-31+g*, 6-311g**, 6-311+g(2d,p), 6-311++g(2d,2p), cc-pvdz, cc-pvtz, cc-pvqz, aug-cc-pvdz, aug-cc-pvtz, aug-cc-pvqz, cc-pcvdz, def2-svp, def2-svpd, def2-tzvp, def2-tzvpd, def2-tzvpp, def2-tzvppd, def2-qzvp, def2-qzvpp, pcseg-0, pcseg-1, pcseg-2, aug-pcseg-1.
xc string combobox no parameters b3lyp DFT functional Exchange-correlation functional used by RKS and UKS: any name PySCF accepts, such as b3lyp, wb97m-v or b88,lyp. up to 200 characters. Common values: svwn, blyp, bp86, pbe, revpbe, tpss, scan, r2scan, m06-l, b97m-v, b3lyp, pbe0, tpssh, m06-2x, pw6b95, x3lyp, wb97x, wb97x-v, wb97m-v, cam-b3lyp, hse06.
density_fit boolean checkbox no parameters true Density fitting Use an auxiliary basis for the two-electron integrals.
save_molden boolean checkbox no parameters false Save molecular orbitals (Molden) Write the converged SCF orbitals to orbitals.molden.
device string select yes parameters auto Compute device Automatic uses GPU4PySCF when installed. One of: auto, cpu, gpu.
threads number number yes parameters 1 CPU threads Threads available to PySCF. minimum 1, maximum 256, step 1.
memory_mb number number yes parameters 2000 Memory (MB) PySCF host memory budget in decimal megabytes. minimum 64, maximum 1048576, step 1.
Example

Example request

These are the defaults, exactly as the web form would post them.

curl -X POST https://athanortools.com/api/pyscf/ \
  -H 'Content-Type: application/json' \
  -d '{
  "input_mode": "parameters",
  "coordinates": "O   0.0000   0.0000   0.0000\nH   0.0000  -0.7570   0.5870\nH   0.0000   0.7570   0.5870",
  "unit": "Angstrom",
  "charge": 0,
  "spin": 0,
  "calculation": "energy",
  "method": "RHF",
  "basis": "cc-pvdz",
  "xc": "b3lyp",
  "density_fit": true,
  "save_molden": false,
  "device": "auto",
  "threads": 1,
  "memory_mb": 2000
}'

The reply is 202 with a queued job; poll its status_url until status is succeeded or failed. See the quick start for the whole exchange.

Responses

Data

statusMeaning
queued Accepted, waiting for the jobs ahead of it. `position` counts how many those are.
running The tool is executing now.
succeeded Finished; `result` holds the tool's output and `license` the terms it came under.
failed Finished; `error` holds a code and a message.
cancelled Abandoned at the submitter's request; there is no result. A job cancelled before its turn never ran at all.

Errors

codeMeaning
invalid_input The client supplied invalid or incomplete input.
tool_unavailable The requested third-party dependency is not available on this host.
execution_failed A configured third-party tool exited unsuccessfully.
internal_error An adapter failed in a way it does not describe. The detail is in the server log, not the response.
not_found No job has that id. Finished jobs are dropped eventually.
unauthorized HTTP 401. The bearer token is wrong, was revoked, or belongs to an account that can no longer sign in. Nothing was run.
job_limit_reached HTTP 429. This address, not being signed in, has submitted as many jobs as it may in 24 hours. Accounts have no limit.
runtime_limit_exceeded The job was stopped when it reached the execution time limit for its submitter.