stko.OrcaEnergy

class stko.OrcaEnergy(orca_path, topline, basename=None, output_dir=None, num_cores=1, charge=0, multiplicity=1, write_input_only=False, discard_output=True)[source]

Bases: object

Uses Orca to calculate energy and other properties.

By default, get_results() will extract other properties of the stk.Molecule passed to calculate(), which will be saved in the attributes of stko.OrcaResults.

All intermediate and output files from Orca are deleted at the end of the job (i.e. the .gbw file will be deleted) because they can quickly build up to large sizes. The discard_output option allows you to keep output files if desired.Additionally, the write_input_only option is available for jobs where you would like more customization or to run outside of the Python environment.

Parameters:
  • orca_path (Path | str) – The path to the Orca executable.

  • topline (str) – Top line designating the type of calculation. Should start with !.

  • basename (str | None) – Base name of Orca output files.

  • output_dir (Path | str | None) – The name of the directory into which files generated during the calculation are written, if None then uuid.uuid4() is used.

  • num_cores (int) – The number of cores Orca should use.

  • charge (int) – Formal molecular charge.

  • multiplicity (int) – Multiplicity of system (2S+1), where S is the spin.

  • write_input_only (bool) – True if you only want the input file written and to not have the Orca job run.

  • discard_output (bool) – True if you want to delete auxillary Orca output files such as the .gbw file.

Notes

When running calculate(), this calculator changes the present working directory with os.chdir(). The original working directory will be restored even if an error is raised, so unless multi-threading is being used this implementation detail should not matter.

If multi-threading is being used an error could occur if two different threads need to know about the current working directory as stko.OrcaEnergy can change it from under them.

Note that this does not have any impact on multi-processing, which should always be safe.

Examples

import stk
import stko

bb1 = stk.BuildingBlock('NCCNCCN', [stk.PrimaryAminoFactory()])
bb2 = stk.BuildingBlock('O=CCCC=O', [stk.AldehydeFactory()])
polymer = stk.ConstructedMolecule(
    stk.polymer.Linear(
        building_blocks=(bb1, bb2),
        repeating_unit="AB",
        orientations=[0, 0],
        num_repeating_units=1
    )
)

# Optimize the constructed molecule so that it has a
# reasonable structure.
opt = stko.UFF()
polymer = opt.optimize(polymer)

# Calculate energy using Orca.
orca = stko.OrcaEnergy(
    orca_path='/opt/orca/orca',
    topline='! SP B97-3c',
)

orca_results = orca.get_results(polymer)

# Extract properties from the energy calculator for a given
# molecule.
total_energy = orca_results.get_total_energy()

If you want the input file written (instead of the job run), you can use the write_input_only argument to save the input file in the output_dir as orca_input.inp with the input xyz file as input_structure.xyz.

# Optimize the constructed molecule so that it has a
# reasonable structure.
optimizer = stko.ETKDG()
polymer = optimizer.optimize(polymer)

# Calculate energy using Orca.
orca = stko.OrcaEnergy(
    orca_path='/opt/orca/orca',
    topline='! SP B97-3c',
    write_input_only=True,
)

orca.get_results(polymer)

Methods

calculate

get_energy

Calculate the energy of mol.

get_results

Calculate the Orca properties of mol.

calculate(mol)[source]
Parameters:

mol (Molecule)

Return type:

Generator

get_energy(mol)[source]

Calculate the energy of mol.

Parameters:

mol (Molecule) – The stk.Molecule whose energy is to be calculated.

Returns:

The energy or None if write_input_only mode.

Return type:

float | None

get_results(mol)[source]

Calculate the Orca properties of mol.

Parameters:

mol (Molecule) – The stk.Molecule whose energy is to be calculated.

Returns:

The properties, with units, from Orca calculations or None if write_input_only mode.

Return type:

OrcaResults | None