Skip to content

Commit

Permalink
improve mix and from_frag
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanwsr committed Dec 2, 2022
1 parent 1180df4 commit 73b6a31
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ jobs:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: true
files: |
./dist/pyAutoMR-$VERSION-py3-none-any.whl
./dist/pyAutoMR-v*-py3-none-any.whl
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

version 0.3.0-rc9 (Nov 16, 2022)
--------------------------
* GitHub Actions for auto-release and pypi upload

version 0.3.0-rc1 (Nov 16, 2022)
--------------------------
Features
Expand Down
41 changes: 25 additions & 16 deletions automr/guess.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,14 @@ def _mix(mol,
print('**** generating mix guess ****')
mo_mix = mf.mo_coeff
nocc = mol.nelectron//2
print('RHF MO energy and HOMO-3~LUMO+3 before mixing')
print('mo_e', mf.mo_energy[nocc-4:nocc+4])
dump_mat.dump_mo(mol, mo_mix[:,nocc-4:nocc+4], ncol=8)
if not isinstance(hl[0], list):
hl = [hl]
for hlitem in hl:
dm_mix, mo_mix = init_guess_mixed(mo_mix, mf.mo_occ, ho=hlitem[0], lu=hlitem[1], mix_param=mix_param)
print('After mixing')
dump_mat.dump_mo(mol, mo_mix[0][:,nocc-4:nocc+4], ncol=8)
dump_mat.dump_mo(mol, mo_mix[1][:,nocc-4:nocc+4], ncol=8)
if xc is None:
Expand All @@ -172,21 +176,22 @@ def _mix(mol,
mf_mix.level_shift = level_shift
mf_mix.max_cycle = 100
mf_mix.kernel(dm0=dm_mix)
if not mf_mix.converged and conv == 'tight':
mf_mix = postscf_check(mf_mix, conv, skipstb, newton)

t2 = time.time()
print('time for guess: %.3f' % (t2-t1))
return mf_mix

def postscf_check(mf, conv, skipstb, newton):
if not mf.converged and conv == 'tight':
raise RuntimeError('UHF not converged')
ss, s = mf_mix.spin_square()
ss, s = mf.spin_square()
if s < 0.1:
print('Warning: S too small, symmetry breaking may be failed')

if conv == 'tight' and not skipstb:
mf_mix = check_stab(mf_mix, newton)

t2 = time.time()
print('time for guess: %.3f' % (t2-t1))
#dm = mf.make_rdm1()
#mf.max_cycle = 0
#mf_mix.kernel(dm)
return mf_mix
mf = check_stab(mf, newton)
return mf

def apply_field(mf, f):
h2 = mf.get_hcore() + np.einsum('x,xij->ij', f, mf.mol.intor('int1e_r', comp=3))
Expand Down Expand Up @@ -274,7 +279,9 @@ def from_frag(xyz, bas, frags, chgs, spins, **kwargs):
return _from_frag(mol, frags, chgs, spins, **kwargs)


def _from_frag(mol_or_mf, frags, chgs, spins, cycle=2, xc=None, verbose=4, rmdegen=False, bgchg=None):
def _from_frag(mol_or_mf, frags, chgs, spins,
conv='loose', cycle=2, level_shift=0.0,
skipstb=False, xc=None, newton=False, verbose=4, rmdegen=False, bgchg=None):

t1 = time.time()
dm, mo, occ = guess_frag(mol_or_mf, frags, chgs, spins, rmdegen=rmdegen, bgchg=bgchg)
Expand All @@ -296,12 +303,14 @@ def _from_frag(mol_or_mf, frags, chgs, spins, cycle=2, xc=None, verbose=4, rmdeg
mf.xc = xc
mf.mo_coeff = mo
mf.verbose = verbose
#mf.conv_tol = 1e-2
mf.max_cycle = cycle
if conv == 'loose':
mf.conv_tol = 1e-3
mf.max_cycle = cycle
elif conv == 'tight':
mf.level_shift = level_shift
mf.max_cycle = 100
mf.kernel(dm0 = dm)
ss, s = mf.spin_square()
if s < 0.1:
print('Warning: S too small, symmetry breaking may be failed')
mf = postscf_check(mf, conv, skipstb, newton)
t2 = time.time()
print('time for guess: %.3f' % (t2-t1))
return mf
Expand Down
7 changes: 7 additions & 0 deletions examples/tutorial/01-mix_adv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from automr import guess

xyz = '''F 0.0 0.0 0.0; F 0.0 0.0 1.5'''
bas = 'def2-svp'

mf = guess.mix_tight(xyz, bas) # end up no polarized spin
mf = guess.mix_tight(xyz, bas, hl=[-2,0]) # correct polarized spin
11 changes: 11 additions & 0 deletions examples/tutorial/03-from_frag_adv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from automr import guess

xyz = '''F 0.0 0.0 0.0; F 0.0 0.0 4.0'''
bas = 'cc-pvtz'
mf = guess.from_frag_tight(xyz, bas, [[0],[1]], [0,0], [1,-1])

mf0 = guess.gen('''F 0.0 0.0 0.0''', bas, 0, 1)
mf0 = guess.apply_field(mf0, (0.01,0.01,0.0).run()
#mf0.analyze()
#mf = guess._from_frag(xyz, bas, [[0],[1]], [0,0], [1,-1])
#
13 changes: 13 additions & 0 deletions examples/tutorial/03-from_frag_manually.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from automr import guess

xyz = '''H 0.0 0.0 0.0; F 0.0 0.0 2.0'''
bas = 'def2-svp'
mf = guess.from_frag_tight(xyz, bas, [[0],[1]], [0,0], [1,-1])

mf0 = guess.gen('''H 0.0 0.0 0.0''', bas, 0, 1)
#mf0 = guess.apply_field(mf0, (0.0,0.0,0.01)).run() # add field in z direction
#mf0.mulliken_pop() # check odd electron on pz
mf1 = guess.gen('''F 0.0 0.0 2.0''', bas, 0, -1).set(max_cycle=5)
mf1 = guess.apply_field(mf1, (0.0,0.01,0.02)).run() # add field in z direction
mf1.mulliken_pop() # check odd electron on pz
mf = guess._from_frag([mf0, mf1], None, None, None, conv='tight')

0 comments on commit 73b6a31

Please sign in to comment.