Getting started with pyscal¶
This example illustrates basic functionality of pyscal python library by setting up a system and the atoms.
import pyscal as pc import numpy as np
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-
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.
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
[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
Atomclass. Here, we will only look at the basic properties of
Atomclass. For a more detailed description, check the examples.
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.
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
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
[0.0, 0.0, 0.0]
Now that we have created the atoms, we can assign them to the system. We can also assign the same box we created before.
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.
[<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,
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
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.
atom = sys.atoms atom.type = 2
Lets verify if it was done properly
Now we can push the atom back to the system with the new type
Reading in an input file¶
Systemis ready for calculations. However, in most realistic simulation situations, we have many atoms and it can be difficult to set each of them
pyscalcan also read in POSCAR files. In principle,
pyscalonly 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
sys = pc.System() sys.read_inputfile('conf.dump')
Once again, lets check if the box dimensions are read in correctly
[[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
[-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.