janpa-py 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- janpa_py-0.1.0/PKG-INFO +89 -0
- janpa_py-0.1.0/README.md +68 -0
- janpa_py-0.1.0/pyproject.toml +51 -0
- janpa_py-0.1.0/setup.cfg +4 -0
- janpa_py-0.1.0/src/janpa/__init__.py +3 -0
- janpa_py-0.1.0/src/janpa/cli/__init__.py +1 -0
- janpa_py-0.1.0/src/janpa/cli/main.py +204 -0
- janpa_py-0.1.0/src/janpa/cli/molden2molden.py +117 -0
- janpa_py-0.1.0/src/janpa/cli/nwchem2molden.py +209 -0
- janpa_py-0.1.0/src/janpa/clpo/__init__.py +5 -0
- janpa_py-0.1.0/src/janpa/clpo/charge_transfer.py +98 -0
- janpa_py-0.1.0/src/janpa/clpo/dipole.py +171 -0
- janpa_py-0.1.0/src/janpa/clpo/graph.py +80 -0
- janpa_py-0.1.0/src/janpa/clpo/hybridization.py +29 -0
- janpa_py-0.1.0/src/janpa/clpo/hybrids.py +85 -0
- janpa_py-0.1.0/src/janpa/clpo/lodesc.py +37 -0
- janpa_py-0.1.0/src/janpa/clpo/lpo.py +876 -0
- janpa_py-0.1.0/src/janpa/clpo/matching.py +67 -0
- janpa_py-0.1.0/src/janpa/convert/__init__.py +1 -0
- janpa_py-0.1.0/src/janpa/convert/cart2sph.py +116 -0
- janpa_py-0.1.0/src/janpa/convert/file47.py +365 -0
- janpa_py-0.1.0/src/janpa/gto/__init__.py +4 -0
- janpa_py-0.1.0/src/janpa/gto/angular.py +661 -0
- janpa_py-0.1.0/src/janpa/gto/basis.py +84 -0
- janpa_py-0.1.0/src/janpa/gto/integrals.py +496 -0
- janpa_py-0.1.0/src/janpa/gto/overlap.py +108 -0
- janpa_py-0.1.0/src/janpa/gto/polynom3d.py +782 -0
- janpa_py-0.1.0/src/janpa/gto/polynom_rho_z.py +189 -0
- janpa_py-0.1.0/src/janpa/gto/spherical.py +262 -0
- janpa_py-0.1.0/src/janpa/gto/wigner.py +1406 -0
- janpa_py-0.1.0/src/janpa/io/__init__.py +2 -0
- janpa_py-0.1.0/src/janpa/io/molden.py +470 -0
- janpa_py-0.1.0/src/janpa/janpa_interface.py +178 -0
- janpa_py-0.1.0/src/janpa/janpa_psi4_interface.py +164 -0
- janpa_py-0.1.0/src/janpa/npa/__init__.py +2 -0
- janpa_py-0.1.0/src/janpa/npa/npa.py +907 -0
- janpa_py-0.1.0/src/janpa/npa/options.py +94 -0
- janpa_py-0.1.0/src/janpa/utils/__init__.py +4 -0
- janpa_py-0.1.0/src/janpa/utils/constants.py +37 -0
- janpa_py-0.1.0/src/janpa/utils/matrix.py +85 -0
- janpa_py-0.1.0/src/janpa/utils/printout.py +99 -0
- janpa_py-0.1.0/src/janpa/utils/simult_diag.py +92 -0
- janpa_py-0.1.0/src/janpa_py.egg-info/PKG-INFO +89 -0
- janpa_py-0.1.0/src/janpa_py.egg-info/SOURCES.txt +52 -0
- janpa_py-0.1.0/src/janpa_py.egg-info/dependency_links.txt +1 -0
- janpa_py-0.1.0/src/janpa_py.egg-info/entry_points.txt +4 -0
- janpa_py-0.1.0/src/janpa_py.egg-info/requires.txt +13 -0
- janpa_py-0.1.0/src/janpa_py.egg-info/top_level.txt +1 -0
- janpa_py-0.1.0/tests/test_algorithms.py +43 -0
- janpa_py-0.1.0/tests/test_clpo.py +149 -0
- janpa_py-0.1.0/tests/test_molden_io.py +12 -0
- janpa_py-0.1.0/tests/test_npa.py +69 -0
- janpa_py-0.1.0/tests/test_polynom.py +33 -0
- janpa_py-0.1.0/tests/test_psi4_interface.py +118 -0
janpa_py-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: janpa-py
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python rewrite of JANPA: Natural Population Analysis and electronic structure tools
|
|
5
|
+
Author: JANPA contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/tequilahub/janpa-py
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
Requires-Dist: numpy>=1.24
|
|
11
|
+
Requires-Dist: scipy>=1.10
|
|
12
|
+
Requires-Dist: rustworkx>=0.13
|
|
13
|
+
Provides-Extra: dev
|
|
14
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
15
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
16
|
+
Requires-Dist: ruff; extra == "dev"
|
|
17
|
+
Requires-Dist: pyscf!=2.15.1,>=2.4; extra == "dev"
|
|
18
|
+
Requires-Dist: networkx>=3.0; extra == "dev"
|
|
19
|
+
Provides-Extra: pyscf
|
|
20
|
+
Requires-Dist: pyscf!=2.15.1,>=2.4; extra == "pyscf"
|
|
21
|
+
|
|
22
|
+
# janpa-py
|
|
23
|
+
|
|
24
|
+
A fast, pure-Python port of [JANPA](https://janpa.sourceforge.net/) for Natural Population Analysis (NPA) and localized orbitals (CLPO/AHO). This library provides native Python implementations of the 7-step NPA algorithm and Chemist's Localized Property-optimized Orbitals (CLPO) using `numpy` and `scipy`, completely eliminating the need for Java binaries or temporary disk I/O.
|
|
25
|
+
|
|
26
|
+
## Key Features
|
|
27
|
+
|
|
28
|
+
- **Pure Python:** Built entirely on standard scientific Python libraries.
|
|
29
|
+
- **In-Memory Execution:** No messy `.molden` or `graph` text files left on your hard drive.
|
|
30
|
+
- **Seamless PySCF Integration:** Designed to work directly with PySCF molecule objects and mean-field results.
|
|
31
|
+
- **Chemical Graph Extraction:** Automatically extracts bonding graphs (edges) from the CLPO density matrix for downstream quantum chemistry workflows.
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
Install it from PyPI (the import name is `janpa`):
|
|
36
|
+
|
|
37
|
+
pip install janpa-py
|
|
38
|
+
|
|
39
|
+
or from source:
|
|
40
|
+
|
|
41
|
+
git clone https://github.com/tequilahub/janpa-py.git
|
|
42
|
+
cd janpa-py
|
|
43
|
+
pip install .
|
|
44
|
+
|
|
45
|
+
## Quick Start with PySCF
|
|
46
|
+
|
|
47
|
+
Here is a minimal example demonstrating how to run NPA, generate CLPO orbitals, and extract the chemical bonding graph directly in memory using PySCF and the `janpa_interface` module:
|
|
48
|
+
|
|
49
|
+
import numpy as np
|
|
50
|
+
from pyscf import gto, scf
|
|
51
|
+
from janpa.janpa_interface import generate_CLPO_molecule_edges
|
|
52
|
+
|
|
53
|
+
# 1. Build molecule and run SCF
|
|
54
|
+
mol = gto.M(atom="H 0 0 0; H 0 0 1", basis="sto-3g", unit="Angstrom")
|
|
55
|
+
mf = scf.RHF(mol).run()
|
|
56
|
+
|
|
57
|
+
# 2. Generate CLPO orbitals and extract the bonding graph
|
|
58
|
+
# silent=True suppresses the verbose JANPA terminal output
|
|
59
|
+
clpo_coeff, edges = generate_CLPO_molecule_edges(mol, mf, silent=True)
|
|
60
|
+
|
|
61
|
+
print("CLPO Coefficient matrix shape:", clpo_coeff.shape)
|
|
62
|
+
print("Extracted CLPO Edges:", edges)
|
|
63
|
+
|
|
64
|
+
The `edges` list contains tuples representing the localized orbital pairs:
|
|
65
|
+
- `(i,)` represents a Lone Pair (LP) on a single center.
|
|
66
|
+
- `(i, i+1)` represents a Bonding (BD) and Antibonding (NB) pair between two centers.
|
|
67
|
+
|
|
68
|
+
## Quick Start with Psi4
|
|
69
|
+
|
|
70
|
+
The `janpa_psi4_interface` module offers the same functions for a Psi4 `Wavefunction` (Psi4 is installed with conda, e.g. `conda install -c conda-forge psi4`). The returned matrices have one row per orbital and one column per Psi4 AO. Basis sets with d or higher shells must be spherical (`puream true`):
|
|
71
|
+
|
|
72
|
+
import psi4
|
|
73
|
+
from janpa.janpa_psi4_interface import generate_CLPO_molecule_edges
|
|
74
|
+
|
|
75
|
+
psi4.set_options({"basis": "cc-pvdz", "puream": True})
|
|
76
|
+
mol = psi4.geometry("H 0 0 0\nH 0 0 1")
|
|
77
|
+
_, wfn = psi4.energy("scf", molecule=mol, return_wfn=True)
|
|
78
|
+
|
|
79
|
+
# wfn is optional: without it the SCF is run on mol with the current psi4 options
|
|
80
|
+
clpo_coeff, edges = generate_CLPO_molecule_edges(mol, wfn)
|
|
81
|
+
|
|
82
|
+
## References and Attribution
|
|
83
|
+
|
|
84
|
+
This Python port is based on the original JANPA software developed by Tymofii Nikolaienko, L. A. Bulavin, and D. M. Hovorun. All theoretical foundations and original algorithms belong to the respective authors. Please refer to the [original JANPA webpage](https://janpa.sourceforge.net/) for full references, copyright information, and the original Java binaries.
|
|
85
|
+
|
|
86
|
+
If you use this software or the underlying methods in your research, please cite the original articles:
|
|
87
|
+
|
|
88
|
+
1. T. Yu. Nikolaienko, L. A. Bulavin; *Localized orbitals for optimal decomposition of molecular properties*, Int. J. Quantum Chem. (2019), Vol.119, page e25798. [DOI: 10.1002/qua.25798](https://doi.org/10.1002/qua.25798)
|
|
89
|
+
2. T. Yu. Nikolaienko, L. A. Bulavin, D. M. Hovorun; *JANPA: an open source cross-platform implementation of the Natural Population Analysis on the Java platform*, Comput. Theor. Chem. (2014), V.1050, P.15-22. [DOI: 10.1016/j.comptc.2014.10.002](https://doi.org/10.1016/j.comptc.2014.10.002)
|
janpa_py-0.1.0/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# janpa-py
|
|
2
|
+
|
|
3
|
+
A fast, pure-Python port of [JANPA](https://janpa.sourceforge.net/) for Natural Population Analysis (NPA) and localized orbitals (CLPO/AHO). This library provides native Python implementations of the 7-step NPA algorithm and Chemist's Localized Property-optimized Orbitals (CLPO) using `numpy` and `scipy`, completely eliminating the need for Java binaries or temporary disk I/O.
|
|
4
|
+
|
|
5
|
+
## Key Features
|
|
6
|
+
|
|
7
|
+
- **Pure Python:** Built entirely on standard scientific Python libraries.
|
|
8
|
+
- **In-Memory Execution:** No messy `.molden` or `graph` text files left on your hard drive.
|
|
9
|
+
- **Seamless PySCF Integration:** Designed to work directly with PySCF molecule objects and mean-field results.
|
|
10
|
+
- **Chemical Graph Extraction:** Automatically extracts bonding graphs (edges) from the CLPO density matrix for downstream quantum chemistry workflows.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Install it from PyPI (the import name is `janpa`):
|
|
15
|
+
|
|
16
|
+
pip install janpa-py
|
|
17
|
+
|
|
18
|
+
or from source:
|
|
19
|
+
|
|
20
|
+
git clone https://github.com/tequilahub/janpa-py.git
|
|
21
|
+
cd janpa-py
|
|
22
|
+
pip install .
|
|
23
|
+
|
|
24
|
+
## Quick Start with PySCF
|
|
25
|
+
|
|
26
|
+
Here is a minimal example demonstrating how to run NPA, generate CLPO orbitals, and extract the chemical bonding graph directly in memory using PySCF and the `janpa_interface` module:
|
|
27
|
+
|
|
28
|
+
import numpy as np
|
|
29
|
+
from pyscf import gto, scf
|
|
30
|
+
from janpa.janpa_interface import generate_CLPO_molecule_edges
|
|
31
|
+
|
|
32
|
+
# 1. Build molecule and run SCF
|
|
33
|
+
mol = gto.M(atom="H 0 0 0; H 0 0 1", basis="sto-3g", unit="Angstrom")
|
|
34
|
+
mf = scf.RHF(mol).run()
|
|
35
|
+
|
|
36
|
+
# 2. Generate CLPO orbitals and extract the bonding graph
|
|
37
|
+
# silent=True suppresses the verbose JANPA terminal output
|
|
38
|
+
clpo_coeff, edges = generate_CLPO_molecule_edges(mol, mf, silent=True)
|
|
39
|
+
|
|
40
|
+
print("CLPO Coefficient matrix shape:", clpo_coeff.shape)
|
|
41
|
+
print("Extracted CLPO Edges:", edges)
|
|
42
|
+
|
|
43
|
+
The `edges` list contains tuples representing the localized orbital pairs:
|
|
44
|
+
- `(i,)` represents a Lone Pair (LP) on a single center.
|
|
45
|
+
- `(i, i+1)` represents a Bonding (BD) and Antibonding (NB) pair between two centers.
|
|
46
|
+
|
|
47
|
+
## Quick Start with Psi4
|
|
48
|
+
|
|
49
|
+
The `janpa_psi4_interface` module offers the same functions for a Psi4 `Wavefunction` (Psi4 is installed with conda, e.g. `conda install -c conda-forge psi4`). The returned matrices have one row per orbital and one column per Psi4 AO. Basis sets with d or higher shells must be spherical (`puream true`):
|
|
50
|
+
|
|
51
|
+
import psi4
|
|
52
|
+
from janpa.janpa_psi4_interface import generate_CLPO_molecule_edges
|
|
53
|
+
|
|
54
|
+
psi4.set_options({"basis": "cc-pvdz", "puream": True})
|
|
55
|
+
mol = psi4.geometry("H 0 0 0\nH 0 0 1")
|
|
56
|
+
_, wfn = psi4.energy("scf", molecule=mol, return_wfn=True)
|
|
57
|
+
|
|
58
|
+
# wfn is optional: without it the SCF is run on mol with the current psi4 options
|
|
59
|
+
clpo_coeff, edges = generate_CLPO_molecule_edges(mol, wfn)
|
|
60
|
+
|
|
61
|
+
## References and Attribution
|
|
62
|
+
|
|
63
|
+
This Python port is based on the original JANPA software developed by Tymofii Nikolaienko, L. A. Bulavin, and D. M. Hovorun. All theoretical foundations and original algorithms belong to the respective authors. Please refer to the [original JANPA webpage](https://janpa.sourceforge.net/) for full references, copyright information, and the original Java binaries.
|
|
64
|
+
|
|
65
|
+
If you use this software or the underlying methods in your research, please cite the original articles:
|
|
66
|
+
|
|
67
|
+
1. T. Yu. Nikolaienko, L. A. Bulavin; *Localized orbitals for optimal decomposition of molecular properties*, Int. J. Quantum Chem. (2019), Vol.119, page e25798. [DOI: 10.1002/qua.25798](https://doi.org/10.1002/qua.25798)
|
|
68
|
+
2. T. Yu. Nikolaienko, L. A. Bulavin, D. M. Hovorun; *JANPA: an open source cross-platform implementation of the Natural Population Analysis on the Java platform*, Comput. Theor. Chem. (2014), V.1050, P.15-22. [DOI: 10.1016/j.comptc.2014.10.002](https://doi.org/10.1016/j.comptc.2014.10.002)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "janpa-py"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python rewrite of JANPA: Natural Population Analysis and electronic structure tools"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "JANPA contributors"},
|
|
14
|
+
]
|
|
15
|
+
dependencies = [
|
|
16
|
+
"numpy>=1.24",
|
|
17
|
+
"scipy>=1.10",
|
|
18
|
+
"rustworkx>=0.13",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://github.com/tequilahub/janpa-py"
|
|
23
|
+
|
|
24
|
+
[project.optional-dependencies]
|
|
25
|
+
dev = [
|
|
26
|
+
"pytest>=7.0",
|
|
27
|
+
"pytest-cov",
|
|
28
|
+
"ruff",
|
|
29
|
+
"pyscf>=2.4,!=2.15.1", # Added for test fixtures; 2.15.1 has no macOS wheel and a broken sdist
|
|
30
|
+
"networkx>=3.0", # Reference for the matching tests
|
|
31
|
+
]
|
|
32
|
+
pyscf = [
|
|
33
|
+
"pyscf>=2.4,!=2.15.1",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[project.scripts]
|
|
37
|
+
janpa = "janpa.cli.main:main"
|
|
38
|
+
molden2molden = "janpa.cli.molden2molden:main"
|
|
39
|
+
nwchem2molden = "janpa.cli.nwchem2molden:main"
|
|
40
|
+
|
|
41
|
+
[tool.setuptools.packages.find]
|
|
42
|
+
# CRITICAL: Tells setuptools that the 'janpa' package is inside the 'src' folder
|
|
43
|
+
where = ["src"]
|
|
44
|
+
include = ["janpa*"]
|
|
45
|
+
|
|
46
|
+
[tool.ruff]
|
|
47
|
+
line-length = 100
|
|
48
|
+
target-version = "py310"
|
|
49
|
+
|
|
50
|
+
[tool.pytest.ini_options]
|
|
51
|
+
testpaths = ["tests"]
|
janpa_py-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# janpa/cli/__init__.py
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# File: janpa/cli/main.py
|
|
2
|
+
"""Main CLI entry point for the janpa NPA program."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
import argparse
|
|
5
|
+
import logging
|
|
6
|
+
import sys
|
|
7
|
+
import time
|
|
8
|
+
import numpy as np
|
|
9
|
+
|
|
10
|
+
from janpa.io.molden import MoldenFile
|
|
11
|
+
from janpa.npa.npa import run_npa
|
|
12
|
+
from janpa.clpo.lpo import create_clpos, CLPOOptions
|
|
13
|
+
from janpa.utils.printout import print_stars, print_matrix, export_orbitals
|
|
14
|
+
|
|
15
|
+
logger = logging.getLogger("janpa")
|
|
16
|
+
|
|
17
|
+
def show_banner():
|
|
18
|
+
print(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *")
|
|
19
|
+
print(" * janpa: A cross-platform open-source implementation of NPA * ")
|
|
20
|
+
print(" * and other electronic structure analysis methods with Python * ")
|
|
21
|
+
print(" * A part of JANPA package, http://janpa.sourceforge.net * ")
|
|
22
|
+
print(" * Version: 2.02 (13-01-2019) [Python port] * ")
|
|
23
|
+
print(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *")
|
|
24
|
+
print()
|
|
25
|
+
print(" (c) Tymofii Nikolaienko, 2014-2019")
|
|
26
|
+
print(" Python port (c) 2024")
|
|
27
|
+
print()
|
|
28
|
+
print(" If any results obtained with this program are published,")
|
|
29
|
+
print(" or for any other reasons, please, cite this work as: ")
|
|
30
|
+
print(" 1) T.Y.Nikolaienko, L.A.Bulavin; Int. J. Quantum Chem. (2019), ")
|
|
31
|
+
print(" Vol.119, page e25798, DOI: 10.1002/qua.25798")
|
|
32
|
+
print(" 2) T.Y.Nikolaienko, L.A.Bulavin, D.M.Hovorun; Comput.Theor.Chem.(2014),")
|
|
33
|
+
print(" Vol.1050, pages 15-22, DOI: 10.1016/j.comptc.2014.10.002")
|
|
34
|
+
print_stars()
|
|
35
|
+
|
|
36
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
37
|
+
p = argparse.ArgumentParser(
|
|
38
|
+
prog="janpa",
|
|
39
|
+
description="JANPA: Natural Population Analysis and electronic structure tools",
|
|
40
|
+
)
|
|
41
|
+
p.add_argument("-i", "--input", required=True, help="Input MOLDEN file")
|
|
42
|
+
p.add_argument("-p", "--params", default="", help="Read options from parameter file")
|
|
43
|
+
|
|
44
|
+
p.add_argument("--npacharges", default="", help="Export NPA charges to file")
|
|
45
|
+
p.add_argument("--wiberg-file", default="", help="Export Wiberg bond orders")
|
|
46
|
+
p.add_argument("--nao-molden", default="", help="Export NAOs in MOLDEN format")
|
|
47
|
+
p.add_argument("--pnao-molden", default="", help="Export PNAOs in MOLDEN format")
|
|
48
|
+
p.add_argument("--pnao2ao-file", default="", help="Export PNAO to AO matrix")
|
|
49
|
+
|
|
50
|
+
p.add_argument("--lho-molden", default="", help="Export LHOs in MOLDEN format")
|
|
51
|
+
p.add_argument("--clpo-molden", default="", help="Export CLPOs in MOLDEN format")
|
|
52
|
+
p.add_argument("--aho-molden", default="", help="Export AHOs in MOLDEN format")
|
|
53
|
+
p.add_argument("--lpo-molden", default="", help="Export LPOs in MOLDEN format")
|
|
54
|
+
|
|
55
|
+
p.add_argument("--clpo2lho-file", default="", help="Export CLPO to LHO matrix")
|
|
56
|
+
p.add_argument("--lho2nao-file", default="", help="Export LHO to NAO matrix")
|
|
57
|
+
p.add_argument("--lpo2aho-file", default="", help="Export LPO to AHO matrix")
|
|
58
|
+
p.add_argument("--aho2nao-file", default="", help="Export AHO to NAO matrix")
|
|
59
|
+
|
|
60
|
+
p.add_argument("--do-fock", action="store_true", help="Perform Fock matrix analysis")
|
|
61
|
+
p.add_argument("--fock-ao-file", default="", help="Export Fock matrix in AO basis")
|
|
62
|
+
p.add_argument("--fock-nao-file", default="", help="Export Fock matrix in NAO basis")
|
|
63
|
+
p.add_argument("--print-nbm-submatrices", action="store_true", help="Print NBM submatrices")
|
|
64
|
+
|
|
65
|
+
p.add_argument("--print-geom", action="store_true", help="Print geometry")
|
|
66
|
+
p.add_argument("--overlap-naive", action="store_true", help="Use naive overlap calculation")
|
|
67
|
+
p.add_argument("--edges", default="", help="Bonds imposed on the CLPOs, between 0-based atoms, one pair per bond, e.g. \"[(1,2),(1,2)]\" = double bond 1=2; bonds between other atom pairs are found automatically")
|
|
68
|
+
p.add_argument("--hybr-opt-thresh", type=float, default=1e-5, help="Hybrid optimization threshold")
|
|
69
|
+
p.add_argument("--hybr-opt-max-iter", type=int, default=10000, help="Max hybrid optimization iterations")
|
|
70
|
+
p.add_argument("--max-bond-ionicity", type=float, default=0.90, help="Max CLPO bond ionicity")
|
|
71
|
+
|
|
72
|
+
p.add_argument("--verbose", action="store_true", help="Verbose output")
|
|
73
|
+
return p
|
|
74
|
+
|
|
75
|
+
def print_bond_indices(indices: np.ndarray, centers, export_fname: str):
|
|
76
|
+
n_atoms = len(centers)
|
|
77
|
+
print("Wiberg-Mayer bond indices (based on density matrix in NAO basis):")
|
|
78
|
+
header = f"{'Centr. A/B':>10}"
|
|
79
|
+
for i in range(n_atoms):
|
|
80
|
+
header += f"{i+1:10d}"
|
|
81
|
+
print(header)
|
|
82
|
+
|
|
83
|
+
for i in range(n_atoms):
|
|
84
|
+
row = f"{i+1:7d} "
|
|
85
|
+
for j in range(i):
|
|
86
|
+
row += f"{'':>10}"
|
|
87
|
+
row += f" ({indices[i, i]:7.4f})"
|
|
88
|
+
for j in range(i + 1, n_atoms):
|
|
89
|
+
row += f"{indices[i, j]:10.4f}"
|
|
90
|
+
print(row)
|
|
91
|
+
|
|
92
|
+
if export_fname:
|
|
93
|
+
atom_labels = [f"{c.name}{i+1}" for i, c in enumerate(centers)]
|
|
94
|
+
print_matrix(
|
|
95
|
+
indices,
|
|
96
|
+
"Wiberg-Mayer bond indices computed in NAO basis (note: "
|
|
97
|
+
"diagonal elements are atomic 'valencies' (sums of all bond orders in current line)):",
|
|
98
|
+
atom_labels, atom_labels, export_fname
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
def main() -> None:
|
|
102
|
+
parser = build_parser()
|
|
103
|
+
args = parser.parse_args()
|
|
104
|
+
|
|
105
|
+
show_banner()
|
|
106
|
+
|
|
107
|
+
t0 = time.perf_counter()
|
|
108
|
+
logger.info("JANPA starting...")
|
|
109
|
+
|
|
110
|
+
fname = args.input
|
|
111
|
+
|
|
112
|
+
print(f"Loading MOLDEN from {fname}")
|
|
113
|
+
try:
|
|
114
|
+
molden = MoldenFile.load(fname)
|
|
115
|
+
except Exception as e:
|
|
116
|
+
print(f"Error loading data: {e}")
|
|
117
|
+
sys.exit(1)
|
|
118
|
+
|
|
119
|
+
print()
|
|
120
|
+
print("Data loaded successfully")
|
|
121
|
+
print(f" Number of basis functions: {molden.n_basis}; number of molecular orbitals: {len(molden.mos)} ")
|
|
122
|
+
print()
|
|
123
|
+
|
|
124
|
+
if not molden.is_spherical:
|
|
125
|
+
print(" ERROR: Input molden file does not have a 'pure' ('spherical') basis set!")
|
|
126
|
+
print(" Try using molden2molden -cart2pure to convert it.")
|
|
127
|
+
sys.exit(1)
|
|
128
|
+
|
|
129
|
+
molden.coords_to_au()
|
|
130
|
+
|
|
131
|
+
if args.print_geom:
|
|
132
|
+
print("\nCartesian coordinates of the atoms (in atomic units):")
|
|
133
|
+
print(f"{'ID':<4}{'Element':<8}{'Nucl.Chrg.':<12}{'X':<15}{'Y':<15}{'Z':<15}")
|
|
134
|
+
for i, c in enumerate(molden.centers):
|
|
135
|
+
print(f"{i+1:<4}{c.name:<8}{c.z:<12.1f}{c.r0[0]:<15.10f}{c.r0[1]:<15.10f}{c.r0[2]:<15.10f}")
|
|
136
|
+
print_stars()
|
|
137
|
+
|
|
138
|
+
if not args.overlap_naive:
|
|
139
|
+
molden.to_unnormalized_primitive_coefs()
|
|
140
|
+
|
|
141
|
+
npa_res = run_npa(molden, {"verbose": args.verbose})
|
|
142
|
+
print_stars()
|
|
143
|
+
|
|
144
|
+
if npa_res.wiberg_indices is not None:
|
|
145
|
+
print_bond_indices(npa_res.wiberg_indices, molden.centers, args.wiberg_file)
|
|
146
|
+
print_stars()
|
|
147
|
+
|
|
148
|
+
print("=" * 100)
|
|
149
|
+
|
|
150
|
+
clpo_opts = CLPOOptions(
|
|
151
|
+
hybr_opt_conv_thresh=args.hybr_opt_thresh,
|
|
152
|
+
hybr_opt_max_iter=args.hybr_opt_max_iter,
|
|
153
|
+
max_bond_ionicity_threshold=args.max_bond_ionicity,
|
|
154
|
+
edges=args.edges
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
if npa_res.sds_nao_alpha is None:
|
|
158
|
+
create_clpos(npa_res.sds_nao, npa_res.nao, molden.centers, clpo_opts)
|
|
159
|
+
else:
|
|
160
|
+
# Twice the spin density keeps the closed-shell occupancy cuts, i.e. 0.5 e per spin as in open-shell NBO
|
|
161
|
+
for label, sds in (("ALPHA", npa_res.sds_nao_alpha), ("BETA", npa_res.sds_nao_beta)):
|
|
162
|
+
print(f"\n{label} SPIN CLPOs (occupancies are twice the {label.lower()} ones)\n")
|
|
163
|
+
create_clpos(2 * sds, npa_res.nao, molden.centers, clpo_opts)
|
|
164
|
+
print_stars()
|
|
165
|
+
|
|
166
|
+
print("Atomic connectivity analysis based on CLPO bonding graph:")
|
|
167
|
+
print()
|
|
168
|
+
print_stars()
|
|
169
|
+
|
|
170
|
+
if args.npacharges and npa_res.npa_charges.size > 0:
|
|
171
|
+
print(f"Writing NPA charges to\t{args.npacharges}")
|
|
172
|
+
with open(args.npacharges, 'w') as ch:
|
|
173
|
+
for q in npa_res.npa_charges:
|
|
174
|
+
ch.write(f"{q:.16f}\n")
|
|
175
|
+
|
|
176
|
+
if args.do_fock and len(molden.mos) >= molden.n_basis:
|
|
177
|
+
print("Fock matrix analysis in NAO basis")
|
|
178
|
+
mo_energies = np.diag([mo.energy for mo in molden.mos])
|
|
179
|
+
C = molden.get_mo_coef_matrix().T # Shape: (n_basis, n_mo)
|
|
180
|
+
try:
|
|
181
|
+
C_inv = np.linalg.inv(C)
|
|
182
|
+
print("Transforming Fock matrix to AO basis...")
|
|
183
|
+
Fock_AO = C @ mo_energies @ C.T
|
|
184
|
+
|
|
185
|
+
if hasattr(npa_res, 'ao_names'):
|
|
186
|
+
print_matrix(Fock_AO, "Fock matrix in AO basis", npa_res.ao_names, npa_res.ao_names, args.fock_ao_file)
|
|
187
|
+
|
|
188
|
+
if npa_res.nao_to_ao is not None:
|
|
189
|
+
print("Transforming Fock matrix to NAO basis...")
|
|
190
|
+
Fock_NAO = npa_res.nao_to_ao.T @ Fock_AO @ npa_res.nao_to_ao
|
|
191
|
+
# Further NAO exports would go here
|
|
192
|
+
except np.linalg.LinAlgError:
|
|
193
|
+
print("ERROR: Could not invert MO -> AO matrix for Fock analysis.")
|
|
194
|
+
|
|
195
|
+
if args.nao_molden and getattr(npa_res, 'nao_to_ao', None) is not None:
|
|
196
|
+
print(f"Writing NAOs to\t{args.nao_molden}")
|
|
197
|
+
# export_orbitals(molden, npa_res.nao_to_ao, ...)
|
|
198
|
+
|
|
199
|
+
elapsed = time.perf_counter() - t0
|
|
200
|
+
logger.info("Total run time: %.2f s", elapsed)
|
|
201
|
+
print_stars()
|
|
202
|
+
|
|
203
|
+
if __name__ == "__main__":
|
|
204
|
+
main()
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# File: janpa/cli/molden2molden.py
|
|
2
|
+
"""molden2molden CLI: format conversion tool."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
import argparse
|
|
5
|
+
import sys
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
from janpa.io.molden import MoldenFile
|
|
9
|
+
from janpa.convert.cart2sph import cart2spher
|
|
10
|
+
from janpa.convert.file47 import import_47, build_basis_set, check_bf_order_and_create_remap, produce_nos
|
|
11
|
+
from janpa.gto.overlap import primitive_int_1d_sphr
|
|
12
|
+
|
|
13
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
14
|
+
p = argparse.ArgumentParser(
|
|
15
|
+
prog="molden2molden",
|
|
16
|
+
description="MOLDEN file format converter"
|
|
17
|
+
)
|
|
18
|
+
p.add_argument("input", help="Input MOLDEN file")
|
|
19
|
+
p.add_argument("output", help="Output MOLDEN file")
|
|
20
|
+
|
|
21
|
+
p.add_argument("-cart2pure", "--cart2spher", action="store_true", help="Convert Cartesian to Spherical")
|
|
22
|
+
p.add_argument("-ignore-lower-l", action="store_true", help="Ignore lower L terms in cart2pure")
|
|
23
|
+
p.add_argument("-angstroms", action="store_true", help="Output coordinates in Angstroms")
|
|
24
|
+
|
|
25
|
+
p.add_argument("-orca3signs", action="store_true", help="Fix ORCA3 signs")
|
|
26
|
+
p.add_argument("-from-orca3-bf", action="store_true", help="Convert basis from ORCA3 style")
|
|
27
|
+
p.add_argument("-to-orca3-bf", action="store_true", help="Convert basis to ORCA3 style")
|
|
28
|
+
p.add_argument("-from-psi4b4-bf", action="store_true", help="Convert basis from PSI4b4 style")
|
|
29
|
+
p.add_argument("-from-psi4v1-mo", action="store_true", help="Convert MOs from PSI4v1 style")
|
|
30
|
+
p.add_argument("-to-psi4b4-bf", action="store_true", help="Convert basis to PSI4b4 style")
|
|
31
|
+
|
|
32
|
+
p.add_argument("-normalize", action="store_true", help="Force basis functions to be unity-normalized")
|
|
33
|
+
|
|
34
|
+
p.add_argument("-geom47", default="", help="Suppress geometry with .47 file")
|
|
35
|
+
p.add_argument("-bs47", default="", help="Suppress basis set with .47 file")
|
|
36
|
+
p.add_argument("-ds47", default="", help="Suppress MO coefficients with .47 file")
|
|
37
|
+
|
|
38
|
+
return p
|
|
39
|
+
|
|
40
|
+
def fix_orca3_psi4_normalization(molden, from_orca3=False, from_psi4b4=False):
|
|
41
|
+
orca_dividers = [1.0, 1.0, 3.0, 15.0, 35.0]
|
|
42
|
+
if from_orca3 or from_psi4b4:
|
|
43
|
+
for rp in molden.radial_parts:
|
|
44
|
+
l = rp.l_used_with
|
|
45
|
+
for cf in range(len(rp.coefs)):
|
|
46
|
+
rnorm2 = primitive_int_1d_sphr(2 * l + 2 + 2 * rp.addit_r_power, 2 * rp.exponents[cf])
|
|
47
|
+
rnorm2 *= 4 * np.pi
|
|
48
|
+
rnorm2 /= (2 * l + 1)
|
|
49
|
+
if from_orca3 and l < len(orca_dividers):
|
|
50
|
+
rnorm2 /= orca_dividers[l]
|
|
51
|
+
rp.coefs[cf] *= np.sqrt(rnorm2)
|
|
52
|
+
for bf in molden.basis:
|
|
53
|
+
bf.coefs = molden.radial_parts[bf.radial_part_id].coefs.copy()
|
|
54
|
+
|
|
55
|
+
def main() -> None:
|
|
56
|
+
parser = build_parser()
|
|
57
|
+
args = parser.parse_args()
|
|
58
|
+
|
|
59
|
+
print(f"Loading input molden from {args.input} ...")
|
|
60
|
+
try:
|
|
61
|
+
molden = MoldenFile.load(args.input)
|
|
62
|
+
except Exception as e:
|
|
63
|
+
print(f"ERROR: Can not load data from {args.input}: {e}")
|
|
64
|
+
sys.exit(1)
|
|
65
|
+
|
|
66
|
+
print("Data loaded successfully.\n")
|
|
67
|
+
|
|
68
|
+
if args.cart2spher and molden.is_spherical:
|
|
69
|
+
print("ERROR: input molden file already uses pure spherical harmonics, -cart2spher key makes no sense and will be ignored!")
|
|
70
|
+
args.cart2spher = False
|
|
71
|
+
|
|
72
|
+
if not args.angstroms and not molden.coords_in_au:
|
|
73
|
+
print("Converting atomic coordinates from Angstroms to a.u. ...")
|
|
74
|
+
molden.coords_to_au()
|
|
75
|
+
if args.angstroms and molden.coords_in_au:
|
|
76
|
+
print("Converting atomic coordinates from a.u. to Angstroms ...")
|
|
77
|
+
molden.coords_to_angstroms()
|
|
78
|
+
|
|
79
|
+
if args.geom47:
|
|
80
|
+
print(f"Supressing geometry with the data from .47 file {args.geom47}")
|
|
81
|
+
data47 = import_47(args.geom47)
|
|
82
|
+
# In a full implementation, we would map data47 coordinates to molden.centers
|
|
83
|
+
|
|
84
|
+
if args.bs47:
|
|
85
|
+
print(f"Supressing basis set with the data from .47 file {args.bs47}")
|
|
86
|
+
data47 = import_47(args.bs47)
|
|
87
|
+
if not build_basis_set(data47, molden):
|
|
88
|
+
print("Error importing basis set data!")
|
|
89
|
+
sys.exit(1)
|
|
90
|
+
|
|
91
|
+
if args.ds47:
|
|
92
|
+
print(f"Supressing MO coefficients with the data from .47 file {args.ds47}")
|
|
93
|
+
data47 = import_47(args.ds47)
|
|
94
|
+
if data47.nbas != molden.n_basis:
|
|
95
|
+
print("ERROR: the number of basis functions is different in the input molden file and in the given .47 file")
|
|
96
|
+
sys.exit(1)
|
|
97
|
+
if not check_bf_order_and_create_remap(data47, molden):
|
|
98
|
+
print("ERROR: reordering of the .47 file basis set failed!")
|
|
99
|
+
sys.exit(1)
|
|
100
|
+
produce_nos(data47, molden)
|
|
101
|
+
|
|
102
|
+
fix_orca3_psi4_normalization(molden, from_orca3=args.from_orca3_bf, from_psi4b4=args.from_psi4b4_bf)
|
|
103
|
+
|
|
104
|
+
if args.cart2spher:
|
|
105
|
+
print("Converting Cartesian to Spherical...")
|
|
106
|
+
molden = cart2spher(molden, ignore_lower_l=args.ignore_lower_l)
|
|
107
|
+
|
|
108
|
+
print(f"Saving result as {args.output} (ascii encoded)...")
|
|
109
|
+
try:
|
|
110
|
+
molden.save(args.output)
|
|
111
|
+
print("OK.")
|
|
112
|
+
except Exception as e:
|
|
113
|
+
print(f"ERROR saving file: {e}")
|
|
114
|
+
sys.exit(1)
|
|
115
|
+
|
|
116
|
+
if __name__ == "__main__":
|
|
117
|
+
main()
|