1# 2# CheMPS2: a spin-adapted implementation of DMRG for ab initio quantum chemistry 3# Copyright (C) 2013-2018 Sebastian Wouters 4# 5# This program is free software; you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation; either version 2 of the License, or 8# (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License along 16# with this program; if not, write to the Free Software Foundation, Inc., 17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18# 19 20import numpy as np 21import sys 22import PyCheMPS2 23import ctypes 24 25# Set the seed of the random number generator and cout.precision 26Initializer = PyCheMPS2.PyInitialize() 27Initializer.Init() 28 29# Read in the FCIDUMP 30psi4group = 7 # d2h: see chemps2/Irreps.h 31filename = b'../../tests/matrixelements/N2.CCPVDZ.FCIDUMP' 32orbirreps = np.array([-1, -1], dtype=ctypes.c_int) # CheMPS2 reads it in from FCIDUMP 33Ham = PyCheMPS2.PyHamiltonian( -1, psi4group, orbirreps, filename ) 34 35# Define the symmetry sector 36TwoS = 0 # Two times the targeted spin 37N = 14 # The number of electrons 38Irrep = 0 # The targeted irrep 39 40# Define the CASSCF 41DOCC = np.array([ 3, 0, 0, 0, 0, 2, 1, 1 ], dtype=ctypes.c_int) # see N2.ccpvdz.out 42SOCC = np.array([ 0, 0, 0, 0, 0, 0, 0, 0 ], dtype=ctypes.c_int) 43NOCC = np.array([ 1, 0, 0, 0, 0, 1, 0, 0 ], dtype=ctypes.c_int) 44NDMRG = np.array([ 4, 0, 1, 1, 0, 4, 1, 1 ], dtype=ctypes.c_int) 45NVIRT = np.array([ 2, 1, 2, 2, 1, 2, 2, 2 ], dtype=ctypes.c_int) 46theDMRGSCF = PyCheMPS2.PyCASSCF(Ham, DOCC, SOCC, NOCC, NDMRG, NVIRT) 47 48# Setting up the ConvergenceScheme 49OptScheme = PyCheMPS2.PyConvergenceScheme( 2 ) # 2 instructions 50OptScheme.set_instruction( 0, 500, 1e-10, 3, 0.1, 1e-5 ) 51OptScheme.set_instruction( 1, 1000, 1e-10, 10, 0.0, 1e-10 ) 52 53# Setting the DMRGSCFoptions and run DMRGSCF 54root_num = 1 # Ground state only 55theDMRGSCFoptions = PyCheMPS2.PyDMRGSCFoptions() 56theDMRGSCFoptions.setDoDIIS( True ) 57theDMRGSCFoptions.setWhichActiveSpace( 2 ) # Localized orbitals 58IPEA = 0.0 59IMAG = 0.0 60PSEUDOCANONICAL = False 61Energy1 = theDMRGSCF.solve( N, TwoS, Irrep, OptScheme, root_num, theDMRGSCFoptions) 62Energy2 = theDMRGSCF.caspt2(N, TwoS, Irrep, OptScheme, root_num, theDMRGSCFoptions, IPEA, IMAG, PSEUDOCANONICAL) 63 64# Clean-up 65if theDMRGSCFoptions.getStoreUnitary(): 66 theDMRGSCF.deleteStoredUnitary() 67if theDMRGSCFoptions.getStoreDIIS(): 68 theDMRGSCF.deleteStoredDIIS() 69 70# The order of deallocation matters! 71del theDMRGSCFoptions 72del OptScheme 73del theDMRGSCF 74del Ham 75del Initializer 76 77# Check whether the test succeeded 78if (( np.fabs( Energy1 + 109.15104350802 ) < 1e-8 ) and ( np.fabs( Energy2 + 0.116979484098865 ) < 1e-8 )): 79 print("================> Did test 14 succeed : yes") 80else: 81 print("================> Did test 14 succeed : no") 82 83