#!/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)

[((195, 543), 'pyscf.gto.M', 'gto.M', ([], {'atom': '"""\nC       1.1879  -0.3829 0.0000\nC       0.0000  0.5526  0.0000\nO       -1.1867 -0.2472 0.0000\nH       -1.9237 0.3850  0.0000\nH       2.0985  0.2306  0.0000\nH       1.1184  -1.0093 0.8869\nH       1.1184  -1.0093 -0.8869\nH       -0.0227 1.1812  0.8852\nH       -0.0227 1.1812  -0.8852\n            """', 'basis': '"""3-21g"""', 'verbose': '(4)'}), '(atom=\n    """\nC       1.1879  -0.3829 0.0000\nC       0.0000  0.5526  0.0000\nO       -1.1867 -0.2472 0.0000\nH       -1.9237 0.3850  0.0000\nH       2.0985  0.2306  0.0000\nH       1.1184  -1.0093 0.8869\nH       1.1184  -1.0093 -0.8869\nH       -0.0227 1.1812  0.8852\nH       -0.0227 1.1812  -0.8852\n            """\n    , basis=\'3-21g\', verbose=4)\n', (200, 543), False, 'from pyscf import gto, scf, mcscf, qmmm\n'), ((559, 579), 'numpy.random.seed', 'numpy.random.seed', (['(1)'], {}), '(1)\n', (576, 579), False, 'import numpy\n'), ((918, 940), 'pyscf.mcscf.CASSCF', 'mcscf.CASSCF', (['mf', '(6)', '(6)'], {}), '(mf, 6, 6)\n', (930, 940), False, 'from pyscf import gto, scf, mcscf, qmmm\n'), ((956, 977), 'pyscf.mcscf.CASCI', 'mcscf.CASCI', (['mf', '(6)', '(6)'], {}), '(mf, 6, 6)\n', (967, 977), False, 'from pyscf import gto, scf, mcscf, qmmm\n'), ((1151, 1163), 'pyscf.scf.RHF', 'scf.RHF', (['mol'], {}), '(mol)\n', (1158, 1163), False, 'from pyscf import gto, scf, mcscf, qmmm\n'), ((1169, 1191), 'pyscf.mcscf.CASSCF', 'mcscf.CASSCF', (['mf', '(6)', '(6)'], {}), '(mf, 6, 6)\n', (1181, 1191), False, 'from pyscf import gto, scf, mcscf, qmmm\n'), ((1197, 1232), 'pyscf.qmmm.mm_charge', 'qmmm.mm_charge', (['mc', 'coords', 'charges'], {}), '(mc, coords, charges)\n', (1211, 1232), False, 'from pyscf import gto, scf, mcscf, qmmm\n'), ((1255, 1267), 'pyscf.scf.RHF', 'scf.RHF', (['mol'], {}), '(mol)\n', (1262, 1267), False, 'from pyscf import gto, scf, mcscf, qmmm\n'), ((1273, 1294), 'pyscf.mcscf.CASCI', 'mcscf.CASCI', (['mf', '(6)', '(6)'], {}), '(mf, 6, 6)\n', (1284, 1294), False, 'from pyscf import gto, scf, mcscf, qmmm\n'), ((1300, 1335), 'pyscf.qmmm.mm_charge', 'qmmm.mm_charge', (['mc', 'coords', 'charges'], {}), '(mc, coords, charges)\n', (1314, 1335), False, 'from pyscf import gto, scf, mcscf, qmmm\n'), ((589, 616), 'numpy.random.random', 'numpy.random.random', (['(5, 3)'], {}), '((5, 3))\n', (608, 616), False, 'import numpy\n'), ((632, 647), 'numpy.arange', 'numpy.arange', (['(5)'], {}), '(5)\n', (644, 647), False, 'import numpy\n'), ((875, 887), 'pyscf.scf.RHF', 'scf.RHF', (['mol'], {}), '(mol)\n', (882, 887), False, 'from pyscf import gto, scf, mcscf, qmmm\n')]