Skip to content

[WIP] Adding Support for Command Line Interface#6

Open
Shibu778 wants to merge 8 commits into
mturiansky:masterfrom
Shibu778:master
Open

[WIP] Adding Support for Command Line Interface#6
Shibu778 wants to merge 8 commits into
mturiansky:masterfrom
Shibu778:master

Conversation

@Shibu778

@Shibu778 Shibu778 commented Oct 3, 2024

Copy link
Copy Markdown

Dear Maintainer,
This pull request introduces a Command Line Interface (CLI) for the nonrad repository, enhancing the usability and accessibility of the tool. The CLI is built using the click library, providing a structured and user-friendly way to interact with the functionalities of nonrad.

Key Features

CLI Group: Added a CLI group nonrad to serve as the entry point for various commands.

Commands

nonrad is the main command.

Subcommands

prep_ccd: Implemented the prep_ccd command which accepts three arguments:

  1. ground_path: Path to the ground state structure file.
  2. excited_path: Path to the excited state structure file.
  3. cc_dir: Directory to store the displaced structures.

pes: Extracts the Potential Energy Surface (PES) related data and plots it. It accepts following arguements:

  1. cc_dir : Path to the directory containing the CCD calculations.
  2. ground_files: Path to the directory containing the ground state calculation files.
  3. excited_files: Path to the directory containing the excited state calculation files.
  4. plot: If True, the potential energy surfaces are plotted. Default is False.
  5. plot_name: Name of the plot file. Default is pes.png.

Changes Made

  1. Created a new cli.py file to define the CLI commands.
  2. Updated pyproject.toml to include the CLI entry point.
  3. Imported necessary modules and defined the nonrad CLI group and pccd command.

Usage

nonrad prep_ccd <ground_path> <excited_path> <cc_dir> -d -0.5 0.5 9

nonrad pes -p -n pes.pdf CC_DIR GROUND_FILES EXCITED_FILES

TODO

  • Add other features
  • Make the CLI more flexible

I will be adding the above as soon as possible.

Please give your suggestion for improvement.

@Shibu778 Shibu778 changed the title Adding Support for Command Line Interface [WIP] Adding Support for Command Line Interface Oct 5, 2024
@mturiansky

Copy link
Copy Markdown
Owner

Hi @Shibu778, thanks for working on this. I see that this is a work in progress, so let me know when you are ready for me to look it over.

Please make sure there are unit tests for all the functionality that you're adding and that the docstrings adhere to numpy-style formatting.

@Shibu778

Copy link
Copy Markdown
Author

Dear @mturiansky,

This pull request introduces a comprehensive Command Line Interface (CLI) for the nonrad repository, exposing the package's full functionalities directly to the terminal. The CLI is built using the click library, using lazy imports to ensure fast startup times.

Following your feedback, I have completed the implementation of all CLI utilities, formatted all docstrings to adhere strictly to numpy-style guidelines, and added a comprehensive suite of unit tests.

Key Features & Subcommands

  • Main Group (nonrad): The entry point for the CLI with version tracking (--version).
  • CCD Commands:
    • prep-ccd: Prepares displaced structures along the configuration coordinate (with custom displacements and copying of input files).
    • pes: Extracts potential energy surfaces from CCD calculations (with energy-offset and plotting support).
    • dq: Computes the configuration-coordinate displacement $dQ$ between two structures.
    • q-from-struct: Calculates the $Q$ coordinate of an arbitrary structure.
    • barrier: Computes the classical barrier height under the harmonic approximation.
  • Recombination Rate:
    • capture: Evaluates the nonradiative capture coefficient $C$ (in $\text{cm}^3,\text{s}^{-1}$) for a single temperature or temperature range.
  • Scaling Helpers:
    • sommerfeld: Computes the Sommerfeld enhancement factor.
    • thermal-velocity: Computes the thermal velocity of a carrier.
    • charged-supercell: Estimates the charged-supercell scaling factor.
  • Electron-Phonon Coupling (elphon):
    • elphon wavecars: Computes $W_{if}$ from VASP WAVECAR files along the CCD path.
    • elphon wswq: Computes $W_{if}$ from VASP WSWQ files.
    • elphon unk: Computes $W_{if}$ from UNK files.

Changes Made

  1. CLI Core Module (nonrad/cli.py): Created the main CLI file, structuring commands as subcommands of nonrad using lazy imports to keep python import overhead minimal. All functions include standard numpy-style docstrings.
  2. Unit Tests (nonrad/tests/test_cli.py): Added 42 tests using click.testing.CliRunner and unittest.mock to test happy paths, option flags, input parameter boundaries, and error conditions for every single subcommand.
  3. Documentation (docs/cli.rst): Added a dedicated documentation page describing the syntax, arguments, options, and usage examples for each command, integrated into the main table of contents (docs/index.rst).
  4. CLI Entry Point: Configured nonrad console script entry point in pyproject.toml.

Verification and Testing

  • Unit Tests: All 80 package tests (including the 42 new CLI tests) pass successfully:
    python -m unittest discover -s nonrad/tests
    (Output: Ran 80 tests. OK (skipped=2))
  • Documentation Build: Verified that Sphinx builds the documentation including the new CLI section without any warning or syntax errors.

Usage Examples

Preparing CCD folders:

nonrad prep-ccd ground_dir/ excited_dir/ ccd_output/ -d -0.5 0.5 9 -f INCAR,POTCAR

Evaluating capture coefficient over a temperature range:

nonrad capture --dq 1.6858 --de 1.0 --wi 0.03 --wf 0.03 --wif 0.094 --volume 1000.0 --temperature-range 100 500 5

The pull request is now fully complete and ready for your review. Please let me know if you have any suggestions or further feedback!

@mturiansky

Copy link
Copy Markdown
Owner

Thanks for your continued work on this. I'll try to look over it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants