{"library":"pymatgen-analysis-defects","title":"Pymatgen Defects Analysis","description":"Pymatgen-analysis-defects is an extension to the core pymatgen library, providing robust tools for analyzing point defects in crystalline materials. It is designed to work seamlessly with VASP inputs and outputs and offers an object-oriented interface to defect physics. The package, currently at version 2026.3.20, is actively maintained with a regular release cadence and is closely integrated with the atomate2 workflow framework, although it can also be used standalone for defect analysis.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install pymatgen-analysis-defects"],"cli":null},"imports":["from pymatgen.analysis.defects.generators import generate_all_native_defects","from pymatgen.analysis.defects.generators import ChargeInterstitialGenerator","from pymatgen.analysis.defects.thermo import DefectEntry","from pymatgen.analysis.defects.thermo import FormationEnergyDiagram","from pymatgen.analysis.defects.core import Defect"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom mp_api.client import MPRester\nfrom pymatgen.analysis.defects.generators import generate_all_native_defects\n\n# Replace with your Materials Project API key if needed\n# For quickstart, using os.environ.get is safer for direct execution\napi_key = os.environ.get(\"MP_API_KEY\", \"\") \n\nif api_key:\n    try:\n        with MPRester(api_key=api_key) as mpr:\n            # Fetch a charge density object for a material (e.g., mp-804 for SrTiO3)\n            print(\"Fetching charge density from Materials Project...\")\n            chgcar = mpr.get_charge_density_from_material_id(\"mp-804\")\n\n            # Generate all native defects for the fetched structure\n            print(\"Generating native defects...\")\n            native_defects = generate_all_native_defects(chgcar.structure)\n\n            print(f\"Found {len(native_defects)} native defects. First 3 examples:\")\n            for i, defect in enumerate(native_defects[:3]):\n                print(f\"  Defect {i+1}: {defect.name}, Charge states: {defect.charge_states}\")\n    except Exception as e:\n        print(f\"An error occurred while connecting to MPRester or processing data: {e}\")\n        print(\"Ensure your MP_API_KEY is correct and you have internet access.\")\nelse:\n    print(\"MP_API_KEY not found. Skipping Materials Project API example.\")\n    print(\"Please set the MP_API_KEY environment variable to run this example.\")\n","lang":"python","description":"This quickstart demonstrates how to use `pymatgen-analysis-defects` to generate a list of native point defects for a material fetched from the Materials Project database. It utilizes `MPRester` from `mp-api` to retrieve a structure and then `generate_all_native_defects` to enumerate possible defects.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}