Adds Formatter to Project

This commit is contained in:
2023-06-11 16:04:25 -03:00
parent 82f3092f3e
commit c4dae5e8d1
29 changed files with 1151 additions and 721 deletions

View File

@@ -16,4 +16,4 @@ class TestAtom(unittest.TestCase):
sig=1.0,
)
self.assertIsInstance(atom, Atom)
self.assertIsInstance(atom, Atom)

View File

@@ -1,30 +1,30 @@
import numpy as np
from diceplayer.shared.environment.molecule import Molecule
from diceplayer.shared.environment.atom import Atom
from diceplayer.shared.environment.molecule import Molecule
import numpy as np
import numpy.testing as npt
import unittest
class TestMolecule(unittest.TestCase):
def test_class_instantiation(self):
mol = Molecule('test')
mol = Molecule("test")
self.assertIsInstance(mol, Molecule)
def test_add_atom(self):
mol = Molecule('test')
mol = Molecule("test")
mol.add_atom(
Atom(lbl=1, na=1, rx=1.0, ry=1.0, rz=1.0, chg=1.0, eps=1.0, sig=1.0)
)
self.assertEqual(len(mol.atom), 1)
npt.assert_equal(mol.com, [1., 1., 1.])
npt.assert_equal(mol.com, [1.0, 1.0, 1.0])
def test_center_of_mass(self):
mol = Molecule('test')
mol = Molecule("test")
mol.add_atom(
Atom(lbl=1, na=1, rx=1.0, ry=1.0, rz=1.0, chg=1.0, eps=1.0, sig=1.0)
@@ -33,10 +33,10 @@ class TestMolecule(unittest.TestCase):
Atom(lbl=1, na=1, rx=0.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
)
npt.assert_equal(mol.com, [.5, .5, .5])
npt.assert_equal(mol.com, [0.5, 0.5, 0.5])
def test_center_of_mass_to_origin(self):
mol = Molecule('test')
mol = Molecule("test")
mol.add_atom(
Atom(lbl=1, na=1, rx=1.0, ry=1.0, rz=1.0, chg=1.0, eps=1.0, sig=1.0)
@@ -47,7 +47,7 @@ class TestMolecule(unittest.TestCase):
npt.assert_equal(mol.com, [0, 0, 0])
def test_charges_and_dipole(self):
mol = Molecule('test')
mol = Molecule("test")
mol.add_atom(
Atom(lbl=1, na=1, rx=0.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
@@ -57,13 +57,10 @@ class TestMolecule(unittest.TestCase):
expected_charge_dipole_array = [1.0, 0.0, 0.0, 0.0, 0.0]
npt.assert_equal(
actual_charge_dipole_array,
expected_charge_dipole_array
)
npt.assert_equal(actual_charge_dipole_array, expected_charge_dipole_array)
def test_distances_between_atoms(self):
mol = Molecule('test')
mol = Molecule("test")
mol.add_atom(
Atom(lbl=1, na=1, rx=0.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
@@ -76,12 +73,11 @@ class TestMolecule(unittest.TestCase):
actual_distance_between_atoms = mol.distances_between_atoms()
npt.assert_almost_equal(
expected_distance_between_atoms,
actual_distance_between_atoms
expected_distance_between_atoms, actual_distance_between_atoms
)
def test_inertia_tensor(self):
mol = Molecule('test')
mol = Molecule("test")
mol.add_atom(
Atom(lbl=1, na=1, rx=0.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
@@ -90,25 +86,28 @@ class TestMolecule(unittest.TestCase):
Atom(lbl=1, na=1, rx=1.0, ry=1.0, rz=1.0, chg=1.0, eps=1.0, sig=1.0)
)
expected_inertia_tensor = [[1.00790, -0.50395, -0.50395],
[-0.50395, 1.0079, -0.50395],
[-0.50395, -0.50395, 1.0079]]
expected_inertia_tensor = [
[1.00790, -0.50395, -0.50395],
[-0.50395, 1.0079, -0.50395],
[-0.50395, -0.50395, 1.0079],
]
actual_inertia_tensor = mol.inertia_tensor()
npt.assert_equal(
expected_inertia_tensor,
actual_inertia_tensor
)
npt.assert_equal(expected_inertia_tensor, actual_inertia_tensor)
def test_principal_axes(self):
mol = Molecule('test')
mol = Molecule("test")
mol.add_atom(
Atom(lbl=1, na=1, rx=0.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
)
expected_evals, expected_evecs = [0., 0., 0.], [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]
expected_evals, expected_evecs = [0.0, 0.0, 0.0], [
[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 1.0],
]
evals, evecs = mol.principal_axes()
@@ -116,7 +115,7 @@ class TestMolecule(unittest.TestCase):
npt.assert_equal(expected_evecs, evecs)
def test_read_position(self):
mol = Molecule('test')
mol = Molecule("test")
mol.add_atom(
Atom(lbl=1, na=1, rx=0.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
@@ -126,30 +125,24 @@ class TestMolecule(unittest.TestCase):
actual_position = mol.read_position()
npt.assert_equal(
expected_position,
actual_position
)
npt.assert_equal(expected_position, actual_position)
def test_update_charges(self):
mol = Molecule('test')
mol = Molecule("test")
mol.add_atom(
Atom(lbl=1, na=1, rx=0.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
)
expected_charges = [2.]
expected_charges = [2.0]
mol.update_charges(expected_charges)
actual_charges = list(map(lambda a: a.chg, mol.atom))
npt.assert_equal(
expected_charges,
actual_charges
)
npt.assert_equal(expected_charges, actual_charges)
def test_sizes_of_molecule(self):
mol = Molecule('test')
mol = Molecule("test")
mol.add_atom(
Atom(lbl=1, na=1, rx=0.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
@@ -162,7 +155,7 @@ class TestMolecule(unittest.TestCase):
npt.assert_equal(sizes, expected_sizes)
def test_standard_orientation(self):
mol = Molecule('test')
mol = Molecule("test")
mol.add_atom(
Atom(lbl=1, na=1, rx=1.0, ry=1.0, rz=1.0, chg=1.0, eps=1.0, sig=1.0)
@@ -175,7 +168,7 @@ class TestMolecule(unittest.TestCase):
self.assertEqual(mol.read_position().tolist(), expected_position)
def test_translate(self):
mol = Molecule('test')
mol = Molecule("test")
mol.add_atom(
Atom(lbl=1, na=1, rx=1.0, ry=1.0, rz=1.0, chg=1.0, eps=1.0, sig=1.0)
@@ -185,18 +178,15 @@ class TestMolecule(unittest.TestCase):
expected_position = [0.0, 0.0, 0.0]
self.assertEqual(
new_mol.read_position().tolist(),
expected_position
)
self.assertEqual(new_mol.read_position().tolist(), expected_position)
def test_minimum_distance(self):
mol1 = Molecule('test1')
mol1 = Molecule("test1")
mol1.add_atom(
Atom(lbl=1, na=1, rx=0.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
)
mol2 = Molecule('test2')
mol2 = Molecule("test2")
mol2.add_atom(
Atom(lbl=1, na=1, rx=1.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
)
@@ -208,5 +198,5 @@ class TestMolecule(unittest.TestCase):
self.assertEqual(expected_distance, actual_distance)
if __name__ == '__main__':
unittest.main()
if __name__ == "__main__":
unittest.main()

View File

@@ -13,15 +13,14 @@ class TestSystem(unittest.TestCase):
def test_add_type(self):
system = System()
system.add_type(Molecule('test'))
system.add_type(Molecule("test"))
self.assertIsInstance(system.molecule, list)
with self.assertRaises(TypeError) as ex:
system.add_type('test')
self.assertEqual(ex.exception, 'Error: molecule is not a Molecule instance')
system.add_type("test")
self.assertEqual(ex.exception, "Error: molecule is not a Molecule instance")
if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()