Skip to content

Commit

Permalink
Merge pull request #75 from matthew-hennefarth/pdft-dip-example
Browse files Browse the repository at this point in the history
PDFT Dipole Moment Examples
  • Loading branch information
MatthewRHermes authored Nov 1, 2024
2 parents 2babf8f + f74968c commit f3d8c32
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 19 deletions.
31 changes: 13 additions & 18 deletions examples/prop/00-dipole_moment.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
#!/usr/bin/env python

'''
"""
Response-theory calculation of the permanent dipole moment
'''
"""

from pyscf import gto, scf, mcpdft
from pyscf.lib import logger

logger.TIMER_LEVEL = logger.INFO

# Energy calculation
h2co_xyz = '''C 0.534004 0.000000 0.000000
h2co_xyz = """C 0.534004 0.000000 0.000000
O -0.676110 0.000000 0.000000
H 1.102430 0.000000 0.920125
H 1.102430 0.000000 -0.920125'''
mol = gto.M (atom = h2co_xyz, basis = 'def2svp', symmetry = False,
verbose = logger.INFO, output = '00-dipole_moment.log')
mf = scf.RHF (mol).run ()
mc = mcpdft.CASSCF (mf, 'tPBE', 6, 6)
mc.kernel ()
H 1.102430 0.000000 -0.920125"""
mol = gto.M(atom=h2co_xyz, basis="def2svp", symmetry=False)
mf = scf.RHF(mol).run()
mc = mcpdft.CASSCF(mf, "tPBE", 6, 6)
mc.kernel()

# Electric Dipole calculation
dipole = mc.dip_moment(unit='Debye')
print ("MC-PDFT electric dipole moment Debye")
print (" {:8.5f} {:8.5f} {:8.5f}".format (*dipole))
print ("Numerical MC-PDFT electric dipole moment from GAMESS [Debye]")
print (" 2.09361 0.00000 0.00000 ")

dipole = mc.dip_moment(unit="Debye")
print("MC-PDFT electric dipole moment Debye")
print(" {:8.5f} {:8.5f} {:8.5f}".format(*dipole))
print("Numerical MC-PDFT electric dipole moment from GAMESS [Debye]")
print(" 2.09361 0.00000 0.00000 ")
46 changes: 46 additions & 0 deletions examples/prop/01-excited_state_dipole_moment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python

"""
Response-theory calculation of the permanent dipole moment for excited states.
For MC-PDFT, excited state dipole moments can be computed with either
SA-MC-PDFT or CMS-PDFT currently.
"""

from pyscf import gto, scf, mcpdft

mol = gto.M(
atom="""O 0 0 0
H 0 -0.757 0.587
H 0 0.757 0.587""",
basis="6-31G",
)
mf = scf.RHF(mol).run()
mc = mcpdft.CASSCF(mf, "tPBE", 4, 4)

mc_sa = mc.state_average(
[
1.0 / 4,
]
* 4
)
mc_sa.run()

for state in range(4):
d_state = mc_sa.dip_moment(unit="Debye", state=state)
print("Electric dipole moment of {} excited state".format(state))
print(" {:8.5f} {:8.5f} {:8.5f}\n".format(*d_state))


mc_cms = mc.multi_state(
[
1.0 / 4,
]
* 4,
method="cms",
)
mc_cms.run()

for state in range(4):
d_state = mc_cms.dip_moment(unit="Debye", state=state)
print("Electric dipole moment of {} excited state".format(state))
print(" {:8.5f} {:8.5f} {:8.5f}\n".format(*d_state))
35 changes: 35 additions & 0 deletions examples/prop/02-pdft_transition_dipole_moment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python

"""
Response-theory calculation of the transition dipole moment.
Can only be used with CMS-PDFT currently.
"""

from pyscf import gto, scf, mcpdft

mol = gto.M(
atom="""O 0 0 0
H 0 -0.757 0.587
H 0 0.757 0.587""",
basis="6-31G",
)
mf = scf.RHF(mol).run()
mc = mcpdft.CASSCF(mf, "tPBE", 4, 4)

mc_cms = mc.multi_state(
[
1.0 / 4,
]
* 4,
method="cms",
)
mc_cms.run()

td_state = mc_cms.trans_moment(unit="Debye", state=(0, 2))
print("Transition dipole moment of <{}|mu|{}> excited state".format(0, 2))
print(" {:8.5f} {:8.5f} {:8.5f}\n".format(*td_state))

# Note that the transition dipole moment is symmetric
h_td_state = mc_cms.trans_moment(unit="Debye", state=(2, 0))
print(max(abs(td_state - h_td_state)))
2 changes: 1 addition & 1 deletion pyscf/mcpdft/mspdft.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def trans_moment (self, unit='Debye', origin='Coord_Center', state=None):
prop.__path__.append (myproppath)
prop.__path__=list(set(prop.__path__))
from pyscf.prop.trans_dip_moment.mspdft import TransitionDipole
if not isinstance(state, list) or len(state)!=2:
if not hasattr(state, '__len__') or len(state) !=2:
raise RuntimeError ('Transition dipole requires two states')
tran_dip_obj = TransitionDipole(self)
mol_trans_dipole = tran_dip_obj.kernel (state=state, unit=unit, origin=origin)
Expand Down

0 comments on commit f3d8c32

Please sign in to comment.