| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# |
| 3 |
# Copyright (c) 2017, the cclib development team |
| 4 |
# |
| 5 |
# This file is part of cclib (http://cclib.github.io) and is distributed under |
| 6 |
# the terms of the BSD 3-Clause License. |
| 7 |
|
| 8 |
"""Unit tests for XYZ reader.""" |
| 9 |
|
| 10 |
import os |
| 11 |
import unittest |
| 12 |
|
| 13 |
import numpy as np |
| 14 |
|
| 15 |
import cclib |
| 16 |
|
| 17 |
|
| 18 |
__filedir__ = os.path.dirname(__file__) |
| 19 |
__filepath__ = os.path.realpath(__filedir__) |
| 20 |
__datadir__ = os.path.join(__filepath__, "..", "..") |
| 21 |
|
| 22 |
|
| 23 |
class XYZReaderTest(unittest.TestCase): |
| 24 |
|
| 25 |
def test_attributes_one(self): |
| 26 |
"""Is an XYZ file with a single geometry read into a ccData properly? |
| 27 |
""" |
| 28 |
fpath = os.path.join(__datadir__, "test/bridge/uracil.xyz") |
| 29 |
xyz = cclib.io.xyzreader.XYZ(fpath) |
| 30 |
data = xyz.parse() |
| 31 |
|
| 32 |
self.assertEqual(data.natom, 12) |
| 33 |
|
| 34 |
atomnos = np.array([7, 6, 1, 8, 7, 6, 8, 6, 6, 1, 1, 1], dtype=int) |
| 35 |
np.testing.assert_equal(data.atomnos, atomnos) |
| 36 |
|
| 37 |
self.assertEqual(data.atomcoords.shape, (1, 12, 3)) |
| 38 |
|
| 39 |
def test_attributes_two(self): |
| 40 |
"""Is an XYZ file with a two geometries read into a ccData properly? |
| 41 |
""" |
| 42 |
fpath = os.path.join(__filedir__, "data/uracil_two.xyz") |
| 43 |
xyz = cclib.io.xyzreader.XYZ(fpath) |
| 44 |
data = xyz.parse() |
| 45 |
|
| 46 |
self.assertEqual(data.natom, 12) |
| 47 |
|
| 48 |
atomnos = np.array([7, 6, 1, 8, 7, 6, 8, 6, 6, 1, 1, 1], dtype=int) |
| 49 |
np.testing.assert_equal(data.atomnos, atomnos) |
| 50 |
|
| 51 |
self.assertEqual(data.atomcoords.shape, (2, 12, 3)) |
| 52 |
self.assertEqual(data.metadata["comments"], ["uracil", " Energy: -97.0646597"]) |
| 53 |
|
| 54 |
|
| 55 |
if __name__ == "__main__": |
| 56 |
unittest.main() |