def test_eleven_atom_BaseMolecule(): mol = molecule.BaseMolecule(*eg.c3h8) assert mol.natm == 11 assert np.all(mol.elem == eg.c3h8[0]) assert np.allclose(mol.xyz, eg.c3h8[1]) assert '...' in str(mol) assert '...' in repr(mol)
def test_BaseMolecule_rearrange_all(): mol = molecule.BaseMolecule(*eg.ch4) ind = [4, 2, 3, 0, 1] mol.rearrange(ind) assert np.all(mol.elem == eg.ch4[0][ind]) assert np.allclose(mol.xyz, eg.ch4[1][ind]) assert not mol.saved
def test_BaseMolecule_copy(): mol1 = molecule.BaseMolecule(*eg.c2h4) mol2 = mol1.copy() assert np.all(mol1.elem == eg.c2h4[0]) assert np.all(mol2.elem == eg.c2h4[0]) assert np.allclose(mol1.xyz, eg.c2h4[1]) assert np.allclose(mol2.xyz, eg.c2h4[1])
def test_BaseMolecule_add_atoms_multiple(): mol = molecule.BaseMolecule(*eg.he) mol.add_atoms(*eg.ch4) soln_elem = np.hstack((eg.he[0], eg.ch4[0])) soln_xyz = np.vstack((eg.he[1], eg.ch4[1])) assert np.all(mol.elem == soln_elem) assert np.allclose(mol.xyz, soln_xyz) assert not mol.saved
def test_BaseMolecule_add_atoms_single(): mol = molecule.BaseMolecule(*eg.he) mol.add_atoms('H', np.ones(3)) soln_elem = np.hstack((eg.he[0], 'H')) soln_xyz = np.vstack((eg.he[1], np.ones(3))) assert np.all(mol.elem == soln_elem) assert np.allclose(mol.xyz, soln_xyz) assert not mol.saved
def test_empty_BaseMolecule(): mol = molecule.BaseMolecule() assert len(mol.elem) == 0 assert len(mol.xyz) == 0 assert len(mol.vec) == 0 assert mol.comment == '' assert str(mol) == '[]' assert repr(mol) == 'BaseMolecule(\'\', [])'
def test_BaseMolecule_add_atoms_new_vec(): mol = molecule.BaseMolecule(*eg.he) mol.add_atoms('H', np.ones(3), new_vec=2 * np.ones(3)) soln_elem = np.hstack((eg.he[0], 'H')) soln_xyz = np.vstack((eg.he[1], np.ones(3))) soln_vec = np.vstack((np.zeros(3), 2 * np.ones(3))) assert np.all(mol.elem == soln_elem) assert np.allclose(mol.xyz, soln_xyz) assert np.allclose(mol.vec, soln_vec)
def test_BaseMolecule_rearrange_old_ind(): mol = molecule.BaseMolecule(*eg.ch4) ninds = [1, 2] oinds = [3, 4] mol.rearrange(ninds, old_ind=oinds) soln_elem = eg.ch4[0][[0, 3, 4, 1, 2]] soln_xyz = eg.ch4[1][[0, 3, 4, 1, 2]] assert np.all(mol.elem == soln_elem) assert np.allclose(mol.xyz, soln_xyz) assert not mol.saved
def test_BaseMolecule_revert(): mol = molecule.BaseMolecule(*eg.he) mol.elem = np.array(['H']) mol.xyz = np.ones((1, 3)) mol.comment = 'comment' mol.revert() assert mol.saved assert np.all(mol.elem == eg.he[0]) assert np.allclose(mol.xyz, eg.he[1]) assert mol.comment == ''
def test_BaseMolecule_save(): mol = molecule.BaseMolecule(*eg.he) mol.elem = np.array(['H']) mol.xyz = np.ones((1, 3)) mol.comment = 'comment' mol.save() assert mol.saved assert np.all(mol.save_elem == ['H']) assert np.allclose(mol.save_xyz, np.ones((1, 3))) assert mol.save_comment == 'comment'
def test_single_atom_vec_BaseMolecule(): mol = molecule.BaseMolecule(*eg.he, vec=np.ones(3)) zf = 3 * '{:14.8f}'.format(0) of = 3 * '{:14.8f}'.format(1) ze = ','.join(3 * ['{:16.8e}'.format(0)]) oe = ','.join(3 * ['{:16.8e}'.format(1)]) assert mol.natm == 1 assert np.all(mol.elem == ['He']) assert np.allclose(mol.xyz, np.zeros((1, 3))) assert str(mol) == '[[He' + zf + '\n ' + of + ']]' assert repr(mol) == ('BaseMolecule(\'\',\n [[He,' + ze + ',\n ' + oe + ']])')
def test_BaseMolecule_rm_atoms_single(): mol = molecule.BaseMolecule(*eg.ch4) mol.rm_atoms(0) assert np.all(mol.elem == eg.ch4[0][1:]) assert np.allclose(mol.xyz, eg.ch4[1][1:]) assert not mol.saved
def test_BaseMolecule_len_elem_not_equal_len_xyz(): with pytest.raises(ValueError, match=r'Number of element labels .*'): mol = molecule.BaseMolecule('H', np.zeros((2, 3)))
def test_BaseMolecule_xyz_vec_different_shape(): with pytest.raises(ValueError, match=r'Cartesian geometry and vector .*'): mol = molecule.BaseMolecule(['H', 'H'], np.zeros((2, 3)), np.ones((1, 3)))
def test_BaseMolecule_vec_not_3d(): with pytest.raises(ValueError, match=r'Molecular vector must be 3.*'): mol = molecule.BaseMolecule('H', np.zeros(3), vec=np.ones(2))
def test_BaseMolecule_xyz_not_3d(): with pytest.raises(ValueError, match=r'Molecular geometry must be 3.*'): mol = molecule.BaseMolecule('H', np.zeros(2))
def test_BaseMolecule_rm_atoms_multiple(): mol = molecule.BaseMolecule(*eg.ch4) mol.rm_atoms((1, 2, 3, 4)) assert np.all(mol.elem == eg.ch4[0][0]) assert np.allclose(mol.xyz, eg.ch4[1][0]) assert not mol.saved
def test_two_atom_comment_BaseMolecule(): mol = molecule.BaseMolecule(*eg.h2, comment='comment') assert mol.natm == 2 assert np.all(mol.elem == eg.h2[0]) assert np.allclose(mol.xyz, eg.h2[1]) assert 'comment' in str(mol)
def test_BaseMolecule_rearrange_fails(): mol = molecule.BaseMolecule(*eg.ch4) with pytest.raises(IndexError, match=r'Old and new indices must be .*'): mol.rearrange([1, 3])