atomsengine.py 830 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import ase.io


#===============================================================================
class AtomsEngine(object):
    """Used to parse various different atomic coordinate files.

    Initially use ASE for all file types, if needed add new types or make
    own implementations.
    """

    def parse_atoms(self, contents, index=None, format=None):
        atoms = ase.io.read(contents, index=index, format=format)
        return atoms

    def parse_number(self, contents, format=None):
        atoms = ase.io.read(contents, index=0, format=format)
        n_atoms = atoms.get_number_of_atoms()
        return n_atoms

    def parse_coordinates(self, contents, index, format=None):
        atoms = ase.io.read(contents, index=index, format=format)
        coordinates = atoms.get_positions()
        return coordinates