Skip to content

Conversation

@lbluque
Copy link
Contributor

@lbluque lbluque commented Sep 30, 2025

Implement automatic formation energy predictions.

  1. Element references are pulled from hugging face and added to the predict unit (same as the isolated atom refereces)
  2. Formation energy calculations are enabled by using a context manager that decorates the calculate method. This way I did not touch any of the calculator code and its usage is explicit and descriptive to users.
  3. OMat24 formation energies will default to apply appropriate MP2020 style corrections. This requires fairchem.data.omat to be installed.
  4. Adapted the inorganic bulk relaxation tutorial to show how to predict formation energies.

Usage:

from ase.build import bulk
from fairchem.core.calculate.ase_calculator import FAIRChemCalculator, set_predict_formation_energy

atoms = bulk('MgO', crystalstructure='rocksalt', a=4.21, cubic=True)
atoms.calc = FAIRChemCalculator.from_model_checkpoint("uma-s-1p1", task_name="omat")

with set_predict_formation_energy(atoms.calc, apply_corrections=True):
    corrected_formation_energy = atoms.get_potential_energy()

total_energy = atoms.get_potential_energy()

Tests need #1603 to pass

@lbluque lbluque marked this pull request as draft September 30, 2025 19:17
@meta-cla meta-cla bot added the cla signed label Sep 30, 2025
@lbluque lbluque added enhancement New feature or request minor Minor version release labels Sep 30, 2025
@Andrew-S-Rosen
Copy link
Contributor

Andrew-S-Rosen commented Oct 22, 2025

@lbluque: Thanks for putting this together! Do you have an ETA for when this PR might be merged? We are hoping to submit a manuscript next month where we think the results of this PR could significantly improve our results and would be interested in trying it out before we send off the paper. I was meeting with @zulissi today and he suggested I reach out.

@lbluque
Copy link
Contributor Author

lbluque commented Oct 23, 2025

Hi @Andrew-S-Rosen 👋 This is mainly just pending getting the DFT calculations ready and uploaded to HF. I'll see if I can push on this to have it ready by next week!

@Andrew-S-Rosen
Copy link
Contributor

@lbluque: That would be great, thanks! We'll be sure to include the results in our paper then and be the first to use it!

Tagging @aryannsaha. This is what I will have you try once it's merged.

@lbluque lbluque marked this pull request as ready for review November 4, 2025 21:55
@lbluque lbluque requested review from rayg1234 and zulissimeta and removed request for zulissimeta November 4, 2025 21:56
Copy link
Contributor

@zulissimeta zulissimeta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relatively minor comments here. The major question in my mind is whether using set_predict_formation_energy to modify a calculator is the right approach here.

pprint.pprint(f"Total energy: {result["results"]["energy"] eV\n Formation energy {form_energy} eV})
```

Congratulations; you ran your first relaxation and predicted the formation energy of MgO using UMA and `quacc`!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a numerical comparison to the MP value here? Just mention what MP says and include a link to the MP structure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea!

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 26.53061% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.86%. Comparing base (d8d88a7) to head (460acdc).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/fairchem/core/calculate/ase_calculator.py 10.25% 35 Missing ⚠️
src/fairchem/core/calculate/pretrained_mlip.py 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1538      +/-   ##
==========================================
- Coverage   66.49%   65.86%   -0.64%     
==========================================
  Files         131      131              
  Lines       10781    10607     -174     
==========================================
- Hits         7169     6986     -183     
- Misses       3612     3621       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed enhancement New feature or request minor Minor version release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants