Running MultiPsi, input/code structure

Running MultiPsi, input/code structure

There are two main ways to run MultiPsi. The first one is using a traditional way using an input file, and the second one is as a python script. For advanced users familiar with python programming, running a python script is the most flexible and powerful option while the input format is more adapted for new users as it is simple and has more failsafes.

Running with an input file

To run multipsi, you can simply run in a terminal

multipsi file.inp

which will print the output to the screen, or redirect the input

multipsi file.inp file.out

You can find example inputs in the examples directory. The general input structure is composed of blocks delimited by @. There is one block for each module (e.g. mcscf, ci, response, etc…) as well as a couple of blocks to define the molecule, active space and method (resp. @molecule, @orbitals and @method settings). The order of the blocks is irrelevant. Within each block are a number of options written as keyword:value, and the value can be multiple lines.

The lines before the first block in the input are called “keylines” and can be used to provide a short-hand input which can be enough for most basic calculations. Thus, a complete input to run a CASSCF with an active space containing 12 electrons in 9 orbitals (full valence) with the def2-svp basis set, followed by a linear response calculation (time-dependent or TD) of the first 5 excited states is simply:

casscf(12,9) def2-svp td:5 # This is the keyline

@molecule
xyz:
O 0.0000   0.0000   0.0000
O 0.0000   1.0885   0.6697
O 0.0000  -1.0885   0.6697
@end

which is fully identical to the long-form input:

@molecule
xyz:
O 0.0000   0.0000   0.0000
O 0.0000   1.0885   0.6697
O 0.0000  -1.0885   0.6697
@end

@orbitals
cas: 12, 9
@end

@method settings
basis: def2-svp
wavefunction: mcscf
@end

@response
n_states:5
@end

Running with a python script

MultiPsi is a python module and can thus be run natively as a python script. For this, you first need to import multipsi and veloxchem:

import veloxchem as vlx
import multipsi as mtp
* Warning * Environment variable OMP_NUM_THREADS not set.
* Warning * Setting OMP_NUM_THREADS to 8.

Then the input above can be run by the following script:

# Define molecule and basis
mol_str = """
O 0.0000   0.0000   0.0000
O 0.0000   1.0885   0.6697
O 0.0000  -1.0885   0.6697
"""

molecule = vlx.Molecule.read_str(mol_str)
molecule.set_charge(0) # default
molecule.set_multiplicity(1) # default

basis = vlx.MolecularBasis.read(molecule,"def2-svp")

# Generate guess
orbguess = mtp.OrbitalGuess()
guessorb = orbguess.compute(molecule, basis)

# Define the active space (full valence = 9 2p orbitals, 12 electrons)
orb_space = mtp.OrbSpace(molecule, guessorb)
orb_space.cas(12, 9)

# MCSCF energy
mcscf_drv = mtp.McscfDriver()
mcscf_dict = mcscf_drv.compute(molecule, basis, orb_space)

# Linear response calculation
mcrpa = mtp.Mclr_EigenSolver()
response_dict = mcrpa.compute(molecule, basis, mcscf_drv, n_states = 5) 
* Info * Reading basis set from file: /opt/anaconda3/envs/vlxenv/lib/python3.9/site-packages/veloxchem/basis/DEF2-SVP     
                                                                                                                          
                                              Molecular Basis (Atomic Basis)                                              
                                             ================================                                             
                                                                                                                          
                               Basis: DEF2-SVP                                                                            
                                                                                                                          
                               Atom Contracted GTOs           Primitive GTOs                                              
                                                                                                                          
                                O   (3S,2P,1D)                (7S,4P,1D)                                                  
                                                                                                                          
                               Contracted Basis Functions : 42                                                            
                               Primitive Basis Functions  : 72                                                            
                                                                                                                          
                                                                                                                          
                          Multi-Configurational Self-Consistent Field Driver
                         ====================================================
                                                                                                                          
        ╭────────────────────────────────────╮
        │          Driver settings           │
        ╰────────────────────────────────────╯
          State-specific calculation
          Max. iterations         : 50
          BFGS window             : 5
          Convergence thresholds:
            - Energy change       : 1e-08
            - Gradient norm       : 0.0001
                                                                                                                          
          Integrals in memory
                                                                                                                          
          Active space definition:
          ------------------------
Number of inactive (occupied) orbitals: 6
Number of active orbitals:              9
Number of virtual orbitals:             27

    This is a CASSCF wavefunction: CAS(12,9)

          CI expansion:
          -------------
Number of determinants:      3570


                                                                                                                          
        MCSCF Iterations
        ----------------
                                                                                                                          
     Iter. | Average Energy | E. Change | Grad. Norm | CI Iter. |   Time
     ---------------------------------------------------------------------
        1     -223.995388550     0.0e+00      1.8e+00         13   0:00:00
        2     -224.231147630    -2.4e-01      5.8e-01         16   0:00:00
        3     -224.281894118    -5.1e-02      1.7e-01          3   0:00:00
        4     -224.288033601    -6.1e-03      6.0e-02          3   0:00:00
        5     -224.288702989    -6.7e-04      2.1e-02          3   0:00:00
        6     -224.288830366    -1.3e-04      9.4e-03          4   0:00:00
        7     -224.288852249    -2.2e-05      4.5e-03          3   0:00:00
        8     -224.288856603    -4.4e-06      1.4e-03          4   0:00:00
        9     -224.288856955    -3.5e-07      4.4e-04          3   0:00:00
       10     -224.288857011    -5.6e-08      1.7e-04          4   0:00:00
       11     -224.288857023    -1.2e-08      9.7e-05          3   0:00:00
       12     -224.288857026    -3.7e-09      4.7e-05          3   0:00:00
                                                                                                                          
** Convergence reached in 12 iterations
                                                                                                                          
        Final results
        -------------
                                                                                                                          
                                                                                                                          
* State 1
- Energy: -224.2888570264581
- S^2   : 0.00  (multiplicity = 1.0 )
- Natural orbitals
1.99224 1.99029 1.96397 1.95643 1.94794 1.76949 0.26737 0.06074 0.05154
                                                                                                                          
                                                 Spin Restricted Orbitals                                                 
                                                 ------------------------                                                 
                                                                                                                          
               Molecular Orbital No.   8:                                                                                 
               --------------------------                                                                                 
               Occupation: 1.990 Energy:   -0.74351 a.u.                                                                  
               (   1 O   2s  :    -0.32) (   1 O   3s  :    -0.33) (   2 O   3s  :     0.16)                              
               (   2 O   1p-1:     0.23) (   2 O   1p0 :    -0.33) (   2 O   2p0 :    -0.26)                              
               (   3 O   3s  :     0.16) (   3 O   1p-1:    -0.23) (   3 O   1p0 :    -0.33)                              
               (   3 O   2p0 :    -0.26)                                                                                  
                                                                                                                          
               Molecular Orbital No.   9:                                                                                 
               --------------------------                                                                                 
               Occupation: 1.964 Energy:   -0.76348 a.u.                                                                  
               (   1 O   1p+1:    -0.55) (   1 O   2p+1:    -0.34) (   2 O   1p+1:    -0.23)                              
               (   3 O   1p+1:    -0.23)                                                                                  
                                                                                                                          
               Molecular Orbital No.  10:                                                                                 
               --------------------------                                                                                 
               Occupation: 1.956 Energy:   -0.84370 a.u.                                                                  
               (   1 O   1p0 :    -0.54) (   1 O   2p0 :    -0.33) (   2 O   1p-1:     0.19)                              
               (   2 O   1p0 :     0.25) (   2 O   2p0 :     0.17) (   3 O   1p-1:    -0.19)                              
               (   3 O   1p0 :     0.25) (   3 O   2p0 :     0.17)                                                        
                                                                                                                          
               Molecular Orbital No.  11:                                                                                 
               --------------------------                                                                                 
               Occupation: 1.948 Energy:   -0.83931 a.u.                                                                  
               (   1 O   1p-1:     0.48) (   1 O   2p-1:     0.20) (   2 O   1p-1:    -0.35)                              
               (   2 O   2p-1:    -0.20) (   3 O   1p-1:    -0.35) (   3 O   2p-1:    -0.20)                              
                                                                                                                          
               Molecular Orbital No.  12:                                                                                 
               --------------------------                                                                                 
               Occupation: 1.769 Energy:   -0.43543 a.u.                                                                  
               (   2 O   1p+1:    -0.48) (   2 O   2p+1:    -0.35) (   3 O   1p+1:     0.48)                              
               (   3 O   2p+1:     0.35)                                                                                  
                                                                                                                          
               Molecular Orbital No.  13:                                                                                 
               --------------------------                                                                                 
               Occupation: 0.267 Energy:   -0.05109 a.u.                                                                  
               (   1 O   1p+1:     0.46) (   1 O   2p+1:     0.28) (   2 O   1p+1:    -0.50)                              
               (   2 O   2p+1:    -0.24) (   3 O   1p+1:    -0.50) (   3 O   2p+1:    -0.24)                              
                                                                                                                          
               Molecular Orbital No.  14:                                                                                 
               --------------------------                                                                                 
               Occupation: 0.061 Energy:    0.41592 a.u.                                                                  
               (   1 O   1s  :    -0.16) (   1 O   2s  :    -0.48) (   1 O   3s  :    -0.30)                              
               (   1 O   1p0 :    -0.57) (   2 O   2s  :     0.17) (   2 O   1p-1:    -0.51)                              
               (   2 O   1p0 :    -0.15) (   2 O   2p-1:    -0.18) (   3 O   2s  :     0.17)                              
               (   3 O   1p-1:     0.51) (   3 O   1p0 :    -0.15) (   3 O   2p-1:     0.18)                              
                                                                                                                          
               Molecular Orbital No.  15:                                                                                 
               --------------------------                                                                                 
               Occupation: 0.052 Energy:    0.51207 a.u.                                                                  
               (   1 O   1p-1:     0.76) (   1 O   2p-1:     0.34) (   2 O   2s  :    -0.19)                              
               (   2 O   3s  :    -0.22) (   2 O   1p-1:     0.34) (   2 O   1p0 :     0.36)                              
               (   2 O   2p-1:     0.21) (   3 O   2s  :     0.19) (   3 O   3s  :     0.22)                              
               (   3 O   1p-1:     0.34) (   3 O   1p0 :    -0.36) (   3 O   2p-1:     0.21)                              
                                                                                                                          
               Molecular Orbital No.  16:                                                                                 
               --------------------------                                                                                 
               Occupation: 0.000 Energy:    0.90478 a.u.                                                                  
               (   1 O   1s  :    -0.16) (   1 O   2s  :    -0.73) (   1 O   3s  :    -0.65)                              
               (   1 O   1p0 :     0.29) (   1 O   2p0 :    -0.95) (   2 O   2s  :    -0.78)                              
               (   2 O   3s  :     1.26) (   2 O   1p-1:     0.16) (   2 O   2p-1:    -0.69)                              
               (   3 O   2s  :    -0.78) (   3 O   3s  :     1.26) (   3 O   1p-1:    -0.16)                              
               (   3 O   2p-1:     0.69)                                                                                  
                                                                                                                          
               Molecular Orbital No.  17:                                                                                 
               --------------------------                                                                                 
               Occupation: 0.000 Energy:    1.02202 a.u.                                                                  
               (   1 O   1p-1:    -0.31) (   1 O   2p-1:     1.30) (   2 O   1s  :    -0.15)                              
               (   2 O   2s  :    -0.72) (   2 O   1p-1:    -0.34) (   2 O   2p-1:     0.73)                              
               (   2 O   2p0 :     0.46) (   3 O   1s  :     0.15) (   3 O   2s  :     0.72)                              
               (   3 O   1p-1:    -0.34) (   3 O   2p-1:     0.73) (   3 O   2p0 :    -0.46)                              
                                                                                                                          
                                                                                                                          
Total MCSCF time: 00:00:03
                                                                                                                          
                          Multi-Configurational Linear response Eigenvalue Solver
                         =========================================================
                                                                                                                          
        ╭────────────────────────────────────╮
        │          Driver settings           │
        ╰────────────────────────────────────╯
          Number of states        : 5
                                                                                                                          
          Max. iterations         : 50
          Residual norm threshold : 1e-08
                                                                                                                          
          Integrals in memory
          Trial vector settings:
            - Linear dependence threshold :1e-10
            - Min. trial vectors          :20
            - Max. trial vectors          :60
                                                                                                                          
Warning, significant negative value in orbital S(2): -0.6561165480740117
          CI parameters:      3569
          Orbital parameters: 459
                                                                                                                          
                                                                                                                          
Initialization time: 00:00:00
                                                                                                                          
                                                                                                                          
        MC-RPA Iterations
        -----------------
                                                                                                                          
     Iter. | Average Energy | Grad. Norm | Converged | CI+Orb vec. | Time
     -----------------------------------------------------------------------
        1       0.328458495      1.7e-01      0/  5     6 +   5      0:00:00    
        2       0.234614052      7.6e-02      0/  5    16 +   5      0:00:00    
        3       0.206906263      5.8e-02      0/  5    18 +  13      0:00:00    
        4       0.189257584      1.8e-02      0/  5    26 +  15      0:00:00    
        5       0.183552768      7.6e-03      0/  5    34 +  17      0:00:00    
        6       0.180802865      2.8e-03      0/  5    36 +  25      0:00:00    
        7       0.179743338      1.3e-03      0/  5    44 +  27      0:00:00    
        8       0.178909151      8.6e-04      0/  5    48 +  33      0:00:00    
        9       0.178505704      4.5e-04      0/  5    54 +  37      0:00:00    
       10       0.178323790      3.0e-04      0/  5    58 +  43      0:00:00    
       11       0.178067739      7.3e-04      0/  5    26 +  47      0:00:00    CI subspace collapsed 
       12       0.177921396      5.1e-04      0/  5    26 +  57      0:00:00    
       13       0.177781405      3.2e-04      0/  5    34 +  59      0:00:00    
       14       0.177728047      2.1e-04      0/  5    40 +  63      0:00:00    
       15       0.177701061      9.7e-05      0/  5    46 +  24      0:00:00    Orb subspace collapsed 
       16       0.177686261      4.2e-05      0/  5    50 +  30      0:00:00    
       17       0.177679596      2.9e-05      0/  5    56 +  34      0:00:00    
       18       0.177673223      1.4e-05      0/  5    60 +  40      0:00:00    
       19       0.177670314      1.2e-05      0/  5    24 +  46      0:00:00    CI subspace collapsed 
       20       0.177668557      8.0e-06      0/  5    30 +  50      0:00:00    
       21       0.177664834      1.2e-05      0/  5    36 +  54      0:00:00    
       22       0.177659609      1.4e-05      1/  5    40 +  60      0:00:00    
       23       0.177656267      1.3e-05      1/  5    46 +  62      0:00:00    
       24       0.177653478      1.1e-05      1/  5    50 +  24      0:00:00    Orb subspace collapsed 
       25       0.177651358      8.2e-06      1/  5    54 +  28      0:00:00    
       26       0.177650350      5.3e-06      1/  5    58 +  32      0:00:00    
       27       0.177649716      3.3e-06      2/  5    58 +  40      0:00:00    
       28       0.177649454      1.8e-06      3/  5    26 +  40      0:00:00    CI subspace collapsed 
       29       0.177648973      1.2e-06      3/  5    26 +  44      0:00:00    
       30       0.177648716      1.2e-06      3/  5    28 +  46      0:00:00    
       31       0.177648557      9.2e-07      3/  5    32 +  46      0:00:00    
       32       0.177648399      3.9e-07      4/  5    32 +  50      0:00:00    
       33       0.177648345      2.1e-07      4/  5    34 +  50      0:00:00    
       34       0.177648327      9.2e-08      4/  5    34 +  52      0:00:00    
       35       0.177648312      3.1e-08      4/  5    36 +  52      0:00:00    
       36       0.177648309      1.7e-08      4/  5    38 +  52      0:00:00    
       37       0.177648307      1.0e-08      5/  5    38 +  54      0:00:00    
                                                                                                                          
** Convergence reached in 37 iterations
                                                                                                                          
                                                                                                                          
                                                                                                                          
                                                 Oscillator strength (au)
 Transition   Energy (Ha)    Energy (eV)    Velocity gauge     Length gauge 
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
          1     0.0781501      2.12657          0.0003717        0.0000075
          2     0.0788577      2.14583          0.0000000        0.0000000
          3     0.2014017      5.48042          0.0741102        0.0930006
          4     0.2501220      6.80617          0.0003565        0.0005101
          5     0.2797100      7.61130          0.0138095        0.0174743
                                                                                                                          
                                                                                                                          
                                                 Rotatory strength (cgs)
 Transition   Energy (Ha)    Energy (eV)    Velocity gauge     Length gauge 
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
          1     0.0781501      2.12657          0.0004564        0.0004787
          2     0.0788577      2.14583         -0.0000727        0.0001244
          3     0.2014017      5.48042         -0.0001355       -0.0001536
          4     0.2501220      6.80617          0.0000730        0.0000873
          5     0.2797100      7.61130         -0.0007738       -0.0008704
                                                                                                                          
Total MC-RPA time: 00:00:18

The script version also provides useful tools to visualize the results, check the orbitals, etc…

You can also use the built-in help functions of python to know the available functions and keywords of modules:

help(mtp.McscfDriver)
Help on class McscfDriver in module multipsi.McscfDriver:

class McscfDriver(builtins.object)
 |  McscfDriver(comm=<mpi4py.MPI.Intracomm object at 0x10ff882f0>, ostream=None)
 |  
 |  Converge a general MCSCF wavefunction
 |  
 |  :param comm:
 |      The MPI communicator (default world).
 |  :param ostream:
 |      The output stream (default stdout).
 |  
 |  Methods defined here:
 |  
 |  __init__(self, comm=<mpi4py.MPI.Intracomm object at 0x10ff882f0>, ostream=None)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  compute(self, molecule, basis, orbital_space, n_states=1, weights='averaged')
 |      Performs a MCSCF calculation
 |      
 |      :param molecule:
 |          The molecule.
 |      :param basis:
 |          The AO basis set.
 |      :param orbital_space:
 |          The Orbital Spaces.
 |      :param n_states:
 |          The number of states (default 1)
 |      :param weights:
 |          The weights of the states in the state-averaged calculation (default equal weights)
 |      
 |      :return:
 |          A dictionary with the main results.
 |  
 |  compute_pdft(self, molecule, basis, functional, istate=0)
 |      Computes the "perturbative" pair-density functional theory energy.
 |      
 |      :param molecule:
 |          The molecule.
 |      :param basis:
 |          The AO basis set.
 |      :param functional:
 |          The PDFT functional.
 |      :param istate:
 |          The effective state-averaged fock matrix in AO basis.
 |      
 |      :return:
 |          The PDFT energy.
 |  
 |  get_energies(self)
 |      Return the list of state energies.
 |      
 |      :return:
 |          A list of energies.
 |  
 |  get_energy(self, istate='SA')
 |      Return the energy of a specific state.
 |      
 |      :param istate:
 |          The index of the state of interest (default "SA" = state-averaged energy)
 |      
 |      :return:
 |          The state energy.
 |  
 |  get_natural_occupations(self, istate=0)
 |      Return the natural occupation numbers for a specific state.
 |      
 |      :param istate:
 |          The index of the state of interest (default: the first state).
 |      
 |      :return:
 |          The numpy array of occupation numbers.
 |  
 |  get_non_separable_2body_density(self, istate=0)
 |      Return the non-separable part of the active
 |      2-body density matrix of a state in MO.
 |      
 |      :param istate:
 |          The index of the state of interest (default: the first state).
 |      
 |      :return:
 |          non-separable part of the 2-body density matrix in MO.
 |  
 |  get_total_density(self, istate=0)
 |      Return the total AO density matrix of a state.
 |      
 |      :param istate:
 |          The index of the state of interest (default: the first state).
 |      :return:
 |          1-body density matrix in AO.
 |  
 |  print_settings(self, orbital_space, n_states, weights)
 |      Print solver settings.
 |      
 |      :param orbital_space:
 |          The Orbital Spaces.
 |      :param n_states:
 |          The number of states.
 |      :param weights:
 |          The weight of each state.
 |  
 |  quick_start(self, molecule, basis, basis2, orbital_space, n_states=1, weights='averaged')
 |      Performs a MCSCF calculation
 |      
 |      :param molecule:
 |          The molecule.
 |      :param basis:
 |          The small AO basis set for which the space was defined
 |      :param basis2:
 |          The large AO basis set to extrapolate to.
 |      :param orbspace:
 |          The Orbital Spaces.
 |      :param n_states:
 |          The number of states (default 1)
 |      :param weights:
 |          The weights of the states in the state-averaged calculation (default equal weights)
 |      
 |      :return:
 |          A dictionary with the main results.
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)