class GetConfig: def __init__(self, symbols): self.symbols = symbols self.filenames = [] self.m = MPRester() self.pathnow = os.getcwd() def write_to(self, source_list, source_tag): for index, struct in enumerate(source_list): struct.to(filename=source_tag + '/' + self.filenames[index]) def get_structure_list(self, *args): structures = [] # single-element if not args[0]: for symbol in self.symbols: sg_structures = self.m.get_structures(symbol) self.filenames.extend( _getFileNameFromList(len(sg_structures), symbol)) structures.extend(sg_structures) # compound if len(self.symbols) > 1: for i in range(len(self.symbols)): if i >= 1: i_combs = list(cb(self.symbols, i + 1)) for index, comb in enumerate(i_combs): chem_str = '-'.join(list(comb)) cp_structures = self.m.get_structures(chem_str) self.filenames.extend( _getFileNameFromList(len(cp_structures), chem_str)) structures.extend(cp_structures) return structures
from pymatgen import MPRester if __name__ == "__main__": MAPI_KEY = None #Materials API key! QUERY = "mp-1203" # QUERY = "TiO" # QUERY = "Ti-O" mpr = MPRester(MAPI_KEY) structures = mpr.get_structures(QUERY) for s in structures: print s
from pymatgen import MPRester, Structure, Specie from pymatgen.command_line.gulp_caller import GulpCaller, GulpIO from matplotlib import pyplot mpr = MPRester() mono: Structure = mpr.get_structure_by_material_id('mp-352') s = mpr.get_structures('ZrO2') ortho: Structure = mpr.get_structure_by_material_id('mp-685097') tetra: Structure = mpr.get_structure_by_material_id('mp-1018721') for j, i in enumerate(mono.sites): if str(i.specie) == 'Hf': print(i.specie) mono.replace(j, species=Specie('Zr')) break for j, i in enumerate(mono.sites): if str(i.specie) == 'Hf': mono.replace(j, species=Specie('Zr')) break for j, i in enumerate(tetra.sites): if str(i.specie) == 'Hf': tetra.replace(j, species=Specie('Zr')) break for j, i in enumerate(ortho.sites): if str(i.specie) == 'Hf': ortho.replace(j, species=Specie('Zr')) break for j, i in enumerate(ortho.sites): if str(i.specie) == 'Hf': ortho.replace(j, species=Specie('Zr')) break