| | import datasets |
| | import torch |
| | from torch_geometric.data import Data |
| |
|
| |
|
| | _CITATION = """\ |
| | @article{metamatbench, |
| | title={MetamatBench: Integrating Heterogeneous Data, Computational Tools, and Visual Interface for Metamaterial Discovery}, |
| | author={Chen, Jianpeng and Zhan, Wangzhi and Wang, Haohui and Jia, Zian and Gan, Jingru and Zhang, Junkai and Qi, Jingyuan and Chen, Tingwei and Huang, Lifu and Chen, Muhao and others}, |
| | journal={arXiv preprint arXiv:2505.20299}, |
| | year={2025} |
| | } |
| | """ |
| |
|
| | _DESCRIPTION = """ |
| | This dataset contains lattice structure data for predicting modulus properties, preprocessed into PyTorch Geometric (PyG) compatible format. |
| | """ |
| |
|
| |
|
| | class LatticeModulusDataset(datasets.GeneratorBasedBuilder): |
| | def _info(self): |
| | return datasets.DatasetInfo( |
| | description=_DESCRIPTION, |
| | citation=_CITATION, |
| | features=datasets.Features({ |
| | 'frac_coords': datasets.Array2D(shape=(None, 3), dtype='float32'), |
| | 'cart_coords': datasets.Array2D(shape=(None, 3), dtype='float32'), |
| | 'node_feat': datasets.Array2D(shape=(None, 4), dtype='float32'), |
| | 'node_type': datasets.Sequence(datasets.Value('int64')), |
| | 'edge_feat': datasets.Array2D(shape=(None, 1), dtype='float32'), |
| | 'edge_index': datasets.Array2D(shape=(2, None), dtype='int64'), |
| | 'lengths': datasets.Array2D(shape=(1, 3), dtype='float32'), |
| | 'num_nodes': datasets.Value('int64'), |
| | 'num_atoms': datasets.Value('int64'), |
| | 'angles': datasets.Array2D(shape=(1, 3), dtype='float32'), |
| | 'vector': datasets.Array2D(shape=(1, 9), dtype='float32'), |
| | 'y': datasets.Array2D(shape=(1, 12), dtype='float32'), |
| | 'young': datasets.Array2D(shape=(1, 3), dtype='float32'), |
| | 'shear': datasets.Array2D(shape=(1, 3), dtype='float32'), |
| | 'poisson': datasets.Array2D(shape=(1, 6), dtype='float32'), |
| | }), |
| | ) |
| |
|
| | def _split_generators(self, dl_manager): |
| | file_path = dl_manager.download_and_extract('data.pkl') |
| | return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={'filepath': file_path})] |
| |
|
| | def _generate_examples(self, filepath): |
| | dataset = torch.load(filepath) |
| |
|
| | for idx, data in enumerate(dataset): |
| | yield idx, { |
| | 'frac_coords': data.frac_coords.numpy(), |
| | 'cart_coords': data.cart_coords.numpy(), |
| | 'node_feat': data.node_feat.numpy(), |
| | 'node_type': data.node_type.numpy().tolist(), |
| | 'edge_feat': data.edge_feat.numpy(), |
| | 'edge_index': data.edge_index.numpy(), |
| | 'lengths': data.lengths.numpy(), |
| | 'num_nodes': data.num_nodes, |
| | 'num_atoms': data.num_atoms, |
| | 'angles': data.angles.numpy(), |
| | 'vector': data.vector.numpy(), |
| | 'y': data.y.numpy(), |
| | 'young': data.young.numpy(), |
| | 'shear': data.shear.numpy(), |
| | 'poisson': data.poisson.numpy(), |
| | } |