def test_opt(self, algorithm="fast"): # graphene-NiPS3 low-strain angle 21.9, theta range 16-30-0.1 graphene = sc.read_POSCAR(path.join( path.dirname(__file__), "../resources/vasp/graphene/POSCAR"), atomic_species=["C"]) nips3 = sc.read_POSCAR(path.join(path.dirname(__file__), "../resources/vasp/NiPS3/POSCAR"), atomic_species=["Ni", "P", "S"]) h = sc.heterostructure() h.set_substrate(graphene) h.add_layer(nips3) res = h.opt(max_el=11, thetas=np.arange(16 * sc.DEGREE, 30 * sc.DEGREE, 0.1 * sc.DEGREE), algorithm=algorithm) self.assertTrue( np.allclose(res.M(), np.array([[7, 9], [10, -8]])) or np.allclose(res.M(), np.array([[9, 7], [-8, 10]]))) self.assertTrue( np.allclose(res.layer_Ms()[0], np.array([[6, -1], [-1, -2]])) or np.allclose(res.layer_Ms()[0], np.array([[-1, 6], [-2, -1]]))) self.assertAlmostEqual(res.thetas()[0], 21.9 * sc.DEGREE) self.assertAlmostEqual(res.max_strain(), 0.000608879275296, places=5) self.assertEqual(res.atom_count(), 552)
def test_bad_arg_thetas(self): graphene = sc.read_POSCAR(path.join( path.dirname(__file__), "../resources/vasp/graphene/POSCAR"), atomic_species=["C"]) h = sc.heterostructure().set_substrate(graphene).add_layer( graphene).add_layer(graphene) with self.assertRaises(TypeError): h.opt(max_el=4, thetas=[np.arange(0, 10 * sc.DEGREE, 1 * sc.DEGREE)])
def test_homogeneous_trilayer(self): graphene = sc.read_POSCAR(path.join( path.dirname(__file__), "../resources/vasp/graphene/POSCAR"), atomic_species=["C"]) h = sc.heterostructure().set_substrate(graphene).add_layer( graphene).add_layer(graphene) res = h.opt(max_el=4, thetas=[np.arange(0, 10 * sc.DEGREE, 1 * sc.DEGREE)] * 2) self.assertEqual(res.atom_count(), 3 * len(graphene.atoms()))
def test_opt_graphene_fast(self): graphene = sc.read_POSCAR(path.join( path.dirname(__file__), "../resources/vasp/graphene/POSCAR"), atomic_species=["C"]) h = sc.heterostructure() h.set_substrate(graphene) h.add_layer(graphene) res = h.opt(max_el=20, thetas=np.arange(5.5 * sc.DEGREE, 7 * sc.DEGREE, 0.001 * sc.DEGREE)) self.assertAlmostEqual(res.max_strain(), 0, places=6) self.assertEqual(res.atom_count(), 364)
def test_read_poscar_without_atomic_species(self): graphene = sc.read_POSCAR(os.path.join( os.path.dirname(__file__), "../resources/vasp/graphene/POSCAR"), atomic_species=["C"]) self.assertEqual(graphene.atoms()[0], sc.Atom("C", (0, 0))) self.assertEqual( graphene.atoms()[1], sc.Atom("C", np.array([2 / 3, 2 / 3, 0]) @ graphene.vectors())) self.assertAlmostEqual(graphene.vectors()[0][0], 2.133341911) self.assertAlmostEqual(graphene.vectors()[0][1], -1.231685527) self.assertAlmostEqual(graphene.vectors()[1][0], 2.133341911) self.assertAlmostEqual(graphene.vectors()[1][1], 1.231685527)
import supercell_core as sc # Read graphene and NiPS3 definition from POSCAR graphene = sc.read_POSCAR("supercell_core/resources/vasp/POSCAR_Gr") nips3 = sc.read_POSCAR("supercell_core/resources/vasp/POSCAR_NiPS3") h = sc.heterostructure().set_substrate(graphene)\ .add_layer(nips3) res = h.opt(max_el=8, thetas=[np.arange(0, 30 * sc.DEGREE, 0.25 * sc.DEGREE)]) # Draw the resulting supercell res.superlattice().draw() plt.title("""Best supercell found for $\\theta$ = {} max strain = {:.4g}""".format(res.thetas()[0], res.max_strain()))
def test_read_POSCAR_IO_fail(self): with self.assertRaises(IOError): sc.read_POSCAR("csnadkjndksca")
def load_graphene(self): return sc.read_POSCAR(os.path.join( os.path.dirname(__file__), "../resources/vasp/graphene/POSCAR"), atomic_species=["C"])
import supercell_core as sc import matplotlib.pyplot as plt # Read graphene and NiPS3 definition from POSCAR graphene = sc.read_POSCAR("supercell_core/resources/vasp/POSCAR_Gr") nips3 = sc.read_POSCAR("supercell_core/resources/vasp/POSCAR_NiPS3", atomic_species=['Ni', 'P', 'S']) h = sc.heterostructure().set_substrate(graphene)\ .add_layer(nips3) res = h.opt(max_el=8, thetas=[np.arange(0, 30 * sc.DEGREE, 0.25 * sc.DEGREE)]) # Draw the resulting supercell res.superlattice().draw() plt.title("""Best supercell found for $\\theta$ = {} max strain = {:.4g}""".format(res.thetas()[0], res.max_strain()))