pymatgen icon indicating copy to clipboard operation
pymatgen copied to clipboard

Improve types for `electronic_structure.{bandstructure/cohp}`

Open DanielYang59 opened this issue 1 year ago • 8 comments

Summary

  • Improve type annotations and docstring for electronic_structure
    • [x] bandstructure
    • [x] cohp
  • Replace unnecessary single-item list extend with append in 8e252388e718415140142a69605896342a5e16c3 for performance

[!CAUTION] Change the cell translation vector translation from list[float] to tuple[float, float, float] (Vector3D) in 9551db207ce444119b35b5881e71e26c38527d74 and 5fcf23619fa804e31b0f7e2d521821a2552c6474

New custom type

  • Add a custom type SpinLike: https://github.com/materialsproject/pymatgen/blob/c83d5d5280cf0004f7d3571b7afc41b7604d8124/pymatgen/electronic_structure/cohp.py#L120-L121

Follow up PR for other modules

  • core (too many changes already)

Script for testing lobsterpy

Bash script
#!/bin/bash -l

CONDA_PROFILE="/opt/anaconda3/etc/profile.d/conda.sh"
ENV_NAME="test_lobster"
PYTHON_VERSION="3.11"
PMG_REPO="https://github.com/DanielYang59/pymatgen.git"
PMG_BRANCH="type-elec-struct"
LOBSTERPY_REPO="https://github.com/JaGeo/LobsterPy.git"

# Functions
function create_and_activate_env() {
  conda create -y -n $ENV_NAME python=$PYTHON_VERSION
  conda activate $ENV_NAME
}

function clone_and_install_pymatgen() {
  git clone --depth 1 -b $PMG_BRANCH $PMG_REPO
  cd pymatgen
  pip install .
  cd ..
}

function clone_and_install_lobsterpy() {
  git clone --depth 1 $LOBSTERPY_REPO
  cd LobsterPy
  pip install -e '.[featurizer,dev,tests]'
  pip install pytest-xdist
  cd ..
}

function run_pytest() {
  cd LobsterPy
  pytest tests --maxfail=1000
  cd ..
}

function remove_env() {
  conda deactivate
  conda env remove -n $ENV_NAME -y
}

# Main Script
source $CONDA_PROFILE
create_and_activate_env
clone_and_install_pymatgen
clone_and_install_lobsterpy
run_pytest
remove_env

DanielYang59 avatar Jun 10 '24 03:06 DanielYang59