Molpro Interface
ElemCo.MolproInterface — Module
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,elemcoilThis 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,$ECVARIABLESKey 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.jland logs output toelemcoil.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_inputWorkflow Benefits
- Automatic data handling: No manual file path management - everything is configured in the
elemcoilfile - Clean separation: Molpro handles quantum chemistry, Julia handles specialized calculations
- Bidirectional communication: Variables and data can flow both ways between Molpro and Julia
- Logging: All Julia output is captured in
elemcoil.logfor debugging - 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.
Exported functions and types
ElemCo.MolproInterface.get_molecule — Method
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.
ElemCo.MolproInterface.get_xml_first — Method
get_xml_first(node::Node, what::AbstractString)Get the first XML node from node using XPath what.
If no nodes match, it raises an error.
ElemCo.MolproInterface.get_xml_geometry — Method
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.
ElemCo.MolproInterface.get_xml_geometry_basis — Method
get_xml_geometry_basis(molecule::Node)Get the geometry and basis set information for a molecule from an XML node.
Returns a tuple of:
- Geometry as a String.
- Basis set as a String.
ElemCo.MolproInterface.get_xml_info — Method
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.
ElemCo.MolproInterface.get_xml_info — Method
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.
ElemCo.MolproInterface.get_xml_last — Method
get_xml_last(node::Node, what::AbstractString)Get the last XML node from node using XPath what.
If no nodes match, it raises an error.
ElemCo.MolproInterface.get_xml_molecules — Method
get_xml_molecules(node::Node)Get all molecule nodes from an XML node.
Returns a vector of nodes representing molecules.
ElemCo.MolproInterface.get_xml_unique — Method
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.
ElemCo.MolproInterface.get_xml_variable — Method
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.
ElemCo.MolproInterface.get_xml_variable_value_type — Method
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.
ElemCo.MolproInterface.get_xml_variable_values — Method
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".
ElemCo.MolproInterface.get_xml_variable_values — Method
get_xml_variable_values(node::Node)Get the values of a variable node.
Returns a vector of string values for the variable node. If the node has non-simple children, it raises an error.
ElemCo.MolproInterface.get_xml_variable_values — Method
get_xml_variable_values(t::Type{T}, node::Node, var::AbstractString) where TGet 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.
ElemCo.MolproInterface.import_orbitals — Method
import_orbitals(EC::ECInfo, filename::AbstractString)Import an orbital coefficient matrix from a Molpro matrop file.
ElemCo.MolproInterface.import_overlap — Method
import_overlap(EC::ECInfo, filename::AbstractString)Import the overlap matrix from a Molpro matrop file.
ElemCo.MolproInterface.is_matrop_file — Method
is_matrop_file(filename::AbstractString)Check if a file is a Molpro matrop file and return the type of the matrix.
ElemCo.MolproInterface.read_matrop_matrix — Method
read_matrop_matrix(filename::AbstractString)Read a square matrix from a Molpro matrop file.
ElemCo.MolproInterface.save_ecvariables_to_file — Method
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.
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.
ElemCo.MolproInterface.MolproInfo — Type
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.
ElemCo.MolproInterface.MolproInfo — Type
MolproInfoA structure to hold information parsed from a Molpro export file.
Internal functions and types
ElemCo.MolproInterface.ao_permutation — Method
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).
ElemCo.MolproInterface.get_xml_last_molecule — Method
get_xml_last_molecule(node::Node)Get the last molecule node from an XML node.
Returns the last molecule node found in the XML document.
ElemCo.MolproInterface.get_xml_variable_value — Method
get_xml_variable_value(t::Type{T}, node::Node, var::AbstractString) where TGet 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.
ElemCo.MolproInterface.parse_exportdata_file — Method
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.
ElemCo.MolproInterface.read_numbers_in_line — Method
read_numbers_in_line(f::IOStream)Read a line from a file and return the numbers in it.
ElemCo.MolproInterface.skip_comment_lines — Method
skip_comment_lines(f::IOStream)Skip lines which do not start with a number or a minus.
ElemCo.MolproInterface.MOLPRO2LIBCINT_PERMUTATION — Constant
MOLPRO2LIBCINT_PERMUTATIONPermutation of the atomic orbitals from the Molpro to the libcint order.