Initial Work on Reading Crystal and Creation Gaussian Input
This commit is contained in:
0
tests/shared/system/__init__.py
Normal file
0
tests/shared/system/__init__.py
Normal file
19
tests/shared/system/test_atom.py
Normal file
19
tests/shared/system/test_atom.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from crystalpol.shared.system.atom import Atom
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
class TestAtom(unittest.TestCase):
|
||||
def test_atom_instantiation(self):
|
||||
atom = Atom(
|
||||
na=1,
|
||||
rx=0,
|
||||
ry=0,
|
||||
rz=0,
|
||||
)
|
||||
|
||||
self.assertIsInstance(atom, Atom)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
102
tests/shared/system/test_crystal.py
Normal file
102
tests/shared/system/test_crystal.py
Normal file
@@ -0,0 +1,102 @@
|
||||
import unittest
|
||||
|
||||
from crystalpol.shared.system.atom import Atom
|
||||
from crystalpol.shared.system.crystal import Crystal
|
||||
from crystalpol.shared.system.molecule import Molecule
|
||||
|
||||
|
||||
class TestCrystal(unittest.TestCase):
|
||||
def test_class_instantiation(self):
|
||||
# Note that this is not a valid crystal
|
||||
crystal_structure = [
|
||||
['H']
|
||||
]
|
||||
|
||||
crystal = Crystal(crystal_structure)
|
||||
|
||||
self.assertIsInstance(crystal, Crystal)
|
||||
|
||||
def test_is_valid_cell(self):
|
||||
crystal_structure = [
|
||||
['H ']
|
||||
]
|
||||
|
||||
crystal = Crystal(crystal_structure)
|
||||
|
||||
molecule = Molecule("TESTE")
|
||||
molecule.add_atom(
|
||||
Atom(
|
||||
na=1,
|
||||
rx=0,
|
||||
ry=0,
|
||||
rz=0,
|
||||
)
|
||||
)
|
||||
|
||||
self.assertTrue(crystal._is_valid_cell([molecule]))
|
||||
|
||||
molecule.add_atom(
|
||||
Atom(
|
||||
na=1,
|
||||
rx=0,
|
||||
ry=0,
|
||||
rz=0,
|
||||
)
|
||||
)
|
||||
|
||||
self.assertFalse(crystal._is_valid_cell([molecule]))
|
||||
|
||||
def test_add_cell(self):
|
||||
# Note that this is not a valid crystal
|
||||
crystal_structure = [
|
||||
['H ']
|
||||
]
|
||||
|
||||
crystal = Crystal(crystal_structure)
|
||||
|
||||
molecule = Molecule("TESTE")
|
||||
molecule.add_atom(
|
||||
Atom(
|
||||
na=1,
|
||||
rx=0,
|
||||
ry=0,
|
||||
rz=0,
|
||||
)
|
||||
)
|
||||
|
||||
crystal.add_cell([molecule])
|
||||
|
||||
self.assertIsInstance(crystal, Crystal)
|
||||
|
||||
def test_add_cell_raises_exception(self):
|
||||
# Note that this is not a valid crystal
|
||||
crystal_structure = [
|
||||
['H ']
|
||||
]
|
||||
|
||||
crystal = Crystal(crystal_structure)
|
||||
|
||||
molecule = Molecule("TESTE")
|
||||
molecule.add_atom(
|
||||
Atom(
|
||||
na=1,
|
||||
rx=0,
|
||||
ry=0,
|
||||
rz=0,
|
||||
)
|
||||
)
|
||||
molecule.add_atom(
|
||||
Atom(
|
||||
na=1,
|
||||
rx=0,
|
||||
ry=0,
|
||||
rz=0,
|
||||
)
|
||||
)
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
crystal.add_cell([molecule])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
87
tests/shared/system/test_molecule.py
Normal file
87
tests/shared/system/test_molecule.py
Normal file
@@ -0,0 +1,87 @@
|
||||
from crystalpol.shared.system.molecule import Molecule
|
||||
from crystalpol.shared.system.atom import Atom
|
||||
|
||||
import io
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
class TestMolecule(unittest.TestCase):
|
||||
def test_class_instantiation(self):
|
||||
molecule = Molecule("TEST")
|
||||
|
||||
self.assertEqual(molecule.mol_name, "TEST")
|
||||
self.assertIsInstance(molecule, Molecule)
|
||||
|
||||
def test_add_atom(self):
|
||||
molecule = Molecule("TEST")
|
||||
|
||||
atom = Atom(
|
||||
na=1,
|
||||
rx=0,
|
||||
ry=0,
|
||||
rz=0,
|
||||
)
|
||||
|
||||
molecule.add_atom(atom)
|
||||
|
||||
self.assertEqual(len(molecule.atoms), 1)
|
||||
self.assertEqual(molecule.atoms[0], atom)
|
||||
|
||||
def test_update_charges(self):
|
||||
molecule = Molecule("TEST")
|
||||
|
||||
atom = Atom(
|
||||
na=1,
|
||||
rx=0,
|
||||
ry=0,
|
||||
rz=0,
|
||||
)
|
||||
|
||||
molecule.add_atom(atom)
|
||||
|
||||
molecule.update_charges([1])
|
||||
|
||||
self.assertEqual(molecule.atoms[-1].chg, 1)
|
||||
|
||||
def test_update_charges_raises_exception(self):
|
||||
molecule = Molecule("TEST")
|
||||
|
||||
atom = Atom(
|
||||
na=1,
|
||||
rx=0,
|
||||
ry=0,
|
||||
rz=0,
|
||||
)
|
||||
|
||||
molecule.add_atom(atom)
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
molecule.update_charges([1, 1])
|
||||
|
||||
def test_print_mol_info(self):
|
||||
molecule = Molecule("TEST")
|
||||
|
||||
atom = Atom(
|
||||
na=1,
|
||||
rx=0,
|
||||
ry=0,
|
||||
rz=0,
|
||||
)
|
||||
|
||||
molecule.add_atom(atom)
|
||||
|
||||
with io.StringIO() as file:
|
||||
molecule.print_mol_info(file)
|
||||
|
||||
file.seek(0)
|
||||
info_string = file.read()
|
||||
|
||||
self.assertIsNotNone(info_string)
|
||||
self.assertTrue(len(info_string) > 0)
|
||||
self.assertTrue("Molecule Name: TEST" in info_string)
|
||||
self.assertTrue("H r: [0, 0, 0] charge: None" in info_string)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user