Skip to content
Community

Fixed-Cell Crystal Relaxation with SevenNet and ASE

Attach an inspected SevenNet calculator to an ASE crystal, compute energy and forces, and perform a bounded fixed-cell relaxation with explicit convergence records.

Level: Intermediate Cost: Free Privacy: Local ~45 min
Start Setup

You'll be able to

  • Produce traceable computational candidate artifacts and inspect the documented acceptance criteria.

What you'll build

Documentation-based review draft. This workflow has not been executed in this batch; no installation, inference, optimization or experimental result has been verified.

Scope and inputs

For atomistic-simulation researchers. Baseline: a user-supplied fully periodic crystal CIF, SevenNet-0's July 2024 checkpoint and ASE BFGS with a fixed cell. This is geometry relaxation, not a validated molecular-dynamics trajectory, band-gap predictor or variable-cell optimization. The chosen older single-task checkpoint makes the example explicit; it is not a recommendation that it outperforms newer models.

Handoff, units and artifacts

ASE reads CIF into Atoms with lattice, periodicity, atomic numbers and Cartesian positions. SevenNetCalculator implements the ASE calculator protocol and checks elements against its actual type_map. Reject absent/unsupported elements, invalid coordinates and nonpositive cell volume. The ASE convention used here is eV for energy, Angstrom for position and eV/Angstrom for forces; do not substitute LAMMPS units. Save initial.extxyz, relaxed.cif, initial/final force arrays, optimization.log, optimization.traj and results.json. fmax=0.05 eV/Angstrom and 100 steps are author-chosen demonstration bounds, not universal convergence advice. Nonconvergence is explicitly a failure to meet the stopping criterion.

Environment, rights and limitations

Inspect the pinned SevenNet 0.13.0 source, install a hardware-compatible PyTorch and record the resolved ASE/dependency versions. The CPU example avoids claiming CUDA or accelerator compatibility. The SevenNet source uses MIT; ASE uses LGPL-2.1-or-later. Keep model provenance and any accompanying weight/training-data conditions, rather than transferring source-code permissions to all data. Input rights remain separate. An in-domain reference energy/force or DFT comparison is needed for scientific assessment. Good convergence alone does not prove physical accuracy, stability or coverage of arbitrary chemistry. Local inference is the baseline; package/model downloads require internet. Setup time excludes optimization.

Official references

Atomic energy and force calculator

SevenNet

Crystal IO and fixed-cell optimizer

ASE

Stack Components

SevenNet

Atomic energy and force calculator · 0.13.0 source 209339d4eb4c1717f906c4cb715629159f00f88c; 7net-0 (July 2024)

Documentation-based review draft. This workflow has not been executed in this batch; no installation, inference, optimization or experimental result has been verified.

Code is open source; compute/storage and any external-service conditions remain the user's responsibility.

View Resource

ASE

Crystal IO and fixed-cell optimizer · ASE calculator/BFGS API; record resolved version

Documentation-based review draft. This workflow has not been executed in this batch; no installation, inference, optimization or experimental result has been verified.

Code is open source; compute/storage and any external-service conditions remain the user's responsibility.

View Resource

Compatibility

ClientOSArchitectureVersion requirements
Python LinuxAny>= 3.11

Setup & Test

1. Prepare an authorized periodic crystal

Linux

Place input.cif in a new working directory. Check units, atom count, periodic cell and intended reference calculation. Confirm actual checkpoint element coverage and terms, not a claimed universal material range.

Official source

Expected result

A valid periodic crystal and documented model/input provenance.

2. Install isolated dependencies

Linux

Use a new Python environment and an appropriate PyTorch install. The source declares Python >=3.8, but resolved dependencies may impose higher requirements; the review example targets Python 3.11 pending execution. Save pip freeze and the downloaded checkpoint checksum.

python -m pip install torch
python -m pip install 'sevenn @ git+https://github.com/MDIL-SNU/SevenNet.git@209339d4eb4c1717f906c4cb715629159f00f88c' ase
python -m pip freeze
Official source

Expected result

The recorded environment imports sevenn.calculator and ASE; no numerical result is implied.

3. Save the authored calculator example

Linux

Save the accompanying Python code as sevennet0_relax.py. It uses documented APIs and is authored here, not an upstream test result. The pinned alias 7net-0 selects July 2024; CPU is explicit, the cell stays fixed, and the output directory must not exist.

"""Authored review example using documented SevenNet/ASE APIs; NOT executed.

Sources: sevenn.calculator.SevenNetCalculator, ASE IO and BFGS documentation.
Fixed-cell geometry optimization only. No MD, reference DFT, or accuracy claim.
"""
import argparse
import json
from pathlib import Path

import numpy as np
from ase.io import read, write
from ase.optimize import BFGS
from sevenn.calculator import SevenNetCalculator

parser = argparse.ArgumentParser()
parser.add_argument("input_cif")
parser.add_argument("output_directory")
args = parser.parse_args()
atoms = read(args.input_cif)
if len(atoms) == 0 or not np.isfinite(atoms.positions).all():
    raise ValueError("Empty structure or nonfinite coordinates")
if not atoms.pbc.all() or atoms.get_volume() <= 0:
    raise ValueError("This example requires a fully periodic crystal with positive cell volume")
# The pinned SevenNet implementation resolves 7net-0 to its July 2024 checkpoint.
# The calculator checks each atomic number against the loaded model type_map.
atoms.calc = SevenNetCalculator(model="7net-0", device="cpu")
energy_initial = float(atoms.get_potential_energy())
forces_initial = atoms.get_forces()
if not np.isfinite(energy_initial) or not np.isfinite(forces_initial).all():
    raise ValueError("Nonfinite initial energy or forces")
out = Path(args.output_directory)
out.mkdir(parents=True, exist_ok=False)
write(out / "initial.extxyz", atoms)
optimizer = BFGS(atoms, logfile=str(out / "optimization.log"), trajectory=str(out / "optimization.traj"))
# These are illustrative stopping settings, not upstream recommendations for all systems.
converged = bool(optimizer.run(fmax=0.05, steps=100))
energy_final = float(atoms.get_potential_energy())
forces_final = atoms.get_forces()
if not np.isfinite(energy_final) or not np.isfinite(forces_final).all():
    raise ValueError("Nonfinite final energy or forces; inspect the partial output")
write(out / "relaxed.cif", atoms)
np.savez(out / "forces.npz", initial=forces_initial, final=forces_final)
record = {"model": "7net-0", "device": "cpu", "atom_count": len(atoms),
          "elements": sorted(set(atoms.get_chemical_symbols())), "fixed_cell": True,
          "energy_initial_eV": energy_initial, "energy_final_eV": energy_final,
          "force_unit": "eV/Angstrom", "fmax_threshold_eV_per_Angstrom": 0.05,
          "max_steps": 100, "converged": converged,
          "final_max_force_eV_per_Angstrom": float(np.linalg.norm(forces_final, axis=1).max())}
(out / "results.json").write_text(json.dumps(record, indent=2) + "\n", encoding="utf-8")
print(json.dumps(record, indent=2))
if not converged:
    raise SystemExit("Optimization reached its step limit; do not describe it as converged")
Official source

Expected result

Configuration checks atom types, coordinates and periodic cell before a bounded BFGS run.

4. Compute energy, forces and a bounded relaxation

Linux

Run on the inspected crystal, using a new output directory. The script preserves input, records finite energies/forces and stops explicitly if 100 steps do not meet the chosen force threshold.

python sevennet0_relax.py input.cif sevennet_review
Official source

Expected result

Expected: initial/final structures, forces.npz, optimization log/trajectory and results.json including converged. A finite energy is not a DFT agreement claim.

Troubleshooting

  • Unknown element: select a documented applicable checkpoint or reject the system.
  • Checkpoint download/import failure: inspect package/model provenance and network access; never replace weights silently.
  • Nonfinite forces: inspect cell, overlaps and model domain.
  • Existing output directory: select a new run name rather than overwriting results.
  • Nonconvergence: retain logs, inspect geometry and choose a separately justified policy; do not mark the run successful.
  • Reference mismatch: compare functional, composition, energy reference and units before blaming the model.
Still not working

Alternatives

Newer SevenNet checkpoints are separate configuration choices with different domains/fidelity tasks. A DFT reference calculation is independent validation; LAMMPS or MD integration is outside this fixed-cell baseline.