Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
self.ccread = cclib.io.ccio.ccread
def extract_energy_with_cclib(self, cclib_attribute, energy_index=-1):
"""
Attempts to extract energies with cclib
Parameters
---------
cclib_attribute : str
The cclib target attribute. Valid options can be found in cclib documentation.
Examples include "ccenergies", "scfenergies", or "mpenergies"
energy_index : int
Which energy to grab from the output file which matches the cclib_attribute.
Default is -1, the last energy printed in the output file which matches the cclib_attribute.
"""
try:
cclib_outputobj = ccio.ccread(self.output_path)
except:
e = None
return e
e = None
# for whatever reason, sometimes each energy is a single element list, so we have to code around that
# also, cclib does not handle things well if something fails to parse, needtry/except pairs
if cclib_attribute == "scfenergies":
try:
e = cclib_outputobj.scfenergies[-1]
if isinstance(e, list):
e = e[0]
except:
e = None
if cclib_attribute == "mpenergies":
try:
e = cclib_outputobj.mpenergies[-1]
def extract_cartesian_gradient_with_cclib(self, grad_index=-1):
"""
Attempts to extract the cartesian gradient with cclib
Parameters
---------
grad_index : int
Which gradient to grab from the output file.
Default is -1, the last gradient printed in the output file which matches the cclib_attribute.
"""
# warning: cartesian reorientation by quantum chemistry software may mess this up
cclib_outputobj = ccio.ccread(self.output_path)
if hasattr(cclib_outputobj, 'grads'):
return cclib_outputobj.grads[-1]
else:
return None
def extract_energy_with_cclib(self, cclib_attribute, energy_index=-1):
"""
Attempts to extract energies with cclib
Parameters
---------
cclib_attribute : str
The cclib target attribute. Valid options can be found in cclib documentation.
Examples include "ccenergies", "scfenergies", or "mpenergies"
energy_index : int
Which energy to grab from the output file which matches the cclib_attribute.
Default is -1, the last energy printed in the output file which matches the cclib_attribute.
"""
try:
cclib_outputobj = ccio.ccread(self.output_path)
except:
e = None
return e
e = None
# for whatever reason, sometimes each energy is a single element list, so we have to code around that
# also, cclib does not handle things well if something fails to parse, needtry/except pairs
if cclib_attribute == "scfenergies":
try:
e = cclib_outputobj.scfenergies[-1]
if isinstance(e, list):
e = e[0]
except:
e = None
if cclib_attribute == "mpenergies":
try:
e = cclib_outputobj.mpenergies[-1]
def extract_cartesian_gradient_with_cclib(self, grad_index=-1):
"""
Attempts to extract the cartesian gradient with cclib
Parameters
---------
grad_index : int
Which gradient to grab from the output file.
Default is -1, the last gradient printed in the output file which matches the cclib_attribute.
"""
# warning: cartesian reorientation by quantum chemistry software may mess this up
cclib_outputobj = ccio.ccread(self.output_path)
if hasattr(cclib_outputobj, 'grads'):
return cclib_outputobj.grads[-1]
else:
return None
def extract_cartesian_gradient_with_cclib(self, grad_index=-1):
"""
Attempts to extract the cartesian gradient with cclib
Parameters
---------
grad_index : int
Which gradient to grab from the output file.
Default is -1, the last gradient printed in the output file which matches the cclib_attribute.
"""
# warning: cartesian reorientation by quantum chemistry software may mess this up
cclib_outputobj = ccio.ccread(self.output_path)
if hasattr(cclib_outputobj, 'grads'):
return cclib_outputobj.grads[-1]
else:
return None
def extract_energy_with_cclib(self, cclib_attribute, energy_index=-1):
"""
Attempts to extract energies with cclib
Parameters
---------
cclib_attribute : str
The cclib target attribute. Valid options can be found in cclib documentation.
Examples include "ccenergies", "scfenergies", or "mpenergies"
energy_index : int
Which energy to grab from the output file which matches the cclib_attribute.
Default is -1, the last energy printed in the output file which matches the cclib_attribute.
"""
cclib_outputobj = ccio.ccread(self.output_path)
e = None
# for whatever reason, sometimes each energy is a single element list, so we have to code around that
# also, cclib does not handle things well if something fails to parse, needtry/except pairs
if cclib_attribute == "scfenergies":
try:
e = cclib_outputobj.scfenergies[-1]
if isinstance(e, list):
e = e[0]
except:
e = None
if cclib_attribute == "mpenergies":
try:
e = cclib_outputobj.mpenergies[-1]
if isinstance(e, list):
e = e[0]
except: