'MPRester' object has no attribute 'search' #2923
-
I am getting the below error while running MPrester from pymatgen. I have updated pymatgen as well. Help me. from pymatgen.ext.matproj import MPRester
import numpy as np
import pandas as pd
# Load SAXS data
data = load_data('SCOOH_Au10_1to4_NH2_Au5_HCl_1mM_20.0C_00133.avg') # replace with your own data file name and path
# Extract scattering vector and intensity data
q = data['q'] # scattering vector in 1/Angstroms
I = data['Intensity'] # intensity
def load_data(filename):
"""Load the original data into a dataframe"""
df=pd.read_csv(filename, skiprows=9, sep='\t',
names=['q', 'Intensity', 'Error'])
return df
# Calculate interplanar spacing from peak positions
lambda_ = 1.5418 # X-ray wavelength in Angstroms (replace with your own wavelength)
theta = 2*np.arcsin(q*lambda_/(4*np.pi))
d = lambda_/(2*np.sin(theta/2))
# Set up Materials Project API key
api_key = 'WJykuMzHXfCduDr3pp7ol7O5Y6EZBPe9' # replace with your own Materials Project API key
# Search the Materials Project for potential matches
with MPRester(api_key) as mpr:
results = mpr.search({'d_hkl': {'$in': [d]}}, ['material_id'])
# Display results
print('Potential matches found in the Materials Project:')
for result in results:
print('- {}'.format(result['material_id']))
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_18132/291635017.py in <module>
9 # Search the Materials Project for potential matches
10 with MPRester(api_key) as mpr:
---> 11 results = mpr.search({'d_hkl': {'$in': [d]}}, ['material_id'])
12
13 # Display results
~\Anaconda3\lib\site-packages\mp_api\client\mprester.py in __getattr__(self, attr)
204 )
205 else:
--> 206 raise AttributeError(f"{self.__class__.__name__!r} object has no attribute {attr!r}")
207
208 def get_task_ids_associated_with_material_id(
AttributeError: 'MPRester' object has no attribute 'search' |
Beta Was this translation helpful? Give feedback.
Answered by
janosh
Mar 30, 2023
Replies: 1 comment 2 replies
-
The filter syntax you're using is Mongo-style which is only supported by the old |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
janosh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The filter syntax you're using is Mongo-style which is only supported by the old
MPRester
in which case the method you want to use isquery
, notsearch
. However, you're using a new API key which is not compatible with the oldMPRester
. If you have an old API key, use that and changesearch
toquery
.