Skip to content

WIP: Simple ase interface#60

Draft
pmrv wants to merge 6 commits intomainfrom
calculator
Draft

WIP: Simple ase interface#60
pmrv wants to merge 6 commits intomainfrom
calculator

Conversation

@pmrv
Copy link

@pmrv pmrv commented Nov 28, 2025

It works, but it cannot be configured yet.

See #34

It works, but it cannot be configured yet.
@github-actions
Copy link

Binder 👈 Launch a binder notebook on branch pyiron/sphinx_parser/calculator

@codecov
Copy link

codecov bot commented Nov 28, 2025

Codecov Report

❌ Patch coverage is 0% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.90%. Comparing base (8e1d73b) to head (f80d900).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
sphinx_parser/calculator.py 0.00% 25 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #60      +/-   ##
==========================================
- Coverage   88.54%   85.90%   -2.65%     
==========================================
  Files           8        9       +1     
  Lines         812      837      +25     
==========================================
  Hits          719      719              
- Misses         93      118      +25     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jan-janssen
Copy link
Member

As a reference the ASE team worked on this some time back https://gitlab.com/ase/ase/-/merge_requests/2657

@pmrv
Copy link
Author

pmrv commented Nov 28, 2025

Yeah, I snooped around in there, but as you expected it's much simpler with the parser and newer ASE infrastructure.

@pmrv
Copy link
Author

pmrv commented Nov 30, 2025

I also found the calculator implemented by FLEUR. Seems like this can be a good template for a "modern" ase calculator too.

Copy link
Member

@samwaseda samwaseda left a comment

Choose a reason for hiding this comment

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

Nice! Thanks!

@samwaseda samwaseda linked an issue Nov 30, 2025 that may be closed by this pull request
@stale
Copy link

stale bot commented Feb 12, 2026

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 12, 2026
@samwaseda samwaseda requested a review from Copilot March 19, 2026 10:18
@stale stale bot removed the stale label Mar 19, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces an ASE FileIOCalculator implementation for running SPHInX DFT calculations via sphinx_parser, aiming to support ASE’s calculate() flow for energies and forces (Issue #34).

Changes:

  • Added a new SphinxDft ASE calculator that writes an input.sx file from an ase.Atoms.
  • Added result parsing from a SPHInX stdout log via SphinxLogParser, exposing energy and forces through self.results.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +50 to +53
def read_results(self):
parser = SphinxLogParser.load_from_path(Path(self.directory) / "log.sx")
self.results["energy"] = parser.get_energy_free()[-1][-1]
self.results["forces"] = parser.get_forces()[-1]
Comment on lines +22 to +35
struct_group = get_structure_group(atoms)[0]
main_group = sphinx.main(
scfDiag=sphinx.main.scfDiag(maxSteps=10, blockCCG={}),
evalForces=sphinx.main.evalForces("forces.txt"),
)
pawPot_group = get_paw_from_structure(atoms)
basis_group = sphinx.basis(
eCut=25, kPoint=sphinx.basis.kPoint(coords=3 * [0.5])
)
paw_group = sphinx.PAWHamiltonian(xc=1, spinPolarized=False, ekt=0.2)
initial_guess_group = sphinx.initialGuess(
waves=sphinx.initialGuess.waves(lcao=sphinx.initialGuess.waves.lcao()),
rho=sphinx.initialGuess.rho(atomicOrbitals=True),
)
Comment on lines +27 to +28
pawPot_group = get_paw_from_structure(atoms)
basis_group = sphinx.basis(
Copy link
Author

Choose a reason for hiding this comment

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

I don't think it's a good idea to hard code this here. @samwaseda does the rest of sphinxparser make reference to the potential location?

Copy link
Member

Choose a reason for hiding this comment

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

Good question. I cannot remember how it works here anymore...

Comment on lines +12 to +53
class SphinxDft(FileIOCalculator):
implemented_properties = ["energy", "forces"]

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs, profile=StandardProfile(command="sphinx"))
self.fileio_rules = FileIORules(stdout_name="log.sx")

def write_input(self, atoms, properties=None, system_changes=None):
super().write_input(atoms, properties, system_changes)

struct_group = get_structure_group(atoms)[0]
main_group = sphinx.main(
scfDiag=sphinx.main.scfDiag(maxSteps=10, blockCCG={}),
evalForces=sphinx.main.evalForces("forces.txt"),
)
pawPot_group = get_paw_from_structure(atoms)
basis_group = sphinx.basis(
eCut=25, kPoint=sphinx.basis.kPoint(coords=3 * [0.5])
)
paw_group = sphinx.PAWHamiltonian(xc=1, spinPolarized=False, ekt=0.2)
initial_guess_group = sphinx.initialGuess(
waves=sphinx.initialGuess.waves(lcao=sphinx.initialGuess.waves.lcao()),
rho=sphinx.initialGuess.rho(atomicOrbitals=True),
)

input_sx = sphinx(
pawPot=pawPot_group,
structure=struct_group,
main=main_group,
basis=basis_group,
PAWHamiltonian=paw_group,
initialGuess=initial_guess_group,
)

cwd = self.directory
with open(Path(cwd) / "input.sx", "w") as f:
f.write(to_sphinx(input_sx))

def read_results(self):
parser = SphinxLogParser.load_from_path(Path(self.directory) / "log.sx")
self.results["energy"] = parser.get_energy_free()[-1][-1]
self.results["forces"] = parser.get_forces()[-1]
Comment on lines +51 to +52
parser = SphinxLogParser.load_from_path(Path(self.directory) / "log.sx")
self.results["energy"] = parser.get_energy_free()[-1][-1]
pmrv and others added 2 commits March 19, 2026 16:01
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Marvin Poul <ponder@creshal.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] ASE compatible Calculator

4 participants