Skip to content

Commit

Permalink
Clean up untracked files finally
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewRHermes committed Jan 18, 2024
1 parent 2c270c9 commit 1f4cda6
Show file tree
Hide file tree
Showing 16 changed files with 990 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,20 @@ Makefile
*.molden
*.npy
*.log
*.log.*
*.dat
*.out
*.err
*.swp
*.chk

# assorted garbage
test_all.sh
*.status
*.rasscf.h5
*.inp
*.timing
*.ods
*.tab
*.txt

16 changes: 16 additions & 0 deletions debug/fci/1414.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import numpy as np
from pyscf import lib, gto, ao2mo
from mrh.my_pyscf.fci import csf_solver
mol = gto.M (atom='Si 0 0 0', spin=14, charge=0, output='1414.log', verbose=lib.logger.DEBUG1)
fci = csf_solver (mol, smult=1)
norb = 14
nelec = (7,7)
h1 = np.random.rand (14,14)
h1 += h1.T
h2 = np.random.rand (14,14,14,14)
h2 = ao2mo.restore (8, h2, norb)
h2 = ao2mo.restore (1, h2, norb)
e, ci = fci.kernel (h1, h2, norb, nelec)
print (e)


17 changes: 17 additions & 0 deletions debug/fci/lih_casscf25_sto3g.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from pyscf import gto, scf, mcscf, lib

mol = gto.M (atom='Li 0 0 0\nH 1.5 0 0', basis='sto-3g', symmetry=True,
output=__file__+'.log', verbose=lib.logger.INFO)
mf = scf.RHF (mol).run ()
print (getattr (mf.mo_coeff, 'degen_mapping', None))
mc0 = mcscf.CASSCF (mf, 5, 2)
mc0.kernel ()

print (getattr (mc0.mo_coeff, 'degen_mapping', None))
print (getattr (mc0.fcisolver.orbsym, 'degen_mapping', None))
mc1 = mcscf.CASCI (mf, 5, 2)
mc1.kernel (mc0.mo_coeff, ci0=mc0.ci)




25 changes: 25 additions & 0 deletions debug/lasscf/async_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pyscf
#from geometry_generator import generator
from pyscf import gto, scf, tools, mcscf,lib
from mrh.my_pyscf.mcscf.lasscf_async import LASSCF
#from mrh.my_pyscf.mcscf.lasscf_sync_o0 import LASSCF
from pyscf.mcscf import avas
lib.logger.TIMER_LEVEL = lib.logger.INFO

nfrags=2
basis='sto-3g'
outputfile='async_1_6-31g_out.log'
#xyz=generator(nfrags)
xyz='butadiene.xyz'
mol=gto.M(atom=xyz,basis=basis,verbose=4,output=outputfile)
mf=scf.RHF(mol)
mf=mf.density_fit()
mf.run()
ncas,nelecas,guess_mo_coeff = avas.kernel(mf, ['C 2p'])
las=LASSCF(mf, list((2,)*nfrags),list((2,)*nfrags))
frag_atom_list=[list(range(1+4*nfrag,3+4*nfrag)) for nfrag in range(nfrags)]
mo_coeff=las.set_fragments_(frag_atom_list, guess_mo_coeff)
las.kernel(mo_coeff)
#mf.mo_coeff=las.mo_coeff
#mf.analyze()

12 changes: 12 additions & 0 deletions debug/lasscf/butadiene.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
10

H -0.943967690125 0.545000000000 0.000000000000
C 0.000000000000 0.000000000000 0.000000000000
C 1.169134295109 0.675000000000 0.000000000000
H 0.000000000000 -1.090000000000 0.000000000000
H 1.169134295109 1.765000000000 0.000000000000
C 2.459512146748 -0.070000000000 0.000000000000
C 3.628646441857 0.605000000000 0.000000000000
H 2.459512146748 -1.160000000000 0.000000000000
H 3.628646441857 1.695000000000 0.000000000000
H 4.572614131982 0.060000000000 0.000000000000
12 changes: 12 additions & 0 deletions debug/lasscf/c2h6n4.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
H -0.145525 2.534624 1.196098
N 0.586282 2.685058 0.454251
N 0.586282 1.768962 -0.376701
C -0.376894 0.666619 -0.222182
H -0.986448 0.788749 0.689250
H -1.039496 0.688384 -1.095107
C 0.376894 -0.666619 -0.222182
H 0.986448 -0.788749 0.689250
H 1.039496 -0.688384 -1.095107
N -0.586282 -1.768962 -0.376701
N -0.586282 -2.685058 0.454251
H 0.145525 -2.534624 1.196098
28 changes: 28 additions & 0 deletions debug/lasscf/c2h6n4_struct.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import numpy as np
from pyscf import gto

def structure (dnn1=0, dnn2=0, basis='6-31g', symmetry=False):
with open ('c2h6n4.xyz', 'r') as f:
equilgeom = f.read ()
mol = gto.M (atom = equilgeom, basis = basis, symmetry=True, unit='au')
atoms = tuple(mol.atom_symbol (i) for i in range (mol.natm))
coords = mol.atom_coords ()

idx_nn = np.asarray ([[0, 1], [10, 11]])
nn_vec = coords[[1,10],:] - coords[[2,9],:]
nn_equil = np.mean (np.linalg.norm (nn_vec, axis=1))
nn_vec /= np.linalg.norm (nn_vec, axis=1)[:,np.newaxis]
delta_coords = np.zeros_like (coords)
delta_coords[idx_nn[0],:] = np.broadcast_to (nn_vec[0,:], (2,3))
delta_coords[idx_nn[1],:] = np.broadcast_to (nn_vec[1,:], (2,3))
scale = np.zeros (12, dtype=coords.dtype)
scale[idx_nn[0]] = dnn1
scale[idx_nn[1]] = dnn2
newcoords = coords + scale[:,np.newaxis] * delta_coords
carts = [[atoms[i]] + list(newcoords[i,:]) for i in range(12)]
dummymol = gto.M (atom = carts, basis=basis, symmetry=True)
newcoords = dummymol.atom_coords ()
carts = [[atoms[i]] + list(newcoords[i,:]) for i in range(12)]
return gto.M (atom = carts, basis=basis, symmetry=symmetry, unit='au')


186 changes: 186 additions & 0 deletions debug/lassi/debug_c2h4n4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
#!/usr/bin/env python
# Copyright 2014-2020 The PySCF Developers. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import copy
import unittest
import numpy as np
from scipy import linalg
from pyscf import lib, gto, scf, dft, fci, mcscf, df
from pyscf.tools import molden
from mrh.tests.lasscf.c2h4n4_struct import structure as struct
from mrh.my_pyscf.mcscf.lasscf_o0 import LASSCF
from mrh.my_pyscf.lassi.lassi import roots_make_rdm12s, root_make_rdm12s, make_stdm12s, ham_2q
from mrh.my_pyscf.lassi import LASSI
topdir = os.path.abspath (os.path.join (__file__, '../../../tests/lassi/'))

def setUpModule ():
global las, lsi, rdm1s, rdm2s
dr_nn = 2.0
mol = struct (dr_nn, dr_nn, '6-31g', symmetry=False)
mol.verbose = 0 #lib.logger.DEBUG
mol.output = '/dev/null' #'test_c2h4n4.log'
mol.spin = 0
mol.build ()
mf = scf.RHF (mol).run ()
las = LASSCF (mf, (4,4), (4,4), spin_sub=(1,1))
las.state_average_(weights=[1.0/5.0,]*5,
spins=[[0,0],[0,0],[2,-2],[-2,2],[2,2]],
smults=[[1,1],[3,3],[3,3],[3,3],[3,3]])
las.frozen = list (range (las.mo_coeff.shape[-1]))
ugg = las.get_ugg ()
las.mo_coeff = np.loadtxt (os.path.join (topdir, 'test_c2h4n4_mo.dat'))
las.ci = ugg.unpack (np.loadtxt (os.path.join (topdir, 'test_c2h4n4_ci.dat')))[1]
lroots = 2 * np.ones ((2,7), dtype=int)
lroots[:,1] = 1 # <- that rootspace is responsible for spin contamination
las.conv_tol_grad = 1e-8
las.lasci (lroots=lroots)
# TODO: potentially save and load CI vectors
# requires extending features of ugg
#las.set (conv_tol_grad=1e-8).run ()
#np.savetxt ('test_c2h4n4_mo.dat', las.mo_coeff)
#np.savetxt ('test_c2h4n4_ci.dat', ugg.pack (las.mo_coeff, las.ci))
#las.e_states = las.energy_nuc () + las.states_energy_elec ()
lsi = LASSI (las).run ()
rdm1s, rdm2s = roots_make_rdm12s (las, las.ci, lsi.si)
las = LASSCF (mf, (4,2,4), ((4,0),(1,1),(0,4)), spin_sub=(5,3,5))
ci_quin = np.array ([[1.0,],])
ci_sing = np.diag ([1,-1])[::-1] / np.sqrt (2)
las.ci = [[ci_quin], [ci_sing], [ci_quin.copy ()]]
las.e_states = las.energy_nuc () + las.states_energy_elec ()

def tearDownModule():
global las, lsi, rdm1s, rdm2s
mol = lsi._las.mol
mol.stdout.close ()
del las, lsi, rdm1s, rdm2s

class KnownValues(unittest.TestCase):
#def test_evals (self):
# self.assertAlmostEqual (lib.fp (lsi.e_roots), 71.48678303162376, 6)

#def test_si (self):
# # Arbitrary signage in both the SI and CI vector, sadly
# # Actually this test seems really inconsistent overall...
# dens = lsi.si.conj () * lsi.si
# self.assertAlmostEqual (lib.fp (np.diag (dens)), 1.2321935065030327, 4)

#def test_nelec (self):
# for ix, ne in enumerate (lsi.nelec):
# with self.subTest(ix):
# if ix in (1,5,8,11):
# self.assertEqual (ne, (6,2))
# else:
# self.assertEqual (ne, (4,4))

#def test_s2 (self):
# s2_array = np.zeros (16)
# quintets = [1,2,5,8,11]
# for ix in quintets: s2_array[ix] = 6
# triplets = [3,6,7,9,10,12,13]
# for ix in triplets: s2_array[ix] = 2
# self.assertAlmostEqual (lib.fp (lsi.s2), lib.fp (s2_array), 3)

#def test_tdms (self):
# las, si = lsi._las, lsi.si
# stdm1s, stdm2s = make_stdm12s (las)
# nelec = float (sum (las.nelecas))
# for ix in range (stdm1s.shape[0]):
# d1 = stdm1s[ix,...,ix].sum (0)
# d2 = stdm2s[ix,...,ix].sum ((0,3))
# with self.subTest (root=ix):
# self.assertAlmostEqual (np.trace (d1), nelec, 9)
# self.assertAlmostEqual (np.einsum ('ppqq->',d2), nelec*(nelec-1), 9)
# rdm1s_test = np.einsum ('ar,asijb,br->rsij', si.conj (), stdm1s, si)
# rdm2s_test = np.einsum ('ar,asijtklb,br->rsijtkl', si.conj (), stdm2s, si)
# self.assertAlmostEqual (lib.fp (rdm1s_test), lib.fp (rdm1s), 9)
# self.assertAlmostEqual (lib.fp (rdm2s_test), lib.fp (rdm2s), 9)

#def test_rdms (self):
# las, e_roots = lsi._las, lsi.e_roots
# h0, h1, h2 = ham_2q (las, las.mo_coeff)
# d1_r = rdm1s.sum (1)
# d2_r = rdm2s.sum ((1, 4))
# nelec = float (sum (las.nelecas))
# for ix, (d1, d2) in enumerate (zip (d1_r, d2_r)):
# with self.subTest (root=ix):
# self.assertAlmostEqual (np.trace (d1), nelec, 9)
# self.assertAlmostEqual (np.einsum ('ppqq->',d2), nelec*(nelec-1), 9)
# e_roots_test = h0 + np.tensordot (d1_r, h1, axes=2) + np.tensordot (d2_r, h2, axes=4) / 2
# for e1, e0 in zip (e_roots_test, e_roots):
# self.assertAlmostEqual (e1, e0, 8)

#def test_singles_constructor (self):
# from mrh.my_pyscf.lassi.states import all_single_excitations
# las2 = all_single_excitations (lsi._las)
# las2.check_sanity ()
# # Meaning of tuple: (na+nb,smult)
# # from state 0, (1+2,2)&(3+2,2) & a<->b & l<->r : 4 states
# # from state 1, smults=((2,4),(4,2),(4,4)) permutations of above: 12 additional states
# # from states 2 and 3, (4+1,4)&(0+3,4) & a<->b & l<->r : 4 additional states
# # from state 4, (2+1,2)&(4+1,4) & (2+1,4)&(4+1,4)
# # & (3+0,4)&(3+2,2) & (3+0,4)&(3+2,4) & l<->r : 8 additional states
# # 5 + 4 + 12 + 4 + 8 = 33
# self.assertEqual (las2.nroots, 33)

#def test_spin_shuffle (self):
# from mrh.my_pyscf.lassi.states import spin_shuffle, spin_shuffle_ci
# mf = lsi._las._scf
# las3 = spin_shuffle (las)
# las3.check_sanity ()
# # The number of states is the number of graphs connecting one number
# # in each row which sum to zero:
# # -2 -1 0 +1 +2
# # -1 0 +1
# # -2 -1 0 +1 +2
# # For the first two rows, paths which sum to -3 and +3 are immediately
# # excluded. Two paths connecting the first two rows each sum to -2 and +2
# # and three paths each sum to -1, 0, +1. Each partial sum then has one
# # remaining option to complete the path, so
# # 2 + 3 + 3 + 3 + 2 = 13
# with self.subTest ("state construction"):
# self.assertEqual (las3.nroots, 13)
# las3.ci = spin_shuffle_ci (las3, las3.ci)
# lsi2 = LASSI (las3).run ()
# errvec = lsi2.s2 - np.around (lsi2.s2)
# with self.subTest ("CI vector rotation"):
# self.assertLess (np.amax (np.abs (errvec)), 1e-8)

#def test_lassis (self):
# from mrh.my_pyscf.lassi.lassis import LASSIS
# las1 = LASSCF (las._scf, (4,4), (4,4), spin_sub=(1,1))
# las1.mo_coeff = las.mo_coeff
# las1.lasci ()
# lsis = LASSIS (las1).run (max_cycle_macro=1)

def test_lassis_slow (self):
from mrh.my_pyscf.lassi.lassis import LASSIS
# TODO: optimize implementation and eventually merge with test_lassis
mol = struct (2.0, 2.0, '6-31g', symmetry=False)
mol.output = 'debug_c2h4n4.log'
mol.verbose = lib.logger.DEBUG
mol.spin = 8
mol.build ()
mf = scf.RHF (mol).run ()
las1 = LASSCF (mf, (5,5), ((3,2),(2,3)), spin_sub=(2,2))
mo_coeff = las1.localize_init_guess ((list (range (5)), list (range (5,10))))
las1.kernel (mo_coeff)
lsis = LASSIS (las1, opt=1).run ()
self.assertAlmostEqual (lsis.e_roots[0], -295.52103109, 7)
self.assertTrue (lsis.converged)

if __name__ == "__main__":
print("Full Tests for SA-LASSI of c2h4n4 molecule")
unittest.main()

Loading

0 comments on commit 1f4cda6

Please sign in to comment.