def test_analyze_exceptions(): latt = Lattice(np.eye(2)) with pytest.raises(NoAtomsError): latt.analyze() latt.add_atom() with pytest.raises(NoConnectionsError): latt.analyze()
def test_position(): latt = Lattice(np.eye(2)) latt.add_atom([0.0, 0.0], "A") latt.add_atom([0.5, 0.5], "B") latt.add_connection("A", "A", 1) latt.add_connection("A", "B", 1) latt.analyze() latt.build((4, 4), primitive=False) assert_array_equal(latt.position(0), [0.0, 0.0]) assert_array_equal(latt.position(1), [0.5, 0.5]) assert_array_equal(latt.position(2), [0.0, 1.0]) assert_array_equal(latt.position(3), [0.5, 1.5])
def test_atom(): latt = Lattice(np.eye(2)) at1 = latt.add_atom([0.0, 0.0], "A") at2 = latt.add_atom([0.5, 0.5], "B") latt.add_connection("A", "A", 1) latt.add_connection("A", "B", 1) latt.analyze() latt.build((4, 4), primitive=False) assert latt.atom(0) == at1 assert latt.atom(1) == at2 assert latt.atom(2) == at1 assert latt.atom(3) == at2
def test_alpha(): latt = Lattice(np.eye(2)) latt.add_atom([0.0, 0.0], "A") latt.add_atom([0.5, 0.5], "B") latt.add_connection("A", "A", 1) latt.add_connection("A", "B", 1) latt.analyze() latt.build((4, 4), primitive=False) assert latt.alpha(0) == 0 assert latt.alpha(1) == 1 assert latt.alpha(2) == 0 assert latt.alpha(3) == 1
def test_add_connection(): latt = Lattice(np.eye(2)) latt.add_atom([0.0, 0.0], atom="A") latt.add_atom([0.5, 0.5], atom="B") latt.add_connection("A", "A", 1) latt.add_connection("A", "B", 1) latt.analyze() # Assert neighbor atom index is right assert all(latt.get_neighbors(alpha=0, distidx=0)[:, -1] == 1) assert all(latt.get_neighbors(alpha=0, distidx=1)[:, -1] == 0) assert all(latt.get_neighbors(alpha=1, distidx=0)[:, -1] == 0)
def test_build_exceptions(): latt = Lattice(np.eye(2)) latt.add_atom() with pytest.raises(NoConnectionsError): latt.build((5, 5)) latt.add_connections(analyze=False) with pytest.raises(NotAnalyzedError): latt.build((5, 5)) latt.analyze() with pytest.raises(ValueError): latt.build((5, 5, 5))