Ensemble Calculators

class mlcalcdriver.calculators.ensemble.Ensemble(modelpaths, device='cpu', units={'dipole_moment': 'Debye', 'energy': 'eV', 'positions': 'angstrom'})[source]

Bases: object

Not a Calculator. This holds the models needed in the actual calculators. Only implemented for SchnetPack models, at the moment. Could be easily expanded.

class mlcalcdriver.calculators.ensemble.EnsembleCalculator(modelpaths, device='cpu', available_properties=None, units={'dipole_moment': 'Debye', 'energy': 'eV', 'positions': 'angstrom'})[source]

Bases: mlcalcdriver.calculators.calculator.Calculator

Calculator using many similarly trained models to approximate a convfidence interval on predictions. Can be used with any Ensemble.

Parameters

available_properties (str or list of str) – Properties that can be predicted by the Calculator. If None, the _get_available_properties method will be used.

property ensemble
Parameters
  • modelpaths (list, tuple or set of str) – Paths to the models

  • SchnetPackCalculators (The other parameters are the same as the base) –

run(property, posinp=None, batch_size=None)[source]

To be implemented for each type of model.

class mlcalcdriver.calculators.ensemble.AseEnsembleCalculator(modelpaths, available_properties=None, device='cpu', **kwargs)[source]

Bases: ase.calculators.calculator.Calculator

Same thing as EnsembleCalculator, but interfaced to use in ASE.

Basic calculator implementation.

restart: str

Prefix for restart file. May contain a directory. Default is None: don’t restart.

ignore_bad_restart_file: bool

Deprecated, please do not use. Passing more than one positional argument to Calculator() is deprecated and will stop working in the future. Ignore broken or missing restart file. By default, it is an error if the restart file is missing or broken.

directory: str or PurePath

Working directory in which to read and write files and perform calculations.

label: str

Name used for all files. Not supported by all calculators. May contain a directory, but please use the directory parameter for that instead.

atoms: Atoms object

Optional Atoms object to which the calculator will be attached. When restarting, atoms will get its positions and unit-cell updated from file.

calculate(atoms=None, properties=['energy'], system_changes=['positions', 'numbers', 'cell', 'pbc', 'initial_charges', 'initial_magmoms'])[source]

Do the calculation.

properties: list of str

List of what needs to be calculated. Can be any combination of ‘energy’, ‘forces’, ‘stress’, ‘dipole’, ‘charges’, ‘magmom’ and ‘magmoms’.

system_changes: list of str

List of what has changed since last calculation. Can be any combination of these six: ‘positions’, ‘numbers’, ‘cell’, ‘pbc’, ‘initial_charges’ and ‘initial_magmoms’.

Subclasses need to implement this, but can ignore properties and system_changes if they want. Calculated properties should be inserted into results dictionary like shown in this dummy example:

self.results = {'energy': 0.0,
                'forces': np.zeros((len(atoms), 3)),
                'stress': np.zeros(6),
                'dipole': np.zeros(3),
                'charges': np.zeros(len(atoms)),
                'magmom': 0.0,
                'magmoms': np.zeros(len(atoms))}

The subclass implementation should first call this implementation to set the atoms attribute and create any missing directories.