MDIL-SNU / SevenNet

SevenNet - a graph neural network interatomic potential package supporting efficient multi-GPU parallel molecular dynamics simulations.
https://pubs.acs.org/doi/10.1021/acs.jctc.4c00190
GNU General Public License v3.0
133 stars 17 forks source link

anyway to read energy, force and stress from extxyz? #87

Closed thangckt closed 1 month ago

thangckt commented 2 months ago

Dear Developers,

I try to use SevenNet with initial data in extxyz format. The problem is that I cannot process the data when your implemetation eventually required an ase.calculator to compute quantities.

You may be awared that extxyz can store per-config and per-atom properties like energy, stress, forces,..

So my question is anyway to read such properties without need to compute with an ase.calculator? (I know how to get them from ase.Atoms. This link is the way they are read in MACE suit)

Thanks.

YutackPark commented 2 months ago

Have you tried sevenn_inference? Currently the sevenn_inference does not save the result (what SevenNet predicted) to .extxyz format but it gives '.csv' files and does not require ase.calculator to evaluate. sevenn_inference can be used vai command line interface only.

Before using sevenn_inference, you may need to convert .extxyz to POSCAR, or you should download a the latest version of SevenNet (in main branch)

or if this is not the answer you wanted could you explain in more detail?

thangckt commented 2 months ago

hi @YutackPark

I mean I have a dataset in extxyz format (already contains energy and atomic forces from DFT calculations). How to feed it into 7Net to train model.

Thanks

YutackPark commented 2 months ago

Hi, SevenNet can directly read .extxyz files for training.

https://github.com/MDIL-SNU/SevenNet/blob/main/sevenn%2Fpresets%2Fbase.yaml

You can put your .extxyz files into load_dataset_path in the above example. As it will try to preprocessing the data first, which might be time-consuming, you may want to separate preprocessing step using sevenn_graph_build.

thangckt commented 2 months ago

hi @YutackPark

Thank you for your guide. I did exactly what you figure out.

I as understand, sevenn_graph_build will use ase.io.read to read extxyz file into ase.Atoms. After that, convert them into 7Net dataset. And the problem may come from this part of your code.

    try:
        y_energy = atoms.get_potential_energy(force_consistent=True)
    except NotImplementedError:
        y_energy = atoms.get_potential_energy()
    y_force = atoms.get_forces(apply_constraint=False)
    try:
        # xx yy zz xy yz zx order
        # We expect this is eV/A^3 unit
        # (ASE automatically converts vasp kB to eV/A^3)
        # So we restore it
        y_stress = -1 * atoms.get_stress()
        y_stress = np.array([y_stress[[0, 1, 2, 5, 3, 4]]])
    except RuntimeError:
        y_stress = None

function atoms.get_potential_energy() will require a calculator, and throw error if atoms have no one.

May I wrong?

YutackPark commented 2 months ago

I understood what you want to do. If that's the case, there is no direct way to achieve what you are trying to do, as SevenNet doesn't know how the extxyz stored their energy, force, and stress that is not stored with a calculator.

To make things work, a python script is needed to re-stored the data into atoms object, this time with the SinglePointCalculator. It might seem tricky for the first time, but we have related issue and example below.

Check my first answer of this issue: https://github.com/MDIL-SNU/SevenNet/issues/61

You can store your EFS with the SinglePointCalculator. Then you save your atoms objects into .extxyz again, and feed it to the SevenNet. Note that you need to put extra care in its units and sign of stress.

YutackPark commented 2 months ago

While #89 is merged, it is limited to sevenn_graph_build. Similar functionality should be developed for sevenn_inference and the training. This may be done during #86.

YutackPark commented 1 month ago

98