| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# |
| 3 |
# Copyright (c) 2018, 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 Molcas output files""" |
| 9 |
|
| 10 |
from __future__ import print_function |
| 11 |
|
| 12 |
import re |
| 13 |
import string |
| 14 |
|
| 15 |
import numpy |
| 16 |
|
| 17 |
from cclib.parser import logfileparser |
| 18 |
from cclib.parser import utils |
| 19 |
|
| 20 |
|
| 21 |
class Molcas(logfileparser.Logfile): |
| 22 |
"""A Molcas log file.""" |
| 23 |
|
| 24 |
def __init__(self, *args, **kwargs): |
| 25 |
|
| 26 |
# Call the __init__ method of the superclass |
| 27 |
super(Molcas, self).__init__(logname="Molcas", *args, **kwargs) |
| 28 |
|
| 29 |
def __str__(self): |
| 30 |
"""Return a string repeesentation of the object.""" |
| 31 |
return "Molcas log file %s" % (self.filename) |
| 32 |
|
| 33 |
def __repr__(self): |
| 34 |
"""Return a representation of the object.""" |
| 35 |
return 'Molcas("%s")' % (self.filename) |
| 36 |
|
| 37 |
#These are yet to be implemented. |
| 38 |
def normalisesym(self, label): |
| 39 |
"""Does Molcas require symmetry label normalization?""" |
| 40 |
|
| 41 |
def after_parsing(self): |
| 42 |
for element, ncore in self.core_array: |
| 43 |
self._assign_coreelectrons_to_element(element, ncore) |
| 44 |
|
| 45 |
def before_parsing(self): |
| 46 |
# Compile the regex for extracting the element symbol from the |
| 47 |
# atom label in the "Molecular structure info" block. |
| 48 |
self.re_atomelement = re.compile('([a-zA-Z]+)\d?') |
| 49 |
|
| 50 |
# Compile the dashes-and-or-spaces-only regex. |
| 51 |
self.re_dashes_and_spaces = re.compile('^[\s-]+$') |
| 52 |
|
| 53 |
# Molcas can do multiple calculations in one job, and each one |
| 54 |
# starts from the gateway module. Onle parse the first. |
| 55 |
# TODO: It would be best to parse each calculation as a separate |
| 56 |
# ccData object and return an iterator - something for 2.x |
| 57 |
self.gateway_module_count = 0 |
| 58 |
|
| 59 |
def extract(self, inputfile, line): |
| 60 |
"""Extract information from the file object inputfile.""" |
| 61 |
|
| 62 |
if "Start Module: gateway" in line: |
| 63 |
self.gateway_module_count += 1 |
| 64 |
|
| 65 |
if self.gateway_module_count > 1: |
| 66 |
return |
| 67 |
|
| 68 |
# Extract the version number and optionally the Git tag and hash. |
| 69 |
if "version" in line: |
| 70 |
match = re.search(r"\s{2,}version\s(\d*\.\d*)", line) |
| 71 |
if match: |
| 72 |
package_version = match.groups()[0] |
| 73 |
self.metadata["package_version"] = package_version |
| 74 |
# Don't add revision information to the main package version for now. |
| 75 |
if "tag" in line: |
| 76 |
tag = line.split()[-1] |
| 77 |
if "build" in line: |
| 78 |
match = re.search(r"\*\s*build\s(\S*)\s*\*", line) |
| 79 |
if match: |
| 80 |
revision = match.groups()[0] |
| 81 |
|
| 82 |
## This section is present when executing &GATEWAY. |
| 83 |
# ++ Molecular structure info: |
| 84 |
# ------------------------- |
| 85 |
|
| 86 |
# ************************************************ |
| 87 |
# **** Cartesian Coordinates / Bohr, Angstrom **** |
| 88 |
# ************************************************ |
| 89 |
|
| 90 |
# Center Label x y z x y z |
| 91 |
# 1 C1 0.526628 -2.582937 0.000000 0.278679 -1.366832 0.000000 |
| 92 |
# 2 C2 2.500165 -0.834760 0.000000 1.323030 -0.441736 0.000000 |
| 93 |
if line[25:63] == 'Cartesian Coordinates / Bohr, Angstrom': |
| 94 |
if not hasattr(self, 'atomnos'): |
| 95 |
self.atomnos = [] |
| 96 |
|
| 97 |
self.skip_lines(inputfile, ['stars', 'blank', 'header']) |
| 98 |
|
| 99 |
line = next(inputfile) |
| 100 |
|
| 101 |
atomelements = [] |
| 102 |
atomcoords = [] |
| 103 |
|
| 104 |
while line.strip() not in ('', '--'): |
| 105 |
sline = line.split() |
| 106 |
atomelement = sline[1].rstrip(string.digits).title() |
| 107 |
atomelements.append(atomelement) |
| 108 |
atomcoords.append(list(map(float, sline[5:]))) |
| 109 |
line = next(inputfile) |
| 110 |
|
| 111 |
self.append_attribute('atomcoords', atomcoords) |
| 112 |
|
| 113 |
if self.atomnos == []: |
| 114 |
self.atomnos = [self.table.number[ae.title()] for ae in atomelements] |
| 115 |
|
| 116 |
if not hasattr(self, 'natom'): |
| 117 |
self.set_attribute('natom', len(self.atomnos)) |
| 118 |
|
| 119 |
## This section is present when executing &SCF. |
| 120 |
# ++ Orbital specifications: |
| 121 |
# ----------------------- |
| 122 |
|
| 123 |
# Symmetry species 1 |
| 124 |
|
| 125 |
# Frozen orbitals 0 |
| 126 |
# Occupied orbitals 3 |
| 127 |
# Secondary orbitals 77 |
| 128 |
# Deleted orbitals 0 |
| 129 |
# Total number of orbitals 80 |
| 130 |
# Number of basis functions 80 |
| 131 |
# -- |
| 132 |
if line[:29] == '++ Orbital specifications:': |
| 133 |
|
| 134 |
self.skip_lines(inputfile, ['dashes', 'blank']) |
| 135 |
line = next(inputfile) |
| 136 |
|
| 137 |
symmetry_count = 1 |
| 138 |
while not line.startswith('--'): |
| 139 |
if line.strip().startswith('Symmetry species'): |
| 140 |
symmetry_count = int(line.split()[-1]) |
| 141 |
if line.strip().startswith('Total number of orbitals'): |
| 142 |
nmos = line.split()[-symmetry_count:] |
| 143 |
self.set_attribute('nmo', sum(map(int, nmos))) |
| 144 |
if line.strip().startswith('Number of basis functions'): |
| 145 |
nbasis = line.split()[-symmetry_count:] |
| 146 |
self.set_attribute('nbasis', sum(map(int, nbasis))) |
| 147 |
|
| 148 |
line = next(inputfile) |
| 149 |
|
| 150 |
if line.strip().startswith(('Molecular charge', 'Total molecular charge')): |
| 151 |
self.set_attribute('charge', int(float(line.split()[-1]))) |
| 152 |
|
| 153 |
# ++ Molecular charges: |
| 154 |
# ------------------ |
| 155 |
|
| 156 |
# Mulliken charges per centre and basis function type |
| 157 |
# --------------------------------------------------- |
| 158 |
|
| 159 |
# C1 |
| 160 |
# 1s 2.0005 |
| 161 |
# 2s 2.0207 |
| 162 |
# 2px 0.0253 |
| 163 |
# 2pz 0.1147 |
| 164 |
# 2py 1.8198 |
| 165 |
# *s -0.0215 |
| 166 |
# *px 0.0005 |
| 167 |
# *pz 0.0023 |
| 168 |
# *py 0.0368 |
| 169 |
# *d2+ 0.0002 |
| 170 |
# *d1+ 0.0000 |
| 171 |
# *d0 0.0000 |
| 172 |
# *d1- 0.0000 |
| 173 |
# *d2- 0.0000 |
| 174 |
# *f3+ 0.0000 |
| 175 |
# *f2+ 0.0001 |
| 176 |
# *f1+ 0.0000 |
| 177 |
# *f0 0.0001 |
| 178 |
# *f1- 0.0001 |
| 179 |
# *f2- 0.0000 |
| 180 |
# *f3- 0.0003 |
| 181 |
# *g4+ 0.0000 |
| 182 |
# *g3+ 0.0000 |
| 183 |
# *g2+ 0.0000 |
| 184 |
# *g1+ 0.0000 |
| 185 |
# *g0 0.0000 |
| 186 |
# *g1- 0.0000 |
| 187 |
# *g2- 0.0000 |
| 188 |
# *g3- 0.0000 |
| 189 |
# *g4- 0.0000 |
| 190 |
# Total 6.0000 |
| 191 |
|
| 192 |
# N-E 0.0000 |
| 193 |
|
| 194 |
# Total electronic charge= 6.000000 |
| 195 |
|
| 196 |
# Total charge= 0.000000 |
| 197 |
#-- |
| 198 |
if line[:24] == '++ Molecular charges:': |
| 199 |
|
| 200 |
atomcharges = [] |
| 201 |
|
| 202 |
while line[6:29] != 'Total electronic charge': |
| 203 |
line = next(inputfile) |
| 204 |
if line[6:9] == 'N-E': |
| 205 |
atomcharges.extend(map(float, line.split()[1:])) |
| 206 |
|
| 207 |
# Molcas only performs Mulliken population analysis. |
| 208 |
self.set_attribute('atomcharges', {'mulliken': atomcharges}) |
| 209 |
|
| 210 |
# Ensure the charge printed here is identical to the |
| 211 |
# charge printed before entering the SCF. |
| 212 |
self.skip_line(inputfile, 'blank') |
| 213 |
line = next(inputfile) |
| 214 |
assert line[6:30] == 'Total charge=' |
| 215 |
if hasattr(self, 'charge'): |
| 216 |
assert int(float(line.split()[2])) == self.charge |
| 217 |
|
| 218 |
# This section is present when executing &SCF |
| 219 |
# This section parses the total SCF Energy. |
| 220 |
# ***************************************************************************************************************************** |
| 221 |
# * * |
| 222 |
# * SCF/KS-DFT Program, Final results * |
| 223 |
# * * |
| 224 |
# * * |
| 225 |
# * * |
| 226 |
# * Final Results * |
| 227 |
# * * |
| 228 |
# ***************************************************************************************************************************** |
| 229 |
|
| 230 |
# :: Total SCF energy -37.6045426484 |
| 231 |
if line[:22] == ':: Total SCF energy' or line[:25] == ':: Total KS-DFT energy': |
| 232 |
if not hasattr(self, 'scfenergies'): |
| 233 |
self.scfenergies = [] |
| 234 |
scfenergy = float(line.split()[-1]) |
| 235 |
self.scfenergies.append(utils.convertor(scfenergy, 'hartree', 'eV')) |
| 236 |
|
| 237 |
## Parsing the scftargets in this section |
| 238 |
# ++ Optimization specifications: |
| 239 |
# ---------------------------- |
| 240 |
|
| 241 |
# SCF Algorithm: Conventional |
| 242 |
# Minimized density differences are used |
| 243 |
# Number of density matrices in core 9 |
| 244 |
# Maximum number of NDDO SCF iterations 400 |
| 245 |
# Maximum number of HF SCF iterations 400 |
| 246 |
# Threshold for SCF energy change 0.10E-08 |
| 247 |
# Threshold for density matrix 0.10E-03 |
| 248 |
# Threshold for Fock matrix 0.15E-03 |
| 249 |
# Threshold for linear dependence 0.10E-08 |
| 250 |
# Threshold at which DIIS is turned on 0.15E+00 |
| 251 |
# Threshold at which QNR/C2DIIS is turned on 0.75E-01 |
| 252 |
# Threshold for Norm(delta) (QNR/C2DIIS) 0.20E-04 |
| 253 |
if line[:34] == '++ Optimization specifications:': |
| 254 |
self.skip_lines(inputfile, ['d', 'b']) |
| 255 |
line = next(inputfile) |
| 256 |
if line.strip().startswith('SCF'): |
| 257 |
scftargets = [] |
| 258 |
self.skip_lines(inputfile, |
| 259 |
['Minimized', 'Number', 'Maximum', 'Maximum']) |
| 260 |
lines = [next(inputfile) for i in range(7)] |
| 261 |
targets = [ |
| 262 |
'Threshold for SCF energy change', |
| 263 |
'Threshold for density matrix', |
| 264 |
'Threshold for Fock matrix', |
| 265 |
'Threshold for Norm(delta)', |
| 266 |
] |
| 267 |
for y in targets: |
| 268 |
scftargets.extend([float(x.split()[-1]) for x in lines if y in x]) |
| 269 |
|
| 270 |
self.append_attribute('scftargets', scftargets) |
| 271 |
|
| 272 |
# ++ Convergence information |
| 273 |
# SCF iterations: Energy and convergence statistics |
| 274 |
# |
| 275 |
# Iter Tot. SCF One-electron Two-electron Energy Max Dij or Max Fij DNorm TNorm AccCon Time |
| 276 |
# Energy Energy Energy Change Delta Norm in Sec. |
| 277 |
# 1 -36.83817703 -50.43096166 13.59278464 0.00E+00 0.16E+00* 0.27E+01* 0.30E+01 0.33E+02 NoneDa 0. |
| 278 |
# 2 -36.03405202 -45.74525152 9.71119950 0.80E+00* 0.14E+00* 0.93E-02* 0.26E+01 0.43E+01 Damp 0. |
| 279 |
# 3 -37.08936118 -48.41536598 11.32600480 -0.11E+01* 0.12E+00* 0.91E-01* 0.97E+00 0.16E+01 Damp 0. |
| 280 |
# 4 -37.31610460 -50.54103969 13.22493509 -0.23E+00* 0.11E+00* 0.96E-01* 0.72E+00 0.27E+01 Damp 0. |
| 281 |
# 5 -37.33596239 -49.47021484 12.13425245 -0.20E-01* 0.59E-01* 0.59E-01* 0.37E+00 0.16E+01 Damp 0. |
| 282 |
# ... |
| 283 |
# Convergence after 26 Macro Iterations |
| 284 |
# -- |
| 285 |
if line[46:91] == 'iterations: Energy and convergence statistics': |
| 286 |
|
| 287 |
self.skip_line(inputfile, 'blank') |
| 288 |
|
| 289 |
while line.split() != ['Energy', 'Energy', 'Energy', 'Change', 'Delta', 'Norm', 'in', 'Sec.']: |
| 290 |
line = next(inputfile) |
| 291 |
|
| 292 |
iteration_regex = ("^([0-9]+)" # Iter |
| 293 |
"( [ \-0-9]*\.[0-9]{6,9})" # Tot. SCF Energy |
| 294 |
"( [ \-0-9]*\.[0-9]{6,9})" # One-electron Energy |
| 295 |
"( [ \-0-9]*\.[0-9]{6,9})" # Two-electron Energy |
| 296 |
"( [ \-0-9]*\.[0-9]{2}E[\-\+][0-9]{2}\*?)" # Energy Change |
| 297 |
"( [ \-0-9]*\.[0-9]{2}E[\-\+][0-9]{2}\*?)" # Max Dij or Delta Norm |
| 298 |
"( [ \-0-9]*\.[0-9]{2}E[\-\+][0-9]{2}\*?)" # Max Fij |
| 299 |
"( [ \-0-9]*\.[0-9]{2}E[\-\+][0-9]{2}\*?)" # DNorm |
| 300 |
"( [ \-0-9]*\.[0-9]{2}E[\-\+][0-9]{2}\*?)" # TNorm |
| 301 |
"( [ A-Za-z0-9]*)" # AccCon |
| 302 |
"( [ \.0-9]*)$") # Time in Sec. |
| 303 |
|
| 304 |
scfvalues = [] |
| 305 |
line = next(inputfile) |
| 306 |
while not line.strip().startswith("Convergence"): |
| 307 |
|
| 308 |
match = re.match(iteration_regex, line.strip()) |
| 309 |
if match: |
| 310 |
groups = match.groups() |
| 311 |
cols = [g.strip() for g in match.groups()] |
| 312 |
cols = [c.replace('*', '') for c in cols] |
| 313 |
|
| 314 |
energy = float(cols[4]) |
| 315 |
density = float(cols[5]) |
| 316 |
fock = float(cols[6]) |
| 317 |
dnorm = float(cols[7]) |
| 318 |
scfvalues.append([energy, density, fock, dnorm]) |
| 319 |
|
| 320 |
if line.strip() == "--": |
| 321 |
self.logger.warning('File terminated before end of last SCF!') |
| 322 |
break |
| 323 |
|
| 324 |
line = next(inputfile) |
| 325 |
|
| 326 |
self.append_attribute('scfvalues', scfvalues) |
| 327 |
|
| 328 |
# Harmonic frequencies in cm-1 |
| 329 |
# |
| 330 |
# IR Intensities in km/mol |
| 331 |
# |
| 332 |
# 1 2 3 4 5 6 |
| 333 |
# |
| 334 |
# Frequency: i60.14 i57.39 128.18 210.06 298.24 309.65 |
| 335 |
# |
| 336 |
# Intensity: 3.177E-03 2.129E-06 4.767E-01 2.056E-01 6.983E-07 1.753E-07 |
| 337 |
# Red. mass: 2.42030 2.34024 2.68044 3.66414 2.61721 3.34904 |
| 338 |
# |
| 339 |
# C1 x -0.00000 0.00000 0.00000 -0.05921 0.00000 -0.06807 |
| 340 |
# C1 y 0.00001 -0.00001 -0.00001 0.00889 0.00001 -0.02479 |
| 341 |
# C1 z -0.03190 0.04096 -0.03872 0.00001 -0.12398 -0.00002 |
| 342 |
# C2 x -0.00000 0.00001 0.00000 -0.06504 0.00000 -0.03487 |
| 343 |
# C2 y 0.00000 -0.00000 -0.00000 0.01045 0.00001 -0.05659 |
| 344 |
# C2 z -0.03703 -0.03449 -0.07269 0.00000 -0.07416 -0.00001 |
| 345 |
# C3 x -0.00000 0.00001 0.00000 -0.06409 -0.00001 0.05110 |
| 346 |
# C3 y -0.00000 0.00001 0.00000 0.00152 0.00000 -0.03263 |
| 347 |
# C3 z -0.03808 -0.08037 -0.07267 -0.00001 0.07305 0.00000 |
| 348 |
# ... |
| 349 |
# H20 y 0.00245 -0.00394 0.03215 0.03444 -0.10424 -0.10517 |
| 350 |
# H20 z 0.00002 -0.00001 0.00000 -0.00000 -0.00000 0.00000 |
| 351 |
# |
| 352 |
# |
| 353 |
# |
| 354 |
# ++ Thermochemistry |
| 355 |
if line[1:29] == 'Harmonic frequencies in cm-1': |
| 356 |
|
| 357 |
self.skip_line(inputfile, 'blank') |
| 358 |
line = next(inputfile) |
| 359 |
|
| 360 |
while 'Thermochemistry' not in line: |
| 361 |
|
| 362 |
if 'Frequency:' in line: |
| 363 |
if not hasattr(self, 'vibfreqs'): |
| 364 |
self.vibfreqs = [] |
| 365 |
vibfreqs = [float(i.replace('i', '-')) for i in line.split()[1:]] |
| 366 |
self.vibfreqs.extend(vibfreqs) |
| 367 |
|
| 368 |
if 'Intensity:' in line: |
| 369 |
if not hasattr(self, 'vibirs'): |
| 370 |
self.vibirs = [] |
| 371 |
vibirs = map(float, line.split()[1:]) |
| 372 |
self.vibirs.extend(vibirs) |
| 373 |
|
| 374 |
if 'Red.' in line: |
| 375 |
self.skip_line(inputfile, 'blank') |
| 376 |
line = next(inputfile) |
| 377 |
if not hasattr(self, 'vibdisps'): |
| 378 |
self.vibdisps = [] |
| 379 |
disps = [] |
| 380 |
for n in range(3*self.natom): |
| 381 |
numbers = [float(s) for s in line[17:].split()] |
| 382 |
# The atomindex should start at 0 instead of 1. |
| 383 |
atomindex = int(re.search(r'\d+$', line.split()[0]).group()) - 1 |
| 384 |
numbermodes = len(numbers) |
| 385 |
if len(disps) == 0: |
| 386 |
# Appends empty array of the following |
| 387 |
# dimensions (numbermodes, natom, 0) to disps. |
| 388 |
for mode in range(numbermodes): |
| 389 |
disps.append([[] for x in range(0, self.natom)]) |
| 390 |
for mode in range(numbermodes): |
| 391 |
disps[mode][atomindex].append(numbers[mode]) |
| 392 |
line = next(inputfile) |
| 393 |
self.vibdisps.extend(disps) |
| 394 |
|
| 395 |
line = next(inputfile) |
| 396 |
|
| 397 |
## Parsing thermochemistry attributes here |
| 398 |
# ++ Thermochemistry |
| 399 |
# |
| 400 |
# ********************* |
| 401 |
# * * |
| 402 |
# * THERMOCHEMISTRY * |
| 403 |
# * * |
| 404 |
# ********************* |
| 405 |
# |
| 406 |
# Mass-centered Coordinates (Angstrom): |
| 407 |
# *********************************************************** |
| 408 |
# ... |
| 409 |
# ***************************************************** |
| 410 |
# Temperature = 0.00 Kelvin, Pressure = 1.00 atm |
| 411 |
# ----------------------------------------------------- |
| 412 |
# Molecular Partition Function and Molar Entropy: |
| 413 |
# q/V (M**-3) S(kcal/mol*K) |
| 414 |
# Electronic 0.100000D+01 0.000 |
| 415 |
# Translational 0.100000D+01 0.000 |
| 416 |
# Rotational 0.100000D+01 2.981 |
| 417 |
# Vibrational 0.100000D+01 0.000 |
| 418 |
# TOTAL 0.100000D+01 2.981 |
| 419 |
# |
| 420 |
# Thermal contributions to INTERNAL ENERGY: |
| 421 |
# Electronic 0.000 kcal/mol 0.000000 au. |
| 422 |
# Translational 0.000 kcal/mol 0.000000 au. |
| 423 |
# Rotational 0.000 kcal/mol 0.000000 au. |
| 424 |
# Vibrational 111.885 kcal/mol 0.178300 au. |
| 425 |
# TOTAL 111.885 kcal/mol 0.178300 au. |
| 426 |
# |
| 427 |
# Thermal contributions to |
| 428 |
# ENTHALPY 111.885 kcal/mol 0.178300 au. |
| 429 |
# GIBBS FREE ENERGY 111.885 kcal/mol 0.178300 au. |
| 430 |
# |
| 431 |
# Sum of energy and thermal contributions |
| 432 |
# INTERNAL ENERGY -382.121931 au. |
| 433 |
# ENTHALPY -382.121931 au. |
| 434 |
# GIBBS FREE ENERGY -382.121931 au. |
| 435 |
# ----------------------------------------------------- |
| 436 |
# ... |
| 437 |
# ENTHALPY -382.102619 au. |
| 438 |
# GIBBS FREE ENERGY -382.179819 au. |
| 439 |
# ----------------------------------------------------- |
| 440 |
# -- |
| 441 |
# |
| 442 |
# ++ Isotopic shifts: |
| 443 |
if line[4:19] == 'THERMOCHEMISTRY': |
| 444 |
|
| 445 |
temperature_values = [] |
| 446 |
pressure_values = [] |
| 447 |
entropy_values = [] |
| 448 |
internal_energy_values = [] |
| 449 |
enthalpy_values = [] |
| 450 |
free_energy_values = [] |
| 451 |
|
| 452 |
while 'Isotopic' not in line: |
| 453 |
|
| 454 |
if line[1:12] == 'Temperature': |
| 455 |
temperature_values.append(float(line.split()[2])) |
| 456 |
pressure_values.append(float(line.split()[6])) |
| 457 |
|
| 458 |
if line[1:48] == 'Molecular Partition Function and Molar Entropy:': |
| 459 |
while 'TOTAL' not in line: |
| 460 |
line = next(inputfile) |
| 461 |
entropy_values.append(utils.convertor(float(line.split()[2]), 'kcal/mol', 'hartree')) |
| 462 |
|
| 463 |
if line[1:40] == 'Sum of energy and thermal contributions': |
| 464 |
internal_energy_values.append(float(next(inputfile).split()[2])) |
| 465 |
enthalpy_values.append(float(next(inputfile).split()[1])) |
| 466 |
free_energy_values.append(float(next(inputfile).split()[3])) |
| 467 |
|
| 468 |
line = next(inputfile) |
| 469 |
# When calculations for more than one temperature value are |
| 470 |
# performed, the values corresponding to room temperature (298.15 K) |
| 471 |
# are returned and if no calculations are performed for 298.15 K, then |
| 472 |
# the values corresponding last temperature value are returned. |
| 473 |
index = -1 |
| 474 |
if 298.15 in temperature_values: |
| 475 |
index = temperature_values.index(298.15) |
| 476 |
|
| 477 |
self.set_attribute('temperature', temperature_values[index]) |
| 478 |
if len(temperature_values) > 1: |
| 479 |
self.logger.warning('More than 1 values of temperature found') |
| 480 |
|
| 481 |
self.set_attribute('pressure', pressure_values[index]) |
| 482 |
if len(pressure_values) > 1: |
| 483 |
self.logger.warning('More than 1 values of pressure found') |
| 484 |
|
| 485 |
self.set_attribute('entropy', entropy_values[index]) |
| 486 |
if len(entropy_values) > 1: |
| 487 |
self.logger.warning('More than 1 values of entropy found') |
| 488 |
|
| 489 |
self.set_attribute('enthalpy', enthalpy_values[index]) |
| 490 |
if len(enthalpy_values) > 1: |
| 491 |
self.logger.warning('More than 1 values of enthalpy found') |
| 492 |
|
| 493 |
self.set_attribute('freeenergy', free_energy_values[index]) |
| 494 |
if len(free_energy_values) > 1: |
| 495 |
self.logger.warning('More than 1 values of freeenergy found') |
| 496 |
|
| 497 |
## Parsing Geometrical Optimization attributes in this section. |
| 498 |
# ++ Slapaf input parameters: |
| 499 |
# ------------------------ |
| 500 |
# |
| 501 |
# Max iterations: 2000 |
| 502 |
# Convergence test a la Schlegel. |
| 503 |
# Convergence criterion on gradient/para.<=: 0.3E-03 |
| 504 |
# Convergence criterion on step/parameter<=: 0.3E-03 |
| 505 |
# Convergence criterion on energy change <=: 0.0E+00 |
| 506 |
# Max change of an internal coordinate: 0.30E+00 |
| 507 |
# ... |
| 508 |
# ... |
| 509 |
# ********************************************************************************************************************** |
| 510 |
# * Energy Statistics for Geometry Optimization * |
| 511 |
# ********************************************************************************************************************** |
| 512 |
# Energy Grad Grad Step Estimated Geom Hessian |
| 513 |
# Iter Energy Change Norm Max Element Max Element Final Energy Update Update Index |
| 514 |
# 1 -382.30023222 0.00000000 0.107221 0.039531 nrc047 0.085726 nrc047 -382.30533799 RS-RFO None 0 |
| 515 |
# 2 -382.30702964 -0.00679742 0.043573 0.014908 nrc001 0.068195 nrc001 -382.30871333 RS-RFO BFGS 0 |
| 516 |
# 3 -382.30805348 -0.00102384 0.014883 0.005458 nrc010 -0.020973 nrc001 -382.30822089 RS-RFO BFGS 0 |
| 517 |
# ... |
| 518 |
# ... |
| 519 |
# 18 -382.30823419 -0.00000136 0.001032 0.000100 nrc053 0.012319 nrc053 -382.30823452 RS-RFO BFGS 0 |
| 520 |
# 19 -382.30823198 0.00000221 0.001051 -0.000092 nrc054 0.066565 nrc053 -382.30823822 RS-RFO BFGS 0 |
| 521 |
# 20 -382.30820252 0.00002946 0.001132 -0.000167 nrc021 -0.064003 nrc053 -382.30823244 RS-RFO BFGS 0 |
| 522 |
# |
| 523 |
# +----------------------------------+----------------------------------+ |
| 524 |
# + Cartesian Displacements + Gradient in internals + |
| 525 |
# + Value Threshold Converged? + Value Threshold Converged? + |
| 526 |
# +-----+----------------------------------+----------------------------------+ |
| 527 |
# + RMS + 5.7330E-02 1.2000E-03 No + 1.6508E-04 3.0000E-04 Yes + |
| 528 |
# +-----+----------------------------------+----------------------------------+ |
| 529 |
# + Max + 1.2039E-01 1.8000E-03 No + 1.6711E-04 4.5000E-04 Yes + |
| 530 |
# +-----+----------------------------------+----------------------------------+ |
| 531 |
if 'Convergence criterion on energy change' in line: |
| 532 |
self.energy_threshold = float(line.split()[6]) |
| 533 |
# If energy change threshold equals zero, |
| 534 |
# then energy change is not a criteria for convergence. |
| 535 |
if self.energy_threshold == 0: |
| 536 |
self.energy_threshold = numpy.inf |
| 537 |
|
| 538 |
if 'Energy Statistics for Geometry Optimization' in line: |
| 539 |
if not hasattr(self, 'geovalues'): |
| 540 |
self.geovalues = [] |
| 541 |
|
| 542 |
self.skip_lines(inputfile, ['stars', 'header']) |
| 543 |
line = next(inputfile) |
| 544 |
assert 'Iter Energy Change Norm' in line |
| 545 |
# A variable keeping track of ongoing iteration. |
| 546 |
iter_number = len(self.geovalues) + 1 |
| 547 |
# Iterate till blank line. |
| 548 |
while line.split() != []: |
| 549 |
for i in range(iter_number): |
| 550 |
line = next(inputfile) |
| 551 |
self.geovalues.append([float(line.split()[2])]) |
| 552 |
line = next(inputfile) |
| 553 |
# Along with energy change, RMS and Max values of change in |
| 554 |
# Cartesian Diaplacement and Gradients are used as optimization |
| 555 |
# criteria. |
| 556 |
self.skip_lines(inputfile, ['border', 'header', 'header', 'border']) |
| 557 |
line = next(inputfile) |
| 558 |
assert '+ RMS +' in line |
| 559 |
line_rms = line.split() |
| 560 |
line = next(inputfile) |
| 561 |
line_max = next(inputfile).split() |
| 562 |
if not hasattr(self, 'geotargets'): |
| 563 |
# The attribute geotargets is an array consisting of the following |
| 564 |
# values: [Energy threshold, Max Gradient threshold, RMS Gradient threshold, \ |
| 565 |
# Max Displacements threshold, RMS Displacements threshold]. |
| 566 |
max_gradient_threshold = float(line_max[8]) |
| 567 |
rms_gradient_threshold = float(line_rms[8]) |
| 568 |
max_displacement_threshold = float(line_max[4]) |
| 569 |
rms_displacement_threshold = float(line_rms[4]) |
| 570 |
self.geotargets = [self.energy_threshold, max_gradient_threshold, rms_gradient_threshold, max_displacement_threshold, rms_displacement_threshold] |
| 571 |
|
| 572 |
max_gradient_change = float(line_max[7]) |
| 573 |
rms_gradient_change = float(line_rms[7]) |
| 574 |
max_displacement_change = float(line_max[3]) |
| 575 |
rms_displacement_change = float(line_rms[3]) |
| 576 |
self.geovalues[iter_number - 1].extend([max_gradient_change, rms_gradient_change, max_displacement_change, rms_displacement_change]) |
| 577 |
|
| 578 |
# ********************************************************* |
| 579 |
# * Nuclear coordinates for the next iteration / Angstrom * |
| 580 |
# ********************************************************* |
| 581 |
# ATOM X Y Z |
| 582 |
# C1 0.235560 -1.415847 0.012012 |
| 583 |
# C2 1.313797 -0.488199 0.015149 |
| 584 |
# C3 1.087050 0.895510 0.014200 |
| 585 |
# ... |
| 586 |
# ... |
| 587 |
# H19 -0.021327 -4.934915 -0.029355 |
| 588 |
# H20 -1.432030 -3.721047 -0.039835 |
| 589 |
# |
| 590 |
# -- |
| 591 |
if 'Nuclear coordinates for the next iteration / Angstrom' in line: |
| 592 |
self.skip_lines(inputfile, ['s', 'header']) |
| 593 |
line = next(inputfile) |
| 594 |
|
| 595 |
atomcoords = [] |
| 596 |
while line.split() != []: |
| 597 |
atomcoords.append([float(c) for c in line.split()[1:]]) |
| 598 |
line = next(inputfile) |
| 599 |
|
| 600 |
if len(atomcoords) == self.natom: |
| 601 |
self.atomcoords.append(atomcoords) |
| 602 |
else: |
| 603 |
self.logger.warning( |
| 604 |
"Parsed coordinates not consistent with previous, skipping. " |
| 605 |
"This could be due to symmetry being turned on during the job. " |
| 606 |
"Length was %i, now found %i. New coordinates: %s" |
| 607 |
% (len(self.atomcoords[-1]), len(atomcoords), str(atomcoords))) |
| 608 |
|
| 609 |
# ********************************************************************************************************************** |
| 610 |
# * Energy Statistics for Geometry Optimization * |
| 611 |
# ********************************************************************************************************************** |
| 612 |
# Energy Grad Grad Step Estimated Geom Hessian |
| 613 |
# Iter Energy Change Norm Max Element Max Element Final Energy Update Update Index |
| 614 |
# 1 -382.30023222 0.00000000 0.107221 0.039531 nrc047 0.085726 nrc047 -382.30533799 RS-RFO None 0 |
| 615 |
# ... |
| 616 |
# ... |
| 617 |
# 23 -382.30823115 -0.00000089 0.001030 0.000088 nrc053 0.000955 nrc053 -382.30823118 RS-RFO BFGS 0 |
| 618 |
# |
| 619 |
# +----------------------------------+----------------------------------+ |
| 620 |
# + Cartesian Displacements + Gradient in internals + |
| 621 |
# + Value Threshold Converged? + Value Threshold Converged? + |
| 622 |
# +-----+----------------------------------+----------------------------------+ |
| 623 |
# + RMS + 7.2395E-04 1.2000E-03 Yes + 2.7516E-04 3.0000E-04 Yes + |
| 624 |
# +-----+----------------------------------+----------------------------------+ |
| 625 |
# + Max + 1.6918E-03 1.8000E-03 Yes + 8.7768E-05 4.5000E-04 Yes + |
| 626 |
# +-----+----------------------------------+----------------------------------+ |
| 627 |
# |
| 628 |
# Geometry is converged in 23 iterations to a Minimum Structure |
| 629 |
if 'Geometry is converged' in line: |
| 630 |
if not hasattr(self, 'optdone'): |
| 631 |
self.optdone = [] |
| 632 |
self.optdone.append(len(self.atomcoords)) |
| 633 |
|
| 634 |
# ********************************************************* |
| 635 |
# * Nuclear coordinates of the final structure / Angstrom * |
| 636 |
# ********************************************************* |
| 637 |
# ATOM X Y Z |
| 638 |
# C1 0.235547 -1.415838 0.012193 |
| 639 |
# C2 1.313784 -0.488201 0.015297 |
| 640 |
# C3 1.087036 0.895508 0.014333 |
| 641 |
# ... |
| 642 |
# ... |
| 643 |
# H19 -0.021315 -4.934913 -0.029666 |
| 644 |
# H20 -1.431994 -3.721026 -0.041078 |
| 645 |
if 'Nuclear coordinates of the final structure / Angstrom' in line: |
| 646 |
self.skip_lines(inputfile, ['s', 'header']) |
| 647 |
line = next(inputfile) |
| 648 |
|
| 649 |
atomcoords = [] |
| 650 |
|
| 651 |
while line.split() != []: |
| 652 |
atomcoords.append([float(c) for c in line.split()[1:]]) |
| 653 |
line = next(inputfile) |
| 654 |
|
| 655 |
if len(atomcoords) == self.natom: |
| 656 |
self.atomcoords.append(atomcoords) |
| 657 |
else: |
| 658 |
self.logger.error( |
| 659 |
'Number of atoms (%d) in parsed atom coordinates ' |
| 660 |
'is smaller than previously (%d), possibly due to ' |
| 661 |
'symmetry. Ignoring these coordinates.' |
| 662 |
% (len(atomcoords), self.natom)) |
| 663 |
|
| 664 |
# All orbitals with orbital energies smaller than E(LUMO)+0.5 are printed |
| 665 |
# |
| 666 |
# ++ Molecular orbitals: |
| 667 |
# ------------------- |
| 668 |
# |
| 669 |
# Title: RKS-DFT orbitals |
| 670 |
# |
| 671 |
# Molecular orbitals for symmetry species 1: a |
| 672 |
# |
| 673 |
# Orbital 1 2 3 4 5 6 7 8 9 10 |
| 674 |
# Energy -10.0179 -10.0179 -10.0075 -10.0075 -10.0066 -10.0066 -10.0056 -10.0055 -9.9919 -9.9919 |
| 675 |
# Occ. No. 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 |
| 676 |
# |
| 677 |
# 1 C1 1s -0.6990 0.6989 0.0342 0.0346 0.0264 -0.0145 -0.0124 -0.0275 -0.0004 -0.0004 |
| 678 |
# 2 C1 2s -0.0319 0.0317 -0.0034 -0.0033 -0.0078 0.0034 0.0041 0.0073 -0.0002 -0.0002 |
| 679 |
# ... |
| 680 |
# ... |
| 681 |
# 58 H18 1s 0.2678 |
| 682 |
# 59 H19 1s -0.2473 |
| 683 |
# 60 H20 1s 0.1835 |
| 684 |
# -- |
| 685 |
if '++ Molecular orbitals:' in line: |
| 686 |
|
| 687 |
self.skip_lines(inputfile, ['d', 'b']) |
| 688 |
line = next(inputfile) |
| 689 |
|
| 690 |
# We don't currently support parsing natural orbitals or active space orbitals. |
| 691 |
if 'Natural orbitals' not in line and "Pseudonatural" not in line: |
| 692 |
self.skip_line(inputfile, 'b') |
| 693 |
|
| 694 |
# Symmetry is not currently supported, so this line can have one form. |
| 695 |
while 'Molecular orbitals for symmetry species 1: a' not in line.strip(): |
| 696 |
line = next(inputfile) |
| 697 |
|
| 698 |
# Symmetry is not currently supported, so this line can have one form. |
| 699 |
if line.strip() != 'Molecular orbitals for symmetry species 1: a': |
| 700 |
return |
| 701 |
|
| 702 |
line = next(inputfile) |
| 703 |
moenergies = [] |
| 704 |
homos = 0 |
| 705 |
mocoeffs = [] |
| 706 |
while line[:2] != '--': |
| 707 |
line = next(inputfile) |
| 708 |
if line.strip().startswith('Orbital'): |
| 709 |
orbital_index = line.split()[1:] |
| 710 |
for i in orbital_index: |
| 711 |
mocoeffs.append([]) |
| 712 |
|
| 713 |
if 'Energy' in line: |
| 714 |
energies = [utils.convertor(float(x), 'hartree', 'eV') for x in line.split()[1:]] |
| 715 |
moenergies.extend(energies) |
| 716 |
|
| 717 |
if 'Occ. No.' in line: |
| 718 |
for i in line.split()[2:]: |
| 719 |
if float(i) != 0: |
| 720 |
homos += 1 |
| 721 |
|
| 722 |
aonames = [] |
| 723 |
tokens = line.split() |
| 724 |
if tokens and tokens[0] == '1': |
| 725 |
while tokens and tokens[0] != '--': |
| 726 |
aonames.append("{atom}_{orbital}".format(atom=tokens[1], orbital=tokens[2])) |
| 727 |
info = tokens[3:] |
| 728 |
j = 0 |
| 729 |
for i in orbital_index: |
| 730 |
mocoeffs[int(i)-1].append(float(info[j])) |
| 731 |
j += 1 |
| 732 |
line = next(inputfile) |
| 733 |
tokens = line.split() |
| 734 |
self.set_attribute('aonames', aonames) |
| 735 |
|
| 736 |
if len(moenergies) != self.nmo: |
| 737 |
moenergies.extend([numpy.nan for x in range(self.nmo - len(moenergies))]) |
| 738 |
|
| 739 |
self.append_attribute('moenergies', moenergies) |
| 740 |
|
| 741 |
if not hasattr(self, 'homos'): |
| 742 |
self.homos = [] |
| 743 |
self.homos.extend([homos-1]) |
| 744 |
|
| 745 |
while len(mocoeffs) < self.nmo: |
| 746 |
nan_array = [numpy.nan for i in range(self.nbasis)] |
| 747 |
mocoeffs.append(nan_array) |
| 748 |
|
| 749 |
self.append_attribute('mocoeffs', mocoeffs) |
| 750 |
|
| 751 |
## Parsing MP energy from the &MBPT2 module. |
| 752 |
# Conventional algorithm used... |
| 753 |
# |
| 754 |
# SCF energy = -74.9644564043 a.u. |
| 755 |
# Second-order correlation energy = -0.0364237923 a.u. |
| 756 |
# |
| 757 |
# Total energy = -75.0008801966 a.u. |
| 758 |
# Reference weight ( Cref**2 ) = 0.98652 |
| 759 |
# |
| 760 |
# :: Total MBPT2 energy -75.0008801966 |
| 761 |
# |
| 762 |
# |
| 763 |
# Zeroth-order energy (E0) = -36.8202538520 a.u. |
| 764 |
# |
| 765 |
# Shanks-type energy S1(E) = -75.0009150108 a.u. |
| 766 |
if 'Total MBPT2 energy' in line: |
| 767 |
mpenergies = [] |
| 768 |
mpenergies.append(utils.convertor(self.float(line.split()[4]), 'hartree', 'eV')) |
| 769 |
if not hasattr(self, 'mpenergies'): |
| 770 |
self.mpenergies = [] |
| 771 |
self.mpenergies.append(mpenergies) |
| 772 |
|
| 773 |
# Parsing data ccenergies from &CCSDT module. |
| 774 |
# --- Start Module: ccsdt at Thu Jul 26 14:03:23 2018 --- |
| 775 |
# |
| 776 |
# ()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()() |
| 777 |
# |
| 778 |
# &CCSDT |
| 779 |
# ... |
| 780 |
# ... |
| 781 |
# 14 -75.01515915 -0.05070274 -0.00000029 |
| 782 |
# 15 -75.01515929 -0.05070289 -0.00000014 |
| 783 |
# 16 -75.01515936 -0.05070296 -0.00000007 |
| 784 |
# Convergence after 17 Iterations |
| 785 |
# |
| 786 |
# |
| 787 |
# Total energy (diff) : -75.01515936 -0.00000007 |
| 788 |
# Correlation energy : -0.0507029554992 |
| 789 |
if 'Start Module: ccsdt' in line: |
| 790 |
self.skip_lines(inputfile, ['b', '()', 'b']) |
| 791 |
line = next(inputfile) |
| 792 |
if '&CCSDT' in line: |
| 793 |
while not line.strip().startswith('Total energy (diff)'): |
| 794 |
line = next(inputfile) |
| 795 |
|
| 796 |
ccenergies = utils.convertor(self.float(line.split()[4]), 'hartree', 'eV') |
| 797 |
if not hasattr(self, 'ccenergies'): |
| 798 |
self.ccenergies= [] |
| 799 |
self.ccenergies.append(ccenergies) |
| 800 |
|
| 801 |
# ++ Primitive basis info: |
| 802 |
# --------------------- |
| 803 |
# |
| 804 |
# |
| 805 |
# ***************************************************** |
| 806 |
# ******** Primitive Basis Functions (Valence) ******** |
| 807 |
# ***************************************************** |
| 808 |
# |
| 809 |
# |
| 810 |
# Basis set:C.AUG-CC-PVQZ......... |
| 811 |
# |
| 812 |
# Type |
| 813 |
# s |
| 814 |
# No. Exponent Contraction Coefficients |
| 815 |
# 1 0.339800000D+05 0.000091 -0.000019 0.000000 0.000000 0.000000 0.000000 |
| 816 |
# 2 0.508900000D+04 0.000704 -0.000151 0.000000 0.000000 0.000000 0.000000 |
| 817 |
# ... |
| 818 |
# ... |
| 819 |
# 29 0.424000000D+00 0.000000 1.000000 |
| 820 |
# |
| 821 |
# Number of primitives 93 |
| 822 |
# Number of basis functions 80 |
| 823 |
# |
| 824 |
# -- |
| 825 |
if line.startswith('++ Primitive basis info:'): |
| 826 |
self.skip_lines(inputfile, ['d', 'b', 'b', 's', 'header', 's', 'b']) |
| 827 |
line = next(inputfile) |
| 828 |
gbasis_array = [] |
| 829 |
while '--' not in line and '****' not in line: |
| 830 |
if 'Basis set:' in line: |
| 831 |
basis_element_patterns = re.findall('Basis set:([A-Za-z]{1,2})\.', line) |
| 832 |
assert len(basis_element_patterns) == 1 |
| 833 |
basis_element = basis_element_patterns[0].title() |
| 834 |
gbasis_array.append((basis_element, [])) |
| 835 |
|
| 836 |
if 'Type' in line: |
| 837 |
line = next(inputfile) |
| 838 |
shell_type = line.split()[0].upper() |
| 839 |
|
| 840 |
self.skip_line(inputfile, 'headers') |
| 841 |
line = next(inputfile) |
| 842 |
|
| 843 |
exponents = [] |
| 844 |
coefficients = [] |
| 845 |
func_array = [] |
| 846 |
while line.split(): |
| 847 |
exponents.append(self.float(line.split()[1])) |
| 848 |
coefficients.append([self.float(i) for i in line.split()[2:]]) |
| 849 |
line = next(inputfile) |
| 850 |
|
| 851 |
for i in range(len(coefficients[0])): |
| 852 |
func_tuple = (shell_type, []) |
| 853 |
for iexp, exp in enumerate(exponents): |
| 854 |
coeff = coefficients[iexp][i] |
| 855 |
if coeff != 0: |
| 856 |
func_tuple[1].append((exp, coeff)) |
| 857 |
gbasis_array[-1][1].append(func_tuple) |
| 858 |
|
| 859 |
line = next(inputfile) |
| 860 |
|
| 861 |
atomsymbols = [self.table.element[atomno] for atomno in self.atomnos] |
| 862 |
self.gbasis = [[] for i in range(self.natom)] |
| 863 |
for element, gbasis in gbasis_array: |
| 864 |
mask = [element == possible_element for possible_element in atomsymbols] |
| 865 |
indices = [i for (i, x) in enumerate(mask) if x] |
| 866 |
for index in indices: |
| 867 |
self.gbasis[index] = gbasis |
| 868 |
|
| 869 |
# ++ Basis set information: |
| 870 |
# ---------------------- |
| 871 |
# ... |
| 872 |
# Basis set label: MO.ECP.HAY-WADT.5S6P4D.3S3P2D.14E-LANL2DZ..... |
| 873 |
# |
| 874 |
# Electronic valence basis set: |
| 875 |
# ------------------ |
| 876 |
# Associated Effective Charge 14.000000 au |
| 877 |
# Associated Actual Charge 42.000000 au |
| 878 |
# Nuclear Model: Point charge |
| 879 |
# ... |
| 880 |
# |
| 881 |
# Effective Core Potential specification: |
| 882 |
# ======================================= |
| 883 |
# |
| 884 |
# Label Cartesian Coordinates / Bohr |
| 885 |
# |
| 886 |
# MO 0.0006141610 -0.0006141610 0.0979067106 |
| 887 |
# -- |
| 888 |
if '++ Basis set information:' in line: |
| 889 |
self.core_array = [] |
| 890 |
basis_element = None |
| 891 |
ncore = 0 |
| 892 |
|
| 893 |
while line[:2] != '--': |
| 894 |
if 'Basis set label' in line: |
| 895 |
try: |
| 896 |
basis_element = line.split()[3].split('.')[0] |
| 897 |
basis_element = basis_element[0] + basis_element[1:].lower() |
| 898 |
except: |
| 899 |
self.logger.warning('Basis set label is missing!') |
| 900 |
basis_element = '' |
| 901 |
if 'valence basis set:' in line.lower(): |
| 902 |
self.skip_line(inputfile, 'd') |
| 903 |
line = next(inputfile) |
| 904 |
if 'Associated Effective Charge' in line: |
| 905 |
effective_charge = float(line.split()[3]) |
| 906 |
actual_charge = float(next(inputfile).split()[3]) |
| 907 |
element = self.table.element[int(actual_charge)] |
| 908 |
ncore = int(actual_charge - effective_charge) |
| 909 |
if basis_element: |
| 910 |
assert basis_element == element |
| 911 |
else: |
| 912 |
basis_element = element |
| 913 |
|
| 914 |
if basis_element and ncore: |
| 915 |
self.core_array.append((basis_element, ncore)) |
| 916 |
basis_element = '' |
| 917 |
ncore = 0 |
| 918 |
|
| 919 |
line = next(inputfile) |