本文整理汇总了Python中pymatgen.MPRester.get_structure_by_material_id方法的典型用法代码示例。如果您正苦于以下问题:Python MPRester.get_structure_by_material_id方法的具体用法?Python MPRester.get_structure_by_material_id怎么用?Python MPRester.get_structure_by_material_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.MPRester
的用法示例。
在下文中一共展示了MPRester.get_structure_by_material_id方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: submit_tests
# 需要导入模块: from pymatgen import MPRester [as 别名]
# 或者: from pymatgen.MPRester import get_structure_by_material_id [as 别名]
def submit_tests(names=None, params=None):
sma = SubmissionMongoAdapter.auto_load()
# note: TiO2 is duplicated twice purposely, duplicate check should catch this
compounds = {"Si": 149, "Al": 134, "ZnO": 2133, "FeO": 18905,
"LiCoO2": 601860, "LiFePO4": 585433, "GaAs": 2534, "Ge": 32, "PbTe": 19717,
"YbO": 1216, "SiC": 567551, "Fe3C": 510623, "SiO2": 547211, "Na2O": 2352,
"InSb (unstable)": 10148, "Sb2O5": 1705, "N2O5": 554368, "BaTiO3": 5020,
"Rb2O": 1394, "TiO2": 554278, "TiO2 (2)": 554278, 'BaNbTePO8': 560794,
"AgCl": 22922, "AgCl (2)": 570858, "SiO2 (2)": 555211, "Mg2SiO4": 2895, "CO2": 20066,
"PbSO4": 22298, "SrTiO3": 5532, "FeAl": 2658, "AlFeCo2": 10884, "NaCoO2": 554427,
"ReO3": 547271, "LaH2": 24153, "SiH3I": 28538, "LiBH4": 30209, "H8S5N2": 28143,
"LiOH": 23856, "SrO2": 2697, "Mn": 35, "Hg4Pt": 2312,
"PdF4": 13868, "Gd2WO6": 651333, 'MnO2': 19395, 'VO2': 504800}
mpr = MPRester()
for name, sid in compounds.iteritems():
if not names or name in names:
sid = mpr.get_materials_id_from_task_id("mp-{}".format(sid))
s = mpr.get_structure_by_material_id(sid, final=False)
snl = StructureNL(s, 'Anubhav Jain <[email protected]>')
parameters = {'priority': 10} if name == 'Si' else None
if params:
parameters.update(params)
sma.submit_snl(snl, '[email protected]', parameters=parameters)
示例2: CompositionToStructureFromMP
# 需要导入模块: from pymatgen import MPRester [as 别名]
# 或者: from pymatgen.MPRester import get_structure_by_material_id [as 别名]
class CompositionToStructureFromMP(ConversionFeaturizer):
"""
Featurizer to get a Structure object from Materials Project using the
composition alone. The most stable entry from Materials Project is selected,
or NaN if no entry is found in the Materials Project.
Args:
target_col_id (str or None): The column in which the converted data will
be written. If the column already exists then an error will be
thrown unless `overwrite_data` is set to `True`. If `target_col_id`
begins with an underscore the data will be written to the column:
`"{}_{}".format(col_id, target_col_id[1:])`, where `col_id` is the
column being featurized. If `target_col_id` is set to None then
the data will be written "in place" to the `col_id` column (this
will only work if `overwrite_data=True`).
overwrite_data (bool): Overwrite any data in `target_column` if it
exists.
map_key (str): Materials API key
"""
def __init__(self, target_col_id='structure', overwrite_data=False,
mapi_key=None):
super().__init__(target_col_id, overwrite_data)
self.mpr = MPRester(mapi_key)
def featurize(self, comp):
"""
Get the most stable structure from Materials Project
Args:
comp (`pymatgen.core.composition.Composition`): A composition.
Returns:
(`pymatgen.core.structure.Structure`): A Structure object.
"""
entries = self.mpr.get_data(comp.reduced_formula, prop="energy_per_atom")
if len(entries) > 0:
most_stable_entry = \
sorted(entries, key=lambda e: e['energy_per_atom'])[0]
s = self.mpr.get_structure_by_material_id(
most_stable_entry["material_id"])
return[s]
return [float("nan")]
def citations(self):
return [
"@article{doi:10.1063/1.4812323, author = {Jain,Anubhav and Ong,"
"Shyue Ping and Hautier,Geoffroy and Chen,Wei and Richards, "
"William Davidson and Dacek,Stephen and Cholia,Shreyas "
"and Gunter,Dan and Skinner,David and Ceder,Gerbrand "
"and Persson,Kristin A. }, title = {Commentary: The Materials "
"Project: A materials genome approach to accelerating materials "
"innovation}, journal = {APL Materials}, volume = {1}, number = "
"{1}, pages = {011002}, year = {2013}, doi = {10.1063/1.4812323}, "
"URL = {https://doi.org/10.1063/1.4812323}, "
"eprint = {https://doi.org/10.1063/1.4812323}}",
"@article{Ong2015, author = {Ong, Shyue Ping and Cholia, "
"Shreyas and Jain, Anubhav and Brafman, Miriam and Gunter, Dan "
"and Ceder, Gerbrand and Persson, Kristin a.}, doi = "
"{10.1016/j.commatsci.2014.10.037}, issn = {09270256}, "
"journal = {Computational Materials Science}, month = {feb}, "
"pages = {209--215}, publisher = {Elsevier B.V.}, title = "
"{{The Materials Application Programming Interface (API): A simple, "
"flexible and efficient API for materials data based on "
"REpresentational State Transfer (REST) principles}}, "
"url = {http://linkinghub.elsevier.com/retrieve/pii/S0927025614007113}, "
"volume = {97}, year = {2015} } "]
def implementors(self):
return ["Anubhav Jain"]
示例3: get_mp_structure
# 需要导入模块: from pymatgen import MPRester [as 别名]
# 或者: from pymatgen.MPRester import get_structure_by_material_id [as 别名]
def get_mp_structure(cls, mpid):
m = MPRester()
return m.get_structure_by_material_id(mpid)
示例4: compute_environments
# 需要导入模块: from pymatgen import MPRester [as 别名]
# 或者: from pymatgen.MPRester import get_structure_by_material_id [as 别名]
def compute_environments(chemenv_configuration):
string_sources = {'cif': {'string': 'a Cif file', 'regexp': '.*\.cif$'},
'mp': {'string': 'the Materials Project database', 'regexp': 'mp-[0-9]+$'}}
questions = {'c': 'cif'}
if chemenv_configuration.has_materials_project_access:
questions['m'] = 'mp'
lgf = LocalGeometryFinder()
lgf.setup_parameters()
allcg = AllCoordinationGeometries()
strategy_class = strategies_class_lookup[chemenv_configuration.package_options['default_strategy']['strategy']]
#TODO: Add the possibility to change the parameters and save them in the chemenv_configuration
default_strategy = strategy_class()
default_strategy.setup_options(chemenv_configuration.package_options['default_strategy']['strategy_options'])
max_dist_factor = chemenv_configuration.package_options['default_max_distance_factor']
firsttime = True
while True:
if len(questions) > 1:
found = False
print('Enter the source from which the structure is coming or <q> to quit :')
for key_character, qq in questions.items():
print(' - <{}> for a structure from {}'.format(key_character, string_sources[qq]['string']))
test = input(' ... ')
if test == 'q':
break
if test not in list(questions.keys()):
for key_character, qq in questions.items():
if re.match(string_sources[qq]['regexp'], str(test)) is not None:
found = True
source_type = qq
if not found:
print('Wrong key, try again ...')
continue
else:
source_type = questions[test]
else:
found = False
source_type = list(questions.values())[0]
if found and len(questions) > 1:
input_source = test
if source_type == 'cif':
if not found:
input_source = input('Enter path to cif file : ')
cp = CifParser(input_source)
structure = cp.get_structures()[0]
elif source_type == 'mp':
if not found:
input_source = input('Enter materials project id (e.g. "mp-1902") : ')
a = MPRester(chemenv_configuration.materials_project_api_key)
structure = a.get_structure_by_material_id(input_source)
lgf.setup_structure(structure)
print('Computing environments for {} ... '.format(structure.composition.reduced_formula))
se = lgf.compute_structure_environments_detailed_voronoi(maximum_distance_factor=max_dist_factor)
print('Computing environments finished')
while True:
test = input('See list of environments determined for each (unequivalent) site ? '
'("y" or "n", "d" with details, "g" to see the grid) : ')
strategy = default_strategy
if test in ['y', 'd', 'g']:
strategy.set_structure_environments(se)
for eqslist in se.equivalent_sites:
site = eqslist[0]
isite = se.structure.index(site)
try:
if strategy.uniquely_determines_coordination_environments:
ces = strategy.get_site_coordination_environments(site)
else:
ces = strategy.get_site_coordination_environments_fractions(site)
except NeighborsNotComputedChemenvError:
continue
if ces is None:
continue
if len(ces) == 0:
continue
comp = site.species_and_occu
#ce = strategy.get_site_coordination_environment(site)
if strategy.uniquely_determines_coordination_environments:
ce = ces[0]
if ce is None:
continue
thecg = allcg.get_geometry_from_mp_symbol(ce[0])
mystring = 'Environment for site #{} {} ({}) : {} ({})\n'.format(str(isite),
comp.get_reduced_formula_and_factor()[0],
str(comp),
thecg.name,
ce[0])
else:
mystring = 'Environments for site #{} {} ({}) : \n'.format(str(isite),
comp.get_reduced_formula_and_factor()[0],
str(comp))
for ce in ces:
cg = allcg.get_geometry_from_mp_symbol(ce[0])
csm = ce[1]['other_symmetry_measures']['csm_wcs_ctwcc']
mystring += ' - {} ({}): {:.2f} % (csm : {:2f})\n'.format(cg.name, cg.mp_symbol,
100.0*ce[2],
csm)
if test in ['d', 'g'] and strategy.uniquely_determines_coordination_environments:
if thecg.mp_symbol != UNCLEAR_ENVIRONMENT_SYMBOL:
mystring += ' <Continuous symmetry measures> '
mingeoms = se.ce_list[isite][thecg.coordination_number][0].minimum_geometries()
for mingeom in mingeoms:
#.........这里部分代码省略.........
示例5: cif_lib_build
# 需要导入模块: from pymatgen import MPRester [as 别名]
# 或者: from pymatgen.MPRester import get_structure_by_material_id [as 别名]
def cif_lib_build(self, crystal_system, size_limit=None):
''' function to build cif and pdf library based on space group symbol
Parameters
----------
crystal_system: str
name of crystal system. It capitalized, like CUBIC.
space group symbol will be generated by get_symbol_list method
size_list : int
optional. Uppder limit of data pulled out per symbol
'''
self.crystal_system = crystal_system
space_group_symbol = self.get_symbol_list(crystal_system)
if isinstance(space_group_symbol, list):
space_group_symbol_set = space_group_symbol
else:
space_group_symbol_set = list(spac_group_symbol)
## changing dir
data_dir = os.path.join(self.working_dir, crystal_system)
self.data_dir = data_dir
self._makedirs(data_dir)
os.chdir(data_dir)
if os.getcwd() == data_dir:
print('Library will be built at %s' % data_dir)
else:
e = 'Werid, return'
raise RuntimeError(e)
# summary lists
missed_list = [] # reference
m_id_list = [] # reference for searchs have been done in the past
time_info = time.strftime('%Y-%m-%d')
# create dirs, cif and calculated dir
cif_dir = os.path.join(data_dir, 'cif_data')
self._makedirs(cif_dir)
self.cif_dir = cif_dir
# looping
for space_group_symbol in space_group_symbol_set:
print('Building library with space_group symbol: {}'.format(space_group_symbol))
## search query
m = MPRester(self.API_key)
search = m.query(criteria = {"spacegroup.symbol": space_group_symbol},
properties = ["material_id"])
if search:
## crazy looping
if size_limit:
dim = 400 # 400 data sets per symbol
else:
dim = len(search)
print('Pull out %s data sets' % dim)
print('Now, starts to save cif and compute pdf...')
for i in range(dim):
# part 1: grab cif files from data base
m_id = search[i]['material_id']
m_id_list.append(m_id)
m_struc = m.get_structure_by_material_id(m_id)
m_formula = m_struc.formula
m_name = m_formula.replace(' ', '') # material name
cif_w = CifWriter(m_struc)
cif_name = '{}_{}.cif'.format(space_group_symbol, m_name)
cif_w_name = os.path.join(cif_dir, cif_name)
if os.path.isfile(cif_w_name):
print('already have {}, skip'.format(cif_name))
pass # skip files already exist
else:
cif_w.write_file(cif_w_name)
print('{} has been saved'.format(cif_name))
else:
print('Hmm, no reasult. Something wrong')
missed_list.append(space_group_symbol)
pass
m_id_list_name = '{}_{}_material_id.txt'.format(crystal_system, time_info)
m_id_list_w_name = os.path.join(data_dir, m_id_list_name)
np.savetxt(m_id_list_w_name, m_id_list)
print('''SUMMARY: for {} cystsal sytem,
Symbols {} can't be found from data base'''.format(crystal_system, missed_list))
return cif_dir