Skip to content
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

power_spectrum2 #43

Merged
merged 24 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion anisoap/representations/ellipsoidal_density_projection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
import warnings
import metatensor
from itertools import product

import numpy as np
Expand All @@ -11,14 +12,19 @@
from rascaline import NeighborList
from scipy.spatial.transform import Rotation
from tqdm.auto import tqdm
from skmatter.preprocessing import StandardFlexibleScaler

from anisoap.representations.radial_basis import (
GTORadialBasis,
MonomialBasis,
)
from anisoap.utils.moment_generator import *
from anisoap.utils.spherical_to_cartesian import spherical_to_cartesian

from anisoap.utils.metatensor_utils import (
cg_combine,
standardize_keys,
ClebschGordanReal
)

def pairwise_ellip_expansion(
lmax,
Expand Down Expand Up @@ -646,3 +652,37 @@ def transform(self, frames, show_progress=False, normalize=True):
return normalized_features
else:
return features
def power_spectrum(self, ell_frames, AniSOAP_HYPERS=None, mycg=None):
calculator = EllipsoidalDensityProjection(**AniSOAP_HYPERS)
arthur-lin1027 marked this conversation as resolved.
Show resolved Hide resolved
if ell_frames is None:
raise ValueError("ell_frames cannot be none")
rosecers marked this conversation as resolved.
Show resolved Hide resolved
required_attributes = [
'c_diameter[1]',
'c_diameter[2]',
'c_diameter[3]',
'c_q',
'positions',
'species',
arthur-lin1027 marked this conversation as resolved.
Show resolved Hide resolved
'quaternion'
arthur-lin1027 marked this conversation as resolved.
Show resolved Hide resolved
]
for index, frame in enumerate(ell_frames):
rosecers marked this conversation as resolved.
Show resolved Hide resolved
for attr in required_attributes:
if attr not in frame:
arthur-lin1027 marked this conversation as resolved.
Show resolved Hide resolved
raise ValueError(f"ell_frame at index {index} is missing a required attribute '{attr}'")

mvg_coeffs = calculator.transform(ell_frames, show_progress=True)
arthur-lin1027 marked this conversation as resolved.
Show resolved Hide resolved
mvg_nu1 = standardize_keys(mvg_coeffs)
mvg_nu2 = cg_combine(
mvg_nu1,
mvg_nu1,
clebsch_gordan=mycg,
lcut=0,
other_keys_match=["types_center"]
)

x_asoap_raw = metatensor.sum_over_samples(mvg_nu2, sample_names="center")
arthur-lin1027 marked this conversation as resolved.
Show resolved Hide resolved
x_asoap_raw = x_asoap_raw.block().values.squeeze()
x_asoap_scaler = StandardFlexibleScaler(column_wise=False).fit(x_asoap_raw)
arthur-lin1027 marked this conversation as resolved.
Show resolved Hide resolved
x_asoap = x_asoap_scaler.transform(x_asoap_raw)

return x_asoap
8 changes: 4 additions & 4 deletions notebooks/anisotropic_representations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@
"evalue": "No module named 'anisoap.representations.projection_coefficients_modified'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn [47], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01manisoap\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mrepresentations\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mprojection_coefficients_modified\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'anisoap.representations.projection_coefficients_modified'"
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
rosecers marked this conversation as resolved.
Show resolved Hide resolved
"\u001B[0;31mModuleNotFoundError\u001B[0m Traceback (most recent call last)",
"Cell \u001B[0;32mIn [47], line 1\u001B[0m\n\u001B[0;32m----> 1\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m \u001B[38;5;21;01manisoap\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mrepresentations\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mprojection_coefficients_modified\u001B[39;00m \u001B[38;5;28;01mimport\u001B[39;00m \u001B[38;5;241m*\u001B[39m\n",
"\u001B[0;31mModuleNotFoundError\u001B[0m: No module named 'anisoap.representations.projection_coefficients_modified'"
]
}
],
Expand Down
Loading