How to use the megnet.data.graph.Converter function in megnet

To help you get started, we’ve selected a few megnet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github materialsvirtuallab / megnet / megnet / data / graph.py View on Github external
def convert(self, d: np.ndarray) -> np.ndarray:
        """
        expand distance vector d with given parameters

        Args:
            d: (1d array) distance array

        Returns
            (matrix) N*M matrix with N the length of d and M the length of centers
        """
        d = np.array(d)
        return np.exp(-(d[:, None] - self.centers[None, :]) ** 2 / self.width ** 2)


class MoorseLongRange(Converter):
    """
    This is an attempt to implement a Moorse/long range interactomic potential like
    distance expansion. The distance is expanded with this basis at different equilibrium
    bond distance, r_eq. It is still a work in progress. Do not use if you do not know
    much about the parameters
    ref: https://en.wikipedia.org/wiki/Morse/Long-range_potential#Function

    Args:
        d_e: (float) dissociate energy
        r_ref: (float) reference bond length
        r_eq: (list) equilibrium bond length
        p: (int) exponential term in the original equation, see ref
        q: (int) exponential term in the original equaiton, see ref
        cm: (list) long range coefficients in u_LR = \Sigma_i_N (cm_i / r^i)
        betas: (list) parameters determining the transition between long range and short range
    """
github materialsvirtuallab / megnet / megnet / data / graph.py View on Github external
self.feature_matrix = np.array(feature_matrix)

    def convert(self, int_array: np.ndarray) -> np.ndarray:
        """
        convert atomic number to row vectors in the feature_matrix

        Args:
            int_array: (1d array) number array of length L

        Returns
            (matrix) L*M matrix with N the length of d and M the length of centers
        """
        return self.feature_matrix[int_array]


class GaussianDistance(Converter):
    """
    Expand distance with Gaussian basis sit at centers and with width 0.5.

    Args:
        centers: (np.array)
        width: (float)
    """

    def __init__(self, centers: np.ndarray = np.linspace(0, 5, 100), width=0.5):
        self.centers = centers
        self.width = width

    def convert(self, d: np.ndarray) -> np.ndarray:
        """
        expand distance vector d with given parameters
github materialsvirtuallab / megnet / megnet / data / graph.py View on Github external
else:
            return {'atom': atoms,
                    'bond': bonds,
                    'state': state_attributes,
                    'index1': index1,
                    'index2': index2
                    }

    @classmethod
    def from_structure_graph(cls, structure_graph: StructureGraph) -> 'StructureGraphFixedRadius':
        return cls(nn_strategy=structure_graph.nn_strategy,
                   atom_converter=structure_graph.atom_converter,
                   bond_converter=structure_graph.bond_converter)


class DummyConverter(Converter):
    """
    Dummy converter as a placeholder
    """

    def convert(self, d: Any) -> Any:
        return d


class EmbeddingMap(Converter):
    """
    Convert an integer to a row vector in a feature matrix

    Args:
        feature_matrix: (np.ndarray) A matrix of shape (N, M)
    """
github materialsvirtuallab / megnet / megnet / data / graph.py View on Github external
def from_structure_graph(cls, structure_graph: StructureGraph) -> 'StructureGraphFixedRadius':
        return cls(nn_strategy=structure_graph.nn_strategy,
                   atom_converter=structure_graph.atom_converter,
                   bond_converter=structure_graph.bond_converter)


class DummyConverter(Converter):
    """
    Dummy converter as a placeholder
    """

    def convert(self, d: Any) -> Any:
        return d


class EmbeddingMap(Converter):
    """
    Convert an integer to a row vector in a feature matrix

    Args:
        feature_matrix: (np.ndarray) A matrix of shape (N, M)
    """

    def __init__(self, feature_matrix: np.ndarray):
        self.feature_matrix = np.array(feature_matrix)

    def convert(self, int_array: np.ndarray) -> np.ndarray:
        """
        convert atomic number to row vectors in the feature_matrix

        Args:
            int_array: (1d array) number array of length L