Calling fortran routine from python: In the case of orbital conversion from PySCF to GAMESS

Unfortunately the definition of MO(Molecular Orbitals) depends on the particular program. Therefore , the MO format of PySCF is different from that of GAMESS. For example, in the case of Carbon atom with 6-31G* basis set, we need to rearrange the sequence of AO for each MO coefficients as

# For the Second Row atoms with the 6-31G* basis set case
#
# We should transform the Second Row Elemenents as
#
# PySCF  -->   GAMESS
#   1s   -->     1s
#   2s   -->     2s
#   3s   -->     2px
#   2px  -->     2py
#   2py  -->     2pz
#   2pz  -->     3s
#   3px  -->     3px
#   3py  -->     3py
#   3pz  -->     3pz
#   3dxx -->     3dxx
#   3dxy -->     3dyy
#   3dxz -->     3dzz
#   3dyy -->     3dxy
#   3dyz -->     3dxz
#   3dzz -->     3dyz
#

This post will show you how to 
1) perform PySCF calculation to obtain MO
2) transform the MO into GAMESS format
3) write the GAMESS formatted MO into $VEC format of GAMESS

I created two files of my_fortran_lib.f90 and mo_write.py.

STEP1: The my_fortran_lib.f90
I created the my_fortran_lib.f90 file as /bighome/cchoi/python/f2py_examples/my_fortran_lib.f90

The most important part of above f90 file is the 
!f2py intent(in) :: V
!f2py intent(hide), depend(V) :: N = shape(V, 0)
!f2py intent(hide), depend(V) :: M = shape(V, 1)
, which tell the f2py compiler the properties of arguments.

STEP2: Creating my_fortran_lib.f90.so 
f2py -c -m my_fortran_lib my_fortran_lib.f90
mv my_fortran_lib.cpython-36m-x86_64-linux-gnu.so my_fortran_lib.so

STEP3: Python script to perform MO calculation, transform MO to GAMESS format and write into $VEC format of GAMESS is save at /bighome/cchoi/python/f2py_examples/mo_write.py

In this python script, I perform ROHF/6-31G* on C6H6 molecule.
To run it,
python3 mo_write.py




An Example MO comparisons below
C6H6, 6-31G*

PYSCF
tools.dump_mat.dump_mo(mol,mf.mo_coeff,ncol=5, digits=12)

                      #0               #1               #2               #3               #4              
 1  C 1s       0.404602815312   0.539492964624  -0.200251307495   0.527641961409  -0.226794255663
 2  C 2s       0.011002964225   0.014989929979  -0.005565752036   0.014774365929  -0.006352615263
 3  C 3s      -0.002164336475  -0.004656560882   0.001746255706  -0.008905084425   0.003882904172
 4  C 2px      0.000017342465  -0.000011247309   0.000124138016  -0.000153565231  -0.000044952814
 5  C 2py      0.000025016703  -0.000098195210  -0.000049651871  -0.000127503063   0.000135768050
 6  C 2pz      0.000001848030  -0.000006497526  -0.000001385442  -0.000010447633   0.000008095902
 7  C 3px     -0.000183133329  -0.000220118818  -0.000995056256   0.001280539534   0.000515145154
 8  C 3py     -0.000262181125   0.000436936738   0.000605848800   0.000945899767  -0.001213499883
 9  C 3pz     -0.000019486291   0.000024929055   0.000024502476   0.000079409843  -0.000070558581
10  C 3dxx    -0.000583288954  -0.000718831736   0.000254202432  -0.000388737823   0.000243031143
11  C 3dxy     0.000021397168  -0.000043958673   0.000008662637  -0.000163012274   0.000120343225
12  C 3dxz     0.000004189709   0.000000496402  -0.000001026503   0.000000433168   0.000005271551
13  C 3dyy    -0.000576454206  -0.000724816633   0.000281020851  -0.000503940716   0.000139079078
14  C 3dyz     0.000013662873   0.000013306761  -0.000003441211   0.000031169150  -0.000022559762
15  C 3dzz    -0.000679907473  -0.000832863680   0.000308719650  -0.000763614205   0.000327287978


GAMESS
$VEC group
--- CLOSED SHELL ORBITALS --- GENERATED AT Sun Nov 24 12:21:34 2019
C6H6
E(RHF)=     -230.7014406537, E(NUC)=  203.6561332056,    8 ITERS
 $VEC
 1  1 4.03662569E-01 1.09768900E-02 1.71000390E-05 2.53679058E-05 1.86739605E-06
 1  2-2.15647406E-03-1.80350318E-04-2.64516765E-04-1.95959502E-05-9.22684909E-04
 1  3-9.11918148E-04-1.07559254E-03 1.96667789E-05 3.83578791E-06 1.24818727E-05
 1  4 4.00709557E-01 1.08951828E-02-1.28376628E-05 2.81320431E-05 1.62813294E-06
 1  5-2.14001481E-03 1.31053028E-04-2.88328235E-04-1.66844589E-05-9.22851667E-04
 1  6-8.98559165E-04-1.06827729E-03-1.54591171E-05 1.44830678E-06 1.24450265E-05
 1  7 4.08210462E-01 1.11032947E-02 3.01164333E-05-1.92307448E-06 3.32912958E-07
 1  8-2.19354078E-03-3.16674180E-04 2.22437893E-05-3.23375839E-06-9.09750575E-04
 1  9-9.45595846E-04-1.08692279E-03-4.69215518E-06 2.69383664E-06 1.04588714E-05
 1 10 4.01983444E-01 1.09301591E-02-3.10251274E-05 4.58236755E-06-1.61278263E-07
 1 11-2.12588194E-03 3.23011049E-04-4.59513673E-05 1.72302292E-06-8.96766003E-04
 1 12-9.33878638E-04-1.07208574E-03-4.22677519E-06 2.67743832E-06 1.02569775E-05
 1 13 4.12299057E-01 1.12166267E-02 1.23200189E-05-2.66278724E-05-1.49668307E-06
 1 14-2.22607102E-03-1.32776337E-04 2.89132579E-04 1.65308215E-05-9.47772699E-04
 1 15-9.24326964E-04-1.09677655E-03-1.52774411E-05 1.55515039E-06 1.26101453E-05
 1 16 4.10553472E-01 1.11686795E-02-1.83584972E-05-2.27665530E-05-1.76569836E-06
 1 17-2.23023803E-03 1.92885502E-04 2.44072389E-04 1.85993826E-05-9.36707584E-04
 1 18-9.25508197E-04-1.09214461E-03 1.87820366E-05 3.85385534E-06 1.27224721E-05
 1 19-1.02709148E-04 8.14432927E-04-1.02116956E-04 8.08992438E-04-1.03931450E-04
 1 20 8.20862692E-04-1.02507486E-04 8.12025598E-04-1.04697148E-04 8.28140544E-04
 1 21-1.04246085E-04 8.24292408E-04

in log file
                      1          2          3          4          5
                  -11.2340   -11.2335   -11.2335   -11.2322   -11.2322
                     A          A          A          A          A
    1  C  1  S    0.403663   0.541513  -0.195857   0.526161  -0.229374
    2  C  1  S    0.010977   0.015046  -0.005444   0.014732  -0.006425
    3  C  1  X    0.000017  -0.000012   0.000124  -0.000153  -0.000044
    4  C  1  Y    0.000025  -0.000098  -0.000050  -0.000127   0.000136
    5  C  1  Z    0.000002  -0.000006  -0.000001  -0.000010   0.000008
    6  C  1  S   -0.002156  -0.004670   0.001706  -0.008858   0.003938
    7  C  1  X   -0.000180  -0.000214  -0.000995   0.001275   0.000506
    8  C  1  Y   -0.000265   0.000432   0.000609   0.000931  -0.001225
    9  C  1  Z   -0.000020   0.000025   0.000025   0.000078  -0.000071
   10  C  1 XX   -0.000923  -0.001144   0.000394  -0.000615   0.000388
   11  C  1 YY   -0.000912  -0.001154   0.000436  -0.000798   0.000224
   12  C  1 ZZ   -0.001076  -0.001326   0.000479  -0.001208   0.000525
   13  C  1 XY    0.000020  -0.000040   0.000008  -0.000149   0.000111
   14  C  1 XZ    0.000004   0.000000  -0.000001   0.000000   0.000005

   15  C  1 YZ    0.000012   0.000012  -0.000003   0.000028  -0.000021

Comments

Popular posts from this blog

The ROHF of GAMESS for TDDFT calculation

Improving SCF convergency of DFT

Fortran compilation on Linux