spainn.calculator
- class calculator.SPaiNNulator(atom_types: numpy.ndarray | torch.Tensor | str | None = None, modelpath: List[str] | str = '', cutoff: float = 10.0, properties: List[str] | None = None, n_states: Dict[str, int] | None = None, thresholds: Dict[str, float] | None = None, nac_key: str = 'nacs')[source]
Interface between SHARC and SchNetPack 2.0
- Parameters:
atom_types (atomic charges or string of atoms)
modelpath (path(s) to trained model(s) or folder(s) with 'best_inference_model') – for adaptive sampling
cutoff (cutoff value)
properties (list of properties returned to SHARC)
n_states (dictionary of calculated states)
thresholds (dictionary of threshold values)
Examples
You can use this calculator to perform predictions of properties using a trained NN model.
Here we show, how to predict the energies for a target molecule. First we import all necessary modules followed by the creation of an ase.Atoms object of the target molecule.
>>> import os, sys >>> import numpy as np >>> import ase >>> >>> symbols = 'CNHHHH' >>> positions = np.array( >>> [[ 0.0000, 0.0000, 0.0000 ], >>> [ 2.4321, 0.0000, 0.0000 ], >>> [-1.0111, 1.7951, 0.0000 ], >>> [ 3.4373, 1.6202, -0.2566 ], >>> [ 3.4373, -1.6202, 0.2566 ], >>> [-1.0111, -1.7951, 0.0000 ]] >>> ) >>> # create ase Atoms object >>> target_mol = ase.Atoms(symbols=symbols, positions=positions)
Next, we define the calculator NacCalculator used to predict the energy of the target molecule and perform the prediction.
>>> from schnetpack.transform import MatScipyNeighborList >>> from spainn.interface import NacCalculator >>> >>> calc = NacCalculator( >>> model_file=os.path.join(os.getcwd(), 'train', 'best_model'), >>> neighbor_list=MatScipyNeighborList(cutoff=10.0) >>> ) >>> target_mol.calc = calc >>> # make prediction >>> pred = target_mol.get_properties(['energy'])
- calculate(sharc_coords: numpy.ndarray | torch.Tensor) Dict[str, List[numpy.ndarray]][source]
Calculate properties from new positions.
If multiple models are used, the average values between the two predictions with the lowest NAC MAE will be returned
- Parameters:
sharc_coords (Coordinates from SHARC simulation)