Saving System and Atom objects to file

pyscal offers tools to save System and Atom classes to file. There are two methods to do this. The to_file() method can save a trajectory file which contains all the atom positions and system box dimensions.

The second approach makes use of and numpy.load methods to save the information. Information including calculated neighbors, q values, solidity, voronoi volume etc are all saved. Saving this information is beneficial in systems with a large number of atoms as it saves time which would otherwise be spent recalculating information. The pickle_object module provides the base functions for pickling support as is used internally in System.

import pyscal.core as pc
import pyscal.traj_process as ptp

First a system is set up using an input file

sys = pc.System()

In the next step, the neighbors are calculated, and \(\bar{q}_4\) and \(\bar{q}_6\) are also calculated.

sys.find_neighbors(method='cutoff', cutoff=3.6)
sys.calculate_q([4, 6], averaged=True)

In order to prevent recalculation of neighbors, for example if later we need to calculate \(\bar{q}_8\) and \(\bar{q}_{10}\), we can save the set of systems to a file.

Saving individual system

Single System instances can be saved without pickle_object module directly, similar to how pandas DataFrames are saved to file.


Thats it! The information is saved in the file. Once again, read_systems() can be used to read the System instance. Alternatively, a new System can be created and the information can be read in from a file.

new_sys = pc.System()

This system retains all the information and hence it can be used for further calculations

new_sys.calculate_q([8, 10], averaged=True)

Here \(\bar{q}_8\) and \(\bar{q}_{10}\) were calculated without having to find neighbors again.


pickling can be incompatible with different python versions. As python documentation also points out - pickling objects is not secure. You should only unpickle objects that you trust.