|
| 1 | +# |
| 2 | +# Calculation methods for qchem outputs |
| 3 | +# |
| 4 | +export cspa |
| 5 | +export mpa |
| 6 | +export density |
| 7 | +export lpa |
| 8 | +export bpa |
| 9 | +export density |
| 10 | +export mbo |
| 11 | +export cda |
| 12 | +export bader |
| 13 | + |
| 14 | +# dimensions of some outputs are NxMxK, however python return dimension N as a list, not an array |
| 15 | +function expand(x) |
| 16 | + N = length(x) |
| 17 | + x = pyconvert(Array{Float64}, x[0]) |
| 18 | + return reshape(x, (N, size(x)...)) |
| 19 | +end |
| 20 | + |
| 21 | +""" |
| 22 | + cspa(file::String) |
| 23 | +
|
| 24 | +C-Squared Population Analysis (CSPA) |
| 25 | +# Arguments |
| 26 | +- `file::String`: Cclib-supported output file |
| 27 | +# Returns |
| 28 | +Tuple with 3 elements: |
| 29 | +- `aoresults`: a three dimensional array with spin, molecular orbital, and atomic orbitals as the axes, so that ``aoresults[1][46][1]`` gives the contribution of the 1st atomic orbital to the 46th alpha/restricted molecular orbital, |
| 30 | +- `fragresults`: a three dimensional array with spin, molecular orbital, and atoms as the axes, so that ``fragresults[1][24][5]`` gives the contribution of the 5th fragment orbitals to the 24th beta molecular orbital) |
| 31 | +- `fragcharges`: a vector with the number of (partial) electrons in each fragment, so that ``fragcharges[3]`` gives the number of electrons in the 3rd fragment. |
| 32 | +""" |
| 33 | +function cspa(file::String) |
| 34 | + #TODO: implement the optional args from docs |
| 35 | + data = cclib[].io.ccread(file) |
| 36 | + mol = cclib[].method.CSPA(data) |
| 37 | + mol.calculate() |
| 38 | + aoresults = mol.__dict__["aoresults"] |> expand |
| 39 | + fragresults = mol.__dict__["fragresults"] |> expand |
| 40 | + fragcharges = pyconvert(Array{Float64}, mol.__dict__["fragcharges"]) |
| 41 | + return aoresults, fragresults, fragcharges |
| 42 | +end |
| 43 | + |
| 44 | +""" |
| 45 | + mpa(file::String) |
| 46 | +
|
| 47 | +Mulliken Population Analysis |
| 48 | +# Arguments |
| 49 | +- `file::String`: Cclib-supported output file |
| 50 | +# Returns |
| 51 | +Tuple with 3 elements: |
| 52 | +- `aoresults`: a three dimensional array with spin, molecular orbital, and atomic orbitals as the axes, so that ``aoresults[1][46][1]`` gives the contribution of the 1st atomic orbital to the 46th alpha/restricted molecular orbital, |
| 53 | +- `fragresults`: a three dimensional array with spin, molecular orbital, and atoms as the axes, so that ``fragresults[1][24][5]`` gives the contribution of the 5th fragment orbitals to the 24th beta molecular orbital) |
| 54 | +- `fragcharges`: a vector with the number of (partial) electrons in each fragment, so that ``fragcharges[3]`` gives the number of electrons in the 3rd fragment. |
| 55 | +""" |
| 56 | +function mpa(file::String) |
| 57 | + data = cclib[].io.ccread(file) |
| 58 | + mol = cclib[].method.MPA(data) |
| 59 | + mol.calculate() |
| 60 | + aoresults = mol.__dict__["aoresults"] |> expand |
| 61 | + fragresults = mol.__dict__["fragresults"] |> expand |
| 62 | + fragcharges = pyconvert(Array{Float64}, mol.__dict__["fragcharges"]) |
| 63 | + return aoresults, fragresults, fragcharges |
| 64 | +end |
| 65 | + |
| 66 | +""" |
| 67 | + lpa(file::String) |
| 68 | +
|
| 69 | +Lowdin Population Analysis |
| 70 | +# Arguments |
| 71 | +- `file::String`: Cclib-supported output file |
| 72 | +# Returns |
| 73 | +Tuple with 3 elements: |
| 74 | +- `aoresults`: a three dimensional array with spin, molecular orbital, and atomic orbitals as the axes, so that ``aoresults[1][46][1]`` gives the contribution of the 1st atomic orbital to the 46th alpha/restricted molecular orbital, |
| 75 | +- `fragresults`: a three dimensional array with spin, molecular orbital, and atoms as the axes, so that ``fragresults[1][24][5]`` gives the contribution of the 5th fragment orbitals to the 24th beta molecular orbital) |
| 76 | +- `fragcharges`: a vector with the number of (partial) electrons in each fragment, so that ``fragcharges[3]`` gives the number of electrons in the 3rd fragment. |
| 77 | +""" |
| 78 | +function lpa(file::String) |
| 79 | + data = cclib[].io.ccread(file) |
| 80 | + mol = cclib[].method.LPA(data) |
| 81 | + mol.calculate() |
| 82 | + aoresults = mol.__dict__["aoresults"] |> expand |
| 83 | + fragresults = mol.__dict__["fragresults"] |> expand |
| 84 | + fragcharges = pyconvert(Array{Float64}, mol.__dict__["fragcharges"]) |
| 85 | + return aoresults, fragresults, fragcharges |
| 86 | +end |
| 87 | + |
| 88 | +""" |
| 89 | + bpa(file::String) |
| 90 | +
|
| 91 | +Bickelhaupt Population Analysis |
| 92 | +# Arguments |
| 93 | +- `file::String`: Cclib-supported output file |
| 94 | +# Returns |
| 95 | +Tuple with 3 elements: |
| 96 | +- `aoresults`: a three dimensional array with spin, molecular orbital, and atomic orbitals as the axes, so that ``aoresults[1][46][1]`` gives the contribution of the 1st atomic orbital to the 46th alpha/restricted molecular orbital, |
| 97 | +- `fragresults`: a three dimensional array with spin, molecular orbital, and atoms as the axes, so that ``fragresults[1][24][5]`` gives the contribution of the 5th fragment orbitals to the 24th beta molecular orbital) |
| 98 | +- `fragcharges`: a vector with the number of (partial) electrons in each fragment, so that ``fragcharges[3]`` gives the number of electrons in the 3rd fragment. |
| 99 | +""" |
| 100 | +function bpa(file::String) |
| 101 | + data = cclib[].io.ccread(file) |
| 102 | + mol = cclib[].method.Bickelhaupt(data) |
| 103 | + mol.calculate() |
| 104 | + aoresults = mol.__dict__["aoresults"] |> expand |
| 105 | + fragresults = mol.__dict__["fragresults"] |> expand |
| 106 | + fragcharges = pyconvert(Array{Float64}, mol.__dict__["fragcharges"]) |
| 107 | + return aoresults, fragresults, fragcharges |
| 108 | +end |
| 109 | + |
| 110 | +""" |
| 111 | + density(file::String) |
| 112 | +
|
| 113 | +Density matrix calculation |
| 114 | +# Arguments |
| 115 | +- `file::String`: Cclib-supported output file |
| 116 | +# Returns |
| 117 | +- An array with three axes. The first axis is for the spin contributions, |
| 118 | +the second and the third axes for the density matrix, which follows standard definition. |
| 119 | +""" |
| 120 | +function density(file::String) |
| 121 | + data = cclib[].io.ccread(file) |
| 122 | + mol = cclib[].method.Density(data) |
| 123 | + mol.calculate() |
| 124 | + return pyconvert(Array{Float64}, mol.__dict__["density"]) |
| 125 | +end |
| 126 | + |
| 127 | +""" |
| 128 | + mbo(file::String) |
| 129 | +
|
| 130 | +Calculate Mayer's bond orders |
| 131 | +# Arguments |
| 132 | +- `file::String`: Cclib-supported output file |
| 133 | +# Returns |
| 134 | +- An array with three axes. The first axis is for contributions of each spin to the MBO, |
| 135 | +while the second and third correspond to the indices of the atoms. |
| 136 | +""" |
| 137 | +function mbo(file::String) |
| 138 | + data = cclib[].io.ccread(file) |
| 139 | + mol = cclib[].method.MBO(data) |
| 140 | + mol.calculate() |
| 141 | + return pyconvert(Array{Float64}, mol.__dict__["fragresults"]) |
| 142 | +end |
| 143 | + |
| 144 | +""" |
| 145 | + cda(file::String) |
| 146 | +
|
| 147 | +Charge decomposition analysis |
| 148 | +# Arguments |
| 149 | +- `mol::String`: Cclib-supported output file |
| 150 | +- `frag1::String`: Cclib-supported output file |
| 151 | +- `frag2::String`: Cclib-supported output file |
| 152 | +# Returns |
| 153 | +- Tuple (donations, backdonations, repulsions) |
| 154 | +donations, bdonations (back donations), and repulsions attributes. |
| 155 | +These attributes are simply lists of 1-dimensional arrays corresponding to the restricted or alpha/beta molecular orbitals of the entire molecule. |
| 156 | +""" |
| 157 | +function cda(mol::String, frag1::String, frag2::String) |
| 158 | + mol = cclib[].io.ccread(mol) |
| 159 | + frag1 = cclib[].io.ccread(frag1) |
| 160 | + frag2 = cclib[].io.ccread(frag2) |
| 161 | + mol = cclib[].method.CDA(mol) |
| 162 | + mol.calculate([frag1, frag2]) |
| 163 | + donations = mol.__dict__["donations"] |> expand |
| 164 | + bdonations = mol.__dict__["bdonations"] |> expand |
| 165 | + repulsions = mol.__dict__["repulsions"] |> expand |
| 166 | + return donations, bdonations, repulsions |
| 167 | +end |
| 168 | + |
| 169 | +# TODO: this requires PyQuante which doens't seem to work |
| 170 | +# when trying to install it into a conda env |
| 171 | +# """ |
| 172 | +# bader(file::string) |
| 173 | + |
| 174 | +# bader's qtaim charges calculation |
| 175 | +# # arguments |
| 176 | +# - `file::string`: cclib-supported output file |
| 177 | +# # returns |
| 178 | +# tuple (donations, backdonations, repulsions) |
| 179 | +# """ |
| 180 | +# function bader(file::String, vol::Vector{Vector{Float64}}) |
| 181 | +# data = cclib[].io.ccread(file) |
| 182 | +# vol = pytuple(pytuple(i) for i in vol) |
| 183 | +# vol = cclib[].method.volume(vol...) |
| 184 | +# mol = cclib[].method.bader(data, vol) |
| 185 | +# mol.calculate() |
| 186 | +# return mol |
| 187 | +# # aoresults = mol.__dict__["aoresults"] |> expand |
| 188 | +# # fragresults = mol.__dict__["fragresults"] |> expand |
| 189 | +# # fragcharges = pyconvert(array{float64}, mol.__dict__["fragcharges"]) |
| 190 | +# # return aoresults, fragresults, fragcharges |
| 191 | +# end |
0 commit comments