Performing Equation of State Analysis using Agentic AI Skills
This is a guide on using agentic AI skills on OpenCode to perform Equation of State analysis. We will ask an AI model to use a defined skill to take in an energy/volume dataset and ask it to fit an EOS model and plot the Energy vs. Volume and Pressure vs. Volume curves and interpret the results.
The files needed for this example can be found at: https://github.com/DukeRC/code/tree/main/Performing-Equation-of-State-Analysis-using-Agentic-AI-Skills
You may either use your AI agentic tool, OpenCode in this case, either through the cloud or as a locally served LLM model to use AI skills to perform this task.
An Equation of State (EOS) is a thermodynamic relationship between quantities including pressure, volume, temperature, enthalpy, entropy etc. to describe the state of matter of a substance, such as gases, fluids, or solids. This can be applied to understand simple ideal gas law to complex models explaining matter in extreme physical environments such as planetary interiors. We will be using Energy (in eV) and Volume (in Angstrom\(^3\)) data (the file EvsV.txt) to fit an EOS model and analyze the data using AI.
To start off, copy the directory eos-models from the repository above to a directory structure similar to the one below.
The working directory where you would run opencode would be EOS. Learn more about the placement of skills files for local and global setups here. The directory structure of eos-models is,
There is an AGENTS.md file at the root of the repository that describes how the results should be presented to the user.
The main file detailing the skill here is the SKILL.md. It describes the expected task workflow, the models, the inputs, outputs, dependencies, common pitfalls etc. It also links a suggested Python routine for the workflow described in run_eos_fit.py. For example, the workflow for an Energy vs. Volume input is described as,
1. load `V, E`
2. quadratic initial guess (`polyfit`) -> `[E0, B0, Bp, V0]`
3. `fitting()` for 4 energy models
4. compute MSE for each model + select best
5. `_get_peos()` by central difference to get pressure curves
6. plot `EvsV.png` and `PvsV.png`
7. write `EOS_fit_results.txt`
The workhorse of the routine is defined through the different EOS models, namely Murnaghan, Birch-Murnaghan, Birch, and Vinet,
# EOS model definitions
def eos_murnaghan(self, coeffs, vol):
"Ref: Phys. Rev. B 28, 5480 (1983)"
E0, B0, Bp, V0 = coeffs
return (
E0
+ B0 / Bp * vol * ((V0 / vol) ** Bp / (Bp - 1.0) + 1.0)
- V0 * B0 / (Bp - 1.0)
)
def eos_birch_murnaghan(self, coeffs, vol):
"Ref: Phys. Rev. B 70, 224107"
E0, B0, Bp, V0 = coeffs
eta = (vol / V0) ** (1.0 / 3.0)
return E0 + 9.0 * B0 * V0 / 16.0 * (eta**2 - 1.0) ** 2 * (
6.0 + Bp * (eta**2 - 1.0) - 4.0 * eta**2
)
def eos_birch(self, coeffs, vol):
"""
Ref: Michael J. Mehl; Barry M. Klein; Dimitris A. Papaconstantopoulos. First-Principles Calculation of Elastic Properties. In Intermetallic Compounds; John Wiley & Sons Ltd, 1994; Vol. 1.
"""
E0, B0, Bp, V0 = coeffs
term = (V0 / vol) ** (2.0 / 3.0) - 1.0
return (
E0
+ 9.0 / 8.0 * B0 * V0 * term**2
+ 9.0 / 16.0 * B0 * V0 * (Bp - 4.0) * term**3
)
def eos_vinet(self, coeffs, vol):
"Ref: Phys. Rev. B 70, 224107"
E0, B0, Bp, V0 = coeffs
eta = (vol / V0) ** (1.0 / 3.0)
return E0 + 2.0 * B0 * V0 / (Bp - 1.0) ** 2 * (
2.0
- (5.0 + 3.0 * Bp * (eta - 1.0) - 3.0 * eta)
* np.exp(-3.0 * (Bp - 1.0) * (eta - 1.0) / 2.0)
)
Once you have the eos-models in the correct location, launch OpenCode, and run the following prompt,
This will calculate the best EOS model based on the Mean Squared Error (MSE), plot the Energy vs. Volume and Pressure vs. Volume curves through a central difference scheme, and provide a brief analysis of the results. For example,

The energy vs. volume fit,

and the pressure vs. volume fit obtained through the central difference scheme,

Feel free to experiment with different models and create similar workflows for scientific AI agentic skills.