#!/usr/bin/env python
#
# Author: Qiming Sun <osirpt.sun@gmail.com>
#

'''
A simple example to run MCSCF with background charges.
'''

import numpy
from pyscf import gto, scf, mcscf, qmmm

mol = gto.M(atom='''
C       1.1879  -0.3829 0.0000
C       0.0000  0.5526  0.0000
O       -1.1867 -0.2472 0.0000
H       -1.9237 0.3850  0.0000
H       2.0985  0.2306  0.0000
H       1.1184  -1.0093 0.8869
H       1.1184  -1.0093 -0.8869
H       -0.0227 1.1812  0.8852
H       -0.0227 1.1812  -0.8852
            ''',
            basis='3-21g',
            verbose=4)

numpy.random.seed(1)
coords = numpy.random.random((5,3)) * 10
charges = (numpy.arange(5) + 1.) * -.1

#
# There are two ways to add background charges to MCSCF method.
# The recommended one is to initialize it in SCF calculation. The MCSCF
# calculation takes the information from SCF objects.
#
mf = qmmm.mm_charge(scf.RHF(mol), coords, charges).run()

mc = mcscf.CASSCF(mf, 6, 6)
mc.run()

mc = mcscf.CASCI(mf, 6, 6)
mc.run()

#
# The other method is to patch the MCSCF object with the background charges.
# Note: it updates the underlying SCF object inplace.
#
mo_init = mf.mo_coeff

mf = scf.RHF(mol)
mc = mcscf.CASSCF(mf, 6, 6)
mc = qmmm.mm_charge(mc, coords, charges)
mc.run(mo_init)

mf = scf.RHF(mol)
mc = mcscf.CASCI(mf, 6, 6)
mc = qmmm.mm_charge(mc, coords, charges)
mc.run(mo_init)

[((13, 6, 25, 22), 'pyscf.gto.M', 'gto.M', (), '', False, 'from pyscf import gto, scf, mcscf, qmmm\n'), ((27, 0, 27, 20), 'numpy.random.seed', 'numpy.random.seed', ({(27, 18, 27, 19): '(1)'}, {}), '(1)', False, 'import numpy\n'), ((38, 5, 38, 27), 'pyscf.mcscf.CASSCF', 'mcscf.CASSCF', ({(38, 18, 38, 20): 'mf', (38, 22, 38, 23): '6', (38, 25, 38, 26): '6'}, {}), '(mf, 6, 6)', False, 'from pyscf import gto, scf, mcscf, qmmm\n'), ((41, 5, 41, 26), 'pyscf.mcscf.CASCI', 'mcscf.CASCI', ({(41, 17, 41, 19): 'mf', (41, 21, 41, 22): '6', (41, 24, 41, 25): '6'}, {}), '(mf, 6, 6)', False, 'from pyscf import gto, scf, mcscf, qmmm\n'), ((50, 5, 50, 17), 'pyscf.scf.RHF', 'scf.RHF', ({(50, 13, 50, 16): 'mol'}, {}), '(mol)', False, 'from pyscf import gto, scf, mcscf, qmmm\n'), ((51, 5, 51, 27), 'pyscf.mcscf.CASSCF', 'mcscf.CASSCF', ({(51, 18, 51, 20): 'mf', (51, 22, 51, 23): '6', (51, 25, 51, 26): '6'}, {}), '(mf, 6, 6)', False, 'from pyscf import gto, scf, mcscf, qmmm\n'), ((52, 5, 52, 40), 'pyscf.qmmm.mm_charge', 'qmmm.mm_charge', ({(52, 20, 52, 22): 'mc', (52, 24, 52, 30): 'coords', (52, 32, 52, 39): 'charges'}, {}), '(mc, coords, charges)', False, 'from pyscf import gto, scf, mcscf, qmmm\n'), ((55, 5, 55, 17), 'pyscf.scf.RHF', 'scf.RHF', ({(55, 13, 55, 16): 'mol'}, {}), '(mol)', False, 'from pyscf import gto, scf, mcscf, qmmm\n'), ((56, 5, 56, 26), 'pyscf.mcscf.CASCI', 'mcscf.CASCI', ({(56, 17, 56, 19): 'mf', (56, 21, 56, 22): '6', (56, 24, 56, 25): '6'}, {}), '(mf, 6, 6)', False, 'from pyscf import gto, scf, mcscf, qmmm\n'), ((57, 5, 57, 40), 'pyscf.qmmm.mm_charge', 'qmmm.mm_charge', ({(57, 20, 57, 22): 'mc', (57, 24, 57, 30): 'coords', (57, 32, 57, 39): 'charges'}, {}), '(mc, coords, charges)', False, 'from pyscf import gto, scf, mcscf, qmmm\n'), ((28, 9, 28, 35), 'numpy.random.random', 'numpy.random.random', ({(28, 29, 28, 34): '(5, 3)'}, {}), '((5, 3))', False, 'import numpy\n'), ((29, 11, 29, 26), 'numpy.arange', 'numpy.arange', ({(29, 24, 29, 25): '(5)'}, {}), '(5)', False, 'import numpy\n'), ((36, 20, 36, 32), 'pyscf.scf.RHF', 'scf.RHF', ({(36, 28, 36, 31): 'mol'}, {}), '(mol)', False, 'from pyscf import gto, scf, mcscf, qmmm\n')]