Example #1
0
    def setUp(self):

        # trivial example, simple square lattice for testing
        structure = Structure(Lattice.tetragonal(5.0, 50.0), ['H'], [[0, 0, 0]])
        self.square_sg = StructureGraph.with_empty_graph(structure, edge_weight_name="", edge_weight_units="")
        self.square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(1, 0, 0))
        self.square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(-1, 0, 0))
        self.square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, 1, 0))
        self.square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, -1, 0))

        # body-centered square lattice for testing
        structure = Structure(Lattice.tetragonal(5.0, 50.0), ['H', 'He'], [[0, 0, 0], [0.5, 0.5, 0.5]])
        self.bc_square_sg = StructureGraph.with_empty_graph(structure, edge_weight_name="", edge_weight_units="")
        self.bc_square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(1, 0, 0))
        self.bc_square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(-1, 0, 0))
        self.bc_square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, 1, 0))
        self.bc_square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, -1, 0))
        self.bc_square_sg.add_edge(0, 1, from_jimage=(0, 0, 0), to_jimage=(0, 0, 0))
        self.bc_square_sg.add_edge(0, 1, from_jimage=(0, 0, 0), to_jimage=(-1, 0, 0))
        self.bc_square_sg.add_edge(0, 1, from_jimage=(0, 0, 0), to_jimage=(-1, -1, 0))
        self.bc_square_sg.add_edge(0, 1, from_jimage=(0, 0, 0), to_jimage=(0, -1, 0))

        # body-centered square lattice for testing
        # directions reversed, should be equivalent to as bc_square
        structure = Structure(Lattice.tetragonal(5.0, 50.0), ['H', 'He'], [[0, 0, 0], [0.5, 0.5, 0.5]])
        self.bc_square_sg_r = StructureGraph.with_empty_graph(structure, edge_weight_name="", edge_weight_units="")
        self.bc_square_sg_r.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(1, 0, 0))
        self.bc_square_sg_r.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(-1, 0, 0))
        self.bc_square_sg_r.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, 1, 0))
        self.bc_square_sg_r.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, -1, 0))
        self.bc_square_sg_r.add_edge(0, 1, from_jimage=(0, 0, 0), to_jimage=(0, 0, 0))
        self.bc_square_sg_r.add_edge(1, 0, from_jimage=(-1, 0, 0), to_jimage=(0, 0, 0))
        self.bc_square_sg_r.add_edge(1, 0, from_jimage=(-1, -1, 0), to_jimage=(0, 0, 0))
        self.bc_square_sg_r.add_edge(1, 0, from_jimage=(0, -1, 0), to_jimage=(0, 0, 0))

        # MoS2 example, structure graph obtained from critic2
        # (not ground state, from mp-1023924, single layer)
        stdout_file = os.path.join(os.path.dirname(__file__), "..", "..", "..",
                                   'test_files/critic2/MoS2_critic2_stdout.txt')
        with open(stdout_file, 'r') as f:
            reference_stdout = f.read()
        self.structure = Structure.from_file(os.path.join(os.path.dirname(__file__), "..", "..", "..",
                                             'test_files/critic2/MoS2.cif'))
        c2o = Critic2Output(self.structure, reference_stdout)
        self.mos2_sg = c2o.structure_graph(edge_weight="bond_length", edge_weight_units="Å")

        latt = Lattice.cubic(4.17)
        species = ["Ni", "O"]
        coords = [[0, 0, 0],
                  [0.5, 0.5, 0.5]]
        self.NiO = Structure.from_spacegroup(225, latt, species, coords).get_primitive_structure()
Example #2
0
    def test_sulfide_type(self):
        # NaS2 -> polysulfide
        latt = Lattice.tetragonal(9.59650, 11.78850)
        species = ["Na"] * 2 + ["S"] * 2
        coords = [[0.00000, 0.00000, 0.17000], [0.27600, 0.25000, 0.12500],
                  [0.03400, 0.25000, 0.29600], [0.14700, 0.11600, 0.40000]]
        struct = Structure.from_spacegroup(122, latt, species, coords)
        self.assertEqual(sulfide_type(struct), "polysulfide")

        # NaCl type NaS -> sulfide
        latt = Lattice.cubic(5.75)
        species = ["Na", "S"]
        coords = [[0.00000, 0.00000, 0.00000], [0.50000, 0.50000, 0.50000]]
        struct = Structure.from_spacegroup(225, latt, species, coords)
        self.assertEqual(sulfide_type(struct), "sulfide")

        # Na2S2O3 -> None (sulfate)
        latt = Lattice.monoclinic(6.40100, 8.10000, 8.47400, 96.8800)
        species = ["Na"] * 2 + ["S"] * 2 + ["O"] * 3
        coords = [[0.29706, 0.62396, 0.08575], [0.37673, 0.30411, 0.45416],
                  [0.52324, 0.10651, 0.21126], [0.29660, -0.04671, 0.26607],
                  [0.17577, 0.03720, 0.38049], [0.38604, -0.20144, 0.33624],
                  [0.16248, -0.08546, 0.11608]]
        struct = Structure.from_spacegroup(14, latt, species, coords)
        self.assertEqual(sulfide_type(struct), None)

        # Na3PS3O -> sulfide
        latt = Lattice.orthorhombic(9.51050, 11.54630, 5.93230)
        species = ["Na"] * 2 + ["S"] * 2 + ["P", "O"]
        coords = [[0.19920, 0.11580, 0.24950], [0.00000, 0.36840, 0.29380],
                  [0.32210, 0.36730, 0.22530], [0.50000, 0.11910, 0.27210],
                  [0.50000, 0.29400, 0.35500], [0.50000, 0.30300, 0.61140]]
        struct = Structure.from_spacegroup(36, latt, species, coords)
        self.assertEqual(sulfide_type(struct), "sulfide")
Example #3
0
 def test_lattice_2_lmpbox(self):
     matrix = np.diag(np.random.randint(5, 14, size=(3,))) \
              + np.random.rand(3, 3) * 0.2 - 0.1
     init_latt = Lattice(matrix)
     frac_coords = np.random.rand(10, 3)
     init_structure = Structure(init_latt, ["H"] * 10, frac_coords)
     origin = np.random.rand(3) * 10 - 5
     box, symmop = lattice_2_lmpbox(lattice=init_latt, origin=origin)
     boxed_latt = box.to_lattice()
     np.testing.assert_array_almost_equal(init_latt.abc, boxed_latt.abc)
     np.testing.assert_array_almost_equal(init_latt.angles,
                                          boxed_latt.angles)
     cart_coords = symmop.operate_multi(init_structure.cart_coords) - origin
     boxed_structure = Structure(boxed_latt, ["H"] * 10,
                                 cart_coords,
                                 coords_are_cartesian=True)
     np.testing.assert_array_almost_equal(boxed_structure.frac_coords,
                                          frac_coords)
     tetra_latt = Lattice.tetragonal(5, 5)
     tetra_box, _ = lattice_2_lmpbox(tetra_latt)
     self.assertIsNone(tetra_box.tilt)
     ortho_latt = Lattice.orthorhombic(5, 5, 5)
     ortho_box, _ = lattice_2_lmpbox(ortho_latt)
     self.assertIsNone(ortho_box.tilt)
     rot_tetra_latt = Lattice([[5, 0, 0], [0, 2, 2], [0, -2, 2]])
     _, rotop = lattice_2_lmpbox(rot_tetra_latt)
     np.testing. \
         assert_array_almost_equal(rotop.rotation_matrix,
                                   [[1, 0, 0],
                                    [0, 2 ** 0.5 / 2, 2 ** 0.5 / 2],
                                    [0, -2 ** 0.5 / 2, 2 ** 0.5 / 2]])
Example #4
0
 def test_lattice_2_lmpbox(self):
     matrix = np.diag(np.random.randint(5, 14, size=(3,))) \
              + np.random.rand(3, 3) * 0.2 - 0.1
     init_latt = Lattice(matrix)
     frac_coords = np.random.rand(10, 3)
     init_structure = Structure(init_latt, ["H"] * 10, frac_coords)
     origin = np.random.rand(3) * 10 - 5
     box, symmop = lattice_2_lmpbox(lattice=init_latt, origin=origin)
     boxed_latt = box.to_lattice()
     np.testing.assert_array_almost_equal(init_latt.abc, boxed_latt.abc)
     np.testing.assert_array_almost_equal(init_latt.angles,
                                          boxed_latt.angles)
     cart_coords = symmop.operate_multi(init_structure.cart_coords) \
                   - origin
     boxed_structure = Structure(boxed_latt, ["H"] * 10, cart_coords,
                                 coords_are_cartesian=True)
     np.testing.assert_array_almost_equal(boxed_structure.frac_coords,
                                          frac_coords)
     tetra_latt = Lattice.tetragonal(5, 5)
     tetra_box, _ = lattice_2_lmpbox(tetra_latt)
     self.assertIsNone(tetra_box.tilt)
     ortho_latt = Lattice.orthorhombic(5, 5, 5)
     ortho_box, _ = lattice_2_lmpbox(ortho_latt)
     self.assertIsNone(ortho_box.tilt)
     rot_tetra_latt = Lattice([[5, 0, 0], [0, 2, 2], [0, -2, 2]])
     _, rotop = lattice_2_lmpbox(rot_tetra_latt)
     np.testing.\
         assert_array_almost_equal(rotop.rotation_matrix,
                                   [[1, 0, 0],
                                    [0, 2 ** 0.5 / 2, 2 ** 0.5 / 2],
                                    [0, -2 ** 0.5 / 2, 2 ** 0.5 / 2]])
    def test_sulfide_type(self):
        # NaS2 -> polysulfide
        latt = Lattice.tetragonal(9.59650, 11.78850)
        species = ["Na"] * 2 + ["S"] * 2
        coords = [[0.00000, 0.00000, 0.17000],
                  [0.27600, 0.25000, 0.12500],
                  [0.03400, 0.25000, 0.29600],
                  [0.14700, 0.11600, 0.40000]]
        struct = Structure.from_spacegroup(122, latt, species, coords)
        self.assertEqual(sulfide_type(struct), "polysulfide")

        # NaCl type NaS -> sulfide
        latt = Lattice.cubic(5.75)
        species = ["Na", "S"]
        coords = [[0.00000, 0.00000, 0.00000],
                  [0.50000, 0.50000, 0.50000]]
        struct = Structure.from_spacegroup(225, latt, species, coords)
        self.assertEqual(sulfide_type(struct), "sulfide")

        # Na2S2O3 -> None (sulfate)
        latt = Lattice.monoclinic(6.40100, 8.10000, 8.47400, 96.8800)
        species = ["Na"] * 2 + ["S"] * 2 + ["O"] * 3
        coords = [[0.29706, 0.62396, 0.08575],
                  [0.37673, 0.30411, 0.45416],
                  [0.52324, 0.10651, 0.21126],
                  [0.29660, -0.04671, 0.26607],
                  [0.17577, 0.03720, 0.38049],
                  [0.38604, -0.20144, 0.33624],
                  [0.16248, -0.08546, 0.11608]]
        struct = Structure.from_spacegroup(14, latt, species, coords)
        self.assertEqual(sulfide_type(struct), None)

        # Na3PS3O -> sulfide
        latt = Lattice.orthorhombic(9.51050, 11.54630, 5.93230)
        species = ["Na"] * 2 + ["S"] * 2 + ["P", "O"]
        coords = [[0.19920, 0.11580, 0.24950],
                  [0.00000, 0.36840, 0.29380],
                  [0.32210, 0.36730, 0.22530],
                  [0.50000, 0.11910, 0.27210],
                  [0.50000, 0.29400, 0.35500],
                  [0.50000, 0.30300, 0.61140]]
        struct = Structure.from_spacegroup(36, latt, species, coords)
        self.assertEqual(sulfide_type(struct), "sulfide")
        
        # test for unphysical cells
        struct.scale_lattice(struct.volume*10)
        self.assertEqual(sulfide_type(struct), "sulfide")
Example #6
0
    def setUp(self):

        # trivial example, simple square lattice for testing
        structure = Structure(Lattice.tetragonal(5.0, 50.0), ['H'],
                              [[0, 0, 0]])
        self.square_sg = StructureGraph.with_empty_graph(structure,
                                                         edge_weight_name="",
                                                         edge_weight_units="")
        self.square_sg.add_edge(0,
                                0,
                                from_jimage=(0, 0, 0),
                                to_jimage=(1, 0, 0))
        self.square_sg.add_edge(0,
                                0,
                                from_jimage=(0, 0, 0),
                                to_jimage=(-1, 0, 0))
        self.square_sg.add_edge(0,
                                0,
                                from_jimage=(0, 0, 0),
                                to_jimage=(0, 1, 0))
        self.square_sg.add_edge(0,
                                0,
                                from_jimage=(0, 0, 0),
                                to_jimage=(0, -1, 0))

        # body-centered square lattice for testing
        structure = Structure(Lattice.tetragonal(5.0, 50.0), ['H', 'He'],
                              [[0, 0, 0], [0.5, 0.5, 0.5]])
        self.bc_square_sg = StructureGraph.with_empty_graph(
            structure, edge_weight_name="", edge_weight_units="")
        self.bc_square_sg.add_edge(0,
                                   0,
                                   from_jimage=(0, 0, 0),
                                   to_jimage=(1, 0, 0))
        self.bc_square_sg.add_edge(0,
                                   0,
                                   from_jimage=(0, 0, 0),
                                   to_jimage=(-1, 0, 0))
        self.bc_square_sg.add_edge(0,
                                   0,
                                   from_jimage=(0, 0, 0),
                                   to_jimage=(0, 1, 0))
        self.bc_square_sg.add_edge(0,
                                   0,
                                   from_jimage=(0, 0, 0),
                                   to_jimage=(0, -1, 0))
        self.bc_square_sg.add_edge(0,
                                   1,
                                   from_jimage=(0, 0, 0),
                                   to_jimage=(0, 0, 0))
        self.bc_square_sg.add_edge(0,
                                   1,
                                   from_jimage=(0, 0, 0),
                                   to_jimage=(-1, 0, 0))
        self.bc_square_sg.add_edge(0,
                                   1,
                                   from_jimage=(0, 0, 0),
                                   to_jimage=(-1, -1, 0))
        self.bc_square_sg.add_edge(0,
                                   1,
                                   from_jimage=(0, 0, 0),
                                   to_jimage=(0, -1, 0))

        # body-centered square lattice for testing
        # directions reversed, should be equivalent to as bc_square
        structure = Structure(Lattice.tetragonal(5.0, 50.0), ['H', 'He'],
                              [[0, 0, 0], [0.5, 0.5, 0.5]])
        self.bc_square_sg_r = StructureGraph.with_empty_graph(
            structure, edge_weight_name="", edge_weight_units="")
        self.bc_square_sg_r.add_edge(0,
                                     0,
                                     from_jimage=(0, 0, 0),
                                     to_jimage=(1, 0, 0))
        self.bc_square_sg_r.add_edge(0,
                                     0,
                                     from_jimage=(0, 0, 0),
                                     to_jimage=(-1, 0, 0))
        self.bc_square_sg_r.add_edge(0,
                                     0,
                                     from_jimage=(0, 0, 0),
                                     to_jimage=(0, 1, 0))
        self.bc_square_sg_r.add_edge(0,
                                     0,
                                     from_jimage=(0, 0, 0),
                                     to_jimage=(0, -1, 0))
        self.bc_square_sg_r.add_edge(0,
                                     1,
                                     from_jimage=(0, 0, 0),
                                     to_jimage=(0, 0, 0))
        self.bc_square_sg_r.add_edge(1,
                                     0,
                                     from_jimage=(-1, 0, 0),
                                     to_jimage=(0, 0, 0))
        self.bc_square_sg_r.add_edge(1,
                                     0,
                                     from_jimage=(-1, -1, 0),
                                     to_jimage=(0, 0, 0))
        self.bc_square_sg_r.add_edge(1,
                                     0,
                                     from_jimage=(0, -1, 0),
                                     to_jimage=(0, 0, 0))

        # MoS2 example, structure graph obtained from critic2
        # (not ground state, from mp-1023924, single layer)
        stdout_file = os.path.join(
            os.path.dirname(__file__), "..", "..", "..",
            'test_files/critic2/MoS2_critic2_stdout.txt')
        with open(stdout_file, 'r') as f:
            reference_stdout = f.read()
        self.structure = Structure.from_file(
            os.path.join(os.path.dirname(__file__), "..", "..", "..",
                         'test_files/critic2/MoS2.cif'))
        c2o = Critic2Output(self.structure, reference_stdout)
        self.mos2_sg = c2o.structure_graph(edge_weight="bond_length",
                                           edge_weight_units="Å")

        latt = Lattice.cubic(4.17)
        species = ["Ni", "O"]
        coords = [[0, 0, 0], [0.5, 0.5, 0.5]]
        self.NiO = Structure.from_spacegroup(225, latt, species,
                                             coords).get_primitive_structure()
Example #7
0
def elongated_tetragonal():
    lattice = Lattice.tetragonal(a=1, c=3 * sqrt(2))
    coords = [[0.0, 0.0, 0.0]]
    return IStructure(lattice=lattice, species=["H"], coords=coords)
Example #8
0
def tetra_close_to_cubic():
    lattice = Lattice.tetragonal(1.001 * 10 / sqrt(2), 10)
    coords = [[0.0, 0.0, 0.0]]
    return IStructure(lattice=lattice, species=["H"], coords=coords)