megnet.models.megnet module¶
Implements megnet models.
- class MEGNetModel(nfeat_edge: Optional[int] = None, nfeat_global: Optional[int] = None, nfeat_node: Optional[int] = None, nblocks: int = 3, lr: float = 0.001, n1: int = 64, n2: int = 32, n3: int = 16, nvocal: int = 95, embedding_dim: int = 16, nbvocal: Optional[int] = None, bond_embedding_dim: Optional[int] = None, ngvocal: Optional[int] = None, global_embedding_dim: Optional[int] = None, npass: int = 3, ntarget: int = 1, act: Callable = <function softplus2>, is_classification: bool = False, loss: str = 'mse', metrics: Optional[List[str]] = None, l2_coef: Optional[float] = None, dropout: Optional[float] = None, graph_converter: Optional[megnet.data.graph.StructureGraph] = None, target_scaler: megnet.utils.preprocessing.Scaler = <megnet.utils.preprocessing.DummyScaler object>, optimizer_kwargs: Dict = {'clipnorm': 3}, dropout_on_predict: bool = False, sample_weight_mode: Optional[str] = None, **kwargs)[source]¶
Bases:
megnet.models.base.GraphModel
Construct a graph network model with or without explicit atom features if n_feature is specified then a general graph model is assumed, otherwise a crystal graph model with z number as atom feature is assumed.
- Parameters
nfeat_edge – (int) number of bond features
nfeat_global – (int) number of state features
nfeat_node – (int) number of atom features
nblocks – (int) number of MEGNetLayer blocks
lr – (float) learning rate
n1 – (int) number of hidden units in layer 1 in MEGNetLayer
n2 – (int) number of hidden units in layer 2 in MEGNetLayer
n3 – (int) number of hidden units in layer 3 in MEGNetLayer
nvocal – (int) number of total element
embedding_dim – (int) number of embedding dimension
nbvocal – (int) number of bond types if bond attributes are types
bond_embedding_dim – (int) number of bond embedding dimension
ngvocal – (int) number of global types if global attributes are types
global_embedding_dim – (int) number of global embedding dimension
npass – (int) number of recurrent steps in Set2Set layer
ntarget – (int) number of output targets
act – (object) activation function
l2_coef – (float or None) l2 regularization parameter
is_classification – (bool) whether it is a classification task
loss – (object or str) loss function
metrics – (list or dict) List or dictionary of Keras metrics to be evaluated by the model during training and testing
dropout – (float) dropout rate
graph_converter – (object) object that exposes a “convert” method for structure to graph conversion
target_scaler – (object) object that exposes a “transform” and “inverse_transform” methods for transforming the target values
optimizer_kwargs (dict) – extra keywords for optimizer, for example clipnorm and clipvalue
sample_weight_mode (str) – sample weight mode for compilation
kwargs (dict) – in the case where bond inputs are pure distances (not the expanded distances nor integers for embedding, i.e., nfeat_edge=None and bond_embedding_dim=None), kwargs can take additional inputs for expand the distance using Gaussian basis. centers (np.ndarray): array for defining the Gaussian expansion centers width (float): width for the Gaussian basis
- classmethod from_mvl_models(name: str) megnet.models.base.GraphModel [source]¶
load model using mvl model names :param name: model name string. Please check
megnet.utils.models.AVAILABEL_MODELS for available models
Returns: GraphModel instance
- classmethod from_url(url: str) megnet.models.base.GraphModel [source]¶
Download and load a model from a URL. E.g. https://github.com/materialsvirtuallab/megnet/blob/master/mvl_models/mp-2019.4.1/formation_energy.hdf5
- Parameters
url – (str) url link of the model
- Returns
GraphModel
- make_megnet_model(nfeat_edge: Optional[int] = None, nfeat_global: Optional[int] = None, nfeat_node: Optional[int] = None, nblocks: int = 3, n1: int = 64, n2: int = 32, n3: int = 16, nvocal: int = 95, embedding_dim: int = 16, nbvocal: Optional[int] = None, bond_embedding_dim: Optional[int] = None, ngvocal: Optional[int] = None, global_embedding_dim: Optional[int] = None, npass: int = 3, ntarget: int = 1, act: Callable = <function softplus2>, is_classification: bool = False, l2_coef: Optional[float] = None, dropout: Optional[float] = None, dropout_on_predict: bool = False, **kwargs) keras.engine.training.Model [source]¶
Make a MEGNet Model :param nfeat_edge: (int) number of bond features :param nfeat_global: (int) number of state features :param nfeat_node: (int) number of atom features :param nblocks: (int) number of MEGNetLayer blocks :param n1: (int) number of hidden units in layer 1 in MEGNetLayer :param n2: (int) number of hidden units in layer 2 in MEGNetLayer :param n3: (int) number of hidden units in layer 3 in MEGNetLayer :param nvocal: (int) number of total element :param embedding_dim: (int) number of embedding dimension :param nbvocal: (int) number of bond types if bond attributes are types :param bond_embedding_dim: (int) number of bond embedding dimension :param ngvocal: (int) number of global types if global attributes are types :param global_embedding_dim: (int) number of global embedding dimension :param npass: (int) number of recurrent steps in Set2Set layer :param ntarget: (int) number of output targets :param act: (object) activation function :param l2_coef: (float or None) l2 regularization parameter :param is_classification: (bool) whether it is a classification task :param dropout: (float) dropout rate :param dropout_on_predict: Whether to use dropout during prediction and training :type dropout_on_predict: bool :param kwargs: in the case where bond inputs are pure distances (not the expanded
distances nor integers for embedding, i.e., nfeat_edge=None and bond_embedding_dim=None), kwargs can take additional inputs for expand the distance using Gaussian basis.
centers (np.ndarray): array for defining the Gaussian expansion centers width (float): width for the Gaussian basis
- Returns
(Model) Keras model, ready to run