Skip to content

marquetand/CasNet

 
 

Repository files navigation

CasNet

A repository used to perform experiments for the work on CasNet.

1. Installation & Setup

This project uses a conda environment and uv for fast package management.

  1. Install Miniconda: If you don't have it, download and install Miniconda from the official website.

  2. Clone the repository:

    git clone https://github.com/marquetand/casnet.git
    cd casnet
    git submodule init
    git submodule update
  3. Create conda environment: Create and activate the casnet environment. This command also installs uv, cmake, and openblas from the conda-forge channel.

    conda create -n casnet python=3.13 -c conda-forge uv cmake openblas
    conda activate casnet
  4. Install dependencies: Use uv to install the required packages.

    uv pip install -r requirements.txt
  5. Install custom PySCF fork: This project requires a specific fork of PySCF which is included as a submodule.

    cd pyscf
    uv pip install -e .
    cd ..
  6. Set Environment Variables:

    source env.sh # (after setting variables in env.sh file)

(Watch out: We're our own fork a of PySCF that returns macro, micro & inner iterations of the CASSCF object)

Weights & Biases (wandb) Setup

Create an account at wandb.ai. To enable logging on Ubuntu, run wandb login in your terminal and paste your API key when prompted. This automatically saves your credentials to ~/.netrc.

The training script defaults to the project name casnet. You can specify a different project using the --wandb_project argument: python train_model.py ... --wandb_project <project_name>



2. Performing CASSCF calculations in PySCF

2.0 Generate geometries (if needed)

First, generate the start and end geometries:
python data/geometries/create_fulvene_endpoints.py Then, generate the interpolated scan:
python data/geometries/generate_geom_scan.py --start_geom geometries/fulvene_equilibrium.xyz --end_geom geometries/fulvene_distorted.xyz --output_folder geometries/geom_scan_200/ --n_steps 200

2.1 Run calculations

python data/casscf/pyscf/run_casscf_calculations.py --geometry_folder geometries/geom_scan_200/ --output_folder pyscf/geom_scan_200_sto_6g/ --basis sto_6g

2.2 Analyze results

python data/check_casscf_calculations.py --output_folder pyscf/geom_scan_200_sto_6g/

2.3 Save results in ASE DB

python data/db/save_casscf_calculations_to_db.py --geometry_folder geometries/geom_scan_200/ --output_folder pyscf/geom_scan_200_sto_6g/

2.4 Generate split

check data/splits/ to see example of split generating scripts, e.g.
python data/splits/generate_geom_scan_split.py --name geom_scan_200 --n_samples 200
There are also other scripts in the folder.

2.5 Convert DB for PhiSNet

python data/db/convert_to_phisnet_db.py --ase_db data_storage/geom_scan_200_sto_6g.db --phisnet_db data_storage/geom_scan_200_sto_6g_phisnet.db



3. Training models

3.1 Train ML-MO model

python train_model.py --db_name geom_scan_200_sto_6g.db --split_name geom_scan_200.npz --property mo_coeffs_adjusted --model_name gs200_sto_6g_MO

3.2 Train ML-F model

python train_model.py --db_name geom_scan_200_sto_6g.db --split_name geom_scan_200.npz --property F --model_name gs200_sto_6g_F

3.3 Train PhiSNet model

Add a configuration in phisnet_fork/configurations/ folder (e.g. named 'test_conf.txt') and then type:
python phisnet_fork/train.py @phisnet_fork/configurations/test_conf.txt



4. Evaluating models

4.1 Evaluate model loss on train/val/test set

python evaluation/compute_model_loss.py --db_name geom_scan_200_sto_6g.db --split_name geom_scan_200.npz --mo_model gs200_sto_6g_MO --F_model gs200_sto_6g_F --phisnet_model gs200_sto_6g_phisnet

4.2 Evaluate orbitals on validation/test set
4.2.1 For ML-MO model

python evaluation/pyscf/compute_SCF_iterations.py --geometry_folder geometries/geom_scan_200/ --split_name geom_scan_200.npz --mode ML-MO --model gs200_sto_6g_MO --basis sto_6g
python evaluation/compute_CASCI_energy_errors.py --geometry_folder geometries/geom_scan_200/ --split_name geom_scan_200.npz --mode ML-MO --model gs200_sto_6g_MO --basis sto_6g

4.2.2 For ML-F model

python evaluation/pyscf/compute_SCF_iterations.py --geometry_folder geometries/geom_scan_200/ --split_name geom_scan_200.npz --mode ML-F --model gs200_sto_6g_F --basis sto_6g
python evaluation/compute_CASCI_energy_errors.py --geometry_folder geometries/geom_scan_200/ --split_name geom_scan_200.npz --mode ML-F --model gs200_sto_6g_F --basis sto_6g

4.2.3 For PhiSNet model

python evaluation/pyscf/compute_SCF_iterations.py --geometry_folder geometries/geom_scan_200/ --split_name geom_scan_200.npz --mode PhiSNet --model gs200_sto_6g_phisnet --basis sto_6g
python evaluation/compute_CASCI_energy_errors.py --geometry_folder geometries/geom_scan_200/ --split_name geom_scan_200.npz --mode PhiSNet --model gs200_sto_6g_phisnet --basis sto_6g

python evaluation/compute_CASCI_energy_errors.py --geometry_folder geometries/geom_scan_200/ --split_name geom_scan_200.npz --mode ML-MO --model gs200_sto_6g_F --basis sto_6g

4.3 Look at predicted orbitals for a particular geometry

python evaluation/paper_figures/plot_orbitals.py
(check this file for setting geometry & orbital model & MO indices)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 96.0%
  • Shell 4.0%