{"id":4709,"library":"pymatgen","title":"Pymatgen: Python Materials Genomics","description":"Pymatgen (Python Materials Genomics) is a robust materials analysis code that defines core object representations for crystal structures, molecules, and electronic structure data. It powers the Materials Project and offers extensive tools for materials design, data analysis, and high-throughput computations. The current version is 2026.3.23, and it maintains a rapid release cadence, often with monthly or bi-monthly updates.","status":"active","version":"2026.3.23","language":"en","source_language":"en","source_url":"https://github.com/materialsproject/pymatgen","tags":["materials science","computational chemistry","vasp","materials project","solid state physics","crystallography"],"install":[{"cmd":"pip install pymatgen","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Used as the default JSON handler for faster serialization/deserialization.","package":"orjson","optional":false},{"reason":"Required for computing advanced properties like elasticity, EOS, and phonons using Structure.calc_property.","package":"matcalc","optional":true}],"imports":[{"symbol":"Structure","correct":"from pymatgen.core import Structure"},{"symbol":"Lattice","correct":"from pymatgen.core import Lattice"},{"symbol":"Molecule","correct":"from pymatgen.core import Molecule"},{"symbol":"MPRester","correct":"from pymatgen.ext.matproj import MPRester"},{"note":"While 'outputs' submodule exists, the main 'Vasprun' object is typically imported directly from 'pymatgen.io.vasp'.","wrong":"from pymatgen.io.vasp.outputs import Vasprun","symbol":"Vasprun","correct":"from pymatgen.io.vasp import Vasprun"},{"symbol":"Kpoints","correct":"from pymatgen.io.vasp.inputs import Kpoints"}],"quickstart":{"code":"import os\nfrom pymatgen.core import Structure, Lattice, Species\nfrom pymatgen.ext.matproj import MPRester\n\n# 1. Create a simple crystal structure (e.g., BCC iron)\nlattice = Lattice.cubic(2.86)\nspecies = [Species(\"Fe\")]\ncoords = [[0, 0, 0]]\nstructure = Structure(lattice, species, coords)\nprint(f\"Created structure: {structure.formula} with {structure.num_sites} sites.\")\n\n# 2. Use MPRester to fetch data (requires API key)\n# Get your API key from materialsproject.org after logging in\n# Set it as an environment variable 'MP_API_KEY'\napi_key = os.environ.get(\"MP_API_KEY\", \"\")\n\nif api_key:\n    try:\n        with MPRester(api_key) as mpr:\n            # Fetch entries for a chemical system, e.g., Li-Fe-O\n            entries = mpr.get_entries(\"Li-Fe-O\", inc_structure=True, property_data=[\"band_gap\"])\n            print(f\"Found {len(entries)} entries for Li-Fe-O.\")\n            if entries:\n                first_entry = entries[0]\n                print(f\"First entry formula: {first_entry.formula_pretty}\")\n                if \"band_gap\" in first_entry.data:\n                    print(f\"Band gap: {first_entry.data['band_gap']} eV\")\n    except Exception as e:\n        print(f\"Error fetching data from Materials Project: {e}\")\n        print(\"Ensure your MP_API_KEY is valid and has network access.\")\nelse:\n    print(\"MP_API_KEY environment variable not found. Skipping MPRester example.\")","lang":"python","description":"This quickstart demonstrates how to create a basic `Structure` object and interact with the Materials Project database using `MPRester`. An `MP_API_KEY` environment variable is required for `MPRester` functionality."},"warnings":[{"fix":"No user-facing fix is typically required, as 'pip install pymatgen' handles the new dependency. Advanced users may need to understand the new internal package structure.","message":"Starting with v2026.3.23, `pymatgen` underwent a major internal reorganization. Core functionality was moved to a separate `pymatgen-core` package, which `pymatgen` now depends on. While `pip install pymatgen` should remain fully backwards compatible and provide the same functionality, be aware of this architectural change in case of complex dependency management or introspection needs.","severity":"gotcha","affected_versions":">=2026.3.23"},{"fix":"Ensure `orjson` is installed: `pip install orjson`.","message":"The `orjson` library became a required dependency as of v2025.5.28 for faster JSON handling. Ensure `orjson` is installed in your environment if you encounter import errors or unexpected behavior related to JSON serialization.","severity":"gotcha","affected_versions":">=2025.5.28"},{"fix":"Check release notes for your specific version regarding `lxml` and `Vasprun` parsing. If performance is an issue, consider upgrading to the latest version which has optimized parsing without `lxml`.","message":"The usage of `lxml` for `Vasprun` parsing fluctuated around v2025.5.1 and v2025.5.2. It was introduced for speed improvements, then removed shortly after for specific situations. This might lead to unexpected performance changes or dependency requirements depending on the exact `pymatgen` version you are using if `Vasprun` parsing is critical.","severity":"gotcha","affected_versions":"2025.5.1 to 2025.5.2"},{"fix":"Review calls to `MPRester.get_entries` and explicitly use `property_data` for consistent entry-specific information or `summary_data=True` for comprehensive (potentially less consistent) data.","message":"The behavior of `MPRester.get_entries` regarding `property_data` and `summary_data` was clarified and refined in v2025.4.24. `property_data` is now consistent with the returned entry, while `summary_data` (obtained via a kwarg) is more comprehensive but not always consistent. Users relying on specific data consistency may need to adjust their calls.","severity":"gotcha","affected_versions":">=2025.4.24"},{"fix":"Migrate any direct usage of `pybtex` through `pymatgen` utilities to `bibtexparser` if issues arise. For most users, this change is internal and will not require code modification.","message":"The internal dependency for BibTeX parsing shifted from `pybtex` to `bibtexparser` in v2025.4.19. While `pymatgen` handles this change internally, users who were directly interacting with `pybtex`-related utilities within `pymatgen` might need to update their code.","severity":"deprecated","affected_versions":">=2025.4.19"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}