Installation and Runtime Configuration

Scratch Files

One very important part of user configuration at the end of the installation process is to tell PSI4 where to write its temporary (“scratch”) files. Electronic structure packages like PSI4 can create rather large temporary disk files. It is very important to ensure that PSI4 is writing its temporary files to a disk drive physically attached to the computer running the computation. If it is not, it will significantly slow down the program and the network. By default, PSI4 will write temporary files to /tmp, but this directory is often not large enough for typical computations. Therefore, you need to (a) make sure there is a sufficiently large directory on a locally attached disk drive (100GB–1TB or more, depending on the size of the molecules to be studied) and (b) tell PSI4 the path to this directory. Scratch file location can be specified through the PSI_SCRATCH environment variable or through the ~/.psi4rc file (see section ~/.psi4rc File). Most of the time, PSI_SCRATCH is preferred, and it overrides any existing ~/.psi4rc setting. You can set up PSI_SCRATCH by issuing the following commands in a terminal, or including them in the appropriate rc file.

# csh, tcsh: add to shell or ~/.tcshrc file
setenv PSI_SCRATCH /path/to/existing/writable/local-not-network/disk/for/scratch/files
# sh, bash: add to shell or ~/.bashrc (Linux/Windows) or ~/.bash_profile (Mac) file
export PSI_SCRATCH=/path/to/existing/writable/local-not-network/disk/for/scratch/files

PSI4 has a number of utilities that manage input and output (I/O) of quantities to and from the hard disk. Most quantities, such as molecular integrals, are intermediates that are not of interest to the user and can be deleted after the computation finishes, but pertinent details of computations are also written to a checkpoint file and might be useful in subsequent computations. All files are written to the designated scratch numbered by content and labeled with the process id, then are deleted at the end of the computation, unless otherwise instructed by the user.

A Python callable handle to the PSI4 I/O management routines is available, and is called psi4_io. To instruct the I/O manager to send all files to another location, say /scratch/user, add the following command to your input file:

psi4_io.set_default_path('/scratch/user')

For batch jobs running through a queue, it might be more convenient to use an environmental variable (in this case $MYSCRATCH) to set the scratch directory; the following code will do that:

import os
scratch_dir = os.environ.get('MYSCRATCH')
if scratch_dir:
    psi4_io.set_default_path(scratch_dir + '/')

Individual files can be sent to specific locations. For example, file 12 contains information about the internal coordiantes of a geometry optimization. The user may want to retain this in the working directory (i.e., where PSI4 was launched from) to analyze the optimization. This is accomplished by the commands below:

psi4_io.set_specific_path(12, './')
psi4_io.set_specific_retention(12, True)

# equivalent to above
psi4_io.set_specific_path(PSIF_INTCO, './')
psi4_io.set_specific_retention(PSIF_INTCO, True)

A guide to the contents of individual scratch files may be found at PSIOH Intermediate Files. To circumvent difficulties with running multiple jobs in the same scratch, the process ID (PID) of the PSI4 instance is incorporated into the full file name; therefore, it is safe to use the same scratch directory for calculations running simultaneously.

Elementary Restart

The PSI4 intermediate files use the following naming scheme

psi.PID.name.filenumber

where by default, PID is the process number, name the name of the molecule, and filenumber is listed in content.

For those modules providing restart capabilities, the previous file can be provided through the``restart_file`` option

energy('scf',restart_file='./psi.PID.name.filenumber')

Only the filenumber is necessary for the driver to appropriately rename the file and copy it to the scratch directory where PSI4 will expect it. The restart capabilities of a specific method (if any) are found in that method’s documentation.

To provide multiple files, pass them as arguments of a Python list

energy('scf',restart_file=['./file1.filenumber','./file2.filenumber'])

Note that the restart_file options is only available for energy procedures as of now.

Executing PSI4 with the psi4 -m (for messy) flag will prevent files being deleted at the end of the run:

psi4 -m

The mechanism for restarting HF/DFT calculations is described in details here.

Saving the Wavefunction

A core object of PSI4 is the Wavefunction (short wfn) object

energy, wfn = energy('scf',return_wfn=True)

This C++/Python object (psi4.core.Wavefunction) contains orbital data, basis set information, result variables and more. It can be saved either to a numpy file or converted to a python dictionary

# write the wavefunction to file
wfn.to_file('my_wfn')

# alternatively store the dict representation of the wavefunction in memory
wfn_dict = wfn.to_file()

In either form, its attributes can be set and edited. This is an expert-level feature, though. In general, let PSI4 create the Wavefunction, then treat it as read-only. The back conversion to a Wavefunction object uses the .from_file() functionality

# read wavefunction from file
wfn_from_file = psi4.core.Wavefunction.from_file('my_wfn')

# make a wavefunction from the dict
wfn_from_dict = psi4.core.Wavefunction.from_file(wfn_dict)

~/.psi4rc File

Caution

The ~/.psi4rc file is only read for Psithon input, not PsiAPI. It does nothing that can’t be done in other more transparent ways. It should be avoided. It is very easy to forget about the ~/.psi4rc file you once created, leading to great confusion over why all your jobs are using the wrong memory or are suddenly not density-fit. Also be aware that ~/.psi4rc contents count as part of your input file (invoked after e.g. from psi4 import * and before your Psithon–>Python parsed input commands), so these settings take priority over command-line arguments to the psi4 executable. Please use the ~/.psi4rc file sparingly.

If using the environment variable PSI_SCRATCH is inconvenient, or if some psi4_io commands must be present in all input files, the ~/.psi4rc resource file can be used (example psi4/samples/example_psi4rc_file).

All the commands mentioned in section Scratch Files can be used in this file.

To set up the scratch path:

psi4_io.set_default_path('/scratch/user')

To set up the scratch path from a variable $MYSCRATCH:

import os
scratch_dir = os.environ.get('MYSCRATCH')
if scratch_dir:
    psi4_io.set_default_path(scratch_dir + '/')

To set up a specific path for the internal coordinate file and instruct PSI4 not to delete it:

psi4_io.set_specific_path(12, './')
psi4_io.set_specific_retention(12, True)

# equivalent to above
psi4_io.set_specific_path(PSIF_INTCO, './')
psi4_io.set_specific_retention(PSIF_INTCO, True)

The Python interpreter will execute the contents of the ~/.psi4rc file in the current user’s home area (if present) before performing any tasks in the input file. As a consequence, the commands in the input files supersede any instructions in the ~/.psi4rc file. During execution, the ~/.psi4rc defaults will be loaded in first, but then the commands in the input file will be executed.

The ~/.psi4rc file can also be used to define constants that are accessible in input files or to place any Python statements that should be executed with every PSI4 instance.

Threading

Most new modules in PSI4 are designed to run efficiently on SMP architectures via application of several thread models. The de facto standard for PSI4 involves using threaded BLAS/LAPACK (particularly Intel’s excellent MKL package) for most tensor-like operations, OpenMP for more general operations, and C++ std::thread for some special-case operations. Note: Using OpenMP alone is a really bad idea. The developers make little to no effort to explicitly parallelize operations which are already easily threaded by MKL or other threaded BLAS. Less than 20% of the threaded code in PSI4 uses OpenMP, the rest is handled by parallel DGEMM and other library routines. From this point forward, it is assumed that you have compiled PSI4 with OpenMP and MKL (Note that it is possible to use g++ or another compiler and yet still link against MKL).

Control of threading in PSI4 can be accomplished at a variety of levels, ranging from global environment variables to direct control of thread count in the input file, to even directives specific to each model. This hierarchy is explained below. Note that each deeper level trumps all previous levels.

(1) OpenMP/MKL Environment Variables

Deprecated since version 1.1: Environment variables OMP_NUM_THREADS and MKL_NUM_THREADS do not affect threading in PSI4.

(2) The -n Command Line Flag

To change the number of threads at runtime, the psi4 -n flag may be used. An example is:

psi4 -i input.dat -o output.dat -n 4

which will run on four threads. Note that is is not available for PsiAPI mode of operation.

(3) Setting Thread Numbers in an Input

For more explicit control, the Process::environment class in PSI4 can override the number of threads set by environment variables. This functionality is accessed via the set_num_threads() function, which controls both MKL and OpenMP thread numbers. The number of threads may be changed multiple times in a PSI4 input file. An example input for this feature is:

# A bit small-ish, but you get the idea
molecule h2o {
0 1
O
H 1 1.0
H 1 1.0 2 90.0
}

# Run from 1 to 4 threads, for instance, to record timings
for nthread in range(1, 5):
    set_num_threads(nthread)
    energy("scf/cc-pvdz")

In PsiAPI mode of operation, this syntax, psi4.set_num_threads(nthread), is the primary way to control threading.

(4) Method-Specific Control

Even more control is possible in certain circumstances. For instance, the threaded generation of AO density-fitted integrals involves a memory requirement proportional to the number of threads. This requirement may exceed the total memory of a small-memory node if all threads are involved in the generation of these integrals. For general DF algorithms, the user may specify:

set MODULE_NAME df_ints_num_threads n

to explicitly control the number of threads used for integral formation. Setting this variable to 0 (the default) uses the number of threads specified by the set_num_threads() Psithon method or the default environmental variables.

PBS job file

To run a PSI4 job on a PBS queueing system, you need to properly set up all necessary variables in the PBS job file. Below is a minimal example of a PBS job file for a threaded job, and a short explanation for each section.

#!/bin/tcsh
#PBS -j oe
#PBS -l pmem=2120mb
#PBS -N jobname
#PBS -V

cd $PBS_O_WORKDIR
setenv myscratch /scratch/user/psi4.$PBS_JOBID

foreach i (`sort $PBS_NODEFILE | uniq`)
    echo "Creating scratch directory " $myscratch " on " $i
    ssh $i rm -rf $myscratch
    ssh $i mkdir -p $myscratch
end

unsetenv PSIDATADIR
setenv PSI_SCRATCH $myscratch
if ! ( $?PSIPATH ) setenv PSIPATH ""
setenv PSIPATH /path/to/external/modules:${PSIPATH}
setenv PSIPATH /path/to/python/modules:${PSIPATH}
/psi/install/directory/bin/psi4 -i input.in -o input.out -n 4

foreach i (`sort $PBS_NODEFILE | uniq`)
    echo "Removing scratch directory " $myscratch " on " $i
    ssh $i rm -rf $myscratch
end

The top section features PBS-specific commands. These depend on the specific characteristics of your PBS queuing system but they may include:

#!/bin/tcsh
#PBS -j oe
#PBS -l pmem=2120mb
#PBS -N jobname
#PBS -V

The PBS -j oe option instructs PBS to write any output or error message from the queuing system in dedicated files. PBS -l pmem=2120mb requests 2120 MB of memory for each thread on the node. The total memory requested for the job by PBS should generally be slightly greater than what indicated in the input file (see memory setting).

Then, we move to the working directory using PBS variable $PBS_O_WORKDIR and we create scratch directories on every node, using the $PBS_NODEFILE which points to a file containing a list of the nodes attributed to the job.

cd $PBS_O_WORKDIR
setenv myscratch /scratch/user/psi4.$PBS_JOBID

foreach i (`sort $PBS_NODEFILE | uniq`)
    echo "Creating scratch directory " $myscratch " on " $i
    ssh $i rm -rf $myscratch
    ssh $i mkdir -p $myscratch
end

The next section is very important as it sets the environment variables needed by PSI4:

unsetenv PSIDATADIR
setenv PSI_SCRATCH $myscratch
if ! ( $?PSIPATH ) setenv PSIPATH ""
setenv PSIPATH /path/to/external/modules:${PSIPATH}
setenv PSIPATH /path/to/python/modules:${PSIPATH}

PSIDATADIR does not need to be set. In the present example we unset it to make sure it does not interfere with the internal location-finding. PSIPATH is needed only if you are using external modules or plugins in PSI4 and should point to the directories where they can be found. In the present example, we make sure the variable is set with if ! ( $?PSIPATH ) setenv PSIPATH "" before adding more paths to it. Finally, PSI_SCRATCH should point to a fast, existing local disk for temporary file storage. To use 4 threads for OpenMP parallelization and threaded BLAS (see section Threading), we set -n4 below. The next step is then to actually run the computation:

/psi/install/directory/bin/psi4 -i input.in -o input.out -n 4

And then to clean up the scratch directories previously created:

foreach i (`sort $PBS_NODEFILE | uniq`)
    echo "Removing scratch directory " $myscratch " on " $i
    ssh $i rm -rf $myscratch
end

Note again that the specific commands for your PBS system may differ. Refer to your system administrator.

Command Line Options

PSI4 can be invoked with no command line arguments, as it takes as input by default the file “input.dat” and directs output by default to “output.dat”. Each set of three commands below is completely equivalent, while the second set, perhaps, is the most common usage.

>>> psi4
>>> psi4 -i input.dat -o output.dat
>>> psi4 input.dat output.dat

>>> psi4 descriptive_filename.in
>>> psi4 -i descriptive_filename.in -o descriptive_filename.out
>>> psi4 descriptive_filename.in descriptive_filename.out

Command-line arguments to PSI4 can be accessed through psi4 --help.

-a, --append

Append results to output file. Default: Truncate first

-h, --help

Display the command-line options and usage information.

-i <filename>, --input <filename>

Input file name. Default: input.dat

--inplace

Runs PSI4 with compiled code from <objdir> but driver code from source, so no need to make between Python edits. Expert mode.

-k, --skip-preprocessor

Skips input preprocessing. Expert mode.

-l <name>, --psidatadir <name>

Overrides the value of PSIDATADIR and specifies the path to the Psi data library (ends in share/psi4). Expert mode.

--loglevel <int>

Sets logging level: WARN=30, INFO=20, DEBUG=10.

-m, --messy

Leave temporary files after the run is completed.

--memory <memory>

The amount of memory to use. Can be specified with units (e.g., ‘10MB’) otherwise bytes is assumed.

--module

The location of the associated PSI4 Python module.

-n <threads>, --nthread <threads>

Number of threads to use (overrides OMP_NUM_THREADS). Also controls the testing parallelism with pytest.

-o <filename>, --output <filename>

Output file name. Use stdout as <filename> to redirect to the screen. Default: when the input filename is “input.dat”, then the output filename defaults to “output.dat”. Otherwise, the output filename defaults to the the input filename with “.out” extension.

--psiapi-path

Generates a bash command to source correct Python interpreter and path for python -c "import psi4"

--qcschema, --schema

Runs input files as QCSchema. Can either be JSON or MessagePack input.

-s <name>, --scratch <name>

This overrides the value of PSI_SCRATCH and provides a path to the location of scratch files

-t <subset>, --test <subset>

Runs pytest tests. If pytest-xdist installed, parallel with -n.

-v, --verbose

Print the Psithon to Python translation of the input file

-V, --version

Print version information.

# stable release
>>> psi4 --version
1.3.2

# development snapshot between 1.3 and 1.4
>>> psi4 --version
1.4a2.dev525

Environment Variables

These environment variables will influence PSI4‘s behavior.

CONDA_PREFIX

Set when a conda environment is activated. Note that if PSI4 has been built against any library in CONDA_PREFIX, the path has been baked into the program, so any available dependencies are liable to been loaded from the environment.

HOST

Set when a conda environment with conda compilers is activated. Used when compatibly building PSI4 from source against conda dependencies.

MKL_NUM_THREADS

Number of threads to use by operations with Intel threaded BLAS libraries.

OMP_NESTED

Do access nested DGEMM in OpenMP sections in DFMP2 for multi-socket platforms. This is very low-level access to OpenMP functions for experienced programmers. Users should leave this variable unset or set to False.

OMP_NUM_THREADS

Number of threads to use by modules with OpenMP threading.

PATH

Path for interfaced executables.

Note

While once configuring PSI4 through PSIPATH was preferred to modifying this environment variable, now PATH is preferred for executables to accommodate QCEngine.

To run Kállay’s MRCC program (see MRCC), the dmrcc executable must be in PATH. Likewise to run Grimme’s dftd3 program (see dftd3), the dftd3 executable must be in PATH.

PSI_SCRATCH

Directory where scratch files are written. Overrides settings in ~/.psi4rc. It is very important to ensure that PSI4 is writing its scratch files to a disk drive physically attached to the computer running the computation. If it is not, it will significantly slow down the program and the network.

Modify PSI_SCRATCH through normal Linux shell commands before invoking psi4

# csh, tcsh: add to shell or ~/.tcshrc file
setenv PSI_SCRATCH /scratch/user
# sh, bash: add to shell or ~/.bashrc (Linux/Windows) or ~/.bash_profile (Mac) file
export PSI_SCRATCH=/scratch/user
PSIPATH

Path in which PSI4 looks for user extensions to the built-in libraries. Specifically, directories containing user basis sets, EFP fragments, databases, plugins, and interfaced executables ( dmrcc for MRCC and dftd3 for DFTD3 ) should be placed in this colon-separated list.

PSI4 is designed so that user extensions that are findable through PSIPATH can be used in input files entirely like their built-in counterparts, without additional tagging as non-standard.

The typical search path is first the built-in libraries, next each PSIPATH directory in order, and finally the execution directory (I won’t swear everything tacks on the execution directory).

Path in which the Python interpreter looks for modules to import. For PSI4, these are generally plugins or databases.

Modify PSIPATH through normal Linux shell commands before invoking psi4

# csh, tcsh: add to shell or ~/.tcshrc file
setenv PSIPATH /home/user/psiadditions:/home/user/gbs
# sh, bash: add to shell or ~/.bashrc (Linux/Windows) or ~/.bash_profile (Mac) file
export PSIPATH=/home/user/psiadditions:/home/user/gbs
PYTHONPATH

Path in which the Python interpreter looks for modules to import. For PSI4, these are generally plugins or databases.

Note

While once configuring PSI4 through PSIPATH was preferred to modifying this environment variable, now PYTHONPATH is preferred for Python moduels to accommodate QCEngine.

Modification of PYTHONPATH can be done in three ways, equivalently.

  • Normal Linux shell commands.

    # csh, tcsh: add to shell or ~/.tcshrc file
    setenv PYTHONPATH /home/user/psiadditions:$PYTHONPATH
    
    # sh, bash: add to shell or ~/.bashrc (Linux/Windows) or ~/.bash_profile (Mac) file
    export PYTHONPATH=/home/user/psiadditions:$PYTHONPATH
    
  • Place the path in the ~/.psi4rc file so that it is available for every PSI4 instance.

    sys.path.insert(0, '/home/user/psiadditions')
    
  • Place the path in the input file, either absolute or relative.

    sys.path.insert(0, '../../psiadditions')
    sys.path.insert(0, '/home/user/psiadditions')
    
PSIDATADIR

Path in which the PSI4 executable looks for its non-compiled dependencies (i.e., basis sets, databases, quadratures, etc.). This path is always known by the PSI4 program or shared library, so this variable is relevant primarily to developers wanting a non-standard location. Value should be set to directory containing driver, basis, etc. directories, generally ending in share/psi4.