- if col < 3
- tabvals[row][col]
- else
- if coeffs == nil
- if mo_ao == 0
- coeffs = mol.get_mo_coefficients(mo_index)
- elsif mo_ao == 1
- coeffs = (0...ncomps).map { |i| (i == mo_index ? 1.0 : 0.0) }
- else
- coeffs = nbo["AO/" + mo_ao_keys[mo_ao]].column(mo_index).to_a[0]
- end
- end
- sprintf("%.6f", coeffs[row])
- end
+ begin
+ if !table_coeffs_matrix || !coeffs_matrix
+ # Update tabvals
+ tabvals = []
+ bs = value("basis")
+ if bs == 0 # AO
+ ncomps.times { |i|
+ a_idx, s_idx, label = mol.get_gaussian_component_info(i)
+ if a_idx_old != a_idx
+ a_idx_old = a_idx
+ a = a_idx.to_s
+ n = mol.atoms[a_idx].name
+ else
+ a = n = ""
+ end
+ tabvals.push([a, n, label, a_idx])
+ }
+ else
+ labels = update_mo_labels.call(bs + 1)
+ ncomps.times { |i|
+ label = labels[i]
+ label = label.gsub(/^\d+: /, "")
+ tabvals.push([(i + 1).to_s, "", label, i])
+ }
+ end
+ # Update coeffs_matrix
+ if !coeffs_matrix
+ # coeffs_matrix = AO/(orbitals_to_display)
+ if mo_ao == 0
+ m = []
+ ncomps.times { |i|
+ mult.times { |j|
+ m.push(mol.get_mo_coefficients(i * mult + j + 1))
+ }
+ }
+ coeffs_matrix = LAMatrix.new(m) # Matrix AO/MO
+ elsif mo_ao == 1
+ coeffs_matrix = LAMatrix.identity(ncomps) # Matrix AO/AO (identity)
+ else
+ coeffs_matrix = nbo["AO/" + mo_ao_keys[mo_ao]]
+ end
+ end
+ # m2 = AO/(basis)
+ if bs == 0 # AO
+ m2 = LAMatrix.identity(ncomps)
+ else
+ m2 = nbo["AO/" + mo_ao_keys[bs + 1]]
+ end
+ # (basis)/(orbitals_to_display)
+ table_coeffs_matrix = m2.inverse * coeffs_matrix
+ end
+ # Update coefficient array
+ if !coeffs
+ coeffs = coeffs_matrix.column(mo_index).to_a[0]
+ end
+ if col < 3
+ tabvals[row][col]
+ else
+ sprintf("%.6f", table_coeffs_matrix[mo_index, row])
+ end
+ rescue => e
+ $stderr.write(e.to_s + "\n")
+ $stderr.write(e.backtrace.inspect + "\n")
+ end