[docs]classApplyCalculator(zntrack.Node):""" Apply a calculator to a list of atoms objects and store the results in a H5MD file. Parameters ---------- data : list[ase.Atoms] List of atoms objects to calculate. model : NodeWithCalculator, optional Node providing the calculator object to apply to the data. """data:list[ase.Atoms]=zntrack.deps()model:NodeWithCalculator|None=zntrack.deps()frames_path:pathlib.Path=zntrack.outs_path(zntrack.nwd/"frames.h5")defrun(self):frames=[]ifself.modelisnotNone:calc=self.model.get_calculator()# Some calculators, e.g. MACE do not follow the ASE API correctly.# and we need to fix some keys in `all_properties`all_properties.append("node_energy")foratomsintqdm.tqdm(self.data):atoms.calc=calcatoms.get_potential_energy()frames.append(freeze_copy_atoms(atoms))else:frames=self.dataio=znh5md.IO(self.frames_path)io.extend(frames)@propertydefframes(self)->list[ase.Atoms]:withself.state.fs.open(self.frames_path,"rb")asf:withh5py.File(f)asfile:returnlist(znh5md.IO(file_handle=file))