Rafael-G-C / pyDFTD3

Python version of Grimme's D3-dispersion correction for Gaussian input/output
http://www.patonlab.com
MIT License
3 stars 1 forks source link

Some gradient #11

Closed Rafael-G-C closed 3 years ago

Rafael-G-C commented 3 years ago

@bast here's the code that returns the error

TypeError: Gradient only defined for scalar-output functions. Output was [array(0.), array(0.), array(0.), array(0.), array(0.), array(0.), array(0.), array(0.), array(0.), array(0.)].

just run the test as python3 -m pytest tests/ in the pyDFTD3 folder on line 93 in test_CO2H2_2.py "2" is the hessian d3_dervs = D3_derivatives(charges,functional,damping,2,coordinates)

bast commented 3 years ago

And what we want to find out is: why is the output a list instead of a float?

Rafael-G-C commented 3 years ago

Yes, and now that I look at it why it a list zeros

bast commented 3 years ago

I think the code fails because the first element in variables here is an array of charges (see here). I think this is some leftover?

Rafael-G-C commented 3 years ago

Okey, might be let's see what's happens when I fix it

bast commented 3 years ago

Also in the test I would not start by cycling through all derivatives but start only with very few elements. It takes time to cycle through all of them and right now we will be very happy if already 1 or 2 work which takes a fraction.

Rafael-G-C commented 3 years ago

I see so stopping the derivative order loop earlier

Rafael-G-C commented 3 years ago

Alright the code can now: get the gradient, hessian, 3rds and 4rds of the sum of the r6, r8 and repulse interactions in kcal this line derivative_orders = list(derivative_orders)[0:1] is used to cut off the list of derivative orders so we have control of how many we want

bast commented 3 years ago

This sounds fantastic!

robertodr commented 3 years ago

Really great Rafael, apologies for tardiness, I didn't get email notifications for these changes... I'll try to fix the conflicts with the base branch and get a test going.

robertodr commented 3 years ago

OK, so:

robertodr commented 3 years ago

A word of warning: the gradient test is pretty slow.

robertodr commented 3 years ago

The tests should hopefully run slightly faster now (I've removed one of the parametrization levels for the gradient test)

I have also reorganized a bit the code to make it easier (hopefully!) for @ringholm to run the numdiff tests:

  1. To run a n order derivative calculation:
    python -m dftd3.dftd3 --damp zero --order 1 examples/formic_acid_dimer.com
  2. This outputs the energy to screen and writes a JSON file with the full input and full output (including the gradient). In Python, you can load the gradient with:

    import json
    
    import numpy as np
    
    with open("formic_acid_dimer.json", "r") as f:
           data = json.load(f)
    
    gradient = np.array(data["formic_acid_dimer"]["output"]["1-st order geometric derivative"])
robertodr commented 3 years ago

Merging so that @ringholm can try the numerical differentiation stuff before the next meeting.