def test_MoleculeBundle_match_to_ref(): mol1 = molecule.Molecule(eg.ch2f2[0], eg.ch2f2[1]) mol2 = molecule.Molecule(eg.ch2f2[0], eg.ch2f2[2]) mol3 = molecule.Molecule(eg.ch2f2[0], eg.ch2f2[3]) mol4 = molecule.Molecule(eg.ch2f2[0], eg.ch2f2[4]) mol5 = molecule.Molecule(eg.ch2f2[0], eg.ch2f2[5]) bund1 = molecule.MoleculeBundle([mol3, mol4, mol5]) bund2 = molecule.MoleculeBundle([mol1, mol2]) inds = bund1.match_to_ref(bund2) assert np.allclose(inds, [0, 0, 1])
def test_MoleculeBundle_add_MoleculeBundle(): mol1 = molecule.Molecule(*eg.he) mol2 = molecule.Molecule(*eg.ch4) mol3 = molecule.Molecule(*eg.c2h4) bund1 = molecule.MoleculeBundle(mol1) bund23 = molecule.MoleculeBundle([mol2, mol3]) bund = bund1 + bund23 assert np.all(bund.molecules[0].elem[1:] == eg.he[0]) assert np.all(bund.molecules[0].xyz[1:] == eg.he[1]) assert np.all(bund.molecules[1].elem[1:] == eg.ch4[0]) assert np.all(bund.molecules[1].xyz[1:] == eg.ch4[1]) assert np.all(bund.molecules[2].elem[1:] == eg.c2h4[0]) assert np.all(bund.molecules[2].xyz[1:] == eg.c2h4[1])
def test_MoleculeBundle_write_vec(tmpdir): f = tmpdir.join('tmp.xyz') vec = np.ones((5, 3)) mol = molecule.Molecule(*eg.ch4, vec=vec, comment='comment line') bund = molecule.MoleculeBundle([mol, mol]) bund.write(f.open(mode='w')) assert f.read() == 2 * ef.xyz_vec
def test_Molecule_add_MoleculeBundle(): mol = molecule.Molecule(*eg.he) bund1 = molecule.MoleculeBundle(molecule.Molecule(*eg.c2h4)) bund = mol + bund1 assert np.all(bund.molecules[0].elem[1:] == eg.he[0]) assert np.all(bund.molecules[0].xyz[1:] == eg.he[1]) assert np.all(bund.molecules[1].elem[1:] == eg.c2h4[0]) assert np.all(bund.molecules[1].xyz[1:] == eg.c2h4[1])
def test_Molecule_match_to_ref(): mol5 = molecule.Molecule(eg.ch2f2[0], eg.ch2f2[5]) mol1 = molecule.Molecule(eg.ch2f2[0], eg.ch2f2[1]) mol2 = molecule.Molecule(eg.ch2f2[0], eg.ch2f2[2]) bund = molecule.MoleculeBundle([mol1, mol2]) ind = mol5.match_to_ref(bund) assert np.all(np.abs(mol5.xyz - mol2.xyz) < 1) assert not np.all(np.abs(mol5.xyz - mol1.xyz) < 1) assert ind == 1
def test_single_atom_MoleculeBundle(): mol = molecule.Molecule(*eg.he) bund = molecule.MoleculeBundle(mol) zf = 3 * '{:14.8f}'.format(0) ze = 3 * ',{:16.8e}'.format(0) assert bund.nmol == 1 assert str(bund) == '[[[He' + zf + ']]]' assert repr(bund) == ('MoleculeBundle(\n Molecule(\'\',\n [[XM' + ze + '],\n [He' + ze + ']]))')
def test_MoleculeBundle_copy(): mol1 = molecule.Molecule(*eg.he) mol2 = molecule.Molecule(*eg.ch4) bund1 = molecule.MoleculeBundle([mol1, mol2]) bund2 = bund1.copy() assert np.all(bund1.molecules[0].elem == bund2.molecules[0].elem) assert np.all(bund1.molecules[1].elem == bund2.molecules[1].elem) assert np.allclose(bund1.molecules[0].xyz, bund2.molecules[0].xyz) assert np.allclose(bund1.molecules[1].xyz, bund2.molecules[1].xyz)
def test_MoleculeBundle_read_openfile(tmpdir): f = ef.tmpf(tmpdir, ef.xyz_novec + ef.zmtvar_nocom) bund = molecule.MoleculeBundle() bund.read(f) assert np.all(bund.molecules[0].elem[1:] == eg.ch4[0]) assert np.all(bund.molecules[1].elem[1:] == eg.ch4[0]) assert np.allclose(bund.molecules[0].xyz[1:], eg.ch4[1]) assert np.allclose(bund.molecules[1].xyz[1:], eg.ch4_zmt[1]) assert not bund.saved
def test_MoleculeBundle_add_molecules(): mol1 = molecule.Molecule('He', np.zeros(3)) mol2 = molecule.Molecule('Ne', np.ones(3)) mol3 = molecule.Molecule('Ar', -np.ones(3)) bund = molecule.MoleculeBundle(mol1) bund.add_molecules([mol2, mol3]) assert bund.molecules[0] == mol1 assert bund.molecules[1] == mol2 assert bund.molecules[2] == mol3 assert not bund.saved
def test_MoleculeBundle_save(): mol = molecule.Molecule(*eg.he) bund = molecule.MoleculeBundle([mol, mol]) bund.molecules = [mol] bund.molecules[0].xyz += 1 bund.molecules[0].elem[1] = 'H' bund.save() assert bund.saved assert bund.molecules[0].saved assert len(bund.save_molecules) == 1
def test_MoleculeBundle_read_filename(tmpdir): f = tmpdir.join('tmp.xyz') f.write(ef.xyz_novec + ef.zmtvar_nocom) bund = molecule.MoleculeBundle() bund.read(str(f.realpath())) assert np.all(bund.molecules[0].elem[1:] == eg.ch4[0]) assert np.all(bund.molecules[1].elem[1:] == eg.ch4[0]) assert np.allclose(bund.molecules[0].xyz[1:], eg.ch4[1]) assert np.allclose(bund.molecules[1].xyz[1:], eg.ch4_zmt[1]) assert not bund.saved
def test_MoleculeBundle_rm_molecules(): mol1 = molecule.Molecule('He', np.zeros(3)) mol2 = molecule.Molecule('Ne', np.ones(3)) mol3 = molecule.Molecule('Ar', -np.ones(3)) bund = molecule.MoleculeBundle([mol1, mol2, mol3]) bund.rm_molecules(1) assert bund.nmol == 2 assert bund.molecules[0] == mol1 assert bund.molecules[1] == mol3 assert not bund.saved
def test_MoleculeBundle_rearrange_old_ind(): mol1 = molecule.Molecule('He', np.zeros(3)) mol2 = molecule.Molecule('Ne', np.ones(3)) mol3 = molecule.Molecule('Ar', -np.ones(3)) bund = molecule.MoleculeBundle([mol1, mol2, mol3]) bund.rearrange(1, old_ind=0) assert bund.molecules[0] == mol2 assert bund.molecules[1] == mol1 assert bund.molecules[2] == mol3 assert not bund.saved
def test_MoleculeBundle_iadd_Molecule(): mol1 = molecule.Molecule(*eg.he) mol2 = molecule.Molecule(*eg.ch4) mol3 = molecule.Molecule(*eg.c2h4) bund = molecule.MoleculeBundle([mol1, mol2]) bund += mol3 assert np.all(bund.molecules[0].elem[1:] == eg.he[0]) assert np.all(bund.molecules[0].xyz[1:] == eg.he[1]) assert np.all(bund.molecules[1].elem[1:] == eg.ch4[0]) assert np.all(bund.molecules[1].xyz[1:] == eg.ch4[1]) assert np.all(bund.molecules[2].elem[1:] == eg.c2h4[0]) assert np.all(bund.molecules[2].xyz[1:] == eg.c2h4[1])
def test_seven_molecule_MoleculeBundle(): mol = molecule.Molecule(*eg.he) bund = molecule.MoleculeBundle(7 * [mol]) assert bund.nmol == 7 assert '...' in str(bund) assert '...' in repr(bund)
def test_MoleculeBundle_measure(): mol1 = molecule.Molecule(eg.ch2f2[0], eg.ch2f2[1]) mol2 = molecule.Molecule(eg.ch2f2[0], eg.ch2f2[2]) bund = molecule.MoleculeBundle([mol1, mol2]) stre = bund.measure('stre', 2, 3) assert np.allclose(stre, [np.sqrt(2), 2.04])
def test_empty_MoleculeBundle(): bund = molecule.MoleculeBundle() assert len(bund.molecules) == 0 assert bund.nmol == 0 assert str(bund) == '[]' assert repr(bund) == 'MoleculeBundle()'
def test_MoleculeBundle_write_openfile(tmpdir): f = tmpdir.join('tmp.xyz') mol = molecule.Molecule(*eg.ch4, comment='comment line') bund = molecule.MoleculeBundle([mol, mol]) bund.write(f.open(mode='w')) assert f.read() == 2 * ef.xyz_novec
def test_MoleculeBundle_write_filename(tmpdir): f = tmpdir.join('tmp.xyz') mol = molecule.Molecule(*eg.ch4, comment='comment line') bund = molecule.MoleculeBundle([mol, mol]) bund.write(str(f.realpath())) assert f.read() == 2 * ef.xyz_novec
def test_MoleculeBundle_add_wrong_type(): bund1 = molecule.MoleculeBundle(molecule.Molecule(*eg.he)) with pytest.raises(TypeError, match=r'Addition not supported for types .*'): bund = bund1 + np.ones(3)
def test_MoleculeBundle_wrong_type(): with pytest.raises(TypeError, match=r'Elements of molecule bundle must .*'): bund = molecule.MoleculeBundle(eg.he)