A Language Server Protocol (LSP) implementation for Quantum ESPRESSO input files.
- Syntax Highlighting: Full support for namelists and cards
- Auto-completion:
- Namelist names (e.g.,
&control,&system) - Parameters within namelists
- Valid values for parameters
- Card names (e.g.,
ATOMIC_SPECIES,K_POINTS)
- Namelist names (e.g.,
- Hover Documentation:
- Parameter descriptions with types and defaults
- Possible values for enumerated parameters
- Card format documentation with examples
- Diagnostics:
- Syntax error detection
- Unknown namelist/card warnings
- Missing required parameter detection
- Unknown parameter warnings
- Document Symbols: File structure outline with namelists, parameters, and cards
pip install qe-lspgit clone https://github.com/newtontech/qe-lsp.git
cd qe-lsp
pip install -e ".[dev]"qe-lspThe server communicates via stdin/stdout using the LSP protocol.
- Install the QE-LSP extension (coming soon)
- Open any
.infile - The language server will automatically start
require'lspconfig'.qe_lsp.setup{
cmd = {'qe-lsp'},
filetypes = {'qe', 'pwscf'},
}(use-package lsp-mode
:hook (qe-mode . lsp)
:commands lsp
:config
(add-to-list 'lsp-language-id-configuration '(qe-mode . "qe"))
(lsp-register-client
(make-lsp-client :new-connection (lsp-stdio-connection "qe-lsp")
:major-modes '(qe-mode)
:server-id 'qe-lsp)))This LSP server supports input file syntax for Quantum ESPRESSO v7.x and earlier versions.
&control- General control parameters&system- System description&electrons- Electronic structure parameters&ions- Ionic relaxation/MD parameters&cell- Variable-cell relaxation parameters
ATOMIC_SPECIES- Atomic species and pseudopotentialsATOMIC_POSITIONS- Atomic positions in the unit cellK_POINTS- K-point grid for Brillouin zone samplingCELL_PARAMETERS- Unit cell vectorsOCCUPATIONS- Occupation numbersCONSTRAINTS- Constraints for ionic coordinatesATOMIC_FORCES- External forces on atomsATOMIC_VELOCITIES- Initial velocities for MD- And more...
See the examples/ directory for sample input files:
scf.in- Self-consistent field calculationrelax.in- Ionic relaxationvc-relax.in- Variable-cell relaxation
git clone https://github.com/newtontech/qe-lsp.git
cd qe-lsp
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -e ".[dev]"# Run all tests with coverage
pytest
# Run tests with verbose output
pytest -v
# Run specific test file
pytest tests/test_parser.py
# Run with coverage report
pytest --cov=src/qe_lsp --cov-report=term-missing# Format code
black src tests
isort src tests
# Type checking
mypy src
# Linting
flake8 src tests
# Security checks
bandit -r src
# Run all pre-commit hooks
pre-commit run --all-filesqe-lsp/
├── src/qe_lsp/
│ ├── __init__.py # Package exports
│ ├── parser.py # QE input file parser
│ ├── data.py # Parameter documentation
│ └── server.py # LSP server implementation
├── tests/
│ ├── conftest.py # Test fixtures
│ ├── test_parser.py # Parser tests
│ ├── test_data.py # Data module tests
│ └── test_server.py # LSP server tests
├── examples/ # Example input files
├── docs/ # Additional documentation
├── pyproject.toml # Project configuration
└── README.md # This file
To add documentation for new parameters:
- Edit
src/qe_lsp/data.py - Add the parameter to the appropriate namelist dictionary
- Follow the existing format:
"new_param": {
"description": "Description of the parameter",
"type": "string", # or "integer", "real", "logical"
"default": "default_value", # optional
"values": ["'option1'", "'option2'"], # for enumerated types
"required": False,
}Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for new functionality
- Ensure all tests pass (
pytest) - Run code quality checks (
pre-commit run --all-files) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Basic parser for namelists and cards
- Hover documentation
- Auto-completion
- Diagnostics
- Document symbols
- Go to definition (pseudopotential files)
- Code actions (quick fixes)
- Formatting support
- Additional QE packages (PHonon, EPW, etc.)
- Multi-root workspace support
MIT License - see LICENSE file for details.
- Quantum ESPRESSO - The amazing DFT package
- pygls - Python LSP framework
- lsprotocol - LSP types
Made with ❤️ for the computational chemistry community.