IndexError: list out of range

I am trying to run Molecular Orbitals within psi4 (version 1.3.2) on WebMO and I’m getting the following error in my output file:

Traceback (most recent call last):
File “/datapool/usr/local/src/psi4/psi4-python37/bin/psi4”, line 287, in
exec(content)
File “”, line 82, in

IndexError: list index out of range

Printing out the relevant lines from the Psithon → Python processed input file:
end = (i+1)*6
lin = “%12s” % (’ ')
for j in range(start,end): lin+= “%10d” % (j+1)
print_out(lin+newline)
lin = " "
→ for num in range(start,end): lin+= “%10.3f” % (float(evals[num]))
print_out("Eigenvalues: “+lin+newline)
for j in range(len(coeffs)):
lin = “%3d %5s” % (j+1,ao_labels[j].split()[0])
lin += “%5s” % (” ".join(ao_labels[j].split()[1:]))
for num in range(start,end): lin+= “%10.5f” % (float(coeffs[j][num]))

I receive the same error when trying to run psi4 in the shell environment, as well. Below is more information from my input file:

evals = list(np.array(wfn.epsilon_a_subset(“AO”, “OCC”)).astype(str))
coeffs = list(np.array(wfn.Ca_subset(“AO”, “OCC”)).astype(str))
length = int(math.ceil(len(evals)/6))
rem = len(evals)%6
start = 0
end = 0
for i in range(length+1):
if rem == 0 and i == length: break
if rem != 0 and i == length:
start = end
end = start + rem
else:
start = i*6
end = (i+1)*6
lin = “%12s” % (’ ')
for j in range(start,end): lin+= “%10d” % (j+1)
print_out(lin+newline)
lin = " "
for num in range(start,end): lin+= “%10.3f” % (float(evals[num]))
print_out("Eigenvalues: “+lin+newline)
for j in range(len(coeffs)):
lin = “%3d %5s” % (j+1,ao_labels[j].split()[0])
lin += “%5s” % (” ".join(ao_labels[j].split()[1:]))
for num in range(start,end): lin+= “%10.5f” % (float(coeffs[j][num]))
print_out(lin+newline)
print_out(newline)

oeprop(wfn, “MULLIKEN_CHARGES”)
mol.print_out()
print_variables()

Any guidance is much appreciated!

Please read our topic on how to ask questions.

In particular, code snippets needs backticks.

Just looking at this script, it looks like your script is buggy, rather than anything Psi4-specific. I recommend you do some debugging on your own until you either find the problem or have a question that requires Psi4 expertise.

Thanks for the reply. I don’t understand how the script would be buggy. It was autogenerated when running PSI4 within WebMO and selecting the “molecular orbitals” calculation. For reference, we are currently running on WebMO version 17.0.0123. (I’m not sure if an older version would have anything to do with the issue). I have also attached both the input and output files generated by WebMO.

output.txt (24.4 KB)
input.txt (2.0 KB)

That changes things.

The script is indeed bugged. Please file a bug report with WebMO (their forums, probably?) for any assistance getting the “molecular orbitals” option corrected.

Replace these lines in your script

for i in range(length+1):
    if rem == 0 and i == length: break
    if rem != 0 and i == length:
        start = end
        end = start + rem
    else:
        start = i*6
        end = (i+1)*6

with these lines

for i in range(length):
    start = i * 6 
    end = start + (rem if i == length - 1 else 6)

I haven’t done thorough testing that they work in general, but they work for your example.