Differentiable Quantum Chemistry (only Differentiable Density Functional Theory and Hartree Fock at the moment)

Overview

DQC: Differentiable Quantum Chemistry

Build Code coverage Docs

Differentiable quantum chemistry package. Currently only support differentiable density functional theory (DFT) and Hartree-Fock (HF) calculation.

Installation, tutorials, and documentations can be found at: https://dqc.readthedocs.io/

Applications

Here is a list of applications made easy by DQC. If you want your applications listed here, please contact us by opening an issue or make a pull request.

Applications Repo Paper
Learning xc functional from experimental data github Paper
Basis optimization github
Alchemical perturbation github

Citations

If you are using DQC for your publication, please kindly cite the following

@article{PhysRevLett.127.126403,
  title = {Learning the Exchange-Correlation Functional from Nature with Fully Differentiable Density Functional Theory},
  author = {Kasim, M. F. and Vinko, S. M.},
  journal = {Phys. Rev. Lett.},
  volume = {127},
  issue = {12},
  pages = {126403},
  numpages = {7},
  year = {2021},
  month = {Sep},
  publisher = {American Physical Society},
  doi = {10.1103/PhysRevLett.127.126403},
  url = {https://link.aps.org/doi/10.1103/PhysRevLett.127.126403}
}

If you want to read the paper in arxiv, you can find it here.

Comments
  • [BUG] different density matrix and Basis by using pscf and dqc

    [BUG] different density matrix and Basis by using pscf and dqc

    I discovered some bug or more or less something I don't understand. So first when I want to just read the Basis from Basis Set Exchange the Parameters are different. I discovered a normalization function in your code, but I don't know what it really does. Bur it changes the input coefficients of the Basis functions. Another Problem I got was by calculation the overlapmatix. In comparison to a similar calculation in pyscf the matrix values are sometime the same. Using another Basis, the overlapmatix differs from each others.

    So here is a code to replicate the errors:

    
    from pyscf import gto, scf
    import dqc
    import numpy as np
    import xitorch as xt
    from dqc.utils.datastruct import AtomCGTOBasis
    import dqc.hamilton.intor as intor
    from dqc.api.parser import parse_moldesc
    
    #using pscf to calc:
    #   the overlap Matrix
    #   as well as print the coefficients of the basis sets
    
    def overlapb_scf(basis):
        """
        just creates the overlap matrix for different input basis
        """
        mol = gto.Mole()
        mol.atom = [['H', [1.0, 0.0, 0.0]],
                    ['H', [-1.0, 0.0, 0.0]]]
        mol.spin = 0
        mol.unit = 'Bohr' # in Angstrom
        mol.verbose = 6
        mol.output = 'scf.out'
        mol.symmetry = False
        mol.basis = basis
        mol.build()
    
        mf = scf.RHF(mol)
        mf.kernel()
        mf.mo_coeff
        dm = mf.make_rdm1()
        overlap = mf.get_ovlp()
        return overlap
    
    
    ########################################################################################################################
    
    #using the dqc module to calc the basis and the overlap matrix
    
    basis_dqc = [dqc.loadbasis("1:3-21G"), dqc.loadbasis("1:3-21G")]
    basis2_dqc = [dqc.loadbasis("1:cc-pvdz"), dqc.loadbasis("1:cc-pvdz")]
    
    def overlapb_dqc(basis):
        """
          just creates the overlap matrix for different input basis
        """
        bpacker = xt.Packer(basis)
        bparams = bpacker.get_param_tensor()
    
        atomstruc = "H 1 0 0; H -1 0 0"
        atomzs, atompos = parse_moldesc(atomstruc)
        atombases = [AtomCGTOBasis(atomz=atomzs[i], bases=basis[i], pos=atompos[i]) for i in range(len(basis))]
    
        wrap = dqc.hamilton.intor.LibcintWrapper(
                atombases)  # creates an wrapper object to pass informations on lower functions
        return intor.overlap(wrap)
    
    print(f"the pyscf:\n3-21G: \n\t{gto.basis.load('3-21G',symb='H')}\n"
          f"coefficients of cc-pvdz: \n\t{gto.basis.load('cc-pvdz',symb='H')} ")
    print(f"\nthe dqc:\n1:3-21G:\n\t {basis_dqc[0]},\n1:cc-pvdz\n\t{basis2_dqc[0]} ")
    
    #checks that the overlap matrix is the same:
    print(f"3-21G: {np.all(np.isclose(overlapb_scf('3-21G'),overlapb_dqc(basis_dqc)))}"
          f"\ncc-pvdz: {np.all(np.isclose(overlapb_scf('cc-pvdz'),overlapb_dqc(basis2_dqc)))}")
    
    

    So the output is:

    
    the pyscf:
    3-21G: 
    	[[0, [5.447178, 0.156285], [0.824547, 0.904691]], [0, [0.183192, 1.0]]]
    coefficients of cc-pvdz: 
    	[[0, [13.01, 0.019685], [1.962, 0.137977], [0.4446, 0.478148]], [0, [0.122, 1.0]], [1, [0.727, 1.0]]] 
    
    the dqc:
    1:3-21G:
    	 [CGTOBasis(angmom=0, alphas=tensor([5.4472, 0.8245], dtype=torch.float64), coeffs=tensor([1.4079, 1.9778], dtype=torch.float64), normalized=True), CGTOBasis(angmom=0, alphas=tensor([0.1832], dtype=torch.float64), coeffs=tensor([0.7074], dtype=torch.float64), normalized=True)],
    1:cc-pvdz
    	[CGTOBasis(angmom=0, alphas=tensor([13.0100,  1.9620,  0.4446,  0.1220], dtype=torch.float64), coeffs=tensor([0.3407, 0.5779, 0.6577, 0.2614], dtype=torch.float64), normalized=True), CGTOBasis(angmom=0, alphas=tensor([0.1220], dtype=torch.float64), coeffs=tensor([0.5215], dtype=torch.float64), normalized=True), CGTOBasis(angmom=1, alphas=tensor([0.7270], dtype=torch.float64), coeffs=tensor([1.9584], dtype=torch.float64), normalized=True)] 
    overwrite output file: scf.out
    overwrite output file: scf.out
    3-21G: True
    cc-pvdz: False
    

    So my question is when does the overlap matrix the same in pscf and dqc. As well as when will they differ from each other?

    Desktop (please complete the following information):

    • DQC version: [e.g. 0.1.0]
    • Python version: [e.g. 3.8]
    • PyTorch version: [e.g. 1.9]
    • OS: [Ubuntu 18.04]
    opened by Jaikinator 10
  • [ENH] Geometry optimization

    [ENH] Geometry optimization

    Is your feature request related to a problem? Please describe. I would like to optimize the geometry of a molecule from an initial configuration. This would then allow me to compute vibrational frequencies and IR spectra at a local minimum of the potential energy surface.

    Describe the solution you'd like

    In PySCF I can use their geometry_optimizer to optimize the geometry of a molecule, for example something like

    from pyscf import gto
    from pyscf.geomopt.geometric_solver import optimize as geometric_opt
    
    mol = gto.Mole(atom=atom, basis = 'sto-3g') # atom is some initial starting description of the molecule
    rhf = scf.RHF(mol)
    mol_opt = geometric_opt(rhf)
    

    I would like to do something similar in dqc, for example something like

    import dqc
    
    mol = dqc.Mol(moldesc=moldesc, basis="sto-3g") # moldesc is some initial starting description of the molecule
    mol.atompos.requires_grad_()
    hf = dqc.HF(mol).run()
    mol_opt = dqc.optimize_geometry(hf) # new proposed function
    

    Describe alternatives you've considered Alternatively this would have to be implemented outside of dqc.

    Additional context I know there are many algorithms possible for geometry optimization and I am very open to whichever is recommended.

    opened by sofroniewn 8
  • [BUG] calculate density matrix

    [BUG] calculate density matrix

    Normally, for example in pyscf the density Matrix P is defined by the expansion coefficient Matrix.
    So the trace of P*S (where S is the overlap Matrix) should be equal to the number of Electrons in the system. When I try your density Matrix given by the code below, the trace of the density Matrix itself result in the number of electrons. So, can you explain to me why you use it like this?

    The Program basis = [dqc.loadbasis("1:3-21G"), dqc.loadbasis("1:3-21G")] atomstruc = "H 1 0 0; H -1 0 0" m = dqc.Mol(atomstruc, basis = basis) qc = dqc.HF(m).run() dm = qc.aodm() print(torch.trace(dm)) #gives 2 in this example

    Desktop (please complete the following information):

    • DQC version: 0.1.0
    • Python version: 3.8.1
    • PyTorch version: 1.9
    • OS: Ubuntu
    opened by Jaikinator 5
  • Add optimal_geometry method

    Add optimal_geometry method

    This PR closes #10 by adding an optimal_geometry method to the properties API. It also adds a make_copy method to the Mol and Sol systems. It adds basic tests to cover the make_copy and optimal_geometry.

    Overall I tried to match the code, naming, and commenting style of the repo as best I could - feel free to change or request changes on anything you don't like.

    One thing I am wondering is if you still like the optimal_geometry name and function descriptions. Alternatives could emphasize that it is a position that is a local minimum of the energy. I don't really mind.

    opened by sofroniewn 4
  • [BUG] Big difference in PySCF vs dqc vibrational frequencies

    [BUG] Big difference in PySCF vs dqc vibrational frequencies

    Describe the bug When I compute vibrational frequencies using PySCF and dqc using the same level of theory I see very different results, and I'm not sure how to interpret the dqc frequencies.

    To Reproduce To compute the dqc frequencies I do

    import dqc
    
    moldesc = 'C          -1.28652        0.25524        0.08013;C           0.07762        0.16535       -0.63495;O           0.22083        0.47033       -1.80613;C           1.24790       -0.33747        0.23567;H          -2.04623        0.61618       -0.60539;H          -1.22080        0.93293        0.92681;H          -1.57890       -0.72292        0.45183;H           1.03268       -1.33368        0.61210;H           2.16265       -0.36812       -0.34714;H           1.39077        0.32217        1.08708'
    
    mol = dqc.Mol(moldesc=moldesc, basis="sto-3g")
    mol.atompos.requires_grad_()
    hf = dqc.HF(mol).run()
    vib = dqc.vibration(hf, freq_unit='cm^-1') # calculate vibrational frequencies
    freq_dqc = vib[0].detach().numpy()
    print(freq_dqc)
    
    # Which gives
    array([ 1.70294616e+04,  1.69718735e+04,  1.68860090e+04,  1.68255299e+04,
            1.68225380e+04,  1.67753119e+04,  1.44644965e+04,  9.52891028e+03,
            9.07347876e+03,  1.88365866e-04,  1.02303786e-04, -6.48131738e-05,
           -5.43764168e+03, -6.09925459e+03, -6.22499857e+03, -6.99690325e+03,
           -9.01539897e+03, -1.08179418e+04, -1.08671386e+04, -1.08868149e+04,
           -1.11379683e+04, -1.12761626e+04, -1.14500718e+04, -1.19746118e+04,
           -1.25462017e+04, -1.26196271e+04, -1.27329229e+04, -1.27626848e+04,
           -1.29649564e+04, -1.29682415e+04])
    

    To compute the PySCF frequencies I do

    from pyscf import gto
    from pyscf.hessian import thermo
    
    
    moldesc = 'C          -1.28652        0.25524        0.08013;C           0.07762        0.16535       -0.63495;O           0.22083        0.47033       -1.80613;C           1.24790       -0.33747        0.23567;H          -2.04623        0.61618       -0.60539;H          -1.22080        0.93293        0.92681;H          -1.57890       -0.72292        0.45183;H           1.03268       -1.33368        0.61210;H           2.16265       -0.36812       -0.34714;H           1.39077        0.32217        1.08708'
    
    mol = gto.Mole(atom=moldesc, basis='sto-3g')
    mol.build()
    mf = mol.RHF().run()
    hessian = mf.Hessian().kernel()
    freq_pyscf = thermo.harmonic_analysis(mf.mol, hessian)['freq_wavenumber']
    print(freq_pyscf)
    
    # Which gives
    array([ 117.92712198,  163.62556757,  394.58567756,  531.09155165,
            557.37323521,  905.59174999, 1100.86423523, 1103.22104045,
           1263.96843255, 1299.84707843, 1432.34457908, 1705.964129  ,
           1706.20007991, 1806.21035873, 1810.62541007, 1810.74231001,
           1814.3241799 , 2129.55729236, 3564.58835085, 3565.97676807,
           3740.70588451, 3742.69670576, 3761.55937183, 3763.21894889])
    

    The molecule I'm using is acetone which I have done geometry optimization on in PySCF, also using HF 'sto-3g'. The values in wavenumber are roughly in line for what I'd expect for acetone based on the literature. The dqc numbers are over a wide range, both positive and negative, despite using the same level of theory.

    Expected behavior I expected the dqc numbers to be more inline with the PySCF numbers

    Desktop (please complete the following information):

    • DQC version: 0.1.0
    • Python version: 3.9
    • PyTorch version: 1.10.2
    • OS: macOS

    Additional context I am pretty new to PySCF, dqc and computational chemistry overall so I apologies if my problem here is a real beginners mistake and I am not understanding things correctly. I hope you also don't mind all the issues I am creating - I'm really impressed with dqc and am hoping to use it in one of my projects!

    opened by sofroniewn 4
  • [BUG] Differentiable tensor atom position error if molecule initialized from string

    [BUG] Differentiable tensor atom position error if molecule initialized from string

    Describe the bug I am unable to perform a vibration calculation when creating a molecule from a string description

    To Reproduce Steps to reproduce the behavior:

    import torch
    import dqc
    moldesc = "H 1 0 0; H -1 0 0"
    mol = dqc.Mol(moldesc=moldesc, basis="3-21G")
    qc = dqc.HF(mol).run()
    ene = qc.energy()  # calculate the energy
    print(ene)
    vib = dqc.vibration(qc) # calculate vibrational frequencies
    print(vib)
    

    Gives

    ---------------------------------------------------------------------------
    RuntimeError                              Traceback (most recent call last)
    /Users/nsofroniew/Documents/code/chem/molecular_vibrations.ipynb Cell 50' in <module>
          [6](vscode-notebook-cell:/Users/nsofroniew/Documents/code/chem/molecular_vibrations.ipynb#ch0000060?line=5)[ ene = qc.energy()  # calculate the energy
          ]()[7](vscode-notebook-cell:/Users/nsofroniew/Documents/code/chem/molecular_vibrations.ipynb#ch0000060?line=6)[ print(ene)
    ----> ]()[8](vscode-notebook-cell:/Users/nsofroniew/Documents/code/chem/molecular_vibrations.ipynb#ch0000060?line=7)[ vib = dqc.vibration(qc) # calculate vibrational frequency
          ]()[9](vscode-notebook-cell:/Users/nsofroniew/Documents/code/chem/molecular_vibrations.ipynb#ch0000060?line=8)[ print(vib)
    
    File ~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py:66, in vibration(qc, freq_unit, length_unit)
         ]()[41](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=40)[ def vibration(qc: BaseQCCalc, freq_unit: Optional[str] = "cm^-1",
         ]()[42](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=41)[               length_unit: Optional[str] = None) -> Tuple[torch.Tensor, torch.Tensor]:
         ]()[43](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=42)[     """
         ]()[44](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=43)[     Calculate the vibration mode of the system based on the Hessian of energy
         ]()[45](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=44)[     with respect to atomic position.
       (...)
         ]()[64](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=63)[         to each axis sorted from the largest frequency to smallest frequency.
         ]()[65](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=64)[     """
    ---> ]()[66](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=65)[     freq, mode = _vibration(qc)
         ]()[67](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=66)[     freq = freq_to(freq, freq_unit)
         ]()[68](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=67)[     mode = length_to(mode, length_unit)
    
    File ~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py:32, in memoize_method.<locals>.new_fcn(self)
         ]()[30](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py?line=29)[     return self.__dict__[cachename]
         ]()[31](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py?line=30)[ else:
    ---> ]()[32](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py?line=31)[     res = fcn(self)
         ]()[33](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py?line=32)[     self.__dict__[cachename] = res
         ]()[34](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py?line=33)[     return res
    
    File ~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py:269, in _vibration(qc)
        ]()[264](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=263)[ @memoize_method
        ]()[265](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=264)[ def _vibration(qc: BaseQCCalc) -> Tuple[torch.Tensor, torch.Tensor]:
        ]()[266](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=265)[     # calculate the vibrational mode and returns the frequencies and normal modes
        ]()[267](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=266)[     # freqs are sorted from largest to smallest
    --> ]()[269](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=268)[     hess = hessian_pos(qc)  # (natoms * ndim, natoms * ndim)
        ]()[270](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=269)[     mass = qc.get_system().atommasses  # (natoms)
        ]()[271](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=270)[     ndim = hess.shape[0] // mass.shape[0]
    
    File ~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py:37, in hessian_pos(qc, unit)
         ]()[19](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=18)[ def hessian_pos(qc: BaseQCCalc, unit: Optional[str] = None) -> torch.Tensor:
         ]()[20](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=19)[     """
         ]()[21](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=20)[     Returns the Hessian of energy with respect to atomic positions.
         ]()[22](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=21)[ 
       (...)
         ]()[35](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=34)[         of the energy with respect to the atomic position
         ]()[36](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=35)[     """
    ---> ]()[37](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=36)[     hess = _hessian_pos(qc)
         ]()[38](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=37)[     hess = length_to(hess, unit)
         ]()[39](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=38)[     return hess
    
    File ~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py:32, in memoize_method.<locals>.new_fcn(self)
         ]()[30](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py?line=29)[     return self.__dict__[cachename]
         ]()[31](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py?line=30)[ else:
    ---> ]()[32](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py?line=31)[     res = fcn(self)
         ]()[33](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py?line=32)[     self.__dict__[cachename] = res
         ]()[34](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py?line=33)[     return res
    
    File ~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py:257, in _hessian_pos(qc)
        ]()[254](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=253)[ atompos = system.atompos
        ]()[256](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=255)[ # check if the atompos requires grad
    --> ]()[257](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=256)[ _check_differentiability(atompos, "atom positions", "hessian")
        ]()[259](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=258)[ # calculate the jacobian
        ]()[260](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=259)[ jac_e_pos = _jac(ene, atompos, create_graph=True)  # (natoms * ndim)
    
    File ~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py:418, in _check_differentiability(a, aname, propname)
        ]()[416](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=415)[ if not (isinstance(a, torch.Tensor) and a.requires_grad):
        ]()[417](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=416)[     msg = "Differentiable tensor %s is required to calculate the %s" % (aname, propname)
    --> ]()[418](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=417)[     raise RuntimeError(msg)
    
    RuntimeError: Differentiable tensor atom positions is required to calculate the hessian]()
    

    Expected behavior I expect to be able to run the vibration calculation. If I use the following code from the examples

    import torch
    import dqc
    atomzs = torch.tensor([1, 1])
    atomposs = torch.tensor([[1, 0, 0], [-1, 0, 0]], dtype=torch.double).requires_grad_()
    mol = dqc.Mol(moldesc=(atomzs, atomposs), basis="3-21G")
    qc = dqc.HF(mol).run()
    ene = qc.energy()  # calculate the energy
    print(ene)
    vib = dqc.vibration(qc) # calculate vibrational frequencies
    print(vib)
    

    Then it works. I will note that the requires_grad_() call is necessary, otherwise I get the same error as above. From an API standpoint I think it would be much cleaner if atomposs did not need the requires_grad_() call, but if that was something you did called during the init.

    Desktop (please complete the following information):

    • DQC version: 0.1.0
    • Python version: 3.9
    • PyTorch version: 1.10.2
    • OS: macOS

    Additional context Overall I'm very excited about dqc, you've done a really nice job from what I can tell so far!!

    opened by sofroniewn 4
  • [BUG] Unable to compute ir_spectrum

    [BUG] Unable to compute ir_spectrum

    Describe the bug I am unable to compute the ir_spectrum of a molecule

    To Reproduce Either

    moldesc = 'C          -1.28652        0.25524        0.08013;C           0.07762        0.16535       -0.63495;O           0.22083        0.47033       -1.80613;C           1.24790       -0.33747        0.23567;H          -2.04623        0.61618       -0.60539;H          -1.22080        0.93293        0.92681;H          -1.57890       -0.72292        0.45183;H           1.03268       -1.33368        0.61210;H           2.16265       -0.36812       -0.34714;H           1.39077        0.32217        1.08708'
    efield = torch.tensor([0, 0, 0], dtype=torch.double)
    mol = dqc.Mol(moldesc=moldesc, basis="sto-3g", efield=efield)
    print(len(mol.atomzs))
    hf = dqc.HF(mol).run()
    mol.atompos.requires_grad_()
    ir = dqc.ir_spectrum(hf, freq_unit='cm^-1') # calculate ir spectrum
    

    which gives

    ---------------------------------------------------------------------------
    AssertionError                            Traceback (most recent call last)
    /Users/nsofroniew/Documents/code/chem/molecular_vibrations.ipynb Cell [5](vscode-notebook-cell:/Users/nsofroniew/Documents/code/chem/molecular_vibrations.ipynb#ch0000059?line=4)0' in <module>
          5[ hf = dqc.HF(mol).run()
          ]()[6](vscode-notebook-cell:/Users/nsofroniew/Documents/code/chem/molecular_vibrations.ipynb#ch0000059?line=5)[ mol.atompos.requires_grad_()
    ----> ]()[7](vscode-notebook-cell:/Users/nsofroniew/Documents/code/chem/molecular_vibrations.ipynb#ch0000059?line=6)[ ir = dqc.ir_spectrum(qc, freq_unit='cm^-1')
    
    File ~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py:95, in ir_spectrum(qc, freq_unit, ints_unit)
         ]()[71](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=70)[ def ir_spectrum(qc: BaseQCCalc, freq_unit: Optional[str] = "cm^-1",
         ]()[72](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=71)[                 ints_unit: Optional[str] = "(debye/angst)^2/amu") \
         ]()[73](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=72)[         -> Tuple[torch.Tensor, torch.Tensor]:
         ]()[74](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=73)[     """
         ]()[75](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=74)[     Calculate the frequency and intensity of the IR vibrational spectra.
         ]()[76](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=75)[     Unlike ``vibration``, this method only returns parts where the frequency is
       (...)
         ]()[93](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=92)[         tensor is the IR intensity with the same order as the frequency.
         ]()[94](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=93)[     """
    ---> ]()[95](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=94)[     freq, ir_ints = _ir_spectrum(qc)
         ]()[96](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=95)[     freq = freq_to(freq, freq_unit)
         ]()[97](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=96)[     ir_ints = ir_ints_to(ir_ints, ints_unit)
    
    File ~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py:32, in memoize_method.<locals>.new_fcn(self)
         ]()[30](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py?line=29)[     return self.__dict__[cachename]
         ]()[31](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py?line=30)[ else:
    ---> ]()[32](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py?line=31)[     res = fcn(self)
         ]()[33](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py?line=32)[     self.__dict__[cachename] = res
         ]()[34](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py?line=33)[     return res
    
    File ~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py:303, in _ir_spectrum(qc)
        ]()[301](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=300)[ # get the derivative of dipole moment w.r.t. positions
        ]()[302](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=301)[ with torch.enable_grad():
    --> ]()[303](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=302)[     mu = _edipole(qc)  # (ndim)
        ]()[304](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=303)[ dmu_dr = _jac(mu, atompos)  # (ndim, natoms * ndim)
        ]()[305](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=304)[ dmu_dq = torch.matmul(dmu_dr, normal_modes)  # (ndim, nfreqs)
    
    File ~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py:32, in memoize_method.<locals>.new_fcn(self)
         ]()[30](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py?line=29)[     return self.__dict__[cachename]
         ]()[31](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py?line=30)[ else:
    ---> ]()[32](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py?line=31)[     res = fcn(self)
         ]()[33](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py?line=32)[     self.__dict__[cachename] = res
         ]()[34](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/utils/misc.py?line=33)[     return res
    
    File ~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py:351, in _edipole(qc)
        ]()[349](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=348)[ system = qc.get_system()
        ]()[350](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=349)[ efield = system.efield
    --> ]()[351](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=350)[ assert isinstance(efield, tuple)
        ]()[352](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=351)[ assert len(efield) > 0, "To calculate dipole, the constant electric field must be provided"
        ]()[354](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/dqc/api/properties.py?line=353) # check if the electric field requires grad
    
    AssertionError:
    

    This fails as efield is not a tuple

    or if I leave efield unspecified

    moldesc = 'C          -1.28652        0.25524        0.08013;C           0.07762        0.16535       -0.63495;O           0.22083        0.47033       -1.80613;C           1.24790       -0.33747        0.23567;H          -2.04623        0.61618       -0.60539;H          -1.22080        0.93293        0.92681;H          -1.57890       -0.72292        0.45183;H           1.03268       -1.33368        0.61210;H           2.16265       -0.36812       -0.34714;H           1.39077        0.32217        1.08708'
    mol = dqc.Mol(moldesc=moldesc, basis="sto-3g")
    print(len(mol.atomzs))
    hf = dqc.HF(mol).run()
    mol.atompos.requires_grad_()
    ir = dqc.ir_spectrum(hf, freq_unit='cm^-1') # calculate ir spectrum
    

    I get the same error message.

    Expected behavior I should be able to pass an efield and then compute an ir spectrum (or ideally if I didn't pass one you could take a reasonable default value).

    Desktop (please complete the following information):

    • DQC version: 0.1.0
    • Python version: 3.9
    • PyTorch version: 1.10.2
    • OS: macOS
    opened by sofroniewn 3
  • [BUG] Customized meta-GGA functional

    [BUG] Customized meta-GGA functional

    I tried to run the customized meta-GGA functional by setting dqc.xc.CustomXC.family =4, but it did not work. This is the code:

    
    import torch
    import dqc
    import torch
    import dqc.xc
    import dqc.utils
    
    class MyXC(dqc.xc.CustomXC):
        def __init__(self):
            super().__init__()
    
        @property
        def family(self):
            # 1 for LDA, 2 for GGA, 4 for MGGA
            return 4
    
        def get_edensityxc(self, densinfo):
            scan = dqc.get_xc("MGGA_X_SCAN + MGGA_C_SCAN")
            return scan.get_edensityxc(densinfo)
    
    
    myxc = MyXC()
    
    
    atomzs, atomposs = dqc.parse_moldesc("H -1 0 0; H 1 0 0")
    atomposs = atomposs.requires_grad_()  # mark atomposs as differentiable
    mol = dqc.Mol((atomzs, atomposs), basis="6-311++G(3df,3pd)")
    qc = dqc.KS(mol, xc=myxc, variational=False).run()
    
    

    Then I got the following error message:

    Traceback (most recent call last): File "test_customxc.py", line 29, in qc = dqc.KS(mol, xc=myxc, variational=False).run() File "/usr/local/lib/python3.8/dist-packages/dqc/qccalc/scf_qccalc.py", line 90, in run scp0 = self._engine.dm2scp(dm) File "/usr/local/lib/python3.8/dist-packages/dqc/qccalc/ks.py", line 116, in dm2scp return self.__dm2fock(dm).fullmatrix() File "/usr/local/lib/python3.8/dist-packages/dqc/qccalc/ks.py", line 177, in __dm2fock vxc = self.hamilton.get_vxc(dm) # spin param or tensor (..., nao, nao) File "/usr/local/lib/python3.8/dist-packages/dqc/hamilton/hcgto.py", line 236, in get_vxc potinfo = self.xc.get_vxc(densinfo) # value: (*BD, nr) File "/usr/local/lib/python3.8/dist-packages/dqc/xc/base_xc.py", line 96, in get_vxc raise NotImplementedError("Default vxc for family %d is not implemented" % self.family) NotImplementedError: Default vxc for family 4 is not implemented

    • DQC version: 0.1.0
    • Python version: 3.3
    • PyTorch version: 1.10.1
    • OS: Ubuntu 20.04 LTS
    opened by ml-electron-project 2
  • [BUG] Wrong number of vibrational frequencies

    [BUG] Wrong number of vibrational frequencies

    Describe the bug The number of vibrational frequencies do not correspond to natoms * ndim.

    To Reproduce Steps to reproduce the behavior:

    moldesc = 'C          -1.28652        0.25524        0.08013;C           0.07762        0.16535       -0.63495;O           0.22083        0.47033       -1.80613;C           1.24790       -0.33747        0.23567;H          -2.04623        0.61618       -0.60539;H          -1.22080        0.93293        0.92681;H          -1.57890       -0.72292        0.45183;H           1.03268       -1.33368        0.61210;H           2.16265       -0.36812       -0.34714;H           1.39077        0.32217        1.08708'
    mol = dqc.Mol(moldesc=moldesc, basis="sto-3g")
    print(len(mol.atomzs))
    hf = dqc.HF(mol).run()
    mol.atompos.requires_grad_()
    vib = dqc.vibration(qc, freq_unit='cm^-1') # calculate vibrational frequencies
    print(vib[0].shape, vib[1].shape)
    

    Here I am trying to calculate the vibrational spectrum of acetone, which as 10 atoms in it (I'm using positions I obtained from a previous geometry optimization in PySCF). The output of the above script is

    10
    torch.Size([6]) torch.Size([6, 6])
    

    So I have 10 atoms as expected, but I only have six vibrational frequencies.

    Expected behavior I expect to get 10 * 3 or 30 frequencies (of which 24 should correspond to vibrations).

    Desktop (please complete the following information):

    • DQC version: 0.1.0
    • Python version: 3.9
    • PyTorch version: 1.10.2
    • OS: macOS
    opened by sofroniewn 1
  • [ENH] GPU support

    [ENH] GPU support

    I tried to run the calculation with the device of Mol set to be cuda.

    atomzs, atomposs = dqc.parse_moldesc(atom_positions)
    mol = dqc.Mol((atomzs, atomposs), basis="6-311++G(3df,3pd)", device= torch.device("cuda"))
    qc=dqc.HF(mol, variational=False)
    qc.run()
    

    However, it occurred errors because some internal torch.tensor such as "dm" are not copied to the cuda device. It worked by just modifying them to refer "Mol.device". I found it sped up HF, KS, and especially force calculation.

    I suggest that it would be useful if this modification is officially implemented.

    opened by ml-electron-project 1
  • [BUG] Bug in `optimal_geometry` for KS case

    [BUG] Bug in `optimal_geometry` for KS case

    Describe the bug There is a bug in the optimal_geometry function add in #11 for DFT case

    To Reproduce Steps to reproduce the behavior:

    import dqc
    
    moldesc = "O 0.0000 0.0000 0.2217; H 0.0000 1.4309 -0.8867; H 0.0000 -1.4309 -0.8867" 
    m = dqc.Mol(moldesc, basis="cc-pvdz", grid=4, efield=efield)
    m.atompos.requires_grad_()
    # sys = dqc.HF(m).run() # WORKS
    sys = dqc.KS(m, xc="lda_x+lda_c_pw").run() # DOESN'T WORK
    dqc.optimal_geometry(sys)
    
    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    /Users/nsofroniew/Documents/code/chem/dqc_0.ipynb Cell 24' in <module>
          [6](vscode-notebook-cell:/Users/nsofroniew/Documents/code/chem/dqc_0.ipynb#ch0000030?line=5)[ # sys = dqc.HF(m).run() # WORKS
          ]()[7](vscode-notebook-cell:/Users/nsofroniew/Documents/code/chem/dqc_0.ipynb#ch0000030?line=6)[ sys = dqc.KS(m, xc="lda_x+lda_c_pw").run() # DOESN'T WORK
    ----> ]()[8](vscode-notebook-cell:/Users/nsofroniew/Documents/code/chem/dqc_0.ipynb#ch0000030?line=7)[ dqc.optimal_geometry(sys)
    
    File ~/GitHub/dqc/dqc/api/properties.py:339, in optimal_geometry(qc, length_unit)
        ]()[321](file:///~/GitHub/dqc/dqc/api/properties.py?line=320)[ def optimal_geometry(qc: BaseQCCalc, length_unit: Optional[str] = None) -> torch.Tensor:
        ]()[322](file:///~/GitHub/dqc/dqc/api/properties.py?line=321)[     """
        ]()[323](file:///~/GitHub/dqc/dqc/api/properties.py?line=322)[     Compute the optimal atomic positions of the system.
        ]()[324](file:///~/GitHub/dqc/dqc/api/properties.py?line=323)[ 
       (...)
        ]()[337](file:///~/GitHub/dqc/dqc/api/properties.py?line=336)[         of atoms at the optimal geometry.
        ]()[338](file:///~/GitHub/dqc/dqc/api/properties.py?line=337)[     """
    --> ]()[339](file:///~/GitHub/dqc/dqc/api/properties.py?line=338)[     atompos = _optimal_geometry(qc)
        ]()[340](file:///~/GitHub/dqc/dqc/api/properties.py?line=339)[     atompos = convert_length(atompos, to_unit=length_unit)
        ]()[341](file:///~/GitHub/dqc/dqc/api/properties.py?line=340)[     return atompos
    
    File ~/GitHub/dqc/dqc/utils/misc.py:32, in memoize_method.<locals>.new_fcn(self)
         ]()[30](file:///~/GitHub/dqc/dqc/utils/misc.py?line=29)[     return self.__dict__[cachename]
         ]()[31](file:///~/GitHub/dqc/dqc/utils/misc.py?line=30)[ else:
    ---> ]()[32](file:///~/GitHub/dqc/dqc/utils/misc.py?line=31)[     res = fcn(self)
         ]()[33](file:///~/GitHub/dqc/dqc/utils/misc.py?line=32)[     self.__dict__[cachename] = res
         ]()[34](file:///~/GitHub/dqc/dqc/utils/misc.py?line=33)[     return res
    
    File ~/GitHub/dqc/dqc/api/properties.py:503, in _optimal_geometry(qc)
        ]()[500](file:///~/GitHub/dqc/dqc/api/properties.py?line=499)[     return ene
        ]()[502](file:///~/GitHub/dqc/dqc/api/properties.py?line=501)[ # get the minimal enery position
    --> ]()[503](file:///~/GitHub/dqc/dqc/api/properties.py?line=502)[ minpos = xitorch.optimize.minimize(_get_energy, atompos, method="gd", maxiter=200, 
        ]()[504](file:///~/GitHub/dqc/dqc/api/properties.py?line=503)[                                    step=1e-2)
        ]()[506](file:///~/GitHub/dqc/dqc/api/properties.py?line=505)[ return minpos
    
    File ~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/optimize/rootfinder.py:275, in minimize(fcn, y0, params, bck_options, method, **fwd_options)
        ]()[270](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/optimize/rootfinder.py?line=269)[ # if it is just using the rootfinder algorithm, then the forward function
        ]()[271](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/optimize/rootfinder.py?line=270)[ # is the one that returns only the grad
        ]()[272](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/optimize/rootfinder.py?line=271)[ else:
        ]()[273](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/optimize/rootfinder.py?line=272)[     _fwd_fcn = _rf_fcn
    --> ]()[275](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/optimize/rootfinder.py?line=274)[ return _RootFinder.apply(_rf_fcn, y0, _fwd_fcn, opt_method, fwd_options, bck_options,
        ]()[276](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/optimize/rootfinder.py?line=275)[                          len(params), *params, *pfunc.objparams())
    
    File ~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/optimize/rootfinder.py:302, in _RootFinder.forward(ctx, fcn, y0, fwd_fcn, is_opt_method, options, bck_options, nparams, *allparams)
        ]()[300](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/optimize/rootfinder.py?line=299)[     name = "rootfinder" if not is_opt_method else "minimizer"
        ]()[301](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/optimize/rootfinder.py?line=300)[     method_fcn = get_method(name, methods, method)
    --> ]()[302](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/optimize/rootfinder.py?line=301)[     y = method_fcn(fwd_fcn, y0, params, **config)
        ]()[304](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/optimize/rootfinder.py?line=303)[ ctx.fcn = fcn
        ]()[305](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/optimize/rootfinder.py?line=304)[ ctx.is_opt_method = is_opt_method
    
    File ~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/_impls/optimize/minimizer.py:50, in gd(fcn, x0, params, step, gamma, maxiter, f_tol, f_rtol, x_tol, x_rtol, verbose, **unused)
         ]()[48](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/_impls/optimize/minimizer.py?line=47)[ v = torch.zeros_like(x)
         ]()[49](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/_impls/optimize/minimizer.py?line=48)[ for i in range(maxiter):
    ---> ]()[50](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/_impls/optimize/minimizer.py?line=49)[     f, dfdx = fcn(x, *params)
         ]()[52](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/_impls/optimize/minimizer.py?line=51)[     # update the step
         ]()[53](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/_impls/optimize/minimizer.py?line=52)[     v = (gamma * v - step * dfdx).detach()
    
    File ~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/_core/pure_function.py:34, in PureFunction.__call__(self, *params)
         ]()[33](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/_core/pure_function.py?line=32)[ def __call__(self, *params):
    ---> ]()[34](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/_core/pure_function.py?line=33)[     return self._fcntocall(*params)
    
    File ~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/optimize/rootfinder.py:256, in minimize.<locals>._min_fwd_fcn(y, *params)
        ]()[254](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/optimize/rootfinder.py?line=253)[ with torch.enable_grad():
        ]()[255](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/optimize/rootfinder.py?line=254)[     y1 = y.clone().requires_grad_()
    --> ]()[256](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/optimize/rootfinder.py?line=255)[     z = pfunc(y1, *params)
        ]()[257](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/optimize/rootfinder.py?line=256)[ grady, = torch.autograd.grad(z, (y1,), retain_graph=True,
        ]()[258](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/optimize/rootfinder.py?line=257)[                              create_graph=torch.is_grad_enabled())
        ]()[259](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/optimize/rootfinder.py?line=258)[ return z, grady
    
    File ~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/_core/pure_function.py:34, in PureFunction.__call__(self, *params)
         ]()[33](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/_core/pure_function.py?line=32)[ def __call__(self, *params):
    ---> ]()[34](file:///~/opt/anaconda3/envs/chem/lib/python3.9/site-packages/xitorch/_core/pure_function.py?line=33)[     return self._fcntocall(*params)
    
    File ~/GitHub/dqc/dqc/api/properties.py:498, in _optimal_geometry.<locals>._get_energy(atompos)
        ]()[496](file:///~/GitHub/dqc/dqc/api/properties.py?line=495)[ def _get_energy(atompos: torch.Tensor) -> torch.Tensor:
        ]()[497](file:///~/GitHub/dqc/dqc/api/properties.py?line=496)[     new_system = system.make_copy(moldesc=(system.atomzs, atompos))
    --> ]()[498](file:///~/GitHub/dqc/dqc/api/properties.py?line=497)[     new_qc = qc.__class__(new_system).run()
        ]()[499](file:///~/GitHub/dqc/dqc/api/properties.py?line=498)[     ene = new_qc.energy()  # calculate the energy
        ]()[500](file:///~/GitHub/dqc/dqc/api/properties.py?line=499)[     return ene
    
    TypeError: __init__() missing 1 required positional argument: 'xc']()
    

    Expected behavior The method should work

    Desktop (please complete the following information):

    • DQC version: master
    • Python version: 3.9
    • PyTorch version: 1.10.2
    • OS: macOS

    Additional context I will try and fix and add a test when I get the chance - maybe later tonight or tomorrow depending on timing. Hopefully it will be an easy fix, just looks like something missing from an __init__

    opened by sofroniewn 1
  • Add initial asv benchmarks

    Add initial asv benchmarks

    This PR begins work towards #12 by adding an initial airspeed velocity compatible benchmark. airspeed velocity must be installed and configured to run them.

    Right now it includes just one benchmark file that has benchmarks for both dqc and PySCF. These could be split into two files if preferred.

    I also just include a couple simple energy calculations for two molecules, based this notebook.

    In my mind this PR is really just illustrative to give a sense of what might be possible. We can either continue discussion on what we want to include in #12 or here.

    Here are the results of benchmarks on my 2019 macbook pro

    (chem) laptop:dqc nsofroniew$ asv run -E existing -b TimePySCF
    · virtualenv package not installed
    · Discovering benchmarks
    · Running 2 total benchmarks (1 commits * 1 environments * 2 benchmarks)
    [  0.00%] ·· Benchmarking existing-py_Users_nsofroniew_opt_anaconda3_envs_chem_bin_python
    [ 25.00%] ··· Running (benchmarks.TimePySCF.time_energy_HF--)..
    [ 75.00%] ··· benchmarks.TimePySCF.time_energy_HF                                                                                                                                                         ok
    [ 75.00%] ··· ========== ============
                   molecule
                  ---------- ------------
                     H2O       61.2±2ms
                    C4H5N     1.52±0.01s
                  ========== ============
    
    [100.00%] ··· benchmarks.TimePySCF.time_energy_LDA                                                                                                                                                        ok
    [100.00%] ··· ========== ============
                   molecule
                  ---------- ------------
                     H2O       316±3ms
                    C4H5N     4.78±0.02s
                  ========== ============
    
    (chem) laptop:dqc:dqc nsofroniew$ asv run -E existing -b TimeDQC
    · virtualenv package not installed
    · Discovering benchmarks
    · Running 2 total benchmarks (1 commits * 1 environments * 2 benchmarks)
    [  0.00%] ·· Benchmarking existing-py_Users_nsofroniew_opt_anaconda3_envs_chem_bin_python
    [ 25.00%] ··· Running (benchmarks.TimeDQC.time_energy_HF--).
    [ 50.00%] ··· Running (benchmarks.TimeDQC.time_energy_LDA--).
    [ 75.00%] ··· benchmarks.TimeDQC.time_energy_HF                                                                                                                                                           ok
    [ 75.00%] ··· ========== ===========
                   molecule
                  ---------- -----------
                     H2O       63.4±1ms
                    C4H5N     16.0±0.3s
                  ========== ===========
    
    [100.00%] ··· benchmarks.TimeDQC.time_energy_LDA                                                                                                                                                          ok
    [100.00%] ··· ========== ============
                   molecule
                  ---------- ------------
                     H2O       414±4ms
                    C4H5N     19.9±0.08s
                  ========== ============
    
    opened by sofroniewn 5
  • [ENH] Performance/ Benchmarking/ Scaling

    [ENH] Performance/ Benchmarking/ Scaling

    Is your feature request related to a problem? Please describe. This is maybe more of a question than a feature request - but it could turn into one.

    I saw you've got one of two files in the repo around benchmarks - like time_forward.py - but I was wondering if you have done or are interested in doing more widespread and systematic benchmarking - particularly with respect to how performance scales with variables like number of atoms for different basis sets on cpu and gpu.

    I'm wondering how you expect performance to compare to a library like PySCF just knowing the architecture of dqc? I'm also curious if performance / scale we're things you were interested in or even motivated by when developing dqc too?

    I havn't tried any comparisons yet and don't really know enough about the actual implementations to have any expectations one way or another. There is a little bit of PySCF benchmark data that could be compared to, or we could compute our own.

    Ideally I'd like to push to as large systems as possible, but I am so new to this space that I'm really not sure what is possible. If I could do things on the scale of amino acids (~20 atoms) that would be a nice start - getting to ~100 atoms would be even better, and so it continues!

    Describe the solution you'd like I could imagine developing a benchmarking suite of both basic calculations and calculations of properties (like IR spectra) and a set of molecules of increasing size and then measuring calculation time for a variety of different basis sets and hardware configurations, cpu/ gpu. The goal would be to assess performance as molecule size increased.

    Describe alternatives you've considered I could do ad-hoc testing using basic timing functionality to try and build up an intuitive feel for scaling performance

    Additional context If this was something you were interested in I'd appreciate your help in designing the best approach to benchmarking as I am so new to this space.

    If benchmarking is successful one can then start doing profiling to try and identify performance gaps and ultimately work on improving performance

    opened by sofroniewn 4
A library for using chemistry in your applications

Chemistry in python Resources Used The following items are not made by me! Click the words to go to the original source Periodic Tab Json -> Used in -

Tech Penguin 28 Dec 17, 2021
UMT is a unified and flexible framework which can handle different input modality combinations, and output video moment retrieval and/or highlight detection results.

Unified Multi-modal Transformers This repository maintains the official implementation of the paper UMT: Unified Multi-modal Transformers for Joint Vi

Applied Research Center (ARC), Tencent PCG 84 Jan 4, 2023
Moment-DETR code and QVHighlights dataset

Moment-DETR QVHighlights: Detecting Moments and Highlights in Videos via Natural Language Queries Jie Lei, Tamara L. Berg, Mohit Bansal For dataset de

Jie Lei 雷杰 133 Dec 22, 2022
CVPR '21: In the light of feature distributions: Moment matching for Neural Style Transfer

In the light of feature distributions: Moment matching for Neural Style Transfer (CVPR 2021) This repository provides code to recreate results present

Nikolai Kalischek 49 Oct 13, 2022
Automatic Differentiation Multipole Moment Molecular Forcefield

Automatic Differentiation Multipole Moment Molecular Forcefield Performance notes On a single gpu, using waterbox_31ang.pdb example from MPIDplugin wh

null 4 Jan 7, 2022
[2021 MultiMedia] CONQUER: Contextual Query-aware Ranking for Video Corpus Moment Retrieval

CONQUER: Contexutal Query-aware Ranking for Video Corpus Moment Retreival PyTorch implementation of CONQUER: Contexutal Query-aware Ranking for Video

Hou zhijian 23 Dec 26, 2022
Differentiable Neural Computers, Sparse Access Memory and Sparse Differentiable Neural Computers, for Pytorch

Differentiable Neural Computers and family, for Pytorch Includes: Differentiable Neural Computers (DNC) Sparse Access Memory (SAM) Sparse Differentiab

ixaxaar 302 Dec 14, 2022
This YoloV5 based model is fit to detect people and different types of land vehicles, and displaying their density on a fitted map, according to their coordinates and detected labels.

This YoloV5 based model is fit to detect people and different types of land vehicles, and displaying their density on a fitted map, according to their

Liron Bdolah 8 May 22, 2022
Numenta Platform for Intelligent Computing is an implementation of Hierarchical Temporal Memory (HTM), a theory of intelligence based strictly on the neuroscience of the neocortex.

NuPIC Numenta Platform for Intelligent Computing The Numenta Platform for Intelligent Computing (NuPIC) is a machine intelligence platform that implem

Numenta 6.3k Dec 30, 2022
Numenta Platform for Intelligent Computing is an implementation of Hierarchical Temporal Memory (HTM), a theory of intelligence based strictly on the neuroscience of the neocortex.

NuPIC Numenta Platform for Intelligent Computing The Numenta Platform for Intelligent Computing (NuPIC) is a machine intelligence platform that implem

Numenta 6.2k Feb 12, 2021
This repository builds a basic vision transformer from scratch so that one beginner can understand the theory of vision transformer.

vision-transformer-from-scratch This repository includes several kinds of vision transformers from scratch so that one beginner can understand the the

null 1 Dec 24, 2021
Drone-based Joint Density Map Estimation, Localization and Tracking with Space-Time Multi-Scale Attention Network

DroneCrowd Paper Detection, Tracking, and Counting Meets Drones in Crowds: A Benchmark. Introduction This paper proposes a space-time multi-scale atte

VisDrone 98 Nov 16, 2022
Details about the wide minima density hypothesis and metrics to compute width of a minima

wide-minima-density-hypothesis Details about the wide minima density hypothesis and metrics to compute width of a minima This repo presents the wide m

Nikhil Iyer 9 Dec 27, 2022
Estimation of human density in a closed space using deep learning.

Siemens HOLLZOF challenge - Human Density Estimation Add project description here. Installing Dependencies: Install Python3 either system-wide, user-w

null 3 Aug 8, 2021
SMD-Nets: Stereo Mixture Density Networks

SMD-Nets: Stereo Mixture Density Networks This repository contains a Pytorch implementation of "SMD-Nets: Stereo Mixture Density Networks" (CVPR 2021)

Fabio Tosi 115 Dec 26, 2022
PyTorch implementations of algorithms for density estimation

pytorch-flows A PyTorch implementations of Masked Autoregressive Flow and some other invertible transformations from Glow: Generative Flow with Invert

Ilya Kostrikov 546 Dec 5, 2022
MADE (Masked Autoencoder Density Estimation) implementation in PyTorch

pytorch-made This code is an implementation of "Masked AutoEncoder for Density Estimation" by Germain et al., 2015. The core idea is that you can turn

Andrej 498 Dec 30, 2022
This program presents convolutional kernel density estimation, a method used to detect intercritical epilpetic spikes (IEDs)

Description This program presents convolutional kernel density estimation, a method used to detect intercritical epilpetic spikes (IEDs) in [Gardy et

Ludovic Gardy 0 Feb 9, 2022
Official code of the paper "Expanding Low-Density Latent Regions for Open-Set Object Detection" (CVPR 2022)

OpenDet Expanding Low-Density Latent Regions for Open-Set Object Detection (CVPR2022) Jiaming Han, Yuqiang Ren, Jian Ding, Xingjia Pan, Ke Yan, Gui-So

csuhan 64 Jan 7, 2023