Beispiel #1
0
    def __init__(self,
                 name: Optional[Union[str, object]] = None,
                 level: Optional[int] = None,
                 **kwargs):
        """

        Args:
            name (str or megnet.models.GraphModel): models name keys, megnet models
                path or a MEGNet GraphModel, if no name is provided, the models will be Eform_MP_2019.
            level (int): megnet graph layer level
        """

        from megnet.utils.models import MODEL_MAPPING, load_model
        from megnet.utils.descriptor import MEGNetDescriptor
        self.AVAILBLE_MODELS = list(MODEL_MAPPING.keys())
        if isinstance(name, str) and name in self.AVAILBLE_MODELS:
            name_or_model = load_model(name)
        elif name is None:
            name_or_model = str(DEFAULT_MODEL)

        else:
            name_or_model = name

        self.describer_model = MEGNetDescriptor(name_or_model)

        if level is None:
            n_layers = sum([
                i.startswith('meg_net')
                for i in self.describer_model.valid_names
            ]) // 3
            level = n_layers
        self.name = name
        self.level = level
        super().__init__(**kwargs)
Beispiel #2
0
    def from_mvl_models(cls, name: str) -> GraphModel:
        """
        load model using mvl model names
        Args:
            name (str): model name string. Please check
                megnet.utils.models.AVAILABEL_MODELS for available models
        Returns: GraphModel instance

        """
        from megnet.utils.models import load_model
        return load_model(name)
Beispiel #3
0
    def __init__(self,
                 name: Optional[Union[str, object]] = None,
                 mode: str = 'site_stats',
                 level: Optional[int] = None,
                 stats: Optional[List] = None,
                 **kwargs):
        """

        Args:s
            name (str or megnet.models.GraphModel): models name keys, megnet models path or
                a MEGNet GraphModel, if no name is provided, the models will be Eform_MP_2019.
            mode (str): choose one from ['site_stats', 'site_readout', 'final'].
                'site_stats': Calculate the site features, and then use maml.utils.stats to compute the feature-wise
                    statistics. This requires the specification of level
                'site_readout': Use the atomic features at the readout stage
                'state': Use the state attributes
                'final': Use the concatenated atom, bond and global features
            level (int): megnet graph layer level
        """
        from megnet.utils.models import MODEL_MAPPING, load_model
        from megnet.utils.descriptor import MEGNetDescriptor
        self.AVAILBLE_MODELS = list(MODEL_MAPPING.keys())
        if isinstance(name, str) and name in self.AVAILBLE_MODELS:
            name_or_model = load_model(name)
        elif name is None:
            name_or_model = str(DEFAULT_MODEL)
        else:
            name_or_model = name

        self.describer_model = MEGNetDescriptor(name_or_model)

        if level is None:
            n_layers = sum([
                i.startswith('meg_net') or i.startswith('megnet')
                for i in self.describer_model.valid_names
            ]) // 3
            level = n_layers

        self.name = name
        self.level = level
        self.mode = mode
        if stats is None:
            stats = [
                'min', 'max', 'range', 'mean', 'mean_absolute_error', 'mode'
            ]
        self.stats = stats
        full_stats, stats_func = get_full_stats_and_funcs(stats)
        self.full_stats = full_stats
        self.stats_func = stats_func
        super().__init__(**kwargs)
Beispiel #4
0
 def test_load_crystal(self):
     model = load_model("Eform_MP_2019")
     self.assertIsInstance(model, GraphModel)
     with self.assertRaises(ValueError):
         _ = load_model("Eform_MP_2020")
Beispiel #5
0
 def test_load_qm9(self):
     model = load_model("QM9_G_2018")
     self.assertIsInstance(model, GraphModel)
Beispiel #6
0
 def from_mvl_models(cls, name: str) -> 'MEGNetModel':
     from megnet.utils.models import load_model
     return load_model(name)