-
Notifications
You must be signed in to change notification settings - Fork 37
GSOC 2025: Add electron density integration tools and BFit data processor #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tutou2356
wants to merge
7
commits into
theochem:master
Choose a base branch
from
tutou2356:electron-density-tools
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
11230f7
Add electron density integration tools
tutou2356 2ec1e49
Implement Ali's review suggestions to modify the code
tutou2356 82fea21
Update comparison table and simplify test_grid_sizes function
tutou2356 aa7e243
Add 1D adaptive grid implementation
tutou2356 1f16be3
feat(grid): Implement adaptive grid refinement
tutou2356 258365a
feat: Add PromolMolecule class
tutou2356 dab3cc2
feat: Filter tiny coefficients and add example notebook
tutou2356 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| BFit Data Processor | ||
|
|
||
| Processes promolecular coefficients and exponents from theochem/BFit | ||
| data files for integration with Grid library. | ||
|
|
||
| Note: This version handles s-type orbital data. | ||
| """ | ||
|
|
||
| import sys | ||
| from pathlib import Path | ||
| from dataclasses import dataclass | ||
| from typing import Dict, Optional | ||
|
|
||
| import numpy as np | ||
|
|
||
| sys.path.insert(0, str(Path(__file__).parent.parent / "src")) | ||
|
|
||
| # Element symbol to atomic number mapping | ||
| ELEMENT_TO_ATOMIC_NUMBER = { | ||
| "h": 1, | ||
| "he": 2, | ||
| "li": 3, | ||
| "be": 4, | ||
| "b": 5, | ||
| "c": 6, | ||
| "n": 7, | ||
| "o": 8, | ||
| "f": 9, | ||
| "ne": 10, | ||
| "na": 11, | ||
| "mg": 12, | ||
| "al": 13, | ||
| "si": 14, | ||
| "p": 15, | ||
| "s": 16, | ||
| "cl": 17, | ||
| "ar": 18, | ||
| "k": 19, | ||
| "ca": 20, | ||
| "sc": 21, | ||
| "ti": 22, | ||
| "v": 23, | ||
| "cr": 24, | ||
| "mn": 25, | ||
| "fe": 26, | ||
| "co": 27, | ||
| "ni": 28, | ||
| "cu": 29, | ||
| "zn": 30, | ||
| "ga": 31, | ||
| "ge": 32, | ||
| "as": 33, | ||
| "se": 34, | ||
| "br": 35, | ||
| "kr": 36, | ||
| "rb": 37, | ||
| "sr": 38, | ||
| "y": 39, | ||
| "zr": 40, | ||
| "nb": 41, | ||
| "mo": 42, | ||
| "tc": 43, | ||
| "ru": 44, | ||
| "rh": 45, | ||
| "pd": 46, | ||
| "ag": 47, | ||
| "cd": 48, | ||
| "in": 49, | ||
| "sn": 50, | ||
| "sb": 51, | ||
| "te": 52, | ||
| "i": 53, | ||
| "xe": 54, | ||
| } | ||
|
|
||
|
|
||
| @dataclass | ||
| class BFitElementData: | ||
| """Store BFit data for a single element""" | ||
|
|
||
| symbol: str | ||
| atomic_number: int | ||
| coeffs: np.ndarray | ||
| exps: np.ndarray | ||
| num_s: int = 0 | ||
| num_p: int = 0 | ||
|
tutou2356 marked this conversation as resolved.
Outdated
|
||
|
|
||
| @property | ||
| def coeffs_s(self) -> np.ndarray: | ||
| """S-type coefficients alias for compatibility""" | ||
| return self.coeffs | ||
|
|
||
| @property | ||
| def exps_s(self) -> np.ndarray: | ||
| """S-type exponents alias for compatibility""" | ||
| return self.exps | ||
|
|
||
|
|
||
| class BFitDataProcessor: | ||
| """Process BFit data and convert to Grid library format""" | ||
|
|
||
| def __init__(self, data_file: Path): | ||
| self.data_file = data_file | ||
| self.raw_data: Optional[np.lib.npyio.NpzFile] = None | ||
| self.element_data: Dict[str, BFitElementData] = {} | ||
|
|
||
| def load_bfit_data(self) -> bool: | ||
| """Load BFit data file""" | ||
| try: | ||
| self.raw_data = np.load(self.data_file) | ||
| return True | ||
| except Exception as e: | ||
| print(f"Failed to load data file: {e}") | ||
| return False | ||
|
|
||
| def parse_element_data(self) -> Dict[str, BFitElementData]: | ||
| """Parse element data from BFit file""" | ||
| if self.raw_data is None: | ||
| print("Data not loaded, call load_bfit_data() first") | ||
| return {} | ||
|
|
||
| # Get all elements with coefficients | ||
| element_symbols = set() | ||
| for key in self.raw_data.files: | ||
| if "_coeffs_s" in key: | ||
| symbol = key.replace("_coeffs_s", "") | ||
| element_symbols.add(symbol) | ||
|
|
||
| for symbol in element_symbols: | ||
| try: | ||
| coeffs_key = f"{symbol}_coeffs_s" | ||
| exps_key = f"{symbol}_exps_s" | ||
|
|
||
| if coeffs_key not in self.raw_data or exps_key not in self.raw_data: | ||
| print(f"Missing coefficient or exponent data for element {symbol}") | ||
| continue | ||
|
|
||
| coeffs = self.raw_data[coeffs_key] | ||
| exps = self.raw_data[exps_key] | ||
| atomic_number = ELEMENT_TO_ATOMIC_NUMBER.get(symbol, 0) | ||
|
|
||
| element_data = BFitElementData( | ||
| symbol=symbol, | ||
| atomic_number=atomic_number, | ||
| coeffs=coeffs, | ||
| exps=exps, | ||
| num_s=len(coeffs), | ||
| num_p=0, | ||
| ) | ||
|
|
||
| self.element_data[symbol] = element_data | ||
|
|
||
| except Exception as e: | ||
| print(f"Error parsing element {symbol}: {e}") | ||
|
|
||
| return self.element_data | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.