Convenience scripts#

This notebook gives some help on the convenience functions to be used in the exercises.

from utils.functions import MRChemOutput, makeEnergyInput, makeNMRInput, submit

Output parser#

MRChemOutput is a convenience class for parsing JSON output files. It contains methods for accessing the relevant properties for the exercises.

You initialize the class by passing in the path to the JSON output file.

help(MRChemOutput)
Help on class MRChemOutput in module utils.functions:

class MRChemOutput(builtins.object)
 |  MRChemOutput(jsonfile)
 |  
 |  Convenience class for accessing data from an MRChem calculation.
 |  
 |  You can access the JSON data via the data attribute.
 |  For example, to get the final SCF total energy:
 |  
 |  
 |  []: calc = MRChemOutput('jobname.json')
 |      E_tot = calc.data['output']['properties']['scf_energy']['E_tot']
 |  
 |  Additionally, the JSON is loaded as a nested SimpleNamespace
 |  (stored in the ns attribute),
 |  and you can quickly navigate the dict by 'dotting' through
 |  the keys. Tab completion should work for this in the Jupyter
 |  environment:
 |  
 |  []: E_tot = calc.ns.output.properties.scf_energy.E_tot
 |  
 |  Known bug
 |  Some keys are not valid Python variable names,
 |  and you cannot access the levels below these keys by dotting.
 |  Workaround: use __.getattribute__(key) to access such keys.
 |  
 |  A few methods are also provided that serve as shortcuts
 |  for navigating the data dictionary, and for plotting
 |  SCF convergence data.
 |  
 |  Methods defined here:
 |  
 |  __init__(self, jsonfile)
 |      Parameters:
 |      jsonfile <str>: Path to MRChem output JSON file
 |  
 |  getFinalSCFEnergy(self) -> float
 |      Return optimized SCF energy in Hartrees.
 |  
 |  getNMRShieldingAnisotropy(self) -> dict
 |      Return anisotropy of the diagonalized NMR shielding tensor.
 |  
 |  getNMRShieldingIsotropicAverage(self) -> dict
 |      Return isotropic average of total NMR shielding tensor.
 |  
 |  getNMRShieldingTensors(self) -> dict
 |      Return total NMR shielding tensor.
 |  
 |  getNMRShieldingTensorsDiagonalized(self) -> dict
 |      Return diagonalized total NMR shielding tensor.
 |  
 |  getNMRShieldingTensorsDiamagnetic(self) -> dict
 |      Return diamagnetic contribution to NMR shielding tensor.
 |  
 |  getNMRShieldingTensorsParamagnetic(self) -> dict
 |      Return paramagnetic contribution to NMR shielding tensor.
 |  
 |  getResponseConvergence(self) -> list
 |      Return convergence data for the x, y, and z dimension response SCFs.
 |  
 |  getSCFConvergence(self) -> list
 |      Return list of tuples containing total energy, energy update, and MO residuals
 |      for all SCF iterations.
 |  
 |  getWalltime(self)
 |  
 |  normalTermination(self)
 |  
 |  plotResponseConvergence(self)
 |      Plot the response SCF convergence in terms of the property, property update, and MO residual.
 |  
 |  plotSCFConvergence(self)
 |      Plot the SCF convergence in terms of total energy, energy udpates, and MO residuals.
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)

Make input files#

makeEnergyInput generates an MRChem input file in the current directory, with a precision and the filename as specified.

help(makeEnergyInput)
Help on function makeEnergyInput in module utils.functions:

makeEnergyInput(world_prec=None, xyzfile=None, fname=None)
    Write MRChem JSON input file for energy calculation.
    
    Parameters:
    -------------
    
    world_prec: precision to use
    xyzfile: path to xyzfile
    fname: name of the generated input file (without extension, .inp assumed)
help(makeNMRInput)
Help on function makeNMRInput in module utils.functions:

makeNMRInput(world_prec=None, xyzfile=None, fname=None)
    Write MRChem JSON input file for NMR calculation.
    
    Parameters:
    -------------
    
    world_prec: precision to use
    xyzfile: path to xyzfile
    fname: name of the generated input file (without extension, .inp assumed)

Submit MRChem job#

submit makes makes a calc dir <inputfile>_calc, moves the input file to this directory, and calls MRChem.

help(submit)
Help on function submit in module utils.functions:

submit(nprocs=None, inputfile=None)
    Make calc dir, move inputfile, and start the calculation.
    
    Parameters:
    -----------
    nprocs      : Number of OpenMP threads to use
    inputfile   : Name of input file (without extension)