pyscf / gpu4pyscf

A plugin to use Nvidia GPU in PySCF package
GNU General Public License v3.0
141 stars 25 forks source link

UKS density fitting gradient problem #223

Open baopengbp opened 1 month ago

baopengbp commented 1 month ago

For small molecules, the UKS density fitting gradient is OK. There is a problem of UKS density fitting gradient when I compute T1 state of PXZ-DPS. The direct SCF is OK.

import time import pyscf from pyscf.geomopt.geometric_solver import optimize from gpu4pyscf.dft import uks

atom = ''' O +0.285437 -4.158343 -1.632910 S +0.230926 -3.572487 -0.284556 O +0.267242 -4.402410 +0.929598 C -1.261603 -2.562902 -0.199664 C -1.826445 -2.281078 +1.045687 C -2.973056 -1.491629 +1.107457 C -3.554131 -1.000794 -0.068718 N -4.729283 -0.193145 -0.000034 C -4.640771 +1.208548 -0.146767 C -3.430281 +1.876262 -0.362100 C -3.393085 +3.267620 -0.498501 C -4.563859 +4.014070 -0.416526 C -5.778681 +3.359783 -0.191313 C -5.814869 +1.979404 -0.055388 O -7.049528 +1.409454 +0.181427 C -7.128768 +0.036190 +0.304534 C -8.390286 -0.501583 +0.515176 C -8.553959 -1.884360 +0.640237 C -7.441461 -2.713968 +0.545168 C -6.170448 -2.171222 +0.331657 C -5.992092 -0.788446 +0.217106 C -2.986770 -1.308869 -1.311579 C -1.833953 -2.088990 -1.381507 C +1.582607 -2.384116 -0.161074 C +2.092824 -1.805784 -1.324951 C +3.129600 -0.880169 -1.224150 C +3.656852 -0.547631 +0.030172 N +4.718807 +0.401567 +0.129316 C +6.045702 +0.021726 -0.171840 C +6.399375 -1.283509 -0.529908 C +7.728181 -1.612246 -0.816074 C +8.724032 -0.643817 -0.742912 C +8.384707 +0.661758 -0.375571 C +7.066115 +0.987218 -0.092130 O +6.811949 +2.294113 +0.275159 C +5.512721 +2.654506 +0.571060 C +5.297004 +3.976122 +0.934312 C +4.007033 +4.422013 +1.237474 C +2.943197 +3.528792 +1.166631 C +3.161207 +2.196814 +0.800240 C +4.448525 +1.735795 +0.504209 C +3.147228 -1.150993 +1.186608 C +2.103668 -2.070407 +1.095472 H -1.380310 -2.686415 +1.947647 H -3.429702 -1.254793 +2.063372 H -2.510236 +1.306253 -0.422062 H -2.438273 +3.756918 -0.667348 H -4.543268 +5.094304 -0.522267 H -6.714066 +3.905063 -0.113910 H -9.232681 +0.180254 +0.576377 H -9.543644 -2.298454 +0.806211 H -7.547883 -3.791180 +0.632326 H -5.312597 -2.829089 +0.251726 H -3.458152 -0.937827 -2.216294 H -1.396909 -2.353523 -2.338490 H +1.691399 -2.089194 -2.292115 H +3.541925 -0.413711 -2.113434 H +5.633620 -2.048948 -0.583442 H +7.971683 -2.633693 -1.092955 H +9.757611 -0.891531 -0.963938 H +9.131961 +1.445495 -0.300399 H +6.153619 +4.641790 +0.971286 H +3.845981 +5.457249 +1.521843 H +1.932732 +3.856216 +1.393217 H +2.323315 +1.511432 +0.743362 H +3.577920 -0.897804 +2.150333 H +1.714440 -2.561770 +1.980825 '''

mol = pyscf.M(atom=atom, spin=2, verbose=4, basis='def2-svp') mf_GPU = uks.UKS(mol, xc='pbe0').density_fit()

mf_GPU.disp = 'd3bj'

mf_GPU.grids.level = 3 mf_GPU.conv_tol = 1e-10 mf_GPU.max_cycle = 50

gradients = [] def callback(envs): gradients.append(envs['gradients'])

start_time = time.time() mol_eq = optimize(mf_GPU, maxsteps=50, callback=callback) print("Optimized coordinate:") print(mol_eq.atom_coords()) print('geometry optimization took', time.time() - start_time, 's')

The first DF gradient is: converged SCF energy = -2191.1017687459 <S^2> = 2.018467 2S+1 = 3.0122862 --------------- DFUKS_Scanner gradients --------------- x y z 0 O 0.0074075928 -0.0503701331 -0.1719910994 1 S 0.0040317954 -0.0463937330 0.0015015689 2 O 0.0015702868 -0.0801459516 0.1535435516 3 C 0.0802308384 -0.0293312424 0.0052545674 4 C -0.0194108000 0.0360821960 -0.0209733619 5 C 0.0037590661 -0.0143464518 0.0094371372 6 C -0.1147167540 0.0811413498 -0.0044039285 7 N 0.0467878655 -0.0258417215 -0.0045235079 8 C 0.0267182992 -0.0434278328 -0.0034430772 9 C -0.0183804654 0.0733211379 -0.0061551308 10 C 0.0018592585 -0.0010985513 -0.0004807828 11 C 0.0058123946 0.0384863958 -0.0051844576 12 C 0.0379732540 0.0105343296 -0.0054599896 13 C -0.0159434997 -0.0239168028 0.0062611757 14 O -0.1389620408 0.0960588850 0.0124048450 15 C 0.0200882968 0.0147833717 -0.0051837819 16 C -0.0065348166 -0.0286815671 0.0024679537 17 C -0.0282689082 -0.0148146968 0.0046516281 18 C -0.0015123931 -0.0009493365 0.0013643065 19 C -0.0734410099 -0.0264017982 0.0118577282 20 C 0.0432248562 -0.0144950575 -0.0022850391 21 C 0.0181673027 -0.0165785283 0.0160831174 22 C -0.0379605328 0.0240640691 0.0047592392 23 C -0.0983847779 -0.0459888622 -0.0166751323 24 C 0.0254661277 0.0404841340 0.0040395884 25 C -0.0204965652 -0.0250883116 0.0215996992 26 C 0.1157057969 0.0894194189 -0.0061293362 27 N -0.0535343579 -0.0208546606 0.0156041026 28 C -0.0637138136 -0.0258228584 -0.0027358795 29 C 0.0902193783 -0.0399946056 -0.0199638283 30 C -0.0486303048 0.0264612128 0.0129992616 31 C 0.0902421292 -0.0392002973 -0.0220331589 32 C -0.0165067011 -0.0395580200 -0.0061180450 33 C -0.0013079658 0.0054221589 0.0033991221 34 O 0.1391237316 0.1138225607 0.0078804042 35 C 0.0352604310 -0.0314912922 -0.0196584156 36 C -0.0381633480 0.0101944878 0.0087992262 37 C -0.0085275428 0.0212763993 0.0072661771 38 C -0.0112760363 0.0123768284 0.0057945253 39 C 0.0144640296 0.0737962720 0.0189795611 40 C -0.0070867268 -0.0194548755 -0.0030321733 41 C -0.0194678643 -0.0181957506 -0.0181578436 42 C 0.0443685354 0.0328341163 0.0102553187 43 H 0.0429839580 -0.0346677751 0.0778138044 44 H -0.0303236695 0.0164181285 0.0697499481 45 H 0.0780892394 -0.0510984559 -0.0040445547 46 H 0.0596996149 0.0232971339 -0.0095224399 47 H 0.0024405730 0.0531711682 -0.0050154021 48 H -0.0520481668 0.0304546703 0.0042639604 49 H -0.0433026077 0.0350983541 0.0033698180 50 H -0.0449383523 -0.0197625124 0.0077542623 51 H -0.0003922228 -0.0572015427 0.0039961452 52 H 0.0712166541 -0.0483077630 -0.0067564397 53 H -0.0295241753 0.0259953636 -0.0624230344 54 H 0.0434795801 -0.0228706507 -0.0813219565 55 H -0.0379667294 -0.0238553072 -0.0874196004 56 H 0.0282729418 0.0342562643 -0.0672397236 57 H -0.0695257650 -0.0473753486 -0.0010689875 58 H -0.0002752048 -0.0387971245 -0.0105449873 59 H 0.0409643134 -0.0099092389 -0.0090965931 60 H 0.0418629297 0.0427952386 0.0039020976 61 H 0.0447567651 0.0344602075 0.0017526412 62 H -0.0098864992 0.0522136486 0.0144307813 63 H -0.0642553635 0.0142715942 0.0122937144 64 H -0.0727871638 -0.0636377303 -0.0069593920 65 H 0.0289963256 0.0189154691 0.0726663106 66 H -0.0377910165 -0.0419801772 0.0778037916

cycle 1: E = -2191.10176875 dE = -2191.1 norm(grad) = 0.634282

The first direct SCF gradient is: converged SCF energy = -2191.10167913584 <S^2> = 2.0184678 2S+1 = 3.0122867 --------------- UKS_Scanner gradients --------------- x y z 0 O 0.0000589797 -0.0020283862 -0.0044643884 1 S 0.0023232417 -0.0234694406 -0.0022217418 2 O -0.0000798197 -0.0028428101 0.0039975683 3 C -0.0292135918 0.0251439531 0.0020938915 4 C 0.0176947792 -0.0126095710 -0.0082209816 5 C -0.0138355558 0.0093479746 -0.0050732578 6 C 0.0074208103 -0.0053285710 -0.0002892279 7 N 0.0101116936 -0.0069052585 -0.0005936181 8 C 0.0047754503 0.0204218459 -0.0029803329 9 C -0.0022485576 -0.0086507975 0.0011871361 10 C 0.0019317294 0.0110313397 -0.0013287699 11 C 0.0072377519 0.0057377319 -0.0013898621 12 C -0.0052670010 -0.0020981272 0.0007884839 13 C 0.0180831883 0.0028248569 -0.0023242172 14 O -0.0169069268 0.0115053446 0.0018625539 15 C 0.0039939138 -0.0177333374 0.0003265314 16 C -0.0000669306 0.0057102593 -0.0004549480 17 C -0.0027104704 -0.0090173251 0.0009209961 18 C -0.0095573359 -0.0057562032 0.0017524748 19 C 0.0073325479 0.0050546262 -0.0016888093 20 C -0.0168259578 -0.0117877542 0.0037000098 21 C -0.0152754499 0.0063152947 0.0064387731 22 C 0.0179713610 -0.0133860071 0.0059748331 23 C 0.0247647732 0.0277988136 0.0030211265 24 C -0.0152698229 -0.0153873793 0.0049255202 25 C 0.0121391512 0.0093356275 0.0061492144 26 C -0.0062746949 -0.0056216626 -0.0010573771 27 N -0.0089202957 -0.0083418948 0.0000634973 28 C 0.0178370474 -0.0083042255 -0.0054659610 29 C -0.0078137783 0.0033436497 0.0022347806 30 C 0.0098710979 -0.0041620596 -0.0025322538 31 C 0.0038699142 -0.0080439797 -0.0024335022 32 C -0.0004816722 0.0055205111 0.0014096873 33 C -0.0016501936 -0.0173621737 -0.0036462913 34 O 0.0151404677 0.0133389271 0.0009830687 35 C -0.0180011822 0.0000727207 0.0022602012 36 C 0.0055467872 -0.0010364757 -0.0010081883 37 C -0.0076877197 0.0044349570 0.0021473454 38 C -0.0034433276 0.0100056842 0.0030486470 39 C 0.0029653646 -0.0078707215 -0.0025169260 40 C -0.0071010064 0.0185879786 0.0058874925 41 C 0.0136287924 0.0088034167 -0.0041662572 42 C -0.0156137721 -0.0137375742 -0.0080674338 43 H -0.0014838248 0.0024453439 -0.0038018287 44 H 0.0017180287 -0.0004499344 -0.0051747528 45 H -0.0030067918 0.0044371839 0.0001178975 46 H -0.0036014867 -0.0016666619 0.0006404832 47 H 0.0000849892 -0.0042854289 0.0004001802 48 H 0.0036835282 -0.0020841253 -0.0004145359 49 H 0.0032796221 -0.0027076167 -0.0001373006 50 H 0.0039668085 0.0015222847 -0.0006302233 51 H 0.0002339378 0.0040557235 -0.0002551677 52 H -0.0051850560 0.0012939599 0.0004864194 53 H 0.0019504105 -0.0009659681 0.0050344690 54 H -0.0013305502 0.0020356480 0.0041500510 55 H 0.0012317026 0.0018973455 0.0041948574 56 H -0.0016248589 -0.0016314137 0.0049236994 57 H 0.0049101551 0.0020376353 -0.0001556143 58 H -0.0007634216 0.0038842146 0.0009841493 59 H -0.0041224436 0.0008704182 0.0008375188 60 H -0.0028947499 -0.0030953583 -0.0003928794 61 H -0.0033938971 -0.0025675882 -0.0000473094 62 H 0.0004794815 -0.0041332023 -0.0011082054 63 H 0.0037949352 -0.0010735427 -0.0008312491 64 H 0.0024281998 0.0046860346 0.0006941415 65 H -0.0018626594 -0.0003046733 -0.0051060953 66 H 0.0010541608 0.0029459449 -0.0036581919

cycle 1: E = -2191.10167914 dE = -2191.1 norm(grad) = 0.113575

wxj6000 commented 1 month ago

The issue has been fixed in https://github.com/pyscf/gpu4pyscf/pull/226