-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from BIG-MAP/partial_matrix
Added functionality to be able to learn partial matrices
- Loading branch information
Showing
23 changed files
with
611 additions
and
108 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,132 @@ | ||
from typing import Callable, Optional | ||
|
||
import numpy as np | ||
|
||
class NodeFeature: | ||
|
||
def __new__(cls, config, data_processor): | ||
return cls.get_feature(config, data_processor) | ||
|
||
registry = {} | ||
|
||
def __init_subclass__(cls) -> None: | ||
NodeFeature.registry[cls.__name__] = cls | ||
|
||
@staticmethod | ||
def get_feature(config: dict, data_processor) -> np.ndarray: | ||
raise NotImplementedError | ||
|
||
@staticmethod | ||
def get_irreps(data_processor): | ||
raise NotImplementedError | ||
|
||
class OneHotZ(NodeFeature): | ||
|
||
@staticmethod | ||
def get_irreps(basis_table): | ||
from e3nn import o3 | ||
return o3.Irreps([(len(basis_table), (0, 1))]) | ||
|
||
@staticmethod | ||
def get_feature(config, data_processor): | ||
indices = data_processor.get_point_types(config) | ||
return data_processor.one_hot_encode(indices) | ||
|
||
class WaterDipole(NodeFeature): | ||
|
||
@staticmethod | ||
def get_irreps(basis_table): | ||
from e3nn import o3 | ||
return o3.Irreps("1x1o") | ||
|
||
@staticmethod | ||
def get_feature(config, data_processor): | ||
|
||
n_atoms = len(config.positions) | ||
|
||
z_dipole = np.array([0.0, 0.0, 0.0]) | ||
for position, point_type in zip(config.positions, config.point_types): | ||
if point_type == 8 or point_type == 1: | ||
|
||
z_dipole[2] += position[2]*(-2 if point_type == 8 else 1) | ||
|
||
z_dipole = data_processor.cartesian_to_basis(z_dipole) / 30 | ||
z_dipole = np.tile(z_dipole, n_atoms).reshape(n_atoms, 3) | ||
|
||
return z_dipole | ||
|
||
class WaterDipoleInv(NodeFeature): | ||
|
||
@staticmethod | ||
def get_irreps(basis_table): | ||
from e3nn import o3 | ||
return o3.Irreps("1x0e") | ||
|
||
@staticmethod | ||
def get_feature(config, data_processor): | ||
|
||
n_atoms = len(config.positions) | ||
|
||
z_dipole = np.array([0.0]) | ||
for position, point_type in zip(config.positions, config.point_types): | ||
if point_type == 8 or point_type == 1: | ||
|
||
z_dipole[0] += position[2]*(-2 if point_type == 8 else 1) | ||
|
||
z_dipole = np.tile(z_dipole, n_atoms).reshape(n_atoms, 1) | ||
|
||
return z_dipole / 30 | ||
|
||
class Nothing(NodeFeature): | ||
|
||
@staticmethod | ||
def get_irreps(basis_table): | ||
from e3nn import o3 | ||
return o3.Irreps("1x0e") | ||
|
||
@staticmethod | ||
def get_feature(config, data_processor): | ||
|
||
n_atoms = len(config.positions) | ||
|
||
z_dipole = np.array([0.0]) | ||
|
||
z_dipole = np.tile(z_dipole, n_atoms).reshape(n_atoms, 1) | ||
|
||
return z_dipole | ||
|
||
class NothingVector(NodeFeature): | ||
|
||
@staticmethod | ||
def get_irreps(basis_table): | ||
from e3nn import o3 | ||
return o3.Irreps("1x1o") | ||
|
||
@staticmethod | ||
def get_feature(config, data_processor): | ||
|
||
n_atoms = len(config.positions) | ||
|
||
z_dipole = np.array([0.0, 0.0, 0.0]) | ||
|
||
z_dipole = np.tile(z_dipole, n_atoms).reshape(n_atoms, 3) | ||
|
||
return z_dipole | ||
|
||
class One(NodeFeature): | ||
|
||
@staticmethod | ||
def get_irreps(basis_table): | ||
from e3nn import o3 | ||
return o3.Irreps("1x0e") | ||
|
||
@staticmethod | ||
def get_feature(config, data_processor): | ||
|
||
n_atoms = len(config.positions) | ||
|
||
z_dipole = np.array([1.0]) | ||
|
||
z_dipole = np.tile(z_dipole, n_atoms).reshape(n_atoms, 1) | ||
|
||
return z_dipole |
Oops, something went wrong.