Skip to content

Commit

Permalink
tests: Redistributed test modules appropriately
Browse files Browse the repository at this point in the history
  • Loading branch information
Somerandomguy10111 committed Jun 23, 2024
1 parent cac85ac commit 5d20d54
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 48 deletions.
27 changes: 2 additions & 25 deletions tests/t_crystal/t_fromcif.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,11 @@ def test_angles(self):
self.assertAlmostEqual(beta, beta_exp, places=3)
self.assertEqual(gamma, gamma_exp)

def test_volume_uc(self):
expected_volumes = [364.21601704000005, 1205.5]
for crystal, volume_exp in zip(self.crystals, expected_volumes):
self.assertAlmostEqual(crystal.volume_uc, volume_exp, places=5)

def test_num_atoms(self):
expected_atom_counts = [16, 44]
expected_atom_counts = [4*4, (11+14+2+5)*4]
for crystal, num_atoms_exp in zip(self.crystals, expected_atom_counts):
self.assertEqual(crystal.num_atoms, num_atoms_exp)

def test_wyckoff_symbols(self):
expected_symbols = [
['d', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'c', 'c', 'c', 'c', 'd', 'd', 'd', 'd'],
['C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'O', 'O', 'O', 'O', 'O', 'O', 'N', 'N', 'H', 'H',
'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H']
]
for crystal, symbols_exp in zip(self.crystals, expected_symbols):
self.assertEqual(crystal.wyckoff_symbols, symbols_exp)

def test_crystal_system(self):
expected_systems = ['orthorhombic', 'monoclinic']
for crystal, system_exp in zip(self.crystals, expected_systems):
self.assertEqual(crystal.crystal_system, system_exp)

def test_space_group(self):
expected_space_groups = [57, 14]
for crystal, space_group_exp in zip(self.crystals, expected_space_groups):
self.assertEqual(crystal.space_group, space_group_exp)
self.assertEqual(len(crystal.base), num_atoms_exp)


if __name__ == "__main__":
Expand Down
58 changes: 35 additions & 23 deletions tests/t_crystal/t_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,7 @@ def test_atomic_volume(self):
for crystal in self.crystals:
print(f'self.crystal atomic volume fraction = {crystal.packing_density}')

def test_scaling(self):
for crystal in self.crystals:
target_density = 0.5
crystal.scale(target_density=target_density)
print(f'Packing density, target density = {crystal.packing_density}, {target_density}')
print(f'Volume scaling = {crystal.packing_density / target_density}')
print(f'New primitives = {crystal.lengths.as_tuple()}')
print(f'New packing density = {crystal.packing_density}')
self.assertEqual(round(crystal.packing_density, 2), round(target_density, 2))


def test_spacegroup_calculation(self):
for spg, crystal in zip(self.spgs,self.crystals):
crystal.calculate_properties()
computed_sg = crystal.space_group
print(f'Computed, actual spg = {computed_sg}, {spg}')

if computed_sg != spg:
raise ValueError(f'Computed spg {computed_sg} does not match actual spg {spg} given in cif file')


def test_to_pymatgen_faithfulness(self):
def test_pymatgen(self):
for struct, crystal in zip(self.pymatgen_structures, self.crystals):
actual = crystal.to_pymatgen()
expected = struct
Expand All @@ -46,7 +25,40 @@ def test_to_pymatgen_faithfulness(self):

print(f'Composition = {actual.composition}')

def test_spacegroup_calculation(self):
for spg, crystal in zip(self.spgs,self.crystals):
crystal.calculate_properties()
computed_sg = crystal.space_group
print(f'Computed, actual spg = {computed_sg}, {spg}')

if computed_sg != spg:
raise ValueError(f'Computed spg {computed_sg} does not match actual spg {spg} given in cif file')


def test_volume_uc(self):
expected_volumes = [364.21601704000005, 1205.5]
for crystal, volume_exp in zip(self.crystals, expected_volumes):
self.assertAlmostEqual(crystal.volume_uc, volume_exp, places=5)


def test_wyckoff_symbols(self):
expected_symbols = [
['d', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'c', 'c', 'c', 'c', 'd', 'd', 'd', 'd'],
['C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'O', 'O', 'O', 'O', 'O', 'O', 'N', 'N', 'H', 'H',
'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H']
]
for crystal, symbols_exp in zip(self.crystals, expected_symbols):
self.assertEqual(crystal.wyckoff_symbols, symbols_exp)

def test_crystal_system(self):
expected_systems = ['orthorhombic', 'monoclinic']
for crystal, system_exp in zip(self.crystals, expected_systems):
self.assertEqual(crystal.crystal_system, system_exp)

def test_space_group(self):
expected_space_groups = [57, 14]
for crystal, space_group_exp in zip(self.crystals, expected_space_groups):
self.assertEqual(crystal.space_group, space_group_exp)

if __name__ == '__main__':
TestPropertyCalculation.execute_all()

14 changes: 14 additions & 0 deletions tests/t_crystal/t_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ def setUp(self):
self.mock_crystal = crystal


def test_scaling(self):
target_density = 0.5
self.mock_crystal.scale(target_density=target_density)
print(f'Packing density, target density = {self.mock_crystal.packing_density}, {target_density}')
print(f'Volume scaling = {self.mock_crystal.packing_density / target_density}')
print(f'New primitives = {self.mock_crystal.lengths.as_tuple()}')
print(f'New packing density = {self.mock_crystal.packing_density}')
self.assertEqual(round(self.mock_crystal.packing_density, 2), round(target_density, 2))


def test_standardization(self):
self.mock_crystal.standardize()
expected_species_list = ['O', 'Si', Void.symbol]
Expand All @@ -42,3 +52,7 @@ def get_site_symbol(site : AtomicSite):
else:
symbol = site.species.element.symbol
return symbol


if __name__ == "__main__":
TestCrystalStandardization.execute_all()

0 comments on commit 5d20d54

Please sign in to comment.