| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# |
| 3 |
# Copyright (c) 2019, the cclib development team |
| 4 |
# |
| 5 |
# This file is part of cclib (http://cclib.github.io) and is distributed under |
| 6 |
# the terms of the BSD 3-Clause License. |
| 7 |
|
| 8 |
"""Parser for ORCA output files""" |
| 9 |
|
| 10 |
|
| 11 |
from __future__ import print_function |
| 12 |
|
| 13 |
import numpy |
| 14 |
import re |
| 15 |
|
| 16 |
from cclib.parser import logfileparser |
| 17 |
from cclib.parser import utils |
| 18 |
|
| 19 |
|
| 20 |
class ORCA(logfileparser.Logfile): |
| 21 |
"""An ORCA log file.""" |
| 22 |
|
| 23 |
def __init__(self, *args, **kwargs): |
| 24 |
|
| 25 |
# Call the __init__ method of the superclass |
| 26 |
super(ORCA, self).__init__(logname="ORCA", *args, **kwargs) |
| 27 |
|
| 28 |
|
| 29 |
def __str__(self): |
| 30 |
"""Return a string representation of the object.""" |
| 31 |
return "ORCA log file %s" % (self.filename) |
| 32 |
|
| 33 |
def __repr__(self): |
| 34 |
"""Return a representation of the object.""" |
| 35 |
return 'ORCA("%s")' % (self.filename) |
| 36 |
|
| 37 |
def normalisesym(self, label): |
| 38 |
"""ORCA does not require normalizing symmetry labels.""" |
| 39 |
return label |
| 40 |
|
| 41 |
def before_parsing(self): |
| 42 |
|
| 43 |
# A geometry optimization is started only when |
| 44 |
# we parse a cycle (so it will be larger than zero(). |
| 45 |
self.gopt_cycle = 0 |
| 46 |
|
| 47 |
# Keep track of whether this is a relaxed scan calculation |
| 48 |
self.is_relaxed_scan = False |
| 49 |
|
| 50 |
def extract(self, inputfile, line): |
| 51 |
"""Extract information from the file object inputfile.""" |
| 52 |
|
| 53 |
# Extract the version number. |
| 54 |
if "Program Version" == line.strip()[:15]: |
| 55 |
self.metadata["package_version"] = line.split()[2] |
| 56 |
|
| 57 |
# ================================================================================ |
| 58 |
# WARNINGS |
| 59 |
# Please study these warnings very carefully! |
| 60 |
# ================================================================================ |
| 61 |
# |
| 62 |
# Warning: TCutStore was < 0. Adjusted to Thresh (uncritical) |
| 63 |
# |
| 64 |
# WARNING: your system is open-shell and RHF/RKS was chosen |
| 65 |
# ===> : WILL SWITCH to UHF/UKS |
| 66 |
# |
| 67 |
# |
| 68 |
# INFO : the flag for use of LIBINT has been found! |
| 69 |
# |
| 70 |
# ================================================================================ |
| 71 |
if "WARNINGS" == line.strip(): |
| 72 |
self.skip_lines(inputfile, ['text', '=', 'blank']) |
| 73 |
if 'warnings' not in self.metadata: |
| 74 |
self.metadata['warnings'] = [] |
| 75 |
if 'info' not in self.metadata: |
| 76 |
self.metadata['info'] = [] |
| 77 |
|
| 78 |
line = next(inputfile) |
| 79 |
while line[0] != '=': |
| 80 |
if line.lower()[:7] == 'warning': |
| 81 |
self.metadata['warnings'].append('') |
| 82 |
while len(line) > 1: |
| 83 |
self.metadata['warnings'][-1] += line[9:].strip() |
| 84 |
line = next(inputfile) |
| 85 |
elif line.lower()[:4] == 'info': |
| 86 |
self.metadata['info'].append('') |
| 87 |
while len(line) > 1: |
| 88 |
self.metadata['info'][-1] += line[9:].strip() |
| 89 |
line = next(inputfile) |
| 90 |
line = next(inputfile) |
| 91 |
|
| 92 |
# ================================================================================ |
| 93 |
# INPUT FILE |
| 94 |
# ================================================================================ |
| 95 |
# NAME = input.dat |
| 96 |
# | 1> %pal nprocs 4 end |
| 97 |
# | 2> ! B3LYP def2-svp |
| 98 |
# | 3> ! Grid4 |
| 99 |
# | 4> |
| 100 |
# | 5> *xyz 0 3 |
| 101 |
# | 6> O 0 0 0 |
| 102 |
# | 7> O 0 0 1.5 |
| 103 |
# | 8> * |
| 104 |
# | 9> |
| 105 |
# | 10> ****END OF INPUT**** |
| 106 |
# ================================================================================ |
| 107 |
if "INPUT FILE" == line.strip(): |
| 108 |
self.skip_line(inputfile, '=') |
| 109 |
self.metadata['input_file_name'] = next(inputfile).split()[-1] |
| 110 |
|
| 111 |
# First, collect all the lines... |
| 112 |
lines = [] |
| 113 |
for line in inputfile: |
| 114 |
if line[0] != '|': |
| 115 |
break |
| 116 |
lines.append(line[6:]) |
| 117 |
|
| 118 |
self.metadata['input_file_contents'] = ''.join(lines[:-1]) |
| 119 |
lines_iter = iter(lines[:-1]) |
| 120 |
|
| 121 |
keywords = [] |
| 122 |
coords = [] |
| 123 |
# ...then parse them separately. |
| 124 |
for line in lines_iter: |
| 125 |
line = line.strip() |
| 126 |
if not line: |
| 127 |
continue |
| 128 |
|
| 129 |
# Keywords block |
| 130 |
if line[0] == '!': |
| 131 |
keywords += line[1:].split() |
| 132 |
|
| 133 |
# Impossible to parse without knowing whether a keyword opens a new block |
| 134 |
elif line[0] == '%': |
| 135 |
pass |
| 136 |
|
| 137 |
# Geometry block |
| 138 |
elif line[0] == '*': |
| 139 |
coord_type, charge, multiplicity = line[1:].split()[:3] |
| 140 |
self.set_attribute('charge', int(charge)) |
| 141 |
self.set_attribute('multiplicity', int(multiplicity)) |
| 142 |
coord_type = coord_type.lower() |
| 143 |
self.metadata['coord_type'] = coord_type |
| 144 |
if coord_type == 'xyz': |
| 145 |
def splitter(line): |
| 146 |
atom, x, y, z = line.split()[:4] |
| 147 |
return [atom, float(x), float(y), float(z)] |
| 148 |
elif coord_type in ['int', 'internal']: |
| 149 |
def splitter(line): |
| 150 |
atom, a1, a2, a3, bond, angle, dihedral = line.split()[:7] |
| 151 |
return [atom, int(a1), int(a2), int(a3), float(bond), float(angle), float(dihedral)] |
| 152 |
elif coord_type == 'gzmt': |
| 153 |
def splitter(line): |
| 154 |
vals = line.split()[:7] |
| 155 |
if len(vals) == 7: |
| 156 |
atom, a1, bond, a2, angle, a3, dihedral = vals |
| 157 |
return [atom, int(a1), float(bond), int(a2), float(angle), int(a3), float(dihedral)] |
| 158 |
elif len(vals) == 5: |
| 159 |
return [vals[0], int(vals[1]), float(vals[2]), int(vals[3]), float(vals[4])] |
| 160 |
elif len(vals) == 3: |
| 161 |
return [vals[0], int(vals[1]), float(vals[2])] |
| 162 |
elif len(vals) == 1: |
| 163 |
return [vals[0]] |
| 164 |
self.logger.warning('Incorrect number of atoms in input geometry.') |
| 165 |
elif 'file' in coord_type: |
| 166 |
pass |
| 167 |
else: |
| 168 |
self.logger.warning('Invalid coordinate type.') |
| 169 |
|
| 170 |
if 'file' not in coord_type: |
| 171 |
for line in lines_iter: |
| 172 |
if not line: |
| 173 |
continue |
| 174 |
if line[0] == '#' or line.strip(' ') == '\n': |
| 175 |
continue |
| 176 |
if line[0] == '*' or line.strip() == "end": |
| 177 |
break |
| 178 |
# Strip basis specification that can appear after coordinates |
| 179 |
line = line.split('newGTO')[0].strip() |
| 180 |
coords.append(splitter(line)) |
| 181 |
|
| 182 |
self.metadata['keywords'] = keywords |
| 183 |
self.metadata['coords'] = coords |
| 184 |
|
| 185 |
if line[0:15] == "Number of atoms": |
| 186 |
|
| 187 |
natom = int(line.split()[-1]) |
| 188 |
self.set_attribute('natom', natom) |
| 189 |
|
| 190 |
if line[1:13] == "Total Charge": |
| 191 |
|
| 192 |
charge = int(line.split()[-1]) |
| 193 |
self.set_attribute('charge', charge) |
| 194 |
|
| 195 |
line = next(inputfile) |
| 196 |
|
| 197 |
mult = int(line.split()[-1]) |
| 198 |
self.set_attribute('mult', mult) |
| 199 |
|
| 200 |
# SCF convergence output begins with: |
| 201 |
# |
| 202 |
# -------------- |
| 203 |
# SCF ITERATIONS |
| 204 |
# -------------- |
| 205 |
# |
| 206 |
# However, there are two common formats which need to be handled, implemented as separate functions. |
| 207 |
if line.strip() == "SCF ITERATIONS": |
| 208 |
|
| 209 |
self.skip_line(inputfile, 'dashes') |
| 210 |
|
| 211 |
line = next(inputfile) |
| 212 |
columns = line.split() |
| 213 |
# "Starting incremental Fock matrix formation" doesn't |
| 214 |
# necessarily appear before the extended format. |
| 215 |
if not columns: |
| 216 |
self.parse_scf_expanded_format(inputfile, columns) |
| 217 |
# A header with distinct columns indicates the condensed |
| 218 |
# format. |
| 219 |
elif columns[1] == "Energy": |
| 220 |
self.parse_scf_condensed_format(inputfile, columns) |
| 221 |
# Assume the extended format. |
| 222 |
else: |
| 223 |
self.parse_scf_expanded_format(inputfile, columns) |
| 224 |
|
| 225 |
# Information about the final iteration, which also includes the convergence |
| 226 |
# targets and the convergence values, is printed separately, in a section like this: |
| 227 |
# |
| 228 |
# ***************************************************** |
| 229 |
# * SUCCESS * |
| 230 |
# * SCF CONVERGED AFTER 9 CYCLES * |
| 231 |
# ***************************************************** |
| 232 |
# |
| 233 |
# ... |
| 234 |
# |
| 235 |
# Total Energy : -382.04963064 Eh -10396.09898 eV |
| 236 |
# |
| 237 |
# ... |
| 238 |
# |
| 239 |
# ------------------------- ---------------- |
| 240 |
# FINAL SINGLE POINT ENERGY -382.049630637 |
| 241 |
# ------------------------- ---------------- |
| 242 |
# |
| 243 |
# We cannot use this last message as a stop condition in general, because |
| 244 |
# often there is vibrational output before it. So we use the 'Total Energy' |
| 245 |
# line. However, what comes after that is different for single point calculations |
| 246 |
# and in the inner steps of geometry optimizations. |
| 247 |
if "SCF CONVERGED AFTER" in line: |
| 248 |
|
| 249 |
if not hasattr(self, "scfenergies"): |
| 250 |
self.scfenergies = [] |
| 251 |
if not hasattr(self, "scfvalues"): |
| 252 |
self.scfvalues = [] |
| 253 |
if not hasattr(self, "scftargets"): |
| 254 |
self.scftargets = [] |
| 255 |
|
| 256 |
while not "Total Energy :" in line: |
| 257 |
line = next(inputfile) |
| 258 |
energy = utils.convertor(float(line.split()[3]), "hartree", "eV") |
| 259 |
self.scfenergies.append(energy) |
| 260 |
|
| 261 |
self._append_scfvalues_scftargets(inputfile, line) |
| 262 |
|
| 263 |
# Sometimes the SCF does not converge, but does not halt the |
| 264 |
# the run (like in bug 3184890). In this this case, we should |
| 265 |
# remain consistent and use the energy from the last reported |
| 266 |
# SCF cycle. In this case, ORCA print a banner like this: |
| 267 |
# |
| 268 |
# ***************************************************** |
| 269 |
# * ERROR * |
| 270 |
# * SCF NOT CONVERGED AFTER 8 CYCLES * |
| 271 |
# ***************************************************** |
| 272 |
if "SCF NOT CONVERGED AFTER" in line: |
| 273 |
|
| 274 |
if not hasattr(self, "scfenergies"): |
| 275 |
self.scfenergies = [] |
| 276 |
if not hasattr(self, "scfvalues"): |
| 277 |
self.scfvalues = [] |
| 278 |
if not hasattr(self, "scftargets"): |
| 279 |
self.scftargets = [] |
| 280 |
|
| 281 |
energy = utils.convertor(self.scfvalues[-1][-1][0], "hartree", "eV") |
| 282 |
self.scfenergies.append(energy) |
| 283 |
|
| 284 |
self._append_scfvalues_scftargets(inputfile, line) |
| 285 |
|
| 286 |
# The convergence targets for geometry optimizations are printed at the |
| 287 |
# beginning of the output, although the order and their description is |
| 288 |
# different than later on. So, try to standardize the names of the criteria |
| 289 |
# and save them for later so that we can get the order right. |
| 290 |
# |
| 291 |
# ***************************** |
| 292 |
# * Geometry Optimization Run * |
| 293 |
# ***************************** |
| 294 |
# |
| 295 |
# Geometry optimization settings: |
| 296 |
# Update method Update .... BFGS |
| 297 |
# Choice of coordinates CoordSys .... Redundant Internals |
| 298 |
# Initial Hessian InHess .... Almoef's Model |
| 299 |
# |
| 300 |
# Convergence Tolerances: |
| 301 |
# Energy Change TolE .... 5.0000e-06 Eh |
| 302 |
# Max. Gradient TolMAXG .... 3.0000e-04 Eh/bohr |
| 303 |
# RMS Gradient TolRMSG .... 1.0000e-04 Eh/bohr |
| 304 |
# Max. Displacement TolMAXD .... 4.0000e-03 bohr |
| 305 |
# RMS Displacement TolRMSD .... 2.0000e-03 bohr |
| 306 |
# |
| 307 |
if line[25:50] == "Geometry Optimization Run": |
| 308 |
|
| 309 |
stars = next(inputfile) |
| 310 |
blank = next(inputfile) |
| 311 |
|
| 312 |
line = next(inputfile) |
| 313 |
while line[0:23] != "Convergence Tolerances:": |
| 314 |
line = next(inputfile) |
| 315 |
|
| 316 |
if hasattr(self, 'geotargets'): |
| 317 |
self.logger.warning('The geotargets attribute should not exist yet. There is a problem in the parser.') |
| 318 |
self.geotargets = [] |
| 319 |
self.geotargets_names = [] |
| 320 |
|
| 321 |
# There should always be five tolerance values printed here. |
| 322 |
for i in range(5): |
| 323 |
line = next(inputfile) |
| 324 |
name = line[:25].strip().lower().replace('.', '').replace('displacement', 'step') |
| 325 |
target = float(line.split()[-2]) |
| 326 |
self.geotargets_names.append(name) |
| 327 |
self.geotargets.append(target) |
| 328 |
|
| 329 |
# The convergence targets for relaxed surface scan steps are printed at the |
| 330 |
# beginning of the output, although the order and their description is |
| 331 |
# different than later on. So, try to standardize the names of the criteria |
| 332 |
# and save them for later so that we can get the order right. |
| 333 |
# |
| 334 |
# ************************************************************* |
| 335 |
# * RELAXED SURFACE SCAN STEP 12 * |
| 336 |
# * * |
| 337 |
# * Dihedral ( 11, 10, 3, 4) : 180.00000000 * |
| 338 |
# ************************************************************* |
| 339 |
# |
| 340 |
# Geometry optimization settings: |
| 341 |
# Update method Update .... BFGS |
| 342 |
# Choice of coordinates CoordSys .... Redundant Internals |
| 343 |
# Initial Hessian InHess .... Almoef's Model |
| 344 |
# |
| 345 |
# Convergence Tolerances: |
| 346 |
# Energy Change TolE .... 5.0000e-06 Eh |
| 347 |
# Max. Gradient TolMAXG .... 3.0000e-04 Eh/bohr |
| 348 |
# RMS Gradient TolRMSG .... 1.0000e-04 Eh/bohr |
| 349 |
# Max. Displacement TolMAXD .... 4.0000e-03 bohr |
| 350 |
# RMS Displacement TolRMSD .... 2.0000e-03 bohr |
| 351 |
if line[25:50] == "RELAXED SURFACE SCAN STEP": |
| 352 |
|
| 353 |
self.is_relaxed_scan = True |
| 354 |
blank = next(inputfile) |
| 355 |
info = next(inputfile) |
| 356 |
stars = next(inputfile) |
| 357 |
blank = next(inputfile) |
| 358 |
|
| 359 |
line = next(inputfile) |
| 360 |
while line[0:23] != "Convergence Tolerances:": |
| 361 |
line = next(inputfile) |
| 362 |
|
| 363 |
self.geotargets = [] |
| 364 |
self.geotargets_names = [] |
| 365 |
|
| 366 |
# There should always be five tolerance values printed here. |
| 367 |
for i in range(5): |
| 368 |
line = next(inputfile) |
| 369 |
name = line[:25].strip().lower().replace('.', '').replace('displacement', 'step') |
| 370 |
target = float(line.split()[-2]) |
| 371 |
self.geotargets_names.append(name) |
| 372 |
self.geotargets.append(target) |
| 373 |
|
| 374 |
# ------------------ |
| 375 |
# CARTESIAN GRADIENT |
| 376 |
# ------------------ |
| 377 |
# |
| 378 |
# 1 H : 0.000000004 0.019501450 -0.021537091 |
| 379 |
# 2 O : 0.000000054 -0.042431648 0.042431420 |
| 380 |
# 3 H : 0.000000004 0.021537179 -0.019501388 |
| 381 |
if line[:18] == 'CARTESIAN GRADIENT': |
| 382 |
next(inputfile) |
| 383 |
next(inputfile) |
| 384 |
|
| 385 |
grads = [] |
| 386 |
line = next(inputfile).strip() |
| 387 |
while line: |
| 388 |
idx, atom, colon, x, y, z = line.split() |
| 389 |
grads.append((float(x), float(y), float(z))) |
| 390 |
|
| 391 |
line = next(inputfile).strip() |
| 392 |
|
| 393 |
if not hasattr(self, 'grads'): |
| 394 |
self.grads = [] |
| 395 |
self.grads.append(grads) |
| 396 |
|
| 397 |
# After each geometry optimization step, ORCA prints the current convergence |
| 398 |
# parameters and the targets (again), so it is a good idea to check that they |
| 399 |
# have not changed. Note that the order of these criteria here are different |
| 400 |
# than at the beginning of the output, so make use of the geotargets_names created |
| 401 |
# before and save the new geovalues in correct order. |
| 402 |
# |
| 403 |
# ----------------------|Geometry convergence|--------------------- |
| 404 |
# Item value Tolerance Converged |
| 405 |
# ----------------------------------------------------------------- |
| 406 |
# Energy change 0.00006021 0.00000500 NO |
| 407 |
# RMS gradient 0.00031313 0.00010000 NO |
| 408 |
# RMS step 0.01596159 0.00200000 NO |
| 409 |
# MAX step 0.04324586 0.00400000 NO |
| 410 |
# .................................................... |
| 411 |
# Max(Bonds) 0.0218 Max(Angles) 2.48 |
| 412 |
# Max(Dihed) 0.00 Max(Improp) 0.00 |
| 413 |
# ----------------------------------------------------------------- |
| 414 |
# |
| 415 |
if line[33:53] == "Geometry convergence": |
| 416 |
|
| 417 |
headers = next(inputfile) |
| 418 |
dashes = next(inputfile) |
| 419 |
|
| 420 |
names = [] |
| 421 |
values = [] |
| 422 |
targets = [] |
| 423 |
line = next(inputfile) |
| 424 |
# Handle both the dots only and dashes only cases |
| 425 |
while len(list(set(line.strip()))) != 1: |
| 426 |
name = line[10:28].strip().lower() |
| 427 |
tokens = line.split() |
| 428 |
value = float(tokens[2]) |
| 429 |
target = float(tokens[3]) |
| 430 |
names.append(name) |
| 431 |
values.append(value) |
| 432 |
targets.append(target) |
| 433 |
line = next(inputfile) |
| 434 |
|
| 435 |
# The energy change is normally not printed in the first iteration, because |
| 436 |
# there was no previous energy -- in that case assume zero. There are also some |
| 437 |
# edge cases where the energy change is not printed, for example when internal |
| 438 |
# angles become improper and internal coordinates are rebuilt as in regression |
| 439 |
# CuI-MePY2-CH3CN_optxes, and in such cases use NaN. |
| 440 |
newvalues = [] |
| 441 |
for i, n in enumerate(self.geotargets_names): |
| 442 |
if (n == "energy change") and (n not in names): |
| 443 |
if self.is_relaxed_scan: |
| 444 |
newvalues.append(0.0) |
| 445 |
else: |
| 446 |
newvalues.append(numpy.nan) |
| 447 |
else: |
| 448 |
newvalues.append(values[names.index(n)]) |
| 449 |
assert targets[names.index(n)] == self.geotargets[i] |
| 450 |
|
| 451 |
self.append_attribute("geovalues", newvalues) |
| 452 |
|
| 453 |
""" Grab cartesian coordinates |
| 454 |
--------------------------------- |
| 455 |
CARTESIAN COORDINATES (ANGSTROEM) |
| 456 |
--------------------------------- |
| 457 |
H 0.000000 0.000000 0.000000 |
| 458 |
O 0.000000 0.000000 1.000000 |
| 459 |
H 0.000000 1.000000 1.000000 |
| 460 |
""" |
| 461 |
if line[0:33] == "CARTESIAN COORDINATES (ANGSTROEM)": |
| 462 |
next(inputfile) |
| 463 |
|
| 464 |
atomnos = [] |
| 465 |
atomcoords = [] |
| 466 |
line = next(inputfile) |
| 467 |
while len(line) > 1: |
| 468 |
atom, x, y, z = line.split() |
| 469 |
if atom[-1] != ">": |
| 470 |
atomnos.append(self.table.number[atom]) |
| 471 |
atomcoords.append([float(x), float(y), float(z)]) |
| 472 |
line = next(inputfile) |
| 473 |
|
| 474 |
self.set_attribute('natom', len(atomnos)) |
| 475 |
self.set_attribute('atomnos', atomnos) |
| 476 |
self.append_attribute("atomcoords", atomcoords) |
| 477 |
|
| 478 |
""" Grab atom masses |
| 479 |
---------------------------- |
| 480 |
CARTESIAN COORDINATES (A.U.) |
| 481 |
---------------------------- |
| 482 |
NO LB ZA FRAG MASS X Y Z |
| 483 |
0 H 1.0000 0 1.008 0.000000 0.000000 0.000000 |
| 484 |
1 O 8.0000 0 15.999 0.000000 0.000000 1.889726 |
| 485 |
2 H 1.0000 0 1.008 0.000000 1.889726 1.889726 |
| 486 |
""" |
| 487 |
if line[0:28] == "CARTESIAN COORDINATES (A.U.)" and not hasattr(self, 'atommasses'): |
| 488 |
next(inputfile) |
| 489 |
next(inputfile) |
| 490 |
|
| 491 |
line = next(inputfile) |
| 492 |
self.atommasses = [] |
| 493 |
while len(line) > 1: |
| 494 |
if line[:32] == '* core charge reduced due to ECP': |
| 495 |
break |
| 496 |
if line.strip() == "> coreless ECP center with (optional) point charge": |
| 497 |
break |
| 498 |
no, lb, za, frag, mass, x, y, z = line.split() |
| 499 |
if lb[-1] != ">": |
| 500 |
self.atommasses.append(float(mass)) |
| 501 |
line = next(inputfile) |
| 502 |
|
| 503 |
if line[21:68] == "FINAL ENERGY EVALUATION AT THE STATIONARY POINT": |
| 504 |
if not hasattr(self, 'optdone'): |
| 505 |
self.optdone = [] |
| 506 |
self.optdone.append(len(self.atomcoords)) |
| 507 |
|
| 508 |
if "The optimization did not converge" in line: |
| 509 |
if not hasattr(self, 'optdone'): |
| 510 |
self.optdone = [] |
| 511 |
|
| 512 |
if line[0:16] == "ORBITAL ENERGIES": |
| 513 |
|
| 514 |
self.skip_lines(inputfile, ['d', 'text', 'text']) |
| 515 |
|
| 516 |
self.mooccnos = [[]] |
| 517 |
self.moenergies = [[]] |
| 518 |
|
| 519 |
line = next(inputfile) |
| 520 |
while len(line) > 20: # restricted calcs are terminated by ------ |
| 521 |
info = line.split() |
| 522 |
mooccno = int(float(info[1])) |
| 523 |
moenergy = float(info[2]) |
| 524 |
self.mooccnos[0].append(mooccno) |
| 525 |
self.moenergies[0].append(utils.convertor(moenergy, "hartree", "eV")) |
| 526 |
line = next(inputfile) |
| 527 |
|
| 528 |
line = next(inputfile) |
| 529 |
|
| 530 |
# handle beta orbitals for UHF |
| 531 |
if line[17:35] == "SPIN DOWN ORBITALS": |
| 532 |
text = next(inputfile) |
| 533 |
|
| 534 |
self.mooccnos.append([]) |
| 535 |
self.moenergies.append([]) |
| 536 |
|
| 537 |
line = next(inputfile) |
| 538 |
while len(line) > 20: # actually terminated by ------ |
| 539 |
info = line.split() |
| 540 |
mooccno = int(float(info[1])) |
| 541 |
moenergy = float(info[2]) |
| 542 |
self.mooccnos[1].append(mooccno) |
| 543 |
self.moenergies[1].append(utils.convertor(moenergy, "hartree", "eV")) |
| 544 |
line = next(inputfile) |
| 545 |
|
| 546 |
if not hasattr(self, 'homos'): |
| 547 |
doubly_occupied = self.mooccnos[0].count(2) |
| 548 |
singly_occupied = self.mooccnos[0].count(1) |
| 549 |
# Restricted closed-shell. |
| 550 |
if doubly_occupied > 0 and singly_occupied == 0: |
| 551 |
self.set_attribute('homos', [doubly_occupied - 1]) |
| 552 |
# Restricted open-shell. |
| 553 |
elif doubly_occupied > 0 and singly_occupied > 0: |
| 554 |
self.set_attribute('homos', [doubly_occupied + singly_occupied - 1, |
| 555 |
doubly_occupied - 1]) |
| 556 |
# Unrestricted. |
| 557 |
else: |
| 558 |
assert len(self.moenergies) == 2 |
| 559 |
assert doubly_occupied == 0 |
| 560 |
assert self.mooccnos[1].count(2) == 0 |
| 561 |
nbeta = self.mooccnos[1].count(1) |
| 562 |
self.set_attribute('homos', [singly_occupied - 1, nbeta - 1]) |
| 563 |
|
| 564 |
# So nbasis was parsed at first with the first pattern, but it turns out that |
| 565 |
# semiempirical methods (at least AM1 as reported by Julien Idé) do not use this. |
| 566 |
# For this reason, also check for the second patterns, and use it as an assert |
| 567 |
# if nbasis was already parsed. Regression PCB_1_122.out covers this test case. |
| 568 |
if line[1:32] == "# of contracted basis functions": |
| 569 |
self.set_attribute('nbasis', int(line.split()[-1])) |
| 570 |
if line[1:27] == "Basis Dimension Dim": |
| 571 |
self.set_attribute('nbasis', int(line.split()[-1])) |
| 572 |
|
| 573 |
if line[0:14] == "OVERLAP MATRIX": |
| 574 |
|
| 575 |
self.skip_line(inputfile, 'dashes') |
| 576 |
|
| 577 |
self.aooverlaps = numpy.zeros((self.nbasis, self.nbasis), "d") |
| 578 |
for i in range(0, self.nbasis, 6): |
| 579 |
self.updateprogress(inputfile, "Overlap") |
| 580 |
|
| 581 |
header = next(inputfile) |
| 582 |
size = len(header.split()) |
| 583 |
|
| 584 |
for j in range(self.nbasis): |
| 585 |
line = next(inputfile) |
| 586 |
broken = line.split() |
| 587 |
self.aooverlaps[j, i:i+size] = list(map(float, broken[1:size+1])) |
| 588 |
|
| 589 |
# Molecular orbital coefficients are parsed here, but also related things |
| 590 |
#like atombasis and aonames if possible. |
| 591 |
# |
| 592 |
# Normally the output is easy to parse like this: |
| 593 |
# ------------------ |
| 594 |
# MOLECULAR ORBITALS |
| 595 |
# ------------------ |
| 596 |
# 0 1 2 3 4 5 |
| 597 |
# -19.28527 -19.26828 -19.26356 -19.25801 -19.25765 -19.21471 |
| 598 |
# 2.00000 2.00000 2.00000 2.00000 2.00000 2.00000 |
| 599 |
# -------- -------- -------- -------- -------- -------- |
| 600 |
# 0C 1s 0.000002 -0.000001 0.000000 0.000000 -0.000000 0.000001 |
| 601 |
# 0C 2s -0.000007 0.000006 -0.000002 -0.000000 0.000001 -0.000003 |
| 602 |
# 0C 3s -0.000086 -0.000061 0.000058 -0.000033 -0.000027 -0.000058 |
| 603 |
# ... |
| 604 |
# |
| 605 |
# But when the numbers get big, things get yucky since ORCA does not use |
| 606 |
# fixed width formatting for the floats, and does not insert extra spaces |
| 607 |
# when the numbers get wider. So things get stuck together overflowing columns, |
| 608 |
# like this: |
| 609 |
# 12C 6s -11.608845-53.775398161.302640-76.633779 29.914985 22.083999 |
| 610 |
# |
| 611 |
# One assumption that seems to hold is that there are always six significant |
| 612 |
# digits in the coefficients, so we can try to use that to delineate numbers |
| 613 |
# when the parsing gets rough. This is what we do below with a regex, and a case |
| 614 |
# like this is tested in regression ORCA/ORCA4.0/invalid-literal-for-float.out |
| 615 |
# which was reported in https://github.com/cclib/cclib/issues/629 |
| 616 |
if line[0:18] == "MOLECULAR ORBITALS": |
| 617 |
|
| 618 |
self.skip_line(inputfile, 'dashes') |
| 619 |
|
| 620 |
aonames = [] |
| 621 |
atombasis = [[] for i in range(self.natom)] |
| 622 |
mocoeffs = [numpy.zeros((self.nbasis, self.nbasis), "d")] |
| 623 |
|
| 624 |
for spin in range(len(self.moenergies)): |
| 625 |
|
| 626 |
if spin == 1: |
| 627 |
self.skip_line(inputfile, 'blank') |
| 628 |
mocoeffs.append(numpy.zeros((self.nbasis, self.nbasis), "d")) |
| 629 |
|
| 630 |
for i in range(0, self.nbasis, 6): |
| 631 |
|
| 632 |
self.updateprogress(inputfile, "Coefficients") |
| 633 |
|
| 634 |
self.skip_lines(inputfile, ['numbers', 'energies', 'occs']) |
| 635 |
dashes = next(inputfile) |
| 636 |
|
| 637 |
for j in range(self.nbasis): |
| 638 |
line = next(inputfile) |
| 639 |
|
| 640 |
# Only need this in the first iteration. |
| 641 |
if spin == 0 and i == 0: |
| 642 |
atomname = line[3:5].split()[0] |
| 643 |
num = int(line[0:3]) |
| 644 |
orbital = line.split()[1].upper() |
| 645 |
|
| 646 |
aonames.append("%s%i_%s" % (atomname, num+1, orbital)) |
| 647 |
atombasis[num].append(j) |
| 648 |
|
| 649 |
# This regex will tease out all number with exactly |
| 650 |
# six digits after the decimal point. |
| 651 |
coeffs = re.findall('-?\d+\.\d{6}', line) |
| 652 |
|
| 653 |
# Something is very wrong if this does not hold. |
| 654 |
assert len(coeffs) <= 6 |
| 655 |
|
| 656 |
mocoeffs[spin][i:i+len(coeffs), j] = [float(c) for c in coeffs] |
| 657 |
|
| 658 |
self.set_attribute('aonames', aonames) |
| 659 |
self.set_attribute('atombasis', atombasis) |
| 660 |
self.set_attribute("mocoeffs", mocoeffs) |
| 661 |
|
| 662 |
# Basis set information |
| 663 |
# ORCA prints this out in a somewhat indirect fashion. |
| 664 |
# Therefore, parsing occurs in several steps: |
| 665 |
# 1. read which atom belongs to which basis set group |
| 666 |
if line[0:21] == "BASIS SET INFORMATION": |
| 667 |
line = next(inputfile) |
| 668 |
line = next(inputfile) |
| 669 |
|
| 670 |
self.tmp_atnames = [] # temporary attribute, needed later |
| 671 |
while(not line[0:5] == '-----'): |
| 672 |
if line[0:4] == "Atom": |
| 673 |
self.tmp_atnames.append(line[8:12].strip()) |
| 674 |
line = next(inputfile) |
| 675 |
|
| 676 |
# 2. Read information for the basis set groups |
| 677 |
if line[0:25] == "BASIS SET IN INPUT FORMAT": |
| 678 |
line = next(inputfile) |
| 679 |
line = next(inputfile) |
| 680 |
|
| 681 |
# loop over basis set groups |
| 682 |
gbasis_tmp = {} |
| 683 |
while(not line[0:5] == '-----'): |
| 684 |
if line[1:7] == 'NewGTO': |
| 685 |
bas_atname = line.split()[1] |
| 686 |
gbasis_tmp[bas_atname] = [] |
| 687 |
|
| 688 |
line = next(inputfile) |
| 689 |
# loop over contracted GTOs |
| 690 |
while(not line[0:6] == ' end;'): |
| 691 |
words = line.split() |
| 692 |
ang = words[0] |
| 693 |
nprim = int(words[1]) |
| 694 |
|
| 695 |
# loop over primitives |
| 696 |
coeff = [] |
| 697 |
for iprim in range(nprim): |
| 698 |
words = next(inputfile).split() |
| 699 |
coeff.append( (float(words[1]), float(words[2])) ) |
| 700 |
gbasis_tmp[bas_atname].append((ang, coeff)) |
| 701 |
|
| 702 |
line = next(inputfile) |
| 703 |
line = next(inputfile) |
| 704 |
|
| 705 |
# 3. Assign the basis sets to gbasis |
| 706 |
self.gbasis = [] |
| 707 |
for bas_atname in self.tmp_atnames: |
| 708 |
self.gbasis.append(gbasis_tmp[bas_atname]) |
| 709 |
del self.tmp_atnames |
| 710 |
|
| 711 |
""" Banner announcing Thermochemistry |
| 712 |
-------------------------- |
| 713 |
THERMOCHEMISTRY AT 298.15K |
| 714 |
-------------------------- |
| 715 |
""" |
| 716 |
if 'THERMOCHEMISTRY AT' == line[:18]: |
| 717 |
|
| 718 |
next(inputfile) |
| 719 |
next(inputfile) |
| 720 |
self.temperature = float(next(inputfile).split()[2]) |
| 721 |
self.pressure = float(next(inputfile).split()[2]) |
| 722 |
total_mass = float(next(inputfile).split()[3]) |
| 723 |
|
| 724 |
# Vibrations, rotations, and translations |
| 725 |
line = next(inputfile) |
| 726 |
while line[:17] != 'Electronic energy': |
| 727 |
line = next(inputfile) |
| 728 |
self.zpe = next(inputfile).split()[4] |
| 729 |
thermal_vibrational_correction = float(next(inputfile).split()[4]) |
| 730 |
thermal_rotional_correction = float(next(inputfile).split()[4]) |
| 731 |
thermal_translational_correction = float(next(inputfile).split()[4]) |
| 732 |
next(inputfile) |
| 733 |
total_thermal_energy = float(next(inputfile).split()[3]) |
| 734 |
|
| 735 |
# Enthalpy |
| 736 |
line = next(inputfile) |
| 737 |
while line[:17] != 'Total free energy': |
| 738 |
line = next(inputfile) |
| 739 |
thermal_enthalpy_correction = float(next(inputfile).split()[4]) |
| 740 |
next(inputfile) |
| 741 |
self.enthalpy = float(next(inputfile).split()[3]) |
| 742 |
|
| 743 |
# Entropy |
| 744 |
line = next(inputfile) |
| 745 |
while line[:18] != 'Electronic entropy': |
| 746 |
line = next(inputfile) |
| 747 |
electronic_entropy = float(line.split()[3]) |
| 748 |
vibrational_entropy = float(next(inputfile).split()[3]) |
| 749 |
rotational_entropy = float(next(inputfile).split()[3]) |
| 750 |
translational_entropy = float(next(inputfile).split()[3]) |
| 751 |
next(inputfile) |
| 752 |
self.entropy = float(next(inputfile).split()[4]) |
| 753 |
|
| 754 |
line = next(inputfile) |
| 755 |
while line[:25] != 'Final Gibbs free enthalpy': |
| 756 |
line = next(inputfile) |
| 757 |
self.freeenergy = float(line.split()[5]) |
| 758 |
|
| 759 |
# Read TDDFT information |
| 760 |
if any(x in line for x in ("TD-DFT/TDA EXCITED", "TD-DFT EXCITED")): |
| 761 |
# Could be singlets or triplets |
| 762 |
if line.find("SINGLETS") >= 0: |
| 763 |
sym = "Singlet" |
| 764 |
elif line.find("TRIPLETS") >= 0: |
| 765 |
sym = "Triplet" |
| 766 |
else: |
| 767 |
sym = "Not specified" |
| 768 |
|
| 769 |
etsecs = [] |
| 770 |
etenergies = [] |
| 771 |
etsyms = [] |
| 772 |
|
| 773 |
lookup = {'a': 0, 'b': 1} |
| 774 |
line = next(inputfile) |
| 775 |
while line.find("STATE") < 0: |
| 776 |
line = next(inputfile) |
| 777 |
# Contains STATE or is blank |
| 778 |
while line.find("STATE") >= 0: |
| 779 |
broken = line.split() |
| 780 |
etenergies.append(float(broken[-2])) |
| 781 |
etsyms.append(sym) |
| 782 |
line = next(inputfile) |
| 783 |
sec = [] |
| 784 |
# Contains SEC or is blank |
| 785 |
while line.strip(): |
| 786 |
start = line[0:8].strip() |
| 787 |
start = (int(start[:-1]), lookup[start[-1]]) |
| 788 |
end = line[10:17].strip() |
| 789 |
end = (int(end[:-1]), lookup[end[-1]]) |
| 790 |
# Coeffients are not printed for RPA, only |
| 791 |
# TDA/CIS. |
| 792 |
contrib = line[35:47].strip() |
| 793 |
try: |
| 794 |
contrib = float(contrib) |
| 795 |
except ValueError: |
| 796 |
contrib = numpy.nan |
| 797 |
sec.append([start, end, contrib]) |
| 798 |
line = next(inputfile) |
| 799 |
etsecs.append(sec) |
| 800 |
line = next(inputfile) |
| 801 |
|
| 802 |
self.extend_attribute('etenergies', etenergies) |
| 803 |
self.extend_attribute('etsecs', etsecs) |
| 804 |
self.extend_attribute('etsyms', etsyms) |
| 805 |
|
| 806 |
# Parse the various absorption spectra for TDDFT and ROCIS. |
| 807 |
if 'ABSORPTION SPECTRUM' in line or 'ELECTRIC DIPOLE' in line: |
| 808 |
# CASSCF has an anomalous printing of ABSORPTION SPECTRUM. |
| 809 |
if line[:-1] == 'ABSORPTION SPECTRUM': |
| 810 |
return |
| 811 |
|
| 812 |
line = line.strip() |
| 813 |
|
| 814 |
# Standard header, occasionally changes |
| 815 |
header = ['d', 'header', 'header', 'd'] |
| 816 |
|
| 817 |
def energy_intensity(line): |
| 818 |
""" TDDFT and related methods standard method of output |
| 819 |
----------------------------------------------------------------------------- |
| 820 |
ABSORPTION SPECTRUM VIA TRANSITION ELECTRIC DIPOLE MOMENTS |
| 821 |
----------------------------------------------------------------------------- |
| 822 |
State Energy Wavelength fosc T2 TX TY TZ |
| 823 |
(cm-1) (nm) (au**2) (au) (au) (au) |
| 824 |
----------------------------------------------------------------------------- |
| 825 |
1 5184116.7 1.9 0.040578220 0.00258 -0.05076 -0.00000 -0.00000 |
| 826 |
""" |
| 827 |
try: |
| 828 |
state, energy, wavelength, intensity, t2, tx, ty, tz = line.split() |
| 829 |
except ValueError as e: |
| 830 |
# Must be spin forbidden and thus no intensity |
| 831 |
energy = line.split()[1] |
| 832 |
intensity = 0 |
| 833 |
return energy, intensity |
| 834 |
|
| 835 |
# Check for variations |
| 836 |
if line == 'COMBINED ELECTRIC DIPOLE + MAGNETIC DIPOLE + ELECTRIC QUADRUPOLE SPECTRUM' or \ |
| 837 |
line == 'COMBINED ELECTRIC DIPOLE + MAGNETIC DIPOLE + ELECTRIC QUADRUPOLE SPECTRUM (origin adjusted)': |
| 838 |
def energy_intensity(line): |
| 839 |
""" TDDFT with DoQuad == True |
| 840 |
------------------------------------------------------------------------------------------------------ |
| 841 |
COMBINED ELECTRIC DIPOLE + MAGNETIC DIPOLE + ELECTRIC QUADRUPOLE SPECTRUM |
| 842 |
------------------------------------------------------------------------------------------------------ |
| 843 |
State Energy Wavelength D2 m2 Q2 D2+m2+Q2 D2/TOT m2/TOT Q2/TOT |
| 844 |
(cm-1) (nm) (*1e6) (*1e6) |
| 845 |
------------------------------------------------------------------------------------------------------ |
| 846 |
1 61784150.6 0.2 0.00000 0.00000 3.23572 0.00000323571519 0.00000 0.00000 1.00000 |
| 847 |
""" |
| 848 |
state, energy, wavelength, d2, m2, q2, intensity, d2_contrib, m2_contrib, q2_contrib = line.split() |
| 849 |
return energy, intensity |
| 850 |
|
| 851 |
elif line == 'COMBINED ELECTRIC DIPOLE + MAGNETIC DIPOLE + ELECTRIC QUADRUPOLE SPECTRUM (Origin Independent, Length Representation)': |
| 852 |
def energy_intensity(line): |
| 853 |
""" TDDFT with doQuad == True (Origin Independent Length Representation) |
| 854 |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 855 |
COMBINED ELECTRIC DIPOLE + MAGNETIC DIPOLE + ELECTRIC QUADRUPOLE SPECTRUM (Origin Independent, Length Representation) |
| 856 |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 857 |
State Energy Wavelength D2 m2 Q2 DM DO D2+m2+Q2+DM+DO D2/TOT m2/TOT Q2/TOT DM/TOT DO/TOT |
| 858 |
(cm-1) (nm) (*1e6) (*1e6) (*1e6) (*1e6) |
| 859 |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 860 |
1 61784150.6 0.2 0.00000 0.00000 3.23572 0.00000 0.00000 0.00000323571519 0.00000 0.00000 1.00000 0.00000 0.00000 |
| 861 |
2 61793079.3 0.2 0.00000 0.00000 2.85949 0.00000 -0.00000 0.00000285948800 0.00000 0.00000 1.00000 0.00000 -0.00000 |
| 862 |
""" |
| 863 |
vals = line.split() |
| 864 |
if len(vals) < 14: |
| 865 |
return vals[1], 0 |
| 866 |
return vals[1], vals[8] |
| 867 |
|
| 868 |
elif line[:5] == 'X-RAY' and \ |
| 869 |
(line[6:23] == 'EMISSION SPECTRUM' or line[6:25] == 'ABSORPTION SPECTRUM'): |
| 870 |
def energy_intensity(line): |
| 871 |
""" X-Ray from XES (emission or absorption, electric or velocity dipole moments) |
| 872 |
------------------------------------------------------------------------------------- |
| 873 |
X-RAY ABSORPTION SPECTRUM VIA TRANSITION ELECTRIC DIPOLE MOMENTS |
| 874 |
------------------------------------------------------------------------------------- |
| 875 |
Transition Energy INT TX TY TZ |
| 876 |
(eV) (normalized) (au) (au) (au) |
| 877 |
------------------------------------------------------------------------------------- |
| 878 |
1 90a -> 0a 8748.824 0.000002678629 0.00004 -0.00001 0.00003 |
| 879 |
""" |
| 880 |
state, start, arrow, end, energy, intensity, tx, ty, tz = line.split() |
| 881 |
return energy, intensity |
| 882 |
|
| 883 |
elif line[:70] == 'COMBINED ELECTRIC DIPOLE + MAGNETIC DIPOLE + ELECTRIC QUADRUPOLE X-RAY': |
| 884 |
header = ['header', 'd', 'header', 'd', 'header', 'header', 'd'] |
| 885 |
def energy_intensity(line): |
| 886 |
""" XAS with quadrupole (origin adjusted) |
| 887 |
------------------------------------------------------------------------------------------------------------------------------- |
| 888 |
COMBINED ELECTRIC DIPOLE + MAGNETIC DIPOLE + ELECTRIC QUADRUPOLE X-RAY ABSORPTION SPECTRUM |
| 889 |
(origin adjusted) |
| 890 |
------------------------------------------------------------------------------------------------------------------------------- |
| 891 |
INT (normalized) |
| 892 |
--------------------------------------------------------- |
| 893 |
Transition Energy D2 M2 Q2 D2+M2+Q2 D2/TOT M2/TOT Q2/TOT |
| 894 |
(eV) (*1e6) (*1e6) |
| 895 |
------------------------------------------------------------------------------------------------------------------------------- |
| 896 |
1 90a -> 0a 8748.824 0.000000 0.000292 0.003615 0.000000027512 0.858012 0.010602 0.131386 |
| 897 |
""" |
| 898 |
state, start, arrow, end, energy, d2, m2, q2, intensity, d2_contrib, m2_contrib, q2_contrib = line.split() |
| 899 |
return energy, intensity |
| 900 |
|
| 901 |
elif line[:55] == 'SPIN ORBIT CORRECTED ABSORPTION SPECTRUM VIA TRANSITION': |
| 902 |
def energy_intensity(line): |
| 903 |
""" ROCIS dipole approximation with SOC == True (electric or velocity dipole moments) |
| 904 |
------------------------------------------------------------------------------- |
| 905 |
SPIN ORBIT CORRECTED ABSORPTION SPECTRUM VIA TRANSITION ELECTRIC DIPOLE MOMENTS |
| 906 |
------------------------------------------------------------------------------- |
| 907 |
States Energy Wavelength fosc T2 TX TY TZ |
| 908 |
(cm-1) (nm) (au**2) (au) (au) (au) |
| 909 |
------------------------------------------------------------------------------- |
| 910 |
0 1 0.0 0.0 0.000000000 0.00000 0.00000 0.00000 0.00000 |
| 911 |
0 2 5184116.4 1.9 0.020288451 0.00258 0.05076 0.00003 0.00000 |
| 912 |
""" |
| 913 |
state, state2, energy, wavelength, intensity, t2, tx, ty, tz = line.split() |
| 914 |
return energy, intensity |
| 915 |
|
| 916 |
elif line[:79] == 'ROCIS COMBINED ELECTRIC DIPOLE + MAGNETIC DIPOLE + ELECTRIC QUADRUPOLE SPECTRUM' \ |
| 917 |
or line[:87] == 'SOC CORRECTED COMBINED ELECTRIC DIPOLE + MAGNETIC DIPOLE + ELECTRIC QUADRUPOLE SPECTRUM': |
| 918 |
def energy_intensity(line): |
| 919 |
""" ROCIS with DoQuad = True and SOC = True (also does origin adjusted) |
| 920 |
------------------------------------------------------------------------------------------------------ |
| 921 |
ROCIS COMBINED ELECTRIC DIPOLE + MAGNETIC DIPOLE + ELECTRIC QUADRUPOLE SPECTRUM |
| 922 |
------------------------------------------------------------------------------------------------------ |
| 923 |
States Energy Wavelength D2 m2 Q2 D2+m2+Q2 D2/TOT m2/TOT Q2/TOT |
| 924 |
(cm-1) (nm) (*1e6) (*1e6) (*population) |
| 925 |
------------------------------------------------------------------------------------------------------ |
| 926 |
0 1 0.0 0.0 0.00000 0.00000 0.00000 0.00000000000000 0.00000 0.00000 0.00000 |
| 927 |
0 2 669388066.6 0.0 0.00000 0.00000 0.00876 0.00000000437784 0.00000 0.00000 1.00000 |
| 928 |
""" |
| 929 |
state, state2, energy, wavelength, d2, m2, q2, intensity, d2_contrib, m2_contrib, q2_contrib = line.split() |
| 930 |
return energy, intensity |
| 931 |
|
| 932 |
# Clashes with Orca 2.6 (and presumably before) TDDFT absorption spectrum printing |
| 933 |
elif line == 'ABSORPTION SPECTRUM' and float(self.metadata['package_version']) > 2.6: |
| 934 |
def energy_intensity(line): |
| 935 |
""" CASSCF absorption spectrum |
| 936 |
------------------------------------------------------------------------------------------ |
| 937 |
ABSORPTION SPECTRUM |
| 938 |
------------------------------------------------------------------------------------------ |
| 939 |
States Energy Wavelength fosc T2 TX TY TZ |
| 940 |
(cm-1) (nm) (D**2) (D) (D) (D) |
| 941 |
------------------------------------------------------------------------------------------ |
| 942 |
0( 0)-> 1( 0) 1 83163.2 120.2 0.088250385 2.25340 0.00000 0.00000 1.50113 |
| 943 |
""" |
| 944 |
reg = r'(\d+)\( ?(\d+)\)-> ?(\d+)\( ?(\d+)\) (\d+)'+ '\s+(\d+\.\d+)'*4 + '\s+(-?\d+\.\d+)'*3 |
| 945 |
res = re.search(reg, line) |
| 946 |
jstate, jblock, istate, iblock, mult, energy, wavelength, intensity, t2, tx, ty, tz = res.groups() |
| 947 |
return energy, intensity |
| 948 |
|
| 949 |
name = line |
| 950 |
self.skip_lines(inputfile, header) |
| 951 |
|
| 952 |
if not hasattr(self, 'transprop'): |
| 953 |
self.transprop = {} |
| 954 |
|
| 955 |
etenergies = [] |
| 956 |
etoscs = [] |
| 957 |
line = next(inputfile) |
| 958 |
# The sections are occasionally ended with dashed lines |
| 959 |
# other times they are blank (other than a new line) |
| 960 |
while len(line.strip('-')) > 2: |
| 961 |
energy, intensity = energy_intensity(line) |
| 962 |
etenergies.append(float(energy)) |
| 963 |
etoscs.append(float(intensity)) |
| 964 |
|
| 965 |
line = next(inputfile) |
| 966 |
|
| 967 |
self.set_attribute('etenergies', etenergies) |
| 968 |
self.set_attribute('etoscs', etoscs) |
| 969 |
self.transprop[name] = (numpy.asarray(etenergies), numpy.asarray(etoscs)) |
| 970 |
|
| 971 |
if line.strip() == "CD SPECTRUM": |
| 972 |
# ------------------------------------------------------------------- |
| 973 |
# CD SPECTRUM |
| 974 |
# ------------------------------------------------------------------- |
| 975 |
# State Energy Wavelength R MX MY MZ |
| 976 |
# (cm-1) (nm) (1e40*cgs) (au) (au) (au) |
| 977 |
# ------------------------------------------------------------------- |
| 978 |
# 1 43167.6 231.7 0.00000 0.00000 -0.00000 0.00000 |
| 979 |
# |
| 980 |
etenergies = [] |
| 981 |
etrotats = [] |
| 982 |
self.skip_lines(inputfile, ["d", "State Energy Wavelength", "(cm-1) (nm)", "d"]) |
| 983 |
line = next(inputfile) |
| 984 |
while line.strip(): |
| 985 |
tokens = line.split() |
| 986 |
if "spin forbidden" in line: |
| 987 |
etrotat, mx, my, mz = 0.0, 0.0, 0.0, 0.0 |
| 988 |
else: |
| 989 |
etrotat, mx, my, mz = [self.float(t) for t in tokens[3:]] |
| 990 |
etenergies.append(self.float(tokens[1])) |
| 991 |
etrotats.append(etrotat) |
| 992 |
line = next(inputfile) |
| 993 |
self.set_attribute("etrotats", etrotats) |
| 994 |
if not hasattr(self, "etenergies"): |
| 995 |
self.logger.warning("etenergies not parsed before ECD section, " |
| 996 |
"the output file may be malformed") |
| 997 |
self.set_attribute("etenergies", etenergies) |
| 998 |
|
| 999 |
if line[:23] == "VIBRATIONAL FREQUENCIES": |
| 1000 |
self.skip_lines(inputfile, ['d', 'b']) |
| 1001 |
|
| 1002 |
# Starting with 4.1, a scaling factor for frequencies is printed |
| 1003 |
if float(self.metadata["package_version"][:3]) > 4.0: |
| 1004 |
self.skip_lines(inputfile, ['Scaling factor for frequencies', 'b']) |
| 1005 |
|
| 1006 |
vibfreqs = numpy.zeros(3 * self.natom) |
| 1007 |
for i, line in zip(range(3 * self.natom), inputfile): |
| 1008 |
vibfreqs[i] = float(line.split()[1]) |
| 1009 |
|
| 1010 |
nonzero = numpy.nonzero(vibfreqs)[0] |
| 1011 |
self.first_mode = nonzero[0] |
| 1012 |
# Take all modes after first |
| 1013 |
# Mode between imaginary and real modes could be 0 |
| 1014 |
self.num_modes = 3*self.natom - self.first_mode |
| 1015 |
if self.num_modes > 3*self.natom - 6: |
| 1016 |
msg = "Modes corresponding to rotations/translations may be non-zero." |
| 1017 |
if self.num_modes == 3*self.natom - 5: |
| 1018 |
msg += '\n You can ignore this if the molecule is linear.' |
| 1019 |
self.set_attribute('vibfreqs', vibfreqs[self.first_mode:]) |
| 1020 |
|
| 1021 |
# NORMAL MODES |
| 1022 |
# ------------ |
| 1023 |
# |
| 1024 |
# These modes are the cartesian displacements weighted by the diagonal matrix |
| 1025 |
# M(i,i)=1/sqrt(m[i]) where m[i] is the mass of the displaced atom |
| 1026 |
# Thus, these vectors are normalized but *not* orthogonal |
| 1027 |
# |
| 1028 |
# 0 1 2 3 4 5 |
| 1029 |
# 0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 |
| 1030 |
# 1 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 |
| 1031 |
# 2 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 |
| 1032 |
# ... |
| 1033 |
if line[:12] == "NORMAL MODES": |
| 1034 |
all_vibdisps = numpy.zeros((3 * self.natom, self.natom, 3), "d") |
| 1035 |
|
| 1036 |
self.skip_lines(inputfile, ['d', 'b', 'text', 'text', 'text', 'b']) |
| 1037 |
|
| 1038 |
for mode in range(0, 3 * self.natom, 6): |
| 1039 |
header = next(inputfile) |
| 1040 |
for atom in range(self.natom): |
| 1041 |
all_vibdisps[mode:mode + 6, atom, 0] = next(inputfile).split()[1:] |
| 1042 |
all_vibdisps[mode:mode + 6, atom, 1] = next(inputfile).split()[1:] |
| 1043 |
all_vibdisps[mode:mode + 6, atom, 2] = next(inputfile).split()[1:] |
| 1044 |
|
| 1045 |
self.set_attribute('vibdisps', all_vibdisps[self.first_mode:]) |
| 1046 |
|
| 1047 |
# ----------- |
| 1048 |
# IR SPECTRUM |
| 1049 |
# ----------- |
| 1050 |
# |
| 1051 |
# Mode freq (cm**-1) T**2 TX TY TZ |
| 1052 |
# ------------------------------------------------------------------- |
| 1053 |
# 6: 2069.36 1.674341 ( -0.000000 0.914970 -0.914970) |
| 1054 |
# 7: 3978.81 76.856228 ( 0.000000 6.199041 -6.199042) |
| 1055 |
# 8: 4113.34 61.077784 ( -0.000000 5.526201 5.526200) |
| 1056 |
if line[:11] == "IR SPECTRUM": |
| 1057 |
self.skip_lines(inputfile, ['d', 'b', 'header', 'd']) |
| 1058 |
|
| 1059 |
all_vibirs = numpy.zeros((3 * self.natom,), "d") |
| 1060 |
|
| 1061 |
line = next(inputfile) |
| 1062 |
while len(line) > 2: |
| 1063 |
num = int(line[0:4]) |
| 1064 |
all_vibirs[num] = float(line.split()[2]) |
| 1065 |
line = next(inputfile) |
| 1066 |
|
| 1067 |
self.set_attribute('vibirs', all_vibirs[self.first_mode:]) |
| 1068 |
|
| 1069 |
# -------------- |
| 1070 |
# RAMAN SPECTRUM |
| 1071 |
# -------------- |
| 1072 |
# |
| 1073 |
# Mode freq (cm**-1) Activity Depolarization |
| 1074 |
# ------------------------------------------------------------------- |
| 1075 |
# 6: 296.23 5.291229 0.399982 |
| 1076 |
# 7: 356.70 0.000000 0.749764 |
| 1077 |
# 8: 368.27 0.000000 0.202068 |
| 1078 |
if line[:14] == "RAMAN SPECTRUM": |
| 1079 |
self.skip_lines(inputfile, ['d', 'b', 'header', 'd']) |
| 1080 |
|
| 1081 |
all_vibramans = numpy.zeros(3 * self.natom) |
| 1082 |
|
| 1083 |
line = next(inputfile) |
| 1084 |
while len(line) > 2: |
| 1085 |
num = int(line[0:4]) |
| 1086 |
all_vibramans[num] = float(line.split()[2]) |
| 1087 |
line = next(inputfile) |
| 1088 |
|
| 1089 |
self.set_attribute('vibramans', all_vibramans[self.first_mode:]) |
| 1090 |
|
| 1091 |
|
| 1092 |
# ORCA will print atomic charges along with the spin populations, |
| 1093 |
# so care must be taken about choosing the proper column. |
| 1094 |
# Population analyses are performed usually only at the end |
| 1095 |
# of a geometry optimization or other run, so we want to |
| 1096 |
# leave just the final atom charges. |
| 1097 |
# Here is an example for Mulliken charges: |
| 1098 |
# -------------------------------------------- |
| 1099 |
# MULLIKEN ATOMIC CHARGES AND SPIN POPULATIONS |
| 1100 |
# -------------------------------------------- |
| 1101 |
# 0 H : 0.126447 0.002622 |
| 1102 |
# 1 C : -0.613018 -0.029484 |
| 1103 |
# 2 H : 0.189146 0.015452 |
| 1104 |
# 3 H : 0.320041 0.037434 |
| 1105 |
# ... |
| 1106 |
# Sum of atomic charges : -0.0000000 |
| 1107 |
# Sum of atomic spin populations: 1.0000000 |
| 1108 |
if line[:23] == "MULLIKEN ATOMIC CHARGES": |
| 1109 |
self.parse_charge_section(line, inputfile, 'mulliken') |
| 1110 |
# Things are the same for Lowdin populations, except that the sums |
| 1111 |
# are not printed (there is a blank line at the end). |
| 1112 |
if line[:22] == "LOEWDIN ATOMIC CHARGES": |
| 1113 |
self.parse_charge_section(line, inputfile, 'lowdin') |
| 1114 |
#CHELPG Charges |
| 1115 |
#-------------------------------- |
| 1116 |
# 0 C : 0.363939 |
| 1117 |
# 1 H : 0.025695 |
| 1118 |
# ... |
| 1119 |
#-------------------------------- |
| 1120 |
#Total charge: -0.000000 |
| 1121 |
#-------------------------------- |
| 1122 |
if line.startswith('CHELPG Charges'): |
| 1123 |
self.parse_charge_section(line, inputfile, 'chelpg') |
| 1124 |
|
| 1125 |
# It is not stated explicitely, but the dipole moment components printed by ORCA |
| 1126 |
# seem to be in atomic units, so they will need to be converted. Also, they |
| 1127 |
# are most probably calculated with respect to the origin . |
| 1128 |
# |
| 1129 |
# ------------- |
| 1130 |
# DIPOLE MOMENT |
| 1131 |
# ------------- |
| 1132 |
# X Y Z |
| 1133 |
# Electronic contribution: 0.00000 -0.00000 -0.00000 |
| 1134 |
# Nuclear contribution : 0.00000 0.00000 0.00000 |
| 1135 |
# ----------------------------------------- |
| 1136 |
# Total Dipole Moment : 0.00000 -0.00000 -0.00000 |
| 1137 |
# ----------------------------------------- |
| 1138 |
# Magnitude (a.u.) : 0.00000 |
| 1139 |
# Magnitude (Debye) : 0.00000 |
| 1140 |
# |
| 1141 |
if line.strip() == "DIPOLE MOMENT": |
| 1142 |
|
| 1143 |
self.skip_lines(inputfile, ['d', 'XYZ', 'electronic', 'nuclear', 'd']) |
| 1144 |
total = next(inputfile) |
| 1145 |
assert "Total Dipole Moment" in total |
| 1146 |
|
| 1147 |
reference = [0.0, 0.0, 0.0] |
| 1148 |
dipole = numpy.array([float(d) for d in total.split()[-3:]]) |
| 1149 |
dipole = utils.convertor(dipole, "ebohr", "Debye") |
| 1150 |
|
| 1151 |
if not hasattr(self, 'moments'): |
| 1152 |
self.set_attribute('moments', [reference, dipole]) |
| 1153 |
else: |
| 1154 |
try: |
| 1155 |
assert numpy.all(self.moments[1] == dipole) |
| 1156 |
except AssertionError: |
| 1157 |
self.logger.warning('Overwriting previous multipole moments with new values') |
| 1158 |
self.set_attribute('moments', [reference, dipole]) |
| 1159 |
|
| 1160 |
if "Molecular Dynamics Iteration" in line: |
| 1161 |
self.skip_lines(inputfile, ['d', 'ORCA MD', 'd', 'New Coordinates']) |
| 1162 |
line = next(inputfile) |
| 1163 |
tokens = line.split() |
| 1164 |
assert tokens[0] == "time" |
| 1165 |
time = utils.convertor(float(tokens[2]), "time_au", "fs") |
| 1166 |
self.append_attribute('time', time) |
| 1167 |
|
| 1168 |
# Static polarizability. |
| 1169 |
if line.strip() == "THE POLARIZABILITY TENSOR": |
| 1170 |
if not hasattr(self, 'polarizabilities'): |
| 1171 |
self.polarizabilities = [] |
| 1172 |
self.skip_lines(inputfile, ['d', 'b']) |
| 1173 |
line = next(inputfile) |
| 1174 |
assert line.strip() == "The raw cartesian tensor (atomic units):" |
| 1175 |
polarizability = [] |
| 1176 |
for _ in range(3): |
| 1177 |
line = next(inputfile) |
| 1178 |
polarizability.append(line.split()) |
| 1179 |
self.polarizabilities.append(numpy.array(polarizability)) |
| 1180 |
|
| 1181 |
if line.strip() == 'ORCA-CASSCF': |
| 1182 |
# ------------------------------------------------------------------------------- |
| 1183 |
# ORCA-CASSCF |
| 1184 |
# ------------------------------------------------------------------------------- |
| 1185 |
# |
| 1186 |
# Symmetry handling UseSym ... ON |
| 1187 |
# Point group ... C2 |
| 1188 |
# Used point group ... C2 |
| 1189 |
# Number of irreps ... 2 |
| 1190 |
# Irrep A has 10 SALCs (ofs= 0) #(closed)= 0 #(active)= 2 |
| 1191 |
# Irrep B has 10 SALCs (ofs= 10) #(closed)= 0 #(active)= 2 |
| 1192 |
# Symmetries of active orbitals: |
| 1193 |
# MO = 0 IRREP= 0 (A) |
| 1194 |
# MO = 1 IRREP= 1 (B) |
| 1195 |
self.skip_lines(inputfile, ['d', 'b']) |
| 1196 |
vals = next(inputfile).split() |
| 1197 |
# Symmetry section is only printed if symmetry is used. |
| 1198 |
if vals[0] == 'Symmetry': |
| 1199 |
assert vals[-1] == 'ON' |
| 1200 |
point_group = next(inputfile).split()[-1] |
| 1201 |
used_point_group = next(inputfile).split()[-1] |
| 1202 |
num_irreps = int(next(inputfile).split()[-1]) |
| 1203 |
num_active = 0 |
| 1204 |
# Parse the irreps. |
| 1205 |
for i, line in zip(range(num_irreps), inputfile): |
| 1206 |
reg = r'Irrep\s+(\w+) has\s+(\d+) SALCs \(ofs=\s*(\d+)\) #\(closed\)=\s*(\d+) #\(active\)=\s*(\d+)' |
| 1207 |
groups = re.search(reg, line).groups() |
| 1208 |
irrep = groups[0] |
| 1209 |
salcs, ofs, closed, active = map(int, groups[1:]) |
| 1210 |
num_active += active |
| 1211 |
self.skip_line(inputfile, 'Symmetries') |
| 1212 |
# Parse the symmetries of the active orbitals. |
| 1213 |
for i, line in zip(range(num_active), inputfile): |
| 1214 |
reg = r'(\d+) IRREP= (\d+) \((\w+)\)' |
| 1215 |
groups = re.search(reg, line).groups() |
| 1216 |
mo, irrep_idx, irrep = groups |
| 1217 |
|
| 1218 |
# Skip until the system specific settings. |
| 1219 |
# This will align the cases of symmetry on and off. |
| 1220 |
line = next(inputfile) |
| 1221 |
while line[:25] != 'SYSTEM-SPECIFIC SETTINGS:': |
| 1222 |
line = next(inputfile) |
| 1223 |
|
| 1224 |
# SYSTEM-SPECIFIC SETTINGS: |
| 1225 |
# Number of active electrons ... 4 |
| 1226 |
# Number of active orbitals ... 4 |
| 1227 |
# Total number of electrons ... 4 |
| 1228 |
# Total number of orbitals ... 20 |
| 1229 |
num_el = int(next(inputfile).split()[-1]) |
| 1230 |
num_orbs = int(next(inputfile).split()[-1]) |
| 1231 |
total_el = int(next(inputfile).split()[-1]) |
| 1232 |
total_orbs = int(next(inputfile).split()[-1]) |
| 1233 |
|
| 1234 |
# Determined orbital ranges: |
| 1235 |
# Internal 0 - -1 ( 0 orbitals) |
| 1236 |
# Active 0 - 3 ( 4 orbitals) |
| 1237 |
# External 4 - 19 ( 16 orbitals) |
| 1238 |
self.skip_lines(inputfile, ['b', 'Determined']) |
| 1239 |
orbital_ranges = [] |
| 1240 |
# Parse the orbital ranges for: Internal, Active, and External orbitals. |
| 1241 |
for i in range(3): |
| 1242 |
vals = next(inputfile).split() |
| 1243 |
start, end, num = int(vals[1]), int(vals[3]), int(vals[5]) |
| 1244 |
# Change from inclusive to exclusive in order to match python. |
| 1245 |
end = end + 1 |
| 1246 |
assert end - start == num |
| 1247 |
orbital_ranges.append((start, end, num)) |
| 1248 |
|
| 1249 |
line = next(inputfile) |
| 1250 |
while line[:8] != 'CI-STEP:': |
| 1251 |
line = next(inputfile) |
| 1252 |
|
| 1253 |
# CI-STEP: |
| 1254 |
# CI strategy ... General CI |
| 1255 |
# Number of symmetry/multplity blocks ... 1 |
| 1256 |
# BLOCK 1 WEIGHT= 1.0000 |
| 1257 |
# Multiplicity ... 1 |
| 1258 |
# Irrep ... 0 (A) |
| 1259 |
# #(Configurations) ... 11 |
| 1260 |
# #(CSFs) ... 12 |
| 1261 |
# #(Roots) ... 1 |
| 1262 |
# ROOT=0 WEIGHT= 1.000000 |
| 1263 |
self.skip_line(inputfile, 'CI strategy') |
| 1264 |
num_blocks = int(next(inputfile).split()[-1]) |
| 1265 |
for b in range(1, num_blocks + 1): |
| 1266 |
vals = next(inputfile).split() |
| 1267 |
block = int(vals[1]) |
| 1268 |
weight = float(vals[3]) |
| 1269 |
assert b == block |
| 1270 |
mult = int(next(inputfile).split()[-1]) |
| 1271 |
vals = next(inputfile).split() |
| 1272 |
# The irrep will only be printed if using symmetry. |
| 1273 |
if vals[0] == 'Irrep': |
| 1274 |
irrep_idx = int(vals[-2]) |
| 1275 |
irrep = vals[-1].strip('()') |
| 1276 |
vals = next(inputfile).split() |
| 1277 |
num_confs = int(vals[-1]) |
| 1278 |
num_csfs = int(next(inputfile).split()[-1]) |
| 1279 |
num_roots = int(next(inputfile).split()[-1]) |
| 1280 |
# Parse the roots. |
| 1281 |
for r, line in zip(range(num_roots), inputfile): |
| 1282 |
reg = r'=(\d+) WEIGHT=\s*(\d\.\d+)' |
| 1283 |
groups = re.search(reg, line).groups() |
| 1284 |
root = int(groups[0]) |
| 1285 |
weight = float(groups[1]) |
| 1286 |
assert r == root |
| 1287 |
|
| 1288 |
# Skip additional setup printing and CASSCF iterations. |
| 1289 |
line = next(inputfile).strip() |
| 1290 |
while line != 'CASSCF RESULTS': |
| 1291 |
line = next(inputfile).strip() |
| 1292 |
|
| 1293 |
# -------------- |
| 1294 |
# CASSCF RESULTS |
| 1295 |
# -------------- |
| 1296 |
# |
| 1297 |
# Final CASSCF energy : -14.597120777 Eh -397.2078 eV |
| 1298 |
self.skip_lines(inputfile, ['d', 'b']) |
| 1299 |
casscf_energy = float(next(inputfile).split()[4]) |
| 1300 |
|
| 1301 |
# This is only printed for first and last step of geometry optimization. |
| 1302 |
# ---------------- |
| 1303 |
# ORBITAL ENERGIES |
| 1304 |
# ---------------- |
| 1305 |
# |
| 1306 |
# NO OCC E(Eh) E(eV) Irrep |
| 1307 |
# 0 0.0868 0.257841 7.0162 1-A |
| 1308 |
self.skip_lines(inputfile, ['b', 'd']) |
| 1309 |
if next(inputfile).strip() == 'ORBITAL ENERGIES': |
| 1310 |
self.skip_lines(inputfile, ['d', 'b', 'NO']) |
| 1311 |
orbitals = [] |
| 1312 |
vals = next(inputfile).split() |
| 1313 |
while vals: |
| 1314 |
occ, eh, ev = map(float, vals[1:4]) |
| 1315 |
# The irrep will only be printed if using symmetry. |
| 1316 |
if len(vals) == 5: |
| 1317 |
idx, irrep = vals[4].split('-') |
| 1318 |
orbitals.append((occ, ev, int(idx), irrep)) |
| 1319 |
else: |
| 1320 |
orbitals.append((occ, ev)) |
| 1321 |
vals = next(inputfile).split() |
| 1322 |
self.skip_lines(inputfile, ['b', 'd']) |
| 1323 |
|
| 1324 |
# Orbital Compositions |
| 1325 |
# --------------------------------------------- |
| 1326 |
# CAS-SCF STATES FOR BLOCK 1 MULT= 1 IRREP= Ag NROOTS= 2 |
| 1327 |
# --------------------------------------------- |
| 1328 |
# |
| 1329 |
# ROOT 0: E= -14.5950507665 Eh |
| 1330 |
# 0.89724 [ 0]: 2000 |
| 1331 |
for b in range(num_blocks): |
| 1332 |
# Parse the block data. |
| 1333 |
reg = r'BLOCK\s+(\d+) MULT=\s*(\d+) (IRREP=\s*\w+ )?(NROOTS=\s*(\d+))?' |
| 1334 |
groups = re.search(reg, next(inputfile)).groups() |
| 1335 |
block = int(groups[0]) |
| 1336 |
mult = int(groups[1]) |
| 1337 |
# The irrep will only be printed if using symmetry. |
| 1338 |
if groups[2] is not None: |
| 1339 |
irrep = groups[2].split('=')[1].strip() |
| 1340 |
nroots = int(groups[3].split('=')[1]) |
| 1341 |
|
| 1342 |
self.skip_lines(inputfile, ['d', 'b']) |
| 1343 |
|
| 1344 |
line = next(inputfile).strip() |
| 1345 |
while line: |
| 1346 |
if line[:4] == 'ROOT': |
| 1347 |
# Parse the root section. |
| 1348 |
reg = r'(\d+):\s*E=\s*(-?\d+.\d+) Eh(\s+\d+\.\d+ eV)?(\s+\d+\.\d+)?' |
| 1349 |
groups = re.search(reg, line).groups() |
| 1350 |
root = int(groups[0]) |
| 1351 |
energy = float(groups[1]) |
| 1352 |
# Excitation energies are only printed for excited state roots. |
| 1353 |
if groups[2] is not None: |
| 1354 |
excitation_energy_ev = float(groups[2].split()[0]) |
| 1355 |
excitation_energy_cm = float(groups[3]) |
| 1356 |
else: |
| 1357 |
# Parse the occupations section. |
| 1358 |
reg = r'(\d+\.\d+) \[\s*(\d+)\]: (\d+)' |
| 1359 |
groups = re.search(reg, line).groups() |
| 1360 |
coeff = float(groups[0]) |
| 1361 |
number = float(groups[1]) |
| 1362 |
occupations = list(map(int, groups[2])) |
| 1363 |
|
| 1364 |
line = next(inputfile).strip() |
| 1365 |
|
| 1366 |
# Skip any extended wavefunction printing. |
| 1367 |
while line != 'DENSITY MATRIX': |
| 1368 |
line = next(inputfile).strip() |
| 1369 |
|
| 1370 |
self.skip_lines(inputfile, ['d', 'b']) |
| 1371 |
# -------------- |
| 1372 |
# DENSITY MATRIX |
| 1373 |
# -------------- |
| 1374 |
# |
| 1375 |
# 0 1 2 3 |
| 1376 |
# 0 0.897244 0.000000 0.000000 0.000000 |
| 1377 |
# 1 0.000000 0.533964 0.000000 0.000000 |
| 1378 |
density = numpy.zeros((num_orbs, num_orbs)) |
| 1379 |
for i in range(0, num_orbs, 6): |
| 1380 |
next(inputfile) |
| 1381 |
for j, line in zip(range(num_orbs), inputfile): |
| 1382 |
density[j][i:i + 6] = list(map(float, line.split()[1:])) |
| 1383 |
self.skip_lines(inputfile, ['Trace', 'b', 'd']) |
| 1384 |
|
| 1385 |
# This is only printed for open-shells. |
| 1386 |
# ------------------- |
| 1387 |
# SPIN-DENSITY MATRIX |
| 1388 |
# ------------------- |
| 1389 |
# |
| 1390 |
# 0 1 2 3 4 5 |
| 1391 |
# 0 -0.003709 0.001410 0.000074 -0.000564 -0.007978 0.000735 |
| 1392 |
# 1 0.001410 -0.001750 -0.000544 -0.003815 0.008462 -0.004529 |
| 1393 |
if next(inputfile).strip() == 'SPIN-DENSITY MATRIX': |
| 1394 |
self.skip_lines(inputfile, ['d', 'b']) |
| 1395 |
spin_density = numpy.zeros((num_orbs, num_orbs)) |
| 1396 |
for i in range(0, num_orbs, 6): |
| 1397 |
next(inputfile) |
| 1398 |
for j, line in zip(range(num_orbs), inputfile): |
| 1399 |
spin_density[j][i:i + 6] = list(map(float, line.split()[1:])) |
| 1400 |
self.skip_lines(inputfile, ['Trace', 'b', 'd', 'ENERGY']) |
| 1401 |
self.skip_lines(inputfile, ['d', 'b']) |
| 1402 |
|
| 1403 |
# ----------------- |
| 1404 |
# ENERGY COMPONENTS |
| 1405 |
# ----------------- |
| 1406 |
# |
| 1407 |
# One electron energy : -18.811767801 Eh -511.8942 eV |
| 1408 |
# Two electron energy : 4.367616074 Eh 118.8489 eV |
| 1409 |
# Nuclear repuslion energy : 0.000000000 Eh 0.0000 eV |
| 1410 |
# ---------------- |
| 1411 |
# -14.444151727 |
| 1412 |
# |
| 1413 |
# Kinetic energy : 14.371970266 Eh 391.0812 eV |
| 1414 |
# Potential energy : -28.816121993 Eh -784.1265 eV |
| 1415 |
# Virial ratio : -2.005022378 |
| 1416 |
# ---------------- |
| 1417 |
# -14.444151727 |
| 1418 |
# |
| 1419 |
# Core energy : -13.604678408 Eh -370.2021 eV |
| 1420 |
one_el_energy = float(next(inputfile).split()[4]) |
| 1421 |
two_el_energy = float(next(inputfile).split()[4]) |
| 1422 |
nuclear_repulsion_energy = float(next(inputfile).split()[4]) |
| 1423 |
self.skip_line(inputfile, 'dashes') |
| 1424 |
energy = float(next(inputfile).strip()) |
| 1425 |
self.skip_line(inputfile, 'blank') |
| 1426 |
kinetic_energy = float(next(inputfile).split()[3]) |
| 1427 |
potential_energy = float(next(inputfile).split()[3]) |
| 1428 |
virial_ratio = float(next(inputfile).split()[3]) |
| 1429 |
self.skip_line(inputfile, 'dashes') |
| 1430 |
energy = float(next(inputfile).strip()) |
| 1431 |
self.skip_line(inputfile, 'blank') |
| 1432 |
core_energy = float(next(inputfile).split()[3]) |
| 1433 |
|
| 1434 |
if line[:15] == 'TOTAL RUN TIME:': |
| 1435 |
self.metadata['success'] = True |
| 1436 |
|
| 1437 |
def parse_charge_section(self, line, inputfile, chargestype): |
| 1438 |
"""Parse a charge section, modifies class in place |
| 1439 |
|
| 1440 |
Parameters |
| 1441 |
---------- |
| 1442 |
line : str |
| 1443 |
the line which triggered entry here |
| 1444 |
inputfile : file |
| 1445 |
handle to file object |
| 1446 |
chargestype : str |
| 1447 |
what type of charge we're dealing with, must be one of |
| 1448 |
'mulliken', 'lowdin' or 'chelpg' |
| 1449 |
""" |
| 1450 |
has_spins = 'AND SPIN POPULATIONS' in line |
| 1451 |
|
| 1452 |
if not hasattr(self, "atomcharges"): |
| 1453 |
self.atomcharges = {} |
| 1454 |
if has_spins and not hasattr(self, "atomspins"): |
| 1455 |
self.atomspins = {} |
| 1456 |
|
| 1457 |
self.skip_line(inputfile, 'dashes') |
| 1458 |
|
| 1459 |
# depending on chargestype, decide when to stop parsing lines |
| 1460 |
# start, stop - indices for slicing lines and grabbing values |
| 1461 |
if chargestype == 'mulliken': |
| 1462 |
should_stop = lambda x: x.startswith('Sum of atomic charges') |
| 1463 |
start, stop = 8, 20 |
| 1464 |
elif chargestype == 'lowdin': |
| 1465 |
# stops when blank line encountered |
| 1466 |
should_stop = lambda x: not bool(x.strip()) |
| 1467 |
start, stop = 8, 20 |
| 1468 |
elif chargestype == 'chelpg': |
| 1469 |
should_stop = lambda x: x.startswith('---') |
| 1470 |
start, stop = 11, 26 |
| 1471 |
|
| 1472 |
charges = [] |
| 1473 |
if has_spins: |
| 1474 |
spins = [] |
| 1475 |
|
| 1476 |
line = next(inputfile) |
| 1477 |
while not should_stop(line): |
| 1478 |
# Don't add point charges or embedding potentials. |
| 1479 |
if "Q :" not in line: |
| 1480 |
charges.append(float(line[start:stop])) |
| 1481 |
if has_spins: |
| 1482 |
spins.append(float(line[stop:])) |
| 1483 |
line = next(inputfile) |
| 1484 |
|
| 1485 |
self.atomcharges[chargestype] = charges |
| 1486 |
if has_spins: |
| 1487 |
self.atomspins[chargestype] = spins |
| 1488 |
|
| 1489 |
def parse_scf_condensed_format(self, inputfile, line): |
| 1490 |
""" Parse the SCF convergence information in condensed format """ |
| 1491 |
|
| 1492 |
# This is what it looks like |
| 1493 |
# ITER Energy Delta-E Max-DP RMS-DP [F,P] Damp |
| 1494 |
# *** Starting incremental Fock matrix formation *** |
| 1495 |
# 0 -384.5203638934 0.000000000000 0.03375012 0.00223249 0.1351565 0.7000 |
| 1496 |
# 1 -384.5792776162 -0.058913722842 0.02841696 0.00175952 0.0734529 0.7000 |
| 1497 |
# ***Turning on DIIS*** |
| 1498 |
# 2 -384.6074211837 -0.028143567475 0.04968025 0.00326114 0.0310435 0.0000 |
| 1499 |
# 3 -384.6479682063 -0.040547022616 0.02097477 0.00121132 0.0361982 0.0000 |
| 1500 |
# 4 -384.6571124353 -0.009144228947 0.00576471 0.00035160 0.0061205 0.0000 |
| 1501 |
# 5 -384.6574659959 -0.000353560584 0.00191156 0.00010160 0.0025838 0.0000 |
| 1502 |
# 6 -384.6574990782 -0.000033082375 0.00052492 0.00003800 0.0002061 0.0000 |
| 1503 |
# 7 -384.6575005762 -0.000001497987 0.00020257 0.00001146 0.0001652 0.0000 |
| 1504 |
# 8 -384.6575007321 -0.000000155848 0.00008572 0.00000435 0.0000745 0.0000 |
| 1505 |
# **** Energy Check signals convergence **** |
| 1506 |
|
| 1507 |
assert line[2] == "Delta-E" |
| 1508 |
assert line[3] == "Max-DP" |
| 1509 |
|
| 1510 |
if not hasattr(self, "scfvalues"): |
| 1511 |
self.scfvalues = [] |
| 1512 |
|
| 1513 |
self.scfvalues.append([]) |
| 1514 |
|
| 1515 |
# Try to keep track of the converger (NR, DIIS, SOSCF, etc.). |
| 1516 |
diis_active = True |
| 1517 |
while line: |
| 1518 |
|
| 1519 |
maxDP = None |
| 1520 |
if 'Newton-Raphson' in line: |
| 1521 |
diis_active = False |
| 1522 |
elif 'SOSCF' in line: |
| 1523 |
diis_active = False |
| 1524 |
elif line[0].isdigit(): |
| 1525 |
shim = 0 |
| 1526 |
try: |
| 1527 |
energy = float(line[1]) |
| 1528 |
deltaE = float(line[2]) |
| 1529 |
maxDP = float(line[3 + int(not diis_active)]) |
| 1530 |
rmsDP = float(line[4 + int(not diis_active)]) |
| 1531 |
except ValueError as e: |
| 1532 |
# Someone in Orca forgot to properly add spaces in the scf printing |
| 1533 |
# code looks like: |
| 1534 |
# %3i %17.10f%12.12f%11.8f %11.8f |
| 1535 |
if line[1].count('.') == 2: |
| 1536 |
integer1, decimal1_integer2, decimal2 = line[1].split('.') |
| 1537 |
decimal1, integer2 = decimal1_integer2[:10], decimal1_integer2[10:] |
| 1538 |
energy = float(integer1 + '.' + decimal1) |
| 1539 |
deltaE = float(integer2 + '.' + decimal2) |
| 1540 |
maxDP = float(line[2 + int(not diis_active)]) |
| 1541 |
rmsDP = float(line[3 + int(not diis_active)]) |
| 1542 |
elif line[1].count('.') == 3: |
| 1543 |
integer1, decimal1_integer2, decimal2_integer3, decimal3 = line[1].split('.') |
| 1544 |
decimal1, integer2 = decimal1_integer2[:10], decimal1_integer2[10:] |
| 1545 |
decimal2, integer3 = decimal2_integer3[:12], decimal2_integer3[12:] |
| 1546 |
energy = float(integer1 + '.' + decimal1) |
| 1547 |
deltaE = float(integer2 + '.' + decimal2) |
| 1548 |
maxDP = float(integer3 + '.' + decimal3) |
| 1549 |
rmsDP = float(line[2 + int(not diis_active)]) |
| 1550 |
elif line[2].count('.') == 2: |
| 1551 |
integer1, decimal1_integer2, decimal2 = line[2].split('.') |
| 1552 |
decimal1, integer2 = decimal1_integer2[:12], decimal1_integer2[12:] |
| 1553 |
deltaE = float(integer1 + '.' + decimal1) |
| 1554 |
maxDP = float(integer2 + '.' + decimal2) |
| 1555 |
rmsDP = float(line[3 + int(not diis_active)]) |
| 1556 |
else: |
| 1557 |
raise e |
| 1558 |
|
| 1559 |
self.scfvalues[-1].append([deltaE, maxDP, rmsDP]) |
| 1560 |
|
| 1561 |
try: |
| 1562 |
line = next(inputfile).split() |
| 1563 |
except StopIteration: |
| 1564 |
self.logger.warning('File terminated before end of last SCF! Last Max-DP: {}'.format(maxDP)) |
| 1565 |
break |
| 1566 |
|
| 1567 |
def parse_scf_expanded_format(self, inputfile, line): |
| 1568 |
""" Parse SCF convergence when in expanded format. """ |
| 1569 |
|
| 1570 |
# The following is an example of the format |
| 1571 |
# ----------------------------------------- |
| 1572 |
# |
| 1573 |
# *** Starting incremental Fock matrix formation *** |
| 1574 |
# |
| 1575 |
# ---------------------------- |
| 1576 |
# ! ITERATION 0 ! |
| 1577 |
# ---------------------------- |
| 1578 |
# Total Energy : -377.960836651297 Eh |
| 1579 |
# Energy Change : -377.960836651297 Eh |
| 1580 |
# MAX-DP : 0.100175793695 |
| 1581 |
# RMS-DP : 0.004437973661 |
| 1582 |
# Actual Damping : 0.7000 |
| 1583 |
# Actual Level Shift : 0.2500 Eh |
| 1584 |
# Int. Num. El. : 43.99982197 (UP= 21.99991099 DN= 21.99991099) |
| 1585 |
# Exchange : -34.27550826 |
| 1586 |
# Correlation : -2.02540957 |
| 1587 |
# |
| 1588 |
# |
| 1589 |
# ---------------------------- |
| 1590 |
# ! ITERATION 1 ! |
| 1591 |
# ---------------------------- |
| 1592 |
# Total Energy : -378.118458080109 Eh |
| 1593 |
# Energy Change : -0.157621428812 Eh |
| 1594 |
# MAX-DP : 0.053240648588 |
| 1595 |
# RMS-DP : 0.002375092508 |
| 1596 |
# Actual Damping : 0.7000 |
| 1597 |
# Actual Level Shift : 0.2500 Eh |
| 1598 |
# Int. Num. El. : 43.99994143 (UP= 21.99997071 DN= 21.99997071) |
| 1599 |
# Exchange : -34.00291075 |
| 1600 |
# Correlation : -2.01607243 |
| 1601 |
# |
| 1602 |
# ***Turning on DIIS*** |
| 1603 |
# |
| 1604 |
# ---------------------------- |
| 1605 |
# ! ITERATION 2 ! |
| 1606 |
# ---------------------------- |
| 1607 |
# .... |
| 1608 |
# |
| 1609 |
if not hasattr(self, "scfvalues"): |
| 1610 |
self.scfvalues = [] |
| 1611 |
|
| 1612 |
self.scfvalues.append([]) |
| 1613 |
|
| 1614 |
line = "Foo" # dummy argument to enter loop |
| 1615 |
while line.find("******") < 0: |
| 1616 |
try: |
| 1617 |
line = next(inputfile) |
| 1618 |
except StopIteration: |
| 1619 |
self.logger.warning('File terminated before end of last SCF!') |
| 1620 |
break |
| 1621 |
info = line.split() |
| 1622 |
if len(info) > 1 and info[1] == "ITERATION": |
| 1623 |
dashes = next(inputfile) |
| 1624 |
energy_line = next(inputfile).split() |
| 1625 |
energy = float(energy_line[3]) |
| 1626 |
deltaE_line = next(inputfile).split() |
| 1627 |
deltaE = float(deltaE_line[3]) |
| 1628 |
if energy == deltaE: |
| 1629 |
deltaE = 0 |
| 1630 |
maxDP_line = next(inputfile).split() |
| 1631 |
maxDP = float(maxDP_line[2]) |
| 1632 |
rmsDP_line = next(inputfile).split() |
| 1633 |
rmsDP = float(rmsDP_line[2]) |
| 1634 |
self.scfvalues[-1].append([deltaE, maxDP, rmsDP]) |
| 1635 |
|
| 1636 |
return |
| 1637 |
|
| 1638 |
# end of parse_scf_expanded_format |
| 1639 |
|
| 1640 |
def _append_scfvalues_scftargets(self, inputfile, line): |
| 1641 |
# The SCF convergence targets are always printed after this, but apparently |
| 1642 |
# not all of them always -- for example the RMS Density is missing for geometry |
| 1643 |
# optimization steps. So, assume the previous value is still valid if it is |
| 1644 |
# not found. For additional certainty, assert that the other targets are unchanged. |
| 1645 |
while not "Last Energy change" in line: |
| 1646 |
line = next(inputfile) |
| 1647 |
deltaE_value = float(line.split()[4]) |
| 1648 |
deltaE_target = float(line.split()[7]) |
| 1649 |
line = next(inputfile) |
| 1650 |
if "Last MAX-Density change" in line: |
| 1651 |
maxDP_value = float(line.split()[4]) |
| 1652 |
maxDP_target = float(line.split()[7]) |
| 1653 |
line = next(inputfile) |
| 1654 |
if "Last RMS-Density change" in line: |
| 1655 |
rmsDP_value = float(line.split()[4]) |
| 1656 |
rmsDP_target = float(line.split()[7]) |
| 1657 |
else: |
| 1658 |
rmsDP_value = self.scfvalues[-1][-1][2] |
| 1659 |
rmsDP_target = self.scftargets[-1][2] |
| 1660 |
assert deltaE_target == self.scftargets[-1][0] |
| 1661 |
assert maxDP_target == self.scftargets[-1][1] |
| 1662 |
self.scfvalues[-1].append([deltaE_value, maxDP_value, rmsDP_value]) |
| 1663 |
self.scftargets.append([deltaE_target, maxDP_target, rmsDP_target]) |