### Training Example Source: https://github.com/mindspore-ai/mindscience/blob/master/MindChem/applications/nequip/README.md Command to start the training process for the NequIP model, specifying configuration file, execution mode, target device, device ID, and data type. ```bash python train.py --config_file_path ./rmd.yaml --mode GRAPH --device_target Ascend --device_id 0 --dtype float32 ``` -------------------------------- ### Dataset Structure Example Source: https://github.com/mindspore-ai/mindscience/blob/master/MindChem/applications/crystalflow/README.md Example of how the dataset folder should be structured. ```txt crystalflow ... └─dataset perov_5 钙钛矿数据集 carbon_24 碳晶体数据集 mp_20 晶胞内原子数最多为20的MP数据集 mpts_52 晶胞内原子数最多为52的MP数据集 dataset_prop.txt 数据集属性文件 ... ``` -------------------------------- ### Install MindSpore Source: https://github.com/mindspore-ai/mindscience/blob/master/MindEnergy/applications/DeepONet-Grid-UQ/README.md Command to install the MindSpore framework. ```bash pip install mindspore ``` -------------------------------- ### Python Training Command Source: https://github.com/mindspore-ai/mindscience/blob/master/MindChem/applications/diffcsp/README.md Command to install requirements and start training. ```bash pip install -r requirement.txt python train.py ``` -------------------------------- ### Start training Source: https://github.com/mindspore-ai/mindscience/blob/master/MindEarth/applications/sea/LeadFormer/LeadFormer.ipynb Initializes the trainer with the configuration and starts the training process. ```python epoch_size = config["train"].get("epochs", 300) trainer = Trainer(config, epochs=epoch_size) trainer.train() ``` -------------------------------- ### Unzip Example PDBs Source: https://github.com/mindspore-ai/mindscience/blob/master/MindSPONGE/applications/proteinmpnn/README.md Command to unzip example PDB files for running demonstrations. ```bash unzip examples/example_inputs.zip -d examples/ ``` -------------------------------- ### Extract Example Data Source: https://github.com/mindspore-ai/mindscience/blob/master/MindSPONGE/applications/rf_diffusion/README.md Commands to extract example PDB and scaffold files for running demonstrations. ```bash tar -xvf examples/ppi_scaffolds_subset.tar.gz -C examples/ tar -xvf examples/antibody_pdbs.tar.gz -C examples/ tar -xvf examples/input_pdbs.tar.gz -C examples/ tar -xvf examples/target_folds.tar.gz -C examples/ tar -xvf examples/tim_barrel_scaffold.tar.gz -C examples/ ``` -------------------------------- ### Modular Installation Source: https://github.com/mindspore-ai/mindscience/blob/master/docs/architecture/mindscience-core.md Configuration for setup.py to support on-demand installation of extras like 'mindflow', 'mindsponge', or 'all'. ```python # 支持按需安装 extras_require={ "mindflow": ["matplotlib", "h5py"], "mindsponge": ["biopython"], "all": ["matplotlib", "h5py", "biopython"] } ``` -------------------------------- ### Install Dependencies Source: https://github.com/mindspore-ai/mindscience/blob/master/MindChem/applications/orb/orb.ipynb Installs the required packages listed in the requirement.txt file. ```python !pip install -r requirement.txt ``` -------------------------------- ### Install Dependencies Source: https://github.com/mindspore-ai/mindscience/blob/master/MindEnergy/applications/PowerFlowNet/README_MINDSPORE_MIGRATION.md Commands to install MindSpore (CPU/GPU/Ascend) and other necessary Python packages. ```bash # MindSpore (CPU/GPU) pip install mindspore # MindSpore Ascend (in Huawei Cloud environment) # Follow official documentation: https://www.mindspore.cn/install # Other dependencies pip install numpy torch-geometric h5py matplotlib ``` -------------------------------- ### Training Log Example Source: https://github.com/mindspore-ai/mindscience/blob/master/MindChem/applications/nequip/README_CN.md Example log output during the training process. ```log 2024-03-25 21:49:49 (INFO): ---- Configuration Summary ----- . . . 2024-03-25 21:49:49 (INFO): -------------------------------- 2024-03-25 21:49:49 (INFO): Loading data... 2024-03-25 21:50:13 (INFO): Initializing model... 2024-03-25 21:50:37 (INFO): Initializing train... 2024-03-25 22:01:58 (INFO): epoch 1: train loss: 1000.02729235, time gap: 680.55, total time used: 680.55 . . . ``` -------------------------------- ### Auxiliary Potential Function Example Source: https://github.com/mindspore-ai/mindscience/blob/master/MindSPONGE/applications/rf_diffusion/README.md Example command for setting guiding potentials, intra/inter weights, guide scale, and decay. ```bash potentials.guiding_potentials=["type:olig_contacts,weight_intra:1,weight_inter:0.1"] potentials.olig_intra_all=True potentials.olig_inter_all=True potentials.guide_scale=2 potentials.guide_decay='quadratic' ``` -------------------------------- ### Create Trainer and Training Configuration Source: https://github.com/mindspore-ai/mindscience/blob/master/MindEnergy/applications/DeepONet-Grid-UQ/DeepONet_Grid_UQ_Probabilistic.ipynb Initializes the trainer and sets up the training configuration. ```python # =================================== # Create trainer and training configuration # =================================== print("\n" + "=" * 50) print("Creating trainer and training configuration") print("=" * 50) ``` -------------------------------- ### Complex Design with Hotspot Residues Source: https://github.com/mindspore-ai/mindscience/blob/master/MindSPONGE/applications/rf_diffusion/README.md Example of specifying hotspot residues for guiding complex design. ```bash 'ppi.hotspot_res=[A30,A33,A34]' ``` -------------------------------- ### PSSM-Guided Design Example Source: https://github.com/mindspore-ai/mindscience/blob/master/MindSPONGE/applications/proteinmpnn/README.md Bash script to mix ProteinMPNN logits with PSSM probabilities for guided design. ```bash bash examples/submit_example_pssm.sh ``` -------------------------------- ### Command-line Argument Parsing for Case Selection Source: https://github.com/mindspore-ai/mindscience/blob/master/CONTRIBUTION.md Example of how to specify the case to run using command-line arguments. ```python import os import time import argparse import numpy as np from mindspore import context, nn, Tensor, set_seed, ops, data_sink, jit, save_checkpoint from mindspore import dtype as mstype from mindflow import FNO1D, load_yaml_config, get_warmup_cosine_annealing_lr from mindflow.pde import FlowWithLoss from src import create_training_dataset, visual, calculate_l2_error # Relevant dependency imports, in the order of Python official libraries, third-party libraries, mindflow, src set_seed(123456) np.random.seed(123456) ``` -------------------------------- ### Directory Structure for a Single Case Source: https://github.com/mindspore-ai/mindscience/blob/master/CONTRIBUTION.md Example directory structure for a single case, such as PINNs solving Burgers equation. ```shell . ├── images │ ├── background.png │ └── result.png ├── src │ ├── __init__.py │ ├── dataset.py │ ├── model.py │ └── utils.py ├── configs │ ├── fno1d.yaml ├── README.md ├── README_CN.md ├── problem.ipynb ├── problem_CN.ipynb ├── burgers_cfg.yaml ├── eval.py └── train.py ``` -------------------------------- ### Loss Function and Optimizer setup Source: https://github.com/mindspore-ai/mindscience/blob/master/MindEnergy/applications/DAE-PINN/DAE-PINN_EN.ipynb Initializes the DaeTrainer, loads IRK weights and times, sets up the Adam optimizer, and configures a learning rate scheduler. ```Python num_irk_stages = model_params['num_irk_stages'] # collecting RK data data_dir = data_params['data_dir'] irk_data = np.loadtxt(os.path.join(data_dir, 'IRK_weights', f'Butcher_IRK{num_irk_stages}.txt'), ndmin=2, dtype=np.float32) irk_weights = np.reshape(irk_data[0:num_irk_stages**2+num_irk_stages], (num_irk_stages+1, num_irk_stages)) irk_weights = Tensor(irk_weights) irk_times = irk_data[num_irk_stages**2 + num_irk_stages:] trainer = DaeTrainer(net, irk_weights=irk_weights, irk_times=irk_times, h=ode_params['h'], dyn_weight=model_params['dyn_weight'], alg_weight=model_params['alg_weight']) optimizer = optim.Adam(net.trainable_params(), lr=float(optim_params['lr'])) scheduler_type = optim_params['scheduler_type'] use_scheduler = optim_params['use_scheduler'] if use_scheduler: if scheduler_type == "plateau": scheduler = optim.lr_scheduler.ReduceLROnPlateau( optimizer, mode='min', patience=optim_params['patience'], factor=optim_params['factor'], ) elif scheduler_type == "step": scheduler = optim.lr_scheduler.StepLR( optimizer, step_size=optim_params['patience'], gamma=optim_params['factor'] ) else: scheduler = None else: scheduler = None ``` -------------------------------- ### Directory Structure for Multiple Cases Source: https://github.com/mindspore-ai/mindscience/blob/master/CONTRIBUTION.md Example directory structure for multiple cases that share the same model and method but use different datasets. ```shell . ├──images │ ├──background.png │ ├──result1.png │ ├──result2.png │ └──result3.png ├──src │ ├──__init__.py │ ├──dataset.py │ ├──model.py │ └──utils.py ├──configs │ ├──fno1d.yaml ├──README.md ├──README_CN.md ├──problem.ipynb ├──problem_CN.ipynb ├──problem_cfg.yaml ├──eval.py └──train.py ``` -------------------------------- ### API Reference - Device Initialization Source: https://github.com/mindspore-ai/mindscience/blob/master/MindEnergy/applications/PowerFlowNet/README_MINDSPORE_MIGRATION.md Code snippets for initializing the device (CPU, GPU, Ascend) and getting device configuration. ```python from powerflownet.configs import init_device, DeviceConfig # Initialize device init_device('Ascend') # 'CPU', 'GPU', 'Ascend' # Get device configuration config = DeviceConfig() device = config.get_device_target() ``` -------------------------------- ### Import and Usage Example Source: https://github.com/mindspore-ai/mindscience/blob/master/MindEnergy/applications/PowerFlowNet/README_MINDSPORE_MIGRATION.md Python code demonstrating how to import models, load data, and set up a training loop using MindSpore. ```python from powerflownet.src import MLPNet, MPN, GCNNet from powerflownet.src import PowerFlowDataV2, PowerFlowDataLoaderV2 from powerflownet.configs import init_device # Initialize device init_device('Ascend') # or 'CPU', 'GPU' # Create model model = MPN( nfeature_dim=4, efeature_dim=2, output_dim=4, hidden_dim=64, n_gnn_layers=3, k=3 ) # Load data dataset = PowerFlowDataV2(root='./data', case='14v2', split=[0.7, 0.15, 0.15], task='train') dataloader = PowerFlowDataLoaderV2(dataset, batch_size=256, shuffle=True) # Train import mindspore as ms from mindspore import nn optimizer = nn.Adam(model.trainable_params(), learning_rate=0.001) loss_fn = MaskedL2Loss(regularize=False) def forward_fn(batch): pred = model(batch) loss = loss_fn(pred, batch.y, batch.pred_mask) return loss grad_fn = ms.value_and_grad(forward_fn, None, model.trainable_params()) for batch in dataloader: loss, grads = grad_fn(batch) optimizer(grads) ``` -------------------------------- ### Symmetric Motif Scaffolding Example Script Source: https://github.com/mindspore-ai/mindscience/blob/master/MindSPONGE/applications/rf_diffusion/README_en.md This script can be used to scaffold C4 symmetric Nickel binding domains, combining symmetric oligomer generation, motif scaffolding, and guiding potentials. ```bash examples/design_nickel.sh ``` -------------------------------- ### Train with Real Data Source: https://github.com/mindspore-ai/mindscience/blob/master/MindEnergy/applications/DeepONet-Grid-UQ/README.md Command to start training using the provided dataset. ```bash python train.py ``` -------------------------------- ### FAQ - Running on Ascend Source: https://github.com/mindspore-ai/mindscience/blob/master/MindEnergy/applications/PowerFlowNet/README_MINDSPORE_MIGRATION.md Code snippet to address the issue of the first epoch taking a long time on Ascend devices. ```python if 'RANK_TABLE_FILE' in os.environ: del os.environ['RANK_TABLE_FILE'] import mindspore as ms ms.set_context(mode=ms.PYNATIVE_MODE) ``` -------------------------------- ### Load configuration and initialize trainer Source: https://github.com/mindspore-ai/mindscience/blob/master/MindEarth/applications/sea/LeadFormer/LeadFormer.ipynb Loads the YAML configuration file and initializes the Trainer object. ```python from mindearth.utils import load_yaml_config from src.solver import Trainer from src.forecast import Tester ``` -------------------------------- ### Install Dependencies Source: https://github.com/mindspore-ai/mindscience/blob/master/MindChem/applications/crystalflow/README.md Installs the required Python packages for the project. ```bash pip install -r requirement.txt ``` -------------------------------- ### Training Configuration and Trainer Creation Source: https://github.com/mindspore-ai/mindscience/blob/master/MindEnergy/applications/DeepONet-Grid-UQ/DeepONet_Grid_UQ_Probabilistic.ipynb Defines the configuration dictionary for training the model and then creates the trainer instance. ```python config = { 'model': { 'm': m, 'dim': dim, 'width': width, 'depth': depth, 'n_basis': n_basis, 'branch_type': branch_type, 'trunk_type': trunk_type, 'activation': activation, 'use_bias': True }, 'training': { 'batch_size': batch_size, 'epochs': n_epochs, 'log_interval': 100, 'eval_interval': 1000, 'scheduler': scheduler, 'min_lr': min_lr, 'max_lr': max_lr, 'total_step': total_step, 'step_per_epoch': step_per_epoch, 'decay_epoch': decay_epoch, 'verbose': verbose, 'loss_type': 'nll', 'optimizer': 'adam', 'weight_decay': 0.0 }, 'output': { 'save_dir': 'outputs', 'save_best': True } } # Create trainer trainer = create_trainer(model, config, save_dir='outputs', distributed=0) print("Trainer created successfully") ``` -------------------------------- ### Evaluation Result Example Source: https://github.com/mindspore-ai/mindscience/blob/master/MindChem/applications/crystalflow/README.md Example of the JSON output for evaluation metrics. ```json {"match_rate": 0.6107671899181959, "rms_dist": 0.07492558322002925} ``` -------------------------------- ### Quick Start - Training Source: https://github.com/mindspore-ai/mindscience/blob/master/MindChem/applications/orb/README.md Commands for initiating single-card and multi-card training of the Orb model. ```bash bash run.sh ``` ```bash bash run_parallel.sh ``` -------------------------------- ### Example Evaluation Output Source: https://github.com/mindspore-ai/mindscience/blob/master/MindChem/applications/crystalflow/README_EN.md Example JSON output from the evaluation process. ```json {"match_rate": 0.6107671899181959, "rms_dist": 0.07492558322002925} ``` -------------------------------- ### Evaluation Result Example Source: https://github.com/mindspore-ai/mindscience/blob/master/MindChem/applications/diffcsp/README.md Example JSON output for evaluation results. ```json {"match_rate": 0.985997357992074, "rms_dist": 0.013073775170360118} ``` -------------------------------- ### Start Monitoring Service Source: https://github.com/mindspore-ai/mindscience/blob/master/MindEnergy/applications/deploy/README.md Command to start the monitoring service. ```bash python monitor.py ``` -------------------------------- ### Project Root Setup Source: https://github.com/mindspore-ai/mindscience/blob/master/MindFlow/applications/data_driven/burgers/fno1d/FNO1D.ipynb Appends the project root directory to sys.path for module imports. ```python import sys import os project_root = os.path.abspath("../../../../..") sys.path.append(project_root) ``` -------------------------------- ### Start Deployment Service Source: https://github.com/mindspore-ai/mindscience/blob/master/MindEnergy/applications/deploy/README.md Command to start the deployment service. ```bash python deploy.py ``` -------------------------------- ### Progress Output Example Source: https://github.com/mindspore-ai/mindscience/blob/master/MindEarth/applications/sea/LeadFormer/LeadFormer.ipynb Example of progress output during model execution, showing iteration progress and potential runtime warnings. ```text 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1301/1301 [11:51<00:00, 1.83it/s] /tmp/ipykernel_1012809/934503037.py:629: RuntimeWarning: All-NaN slice encountered disnrst = np.nanmin(dismin, axis=0) ``` -------------------------------- ### Load Model Source: https://github.com/mindspore-ai/mindscience/blob/master/MindEnergy/applications/deploy/EXAMPLE.md Use curl to load a model. ```bash curl -X POST "http://localhost:8001/mindscience/deploy/load_model" \ -H "Content-Type: multipart/form-data" \ -F "model_name=your_model" \ -F "model_file=@/path/to/your/model_file.zip" ``` -------------------------------- ### Install HMMER Source: https://github.com/mindspore-ai/mindscience/blob/master/MindSPONGE/applications/AlphaFold3/README.md Download, compile, and install HMMER, then add its bin directory to the PATH. ```bash mkdir /path/to/hmmer_build /path/to/hmmer && \ mv ./hmmer-3.4.tar.gz /path/to/hmmer_build && \ cd /path/to/hmmer_build && tar -zxf hmmer-3.4.tar.gz && rm hmmer-3.4.tar.gz && \ cd /path/to/hmmer_build/hmmer-3.4 && ./configure --prefix=/path/to/hmmer && \ make -j8 && make install && \ cd /path/to/hmmer_build/hmmer-3.4/easel && make install && \ rm -rf /path/to/hmmer_build export PATH=/hmmer/bin:$PATH which jackhmmer ``` -------------------------------- ### Install Dependencies Source: https://github.com/mindspore-ai/mindscience/blob/master/MindSPONGE/applications/AlphaFold3/README.md Install the required Python packages and set the PYTHONPATH environment variable. ```bash pip install -r requirements.txt #`{PATH}` is the current directory export PYTHONPATH={PATH}/mindscience ``` -------------------------------- ### Model File Structure Source: https://github.com/mindspore-ai/mindscience/blob/master/MindEnergy/applications/deploy/EXAMPLE.md The directory format for model_file.zip. ```bash model_file.zip ├── your_model_1.mindir ├── your_model_2.mindir ├── ... └── your_model_n.mindir ``` -------------------------------- ### Install MindScience Source: https://github.com/mindspore-ai/mindscience/blob/master/MindEnergy/applications/DAE-PINN/DAE-PINN.ipynb Code snippet to install the MindScience library, with options for Ascend backend. ```python mindscience_version = "0.1.0" # update if needed # Comment out the following code if you are using NPU. !pip uninstall -y mindscience-ascend !pip install mindscience-ascend==$mindscience_version # NPU Uncomment if needed. # !pip uninstall -y mindscience-ascend # !pip install mindscience-ascend==$mindscience_version ``` -------------------------------- ### Download Results Source: https://github.com/mindspore-ai/mindscience/blob/master/MindEnergy/applications/deploy/EXAMPLE.md Download the results of a completed inference task. Replace {task_id} with the actual task ID. ```bash curl -X GET "http://localhost:8001/mindscience/deploy/query_results/{task_id}" -o "results.h5" ``` ```bash curl -X GET "http://localhost:8001/mindscience/deploy/query_results/123e4567-e89b-12d3-a456-426614174000" -o "results.h5" ``` -------------------------------- ### RFantibody Fv Design Example Source: https://github.com/mindspore-ai/mindscience/blob/master/MindSPONGE/applications/rf_diffusion/README.md Example configuration for designing an antibody Fv fragment. ```bash python run_inference.py \ --config-name antibody \ antibody.target_pdb=./examples/antibody_pdbs/rsv_site3.pdb \ antibody.framework_pdb=./examples/antibody_pdbs/hu-4D5-8_Fv.pdb \ inference.ckpt_override_path=./models/RFdiffusion_Ab.ckpt \ 'ppi.hotspot_res=[T305,T456]' \ 'antibody.design_loops=[L1:8-13,L2:7,L3:9-11,H1:7,H2:6,H3:5-13]' \ inference.num_designs=2 \ diffuser.T=50 \ inference.deterministic=True \ inference.output_prefix=example_outputs/ab_des ``` -------------------------------- ### Dataset Directory Structure Source: https://github.com/mindspore-ai/mindscience/blob/master/MindChem/applications/diffcsp/README.md Example structure for the dataset folder. ```txt diffcsp ... └─dataset perov_5 钙钛矿数据集 carbon_24 碳晶体数据集 mp_20 晶胞内原子数最多为20的MP数据集 mpts_52 晶胞内原子数最多为52的MP数据集 dataset_prop.txt 数据集属性文件 ... ``` -------------------------------- ### Multi-card Training Source: https://github.com/mindspore-ai/mindscience/blob/master/MindEnergy/applications/DeepONet-Grid-UQ/README.md Command for multi-card training. ```bash msrun --worker_num 8 --local_worker_num 8 --log_dir msrun_log python train.py --distributed 1 ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/mindspore-ai/mindscience/blob/master/MindEnergy/applications/deploy/README.md Command to install Python dependencies from the requirements.txt file. ```bash pip install -r requirements.txt ```