def test_temperature(self): mf = MolecularFrame('Li crystal').import_from(make_supercell_li()) mf.temperature = 50.0 self.assertAlmostEqual(mf.temperature, 50.0) with self.assertRaises(AssertionError): mf.temperature = 0 # T > 0
def test_center_of_mass(self): mf = MolecularFrame('Li crystal').import_from(make_supercell_li()) for i in range(3): self.assertAlmostEqual(mf.center_of_mass[i], 16.672499, 5) # Set COM to center mf.center_of_mass = (0, 0, 0) for i in range(3): self.assertAlmostEqual(mf.center_of_mass[i], 0)
def test_molecular_frame_clone(self): mf = MolecularFrame('Li crystal').import_from(make_supercell_li()) mf_clone = mf.clone() mf.atoms_section.atoms[ 0].x = 1.0 # make a change to the first atom in mf self.assertIsInstance(mf_clone, MolecularFrame) self.assertTrue(not mf_clone.atoms_section.atoms[0].x == mf.atoms_section.atoms[0].x) self.assertEqual(mf_clone.atoms_section.atoms[0].y, mf.atoms_section.atoms[0].y)
def test_molecular_frame_equal(self): mf = MolecularFrame('Cu crystal').import_from(make_supercell_cu()) new_mf = mf # equal operator self.assertEqual(new_mf.get_number_of_atoms(), mf.get_number_of_atoms()) self.assertEqual(new_mf.name, mf.name) self.assertEqual(new_mf.atoms_section.atoms[1].x, mf.atoms_section.atoms[1].x) # atom x position self.assertEqual( new_mf.atoms_section.atoms[1].symbol, mf.atoms_section.atoms[1].symbol) # second atom symbol
def test_molecular_frame_select_region(self): def sphere(x, y, z): """sphere region""" if np.sqrt(x**2 + y**2 + z**2) < 7.0: return True else: return False mf = MolecularFrame('Li crystal').import_from(make_supercell_li()) sel_mf = mf.select(SelectRegion(sphere)) self.assertIsInstance(sel_mf, MolecularFrame) self.assertEqual(sel_mf.get_number_of_atoms(), 12)
def test_molecular_frame_formatter(self): mf1 = MolecularFrame('Cu crystal').import_from(make_supercell_cu()) filename = "cu_pytest.xyz" mf1.write(filename) mf2 = MolecularFrame().read(filename) self.assertEqual(mf1.get_number_of_atoms(), mf2.get_number_of_atoms()) os.system("rm -f %s" % filename)
def test_molecular_frame_plus(self): mf1 = MolecularFrame('Cu crystal').import_from(make_supercell_cu()) mf2 = MolecularFrame('Li crystal').import_from(make_supercell_li()) mf = mf1 + mf2 # plus operator self.assertIsInstance(mf, MolecularFrame) self.assertTrue(mf1.name in mf.name and mf2.name in mf.name) self.assertEqual(mf.get_number_of_atoms(), mf1.get_number_of_atoms() + mf2.get_number_of_atoms())
def test_molecular_frame_import_ase(self): mf = MolecularFrame('Cu crystal') mf.import_from(package_instance=make_supercell_cu(), package_name="ASE") self.assertEqual(mf.get_number_of_atoms(), make_supercell_cu().get_number_of_atoms()) self.assertEqual(mf.name, 'Cu crystal') self.assertAlmostEqual( mf.atoms_section.atoms[1].x, make_supercell_cu().get_positions()[1][0]) # 2nd atom self.assertEqual(mf.get_atoms_section().atoms[1].symbol, 'Cu') # second atom symbol
def test_molecular_frame_adaptor(self): mf1 = MolecularFrame('Cu crystal').import_from(make_supercell_cu()) mf2 = MolecularFrame().import_from(mf1.export()) self.assertEqual(mf1.get_number_of_atoms(), mf2.get_number_of_atoms()) self.assertTrue(Atoms().name in mf2.get_sections_name()) self.assertTrue(Box().name in mf2.get_sections_name())
def test_molecular_frame(self): mf = MolecularFrame() self.assertIsInstance(mf, MolecularFrame) self.assertEqual(mf.name, 'Molecular Frame')