|
| 1 | +import numpy as np |
| 2 | + |
| 3 | +from dpdata.format import Format |
| 4 | +from dpdata.psi4.output import read_psi4_output |
| 5 | +from dpdata.unit import EnergyConversion, ForceConversion, LengthConversion |
| 6 | + |
| 7 | +length_convert = LengthConversion("bohr", "angstrom").value() |
| 8 | +energy_convert = EnergyConversion("hartree", "eV").value() |
| 9 | +force_convert = ForceConversion("hartree/bohr", "eV/angstrom").value() |
| 10 | + |
| 11 | + |
| 12 | +@Format.register("psi4/out") |
| 13 | +class PSI4OutFormat(Format): |
| 14 | + """Psi4 output. |
| 15 | +
|
| 16 | + Note that both the energy and the gradient should be |
| 17 | + printed into the output file. |
| 18 | + """ |
| 19 | + |
| 20 | + def from_labeled_system(self, file_name: str, **kwargs) -> dict: |
| 21 | + """Read from Psi4 output. |
| 22 | +
|
| 23 | + Parameters |
| 24 | + ---------- |
| 25 | + file_name : str |
| 26 | + file name |
| 27 | + **kwargs |
| 28 | + keyword arguments |
| 29 | +
|
| 30 | + Returns |
| 31 | + ------- |
| 32 | + dict |
| 33 | + system data |
| 34 | + """ |
| 35 | + symbols, coord, energy, forces = read_psi4_output(file_name) |
| 36 | + |
| 37 | + atom_names, atom_types, atom_numbs = np.unique( |
| 38 | + symbols, return_inverse=True, return_counts=True |
| 39 | + ) |
| 40 | + natoms = coord.shape[0] |
| 41 | + |
| 42 | + return { |
| 43 | + "atom_types": atom_types, |
| 44 | + "atom_names": list(atom_names), |
| 45 | + "atom_numbs": list(atom_numbs), |
| 46 | + "coords": (coord * length_convert).reshape((1, natoms, 3)), |
| 47 | + "energies": np.array([energy * energy_convert]), |
| 48 | + "forces": (forces * force_convert).reshape((1, natoms, 3)), |
| 49 | + "cells": np.zeros((1, 3, 3)), |
| 50 | + "orig": np.zeros(3), |
| 51 | + "nopbc": True, |
| 52 | + } |
0 commit comments