Getting started with pyscal
This example illustrates basic functionality of pyscal python library by setting up a system and the atoms.
[1]:
import pyscal as pc
import numpy as np
The System
class
System
is the basic class of pyscal and is required to be setup in order to perform any calculations. It can be set up as-
[2]:
sys = pc.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.
[4]:
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
[5]:
sys.box
[5]:
[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
The Atom
class
Atom
class. Here, we will only look at the basic properties of Atom
class. For a more detailed description, check the examples.[6]:
atom1 = pc.Atom()
atom2 = pc.Atom()
Now two empty atom objects are created. The basic poperties of an atom are its positions and id. There are various other properties which can be set here. A detailed description can be found here.
[7]:
atom1.pos = [0., 0., 0.]
atom1.id = 0
atom2.pos = [0.5, 0.5, 0.5]
atom2.id = 1
Alternatively, atom objects can also be set up as
[8]:
atom1 = pc.Atom(pos=[0., 0., 0.], id=0)
atom2 = pc.Atom(pos=[0.5, 0.5, 0.5], id=1)
We can check the details of the atom by querying it
[9]:
atom1.pos
[9]:
[0.0, 0.0, 0.0]
Combining System
and Atom
Now that we have created the atoms, we can assign them to the system. We can also assign the same box we created before.
[10]:
sys = pc.System()
sys.box = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
sys.atoms = [atom1, atom2]
That sets up the system completely. It has both of it’s constituents - atoms and the simulation box. We can check if everything works correctly.
[11]:
sys.atoms
[11]:
[<pyscal.catom.Atom at 0x7f66e9752730>, <pyscal.catom.Atom at 0x7f66e9752930>]
This returns all the atoms of the system. Alternatively a single atom can be accessed by,
[12]:
atom = sys.get_atom(1)
The above call will fetch the atom at position 1 in the list of all atoms in the system. Due to Atom being a completely C++ class, it is necessary to use get_atom()
and set_atom()
to access individual atoms and set them back into the system object after modification. A list of all atoms however can be accessed directly by atoms.
Once you have all the atoms, you can modify any one and add it back to the list of all atoms in the system. The following statement will set the type of the first atom to 2.
[13]:
atom = sys.atoms[0]
atom.type = 2
Lets verify if it was done properly
[14]:
atom.type
[14]:
2
Now we can push the atom back to the system with the new type
[15]:
sys.set_atom(atom)
Reading in an input file
System
is ready for calculations. However, in most realistic simulation situations, we have many atoms and it can be difficult to set each of thempyscal
can also read in POSCAR files. In principle, pyscal
only needs the atom positions and simulation box size, so you can write a python function to process the input file, extract the details and pass to
pyscal
.[16]:
sys = pc.System()
sys.read_inputfile('conf.dump')
Once again, lets check if the box dimensions are read in correctly
[17]:
sys.box
[17]:
[[18.85618, 0.0, 0.0], [0.0, 18.86225, 0.0], [0.0, 0.0, 19.01117]]
Now we can get all atoms that belong to this system
[18]:
len(sys.atoms)
[18]:
500
[19]:
sys.atoms[0].pos
[19]:
[-5.66782, -6.06781, -6.58151]
Thats it! Now we are ready for some calculations. You can find more in the examples section of the documentation.