Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOSCF with dm21 in pySCF #479

Open
HengZ-921 opened this issue Nov 13, 2023 · 4 comments
Open

SOSCF with dm21 in pySCF #479

HengZ-921 opened this issue Nov 13, 2023 · 4 comments

Comments

@HengZ-921
Copy link

Hello, I have tried to apply dm21 to transitional metal systems recently. But even with single atom like V, Cr, Mn, I found they are very hard to converge. I tried to apply SOSCF by
mf = scf.UKS(mol).density_fit()
mf._numint = dm21.NeuralNumInt(dm21.Functional.DM21)
mf = mf.newton()
mf.kernel(mo_init,mocc_init)
which is basically the example code for SOSCF in pySCF example.

but it gave me the error message

File "/cluster/home/vuckovics/miniconda3/envs/pyscf-2.4.0/lib/python3.11/site-packages/pyscf/soscf/newton_ah.py", line 853, in kernel
return _CIAH_SOSCF.kernel(self, mo_coeff, mo_occ, dm0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/cluster/home/vuckovics/miniconda3/envs/pyscf-2.4.0/lib/python3.11/site-packages/pyscf/soscf/newton_ah.py", line 738, in kernel
kernel(self, mo_coeff, mo_occ, dm0, conv_tol=self.conv_tol,
File "/cluster/home/vuckovics/miniconda3/envs/pyscf-2.4.0/lib/python3.11/site-packages/pyscf/soscf/newton_ah.py", line 533, in kernel
rotaiter.send((mo_coeff, mo_occ, dm, vhf, e_tot))
File "/cluster/home/vuckovics/miniconda3/envs/pyscf-2.4.0/lib/python3.11/site-packages/pyscf/soscf/newton_ah.py", line 339, in _rotate_orb_cc
g_kf, h_op, h_diag = mf.gen_g_hop(mo_coeff, mo_occ, fock_ao)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/cluster/home/vuckovics/miniconda3/envs/pyscf-2.4.0/lib/python3.11/site-packages/pyscf/soscf/newton_ah.py", line 205, in gen_g_hop_uhf
vind = mf.gen_response(mo_coeff, mo_occ, hermi=1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/cluster/home/vuckovics/miniconda3/envs/pyscf-2.4.0/lib/python3.11/site-packages/pyscf/scf/_response_functions.py", line 171, in _gen_uhf_response
rho0, vxc, fxc = ni.cache_xc_kernel(mol, mf.grids, mf.xc,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/cluster/home/vuckovics/miniconda3/envs/pyscf-2.4.0/lib/python3.11/site-packages/pyscf/dft/numint.py", line 2578, in cache_xc_kernel
vxc, fxc = ni.eval_xc_eff(xc_code, rho, deriv=2, xctype=xctype)[1:3]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/cluster/home/vuckovics/miniconda3/envs/pyscf-2.4.0/lib/python3.11/site-packages/pyscf/dft/numint.py", line 2711, in eval_xc_eff
exc, vxc, fxc, kxc = self.eval_xc(xc_code, rhop, spin, 0, deriv, omega,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/cluster/home/vuckovics/miniconda3/envs/pyscf-2.4.0/lib/python3.11/site-packages/density_functional_approximation_dm21/neural_numint.py", line 711, in eval_xc
mol=self._system_state.mol,
^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'mol'

Could you please tell me how to apply newton properly with dm21?

@jsspencer
Copy link
Collaborator

Sorry, DM21 doesn't support second-order derivatives required for Newton optimization (and the way NumInt is patched in the PySCF-DM21 interface would require some careful handling even if it did, as your error shows).

A quasi-Newton method can be used (e.g. one from scipy). You might also find it useful to start from an initial guess produced by a cheaper functional (e.g. B3LYP, as shown in the README)

@DeepDevIA
Copy link

Sorry, DM21 doesn't support second-order derivatives required for Newton optimization (and the way NumInt is patched in the PySCF-DM21 interface would require some careful handling even if it did, as your error shows).

A quasi-Newton method can be used (e.g. one from scipy). You might also find it useful to start from an initial guess produced by a cheaper functional (e.g. B3LYP, as shown in the README)

Hi jsspencer
how about Transition state ..!,I tried to reproduce the Bicyclobutane example (Fig 3 C of the paper) and I got the same error message: AttributeError: 'NoneType' object has no attribute 'mol'
in there any way to do this please!!
thanks

@jsspencer
Copy link
Collaborator

Did you follow the steps in https://github.com/google-deepmind/deepmind-research/tree/master/density_functional_approximation_dm21#best-practices-for-using-the-neural-functionals (but for a single molecule)? I don't know why you would trigger that AttributeError -- hard to know without code.

@DeepDevIA
Copy link

maybe I wrote my code wrong.!? I will review my code carefully.
thanks for observing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@jsspencer @HengZ-921 @DeepDevIA and others