aoterodelaroza / critic2

Analysis of quantum chemical interactions in molecules and solids.
Other
97 stars 35 forks source link

pointprops issue in json file #45

Closed wutobias closed 3 years ago

wutobias commented 3 years ago

Hi,

when generating a json output from auto with multiple POINTPROP defined, the json file is not correctly formatted.

For example:

molecule molecule.fchk
load molecule.fchk id wfn

reference wfn
POINTPROP gtf
POINTPROP vtf
POINTPROP htf

auto
CPREPORT verylong
CPREPORT molecule.json verylong

Will generate a pointprops section in the json file that looks like this:

      "pointprops": [{
        "id": 1,
        "name": "gtf",
        "expression": "gtf(1)",
        "value": 3.10546301922625E-01,
        "id": 2,
        "name": "vtf",
        "expression": "vtf(1)",
        "value": -7.45231180724215E-01,
        "id": 3,
        "name": "htf",
        "expression": "htf(1)",
        "value": -4.34684878801590E-01
        }

When it should look like this:

      "pointprops": [{
        "id": 1,
        "name": "gtf",
        "expression": "gtf(1)",
        "value": 3.10546301922625E-01
        },{
        "id": 2,
        "name": "vtf",
        "expression": "vtf(1)",
        "value": -7.45231180724215E-01
        },{
        "id": 3,
        "name": "htf",
        "expression": "htf(1)",
        "value": -4.34684878801590E-01
        },{

I think it can be solved rewriting lines 1819 onwards in autocp@proc.f90 like this (basically just inserting the brackets):

          do ip = 1, sy%npropp
             if (sy%propp(ip)%ispecial == 0) then
                fres = sy%eval(sy%propp(ip)%expr,.true.,iok,xp)
                write (lu,'(A,"      ""id"": ",A,",")') prfx, string(ip)
                write (lu,'(A,"      ""name"": """,A,""",")') prfx, string(sy%propp(ip)%name)
                write (lu,'(A,"      ""expression"": """,A,""",")') prfx, string(sy%propp(ip)%expr)
                write (lu,'(A,"      ""value"": ",A)') prfx, string(fres,'e',decimal=14)
                if (ip == ilast) then
                   write (lu,'(A,"    }],")') prfx
                else
                   write (lu,'(A,"      },{")') prfx
                end if
             endif
          end do

Regards, Tobias

aoterodelaroza commented 3 years ago

Since this is the nth time this happens already, I've decided to rip the band-aid off and do it properly. I've pushed a new branch "json" to the repo that incorporates a copy of the json-fortran library and uses it to write the json files (the one coming out of the integration and the one from CPREPORT). The json-fortran library does not seem to support arrays of arrays so any n>1-dimensional array has been converted into a vector (in Fortran order). Besides this and a few cosmetic changes, it should be more or less the same as before. Could you please pull it and see how it works for you? I've also implemented writing the stress tensor info. The code still needs more testing and a thorough read before merging.

aoterodelaroza commented 3 years ago

@mkhorton @bjoe2k4 @samblau This may be of interest to you as well. I don't want to break anyone's code once it is merged with the master branch.

mkhorton commented 3 years ago

Thank you for the notification @aoterodelaroza !

wutobias commented 3 years ago

Thanks @aoterodelaroza ! It seems to work like a charm. I see the json files are now formatted correctly and the stress tensor is in them. I compared a few of the values in the json files coming from the old and new code and they seem to match.

aoterodelaroza commented 3 years ago

Sounds good! I'll wait a few days to run some tests and make sure everything is correct, and that way everyone can check the impact on their code, then merge with master.

mkhorton commented 3 years ago

The json-fortran library does not seem to support arrays of arrays so any n>1-dimensional array has been converted into a vector (in Fortran order).

This is an unfortunate limitation, I don't think it'll be too hard to update my own code to support this however.

aoterodelaroza commented 3 years ago

OK, I've checked and everything looks good, and the build systems and tests have been updated. The json branch has been merged with master. Enjoy!