Skip to content

Commit

Permalink
fix tests data file path
Browse files Browse the repository at this point in the history
  • Loading branch information
abelcarreras committed Apr 26, 2022
1 parent 94f34ff commit 110a775
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
12 changes: 8 additions & 4 deletions tests/test_file_io.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import unittest
from cosymlib import file_io
from numpy import testing
import os


data_dir = os.path.join(os.path.dirname(__file__), 'data')


class TestPointGroup(unittest.TestCase):
Expand All @@ -16,7 +20,7 @@ def test_reading_xyz(self):
[ 0.2051, 0.8240, -0.6786],
[ 0.3345, -0.9314, -0.4496],
[-1.0685, -0.0537, 0.1921]]
structure = file_io.get_geometry_from_file_xyz('data/file_io/test.xyz', read_multiple=True)
structure = file_io.get_geometry_from_file_xyz(data_dir + '/file_io/test.xyz', read_multiple=True)
testing.assert_array_equal(structure[0].get_positions(), methane)
testing.assert_array_equal(structure[1].get_positions(), ammonium)
self.assertEqual(structure[0].get_symbols(), ['C', 'H', 'H', 'H', 'H'])
Expand All @@ -35,7 +39,7 @@ def test_reading_cor(self):
[7.85296, 1.80990, 1.32660],
[4.85354, 1.20560, -1.32660],
[8.03285, 0.37875, -0.26075]]
structures = file_io.get_geometry_from_file_cor('data/file_io/test.cor', read_multiple=True)
structures = file_io.get_geometry_from_file_cor(data_dir +'/file_io/test.cor', read_multiple=True)
testing.assert_array_equal(structures[0].get_positions(), structure1)
testing.assert_array_equal(structures[1].get_positions(), structure2)
self.assertEqual(structures[0].get_symbols(), ['Pd', 'N', 'N', 'N', 'N'])
Expand All @@ -48,7 +52,7 @@ def test_reading_fchk(self):
beta_occupancy = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
alpha_electrons = 18
beta_electrons = 18
molecule = file_io.get_molecule_from_file_fchk('data/file_io/test.fchk', read_multiple=False)
molecule = file_io.get_molecule_from_file_fchk(data_dir + '/file_io/test.fchk', read_multiple=False)
self.assertEqual(molecule.electronic_structure.alpha_occupancy, alpha_occupancy)
self.assertEqual(molecule.electronic_structure.beta_occupancy, beta_occupancy)
self.assertEqual(molecule.electronic_structure.alpha_electrons, alpha_electrons)
Expand All @@ -59,7 +63,7 @@ def test_readinf_molden(self):
beta_occupancy = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
alpha_electrons = 13
beta_electrons = 13
molecule = file_io.get_molecule_from_file_molden('data/file_io/test.molden', read_multiple=False)
molecule = file_io.get_molecule_from_file_molden(data_dir + '/file_io/test.molden', read_multiple=False)
self.assertEqual(molecule.electronic_structure.alpha_occupancy, alpha_occupancy)
self.assertEqual(molecule.electronic_structure.beta_occupancy, beta_occupancy)
self.assertEqual(molecule.electronic_structure.alpha_electrons, alpha_electrons)
Expand Down
6 changes: 5 additions & 1 deletion tests/test_point_group.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import unittest
from cosymlib import file_io, Cosymlib
import os


data_dir = os.path.join(os.path.dirname(__file__), 'data')


class TestPointGroup(unittest.TestCase):
Expand All @@ -8,7 +12,7 @@ def test(self):
point_groups = ['C1', 'Cs', 'Ci', 'Cinfh', 'Dinfh', 'C2', 'C3', 'C2h', 'C3h', 'C2v', 'C3v', 'C4v', 'C5v', 'D2',
'D3', 'D2h', 'D3h', 'D4h', 'D5h', 'D6h', 'D7h', 'D8h', 'D2d', 'D3d', 'D4d', 'D5d', 'D6d', 'D8d',
'S4', 'T', 'Th', 'Td', 'O', 'Oh']
molecules = file_io.read_generic_structure_file('data/point_group/sym_molecules.xyz', read_multiple=True)
molecules = file_io.read_generic_structure_file(data_dir + '/point_group/sym_molecules.xyz', read_multiple=True)
symobj = Cosymlib(molecules)
calculated_point_groups = [pg for pg in (symobj.get_point_group())]
for pg1, pg2 in zip(point_groups, calculated_point_groups):
Expand Down
24 changes: 14 additions & 10 deletions tests/test_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
from cosymlib import file_io
import cosymlib.shape as shape
import cosymlib.shape.maps as maps
import os


data_dir = os.path.join(os.path.dirname(__file__), 'data')


class TestShape(unittest.TestCase):

def test_example01(self):
molecules, options = classic_inputs.read_old_input('data/shape/example01.dat')
molecules, options = classic_inputs.read_old_input(data_dir + '/shape/example01.dat')
reference_polyhedron = []
for number in options['%labels']:
reference_polyhedron.append(shape.tools.get_shape_label(int(number), options['%n_atoms']))
Expand All @@ -29,7 +33,7 @@ def test_example02(self):
[5.047, 36.698],
[5.234, 36.822],
[5.1, 36.733]]
molecules, options = classic_inputs.read_old_input('data/shape/example02.dat')
molecules, options = classic_inputs.read_old_input(data_dir + '/shape/example02.dat')
reference_polyhedron = []
for number in options['%labels']:
reference_polyhedron.append(shape.tools.get_shape_label(int(number), options['%n_atoms']))
Expand All @@ -44,7 +48,7 @@ def test_example02(self):
def test_example03(self):
nice_measures = [[31.375, 0.97],
[33.44, 0.16]]
molecules, options = classic_inputs.read_old_input('data/shape/example03.dat')
molecules, options = classic_inputs.read_old_input(data_dir + '/shape/example03.dat')
reference_polyhedron = []
for number in options['%labels']:
reference_polyhedron.append(shape.tools.get_shape_label(int(number), options['%n_atoms']))
Expand Down Expand Up @@ -79,7 +83,7 @@ def test_example04(self):
[-5.66862241e-01, -1.42522607e+00, 1.26951447e+00],
[-1.72449417e+00, 9.49990377e-01, 2.96491640e-01],
[1.72449417e+00, -9.49990377e-01, -2.96491640e-01]]
molecules, options = classic_inputs.read_old_input('data/shape/example04.dat')
molecules, options = classic_inputs.read_old_input(data_dir + '/shape/example04.dat')
reference_polyhedron = []
for number in options['%labels']:
reference_polyhedron.append(shape.tools.get_shape_label(int(number), options['%n_atoms']))
Expand Down Expand Up @@ -125,7 +129,7 @@ def test_example05(self):
[15.097, 0.05],
[16.737, 0.]])

molecules, options = classic_inputs.read_old_input('data/shape/example05.dat')
molecules, options = classic_inputs.read_old_input(data_dir + '/shape/example05.dat')
reference_polyhedron = []
for number in options['%labels']:
reference_polyhedron.append(shape.tools.get_shape_label(int(number), options['%n_atoms']))
Expand Down Expand Up @@ -164,7 +168,7 @@ def test_example06(self):
4.4, 1.6, 3.5, 3.8, 3.6, 4.7, 4.8, 3.7, 1.8, 1.6, 2.3, 3.7, 3.,
1.3, 0.9, 2.8, 0.9, 4.1, 3.2, 4.6, 1.7, 0.8, 1., 0.7, 0.6, 0.2,
4.6, 1.5, 1.5, 1.7, 2.5, 2.9, 0.5, 0.8, 1.3]
molecules, options = classic_inputs.read_old_input('data/shape/example06.dat')
molecules, options = classic_inputs.read_old_input(data_dir + '/shape/example06.dat')
reference_polyhedron = []
for number in options['%labels']:
reference_polyhedron.append(shape.tools.get_shape_label(int(number), options['%n_atoms']))
Expand All @@ -179,7 +183,7 @@ def test_example06(self):
self.assertTrue(np.allclose(nice_dev_path, devpath, atol=1e-1))

def test_example07(self):
molecules, options = classic_inputs.read_old_input('data/shape/example06.dat')
molecules, options = classic_inputs.read_old_input(data_dir + '/shape/example06.dat')
reference_polyhedron = []
for number in options['%labels']:
reference_polyhedron.append(shape.tools.get_shape_label(int(number), options['%n_atoms']))
Expand All @@ -195,13 +199,13 @@ def test_example07(self):
def test_example08(self):
nice_measures = [[1.976, 3.699],
[6.955, 0.602]]
molecules, options = classic_inputs.read_old_input('data/shape/example08.dat')
molecules, options = classic_inputs.read_old_input(data_dir + '/shape/example08.dat')
central_atom = options['%central_atom']
reference_polyhedron = []
if options['%labels'] != 0:
for number in options['%labels']:
if int(number) == 0:
for ref in file_io.get_geometry_from_file_ref('data/shape/example08.ref', read_multiple=True):
for ref in file_io.get_geometry_from_file_ref(data_dir + '/shape/example08.ref', read_multiple=True):
reference_polyhedron.append(ref)
else:
reference_polyhedron.append(shape.tools.get_shape_label(int(number), options['%n_atoms']))
Expand All @@ -226,5 +230,5 @@ def test_example08(self):
# ref_str1 = shape.shape_tools.order_coordinates(ref_str1, [len(ref_str1), central_atom])
# ref_str2 = shape.shape_tools.get_test_structure('CSAPR-9', central_atom)
# ref_str2 = shape.shape_tools.order_coordinates(ref_str2, [len(ref_str2), central_atom])
# good_results = np.loadtxt('data/shape/example09_results')
# good_results = np.loadtxt(data_dir + '/shape/example09_results')
# self.assertTrue(np.allclose(good_results, ref_str1, atol=1e-3))
6 changes: 5 additions & 1 deletion tests/test_symgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
from cosymlib import file_io
from numpy import testing
from cosymlib.molecule.geometry import Geometry
import os


data_dir = os.path.join(os.path.dirname(__file__), 'data')


class TestSymgroupFchk(unittest.TestCase):

def setUp(self):
self._structure = file_io.read_generic_structure_file('data/wfnsym/tih4_5d.fchk')
self._structure = file_io.read_generic_structure_file(data_dir + '/wfnsym/tih4_5d.fchk')
self._geometry = self._structure.geometry

def test_symmetry_measure(self):
Expand Down
6 changes: 5 additions & 1 deletion tests/test_wfnsym.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import unittest
from cosymlib import file_io
from numpy import testing
import os


data_dir = os.path.join(os.path.dirname(__file__), 'data')


class TestWfnsym(unittest.TestCase):

def setUp(self):
self.structure = file_io.read_generic_structure_file('data/wfnsym/tih4_5d.fchk')
self.structure = file_io.read_generic_structure_file(data_dir + '/wfnsym/tih4_5d.fchk')

def test_symmetry_overlap_analysis(self):
td_labels = ['E', '2C3', '2C3', '2C3', '2C3', 'C2', 'C2', 'C2', '2S4', '2S4', '2S4',
Expand Down

0 comments on commit 110a775

Please sign in to comment.