Exporting and Importing

GRANAD lets you save orbitals to xyz files. It also offers rudimentary support for loading orbitals from xyz files. For demonstration, we will create a triangular flake, print its xyz representation, save it to file and reload it.

from granad import MaterialCatalog, Triangle, OrbitalList
graphene = MaterialCatalog.get( "graphene" )
flake = graphene.cut_flake( Triangle(15)  )

We can look at only the atoms in this file. They are given as a dictionary. The type of atom is the key. The value is all positions where atoms of this type are.

print(flake.atoms)
defaultdict(<class 'list'>, {'C': [['0.7101408311032396', '1.23', '0.0'], ['2.1304224933097187', '1.23', '0.0'], ['0.0', '2.46', '0.0'], ['0.7101408311032396', '3.6900000000000004', '0.0'], ['2.1304224933097187', '3.6900000000000004', '0.0'], ['2.840563324412959', '2.46', '0.0'], ['4.260844986619438', '2.46', '0.0'], ['4.970985817722679', '3.6900000000000004', '0.0'], ['6.391267479929158', '3.6900000000000004', '0.0'], ['0.0', '4.92', '0.0'], ['0.7101408311032396', '6.1499999999999995', '0.0'], ['2.1304224933097187', '6.1499999999999995', '0.0'], ['2.840563324412959', '4.92', '0.0'], ['4.260844986619438', '4.92', '0.0'], ['4.970985817722679', '6.1499999999999995', '0.0'], ['6.391267479929158', '6.1499999999999995', '0.0'], ['7.1014083110323964', '4.92', '0.0'], ['8.521689973238875', '4.92', '0.0'], ['9.231830804342117', '6.1499999999999995', '0.0'], ['10.652112466548594', '6.1499999999999995', '0.0'], ['0.0', '7.38', '0.0'], ['0.7101408311032396', '8.61', '0.0'], ['2.1304224933097187', '8.61', '0.0'], ['2.840563324412959', '7.38', '0.0'], ['4.260844986619438', '7.38', '0.0'], ['4.970985817722679', '8.61', '0.0'], ['6.391267479929158', '8.61', '0.0'], ['7.1014083110323964', '7.38', '0.0'], ['8.521689973238875', '7.38', '0.0'], ['9.231830804342117', '8.61', '0.0'], ['10.652112466548594', '8.61', '0.0'], ['11.362253297651833', '7.38', '0.0'], ['0.0', '9.84', '0.0'], ['0.7101408311032396', '11.07', '0.0'], ['2.1304224933097187', '11.07', '0.0'], ['2.840563324412959', '9.84', '0.0'], ['4.260844986619438', '9.84', '0.0'], ['4.970985817722679', '11.07', '0.0'], ['6.391267479929158', '11.07', '0.0'], ['7.1014083110323964', '9.84', '0.0'], ['8.521689973238875', '9.84', '0.0'], ['0.0', '12.3', '0.0'], ['0.7101408311032396', '13.530000000000001', '0.0'], ['2.1304224933097187', '13.530000000000001', '0.0'], ['2.840563324412959', '12.3', '0.0'], ['4.260844986619438', '12.3', '0.0']]})

If you supply no name to the to_xyz method, it will return the string

print(flake.to_xyz())
46

C 0.7101408311032396 1.23 0.0
C 2.1304224933097187 1.23 0.0
C 0.0 2.46 0.0
C 0.7101408311032396 3.6900000000000004 0.0
C 2.1304224933097187 3.6900000000000004 0.0
C 2.840563324412959 2.46 0.0
C 4.260844986619438 2.46 0.0
C 4.970985817722679 3.6900000000000004 0.0
C 6.391267479929158 3.6900000000000004 0.0
C 0.0 4.92 0.0
C 0.7101408311032396 6.1499999999999995 0.0
C 2.1304224933097187 6.1499999999999995 0.0
C 2.840563324412959 4.92 0.0
C 4.260844986619438 4.92 0.0
C 4.970985817722679 6.1499999999999995 0.0
C 6.391267479929158 6.1499999999999995 0.0
C 7.1014083110323964 4.92 0.0
C 8.521689973238875 4.92 0.0
C 9.231830804342117 6.1499999999999995 0.0
C 10.652112466548594 6.1499999999999995 0.0
C 0.0 7.38 0.0
C 0.7101408311032396 8.61 0.0
C 2.1304224933097187 8.61 0.0
C 2.840563324412959 7.38 0.0
C 4.260844986619438 7.38 0.0
C 4.970985817722679 8.61 0.0
C 6.391267479929158 8.61 0.0
C 7.1014083110323964 7.38 0.0
C 8.521689973238875 7.38 0.0
C 9.231830804342117 8.61 0.0
C 10.652112466548594 8.61 0.0
C 11.362253297651833 7.38 0.0
C 0.0 9.84 0.0
C 0.7101408311032396 11.07 0.0
C 2.1304224933097187 11.07 0.0
C 2.840563324412959 9.84 0.0
C 4.260844986619438 9.84 0.0
C 4.970985817722679 11.07 0.0
C 6.391267479929158 11.07 0.0
C 7.1014083110323964 9.84 0.0
C 8.521689973238875 9.84 0.0
C 0.0 12.3 0.0
C 0.7101408311032396 13.530000000000001 0.0
C 2.1304224933097187 13.530000000000001 0.0
C 2.840563324412959 12.3 0.0
C 4.260844986619438 12.3 0.0

To save this to a file, do

flake.to_xyz('flake.xyz')

Reloading is limited: all atoms in the xyz file get the same group id by default.

new_flake = OrbitalList.from_xyz('flake.xyz')
assert new_flake.atoms == flake.atoms