Getting started with pyscal#
The System class#
System is the central class in pyscal. It is required for setting up calculations. We start by importing the class,
[1]:
from pyscal import System
And then create a system
[2]:
sys = System()
sys is a System object. But at this point, it is completely empty. We have to provide the system with the following information- * the simulation box dimensions * the positions of individual atoms.
[3]:
sys.box = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
We can easily check if everything worked by getting the box dimensions
[4]:
sys.box
[4]:
[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
The Atoms class#
We start by importing the Atoms class
[5]:
from pyscal import Atoms
The next part is assigning the atoms. This can be done using the Atom class.
First, we prepare the positions
[8]:
adict = {"positions": [[0, 0, 0], [0.5, 0.5, 0.5]]}
Now we can create atoms
[9]:
atoms = Atoms(adict)
Atoms is python class and you can access the various keys.
[11]:
atoms.positions
[11]:
[[0, 0, 0], [0.5, 0.5, 0.5]]
It is also a dictionary and you can check the available keys.
[12]:
atoms.keys()
[12]:
dict_keys(['positions', 'ids', 'ghost', 'types', 'species', 'mask_1', 'mask_2', 'condition', 'head'])
There are more keys that were auto-generated, which is not important for us for the moment.
For more details about the Atoms class, please see further examples.
Combining System and Atoms#
Now we can add the atoms to the System we created before.
[13]:
sys.atoms = atoms
System is ready for calculations. However, in most realistic simulation situations, we have many atoms and it can be difficult to set each of them[14]:
sys = System('conf.dump')
[16]:
sys.atoms.positions[:5]
[16]:
[[-5.66782, -6.06781, -6.58151],
[-3.61832, -5.66888, -5.46712],
[-0.947172, 10.3193, 11.3033],
[-0.10301, -6.35752, -6.44787],
[1.61271, -5.30872, -7.68795]]
Alternatively, it can be a two-step process
[17]:
sys = System()
[18]:
sys.read_inputfile('conf.dump')
The read_inputfile function supports a number of other options as well.
[19]:
sys.read_inputfile?
Signature:
sys.read_inputfile(
filename,
format='lammps-dump',
compressed=False,
customkeys=None,
)
Docstring:
Read input file that contains the information of system configuration.
Parameters
----------
filename : string
name of the input file.
format : {'lammps-dump', 'poscar', 'ase', 'mdtraj'}
format of the input file, in case of `ase` the ASE Atoms object
compressed : bool, optional
If True, force to read a `gz` compressed format, default False.
customkeys : list
A list containing names of headers of extra data that needs to be read in from the
input file.
Returns
-------
None
Notes
-----
`format` keyword specifies the format of the input file. Currently only
a `lammps-dump` and `poscar` files are supported. Additionaly, the widely
use Atomic Simulation environment (https://wiki.fysik.dtu.dk/ase/ase/ase.html).
mdtraj objects (http://mdtraj.org/1.9.3/) are also supported by using the keyword
`'mdtraj'` for format. Please note that triclinic boxes are not yet supported for
mdtraj format.
Atoms object can also be used directly. This function uses the
:func:`~pyscal.traj_process` module to process a file which is then assigned to system.
`compressed` keyword is not required if a file ends with `.gz` extension, it is
automatically treated as a compressed file.
Triclinic simulation boxes can also be read in.
If `custom_keys` are provided, this extra information is read in from input files if
available. This information is can be accessed directly as `self.atoms['customkey']`
File: ~/miniconda3/envs/pyscal-test/lib/python3.10/site-packages/pyscal/core.py
Type: method
[ ]: