from pymatgen import Structure data = { "lattice": { "matrix": [[3.0, 0.0, 0.0], [0.0, 3.0, 0.0], [0.0, 0.0, 3.0]], "a": 3.0, "b": 3.0, "c": 3.0, "alpha": 90.0, "beta": 90.0, "gamma": 90.0 }, "sites": [ { "species": [{"element": "Si", "occu": 1.0}], "xyz": [0.0, 0.0, 0.0] }, { "species": [{"element": "O", "occu": 1.0}], "xyz": [0.5, 0.5, 0.5] } ] } structure = Structure.from_dict(data)
import numpy as np from pymatgen import Structure structure = Structure.from_file("mystructure.cif") data = structure.as_dict() data["lattice"]["matrix"] = np.identity(3) * 2.0 new_structure = Structure.from_dict(data)This example demonstrates how a `Structure` object can be modified using a dictionary object. The original structure is loaded from a CIF file, then converted to a dictionary using the `as_dict()` method. The lattice matrix is modified by assigning a new 3x3 numpy identity matrix multiplied by 2, and the modified dictionary is used to create a new `Structure` object.