dpdata icon indicating copy to clipboard operation
dpdata copied to clipboard

[Feature Request] Support property label format in dpdata

Open Chengqian-Zhang opened this issue 1 year ago • 2 comments

Summary

Until now, property fitting has been merged to deepmd-kit. But the training dataset is not supported to be converted from dpdata. Not like other labels, property does not have a general data source file.

Detailed Description

See above

Further Information, Files, and Links

See above

Chengqian-Zhang avatar Sep 19 '24 12:09 Chengqian-Zhang

I don't have permission to assign myself

Chengqian-Zhang avatar Sep 19 '24 12:09 Chengqian-Zhang

please check if the data registration mechanism (https://github.com/deepmodeling/dpdata/pull/505) solves the issue, if not what feature is needed to be implemented.

wanghan-iapcm avatar Sep 20 '24 01:09 wanghan-iapcm

The data registration mechanism (https://github.com/deepmodeling/dpdata/pull/505) can solve the issue. A usage example:

import dpdata
import numpy as np
from dpdata.data_type import (
    Axis,
    DataType,
)

property_name = "band_prop"  # fittng_net/property_name
task_dim = 3  # fitting_net/task_dim

# register datatype
datatypes = [
    DataType(
        property_name,
        np.ndarray,
        shape=(Axis.NFRAMES, task_dim),
        required=False,
    ),
]
datatypes.extend(
    [
        DataType(
            "energies",
            np.ndarray,
            shape=(Axis.NFRAMES, 1),
            required=False,
        ),
        DataType(
            "forces",
            np.ndarray,
            shape=(Axis.NFRAMES, Axis.NATOMS, 1),
            required=False,
        ),
    ]
)

for datatype in datatypes:
    dpdata.System.register_data_type(datatype)
    dpdata.LabeledSystem.register_data_type(datatype)

ls = dpdata.MultiSystems()
frame = dpdata.System("POSCAR", fmt="vasp/poscar")
labelframe = dpdata.LabeledSystem()
labelframe.append(frame)
labelframe.data[property_name] = np.array([[-0.236, 0.056, 0.292]], dtype=np.float32)
ls.append(labelframe)
ls.to_deepmd_npy_mixed("deepmd")

Chengqian-Zhang avatar Dec 24 '24 17:12 Chengqian-Zhang