Molpro Interface

ElemCo.MolproInterfaceModule

This module provides an interface to Molpro to read and write orbitals and other data.

It includes functions to read Molpro matrop files to import overlap/density matrices and orbital coefficients.

A convenient way to use the interface is given below.

ElemCo.jl Molpro Interface: Seamless Julia-Molpro Integration

The ElemCo.jl package provides a streamlined workflow for integrating Julia calculations with Molpro quantum chemistry computations through a simple include mechanism and macro-based data exchange.

Setup

Add the following line to your Molpro input file:

include,elemcoil

This includes a separate configuration file elemcoil that handles all data exchange between Molpro and Julia.

Configuration File (elemcoil)

The elemcoil file defines the interface between Molpro and Julia:

$XML='data/mol.xml'
$ORBITALS='data/orbs.dat'
!$ECORBITALS='data/ecorbs.dat'
$ECVARIABLES='data/ecvars.dat'

system,'mkdir -p','data'

put,xml,$XML

{matrop
load ORB ORB
write,ORB,$ORBITALS,new,sci
}

system,'julia input.jl',' > elemcoil.log'

!{matrop
!read,ORB,file=$ECORBITALS
!save,ORB,3200.2,ORBITALS
!}

readvar,$ECVARIABLES

Key Components:

  • Variable definitions: Define file paths for XML output, orbital data, and variable exchange
  • Data export: Automatically exports Molpro XML and orbital matrices to specified files
  • Julia execution: Calls the Julia script input.jl and logs output to elemcoil.log
  • Data import: Reads back modified variables and orbitals (commented sections for optional use)

Julia Script (input.jl)

Use the convenient @molpro_input and @molpro_output macros for seamless data access:

using ElemCo

# Read Molpro data using the @molpro_input macro
@molpro_input

# Perform Julia calculations
result = @cc dcsd

# Export results back to Molpro using @molpro_output macro, with a prefix for variable names
@molpro_output result prefix="EC_" 

This script reads the Molpro data defined in elemcoil, performs calculations using Julia's ElemCo.jl package, and exports results back to Molpro with a specified prefix.

The geometry and basis set information is automatically handled by the @molpro_input macro. Note that the XML file in Molpro stores only the AO basis set. The fitting basis set is not stored in the XML file. If you need a specific fitting basis set, you can define it before the @molpro_input macro in the usual way, e.g.:

geometry = Dict("mpfit" => "avtz-mpfit", "jkfit" => "vqz-jkfit")
@molpro_input

Workflow Benefits

  1. Automatic data handling: No manual file path management - everything is configured in the elemcoil file
  2. Clean separation: Molpro handles quantum chemistry, Julia handles specialized calculations
  3. Bidirectional communication: Variables and data can flow both ways between Molpro and Julia
  4. Logging: All Julia output is captured in elemcoil.log for debugging
  5. Flexible integration: Commented sections allow for orbital modifications when needed

Use Cases

  • Post-processing: Analyze Molpro results with Julia's rich ecosystem
  • Method development: Implement new electronic structure methods in Julia
  • Data analysis: Use Julia's plotting and statistical capabilities on quantum chemistry data
  • Orbital manipulation: Modify or transform molecular orbitals using Julia algorithms
  • Property calculations: Compute additional molecular properties not available in Molpro

This interface makes it easy to leverage Julia's computational capabilities within existing Molpro workflows while maintaining clean, readable code.

source

Exported functions and types

ElemCo.MolproInterface.get_moleculeMethod
get_molecule(MI::MolproInfo)

Get the last molecule from a MolproInfo object.

This function retrieves the last molecule node from the XML document stored in the MolproInfo object.

source
ElemCo.MolproInterface.get_xml_geometryMethod
get_xml_geometry(molecule::Node)

Get the geometry of a molecule from an XML node.

Returns a tuple of:

  • A vector of atom IDs as strings.
  • A vector of element types as strings.
  • A 3xN matrix of atomic coordinates (in Angstrom), where N is the number of atoms.
source
ElemCo.MolproInterface.get_xml_infoMethod
get_xml_info(nodes::Vector{Node}, what::AbstractString)

Get XML information from multiple nodes using XPath what.

Returns a vector of nodes that match the XPath expression across all nodes. If what is an empty string, it returns the nodes themselves.

source
ElemCo.MolproInterface.get_xml_infoMethod
get_xml_info(node::Node, what::AbstractString)

Get XML information from a node using XPath what.

Returns a vector of nodes that match the XPath expression. If what is an empty string, it returns the node itself.

source
ElemCo.MolproInterface.get_xml_uniqueMethod
get_xml_unique(node::Node, what::AbstractString)

Get a unique XML node from node using XPath what.

If exactly one node matches, it returns that node. If no nodes match or multiple nodes match, it raises an error.

source
ElemCo.MolproInterface.get_xml_variableMethod
get_xml_variable(node::Node, var::AbstractString)

Get the first variable node with the given name var from the XML node.

If no such variable exists returns nothing. If multiple variables with the same name exist, it raises an error.

source
ElemCo.MolproInterface.get_xml_variable_value_typeMethod
get_xml_variable_value_type(node::Node, var::AbstractString)

Get the type and number of values for a variable with the given name var from the XML node.

Returns a tuple of:

  • The variable type as a string (e.g., "xsd:double", "xsd:string").
  • The number of values for the variable.
source
ElemCo.MolproInterface.get_xml_variable_valuesMethod
get_xml_variable_values(node::Node, var::AbstractString)

Get the values of a variable with the given name var from the XML node.

Returns a tuple of:

  • A vector of string values for the variable.
  • The type of the variable as a string (e.g., "xsd:double", "xsd:string").

If the variable does not exist, returns an empty vector and "none".

source
ElemCo.MolproInterface.get_xml_variable_valuesMethod
get_xml_variable_values(t::Type{T}, node::Node, var::AbstractString) where T

Get the values of a variable with the given name var from the XML node as a specific type T.

If the variable does not exist, it returns an empty vector of type T. Raises an error if the variable type does not match the expected type.

source
ElemCo.MolproInterface.save_ecvariables_to_fileMethod
save_ecvariables_to_file(MI::MolproInfo, dict; new=true, prefix="")

Save variables from a dictionary to the ECVARIABLES file in the MolproInfo object.

This function writes each key-value pair in the dictionary to the file in the format key=value. If the value is empty, it is skipped. The prefix argument allows adding a prefix to each line.

source
ElemCo.MolproInterface.set_options_from_xml!Method
set_options_from_xml!(EC::ECInfo, node::Node)

Set the options for an ECInfo object from an XML node.

This function extracts the charge, multiplicity, and core electron count from the XML node and updates the ECInfo options accordingly.

source
ElemCo.MolproInterface.MolproInfoType
MolproInfo(exportdata_file::AbstractString)

Constructor for MolproInfo that parses an exportdata file from Molpro input.

The exportdata file contains variable definitions in the format:

  • $VAR=value - variable definitions
  • !comment - comments (ignored)
  • Other lines terminate parsing

Returns a MolproInfo object with parsed variables and XML document.

source

Internal functions and types

ElemCo.MolproInterface.ao_permutationMethod
ao_permutation(EC::ECInfo)

Return the permutation of the atomic orbitals from the Molpro to the libcint order such that μ(molpro)[ao_permutation(EC)] = μ(libcint).

source
ElemCo.MolproInterface.get_xml_variable_valueMethod
get_xml_variable_value(t::Type{T}, node::Node, var::AbstractString) where T

Get the value of a variable with the given name var from the XML node as a specific type T.

If the variable does not exist or has no values, it raises an error. If the variable has multiple values, it raises an error.

source
ElemCo.MolproInterface.parse_exportdata_fileMethod
parse_exportdata_file(exportdata_file::AbstractString)

Parse a Molpro exportdata file and return a dictionary of variables.

The exportdata file contains variable definitions in the format:

  • $VAR=value - variable definitions
  • !comment - comments (ignored)
  • Other lines terminate parsing

Returns a dictionary where keys are variable names and values are their corresponding values.

source