-
Notifications
You must be signed in to change notification settings - Fork 2
Deleting unused imports and variables #23
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
YCC-ProjBackups
wants to merge
4
commits into
main
Choose a base branch
from
ycc/pr/cleanup
base: main
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 | ||
|---|---|---|---|---|
| @@ -1,18 +1,14 @@ | ||||
| import numpy as np | ||||
|
|
||||
| from anisoap.utils.spherical_to_cartesian import spherical_to_cartesian | ||||
| from ..representations.radial_basis import RadialBasis | ||||
| from ..utils import quaternion_to_rotation_matrix # missing? | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| from ..utils import compute_moments_inefficient_implementation | ||||
| from ..utils.spherical_to_cartesian import spherical_to_cartesian | ||||
|
|
||||
| try: | ||||
| from tqdm import tqdm | ||||
| except ImportError: | ||||
| tqdm = lambda i, **kwargs: i | ||||
|
|
||||
| from ..utils import ( | ||||
| compute_moments_diagonal_inefficient_implementation, | ||||
| compute_moments_inefficient_implementation, | ||||
| quaternion_to_rotation_matrix, | ||||
| ) | ||||
| from .radial_basis import RadialBasis | ||||
| tqdm = lambda i, **_: i | ||||
|
|
||||
|
|
||||
| class DensityProjectionCalculator: | ||||
|
|
@@ -55,7 +51,7 @@ def __init__( | |||
| if compute_gradients: | ||||
| raise NotImplementedError("Sorry! Gradients have not yet been implemented") | ||||
|
|
||||
| # Precompute the spherical to Cartesian transformation | ||||
| # Pre-compute the spherical to Cartesian transformation | ||||
| # coefficients. | ||||
| num_ns = [] | ||||
| for l in range(max_angular + 1): | ||||
|
|
||||
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 | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,3 @@ | ||||||||||||||||||||||||
| import sys | ||||||||||||||||||||||||
| import warnings | ||||||||||||||||||||||||
| from itertools import product | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -10,11 +9,15 @@ | |||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| from rascaline import NeighborList | ||||||||||||||||||||||||
| from scipy.spatial.transform import Rotation | ||||||||||||||||||||||||
| from tqdm.auto import tqdm | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| from anisoap.representations.radial_basis import RadialBasis | ||||||||||||||||||||||||
| from anisoap.utils.moment_generator import * | ||||||||||||||||||||||||
| from anisoap.utils.spherical_to_cartesian import spherical_to_cartesian | ||||||||||||||||||||||||
| from ..representations.radial_basis import RadialBasis | ||||||||||||||||||||||||
| from ..utils.moment_generator import * | ||||||||||||||||||||||||
| from ..utils.spherical_to_cartesian import spherical_to_cartesian | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||
| from tqdm.auto import tqdm | ||||||||||||||||||||||||
| except ImportError: | ||||||||||||||||||||||||
| tqdm = lambda x, **_: x | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def pairwise_ellip_expansion( | ||||||||||||||||||||||||
|
|
@@ -95,12 +98,9 @@ def pairwise_ellip_expansion( | |||||||||||||||||||||||
| leave=False, | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||
| frame_idx, i, j = ( | ||||||||||||||||||||||||
| nl_sample["structure"], | ||||||||||||||||||||||||
| nl_sample["first_atom"], | ||||||||||||||||||||||||
| nl_sample["second_atom"], | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| i_global = frame_to_global_atom_idx[frame_idx] + i | ||||||||||||||||||||||||
| frame_idx, j = (nl_sample["structure"], nl_sample["second_atom"]) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # i_global is not needed | ||||||||||||||||||||||||
| j_global = frame_to_global_atom_idx[frame_idx] + j | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| r_ij = np.asarray( | ||||||||||||||||||||||||
|
|
@@ -257,13 +257,11 @@ def contract_pairwise_feat(pair_ellip_feat, species, show_progress=False): | |||||||||||||||||||||||
| block_samples = [] | ||||||||||||||||||||||||
| block_values = [] | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| for isample, sample in enumerate( | ||||||||||||||||||||||||
| tqdm( | ||||||||||||||||||||||||
| possible_block_samples, | ||||||||||||||||||||||||
| disable=(not show_progress), | ||||||||||||||||||||||||
| desc="Finding matching block samples", | ||||||||||||||||||||||||
| leave=False, | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| for sample in tqdm( | ||||||||||||||||||||||||
| possible_block_samples, | ||||||||||||||||||||||||
| disable=(not show_progress), | ||||||||||||||||||||||||
| desc="Finding matching block samples", | ||||||||||||||||||||||||
| leave=False, | ||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||
| sample_idx = [ | ||||||||||||||||||||||||
| idx | ||||||||||||||||||||||||
|
|
@@ -283,7 +281,7 @@ def contract_pairwise_feat(pair_ellip_feat, species, show_progress=False): | |||||||||||||||||||||||
| # block_values has as many entries as samples satisfying (key, neighbor_species=ele). | ||||||||||||||||||||||||
| # When we iterate over neighbor species, not all (structure, center) would be present | ||||||||||||||||||||||||
| # Example: (0,0,1) might be present in a block with neighbor_species = 1 but no other pair block | ||||||||||||||||||||||||
| # ever has (0,0,x) present as a sample- so (0,0) doesnt show up in a block_sample for all ele | ||||||||||||||||||||||||
| # ever has (0,0,x) present as a sample- so (0,0) doesn't show up in a block_sample for all ele | ||||||||||||||||||||||||
| # so in general we have a ragged list of contract_blocks | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| contract_blocks.append(block_values) | ||||||||||||||||||||||||
|
|
@@ -304,11 +302,11 @@ def contract_pairwise_feat(pair_ellip_feat, species, show_progress=False): | |||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| # Create storage for the final values - we need as many rows as all_block_samples, | ||||||||||||||||||||||||
| # block.values.shape[1:] accounts for "components" and "properties" that are already part of the pair blocks | ||||||||||||||||||||||||
| # and we dont alter these | ||||||||||||||||||||||||
| # len(contract_blocks) - adds the additional dimension for the neighbor_species since we accumulated | ||||||||||||||||||||||||
| # values for each of them as \sum_{j in ele} <|rho_ij> | ||||||||||||||||||||||||
| # Thus - all_block_values.shape = (num_final_samples, components_pair, properties_pair, num_species) | ||||||||||||||||||||||||
| # block.values.shape[1:] accounts for "components" and "properties" that | ||||||||||||||||||||||||
| # are already part of the pair blocks and we dont alter these | ||||||||||||||||||||||||
| # len(contract_blocks) - adds the additional dimension for the neighbor_species | ||||||||||||||||||||||||
| # since we accumulated values for each of them as \sum_{j in ele} <|rho_ij> | ||||||||||||||||||||||||
| # Thus - all_block_values.shape = (num_final_samples, components_pair, properties_pair, num_species) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| for iele, elem_cont_samples in enumerate( | ||||||||||||||||||||||||
| tqdm( | ||||||||||||||||||||||||
|
|
@@ -319,15 +317,14 @@ def contract_pairwise_feat(pair_ellip_feat, species, show_progress=False): | |||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||
| # This effectively loops over the species of the neighbors | ||||||||||||||||||||||||
| # Now we just need to add the contributions to the final samples and values from this species to the right | ||||||||||||||||||||||||
| # samples | ||||||||||||||||||||||||
| # Now we just need to add the contributions to the final samples and | ||||||||||||||||||||||||
| # values from this species to the right samples | ||||||||||||||||||||||||
| nzidx = [ | ||||||||||||||||||||||||
| i | ||||||||||||||||||||||||
| for i in range(len(all_block_samples)) | ||||||||||||||||||||||||
| if all_block_samples[i] in elem_cont_samples | ||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||
| # identifies where the samples that this species contributes to, are present in the final samples | ||||||||||||||||||||||||
| # print(apecies[ib],key, bb, all_block_samples) | ||||||||||||||||||||||||
| all_block_values[nzidx, :, :, iele] = contract_blocks[iele] | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| new_block = TensorBlock( | ||||||||||||||||||||||||
|
|
@@ -420,11 +417,12 @@ def __init__( | |||||||||||||||||||||||
| raise ValueError( | ||||||||||||||||||||||||
| "radial_gaussian_width is set as an integer, which could cause overflow errors. Pass in float." | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| radial_hypers = {} | ||||||||||||||||||||||||
| radial_hypers["radial_basis"] = radial_basis_name.lower() # lower case | ||||||||||||||||||||||||
| radial_hypers["radial_gaussian_width"] = radial_gaussian_width | ||||||||||||||||||||||||
| radial_hypers["max_angular"] = max_angular | ||||||||||||||||||||||||
| self.radial_basis = RadialBasis(**radial_hypers) | ||||||||||||||||||||||||
| radial_hypers = { | ||||||||||||||||||||||||
| "radial_gaussian_width": radial_gaussian_width, | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| self.radial_basis = RadialBasis( | ||||||||||||||||||||||||
| radial_basis_name.lower(), max_angular, **radial_hypers | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
|
rosecers marked this conversation as resolved.
Comment on lines
+420
to
+425
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| self.num_ns = self.radial_basis.get_num_radial_functions() | ||||||||||||||||||||||||
| self.sph_to_cart = spherical_to_cartesian(self.max_angular, self.num_ns) | ||||||||||||||||||||||||
|
|
@@ -455,7 +453,7 @@ def transform(self, frames, show_progress=False, normalize=True): | |||||||||||||||||||||||
| show_progress : bool | ||||||||||||||||||||||||
| Show progress bar for frame analysis and feature generation | ||||||||||||||||||||||||
| normalize: bool | ||||||||||||||||||||||||
| Whether to perform Lowdin Symmetric Orthonormalization or not. Orthonormalization generally | ||||||||||||||||||||||||
| Whether to perform Löwdin Symmetric Orthonormalization or not. Orthonormalization generally | ||||||||||||||||||||||||
| leads to better performance. Default: True. | ||||||||||||||||||||||||
| Returns | ||||||||||||||||||||||||
| ------- | ||||||||||||||||||||||||
|
|
@@ -483,8 +481,6 @@ def transform(self, frames, show_progress=False, normalize=True): | |||||||||||||||||||||||
| # Define variables determining size of feature vector coming from frames | ||||||||||||||||||||||||
| self.num_atoms_per_frame = np.array([len(frame) for frame in frames]) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| num_particle_types = len(species) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Initialize arrays in which to store all features | ||||||||||||||||||||||||
| self.feature_gradients = 0 | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, everything still runs fine.
For the
quaternion_to_rotation_matrix, I am fairly certain it is missing. The reason for not crashing the program is probably because we never useDensityProjectionClasscalculator -- onlyEllipsoidalDensityProjection. InEllipsoidalDensityProjection, we usescipy.spatial.transform.Rotation.from_quat(...)to convert quaternion to rotation type.Please let me know if I missed anything!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with removing it if it's no longer needed. It might be a relic from the first version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*removing this line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, we can remove this line in that case