| from ase import units |
| from ase.io import write, Trajectory, read |
| from ase.md.langevin import Langevin |
| from ase.md.velocitydistribution import MaxwellBoltzmannDistribution, Stationary, ZeroRotation |
| from ase.build import molecule |
| from ase.md import MDLogger |
| import numpy as np |
|
|
| |
| import os |
| _REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| _JD_PATH = os.path.join(_REPO_ROOT, "weight", "Jd.pt") |
| if os.path.isfile(_JD_PATH): |
| os.environ.setdefault("ONESCIENCE_UMA_JD_PATH", _JD_PATH) |
|
|
| from onescience.utils.uma.units.mlip_unit import load_predict_unit |
| from onescience.utils.uma.calculate.ase_calculator import FAIRChemCalculator |
|
|
| |
| ckpt = "../weight/uma-s-1p1_converted.pt" |
|
|
| |
| predictor = load_predict_unit(ckpt, device="cuda") |
| calc = FAIRChemCalculator(predictor, task_name="omol") |
|
|
| |
| atoms = molecule("H2O") |
| atoms.calc = calc |
|
|
| |
| T0 = 400 |
| MaxwellBoltzmannDistribution(atoms, temperature_K=T0) |
| Stationary(atoms) |
| ZeroRotation(atoms) |
|
|
| |
| dt = 0.1 * units.fs |
| gamma = 0.001 / units.fs |
| dyn = Langevin(atoms, timestep=dt, temperature_K=T0, friction=gamma) |
|
|
| |
| traj = Trajectory("my_md.traj", "w", atoms) |
| dyn.attach(traj.write, interval=1) |
| logger = MDLogger(dyn, atoms, "md.log", header=True, stress=False, peratom=False) |
| dyn.attach(logger, interval=10) |
|
|
| |
| def printer(): |
| epot = atoms.get_potential_energy() |
| ekin = atoms.get_kinetic_energy() |
| Tinst = 2.0 * ekin / (3 * len(atoms) * units.kB) |
| print(f"Step {dyn.nsteps:5d} Epot={epot: .6f} eV Ekin={ekin: .6f} eV T={Tinst: .1f} K") |
| dyn.attach(printer, interval=50) |
|
|
| |
| steps = 1000 |
| dyn.run(steps=steps) |
|
|
| |
| Epot = atoms.get_potential_energy() |
| Ekin = atoms.get_kinetic_energy() |
| Tfinal = 2.0 * Ekin / (3 * len(atoms) * units.kB) |
| print("\n== MD Finished ==") |
| print(f"Final Epot = {Epot:.6f} eV, Ekin = {Ekin:.6f} eV, T = {Tfinal:.2f} K") |
| print("COM =", atoms.get_center_of_mass()) |
|
|
| |
| write("final.xyz", atoms) |
| try: |
| write("final.cif", atoms) |
| except Exception as e: |
| print("Save CIF skipped:", e) |
|
|
| |
| |
| |
|
|