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 37Nelec = 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([ 2, 0, 1, 1, 0, 2, 1, 1 ], dtype=ctypes.c_int) 45NVIRT = np.array([ 4, 1, 2, 2, 1, 4, 2, 2 ], dtype=ctypes.c_int) 46theDMRGSCF = PyCheMPS2.PyCASSCF(Ham, DOCC, SOCC, NOCC, NDMRG, NVIRT) 47 48# Setting the DMRGSCFoptions and run DMRGSCF 49root_num = 1 # Ground state only 50scf_options = PyCheMPS2.PyDMRGSCFoptions() 51scf_options.setDoDIIS( True ) 52IPEA = 0.0 53IMAG = 0.0 54PSEUDOCANONICAL = False 55Energy1 = theDMRGSCF.solve_fci( Nelec, TwoS, Irrep, root_num, scf_options) 56Energy2 = theDMRGSCF.caspt2_fci(Nelec, TwoS, Irrep, root_num, scf_options, IPEA, IMAG, PSEUDOCANONICAL) 57 58# Clean-up 59if scf_options.getStoreUnitary(): 60 theDMRGSCF.deleteStoredUnitary() 61if scf_options.getStoreDIIS(): 62 theDMRGSCF.deleteStoredDIIS() 63 64# The order of deallocation matters! 65del scf_options 66del theDMRGSCF 67del Ham 68del Initializer 69 70# Check whether the test succeeded 71if (( np.fabs( Energy1 + 109.103502335253 ) < 1e-8 ) and ( np.fabs( Energy2 + 0.159997813112638 ) < 1e-8 )): 72 print("================> Did test 13 succeed : yes") 73else: 74 print("================> Did test 13 succeed : no") 75 76