import os import sys from mp_api.client import MPRester from pymatgen.io.vasp import Poscar API_KEY = os.getenv('MP_APIKEY') if API_KEY is None: print("\nError: Can not get MP API Key from the environment var MP_APIKEY\n") input("Press ENTER to terminate>>\n") exit() argv = sys.argv narg = len(argv) if narg <= 1: print("\nError: Chemical formula must be given as the first arg\n") input("Press ENTER to terminate>>\n") exit() formula = argv[1] mpr = MPRester(API_KEY) if mpr is None: print(f"\nError: Can not get MPRester using the given API_KEY [{API_KEY}]\n") input("Press ENTER to terminate>>\n") exit() search_criteria = {"formula": formula} results = mpr.summary.search(**search_criteria) if results: material_id = results[0].material_id print(f"Found material_id for CsCl: {material_id}") structure = mpr.get_structure_by_material_id(material_id) poscar = Poscar(structure) poscar.write_file('POSCAR') print(f"POSCAR file for {formula} has been created.") else: print(f"No materials found for {formula}.") print() input("Press ENTER to terminate>>\n")