cjpcool commited on
Commit
395e1e6
·
1 Parent(s): b95dfea

Upload py file

Browse files
Files changed (1) hide show
  1. meta_modulus.py +68 -0
meta_modulus.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ import torch
3
+ from torch_geometric.data import Data
4
+
5
+
6
+ _CITATION = """\
7
+ @article{metamatbench,
8
+ title={MetamatBench: Integrating Heterogeneous Data, Computational Tools, and Visual Interface for Metamaterial Discovery},
9
+ 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},
10
+ journal={arXiv preprint arXiv:2505.20299},
11
+ year={2025}
12
+ }
13
+ """
14
+
15
+ _DESCRIPTION = """
16
+ This dataset contains lattice structure data for predicting modulus properties, preprocessed into PyTorch Geometric (PyG) compatible format.
17
+ """
18
+
19
+
20
+ class LatticeModulusDataset(datasets.GeneratorBasedBuilder):
21
+ def _info(self):
22
+ return datasets.DatasetInfo(
23
+ description=_DESCRIPTION,
24
+ citation=_CITATION,
25
+ features=datasets.Features({
26
+ 'frac_coords': datasets.Array2D(shape=(None, 3), dtype='float32'),
27
+ 'cart_coords': datasets.Array2D(shape=(None, 3), dtype='float32'),
28
+ 'node_feat': datasets.Array2D(shape=(None, 4), dtype='float32'),
29
+ 'node_type': datasets.Sequence(datasets.Value('int64')),
30
+ 'edge_feat': datasets.Array2D(shape=(None, 1), dtype='float32'),
31
+ 'edge_index': datasets.Array2D(shape=(2, None), dtype='int64'),
32
+ 'lengths': datasets.Array2D(shape=(1, 3), dtype='float32'),
33
+ 'num_nodes': datasets.Value('int64'),
34
+ 'num_atoms': datasets.Value('int64'),
35
+ 'angles': datasets.Array2D(shape=(1, 3), dtype='float32'),
36
+ 'vector': datasets.Array2D(shape=(1, 9), dtype='float32'),
37
+ 'y': datasets.Array2D(shape=(1, 12), dtype='float32'),
38
+ 'young': datasets.Array2D(shape=(1, 3), dtype='float32'),
39
+ 'shear': datasets.Array2D(shape=(1, 3), dtype='float32'),
40
+ 'poisson': datasets.Array2D(shape=(1, 6), dtype='float32'),
41
+ }),
42
+ )
43
+
44
+ def _split_generators(self, dl_manager):
45
+ file_path = dl_manager.download_and_extract('data.pkl')
46
+ return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={'filepath': file_path})]
47
+
48
+ def _generate_examples(self, filepath):
49
+ dataset = torch.load(filepath)
50
+
51
+ for idx, data in enumerate(dataset):
52
+ yield idx, {
53
+ 'frac_coords': data.frac_coords.numpy(),
54
+ 'cart_coords': data.cart_coords.numpy(),
55
+ 'node_feat': data.node_feat.numpy(),
56
+ 'node_type': data.node_type.numpy().tolist(),
57
+ 'edge_feat': data.edge_feat.numpy(),
58
+ 'edge_index': data.edge_index.numpy(),
59
+ 'lengths': data.lengths.numpy(),
60
+ 'num_nodes': data.num_nodes,
61
+ 'num_atoms': data.num_atoms,
62
+ 'angles': data.angles.numpy(),
63
+ 'vector': data.vector.numpy(),
64
+ 'y': data.y.numpy(),
65
+ 'young': data.young.numpy(),
66
+ 'shear': data.shear.numpy(),
67
+ 'poisson': data.poisson.numpy(),
68
+ }