### Install GRIDAY using Python Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/installation.md Install the GRIDAY tool programmatically by calling a Python function. This is an alternative to the command-line installation. ```python from moftransformer.utils import install_griday install_griday() ``` -------------------------------- ### Install GRIDAY for MOFTransformer Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/prepare_data.md Use this command to install the GRIDAY tool, which is required for calculating energy-grids from cif files for MOFTransformer. ```bash moftransformer install-griday ``` -------------------------------- ### Example Command-Line Training Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/training.md A practical example of using the command-line interface for training. This command specifies the dataset root, downstream task, number of epochs, number of devices, and batch size. ```bash $ moftransformer run --root_dataset './data' --downstream 'example' --max_epochs 10 --devices 2 --batch_size 216 ``` -------------------------------- ### Install MOFTransformer using PIP Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/installation.md Use this command to install the MOFTransformer package directly from PyPI. Ensure Python and PyTorch are installed first. ```bash pip install moftransformer ``` -------------------------------- ### Train for Multi-Task Learning Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/training.md Example demonstrating multi-task learning setup using `moftransformer.run`. This configuration is suitable when dealing with multiple target variables, requiring lists for `mean`, `std`, and specifying `n_targets`. ```python import moftransformer from moftransformer.examples import example_path # data root and downstream from example root_dataset = example_path['root_dataset'] downstream = example_path['downstream'] log_dir = './logs/' # load_path = "pmtransformer" (default) # kwargs (optional) max_epochs = 10 batch_size = 8 mean = [0, 1, 2] std = [1, 2, 3] n_targets = 3 moftransformer.run(root_dataset, downstream, log_dir=log_dir, max_epochs=max_epochs, batch_size=batch_size, mean=mean, std=std, n_targets=n_targets) ``` -------------------------------- ### Install CGCNN Prerequisites Source: https://github.com/hspark1212/moftransformer/blob/master/baseline_model/CGCNN/README.md Commands to create a conda environment and install necessary dependencies for the CGCNN package. ```bash conda upgrade conda conda create -n cgcnn python=3 scikit-learn pytorch torchvision pymatgen -c pytorch -c conda-forge ``` -------------------------------- ### Install GRIDAY using Make Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/installation.md Manually install GRIDAY using the Makefile if automatic installation fails. This process may require updating GCC/G++ versions, especially in Anaconda environments. ```bash $ conda install -c conda-forge gcc=9.5.0 $ conda install -c conda-forge gxx=9.5.0 $ cd [PATH_MOFTransformer]/libs/GRIDAY/ # move to path of griday-file $ make # make Makefile $ cd scripts/ $ make # make Makefile ``` -------------------------------- ### Run MOFTransformer Data Preparation Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/prepare_data.md This Python script demonstrates how to use the `prepare_data` function to generate atom-wise graph embeddings and energy-grids from cif files. Ensure GRIDAY is installed and cif files are in the specified directory. ```python from moftransformer.examples import example_path from moftransformer.utils import prepare_data # Get example path root_cifs = example_path['root_cif'] root_dataset = example_path['root_dataset'] downstream = example_path['downstream'] train_fraction = 0.8 # default value test_fraction = 0.1 # default value # Run prepare data prepare_data(root_cifs, root_dataset, downstream=downstream, train_fraction=train_fraction, test_fraction=test_fraction) ``` -------------------------------- ### Editable Install MOFTransformer Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/installation.md Clone the repository and install in editable mode to modify the source code. This requires Git and a Python environment. ```bash git clone https://github.com/hspark1212/MOFTransformer.git cd MOFTransformer pip install -e . ``` -------------------------------- ### Train PMTransformer (Single-Task) Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/training.md Example of training a PMTransformer for a single downstream task using the `moftransformer.run` function. Ensure the dataset and downstream task are correctly specified. Optional keyword arguments can configure training parameters. ```python import moftransformer from moftransformer.examples import example_path # data root and downstream from example root_dataset = example_path['root_dataset'] downstream = example_path['downstream'] log_dir = './logs/' # load_path = "pmtransformer" (default) # kwargs (optional) max_epochs = 10 batch_size = 8 mean = 0 std = 1 moftransformer.run(root_dataset, downstream, log_dir=log_dir, max_epochs=max_epochs, batch_size=batch_size, mean=mean, std=std) ``` -------------------------------- ### Training MOFTransformer using Python `run` function Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/training.md This section details how to train MOFTransformers using the `moftransformer.run` function, including parameter explanations and examples for single-task and multi-task learning. ```APIDOC ## MOFTRANSFORMER.RUN ### Description Trains a MOFTransformer model with specified dataset and configuration. ### Method `moftransformer.run` ### Parameters - **root_dataset** (string) - Required - A folder containing graph data, grid data, and json of MOFs. - **downstream** (string) - Required - Name of user-specific task (e.g. bandgap, gasuptake). - **log_dir** (string) - Optional - Directory to save log, models, and params. (default: `logs/`) - **test_only** (boolean) - Optional - If True, only the test process is performed without the learning model. (default: `False`) - **kwargs** (dict) - Optional - Configuration for MOFTransformer, including: - **max_epochs** (int) - Maximum number of training epochs. - **batch_size** (int) - Batch size for training. - **mean** (float or list of floats) - Mean value(s) for normalization. - **std** (float or list of floats) - Standard deviation value(s) for normalization. - **n_targets** (int) - Number of targets for multi-task learning. ### Request Example (Single-task) ```python import moftransformer from moftransformer.examples import example_path root_dataset = example_path['root_dataset'] downstream = example_path['downstream'] log_dir = './logs/' max_epochs = 10 batch_size = 8 mean = 0 std = 1 moftransformer.run(root_dataset, downstream, log_dir=log_dir, max_epochs=max_epochs, batch_size=batch_size, mean=mean, std=std) ``` ### Request Example (Multi-task) ```python import moftransformer from moftransformer.examples import example_path root_dataset = example_path['root_dataset'] downstream = example_path['downstream'] log_dir = './logs/' max_epochs = 10 batch_size = 8 mean = [0, 1, 2] std = [1, 2, 3] n_targets = 3 moftransformer.run(root_dataset, downstream, log_dir=log_dir, max_epochs=max_epochs, batch_size=batch_size, mean=mean, std=std, n_targets=n_targets) ``` ### Post-training After training, the trained model, logs, and hyperparameters will be saved at `log_dir`. You can monitor the results using tensorboard: ```bash $ tensorboard --logdir=[log_dir] --bind_all ``` ``` -------------------------------- ### Training MOFTransformer using Command-Line Interface Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/training.md This section explains how to initiate MOFTransformer training directly from the command line, mirroring the parameters available in the Python `run` function. ```APIDOC ## MOFTRANSFORMER RUN (Command-Line) ### Description Initiates MOFTransformer training using the command-line interface. ### Method `moftransformer run` ### Endpoint `moftransformer run --root_dataset [root_dataset] --downstream [downstream] --logdir [logdir] ...` ### Parameters Parameters are similar to the Python `moftransformer.run` function. Use `-h` for a full list. ### Example ```bash $ moftransformer run --root_dataset './data' --downstream 'example' --max_epochs 10 --devices 2 --batch_size 216 ``` ### Help For detailed parameter information, run: ```bash $ moftransformer run -h ``` ``` -------------------------------- ### View Training Results with TensorBoard Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/training.md Command to launch TensorBoard for visualizing training logs, models, and hyperparameters saved in the specified log directory. Use the `--bind_all` flag to make it accessible externally. ```bash tensorboard --logdir=[log_dir] --bind_all ``` -------------------------------- ### Download MOFTransformer Models and Data via Command-Line Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/installation.md Use the command-line interface to download pre-trained models, fine-tuned models, or datasets for CoREMOF and QMOF. Specify the target and optionally an output directory. ```bash moftransformer download [target] (--outdir outdir) (--remove_tarfile) ``` ```bash # download pre-trained model (required) $ moftransformer download pretrain_model # download graph-data and graph-data for CoREMOF (optional) $ moftransformer download coremof # download graph-data and graph-data for QMOF (optional) $ moftransformer download qmof # download fine-tuned model (optional) $ mofransformer download finetuned_model ``` -------------------------------- ### Initialize PatchVisualizer Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/visualization.md Methods to instantiate the visualizer using either a specific CIF name or an index from a directory. ```python from moftransformer.visualize import PatchVisualizer from moftransformer.examples import visualize_example_path model_path = "examples/finetuned_bandgap.ckpt" # or 'examples/finetuned_h2_uptake.ckpt' data_path = visualize_example_path cifname = 'MIBQAR01_FSR' vis = PatchVisualizer.from_cifname(cifname, model_path, data_path) vis.draw_graph() ``` ```python from moftransformer.visualize import PatchVisualizer from moftransformer.examples import visualize_example_path model_path = "examples/finetuned_bandgap.ckpt" # or 'examples/finetuned_h2_uptake.ckpt' data_path = visualize_example_path batch_id = 0 vis = PatchVisualizer.from_index(0, model_path, data_path) ``` -------------------------------- ### Train MOFTransformer via Command-Line Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/training.md Initiate MOFTransformer training directly from the command line using the `run` subcommand. This method accepts parameters equivalent to the Python `run` function, allowing for flexible configuration. ```bash $ moftransformer run --root_dataset [root_dataset] --downstream [downstream] --logdir [logdir] ... ``` -------------------------------- ### Download Finetuned Models Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/visualization.md Command to download pre-trained model checkpoints for analysis. ```bash $ moftransformer download finetuned_model -o ./examples ``` -------------------------------- ### Download Pretrained Model and Database Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/tutorial.md Commands to download the required pretrained model and the hMOF dataset. ```bash $ moftransformer download pretrain_model ``` ```bash $ moftransformer download hmof -o ./hmof ``` -------------------------------- ### Download Pre-trained Model Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/training.md Use this command to download a pre-trained MOFTransformer model for further training or fine-tuning. ```bash moftransformer download pretrain_model ``` -------------------------------- ### Train a CGCNN model with custom dataset Source: https://github.com/hspark1212/moftransformer/blob/master/baseline_model/CGCNN/README.md Use this command to train a CGCNN model. Specify the root directory for your dataset. You can control the data split using `--train-size`, `--val-size`, `--test-size` or `--train-ratio`, `--val-ratio`, `--test-ratio` flags. Do not use size and ratio flags simultaneously. ```bash python main.py root_dir ``` ```bash python main.py --train-size 6 --val-size 2 --test-size 2 data/sample-regression ``` ```bash python main.py --train-ratio 0.6 --val-ratio 0.2 --test-ratio 0.2 data/sample-regression ``` ```bash python main.py --task classification --train-size 5 --val-size 2 --test-size 3 data/sample-classification ``` -------------------------------- ### Import PatchVisualizer Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/visualization.md Initial import required to access visualization tools. ```python from visualize import PatchVisualizer ``` -------------------------------- ### Test MOFTransformer via Command Line Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/test.md Executes model testing directly from the terminal using the moftransformer CLI. ```bash $ moftransformer test --root_dataset './data' --downstream 'example' --load_path 'model.ckpt' --mean 0 --std 1 ``` -------------------------------- ### Download Pre-embeddings for CoREMOF, QMOF Source: https://github.com/hspark1212/moftransformer/blob/master/README.md Download pre-computed embeddings for CoREMOF and QMOF datasets. These embeddings serve as inputs for the PMTransformer model. ```bash moftransformer download coremof ``` ```bash moftransformer download qmof ``` -------------------------------- ### Download MOFTransformer Models and Data using Python Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/installation.md Download necessary models and datasets programmatically using Python functions. Optional arguments for output directory and tar file removal are available. ```python from moftransformer.utils.download import ( download_pretrain_model, download_qmof, download_coremof, download_hmof, download_finetuned_model ) # download pre-trained model download_pretrain_model() # download coremof download_coremof() # download qmof download_qmof() # download finetuned_model download_finetuned_model() ``` -------------------------------- ### Initialize PatchVisualizer with Matplotlib Widget Source: https://github.com/hspark1212/moftransformer/blob/master/README.md Initializes the PatchVisualizer using a matplotlib widget backend, suitable for interactive environments. Ensure the model and data paths are correctly specified. ```python %matplotlib widget from visualize import PatchVisualizer model_path = "examples/finetuned_bandgap.ckpt" # or 'examples/finetuned_h2_uptake.ckpt' data_path = 'examples/visualize/dataset/' cifname = 'MIBQAR01_FSR' vis = PatchVisualizer.from_cifname(cifname, model_path, data_path) vis.draw_graph() ``` -------------------------------- ### Predict material properties with a pre-trained CGCNN model Source: https://github.com/hspark1212/moftransformer/blob/master/baseline_model/CGCNN/README.md Use this command to predict properties using a pre-trained model. Provide the path to the pre-trained model file and the root directory of the dataset for which you want to predict properties. For classification tasks, the output probability is between 0 and 1. ```bash python predict.py pre-trained.pth.tar root_dir ``` ```bash python predict.py pre-trained/formation-energy-per-atom.pth.tar data/sample-regression ``` ```bash python predict.py pre-trained/semi-metal-classification.pth.tar data/sample-classification ``` -------------------------------- ### Visualize Feature Importance with PatchVisualizer (Grid) Source: https://github.com/hspark1212/moftransformer/blob/master/README.md Visualize the feature importance analysis of energy-grid embeddings for a fine-tuned model. Requires a trained model checkpoint and dataset. ```python vis = PatchVisualizer.from_cifname(cifname, model_path, data_path) vis.draw_grid() ``` -------------------------------- ### Test MOFTransformer Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/tutorial.md Execution of the testing phase by loading a saved checkpoint file. ```python import moftransformer root_dataset = './hmof/downstream_release' downstream = 'raspa_100bar' load_path = './logs/pretrained_mof_seed0_from_pretrained_model/version_0/checkpoints/last.ckpt' # cpkt : ./logs/[target_model_path]/[version]/checkpoints/[model].ckpt max_epochs = 20 mean = 487.841 std = 63.088 batch_size = 32 moftransformer.run(root_dataset, downstream, test_only=True, load_path=load_path, max_epochs=max_epochs, mean=mean, std=std, batch_size=batch_size) ``` -------------------------------- ### Test MOFTransformer with TensorBoard logging Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/test.md Uses the run function with test_only set to True to enable TensorBoard logging during evaluation. ```python from pathlib import Path import moftransformer from moftransformer.examples import example_path root_dataset = example_path['root_dataset'] downstream = example_path['downstream'] # Get ckpt file seed = 0 # default seeds version = 0 # version for model. It increases with the number of trains # For version > 2.1.1, best.ckpt exists. checkpoint = 'best' # Epochs where the model is stored. # optional keyword mean = 0 std = 1 load_path = Path(log_dir) / f'pretrained_mof_seed{seed}_from_pmtransformer/version_{version}/checkpoints/{checkpoint}.ckpt' if not load_path.exists(): raise ValueError(f'load_path does not exists. check path for .ckpt file : {load_path}') moftransformer.run(root_dataset, downstream=downstream, log_dir='logs/', test_only=True, load_path=load_path, mean=mean, std=std) ``` -------------------------------- ### Predicting via Command-Line Interface Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/predict.md Execute predictions directly from the terminal using the moftransformer CLI. ```bash $ moftransformer predict --root_dataset [root_dataset] --load_path [load_path]--downstream [downstream] --split [split] --save_dir [save_dir] ... ``` ```bash $ moftransformer predict --root_dataset './data' --load_path 'path/of/model' --downstream 'exmaple' --mean 0. --std 1. ``` -------------------------------- ### Train MOFTransformer Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/tutorial.md Configuration and execution of the training process using the downloaded hMOF database. ```python import moftransformer root_dataset = './hmof/downstream_release' downstream = 'raspa_100bar' log_dir = './logs' max_epochs = 20 mean = 487.841 std = 63.088 batch_size = 32 load_path = "pmtransformer" # default : "pmtransformer", you can also choose "moftransformer" or None or path of other training models. moftransformer.run(root_dataset, downstream, max_epochs=max_epochs, mean=mean, std=std, batch_size=batch_size, log_dir=log_dir, load_path="pmtransformer") ``` -------------------------------- ### Visualize Energy-grid Embeddings Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/visualization.md Methods for rendering energy-grid embeddings, supporting filtering by attention scores, specific patch positions, and ranking. ```python %matplotlib widget vis.draw_grid() ``` ```python %matplotlib widget minatt, maxatt = 0.005, 0.008 view_init=(0, -55) cmap = 'rocket_r' alpha = 0.3 grid_scale_factor = 1.8 atomic_scale_factor = 2 vis.draw_grid(minatt=minatt, maxatt=maxatt, view_init=view_init, alpha=alpha, cmap=cmap, grid_scale_factor=grid_scale_factor, atomic_scale_factor=atomic_scale_factor, remove_under_minatt=True) ``` ```python %matplotlib widget view_init=(27, -92) alpha = 1 grid_scale_factor = 1.8 atomic_scale_factor = 2 patch_list = [[0,0,0], [1,1,1], [2,2,2], [3,3,3], [4,4,4], [5,5,5]] # make list to patch vis.draw_grid(view_init=view_init, alpha=alpha, grid_scale_factor=grid_scale_factor, patch_list=patch_list, atomic_scale_factor=atomic_scale_factor) ``` ```python %matplotlib widget view_init = (0, 125) grid_scale_factor=1.8 atomic_scale_factor=1.5 rank = range(20) vis.draw_grid_with_attention_rank(rank, view_init=view_init, grid_scale_factor=grid_scale_factor, atomic_scale_factor=atomic_scale_factor) ``` -------------------------------- ### Test MOFTransformer using Python Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/test.md Evaluates a model using the test function. Results are saved to the specified directory or the model's default location. ```python from pathlib import Path import moftransformer from moftransformer.examples import example_path root_dataset = example_path['root_dataset'] downstream = example_path['downstream'] # Get ckpt file seed = 0 # default seeds version = 0 # version for model. It increases with the number of trains # For version > 2.1.1, best.ckpt exists checkpoint = 'best' # Epochs where the model is stored. save_dir = 'result/' # optional keyword mean = 0 std = 1 load_path = Path(log_dir) / f'pretrained_mof_seed{seed}_from_pmtransformer/version_{version}/checkpoints/{checkpoint}.ckpt' if not load_path.exists(): raise ValueError(f'load_path does not exists. check path for .ckpt file : {load_path}') moftransformer.test(root_dataset, load_path, downstream=downstream, save_dir=save_dir, mean=mean, std=std) ``` -------------------------------- ### Predict Material Properties with MOFTransformer Source: https://github.com/hspark1212/moftransformer/blob/master/README.md Use this snippet to predict material properties using a fine-tuned MOFTransformer model. Ensure the model checkpoint exists at the specified load_path. ```python from pathlib import Path import moftransformer from moftransformer.examples import example_path root_dataset = example_path['root_dataset'] downstream = example_path['downstream'] # Get ckpt file log_dir = './logs/' # same directory make from training seed = 0 # default seeds version = 0 # version for model. It increases with the number of trains checkpoint = 'best' # Epochs where the model is stored. mean = 0 std = 1 load_path = Path(log_dir) / f'pretrained_mof_seed{seed}_from_pmtransformer/version_{version}/checkpoints/{checkpoint}.ckpt' if not load_path.exists(): raise ValueError(f'load_path does not exists. check path for .ckpt file : {load_path}') moftransformer.predict( root_dataset, load_path=load_path, downstream=downstream, split='all', mean=mean, std=std ) ``` -------------------------------- ### Manage CGCNN Environment Source: https://github.com/hspark1212/moftransformer/blob/master/baseline_model/CGCNN/README.md Commands to activate, test, and deactivate the CGCNN conda environment. ```bash source activate cgcnn ``` ```bash python main.py -h python predict.py -h ``` ```bash source deactivate ``` -------------------------------- ### Visualize Specific Patches Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/visualization.md Methods to visualize individual patches based on position or attention rank. ```python %matplotlib widget patch_position = [2, 2, 2] view_init = (0, -55) vis.draw_specific_patch(patch_position, alpha=0.5, view_init=view_init) ``` ```python view_init = (15, -58) vis.draw_specific_patch_with_attention_rank(1, alpha=0.5, ep=0.8, view_init = view_init, grid_scale_factor=2) ``` -------------------------------- ### Command-line Prediction Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/predict.md Run predictions directly from the terminal using the moftransformer CLI. ```APIDOC ## CLI: moftransformer predict ### Description Perform model prediction via the command line using the same parameters as the Python function. ### Usage ```bash $ moftransformer predict --root_dataset [root_dataset] --load_path [load_path] --downstream [downstream] --split [split] --save_dir [save_dir] ``` ### Example ```bash $ moftransformer predict --root_dataset './data' --load_path 'path/of/model' --downstream 'example' --mean 0. --std 1. ``` ``` -------------------------------- ### Prepare Data for Single Task Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/dataset.md Use this function to generate atom-wise graph embeddings and energy-grid embeddings for a single downstream task. Ensure CIF files and a corresponding `raw_{downstream}.json` file are present in the `root_cifs` directory. ```python from moftransformer.utils import prepare_data # single task prepare_data(root_cifs, root_dataset, downstream="example") ``` -------------------------------- ### Prepare Data for Multiple Tasks Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/dataset.md This function call is used to generate embeddings for multiple downstream tasks simultaneously. Provide a list of task names to the `downstream` argument. ```python prepare_data(root_cifs, root_dataset, downstream=["example1", "example2", ...]) ``` -------------------------------- ### Visualize Feature Importance with PatchVisualizer (Graph) Source: https://github.com/hspark1212/moftransformer/blob/master/README.md Visualize the feature importance analysis of atom-based graph embeddings for a fine-tuned model. Requires a trained model checkpoint and dataset. ```python from moftransformer.visualize import PatchVisualizer from moftransformer.examples import visualize_example_path model_path = "examples/finetuned_bandgap.ckpt" # or 'examples/finetuned_h2_uptake.ckpt' data_path = visualize_example_path cifname = 'MIBQAR01_FSR' vis = PatchVisualizer.from_cifname(cifname, model_path, data_path) vis.draw_graph() ``` -------------------------------- ### Test Fine-tuned MOFTransformer Model Source: https://github.com/hspark1212/moftransformer/blob/master/README.md Test the fine-tuned MOFTransformer model. Specify the dataset root, downstream task, and checkpoint details to load the model for evaluation. ```python from pathlib import Path import moftransformer from moftransformer.examples import example_path root_dataset = example_path['root_dataset'] downstream = example_path['downstream'] # Get ckpt file seed = 0 # default seeds version = 0 # version for model. It increases with the number of trains # For version > 2.1.1, best.ckpt exists checkpoint = 'best' # Epochs where the model is stored. save_dir = 'result/' ``` -------------------------------- ### Define Custom Dataset Structure Source: https://github.com/hspark1212/moftransformer/blob/master/baseline_model/CGCNN/README.md The required directory structure for inputting custom crystal data into the CGCNN model. ```text root_dir ├── id_prop.csv ├── atom_init.json ├── id0.cif ├── id1.cif ├── ... ``` -------------------------------- ### Cite CGCNN in BibTeX Source: https://github.com/hspark1212/moftransformer/blob/master/baseline_model/CGCNN/README.md Use this BibTeX entry to cite the CGCNN framework in academic publications. ```bibtex @article{PhysRevLett.120.145301, title = {Crystal Graph Convolutional Neural Networks for an Accurate and Interpretable Prediction of Material Properties}, author = {Xie, Tian and Grossman, Jeffrey C.}, journal = {Phys. Rev. Lett.}, volume = {120}, issue = {14}, pages = {145301}, numpages = {6}, year = {2018}, month = {Apr}, publisher = {American Physical Society}, doi = {10.1103/PhysRevLett.120.145301}, url = {https://link.aps.org/doi/10.1103/PhysRevLett.120.145301} } ``` -------------------------------- ### Predicting with Python API Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/predict.md Use the moftransformer.predict function to run inference on a dataset using a pre-trained checkpoint. ```python from pathlib import Path import moftransformer from moftransformer.examples import example_path root_dataset = example_path['root_dataset'] downstream = example_path['downstream'] # Get ckpt file seed = 0 # default seeds version = 0 # version for model. It increases with the number of trains checkpoint = 'best' # Epochs where the model is stored. mean = 0 std = 1 load_path = Path(log_dir) / f'pretrained_mof_seed{seed}_from_pmtransformer/version_{version}/checkpoints/{checkpoint}.ckpt' if not load_path.exists(): raise ValueError(f'load_path does not exists. check path for .ckpt file : {load_path}') moftransformer.predict( root_dataset, load_path=load_path, downstream=downstream, split='all', mean=mean, std=std ) ``` -------------------------------- ### Visualize Atom-based Graph Embeddings Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/visualization.md Methods for rendering graph embeddings with attention scores, including parameter customization. ```python %matplotlib widget vis.draw_graph() ``` ```python %matplotlib widget minatt, maxatt = 0.002, 0.006 view_init=(0, -55) cmap = 'rocket_r' alpha = 0.5 grid_scale_factor = 1.8 atomic_scale_factor = 1.5 att_scale_factor= 3 vis.draw_graph(minatt=minatt, maxatt=maxatt, view_init=view_init, alpha=alpha, cmap=cmap, grid_scale_factor=grid_scale_factor, atomic_scale_factor=atomic_scale_factor, att_scale_factor=att_scale_factor) ``` -------------------------------- ### moftransformer.predict Source: https://github.com/hspark1212/moftransformer/blob/master/docs/source/getting_started/predict.md The predict function generates model outputs for a given dataset and saves the results as a CSV file. ```APIDOC ## moftransformer.predict ### Description Executes model prediction on a specified dataset and saves the results to a CSV file. ### Parameters - **root_dataset** (str) - Required - A folder containing graph data, grid data, and JSON of MOFs. - **load_path** (str) - Required - Path to the model checkpoint file (*.ckpt). - **downstream** (str) - Optional - Name of the user-specific task (e.g., bandgap, gasuptake). - **split** (str) - Optional - The dataset split to predict ('all', 'train', 'test', or 'val'). - **save_dir** (str) - Optional - Directory path to save the resulting CSV file. - **kwargs** (dict) - Optional - Additional configuration for MOFTransformer. ### Request Example ```python moftransformer.predict( root_dataset='./data', load_path='path/to/model.ckpt', downstream='bandgap', split='all' ) ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.