- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 650
Implement interface to set custom parameters of XC functionals in Libxc #1746
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
Conversation
| This is not the way to set libxc parameters. You are not supposed to touch the Libxc internal arrays. Also, your example is hardcoded to a single functional, which sets a bad example. We have generic functionality to do this. Use the function  Several people have expressed interest in being able to set libxc functional parameters in PySCF. For instance, I have been in touch with @ychen428 since early 2023 who has a proper interface to the external parameter setters. Per my request, @ychen428 promised to open up a pull request "shortly" several months ago, but I don't see one up yet. @ychen428 please open up a pull request; like we discussed by email the interface may need some discussion with the PySCF main developers since it's not obvious what is the best way to store the parameters in PySCF. | 
| Thanks for pointing me towards the right direction. I didn't know Libxc has such a convenient method to set external parameters. I made a new implementation of the interface to set external parameters. This should be much cleaner than what is previously done. In the new implementation, no manual adjustment of HF exchange percentage is needed. | 
| 
 This is still missing. | 
| In the current implementation, the external parameters are set when PySCF queries properties of the functional. Here is a summary of how this is achieved. In  Can you please let me know which part I am missing? | 
| 
 I do see now that the minute change of adding  | 
| Thanks for the suggestions. I have fixed the issues mentioned above. 
 I used 8-space indentation because  | 
| Modifying the internal parameters of libxc through PySCF's libxc interface IMO is not a good way to use libxc. The pyscf libxc interface is supposed to combine different libxc functionals at Python level. In this scenario, it is better to use pylibxc library and call its APIs to modify functionals. An adapter may need to be implemented for calling pylibxc in the dft module. | 
| 
 Please consider to cache parameters in Python. Modification to libxc library can only applied when needed and parameters should be restored immediately after calling the libxc functions. It looks an error-prone code to persistently change the libxc internal parameters. E.g., imaging that the libxc library is called by another thread after set_ext_params in one thread. | 
| @sunqm an issue is that pylibxc is overengineered in terms of an interface and we are thinking about disbanding it in favor of a more minimal interface similar to the C interfacing used in PySCF... However, it is true that many codes will want a more abstract, object-oriented interface to Libxc; this could be done by another project in a higher-level language like C++ with Python interfaces. | 
d7310e6    to
    88266d5      
    Compare
  
    | Here is a new implementation where the external parameters are cached in Python. The parameters are cached in the  I made modifications in the base classes  | 
| This feature looks make the interface to libxc unnecessarily complicated. I think it needs more consideration whether and how to handle this feature. I will close the PR for the moment. | 
In this pull request, I added a callback interface in
libxc_itrf.cto allow using custom parameters in XC functionals. The user can adjust the parameters in thexc_func_typestruct right before Libxc evaluates the functional through the callback interface. A fully commented example is supplied.