error message issubclass() arg 1 must be a class
The sample script included at the bottom of the issue results in the following error message when executed with texts script -f test.vm
:
raise TextXError(str(err), **get_location_context(obj)) from err
textx.exceptions.TextXError: /home/rodri/Projects/vre-language_testing/i-arg_1_must_be_a_class/tst_mwe3.vm:2:1: issubclass() arg 1 must be a class => 'energy_ = -153.78488212 [electron_volt]
The sample is based on the vre-language/examples/TextM-examples/Pt-ORR_UseCase/02-electrochemistry/TextM-oxycat_electrochem.vm
file.
While trying to make a minimum working example out of the full script I found that the crash is somehow originated when the U_max
part almost at the end:
orr_potentials = map((g: -g/(n*e)), orr_free_energies)
min(s) = reduce((x, y: if(x<y, x, y)), s)
#
U_max = min(orr_potentials)
print('U_max=', U_max)
If this section is commented out, the script is executed without issues. I tried to isolate and test all parts of the script separately. This was done by directly providing the required parameters to sections of the script, instead of calling them from previous variables or functions. In these cases the error does not occurr. It only happens if the whole script is executed.
Sample script:
### VASP total and vibratinal energies
energy_ = -153.78488212 [electron_volt]
energy_O = -160.02030190 [electron_volt]
energy_OH = -163.59352476 [electron_volt]
energy_OOH = -167.86220067 [electron_volt]
##
vib_ener_O = (vibrational_energies: 0.055954544, 0.045046768, 0.044947491) [electron_volt]
#
vib_ener_OH = (vibrational_energies: 0.449608408, 0.067996806, 0.06709252600000001, 0.042573099999999996, 0.021048982, 0.02020558) [electron_volt]
#
vib_ener_OOH = (vibrational_energies: 0.448162632, 0.142670432, 0.042869318999999996, 0.042677173000000006, 0.039394802, 0.028062200000000002, 0.017229372000000003, 0.0059731129999999995, 0.002726201) [electron_volt]
# 08 - Functions for vibrational entropy and zero-point vibrational enthalpy (ZPE) of adsorbates
use exp, log from numpy
#
zpe_f(vib_ener) = 0.5*sum(vib_ener)
#
beta = 1.0/(kB*temperature)
exp_hob(ene) = exp(-ene*beta)
entr(ene, exp_hob) = ene * beta * exp_hob / (1.0-exp_hob) - log(1.0-exp_hob)
vib_entr_f(vib_energies) = kB * sum(map(entr, vib_energies, map(exp_hob, vib_energies)))
## Properties of chemical Species (objects) involved in ORR
#
H2O = Species H2O (
(energy: -14.22696993) [electron_volt],
(zpe: 0.558) [eV],
(entropy: 2.1669e-3) [eV/K],
(temperature: 298.15) [K]
)
H2 = Species H2 (
(energy: -6.75996823) [electron_volt],
(zpe: 0.270) [eV],
(entropy: 1.3613e-3) [eV/K],
(temperature: 298.15) [K]
)
orr_free = -4.916 [eV]
O2 = Species O2 (
(free_energy: 2.*H2O.free_energy[0] - 2.*H2.free_energy[0] - orr_free),
(zpe: 0.098) [eV],
(entropy: 2.1370e-3) [eV/K],
(temperature: 298.15) [K]
)
M = Species M (
(energy: energy_ ),
(zpe: 0.0) [eV],
(entropy: 0.0) [eV/K],
(temperature: 298.15) [K]
)
MO = Species MO (
(energy: energy_O),
(zpe: zpe_f(vib_ener_O)),
(entropy: vib_entr_f(vib_ener_O)),
(temperature: 298.15) [K]
)
MOH = Species MOH (
(energy: energy_OH),
(zpe: zpe_f(vib_ener_OH)),
(entropy: vib_entr_f(vib_ener_OH)),
(temperature: 298.15) [K]
)
MOOH = Species MOOH (
(energy: energy_OOH),
(zpe: zpe_f(vib_ener_OOH)),
(entropy: vib_entr_f(vib_ener_OOH)),
(temperature: 298.15) [K]
)
## ORR chemical sub-reactions
#
# Define chemical reaction steps:
orr1 = Reaction M + O2 + 0.5 H2 = MOOH
orr2 = Reaction MOOH + 0.5 H2 = MO + H2O
orr3 = Reaction MO + 0.5 H2 = MOH
orr4 = Reaction MOH + 0.5 H2 = M + H2O
## Electrochemistry: Compute U_max and Overpotential
#
orr = (reactions: orr1, orr2, orr3, orr4)
orr_free_energies = map((r: r.free_energy[0]), orr)
# Critical potential U_max
orr_potentials = map((g: -g/(n*e)), orr_free_energies)
min(s) = reduce((x, y: if(x<y, x, y)), s)
#
U_max = min(orr_potentials)
print('U_max=', U_max)
# Additional Global Parameters and Constants
#
temperature = 298.15 [K]
kB = 1 [boltzmann_constant]
e = 1 [elementary_charge] # available in pint
n = 1 # number of exchanged electrons, all ORR/OER elementary reactions are one-electron